mirror of
https://github.com/e107inc/e107.git
synced 2025-04-19 20:21:51 +02:00
Theme handler optimization
This commit is contained in:
parent
4823730ef1
commit
87b9489976
@ -1387,14 +1387,23 @@ class e107
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Retrieve rater singleton object
|
||||
*
|
||||
/**
|
||||
* Retrieve e_theme singleton object
|
||||
* @return e_theme
|
||||
*/
|
||||
public static function getTheme()
|
||||
public static function getTheme($themedir='front', $clearCache=false)
|
||||
{
|
||||
return self::getSingleton('e_theme', true);
|
||||
if($themedir === 'front')
|
||||
{
|
||||
$themedir= self::getPref('sitetheme');
|
||||
}
|
||||
|
||||
if($themedir === 'admin')
|
||||
{
|
||||
$themedir = self::getPref('admintheme');
|
||||
}
|
||||
|
||||
return self::getSingleton('e_theme', true, null, array('themedir'=> $themedir, 'force'=> $clearCache));
|
||||
}
|
||||
|
||||
|
||||
|
@ -40,17 +40,77 @@ class e_theme
|
||||
'multimedia'
|
||||
);
|
||||
|
||||
private $_data = array();
|
||||
|
||||
private $_current = null;
|
||||
|
||||
private $_frontcss = null;
|
||||
|
||||
private $_admincss = null;
|
||||
|
||||
private $_legacy_themes = array();
|
||||
|
||||
|
||||
const CACHETIME = 120; // 2 hours
|
||||
const CACHETAG = "Meta_theme";
|
||||
|
||||
|
||||
function __construct()
|
||||
function __construct($options=array())
|
||||
{
|
||||
|
||||
if(!empty($options['themedir']))
|
||||
{
|
||||
$this->_current = $options['themedir'];
|
||||
}
|
||||
|
||||
if(!defined('E107_INSTALL'))
|
||||
{
|
||||
$this->_frontcss = e107::getPref('themecss');
|
||||
$this->_admincss = e107::getPref('admincss');
|
||||
}
|
||||
|
||||
if(empty($this->_data) || $options['force'] === true)
|
||||
{
|
||||
|
||||
$this->load($options['force']);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
public function cssAttribute($mode='front', $var=null)
|
||||
{
|
||||
$css = $this->get('css');
|
||||
|
||||
if(empty($css))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach($css as $k=>$v)
|
||||
{
|
||||
if($mode === 'front' && $v['name'] === $this->_frontcss)
|
||||
{
|
||||
return !empty($var) ? varset($v[$var],null) : $v;
|
||||
}
|
||||
|
||||
if($mode === 'admin' && $v['name'] === $this->_admincss)
|
||||
{
|
||||
return !empty($var) ? varset($v[$var],null) : $v;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -91,11 +151,101 @@ class e_theme
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Load data for all themes in theme directory.
|
||||
* @param bool|false $force
|
||||
* @return $this
|
||||
*/
|
||||
private function load($force=false)
|
||||
{
|
||||
$themeArray = array();
|
||||
|
||||
$tloop = 1;
|
||||
|
||||
$cacheTag = self::CACHETAG;
|
||||
|
||||
if($force === false && $tmp = e107::getCache()->retrieve($cacheTag, self::CACHETIME, true, true))
|
||||
{
|
||||
$this->_data = e107::unserialize($tmp);
|
||||
return $this;
|
||||
}
|
||||
|
||||
$array = scandir(e_THEME);
|
||||
|
||||
foreach($array as $file)
|
||||
{
|
||||
if($file != "." && $file != ".." && $file != "CVS" && $file != "templates" && is_dir(e_THEME.$file) && is_readable(e_THEME.$file."/theme.php"))
|
||||
{
|
||||
|
||||
$themeArray[$file] = self::getThemeInfo($file);
|
||||
$themeArray[$file]['id'] = $tloop;
|
||||
|
||||
$tloop++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$cacheSet = e107::serialize($themeArray,'json');
|
||||
|
||||
e107::getCache()->set($cacheTag,$cacheSet,true,true,true);
|
||||
|
||||
$this->_data = $themeArray;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return a var from the current theme.
|
||||
* @param $var
|
||||
* @param null $key
|
||||
* @return array|bool
|
||||
*/
|
||||
public function get($var, $key=null)
|
||||
{
|
||||
return isset($this->_data[$this->_current][$var]) ? $this->_data[$this->_current][$var] : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a list of all local themes in various formats.
|
||||
* Replaces getThemeList
|
||||
* @param null|string $mode null, 'version' | 'id'
|
||||
* @return array|bool a list or false if no results
|
||||
*/
|
||||
public function getList($mode=null)
|
||||
{
|
||||
$arr = array();
|
||||
|
||||
if($mode === 'version')
|
||||
{
|
||||
foreach($this->_data as $dir=>$v)
|
||||
{
|
||||
$arr[$dir] = $v['version'];
|
||||
}
|
||||
|
||||
}
|
||||
elseif($mode === 'id')
|
||||
{
|
||||
foreach($this->_data as $dir=>$v)
|
||||
{
|
||||
$arr[] = $dir;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$arr = $this->_data;
|
||||
}
|
||||
|
||||
|
||||
return !empty($arr) ? $arr : false;
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of all themes in theme folder and its data.
|
||||
* @deprecated
|
||||
* @see load();
|
||||
* @param bool|false xml|false
|
||||
* @param bool|false $force force a refresh ie. ignore cached list.
|
||||
* @return array
|
||||
@ -157,8 +307,12 @@ class e_theme
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Internal Use. Heavy CPU usage.
|
||||
* Use e107::getTheme($themeDir,$force)->get() instead.
|
||||
* @param $file
|
||||
* @return mixed
|
||||
*/
|
||||
public static function getThemeInfo($file)
|
||||
{
|
||||
$reject = array('e_.*');
|
||||
@ -233,7 +387,10 @@ class e_theme
|
||||
public static function parse_theme_php($path)
|
||||
{
|
||||
$CUSTOMPAGES = "";
|
||||
$tp = e107::getParser();
|
||||
|
||||
$tp = e107::getParser(); // could be used by a theme file.
|
||||
$sql = e107::getDb(); // could be used by a theme file.
|
||||
|
||||
$fp = fopen(e_THEME.$path."/theme.php", "r");
|
||||
$themeContents = fread($fp, filesize(e_THEME.$path."/theme.php"));
|
||||
fclose($fp);
|
||||
@ -341,6 +498,7 @@ class e_theme
|
||||
}
|
||||
// echo "<h2>".$themeArray['name']."</h2>";
|
||||
// print_a($lays);
|
||||
$themeArray['legacy'] = true;
|
||||
|
||||
return $themeArray;
|
||||
}
|
||||
@ -453,6 +611,7 @@ class e_theme
|
||||
$vars['layouts'] = $lays;
|
||||
$vars['path'] = $path;
|
||||
$vars['custompages'] = $custom;
|
||||
$vars['legacy'] = false;
|
||||
|
||||
if(!empty($vars['stylesheets']['css']))
|
||||
{
|
||||
@ -462,7 +621,15 @@ class e_theme
|
||||
{
|
||||
// $notadmin = vartrue($val['@attributes']['admin']) ? false : true;
|
||||
$notadmin = (varset($val['@attributes']['scope']) !== 'admin') ? true : false;
|
||||
$vars['css'][] = array("name" => $val['@attributes']['file'], "info"=> $val['@attributes']['name'], "nonadmin"=>$notadmin, 'scope'=> vartrue($val['@attributes']['scope']));
|
||||
|
||||
$vars['css'][] = array(
|
||||
"name" => $val['@attributes']['file'],
|
||||
"info" => $val['@attributes']['name'],
|
||||
"nonadmin" => $notadmin,
|
||||
'scope' => vartrue($val['@attributes']['scope']),
|
||||
'library' => vartrue($val['@attributes']['library'])
|
||||
|
||||
);
|
||||
}
|
||||
|
||||
unset($vars['stylesheets']);
|
||||
|
@ -18,11 +18,11 @@
|
||||
<image>preview_frontend.png</image>
|
||||
</screenshots>
|
||||
<stylesheets>
|
||||
<css file="style.css" name="Default" />
|
||||
<css file="css/bootstrap-dark.min.css" name="Bootstrap3 Dark Admin" scope='admin' />
|
||||
<css file="https://maxcdn.bootstrapcdn.com/bootswatch/3.3.7/flatly/bootstrap.min.css" name="Flatly" scope='admin' />
|
||||
<css file="https://maxcdn.bootstrapcdn.com/bootswatch/3.3.7/sandstone/bootstrap.min.css" name="Sandstone" scope='admin' />
|
||||
<css file="https://maxcdn.bootstrapcdn.com/bootswatch/3.3.7/superhero/bootstrap.min.css" name="Superhero" scope='admin' />
|
||||
<css file="style.css" name="Default" library='bootstrap,fontawesome' />
|
||||
<css file="css/bootstrap-dark.min.css" name="Bootstrap3 Dark Admin" scope='admin' library='false' />
|
||||
<css file="https://maxcdn.bootstrapcdn.com/bootswatch/3.3.7/flatly/bootstrap.min.css" name="Flatly" scope='admin' library='false' />
|
||||
<css file="https://maxcdn.bootstrapcdn.com/bootswatch/3.3.7/sandstone/bootstrap.min.css" name="Sandstone" library='false' scope='admin' />
|
||||
<css file="https://maxcdn.bootstrapcdn.com/bootswatch/3.3.7/superhero/bootstrap.min.css" name="Superhero" library='false' scope='admin' />
|
||||
<css file="*" name="*" />
|
||||
</stylesheets>
|
||||
<layouts>
|
||||
|
@ -538,6 +538,7 @@ $(document).ready(function()
|
||||
|
||||
$(this).switchClass( "link", "link-active", 30 );
|
||||
$(this).closest("li").addClass("active");
|
||||
|
||||
$(id).removeClass('e-hideme').show({
|
||||
effect: "slide"
|
||||
});
|
||||
@ -545,7 +546,8 @@ $(document).ready(function()
|
||||
if(hash) {
|
||||
window.location.hash = 'nav-' + hash;
|
||||
if(form) {
|
||||
$(form).attr('action', $(form).attr('action').split('#')[0] + '#nav-' + hash);
|
||||
|
||||
// $(form).attr('action', $(form).attr('action').split('#')[0] + '#nav-' + hash); // breaks menu-manager nav.
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user