3 * StatusNet - the distributed open-source microblogging tool
4 * Copyright (C) 2010, StatusNet, Inc.
6 * A plugin to enable social-bookmarking functionality
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 SocialBookmark
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')) {
36 * Bookmark plugin main class
40 * @author Brion Vibber <brionv@status.net>
41 * @author Evan Prodromou <evan@status.net>
42 * @copyright 2010 StatusNet, Inc.
43 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
44 * @link http://status.net/
47 class BookmarkPlugin extends Plugin
50 * Database schema setup
55 * @return boolean hook value; true means continue processing, false means stop.
58 function onCheckSchema()
60 $schema = Schema::get();
62 // For storing user-submitted flags on profiles
64 $schema->ensureTable('notice_bookmark',
65 array(new ColumnDef('notice_id',
70 new ColumnDef('title',
73 new ColumnDef('description',
79 function onNoticeDeleteRelated($notice)
81 $nb = Notice_bookmark::staticGet('notice_id', $notice->id);
90 function onEndShowStyles($action)
92 $action->style('.bookmark_tags li { display: inline; }');
93 $action->style('.bookmark_mentions li { display: inline; }');
98 * Load related modules when needed
100 * @param string $cls Name of the class to be loaded
102 * @return boolean hook value; true means continue processing, false means stop.
105 function onAutoload($cls)
107 $dir = dirname(__FILE__);
111 case 'NewbookmarkAction':
112 include_once $dir.'/newbookmark.php';
114 case 'Notice_bookmark':
115 include_once $dir.'/'.$cls.'.php';
118 include_once $dir.'/'.strtolower($cls).'.php';
126 * Map URLs to actions
128 * @param Net_URL_Mapper $m path-to-action mapper
130 * @return boolean hook value; true means continue processing, false means stop.
133 function onRouterInitialized($m)
135 $m->connect('main/bookmark/new',
136 array('action' => 'newbookmark'),
137 array('id' => '[0-9]+'));
142 function onStartShowNoticeItem($nli)
144 $nb = Notice_bookmark::staticGet('notice_id',
148 $att = $nli->notice->attachments();
149 $nli->out->elementStart('h3');
150 $nli->out->element('a',
151 array('href' => $att[0]->url),
153 $nli->out->elementEnd('h3');
154 $nli->out->element('p',
155 array('class' => 'bookmark_description'),
157 $nli->out->elementStart('p');
158 $nli->out->element('a', array('href' => $nli->profile->profileurl,
159 'class' => 'bookmark_author',
160 'title' => $nli->profile->getBestName()),
161 $nli->profile->getBestName());
162 $nli->out->elementEnd('p');
163 $tags = $nli->notice->getTags();
164 $nli->out->elementStart('ul', array('class' => 'bookmark_tags'));
165 foreach ($tags as $tag) {
166 $nli->out->elementStart('li');
167 $nli->out->element('a',
168 array('rel' => 'tag',
169 'href' => Notice_tag::url($tag)),
171 $nli->out->elementEnd('li');
172 $nli->out->text(' ');
174 $nli->out->elementEnd('ul');
175 $replies = $nli->notice->getReplies();
176 if (!empty($replies)) {
177 $nli->out->elementStart('ul', array('class' => 'bookmark_mentions'));
178 foreach ($replies as $reply) {
179 $other = Profile::staticGet('id', $reply);
180 $nli->out->elementStart('li');
181 $nli->out->element('a', array('rel' => 'tag',
182 'href' => $other->profileurl,
183 'title' => $other->getBestName()),
184 sprintf('for:%s', $other->nickname));
185 $nli->out->elementEnd('li');
186 $nli->out->text(' ');
188 $nli->out->elementEnd('ul');
195 function onStartActivityObjectFromNotice($notice, &$object)
197 $nb = Notice_bookmark::staticGet('notice_id',
202 $object->id = $notice->uri;
203 $object->type = ActivityObject::BOOKMARK;
204 $object->title = $nb->title;
205 $object->summary = $nb->summary;
207 // Attributes of the URL
209 $attachments = $notice->attachments();
211 if (count($attachments) != 1) {
212 throw new ServerException(_('Bookmark notice with the wrong number of attachments.'));
215 $target = $attachments[0];
217 $attrs = array('rel' => 'related',
218 'href' => $target->url);
220 if (!empty($target->title)) {
221 $attrs['title'] = $target->title;
224 $object->extra[] = array('link', $attrs);
226 // Attributes of the thumbnail, if any
228 $thumbnail = $target->getThumbnail();
230 if (!empty($thumbnail)) {
231 $tattrs = array('rel' => 'preview',
232 'href' => $thumbnail->url);
234 if (!empty($thumbnail->width)) {
235 $tattrs['media:width'] = $thumbnail->width;
238 if (!empty($thumbnail->height)) {
239 $tattrs['media:height'] = $thumbnail->height;
242 $object->extra[] = array('link', $attrs);
251 function onPluginVersion(&$versions)
253 $versions[] = array('name' => 'Sample',
254 'version' => STATUSNET_VERSION,
255 'author' => 'Evan Prodromou',
256 'homepage' => 'http://status.net/wiki/Plugin:Bookmark',
258 _m('Simple extension for supporting bookmarks.'));