]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/Directory/DirectoryPlugin.php
DirectoryPlugin - Group directory mostly working. HTML markup for results needs fixing.
[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      * Load related modules when needed
73      *
74      * @param string $cls Name of the class to be loaded
75      *
76      * @return boolean hook value; true means continue processing,
77      *         false means stop.
78      */
79     function onAutoload($cls)
80     {
81         // common_debug("class = $cls");
82
83         $dir = dirname(__FILE__);
84
85         switch ($cls)
86         {
87         case 'UserdirectoryAction':
88         case 'GroupdirectoryAction':
89             include_once $dir
90                 . '/actions/' . strtolower(mb_substr($cls, 0, -6)) . '.php';
91             return false;
92         case 'AlphaNav':
93             include_once $dir
94                 . '/lib/' . strtolower($cls) . '.php';
95             return false;
96         case 'SortableSubscriptionList':
97         case 'SortableGroupList':
98             include_once $dir
99                 . '/lib/' . strtolower($cls) . '.php';
100             return false;
101         default:
102             return true;
103         }
104     }
105
106     /**
107      * Map URLs to actions
108      *
109      * @param Net_URL_Mapper $m path-to-action mapper
110      *
111      * @return boolean hook value; true means continue processing,
112      *         false means stop.
113      */
114     function onRouterInitialized($m)
115     {
116
117         $m->connect(
118             'directory/users',
119             array('action' => 'userdirectory'),
120             array('filter' => 'all')
121         );
122
123         $m->connect(
124             'directory/users/:filter',
125             array('action' => 'userdirectory'),
126             array('filter' => '([0-9a-zA-Z_]{1,64}|0-9)')
127         );
128
129         $m->connect(
130             'groups/:filter',
131             array('action' => 'groupdirectory'),
132             array('filter' => '([0-9a-zA-Z_]{1,64}|0-9)')
133         );
134
135         return true;
136     }
137
138     /**
139      * Hijack the routing (URL -> Action) for the normal directory page
140      * and substitute our group directory action
141      *
142      * @param string $path     path to connect
143      * @param array  $defaults path defaults
144      * @param array  $rules    path rules
145      * @param array  $result   unused
146      *
147      * @return boolean hook return
148      */
149     function onStartConnectPath(&$path, &$defaults, &$rules, &$result)
150     {
151         if (in_array($path, array('group', 'group/', 'groups', 'groups/'))) {
152             $defaults['action'] = 'groupdirectory';
153             return true;
154         }
155         return true;
156     }
157
158     /**
159      * Hijack the mapping (Action -> URL) and return the URL to our
160      * group directory page instead of the normal groups page
161      *
162      * @param Action    $action     action to find a path for
163      * @param array     $params     parameters to pass to the action
164      * @param string    $fragment   any url fragement
165      * @param boolean   $addSession whether to add session variable
166      * @param string    $url        resulting URL to local resource
167      *
168      * @return string the local URL
169      */
170     function onEndLocalURL(&$action, &$params, &$fragment, &$addSession, &$url) {
171         if (in_array($action, array('group', 'group/', 'groups', 'groups/'))) {
172                 $url = common_local_url('groupdirectory');
173         }
174         return true;
175     }
176
177     /**
178      * Link in a styelsheet for the onboarding actions
179      *
180      * @param Action $action Action being shown
181      *
182      * @return boolean hook flag
183      */
184     function onEndShowStatusNetStyles($action)
185     {
186         if (in_array(
187             $action->trimmed('action'),
188             array('userdirectory'))
189         ) {
190             $action->cssLink($this->path('css/directory.css'));
191         }
192
193         return true;
194     }
195
196     /**
197      * Modify the public local nav to add a link to the user directory
198      *
199      * @param Action $action The current action handler. Use this to
200      *                       do any output.
201      *
202      * @return boolean hook value; true means continue processing,
203      *         false means stop.
204      *
205      * @see Action
206      */
207     function onEndPublicGroupNav($nav)
208     {
209         // XXX: Maybe this should go under search instead?
210
211         $actionName = $nav->action->trimmed('action');
212
213         $nav->out->menuItem(
214             common_local_url('userdirectory'),
215             // TRANS: Menu item text for user directory.
216             _m('MENU','Directory'),
217             // TRANS: Menu item title for user directory.
218             _m('User Directory.'),
219             $actionName == 'userdirectory',
220             'nav_directory'
221         );
222
223         return true;
224     }
225
226     /*
227      * Version info
228      */
229     function onPluginVersion(&$versions)
230     {
231         $versions[] = array(
232             'name' => 'Directory',
233             'version' => STATUSNET_VERSION,
234             'author' => 'Zach Copley',
235             'homepage' => 'http://status.net/wiki/Plugin:Directory',
236             // TRANS: Plugin description.
237             'rawdescription' => _m('Add a user directory.')
238         );
239
240         return true;
241     }
242 }