]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/Directory/DirectoryPlugin.php
* Fix pagination
[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
48     private $dir = null;
49
50     /**
51      * Initializer for this plugin
52      *
53      * @return boolean hook value; true means continue processing,
54      *         false means stop.
55      */
56     function initialize()
57     {
58         $this->dir = dirname(__FILE__);
59         return true;
60     }
61
62     /**
63      * Cleanup for this plugin.
64      *
65      * @return boolean hook value; true means continue processing,
66      *         false means stop.
67      */
68     function cleanup()
69     {
70         return true;
71     }
72
73     /**
74      * Load related modules when needed
75      *
76      * @param string $cls Name of the class to be loaded
77      *
78      * @return boolean hook value; true means continue processing,
79      *         false means stop.
80      */
81     function onAutoload($cls)
82     {
83         // common_debug("class = $cls");
84
85         switch ($cls)
86         {
87         case 'UserdirectoryAction':
88             include_once $this->dir
89                 . '/actions/' . strtolower(mb_substr($cls, 0, -6)) . '.php';
90             return false;
91         case 'AlphaNav':
92             include_once $this->dir
93                 . '/lib/' . strtolower($cls) . '.php';
94             return false;
95         default:
96             return true;
97         }
98     }
99
100     /**
101      * Map URLs to actions
102      *
103      * @param Net_URL_Mapper $m path-to-action mapper
104      *
105      * @return boolean hook value; true means continue processing,
106      *         false means stop.
107      */
108     function onRouterInitialized($m)
109     {
110         $m->connect(
111             'directory/users/:filter',
112             array('action' => 'userdirectory'),
113             array('filter' => '[0-9a-zA-Z_]{1,64}')
114         );
115
116         $m->connect(
117             'directory/users',
118             array('action' => 'userdirectory'),
119             array('filter' => 'all')
120         );
121
122         return true;
123     }
124
125     /**
126      * Link in a styelsheet for the onboarding actions
127      *
128      * @param Action $action Action being shown
129      *
130      * @return boolean hook flag
131      */
132     function onEndShowStatusNetStyles($action)
133     {
134         if (in_array(
135             $action->trimmed('action'),
136             array('userdirectory'))
137         ) {
138             $action->cssLink($this->path('css/directory.css'));
139         }
140
141         return true;
142     }
143
144     /**
145      * Modify the public local nav to add a link to the user directory
146      *
147      * @param Action $action The current action handler. Use this to
148      *                       do any output.
149      *
150      * @return boolean hook value; true means continue processing,
151      *         false means stop.
152      *
153      * @see Action
154      */
155     function onEndPublicGroupNav($nav)
156     {
157         // XXX: Maybe this should go under search instead?
158
159         $actionName = $nav->action->trimmed('action');
160
161         $nav->out->menuItem(
162             common_local_url('userdirectory'),
163             _('Directory'),
164             _('User Directory'),
165             $actionName == 'userdirectory',
166             'nav_directory'
167         );
168
169         return true;
170     }
171
172     /*
173      * Version info
174      */
175     function onPluginVersion(&$versions)
176     {
177         $versions[] = array(
178             'name' => 'Directory',
179             'version' => STATUSNET_VERSION,
180             'author' => 'Zach Copley',
181             'homepage' => 'http://status.net/wiki/Plugin:Directory',
182             'rawdescription' => _m('Add a user directory.')
183         );
184
185         return true;
186     }
187 }