]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/Directory/DirectoryPlugin.php
e38229dd21ce52ab2c174a5fa375f8c996c62905
[quix0rs-gnu-social.git] / plugins / Directory / DirectoryPlugin.php
1 <?php
2 /**
3  * StatusNet - the distributed open-source microblogging tool
4  * Copyright (C) 2011, StatusNet, Inc.
5  *
6  * Adds a user directory
7  *
8  * PHP version 5
9  *
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.
14  *
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.
19  *
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/>.
22  *
23  * @category  Plugin
24  * @package   StatusNet
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/
29  */
30
31 if (!defined('STATUSNET')) {
32     exit(1);
33 }
34
35 /**
36  * Directory plugin main class
37  *
38  * @category  Plugin
39  * @package   StatusNet
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/
44  */
45 class DirectoryPlugin extends Plugin
46 {
47     private $dir = null;
48
49     /**
50      * Initializer for this plugin
51      *
52      * @return boolean hook value; true means continue processing,
53      *         false means stop.
54      */
55     function initialize()
56     {
57         return true;
58     }
59
60     /**
61      * Cleanup for this plugin.
62      *
63      * @return boolean hook value; true means continue processing,
64      *         false means stop.
65      */
66     function cleanup()
67     {
68         return true;
69     }
70
71     /**
72      * Map URLs to actions
73      *
74      * @param Net_URL_Mapper $m path-to-action mapper
75      *
76      * @return boolean hook value; true means continue processing,
77      *         false means stop.
78      */
79     function onRouterInitialized($m)
80     {
81
82         $m->connect(
83             'directory/users/:filter',
84             array('action' => 'userdirectory'),
85             array('filter' => '[0-9a-zA-Z]|(0-9)')
86         );
87
88         $m->connect(
89             'directory/users',
90             array('action' => 'userdirectory')
91         );
92
93         $m->connect(
94             'groups/:filter',
95             array('action' => 'groupdirectory'),
96             array('filter' => '[0-9a-zA-Z]|(0-9)')
97         );
98
99         $m->connect(
100             'groups',
101             array('action' => 'groupdirectory')
102         );
103
104         return true;
105     }
106
107     /**
108      * Hijack the routing (URL -> Action) for the normal directory page
109      * and substitute our group directory action
110      *
111      * @param string $path     path to connect
112      * @param array  $defaults path defaults
113      * @param array  $rules    path rules
114      * @param array  $result   unused
115      *
116      * @return boolean hook return
117      */
118     function onStartConnectPath(&$path, &$defaults, &$rules, &$result)
119     {
120         if (in_array($path, array('group', 'group/', 'groups', 'groups/'))) {
121             $defaults['action'] = 'groupdirectory';
122             return true;
123         }
124         return true;
125     }
126
127     // The following three function are to replace the existing groups
128     // list page with the directory plugin's group directory page
129
130     /**
131      * Hijack the mapping (Action -> URL) and return the URL to our
132      * group directory page instead of the normal groups page
133      *
134      * @param Action    $action     action to find a path for
135      * @param array     $params     parameters to pass to the action
136      * @param string    $fragment   any url fragement
137      * @param boolean   $addSession whether to add session variable
138      * @param string    $url        resulting URL to local resource
139      *
140      * @return string the local URL
141      */
142     function onEndLocalURL(&$action, &$params, &$fragment, &$addSession, &$url) {
143         if (in_array($action, array('group', 'group/', 'groups', 'groups/'))) {
144                 $url = common_local_url('groupdirectory');
145         }
146         return true;
147     }
148
149     /**
150      * Link in a styelsheet for the onboarding actions
151      *
152      * @param Action $action Action being shown
153      *
154      * @return boolean hook flag
155      */
156     public function onEndShowStylesheets(Action $action)
157     {
158         if (in_array(
159             $action->trimmed('action'),
160             array('userdirectory', 'groupdirectory'))
161         ) {
162             $action->cssLink($this->path('css/directory.css'));
163         }
164
165         return true;
166     }
167
168     /**
169      * Fool the public nav into thinking it's on the regular
170      * group page when it's actually on our injected group
171      * directory page. This way "Groups" gets hilighted when
172      * when we're on the groups directory page.
173      *
174      * @param type $action the current action
175      *
176      * @return boolean hook flag
177      */
178     function onStartPublicGroupNav($action)
179     {
180         if ($action->trimmed('action') == 'groupdirectory') {
181             $action->actionName = 'groups';
182         }
183         return true;
184     }
185
186     /**
187      * Modify the public local nav to add a link to the user directory
188      *
189      * @param Action $action The current action handler. Use this to
190      *                       do any output.
191      *
192      * @return boolean hook value; true means continue processing,
193      *         false means stop.
194      *
195      * @see Action
196      */
197     function onEndPublicGroupNav($nav)
198     {
199         // XXX: Maybe this should go under search instead?
200
201         $actionName = $nav->action->trimmed('action');
202
203         $nav->out->menuItem(
204             common_local_url('userdirectory'),
205             // TRANS: Menu item text for user directory.
206             _m('MENU','Directory'),
207             // TRANS: Menu item title for user directory.
208             _m('User Directory.'),
209             $actionName == 'userdirectory',
210             'nav_directory'
211         );
212
213         return true;
214     }
215
216     /*
217      * Version info
218      */
219     function onPluginVersion(array &$versions)
220     {
221         $versions[] = array(
222             'name' => 'Directory',
223             'version' => GNUSOCIAL_VERSION,
224             'author' => 'Zach Copley',
225             'homepage' => 'http://status.net/wiki/Plugin:Directory',
226             // TRANS: Plugin description.
227             'rawdescription' => _m('Add a user directory.')
228         );
229
230         return true;
231     }
232 }