3 * StatusNet - the distributed open-source microblogging tool
4 * Copyright (C) 2011, StatusNet, Inc.
6 * Adds a user directory
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 Zach Copely <zach@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 * Directory plugin main class
40 * @author Zach Copley <zach@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 DirectoryPlugin extends Plugin
50 * Initializer for this plugin
52 * @return boolean hook value; true means continue processing,
61 * Cleanup for this plugin.
63 * @return boolean hook value; true means continue processing,
72 * Load related modules when needed
74 * @param string $cls Name of the class to be loaded
76 * @return boolean hook value; true means continue processing,
79 function onAutoload($cls)
81 // common_debug("class = $cls");
83 $dir = dirname(__FILE__);
87 case 'UserdirectoryAction':
88 case 'GroupdirectoryAction':
90 . '/actions/' . strtolower(mb_substr($cls, 0, -6)) . '.php';
94 . '/lib/' . strtolower($cls) . '.php';
96 case 'SortableSubscriptionList':
97 case 'SortableGroupList':
99 . '/lib/' . strtolower($cls) . '.php';
107 * Map URLs to actions
109 * @param Net_URL_Mapper $m path-to-action mapper
111 * @return boolean hook value; true means continue processing,
114 function onRouterInitialized($m)
119 array('action' => 'userdirectory'),
120 array('filter' => 'all')
124 'directory/users/:filter',
125 array('action' => 'userdirectory'),
126 array('filter' => '([0-9a-zA-Z_]{1,64}|0-9)')
131 array('action' => 'groupdirectory'),
132 array('filter' => '([0-9a-zA-Z_]{1,64}|0-9)')
137 array('action' => 'groupdirectory')
144 * Hijack the routing (URL -> Action) for the normal directory page
145 * and substitute our group directory action
147 * @param string $path path to connect
148 * @param array $defaults path defaults
149 * @param array $rules path rules
150 * @param array $result unused
152 * @return boolean hook return
154 function onStartConnectPath(&$path, &$defaults, &$rules, &$result)
156 if (in_array($path, array('group', 'group/', 'groups', 'groups/'))) {
157 $defaults['action'] = 'groupdirectory';
163 // The following three function are to replace the existing groups
164 // list page with the directory plugin's group directory page
167 * Hijack the mapping (Action -> URL) and return the URL to our
168 * group directory page instead of the normal groups page
170 * @param Action $action action to find a path for
171 * @param array $params parameters to pass to the action
172 * @param string $fragment any url fragement
173 * @param boolean $addSession whether to add session variable
174 * @param string $url resulting URL to local resource
176 * @return string the local URL
178 function onEndLocalURL(&$action, &$params, &$fragment, &$addSession, &$url) {
179 if (in_array($action, array('group', 'group/', 'groups', 'groups/'))) {
180 $url = common_local_url('groupdirectory');
186 * Link in a styelsheet for the onboarding actions
188 * @param Action $action Action being shown
190 * @return boolean hook flag
192 function onEndShowStatusNetStyles($action)
195 $action->trimmed('action'),
196 array('userdirectory', 'groupdirectory'))
198 $action->cssLink($this->path('css/directory.css'));
205 * Fool the public nav into thinking it's on the regular
206 * group page when it's actually on our injected group
207 * directory page. This way "Groups" gets hilighted when
208 * when we're on the groups directory page.
210 * @param type $action the current action
212 * @return boolean hook flag
214 function onStartPublicGroupNav($action)
216 if ($action->trimmed('action') == 'groupdirectory') {
217 $action->actionName = 'groups';
223 * Modify the public local nav to add a link to the user directory
225 * @param Action $action The current action handler. Use this to
228 * @return boolean hook value; true means continue processing,
233 function onEndPublicGroupNav($nav)
235 // XXX: Maybe this should go under search instead?
237 $actionName = $nav->action->trimmed('action');
240 common_local_url('userdirectory'),
241 // TRANS: Menu item text for user directory.
242 _m('MENU','Directory'),
243 // TRANS: Menu item title for user directory.
244 _m('User Directory.'),
245 $actionName == 'userdirectory',
255 function onPluginVersion(&$versions)
258 'name' => 'Directory',
259 'version' => STATUSNET_VERSION,
260 'author' => 'Zach Copley',
261 'homepage' => 'http://status.net/wiki/Plugin:Directory',
262 // TRANS: Plugin description.
263 'rawdescription' => _m('Add a user directory.')