]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - lib/moremenu.php
Merge branch 'master' into 1.0.x
[quix0rs-gnu-social.git] / lib / moremenu.php
1 <?php
2 /**
3  * StatusNet - the distributed open-source microblogging tool
4  * Copyright (C) 2011, StatusNet, Inc.
5  *
6  * A menu with a More... button to show more elements
7  * 
8  * PHP version 5
9  *
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.
14  *
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.
19  *
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/>.
22  *
23  * @category  Widget
24  * @package   StatusNet
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/
29  */
30
31 if (!defined('STATUSNET')) {
32     // This check helps protect against security problems;
33     // your code file can't be executed directly from the web.
34     exit(1);
35 }
36
37 /**
38  * A menu with a More... element to show more items
39  *
40  * @category  General
41  * @package   StatusNet
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/
46  */
47
48 class MoreMenu extends Menu
49 {
50     const SOFT_MAX = 5;
51     const HARD_MAX = 15;
52     
53     /**
54      * Show a menu with a limited number of elements
55      *
56      * @param
57      *
58      * @return
59      */
60
61     function show()
62     {
63         $items = $this->getItems();
64         $tag = $this->tag();
65         $menuID  = null;
66
67         $attrs = array('class' => 'nav');
68
69         if (!is_null($tag)) {
70             $menuID = 'nav_' . $tag;
71             $attrs['id'] = $menuID;
72         }
73
74         if (Event::handle('StartNav', array($this, &$tag, &$items))) {
75
76             $this->out->elementStart('ul', $attrs);
77
78             $total = count($items);
79
80             if ($total <= self::SOFT_MAX + 1) {
81                 $toShow = $items;
82             } else {
83                 $toShow = array_slice($items, 0, self::SOFT_MAX);
84             }
85
86             foreach ($toShow as $item) {
87                 list($actionName, $args, $label, $description, $id) = $item;
88                 $this->item($actionName, $args, $label, $description, $id);
89             }
90
91             if ($total > self::SOFT_MAX + 1) {
92
93                 $this->out->elementStart('li', array('class' => 'more_link'));
94                 $this->out->element('a', array('href' => '#',
95                                                'onclick' => 'SN.U.showMoreMenuItems("'.$menuID.'"); return false;'),
96                                     _('More ▼'));
97                 $this->out->elementEnd('li');
98
99                 $extended = array_slice($items, self::SOFT_MAX, self::HARD_MAX - self::SOFT_MAX);
100
101                 foreach ($extended as $item) {
102                     list($actionName, $args, $label, $description, $id) = $item;
103                     $this->item($actionName, $args, $label, $description, $id, 'extended_menu');
104                 }
105
106                 if ($total > self::HARD_MAX) {
107                     $seeAll = $this->seeAllItem();
108
109                     if (!empty($seeAll)) {
110                         list($actionName, $args, $label, $description, $id) = $seeAll;
111                         $this->item($actionName, $args, $label, $description, $id, 'extended_menu see_all');
112                     }
113                 }
114             }
115             
116             $this->out->elementEnd('ul');
117
118             Event::handle('EndNav', array($this, $tag, $items));
119         }
120     }
121
122     function seeAllItem()
123     {
124         return null;
125     }
126     
127 }