Merge branch '0.8.x' into small-fixes

This commit is contained in:
Jeffery To
2009-06-26 15:44:31 +08:00
49 changed files with 881 additions and 380 deletions

View File

@@ -82,7 +82,8 @@ class AttachmentList extends Widget
$atts = new File;
$att = $atts->getAttachments($this->notice->id);
if (empty($att)) return 0;
$this->out->elementStart('dl', array('id' =>'attachments'));
$this->out->elementStart('dl', array('id' =>'attachments',
'class' => 'entry-content'));
$this->out->element('dt', null, _('Attachments'));
$this->out->elementStart('dd');
$this->out->elementStart('ol', array('class' => 'attachments'));
@@ -249,10 +250,13 @@ class Attachment extends AttachmentListItem
$this->out->elementStart('div', 'entry-title');
$this->out->elementStart('a', $this->linkAttr());
$this->out->element('span', null, $this->linkTitle());
$this->showRepresentation();
$this->out->elementEnd('a');
$this->out->elementEnd('div');
$this->out->elementStart('div', 'entry-content');
$this->showRepresentation();
$this->out->elementEnd('div');
if (!empty($this->oembed->author_name) || !empty($this->oembed->provider)) {
$this->out->elementStart('div', array('id' => 'oembed_info',
'class' => 'entry-content'));

View File

@@ -95,9 +95,9 @@ $config =
'server' => $_server,
'theme' => 'default',
'design' =>
array('backgroundcolor' => '#F0F2F5',
array('backgroundcolor' => '#CEE1E9',
'contentcolor' => '#FFFFFF',
'sidebarcolor' => '#CEE1E9',
'sidebarcolor' => '#C8D1D5',
'textcolor' => '#000000',
'linkcolor' => '#002E6E',
'backgroundimage' => null,
@@ -125,7 +125,13 @@ $config =
array('appname' => 'laconica', # for syslog
'priority' => 'debug'), # XXX: currently ignored
'queue' =>
array('enabled' => false),
array('enabled' => false,
'subsystem' => 'db', # default to database, or 'stomp'
'stomp_server' => null,
'queue_basename' => 'laconica',
'stomp_username' => null,
'stomp_password' => null,
),
'license' =>
array('url' => 'http://creativecommons.org/licenses/by/3.0/',
'title' => 'Creative Commons Attribution 3.0',

View File

@@ -132,13 +132,13 @@ class DesignSettingsAction extends AccountSettingsAction
_('Off'));
$this->element('p', 'form_guide', _('Turn background image on or off.'));
$this->elementEnd('li');
}
$this->elementStart('li');
$this->checkbox('design_background-image_repeat',
_('Tile background image'),
($design->disposition & BACKGROUND_TILE) ? true : false );
$this->elementEnd('li');
$this->elementStart('li');
$this->checkbox('design_background-image_repeat',
_('Tile background image'),
($design->disposition & BACKGROUND_TILE) ? true : false );
$this->elementEnd('li');
}
$this->elementEnd('ul');
$this->elementEnd('fieldset');
@@ -388,7 +388,11 @@ class DesignSettingsAction extends AccountSettingsAction
$original = clone($design);
$design->backgroundimage = $filename;
// default to on, no tile
$design->setDisposition(true, false, false);
$result = $design->update($original);
if ($result === false) {

View File

@@ -72,7 +72,8 @@ class ImageFile
break;
case UPLOAD_ERR_INI_SIZE:
case UPLOAD_ERR_FORM_SIZE:
throw new Exception(sprintf(_('That file is too big. The maximum file size is %d.'), $this->maxFileSize()));
throw new Exception(sprintf(_('That file is too big. The maximum file size is %d.'),
ImageFile::maxFileSize()));
return;
case UPLOAD_ERR_PARTIAL:
@unlink($_FILES[$param]['tmp_name']);

View File

@@ -432,7 +432,7 @@ class NoticeListItem extends Widget
$this->out->elementStart('dl', 'response');
$this->out->element('dt', null, _('To'));
$this->out->elementStart('dd');
$this->out->element('a', array('href' => $convurl),
$this->out->element('a', array('href' => $convurl.'#notice-'.$this->notice->id),
_('in context'));
$this->out->elementEnd('dd');
$this->out->elementEnd('dl');

View File

@@ -112,12 +112,21 @@ class QueueHandler extends Daemon
}
function stomp_dispatch() {
require("Stomp.php");
$con = new Stomp(common_config('queue','stomp_server'));
if (!$con->connect()) {
// use an external message queue system via STOMP
require_once("Stomp.php");
$server = common_config('queue','stomp_server');
$username = common_config('queue', 'stomp_username');
$password = common_config('queue', 'stomp_password');
$con = new Stomp($server);
if (!$con->connect($username, $password)) {
$this->log(LOG_ERR, 'Failed to connect to queue server');
return false;
}
$queue_basename = common_config('queue','queue_basename');
// subscribe to the relevant queue (format: basename-transport)
$con->subscribe('/queue/'.$queue_basename.'-'.$this->transport());

View File

@@ -497,6 +497,22 @@ function common_linkify($url) {
$attrs = array('href' => $longurl, 'rel' => 'external');
$is_attachment = false;
$attachment_id = null;
$has_thumb = false;
// Check to see whether there's a filename associated with this URL.
// If there is, it's an upload and qualifies as an attachment
$localfile = File::staticGet('url', $longurl);
if (!empty($localfile)) {
if (isset($localfile->filename)) {
$is_attachment = true;
$attachment_id = $localfile->id;
}
}
// if this URL is an attachment, then we set class='attachment' and id='attahcment-ID'
// where ID is the id of the attachment for the given URL.
//
@@ -504,24 +520,35 @@ function common_linkify($url) {
// we're currently picking up oembeds only.
// I think the best option is another file_view table in the db
// and associated dbobject.
$query = "select file_oembed.file_id as file_id from file join file_oembed on file.id = file_oembed.file_id where file.url='$longurl'";
$file = new File;
$file->query($query);
$file->fetch();
if (!empty($file->file_id)) {
$is_attachment = true;
$attachment_id = $file->file_id;
$query = "select file_thumbnail.file_id as file_id from file join file_thumbnail on file.id = file_thumbnail.file_id where file.url='$longurl'";
$file2 = new File;
$file2->query($query);
$file2->fetch();
if (empty($file2->file_id)) {
$attrs['class'] = 'attachment';
} else {
if (!empty($file2)) {
$has_thumb = true;
}
}
// Add clippy
if ($is_attachment) {
$attrs['class'] = 'attachment';
if ($has_thumb) {
$attrs['class'] = 'attachment thumbnail';
}
$attrs['id'] = "attachment-{$file->file_id}";
$attrs['id'] = "attachment-{$attachment_id}";
}
return XMLStringer::estring('a', $attrs, $display);
}
@@ -826,89 +853,91 @@ function common_broadcast_notice($notice, $remote=false)
function common_enqueue_notice($notice)
{
$transports = array('omb', 'sms', 'public', 'twitter', 'facebook', 'ping');
if (common_config('xmpp', 'enabled'))
{
$transports[] = 'jabber';
}
if (common_config('queue','subsystem') == 'stomp') {
// use an external message queue system via STOMP
require_once("Stomp.php");
$con = new Stomp(common_config('queue','stomp_server'));
if (!$con->connect()) {
common_log(LOG_ERR, 'Failed to connect to queue server');
return false;
}
$queue_basename = common_config('queue','queue_basename');
foreach (array('jabber', 'omb', 'sms', 'public', 'twitter', 'facebook', 'ping') as $transport) {
if (!$con->send(
'/queue/'.$queue_basename.'-'.$transport, // QUEUE
$notice->id, // BODY of the message
array ( // HEADERS of the msg
'created' => $notice->created
))) {
common_log(LOG_ERR, 'Error sending to '.$transport.' queue');
return false;
}
common_log(LOG_DEBUG, 'complete remote queueing notice ID = ' . $notice->id . ' for ' . $transport);
}
//send tags as headers, so they can be used as JMS selectors
common_log(LOG_DEBUG, 'searching for tags ' . $notice->id);
$tags = array();
$tag = new Notice_tag();
$tag->notice_id = $notice->id;
if ($tag->find()) {
while ($tag->fetch()) {
common_log(LOG_DEBUG, 'tag found = ' . $tag->tag);
array_push($tags,$tag->tag);
}
}
$tag->free();
$con->send('/topic/laconica.'.$notice->profile_id,
$notice->content,
array(
'profile_id' => $notice->profile_id,
'created' => $notice->created,
'tags' => implode($tags,' - ')
)
);
common_log(LOG_DEBUG, 'sent to personal topic ' . $notice->id);
$con->send('/topic/laconica.allusers',
$notice->content,
array(
'profile_id' => $notice->profile_id,
'created' => $notice->created,
'tags' => implode($tags,' - ')
)
);
common_log(LOG_DEBUG, 'sent to catch-all topic ' . $notice->id);
$result = true;
common_enqueue_notice_stomp($notice, $transports);
}
else {
// in any other case, 'internal'
foreach (array('jabber', 'omb', 'sms', 'public', 'twitter', 'facebook', 'ping') as $transport) {
$qi = new Queue_item();
$qi->notice_id = $notice->id;
$qi->transport = $transport;
$qi->created = $notice->created;
$result = $qi->insert();
if (!$result) {
$last_error = &PEAR::getStaticProperty('DB_DataObject','lastError');
common_log(LOG_ERR, 'DB error inserting queue item: ' . $last_error->message);
return false;
}
common_log(LOG_DEBUG, 'complete queueing notice ID = ' . $notice->id . ' for ' . $transport);
}
common_enqueue_notice_db($notice, $transports);
}
return $result;
}
function common_post_inbox_transports()
function common_enqueue_notice_stomp($notice, $transports)
{
$transports = array('omb', 'sms');
// use an external message queue system via STOMP
require_once("Stomp.php");
if (common_config('xmpp', 'enabled')) {
$transports = array_merge($transports, array('jabber', 'public'));
$server = common_config('queue','stomp_server');
$username = common_config('queue', 'stomp_username');
$password = common_config('queue', 'stomp_password');
$con = new Stomp($server);
if (!$con->connect($username, $password)) {
common_log(LOG_ERR, 'Failed to connect to queue server');
return false;
}
return $transports;
$queue_basename = common_config('queue','queue_basename');
foreach ($transports as $transport) {
$result = $con->send('/queue/'.$queue_basename.'-'.$transport, // QUEUE
$notice->id, // BODY of the message
array ('created' => $notice->created));
if (!$result) {
common_log(LOG_ERR, 'Error sending to '.$transport.' queue');
return false;
}
common_log(LOG_DEBUG, 'complete remote queueing notice ID = ' . $notice->id . ' for ' . $transport);
}
//send tags as headers, so they can be used as JMS selectors
common_log(LOG_DEBUG, 'searching for tags ' . $notice->id);
$tags = array();
$tag = new Notice_tag();
$tag->notice_id = $notice->id;
if ($tag->find()) {
while ($tag->fetch()) {
common_log(LOG_DEBUG, 'tag found = ' . $tag->tag);
array_push($tags,$tag->tag);
}
}
$tag->free();
$con->send('/topic/laconica.'.$notice->profile_id,
$notice->content,
array(
'profile_id' => $notice->profile_id,
'created' => $notice->created,
'tags' => implode($tags,' - ')
)
);
common_log(LOG_DEBUG, 'sent to personal topic ' . $notice->id);
$con->send('/topic/laconica.allusers',
$notice->content,
array(
'profile_id' => $notice->profile_id,
'created' => $notice->created,
'tags' => implode($tags,' - ')
)
);
common_log(LOG_DEBUG, 'sent to catch-all topic ' . $notice->id);
$result = true;
}
function common_enqueue_notice_db($notice, $transports)
{
// in any other case, 'internal'
foreach ($transports as $transport) {
common_enqueue_notice_transport($notice, $transport);
}
}
function common_enqueue_notice_transport($notice, $transport)

View File

@@ -22,7 +22,7 @@ if (!defined('LACONICA')) { exit(1); }
require_once(INSTALLDIR.'/lib/queuehandler.php');
/**
* Common superclass for all XMPP-using queue handlers. They all need to
* Common superclass for all XMPP-using queue handlers. They all need to
* service their message queues on idle, and forward any incoming messages
* to the XMPP listener connection. So, we abstract out common code to a
* superclass.
@@ -30,12 +30,11 @@ require_once(INSTALLDIR.'/lib/queuehandler.php');
class XmppQueueHandler extends QueueHandler
{
function start()
{
# Low priority; we don't want to receive messages
$this->log(LOG_INFO, "INITIALIZE");
$this->conn = jabber_connect($this->_id);
$this->conn = jabber_connect($this->_id.$this->transport());
if ($this->conn) {
$this->conn->addEventHandler('message', 'forward_message', $this);
$this->conn->addEventHandler('reconnect', 'handle_reconnect', $this);
@@ -44,7 +43,7 @@ class XmppQueueHandler extends QueueHandler
}
return !is_null($this->conn);
}
function handle_reconnect(&$pl)
{
$this->conn->processUntil('session_start');
@@ -63,7 +62,7 @@ class XmppQueueHandler extends QueueHandler
die($e->getMessage());
}
}
function forward_message(&$pl)
{
if ($pl['type'] != 'chat') {