123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373 |
- <?php
- if (!defined('GNUSOCIAL')) { exit(1); }
- class SharePlugin extends ActivityVerbHandlerPlugin
- {
- public function tag()
- {
- return 'share';
- }
- public function types()
- {
- return array();
- }
- public function verbs()
- {
- return array(ActivityVerb::SHARE);
- }
-
-
- public function isMyActivity(Activity $act) {
- return (count($act->objects) == 1
- && ($act->objects[0] instanceof Activity)
- && $this->isMyVerb($act->verb));
- }
- public function onRouterInitialized(URLMapper $m)
- {
-
- $m->connect('main/repeat', array('action' => 'repeat'));
-
- $m->connect('api/statuses/retweeted_by_me.:format',
- array('action' => 'ApiTimelineRetweetedByMe',
- 'format' => '(xml|json|atom|as)'));
- $m->connect('api/statuses/retweeted_to_me.:format',
- array('action' => 'ApiTimelineRetweetedToMe',
- 'format' => '(xml|json|atom|as)'));
- $m->connect('api/statuses/retweets_of_me.:format',
- array('action' => 'ApiTimelineRetweetsOfMe',
- 'format' => '(xml|json|atom|as)'));
- $m->connect('api/statuses/retweet/:id.:format',
- array('action' => 'ApiStatusesRetweet',
- 'id' => '[0-9]+',
- 'format' => '(xml|json)'));
- $m->connect('api/statuses/retweets/:id.:format',
- array('action' => 'ApiStatusesRetweets',
- 'id' => '[0-9]+',
- 'format' => '(xml|json)'));
- }
-
- protected function saveObjectFromActivity(Activity $act, Notice $stored, array $options=array())
- {
- assert($this->isMyActivity($act));
-
- if (count($act->objects) !== 1) {
-
- throw new ClientException(_m('Can only handle share activities with exactly one object.'));
- }
- $shared = $act->objects[0];
- if (!$shared instanceof Activity) {
-
- throw new ClientException(_m('Can only handle shared activities.'));
- }
- $sharedUri = $shared->id;
- if (!empty($shared->objects[0]->id)) {
-
-
-
- $sharedUri = $shared->objects[0]->id;
- }
- if (empty($sharedUri)) {
- throw new ClientException(_m('Shared activity does not have an id'));
- }
- try {
-
-
-
- $sharedNotice = Notice::getByUri($sharedUri);
- } catch (NoResultException $e) {
-
-
-
- $other = Ostatus_profile::ensureActivityObjectProfile($shared->actor);
- $sharedNotice = Notice::saveActivity($shared, $other->localProfile(), array('source'=>'share'));
- } catch (FeedSubException $e) {
-
-
- common_log(LOG_INFO, __METHOD__ . ' got a ' . get_class($e) . ': ' . $e->getMessage());
- return false;
- }
-
-
- $stored->repeat_of = $sharedNotice->getID();
- $stored->conversation = $sharedNotice->conversation;
-
-
-
-
- return true;
- }
-
-
-
- public function onEndNoticeAsActivity(Notice $stored, Activity $act, Profile $scoped=null)
- {
- if (!$this->isMyNotice($stored)) {
- return true;
- }
- $this->extendActivity($stored, $act, $scoped);
- return false;
- }
- public function extendActivity(Notice $stored, Activity $act, Profile $scoped=null)
- {
-
- $target = Notice::getByID($stored->repeat_of);
-
-
- $act->title = sprintf(_('%1$s repeated a notice by %2$s'),
- $stored->getProfile()->getNickname(),
- $target->getProfile()->getNickname());
- $act->objects[] = $target->asActivity($scoped);
- }
- public function activityObjectFromNotice(Notice $stored)
- {
-
-
- $object = new Activity();
- $object->actor = $stored->getProfile()->asActivityObject();
- $object->verb = ActivityVerb::SHARE;
- $object->content = $stored->getRendered();
- $this->extendActivity($stored, $object);
- return $object;
- }
- public function deleteRelated(Notice $notice)
- {
-
- return true;
- }
-
-
- 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');
-
- $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) {
-
- $item = new ThreadedNoticeListInlineRepeatsItem($notice, $nli->out);
- } else {
- $item = new ThreadedNoticeListRepeatsItem($notice, $nli->out);
- }
- $threadActive = $item->show() || $threadActive;
- return true;
- }
-
- public function onEndShowNoticeOptionItems($nli)
- {
-
-
- $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()) {
- if ($scoped->hasRepeated($nli->notice)) {
- $nli->out->element('span', array('class' => 'repeated',
-
- 'title' => _('Notice repeated.')),
-
- _('Repeated'));
- } else {
- $repeat = new RepeatForm($nli->out, $nli->notice);
- $repeat->show();
- }
- }
- }
- }
- protected function showNoticeListItem(NoticeListItem $nli)
- {
-
- }
- public function openNoticeListItemElement(NoticeListItem $nli)
- {
-
- }
- public function closeNoticeListItemElement(NoticeListItem $nli)
- {
-
- }
-
-
- 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) {
-
- $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);
- }
-
-
- public function onStartInterpretCommand($cmd, $arg, $user, &$result)
- {
- if ($result === false && in_array($cmd, array('repeat', 'rp', 'rt', 'rd'))) {
- if (empty($arg)) {
- $result = null;
- } else {
- list($other, $extra) = CommandInterpreter::split_arg($arg);
- if (!empty($extra)) {
- $result = null;
- } else {
- $result = new RepeatCommand($user, $other);
- }
- }
- return false;
- }
- return true;
- }
- public function onHelpCommandMessages(HelpCommand $help, array &$commands)
- {
-
- $commands['repeat #<notice_id>'] = _m('COMMANDHELP', "repeat a notice with a given id");
-
- $commands['repeat <nickname>'] = _m('COMMANDHELP', "repeat the last notice from user");
- }
-
- public function onCommandSupportedAPI(Command $cmd, &$supported)
- {
- $supported = $supported || $cmd instanceof RepeatCommand;
- }
- protected function getActionTitle(ManagedAction $action, $verb, Notice $target, Profile $scoped)
- {
-
- }
- protected function doActionPreparation(ManagedAction $action, $verb, Notice $target, Profile $scoped)
- {
-
- }
- protected function doActionPost(ManagedAction $action, $verb, Notice $target, Profile $scoped)
- {
-
- }
- protected function getActivityForm(ManagedAction $action, $verb, Notice $target, Profile $scoped)
- {
- return new RepeatForm($action, $target);
- }
- public function onPluginVersion(array &$versions)
- {
- $versions[] = array('name' => 'Share verb',
- 'version' => GNUSOCIAL_VERSION,
- 'author' => 'Mikael Nordfeldth',
- 'homepage' => 'https://gnu.io/',
- 'rawdescription' =>
-
- _m('Shares (repeats) using ActivityStreams.'));
- return true;
- }
- }
|