3 * StatusNet - the distributed open-source microblogging tool
4 * Copyright (C) 2010, StatusNet, Inc.
6 * A plugin to add titles to notices
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/>.
23 * @category NoticeTitle
25 * @author Evan Prodromou <evan@status.net>
26 * @copyright 2010 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.
37 define('NOTICE_TITLE_PLUGIN_VERSION', '0.1');
40 * NoticeTitle plugin to add an optional title to notices.
42 * Stores notice titles in a secondary table, notice_title.
44 * @category NoticeTitle
46 * @author Evan Prodromou <evan@status.net>
47 * @copyright 2010 StatusNet, Inc.
48 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
49 * @link http://status.net/
52 class NoticeTitlePlugin extends Plugin
55 * Database schema setup
57 * Add the notice_title helper table
62 * @return boolean hook value; true means continue processing, false means stop.
65 function onCheckSchema()
67 $schema = Schema::get();
69 // For storing titles for notices
71 $schema->ensureTable('notice_title',
72 array(new ColumnDef('notice_id',
77 new ColumnDef('title',
79 Notice_title::MAXCHARS,
86 * Load related modules when needed
88 * @param string $cls Name of the class to be loaded
90 * @return boolean hook value; true means continue processing, false means stop.
93 function onAutoload($cls)
95 $dir = dirname(__FILE__);
100 include_once $dir . '/'.$cls.'.php';
108 * Provide plugin version information.
110 * This data is used when showing the version page.
112 * @param array &$versions array of version data arrays; see EVENTS.txt
114 * @return boolean hook value
117 function onPluginVersion(&$versions)
119 $url = 'http://status.net/wiki/Plugin:NoticeTitle';
121 $versions[] = array('name' => 'NoticeTitle',
122 'version' => NOTICE_TITLE_PLUGIN_VERSION,
123 'author' => 'Evan Prodromou',
126 _m('Adds optional titles to notices'));
131 * Show title entry when showing notice form
133 * @param Form $form Form being shown
135 * @return boolean hook value
138 function onStartShowNoticeFormData($form)
140 $form->out->element('input', array('type' => 'text',
141 'id' => 'notice_title',
142 'name' => 'notice_title',
144 'maxlength' => Notice_title::MAXCHARS));
149 * Validate notice title before saving
151 * @param Action $action NewNoticeAction being executed
152 * @param integer &$authorId Author ID
153 * @param string &$text Text of the notice
154 * @param array &$options Options array
156 * @return boolean hook value
159 function onStartNoticeSaveWeb($action, &$authorId, &$text, &$options)
161 $title = $action->trimmed('notice_title');
162 if (!empty($title)) {
163 if (mb_strlen($title) > Notice_title::MAXCHARS) {
164 throw new Exception(sprintf(_m("Notice title too long (max %d)",
165 Notice_title::MAXCHARS)));
172 * Save notice title after notice is saved
174 * @param Action $action NewNoticeAction being executed
175 * @param Notice $notice Notice that was saved
177 * @return boolean hook value
180 function onEndNoticeSaveWeb($action, $notice)
182 if (!empty($notice)) {
184 $title = $action->trimmed('notice_title');
186 if (!empty($title)) {
188 $nt = new Notice_title();
190 $nt->notice_id = $notice->id;
201 * Show the notice title in lists
203 * @param NoticeListItem $nli NoticeListItem being shown
205 * @return boolean hook value
208 function onStartShowNoticeItem($nli)
210 $title = Notice_title::fromNotice($nli->notice);
212 if (!empty($title)) {
213 $nli->out->element('h4', array('class' => 'notice_title'), $title);
220 * Show the notice title in RSS output
222 * @param Notice $notice Notice being shown
223 * @param array &$entry array of values used for RSS output
225 * @return boolean hook value
228 function onEndRssEntryArray($notice, &$entry)
230 $title = Notice_title::fromNotice($notice);
232 if (!empty($title)) {
233 $entry['title'] = $title;
240 * Show the notice title in Atom output
242 * @param Notice &$notice Notice being shown
243 * @param XMLStringer &$xs output context
244 * @param string &$output string to be output as title
246 * @return boolean hook value
249 function onStartActivityTitle(&$notice, &$xs, &$output)
251 $title = Notice_title::fromNotice($notice);
253 if (!empty($title)) {