3 * StatusNet - the distributed open-source microblogging tool
4 * Copyright (C) 2011, StatusNet, Inc.
6 * A menu with a More... button to show more elements
10 * This program is free software: you can redistribute it and/or modify
11 * it under the terms of the GNU Affero General Public License as published by
12 * the Free Software Foundation, either version 3 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Affero General Public License for more details.
20 * You should have received a copy of the GNU Affero General Public License
21 * along with this program. If not, see <http://www.gnu.org/licenses/>.
25 * @author Evan Prodromou <evan@status.net>
26 * @copyright 2011 StatusNet, Inc.
27 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
28 * @link http://status.net/
31 if (!defined('STATUSNET')) {
32 // This check helps protect against security problems;
33 // your code file can't be executed directly from the web.
38 * A menu with a More... element to show more items
42 * @author Evan Prodromou <evan@status.net>
43 * @copyright 2011 StatusNet, Inc.
44 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
45 * @link http://status.net/
47 class MoreMenu extends Menu
53 * Show a menu with a limited number of elements
61 $items = $this->getItems();
65 $attrs = array('class' => 'nav');
68 $menuID = 'nav_' . $tag;
69 $attrs['id'] = $menuID;
72 if (Event::handle('StartNav', array($this, &$tag, &$items))) {
73 $this->out->elementStart('ul', $attrs);
75 $total = count($items);
77 if ($total <= self::SOFT_MAX + 1) {
80 $toShow = array_slice($items, 0, self::SOFT_MAX);
83 foreach ($toShow as $item) {
84 if (count($item) == 5) {
85 list($actionName, $args, $label, $description, $id) = $item;
87 list($actionName, $args, $label, $description) = $item;
90 $this->item($actionName, $args, $label, $description, $id);
93 if ($total > self::SOFT_MAX + 1) {
94 $this->out->elementStart('li', array('class' => 'more_link'));
95 $this->out->element('a', array('href' => '#',
96 'onclick' => 'SN.U.showMoreMenuItems("'.$menuID.'"); return false;'),
97 // TRANS: Link description to show more items in a list.
99 $this->out->elementEnd('li');
101 $extended = array_slice($items, self::SOFT_MAX, self::HARD_MAX - self::SOFT_MAX);
103 foreach ($extended as $item) {
104 if (count($item) == 5) {
105 list($actionName, $args, $label, $description, $id) = $item;
107 list($actionName, $args, $label, $description) = $item;
110 $this->item($actionName, $args, $label, $description, $id, 'extended_menu');
113 if ($total > self::HARD_MAX) {
114 $seeAll = $this->seeAllItem();
116 if (!empty($seeAll)) {
117 if (count($seeAll) == 5) {
118 list($actionName, $args, $label, $description, $id) = $seeAll;
120 list($actionName, $args, $label, $description) = $seeAll;
123 $this->item($actionName, $args, $label, $description, $id, 'extended_menu see_all');
128 $this->out->elementEnd('ul');
130 Event::handle('EndNav', array($this, $tag, $items));
134 function seeAllItem()