1
0
mirror of https://github.com/e107inc/e107.git synced 2025-01-29 10:38:08 +01:00

Fixes #4200 - check theme version is compatible and disable installation if necessary.

This commit is contained in:
Cameron 2020-07-01 13:00:34 -07:00
parent 5f58f8f59d
commit 582bd3f72c
5 changed files with 52 additions and 6 deletions

View File

@ -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']) ? "<button class='btn btn-default btn-secondary btn-small btn-sm btn-inverse' type='submit' name='selectmain[".$theme['path']."]' alt=\"".TPVLAN_10."\" title=\"".TPVLAN_10."\" >".$tp->toGlyph('fa-home',array('size'=>'2x'))."</button>" : "<button class='btn btn-small btn-default btn-secondary btn-sm btn-inverse' type='button'>".$tp->toGlyph('fa-check',array('size'=>'2x'))."</button>";
$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']) ? "<button class='btn btn-default btn-secondary btn-small btn-sm btn-inverse' type='submit' ".$disabled." name='selectmain[".$theme['path']."]' alt=\"".$mainTitle."\" title=\"".$mainTitle."\" >".$tp->toGlyph('fa-home',array('size'=>'2x'))."</button>" : "<button class='btn btn-small btn-default btn-secondary btn-sm btn-inverse' type='button'>".$tp->toGlyph('fa-check',array('size'=>'2x'))."</button>";
$info_icon = "<a class='btn btn-default btn-secondary btn-small btn-sm btn-inverse e-modal' data-modal-caption=\"".$theme['name']." ".$theme['version']."\" href='".$infoPath."' title='".TPVLAN_7."'>".$tp->toGlyph('fa-info-circle',array('size'=>'2x'))."</a>";
// $admin_icon = ($pref['admintheme'] != $theme['path'] ) ? "<button class='btn btn-default btn-small btn-sm btn-inverse' type='submit' name='selectadmin[".$theme['id']."]' alt=\"".TPVLAN_32."\" title=\"".TPVLAN_32."\" >".$tp->toGlyph('fa-gears',array('size'=>'2x'))."</button>" : "<button class='btn btn-small btn-default btn-sm btn-inverse' type='button'>".$tp->toGlyph('fa-check',array('size'=>'2x'))."</button>";

View File

@ -5374,6 +5374,10 @@ return;
return preg_replace('/[^\w\d_\.-]/',"-",$text);
}
if($type === 'version')
{
return preg_replace('/[^\d_\.]/',"",$text);
}
if($validate == false)
{

View File

@ -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']) ? "<a href='mailto:".$theme['email']."' title='".$theme['email']."'>".$theme['author']."</a>" : $theme['author'];
$website = !empty($theme['website']) ? "<a href='".$theme['website']."' rel='external'>".$theme['website']."</a>" : "";
// $preview = "<a href='".SITEURL."news.php?themepreview.".$theme['id']."' title='".TPVLAN_9."' >".($theme['preview'] ? "<img src='".$theme['preview']."' style='border: 1px solid #000;width:200px' alt='' />" : "<img src='".e_IMAGE_ABS."admin_images/nopreview.png' title='".TPVLAN_12."' alt='' />")."</a>";
$description = vartrue($theme['description'],'');
$compat = (version_compare(1.9,$theme['compatibility'],'<')) ? "<span class='label label-warning'>".$theme['compatibility']."</span><span class='text-warning'> ".TPVLAN_77."</span>": vartrue($theme['compatibility'],'1.0');
$compat = (version_compare(1.9,$theme['compatibility'],'<')) ? "<span class='label label-".$compatLabelType."'>".$theme['compatibility']."</span><span class='text-".$compatLabelType."'> ".$compatLabel."</span>": vartrue($theme['compatibility'],'1.0');
$price = (!empty($theme['price'])) ? "<span class='label label-primary'><i class='icon-shopping-cart icon-white'></i> ".$theme['price']."</span>" : "<span class='label label-success'>".TPVLAN_76."</span>";
$text = e107::getForm()->open('theme-info','post');

View File

@ -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.");
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.");

View File

@ -1089,12 +1089,28 @@ while(&#036;row = &#036;sql-&gt;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;