]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/Directory/DirectoryPlugin.php
4fe1eaec9eb6fb9aac50109eb94728aeeb27d7d9
[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             include_once $dir
89                 . '/actions/' . strtolower(mb_substr($cls, 0, -6)) . '.php';
90             return false;
91         case 'AlphaNav':
92             include_once $dir
93                 . '/lib/' . strtolower($cls) . '.php';
94             return false;
95         case 'SortableSubscriptionList':
96             include_once $dir
97                 . '/lib/' . strtolower($cls) . '.php';
98             return false;
99         default:
100             return true;
101         }
102     }
103
104     /**
105      * Map URLs to actions
106      *
107      * @param Net_URL_Mapper $m path-to-action mapper
108      *
109      * @return boolean hook value; true means continue processing,
110      *         false means stop.
111      */
112     function onRouterInitialized($m)
113     {
114         $m->connect(
115             'directory/users',
116             array('action' => 'userdirectory'),
117             array('filter' => 'all')
118         );
119
120         $m->connect(
121             'directory/users/:filter',
122             array('action' => 'userdirectory'),
123             array('filter' => '([0-9a-zA-Z_]{1,64}|0-9)')
124         );
125
126         return true;
127     }
128
129     /**
130      * Link in a styelsheet for the onboarding actions
131      *
132      * @param Action $action Action being shown
133      *
134      * @return boolean hook flag
135      */
136     function onEndShowStatusNetStyles($action)
137     {
138         if (in_array(
139             $action->trimmed('action'),
140             array('userdirectory'))
141         ) {
142             $action->cssLink($this->path('css/directory.css'));
143         }
144
145         return true;
146     }
147
148     /**
149      * Modify the public local nav to add a link to the user directory
150      *
151      * @param Action $action The current action handler. Use this to
152      *                       do any output.
153      *
154      * @return boolean hook value; true means continue processing,
155      *         false means stop.
156      *
157      * @see Action
158      */
159     function onEndPublicGroupNav($nav)
160     {
161         // XXX: Maybe this should go under search instead?
162
163         $actionName = $nav->action->trimmed('action');
164
165         $nav->out->menuItem(
166             common_local_url('userdirectory'),
167             // TRANS: Menu item text for user directory.
168             _m('MENU','Directory'),
169             // TRANS: Menu item title for user directory.
170             _m('User Directory.'),
171             $actionName == 'userdirectory',
172             'nav_directory'
173         );
174
175         return true;
176     }
177
178     /*
179      * Version info
180      */
181     function onPluginVersion(&$versions)
182     {
183         $versions[] = array(
184             'name' => 'Directory',
185             'version' => STATUSNET_VERSION,
186             'author' => 'Zach Copley',
187             'homepage' => 'http://status.net/wiki/Plugin:Directory',
188             // TRANS: Plugin description.
189             'rawdescription' => _m('Add a user directory.')
190         );
191
192         return true;
193     }
194 }