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 * Database schema setup
59 * @return boolean hook value; true means continue processing, false means stop.
61 function onCheckSchema()
63 $schema = Schema::get();
65 $schema->ensureTable('blog_entry', Blog_entry::schemaDef());
71 * Load related modules when needed
73 * @param string $cls Name of the class to be loaded
75 * @return boolean hook value; true means continue processing, false means stop.
77 function onAutoload($cls)
79 $dir = dirname(__FILE__);
83 case 'NewblogentryAction':
84 case 'ShowblogentryAction':
85 include_once $dir . '/' . strtolower(mb_substr($cls, 0, -6)) . '.php';
88 case 'BlogEntryListItem':
89 include_once $dir . '/'.strtolower($cls).'.php';
92 include_once $dir . '/'.$cls.'.php';
100 * Map URLs to actions
102 * @param Net_URL_Mapper $m path-to-action mapper
104 * @return boolean hook value; true means continue processing, false means stop.
106 function onRouterInitialized($m)
108 $m->connect('blog/new',
109 array('action' => 'newblogentry'));
110 $m->connect('blog/:id',
111 array('action' => 'showblogentry'),
112 array('id' => UUID::REGEX));
116 function onPluginVersion(&$versions)
118 $versions[] = array('name' => 'Blog',
119 'version' => STATUSNET_VERSION,
120 'author' => 'Evan Prodromou',
121 'homepage' => 'http://status.net/wiki/Plugin:Blog',
123 _m('Let users write and share long-form texts.'));
139 return array(Blog_entry::TYPE);
142 function saveNoticeFromActivity($activity, $actor, $options=array())
144 if (count($activity->objects) != 1) {
145 // TRANS: Exception thrown when there are too many activity objects.
146 throw new ClientException(_m('Too many activity objects.'));
149 $entryObj = $activity->objects[0];
151 if ($entryObj->type != Blog_entry::TYPE) {
152 // TRANS: Exception thrown when blog plugin comes across a non-event type object.
153 throw new ClientException(_m('Wrong type for object.'));
158 switch ($activity->verb) {
159 case ActivityVerb::POST:
160 $notice = Blog_entry::saveNew($actor,
166 // TRANS: Exception thrown when blog plugin comes across a undefined verb.
167 throw new ClientException(_m('Unknown verb for blog entries.'));
173 function activityObjectFromNotice($notice)
175 $entry = Blog_entry::fromNotice($notice);
178 throw new ClientException(sprintf(_('No blog entry for notice %s'),
182 return $entry->asActivityObject();
185 function entryForm($out)
187 return new BlogEntryForm($out);
190 function deleteRelated($notice)
192 if ($notice->object_type == Blog_entry::TYPE) {
193 $entry = Blog_entry::fromNotice($notice);
194 if (exists($entry)) {
200 function adaptNoticeListItem($nli)
202 $notice = $nli->notice;
204 if ($notice->object_type == Blog_entry::TYPE) {
205 return new BlogEntryListItem($nli);
211 function onEndShowScripts($action)
213 $action->script(common_path('plugins/TinyMCE/js/jquery.tinymce.js'));
214 $action->inlineScript('var _tinymce_path = "'.common_path('plugins/TinyMCE/js/tiny_mce.js').'";'."\n".
215 'var _tinymce_placeholder = "'.common_path('plugins/TinyMCE/icons/placeholder.png').'";'."\n");
216 $action->script($this->path('blog.js'));