From bfd64fc2a6f9aea949955dd5e12ead6954144a9f Mon Sep 17 00:00:00 2001 From: secretr Date: Sun, 16 Aug 2009 16:30:56 +0000 Subject: [PATCH] Introducing e_menu front-end class --- class2.php | 44 +- e107_admin/menus.php | 10 +- e107_files/shortcode/menu.php | 146 +-- e107_handlers/e107_class.php | 20 +- e107_handlers/menu_class.php | 1340 ++++----------------------- e107_handlers/menumanager_class.php | 1187 ++++++++++++++++++++++++ e107_handlers/theme_handler.php | 10 +- 7 files changed, 1412 insertions(+), 1345 deletions(-) create mode 100644 e107_handlers/menumanager_class.php diff --git a/class2.php b/class2.php index cc72d61ff..082cccf9a 100644 --- a/class2.php +++ b/class2.php @@ -9,9 +9,9 @@ * General purpose file * * $Source: /cvs_backup/e107_0.8/class2.php,v $ -* $Revision: 1.127 $ -* $Date: 2009-08-14 22:31:08 $ -* $Author: e107coders $ +* $Revision: 1.128 $ +* $Date: 2009-08-16 16:30:56 $ +* $Author: secretr $ * */ // @@ -1164,43 +1164,7 @@ if(!defined("THEME_LAYOUT")) $sql->db_Mark_Time('Start: Get menus'); if(!isset($_E107['no_menus'])) { - $menu_layout_field = (THEME_LAYOUT != $pref['sitetheme_deflayout']) ? THEME_LAYOUT : ""; - $menu_data = $e107cache->retrieve_sys("menus_".USERCLASS_LIST."_".md5(e_LANGUAGE.$menu_layout_field)); - $menu_data = $eArrayStorage->ReadArray($menu_data); - $eMenuList = array(); - $eMenuActive = array(); - $eMenuArea = array(); - - if(!is_array($menu_data)) - { - - $menu_qry = 'SELECT * FROM #menus WHERE menu_location > 0 AND menu_class IN ('.USERCLASS_LIST.') AND menu_layout = "'.$menu_layout_field.'" ORDER BY menu_location,menu_order'; - if ($sql->db_Select_gen($menu_qry)) - { - while ($row = $sql->db_Fetch()) - { - $eMenuList[$row['menu_location']][] = $row; - $eMenuArea[$row['menu_location']][$row['menu_name']] = 1; - $eMenuActive[$row['menu_name']] = $row['menu_name']; - } - } - $menu_data['menu_area'] = $eMenuArea; - $menu_data['menu_list'] = $eMenuList; - $menu_data['menu_active'] = $eMenuActive; - $menu_data = $eArrayStorage->WriteArray($menu_data, false); - $e107cache->set_sys('menus_'.USERCLASS_LIST.'_'.md5(e_LANGUAGE), $menu_data); - - unset($menu_data,$menu_layout_field,$menu_qry); - } - else - { - $eMenuArea = $menu_data['menu_area']; - $eMenuList = $menu_data['menu_list']; - $eMenuActive = $menu_data['menu_active']; - unset($menu_data); - } - - + e107::getMenu()->init(); } diff --git a/e107_admin/menus.php b/e107_admin/menus.php index 8eb8f9522..db8dcf170 100644 --- a/e107_admin/menus.php +++ b/e107_admin/menus.php @@ -10,9 +10,9 @@ | GNU General Public License (http://gnu.org). | | $Source: /cvs_backup/e107_0.8/e107_admin/menus.php,v $ -| $Revision: 1.31 $ -| $Date: 2009-07-17 02:28:49 $ -| $Author: e107coders $ +| $Revision: 1.32 $ +| $Date: 2009-08-16 16:30:56 $ +| $Author: secretr $ +----------------------------------------------------------------------------+ */ require_once("../class2.php"); @@ -27,12 +27,12 @@ $e_sub_cat = 'menus'; require_once(e_HANDLER."file_class.php"); require_once(e_HANDLER."form_handler.php"); require_once (e_HANDLER.'message_handler.php'); -require_once(e_HANDLER."menu_class.php"); +require_once(e_HANDLER."menumanager_class.php"); $rs = new form; $frm = new e_form(); - $men = new menuManager(); // use 1 for dragdrop. + $men = new e_menuManager(); // use 1 for dragdrop. if(isset($_GET['ajax'])) diff --git a/e107_files/shortcode/menu.php b/e107_files/shortcode/menu.php index 555d20f5b..7015f5075 100644 --- a/e107_files/shortcode/menu.php +++ b/e107_files/shortcode/menu.php @@ -1,151 +1,9 @@ eMenuArea = $tmp[0]; - - - foreach($eMenuList[$tmp[0]] as $row) - { - $pkey = str_replace("/","",$row['menu_path']); - $show_menu[$pkey] = $row['menu_name']; - - if($row['menu_pages']) - { - list($listtype, $listpages) = explode('-', $row['menu_pages'], 2); - $pagelist = explode('|',$listpages); - $check_url = e_SELF.(e_QUERY ? '?'.e_QUERY : ''); - - if($listtype == '1') //show menu - { - //$show_menu[$pkey] = FALSE; - unset($show_menu[$pkey]); - foreach($pagelist as $p) - { - if(substr($p, -1) == '!') - { - $p = substr($p, 0, -1); - if(substr($check_url, strlen($p)*-1) == $p) - { - // $show_menu[$pkey] = TRUE; - $show_menu[$pkey] = $row['menu_name']; - } - } - else - { - if(strpos($check_url,$p) !== FALSE) - { - // $show_menu[$pkey] = TRUE; - $show_menu[$pkey] = $row['menu_name']; - } - } - } - } - elseif($listtype == '2') //hide menu - { - // $show_menu[$pkey] = TRUE; - $show_menu[$pkey] = $row['menu_name']; - foreach($pagelist as $p) { - if(substr($p, -1) == '!') - { - $p = substr($p, 0, -1); - if(substr($check_url, strlen($p)*-1) == $p) - { - // $show_menu[$pkey] = FALSE; - unset($show_menu[$pkey]); - } - } - else - { - if(strpos($check_url, $p) !== FALSE) - { - // $show_menu[$pkey] = FALSE; - unset($show_menu[$pkey]); - } - } - } - } - } - } - - e107::getRender()->eMenuTotal = count($show_menu); - - foreach($show_menu as $mpath=>$mname) - { - // $mname = $row['menu_name']; - if($error_handler->debug == true) - { - echo "\n\n"; - } - $sql->db_Mark_Time($mname); - if(is_numeric($mpath)) - { - $sql -> db_Select("page", "*", "page_id='".$mpath."' "); - $page = $sql -> db_Fetch(); - $caption = $e107->tp->toHTML($page['page_title'], TRUE, 'parse_sc, constants'); - $text = $e107->tp->toHTML($page['page_text'], TRUE, 'parse_sc, constants'); - e107::getRender()->tablerender($caption, $text); - } - else - { - if (is_readable(e_PLUGIN.$mpath."/languages/".e_LANGUAGE.".php")) - { - include_once(e_PLUGIN.$mpath."/languages/".e_LANGUAGE.".php"); - } - elseif (is_readable(e_PLUGIN.$mpath."/languages/".e_LANGUAGE."/".e_LANGUAGE.".php")) - { - include_once(e_PLUGIN.$mpath."/languages/".e_LANGUAGE."/".e_LANGUAGE.".php"); - } - elseif (is_readable(e_PLUGIN.$mpath."/languages/English.php")) - { - include_once(e_PLUGIN.$mpath."/languages/English.php"); - } - elseif (is_readable(e_PLUGIN.$mpath."/languages/English/English.php")) - { - include_once(e_PLUGIN.$mpath."/languages/English/English.php"); - } - - if(file_exists(e_PLUGIN.$mpath."/".$mname.".php")) - { - include_once(e_PLUGIN.$mpath."/".$mname.".php"); - } - } - $sql->db_Mark_Time("(After ".$mname.")"); - if ($error_handler->debug == true) - { - echo "\n\n"; - } - unset($caption,$text); // clear variables for proceeding menus. - } - - - e107::getRender()->eMenuCount = 0; - e107::getRender()->eMenuArea = null; - - - if ($buffer_output) - { - $ret = ob_get_contents(); - ob_end_clean(); - return $ret; - } + return e107::getMenu()->render($parm); } diff --git a/e107_handlers/e107_class.php b/e107_handlers/e107_class.php index d2b276f23..76b05a7c8 100644 --- a/e107_handlers/e107_class.php +++ b/e107_handlers/e107_class.php @@ -9,8 +9,8 @@ * e107 Main * * $Source: /cvs_backup/e107_0.8/e107_handlers/e107_class.php,v $ - * $Revision: 1.34 $ - * $Date: 2009-08-05 19:56:48 $ + * $Revision: 1.35 $ + * $Date: 2009-08-16 16:30:56 $ * $Author: secretr $ */ @@ -217,8 +217,12 @@ class e107 * @param string $regpath additional registry path * @return Object */ - public static function getSingleton($class_name, $path = null, $regpath = '') + public static function getSingleton($class_name, $path = true, $regpath = '') { + if(true === $path) + { + //TODO All handler class names in array (lazy loading) + } $id = 'core/e107/singleton/'.$class_name.$regpath; if(!e107::getRegistry($id)) { @@ -488,6 +492,16 @@ class e107 return self::getSingleton('ArrayData', e_HANDLER.'arraystorage_class.php'); } + /** + * Retrieve menu handler singleton object + * + * @return e_menu + */ + public static function getMenu() + { + return self::getSingleton('e_menu', e_HANDLER.'menu_class.php'); + } + /** * Retrieve URL singleton object * diff --git a/e107_handlers/menu_class.php b/e107_handlers/menu_class.php index 8915ff245..ac4f17c45 100644 --- a/e107_handlers/menu_class.php +++ b/e107_handlers/menu_class.php @@ -10,1177 +10,221 @@ | GNU General Public License (http://gnu.org). | | $Source: /cvs_backup/e107_0.8/e107_handlers/menu_class.php,v $ -| $Revision: 1.7 $ -| $Date: 2009-08-03 20:17:12 $ -| $Author: marj_nl_fr $ +| $Revision: 1.8 $ +| $Date: 2009-08-16 16:30:56 $ +| $Author: secretr $ +----------------------------------------------------------------------------+ */ -if (!defined('e107_INIT')) { exit; } +if(!defined('e107_INIT')) +{ + exit(); +} - -class menuManager{ - - - var $menu_areas = array(); - var $curLayout; - var $menuId; - var $menuNewLoc; - var $dragDrop; - var $menuActivateLoc; - var $menuActivateIds; - var $debug; - var $menuMessage; - - function menuManager($dragdrop=FALSE) +class e_menu +{ + public $eMenuArea; + public $eMenuList; + public $eMenuActive; + + function __construct() + { + + } + + /** + * Init + * + */ + public function init() + { + $menu_layout_field = THEME_LAYOUT != e107::getPref('sitetheme_deflayout') ? THEME_LAYOUT : ""; + $menu_data = e107::getCache()->retrieve_sys("menus_".USERCLASS_LIST."_".md5(e_LANGUAGE.$menu_layout_field)); + $menu_data = e107::getArrayStorage()->ReadArray($menu_data); + $eMenuList = array(); + $eMenuActive = array(); + $eMenuArea = array(); + + if(!is_array($menu_data)) { - global $pref, $HEADER,$FOOTER, $NEWSHEADER; - - - $this->debug = FALSE; - - - $this->dragDrop = $dragdrop; - - - - if($this->dragDrop) + + $menu_qry = 'SELECT * FROM #menus WHERE menu_location > 0 AND menu_class IN ('.USERCLASS_LIST.') AND menu_layout = "'.$menu_layout_field.'" ORDER BY menu_location,menu_order'; + if (e107::getDb()->db_Select_gen($menu_qry)) + { + while ($row = e107::getDb()->db_Fetch()) { - $this->debug = TRUE; + $eMenuList[$row['menu_location']][] = $row; + $eMenuArea[$row['menu_location']][$row['menu_name']] = 1; + $eMenuActive[$row['menu_name']] = $row['menu_name']; } + } + $menu_data['menu_area'] = $eMenuArea; + $menu_data['menu_list'] = $eMenuList; + $menu_data['menu_active'] = $eMenuActive; + $menu_data = e107::getArrayStorage()->WriteArray($menu_data, false); + e107::getCache()->set_sys('menus_'.USERCLASS_LIST.'_'.md5(e_LANGUAGE), $menu_data); + + unset($menu_data,$menu_layout_field,$menu_qry); + } + else + { + $eMenuArea = $menu_data['menu_area']; + $eMenuList = $menu_data['menu_list']; + $eMenuActive = $menu_data['menu_active']; + unset($menu_data); + } - if ($NEWSHEADER) + $this->eMenuActive = $eMenuActive; + $this->eMenuArea = $eMenuArea; + $this->eMenuList = $eMenuList; + } + + function render($parm = '') + { + + global $sql, $ns, $tp, $sc_style; + global $error_handler; + $e107 = e107::getInstance(); + + $eMenuList = $this->eMenuList; + + $tmp = explode(':',$parm); + + $buffer_output = true; // Default - return all output. + if (isset($tmp[1]) && $tmp[1] == 'echo') { $buffer_output = false; } + + if (!array_key_exists($tmp[0], $eMenuList)) { return; } + + if ($buffer_output) + { + ob_start(); + } + + e107::getRender()->eMenuArea = $tmp[0]; + + + foreach($eMenuList[$tmp[0]] as $row) + { + $pkey = str_replace("/","",$row['menu_path']); + $show_menu[$pkey] = $row['menu_name']; + + if($row['menu_pages']) + { + list($listtype, $listpages) = explode('-', $row['menu_pages'], 2); + $pagelist = explode('|',$listpages); + $check_url = e_SELF.(e_QUERY ? '?'.e_QUERY : ''); + + if($listtype == '1') //show menu { - $HEADER .= $NEWSHEADER; - } - - - if(isset($_POST['custom_select'])) - { - $this->curLayout = $_POST['custom_select']; - } - elseif($_GET['lay']) - { - $this->curLayout = $_GET['lay']; - } - else - { - $tmp = explode('.', e_QUERY); - $this->curLayout = ($tmp[1]) ? $tmp[1] : $pref['sitetheme_deflayout']; - } - - $this->dbLayout = ($this->curLayout !=$pref['sitetheme_deflayout']) ? $this->curLayout : ""; //menu_layout is left blank when it's default. - - if(isset($_POST['menu_id']) || $_GET['id']) - { - $this->menuId = (isset($_POST['menu_id'])) ? intval($_POST['menu_id']) : $_GET['id']; - } - - if ($menu_act == "sv" || isset($_POST['class_submit'])) - { - - $this->menuSaveVisibility(); - - } - - if ($_GET['mode'] == "deac") - { - $this->menuDeactivate(); - } - - if ($_GET['mode'] == "conf") - { - $this->menuGoConfig(); - } - - $this->menuGrabLayout(); - - $menu_array = $this->parseheader($HEADER.$FOOTER, 'check'); - - if($menu_array) - { - sort($menu_array, SORT_NUMERIC); - $menu_check = 'set'; - foreach ($menu_array as $menu_value) + //$show_menu[$pkey] = FALSE; + unset($show_menu[$pkey]); + foreach($pagelist as $p) { - if ($menu_value != $menu_check) + if(substr($p, -1) == '!') { - $this->menu_areas[] = $menu_value; + $p = substr($p, 0, -1); + if(substr($check_url, strlen($p)*-1) == $p) + { + // $show_menu[$pkey] = TRUE; + $show_menu[$pkey] = $row['menu_name']; + } } - $menu_check = $menu_value; - } - } - - $this->menuModify(); - - if($_POST['menuActivate']) - { - $this->menuActivateLoc = key($_POST['menuActivate']); - $this->menuActivateIds = $_POST['menuselect']; - $this->menuActivate(); - - } - - if($_POST['menuSetCustomPages']) - { - $this->menuSetCustomPages($_POST['custompages']); - } - - if(isset($_POST['menuUsePreset']) && $_POST['curLayout']) - { - - $this->menuSetPreset(); - } - - $this->menuSetConfigList(); // Update Active MenuConfig List. - - } - -// ------------------------------------------------------------------------- - - function menuRenderIframe($url='') - { - global $ns,$sql; - if(!$url) - { - $url = e_SELF."?configure.".$this->curLayout; - } - - $cnt = $sql->db_Select("menus", "*", "menu_location > 0 AND menu_layout = '$curLayout' ORDER BY menu_name "); // calculate height to remove vertical scroll-bar. - - $text .= ""; - - return $text; - } - - - function menuRenderMessage() - { - // return $this->menuMessage; - $emessage = &eMessage::getInstance(); - - $text = $emessage->render($message); - // $text .= "ID = ".$this->menuId; - return $text; - - } - - - function menuAddMessage($message, $type = E_MESSAGE_INFO, $session = false) - { - $emessage = &eMessage::getInstance(); - $emessage->add($message, $type, $session); - } - - // ------------------------------------------------------------------------- - - function menuGrabLayout() - { - global $HEADER,$FOOTER,$CUSTOMHEADER,$CUSTOMFOOTER; - - if(($this->curLayout == 'legacyCustom' || $this->curLayout=='legacyDefault') && (isset($CUSTOMHEADER) || isset($CUSTOMFOOTER)) ) // 0.6 themes. - { - if($this->curLayout == 'legacyCustom') - { - $HEADER = ($CUSTOMHEADER) ? $CUSTOMHEADER : $HEADER; - $FOOTER = ($CUSTOMFOOTER) ? $CUSTOMFOOTER : $FOOTER; - } - } - elseif($this->curLayout && $this->curLayout != "legacyCustom" && (isset($CUSTOMHEADER[$this->curLayout]) || isset($CUSTOMHEADER[$this->curLayout]))) // 0.7 themes - { - // echo " MODE 0.7 ".$this->curLayout; - $HEADER = ($CUSTOMHEADER[$this->curLayout]) ? $CUSTOMHEADER[$this->curLayout] : $HEADER; - $FOOTER = ($CUSTOMFOOTER[$this->curLayout]) ? $CUSTOMFOOTER[$this->curLayout] : $FOOTER; - } - elseif($this->curLayout && is_array($HEADER) && isset($HEADER[$this->curLayout]) && isset($FOOTER[$this->curLayout])) // 0.8 themes - we use only $HEADER and $FOOTER arrays. - { - // echo " MODE 0.8 ".$this->curLayout; - - $HEADER = $HEADER[$this->curLayout]; - $FOOTER = $FOOTER[$this->curLayout]; - - } - - // Almost the same code as found in templates/header_default.php --------- - - } - - function menuGoConfig() - { - if(!$_GET['path'] || ($_GET['mode'] != "conf")) - { - return; - } - - $file = urldecode($_GET['path']).".php"; - $newurl = e_PLUGIN_ABS.$file; - - /* - - - - return ""; - -*/ - header("Location: ".$newurl); - exit; - // echo "URL = ".$newurl; - // $newurl = $PLUGINS_DIRECTORY.$location."/{$position}{$this->menuNewLoc}.php"; - // $newurl = SITEURL.str_replace("//", "/", $newurl); - // echo " "; - // exit; - - - } - - // ----------------------------------------------------------------------------- - - function menuModify() - { - global $pref,$sql,$admin_log,$ns; - - $menu_act = ""; - - if (isset($_POST['menuAct'])) - { - foreach ($_POST['menuAct'] as $k => $v) - { - if (trim($v)) - { - $this->menuId = $k; - list($menu_act, $location, $position, $this->menuNewLoc) = explode(".", $_POST['menuAct'][$k]); - } - } - } - - - if ($menu_act == "move") - { - $this->menuMove(); - } - - - - if ($menu_act == "bot") - { - $menu_count = $sql->db_Count("menus", "(*)", " WHERE menu_location='{$location}' AND menu_layout = '".$this->dbLayout."' "); - $sql->db_Update("menus", "menu_order=".($menu_count+1)." WHERE menu_order='{$position}' AND menu_location='{$location}' AND menu_layout = '$this->dbLayout' "); - $sql->db_Update("menus", "menu_order=menu_order-1 WHERE menu_location='{$location}' AND menu_order > {$position} AND menu_layout = '".$this->dbLayout."' "); - $admin_log->log_event('MENU_06',$location.'[!br!]'.$position.'[!br!]'.$this->menuId,E_LOG_INFORMATIVE,''); - } - - if ($menu_act == "top") - { - $sql->db_Update("menus", "menu_order=menu_order+1 WHERE menu_location='{$location}' AND menu_order < {$position} AND menu_layout = '".$this->dbLayout."' ",$this->debug); - $sql->db_Update("menus", "menu_order=1 WHERE menu_id='{$this->menuId}' "); - $admin_log->log_event('MENU_05',$location.'[!br!]'.$position.'[!br!]'.$this->menuId,E_LOG_INFORMATIVE,''); - } - - if ($menu_act == "dec") - { - $sql->db_Update("menus", "menu_order=menu_order-1 WHERE menu_order='".($position+1)."' AND menu_location='{$location}' AND menu_layout = '".$this->dbLayout."' ",$this->debug); - $sql->db_Update("menus", "menu_order=menu_order+1 WHERE menu_id='{$this->menuId}' AND menu_location='{$location}' AND menu_layout = '".$this->dbLayout."' ",TRUE); - $admin_log->log_event('MENU_08',$location.'[!br!]'.$position.'[!br!]'.$this->menuId,E_LOG_INFORMATIVE,''); - } - - if ($menu_act == "inc") - { - $sql->db_Update("menus", "menu_order=menu_order+1 WHERE menu_order='".($position-1)."' AND menu_location='{$location}' AND menu_layout = '".$this->dbLayout."' ",$this->debug); - $sql->db_Update("menus", "menu_order=menu_order-1 WHERE menu_id='{$this->menuId}' AND menu_location='{$location}' AND menu_layout = '".$this->dbLayout."' "); - $admin_log->log_event('MENU_07',$location.'[!br!]'.$position.'[!br!]'.$this->menuId,E_LOG_INFORMATIVE,''); - } - - if (strpos(e_QUERY, 'configure') === FALSE) - { // Scan plugin directories to see if menus to add - $this->menuScanMenus(); - } - } - - - - - - - // ---------------------------------------------------------------------------- - - function menuSetPreset() - { - global $pref,$sql,$location,$admin_log; - - if(!$menuAreas = $this->getMenuPreset()) - { - return FALSE; - } - - - $sql->db_Update("menus", "menu_location='0' WHERE menu_layout = '".$this->dbLayout."' "); // Clear All existing. - foreach($menuAreas as $val) - { - - if($sql->db_Select("menus", 'menu_name, menu_path' , "menu_name = '".$val['menu_name']."' LIMIT 1")) - { - $row=$sql->db_Fetch(); - - if(!$sql->db_Update('menus', "menu_order='{$val['menu_order']}', menu_location = ".$val['menu_location'].", menu_class= ".$val['menu_class']." WHERE menu_name='".$val['menu_name']."' AND menu_layout = '".$this->dbLayout."' LIMIT 1 ")) - { - $qry = " - INSERT into #menus - (`menu_name`, `menu_location`, `menu_order`, `menu_pages`,`menu_class`, `menu_path`, `menu_layout`) - VALUES ('{$val['menu_name']}', {$val['menu_location']}, {$val['menu_order']}, '', '{$val['menu_class']}', '{$row['menu_path']}', '".$this->dbLayout."') - "; - $sql->db_Select_gen($qry,$this->debug); - $admin_log->log_event('MENU_01',$row['menu_name'].'[!br!]'.$location.'[!br!]'.$menu_count.'[!br!]'.$row['menu_path'],E_LOG_INFORMATIVE,''); - - } - } - } - - return $menuAreas; - - } - - - // ---------------------------------------------------------------------------- - - function menuScanMenus() - { - global $sql, $sql2; - - $efile = new e_file; - $efile->dirFilter = array('/', 'CVS', '.svn', 'languages'); - $fileList = $efile->get_files(e_PLUGIN,"_menu\.php$",'standard',2); - foreach($fileList as $file) - { - list($parent_dir) = explode('/',str_replace(e_PLUGIN,"",$file['path'])); - $file['path'] = str_replace(e_PLUGIN,"",$file['path']); - $file['fname'] = str_replace(".php","",$file['fname']); - $valid_menu = FALSE; - $existing_menu = $sql->db_Count("menus", "(*)", "WHERE menu_name='{$file['fname']}'"); - if (file_exists(e_PLUGIN.$parent_dir.'/plugin.xml') || file_exists(e_PLUGIN.$parent_dir.'/plugin.php')) - { - if (plugInstalled($parent_dir)) - { // Its a 'new style' plugin with a plugin.php file, or an even newer one with plugin.xml file - only include if plugin installed - $valid_menu = TRUE; // Whether new or existing, include in list -// echo "Include {$parent_dir}:{$file['fname']}
"; - } - } - else - { // Just add the menu anyway - $valid_menu = TRUE; -// echo "Default Include {$parent_dir}:{$file['fname']}
"; - } - if ($valid_menu) - { - $menustr .= "&".str_replace(".php", "", $file['fname']); - if (!$existing_menu) - { // New menu to add to list - if($sql->db_Insert("menus", " 0, '{$file['fname']}', 0, 0, 0, '' ,'{$file['path']}', ''")) + else { - // Could do admin logging here - but probably not needed - $message .= MENLAN_10." - ".$file['fname']."
"; + if(strpos($check_url,$p) !== FALSE) + { + // $show_menu[$pkey] = TRUE; + $show_menu[$pkey] = $row['menu_name']; + } + } + } + } + elseif($listtype == '2') //hide menu + { + // $show_menu[$pkey] = TRUE; + $show_menu[$pkey] = $row['menu_name']; + foreach($pagelist as $p) { + if(substr($p, -1) == '!') + { + $p = substr($p, 0, -1); + if(substr($check_url, strlen($p)*-1) == $p) + { + // $show_menu[$pkey] = FALSE; + unset($show_menu[$pkey]); + } + } + else + { + if(strpos($check_url, $p) !== FALSE) + { + // $show_menu[$pkey] = FALSE; + unset($show_menu[$pkey]); + } } } } } - - //Reorder all menus into 1...x order - if (!is_object($sql2)) $sql2 = new db; // Shouldn't be needed - foreach ($this->menu_areas as $menu_act) - { - if ($sql->db_Select("menus", "menu_id", "menu_location={$menu_act} ORDER BY menu_order ASC")) + } + + e107::getRender()->eMenuTotal = count($show_menu); + + foreach($show_menu as $mpath=>$mname) + { + // $mname = $row['menu_name']; + if($error_handler->debug == true) { - $c = 1; - while ($row = $sql->db_Fetch()) + echo "\n\n"; + } + $sql->db_Mark_Time($mname); + if(is_numeric($mpath)) + { + $sql -> db_Select("page", "*", "page_id='".$mpath."' "); + $page = $sql -> db_Fetch(); + $caption = $e107->tp->toHTML($page['page_title'], TRUE, 'parse_sc, constants'); + $text = $e107->tp->toHTML($page['page_text'], TRUE, 'parse_sc, constants'); + e107::getRender()->tablerender($caption, $text); + } + else + { + if (is_readable(e_PLUGIN.$mpath."/languages/".e_LANGUAGE.".php")) { - $sql2->db_Update("menus", "menu_order={$c} WHERE menu_id=".$row['menu_id']); - $c++; + include_once(e_PLUGIN.$mpath."/languages/".e_LANGUAGE.".php"); + } + elseif (is_readable(e_PLUGIN.$mpath."/languages/".e_LANGUAGE."/".e_LANGUAGE.".php")) + { + include_once(e_PLUGIN.$mpath."/languages/".e_LANGUAGE."/".e_LANGUAGE.".php"); + } + elseif (is_readable(e_PLUGIN.$mpath."/languages/English.php")) + { + include_once(e_PLUGIN.$mpath."/languages/English.php"); + } + elseif (is_readable(e_PLUGIN.$mpath."/languages/English/English.php")) + { + include_once(e_PLUGIN.$mpath."/languages/English/English.php"); + } + + if(file_exists(e_PLUGIN.$mpath."/".$mname.".php")) + { + include_once(e_PLUGIN.$mpath."/".$mname.".php"); } } - } - - $sql->db_Select("menus", "*", "menu_path NOT REGEXP('[0-9]+') "); - while (list($menu_id, $menu_name, $menu_location, $menu_order) = $sql->db_Fetch(MYSQL_NUM)) - { - if (stristr($menustr, $menu_name) === FALSE) + $sql->db_Mark_Time("(After ".$mname.")"); + if ($error_handler->debug == true) { - $sql2->db_Delete("menus", "menu_name='$menu_name'"); - $message .= MENLAN_11." - ".$menu_name."
"; + echo "\n\n"; } + unset($caption,$text); // clear variables for proceeding menus. } - - $this->menuAddMessage($message, E_MESSAGE_INFO); - - } - - // --------------------------------------------------------------------------- - - - function menuPresetPerms($val) - { - $link_class = strtolower(trim($val)); - $menu_perm['everyone'] = e_UC_PUBLIC; - $menu_perm['guest'] = e_UC_GUEST; - $menu_perm['member'] = e_UC_MEMBER; - $menu_perm['mainadmin'] = e_UC_MAINADMIN; - $menu_perm['admin'] = e_UC_ADMIN; - $menu_perm['nobody'] = e_UC_NOBODY; - $link_class = ($menu_perm[$link_class]) ? $menu_perm[$link_class] : e_UC_PUBLIC; - - return $link_class; - } - - - - - - - function menuVisibilityOptions() - { - if(!$_GET['vis']) return; - - global $sql,$ns,$frm; - require_once(e_HANDLER."userclass_class.php"); - if(!$sql->db_Select("menus", "*", "menu_id=".intval($_GET['vis']))) + + + e107::getRender()->eMenuCount = 0; + e107::getRender()->eMenuArea = null; + + + if ($buffer_output) { - $this->menuAddMessage("Couldn't Load Menu",E_MESSAGE_ERROR); - return; - }; - $row = $sql->db_Fetch(); - $listtype = substr($row['menu_pages'], 0, 1); - $menu_pages = substr($row['menu_pages'], 2); - $menu_pages = str_replace("|", "\n", $menu_pages); - - $text = "
-
-
- ". MENLAN_7." ".$row['menu_name']." - - - - - - - - - - -
- - ".MENLAN_4." ". - r_userclass('menu_class', $row['menu_class'], "off", "public,member,guest,admin,main,classes,nobody")." -

"; - $checked = ($listtype == 1) ? " checked='checked' " : ""; - $text .= " ".MENLAN_26."
"; - $checked = ($listtype == 2) ? " checked='checked' " : ""; - $text .= " ".MENLAN_27."

".MENLAN_28."
"; - $text .= ""; - $text .= "
-
"; - // - $text .= $frm->admin_button('class_submit', MENLAN_6, 'update'); - - $text .= " -
-
-
-
"; - return $text; - $caption = MENLAN_7." ".$row['menu_name']; - $ns->tablerender($caption, $text); - } - - - - // ----------------------------------------------------------------------------- - - - function menuActivate() // Activate Multiple Menus. - { - global $sql, $admin_log, $pref; - - $location = $this->menuActivateLoc; - - $menu_count = $sql->db_Count("menus", "(*)", " WHERE menu_location=".$location." AND menu_layout = '".$this->dbLayout."' "); - - foreach($this->menuActivateIds as $sel_mens) - { - //Get info from menu being activated - if($sql->db_Select("menus", 'menu_name, menu_path' , "menu_id = ".$sel_mens." ")) - { - $row=$sql->db_Fetch(); - //If menu is not already activated in that area, add the record. - - $query = "SELECT menu_name,menu_path FROM #menus WHERE menu_name='".$row['menu_name']."' AND menu_layout = '".$this->dbLayout."' AND menu_location = ".$location." LIMIT 1 "; - - if(!$sql->db_Select_gen($query, $this->debug)) - { - $qry = " - INSERT into #menus - (`menu_name`, `menu_location`, `menu_order`, `menu_pages`, `menu_path`, `menu_layout`) - VALUES ('{$row['menu_name']}', {$location}, {$menu_count}, '', '{$row['menu_path']}', '".$this->dbLayout."') - "; - $sql->db_Select_gen($qry,$this->debug); - $admin_log->log_event('MENU_01',$row['menu_name'].'[!br!]'.$location.'[!br!]'.$menu_count.'[!br!]'.$row['menu_path'],E_LOG_INFORMATIVE,''); - $menu_count++; - } - } + $ret = ob_get_contents(); + ob_end_clean(); + return $ret; } } - - - - // ----------------------------------------------------------------------------- - - - function menuSetCustomPages($array) - { - global $pref; - $key = key($array); - $pref['sitetheme_custompages'][$key] = array_filter(explode(" ",$array[$key])); - save_prefs(); - } - - - // ------------------------------------------------------------------------------ - - function getMenuPreset() - { - global $pref; - - $layout = $this->curLayout; - - if(!isset($pref['sitetheme_layouts'][$layout]['menuPresets'])) - { - return FALSE; - } - - $temp = $pref['sitetheme_layouts'][$layout]['menuPresets']['area']; - - foreach($temp as $key=>$val) - { - $iD = $val['@attributes']['id']; - if(varset($val['menu'][1])) // More than one menu item under in theme.xml. - { - foreach($val['menu'] as $k=>$v) - { - // $uclass = (defined(trim($v['@attributes']['perm']))) ? constant(trim($v['@attributes']['userclass'])) : 0; - $menuArea[] = array( - 'menu_location' => $iD, - 'menu_order' => $k, - 'menu_name' => $v['@attributes']['name']."_menu", - 'menu_class' => $this->menuPresetPerms($v['@attributes']['perm']) - ); - } - } - else // Only one menu item under in theme.xml. - { - // $uclass = (defined(trim($val['menu']['@attributes']['userclass']))) ? constant(trim($val['menu']['@attributes']['userclass'])) : 0; - $menuArea[] = array( - 'menu_location' => $iD, - 'menu_order' => 0, - 'menu_name' => $val['menu']['@attributes']['name']."_menu", - 'menu_class' => $this->menuPresetPerms($v['@attributes']['perm']) - ); - } - } - - return $menuArea; - - } - - - // ------------------------------------------------------------------------------ - - function checkMenuPreset($array,$name) - { - if(!is_array($array)) - { - return; - } - foreach($array as $key=>$val) - { - if($val['menu_name']==$name) - { - return $val['menu_location']; - } - } - - return FALSE; - } - - - - // -------------------------------------------------------------------------- - - function menuSaveVisibility() - { - global $sql, $admin_log; - $pagelist = explode("\r\n", $_POST['pagelist']); - for ($i = 0 ; $i < count($pagelist) ; $i++) - { - $pagelist[$i] = trim($pagelist[$i]); - } - $plist = implode("|", $pagelist); - $pageparms = $_POST['listtype'].'-'.$plist; - $pageparms = preg_replace("#\|$#", "", $pageparms); - $pageparms = (trim($_POST['pagelist']) == '') ? '' : $pageparms; - - if($sql->db_Update("menus", "menu_class='".$_POST['menu_class']."', menu_pages='{$pageparms}' WHERE menu_id=".intval($this->menuId))) - { - $admin_log->log_event('MENU_02',$_POST['menu_class'].'[!br!]'.$pageparms.'[!br!]'.$this->menuId,E_LOG_INFORMATIVE,''); - $message = "
".MENLAN_8."
"; - $this->menuAddMessage($message,E_MESSAGE_SUCCESS); - } - else - { - $message = "the update failed"; - $this->menuAddMessage($message,E_MESSAGE_ERROR); - } - - } - - - - // ----------------------------------------------------------------------- - - function menuDeactivate() - { // Get current menu name - global $sql,$admin_log; - - if($sql->db_Select('menus', 'menu_name', 'menu_id='.$this->menuId, 'default')) - { - - $row = $sql->db_Fetch(); - //Check to see if there is already a menu with location = 0 (to maintain BC) - if($sql->db_Select('menus', 'menu_id', "menu_name='{$row['menu_name']}' AND menu_location = 0 AND menu_layout ='".$this->dbLayout."' LIMIT 1")) - { - //menu_location=0 already exists, we can just delete this record - $sql->db_Delete('menus', 'menu_id='.$this->menuId); - } - else - { - //menu_location=0 does NOT exist, let's just convert this to it - if(!$sql->db_Update("menus", "menu_location=0, menu_order=0, menu_class=0, menu_pages='' WHERE menu_id=".$this->menuId)) - { - $message = "FAILED"; - } - } - //Move all other menus up - $sql->db_Update("menus", "menu_order=menu_order-1 WHERE menu_location={$location} AND menu_order > {$position} AND menu_layout = '".$this->dbLayout."' "); - $admin_log->log_event('MENU_04',$row['menu_name'].'[!br!]'.$location.'[!br!]'.$position.'[!br!]'.$this->menuId,E_LOG_INFORMATIVE,''); - } - - echo $message; - } - - - // ---------------------------------------------------------------------- - - function menuMove() - {// Get current menu name - - global $admin_log,$sql; - - if($sql->db_Select('menus', 'menu_name', 'menu_id='.$this->menuId, 'default')) - { - $row = $sql->db_Fetch(); - //Check to see if menu is already active in the new area, if not then move it - if(!$sql->db_Select('menus', 'menu_id', "menu_name='{$row['menu_name']}' AND menu_location = ".$this->menuNewLoc." AND menu_layout='".$this->dbLayout ."' LIMIT 1")) - { - $menu_count = $sql->db_Count("menus", "(*)", " WHERE menu_location=".$this->menuNewLoc); - $sql->db_Update("menus", "menu_location='{$this->menuNewLoc}', menu_order=".($menu_count+1)." WHERE menu_id=".$this->menuId); - $sql->db_Update("menus", "menu_order=menu_order-1 WHERE menu_location='{$location}' AND menu_order > {$position} AND menu_layout='".$this->dbLayout ."' "); - } - $admin_log->log_event('MENU_03',$row['menu_name'].'[!br!]'.$this->menuNewLoc.'[!br!]'.$this->menuId,E_LOG_INFORMATIVE,''); - } - } - - - // =----------------------------------------------------------------------------- - - - function menuRenderPage() - { - global $sql, $ns, $HEADER, $FOOTER, $rs, $pref, $tp; - - echo "
"; - $this->parseheader($HEADER); // $layouts_str; - - $layout = ($this->curLayout); - $menuPreset = $this->getMenuPreset($layout); - - - echo "
"; - echo $rs->form_open("post", e_SELF."?configure.".$this->curLayout, "menuActivation"); - $text = ""; - - - $text .= ""; - $text .= ""; - - $text .= "
".MENLAN_36."......".MENLAN_37."
"; - - $sql->db_Select("menus", "menu_name, menu_id, menu_pages, menu_path", "1 GROUP BY menu_name ORDER BY menu_name ASC"); - - if(!$this->dragDrop) - { - $text .= "
"; - $text .= "\n"; - - } - else - { - $text .= "
\n"; - } - - $color = ""; - while ($row = $sql->db_Fetch()) - { - $pdeta = ""; - $color = ($color == "white") ? "#DDDDDD" : "white"; - if($row['menu_pages'] == "dbcustom") - { - $pdeta = MENLAN_42; - } - else - { - $row['menu_name'] = preg_replace("#_menu$#i", "", $row['menu_name']); - if($pnum = $this->checkMenuPreset($menuPreset,$row['menu_name'].'_menu')) - { - $pdeta = MENLAN_39." {$pnum}"; - } - } - - if(!$this->dragDrop) - { - $menuInf = (strlen($row['menu_path']) > 1) ? ' ('.substr($row['menu_path'],0,-1).')' : ''; - $text .= "
- - - \n"; - } - else - { - $text .= "
dbLayout."' style='border:1px outset black;text-align:left;color:black'> - -
".$row['menu_name']." {$pdeta}
-
"; - $text .= $this->menuRenderMenu($row,$menu_count); - $text .= "
\n"; - } - } - $text .= (!$this->dragDrop) ? "
".$row['menu_name'].$menuInf." ".$pdeta." 
" : ""; - $text .= "
"; - - $text .= "

"; - foreach ($this->menu_areas as $menu_act) - { - $text .= "

\n"; - } - - - if($layout) - { - if(isset($pref['sitetheme_layouts'][$layout]['menuPresets'])) - { - $text .= "toJS(MENLAN_41)."')\" />

\n"; // Use Menu Presets - $text .= ""; - } - $text .= ""; - } - - $text .= "
"; - $ns -> tablerender(MENLAN_22, $text); - echo $rs->form_close(); - echo "
"; - - - - $this->parseheader($FOOTER); - if($this->debug) - { - echo "
 
"; - } - echo "
"; - } - - - - - - //------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------// - function menuSelectLayout() - { - global $rs, $pref; - - $text .= "
"; - // color:white;background-color:black;width:98%;display:block;padding:15px;text-align:center - $text .= "
".MENLAN_30." "; - // $text .= "\n"; // window.frames['menu_iframe'].location=this.options[selectedIndex].value ??? - - $text .= " -
"; - return $text; - } - - //------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------// - function parseheader($LAYOUT, $check = FALSE) - { - // $tmp = explode("\n", $LAYOUT); - // Split up using the same function as the shortcode handler - $tmp = preg_split('#(\{\S[^\x02]*?\S\})#', $LAYOUT, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE ); - for ($c = 0; $c < count($tmp); $c++) - { - if (preg_match("/[\{|\}]/", $tmp[$c])) - { - if ($check) - { - if (strstr($tmp[$c], "{MENU=")) - { - $str[] = preg_replace("/\{MENU=(.*?)(:.*?)?\}/si", "\\1", $tmp[$c]); - } - } - else - { - $this->checklayout($tmp[$c],$this->curLayout); - } - } - else - { - if (!$check) - { - echo $tmp[$c]; - } - } - } - if ($check) - { - return $str; - } - } - - function checklayout($str) - { // Displays a basic representation of the theme - global $pref, $ns, $PLUGINS_DIRECTORY, $rs, $sc_style, $tp, $menu_order; - - $menuLayout = ($this->curLayout != $pref['sitetheme_deflayout']) ? $this->curLayout : ""; - - if (strstr($str, "LOGO")) - { - echo $tp -> parseTemplate("{LOGO}"); - } - else if(strstr($str, "SITENAME")) - { - echo "
[SiteName]
"; - } - else if (strstr($str, "SITETAG")) - { - echo "
[SiteTag]
"; - } - else if (strstr($str, "SITELINKS")) - { - echo "
[SiteLinks]
"; - } - else if (strstr($str, "LANGUAGELINKS")) - { - echo "
[Language]
"; - } - else if (strstr($str, "CUSTOM")) - { - $cust = preg_replace("/\W*\{CUSTOM=(.*?)(\+.*)?\}\W*/si", "\\1", $str); - echo "
[".$cust."]
"; - } - // Display embedded Plugin information. - else if (strstr($str, "PLUGIN")) - { - $plug = preg_replace("/\{PLUGIN=(.*?)\}/si", "\\1", $str); - $plug = trim($plug); - if (file_exists((e_PLUGIN."{$plug}/{$plug}_config.php"))) - { - $link = e_PLUGIN."{$plug}/{$plug}_config.php"; - } - - if(file_exists((e_PLUGIN.$plug."/config.php"))) - { - $link = e_PLUGIN.$plug."/config.php"; - } - - $plugtext = ($link) ? "(".MENLAN_34.":".LAN_CONFIGURE.")" : "(".MENLAN_34.")" ; - echo "
"; - $ns -> tablerender($plug, $plugtext); - } - else if (strstr($str, "MENU")) - { - // $ns = new e107table; - $menu = preg_replace("/\{MENU=(.*?)(:.*?)?\}/si", "\\1", $str); - if (isset($sc_style['MENU']['pre']) && strpos($str, 'ret') !== false) - { - echo $sc_style['MENU']['pre']; - } - echo " -
- -
- -
".MENLAN_14." ".$menu."

"; - $text = " "; - $sql9 = new db; - if ($sql9->db_Count("menus", "(*)", " WHERE menu_location='$menu' AND menu_layout = '".$this->dbLayout."' ")) - { - unset($text); - echo $rs->form_open("post", e_SELF."?configure.".$this->curLayout, "frm_menu_".intval($menu)); - - $MODE = 1; - - $sql9->db_Select("menus", "*", "menu_location='$menu' AND menu_layout='".$this->dbLayout."' ORDER BY menu_order"); - $menu_count = $sql9->db_Rows(); - while ($row = $sql9->db_Fetch(MYSQL_ASSOC)) - { - echo "\n\n\n \n\n -
dbLayout."'> - -
"; - - echo $this->menuRenderMenu($row,$menu_count); - - echo "\n
"; - echo "\n\n\n\n\n\n"; - echo "

"; - - - } - - echo $rs->form_close(); - } - echo "
"; - if(isset($sc_style['MENU']['post']) && strpos($str, 'ret') !== false) { - echo $sc_style['MENU']['post']; - } - } - else if (strstr($str, "SETSTYLE")) { - $tmp = explode("=", $str); - $style = preg_replace("/\{SETSTYLE=(.*?)\}/si", "\\1", $str); - } - else if (strstr($str, "SITEDISCLAIMER")) { - echo "[Sitedisclaimer]"; - } - } - //------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------// - - function menuRenderMenu($row,$menu_count ) - { - global $ns,$rs,$menu,$menu_info,$menu_act; - // $menu_count is empty in here - //FIXME extract - extract($row); - if(!$menu_id){ return; } - - $menu_name = preg_replace("#_menu#i", "", $menu_name); - //TODO we need a CSS class for this - $vis = ($menu_class || strlen($menu_pages) > 1) ? " * " : ""; - //DEBUG div not allowed in final tags $caption = "
{$menu_name}{$vis}
"; - // use theme render style instead - $caption = $menu_name.$vis; - $menu_info = "{$menu_location}.{$menu_order}"; - - $text = ""; - $conf = ''; - if (file_exists(e_PLUGIN.$menu_path.$menu_name.'_menu_config.php')) - { - $conf = $menu_path.$menu_name.'_menu_config.php'; - } - - if($conf == '' && file_exists(e_PLUGIN."{$menu_path}config.php")) - { - $conf = "{$menu_path}config"; - } - - $text .= " + ".MENLAN_4." ". + r_userclass('menu_class', $row['menu_class'], "off", "public,member,guest,admin,main,classes,nobody")." + + +
"; + $checked = ($listtype == 1) ? " checked='checked' " : ""; + $text .= " ".MENLAN_26."
"; + $checked = ($listtype == 2) ? " checked='checked' " : ""; + $text .= " ".MENLAN_27."

".MENLAN_28."
"; + $text .= ""; + $text .= " + +
"; + // + $text .= $frm->admin_button('class_submit', MENLAN_6, 'update'); + + $text .= " +
+ + + "; + return $text; + $caption = MENLAN_7." ".$row['menu_name']; + $ns->tablerender($caption, $text); + } + + + + // ----------------------------------------------------------------------------- + + + function menuActivate() // Activate Multiple Menus. + { + global $sql, $admin_log, $pref; + + $location = $this->menuActivateLoc; + + $menu_count = $sql->db_Count("menus", "(*)", " WHERE menu_location=".$location." AND menu_layout = '".$this->dbLayout."' "); + + foreach($this->menuActivateIds as $sel_mens) + { + //Get info from menu being activated + if($sql->db_Select("menus", 'menu_name, menu_path' , "menu_id = ".$sel_mens." ")) + { + $row=$sql->db_Fetch(); + //If menu is not already activated in that area, add the record. + + $query = "SELECT menu_name,menu_path FROM #menus WHERE menu_name='".$row['menu_name']."' AND menu_layout = '".$this->dbLayout."' AND menu_location = ".$location." LIMIT 1 "; + + if(!$sql->db_Select_gen($query, $this->debug)) + { + $qry = " + INSERT into #menus + (`menu_name`, `menu_location`, `menu_order`, `menu_pages`, `menu_path`, `menu_layout`) + VALUES ('{$row['menu_name']}', {$location}, {$menu_count}, '', '{$row['menu_path']}', '".$this->dbLayout."') + "; + $sql->db_Select_gen($qry,$this->debug); + $admin_log->log_event('MENU_01',$row['menu_name'].'[!br!]'.$location.'[!br!]'.$menu_count.'[!br!]'.$row['menu_path'],E_LOG_INFORMATIVE,''); + $menu_count++; + } + } + } + } + + + + // ----------------------------------------------------------------------------- + + + function menuSetCustomPages($array) + { + global $pref; + $key = key($array); + $pref['sitetheme_custompages'][$key] = array_filter(explode(" ",$array[$key])); + save_prefs(); + } + + + // ------------------------------------------------------------------------------ + + function getMenuPreset() + { + global $pref; + + $layout = $this->curLayout; + + if(!isset($pref['sitetheme_layouts'][$layout]['menuPresets'])) + { + return FALSE; + } + + $temp = $pref['sitetheme_layouts'][$layout]['menuPresets']['area']; + + foreach($temp as $key=>$val) + { + $iD = $val['@attributes']['id']; + if(varset($val['menu'][1])) // More than one menu item under in theme.xml. + { + foreach($val['menu'] as $k=>$v) + { + // $uclass = (defined(trim($v['@attributes']['perm']))) ? constant(trim($v['@attributes']['userclass'])) : 0; + $menuArea[] = array( + 'menu_location' => $iD, + 'menu_order' => $k, + 'menu_name' => $v['@attributes']['name']."_menu", + 'menu_class' => $this->menuPresetPerms($v['@attributes']['perm']) + ); + } + } + else // Only one menu item under in theme.xml. + { + // $uclass = (defined(trim($val['menu']['@attributes']['userclass']))) ? constant(trim($val['menu']['@attributes']['userclass'])) : 0; + $menuArea[] = array( + 'menu_location' => $iD, + 'menu_order' => 0, + 'menu_name' => $val['menu']['@attributes']['name']."_menu", + 'menu_class' => $this->menuPresetPerms($v['@attributes']['perm']) + ); + } + } + + return $menuArea; + + } + + + // ------------------------------------------------------------------------------ + + function checkMenuPreset($array,$name) + { + if(!is_array($array)) + { + return; + } + foreach($array as $key=>$val) + { + if($val['menu_name']==$name) + { + return $val['menu_location']; + } + } + + return FALSE; + } + + + + // -------------------------------------------------------------------------- + + function menuSaveVisibility() + { + global $sql, $admin_log; + $pagelist = explode("\r\n", $_POST['pagelist']); + for ($i = 0 ; $i < count($pagelist) ; $i++) + { + $pagelist[$i] = trim($pagelist[$i]); + } + $plist = implode("|", $pagelist); + $pageparms = $_POST['listtype'].'-'.$plist; + $pageparms = preg_replace("#\|$#", "", $pageparms); + $pageparms = (trim($_POST['pagelist']) == '') ? '' : $pageparms; + + if($sql->db_Update("menus", "menu_class='".$_POST['menu_class']."', menu_pages='{$pageparms}' WHERE menu_id=".intval($this->menuId))) + { + $admin_log->log_event('MENU_02',$_POST['menu_class'].'[!br!]'.$pageparms.'[!br!]'.$this->menuId,E_LOG_INFORMATIVE,''); + $message = "
".MENLAN_8."
"; + $this->menuAddMessage($message,E_MESSAGE_SUCCESS); + } + else + { + $message = "the update failed"; + $this->menuAddMessage($message,E_MESSAGE_ERROR); + } + + } + + + + // ----------------------------------------------------------------------- + + function menuDeactivate() + { // Get current menu name + global $sql,$admin_log; + + if($sql->db_Select('menus', 'menu_name', 'menu_id='.$this->menuId, 'default')) + { + + $row = $sql->db_Fetch(); + //Check to see if there is already a menu with location = 0 (to maintain BC) + if($sql->db_Select('menus', 'menu_id', "menu_name='{$row['menu_name']}' AND menu_location = 0 AND menu_layout ='".$this->dbLayout."' LIMIT 1")) + { + //menu_location=0 already exists, we can just delete this record + $sql->db_Delete('menus', 'menu_id='.$this->menuId); + } + else + { + //menu_location=0 does NOT exist, let's just convert this to it + if(!$sql->db_Update("menus", "menu_location=0, menu_order=0, menu_class=0, menu_pages='' WHERE menu_id=".$this->menuId)) + { + $message = "FAILED"; + } + } + //Move all other menus up + $sql->db_Update("menus", "menu_order=menu_order-1 WHERE menu_location={$location} AND menu_order > {$position} AND menu_layout = '".$this->dbLayout."' "); + $admin_log->log_event('MENU_04',$row['menu_name'].'[!br!]'.$location.'[!br!]'.$position.'[!br!]'.$this->menuId,E_LOG_INFORMATIVE,''); + } + + echo $message; + } + + + // ---------------------------------------------------------------------- + + function menuMove() + {// Get current menu name + + global $admin_log,$sql; + + if($sql->db_Select('menus', 'menu_name', 'menu_id='.$this->menuId, 'default')) + { + $row = $sql->db_Fetch(); + //Check to see if menu is already active in the new area, if not then move it + if(!$sql->db_Select('menus', 'menu_id', "menu_name='{$row['menu_name']}' AND menu_location = ".$this->menuNewLoc." AND menu_layout='".$this->dbLayout ."' LIMIT 1")) + { + $menu_count = $sql->db_Count("menus", "(*)", " WHERE menu_location=".$this->menuNewLoc); + $sql->db_Update("menus", "menu_location='{$this->menuNewLoc}', menu_order=".($menu_count+1)." WHERE menu_id=".$this->menuId); + $sql->db_Update("menus", "menu_order=menu_order-1 WHERE menu_location='{$location}' AND menu_order > {$position} AND menu_layout='".$this->dbLayout ."' "); + } + $admin_log->log_event('MENU_03',$row['menu_name'].'[!br!]'.$this->menuNewLoc.'[!br!]'.$this->menuId,E_LOG_INFORMATIVE,''); + } + } + + + // =----------------------------------------------------------------------------- + + + function menuRenderPage() + { + global $sql, $ns, $HEADER, $FOOTER, $rs, $pref, $tp; + + echo "
"; + $this->parseheader($HEADER); // $layouts_str; + + $layout = ($this->curLayout); + $menuPreset = $this->getMenuPreset($layout); + + + echo "
"; + echo $rs->form_open("post", e_SELF."?configure.".$this->curLayout, "menuActivation"); + $text = ""; + + + $text .= ""; + $text .= ""; + + $text .= "
".MENLAN_36."......".MENLAN_37."
"; + + $sql->db_Select("menus", "menu_name, menu_id, menu_pages, menu_path", "1 GROUP BY menu_name ORDER BY menu_name ASC"); + + if(!$this->dragDrop) + { + $text .= "
"; + $text .= "\n"; + + } + else + { + $text .= "
\n"; + } + + $color = ""; + while ($row = $sql->db_Fetch()) + { + $pdeta = ""; + $color = ($color == "white") ? "#DDDDDD" : "white"; + if($row['menu_pages'] == "dbcustom") + { + $pdeta = MENLAN_42; + } + else + { + $row['menu_name'] = preg_replace("#_menu$#i", "", $row['menu_name']); + if($pnum = $this->checkMenuPreset($menuPreset,$row['menu_name'].'_menu')) + { + $pdeta = MENLAN_39." {$pnum}"; + } + } + + if(!$this->dragDrop) + { + $menuInf = (strlen($row['menu_path']) > 1) ? ' ('.substr($row['menu_path'],0,-1).')' : ''; + $text .= "
+ + + \n"; + } + else + { + $text .= "
dbLayout."' style='border:1px outset black;text-align:left;color:black'> + +
".$row['menu_name']." {$pdeta}
+
"; + $text .= $this->menuRenderMenu($row,$menu_count); + $text .= "
\n"; + } + } + $text .= (!$this->dragDrop) ? "
".$row['menu_name'].$menuInf." ".$pdeta." 
" : ""; + $text .= "
"; + + $text .= "

"; + foreach ($this->menu_areas as $menu_act) + { + $text .= "

\n"; + } + + + if($layout) + { + if(isset($pref['sitetheme_layouts'][$layout]['menuPresets'])) + { + $text .= "toJS(MENLAN_41)."')\" />

\n"; // Use Menu Presets + $text .= ""; + } + $text .= ""; + } + + $text .= "
"; + $ns -> tablerender(MENLAN_22, $text); + echo $rs->form_close(); + echo "
"; + + + + $this->parseheader($FOOTER); + if($this->debug) + { + echo "
 
"; + } + echo "
"; + } + + + + + + //------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------// + function menuSelectLayout() + { + global $rs, $pref; + + $text .= "
"; + // color:white;background-color:black;width:98%;display:block;padding:15px;text-align:center + $text .= "
".MENLAN_30." "; + // $text .= "\n"; // window.frames['menu_iframe'].location=this.options[selectedIndex].value ??? + + $text .= " +
"; + return $text; + } + + //------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------// + function parseheader($LAYOUT, $check = FALSE) + { + // $tmp = explode("\n", $LAYOUT); + // Split up using the same function as the shortcode handler + $tmp = preg_split('#(\{\S[^\x02]*?\S\})#', $LAYOUT, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE ); + for ($c = 0; $c < count($tmp); $c++) + { + if (preg_match("/[\{|\}]/", $tmp[$c])) + { + if ($check) + { + if (strstr($tmp[$c], "{MENU=")) + { + $str[] = preg_replace("/\{MENU=(.*?)(:.*?)?\}/si", "\\1", $tmp[$c]); + } + } + else + { + $this->checklayout($tmp[$c],$this->curLayout); + } + } + else + { + if (!$check) + { + echo $tmp[$c]; + } + } + } + if ($check) + { + return $str; + } + } + + function checklayout($str) + { // Displays a basic representation of the theme + global $pref, $ns, $PLUGINS_DIRECTORY, $rs, $sc_style, $tp, $menu_order; + + $menuLayout = ($this->curLayout != $pref['sitetheme_deflayout']) ? $this->curLayout : ""; + + if (strstr($str, "LOGO")) + { + echo $tp -> parseTemplate("{LOGO}"); + } + else if(strstr($str, "SITENAME")) + { + echo "
[SiteName]
"; + } + else if (strstr($str, "SITETAG")) + { + echo "
[SiteTag]
"; + } + else if (strstr($str, "SITELINKS")) + { + echo "
[SiteLinks]
"; + } + else if (strstr($str, "LANGUAGELINKS")) + { + echo "
[Language]
"; + } + else if (strstr($str, "CUSTOM")) + { + $cust = preg_replace("/\W*\{CUSTOM=(.*?)(\+.*)?\}\W*/si", "\\1", $str); + echo "
[".$cust."]
"; + } + // Display embedded Plugin information. + else if (strstr($str, "PLUGIN")) + { + $plug = preg_replace("/\{PLUGIN=(.*?)\}/si", "\\1", $str); + $plug = trim($plug); + if (file_exists((e_PLUGIN."{$plug}/{$plug}_config.php"))) + { + $link = e_PLUGIN."{$plug}/{$plug}_config.php"; + } + + if(file_exists((e_PLUGIN.$plug."/config.php"))) + { + $link = e_PLUGIN.$plug."/config.php"; + } + + $plugtext = ($link) ? "(".MENLAN_34.":".LAN_CONFIGURE.")" : "(".MENLAN_34.")" ; + echo "
"; + $ns -> tablerender($plug, $plugtext); + } + else if (strstr($str, "MENU")) + { + // $ns = new e107table; + $menu = preg_replace("/\{MENU=(.*?)(:.*?)?\}/si", "\\1", $str); + if (isset($sc_style['MENU']['pre']) && strpos($str, 'ret') !== false) + { + echo $sc_style['MENU']['pre']; + } + echo " +
+ +
+ +
".MENLAN_14." ".$menu."

"; + $text = " "; + $sql9 = new db; + if ($sql9->db_Count("menus", "(*)", " WHERE menu_location='$menu' AND menu_layout = '".$this->dbLayout."' ")) + { + unset($text); + echo $rs->form_open("post", e_SELF."?configure.".$this->curLayout, "frm_menu_".intval($menu)); + + $MODE = 1; + + $sql9->db_Select("menus", "*", "menu_location='$menu' AND menu_layout='".$this->dbLayout."' ORDER BY menu_order"); + $menu_count = $sql9->db_Rows(); + while ($row = $sql9->db_Fetch(MYSQL_ASSOC)) + { + echo "\n\n\n \n\n +
dbLayout."'> + +
"; + + echo $this->menuRenderMenu($row,$menu_count); + + echo "\n
"; + echo "\n\n\n\n\n\n"; + echo "

"; + + + } + + echo $rs->form_close(); + } + echo "
"; + if(isset($sc_style['MENU']['post']) && strpos($str, 'ret') !== false) { + echo $sc_style['MENU']['post']; + } + } + else if (strstr($str, "SETSTYLE")) { + $tmp = explode("=", $str); + $style = preg_replace("/\{SETSTYLE=(.*?)\}/si", "\\1", $str); + } + else if (strstr($str, "SITEDISCLAIMER")) { + echo "[Sitedisclaimer]"; + } + } + //------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------// + + function menuRenderMenu($row,$menu_count ) + { + global $ns,$rs,$menu,$menu_info,$menu_act; + // $menu_count is empty in here + //FIXME extract + extract($row); + if(!$menu_id){ return; } + + $menu_name = preg_replace("#_menu#i", "", $menu_name); + //TODO we need a CSS class for this + $vis = ($menu_class || strlen($menu_pages) > 1) ? " * " : ""; + //DEBUG div not allowed in final tags $caption = "
{$menu_name}{$vis}
"; + // use theme render style instead + $caption = $menu_name.$vis; + $menu_info = "{$menu_location}.{$menu_order}"; + + $text = ""; + $conf = ''; + if (file_exists(e_PLUGIN.$menu_path.$menu_name.'_menu_config.php')) + { + $conf = $menu_path.$menu_name.'_menu_config.php'; + } + + if($conf == '' && file_exists(e_PLUGIN."{$menu_path}config.php")) + { + $conf = "{$menu_path}config"; + } + + $text .= "