1
0
mirror of https://github.com/e107inc/e107.git synced 2025-08-03 21:27:25 +02:00

Issue #3184 Issue #3912 New Feature: can now use :(e_ROUTE) to switch theme layout visibility.

This commit is contained in:
Cameron
2021-02-14 10:36:45 -08:00
parent 4669285b6f
commit 50e0445807
5 changed files with 67 additions and 32 deletions

View File

@@ -804,10 +804,14 @@ class theme_admin_ui extends e_admin_ui
switch($type) switch($type)
{ {
case "main/main": case "main/main":
$text = "<b>".TPVLAN_56."</b><br />"; // Visbility Filter $text = '<b>'.TPVLAN_56.'</b><br />'; // Visbility Filter
$text .= "<br />".$tp->toHTML(TPVLANHELP_03,true); $text .= '<br />'.$tp->toHTML(TPVLANHELP_03,true);
$text .= "<ul style='padding-left:10px;margin-top:10px'><li>".$tp->toHTML(TPVLANHELP_04,true)."</li>"; $text .= '<ul style="padding-left:10px;margin-top:10px">
$text .= "<li>".$tp->toHTML(TPVLANHELP_05,true)."</li></ul>"; <li>'.$tp->toHTML(TPVLANHELP_06,true).'</li>
<li>'.$tp->toHTML(TPVLANHELP_04,true).'</li>
<li>'.$tp->toHTML(TPVLANHELP_05,true).'</li>
</ul>';
break; break;
case "label2": case "label2":
@@ -815,7 +819,7 @@ class theme_admin_ui extends e_admin_ui
break; break;
default: default:
$text = TPVLANHELP_01."<br /><br />".TPVLANHELP_02; $text = TPVLANHELP_01.'<br /><br />'.TPVLANHELP_02;
} }

View File

@@ -21,7 +21,9 @@ if(!defined('ADMIN_AREA'))
define('ADMIN_AREA', false); define('ADMIN_AREA', false);
} }
e_theme::initThemeLayout(); e107::getDebug()->logTime('(Header Top)');
e_theme::initThemeLayout(); // set THEME_LAYOUT
if(!isset($_E107['no_menus'])) if(!isset($_E107['no_menus']))
{ {
@@ -32,13 +34,13 @@ if(!isset($_E107['no_menus']))
$e107 = e107::getInstance(); $e107 = e107::getInstance();
$sql = e107::getDb(); $sql = e107::getDb();
e107::getDebug()->logTime('(Header Top)');
if($themeSC = e107::getScBatch('theme')) // init theme_shortcodes after THEME_LAYOUT is available. if($themeSC = e107::getScBatch('theme')) // init theme_shortcodes after THEME_LAYOUT is available.
{ {
$themeSC->init(); $themeSC->init();
unset($themeSC); unset($themeSC);
} }
e107::getRender()->init(); e107::getRender()->init(); // init 'theme' class.
//e107::js('core', 'bootstrap/js/bootstrap-tooltip.js','jquery'); //e107::js('core', 'bootstrap/js/bootstrap-tooltip.js','jquery');

View File

@@ -496,7 +496,7 @@ class e_theme
* @param string $url * @param string $url
* @return string * @return string
*/ */
private function filterTrackers($url) private static function filterTrackers($url)
{ {
if(strpos($url,'?') === false || empty($url)) if(strpos($url,'?') === false || empty($url))
{ {
@@ -514,27 +514,26 @@ class e_theme
/** /**
* Calculate THEME_LAYOUT constant based on theme preferences and current URL. * Calculate THEME_LAYOUT constant based on theme preferences and current request. (url, script, route)
* *
* @param array $cusPagePref * @param array $cusPagePref
* @param string $defaultLayout * @param string $defaultLayout
* @param string $request_url (optional) defaults to e_REQUEST_URL * @param array $request url => (optional) defaults to e_REQUEST_URL, 'script'=> $_SERVER['SCRIPT_FILENAME'], 'route' => e_ROUTE
* @param string $request_script $_SERVER['SCRIPT_FILENAME'];
* @return int|string * @return int|string
*/ */
public function getThemeLayout($cusPagePref, $defaultLayout, $request_url = null, $request_script = null) public static function getThemeLayout($cusPagePref, $defaultLayout, $request)
{ {
$request_url = isset($request['url']) ? $request['url'] : null;
$request_script = isset($request['script']) ? $request['script'] : null;
if($request_url === null) if($request_url === null)
{ {
$request_url = e_REQUEST_URL; $request_url = e_REQUEST_URL;
} }
$def = ""; // no custom pages found yet. $def = ""; // no custom pages found yet.
$matches = array(); $matches = array();
if(is_array($cusPagePref) && count($cusPagePref)>0) // check if we match a page in layout custompages. if(is_array($cusPagePref) && count($cusPagePref)>0) // check if we match a page in layout custompages.
{ {
//e_SELF.(e_QUERY ? '?'.e_QUERY : ''); //e_SELF.(e_QUERY ? '?'.e_QUERY : '');
@@ -542,7 +541,7 @@ class e_theme
// FIX - check against urldecoded strings // FIX - check against urldecoded strings
$c_url = rtrim(rawurldecode($c_url), '?'); $c_url = rtrim(rawurldecode($c_url), '?');
$c_url = $this->filterTrackers($c_url); $c_url = self::filterTrackers($c_url);
// First check all layouts for exact matches - possible fix for future issues?. // First check all layouts for exact matches - possible fix for future issues?.
/* /*
@@ -565,13 +564,19 @@ class e_theme
if(!is_array($cusPageArray)) { continue; } if(!is_array($cusPageArray)) { continue; }
// NEW - Front page template check - early // NEW - Front page template check - early
if(in_array('FRONTPAGE', $cusPageArray) && ($c_url == SITEURL || rtrim($c_url, '/') == SITEURL.'index.php')) if(in_array('FRONTPAGE', $cusPageArray) && ($c_url == SITEURL || rtrim($c_url, '/') === SITEURL.'index.php'))
{ {
return $lyout; return $lyout;
} }
foreach($cusPageArray as $kpage) foreach($cusPageArray as $kpage)
{ {
// e_ROUTE
if(!empty($request['route']) && (strpos($kpage,':'.$request['route']) === 0))
{
return $lyout;
}
$kpage = str_replace('&#036;', '$', $kpage); // convert database encoding. $kpage = str_replace('&#036;', '$', $kpage); // convert database encoding.
$lastChar = substr($kpage, -1); $lastChar = substr($kpage, -1);
@@ -585,8 +590,6 @@ class e_theme
} }
} }
if($lastChar === '!') if($lastChar === '!')
{ {
@@ -1218,6 +1221,10 @@ class e_theme
} }
/**
* Define the THEME_STYLE constant
* @param $pref
*/
public static function initThemeStyle($pref) public static function initThemeStyle($pref)
{ {
@@ -1240,20 +1247,34 @@ class e_theme
} }
/**
* define the THEME_LAYOUT constant.
* @return null
*/
public static function initThemeLayout() public static function initThemeLayout()
{ {
if(!defined('THEME_LAYOUT')) if(defined('THEME_LAYOUT'))
{ {
return null;
}
$sitetheme_custompages = e107::getPref('sitetheme_custompages', array()); $sitetheme_custompages = e107::getPref('sitetheme_custompages', array());
$sitetheme_deflayout = e107::getPref('sitetheme_deflayout'); $sitetheme_deflayout = e107::getPref('sitetheme_deflayout');
$user_pref = e107::getUser()->getPref(); $user_pref = e107::getUser()->getPref();
$cusPagePref = !empty($user_pref['sitetheme_custompages']) ? $user_pref['sitetheme_custompages'] : $sitetheme_custompages; $cusPagePref = !empty($user_pref['sitetheme_custompages']) ? $user_pref['sitetheme_custompages'] : $sitetheme_custompages;
$cusPageDef = !empty($user_pref['sitetheme_deflayout']) ? $user_pref['sitetheme_deflayout'] : $sitetheme_deflayout; $cusPageDef = !empty($user_pref['sitetheme_deflayout']) ? $user_pref['sitetheme_deflayout'] : $sitetheme_deflayout;
$deflayout = e107::getTheme()->getThemeLayout($cusPagePref, $cusPageDef, e_REQUEST_URL, varset($_SERVER['SCRIPT_FILENAME']));
$request = [
'url' => e_REQUEST_URL,
'script' => varset($_SERVER['SCRIPT_FILENAME'],null),
'route' => deftrue('e_ROUTE', null),
];
$deflayout = self::getThemeLayout($cusPagePref, $cusPageDef, $request);
define('THEME_LAYOUT',$deflayout); define('THEME_LAYOUT',$deflayout);
}
} }
@@ -1317,7 +1338,7 @@ class e_theme
define('THEME_LEGACY', false); define('THEME_LEGACY', false);
define('USERTHEME', 'bootstrap3'); define('USERTHEME', 'bootstrap3');
define('BOOTSTRAP', 3); define('BOOTSTRAP', 3);
define('FONTAWESOME', 4); define('FONTAWESOME', 5);
if (ADMIN && (e_ADMIN_AREA !== true)) if (ADMIN && (e_ADMIN_AREA !== true))
{ {

View File

@@ -139,4 +139,5 @@ define("TPVLANHELP_03", "By default, the visibility filter will change the theme
define("TPVLANHELP_04", "End lines with a [b]![/b] to exactly match against the end of URL."); define("TPVLANHELP_04", "End lines with a [b]![/b] to exactly match against the end of URL.");
define("TPVLANHELP_05", "End lines with a [b]$[/b] to exactly match against the end of script path."); define("TPVLANHELP_05", "End lines with a [b]$[/b] to exactly match against the end of script path.");
define("TPVLANHELP_06", "Start lines with a [b]:[/b] to partially or fully match against the e_ROUTE constant.");
define("TPVLAN_97", "This theme requires a newer version of e107."); define("TPVLAN_97", "This theme requires a newer version of e107.");

View File

@@ -452,6 +452,8 @@
array ( array (
0 => 'forum', 0 => 'forum',
1 => 'user.php!', // <-- exact match of URL 1 => 'user.php!', // <-- exact match of URL
2 => ':forum/index',
// 2 => '/user', // <-- Expecting URL to match both user and usersetting since it contains no "!" // 2 => '/user', // <-- Expecting URL to match both user and usersetting since it contains no "!"
), ),
'jumbotron_sidebar_right' => 'jumbotron_sidebar_right' =>
@@ -469,6 +471,7 @@
3 => '/user/settings?', 3 => '/user/settings?',
4 => 'script.php$', 4 => 'script.php$',
5 => '/news/?bla', 5 => '/news/?bla',
6 => ':news/view/index',
), ),
'script_match' => 'script_match' =>
array( array(
@@ -506,13 +509,17 @@
22 => array('url' => SITEURL."news/my-news-title", 'script' => '/news.php', 'expected' => 'jumbotron_sidebar_right'), 22 => array('url' => SITEURL."news/my-news-title", 'script' => '/news.php', 'expected' => 'jumbotron_sidebar_right'),
23 => array('url' => SITEURL."news/?bla", 'script' => '/news.php', 'expected' => 'other_layout'), 23 => array('url' => SITEURL."news/?bla", 'script' => '/news.php', 'expected' => 'other_layout'),
// Using e_ROUTE;
24 => array('url' => 'whatever.php', 'script'=>'whatever.php', 'route'=> 'news/view/index', 'expected'=> 'other_layout'),
25 => array('url' => 'whatever.php', 'script'=>'whatever.php', 'route'=> 'forum/index', 'expected'=> 'jumbotron_full'),
); );
foreach($tests as $item=>$var) foreach($tests as $item=>$var)
{ {
$var['script'] = isset($var['script']) ? $var['script'] : null; $var['script'] = isset($var['script']) ? $var['script'] : null;
$result = $this->tm->getThemeLayout($pref, $defaultLayout, $var['url'], $var['script']); $result = $this->tm::getThemeLayout($pref, $defaultLayout, $var);
$this->assertEquals($var['expected'],$result, "Wrong theme layout returned for item [".$item."] ".$var['url']); $this->assertEquals($var['expected'],$result, "Wrong theme layout returned for item [".$item."] ".$var['url']);
// echo $var['url']."\t\t\t".$result."\n\n"; // echo $var['url']."\t\t\t".$result."\n\n";
} }