]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/ActivityVerbPost/ActivityVerbPostPlugin.php
First step of making Bookmark saveActivity-compatible
[quix0rs-gnu-social.git] / plugins / ActivityVerbPost / ActivityVerbPostPlugin.php
1 <?php
2 /*
3  * GNU Social - a federating social network
4  * Copyright (C) 2014, Free Software Foundation, Inc.
5  *
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.
10  *
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.
15  *
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/>.
18  */
19
20 if (!defined('GNUSOCIAL')) { exit(1); }
21
22 /**
23  * @package     Activity
24  * @maintainer  Mikael Nordfeldth <mmn@hethane.se>
25  */
26 class ActivityVerbPostPlugin extends ActivityVerbHandlerPlugin
27 {
28     // TODO: Implement a "fallback" feature which can handle anything _as_ an activityobject "note"
29
30     public function tag()
31     {
32         return 'post';
33     }
34
35     public function types()
36     {
37         return array(ActivityObject::ARTICLE,
38                      ActivityObject::BLOGENTRY,
39                      ActivityObject::NOTE,
40                      ActivityObject::STATUS,
41                      ActivityObject::COMMENT,
42                     // null,    // if we want to follow the original Ostatus_profile::processActivity code
43                     );
44     }
45
46     public function verbs()
47     {
48         return array(ActivityVerb::POST);
49     }
50
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())
53     {
54         assert($this->isMyActivity($act));
55
56         $stored->object_type = ActivityUtils::resolveUri($act->objects[0]->type);
57
58         // We don't have to do just about anything for a new, remote notice since the fields
59         // are handled in the main Notice::saveActivity function. Such as content, attachments,
60         // parent/conversation etc.
61
62         // By returning true here instead of something that evaluates
63         // to false, we show that we have processed everything properly.
64         return true;
65     }
66
67     public function activityObjectFromNotice(Notice $notice)
68     {
69         $object = new ActivityObject();
70
71         $object->type    = $notice->object_type ?: ActivityObject::NOTE;
72         $object->id      = $notice->getUri();
73         $object->title   = sprintf('New %1$s by %2$s', ActivityObject::canonicalType($object->type), $notice->getProfile()->getNickname());
74         $object->content = $notice->rendered;
75         $object->link    = $notice->getUrl();
76
77         $object->extra[] = array('status_net', array('notice_id' => $notice->getID()));
78
79         return $object;
80     }
81
82     public function deleteRelated(Notice $notice)
83     {
84         // No action needed as the table for data storage _is_ the notice table.
85         return true;
86     }
87
88
89     /**
90      * Command stuff
91      */
92
93     // FIXME: Move stuff from lib/command.php to here just as with Share etc.
94
95
96     /**
97      * Layout stuff
98      */
99
100     protected function showNoticeContent(Notice $stored, HTMLOutputter $out, Profile $scoped=null)
101     {
102         $out->raw($stored->rendered);
103     }
104
105     protected function getActionTitle(ManagedAction $action, $verb, Notice $target, Profile $scoped)
106     {
107         // return page title
108     }
109
110     protected function doActionPreparation(ManagedAction $action, $verb, Notice $target, Profile $scoped)
111     {
112         // prepare Action?
113     }
114
115     protected function doActionPost(ManagedAction $action, $verb, Notice $target, Profile $scoped)
116     {
117         // handle repeat POST
118     }
119
120     protected function getActivityForm(ManagedAction $action, $verb, Notice $target, Profile $scoped)
121     {
122         return new NoticeForm($action, array());
123     }
124
125     public function onPluginVersion(array &$versions)
126     {
127         $versions[] = array('name' => 'Post verb',
128                             'version' => GNUSOCIAL_VERSION,
129                             'author' => 'Mikael Nordfeldth',
130                             'homepage' => 'https://gnu.io/',
131                             'rawdescription' =>
132                             // TRANS: Plugin description.
133                             _m('Post handling with ActivityStreams.'));
134
135         return true;
136     }
137 }