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,
74 * @param URLMapper $m path-to-action mapper
76 * @return boolean hook value; true means continue processing,
79 public function onRouterInitialized(URLMapper $m)
83 'directory/users/:filter/sort_by/:sort/reverse/:reverse',
84 array('action' => 'userdirectory'),
85 array('filter' => '[0-9a-zA-Z]|(0-9)'),
86 array('sort' => '[a-z]+'),
87 array('reverse' => '[0-9]')
91 'directory/users/:filter/sort_by/:sort',
92 array('action' => 'userdirectory'),
93 array('filter' => '[0-9a-zA-Z]|(0-9)'),
94 array('sort' => '[a-z]+')
98 'directory/users/:filter',
99 array('action' => 'userdirectory'),
100 array('filter' => '[0-9a-zA-Z]|(0-9)')
104 'directory/users/sort_by/:sort/reverse/:reverse',
105 array('action' => 'userdirectory'),
106 array('sort' => '[a-z]+'),
107 array('reverse' => '[0-9]')
111 'directory/users/sort_by/:sort',
112 array('action' => 'userdirectory'),
113 array('sort' => '[a-z]+')
118 array('action' => 'userdirectory')
123 array('action' => 'groupdirectory'),
124 array('filter' => '[0-9a-zA-Z]|(0-9)')
129 array('action' => 'groupdirectory')
134 array('action' => 'groupdirectory')
141 * Hijack the routing (URL -> Action) for the normal directory page
142 * and substitute our group directory action
144 * @param string $path path to connect
145 * @param array $defaults path defaults
146 * @param array $rules path rules
147 * @param array $result unused
149 * @return boolean hook return
151 function onStartConnectPath(&$path, &$defaults, &$rules, &$result)
153 if (in_array($path, array('group', 'group/', 'groups', 'groups/'))) {
154 $defaults['action'] = 'groupdirectory';
160 // The following three function are to replace the existing groups
161 // list page with the directory plugin's group directory page
164 * Hijack the mapping (Action -> URL) and return the URL to our
165 * group directory page instead of the normal groups page
167 * @param Action $action action to find a path for
168 * @param array $params parameters to pass to the action
169 * @param string $fragment any url fragement
170 * @param boolean $addSession whether to add session variable
171 * @param string $url resulting URL to local resource
173 * @return string the local URL
175 function onEndLocalURL(&$action, &$params, &$fragment, &$addSession, &$url) {
176 if (in_array($action, array('group', 'group/', 'groups', 'groups/'))) {
177 $url = common_local_url('groupdirectory');
183 * Link in a styelsheet for the onboarding actions
185 * @param Action $action Action being shown
187 * @return boolean hook flag
189 public function onEndShowStylesheets(Action $action)
192 $action->trimmed('action'),
193 array('userdirectory', 'groupdirectory'))
195 $action->cssLink($this->path('css/directory.css'));
202 * Fool the public nav into thinking it's on the regular
203 * group page when it's actually on our injected group
204 * directory page. This way "Groups" gets hilighted when
205 * when we're on the groups directory page.
207 * @param type $action the current action
209 * @return boolean hook flag
211 function onStartPublicGroupNav($action)
213 if ($action->trimmed('action') == 'groupdirectory') {
214 $action->actionName = 'groups';
220 * Modify the public local nav to add a link to the user directory
222 * @param Action $action The current action handler. Use this to
225 * @return boolean hook value; true means continue processing,
230 function onEndPublicGroupNav($nav)
232 // XXX: Maybe this should go under search instead?
234 $actionName = $nav->action->trimmed('action');
237 common_local_url('userdirectory'),
238 // TRANS: Menu item text for user directory.
239 _m('MENU','Directory'),
240 // TRANS: Menu item title for user directory.
241 _m('User Directory.'),
242 $actionName == 'userdirectory',
252 function onPluginVersion(array &$versions)
255 'name' => 'Directory',
256 'version' => GNUSOCIAL_VERSION,
257 'author' => 'Zach Copley',
258 'homepage' => 'http://status.net/wiki/Plugin:Directory',
259 // TRANS: Plugin description.
260 'rawdescription' => _m('Add a user directory.')