1
0
mirror of https://github.com/e107inc/e107.git synced 2025-01-17 12:48:24 +01:00

Moved parseheader() to e107 class as renderLayout() Added test.

This commit is contained in:
Cameron 2020-12-20 13:25:03 -08:00
parent 601df26d51
commit bdb4104f9c
6 changed files with 64 additions and 35 deletions

View File

@ -78,7 +78,7 @@ if (varset($e107_popup) != 1)
'{---FOOTER---}' => $tp->parseTemplate('{FOOTER}',true)
);
parseheader($FOOTER, $psc);
e107::renderLayout($FOOTER, $psc);
}
$eTimingStop = microtime();

View File

@ -79,33 +79,6 @@ $js_body_onload = array(); // Legacy array of code to load with page.
// A: Define themeable header parsing
//
if (!function_exists("parseheader"))
{
function parseheader($LAYOUT, $opts=array())
{
$tp = e107::getParser();
$tmp = explode("\n", $LAYOUT);
$sc = e107::getScBatch('_theme_');
$search = array_keys($opts);
$replace = array_values($opts);
foreach ($tmp as $line)
{
$line = str_replace($search, $replace, $line); // Quick-fix allow for use of {THEME} shortcode.
if (preg_match("/{.+?}/", $line))
{
echo $tp->parseTemplate($line, true, $sc)."\n"; // retain line-breaks.
}
else
{
echo $line."\n"; // retain line-breaks.
}
}
}
}
//
// B: Send HTTP headers (these come before ANY html)
@ -763,10 +736,11 @@ if ($e107_popup != 1) {
//
// M: Send top of body for custom pages and for news
//
e107::getDebug()->logTime('Render Layout');
// BC Fix
if (defset('e_PAGE') == 'news.php' && isset($NEWSHEADER))
{
parseheader($NEWSHEADER);
e107::renderLayout($NEWSHEADER);
}
else
{
@ -786,7 +760,7 @@ if ($e107_popup != 1) {
'{---FOOTER---}' => e107::getParser()->parseTemplate('{FOOTER}',true),
);
parseheader($HEADER, $psc);
e107::renderLayout($HEADER, $psc);
// echo $HEADER;
}
@ -798,6 +772,7 @@ if ($e107_popup != 1) {
//
// N: Send other top-of-body HTML
//
e107::getDebug()->logTime('Render Other');
if(ADMIN && !vartrue($_SERVER['E_DEV']) && file_exists(e_BASE.'install.php'))
{

View File

@ -304,6 +304,42 @@ class e107
exit();
}
/**
* Render layout - replacement for legacy parseheader() function in header_default.php
* @param string $LAYOUT
* @param array $opts - magic shortcode key=>value pair replacements
* @return void
*/
public static function renderLayout($LAYOUT, $opts = array())
{
$tp = self::getParser();
$tmp = explode("\n", $LAYOUT);
$sc = self::getScBatch('_theme_'); // include the theme shortcodes.
$search = array_keys($opts);
$replace = array_values($opts);
foreach ($tmp as $line)
{
$line = str_replace($search, $replace, $line); // Quick-fix allow for use of {THEME} shortcode.
if (strpos($line,'{') === false)
{
echo $line . "\n"; // retain line-breaks.
continue;
}
if (preg_match("/{.+?}/", $line))
{
echo $tp->parseTemplate($line, true, $sc) . "\n"; // retain line-breaks.
}
}
}
/**
* Cloning is not allowed
*
@ -5100,6 +5136,8 @@ class e107
}
/**
* Removed, see eHelper::getMemoryUsage()
* Get the current memory usage of the code

View File

@ -4433,9 +4433,9 @@ class e_parser
{
$userData = array();
$userData['user_id'] = USERID;
$userData['user_image'] = USERIMAGE;
$userData['user_name'] = USERNAME;
$userData['user_currentvisit'] = USERCURRENTVISIT;
$userData['user_image'] = deftrue('USERIMAGE');
$userData['user_name'] = deftrue('USERNAME');
$userData['user_currentvisit'] = deftrue('USERCURRENTVISIT');
}

View File

@ -49,6 +49,22 @@ class e107Test extends \Codeception\Test\Unit
}
public function testRenderLayout()
{
$LAYOUT = file_get_contents(e_THEME."bootstrap3/theme.html");
ob_start();
$this->e107::renderLayout($LAYOUT);
$result = ob_get_clean();
$this->assertStringNotContainsString('{MENU=1}',$result);
$this->assertStringNotContainsString('{NAVIGATION=main}',$result);
$this->assertStringNotContainsString('{BOOTSTRAP_BRANDING}',$result);
}
/*
public function testInitInstall()
{

View File

@ -233,7 +233,7 @@ class theme_shortcodes extends e_shortcode
return $tp->parseTemplate($text, true, $login_menu_shortcodes);
return e107::getParser()->parseTemplate($text, true, $login_menu_shortcodes);
}
@ -276,7 +276,7 @@ class theme_shortcodes extends e_shortcode
';
return $tp->parseTemplate($text,true,$login_menu_shortcodes);
return e107::getParser()->parseTemplate($text,true,$login_menu_shortcodes);
}