From 176ae8640949f8b865a3abd63513e0ab7ebd2885 Mon Sep 17 00:00:00 2001 From: Cameron Date: Sat, 20 Feb 2021 12:15:28 -0800 Subject: [PATCH] Issue #3068 - Added a warning for misconfigured theme layouts. Moved e_layout class to menumanager_class.php file. Closes #4030 - Menu Layout detection test. themeLan() was failing with themes containing hyphens in the folder name. --- e107_handlers/e107_class.php | 2 +- e107_handlers/menumanager_class.php | 50 +++++++++++++-- .../_data/basic-light/languages/English.php | 4 +- e107_tests/tests/unit/e107Test.php | 9 +-- e107_tests/tests/unit/e_menu_layoutTest.php | 64 ++++++++++++------- e107_themes/bootstrap3/css/modern-light.css | 4 +- 6 files changed, 95 insertions(+), 38 deletions(-) diff --git a/e107_handlers/e107_class.php b/e107_handlers/e107_class.php index 02c2c65e8..90e8bdda6 100644 --- a/e107_handlers/e107_class.php +++ b/e107_handlers/e107_class.php @@ -3837,7 +3837,7 @@ class e107 } else { - $theme = e_THEME . preg_replace('#[^\w/]#', '', $theme) . '/languages/'; + $theme = e_THEME . filter_var($theme) . '/languages/'; } $cstring = 'themelan/'.$theme.$fname.($flat ? '_1' : '_0'); diff --git a/e107_handlers/menumanager_class.php b/e107_handlers/menumanager_class.php index 467981e3e..9eaf0328b 100644 --- a/e107_handlers/menumanager_class.php +++ b/e107_handlers/menumanager_class.php @@ -2038,7 +2038,12 @@ class e_menuManager // TODO Sorting, visibility, parameters and delete. // TODO Get THIS http://jsbin.com/odiqi3 working with iFrames!! XXX XXX -class e_layout + +/** + * Used only for the menu-selector at the moment. + * Class e_layout + */ +class e_mm_layout { private $menuData = array(); private $iframe = false; @@ -2436,8 +2441,19 @@ class e_layout $srch = array(''); + // replace LAN file load. + $themeFileContent = preg_replace("/e107::lan\(['|\"]theme.*\);/","e107::themeLan(null, '".$theme."');", $themeFileContent); + // $themeFileContent = preg_replace("/define\(['|\"]BOOTSTRAP['|\"].*;/", '', $themeFileContent); + // $themeFileContent = preg_replace("/define\(['|\"]FONTAWESOME['|\"].*;/", '', $themeFileContent); + $themeFileContent = preg_replace("/LAN_[\w]*/", '""', $themeFileContent); + $themeFileContent = preg_replace("/include_lan\(.*;/", '', $themeFileContent); + + $themeFileContent = preg_replace("/define\(.*;/", '', $themeFileContent); + $themeFileContent = preg_replace('/\(\s?THEME\s?\./', '( e_THEME. "' . $theme . '/" .', str_replace($srch, '', $themeFileContent)); + $themeFileContent = str_replace('USER_WIDTH', "''", $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. @@ -2445,13 +2461,35 @@ class e_layout $themeFileContent = str_replace('__DIR__', var_export(dirname($file), true), $themeFileContent); $themeFileContent = str_replace('__FILE__', var_export($file, true), $themeFileContent); - try + + + if(PHP_MAJOR_VERSION > 6) { - @eval($themeFileContent); + try + { + eval($themeFileContent); + } + catch(Error $e) + { + + trigger_error("Couldn't parse theme.php file. ". $e->getMessage()."\n\n".$themeFileContent); + echo "
Couldn't parse theme.php: " . $e->getMessage() . "
"; + file_put_contents(e_LOG."menuManagerParseDebug.log", $themeFileContent); + } } - catch(ParseError $e) + else { - echo "
Couldn't parse theme.php: " . $e->getMessage() . "
"; + try + { + eval($themeFileContent); + } + catch(ParseError $e) + { + trigger_error("Couldn't parse theme.php file.". $e->getMessage()); + echo "
Couldn't parse theme.php: " . $e->getMessage() . "
"; + + } + } } @@ -3050,3 +3088,5 @@ class e_layout + + diff --git a/e107_tests/tests/_data/basic-light/languages/English.php b/e107_tests/tests/_data/basic-light/languages/English.php index 8073a5fd7..ac95c2ce2 100644 --- a/e107_tests/tests/_data/basic-light/languages/English.php +++ b/e107_tests/tests/_data/basic-light/languages/English.php @@ -1,9 +1,9 @@ mcpeace."); define("MAW_THEME_2", "maw"); diff --git a/e107_tests/tests/unit/e107Test.php b/e107_tests/tests/unit/e107Test.php index c058dc320..1d9b3656b 100644 --- a/e107_tests/tests/unit/e107Test.php +++ b/e107_tests/tests/unit/e107Test.php @@ -1314,13 +1314,14 @@ class e107Test extends \Codeception\Test\Unit } - /* + public function testThemeLan() { - $res = null; - $this->assertTrue($res); - } + $result = e107::themeLan(null, 'basic-light'); + var_dump($result); + } + /* public function testLan() { $res = null; diff --git a/e107_tests/tests/unit/e_menu_layoutTest.php b/e107_tests/tests/unit/e_menu_layoutTest.php index d0edae132..9b1dc15c4 100644 --- a/e107_tests/tests/unit/e_menu_layoutTest.php +++ b/e107_tests/tests/unit/e_menu_layoutTest.php @@ -16,23 +16,26 @@ protected function _before() { - // require_once(e_HANDLER."menumanager_class.php"); + require_once(e_HANDLER."menumanager_class.php"); } private function copydir( $src, $dst ) { if(!is_dir($src) || is_dir($dst)) { + echo 'Skipping directory creation. '.$dst.' already exists.'."\n"; return false; } - - $dir = opendir($src); - @mkdir(dirname($dst)); + mkdir($dst); $DS = DIRECTORY_SEPARATOR ; - while(false !== ($file = readdir($dir))) + $files = scandir($src); + + unset($files[0], $files[1]); + + foreach($files as $file) { if($file != '.' && $file != '..') { @@ -47,7 +50,7 @@ } } - closedir($dir); + // closedir($dir); } @@ -63,7 +66,8 @@ public function testGetLayouts() { - /* FIXME: https://github.com/e107inc/e107/issues/4030 + //FIXME: https://github.com/e107inc/e107/issues/4030 + $src1 = codecept_data_dir()."testcore"; $dest1 = e_THEME."testcore"; @@ -74,6 +78,7 @@ $this->copydir($src2,$dest2); + $src3 = codecept_data_dir()."basic-light"; $dest3 = e_THEME."basic-light"; @@ -82,11 +87,11 @@ $tests = array( 'bootstrap3' => array ( - 'templates' => array( // template key and string length - 'jumbotron_home' => 3132, - 'modern_business_home' => 3842, - 'jumbotron_full' => 2239, - 'jumbotron_sidebar_right' => 2973 + 'templates' => array ( + 0 => 'jumbotron_full', + 1 => 'jumbotron_home', + 2 => 'jumbotron_sidebar_right', + 3 => 'modern_business_home', ), 'menus' => array ( 'jumbotron_home' => array ('1','2','3','4','5','6','7','8','9','10','11','12','13','14','100','101','102','103','104','105','106','107',), @@ -99,8 +104,8 @@ 'testkubrick' => array ( 'templates' => array( - 'legacyCustom' => 267, - 'legacyDefault' => 308 + 'legacyCustom', + 'legacyDefault' ), 'menus' => array( 'legacyCustom' => array(), @@ -110,9 +115,9 @@ 'testcore' => array ( 'templates' => array ( - 'HOME' => 1494, - 'FULL' => 1269, - 'legacyDefault'=> 1654 + 'HOME', + 'FULL', + 'legacyDefault' ), 'menus' => array( 'HOME' => array('2', '3', '4'), @@ -123,10 +128,10 @@ 'basic-light' => array( 'templates' => array( - 'default' => 3274, - 'default-home' => 3274, - 'simple-page' => 1553, - 'wide-page' => 1235 + 'default' , + 'default-home', + 'simple-page', + 'wide-page' ), 'menus' => array( 'default' => array('1', '2', '3', '4'), @@ -142,8 +147,19 @@ foreach($tests as $theme=>$vars) { - $result = e_menu_layout::getLayouts($theme); + $result = e_mm_layout::getLayouts($theme); + $templates = array_keys($result['templates']); + $this->assertSame($vars['templates'], $templates); + foreach($vars['menus'] as $key=>$arr) + { + $this->assertSame($arr, $result['menus'][$key], $key." is different"); + } + + // $this->assertEquals($templates, $vars['templates']); + + +/* foreach($vars['templates'] as $key=>$length) { $content = str_replace(array("\r", "\n"),'',$result['templates'][$key]); @@ -158,14 +174,14 @@ foreach($vars['menus'] as $key=>$arr) { $this->assertEquals($arr, $result['menus'][$key], $key." is different"); - } + }*/ } - */ + } diff --git a/e107_themes/bootstrap3/css/modern-light.css b/e107_themes/bootstrap3/css/modern-light.css index fa110b8c0..b0f65d5a1 100644 --- a/e107_themes/bootstrap3/css/modern-light.css +++ b/e107_themes/bootstrap3/css/modern-light.css @@ -1645,8 +1645,8 @@ ul.col-selection { background-color: #FCFDFF; } .admin-right-panel .alert a.close { text-shadow: 0 1px 0 #fff; color: rgba(0,0,0,0.6) } .admin-right-panel .dropdown-menu { background-color: rgb(252, 253, 255); color: rgba(0,0,0,0.75) } .admin-right-panel .dropdown-menu a { color: rgba(0,0,0,0.75); } -#admin-menus #sc-admin-help { background: #373737 } - +#admin-menus #sc-admin-help , +#admin-menus .admin-ui-nav-menu { background: #373737 }