3 * StatusNet - the distributed open-source microblogging tool
4 * Copyright (C) 2011, StatusNet, Inc.
6 * A plugin to enable local tab subscription
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 TagSubPlugin
25 * @author Brion Vibber <brion@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')) {
36 * TagSub plugin main class
38 * @category TagSubPlugin
40 * @author Brion Vibber <brionv@status.net>
41 * @copyright 2011 StatusNet, Inc.
42 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
43 * @link http://status.net/
45 class TagSubPlugin extends Plugin
47 const VERSION = '0.1';
50 * Database schema setup
54 * @return boolean hook value; true means continue processing, false means stop.
56 function onCheckSchema()
58 $schema = Schema::get();
59 $schema->ensureTable('tagsub', TagSub::schemaDef());
64 * Load related modules when needed
66 * @param string $cls Name of the class to be loaded
68 * @return boolean hook value; true means continue processing, false means stop.
70 function onAutoload($cls)
72 $dir = dirname(__FILE__);
77 include_once $dir.'/'.$cls.'.php';
80 case 'TagunsubAction':
85 include_once $dir.'/'.strtolower($cls).'.php';
95 * @param Net_URL_Mapper $m path-to-action mapper
97 * @return boolean hook value; true means continue processing, false means stop.
99 function onRouterInitialized($m)
101 $m->connect('tag/:tag/subscribe',
102 array('action' => 'tagsub'),
103 array('tag' => Router::REGEX_TAG));
104 $m->connect('tag/:tag/unsubscribe',
105 array('action' => 'tagunsub'),
106 array('tag' => Router::REGEX_TAG));
108 $m->connect(':nickname/tag-subscriptions',
109 array('action' => 'tagsubs'),
110 array('nickname' => Nickname::DISPLAY_FMT));
115 * Plugin version data
117 * @param array &$versions array of version data
121 function onPluginVersion(&$versions)
123 $versions[] = array('name' => 'TagSub',
124 'version' => self::VERSION,
125 'author' => 'Brion Vibber',
126 'homepage' => 'http://status.net/wiki/Plugin:TagSub',
128 // TRANS: Plugin description.
129 _m('Plugin to allow following all messages with a given tag.'));
134 * Hook inbox delivery setup so tag subscribers receive all
135 * notices with that tag in their inbox.
137 * Currently makes no distinction between local messages and
138 * remote ones which happen to come in to the system. Remote
139 * notices that don't come in at all won't ever reach this.
141 * @param Notice $notice
142 * @param array $ni in/out map of profile IDs to inbox constants
143 * @return boolean hook result
145 function onStartNoticeWhoGets(Notice $notice, array &$ni)
147 foreach ($notice->getTags() as $tag) {
148 $tagsub = new TagSub();
152 while ($tagsub->fetch()) {
153 // These constants are currently not actually used, iirc
154 $ni[$tagsub->profile_id] = NOTICE_INBOX_SOURCE_SUB;
162 * @param TagAction $action
163 * @return boolean hook result
165 function onStartTagShowContent(TagAction $action)
167 $user = common_current_user();
169 $tag = $action->trimmed('tag');
170 $tagsub = TagSub::pkeyGet(array('tag' => $tag,
171 'profile_id' => $user->id));
173 $form = new TagUnsubForm($action, $tag);
175 $form = new TagSubForm($action, $tag);
177 $action->elementStart('div', 'entity_actions');
178 $action->elementStart('ul');
179 $action->elementStart('li', 'entity_subscribe');
181 $action->elementEnd('li');
182 $action->elementEnd('ul');
183 $action->elementEnd('div');
189 * Menu item for personal subscriptions/groups area
191 * @param Widget $widget Widget being executed
193 * @return boolean hook return
196 function onEndSubGroupNav($widget)
198 $action = $widget->out;
199 $action_name = $action->trimmed('action');
201 $action->menuItem(common_local_url('tagsubs', array('nickname' => $action->user->nickname)),
202 // TRANS: SubMirror plugin menu item on user settings page.
204 // TRANS: SubMirror plugin tooltip for user settings menu item.
205 _m('Configure tag subscriptions'),
206 $action_name == 'tagsubs' && $action->arg('nickname') == $action->user->nickname);
212 * Add a count of mirrored feeds into a user's profile sidebar stats.
214 * @param Profile $profile
215 * @param array $stats
216 * @return boolean hook return value
218 function onProfileStats($profile, &$stats)
220 $cur = common_current_user();
221 if (!empty($cur) && $cur->id == $profile->id) {
222 $tagsub = new TagSub();
223 $tagsub->profile_id = $profile->id;
226 'label' => _m('Tag subscriptions'),
227 'link' => common_local_url('tagsubs', array('nickname' => $profile->nickname)),
228 'value' => $tagsub->count(),
231 $insertAt = count($stats);
232 foreach ($stats as $i => $row) {
233 if ($row['id'] == 'groups') {
234 // Slip us in after them.
239 array_splice($stats, $insertAt, 0, array($entry));
244 function onEndDefaultLocalNav($menu, $user)
246 $user = common_current_user();
248 $tags = TagSub::forProfile($user->getProfile());
251 $tagSubMenu = new TagSubMenu($menu->out, $user, $tags);
252 $menu->submenu(_m('Tags'), $tagSubMenu);