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

Option to save theme prefs in own db row. (like plugins). Example coming soon. Pref Cache aliases updated to avoid conflicts between themes, plugins and core files.

This commit is contained in:
Cameron 2016-12-31 10:10:41 -08:00
parent 2905d64706
commit fda3abae3d
3 changed files with 145 additions and 5 deletions

View File

@ -120,6 +120,13 @@ class e107
*/
protected static $_plug_config_arr = array();
/**
* e107 theme config object storage
*
* @var array
*/
protected static $_theme_config_arr = array();
/**
* Core handlers array
* For new/missing handler add
@ -1027,6 +1034,45 @@ class e107
return self::getPlugConfig($plug_name)->getPref($pref_name, $default, $index);
}
/**
* Retrieve theme config handlers.
* Multiple theme preference DB rows are supported
* Class overload is supported.
* Examples:
* - <code>e107::getTHemeConfig('mytheme');</code>
* will search for e107_plugins/myplug/e_pref/myplug_pref.php which
* should contain class 'e_plugin_myplug_pref' class (child of e_plugin_pref)
* - <code>e107::getPluginConfig('myplug', 'row2');</code>
* will search for e107_plugins/myplug/e_pref/myplug_row2_pref.php which
* should contain class 'e_plugin_myplug_row2_pref' class (child of e_plugin_pref)
*
* @param string $theme_name
* @param string $multi_row
* @param boolean $load load from DB on startup
* @return e_plugin_pref
*/
public static function getThemeConfig($theme_name=null, $multi_row = '', $load = true)
{
if(empty($theme_name))
{
$theme_name = self::getPref('sitetheme');
}
if(!isset(self::$_theme_config_arr[$theme_name.$multi_row]))
{
e107_require_once(e_HANDLER.'pref_class.php');
self::$_theme_config_arr[$theme_name.$multi_row] = new e_theme_pref($theme_name, $multi_row, $load);
}
return self::$_theme_config_arr[$theme_name.$multi_row];
}
/**
* Get current theme preference. $pref_name is parsed,
* so that $pref_name = 'x/y/z' will search for value pref_data[x][y][z]
@ -1040,10 +1086,21 @@ class e107
*/
public static function getThemePref($pref_name = '', $default = null, $index = null)
{
// new storage method in it's own core table row. eg. theme_bootstrap3
$theme_name = self::getPref('sitetheme');
if(self::getThemeConfig($theme_name)->hasData() === true)
{
return empty($pref_name) ? self::getThemeConfig($theme_name)->getPref() : self::getThemeConfig($theme_name)->get($pref_name, $default);
}
// old storage method in core prefs.
$legacy_pref_name = ($pref_name) ? $pref_name = '/'.$pref_name : '';
$tprefs = self::getConfig()->getPref('sitetheme_pref'.$legacy_pref_name, $default, $index);
if($pref_name) $pref_name = '/'.$pref_name;
$tprefs = self::getConfig()->getPref('sitetheme_pref'.$pref_name, $default, $index);
return !empty($tprefs) ? $tprefs : array();
}
/**

View File

@ -69,7 +69,7 @@ class e_pref extends e_front_model
* Constructor
*
* @param string $prefid
* @param string $alias
* @param string $alias Used by cache file.
* @param array $data
* @param boolean $sanitize_data
*/
@ -83,6 +83,7 @@ class e_pref extends e_front_model
{
$alias = $prefid;
}
$this->alias = preg_replace('/[^\w\-]/', '', $alias);
$this->loadData($data, $sanitize_data);
@ -965,7 +966,7 @@ class e_plugin_pref extends e_pref
{
$plugin_id = $plugin_id.'_'.$multi_row;
}
parent::__construct('plugin_'.$plugin_id, $this->plugin_id);
parent::__construct('plugin_'.$plugin_id, "plugin_".$this->plugin_id);
if($load && e107::findPref('plug_installed/'.$this->plugin_id))
{
$this->load();
@ -999,6 +1000,81 @@ class e_plugin_pref extends e_pref
}
}
/**
* Handle plugin preferences
*
* @package e107
* @category e107_handlers
* @version 1.0
* @author SecretR
* @copyright Copyright (c) 2009, e107 Inc.
*/
class e_theme_pref extends e_pref
{
/**
* Unique plugin name
*
* @var string
*/
protected $theme_id;
/**
* Constructor
* Note: object data will be loaded only if the plugin is installed (no matter of the passed
* $load value)
*
* @param string $theme_id unique plugin name
* @param string $multi_row additional field identifier appended to the $prefid
* @param boolean $load load on startup
*/
function __construct($theme_id, $multi_row = '', $load = true)
{
$this->theme_id = $theme_id;
if($multi_row)
{
$theme_id = $theme_id.'_'.$multi_row;
}
parent::__construct('theme_'.$theme_id, "theme_".$this->theme_id);
// if($load && e107::findPref('plug_installed/'.$this->theme_id))
{
$this->load();
}
}
/**
* Retrive unique plugin name
*
* @return string
*/
public function getPluginId()
{
return $this->theme_id;
}
/**
* Delete plugin preferences
* @see e107_handlers/e_pref#delete()
* @return boolean
*/
public function delete($ids, $destroy = true, $session_messages = false)
{
$ret = false;
if($this->theme_id)
{
$ret = e107::getDb($this->theme_id)->delete('core', "e107_name='{$this->theme_id}'");
$this->destroy();
}
return $ret;
}
}
/**
* DEPRECATED - see e107::getConfig(), e_core_pref and e_plugin_pref
*

View File

@ -71,6 +71,12 @@ class user_dashboard // plugin-folder + '_url'
{
$diz = date('j', $row['user_join']);
if(!isset($amt[$diz]))
{
$amt[$diz] = 0;
}
$amt[$diz] += 1;
$dateName[$diz] = date('jS', $row['user_join']);
}
@ -90,7 +96,8 @@ class user_dashboard // plugin-folder + '_url'
for ($i=1; $i < ($totalDays +1); $i++)
{
$diz = date('D jS', mktime(1,1,1,$monthNumber,$i, $yearNumber));
$data[] = array($diz, $amt[$i]); // $dateName[$i]
$val = !empty($amt[$i]) ? $amt[$i] : 0;
$data[] = array($diz, $val); // $dateName[$i]
$ticks[] = $i;
}