package.xml 0000644 0001750 0000764 00000132407 12240217746 013203 0 ustar slusarz slusarz
* false, * 'username' => 'root', * 'password' => 'PASSWORD', * 'socket' => '/var/run/mysqld/mysqld.sock', * 'protocol' => 'unix', * 'database' => 'horde', * 'charset' => 'utf-8', * 'ssl' => true, * 'splitread' => false, * 'phptype' => 'mysql', * ) * ); ** * Configuring for the Kolab storage backend is more complex: * *
* 'horde',
* 'params' => array(
* 'host' => 'example.org',
* 'username' => 'user@example.org',
* 'password' => 'test',
* 'port' => 993,
* 'secure' => true
* ),
* 'queryset' => array(
* 'list' => array('queryset' => 'horde'),
* 'data' => array('queryset' => 'horde'),
* ),
* 'cache' => new Horde_Cache(new Horde_Cache_Storage_Mock()),
* //'logger' => new Horde_Log_Logger(new Horde_Log_Handler_Stream(STDOUT)),
* )
* );
* $conf['params']['kolab'] = $factory->create();
*
*
*
* Copyright 2011-2013 Horde LLC (http://www.horde.org/)
*
* See the enclosed file COPYING for license information (LGPL). If you
* did not receive this file, see http://www.horde.org/licenses/lgpl21.
*
* @author Gunnar Wrobel
* 'directory' - (string) [REQUIRED] Preference storage directory.
*
*
* @throws InvalidArgumentException
*/
public function __construct($user, array $params = array())
{
// Sanity check for directory
if (empty($params['directory']) || !is_dir($params['directory'])) {
throw new InvalidArgumentException('Preference storage directory is not available.');
}
if (!is_writable($params['directory'])) {
throw new InvalidArgumentException(sprintf('Directory %s is not writeable.', $params['directory']));
}
parent::__construct($user, $params);
$this->_fullpath = $this->_params['directory'] . '/' . basename($this->_params['user']) . '.prefs';
}
/**
* Retrieves the requested preferences scope from the storage backend.
*
* @param Horde_Prefs_Scope $scope_ob The scope object.
*
* @return Horde_Prefs_Scope The modified scope object.
* @throws Horde_Prefs_Exception
*/
public function get($scope_ob)
{
if ($this->_loadFileCache() &&
isset($this->_fileCache[$scope_ob->scope])) {
foreach ($this->_fileCache[$scope_ob->scope] as $name => $val) {
$scope_ob->set($name, $val);
}
}
return $scope_ob;
}
/**
* Load the preferences from the files.
*
* @return boolean True on success.
* @throws Horde_Prefs_Exception
*/
protected function _loadFileCache()
{
if (is_null($this->_fileCache)) {
// Try to read
if (!file_exists($this->_fullpath)) {
$this->_fileCache = array(
'__file_version' => self::VERSION
);
return false;
}
$this->_fileCache = @unserialize(file_get_contents($this->_fullpath));
// Check version number. We can call format transformations hooks
// in the future.
if (!is_array($this->_fileCache) ||
!array_key_exists('__file_version', $this->_fileCache) ||
!($this->_fileCache['__file_version'] == self::VERSION)) {
if ($this->_fileCache['__file_version'] == 1) {
$this->updateFileFormat();
} else {
throw new Horde_Prefs_Exception(sprintf('Wrong version number found: %s (should be %d)', $this->_fileCache['__file_version'], self::VERSION));
}
}
}
return true;
}
/**
* Stores changed preferences in the storage backend.
*
* @param Horde_Prefs_Scope $scope_ob The scope object.
*
* @throws Horde_Prefs_Exception
*/
public function store($scope_ob)
{
$this->_loadFileCache();
/* Driver has no support for storing locked status. */
foreach ($scope_ob->getDirty() as $name) {
$value = $scope_ob->get($name);
if (is_null($value)) {
unset($this->_fileCache[$scope_ob->scope][$name]);
} else {
$this->_fileCache[$scope_ob->scope][$name] = $value;
}
}
$tmp_file = Horde_Util::getTempFile('PrefsFile', true, $this->_params['directory']);
if ((file_put_contents($tmp_file, serialize($this->_fileCache)) === false) ||
(@rename($tmp_file, $this->_fullpath) === false)) {
throw new Horde_Prefs_Exception(sprintf('Write of preferences to %s failed', $this->_fullpath));
}
}
/**
* Removes preferences from the backend.
*
* @param string $scope The scope of the prefs to clear. If null, clears
* all scopes.
* @param string $pref The pref to clear. If null, clears the entire
* scope.
*
* @throws Horde_Db_Exception
*/
public function remove($scope = null, $pref = null)
{
// TODO
}
/* Helper functions. */
/**
* Updates format of file.
*/
public function updateFileFormat()
{
$new_vers = array('__file_version' => self::VERSION);
unset($this->_fileCache['__file_version']);
foreach ($this->_fileCache as $scope => $prefs) {
foreach ($prefs as $name => $pref) {
$new_vers[$scope][$name] = $pref['v'];
}
}
$this->_fileCache = $new_vers;
}
/**
* Lists all available scopes.
*
* @return array The list of scopes stored in the backend.
*/
public function listScopes()
{
$this->_loadFileCache();
return array_diff(
array_keys($this->_fileCache), array('__file_version')
);
}
}
Horde_Prefs-2.5.2/lib/Horde/Prefs/Storage/Imsp.php 0000644 0001750 0000764 00000003611 12240217745 021634 0 ustar slusarz slusarz
* @category Horde
* @package Prefs
*/
class Horde_Prefs_Storage_Imsp extends Horde_Prefs_Storage_Base
{
/**
* Handle for the IMSP server connection.
*
* @var Horde_Imsp_Options
*/
protected $_imsp;
public function __construct($user, array $params = array())
{
if (empty($params['imsp'])) {
throw new InvalidArguementException('Missing required imsp parameter.');
}
$this->_imsp = $params['imsp'];
parent::__construct($user, $params);
}
/**
*/
public function get($scope_ob)
{
try {
$prefs = $this->_imsp->get($scope_ob->scope . '.*');
} catch (Horde_Imsp_Exception $e) {
throw new Horde_Prefs_Exception($e);
}
foreach ($prefs as $name => $val) {
$name = str_replace($scope_ob->scope . '.', '', $name);
if ($val != '-') {
$scope_ob->set($name, $val);
}
}
return $scope_ob;
}
/**
*/
public function store($scope_ob)
{
/* Driver has no support for storing locked status. */
foreach ($scope_ob->getDirty() as $name) {
$value = $scope_ob->get($name);
try {
$this->_imsp->set($scope_ob->scope . '.' . $name, $value ? $value : '-');
} catch (Horde_Imsp_Exception $e) {
throw new Horde_Prefs_Exception($e);
}
}
}
/**
*/
public function remove($scope = null, $pref = null)
{
// TODO
}
/* Helper functions. */
}
Horde_Prefs-2.5.2/lib/Horde/Prefs/Storage/KolabImap.php 0000644 0001750 0000764 00000022470 12240217745 022567 0 ustar slusarz slusarz
* @category Horde
* @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
* @package Prefs
*/
class Horde_Prefs_Storage_KolabImap extends Horde_Prefs_Storage_Base
{
/**
* Handle for the current Kolab connection.
*
* @var Horde_Kolab_Storage
*/
protected $_kolab;
/**
* Name of the preferences default folder
*
* @var string
*/
protected $_folder;
/**
* Log handler.
*
* @var Horde_Log_Logger
*/
protected $_logger;
/**
* Constructor.
*
* @param string $user The username.
* @param array $params Configuration parameters.
*
* 'kolab' - (Horde_Kolab_Storage) [REQUIRED] The storage backend.
* 'folder' - (string) The default name of the preferences folder.
* DEFAULT: _('Preferences')
*
*
* @throws InvalidArgumentException
*/
public function __construct($user, array $params = array())
{
if (!isset($params['kolab'])) {
throw new InvalidArgumentException('Missing "kolab" parameter.');
}
$this->_kolab = $params['kolab'];
unset($params['kolab']);
if (isset($params['logger'])) {
$this->_logger = $params['logger'];
}
if (isset($params['folder'])) {
$this->_folder = $params['folder'];
} else {
$this->_folder = Horde_Prefs_Translation::t("Preferences");
}
parent::__construct($user, $params);
}
/**
* Retrieves the requested preferences scope from the storage backend.
*
* @param Horde_Prefs_Scope $scope_ob The scope object.
*
* @return Horde_Prefs_Scope The modified scope object.
* @throws Horde_Prefs_Exception
*/
public function get($scope_ob)
{
try {
$data = $this->_getStorage();
} catch (Horde_Prefs_Exception $e) {
$this->_logMissingStorage($e);
return $scope_ob;
}
/** This may not fail (or if it does it is okay to pass the error up */
$query = $data->getQuery(Horde_Kolab_Storage_Data::QUERY_PREFS);
try {
$pref = $query->getApplicationPreferences($scope_ob->scope);
} catch (Horde_Kolab_Storage_Exception $e) {
$this->_logMissingScope($e, $scope_ob->scope);
return $scope_ob;
}
foreach ($this->_prefToArray($pref['pref']) as $key => $value) {
$scope_ob->set($key, $value);
}
return $scope_ob;
}
/**
* Stores changed preferences in the storage backend.
*
* @param Horde_Prefs_Scope $scope_ob The scope object.
*
* @throws Horde_Prefs_Exception
*/
public function store($scope_ob)
{
/** This *must* succeed */
$data = $this->_getStorage(true);
$query = $data->getQuery(Horde_Kolab_Storage_Data::QUERY_PREFS);
try {
$pref = $query->getApplicationPreferences($scope_ob->scope);
} catch (Horde_Kolab_Storage_Exception $e) {
$pref = array('application' => $scope_ob->scope);
}
if (isset($pref['pref'])) {
$new = $this->_prefToArray($pref['pref']);
} else {
$new = array();
}
foreach ($scope_ob->getDirty() as $name) {
$new[$name] = $scope_ob->get($name);
}
$pref['pref'] = $this->_arrayToPref($new);
try {
if (!isset($pref['uid'])) {
$data->create($pref);
} else {
$data->modify($pref);
}
} catch (Horde_Kolab_Storage_Exception $e) {
throw new Horde_Prefs_Exception($e);
}
}
/**
* Removes preferences from the backend.
*
* @param string $scope The scope of the prefs to clear. If null, clears
* all scopes.
* @param string $pref The pref to clear. If null, clears the entire
* scope.
*
* @throws Horde_Prefs_Exception
*/
public function remove($scope = null, $pref = null)
{
try {
$data = $this->_getStorage();
} catch (Horde_Prefs_Exception $e) {
$this->_logMissingStorage($e);
return;
}
if ($scope === null) {
$data->deleteAll();
return;
}
$query = $data->getQuery(Horde_Kolab_Storage_Data::QUERY_PREFS);
try {
$pref = $query->getApplicationPreferences($scope);
} catch (Horde_Kolab_Storage_Exception $e) {
$this->_logMissingScope($e, $scope);
return;
}
if ($pref === null) {
$data->delete($pref['uid']);
return;
}
$new = $this->_prefToArray($pref);
unset($new[$pref]);
$pref['pref'] = $this->_arrayToPref($new);
try {
$data->modify($pref);
} catch (Horde_Kolab_Storage_Exception $e) {
throw new Horde_Prefs_Exception($e);
}
}
/**
* Lists all available scopes.
*
* @return array The list of scopes stored in the backend.
*/
public function listScopes()
{
try {
$data = $this->_getStorage();
} catch (Horde_Prefs_Exception $e) {
$this->_logMissingStorage($e);
return;
}
return $data->getQuery(Horde_Kolab_Storage_Data::QUERY_PREFS)
->getApplications();
}
/* Helper functions. */
/**
* Opens a connection to the Kolab server.
*
* @param boolean $create_missing Create a preferences folder if it is
* missing.
*
* @return Horde_Kolab_Storage_Data The storage backend.
*
* @throws Horde_Prefs_Exception
*/
protected function _getStorage($create_missing = false)
{
$query = $this->_kolab->getList()->getQuery();
if ($folder = $query->getDefault('h-prefs')) {
return $this->_kolab->getData($folder);
}
$folders = $query->listByType('h-prefs');
if (!empty($folders)) {
return $this->_kolab->getData($folders[0]);
}
if (!$create_missing) {
throw new Horde_Prefs_Exception(
'No Kolab storage backend available.'
);
}
$params = $this->getParams();
$folder = $this->_kolab->getList()
->getNamespace()
->constructFolderName($params['user'], $this->_folder);
$this->_kolab->getList()->getListManipulation()->createFolder($folder, 'h-prefs.default');
if ($this->_logger !== null) {
$this->_logger->info(
sprintf(
__CLASS__ . ': Created default Kolab preferences folder "%s".',
$this->_folder
)
);
}
return $this->_kolab->getData($folder);
}
/**
* Convert Kolab preferences data to an array.
*
* @param array $pref The preferences list.
*
* @return array The preferences data as array.
*/
private function _prefToArray($pref)
{
$result = array();
foreach ($pref as $prefstr) {
/** If the string doesn't contain a colon delimiter, skip it. */
if (strpos($prefstr, ':') !== false) {
/** Split the string into its name:value components. */
list($name, $val) = explode(':', $prefstr, 2);
$result[$name] = base64_decode($val);
}
}
return $result;
}
/**
* Convert a key => value list of preferences to the Kolab preferences.
*
* @param array $pref The preferences.
*
* @return array The preferences data as list.
*/
private function _arrayToPref($pref)
{
$result = array();
foreach ($pref as $name => $value) {
if ($value !== null) {
$result[] = $name . ':' . base64_encode($value);
}
}
return $result;
}
/**
* Log the missing backend.
*
* @param Exception $e The exception that occurred.
*
* @return NULL
*/
private function _logMissingStorage(Exception $e)
{
if ($this->_logger !== null) {
$this->_logger->debug(
sprintf(
__CLASS__ . ': Failed retrieving Kolab preferences data storage (%s)',
$e->getMessage()
)
);
}
}
/**
* Log the missing scope.
*
* @param Exception $e The exception that occurred.
* @param string $scope The scope that was attempted to get.
*
* @return NULL
*/
private function _logMissingScope(Exception $e, $scope)
{
if ($this->_logger !== null) {
$this->_logger->debug(
sprintf(
__CLASS__ . ': No preference information available for scope %s (%s).',
$scope,
$e->getMessage()
)
);
}
}
}
Horde_Prefs-2.5.2/lib/Horde/Prefs/Storage/Ldap.php 0000644 0001750 0000764 00000017600 12240217745 021607 0 ustar slusarz slusarz
* @author Ben Klang
* - collection: (string) The collection name.
* - mongo_db: (Horde_Mongo_Client) [REQUIRED] A MongoDB client object.
*
*/
public function __construct($user, array $params = array())
{
if (!isset($params['mongo_db'])) {
throw new InvalidArgumentException('Missing mongo_db parameter.');
}
parent::__construct($user, array_merge(array(
'collection' => 'horde_prefs'
), $params));
$this->_db = $this->_params['mongo_db']->selectCollection(null, $this->_params['collection']);
}
/**
*/
public function get($scope_ob)
{
try {
$res = $this->_db->find(array(
self::SCOPE => $scope_ob->scope,
self::UID => $this->_params['user']
), array(
self::NAME => 1,
self::VALUE => 1
));
} catch (MongoException $e) {
throw new Horde_Prefs_Exception($e);
}
foreach ($res as $val) {
$scope_ob->set($val[self::NAME], $val[self::VALUE]->bin);
}
return $scope_ob;
}
/**
*/
public function store($scope_ob)
{
foreach ($scope_ob->getDirty() as $name) {
$value = $scope_ob->get($name);
if (is_null($value)) {
$this->remove($scope_ob->scope, $name);
} else {
$query = array(
self::NAME => $name,
self::SCOPE => $scope_ob->scope,
self::UID => $this->_params['user']
);
try {
$this->_db->update(
$query,
array_merge($query, array(
self::VALUE => new MongoBinData($value, MongoBinData::BYTE_ARRAY)
)),
array(
'upsert' => true
)
);
} catch (MongoException $e) {
throw new Horde_Prefs_Exception($e);
}
}
}
}
/**
*/
public function remove($scope = null, $pref = null)
{
$query = array(
self::UID => $this->_params['user']
);
if (!is_null($scope)) {
$query[self::SCOPE] = $scope;
if (!is_null($pref)) {
$query[self::NAME] = $pref;
}
}
try {
$this->_db->remove($query);
} catch (MongoException $e) {
throw new Horde_Prefs_Exception($e);
}
}
/**
*/
public function listScopes()
{
try {
return $this->_db->distinct(self::SCOPE);
} catch (MongoException $e) {
throw new Horde_Prefs_Exception($e);
}
}
/* Horde_Mongo_Collection_Index methods. */
/**
*/
public function checkMongoIndices()
{
return $this->_params['mongo_db']->checkIndices($this->_db, $this->_indices);
}
/**
*/
public function createMongoIndices()
{
$this->_params['mongo_db']->createIndices($this->_db, $this->_indices);
}
}
Horde_Prefs-2.5.2/lib/Horde/Prefs/Storage/Null.php 0000644 0001750 0000764 00000001332 12240217745 021634 0 ustar slusarz slusarz
* @category Horde
* @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
* @package Prefs
*/
class Horde_Prefs_Storage_Null extends Horde_Prefs_Storage_Base
{
/**
*/
public function get($scope_ob)
{
return $scope_ob;
}
/**
*/
public function store($scope_ob)
{
}
/**
*/
public function remove($scope = null, $pref = null)
{
}
}
Horde_Prefs-2.5.2/lib/Horde/Prefs/Storage/Sql.php 0000644 0001750 0000764 00000014471 12240217745 021471 0 ustar slusarz slusarz
* @author Michael Slusarz
* 'db' - (Horde_Db_Adapter) [REQUIRED] The DB instance.
* 'table' - (string) The name of the prefs table.
* DEFAULT: 'horde_prefs'
*
*
* @throws InvalidArgumentException
*/
public function __construct($user, array $params = array())
{
if (!isset($params['db'])) {
throw new InvalidArgumentException('Missing db parameter.');
}
$this->_db = $params['db'];
unset($params['db']);
$params = array_merge(array(
'table' => 'horde_prefs'
), $params);
parent::__construct($user, $params);
}
/**
* Returns the charset of the DB backend.
*
* @return string The connection's charset.
*/
public function getCharset()
{
return $this->_db->getOption('charset');
}
/**
*/
public function get($scope_ob)
{
$charset = $this->_db->getOption('charset');
$query = 'SELECT pref_name, pref_value FROM ' .
$this->_params['table'] . ' ' .
'WHERE pref_uid = ? AND pref_scope = ?';
$values = array($this->_params['user'], $scope_ob->scope);
try {
$result = $this->_db->selectAll($query, $values);
$columns = $this->_db->columns($this->_params['table']);
} catch (Horde_Db_Exception $e) {
throw new Horde_Prefs_Exception($e);
}
foreach ($result as $row) {
$name = trim($row['pref_name']);
$value = $columns['pref_value']->binaryToString($row['pref_value']);
$scope_ob->set($name, Horde_String::convertCharset($value, $charset, 'UTF-8'));
}
return $scope_ob;
}
/**
*/
public function store($scope_ob)
{
if (!$this->_db->isActive()) {
$this->_db->reconnect();
}
$charset = $this->_db->getOption('charset');
// For each preference, check for an existing table row and
// update it if it's there, or create a new one if it's not.
foreach ($scope_ob->getDirty() as $name) {
$value = $scope_ob->get($name);
if (is_null($value)) {
$this->remove($scope_ob->scope, $name);
} else {
$values = array($this->_params['user'], $name, $scope_ob->scope);
// Does a row already exist for this preference?
$query = 'SELECT 1 FROM ' . $this->_params['table'] .
' WHERE pref_uid = ? AND pref_name = ?' .
' AND pref_scope = ?';
try {
$check = $this->_db->selectValue($query, $values);
} catch (Horde_Db_Exception $e) {
throw new Horde_Prefs_Exception($e);
}
/* Driver has no support for storing locked status. */
$value = Horde_String::convertCharset($value, 'UTF-8', $charset);
$value = new Horde_Db_Value_Binary($value);
if (empty($check)) {
// Insert a new row.
$query = 'INSERT INTO ' . $this->_params['table'] . ' ' .
'(pref_uid, pref_scope, pref_name, pref_value) VALUES' .
'(?, ?, ?, ?)';
$values = array(
$this->_params['user'],
$scope_ob->scope,
$name,
$value
);
try {
$this->_db->insert($query, $values);
} catch (Horde_Db_Exception $e) {
throw new Horde_Prefs_Exception($e);
}
} else {
// Update the existing row.
$query = 'UPDATE ' . $this->_params['table'] .
' SET pref_value = ?' .
' WHERE pref_uid = ?' .
' AND pref_name = ?' .
' AND pref_scope = ?';
$values = array(
$value,
$this->_params['user'],
$name,
$scope_ob->scope
);
try {
$this->_db->update($query, $values);
} catch (Horde_Db_Exception $e) {
throw new Horde_Prefs_Exception($e);
}
}
}
}
}
/**
*/
public function remove($scope = null, $pref = null)
{
$query = 'DELETE FROM ' . $this->_params['table'] .
' WHERE pref_uid = ?';
$values = array($this->_params['user']);
if (!is_null($scope)) {
$query .= ' AND pref_scope = ?';
$values[] = $scope;
if (!is_null($pref)) {
$query .= ' AND pref_name = ?';
$values[] = $pref;
}
}
try {
$this->_db->delete($query, $values);
} catch (Horde_Db_Exception $e) {
throw new Horde_Prefs_Exception($e);
}
}
/**
* Lists all available scopes.
*
* @return array The list of scopes stored in the backend.
*/
public function listScopes()
{
$query = 'SELECT ' . $this->_db->distinct('pref_scope') . ' FROM '
. $this->_params['table'];
try {
return $this->_db->selectValues($query);
} catch (Horde_Db_Exception $e) {
throw new Horde_Prefs_Exception($e);
}
}
}
Horde_Prefs-2.5.2/lib/Horde/Prefs/CategoryManager.php 0000644 0001750 0000764 00000015407 12240217745 022376 0 ustar slusarz slusarz
* @category Horde
* @package Prefs
*/
class Horde_Prefs_CategoryManager
{
/**
* Get all categories.
*/
static public function get()
{
$string = $GLOBALS['prefs']->getValue('categories');
if (empty($string)) {
return array();
}
$categories = explode('|', $string);
asort($categories);
return $categories;
}
/**
* TODO
*/
static public function getSelect($id, $current = null)
{
$categories = self::get();
$colors = self::colors();
$fgcolors = self::fgColors();
$id_html = htmlspecialchars($id);
$html = '';
}
/**
* TODO
*/
static public function getJavaScript($formname, $elementname)
{
$prompt = addslashes(Horde_Prefs_Translation::t("Please type the new category name:"));
$error = addslashes(Horde_Prefs_Translation::t("You must type a new category name."));
return <<
* [pref_name] => array(
* [d] => (string) Default value
* If not present, 'v' is the default value.
* [l] => (boolean) Locked
* If not present, pref is not locked.
* [v] => (string) Current pref value
* )
*
* For internal storage, if 'l' and 'v' are both not available:
* [pref_name] => (string) Current pref value
*
*
* @var array
*/
protected $_prefs = array();
/**
* Constructor.
*
* @param string $scope The scope for this set of preferences.
*/
public function __construct($scope)
{
$this->scope = $scope;
}
/**
* Removes a preference entry.
*
* @param string $pref The name of the preference to remove.
*
* @return boolean True if preference was removed.
*/
public function remove($pref)
{
if (!($p = $this->_fromInternal($pref))) {
return false;
}
if (isset($p['d'])) {
$p['v'] = $p['d'];
unset($p['d']);
$this->_toInternal($pref, $p);
$this->setDirty($pref, false);
}
return true;
}
/**
* Sets the value for a preference.
*
* @param string $pref The preference name.
* @param string $val The preference value.
*/
public function set($pref, $val)
{
if ($p = $this->_fromInternal($pref)) {
if ($val != $p['v']) {
if (isset($p['d']) && ($val == $p['d'])) {
unset($p['d']);
} else {
$p['d'] = $p['v'];
}
$p['v'] = $val;
$this->_toInternal($pref, $p);
}
} else {
$this->_toInternal($pref, array('v' => $val));
}
}
/**
* Does a preference exist in this scope?
*
* @return boolean True if the preference exists.
*/
public function exists($pref)
{
return isset($this->_prefs[$pref]);
}
/**
* Returns the value of a preference.
*
* @param string $pref The preference name to retrieve.
*
* @return string The value of the preference, null if it doesn't exist.
*/
public function get($pref)
{
return ($p = $this->_fromInternal($pref))
? $p['v']
: null;
}
/**
* Mark a preference as locked.
*
* @param string $pref The preference name.
* @param boolean $locked Is the preference locked?
*/
public function setLocked($pref, $locked)
{
if ($p = $this->_fromInternal($pref)) {
if ($locked) {
if (!isset($p['l'])) {
$p['l'] = true;
$this->_toInternal($pref, $p);
}
} elseif (isset($p['l'])) {
unset($p['l']);
$this->_toInternal($pref, $p);
}
}
}
/**
* Is a preference locked?
*
* @param string $pref The preference name.
*
* @return boolean Whether the preference is locked.
*/
public function isLocked($pref)
{
return ($p = $this->_fromInternal($pref))
? !empty($p['l'])
: false;
}
/**
* Is a preference's value the default?
*
* @param string $pref The preference name.
*
* @return boolean True if the preference contains the default value.
*/
public function isDefault($pref)
{
return ($p = $this->_fromInternal($pref))
? !isset($p['d'])
: true;
}
/**
* Returns the default value of a preference.
*
* @param string $pref The preference name.
*
* @return string The preference's default value.
*/
public function getDefault($pref)
{
return ($p = $this->_fromInternal($pref))
? (isset($p['d']) ? $p['d'] : $p['v'])
: null;
}
/**
* Get the list of dirty preferences.
*
* @return array The list of dirty preferences.
*/
public function getDirty()
{
return array_keys($this->_dirty);
}
/**
* Is a preference marked dirty?
*
* @param mixed $pref The preference name. If null, will return true if
* scope contains at least one dirty pref.
*
* @return boolean True if the preference is marked dirty.
*/
public function isDirty($pref = null)
{
return is_null($pref)
? !empty($this->_dirty)
: isset($this->_dirty[$pref]);
}
/**
* Set the dirty flag for a preference
*
* @param string $pref The preference name.
* @param boolean $dirty True to mark the pref as dirty.
*/
public function setDirty($pref, $dirty)
{
if ($dirty) {
$this->_dirty[$pref] = true;
} else {
unset($this->_dirty[$pref]);
}
}
/**
*/
protected function _fromInternal($pref)
{
if (!isset($this->_prefs[$pref])) {
return false;
}
return is_array($this->_prefs[$pref])
? $this->_prefs[$pref]
: array('v' => $this->_prefs[$pref]);
}
/**
*/
protected function _toInternal($pref, array $value)
{
if (!isset($value['d']) && !isset($value['l'])) {
$value = $value['v'];
}
$this->_prefs[$pref] = $value;
if (!$this->init) {
$this->setDirty($pref, true);
}
}
/* Iterator methods. */
/**
*/
public function current()
{
return $this->_fromInternal($this->key());
}
/**
*/
public function key()
{
return key($this->_prefs);
}
/**
*/
public function next()
{
return next($this->_prefs);
}
/**
*/
public function rewind()
{
return reset($this->_prefs);
}
/**
*/
public function valid()
{
return !is_null(key($this->_prefs));
}
/* Serializable methods. */
/**
*/
public function serialize()
{
return json_encode(array(
$this->scope,
$this->_prefs
));
}
/**
*/
public function unserialize($data)
{
list($this->scope, $this->_prefs) = json_decode($data, true);
}
}
Horde_Prefs-2.5.2/lib/Horde/Prefs/Translation.php 0000644 0001750 0000764 00000003212 12240217745 021613 0 ustar slusarz slusarz
* @package Prefs
*/
class Horde_Prefs_Translation extends Horde_Translation
{
/**
* Returns the translation of a message.
*
* @var string $message The string to translate.
*
* @return string The string translation, or the original string if no
* translation exists.
*/
static public function t($message)
{
self::$_domain = 'Horde_Prefs';
self::$_directory = '@data_dir@' == '@'.'data_dir'.'@' ? __DIR__ . '/../../../locale' : '@data_dir@/Horde_Prefs/locale';
return parent::t($message);
}
/**
* Returns the plural translation of a message.
*
* @param string $singular The singular version to translate.
* @param string $plural The plural version to translate.
* @param integer $number The number that determines singular vs. plural.
*
* @return string The string translation, or the original string if no
* translation exists.
*/
static public function ngettext($singular, $plural, $number)
{
self::$_domain = 'Horde_Prefs';
self::$_directory = '@data_dir@' == '@'.'data_dir'.'@' ? __DIR__ . '/../../../locale' : '@data_dir@/Horde_Prefs/locale';
return parent::ngettext($singular, $plural, $number);
}
}
Horde_Prefs-2.5.2/lib/Horde/Prefs.php 0000644 0001750 0000764 00000031565 12240217745 017331 0 ustar slusarz slusarz
* @category Horde
* @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
* @package Prefs
*/
class Horde_Prefs implements ArrayAccess
{
/* The default scope name. */
const DEFAULT_SCOPE = 'horde';
/**
* Caching object.
*
* @var Horde_Prefs_Cache
*/
protected $_cache;
/**
* General library options.
*
* @var array
*/
protected $_opts = array(
'cache' => null,
'logger' => null,
'password' => '',
'sizecallback' => null,
'storage' => null,
'user' => ''
);
/**
* String containing the name of the current scope. This is used
* to differentiate between sets of preferences. By default, preferences
* belong to this scope.
*
* @var string
*/
protected $_scope = self::DEFAULT_SCOPE;
/**
* Scope list. Keys are scope names, values are Horde_Prefs_Scope
* objects.
*
* @var array
*/
protected $_scopes = array();
/**
* The storage driver(s).
*
* @var array
*/
protected $_storage;
/**
* Constructor.
*
* @param string $scope The scope for this set of preferences.
* @param mixed $storage The storage object(s) to use. Either a single
* Horde_Prefs_Storage object, or an array of
* objects.
* @param array $opts Additional confguration options:
*
* cache - (Horde_Prefs_Cache) The cache driver to use.
* DEFAULT: No caching.
* logger - (Horde_Log_Logger) Logging object.
* DEFAULT: NONE
* password - (string) The password associated with 'user'.
* DEFAULT: NONE
* sizecallback - (callback) If set, called when setting a value in the
* backend.
* DEFAULT: NONE
* user - (string) The name of the user who owns this set of preferences.
* DEFAULT: NONE
*
*/
public function __construct($scope, $storage = null, array $opts = array())
{
$this->_opts = array_merge($this->_opts, $opts);
$this->_cache = isset($this->_opts['cache'])
? $this->_opts['cache']
: new Horde_Prefs_Cache_Null($this->getUser());
$this->_scope = $scope;
if (is_null($storage)) {
$storage = array(new Horde_Prefs_Storage_Null($this->getUser()));
} elseif (!is_array($storage)) {
$storage = array($storage);
}
$this->_storage = $storage;
register_shutdown_function(array($this, 'store'), false);
$this->retrieve($scope);
}
/**
* Return the user who owns these preferences.
*
* @return string The user these preferences are for.
*/
public function getUser()
{
return $this->_opts['user'];
}
/**
* Get the current scope.
*
* @return string The current scope (application).
*/
public function getScope()
{
return $this->_scope;
}
/**
* Returns the storage drivers.
*
* @return array The storage drivers.
*/
public function getStorage()
{
return $this->_storage;
}
/**
* Removes a preference entry from the $prefs hash.
*
* @param string $pref The name of the preference to remove. If null,
* removes all prefs.
*/
public function remove($pref = null)
{
$to_remove = array();
if (is_null($pref)) {
foreach ($this->_scopes as $key => $val) {
$to_remove[$key] = array_keys(iterator_to_array($val));
}
} elseif ($scope = $this->_getScope($pref)) {
$to_remove[$scope] = array($pref);
}
foreach ($to_remove as $key => $val) {
$scope = $this->_scopes[$key];
foreach ($val as $prefname) {
$scope->remove($prefname);
foreach ($this->_storage as $storage) {
try {
$storage->remove($scope->scope, $prefname);
} catch (Exception $e) {}
}
}
}
}
/**
* Sets the given preference to the specified value if the preference is
* modifiable.
*
* @param string $pref The preference name to modify.
* @param string $val The preference value (UTF-8).
* @param array $opts Additional options:
*
* - force: (boolean) If true, will set the value disregarding the
* current locked status of the pref. (@since 2.5.0)
* DEFAULT: false
* - nosave: (boolean) If true, the preference will not be saved to the
* storage backend(s).
* DEFAULT: false
*
*
* @return boolean True if the value was successfully set, false on a
* failure.
* @throws Horde_Prefs_Exception
*/
public function setValue($pref, $val, array $opts = array())
{
/* Exit early if preference doesn't exist or is locked. */
if (!($scope = $this->_getScope($pref)) ||
(empty($opts['force']) &&
$this->_scopes[$scope]->isLocked($pref))) {
return false;
}
// Check to see if the value exceeds the allowable storage limit.
if ($this->_opts['sizecallback'] &&
call_user_func($this->_opts['sizecallback'], $pref, strlen($val))) {
return false;
}
$this->_scopes[$scope]->set($pref, $val);
if (!empty($opts['nosave'])) {
$this->_scopes[$scope]->setDirty($pref, false);
}
foreach ($this->_storage as $storage) {
$storage->onChange($scope, $pref);
}
if ($this->_opts['logger']) {
$this->_opts['logger']->log(__CLASS__ . ': Storing preference value (' . $pref . ')', 'DEBUG');
}
return true;
}
/**
* Shortcut to setValue().
*/
public function __set($name, $value)
{
return $this->setValue($name, $value);
}
/**
* Returns the value of the requested preference.
*
* @param string $pref The preference name.
*
* @return string The value of the preference (UTF-8), null if it doesn't
* exist.
*/
public function getValue($pref)
{
return ($scope = $this->_getScope($pref))
? $this->_scopes[$scope]->get($pref)
: null;
}
/**
* Shortcut to getValue().
*/
public function __get($name)
{
return $this->getValue($name);
}
/**
* Mark a preference as locked.
*
* @param string $pref The preference name.
* @param boolean $locked Is the preference locked?
*/
public function setLocked($pref, $bool)
{
if ($scope = $this->_getScope($pref)) {
$this->_scopes[$scope]->setLocked($pref, $bool);
}
}
/**
* Is a preference locked?
*
* @param string $pref The preference name.
*
* @return boolean Whether the preference is locked.
*/
public function isLocked($pref)
{
return ($scope = $this->_getScope($pref))
? $this->_scopes[$scope]->isLocked($pref)
: false;
}
/**
* Is a preference marked dirty?
*
* @param string $pref The preference name.
*
* @return boolean True if the preference is marked dirty.
*/
public function isDirty($pref)
{
return ($scope = $this->_getScope($pref))
? $this->_scopes[$scope]->isDirty($pref)
: false;
}
/**
* Returns the default value of the given preference.
*
* @param string $pref The name of the preference to get the default for.
*
* @return string The preference's default value.
*/
public function getDefault($pref)
{
return ($scope = $this->_getScope($pref))
? $this->_scopes[$scope]->getDefault($pref)
: null;
}
/**
* Determines if the current preference value is the default value.
*
* @param string $pref The name of the preference to check.
*
* @return boolean True if the preference is the application default
* value.
*/
public function isDefault($pref)
{
return ($scope = $this->_getScope($pref))
? $this->_scopes[$scope]->isDefault($pref)
: false;
}
/**
* Returns the scope of a preference.
*
* @param string $pref The preference name.
*
* @return mixed The scope of the preference, or null if it doesn't
* exist.
*/
protected function _getScope($pref)
{
if ($this->_scopes[$this->_scope]->exists($pref)) {
return $this->_scope;
} elseif (($this->_scope != self::DEFAULT_SCOPE) &&
($this->_scopes[self::DEFAULT_SCOPE]->exists($pref))) {
return self::DEFAULT_SCOPE;
}
return null;
}
/**
* Retrieves preferences for the current scope.
*
* @param string $scope Optional scope specifier - if not present the
* current scope will be used.
*/
public function retrieve($scope = null)
{
if (is_null($scope)) {
$scope = $this->getScope();
} else {
$this->_scope = $scope;
}
$this->_loadScope(self::DEFAULT_SCOPE);
if ($scope != self::DEFAULT_SCOPE) {
$this->_loadScope($scope);
}
}
/**
* Load a specific preference scope.
*
* @param string $scope The scope to load.
*/
protected function _loadScope($scope)
{
// Return if we've already loaded these prefs.
if (!empty($this->_scopes[$scope])) {
return;
}
// Now check the prefs cache for existing values.
try {
if ((($cached = $this->_cache->get($scope)) !== false) &&
($cached instanceof Horde_Prefs_Scope)) {
$this->_scopes[$scope] = $cached;
return;
}
} catch (Horde_Prefs_Exception $e) {}
$scope_ob = new Horde_Prefs_Scope($scope);
$scope_ob->init = true;
// Need to set object in scopes array now, since the storage object
// might recursively call the prefs object.
$this->_scopes[$scope] = $scope_ob;
foreach ($this->_storage as $storage) {
$scope_ob = $storage->get($scope_ob);
}
$scope_ob->init = false;
$this->_cache->store($scope_ob);
}
/**
* Save all dirty prefs to the storage backend.
*
* @param boolean $throw Throw exception on error? If false, ignores
* errors. (Since 2.1.0)
*/
public function store($throw = true)
{
foreach ($this->_scopes as $scope) {
if ($scope->isDirty()) {
foreach ($this->_storage as $storage) {
try {
$storage->store($scope);
} catch (Exception $e) {
if ($throw) {
throw $e;
}
}
}
try {
$this->_cache->store($scope);
} catch (Exception $e) {
if ($throw) {
throw $e;
}
}
}
}
}
/**
* Cleanup (e.g. remove) scope(s).
*
* @param boolean $all Cleanup all scopes. If false, clean present scope
* only.
*/
public function cleanup($all = false)
{
if ($all) {
/* Destroy all scopes. */
$this->_scopes = array();
$scope = null;
} else {
unset($this->_scopes[$this->_scope]);
$scope = $this->_scope;
}
try {
$this->_cache->remove($scope);
} catch (Horde_Prefs_Exception $e) {}
}
/* ArrayAccess methods. */
public function offsetExists($offset)
{
return !is_null($this->getValue($offset));
}
public function offsetGet($offset)
{
return $this->getValue($offset);
}
public function offsetSet($offset, $value)
{
$this->setValue($offset, $value);
}
public function offsetUnset($offset)
{
$this->remove($offset);
}
}
Horde_Prefs-2.5.2/locale/ar/LC_MESSAGES/Horde_Prefs.mo 0000644 0001750 0000764 00000000705 12240217745 022105 0 ustar slusarz slusarz , <