From 582bd3f72c08fed54df56469ee434d1333653974 Mon Sep 17 00:00:00 2001 From: Cameron Date: Wed, 1 Jul 2020 13:00:34 -0700 Subject: [PATCH] Fixes #4200 - check theme version is compatible and disable installation if necessary. --- e107_admin/theme.php | 16 +++++++++++++++- e107_handlers/e_parse_class.php | 4 ++++ e107_handlers/theme_handler.php | 14 ++++++++++++-- e107_languages/English/admin/lan_theme.php | 4 +++- e107_tests/tests/unit/e_parseTest.php | 20 ++++++++++++++++++-- 5 files changed, 52 insertions(+), 6 deletions(-) diff --git a/e107_admin/theme.php b/e107_admin/theme.php index bfaa4f1e0..5536ec714 100644 --- a/e107_admin/theme.php +++ b/e107_admin/theme.php @@ -955,7 +955,21 @@ class theme_admin_form_ui extends e_admin_form_ui $infoPath = e_SELF."?mode=".$_GET['mode']."&id=".$theme['path']."&action=info&iframe=1"; $previewPath = $tp->replaceConstants($theme['thumbnail'],'abs'); - $main_icon = ($pref['sitetheme'] != $theme['path']) ? "" : ""; + $version = $tp->filter(e_VERSION,'version'); + $compat = $tp->filter($theme['compatibility'], 'version'); + + $disabled = ''; + $mainTitle = TPVLAN_10; + + if(version_compare($compat,$version, '<=') === false) + { + $disabled = 'disabled'; + $mainTitle = defset('TPVLAN_97', "This theme requires a newer version of e107."); + } + + e107::getDebug()->log($theme['path']." - ".$disabled. " (".$compat.")"); + + $main_icon = ($pref['sitetheme'] != $theme['path']) ? "" : ""; $info_icon = "".$tp->toGlyph('fa-info-circle',array('size'=>'2x')).""; // $admin_icon = ($pref['admintheme'] != $theme['path'] ) ? "" : ""; diff --git a/e107_handlers/e_parse_class.php b/e107_handlers/e_parse_class.php index 93dabcd4d..d5d55e8f2 100644 --- a/e107_handlers/e_parse_class.php +++ b/e107_handlers/e_parse_class.php @@ -5374,6 +5374,10 @@ return; return preg_replace('/[^\w\d_\.-]/',"-",$text); } + if($type === 'version') + { + return preg_replace('/[^\d_\.]/',"",$text); + } if($validate == false) { diff --git a/e107_handlers/theme_handler.php b/e107_handlers/theme_handler.php index 87a0b97d5..2ab9332f3 100644 --- a/e107_handlers/theme_handler.php +++ b/e107_handlers/theme_handler.php @@ -829,7 +829,7 @@ class e_theme $vars['name'] = varset($vars['@attributes']['name']); $vars['version'] = varset($vars['@attributes']['version']); $vars['date'] = varset($vars['@attributes']['date']); - $vars['compatibility'] = varset($vars['@attributes']['compatibility']); + $vars['compatibility'] = !empty($vars['@attributes']['compatibility']) ? $tp->filter($vars['@attributes']['compatibility'], 'version') : ''; $vars['releaseUrl'] = varset($vars['@attributes']['releaseUrl']); $vars['email'] = varset($vars['author']['@attributes']['email']); $vars['website'] = varset($vars['author']['@attributes']['url']); @@ -1865,13 +1865,23 @@ class themeHandler $theme['compatibility'] = '2.0'; } + $version = e107::getParser()->filter(e_VERSION,'version'); + + $compatLabel = TPVLAN_77; + $compatLabelType = 'warning'; + + if(version_compare($theme['compatibility'],$version, '<=') === false) + { + $compatLabelType = 'danger'; + $compatLabel = defset('TPVLAN_97', "This theme requires a newer version of e107."); + } global $pref; $author = !empty($theme['email']) ? "".$theme['author']."" : $theme['author']; $website = !empty($theme['website']) ? "".$theme['website']."" : ""; // $preview = "".($theme['preview'] ? "" : "").""; $description = vartrue($theme['description'],''); - $compat = (version_compare(1.9,$theme['compatibility'],'<')) ? "".$theme['compatibility']." ".TPVLAN_77."": vartrue($theme['compatibility'],'1.0'); + $compat = (version_compare(1.9,$theme['compatibility'],'<')) ? "".$theme['compatibility']." ".$compatLabel."": vartrue($theme['compatibility'],'1.0'); $price = (!empty($theme['price'])) ? " ".$theme['price']."" : "".TPVLAN_76.""; $text = e107::getForm()->open('theme-info','post'); diff --git a/e107_languages/English/admin/lan_theme.php b/e107_languages/English/admin/lan_theme.php index 79f1f81bf..2a5c6bdc4 100644 --- a/e107_languages/English/admin/lan_theme.php +++ b/e107_languages/English/admin/lan_theme.php @@ -137,4 +137,6 @@ define("TPVLANHELP_02", "Look at the tooltips (when available) for more details. define("TPVLANHELP_03", "By default, the visibility filter will change the theme's layout based on a partial URL match."); 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."); \ No newline at end of file +define("TPVLANHELP_05", "End lines with a [b]$[/b] to exactly match against the end of script path."); + +define("TPVLAN_97", "This theme requires a newer version of e107."); \ No newline at end of file diff --git a/e107_tests/tests/unit/e_parseTest.php b/e107_tests/tests/unit/e_parseTest.php index ce90be860..696ea6e7e 100644 --- a/e107_tests/tests/unit/e_parseTest.php +++ b/e107_tests/tests/unit/e_parseTest.php @@ -1089,12 +1089,28 @@ while($row = $sql->fetch()) { } - +*/ public function testFilter() { + $tests = array( + 0 => array('input' => 'test123 xxx', 'mode' => 'w', 'expected' => 'test123xxx'), + 1 => array('input' => 'test123 xxx', 'mode' => 'd', 'expected' => '123'), + 2 => array('input' => 'test123 xxx', 'mode' => 'wd', 'expected' => 'test123xxx'), + 3 => array('input' => 'test123 xxx', 'mode' => 'wds', 'expected' => 'test123 xxx'), + 4 => array('input' => 'test123 xxx.jpg', 'mode' => 'file', 'expected' => 'test123-xxx.jpg'), + 5 => array('input' => '2.1.4 (test)', 'mode' => 'version', 'expected' => '2.1.4'), + ); + + foreach($tests as $var) + { + $result = $this->tp->filter($var['input'],$var['mode']); + $this->assertEquals($var['expected'],$result); + } + + } -*/ + public function testCleanHtml() { global $_E107;