1
0
mirror of https://github.com/e107inc/e107.git synced 2025-07-31 20:00:37 +02:00

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.
This commit is contained in:
Cameron
2021-02-20 12:15:28 -08:00
parent 821f2e9c22
commit 176ae86409
6 changed files with 95 additions and 38 deletions

View File

@@ -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');

View File

@@ -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('<?php', '?>');
// 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);
if(PHP_MAJOR_VERSION > 6)
{
try
{
@eval($themeFileContent);
eval($themeFileContent);
}
catch(Error $e)
{
trigger_error("Couldn't parse theme.php file. ". $e->getMessage()."\n\n".$themeFileContent);
echo "<div class='alert alert-danger'>Couldn't parse theme.php: " . $e->getMessage() . " </div>";
file_put_contents(e_LOG."menuManagerParseDebug.log", $themeFileContent);
}
}
else
{
try
{
eval($themeFileContent);
}
catch(ParseError $e)
{
trigger_error("Couldn't parse theme.php file.". $e->getMessage());
echo "<div class='alert alert-danger'>Couldn't parse theme.php: " . $e->getMessage() . " </div>";
}
}
}
@@ -3050,3 +3088,5 @@ class e_layout

View File

@@ -1,9 +1,9 @@
<?php
define("EMESSLAN_TITLE_INFO", "System Information");
/*define("EMESSLAN_TITLE_INFO", "System Information");
define("EMESSLAN_TITLE_ERROR", "Error");
define("EMESSLAN_TITLE_SUCCESS", "Success");
define("EMESSLAN_TITLE_WARNING", "Warning");
define("EMESSLAN_TITLE_DEBUG", "System Debug");
define("EMESSLAN_TITLE_DEBUG", "System Debug");*/
define("MAW_THEME_1", "Basic-Light theme by <a href='http://manatwork.info' title='Man at Work Premium and Custom e107 Themes' rel='external'>mcpeace</a>.");
define("MAW_THEME_2", "<a id='copyright' href='http://manatwork.info' title='Man at Work Premium and Custom e107 Themes' rel='copyright'>maw</a>");

View File

@@ -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;

View File

@@ -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");
}
}*/
}
*/
}

View File

@@ -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 }