X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=plugins%2FRealtime%2FRealtimePlugin.php;h=030df405b0f6041408bbe425d712728b60b62ef6;hb=04ca706601a2a3b556cc52fa21b61fcd842c4e87;hp=4fb8bf84e5e55adac63eaf352c45e40606014a18;hpb=1f12993a4ddad8eba29c604c55f6b82d08dc0127;p=quix0rs-gnu-social.git diff --git a/plugins/Realtime/RealtimePlugin.php b/plugins/Realtime/RealtimePlugin.php index 4fb8bf84e5..99d1ff9c10 100644 --- a/plugins/Realtime/RealtimePlugin.php +++ b/plugins/Realtime/RealtimePlugin.php @@ -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; @@ -59,6 +58,7 @@ class RealtimePlugin extends Plugin { $this->replyurl = common_local_url('newnotice'); $this->favorurl = common_local_url('favor'); + $this->repeaturl = common_local_url('repeat'); // FIXME: need to find a better way to pass this pattern in $this->deleteurl = common_local_url('deletenotice', array('notice' => '0000000000')); @@ -77,14 +77,12 @@ class RealtimePlugin extends Plugin } $base = $action->selfUrl(); - if (mb_strstr($url, '?')) { + if (mb_strstr($base, '?')) { $url = $base . '&realtime=1'; } else { $url = $base . '?realtime=1'; } - $title = $action->title(); - $scripts = $this->_getScripts(); foreach ($scripts as $script) { @@ -99,30 +97,31 @@ class RealtimePlugin extends Plugin $user_id = 0; } - // FIXME: Need to check if the current URL is a poped realtime window - if (1==2) { + if ($action->boolean('realtime')) { $realtimeUI = ' RealtimeUpdate.initPopupWindow();'; } else { - // FIXME: This icon URL is no good if fancy URLs are off. - $iconurl = $base.'plugins/Realtime/icon_external.gif'; - $realtimeUI = ' RealtimeUpdate.addPopup("'.$url.'", "'.$title.'", "'. $iconurl .'");'; + $pluginPath = common_path('plugins/Realtime/'); + $realtimeUI = ' RealtimeUpdate.initActions("'.$url.'", "'.$timeline.'", "'. $pluginPath .'");'; } - $action->elementStart('script', array('type' => 'text/javascript')); - $script = ' $(document).ready(function() { '. - $this->_updateInitialize($timeline, $user_id). $realtimeUI. + $this->_updateInitialize($timeline, $user_id). '}); '; - $action->raw($script); + $action->inlineScript($script); - $action->elementEnd('script'); + return true; + } + function onEndShowStatusNetStyles($action) + { + $action->cssLink('plugins/Realtime/realtimeupdate.css', + null, 'screen, projection, tv'); return true; } - function onEndNoticeSave($notice) + function onHandleQueuedNotice($notice) { $paths = array(); @@ -136,8 +135,8 @@ class RealtimePlugin extends Plugin // Add to the public timeline - if ($notice->is_local || - ($notice->is_local == 0 && !common_config('public', 'localonly'))) { + if ($notice->is_local == Notice::LOCAL_PUBLIC || + ($notice->is_local == Notice::REMOTE_OMB && !common_config('public', 'localonly'))) { $paths[] = array('public'); } @@ -154,14 +153,11 @@ class RealtimePlugin extends Plugin // Add to inbox timelines // XXX: do a join - $inbox = new Notice_inbox(); - $inbox->notice_id = $notice->id; + $ni = $notice->whoGets(); - if ($inbox->find()) { - while ($inbox->fetch()) { - $user = User::staticGet('id', $inbox->user_id); - $paths[] = array('all', $user->nickname); - } + foreach (array_keys($ni) as $user_id) { + $user = User::staticGet('id', $user_id); + $paths[] = array('all', $user->nickname); } // Add to the replies timeline @@ -217,12 +213,13 @@ class RealtimePlugin extends Plugin $action->elementStart('body', (common_current_user()) ? array('id' => $action->trimmed('action'), - 'class' => 'user_in') - : array('id' => $action->trimmed('action'))); + 'class' => 'user_in realtime-popup') + : array('id' => $action->trimmed('action'), + 'class'=> 'realtime-popup')); - $action->elementStart('div', array('id' => 'header')); // XXX hack to deal with JS that tries to get the // root url from page output + $action->elementStart('address'); $action->element('a', array('class' => 'url', 'href' => common_local_url('public')), @@ -232,9 +229,9 @@ class RealtimePlugin extends Plugin if (common_logged_in()) { $action->showNoticeForm(); } - $action->elementEnd('div'); $action->showContentBlock(); + $action->showScripts(); $action->elementEnd('body'); return false; // No default processing } @@ -244,28 +241,34 @@ class RealtimePlugin extends Plugin // FIXME: this code should be abstracted to a neutral third // party, like Notice::asJson(). I'm not sure of the ethics // of refactoring from within a plugin, so I'm just abusing - // the TwitterApiAction method. Don't do this unless you're me! - - require_once(INSTALLDIR.'/lib/twitterapi.php'); + // the ApiAction method. Don't do this unless you're me! - $act = new TwitterApiAction('/dev/null'); + $act = new ApiAction('/dev/null'); - $arr = $act->twitter_status_array($notice, true); + $arr = $act->twitterStatusArray($notice, true); $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; + // Add needed repeat data + + if (!empty($notice->repeat_of)) { + $original = Notice::staticGet('id', $notice->repeat_of); + if (!empty($original)) { + $arr['retweeted_status']['url'] = $original->bestUrl(); + $arr['retweeted_status']['html'] = htmlspecialchars($original->rendered); + $arr['retweeted_status']['source'] = htmlspecialchars($original->source); + $originalProfile = $original->getProfile(); + $arr['retweeted_status']['user']['profile_url'] = $originalProfile->profileurl; + $arr['retweeted_status']['conversation_url'] = $this->getConversationUrl($original); + } + $original = null; + } + return $arr; } @@ -289,22 +292,68 @@ class RealtimePlugin extends Plugin return $tags; } - // Push this up to Plugin - - function log($level, $msg) + function getConversationUrl($notice) { - common_log($level, get_class($this) . ': '.$msg); + $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', - 'plugins/Realtime/json2.js'); + return array('plugins/Realtime/realtimeupdate.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) { - return "RealtimeUpdate.init($user_id, \"$this->replyurl\", \"$this->favorurl\", \"$this->deleteurl\"); "; + return "RealtimeUpdate.init($user_id, \"$this->replyurl\", \"$this->favorurl\", \"$this->repeaturl\", \"$this->deleteurl\"); "; } function _connect()