]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/Directory/lib/alphanav.php
* Fix pagination
[quix0rs-gnu-social.git] / plugins / Directory / lib / alphanav.php
1 <?php
2 /**
3  * StatusNet, the distributed open-source microblogging tool
4  *
5  * Widget to display an alphabet menu
6  *
7  * PHP version 5
8  *
9  * LICENCE: This program is free software: you can redistribute it and/or modify
10  * it under the terms of the GNU Affero General Public License as published by
11  * the Free Software Foundation, either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU Affero General Public License for more details.
18  *
19  * You should have received a copy of the GNU Affero General Public License
20  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
21  *
22  * @category  Widget
23  * @package   StatusNet
24  * @author    Zach Copley <zach@status.net>
25  * @copyright 2011 StatusNet, Inc.
26  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
27  * @link      http://status.net/
28  */
29
30 if (!defined('STATUSNET') && !defined('LACONICA')) {
31     exit(1);
32 }
33
34 /**
35  * Outputs a fancy alphabet letter navigation menu
36  *
37  * @category Widget
38  * @package  StatusNet
39  * @author   Zach Copley <zach@status.net>
40  * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
41  * @link     http://status.net/
42  *
43  * @see      HTMLOutputter
44  */
45
46 class AlphaNav extends Widget
47 {
48     protected $action  = null;
49     protected $filters = array();
50
51     /**
52      * Prepare the widget for use
53      *
54      * @param Action  $action  the current action
55      * @param boolean $numbers whether to output 0..9
56      * @param Array   $prepend array of filters to prepend
57      * @param Array   $append  array of filters to append
58      */
59     function __construct(
60             $action  = null,
61             $numbers = false,
62             $prepend = false,
63             $append  = false
64     )
65     {
66         parent::__construct($action);
67
68         $this->action  = $action;
69
70         if ($prepend) {
71             $this->filters = array_merge($prepend, $this->filters);
72         }
73
74         if ($numbers) {
75             $this->filters = array_merge($this->filters, range(0, 9));
76         }
77
78         if ($append) {
79             $this->filters = array_merge($this->filters, $append);
80         }
81
82         $this->filters = array_merge($this->filters, range('A', 'Z'));
83     }
84
85     /**
86      * Show the widget
87      *
88      * Emit the HTML for the widget, using the configured outputter.
89      *
90      * @return void
91      */
92
93     function show()
94     {
95         $actionName = $this->action->trimmed('action');
96
97         $this->action->elementStart('div', array('class' => 'alpha_nav'));
98
99         for ($i = 0, $size = sizeof($this->filters); $i < $size; $i++) {
100
101             $filter = $this->filters[$i];
102             $classes = '';
103
104             // Add some classes for styling
105             if ($i == 0) {
106                 $classes .= 'first '; // first filter in the list
107             } elseif ($i == $size - 1) {
108                 $classes .= 'last ';  // last filter in the list
109             }
110
111             $href = common_local_url(
112                 $actionName,
113                 array('filter' => strtolower($filter))
114             );
115
116             $params  = array('href' => $href);
117             $current = $this->action->arg('filter');
118
119             // Highlight the selected filter. If there is no selected
120             // filter, highlight the first filter in the list
121             if (empty($current) && $i == 0
122                 || $current === strtolower($filter)) {
123                 $classes .= 'current ';
124             }
125
126             if (!empty($classes)) {
127                 $params['class'] = trim($classes);
128             }
129
130             $this->action->element('a', $params, $filter);
131         }
132
133         $this->action->elementEnd('div');
134     }
135
136 }