summaryrefslogtreecommitdiff
path: root/plugins/Realtime/RealtimePlugin.php
diff options
context:
space:
mode:
authorEvan Prodromou <evan@controlyourself.ca>2009-07-14 15:26:39 -0400
committerEvan Prodromou <evan@controlyourself.ca>2009-07-14 15:26:39 -0400
commit86533d99d760b7d6b3a6a047898eec5e25497138 (patch)
tree887b44d4197af7ce13932e4d075e34179c3c015b /plugins/Realtime/RealtimePlugin.php
parent7a84b349a2f6ee36f4813bf2828c5bf2399d1614 (diff)
make RealtimePlugin work correctly
Diffstat (limited to 'plugins/Realtime/RealtimePlugin.php')
-rw-r--r--plugins/Realtime/RealtimePlugin.php75
1 files changed, 45 insertions, 30 deletions
diff --git a/plugins/Realtime/RealtimePlugin.php b/plugins/Realtime/RealtimePlugin.php
index 45251c66f..cb3b30845 100644
--- a/plugins/Realtime/RealtimePlugin.php
+++ b/plugins/Realtime/RealtimePlugin.php
@@ -2,7 +2,7 @@
/**
* Laconica, the distributed open-source microblogging tool
*
- * Plugin to do "real time" updates using Comet/Bayeux
+ * Superclass for plugins that do "real time" updates of timelines using Ajax
*
* PHP version 5
*
@@ -32,7 +32,10 @@ if (!defined('LACONICA')) {
}
/**
- * Plugin to do realtime updates using Comet
+ * Superclass for plugin to do realtime updates
+ *
+ * Based on experience with the Comet and Meteor plugins,
+ * this superclass extracts out some of the common functionality
*
* @category Plugin
* @package Laconica
@@ -41,25 +44,25 @@ if (!defined('LACONICA')) {
* @link http://laconi.ca/
*/
-class CometPlugin extends Plugin
+class RealtimePlugin extends Plugin
{
- var $server = null;
+ protected $replyurl = null;
+ protected $favorurl = null;
+ protected $deleteurl = null;
- function __construct($server=null, $username=null, $password=null)
+ function onInitializePlugin()
{
- $this->server = $server;
- $this->username = $username;
- $this->password = $password;
-
- parent::__construct();
+ $this->replyurl = common_local_url('newnotice');
+ $this->favorurl = common_local_url('favor');
+ // FIXME: need to find a better way to pass this pattern in
+ $this->deleteurl = common_local_url('deletenotice',
+ array('notice' => '0000000000'));
}
function onEndShowScripts($action)
{
$timeline = null;
- $this->log(LOG_DEBUG, 'got action ' . $action->trimmed('action'));
-
switch ($action->trimmed('action')) {
case 'public':
$timeline = '/timelines/public';
@@ -76,11 +79,11 @@ class CometPlugin extends Plugin
return true;
}
- $scripts = array('jquery.comet.js', 'json2.js', 'updatetimeline.js');
+ $scripts = $this->_getScripts();
foreach ($scripts as $script) {
$action->element('script', array('type' => 'text/javascript',
- 'src' => common_path('plugins/Comet/'.$script)),
+ 'src' => $script),
' ');
}
@@ -92,14 +95,10 @@ class CometPlugin extends Plugin
$user_id = 0;
}
- $replyurl = common_local_url('newnotice');
- $favorurl = common_local_url('favor');
- // FIXME: need to find a better way to pass this pattern in
- $deleteurl = common_local_url('deletenotice',
- array('notice' => '0000000000'));
-
$action->elementStart('script', array('type' => 'text/javascript'));
- $action->raw("$(document).ready(function() { updater.init(\"$this->server\", \"$timeline\", $user_id, \"$replyurl\", \"$favorurl\", \"$deleteurl\"); });");
+ $action->raw("$(document).ready(function() { ");
+ $action->raw($this->_updateInitialize($timeline, $user_id));
+ $action->raw(" });");
$action->elementEnd('script');
return true;
@@ -107,8 +106,6 @@ class CometPlugin extends Plugin
function onEndNoticeSave($notice)
{
- $this->log(LOG_INFO, "Called for save notice.");
-
$timelines = array();
// XXX: Add other timelines; this is just for the public one
@@ -127,20 +124,16 @@ class CometPlugin extends Plugin
}
if (count($timelines) > 0) {
- // Require this, since we need it
- require_once(INSTALLDIR.'/plugins/Comet/bayeux.class.inc.php');
$json = $this->noticeAsJson($notice);
- // Bayeux? Comet? Huh? These terms confuse me
- $bay = new Bayeux($this->server, $this->user, $this->password);
+ $this->_connect();
foreach ($timelines as $timeline) {
- $this->log(LOG_INFO, "Posting notice $notice->id to '$timeline'.");
- $bay->publish($timeline, $json);
+ $this->_publish($timeline, $json);
}
- $bay = NULL;
+ $this->_disconnect();
}
return true;
@@ -202,4 +195,26 @@ class CometPlugin extends Plugin
{
common_log($level, get_class($this) . ': '.$msg);
}
+
+ function _getScripts()
+ {
+ return array(common_local_path('plugins/Realtime/realtimeupdater.js'));
+ }
+
+ function _updateInitialize()
+ {
+ return '; ';
+ }
+
+ function _connect()
+ {
+ }
+
+ function _publish()
+ {
+ }
+
+ function _disconnect()
+ {
+ }
}