]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/Blog/BlogPlugin.php
Merge remote-tracking branch 'upstream/master'
[quix0rs-gnu-social.git] / plugins / Blog / BlogPlugin.php
1 <?php
2 /**
3  * StatusNet - the distributed open-source microblogging tool
4  * Copyright (C) 2011, StatusNet, Inc.
5  *
6  * A microapp to implement lite blogging
7  *
8  * PHP version 5
9  *
10  * This program is free software: you can redistribute it and/or modify
11  * it under the terms of the GNU Affero General Public License as published by
12  * the Free Software Foundation, either version 3 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Affero General Public License for more details.
19  *
20  * You should have received a copy of the GNU Affero General Public License
21  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
22  *
23  * @category  Blog
24  * @package   StatusNet
25  * @author    Evan Prodromou <evan@status.net>
26  * @copyright 2011 StatusNet, Inc.
27  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
28  * @link      http://status.net/
29  */
30
31 if (!defined('STATUSNET')) {
32     // This check helps protect against security problems;
33     // your code file can't be executed directly from the web.
34     exit(1);
35 }
36
37 /**
38  * Blog plugin
39  *
40  * Many social systems have a way to write and share long-form texts with
41  * your network. This microapp plugin lets users post blog entries.
42  *
43  * @category  Blog
44  * @package   StatusNet
45  * @author    Evan Prodromou <evan@status.net>
46  * @copyright 2011 StatusNet, Inc.
47  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
48  * @link      http://status.net/
49  */
50
51 class BlogPlugin extends MicroAppPlugin
52 {
53
54     var $oldSaveNew = true;
55
56     /**
57      * Database schema setup
58      *
59      * @see Schema
60      * @see ColumnDef
61      *
62      * @return boolean hook value; true means continue processing, false means stop.
63      */
64     function onCheckSchema()
65     {
66         $schema = Schema::get();
67
68         $schema->ensureTable('blog_entry', Blog_entry::schemaDef());
69
70         return true;
71     }
72     
73     public function newFormAction(){
74         return 'newblogentry';
75     }
76
77     /**
78      * Map URLs to actions
79      *
80      * @param URLMapper $m path-to-action mapper
81      *
82      * @return boolean hook value; true means continue processing, false means stop.
83      */
84     public function onRouterInitialized(URLMapper $m)
85     {
86         $m->connect('blog/new',
87                     array('action' => 'newblogentry'));
88         $m->connect('blog/:id',
89                     array('action' => 'showblogentry'),
90                     array('id' => UUID::REGEX));
91         return true;
92     }
93
94     function onPluginVersion(array &$versions)
95     {
96         $versions[] = array('name' => 'Blog',
97                             'version' => GNUSOCIAL_VERSION,
98                             'author' => 'Evan Prodromou',
99                             'homepage' => 'http://status.net/wiki/Plugin:Blog',
100                             'rawdescription' =>
101                             // TRANS: Plugin description.
102                             _m('Let users write and share long-form texts.'));
103         return true;
104     }
105
106     function appTitle()
107     {
108         // TRANS: Blog application title.
109         return _m('TITLE','Blog');
110     }
111
112     function tag()
113     {
114         return 'blogentry';
115     }
116
117     function types()
118     {
119         return array(Blog_entry::TYPE);
120     }
121
122     function saveNoticeFromActivity(Activity $activity, Profile $actor, array $options=array())
123     {
124         if (count($activity->objects) != 1) {
125             // TRANS: Exception thrown when there are too many activity objects.
126             throw new ClientException(_m('Too many activity objects.'));
127         }
128
129         $entryObj = $activity->objects[0];
130
131         if ($entryObj->type != Blog_entry::TYPE) {
132             // TRANS: Exception thrown when blog plugin comes across a non-blog entry type object.
133             throw new ClientException(_m('Wrong type for object.'));
134         }
135
136         $notice = null;
137
138         switch ($activity->verb) {
139         case ActivityVerb::POST:
140             $notice = Blog_entry::saveNew($actor,
141                                          $entryObj->title,
142                                          $entryObj->content,
143                                          $options);
144             break;
145         default:
146             // TRANS: Exception thrown when blog plugin comes across a undefined verb.
147             throw new ClientException(_m('Unknown verb for blog entries.'));
148         }
149
150         return $notice;
151     }
152
153     function activityObjectFromNotice(Notice $notice)
154     {
155         $entry = Blog_entry::fromNotice($notice);
156
157         if (empty($entry)) {
158             // TRANS: Exception thrown when requesting a non-existing blog entry for notice.
159             throw new ClientException(sprintf(_m('No blog entry for notice %s.'),
160                         $notice->id));
161         }
162
163         return $entry->asActivityObject();
164     }
165
166     function entryForm($out)
167     {
168         return new BlogEntryForm($out);
169     }
170
171     function deleteRelated(Notice $notice)
172     {
173         if ($notice->object_type == Blog_entry::TYPE) {
174             $entry = Blog_entry::fromNotice($notice);
175             if (!empty($entry)) {
176                 $entry->delete();
177             }
178         }
179     }
180
181     function adaptNoticeListItem($nli)
182     {
183         $notice = $nli->notice;
184
185         if ($notice->object_type == Blog_entry::TYPE) {
186             return new BlogEntryListItem($nli);
187         }
188
189         return null;
190     }
191
192     function onEndShowScripts(Action $action)
193     {
194         $action->script(common_path('plugins/TinyMCE/js/jquery.tinymce.js'));
195         $action->inlineScript('var _tinymce_path = "'.common_path('plugins/TinyMCE/js/tiny_mce.js').'";'."\n".
196                               'var _tinymce_placeholder = "'.common_path('plugins/TinyMCE/icons/placeholder.png').'";'."\n");
197         $action->script($this->path('blog.js'));
198         return true;
199     }
200 }