]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - plugins/Realtime/RealtimePlugin.php
json_encode() realtime arguments (closes Bug#3260)
[quix0rs-gnu-social.git] / plugins / Realtime / RealtimePlugin.php
index b559d80c605a540aa333299fb3e25deb998a0f35..634aab4c0080c453fcfbf9c97806a5aba37de177 100644 (file)
@@ -43,7 +43,6 @@ if (!defined('STATUSNET') && !defined('LACONICA')) {
  * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
  * @link     http://status.net/
  */
-
 class RealtimePlugin extends Plugin
 {
     protected $replyurl = null;
@@ -103,7 +102,7 @@ class RealtimePlugin extends Plugin
         }
         else {
             $pluginPath = common_path('plugins/Realtime/');
-            $realtimeUI = ' RealtimeUpdate.initActions("'.$url.'", "'.$timeline.'", "'. $pluginPath .'");';
+            $realtimeUI = ' RealtimeUpdate.initActions('.json_encode($url).', '.json_encode($timeline).', '. json_encode($pluginPath).');';
         }
 
         $script = ' $(document).ready(function() { '.
@@ -117,8 +116,9 @@ class RealtimePlugin extends Plugin
 
     function onEndShowStatusNetStyles($action)
     {
-        $action->cssLink('plugins/Realtime/realtimeupdate.css',
-                         null, 'screen, projection, tv');
+        $action->cssLink(Plugin::staticPath('Realtime', 'realtimeupdate.css'),
+                         null,
+                         'screen, projection, tv');
         return true;
     }
 
@@ -250,14 +250,7 @@ class RealtimePlugin extends Plugin
         $arr['url'] = $notice->bestUrl();
         $arr['html'] = htmlspecialchars($notice->rendered);
         $arr['source'] = htmlspecialchars($arr['source']);
-
-        if (!empty($notice->reply_to)) {
-            $reply_to = Notice::staticGet('id', $notice->reply_to);
-            if (!empty($reply_to)) {
-                $arr['in_reply_to_status_url'] = $reply_to->bestUrl();
-            }
-            $reply_to = null;
-        }
+        $arr['conversation_url'] = $this->getConversationUrl($notice);
 
         $profile = $notice->getProfile();
         $arr['user']['profile_url'] = $profile->profileurl;
@@ -272,10 +265,7 @@ class RealtimePlugin extends Plugin
                 $arr['retweeted_status']['source'] = htmlspecialchars($original->source);
                 $originalProfile = $original->getProfile();
                 $arr['retweeted_status']['user']['profile_url'] = $originalProfile->profileurl;
-                if (!empty($original->reply_to)) {
-                    $originalReply = Notice::staticGet('id', $original->reply_to);
-                    $arr['retweeted_status']['in_reply_to_status_url'] = $originalReply->bestUrl();
-                }
+                $arr['retweeted_status']['conversation_url'] = $this->getConversationUrl($original);
             }
             $original = null;
         }
@@ -303,9 +293,63 @@ class RealtimePlugin extends Plugin
         return $tags;
     }
 
+    function getConversationUrl($notice)
+    {
+        $convurl = null;
+
+        if ($notice->hasConversation()) {
+            $conv = Conversation::staticGet(
+                'id',
+                $notice->conversation
+            );
+            $convurl = $conv->uri;
+
+            if(empty($convurl)) {
+                $msg = sprintf(
+                    "Couldn't find Conversation ID %d to make 'in context'"
+                    . "link for Notice ID %d",
+                    $notice->conversation,
+                    $notice->id
+                );
+
+                common_log(LOG_WARNING, $msg);
+            } else {
+                $convurl .= '#notice-' . $notice->id;
+            }
+        }
+
+        return $convurl;
+    }
+
     function _getScripts()
     {
-        return array('plugins/Realtime/realtimeupdate.js');
+        return array(Plugin::staticPath('Realtime', 'realtimeupdate.min.js'));
+    }
+
+    /**
+     * Export any i18n messages that need to be loaded at runtime...
+     *
+     * @param Action $action
+     * @param array $messages
+     *
+     * @return boolean hook return value
+     */
+    function onEndScriptMessages($action, &$messages)
+    {
+        // TRANS: Text label for realtime view "play" button, usually replaced by an icon.
+        $messages['realtime_play'] = _m('BUTTON', 'Play');
+        // TRANS: Tooltip for realtime view "play" button.
+        $messages['realtime_play_tooltip'] = _m('TOOLTIP', 'Play');
+        // TRANS: Text label for realtime view "pause" button
+        $messages['realtime_pause'] = _m('BUTTON', 'Pause');
+        // TRANS: Tooltip for realtime view "pause" button
+        $messages['realtime_pause_tooltip'] = _m('TOOLTIP', 'Pause');
+        // TRANS: Text label for realtime view "popup" button, usually replaced by an icon.
+        $messages['realtime_popup'] = _m('BUTTON', 'Pop up');
+        // TRANS: Tooltip for realtime view "popup" button.
+        $messages['realtime_popup_tooltip'] = _m('TOOLTIP', 'Pop up in a window');
+
+        return true;
     }
 
     function _updateInitialize($timeline, $user_id)