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