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/
45 class AlphaNav extends Widget
47 protected $action = null;
48 protected $filters = array();
51 * Prepare the widget for use
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
65 parent::__construct($action);
67 $this->action = $action;
70 $this->filters = array_merge($prepend, $this->filters);
74 $this->filters = array_merge($this->filters, range(0, 9));
77 $this->filters = array_merge($this->filters, range('A', 'Z'));
80 $this->filters = array_merge($this->filters, $append);
87 * Emit the HTML for the widget, using the configured outputter.
93 $actionName = $this->action->trimmed('action');
95 $this->action->elementStart('div', array('class' => 'alpha_nav'));
97 for ($i = 0, $size = sizeof($this->filters); $i < $size; $i++) {
99 $filter = $this->filters[$i];
102 // Add some classes for styling
104 $classes .= 'first '; // first filter in the list
105 } elseif ($i == $size - 1) {
106 $classes .= 'last '; // last filter in the list
109 // hack to get around $m->connect(array('action' => 'all, 'nickname' => $nickname));
110 if (strtolower($filter) == 'all') {
111 $href = common_local_url($actionName);
113 $href = common_local_url(
115 array('filter' => strtolower($filter))
119 $params = array('href' => $href);
122 if (!empty($this->action->sort)) {
123 $params['sort'] = $this->action->sort;
127 if ($this->action->reverse) {
128 $params['reverse'] = 'true';
131 $current = $this->action->arg('filter');
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 ';
140 if (!empty($classes)) {
141 $params['class'] = trim($classes);
144 $this->action->element('a', $params, $filter);
147 $this->action->elementEnd('div');