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));
79 $this->filters = array_merge($this->filters, $append);
82 $this->filters = array_merge($this->filters, range('A', 'Z'));
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 $href = common_local_url(
113 array('filter' => strtolower($filter))
116 $params = array('href' => $href);
119 if (!empty($this->action->sort)) {
120 $params['sort'] = $this->action->sort;
124 if (!empty($this->action->order)) {
125 $params['asc'] = 'true';
128 $current = $this->action->arg('filter');
130 // Highlight the selected filter. If there is no selected
131 // filter, highlight the first filter in the list
132 if (!isset($current) && $i == 0
133 || $current === strtolower($filter)) {
134 $classes .= 'current ';
137 if (!empty($classes)) {
138 $params['class'] = trim($classes);
141 $this->action->element('a', $params, $filter);
144 $this->action->elementEnd('div');