Beispiel #1
0
 function getMenuData(&$params)
 {
     $menu = new RokNavMenuTree();
     $menu->_params =& $params;
     $items =& JSite::getMenu();
     // Get Menu Items
     $rows = $items->getItems('menutype', $params->get('menutype'));
     $maxdepth = $menu->getParameter('maxdepth', 10);
     // Build Menu Tree root down (orphan proof - child might have lower id than parent)
     $user =& JFactory::getUser();
     $ids = array();
     $ids[0] = true;
     $last = null;
     $unresolved = array();
     // pop the first item until the array is empty if there is any item
     if (is_array($rows)) {
         while (count($rows) && !is_null($row = array_shift($rows))) {
             $row->ionly = $params->get('menu_images_link');
             if (!$menu->addNode($params, $row)) {
                 if (!array_key_exists($row->id, $unresolved) || $unresolved[$row->id] < $maxdepth) {
                     array_push($rows, $row);
                     if (!isset($unresolved[$row->id])) {
                         $unresolved[$row->id] = 1;
                     } else {
                         $unresolved[$row->id]++;
                     }
                 }
             }
         }
     }
     return $menu;
 }
 function getMenuData(&$params)
 {
     $menu = new RokNavMenuTree();
     $menu->_params =& $params;
     $items =& JSite::getMenu();
     // Get Menu Items
     $rows = $items->getItems('menutype', $params->get('menutype'));
     $maxdepth = $menu->getParameter('maxdepth', 10);
     // Build Menu Tree root down (orphan proof - child might have lower id than parent)
     $user =& JFactory::getUser();
     $ids = array();
     $ids[0] = true;
     $last = null;
     $unresolved = array();
     // pop the first item until the array is empty if there is any item
     if (is_array($rows)) {
         while (count($rows) && !is_null($row = array_shift($rows))) {
             $row->ionly = $params->get('menu_images_link');
             if (!$menu->addNode($params, $row)) {
                 // no parent yet so push item to back of list
                 // SAM: But if the key isn't in the list and we dont _add_ this is infinite, so check the unresolved queue
                 if (!array_key_exists($row->id, $unresolved) || $unresolved[$row->id] < $maxdepth) {
                     array_push($rows, $row);
                     // so let us do max $maxdepth passes
                     // TODO: Put a time check in this loop in case we get too close to the PHP timeout
                     if (!isset($unresolved[$row->id])) {
                         $unresolved[$row->id] = 1;
                     } else {
                         $unresolved[$row->id]++;
                     }
                 }
             }
         }
     }
     return $menu;
 }
        public function getFullMenuItems($args){
            $menu = JSite::getMenu();
            // Get Menu Items
            $rows = $menu->getItems('menutype', $args['menutype']);

            $outputNodes = array();
            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 = new JParameter($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('new');
                            break;
                        case 2:
                            $node->setLink(str_replace('index.php', 'index2.php', $node->getLink()));
                            $node->setTarget('newnotool');
                            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())) ? preg_replace("#/$#", "", 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)){
                    // Add node to output list
                    $outputNodes[$node->getId()] = $node;
                }
            }
            return $outputNodes;
        }
 public function getFullMenuItems($args)
 {
     $app = JFactory::getApplication();
     $menu = $app->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;
 }
 function _getItemData(&$params, $item)
 {
     //Create the new Node
     $node = new RokNavMenuNode();
     $tmp = null;
     // Menu Link is a special type that is a link to another item
     if ($item->type == 'menulink') {
         $menu =& JSite::getMenu();
         if ($newItem = $menu->getItem($item->query['Itemid'])) {
             $tmp = clone $newItem;
             $tmp->name = addslashes(htmlspecialchars($item->name, ENT_QUOTES, 'UTF-8'));
             $tmp->mid = $item->id;
             $tmp->parent = $item->parent;
             $tmp->params = $item->params;
             $tmp->url = null;
             $tmp->nav = 'current';
             $tmp->menualias = true;
         }
     }
     if ($item->type != 'menulink' || $item->type == 'menulink' && $tmp == null) {
         $tmp = clone $item;
         $tmp->name = addslashes(htmlspecialchars($item->name, ENT_QUOTES, 'UTF-8'));
         $tmp->mid = $tmp->id;
         $tmp->url = null;
         $tmp->nav = 'current';
         $tmp->menualias = false;
     }
     $iParams = new JRegistry($tmp->params);
     if ($params->get('menu_images') && $iParams->get('menu_image') && $iParams->get('menu_image') != -1) {
         $image = JURI::base(true) . '/images/stories/' . $iParams->get('menu_image');
         if ($tmp->ionly) {
             $tmp->name = null;
         }
     } else {
         $image = null;
     }
     switch ($tmp->type) {
         case 'separator':
             $tmp->outtype = 'separator';
             break;
         case 'url':
             if (strpos($tmp->link, 'index.php?') === 0 && strpos($tmp->link, 'Itemid=') === false) {
                 $tmp->url = $tmp->link . '&amp;Itemid=' . $tmp->id;
             } else {
                 $tmp->url = $tmp->link;
             }
             $tmp->outtype = 'menuitem';
             break;
         default:
             $router = JSite::getRouter();
             $tmp->url = $router->getMode() == JROUTER_MODE_SEF ? 'index.php?Itemid=' . $tmp->id : $tmp->link . '&Itemid=' . $tmp->id;
             $tmp->outtype = 'menuitem';
             break;
     }
     if ($tmp->url != null) {
         // set the target based on menu item options
         switch ($tmp->browserNav) {
             case 0:
                 $tmp->nav = 'current';
                 break;
             case 1:
                 $tmp->nav = 'new';
                 break;
             case 2:
                 $tmp->url = str_replace('index.php', 'index2.php', $tmp->url);
                 $tmp->nav = 'newnotool';
                 break;
             default:
                 $tmp->nav = 'current';
                 break;
         }
         // Get the final URL
         if ($tmp->home == 1) {
             // Set Home Links to the Base
             $tmp->url = str_replace(array($tmp->route . '/', $tmp->route), '', JRoute::_($tmp->url));
         }
         if ($tmp->type != 'separator' && $tmp->type != 'url') {
             $iSecure = $iParams->get('secure', 0);
             if ($this->_params->get('url_type', 'relative') == 'full') {
                 $url = JRoute::_($tmp->url, true, $iSecure);
                 $base = !preg_match("/^http/", $tmp->url) ? rtrim(JURI::base(false), '/') : '';
                 $routed = $base . $url;
                 $secure = RokNavMenuTree::_getSecureUrl($routed, $iSecure);
                 $tmp->url = $secure;
             } else {
                 $tmp->url = JRoute::_($tmp->url, true, $iSecure);
             }
         } else {
             if ($tmp->type == 'url') {
                 $tmp->url = str_replace('&', '&amp;', $tmp->url);
             } else {
             }
         }
     }
     $node->id = $tmp->mid;
     $node->parent = $tmp->parent;
     $node->title = $tmp->name;
     $node->access = $tmp->access;
     $node->link = $tmp->url;
     $node->level = $item->sublevel;
     $node->image = $image;
     $node->alias = $tmp->alias;
     $node->nav = $tmp->nav;
     $node->displayType = $tmp->browserNav;
     $node->setParameters($tmp->params);
     $node->type = $tmp->outtype;
     $node->order = $item->ordering;
     $node->addListItemClass("item" . $node->id);
     $node->addSpanClass($tmp->outtype);
     return $node;
 }