X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=plugins%2FShare%2FSharePlugin.php;h=d34bcc779e2b2253efcd5d907270af17e16d0af4;hb=e4a1dff98d6a15c8f513bdb2ef55c699f8e70bcd;hp=5972d1b517a70e0b74e73505ac4f26eb0cdcfbbb;hpb=1350987e2eb9b7e4fe18df1a06b356027818dc8d;p=quix0rs-gnu-social.git diff --git a/plugins/Share/SharePlugin.php b/plugins/Share/SharePlugin.php index 5972d1b517..d34bcc779e 100644 --- a/plugins/Share/SharePlugin.php +++ b/plugins/Share/SharePlugin.php @@ -40,6 +40,14 @@ class SharePlugin extends ActivityVerbHandlerPlugin return array(ActivityVerb::SHARE); } + // Share is a bit special and $act->objects[0] should be an Activity + // instead of ActivityObject! Therefore also $act->objects[0]->type is not set. + public function isMyActivity(Activity $act) { + return (count($act->objects) == 1 + && ($act->objects[0] instanceof Activity) + && $this->isMyVerb($act->verb)); + } + public function onRouterInitialized(URLMapper $m) { // Web UI actions @@ -108,13 +116,7 @@ class SharePlugin extends ActivityVerbHandlerPlugin // TODO: Remember to check Deleted_notice! // TODO: If a post is shared that we can't retrieve - what to do? $other = Ostatus_profile::ensureActivityObjectProfile($shared->actor); - $sharedNotice = $other->processActivity($shared, 'push'); // FIXME: push/salmon/what? - if (!$sharedNotice instanceof Notice) { - // And if we apparently can't get the shared notice, we'll abort the whole thing. - // TRANS: Client exception thrown when saving an activity share fails. - // TRANS: %s is a share ID. - throw new ClientException(sprintf(_m('Failed to save activity %s.'), $sharedUri)); - } + $sharedNotice = Notice::saveActivity($shared, $other->localProfile(), array('source'=>'share')); } catch (FeedSubException $e) { // Remote feed could not be found or verified, should we // transform this into an "RT @user Blah, blah, blah..."? @@ -122,6 +124,11 @@ class SharePlugin extends ActivityVerbHandlerPlugin return false; } + // Setting this here because when the algorithm gets back to + // Notice::saveActivity it will update the Notice object. + $stored->repeat_of = $sharedNotice->getID(); + $stored->conversation = $sharedNotice->conversation; + // We don't have to save a repeat in a separate table, we can // find repeats by just looking at the notice.repeat_of field. @@ -147,7 +154,7 @@ class SharePlugin extends ActivityVerbHandlerPlugin public function extendActivity(Notice $stored, Activity $act, Profile $scoped=null) { // TODO: How to handle repeats of deleted notices? - $target = Notice::getById($stored->repeat_of); + $target = Notice::getByID($stored->repeat_of); // TRANS: A repeat activity's title. %1$s is repeater's nickname // and %2$s is the repeated user's nickname. $act->title = sprintf(_('%1$s repeated a notice by %2$s'), @@ -156,14 +163,15 @@ class SharePlugin extends ActivityVerbHandlerPlugin $act->objects[] = $target->asActivity($scoped); } - public function activityObjectFromNotice(Notice $notice) + public function activityObjectFromNotice(Notice $stored) { // Repeat is a little bit special. As it's an activity, our // ActivityObject is instead turned into an Activity $object = new Activity(); + $object->actor = $stored->getProfile()->asActivityObject(); $object->verb = ActivityVerb::SHARE; - $object->content = $notice->rendered; - $this->extendActivity($stored, $act); + $object->content = $stored->getRendered(); + $this->extendActivity($stored, $object); return $object; } @@ -174,10 +182,47 @@ class SharePlugin extends ActivityVerbHandlerPlugin return true; } - // API stuff + // Layout stuff /** - * show the "favorite" form in the notice options element + * show a link to the author of repeat + * + * FIXME: Some repeat stuff still in lib/noticelistitem.php! ($nli->repeat etc.) + */ + public function onEndShowNoticeInfo(NoticeListItem $nli) + { + if (!empty($nli->repeat)) { + $repeater = $nli->repeat->getProfile(); + + $attrs = array('href' => $repeater->getUrl(), + 'class' => 'h-card p-author', + 'title' => $repeater->getFancyName()); + + $nli->out->elementStart('span', 'repeat'); + + // TRANS: Addition in notice list item if notice was repeated. Followed by a span with a nickname. + $nli->out->raw(_('Repeated by').' '); + + $nli->out->element('a', $attrs, $repeater->getNickname()); + + $nli->out->elementEnd('span'); + } + } + + public function onEndShowThreadedNoticeTailItems(NoticeListItem $nli, Notice $notice, &$threadActive) + { + if ($nli instanceof ThreadedNoticeListSubItem) { + // The sub-items are replies to a conversation, thus we use different HTML elements etc. + $item = new ThreadedNoticeListInlineRepeatsItem($notice, $nli->out); + } else { + $item = new ThreadedNoticeListRepeatsItem($notice, $nli->out); + } + $threadActive = $item->show() || $threadActive; + return true; + } + + /** + * show the "repeat" form in the notice options element * FIXME: Don't let a NoticeListItemAdapter slip in here (or extend that from NoticeListItem) * * @return void @@ -185,8 +230,9 @@ class SharePlugin extends ActivityVerbHandlerPlugin public function onEndShowNoticeOptionItems($nli) { // FIXME: Use bitmasks (but be aware that PUBLIC_SCOPE is 0!) - if ($nli->notice->scope == Notice::PUBLIC_SCOPE || - $nli->notice->scope == Notice::SITE_SCOPE) { + // Also: AHHH, $scope and $scoped are scarily similar looking. + $scope = $nli->notice->getScope(); + if ($scope === Notice::PUBLIC_SCOPE || $scope === Notice::SITE_SCOPE) { $scoped = Profile::current(); if ($scoped instanceof Profile && $scoped->getID() !== $nli->notice->getProfile()->getID()) { @@ -205,7 +251,7 @@ class SharePlugin extends ActivityVerbHandlerPlugin } } - public function showNoticeListItem(NoticeListItem $nli) + protected function showNoticeListItem(NoticeListItem $nli) { // pass } @@ -218,9 +264,38 @@ class SharePlugin extends ActivityVerbHandlerPlugin // pass } + // API stuff + + /** + * Typically just used to fill out Twitter-compatible API status data. + * + * FIXME: Make all the calls before this end up with a Notice instead of ArrayWrapper please... + */ + public function onNoticeSimpleStatusArray($notice, array &$status, Profile $scoped=null, array $args=array()) + { + $status['repeated'] = $scoped instanceof Profile + ? $scoped->hasRepeated($notice) + : false; + + if ($status['repeated'] === true) { + // Qvitter API wants the "repeated_id" value set too. + $repeated = Notice::pkeyGet(array('profile_id' => $scoped->getID(), + 'repeat_of' => $notice->getID(), + 'verb' => ActivityVerb::SHARE)); + $status['repeated_id'] = $repeated->getID(); + } + } + + public function onTwitterUserArray(Profile $profile, array &$userdata, Profile $scoped=null, array $args=array()) + { + $userdata['favourites_count'] = Fave::countByProfile($profile); + } + + // Command stuff + /** - * EndInterpretCommand for FavoritePlugin will handle the 'fav' command - * using the class FavCommand. + * EndInterpretCommand for RepeatPlugin will handle the 'repeat' command + * using the class RepeatCommand. * * @param string $cmd Command being run * @param string $arg Rest of the message (including address) @@ -249,10 +324,10 @@ class SharePlugin extends ActivityVerbHandlerPlugin public function onHelpCommandMessages(HelpCommand $help, array &$commands) { - // TRANS: Help message for IM/SMS command "fav ". - $commands['fav '] = _m('COMMANDHELP', "add user's last notice as a 'fave'"); - // TRANS: Help message for IM/SMS command "fav #". - $commands['fav #'] = _m('COMMANDHELP', "add notice with the given id as a 'fave'"); + // TRANS: Help message for IM/SMS command "repeat #". + $commands['repeat #'] = _m('COMMANDHELP', "repeat a notice with a given id"); + // TRANS: Help message for IM/SMS command "repeat ". + $commands['repeat '] = _m('COMMANDHELP', "repeat the last notice from user"); } /**