https-bitbucket.org-bityvip /tmp/busines13_bundle_installer/mod_roknavmenu/lib/providers/RokMenuProviderJoomla16.php

Language PHP Lines 240
MD5 Hash f87477eea9fdd7b29f03480fb00e0e63 Estimated Cost $4,516 (why?)
Repository https://bitbucket.org/izubizarreta/https-bitbucket.org-bityvip.git View Raw File View Project SPDX
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
<?php
/**
 * @version   1.13 July 2, 2012
 * @author    RocketTheme http://www.rockettheme.com
 * @copyright Copyright (C) 2007 - 2012 RocketTheme, LLC
 * @license   http://www.gnu.org/licenses/gpl-2.0.html GNU/GPLv2 only
 */

require_once(dirname(__FILE__) . '/JoomlaRokMenuNode.php');

if (!class_exists('RokMenuProviderJoomla16'))
{


    class RokMenuProviderJoomla16 extends AbstractRokMenuProvider
    {

        const ROOT_ID = 1;

        protected function getMenuItems()
        {
            //Cache this basd on access level
            $conf =& JFactory::getConfig();
            if ($conf->getValue('config.caching') && $this->args["module_cache"])
            {
                $user =& JFactory::getUser();
                $cache =& JFactory::getCache('mod_roknavmenu');
                $cache->setCaching(true);
                $args = array($this->args);
                $checksum = md5(implode(',', $this->args));
                $menuitems = $cache->get(array($this, 'getFullMenuItems'), $args, 'mod_roknavmenu-' . $user->get('aid', 0) . '-' . $checksum);
            }
            else
            {
                $menuitems = $this->getFullMenuItems($this->args);
            }


	        /* Set the active to the current run since its not saved with the cache */
            $jmenu = JSite::getMenu();
            $active = $jmenu->getActive();

            if (is_object($active))
            {
                if (array_key_exists($active->id, $menuitems))
                {
                	$this->current_node = $active->id;
                }
            }

            $this->populateActiveBranch($menuitems);
            return $menuitems;
        }

        public function getFullMenuItems($args)
        {
            $menu = JSite::getMenu();
            // Get Menu Items
            $rows = $menu->getItems('menutype', $args['menutype']);

            $outputNodes = array();

            if (is_array($rows) && count($rows) > 0)
            {
                foreach ($rows as $item)
                {
                    //Create the new Node
                    $node = new JoomlaRokMenuNode();

                    $node->setId($item->id);
                    $node->setParent($item->parent_id);
                    $node->setTitle(addslashes(htmlspecialchars($item->title, ENT_QUOTES, 'UTF-8')));
                    $node->setParams($item->params);
                    $node->setLink($item->link);

                    // Menu Link is a special type that is a link to another item
                    if ($item->type == 'alias' && $newItem = $menu->getItem($item->params->get('aliasoptions')))
                    {
                        $node->setAlias(true);
                        $node->setLink($newItem->link);
                    }

                    // Get the icon image associated with the item
                    $iParams = (is_object($item->params)) ? $item->params : new JRegisry($item->params);
                    if ($args['menu_images'] && $iParams->get('menu_image') && $iParams->get('menu_image') != -1)
                    {
                        $node->setImage(JURI::base(true) . '/images/stories/' . $iParams->get('menu_image'));
                        if ($args['menu_images_link'])
                        {
                            $node->setLink(null);
                        }
                    }

                    switch ($item->type)
                    {
                        case 'separator':
                            $node->setType('separator');
                            break;
                        case 'url':
                            if ((strpos($node->getLink(), 'index.php?') === 0) && (strpos($node->getLink(), 'Itemid=') === false))
                            {
                                $node->setLink($node->getLink() . '&amp;Itemid=' . $node->getId());
                            } elseif (!empty($item->link) && ($item->link != null)){
                                $node->setLink($item->link);
                            }
                            $node->setType('menuitem');
                            break;
                        default :
                            $router = JSite::getRouter();
                            if ($node->isAlias() && $newItem)
                            {
                                $menu_id = $item->params->get('aliasoptions');
                                $node->setMenuId($menu_id);
                                //for aliased items formatter.php doesn't cover
                                if ($node->getMenuId() == $this->current_node) {
                                    //taken back out because it caused all the aliased menu items on RT demos to highlight
                                    //$node->addListItemClass('active');
                                    //$node->setCssId('current');
                                }
                            }
                            else
                            {
                                $menu_id = $node->getId();
                                $node->setMenuId($menu_id);
                            }
                            $link = ($router->getMode() == JROUTER_MODE_SEF) ? 'index.php?Itemid=' . $menu_id : $node->getLink() . '&Itemid=' . $menu_id;
                            $node->setLink($link);
                            $node->setType('menuitem');
                            break;
                    }

                    if ($node->getLink() != null)
                    {
                        // set the target based on menu item options
                        switch ($item->browserNav)
                        {
                            case 1:
                                $node->setTarget('_blank');
                                break;
                            case 2:
                                //$node->setLink(str_replace('index.php', 'index2.php', $node->getLink()));
                                //$node->setTarget('newnotool');
                            	$value = addslashes(htmlspecialchars("window.open(this.href,'targetWindow','toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes');return false;", ENT_QUOTES, 'UTF-8'));
                                $node->addLinkAttrib('onclick', $value);
                                break;
                            default:
                                //$node->setTarget('current');
                                break;
                        }


                        // Get the final URL
                        if ($item->home == 1)
                        { // Set Home Links to the Base
                            //removed because it breaks SEF extensions
                            //$node->setLink(JRoute::_(JURI::base()));
                        }

                        if ($item->type != 'separator' && $item->type != 'url')
                        {
                            $iSecure = $iParams->get('secure', 0);
                            if (array_key_exists('url_type', $args) && $args['url_type'] == 'full')
                            {
                                $url = JRoute::_($node->getLink(), true, $iSecure);
                                $base = (!preg_match("/^http/", $node->getLink())) ? rtrim(JURI::base(false) . '/') : '';
                                $routed = $base . $url;
                                $secure = RokNavMenuTree::_getSecureUrl($routed, $iSecure);
                                $node->setLink($secure);
                            } else
                            {
                                $node->setLink(JRoute::_($node->getLink(), true, $iSecure));
                            }
                        }
                        else if ($item->type == 'url')
                        {
                            $node->setLink(str_replace('&', '&amp;', $node->getLink()));
                        }
                    }
                    $node->addListItemClass("item" . $node->getId());
                    $node->setAccess($item->access);
                    $node->addSpanClass($node->getType());

                    $outputNodes[$node->getId()] = $node;
                }
            }
            return $outputNodes;
        }

        /**
         * @param  $nodeList
         * @return void
         */
        protected function populateActiveBranch($nodeList)
        {
            // setup children array to find parents and children
            $children = array();
            $list = array();
            foreach ($nodeList as $node)
            {

                $thisref = &$children[$node->getId()];
                $thisref['parent_id'] = $node->getParent();
                if ($node->getParent() == 1)
                {
                    $list[$node->getId()] = &$thisref;
                } else
                {
                    $children[$node->getParent()]['children'][] = $node->getId();
                }
            }
            // Find active branch
            if ($this->current_node != 1)
            {
                if (array_key_exists($this->current_node, $nodeList))
                {
                    $parent_id = $children[$this->current_node]['parent_id'];
                    while ($parent_id && $parent_id != 1)
                    {
                        $this->active_branch[$parent_id] = $nodeList[$parent_id];
                        $parent_id = $children[$parent_id]['parent_id'];
                    }
                    $this->active_branch = array_reverse($this->active_branch, true);
                    $this->active_branch[$this->current_node] = $nodeList[$this->current_node];
                }
            }
        }

        public function getMenuTree()
        {
            if (null == $this->menu)
            {
                $this->menu = new RokMenuNodeTree(self::ROOT_ID);
                $this->populateMenuTree();
            }
            return $this->menu;
        }

    }

}
Back to Top