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 // TODO: Implement a "fallback" feature which can handle anything _as_ an activityobject "note"
35 public function types()
37 return array(ActivityObject::ARTICLE,
38 ActivityObject::BLOGENTRY,
40 ActivityObject::STATUS,
41 ActivityObject::COMMENT,
42 // null, // if we want to follow the original Ostatus_profile::processActivity code
46 public function verbs()
48 return array(ActivityVerb::POST);
51 // FIXME: Set this to abstract public in lib/activityhandlerplugin.php when all plugins have migrated!
52 protected function saveObjectFromActivity(Activity $act, Notice $stored, array $options=array())
54 assert($this->isMyActivity($act));
56 $stored->object_type = ActivityUtils::resolveUri($act->objects[0]->type);
57 if (common_valid_http_url($act->objects[0]->link)) {
58 $stored->url = $act->objects[0]->link;
61 // We don't have to do just about anything for a new, remote notice since the fields
62 // are handled in the main Notice::saveActivity function. Such as content, attachments,
63 // parent/conversation etc.
65 // By returning true here instead of something that evaluates
66 // to false, we show that we have processed everything properly.
70 public function activityObjectFromNotice(Notice $notice)
72 $object = new ActivityObject();
74 $object->type = $notice->object_type ?: ActivityObject::NOTE;
75 $object->id = $notice->getUri();
76 $object->title = sprintf('New %1$s by %2$s', ActivityObject::canonicalType($object->type), $notice->getProfile()->getNickname());
77 $object->content = $notice->getRendered();
78 $object->link = $notice->getUrl();
80 $object->extra[] = array('status_net', array('notice_id' => $notice->getID()));
85 public function deleteRelated(Notice $notice)
87 // No action needed as the table for data storage _is_ the notice table.
96 // FIXME: Move stuff from lib/command.php to here just as with Share etc.
103 protected function showNoticeContent(Notice $stored, HTMLOutputter $out, Profile $scoped=null)
105 $out->raw($stored->getRendered());
108 protected function getActionTitle(ManagedAction $action, $verb, Notice $target, Profile $scoped)
113 protected function doActionPreparation(ManagedAction $action, $verb, Notice $target, Profile $scoped)
118 protected function doActionPost(ManagedAction $action, $verb, Notice $target, Profile $scoped)
123 protected function getActivityForm(ManagedAction $action, $verb, Notice $target, Profile $scoped)
125 return new NoticeForm($action, array());
128 public function onPluginVersion(array &$versions)
130 $versions[] = array('name' => 'Post verb',
131 'version' => GNUSOCIAL_VERSION,
132 'author' => 'Mikael Nordfeldth',
133 'homepage' => 'https://gnu.io/',
135 // TRANS: Plugin description.
136 _m('Post handling with ActivityStreams.'));