]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/ActivityVerbPost/ActivityVerbPostPlugin.php
[TRANSLATION] Update license and copyright notice in translation files
[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     const PLUGIN_VERSION = '2.0.0';
29
30     // TODO: Implement a "fallback" feature which can handle anything _as_ an activityobject "note"
31
32     public function tag()
33     {
34         return 'post';
35     }
36
37     public function types()
38     {
39         return array(ActivityObject::ARTICLE,
40                      ActivityObject::BLOGENTRY,
41                      ActivityObject::NOTE,
42                      ActivityObject::STATUS,
43                      ActivityObject::COMMENT,
44                     // null,    // if we want to follow the original Ostatus_profile::processActivity code
45                     );
46     }
47
48     public function verbs()
49     {
50         return array(ActivityVerb::POST);
51     }
52
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())
55     {
56         assert($this->isMyActivity($act));
57
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;
61         }
62
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.
66
67         // By returning true here instead of something that evaluates
68         // to false, we show that we have processed everything properly.
69         return true;
70     }
71
72     public function activityObjectFromNotice(Notice $notice)
73     {
74         $object = new ActivityObject();
75
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();
81
82         $object->extra[] = array('statusnet:notice_id', null, $notice->getID());
83
84         return $object;
85     }
86
87     public function deleteRelated(Notice $notice)
88     {
89         // No action needed as the table for data storage _is_ the notice table.
90         return true;
91     }
92
93
94     /**
95      * Command stuff
96      */
97
98     // FIXME: Move stuff from lib/command.php to here just as with Share etc.
99
100
101     /**
102      * Layout stuff
103      */
104
105     protected function showNoticeContent(Notice $stored, HTMLOutputter $out, Profile $scoped=null)
106     {
107         $out->raw($stored->getRendered());
108     }
109
110     protected function getActionTitle(ManagedAction $action, $verb, Notice $target, Profile $scoped)
111     {
112         // return page title
113     }
114
115     protected function doActionPreparation(ManagedAction $action, $verb, Notice $target, Profile $scoped)
116     {
117         // prepare Action?
118     }
119
120     protected function doActionPost(ManagedAction $action, $verb, Notice $target, Profile $scoped)
121     {
122         // handle POST
123     }
124
125     protected function getActivityForm(ManagedAction $action, $verb, Notice $target, Profile $scoped)
126     {
127         return new NoticeForm($action, array());
128     }
129
130     public function onPluginVersion(array &$versions)
131     {
132         $versions[] = array('name' => 'Post verb',
133                             'version' => self::PLUGIN_VERSION,
134                             'author' => 'Mikael Nordfeldth',
135                             'homepage' => 'https://gnu.io/',
136                             'rawdescription' =>
137                             // TRANS: Plugin description.
138                             _m('Post handling with ActivityStreams.'));
139
140         return true;
141     }
142 }