Beispiel #1
0
 function __construct()
 {
     parent::__construct();
     # Check for cached version
     $cache_file = 'jreviews_menu_' . cmsFramework::locale() . '_' . md5(cmsFramework::getConfig('secret'));
     if ($cache = S2Cache::read($cache_file)) {
         $this->___menu_data = $cache['___menu_data'];
         return;
     }
     $menuList = array();
     switch ($this->cmsVersion) {
         case CMS_JOOMLA15:
             $select = "\n                    SELECT \n                        id,\n                        name,\n                        link AS menu_type,\n                        link,\n                        componentid,\n                        params,\n                        access,\n                        published\n                ";
             break;
         case CMS_JOOMLA16:
             $select = "\n                    SELECT \n                        id, \n                        title AS name,\n                        link AS menu_type,\n                        link,\n                        component_id AS componentid,\n                        params,\n                        access,\n                        published\n                ";
             break;
     }
     // Get all com_content category/section menus and JReviews menus
     $sql = $select . "\n            FROM #__menu\n            WHERE published = 1\n            ORDER BY link DESC\n        ";
     $this->_db->setQuery($sql);
     $menuList = $this->_db->loadObjectList();
     // Get itemid for each menu link and store it
     if (!empty($menuList)) {
         foreach ($menuList as $menu) {
             $params = stringToArray($menu->params);
             $m_name = Sanitize::getVar($params, 'sef_name') != '' ? Sanitize::getVar($params, 'sef_name') : $menu->name;
             function_exists("sefEncode") and $m_name = sefEncode($m_name);
             $m_action = Sanitize::getVar($params, 'action');
             $m_dir_id = str_replace(",", "-", Sanitize::getVar($params, 'dirid'));
             $m_cat_id = str_replace(",", "-", Sanitize::getVar($params, 'catid'));
             $m_section_id = str_replace(",", "-", Sanitize::getVar($params, 'sectionid'));
             $m_criteria_id = str_replace(",", "-", Sanitize::getVar($params, 'criteriaid'));
             // Create a variable to get Menu Name from Itemid
             $this->set('jr_itemid_' . $menu->id, $m_name);
             $this->set('jr_menu_' . $m_name, $menu->id);
             if (strpos($menu->menu_type, 'option=com_content&view=section&id=') || strpos($menu->menu_type, 'option=com_content&view=section&layout=blog&id=')) {
                 $menu->componentid = end(explode('id=', $menu->menu_type));
                 $menu->menu_type = 'content_section';
             } elseif (strpos($menu->menu_type, 'option=com_content&view=category&id=') || strpos($menu->menu_type, 'option=com_content&view=category&layout=blog&id=')) {
                 $menu->componentid = end(explode('id=', $menu->menu_type));
                 $menu->menu_type = 'content_category';
             } elseif (strpos($menu->menu_type, 'option=com_content&view=article&id=') || strpos($menu->menu_type, 'option=com_content&task=view&id=')) {
                 $menu->componentid = end(explode('id=', $menu->menu_type));
                 $menu->menu_type = 'content_item_link';
             }
             switch ($menu->menu_type) {
                 case 'content_section':
                 case 'content_blog_section':
                     if ($menu->componentid) {
                         // Only one section id
                         $this->set('core_section_menu_id_' . $menu->componentid, $menu->id);
                     } else {
                         $section_ids = explode(",", Sanitize::getVar($params, 'sectionid'));
                         $this->set('jr_manyIds_' . $menu->id, 1);
                         foreach ($section_ids as $section_id) {
                             $this->set('core_section_menu_id_' . $section_id, $menu->id);
                         }
                     }
                     break;
                 case 'content_category':
                 case 'content_blog_category':
                     if ($menu->componentid) {
                         // Only one category id
                         $this->set('core_category_menu_id_' . $menu->componentid, $menu->id);
                     } else {
                         $cat_ids = explode(",", Sanitize::getVar($params, 'categoryid'));
                         $this->set('jr_manyIds_' . $menu->id, 1);
                         foreach ($cat_ids as $cat_id) {
                             $this->set('core_category_menu_id_' . $cat_id, $menu->id);
                         }
                     }
                     break;
                 case 'content_item_link':
                     $this->set('core_content_menu_id_' . $menu->componentid, $menu->id);
                     break;
                 default:
                     if ($menu->componentid > 0 && strstr($menu->link, 'index.php?option=' . S2Paths::get('jreviews', 'S2_CMSCOMP'))) {
                         // It's a JReviews menu
                         $access = $this->cmsVersion == CMS_JOOMLA15 ? 0 : 1;
                         // Get a JReviews menu with public access to use in ajax requests
                         if ($menu->access == $access && $menu->published == 1) {
                             $this->set('jreviews_public', $menu->id);
                         }
                         $this->set('jr_menu_action_' . $m_dir_id, $m_action);
                         $this->set('menu_params_' . $menu->id, $params);
                         switch ($m_action) {
                             case '0':
                                 // Directory menu
                                 $this->set('jr_directory_menu_id_' . $m_dir_id, $menu->id);
                                 break;
                             case '1':
                                 // Section menu
                                 $this->set('jr_section_menu_id_' . $m_section_id, $menu->id);
                                 break;
                             case '2':
                                 // Category menu
                                 $this->set('jr_category_menu_id_' . $m_cat_id, $menu->id);
                                 break;
                             case '10':
                                 $this->set('jr_myreviews', $menu->id);
                                 break;
                             case '11':
                                 $m_criteria_id && $this->set('jr_advsearch_' . $m_criteria_id, $menu->id);
                                 !$m_criteria_id && $this->set('jr_advsearch', $menu->id);
                                 break;
                             case '12':
                                 $this->set('jr_mylistings', $menu->id);
                                 break;
                             case '18':
                                 $this->set('jr_reviewers', $menu->id);
                                 break;
                             default:
                                 $this->set('jr_menu_id_action_' . $m_action, $menu->id);
                                 break;
                         }
                     }
                     break;
             }
         }
         S2Cache::write($cache_file, array('___menu_data' => $this->___menu_data));
     }
     //        prx($this->___menu_data);exit;
 }
Beispiel #2
0
 function __construct()
 {
     parent::__construct();
     $menuList = array();
     switch (getCmsVersion()) {
         case CMS_JOOMLA15:
             $select = 'SELECT id,name,link AS menu_type,link,componentid,params,access,published';
             $type = "\n AND type = 'component'";
             $link = "\n AND ( \n                    link LIKE '%option=com_content&view=section%' OR\n                    link LIKE '%option=com_content&view=section&layout=blog%' OR\n                    link LIKE '%option=com_content&view=category\\%' OR\n                    link LIKE '%option=com_content&view=category&layout=blog%' OR\n                    link LIKE '%option=com_content&view=article%'                \n                )";
             break;
         case CMS_JOOMLA16:
             $select = "\n                    SELECT \n                        id, \n                        alias AS name,\n                        link AS menu_type,\n                        link,\n                        component_id AS componentid,\n                        params,\n                        access,\n                        published\n                ";
             $type = "\n AND type = 'component'";
             $link = "\n AND ( \n                    link LIKE '%option=com_content&view=section%' OR\n                    link LIKE '%option=com_content&view=section&layout=blog%' OR\n                    link LIKE '%option=com_content&view=category\\%' OR\n                    link LIKE '%option=com_content&view=category&layout=blog%' OR\n                    link LIKE '%option=com_content&view=article%'                \n                )";
             break;
     }
     // Get all com_content category/section menus and jReviews menus
     $sql = $select . "\n FROM #__menu" . "\n WHERE published = 1" . (getCmsVersion() == CMS_MAMBO46 ? "\n ORDER BY link ASC" : "\n ORDER BY link DESC");
     # Check for cached version
     $cache_prefix = 'menu_model';
     $cache_key = $sql;
     if ($cache = S2cacheRead($cache_prefix, $cache_key)) {
         $menuList = $cache;
     }
     if (empty($menuList)) {
         // Mambo4.6, as opposed to Mambo4.5, does not allow using other components Itemids so jReviews
         // Sections and category lists cannot use the section/category table or blog list menu Itemids
         $this->_db->setQuery($sql);
         $menuList = $this->_db->loadObjectList();
         # Send to cache
         S2cacheWrite($cache_prefix, $cache_key, $menuList);
     }
     // Get itemid for each menu link and store it
     if (is_array($menuList)) {
         foreach ($menuList as $menu) {
             $this->menues[$menu->id] = $menu;
             $params = stringToArray($menu->params);
             $paramsArray = explode("\n", $menu->params);
             if (Sanitize::getVar($params, 'sef_name') != '') {
                 $m_name = Sanitize::getVar($params, 'sef_name');
             } else {
                 $m_name = $menu->name;
             }
             if (function_exists("sefEncode")) {
                 $m_name = sefEncode($m_name);
             }
             $m_action = Sanitize::getVar($params, 'action');
             $m_dir_id = str_replace(",", "-", Sanitize::getVar($params, 'dirid'));
             $m_cat_id = str_replace(",", "-", Sanitize::getVar($params, 'catid'));
             $m_section_id = str_replace(",", "-", Sanitize::getVar($params, 'sectionid'));
             $m_criteria_id = str_replace(",", "-", Sanitize::getVar($params, 'criteriaid'));
             // Create a variable to get Menu Name from Itemid
             $this->set('jr_itemid_' . $menu->id, $m_name);
             $this->set('jr_menu_' . $m_name, $menu->id);
             # Fix for change in menu structure in J1.5
             if (getCmsVersion() == CMS_JOOMLA15) {
                 if (strpos($menu->menu_type, 'option=com_content&view=section&id=') || strpos($menu->menu_type, 'option=com_content&view=section&layout=blog&id=')) {
                     $menu->componentid = end(explode('id=', $menu->menu_type));
                     $menu->menu_type = 'content_section';
                 } elseif (strpos($menu->menu_type, 'option=com_content&view=category&id=') || strpos($menu->menu_type, 'option=com_content&view=category&layout=blog&id=')) {
                     $menu->componentid = end(explode('id=', $menu->menu_type));
                     $menu->menu_type = 'content_category';
                 } elseif (strpos($menu->menu_type, 'option=com_content&view=article&id=') || strpos($menu->menu_type, 'option=com_content&task=view&id=')) {
                     $menu->componentid = end(explode('id=', $menu->menu_type));
                     $menu->menu_type = 'content_item_link';
                 }
             }
             switch ($menu->menu_type) {
                 case 'content_section':
                 case 'content_blog_section':
                     if ($menu->componentid) {
                         // Only one section id
                         $this->set('core_section_menu_id_' . $menu->componentid, $menu->id);
                         //                                $this->set('jr_section_menu_id_'.$menu->componentid,$menu->id);
                     } else {
                         $section_ids = explode(",", Sanitize::getVar($params, 'sectionid'));
                         $this->set('jr_manyIds_' . $menu->id, 1);
                         foreach ($section_ids as $section_id) {
                             $this->set('core_section_menu_id_' . $section_id, $menu->id);
                             //                                    $this->set('jr_section_menu_id_'.$section_id,$menu->id);
                         }
                     }
                     break;
                 case 'content_category':
                 case 'content_blog_category':
                     if ($menu->componentid) {
                         // Only one category id
                         $this->set('core_category_menu_id_' . $menu->componentid, $menu->id);
                         //                            $this->set('jr_category_menu_id_'.$menu->componentid,$menu->id);
                     } else {
                         $cat_ids = explode(",", Sanitize::getVar($params, 'categoryid'));
                         $this->set('jr_manyIds_' . $menu->id, 1);
                         foreach ($cat_ids as $cat_id) {
                             $this->set('core_category_menu_id_' . $cat_id, $menu->id);
                             //                                    $this->set('jr_category_menu_id_'.$cat_id,$menu->id);
                         }
                     }
                     break;
                 case 'content_item_link':
                     $this->set('core_content_menu_id_' . $menu->componentid, $menu->id);
                     break;
                 default:
                     if ($menu->link == 'index.php?option=' . S2Paths::get('jreviews', 'S2_CMSCOMP')) {
                         // It's a jReviews menu
                         // Get a jReviews menu with public access to use in xajax requests
                         if ($menu->access == 0 && $menu->published == 1) {
                             $this->set('jreviews_public', $menu->id);
                         }
                         $menuParams = array();
                         foreach ($paramsArray as $parameter) {
                             $menuParams[current(explode('=', $parameter))] = end(explode('=', $parameter));
                         }
                         $this->set('jr_menu_action_' . $m_dir_id, $m_action);
                         $this->set('menu_params_' . $menu->id, $menuParams);
                         switch ($m_action) {
                             case '0':
                                 // Directory menu
                                 $this->set('jr_directory_menu_id_' . $m_dir_id, $menu->id);
                                 break;
                             case '1':
                                 // Section menu
                                 $this->set('jr_section_menu_id_' . $m_section_id, $menu->id);
                                 break;
                             case '2':
                                 // Category menu
                                 $this->set('jr_category_menu_id_' . $m_cat_id, $menu->id);
                                 break;
                             case '10':
                                 $this->set('jr_myreviews', $menu->id);
                                 break;
                             case '11':
                                 $m_criteria_id && $this->set('jr_advsearch_' . $m_criteria_id, $menu->id);
                                 !$m_criteria_id && $this->set('jr_advsearch', $menu->id);
                                 break;
                             case '12':
                                 $this->set('jr_mylistings', $menu->id);
                                 break;
                             case '18':
                                 $this->set('jr_reviewers', $menu->id);
                                 break;
                             default:
                                 $this->set('jr_menu_id_action_' . $m_action, $menu->id);
                                 break;
                         }
                     }
                     break;
             }
         }
     }
     //        prx($this->___menu_data);
 }