Skip to content

Commit

Permalink
Horde::callHook -> Horde_Core_Hooks#callHook
Browse files Browse the repository at this point in the history
Horde::hookExists -> Horde_Core_Hooks#hookExists
  • Loading branch information
slusarz committed Feb 5, 2014
1 parent ffa902c commit b6019a6
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 25 deletions.
3 changes: 2 additions & 1 deletion ingo/bin/ingo-postfix-policyd
Expand Up @@ -137,7 +137,8 @@ function smtpd_access_policy($query)
}

try {
$user = Horde::callHook('smtpd_access_policy_username', $query, 'ingo');
$user = $GLOBALS['injector']->getInstance('Horde_Core_Hooks')
->callHook('smtpd_access_policy_username', 'ingo', $query);
} catch (Horde_Exception_HookNotSet $e) {}

// Get $user's rules if we don't have them already.
Expand Down
3 changes: 2 additions & 1 deletion ingo/lib/Factory/Transport.php
Expand Up @@ -39,7 +39,8 @@ public function create(array $transport)

/* Get authentication parameters. */
try {
$auth = Horde::callHook('transport_auth', array($transport['driver']), 'ingo');
$auth = $GLOBALS['injector']->getInstance('Horde_Core_Hooks')
->callHook('transport_auth', 'ingo', array($transport['driver']));
} catch (Horde_Exception_HookNotSet $e) {
$auth = null;
}
Expand Down
3 changes: 2 additions & 1 deletion ingo/lib/Storage/Vacation.php
Expand Up @@ -119,7 +119,8 @@ public function setVacationEnd($data)
public function getVacationAddresses()
{
try {
return Horde::callHook('vacation_addresses', array(Ingo::getUser()), 'ingo');
return $GLOBALS['injector']->getInstance('Horde_Core_Hooks')
->callHook('vacation_addresses', 'ingo', array(Ingo::getUser()));
} catch (Horde_Exception_HookNotSet $e) {
return $this->_addr;
}
Expand Down
9 changes: 7 additions & 2 deletions turba/lib/Api.php
Expand Up @@ -750,10 +750,15 @@ public function import($content, $contentType = 'array', $source = null)

// We can't use $object->setValue() here since that cannot be used
// with composite fields.
if (Horde::hookExists('encode_attribute', 'turba')) {
$hooks = $injector->getInstance('Horde_Core_Hooks');
if ($hooks->hookExists('encode_attribute', 'turba')) {
foreach ($content as $attribute => &$value) {
try {
$value = Horde::callHook('encode_attribute', array($attribute, $value, null, null), 'turba');
$value = $hooks->callHook(
'encode_attribute',
'turba',
array($attribute, $value, null, null)
);
} catch (Turba_Exception $e) {}
}
}
Expand Down
32 changes: 21 additions & 11 deletions turba/lib/Driver.php
Expand Up @@ -1106,24 +1106,29 @@ public function getFields()
public function tovCard(Turba_Object $object, $version = '2.1',
array $fields = null, $skipEmpty = false)
{
global $injector;

$hash = $object->getAttributes();
$vcard = new Horde_Icalendar_Vcard($version);
$formattedname = false;
$charset = ($version == '2.1')
? array('CHARSET' => 'UTF-8')
: array();

$haveDecodeHook = Horde::hookExists('decode_attribute', 'turba');
$hooks = $injector->getInstance('Horde_Core_Hooks');
$decode_hook = $hooks->hookExists('decode_attribute', 'turba');

foreach ($hash as $key => $val) {
if ($skipEmpty && !strlen($val)) {
continue;
}
if ($haveDecodeHook) {
if ($decode_hook) {
try {
$val = Horde::callHook(
$val = $hooks->callHook(
'decode_attribute',
array($key, $val, $object),
'turba');
'turba',
array($key, $val, $object)
);
} catch (Turba_Exception $e) {}
}
switch ($key) {
Expand Down Expand Up @@ -2479,8 +2484,10 @@ public function toHash(Horde_Icalendar_Vcard $vcard)
*/
public function toASContact(Turba_Object $object, array $options = array())
{
global $injector;

$message = new Horde_ActiveSync_Message_Contact(array(
'logger' => $GLOBALS['injector']->getInstance('Horde_Log_Logger'),
'logger' => $injector->getInstance('Horde_Log_Logger'),
'protocolversion' => $options['protocolversion'])
);
$hash = $object->getAttributes();
Expand Down Expand Up @@ -2509,14 +2516,17 @@ public function toASContact(Turba_Object $object, array $options = array())
}
}

$haveDecodeHook = Horde::hookExists('decode_attribute', 'turba');
$hooks = $injector->getInstance('Horde_Core_Hooks');
$decode_hook = $hooks->hookExists('decode_attribute', 'turba');

foreach ($hash as $field => $value) {
if ($haveDecodeHook) {
if ($decode_hook) {
try {
$value = Horde::callHook(
$value = $hooks->callHook(
'decode_attribute',
array($field, $value, $object),
'turba');
'turba',
array($field, $value, $object)
);
} catch (Turba_Exception $e) {
Horde::log($e);
}
Expand Down
39 changes: 30 additions & 9 deletions turba/lib/Object.php
Expand Up @@ -90,10 +90,17 @@ public function getGuid($delimiter = ':')
*/
public function getValue($attribute)
{
global $attributes, $injector;

if (isset($this->attributes[$attribute]) &&
Horde::hookExists('decode_attribute', 'turba')) {
($hooks = $injector->getInstance('Horde_Core_Hooks')) &&
$hooks->hookExists('decode_attribute', 'turba')) {
try {
return Horde::callHook('decode_attribute', array($attribute, $this->attributes[$attribute], $this), 'turba');
return $hooks->callHook(
'decode_attribute',
'turba',
array($attribute, $this->attributes[$attribute], $this)
);
} catch (Turba_Exception $e) {}
} elseif (isset($this->driver->map[$attribute]) &&
is_array($this->driver->map[$attribute])) {
Expand All @@ -103,15 +110,15 @@ public function getValue($attribute)
}
return Turba::formatCompositeField($this->driver->map[$attribute]['format'], $args);
} elseif (!isset($this->attributes[$attribute])) {
if (isset($GLOBALS['attributes'][$attribute]) &&
($GLOBALS['attributes'][$attribute]['type'] == 'Turba:TurbaTags') &&
if (isset($attributes[$attribute]) &&
($attributes[$attribute]['type'] == 'Turba:TurbaTags') &&
($uid = $this->getValue('__uid'))) {
$this->synchronizeTags($GLOBALS['injector']->getInstance('Turba_Tagger')->getTags($uid, 'contact'));
$this->synchronizeTags($injector->getInstance('Turba_Tagger')->getTags($uid, 'contact'));
} else {
return null;
}
} elseif (isset($GLOBALS['attributes'][$attribute]) &&
($GLOBALS['attributes'][$attribute]['type'] == 'image')) {
} elseif (isset($attributes[$attribute]) &&
($attributes[$attribute]['type'] == 'image')) {
return empty($this->attributes[$attribute])
? null
: array(
Expand All @@ -133,11 +140,25 @@ public function getValue($attribute)
*/
public function setValue($attribute, $value)
{
if (Horde::hookExists('encode_attribute', 'turba')) {
global $injector;

$hooks = $injector->getInstance('Horde_Core_Hooks');

if ($hooks->hookExists('encode_attribute', 'turba')) {
try {
$value = Horde::callHook('encode_attribute', array($attribute, $value, isset($this->attributes[$attribute]) ? $this->attributes[$attribute] : null, $this), 'turba');
$value = $hooks->callHook(
'encode_attribute',
'turba',
array(
$attribute,
$value,
isset($this->attributes[$attribute]) ? $this->attributes[$attribute] : null,
$this
)
);
} catch (Turba_Exception $e) {}
}

if (isset($this->driver->map[$attribute]) &&
is_array($this->driver->map[$attribute]) &&
!isset($this->driver->map[$attribute]['attribute'])) {
Expand Down

0 comments on commit b6019a6

Please sign in to comment.