From 5c9e04373ecb75b5c35fa9d472aa06296fbc962a Mon Sep 17 00:00:00 2001 From: Cameron Date: Sun, 17 Jan 2021 09:10:00 -0800 Subject: [PATCH] Moved methods from e_menu_layout to e_layout. --- e107_admin/menus.php | 318 +++++++++++++++++++++++++- e107_handlers/e107_class.php | 4 +- e107_handlers/js_manager.php | 4 +- e107_handlers/menumanager_class.php | 343 ---------------------------- 4 files changed, 318 insertions(+), 351 deletions(-) diff --git a/e107_admin/menus.php b/e107_admin/menus.php index ce194086a..3f72e0667 100644 --- a/e107_admin/menus.php +++ b/e107_admin/menus.php @@ -649,7 +649,7 @@ if(!function_exists('e_help')) } - return e_menu_layout::menuSelector(); + return e_layout::menuSelector(); } } @@ -886,9 +886,319 @@ class e_layout } - - - + public static function menuSelector() + { + + // $p = e107::getPref('e_menu_list'); // new storage for xxxxx_menu.php list. + $sql = e107::getDb(); + $frm = e107::getForm(); + + $done = array(); + + $pageMenu = array(); + $pluginMenu = array(); + + $sql->select("menus", "menu_name, menu_id, menu_pages, menu_path", "1 ORDER BY menu_name ASC"); + while($row = $sql->fetch()) + { + + if(in_array($row['menu_name'], $done)) + { + continue; + } + + $done[] = $row['menu_name']; + + if(is_numeric($row['menu_path'])) + { + $pageMenu[] = $row; + } + else + { + $pluginMenu[] = $row; + } + + } + + $tab1 = ''; + + $tab2 = ''; + + $tabs = array( + 'custom' => array('caption' => '', 'text' => $tab1), + 'plugin' => array('caption' => '', 'text' => $tab2) + + ); + + + $defLayout = e107::getRegistry('core/e107/menu-manager/curLayout');; + + $text = '
'; + + $text .= ""; + + + $layouts = self::getLayouts(); + $tp = e107::getParser(); + + // var_dump($layouts['menus']); + + + $text .= ' + + '; + + + $text .= $frm->tabs($tabs); + + + $text .= '
'; + + $tp = e107::getParser(); + + $caption = MENLAN_22;; + + + return array('caption' => $caption, 'text' => $text); + + + } + + public static function getLayouts($theme = null) + { + + if(empty($theme)) + { + $theme = e107::pref('core', 'sitetheme'); + } + + $sql = e107::getDb(); // required + $tp = e107::getParser(); + + $HEADER = null; + $FOOTER = null; + $LAYOUT = null; + $CUSTOMHEADER = null; + $CUSTOMFOOTER = null; + + $path = e_THEME . $theme . '/'; + $file = $path . "theme.php"; + + if(!is_readable($file)) + { + return false; + } + + e107::set('css_enabled', false); + e107::set('js_enabled', false); + + // new v2.2.2 HTML layout support. + if(is_dir($path . "layouts") && is_readable($path . "theme.html")) + { + $lyt = scandir($path . "layouts"); + $LAYOUT = array(); + + foreach($lyt as $lays) + { + if($lays === '.' || $lays === '..') + { + continue; + } + + $key = str_replace("_layout.html", '', $lays); + + if($lm = e_theme::loadLayout($key, $theme)) + { + $LAYOUT = $LAYOUT + $lm; + } + + } + + } + else // prior to v2.2.2 + { + + $themeFileContent = file_get_contents($file); + + $srch = array(''); + + $themeFileContent = preg_replace('/\(\s?THEME\s?\./', '( e_THEME. "' . $theme . '/" .', str_replace($srch, '', $themeFileContent)); + + $themeFileContent = str_replace('tablestyle', $tp->filter($theme, 'wd') . "_tablestyle", $themeFileContent); // rename function to avoid conflicts while parsing. + + $themeFileContent = str_replace("class " . $theme . "_theme", "class " . $theme . "__theme", $themeFileContent); // rename class to avoid conflicts while parsing. + + $themeFileContent = str_replace('__DIR__', var_export(dirname($file), true), $themeFileContent); + $themeFileContent = str_replace('__FILE__', var_export($file, true), $themeFileContent); + + try + { + @eval($themeFileContent); + } + catch(ParseError $e) + { + echo "
Couldn't parse theme.php: " . $e->getMessage() . "
"; + } + } + + + e107::set('css_enabled', true); + e107::set('js_enabled', true); + + $head = array(); + $foot = array(); + + + if(isset($LAYOUT) && (isset($HEADER) || isset($FOOTER))) + { + $fallbackLan = "This theme is using deprecated elements. All [x]HEADER and [x]FOOTER variables should be removed from theme.php."; // DO NOT TRANSLATE! + $warningLan = $tp->lanVars(deftrue('MENLAN_60', $fallbackLan), '$'); + echo "
" . $warningLan . "
"; + + } + + + if(isset($LAYOUT) && is_array($LAYOUT)) // $LAYOUT is a combined $HEADER,$FOOTER. + { + foreach($LAYOUT as $key => $template) + { + if($key == '_header_' || $key == '_footer_' || $key == '_modal_') + { + continue; + } + + if(strpos($template, '{---}') !== false) + { + list($hd, $ft) = explode("{---}", $template); + $head[$key] = isset($LAYOUT['_header_']) ? $LAYOUT['_header_'] . $hd : $hd; + $foot[$key] = isset($LAYOUT['_footer_']) ? $ft . $LAYOUT['_footer_'] : $ft; + } + else + { + e107::getMessage()->addDebug('Missing "{---}" in $LAYOUT["' . $key . '"] '); + } + } + unset($hd, $ft); + } + + + if(is_string($CUSTOMHEADER)) + { + $head['legacyCustom'] = $CUSTOMHEADER; + } + elseif(is_array($CUSTOMHEADER)) + { + foreach($CUSTOMHEADER as $k => $v) + { + $head[$k] = $v; + } + } + + if(is_string($HEADER)) + { + $head['legacyDefault'] = $HEADER; + } + elseif(is_array($HEADER)) + { + foreach($HEADER as $k => $v) + { + $head[$k] = $v; + } + + } + + if(is_string($CUSTOMFOOTER)) + { + $foot['legacyCustom'] = $CUSTOMFOOTER; + } + elseif(is_array($CUSTOMFOOTER)) + { + foreach($CUSTOMFOOTER as $k => $v) + { + $foot[$k] = $v; + } + } + + + if(is_string($FOOTER)) + { + $foot['legacyDefault'] = $FOOTER; + } + elseif(is_array($FOOTER)) + { + foreach($FOOTER as $k => $v) + { + $foot[$k] = $v; + } + } + + $layout = array(); + + + foreach($head as $k => $v) + { + $template = $head[$k] . "\n{---}" . $foot[$k]; + $layout['templates'][$k] = $template; + $layout['menus'][$k] = self::countMenus($template, $k); + } + + + return $layout; + + + } + + private static function countMenus($template, $name) + { + + if(preg_match_all("/\{(?:MENU|MENUAREA)=([\d]{1,3})(:[\w\d]*)?\}/", $template, $matches)) + { + sort($matches[1]); + + return $matches[1]; + } + + e107::getDebug()->log("No Menus Found in Template:" . $name . " with strlen: " . strlen($template)); + + return array(); + } /** diff --git a/e107_handlers/e107_class.php b/e107_handlers/e107_class.php index 3123207fe..45e8de472 100644 --- a/e107_handlers/e107_class.php +++ b/e107_handlers/e107_class.php @@ -1463,7 +1463,7 @@ class e107 } /** - * Retrieve user-session singleton object + * Retrieve user-session 'UserHandler' singleton object * * @return UserHandler */ @@ -1887,7 +1887,7 @@ class e107 } /** - * Retrieve user model object. + * Retrieve user model 'e_user' object. * * @param integer $user_id target user * @param boolean $checkIfCurrent if tru user_id will be compared to current user, if there is a match diff --git a/e107_handlers/js_manager.php b/e107_handlers/js_manager.php index 97a84cf02..0cc74609a 100644 --- a/e107_handlers/js_manager.php +++ b/e107_handlers/js_manager.php @@ -283,7 +283,7 @@ class e_jsmanager } $this->_dependence = null; - if($vis != 'auto') + if($vis != 'auto') // TODO FIX ME - should it be in the loop above? { $this->checkLibDependence(null, $core); } @@ -1720,7 +1720,7 @@ class e_jsmanager // resolve relative paths for ($i = 0, $iMax = count($parts); $i < $iMax; $i +=1) { - if ($parts[$i] === "..") // resolve .. + if (isset($parts[$i]) && ($parts[$i] === "..")) // resolve .. { if ($i === 0) { diff --git a/e107_handlers/menumanager_class.php b/e107_handlers/menumanager_class.php index 63c67a096..5e6992fbc 100644 --- a/e107_handlers/menumanager_class.php +++ b/e107_handlers/menumanager_class.php @@ -2017,346 +2017,3 @@ class e_menuManager - - - -// new v2.1.4 -class e_menu_layout -{ - function __construct() - { - - } - - static function getLayouts($theme=null) - { - if(empty($theme)) - { - $theme = e107::pref('core','sitetheme'); - } - - $sql = e107::getDb(); // required - $tp = e107::getParser(); - - $HEADER = null; - $FOOTER = null; - $LAYOUT = null; - $CUSTOMHEADER = null; - $CUSTOMFOOTER = null; - - $path = e_THEME.$theme.'/'; - $file = $path."theme.php"; - - if(!is_readable($file)) - { - return false; - } - - e107::set('css_enabled',false); - e107::set('js_enabled',false); - - // new v2.2.2 HTML layout support. - if(is_dir($path."layouts") && is_readable($path."theme.html")) - { - $lyt = scandir($path."layouts"); - $LAYOUT = array(); - - foreach($lyt as $lays) - { - if($lays === '.' || $lays === '..') - { - continue; - } - - $key = str_replace("_layout.html", '', $lays); - - if($lm = e_theme::loadLayout($key, $theme)) - { - $LAYOUT = $LAYOUT + $lm; - } - - } - - } - else // prior to v2.2.2 - { - - $themeFileContent = file_get_contents($file); - - $srch = array(''); - - $themeFileContent = preg_replace('/\(\s?THEME\s?\./', '( e_THEME. "'.$theme.'/" .', str_replace($srch, '', $themeFileContent)); - - $themeFileContent = str_replace('tablestyle', $tp->filter($theme, 'wd')."_tablestyle",$themeFileContent); // rename function to avoid conflicts while parsing. - - $themeFileContent = str_replace("class ".$theme."_theme", "class ".$theme."__theme", $themeFileContent); // rename class to avoid conflicts while parsing. - - $themeFileContent = str_replace('__DIR__', var_export(dirname($file), true), $themeFileContent); - $themeFileContent = str_replace('__FILE__', var_export($file, true), $themeFileContent); - - try - { - @eval($themeFileContent); - } - catch (ParseError $e) - { - echo "
Couldn't parse theme.php: ". $e->getMessage()."
"; - } - } - - - e107::set('css_enabled',true); - e107::set('js_enabled',true); - - $head = array(); - $foot = array(); - - - - - if(isset($LAYOUT) && (isset($HEADER) || isset($FOOTER))) - { - $fallbackLan = "This theme is using deprecated elements. All [x]HEADER and [x]FOOTER variables should be removed from theme.php."; // DO NOT TRANSLATE! - $warningLan = $tp->lanVars(deftrue('MENLAN_60',$fallbackLan),'$'); - echo "
".$warningLan."
"; - - } - - - - if(isset($LAYOUT) && is_array($LAYOUT)) // $LAYOUT is a combined $HEADER,$FOOTER. - { - foreach($LAYOUT as $key=>$template) - { - if($key == '_header_' || $key == '_footer_' || $key == '_modal_') - { - continue; - } - - if(strpos($template,'{---}') !==false) - { - list($hd,$ft) = explode("{---}",$template); - $head[$key] = isset($LAYOUT['_header_']) ? $LAYOUT['_header_'] . $hd : $hd; - $foot[$key] = isset($LAYOUT['_footer_']) ? $ft . $LAYOUT['_footer_'] : $ft ; - } - else - { - e107::getMessage()->addDebug('Missing "{---}" in $LAYOUT["'.$key.'"] '); - } - } - unset($hd,$ft); - } - - - if(is_string($CUSTOMHEADER)) - { - $head['legacyCustom'] = $CUSTOMHEADER; - } - elseif(is_array($CUSTOMHEADER)) - { - foreach($CUSTOMHEADER as $k=>$v) - { - $head[$k] = $v; - } - } - - if(is_string($HEADER)) - { - $head['legacyDefault'] = $HEADER; - } - elseif(is_array($HEADER)) - { - foreach($HEADER as $k=>$v) - { - $head[$k] = $v; - } - - } - - if(is_string($CUSTOMFOOTER)) - { - $foot['legacyCustom'] = $CUSTOMFOOTER; - } - elseif(is_array($CUSTOMFOOTER)) - { - foreach($CUSTOMFOOTER as $k=>$v) - { - $foot[$k] = $v; - } - } - - - if(is_string($FOOTER)) - { - $foot['legacyDefault'] = $FOOTER; - } - elseif(is_array($FOOTER)) - { - foreach($FOOTER as $k=>$v) - { - $foot[$k] = $v; - } - } - - $layout = array(); - - - - foreach($head as $k=>$v) - { - $template = $head[$k]."\n{---}".$foot[$k]; - $layout['templates'][$k] = $template; - $layout['menus'][$k] = self::countMenus($template, $k); - } - - - return $layout; - - - } - - - private static function countMenus($template, $name) - { - if(preg_match_all("/\{(?:MENU|MENUAREA)=([\d]{1,3})(:[\w\d]*)?\}/", $template, $matches)) - { - sort($matches[1]); - return $matches[1]; - } - - e107::getDebug()->log("No Menus Found in Template:".$name." with strlen: ".strlen($template)); - - return array(); - } - - - - static function menuSelector() - { - - // $p = e107::getPref('e_menu_list'); // new storage for xxxxx_menu.php list. - $sql = e107::getDb(); - $frm = e107::getForm(); - - $done = array(); - - $pageMenu = array(); - $pluginMenu = array(); - - $sql->select("menus", "menu_name, menu_id, menu_pages, menu_path", "1 ORDER BY menu_name ASC"); - while ($row = $sql->fetch()) - { - - if(in_array($row['menu_name'],$done)) - { - continue; - } - - $done[] = $row['menu_name']; - - if(is_numeric($row['menu_path'])) - { - $pageMenu[] = $row; - } - else - { - $pluginMenu[] = $row; - } - - } - - $tab1 = ''; - - $tab2 = ''; - - $tabs = array( - 'custom' => array('caption'=>'', 'text'=>$tab1), - 'plugin' => array('caption'=>'', 'text'=>$tab2) - - ); - - - $defLayout =e107::getRegistry('core/e107/menu-manager/curLayout');; - - $text = '
'; - - $text .= ""; - - - $layouts = self::getLayouts(); - $tp = e107::getParser(); - - // var_dump($layouts['menus']); - - - $text .= ' - - '; - - - $text .= $frm->tabs($tabs); - - - - - - $text .= '
'; - - $tp = e107::getParser(); - - $caption = MENLAN_22; - - ; - - - - - return array('caption'=>$caption,'text'=>$text); - - - - - - - } - - - -}