3 * GNU Social - a federating social network
4 * Copyright (C) 2014, Free Software Foundation, Inc.
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Affero General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Affero General Public License for more details.
16 * You should have received a copy of the GNU Affero General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 if (!defined('GNUSOCIAL')) { exit(1); }
24 * @maintainer Mikael Nordfeldth <mmn@hethane.se>
26 class ActivityVerbPostPlugin extends ActivityVerbHandlerPlugin
28 const PLUGIN_VERSION = '2.0.0';
30 // TODO: Implement a "fallback" feature which can handle anything _as_ an activityobject "note"
37 public function types()
39 return array(ActivityObject::ARTICLE,
40 ActivityObject::BLOGENTRY,
42 ActivityObject::STATUS,
43 ActivityObject::COMMENT,
44 // null, // if we want to follow the original Ostatus_profile::processActivity code
48 public function verbs()
50 return array(ActivityVerb::POST);
53 // FIXME: Set this to abstract public in lib/activityhandlerplugin.php when all plugins have migrated!
54 protected function saveObjectFromActivity(Activity $act, Notice $stored, array $options=array())
56 assert($this->isMyActivity($act));
58 $stored->object_type = ActivityUtils::resolveUri($act->objects[0]->type);
59 if (common_valid_http_url($act->objects[0]->link)) {
60 $stored->url = $act->objects[0]->link;
63 // We don't have to do just about anything for a new, remote notice since the fields
64 // are handled in the main Notice::saveActivity function. Such as content, attachments,
65 // parent/conversation etc.
67 // By returning true here instead of something that evaluates
68 // to false, we show that we have processed everything properly.
72 public function activityObjectFromNotice(Notice $notice)
74 $object = new ActivityObject();
76 $object->type = $notice->object_type ?: ActivityObject::NOTE;
77 $object->id = $notice->getUri();
78 $object->title = sprintf('New %1$s by %2$s', ActivityObject::canonicalType($object->type), $notice->getProfile()->getNickname());
79 $object->content = $notice->getRendered();
80 $object->link = $notice->getUrl();
82 $object->extra[] = array('statusnet:notice_id', null, $notice->getID());
87 public function deleteRelated(Notice $notice)
89 // No action needed as the table for data storage _is_ the notice table.
98 // FIXME: Move stuff from lib/command.php to here just as with Share etc.
105 protected function showNoticeContent(Notice $stored, HTMLOutputter $out, Profile $scoped=null)
107 $out->raw($stored->getRendered());
110 protected function getActionTitle(ManagedAction $action, $verb, Notice $target, Profile $scoped)
115 protected function doActionPreparation(ManagedAction $action, $verb, Notice $target, Profile $scoped)
120 protected function doActionPost(ManagedAction $action, $verb, Notice $target, Profile $scoped)
125 protected function getActivityForm(ManagedAction $action, $verb, Notice $target, Profile $scoped)
127 return new NoticeForm($action, array());
130 public function onPluginVersion(array &$versions)
132 $versions[] = array('name' => 'Post verb',
133 'version' => self::PLUGIN_VERSION,
134 'author' => 'Mikael Nordfeldth',
135 'homepage' => 'https://gnu.io/',
137 // TRANS: Plugin description.
138 _m('Post handling with ActivityStreams.'));