]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/ActivityVerbPost/ActivityVerbPostPlugin.php
5dd0ee12d7bafb426cb7b9a8a8b277020e2d3c8b
[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         if (common_valid_http_url($act->objects[0]->link)) {
58             $stored->url = $act->objects[0]->link;
59         }
60
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.
64
65         // By returning true here instead of something that evaluates
66         // to false, we show that we have processed everything properly.
67         return true;
68     }
69
70     public function activityObjectFromNotice(Notice $notice)
71     {
72         $object = new ActivityObject();
73
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->rendered;
78         $object->link    = $notice->getUrl();
79
80         $object->extra[] = array('status_net', array('notice_id' => $notice->getID()));
81
82         return $object;
83     }
84
85     public function deleteRelated(Notice $notice)
86     {
87         // No action needed as the table for data storage _is_ the notice table.
88         return true;
89     }
90
91
92     /**
93      * Command stuff
94      */
95
96     // FIXME: Move stuff from lib/command.php to here just as with Share etc.
97
98
99     /**
100      * Layout stuff
101      */
102
103     protected function showNoticeContent(Notice $stored, HTMLOutputter $out, Profile $scoped=null)
104     {
105         $out->raw($stored->rendered);
106     }
107
108     protected function getActionTitle(ManagedAction $action, $verb, Notice $target, Profile $scoped)
109     {
110         // return page title
111     }
112
113     protected function doActionPreparation(ManagedAction $action, $verb, Notice $target, Profile $scoped)
114     {
115         // prepare Action?
116     }
117
118     protected function doActionPost(ManagedAction $action, $verb, Notice $target, Profile $scoped)
119     {
120         // handle POST
121     }
122
123     protected function getActivityForm(ManagedAction $action, $verb, Notice $target, Profile $scoped)
124     {
125         return new NoticeForm($action, array());
126     }
127
128     public function onPluginVersion(array &$versions)
129     {
130         $versions[] = array('name' => 'Post verb',
131                             'version' => GNUSOCIAL_VERSION,
132                             'author' => 'Mikael Nordfeldth',
133                             'homepage' => 'https://gnu.io/',
134                             'rawdescription' =>
135                             // TRANS: Plugin description.
136                             _m('Post handling with ActivityStreams.'));
137
138         return true;
139     }
140 }