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

Language PHP Lines 158
MD5 Hash 740f733b3a8a69fac46c0d85cb49ad37 Estimated Cost $2,839 (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
<?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('RokMenuProviderJoomla')) {
    class RokMenuProviderJoomla extends AbstractRokMenuProvider {

        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);
            }

            $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);
                    $node->setTitle(addslashes(htmlspecialchars($item->name, 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 == 'menulink' && $newItem = $menu->getItem($item->query['Itemid'])) {
                        $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());
                            }
                            $node->setType('menuitem');
                            break;
                        default :
                            $router = JSite::getRouter();
                            if ($node->isAlias() && $newItem){
                                $menu_id = $item->query['Itemid'];
                            }
                            else {
                                $menu_id = $node->getId();
                            }
                            $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
                            $node->setLink(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());

                    $user =& JFactory::getUser();


                    if (($node->getAccess() <=  $user->get('aid', 0))||((isset($args['check_access_level'][0]) && $args['check_access_level'][0]==1))){
                        // Add node to output list
                        $outputNodes[$node->getId()] = $node;
                    }
                }
                return $outputNodes;
            }
        }
    }
}
Back to Top