3 * StatusNet, the distributed open-source microblogging tool
5 * Widget to display an alphabet menu
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.
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.
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/>.
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/
30 if (!defined('STATUSNET')) {
35 * Outputs a fancy alphabet letter navigation menu
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/
46 class AlphaNav extends Widget
48 protected $action = null;
49 protected $filters = array();
52 * Prepare the widget for use
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
66 parent::__construct($action);
68 $this->action = $action;
71 $this->filters = array_merge($prepend, $this->filters);
75 $this->filters = array_merge($this->filters, range(0, 9));
78 $this->filters = array_merge($this->filters, range('A', 'Z'));
81 $this->filters = array_merge($this->filters, $append);
88 * Emit the HTML for the widget, using the configured outputter.
95 $actionName = $this->action->trimmed('action');
97 $this->action->elementStart('div', array('class' => 'alpha_nav'));
99 for ($i = 0, $size = sizeof($this->filters); $i < $size; $i++) {
101 $filter = $this->filters[$i];
104 // Add some classes for styling
106 $classes .= 'first '; // first filter in the list
107 } elseif ($i == $size - 1) {
108 $classes .= 'last '; // last filter in the list
111 // hack to get around $m->connect(array('action' => 'all, 'nickname' => $nickname));
112 if (strtolower($filter) == 'all') {
113 $href = common_local_url($actionName);
115 $href = common_local_url(
117 array('filter' => strtolower($filter))
121 $params = array('href' => $href);
124 if (!empty($this->action->sort)) {
125 $params['sort'] = $this->action->sort;
129 if ($this->action->reverse) {
130 $params['reverse'] = 'true';
133 $current = $this->action->arg('filter');
135 // Highlight the selected filter. If there is no selected
136 // filter, highlight the last filter in the list (all)
137 if (!isset($current) && $i == ($size - 1)
138 || $current === strtolower($filter)) {
139 $classes .= 'current ';
142 if (!empty($classes)) {
143 $params['class'] = trim($classes);
146 $this->action->element('a', $params, $filter);
149 $this->action->elementEnd('div');