mirror of
https://github.com/e107inc/e107.git
synced 2025-08-01 20:30:39 +02:00
Preference handler fixes and BC, save_prefs() is using pref handler now and is deprecated, theme handler changes to reflect new preference management.
This commit is contained in:
37
class2.php
37
class2.php
@@ -9,9 +9,9 @@
|
||||
* General purpose file
|
||||
*
|
||||
* $Source: /cvs_backup/e107_0.8/class2.php,v $
|
||||
* $Revision: 1.129 $
|
||||
* $Date: 2009-08-16 23:58:30 $
|
||||
* $Author: e107coders $
|
||||
* $Revision: 1.130 $
|
||||
* $Date: 2009-08-17 14:40:23 $
|
||||
* $Author: secretr $
|
||||
*
|
||||
*/
|
||||
//
|
||||
@@ -1472,10 +1472,36 @@ function get_user_data($uid, $extra = '')
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------//
|
||||
|
||||
//SO MUCH DEPRECATED - use e107::getConfig(alias)->save() instead
|
||||
function save_prefs($table = 'core', $uid = USERID, $row_val = '')
|
||||
{
|
||||
global $pref, $user_pref, $tp, $PrefCache, $sql, $eArrayStorage, $theme_pref, $iconpool;
|
||||
global $pref, $user_pref, $tp, $PrefCache, $sql, $eArrayStorage, $theme_pref, $iconpool;
|
||||
|
||||
switch($table)
|
||||
{
|
||||
case 'core':
|
||||
//brute load, force update
|
||||
return e107::getConfig()->loadData($pref, false)->save(false, true);
|
||||
break;
|
||||
|
||||
case 'iconpool':
|
||||
//brute load, force update
|
||||
return e107::getConfig('ipool')->loadData($iconpool, true)->save(false, true);
|
||||
break;
|
||||
|
||||
case 'theme':
|
||||
//brute load, force update
|
||||
return e107::getConfig()->set('sitetheme_pref', $theme_pref)->save(false, true);
|
||||
break;
|
||||
|
||||
default:
|
||||
$_user_pref = $tp->toDB($user_pref, true, true);
|
||||
$tmp = $eArrayStorage->WriteArray($_user_pref);
|
||||
$sql->db_Update('user', "user_prefs='$tmp' WHERE user_id=".intval($uid));
|
||||
return $tmp;
|
||||
break;
|
||||
}
|
||||
/*
|
||||
if ($table == 'core')
|
||||
{
|
||||
if ($row_val == '')
|
||||
@@ -1526,6 +1552,7 @@ function save_prefs($table = 'core', $uid = USERID, $row_val = '')
|
||||
$sql->db_Update('user', "user_prefs='$tmp' WHERE user_id=".intval($uid));
|
||||
return $tmp;
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
|
@@ -9,9 +9,9 @@
|
||||
* e107 Main
|
||||
*
|
||||
* $Source: /cvs_backup/e107_0.8/e107_handlers/e107_class.php,v $
|
||||
* $Revision: 1.36 $
|
||||
* $Date: 2009-08-17 11:29:41 $
|
||||
* $Author: e107coders $
|
||||
* $Revision: 1.37 $
|
||||
* $Date: 2009-08-17 14:40:22 $
|
||||
* $Author: secretr $
|
||||
*/
|
||||
|
||||
if (!defined('e107_INIT')) { exit; }
|
||||
@@ -370,7 +370,7 @@ class e107
|
||||
*/
|
||||
public static function getPlugPref($plug_name, $pref_name, $default = null)
|
||||
{
|
||||
return self::getPlugConfig($plug_name)->get($pref_name, $default);
|
||||
return empty($pref_name) ? self::getPlugConfig($plug_name)->getPref() : self::getPlugConfig($plug_name)->get($pref_name, $default);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -398,10 +398,9 @@ class e107
|
||||
* @param mixed $default default value if preference is not found
|
||||
* @return mixed
|
||||
*/
|
||||
public static function getThemePref($pref_name, $default = null, $index = null)
|
||||
public static function getThemePref($pref_name = '', $default = null, $index = null)
|
||||
{
|
||||
$prefobj = e107::getConfig();
|
||||
return $prefobj->getPref('sitetheme_pref/'.$pref_name, $default, $index);
|
||||
return e107::getConfig()->getPref('sitetheme_pref/'.$pref_name, $default, $index);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -9,9 +9,9 @@
|
||||
* e107 Preference Handler
|
||||
*
|
||||
* $Source: /cvs_backup/e107_0.8/e107_handlers/pref_class.php,v $
|
||||
* $Revision: 1.9 $
|
||||
* $Date: 2009-08-08 08:11:02 $
|
||||
* $Author: marj_nl_fr $
|
||||
* $Revision: 1.10 $
|
||||
* $Date: 2009-08-17 14:40:23 $
|
||||
* $Author: secretr $
|
||||
*/
|
||||
|
||||
if (!defined('e107_INIT')) { exit; }
|
||||
@@ -84,6 +84,7 @@ class e_pref extends e_model
|
||||
$alias = $prefid;
|
||||
}
|
||||
$this->alias = preg_replace('/[^\w\-]/', '', $alias);
|
||||
|
||||
$this->loadData($data, $sanitize_data);
|
||||
}
|
||||
|
||||
@@ -115,13 +116,39 @@ class e_pref extends e_model
|
||||
|
||||
/**
|
||||
* Advanced setter - $pref_name is parsed (multidimensional arrays support)
|
||||
* Object data reseting is not allowed, adding new pref is not allowed
|
||||
* Object data reseting is not allowed, adding new pref is allowed
|
||||
* @param string|array $pref_name
|
||||
* @param mixed $value
|
||||
* @return e_pref
|
||||
*/
|
||||
public function setPref($pref_name, $value = null)
|
||||
{
|
||||
global $pref;
|
||||
//object reset not allowed, adding new pref is allowed
|
||||
if(empty($pref_name))
|
||||
{
|
||||
return $this;
|
||||
}
|
||||
parent::setData($pref_name, $value, false);
|
||||
|
||||
//BC
|
||||
if($this->alias === 'core')
|
||||
{
|
||||
$pref = $this->getData();
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Advanced setter - $pref_name is parsed (multidimensional arrays support)
|
||||
* Object data reseting is not allowed, adding new pref is not allowed
|
||||
* @param string|array $pref_name
|
||||
* @param mixed $value
|
||||
* @return e_pref
|
||||
*/
|
||||
public function updatePref($pref_name, $value = null)
|
||||
{
|
||||
global $pref;
|
||||
//object reset not allowed, adding new pref is not allowed
|
||||
if(empty($pref_name))
|
||||
{
|
||||
@@ -129,25 +156,17 @@ class e_pref extends e_model
|
||||
}
|
||||
parent::setData($pref_name, $value, true);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Alias of {@link setPref()}
|
||||
*
|
||||
* @param string $pref_name
|
||||
* @param mixed $value
|
||||
* @return e_pref
|
||||
*/
|
||||
public function updatePref($pref_name, $value)
|
||||
{
|
||||
$this->setPref($pref_name, $value);
|
||||
//BC
|
||||
if($this->alias === 'core')
|
||||
{
|
||||
$pref = $this->getData();
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Simple setter - $pref_name is not parsed (no multidimensional arrays support)
|
||||
* Adding new pref is not allowed
|
||||
* Adding new pref is allowed
|
||||
*
|
||||
* @param string $pref_name
|
||||
* @param mixed $value
|
||||
@@ -155,16 +174,24 @@ class e_pref extends e_model
|
||||
*/
|
||||
public function set(string $pref_name, $value)
|
||||
{
|
||||
global $pref;
|
||||
if(empty($pref_name))
|
||||
{
|
||||
return $this;
|
||||
}
|
||||
parent::set($pref_name, $value, true);
|
||||
parent::set($pref_name, $value, false);
|
||||
|
||||
//BC
|
||||
if($this->alias === 'core')
|
||||
{
|
||||
$pref = $this->getData();
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Alias of {@link set()}
|
||||
* Simple setter - $pref_name is not parsed (no multidimensional arrays support)
|
||||
* Non existing setting will be not created
|
||||
*
|
||||
* @param string $pref_name
|
||||
* @param mixed $value
|
||||
@@ -172,7 +199,18 @@ class e_pref extends e_model
|
||||
*/
|
||||
public function update(string $pref_name, $value)
|
||||
{
|
||||
$this->set($pref_name, $value);
|
||||
global $pref;
|
||||
if(empty($pref_name))
|
||||
{
|
||||
return $this;
|
||||
}
|
||||
parent::set($pref_name, $value, true);
|
||||
|
||||
//BC
|
||||
if($this->alias === 'core')
|
||||
{
|
||||
$pref = $this->getData();
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
@@ -217,7 +255,14 @@ class e_pref extends e_model
|
||||
*/
|
||||
public function remove(string $pref_name)
|
||||
{
|
||||
global $pref;
|
||||
parent::remove($pref_name);
|
||||
|
||||
//BC
|
||||
if($this->alias === 'core')
|
||||
{
|
||||
$pref = $this->getData();
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
@@ -244,7 +289,13 @@ class e_pref extends e_model
|
||||
*/
|
||||
final public function addData($pref_name, $value = null)
|
||||
{
|
||||
global $pref;
|
||||
parent::addData($pref_name, $value, false);
|
||||
//BC
|
||||
if($this->alias === 'core')
|
||||
{
|
||||
$pref = $this->getData();
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
@@ -258,7 +309,14 @@ class e_pref extends e_model
|
||||
*/
|
||||
final public function setData($pref_name, $value = null)
|
||||
{
|
||||
global $pref;
|
||||
parent::setData($pref_name, $value, true);
|
||||
|
||||
//BC
|
||||
if($this->alias === 'core')
|
||||
{
|
||||
$pref = $this->getData();
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
@@ -271,7 +329,14 @@ class e_pref extends e_model
|
||||
*/
|
||||
final public function removeData(string $pref_name)
|
||||
{
|
||||
global $pref;
|
||||
parent::removeData($pref_name);
|
||||
|
||||
//BC
|
||||
if($this->alias === 'core')
|
||||
{
|
||||
$pref = $this->getData();
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
@@ -284,6 +349,7 @@ class e_pref extends e_model
|
||||
*/
|
||||
public function loadData(array $data, $sanitize = true)
|
||||
{
|
||||
global $pref;
|
||||
if(!empty($data))
|
||||
{
|
||||
if($sanitize)
|
||||
@@ -292,6 +358,11 @@ class e_pref extends e_model
|
||||
}
|
||||
parent::setData($data, null, false);
|
||||
$this->pref_cache = e107::getArrayStorage()->WriteArray($data, false); //runtime cache
|
||||
//BC
|
||||
if($this->alias === 'core')
|
||||
{
|
||||
$pref = $this->getData();
|
||||
}
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
@@ -305,10 +376,16 @@ class e_pref extends e_model
|
||||
*/
|
||||
public function load($force = false)
|
||||
{
|
||||
global $pref;
|
||||
if($force || !$this->hasData())
|
||||
{
|
||||
$this->data_has_changed = false;
|
||||
$this->_load($force);
|
||||
//BC
|
||||
if($this->alias === 'core')
|
||||
{
|
||||
$pref = $this->getData();
|
||||
}
|
||||
}
|
||||
|
||||
return $this;
|
||||
@@ -327,12 +404,11 @@ class e_pref extends e_model
|
||||
|
||||
if($data !== false)
|
||||
{
|
||||
//var_dump('Pref cache used: '.$this->alias);
|
||||
$this->pref_cache = e107::getArrayStorage()->WriteArray($data, false); //runtime cache
|
||||
return $this->loadData($data, false);
|
||||
$this->loadData($data, false);
|
||||
return $this;
|
||||
}
|
||||
|
||||
//var_dump('Pref cache not used: '.$this->alias);
|
||||
if (e107::getDb()->db_Select('core', 'e107_value', "e107_name='{$id}'"))
|
||||
{
|
||||
$row = e107::getDb()->db_Fetch();
|
||||
@@ -354,7 +430,8 @@ class e_pref extends e_model
|
||||
if(empty($data))
|
||||
$data = array();
|
||||
|
||||
return $this->loadData($data, false);
|
||||
$this->loadData($data, false);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -367,9 +444,10 @@ class e_pref extends e_model
|
||||
*/
|
||||
public function save($from_post = true, $force = false, $session_messages = false)
|
||||
{
|
||||
global $pref;
|
||||
if(!$this->prefid)
|
||||
{
|
||||
return $this;
|
||||
return false;
|
||||
}
|
||||
|
||||
if($from_post)
|
||||
@@ -401,6 +479,9 @@ class e_pref extends e_model
|
||||
|
||||
if(e107::getDb()->db_Select_gen("REPLACE INTO `#core` (e107_name,e107_value) values ('{$this->prefid}', '".addslashes($dbdata)."') "))
|
||||
{
|
||||
$this->data_has_changed = false; //reset status
|
||||
$this->setPrefCache($this->toString(false), true); //reset pref cache - runtime & file
|
||||
|
||||
if($this->set_backup === true)
|
||||
{
|
||||
if($this->serial_bc)
|
||||
@@ -411,16 +492,19 @@ class e_pref extends e_model
|
||||
{
|
||||
$dbdata = $this->pref_cache;
|
||||
}
|
||||
if(e107::getDb()->db_Select_gen("REPLACE INTO `#core` (e107_name,e107_value) values ('{$this->prefid}_Backup', '".addslashes($dbdata)."') "))
|
||||
if(e107::getDb()->db_Select_gen("REPLACE INTO `#core` (e107_name,e107_value) values ('".$this->prefid."_Backup', '".addslashes($dbdata)."') "))
|
||||
{
|
||||
$emessage->add('Backup successfully created.', E_MESSAGE_SUCCESS, $session_messages);
|
||||
ecache::clear_sys('Config_'.$this->alias.'_backup');
|
||||
}
|
||||
}
|
||||
|
||||
$this->data_has_changed = false; //reset status
|
||||
$this->setPrefCache($this->toString(false), true); //reset pref cache - runtime & file
|
||||
$emessage->add('Settings successfully saved.', E_MESSAGE_SUCCESS, $session_messages);
|
||||
//BC
|
||||
if($this->alias === 'core')
|
||||
{
|
||||
$pref = $this->getData();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
//TODO - DB error messages
|
||||
@@ -476,7 +560,6 @@ class e_pref extends e_model
|
||||
}
|
||||
if($save)
|
||||
{
|
||||
|
||||
ecache::set_sys('Config_'.($save !== true ? $save : $this->alias), $cache_string, true);
|
||||
}
|
||||
return $this;
|
||||
@@ -916,7 +999,6 @@ class e_model
|
||||
*/
|
||||
public function set($key, $value = null, $strict = false)
|
||||
{
|
||||
$this->data_has_changed = true;
|
||||
return $this->_setDataSimple($key, $value, $strict);
|
||||
}
|
||||
|
||||
@@ -1120,6 +1202,14 @@ class e_model
|
||||
return ($strict ? $newData !== $postedData : $newData != $postedData);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return boolean
|
||||
*/
|
||||
public function dataHasChanged()
|
||||
{
|
||||
return $this->data_has_changed;
|
||||
}
|
||||
|
||||
/**
|
||||
* Merge posted data with the object data
|
||||
* Should be used on edit/update/create record (back-end)
|
||||
@@ -1383,12 +1473,12 @@ class e_model
|
||||
{
|
||||
if(!$strict)
|
||||
{
|
||||
$this->{$data_src}[$key] = $value;
|
||||
//data has changed
|
||||
if('_data' === $data_src && !$this->data_has_changed)
|
||||
{
|
||||
$this->data_has_changed = (isset($this->_data[$key]) && $this->_data[$key] != $value);
|
||||
}
|
||||
$this->{$data_src}[$key] = $value;
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
@@ -10,9 +10,9 @@
|
||||
| GNU General Public License (http://gnu.org).
|
||||
|
|
||||
| $Source: /cvs_backup/e107_0.8/e107_handlers/theme_handler.php,v $
|
||||
| $Revision: 1.45 $
|
||||
| $Date: 2009-08-17 12:48:52 $
|
||||
| $Author: e107coders $
|
||||
| $Revision: 1.46 $
|
||||
| $Date: 2009-08-17 14:40:22 $
|
||||
| $Author: secretr $
|
||||
+----------------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
@@ -76,15 +76,21 @@ class themeHandler{
|
||||
if(isset($_POST['submit_adminstyle']))
|
||||
{
|
||||
$this -> id = $_POST['curTheme'];
|
||||
$this -> setAdminStyle();
|
||||
|
||||
if($this -> setAdminStyle())
|
||||
{
|
||||
eMessage::getInstance()->add(TPVLAN_43, E_MESSAGE_SUCCESS);
|
||||
}
|
||||
e107::getConfig()->save(true);
|
||||
}
|
||||
|
||||
if(isset($_POST['submit_style']))
|
||||
{
|
||||
$this -> id = $_POST['curTheme'];
|
||||
$this -> setStyle();
|
||||
|
||||
$this -> SetCustomPages($_POST['custompages']);
|
||||
$this -> setStyle();
|
||||
|
||||
e107::getConfig()->save(true);
|
||||
|
||||
}
|
||||
|
||||
@@ -564,9 +570,7 @@ class themeHandler{
|
||||
|
||||
function setThemeConfig()
|
||||
{
|
||||
global $theme_pref;
|
||||
$this -> loadThemeConfig();
|
||||
|
||||
if($this->themeConfigObj)
|
||||
{
|
||||
return call_user_method("process",$this->themeConfigObj);
|
||||
@@ -1044,27 +1048,24 @@ class themeHandler{
|
||||
function setStyle()
|
||||
{
|
||||
global $pref, $e107cache, $ns, $sql, $emessage;
|
||||
$pref['themecss'] = $_POST['themecss'];
|
||||
$pref['image_preload'] = $_POST['image_preload'];
|
||||
$pref['sitetheme_deflayout'] = $_POST['layout_default'];
|
||||
//TODO adminlog
|
||||
e107::getConfig()->setPosted('themecss', $_POST['themecss'])
|
||||
->setPosted('image_preload', $_POST['image_preload'])
|
||||
->setPosted('sitetheme_deflayout', $_POST['layout_default']);
|
||||
|
||||
$e107cache->clear_sys();
|
||||
if(save_prefs())
|
||||
$msg = $this->setThemeConfig();
|
||||
if($msg)
|
||||
{
|
||||
$emessage->add(TPVLAN_37, E_MESSAGE_SUCCESS); // Default Message
|
||||
$emessage->add($this -> setThemeConfig(),E_MESSAGE_SUCCESS); // Custom Message from theme config.
|
||||
$this->theme_adminlog('03',$pref['image_preload'].', '.$pref['themecss']);
|
||||
}
|
||||
else
|
||||
{
|
||||
$emessage->add(TPVLAN_43, E_MESSAGE_ERROR);
|
||||
$emessage->add(TPVLAN_37, E_MESSAGE_SUCCESS);
|
||||
if(is_array($msg))
|
||||
$emessage->add($msg[0], $msg[1]);
|
||||
}
|
||||
}
|
||||
|
||||
function setAdminStyle()
|
||||
{
|
||||
global $pref, $e107cache, $ns, $emessage;
|
||||
$pref['admincss'] = $_POST['admincss'];
|
||||
/*$pref['admincss'] = $_POST['admincss'];
|
||||
$pref['adminstyle'] = $_POST['adminstyle'];
|
||||
|
||||
|
||||
@@ -1077,23 +1078,31 @@ class themeHandler{
|
||||
else
|
||||
{
|
||||
$emessage->add(TPVLAN_43, E_MESSAGE_ERROR);
|
||||
}
|
||||
}*/
|
||||
//TODO adminlog
|
||||
e107::getConfig()->setPosted('admincss', $_POST['admincss'])
|
||||
->setPosted('adminstyle', $_POST['adminstyle']);
|
||||
|
||||
return (e107::getConfig()->dataHasChangedFor('admincss') || e107::getConfig()->dataHasChangedFor('adminstyle'));
|
||||
}
|
||||
|
||||
function SetCustomPages($array)
|
||||
{
|
||||
if(!is_array($array)){ return; }
|
||||
|
||||
global $pref;
|
||||
//global $pref;
|
||||
$key = key($array);
|
||||
//['sitetheme_custompages']
|
||||
$array[$key] = trim(str_replace("\r\n", "\n", $array[$key]));
|
||||
$newprefs[$key] = array_filter(explode("\n", $array[$key]));
|
||||
$newprefs[$key] = array_unique($newprefs[$key]);
|
||||
|
||||
$pref['sitetheme_custompages'][$key] = array_filter(explode("\n",trim($array[$key])));
|
||||
|
||||
if($pref['sitetheme_deflayout'] == 'legacyCustom')
|
||||
if(e107::getPref('sitetheme_deflayout') == 'legacyCustom')
|
||||
{
|
||||
$pref['sitetheme_custompages']['legacyCustom'] = array();
|
||||
$newprefs['legacyCustom'] = array();
|
||||
}
|
||||
save_prefs();
|
||||
//setPosted couldn't be used here - sitetheme_custompages structure is not defined
|
||||
e107::getConfig()->set('sitetheme_custompages', e107::getParser()->toDB($newprefs));
|
||||
}
|
||||
|
||||
|
||||
|
@@ -5,19 +5,18 @@ class theme__blank
|
||||
{
|
||||
var $themePref;
|
||||
|
||||
|
||||
function process()
|
||||
{
|
||||
$theme_pref = array();
|
||||
|
||||
$pref = e107::getConfig();
|
||||
|
||||
$theme_pref = array();
|
||||
$theme_pref['example'] = $_POST['_blank_example'];
|
||||
$theme_pref['example2'] = $_POST['_blank_example2'];
|
||||
|
||||
// print_a($theme_pref);
|
||||
$pref->add('sitetheme_pref', $theme_pref);
|
||||
print_a($pref->get('sitetheme_pref'));
|
||||
var_dump($pref->add('sitetheme_pref', $theme_pref)->save(FALSE));
|
||||
// save_prefs($pref['sitetheme_pref']);
|
||||
$pref->set('sitetheme_pref', $theme_pref);
|
||||
|
||||
return $pref->dataHasChanged();
|
||||
}
|
||||
|
||||
function config()
|
||||
@@ -27,7 +26,7 @@ class theme__blank
|
||||
|
||||
$var[1]['caption'] = "Another Example";
|
||||
$var[1]['html'] = "<input type='text' name='_blank_example2' value='".e107::getThemePref('example2')."' />";
|
||||
var_dump(e107::getThemePref());
|
||||
//var_dump(e107::getThemePref());
|
||||
return $var;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user