1
0
mirror of https://github.com/e107inc/e107.git synced 2025-01-17 04:38:27 +01:00

Ability to use theme.xml to define library dependencies.

This commit is contained in:
Lóna Lore 2017-03-02 20:55:31 +01:00
parent aa36466220
commit 53a7fb2fc9
8 changed files with 175 additions and 35 deletions

View File

@ -111,6 +111,10 @@ function loadJSAddons()
}
// Load library dependencies.
e107::getTheme('current', true)->loadLibrary();
// Load other JS files.
loadJSAddons();

View File

@ -23,7 +23,8 @@ $sql = e107::getDb();
$sql->db_Mark_Time('(Header Top)');
// Load library dependencies.
e107::getTheme('current', true)->loadLibrary();
//e107::js('core', 'bootstrap/js/bootstrap-tooltip.js','jquery');
// e107::css('core', 'bootstrap/css/tooltip.css','jquery');

View File

@ -1404,7 +1404,6 @@ class e107
if(!defined('E107_INSTALL'))
{
if($themedir === 'front')
{
$themedir= self::getPref('sitetheme');
@ -1416,6 +1415,19 @@ class e107
}
}
// Get the currently used theme.
if ($themedir == 'current')
{
// If we are in the admin area.
if (deftrue('e_ADMIN_AREA', false))
{
$themedir = self::getPref('admintheme');
}
else
{
$themedir= self::getPref('sitetheme');
}
}
return self::getSingleton('e_theme', true, null, array('themedir'=> $themedir, 'force'=> $clearCache));
}

View File

@ -1877,13 +1877,63 @@ class e_library_manager
$coreLib = $coreLibs[$library['machine_name']];
$library['files'] = $coreLib['files'];
$library['variants'] = $coreLib['variants'];
// Admin UI uses its own CSS.
unset($library['files']['css']);
unset($library['variants']['dev']['files']['css']);
break;
}
}
$excluded = $this->getExcludedLibraries();
if(empty($excluded))
{
return;
}
// Make sure we have the name without cdn prefix.
$basename = str_replace('cdn.', '', $library['machine_name']);
// If this library (or the CDN version of this library) is excluded
// by the theme is currently used.
if (in_array($basename, $excluded) || in_array('cdn.' . $basename, $excluded))
{
unset($library['files']['css']);
if (!empty($library['variants']))
{
foreach($library['variants'] as &$variant)
{
if(!empty($variant['files']['css']))
{
unset($variant['files']['css']);
}
}
}
}
}
/**
* Get excluded libraries.
*
* @return array
*/
public function getExcludedLibraries()
{
// This static cache is re-used by preLoad() to save memory.
static $excludedLibraries;
if(!isset($excludedLibraries))
{
$excludedLibraries = array();
$exclude = e107::getTheme('current', true)->cssAttribute('auto', 'exclude');
if($exclude)
{
// Split string into array and remove whitespaces.
$excludedLibraries = array_map('trim', explode(',', $exclude));
}
}
return $excludedLibraries;
}
}

View File

@ -80,12 +80,64 @@ class e_theme
}
/**
* Get info on the current front or admin theme and selected style. (ie. as found in theme.xml <stylesheets>)
* @param string $mode
* @param null $var file | name | scope | library
* @return bool
* Load library dependencies.
*
* @param string $scope
* front | admin | all | auto
*/
public function cssAttribute($mode='front', $var=null)
public function loadLibrary($scope = 'auto')
{
if($scope === 'auto')
{
$scope = 'front';
if(deftrue('e_ADMIN_AREA', false))
{
$scope = 'admin';
}
}
$libraries = $this->get('library');
if(empty($libraries))
{
return;
}
foreach($libraries as $library)
{
if(empty($library['name']))
{
continue;
}
// If no scope set, we load library on both areas.
if(empty($library['scope']) || $library['scope'] === 'all')
{
e107::library('load', $library['name']);
continue;
}
if($library['scope'] === $scope)
{
e107::library('load', $library['name']);
continue;
}
}
}
/**
* Get info on the current front or admin theme and selected style.
* (ie. as found in theme.xml <stylesheets>)
*
* @param string $mode
* front | admin | auto
* @param string $var
* file | name | scope | exclude
*
* @return mixed
*/
public function cssAttribute($mode = 'front', $var = null)
{
$css = $this->get('css');
@ -94,23 +146,30 @@ class e_theme
return false;
}
foreach($css as $k=>$v)
if($mode === 'auto')
{
$mode = 'front';
if(deftrue('e_ADMIN_AREA', false))
{
$mode = 'admin';
}
}
foreach($css as $k => $v)
{
if($mode === 'front' && $v['name'] === $this->_frontcss)
{
return !empty($var) ? varset($v[$var],null) : $v;
return !empty($var) ? varset($v[$var], null) : $v;
}
if($mode === 'admin' && $v['name'] === $this->_admincss)
{
return !empty($var) ? varset($v[$var],null) : $v;
return !empty($var) ? varset($v[$var], null) : $v;
}
}
return false;
}
@ -622,10 +681,26 @@ class e_theme
}
$vars['layouts'] = $lays;
$vars['path'] = $path;
$vars['custompages'] = $custom;
$vars['legacy'] = false;
$vars['layouts'] = $lays;
$vars['path'] = $path;
$vars['custompages'] = $custom;
$vars['legacy'] = false;
$vars['library'] = array();
if(!empty($vars['libraries']['library']))
{
$vars['css'] = array();
foreach($vars['libraries']['library'] as $val)
{
$vars['library'][] = array(
'name' => $val['@attributes']['name'],
'scope' => varset($val['@attributes']['scope']),
);
}
unset($vars['libraries']);
}
if(!empty($vars['stylesheets']['css']))
{
@ -641,7 +716,7 @@ class e_theme
"info" => $val['@attributes']['name'],
"nonadmin" => $notadmin,
'scope' => vartrue($val['@attributes']['scope']),
'library' => vartrue($val['@attributes']['library'])
'exclude' => vartrue($val['@attributes']['exclude'])
);
}

View File

@ -20,10 +20,6 @@ define("SEP", " <span class='fa fa-play e-breadcrumb'></span> ");
define("BOOTSTRAP", 3);
define('FONTAWESOME', 4);
e107::library('load', 'bootstrap');
e107::library('load', 'fontawesome');
e107::library('load', 'bootstrap.editable');
$adminStyle = e107::pref('core', 'admincss', 'css/bootstrap-dark.min.css');
e107::css('theme', $adminStyle);
e107::css('theme', 'admin_style.css');

View File

@ -20,9 +20,6 @@ define("BOOTSTRAP", 3);
define("FONTAWESOME", 4);
define('VIEWPORT', "width=device-width, initial-scale=1.0");
e107::library('load', 'bootstrap');
e107::library('load', 'fontawesome');
// CDN provider for Bootswatch.
$cndPref = e107::pref('theme', 'cdn', 'cdnjs');
$bootswatch = e107::pref('theme', 'bootswatch', false);

View File

@ -17,13 +17,18 @@
<screenshots>
<image>preview_frontend.png</image>
</screenshots>
<libraries>
<library name="bootstrap" scope="all"/>
<library name="fontawesome" scope="all"/>
<library name="bootstrap.editable" scope="admin"/>
</libraries>
<stylesheets>
<css file="style.css" name="Default" library="bootstrap,fontawesome" />
<css file="css/bootstrap-dark.min.css" name="Bootstrap3 Dark Admin" scope='admin' library='fontawesome' />
<css file="https://maxcdn.bootstrapcdn.com/bootswatch/3.3.7/flatly/bootstrap.min.css" name="Flatly" scope='admin' library='fontawesome' />
<css file="https://maxcdn.bootstrapcdn.com/bootswatch/3.3.7/sandstone/bootstrap.min.css" name="Sandstone" library='fontawesome' scope='admin' />
<css file="https://maxcdn.bootstrapcdn.com/bootswatch/3.3.7/superhero/bootstrap.min.css" name="Superhero" library='fontawesome' scope='admin' />
<css file="*" name="*" />
<css file="style.css" name="Default"/>
<css file="css/bootstrap-dark.min.css" name="Bootstrap3 Dark Admin" scope='admin' exclude='bootstrap'/>
<css file="https://maxcdn.bootstrapcdn.com/bootswatch/3.3.7/flatly/bootstrap.min.css" name="Flatly" scope='admin' exclude='bootstrap'/>
<css file="https://maxcdn.bootstrapcdn.com/bootswatch/3.3.7/sandstone/bootstrap.min.css" name="Sandstone" scope='admin' exclude='bootstrap'/>
<css file="https://maxcdn.bootstrapcdn.com/bootswatch/3.3.7/superhero/bootstrap.min.css" name="Superhero" scope='admin' exclude='bootstrap'/>
<css file="*" name="*"/>
</stylesheets>
<layouts>
<layout name='jumbotron_home' title='Jumbotron (home)' default='false'>