// if (!$username || empty($_SESSION['turba']['has_share'])) {
// return;
// }
-//
+//
// require TURBA_BASE . '/config/sources.php';
// $shares = Turba::listShares(true);
// if (is_a($shares, 'PEAR_Error')) {
// return;
// }
-//
+//
// foreach ($shares as $uid => $share) {
// $params = @unserialize($share->get('params'));
// if (empty($params['source'])) {
/**
* Called when we store a value.
*
- * Passwords should be MD5 encoded, but not displayed.
+ * @param string $attribute Attribute name.
+ * @param string $new New value.
+ * @param string $old Old value.
+ * @param Turba_Object $contact Contact object.
*
- * @todo Make this a generic encode() method.
+ * @return string The encoded value.
*/
-// public function encode_password($new_password, $old_password, &$contact)
+// public function encode_attribute($attribute, $new, $old, $contact)
// {
-// if (is_null($new_password) || $new_password == '' ||
-// $new_password == '[Not Displayed]') {
-// return $old_password;
-// } else {
-// return md5($new_password);
+// switch ($attribute) {
+// case 'password':
+// /* Passwords should be MD5 encoded, but not displayed. */
+// return (is_null($new) || ($new == '') || ($new == '[Not Displayed']))
+// ? $old
+// : hash('md5', $new);
// }
+//
+// return $new;
// }
/**
* Called when we display a value.
*
- * Passwords should be MD5 encoded, but not displayed.
+ * @param string $attribute Attribute name.
+ * @param string $new New value.
+ * @param string $old Old value.
+ * @param Turba_Object $contact Contact object.
*
- * @todo Make this a generic decode() method.
+ * @return string The decoded value.
+ * @throws Turba_Exception Thrown if there is nothing to decode.
*/
-// public function decode_password($password, &$contact)
+// public function decode_attribute($attribute, $value, $contact)
// {
-// if (strstr($_SERVER['PHP_SELF'], 'editobject')) {
-// return null;
-// } else {
-// return '[Not Displayed]';
+// switch ($attribute) {
+// case 'password':
+// /* Passwords should be MD5 encoded, but not displayed. */
+// return (strstr($_SERVER['PHP_SELF'], 'editobject'))
+// ? null
+// : '[Not Displayed]';
// }
+//
+// throw new Turba_Exception('No decode handler.');
// }
+
}
use the updated data with your old Turba version anymore.
+Upgrading Turba from 2.x to 3.x
+===============================
+
+The ``_turba_hook_encode_{attribute}`` hook has been moved to the
+'encode_attribute' hook.
+
+The ``_turba_hook_decode_{attribute}`` hook has been moved to the
+'decode_attribute' hook.
+
+
Upgrading Turba from 2.3.x to 2.3.3
===================================
*/
function getValue($attribute)
{
- /* Cache hooks to avoid multiple file_exists() calls. */
- static $hooks;
- if (!isset($hooks)) {
- $hooks = array();
+ if (isset($this->attributes[$attribute])) {
try {
- Horde::loadConfiguration('hooks.php', null, 'turba');
- } catch (Horde_Exception $e) {}
- }
- if (!isset($hooks[$attribute])) {
- $function = '_turba_hook_decode_' . $attribute;
- if (function_exists($function)) {
- $hooks[$attribute] = $function;
- } else {
- $hooks[$attribute] = false;
- }
- }
-
- if (isset($this->attributes[$attribute]) &&
- !empty($hooks[$attribute])) {
- return call_user_func_array($hooks[$attribute],
- array($this->attributes[$attribute], &$this));
+ return Horde::callHook('decode_attribute', array($attribute, $this->attributes[$attribute], $this), 'turba');
+ } catch (Horde_Exception_HookNotSet $e) {}
+ } catch (Turba_Exception $e) {}
}
if (isset($this->driver->map[$attribute]) &&
*/
function setValue($attribute, $value)
{
- /* Cache hooks to avoid multiple file_exists() calls. */
- static $hooks;
- if (!isset($hooks)) {
- $hooks = array();
- try {
- Horde::loadConfiguration('hooks.php', null, 'turba');
- } catch (Horde_Exception $e) {}
- }
- if (!isset($hooks[$attribute])) {
- $function = '_turba_hook_encode_' . $attribute;
- if (function_exists($function)) {
- $hooks[$attribute] = $function;
- } else {
- $hooks[$attribute] = false;
- }
- }
- if ($hooks[$attribute]) {
- $value = call_user_func_array($hooks[$attribute], array($value, $this->attributes[$attribute], &$this));
- }
+ try {
+ $value = Horde::callHook('encode_attribute', array($attribute, $value, $this->attributes[$attribute], $this), 'turba');
+ } catch (Horde_Exception_HookNotSet $e) {}
+ } catch (Turba_Exception $e) {}
if (isset($this->driver->map[$attribute]) &&
is_array($this->driver->map[$attribute]) &&