]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - plugins/Realtime/RealtimePlugin.php
Merge branch '1.0.x' of gitorious.org:statusnet/mainline into 1.0.x
[quix0rs-gnu-social.git] / plugins / Realtime / RealtimePlugin.php
index ff837d96175449212daa22b215b7b659e938f215..eca3a8b029be1f90ebee22158f761f68c9117460 100644 (file)
@@ -73,6 +73,10 @@ class RealtimePlugin extends Plugin
 
         switch ($cls)
         {
+        case 'KeepalivechannelAction':
+        case 'ClosechannelAction':
+            include_once $dir . '/' . strtolower(mb_substr($cls, 0, -6)) . '.php';
+            return false;
         case 'Realtime_channel':
             include_once $dir.'/'.$cls.'.php';
             return false;
@@ -81,9 +85,32 @@ class RealtimePlugin extends Plugin
         }
     }
 
+    /**
+     * Hook for RouterInitialized event.
+     *
+     * @param Net_URL_Mapper $m path-to-action mapper
+     * @return boolean hook return
+     */
+    function onRouterInitialized($m)
+    {
+        $m->connect('main/channel/:channelkey/keepalive',
+                    array('action' => 'keepalivechannel'),
+                    array('channelkey' => '[a-z0-9]{32}'));
+        $m->connect('main/channel/:channelkey/close',
+                    array('action' => 'closechannel'),
+                    array('channelkey' => '[a-z0-9]{32}'));
+        return true;
+    }
+
     function onEndShowScripts($action)
     {
-        $timeline = $this->_getTimeline($action);
+        $channel = $this->_getChannel($action);
+
+        if (empty($channel)) {
+            return true;
+        }
+
+        $timeline = $this->_pathToChannel(array($channel->channel_key));
 
         // If there's not a timeline on this page,
         // just return true
@@ -118,12 +145,14 @@ class RealtimePlugin extends Plugin
         }
         else {
             $pluginPath = common_path('plugins/Realtime/');
-            $realtimeUI = ' RealtimeUpdate.initActions("'.$url.'", "'.$timeline.'", "'. $pluginPath .'");';
+            $keepalive = common_local_url('keepalivechannel', array('channelkey' => $channel->channel_key));
+            $close = common_local_url('closechannel', array('channelkey' => $channel->channel_key));
+            $realtimeUI = ' RealtimeUpdate.initActions("'.$url.'", "'.$timeline.'", "'. $pluginPath .'", "'.$keepalive.'", "'.$close.'"); ';
         }
 
         $script = ' $(document).ready(function() { '.
           $realtimeUI.
-          $this->_updateInitialize($timeline, $user_id).
+            $this->_updateInitialize($timeline, $user_id).
           '}); ';
         $action->inlineScript($script);
 
@@ -412,7 +441,18 @@ class RealtimePlugin extends Plugin
         return '';
     }
 
+
     function _getTimeline($action)
+    {
+        $channel = $this->_getChannel($action);
+        if (empty($channel)) {
+            return null;
+        }
+
+        return $this->_pathToChannel(array($channel->channel_key));
+    }
+
+    function _getChannel($action)
     {
         $timeline = null;
                $arg1     = null;
@@ -461,16 +501,13 @@ class RealtimePlugin extends Plugin
                                                                                                $action_name,
                                                                                                $arg1,
                                                                                                $arg2);
-               
-               if (!empty($channel)) {
-                       $timeline = $this->_pathToChannel(array($channel->channel_key));
-               }
-                               
-        return $timeline;
+
+        return $channel;
     }
     
     function onStartReadWriteTables(&$alwaysRW, &$rwdb)
     {
        $alwaysRW[] = 'realtime_channel';
+       return true;
     }
 }