. * * @category Widget * @package StatusNet * @author Zach Copley * @copyright 2011 StatusNet, Inc. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 * @link http://status.net/ */ if (!defined('STATUSNET') && !defined('LACONICA')) { exit(1); } /** * Outputs a fancy alphabet letter navigation menu * * @category Widget * @package StatusNet * @author Zach Copley * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 * @link http://status.net/ * * @see HTMLOutputter */ class AlphaNav extends Widget { protected $action = null; protected $filters = array(); /** * Prepare the widget for use * * @param Action $action the current action * @param boolean $numbers whether to output 0..9 * @param Array $prepend array of filters to prepend * @param Array $append array of filters to append */ function __construct( $action = null, $numbers = false, $prepend = false, $append = false ) { parent::__construct($action); $this->action = $action; if ($prepend) { $this->filters = array_merge($prepend, $this->filters); } if ($numbers) { $this->filters = array_merge($this->filters, range(0, 9)); } if ($append) { $this->filters = array_merge($this->filters, $append); } $this->filters = array_merge($this->filters, range('A', 'Z')); } /** * Show the widget * * Emit the HTML for the widget, using the configured outputter. * * @return void */ function show() { $actionName = $this->action->trimmed('action'); $this->action->elementStart('div', array('class' => 'alpha_nav')); for ($i = 0, $size = sizeof($this->filters); $i < $size; $i++) { $filter = $this->filters[$i]; $classes = ''; // Add some classes for styling if ($i == 0) { $classes .= 'first '; // first filter in the list } elseif ($i == $size - 1) { $classes .= 'last '; // last filter in the list } $href = common_local_url( $actionName, array('filter' => strtolower($filter)) ); $params = array('href' => $href); $current = $this->action->arg('filter'); // Highlight the selected filter. If there is no selected // filter, highlight the first filter in the list if (empty($current) && $i == 0 || $current === strtolower($filter)) { $classes .= 'current '; } if (!empty($classes)) { $params['class'] = trim($classes); } $this->action->element('a', $params, $filter); } $this->action->elementEnd('div'); } }