Merge branch '0.7.x' of git@gitorious.org:laconica/dev into 0.7.x

This commit is contained in:
Robin Millette 2009-04-24 20:01:25 +00:00
commit f2f4e8c586
11 changed files with 309 additions and 41 deletions

View File

@ -172,15 +172,54 @@ class NewmessageAction extends Action
$this->notify($user, $this->other, $message);
$url = common_local_url('outbox', array('nickname' => $user->nickname));
if ($this->boolean('ajax')) {
$this->startHTML('text/xml;charset=utf-8');
$this->elementStart('head');
$this->element('title', null, _('Message sent'));
$this->elementEnd('head');
$this->elementStart('body');
$this->element('p', array('id' => 'command_result'),
sprintf(_('Direct message to %s sent'),
$this->other->nickname));
$this->elementEnd('body');
$this->elementEnd('html');
} else {
$url = common_local_url('outbox',
array('nickname' => $user->nickname));
common_redirect($url, 303);
}
}
common_redirect($url, 303);
/**
* Show an Ajax-y error message
*
* Goes back to the browser, where it's shown in a popup.
*
* @param string $msg Message to show
*
* @return void
*/
function ajaxErrorMsg($msg)
{
$this->startHTML('text/xml;charset=utf-8', true);
$this->elementStart('head');
$this->element('title', null, _('Ajax Error'));
$this->elementEnd('head');
$this->elementStart('body');
$this->element('p', array('id' => 'error'), $msg);
$this->elementEnd('body');
$this->elementEnd('html');
}
function showForm($msg = null)
{
$this->msg = $msg;
if ($msg && $this->boolean('ajax')) {
$this->ajaxErrorMsg($msg);
return;
}
$this->msg = $msg;
$this->showPage();
}

View File

@ -197,7 +197,12 @@ class Notice extends Memcached_DataObject
$notice->saveTags();
$notice->saveGroups();
$notice->addToInboxes();
if (common_config('queue', 'enabled')) {
$notice->addToAuthorInbox();
} else {
$notice->addToInboxes();
}
$notice->query('COMMIT');
Event::handle('EndNoticeSave', array($notice));
@ -207,7 +212,11 @@ class Notice extends Memcached_DataObject
# XXX: someone clever could prepend instead of clearing the cache
if (common_config('memcached', 'enabled')) {
$notice->blowCaches();
if (common_config('queue', 'enabled')) {
$notice->blowAuthorCaches();
} else {
$notice->blowCaches();
}
}
return $notice;
@ -271,6 +280,17 @@ class Notice extends Memcached_DataObject
$this->blowGroupCache($blowLast);
}
function blowAuthorCaches($blowLast=false)
{
// Clear the user's cache
$cache = common_memcache();
if (!empty($cache)) {
$cache->delete(common_cache_key('user:notices_with_friends:' . $this->profile_id));
}
$this->blowNoticeCache($blowLast);
$this->blowPublicCache($blowLast);
}
function blowGroupCache($blowLast=false)
{
$cache = common_memcache();
@ -639,6 +659,33 @@ class Notice extends Memcached_DataObject
return;
}
function addToAuthorInbox()
{
$enabled = common_config('inboxes', 'enabled');
if ($enabled === true || $enabled === 'transitional') {
$user = User::staticGet('id', $this->profile_id);
if (empty($user)) {
return;
}
$inbox = new Notice_inbox();
$UT = common_config('db','type')=='pgsql'?'"user"':'user';
$qry = 'INSERT INTO notice_inbox (user_id, notice_id, created) ' .
"SELECT $UT.id, " . $this->id . ", '" . $this->created . "' " .
"FROM $UT " .
"WHERE $UT.id = " . $this->profile_id . ' ' .
'AND NOT EXISTS (SELECT user_id, notice_id ' .
'FROM notice_inbox ' .
"WHERE user_id = " . $this->profile_id . ' '.
'AND notice_id = ' . $this->id . ' )';
if ($enabled === 'transitional') {
$qry .= " AND $UT.inboxed = 1";
}
$inbox->query($qry);
}
return;
}
function saveGroups()
{
$enabled = common_config('inboxes', 'enabled');
@ -691,24 +738,29 @@ class Notice extends Memcached_DataObject
// FIXME: do this in an offline daemon
$inbox = new Notice_inbox();
$UT = common_config('db','type')=='pgsql'?'"user"':'user';
$qry = 'INSERT INTO notice_inbox (user_id, notice_id, created, source) ' .
"SELECT $UT.id, " . $this->id . ", '" . $this->created . "', 2 " .
"FROM $UT JOIN group_member ON $UT.id = group_member.profile_id " .
'WHERE group_member.group_id = ' . $group->id . ' ' .
'AND NOT EXISTS (SELECT user_id, notice_id ' .
'FROM notice_inbox ' .
"WHERE user_id = $UT.id " .
'AND notice_id = ' . $this->id . ' )';
if ($enabled === 'transitional') {
$qry .= " AND $UT.inboxed = 1";
}
$result = $inbox->query($qry);
$this->addToGroupInboxes($group);
}
}
}
function addToGroupInboxes($group)
{
$inbox = new Notice_inbox();
$UT = common_config('db','type')=='pgsql'?'"user"':'user';
$qry = 'INSERT INTO notice_inbox (user_id, notice_id, created, source) ' .
"SELECT $UT.id, " . $this->id . ", '" . $this->created . "', 2 " .
"FROM $UT JOIN group_member ON $UT.id = group_member.profile_id " .
'WHERE group_member.group_id = ' . $group->id . ' ' .
'AND NOT EXISTS (SELECT user_id, notice_id ' .
'FROM notice_inbox ' .
"WHERE user_id = $UT.id " .
'AND notice_id = ' . $this->id . ' )';
if ($enabled === 'transitional') {
$qry .= " AND $UT.inboxed = 1";
}
$result = $inbox->query($qry);
}
function saveReplies()
{
// Alternative reply format

View File

@ -166,6 +166,16 @@ $(document).ready(function(){
$("#notice_action-submit").addClass("disabled");
return true;
},
error: function (xhr, textStatus, errorThrown) { $("#form_notice").removeClass("processing");
$("#notice_action-submit").removeAttr("disabled");
$("#notice_action-submit").removeClass("disabled");
if ($(".error", xhr.responseXML).length > 0) {
$('#form_notice').append(document._importNode($(".error", xhr.responseXML).get(0), true));
}
else {
alert("Sorry! We had trouble sending your notice ("+xhr.status+" "+xhr.statusText+"). Please report the problem to the site administrator if this happens again.");
}
},
success: function(xml) { if ($("#error", xml).length > 0) {
var result = document._importNode($("p", xml).get(0), true);
result = result.textContent || result.innerHTML;
@ -192,10 +202,8 @@ $(document).ready(function(){
$("#notice_action-submit").removeClass("disabled");
}
};
if (document.body.id != 'inbox' && document.body.id != 'outbox') {
$("#form_notice").ajaxForm(PostNotice);
$("#form_notice").each(addAjaxHidden);
}
$("#form_notice").ajaxForm(PostNotice);
$("#form_notice").each(addAjaxHidden);
NoticeHover();
NoticeReply();
});

View File

@ -36,7 +36,7 @@ class QueueHandler extends Daemon
$this->set_id($id);
}
}
function class_name()
{
return ucfirst($this->transport()) . 'Handler';
@ -46,7 +46,7 @@ class QueueHandler extends Daemon
{
return strtolower($this->class_name().'.'.$this->get_id());
}
function get_id()
{
return $this->_id;
@ -56,16 +56,16 @@ class QueueHandler extends Daemon
{
$this->_id = $id;
}
function transport()
{
return null;
}
function start()
{
}
function finish()
{
}
@ -74,14 +74,14 @@ class QueueHandler extends Daemon
{
return true;
}
function run()
{
if (!$this->start()) {
return false;
}
$this->log(LOG_INFO, 'checking for queued notices');
$transport = $this->transport();
$this->log(LOG_INFO, 'checking for queued notices for "' . $transport . '"');
do {
$qi = Queue_item::top($transport);
if ($qi) {
@ -113,7 +113,7 @@ class QueueHandler extends Daemon
} else {
$this->clear_old_claims();
$this->idle(5);
}
}
} while (true);
if (!$this->finish()) {
return false;
@ -127,7 +127,7 @@ class QueueHandler extends Daemon
sleep($timeout);
}
}
function clear_old_claims()
{
$qi = new Queue_item();
@ -137,10 +137,9 @@ class QueueHandler extends Daemon
$qi->free();
unset($qi);
}
function log($level, $msg)
{
common_log($level, $this->class_name() . ' ('. $this->get_id() .'): '.$msg);
}
}

View File

@ -879,7 +879,23 @@ function common_broadcast_notice($notice, $remote=false)
function common_enqueue_notice($notice)
{
foreach (array('jabber', 'omb', 'sms', 'public', 'twitter', 'facebook', 'ping') as $transport) {
$transports = array('omb', 'sms', 'twitter', 'facebook', 'ping');
if (common_config('xmpp', 'enabled')) {
$transports = array_merge($transports, array('jabber', 'public'));
}
if (common_config('memcached', 'enabled')) {
// Note: limited to 8 chars
$transports[] = 'memcache';
}
if (common_config('inboxes', 'enabled') === true ||
common_config('inboxes', 'enabled') === 'transitional') {
$transports[] = 'inbox';
}
foreach ($transports as $transport) {
$qi = new Queue_item();
$qi->notice_id = $notice->id;
$qi->transport = $transport;
@ -1332,7 +1348,7 @@ function common_compatible_license($from, $to)
*/
function common_database_tablename($tablename)
{
if(common_config('db','quote_identifiers')) {
$tablename = '"'. $tablename .'"';
}

View File

@ -121,6 +121,12 @@ class LinkbackPlugin extends Plugin
{
$args = array($this->notice->uri, $url);
if (!extension_loaded('xmlrpc')) {
if (!dl('xmlrpc.so')) {
common_log(LOG_ERR, "Can't pingback; xmlrpc extension not available.");
}
}
$request = xmlrpc_encode_request('pingback.ping', $args);
$context = stream_context_create(array('http' => array('method' => "POST",
'header' =>
@ -141,7 +147,7 @@ class LinkbackPlugin extends Plugin
}
// Largely cadged from trackback_cls.php by
// Ran Aroussi <ran@blogish.org>, GPL2
// Ran Aroussi <ran@blogish.org>, GPL2 or any later version
// http://phptrackback.sourceforge.net/
function getTrackback($text, $url)

69
scripts/inboxqueuehandler.php Executable file
View File

@ -0,0 +1,69 @@
#!/usr/bin/env php
<?php
/*
* Laconica - a distributed open-source microblogging tool
* Copyright (C) 2008,2009 Control Yourself, Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
// Abort if called from a web server
if (isset($_SERVER) && array_key_exists('REQUEST_METHOD', $_SERVER)) {
print "This script must be run from the command line\n";
exit();
}
define('INSTALLDIR', realpath(dirname(__FILE__) . '/..'));
define('LACONICA', true);
require_once(INSTALLDIR . '/lib/common.php');
require_once(INSTALLDIR . '/lib/queuehandler.php');
set_error_handler('common_error_handler');
class InboxQueueHandler extends QueueHandler
{
function transport()
{
return 'inbox';
}
function start() {
$this->log(LOG_INFO, "INITIALIZE");
return true;
}
function handle_notice($notice)
{
$this->log(LOG_INFO, "Distributing notice to inboxes for $notice->id");
$notice->addToInboxes();
$notice->blowSubsCache();
return true;
}
function finish() {
}
}
ini_set("max_execution_time", "0");
ini_set("max_input_time", "0");
set_time_limit(0);
mb_internal_encoding('UTF-8');
$id = ($argc > 1) ? $argv[1] : null;
$handler = new InboxQueueHandler($id);
$handler->runOnce();

View File

@ -0,0 +1,70 @@
#!/usr/bin/env php
<?php
/*
* Laconica - a distributed open-source microblogging tool
* Copyright (C) 2008,2009 Control Yourself, Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
// Abort if called from a web server
if (isset($_SERVER) && array_key_exists('REQUEST_METHOD', $_SERVER)) {
print "This script must be run from the command line\n";
exit();
}
define('INSTALLDIR', realpath(dirname(__FILE__) . '/..'));
define('LACONICA', true);
require_once(INSTALLDIR . '/lib/common.php');
require_once(INSTALLDIR . '/lib/queuehandler.php');
set_error_handler('common_error_handler');
class MemcachedQueueHandler extends QueueHandler
{
function transport()
{
return 'memcache';
}
function start() {
$this->log(LOG_INFO, "INITIALIZE");
return true;
}
function handle_notice($notice)
{
// XXX: fork here
$this->log(LOG_INFO, "Blowing memcached for $notice->id");
$notice->blowCaches();
return true;
}
function finish() {
}
}
ini_set("max_execution_time", "0");
ini_set("max_input_time", "0");
set_time_limit(0);
mb_internal_encoding('UTF-8');
$id = ($argc > 1) ? $argv[1] : null;
$handler = new MemcachedQueueHandler($id);
$handler->runOnce();

View File

@ -24,7 +24,8 @@ DIR=`dirname $0`
for f in xmppdaemon.php jabberqueuehandler.php publicqueuehandler.php \
xmppconfirmhandler.php smsqueuehandler.php ombqueuehandler.php \
twitterqueuehandler.php facebookqueuehandler.php pingqueuehandler.php; do
twitterqueuehandler.php facebookqueuehandler.php pingqueuehandler.php \
memcachedqueuehandler.php inboxqueuehandler.php; do
echo -n "Starting $f...";
php $DIR/$f

View File

@ -24,7 +24,8 @@ SDIR=`dirname $0`
DIR=`php $SDIR/getpiddir.php`
for f in jabberhandler ombhandler publichandler smshandler pinghandler \
xmppconfirmhandler xmppdaemon twitterhandler facebookhandler ; do
xmppconfirmhandler xmppdaemon twitterhandler facebookhandler \
memcachedhandler inboxhandler; do
FILES="$DIR/$f.*.pid"
for ff in "$FILES" ; do

View File

@ -86,7 +86,7 @@ border:0;
.error,
.success {
padding:4px 7px;
padding:4px 1.55%;
border-radius:4px;
-moz-border-radius:4px;
-webkit-border-radius:4px;
@ -426,6 +426,7 @@ line-height:1;
#form_notice fieldset {
border:0;
padding:0;
position:relative;
}
#form_notice legend {
display:none;
@ -480,7 +481,13 @@ margin-bottom:7px;
margin-left:18px;
float:left;
}
#form_notice .error {
float:left;
clear:both;
width:96.9%;
margin-bottom:0;
line-height:1.618;
}
/* entity_profile */
.entity_profile {