]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/Directory/lib/alphanav.php
Introduced common_location_shared() to check if location sharing is always,
[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')) {
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 class AlphaNav extends Widget
46 {
47     protected $action  = null;
48     protected $filters = array();
49
50     /**
51      * Prepare the widget for use
52      *
53      * @param Action  $action  the current action
54      * @param boolean $numbers whether to output 0..9
55      * @param Array   $prepend array of filters to prepend
56      * @param Array   $append  array of filters to append
57      */
58     function __construct(
59             $action  = null,
60             $numbers = false,
61             $prepend = false,
62             $append  = false
63     )
64     {
65         parent::__construct($action);
66
67         $this->action  = $action;
68
69         if ($prepend) {
70             $this->filters = array_merge($prepend, $this->filters);
71         }
72
73         if ($numbers) {
74             $this->filters = array_merge($this->filters, range(0, 9));
75         }
76
77         $this->filters = array_merge($this->filters, range('A', 'Z'));
78
79         if ($append) {
80             $this->filters = array_merge($this->filters, $append);
81         }
82     }
83
84     /**
85      * Show the widget
86      *
87      * Emit the HTML for the widget, using the configured outputter.
88      *
89      * @return void
90      */
91     function show()
92     {
93         $actionName = $this->action->trimmed('action');
94
95         $this->action->elementStart('div', array('class' => 'alpha_nav'));
96
97         for ($i = 0, $size = sizeof($this->filters); $i < $size; $i++) {
98
99             $filter = $this->filters[$i];
100             $classes = '';
101
102             // Add some classes for styling
103             if ($i == 0) {
104                 $classes .= 'first '; // first filter in the list
105             } elseif ($i == $size - 1) {
106                 $classes .= 'last ';  // last filter in the list
107             }
108
109             // hack to get around $m->connect(array('action' => 'all, 'nickname' => $nickname));
110             if (strtolower($filter) == 'all') {
111                 $href = common_local_url($actionName);
112             } else {
113                 $href = common_local_url(
114                     $actionName,
115                     array('filter' => strtolower($filter))
116                 );
117             }
118
119             $params  = array('href' => $href);
120
121             // sort column
122             if (!empty($this->action->sort)) {
123                 $params['sort'] = $this->action->sort;
124             }
125
126             // sort order
127             if ($this->action->reverse) {
128                 $params['reverse'] = 'true';
129             }
130
131             $current = $this->action->arg('filter');
132
133             // Highlight the selected filter. If there is no selected
134             // filter, highlight the last filter in the list (all)
135             if (!isset($current) && $i == ($size - 1)
136                 || $current === strtolower($filter)) {
137                 $classes .= 'current ';
138             }
139
140             if (!empty($classes)) {
141                 $params['class'] = trim($classes);
142             }
143
144             $this->action->element('a', $params, $filter);
145         }
146
147         $this->action->elementEnd('div');
148     }
149 }