3 * StatusNet - the distributed open-source microblogging tool
4 * Copyright (C) 2011, StatusNet, Inc.
6 * A microapp to implement lite blogging
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.
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.
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/>.
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/
31 if (!defined('STATUSNET')) {
32 // This check helps protect against security problems;
33 // your code file can't be executed directly from the web.
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.
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/
51 class BlogPlugin extends MicroAppPlugin
54 var $oldSaveNew = true;
57 * Database schema setup
62 * @return boolean hook value; true means continue processing, false means stop.
64 function onCheckSchema()
66 $schema = Schema::get();
68 $schema->ensureTable('blog_entry', Blog_entry::schemaDef());
76 * @param Net_URL_Mapper $m path-to-action mapper
78 * @return boolean hook value; true means continue processing, false means stop.
80 function onRouterInitialized($m)
82 $m->connect('blog/new',
83 array('action' => 'newblogentry'));
84 $m->connect('blog/:id',
85 array('action' => 'showblogentry'),
86 array('id' => UUID::REGEX));
90 function onPluginVersion(&$versions)
92 $versions[] = array('name' => 'Blog',
93 'version' => GNUSOCIAL_VERSION,
94 'author' => 'Evan Prodromou',
95 'homepage' => 'http://status.net/wiki/Plugin:Blog',
97 // TRANS: Plugin description.
98 _m('Let users write and share long-form texts.'));
104 // TRANS: Blog application title.
105 return _m('TITLE','Blog');
115 return array(Blog_entry::TYPE);
118 function saveNoticeFromActivity(Activity $activity, Profile $actor, array $options=array())
120 if (count($activity->objects) != 1) {
121 // TRANS: Exception thrown when there are too many activity objects.
122 throw new ClientException(_m('Too many activity objects.'));
125 $entryObj = $activity->objects[0];
127 if ($entryObj->type != Blog_entry::TYPE) {
128 // TRANS: Exception thrown when blog plugin comes across a non-blog entry type object.
129 throw new ClientException(_m('Wrong type for object.'));
134 switch ($activity->verb) {
135 case ActivityVerb::POST:
136 $notice = Blog_entry::saveNew($actor,
142 // TRANS: Exception thrown when blog plugin comes across a undefined verb.
143 throw new ClientException(_m('Unknown verb for blog entries.'));
149 function activityObjectFromNotice(Notice $notice)
151 $entry = Blog_entry::fromNotice($notice);
154 // TRANS: Exception thrown when requesting a non-existing blog entry for notice.
155 throw new ClientException(sprintf(_m('No blog entry for notice %s.'),
159 return $entry->asActivityObject();
162 function entryForm($out)
164 return new BlogEntryForm($out);
167 function deleteRelated(Notice $notice)
169 if ($notice->object_type == Blog_entry::TYPE) {
170 $entry = Blog_entry::fromNotice($notice);
171 if (!empty($entry)) {
177 function adaptNoticeListItem($nli)
179 $notice = $nli->notice;
181 if ($notice->object_type == Blog_entry::TYPE) {
182 return new BlogEntryListItem($nli);
188 function onEndShowScripts($action)
190 $action->script(common_path('plugins/TinyMCE/js/jquery.tinymce.js'));
191 $action->inlineScript('var _tinymce_path = "'.common_path('plugins/TinyMCE/js/tiny_mce.js').'";'."\n".
192 'var _tinymce_placeholder = "'.common_path('plugins/TinyMCE/icons/placeholder.png').'";'."\n");
193 $action->script($this->path('blog.js'));