1
0
mirror of https://github.com/e107inc/e107.git synced 2025-08-16 03:24:20 +02:00

Issue #4228 Theme manager - display only the relevant stylesheets for the selected scope.

This commit is contained in:
Cameron
2021-02-13 17:56:53 -08:00
parent 6662b04323
commit 3bb541a6d9
2 changed files with 33 additions and 81 deletions

View File

@@ -207,7 +207,6 @@ class e_theme
if($scp === $scope || $scp === 'all' || $scope === 'all')
{
unset($info['name']);
unset($info['scope']);
$ret[$name] = $info;
@@ -2794,18 +2793,24 @@ class themeHandler
private function filterStylesheets($mode, $theme)
{
$remove = array();
$detected = array();
if($mode == self::RENDER_SITEPREFS)
{
$detected = e107::getTheme()->getScope('css', 'front');
foreach($theme['css'] as $k=>$v) // check if wildcard is present.
{
if($v['name'] == '*')
{
foreach($theme['files'] as $val) // get wildcard list of css files.
{
if(substr($val,-4) == '.css' && strpos($val, "admin_") !== 0)
if(isset($detected[$val]))
{
continue;
}
if(substr($val,-4) === '.css' && strpos($val, "admin_") !== 0)
{
$detected[$val] = array('name'=>$val, 'info'=>'User-added Stylesheet', 'nonadmin'=>1);
}
@@ -2813,87 +2818,14 @@ class themeHandler
break;
}
}
}
foreach($theme['css'] as $k=>$vl) // as defined.
elseif($mode === self::RENDER_ADMINPREFS)
{
if(!empty($detected[$vl['name']])) // remove any detected files which are listed
{
unset($detected[$vl['name']]);
}
// frontend
if($mode === self::RENDER_SITEPREFS)
{
if(strpos($vl['name'], "admin_") === 0)
{
$remove[$k] = $vl['name'];
}
if($vl['scope'] == 'admin')
{
$remove[$k] = $vl['name'];
}
if($vl['name'] == '*' )
{
$remove[$k] = $vl['name'];
$wildcard = true;
continue;
}
}
if($mode === self::RENDER_ADMINPREFS)
{
if($vl['name'] == "style.css" || empty($vl['info'])) // Hide the admin css unless it has a header. eg. /* info: Default stylesheet */
{
$remove[$k] = $vl['name'];
}
if($vl['name'] == '*' )
{
$remove[$k] = $vl['name'];
}
if($vl['scope'] === 'front')
{
$remove[$k] = $vl['name'];
}
if(!empty($vl['nonadmin']))
{
$remove[$k] = $vl['name'];
}
}
$detected = e107::getTheme('admin')->getScope('css', 'admin');
}
foreach($remove as $k=>$file)
{
unset($theme['css'][$k]);
// unset($detected[$file]);
}
foreach($detected as $k=>$v)
{
$theme['css'][] = $v;
}
// print_a($detected);
// print_a($remove);
return $theme['css'];
return $detected;
}

View File

@@ -57,10 +57,12 @@
'expected' => array (
'bootstrap' =>
array (
'name' => 'bootstrap',
'version' => '3',
),
'fontawesome' =>
array (
'name' => 'fontawesome',
'version' => '5',
),
)
@@ -72,14 +74,17 @@
'expected' => array (
'bootstrap' =>
array (
'name' => 'bootstrap',
'version' => '3',
),
'fontawesome' =>
array (
'name' => 'fontawesome',
'version' => '5',
),
'bootstrap.editable' =>
array (
'name' => 'bootstrap.editable',
'version' => '',
),
)
@@ -91,14 +96,17 @@
'expected' => array (
'bootstrap' =>
array (
'name' => 'bootstrap',
'version' => '3',
),
'fontawesome' =>
array (
'name' => 'fontawesome',
'version' => '5',
),
'bootstrap.editable' =>
array (
'name' => 'bootstrap.editable',
'version' => '',
),
)
@@ -110,10 +118,12 @@
'expected' => array (
'bootstrap' =>
array (
'name' => 'bootstrap',
'version' => '3',
),
'fontawesome' =>
array (
'name' => 'fontawesome',
'version' => '4',
),
)
@@ -125,6 +135,7 @@
'expected' => array (
'style.css' =>
array (
'name' => 'style.css',
'info' => 'Default',
'nonadmin' => true,
'exclude' => '',
@@ -140,6 +151,7 @@
'expected' => array (
'css/modern-light.css' =>
array (
'name' => 'css/modern-light.css',
'info' => 'Modern Light',
'nonadmin' => false,
'exclude' => 'bootstrap',
@@ -148,6 +160,7 @@
),
'css/modern-dark.css' =>
array (
'name' => 'css/modern-dark.css',
'info' => 'Modern Dark',
'nonadmin' => false,
'exclude' => 'bootstrap',
@@ -156,6 +169,7 @@
),
'css/bootstrap-dark.min.css' =>
array (
'name' => 'css/bootstrap-dark.min.css',
'info' => 'Legacy Dark Admin',
'nonadmin' => false,
'exclude' => 'bootstrap',
@@ -164,6 +178,7 @@
),
'css/kadmin.css' =>
array (
'name' => 'css/kadmin.css',
'info' => 'K-Admin Inspired',
'nonadmin' => false,
'exclude' => '',
@@ -172,6 +187,7 @@
),
'css/corporate.css' =>
array (
'name' => 'css/corporate.css',
'info' => 'Corporate',
'nonadmin' => false,
'exclude' => 'bootstrap',
@@ -180,6 +196,7 @@
),
'https://maxcdn.bootstrapcdn.com/bootswatch/3.3.7/flatly/bootstrap.min.css' =>
array (
'name' => 'https://maxcdn.bootstrapcdn.com/bootswatch/3.3.7/flatly/bootstrap.min.css',
'info' => 'Flatly',
'nonadmin' => false,
'exclude' => 'bootstrap',
@@ -188,6 +205,7 @@
),
'https://maxcdn.bootstrapcdn.com/bootswatch/3.3.7/sandstone/bootstrap.min.css' =>
array (
'name' => 'https://maxcdn.bootstrapcdn.com/bootswatch/3.3.7/sandstone/bootstrap.min.css',
'info' => 'Sandstone',
'nonadmin' => false,
'exclude' => 'bootstrap',
@@ -196,6 +214,7 @@
),
'https://maxcdn.bootstrapcdn.com/bootswatch/3.3.7/superhero/bootstrap.min.css' =>
array (
'name' => 'https://maxcdn.bootstrapcdn.com/bootswatch/3.3.7/superhero/bootstrap.min.css',
'info' => 'Superhero',
'nonadmin' => false,
'exclude' => 'bootstrap',
@@ -286,7 +305,8 @@
$result = e107::getTheme('bootstrap3')->getThemeFiles('css', 'wysiwyg');
$this->assertSame($expected, $result);
$result = e107::getTheme('bootstrap5')->getThemeFiles('css', 'wysiwyg');
var_export($result);
}