123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150 |
- <?php
- if (!defined('STATUSNET')) {
- exit(1);
- }
- class AlphaNav extends Widget
- {
- protected $action = null;
- protected $filters = array();
-
- 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));
- }
- $this->filters = array_merge($this->filters, range('A', 'Z'));
- if ($append) {
- $this->filters = array_merge($this->filters, $append);
- }
- }
-
- 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 = '';
-
- if ($i == 0) {
- $classes .= 'first ';
- } elseif ($i == $size - 1) {
- $classes .= 'last ';
- }
-
- if (strtolower($filter) == 'all') {
- $href = common_local_url($actionName);
- } else {
- $href = common_local_url(
- $actionName,
- array('filter' => strtolower($filter))
- );
- }
- $params = array('href' => $href);
-
- if (!empty($this->action->sort)) {
- $params['sort'] = $this->action->sort;
- }
-
- if ($this->action->reverse) {
- $params['reverse'] = 'true';
- }
- $current = $this->action->arg('filter');
-
-
- if (!isset($current) && $i == ($size - 1)
- || $current === strtolower($filter)) {
- $classes .= 'current ';
- }
- if (!empty($classes)) {
- $params['class'] = trim($classes);
- }
- $this->action->element('a', $params, $filter);
- }
- $this->action->elementEnd('div');
- }
- }
|