mirror of
https://github.com/Piwigo/Piwigo.git
synced 2026-06-02 04:15:05 +02:00
issue #1640 user preferences
This commit is contained in:
@@ -395,6 +395,8 @@ SELECT
|
||||
}
|
||||
unset($value);
|
||||
|
||||
$userdata['preferences'] = empty($userdata['preferences']) ? array() : unserialize($userdata['preferences']);
|
||||
|
||||
if ($use_cache)
|
||||
{
|
||||
if (!isset($userdata['need_update'])
|
||||
@@ -1708,4 +1710,100 @@ UPDATE '.USER_INFOS_TABLE.'
|
||||
|
||||
return $last_visit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Save user preferences in database
|
||||
* @since 13
|
||||
*/
|
||||
function userprefs_save()
|
||||
{
|
||||
global $user;
|
||||
|
||||
$dbValue = pwg_db_real_escape_string(serialize($user['preferences']));
|
||||
|
||||
$query = '
|
||||
UPDATE '.USER_INFOS_TABLE.'
|
||||
SET preferences = \''.$dbValue.'\'
|
||||
WHERE user_id = '.$user['id'].'
|
||||
;';
|
||||
pwg_query($query);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add or update a user preferences parameter
|
||||
* @since 13
|
||||
*
|
||||
* @param string $param
|
||||
* @param string $value
|
||||
* @param boolean $updateGlobal update global *$conf* variable
|
||||
*/
|
||||
function userprefs_update_param($param, $value)
|
||||
{
|
||||
global $user;
|
||||
|
||||
// If the field is true or false, the variable is transformed into a boolean value.
|
||||
if ('true' == $value)
|
||||
{
|
||||
$value = true;
|
||||
}
|
||||
elseif ('false' == $value)
|
||||
{
|
||||
$value = false;
|
||||
}
|
||||
|
||||
$user['preferences'][$param] = $value;
|
||||
|
||||
userprefs_save();
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete one or more user preferences parameters
|
||||
* @since 13
|
||||
*
|
||||
* @param string|string[] $params
|
||||
*/
|
||||
function userprefs_delete_param($params)
|
||||
{
|
||||
global $user;
|
||||
|
||||
if (!is_array($params))
|
||||
{
|
||||
$params = array($params);
|
||||
}
|
||||
if (empty($params))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ($params as $param)
|
||||
{
|
||||
if (isset($user['preferences'][$param]))
|
||||
{
|
||||
unset($user['preferences'][$param]);
|
||||
}
|
||||
}
|
||||
|
||||
userprefs_save();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a default value for a user preferences parameter.
|
||||
* @since 13
|
||||
*
|
||||
* @param string $param the configuration value to be extracted (if it exists)
|
||||
* @param mixed $default_value the default value if it does not exist yet.
|
||||
*
|
||||
* @return mixed The configuration value if the variable exists, otherwise the default.
|
||||
*/
|
||||
function userprefs_get_param($param, $default_value=null)
|
||||
{
|
||||
global $user;
|
||||
|
||||
if (isset($user['preferences'][$param]))
|
||||
{
|
||||
return $user['preferences'][$param];
|
||||
}
|
||||
|
||||
return $default_value;
|
||||
}
|
||||
?>
|
||||
|
||||
@@ -763,6 +763,34 @@ SELECT
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* API method
|
||||
* Set a preferences parameter to current user
|
||||
* @since 13
|
||||
* @param mixed[] $params
|
||||
* @option string param
|
||||
* @option string|mixed value
|
||||
*/
|
||||
function ws_users_preferences_set($params, &$service)
|
||||
{
|
||||
global $user;
|
||||
|
||||
if (!preg_match('/^[a-zA-Z0-9_-]+$/', $params['param']))
|
||||
{
|
||||
return new PwgError(WS_ERR_INVALID_PARAM, 'Invalid param name #'.$params['param'].'#');
|
||||
}
|
||||
|
||||
$value = stripslashes($params['value']);
|
||||
if ($params['is_json'])
|
||||
{
|
||||
$value = json_decode($value, true);
|
||||
}
|
||||
|
||||
userprefs_update_param($params['param'], $value, true);
|
||||
|
||||
return $user['preferences'];
|
||||
}
|
||||
|
||||
/**
|
||||
* API method
|
||||
* Adds a favorite image for the current user
|
||||
|
||||
Reference in New Issue
Block a user