diff --git a/e107_admin/menus.php b/e107_admin/menus.php index 3769d2c73..956baa0dd 100644 --- a/e107_admin/menus.php +++ b/e107_admin/menus.php @@ -11,8 +11,8 @@ | GNU General Public License (http://gnu.org). | | $Source: /cvs_backup/e107_0.8/e107_admin/menus.php,v $ -| $Revision: 1.23 $ -| $Date: 2009-07-09 11:37:36 $ +| $Revision: 1.24 $ +| $Date: 2009-07-10 14:27:30 $ | $Author: e107coders $ +----------------------------------------------------------------------------+ */ @@ -23,970 +23,1097 @@ if (!getperms("2")) exit; } $e_sub_cat = 'menus'; -require_once("auth.php"); -require_once(e_HANDLER."form_handler.php"); + + require_once(e_HANDLER."file_class.php"); -$frm = new form; +require_once(e_HANDLER."form_handler.php"); + + + $frm = new form; + $men = new menuManager(1); // use 1 for dragdrop. + $menu->debug = FALSE; + + + + + if(isset($_GET['ajax'])) + { + $men->menuSaveAjax(); + exit; + } + +require_once("auth.php"); + + + + + if($_POST) { -// print_a($_POST); + // print_a($_POST); // exit; $e107cache->clear_sys("menus_"); } - $tmp = explode('.', e_QUERY); - $curLayout = ($tmp[1]) ? $tmp[1] : $pref['sitetheme_deflayout'] ; - - if(isset($_POST['custom_select'])) - { - $curLayout = $_POST['custom_select']; - } - // Almost the same code as found in templates/header_default.php --------- - - - if(($curLayout == 'legacyCustom' || $curLayout=='legacyDefault') && (isset($CUSTOMHEADER) || isset($CUSTOMFOOTER)) ) // 0.6 themes. - { - if($curLayout == 'legacyCustom') + if ($message != "") { - $HEADER = ($CUSTOMHEADER) ? $CUSTOMHEADER : $HEADER; - $FOOTER = ($CUSTOMFOOTER) ? $CUSTOMFOOTER : $FOOTER; - } - } - elseif($curLayout && $curLayout != "legacyCustom" && (isset($CUSTOMHEADER[$curLayout]) || isset($CUSTOMHEADER[$curLayout]))) // 0.7 themes - { - // echo " MODE 0.7"; - $HEADER = ($CUSTOMHEADER[$curLayout]) ? $CUSTOMHEADER[$curLayout] : $HEADER; - $FOOTER = ($CUSTOMFOOTER[$curLayout]) ? $CUSTOMFOOTER[$curLayout] : $FOOTER; - } - elseif($curLayout && isset($HEADER[$curLayout]) && isset($FOOTER[$curLayout])) // 0.8 themes - we use only $HEADER and $FOOTER arrays. - { - // echo " MODE 0.8"; - $HEADER = $HEADER[$curLayout]; - $FOOTER = $FOOTER[$curLayout]; - } - - // ------------------------------------------------------------------------ - - - $layouts_str = $HEADER.$FOOTER; - - - if ($NEWSHEADER) - { - $layouts_str .= $NEWSHEADER; - } - - $menu_array = parseheader($layouts_str, 'check'); - - - sort($menu_array, SORT_NUMERIC); - $menu_check = 'set'; - foreach ($menu_array as $menu_value) - { - if ($menu_value != $menu_check) - { - $menu_areas[] = $menu_value; - } - $menu_check = $menu_value; - } - - // Cams Bit ----------- Activate Multiple Menus --- - if($_POST['menuActivate']) - { - menuActivate(); - - } - - if($_POST['menuSetCustomPages']) - { - menuSetCustomPages($_POST['custompages']); - } - - if(isset($_POST['menuUsePreset']) && $_POST['curLayout']) - { - - menuSetPreset(); - } - - - if (isset($_POST['menuAct'])) - { - foreach ($_POST['menuAct'] as $k => $v) - { - if (trim($v)) - { - $id = $k; - list($menu_act, $location, $position, $newloc) = explode(".", $_POST['menuAct'][$k]); - } - } - } - - if ($menu_act == 'config') - { - if($newloc) - { - $newloc = ".".$newloc; - } - $newurl = $PLUGINS_DIRECTORY.$location."/{$position}{$newloc}.php"; - $newurl = SITEURL.str_replace("//", "/", $newurl); - echo " "; - exit; - } - - if ($menu_act == "adv") - { - menuVisibilityOptions(); - } - - - - unset($message); - - if ($menu_act == "sv") - { - menuSaveVisibility(); - - } - - if ($menu_act == "move") - { - menuMove(); - } - - if ($menu_act == "deac") - { - menuDeactivate(); - } - - if ($menu_act == "bot") - { - $menu_count = $sql->db_Count("menus", "(*)", " WHERE menu_location='{$location}' AND menu_layout = '$curLayout' "); - $sql->db_Update("menus", "menu_order=".($menu_count+1)." WHERE menu_order='{$position}' AND menu_location='{$location}' AND menu_layout = '$curLayout' "); - $sql->db_Update("menus", "menu_order=menu_order-1 WHERE menu_location='{$location}' AND menu_order > {$position} AND menu_layout = '$curLayout' "); - $admin_log->log_event('MENU_06',$location.'[!br!]'.$position.'[!br!]'.$id,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 = '$curLayout' "); - $sql->db_Update("menus", "menu_order=1 WHERE menu_id='{$id}' "); - $admin_log->log_event('MENU_05',$location.'[!br!]'.$position.'[!br!]'.$id,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 = '$curLayout' "); - $sql->db_Update("menus", "menu_order=menu_order+1 WHERE menu_id='{$id}' AND menu_location='{$location}' AND menu_layout = '$curLayout' "); - $admin_log->log_event('MENU_08',$location.'[!br!]'.$position.'[!br!]'.$id,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 = '$curLayout' "); - $sql->db_Update("menus", "menu_order=menu_order-1 WHERE menu_id='{$id}' AND menu_location='{$location}' AND menu_layout = '$curLayout' "); - $admin_log->log_event('MENU_07',$location.'[!br!]'.$position.'[!br!]'.$id,E_LOG_INFORMATIVE,''); - } - - if (strpos(e_QUERY, 'configure') === FALSE) - { // Scan plugin directories to see if menus to add - menuScanMenus(); - } - - if ($message != "") - { - echo $ns -> tablerender('Updated', "
".$message."


"); - } - - - if (strpos(e_QUERY, 'configure') === FALSE) - { - $cnt = $sql->db_Select("menus", "*", "menu_location > 0 AND menu_layout = '$curLayout' ORDER BY menu_name "); // calculate height to remove vertical scroll-bar. - $text = ""; - $ns -> tablerender(MENLAN_35, $text, 'menus_config'); - } - else // Within the IFrame. - { - - echo menuSelectLayout(); - menuRenderPage(); - - } - - - - -// ---------------------------------------------------------------------------- - -function menuSetPreset() -{ - global $pref,$sql,$location,$admin_log; - $layout = ($_POST['curLayout'] != $pref['sitetheme_deflayout']) ? $_POST['curLayout'] : ""; - $menuAreas = getMenuPreset($_POST['curLayout']); - - $sql->db_Update("menus", "menu_location='0' WHERE menu_layout = '$layout' "); // 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 = '$layout' 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']}', '{$layout}') - "; - $sql->db_Select_gen($qry); - $admin_log->log_event('MENU_01',$row['menu_name'].'[!br!]'.$location.'[!br!]'.$menu_count.'[!br!]'.$row['menu_path'],E_LOG_INFORMATIVE,''); - - } - } - } - -} - - -// ---------------------------------------------------------------------------- - -function menuScanMenus() -{ - global $sql, $sql2, $menu_areas; - - $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")) - { - // include(e_PLUGIN.$parent_dir."/plugin.php"); - if (isset($pref['plug_installed'][$parent_dir])) - // if ($sql->db_Select("plugin", "*", "plugin_path='".$eplug_folder."' AND plugin_installflag='1' ")) - { // 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 - } - } - else - { // Just add the menu anyway - $valid_menu = TRUE; - } - 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']}', ''")) - { - // Could do admin logging here - but probably not needed - $message .= "".MENLAN_10." - ".$file['fname']."
"; - } - } - } + echo $ns -> tablerender('Updated', "
".$message."


"); } - //Reorder all menus into 1...x order - if (!is_object($sql2)) $sql2 = new db; // Shouldn't be needed - foreach ($menu_areas as $menu_act) + + if (strpos(e_QUERY, 'configure') === FALSE) { - if ($sql->db_Select("menus", "menu_id", "menu_location={$menu_act} ORDER BY menu_order ASC")) - { - $c = 1; - while ($row = $sql->db_Fetch()) - { - $sql2->db_Update("menus", "menu_order={$c} WHERE menu_id=".$row['menu_id']); - $c++; - } - } + $cnt = $sql->db_Select("menus", "*", "menu_location > 0 AND menu_layout = '$curLayout' ORDER BY menu_name "); // calculate height to remove vertical scroll-bar. + $text = ""; + $ns -> tablerender(MENLAN_35, $text, 'menus_config'); } - - $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)) + else // Within the IFrame. { - if (stristr($menustr, $menu_name) === FALSE) - { - $sql2->db_Delete("menus", "menu_name='$menu_name'"); - $message .= "".MENLAN_11." - ".$menu_name."
"; - } + + echo "
+ e_QUERY = ".e_QUERY."
+ curLayout = ".$men->curLayout."
+ dbLayout = ".$men->dbLayout."
+
"; + + + echo $men->menuSelectLayout(); + $men->menuRenderPage(); + } - echo $message; -} - -// --------------------------------------------------------------------------- - -function menuVisibilityOptions() -{ - global $sql,$ns,$id,$curLayout; - require_once(e_HANDLER."userclass_class.php"); - $sql->db_Select("menus", "*", "menu_id=".$id); - $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_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 .= " -

- -
-
-
"; - $caption = MENLAN_7." ".$row['menu_name']; - $ns->tablerender($caption, $text); -} - - - // ----------------------------------------------------------------------------- +class menuManager{ -function menuActivate() -{ - global $sql, $admin_log, $pref; - $location = key($_POST['menuActivate']); + var $menu_areas = array(); + var $curLayout; + var $menuId; + var $menuNewLoc; + var $dragDrop; + var $menuActivateLoc; + var $menuActivateIds; + var $debug; - $layout = ($_POST['curLayout'] != $pref['sitetheme_deflayout']) ? $_POST['curLayout'] : ""; - - $menu_count = $sql->db_Count("menus", "(*)", " WHERE menu_location=".$location." AND menu_layout = '$layout' "); - - foreach($_POST['menuselect'] as $sel_mens) - { - //Get info from menu being activated - if($sql->db_Select("menus", 'menu_name, menu_path' , "menu_id = ".$sel_mens." ")) + function menuManager($dragdrop=FALSE) { - $row=$sql->db_Fetch(); - //If menu is not already activated in that area, add the record. + global $pref, $HEADER,$FOOTER, $NEWSHEADER; - if(!$sql->db_Select('menus', 'menu_name,menu_path', " menu_name='".$row['menu_name']."' AND menu_layout = '$layout' AND menu_location = ".$location." LIMIT 1 ")) - { - $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']}', '{$layout}') - "; - $sql->db_Select_gen($qry); - $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($layout) -{ - global $pref; - - // print_a($pref['sitetheme_layouts'][$layout]['menuPresets']); - if(!isset($pref['sitetheme_layouts'][$layout]['menuPresets'])) - { - return; - } - - $temp = $pref['sitetheme_layouts'][$layout]['menuPresets']['area']; - - foreach($temp as $key=>$val) - { - $iD = $val['@attributes']['id']; - foreach($val['menu'] as $k=>$v) - { - $uclass = (defined(trim($v['@attributes']['userclass']))) ? constant(trim($v['@attributes']['userclass'])) : 0; - $menuArea[] = array( - 'menu_location' => $iD, - 'menu_order' => $k, - 'menu_name' => $v['@attributes']['name']."_menu", - 'menu_class' => intval($uclass) - ); - } - } - - 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,$id; - $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($id))) - { - $admin_log->log_event('MENU_02',$_POST['menu_class'].'[!br!]'.$pageparms.'[!br!]'.$id,E_LOG_INFORMATIVE,''); - $message = "
".MENLAN_8."
"; - } - else - { - $message = "the update failed"; - - } - - echo $message; - -} - - - -// ----------------------------------------------------------------------- - -function menuDeactivate() -{ // Get current menu name - global $sql,$admin_log,$id,$curLayout; - - if($sql->db_Select('menus', 'menu_name', 'menu_id='.$id, '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 ='".$curLayout."' LIMIT 1")) - { - //menu_location=0 already exists, we can just delete this record - $sql->db_Delete('menus', 'menu_id='.$id); - } - 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=".$id)) - { - $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 = '".$curLayout."' "); - $admin_log->log_event('MENU_04',$row['menu_name'].'[!br!]'.$location.'[!br!]'.$position.'[!br!]'.$id,E_LOG_INFORMATIVE,''); - } - - echo $message; -} - - -// ---------------------------------------------------------------------- - -function menuMove() -{// Get current menu name - - global $id,$admin_log,$sql,$newloc, $curLayout; - - if($sql->db_Select('menus', 'menu_name', 'menu_id='.$id, '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 = ".$newloc." AND menu_layout='".$curLayout ."' LIMIT 1")) - { - $menu_count = $sql->db_Count("menus", "(*)", " WHERE menu_location=".$newloc); - $sql->db_Update("menus", "menu_location='{$newloc}', menu_order=".($menu_count+1)." WHERE menu_id=".$id); - $sql->db_Update("menus", "menu_order=menu_order-1 WHERE menu_location='{$location}' AND menu_order > {$position} AND menu_layout='".$curLayout ."' "); - } - $admin_log->log_event('MENU_03',$row['menu_name'].'[!br!]'.$newloc.'[!br!]'.$id,E_LOG_INFORMATIVE,''); - } -} - - -// =----------------------------------------------------------------------------- - - -function menuRenderPage() -{ - global $sql, $ns, $HEADER, $FOOTER, $frm, $curLayout, $pref, $tp, $menu_areas; - - parseheader($HEADER); // $layouts_str; - - $layout = ($curLayout) ? $curLayout : $pref['sitetheme_deflayout']; - $menuPreset = getMenuPreset($layout); - - - echo "
"; - echo $frm->form_open("post", e_SELF."?configure.".$curLayout, "menuActivation"); - $text = ""; - - $sql->db_Select("menus", "menu_name, menu_id, menu_pages", "1 GROUP BY menu_name ORDER BY menu_name ASC"); - $text .= ""; - $text .= ""; - - $text .= "
".MENLAN_36."......".MENLAN_37."
"; - - - $text .= "
- \n"; - 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 = checkMenuPreset($menuPreset,$row['menu_name']."_menu")) - { - $pdeta = MENLAN_39." {$pnum}"; - } - } - - - $text .= " - - - \n"; - - } - $text .= "
".$row['menu_name']." ".$pdeta." 
"; - - $text .= "

"; - foreach ($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 .= "
"; - echo $ns -> tablerender(MENLAN_22, $text); - echo $frm->form_close(); - echo "
"; - - parseheader($FOOTER); -} - - - - - -//------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------// -function menuSelectLayout() -{ - global $frm, $curLayout, $pref, $HEADER, $CUSTOMHEADER, $CUSTOMFOOTER, $CUSTOMPAGES; - - $text .= "
"; - $text .= "
".MENLAN_30." "; - $text .= "
"; - return $text; - - - if(is_array($HEADER)) - { - foreach($HEADER as $key=>$val) - { - $default = ($curLayout == $key || $curLayout == 'default_layout' ) ? "selected" : FALSE; - $deftext = ($key==$pref['sitetheme_deflayout']) ? " (".MENLAN_31.")" : ""; - $diz = str_replace("_"," ",$key); - $text .= $frm->form_option(ucwords($diz).$deftext, $default, $key); - } - } - else - { - $text .= $frm->form_option(MENLAN_31, '', ''); - } - - if($CUSTOMHEADER && !is_array($CUSTOMHEADER)) - { - $CUSTOMHEADER = array('legacyCustom'=>$CUSTOMHEADER); - } - - if($CUSTOMFOOTER && !is_array($CUSTOMFOOTER)) - { - $CUSTOMFOOTER = array('legacyCustom'=> $CUSTOMFOOTER); - - } - - if(is_array($CUSTOMHEADER) || is_array($CUSTOMFOOTER)) - { - $customlist = (is_array($CUSTOMHEADER)) ? array_merge($CUSTOMHEADER,$CUSTOMFOOTER) : $CUSTOMFOOTER; - foreach($customlist as $key=>$val) - { - $selected = ($curLayout == $key || $curLayout == 'default_layout' ) ? "selected='selected'" : ""; - $deftext = ($key==$pref['sitetheme_deflayout']) ? " (".MENLAN_31.")" : ""; - $diz = ($key == "legacyCustom") ? MENLAN_33 : str_replace("_"," ",$key); - $text .= "\n"; - // $text .= $frm->form_option(ucwords($diz).$deftext, $default, $key); - } - } - - - - $text .= ""; - - // TO-DO Saving of the custompage preference for each layout. - /* - if($curLayout && ($curLayout != $pref['sitetheme_deflayout'])) - { - - if(!isset($pref['sitetheme_custompages'][$curLayout])) - { - if(isset($pref['sitetheme_layouts'][$curLayout]['customPages'])) - { - $custPages = $pref['sitetheme_layouts'][$curLayout]['customPages']; - } - elseif(isset($CUSTOMPAGES[$curLayout]) && $curLayout !='legacyCustom') - { - $custPages = $CUSTOMPAGES[$curLayout]; - } - elseif($CUSTOMPAGES) - { - $custPages = $CUSTOMPAGES; - - } - - menuSetCustomPages(array($curLayout=>$custPages)); - } - else - { - $custPages = $pref['sitetheme_custompages'][$curLayout]; - } - - $text .= "
Displays on these pages: - -
"; - }*/ - $text .= " - "; - return $text; - -} - -//------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------// -function parseheader($LAYOUT, $check = FALSE) -{ - global $curLayout; -// $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 - { - checklayout($tmp[$c],$curLayout); - } - } - else - { - if (!$check) - { - echo $tmp[$c]; - } - } - } - if ($check) - { - return $str; - } -} - -function checklayout($str,$curLayout) -{ // Displays a basic representation of the theme - global $pref, $menu_areas, $ns, $PLUGINS_DIRECTORY, $frm, $sc_style, $tp, $menu_order; - - $menuLayout = ($curLayout != $pref['sitetheme_deflayout']) ? $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.":".MENLAN_16.")" : "(".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 = '$menuLayout' ")) - { - unset($text); - echo $frm->form_open("post", e_SELF."?configure.".$curLayout, "frm_menu_".intval($menu)); - - $sql9->db_Select("menus", "*", "menu_location='$menu' AND menu_layout='$menuLayout' ORDER BY menu_order"); - $menu_count = $sql9->db_Rows(); - while (list($menu_id, $menu_name, $menu_location, $menu_order, $menu_class, $menu_pages, $menu_path) = $sql9->db_Fetch(MYSQL_NUM)) { - $menu_name = preg_replace("#_menu#i", "", $menu_name); - $vis = ($menu_class || strlen($menu_pages) > 1) ? " * " : - ""; - $caption = "
{$menu_name}{$vis}
"; - $menu_info = "{$menu_location}.{$menu_order}"; - - $text = ""; - $conf = ''; - if (file_exists(e_PLUGIN."{$menu_path}/{$menu_name}_menu_config.php")) + $this->dragDrop = $dragdrop; + if($this->dragDrop) { - $conf = "config.{$menu_path}.{$menu_name}_menu_config"; + $this->debug = TRUE; } - if($conf == '' && file_exists(e_PLUGIN."{$menu_path}/config.php")) + if ($NEWSHEADER) { - $conf = "config.{$menu_path}.config"; + $HEADER .= $NEWSHEADER; } - $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 .= " + +
+ + + + + + "; + $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; + // print_a($pref['sitetheme_layouts'][$layout]['menuPresets']); + if(!isset($pref['sitetheme_layouts'][$layout]['menuPresets'])) + { + return; + } + + $temp = $pref['sitetheme_layouts'][$layout]['menuPresets']['area']; + + foreach($temp as $key=>$val) + { + $iD = $val['@attributes']['id']; + foreach($val['menu'] as $k=>$v) + { + $uclass = (defined(trim($v['@attributes']['userclass']))) ? constant(trim($v['@attributes']['userclass'])) : 0; + $menuArea[] = array( + 'menu_location' => $iD, + 'menu_order' => $k, + 'menu_name' => $v['@attributes']['name']."_menu", + 'menu_class' => intval($uclass) + ); + } + } + + 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."
"; + } + else + { + $message = "the update failed"; + + } + + echo $message; + + } + + + + // ----------------------------------------------------------------------- + + function menuDeactivate() + { // Get current menu name + global $sql,$admin_log; + + echo "ID = ".$this->menuId; + 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 { - $text .= $frm->form_option(MENLAN_31, FALSE, 'default_layout'); + //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,''); + } - if ($NEWSHEADER) + echo $message; + } + + + // ---------------------------------------------------------------------- + + function menuMove() + {// Get current menu name + + global $admin_log,$sql; + + if($sql->db_Select('menus', 'menu_name', 'menu_id='.$this->menuId, 'default')) { - if ($curLayout == 'newsheader_layout') + $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")) { - $text .= $frm->form_option(MENLAN_32, 'selected', 'newsheader_layout'); - } - else - { - $text .= $frm->form_option(MENLAN_32, FALSE, 'newsheader_layout'); + $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,''); } + } - if ($CUSTOMPAGES) + + // =----------------------------------------------------------------------------- + + + function menuRenderPage() + { + global $sql, $ns, $HEADER, $FOOTER, $frm, $pref, $tp; + + echo "
"; + $this->parseheader($HEADER); // $layouts_str; + + $layout = ($this->curLayout); + $menuPreset = $this->getMenuPreset($layout); + + + echo "
"; + echo $frm->form_open("post", e_SELF."?configure.".$this->curLayout, "menuActivation"); + $text = ""; + + + $text .= ""; + $text .= "
".MENLAN_36."......".MENLAN_37."
"; + + $sql->db_Select("menus", "menu_name, menu_id, menu_pages", "1 GROUP BY menu_name ORDER BY menu_name ASC"); + + if(!$this->dragDrop) + { + $text .= "
"; + $text .= "\n"; + + } + else + { + $text .= "
\n"; + } + + + while ($row = $sql->db_Fetch()) + { + $pdeta = ""; + $color = ($color == "white") ? "#DDDDDD" : "white"; + if($row['menu_pages'] == "dbcustom") { - if (is_array($CUSTOMPAGES)) + $pdeta = MENLAN_42; + } + else + { + $row['menu_name'] = preg_replace("#_menu$#i", "", $row['menu_name']); + if($pnum = $this->checkMenuPreset($menuPreset,$row['menu_name']."_menu")) { - foreach ($CUSTOMPAGES as $custom_pages_key => $custom_pages_value) - { - if ($curLayout == $custom_pages_key) - { - $text .= $frm->form_option($custom_pages_key, 'selected', $custom_pages_key); - } - else - { - $text .= $frm->form_option($custom_pages_key, FALSE, $custom_pages_key); - } - } - } - else - { - if ($curLayout == 'custom_layout') - { - $text .= $frm->form_option(MENLAN_33, 'selected', 'custom_layout'); - } - else - { - $text .= $frm->form_option(MENLAN_33, FALSE, 'custom_layout'); - } + $pdeta = MENLAN_39." {$pnum}"; } } - $text .= $frm->form_select_close(); + if(!$this->dragDrop) + { + $text .= "
+ + + \n"; + } + else + { + $text .= "
- $text .= " - -
".$row['menu_name']." ".$pdeta." 
- "; +
".$row['menu_name']." $pdeta
+
"; + $text .= $this->menuRenderMenu($row,$menu_count); + $text .= "
\n"; + } + } + $text .= (!$this->dragDrop) ? "
" : ""; + $text .= "
"; - $ns->tablerender(MENLAN_29, $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 .= ""; + + $text .= ""; + $ns -> tablerender(MENLAN_22, $text); + echo $frm->form_close(); + echo "
"; + + + + $this->parseheader($FOOTER); + echo "
 
"; + + echo ""; + } + + + + + + //------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------// + function menuSelectLayout() + { + global $frm, $pref; + + $text .= "
"; + $text .= "
".MENLAN_30." "; + $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, $frm, $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.":".MENLAN_16.")" : "(".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 $frm->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 +
+ +
"; + + echo $this->menuRenderMenu($row,$menu_count); + + echo "\n
"; + echo "\n\n\n\n\n\n"; + echo "

"; + + + } + + echo $frm->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,$frm,$menu,$menu_info,$menu_act; + // $menu_count is empty in here + extract($row); + if(!$menu_id){ return; } + + $menu_name = preg_replace("#_menu#i", "", $menu_name); + $vis = ($menu_class || strlen($menu_pages) > 1) ? " * " : ""; + $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 = "config.{$menu_path}.{$menu_name}_menu_config"; + } + + if($conf == '' && file_exists(e_PLUGIN."{$menu_path}/config.php")) + { + $conf = "config.{$menu_path}.config"; + } + + $text .= "