alphanav.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. <?php
  2. /**
  3. * StatusNet, the distributed open-source microblogging tool
  4. *
  5. * Widget to display an alphabet menu
  6. *
  7. * PHP version 5
  8. *
  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.
  13. *
  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.
  18. *
  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/>.
  21. *
  22. * @category Widget
  23. * @package StatusNet
  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/
  28. */
  29. if (!defined('STATUSNET')) {
  30. exit(1);
  31. }
  32. /**
  33. * Outputs a fancy alphabet letter navigation menu
  34. *
  35. * @category Widget
  36. * @package StatusNet
  37. * @author Zach Copley <zach@status.net>
  38. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
  39. * @link http://status.net/
  40. *
  41. * @see HTMLOutputter
  42. */
  43. class AlphaNav extends Widget
  44. {
  45. public $widgetOpts;
  46. public $scoped;
  47. protected $action = null;
  48. protected $filters = array();
  49. /**
  50. * Prepare the widget for use
  51. *
  52. * @param Action $action the current action
  53. * @param boolean $numbers whether to output 0..9
  54. * @param Array $prepend array of filters to prepend
  55. * @param Array $append array of filters to append
  56. */
  57. function __construct(
  58. $action = null,
  59. $numbers = false,
  60. $prepend = false,
  61. $append = false
  62. )
  63. {
  64. parent::__construct($action);
  65. $this->action = $action;
  66. if ($prepend) {
  67. $this->filters = array_merge($prepend, $this->filters);
  68. }
  69. if ($numbers) {
  70. $this->filters = array_merge($this->filters, range(0, 9));
  71. }
  72. $this->filters = array_merge($this->filters, range('A', 'Z'));
  73. if ($append) {
  74. $this->filters = array_merge($this->filters, $append);
  75. }
  76. }
  77. /**
  78. * Show the widget
  79. *
  80. * Emit the HTML for the widget, using the configured outputter.
  81. *
  82. * @return void
  83. */
  84. function show()
  85. {
  86. $actionName = $this->action->trimmed('action');
  87. $this->action->elementStart('div', array('class' => 'alpha_nav'));
  88. for ($i = 0, $size = sizeof($this->filters); $i < $size; $i++) {
  89. $filter = $this->filters[$i];
  90. $classes = '';
  91. // Add some classes for styling
  92. if ($i == 0) {
  93. $classes .= 'first '; // first filter in the list
  94. } elseif ($i == $size - 1) {
  95. $classes .= 'last '; // last filter in the list
  96. }
  97. // hack to get around $m->connect(array('action' => 'all, 'nickname' => $nickname));
  98. if (strtolower($filter) == 'all') {
  99. $href = common_local_url($actionName);
  100. } else {
  101. $href = common_local_url(
  102. $actionName,
  103. array('filter' => strtolower($filter))
  104. );
  105. }
  106. $params = array('href' => $href);
  107. // sort column
  108. if (!empty($this->action->sort)) {
  109. $params['sort'] = $this->action->sort;
  110. }
  111. // sort order
  112. if ($this->action->reverse) {
  113. $params['reverse'] = 'true';
  114. }
  115. $current = $this->action->arg('filter');
  116. // Highlight the selected filter. If there is no selected
  117. // filter, highlight the last filter in the list (all)
  118. if (!isset($current) && $i == ($size - 1)
  119. || $current === strtolower($filter)) {
  120. $classes .= 'current ';
  121. }
  122. if (!empty($classes)) {
  123. $params['class'] = trim($classes);
  124. }
  125. $this->action->element('a', $params, $filter);
  126. }
  127. $this->action->elementEnd('div');
  128. }
  129. }