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