*/
public function getPublicKey($address, $fingerprint = null, $server = true)
{
- $result = false;
-
/* If there is a cache driver configured, try to get the public key
* from the cache. */
- if (!empty($GLOBALS['conf']['cache']['driver'])) {
- $cache = &Horde_Cache::singleton($GLOBALS['conf']['cache']['driver'], Horde::getDriverConfig('cache', $GLOBALS['conf']['cache']['driver']));
- if (is_a($cache, 'PEAR_Error')) {
- Horde::fatal($cache, __FILE__, __LINE__);
- } else {
- $result = $cache->get("PGPpublicKey_" . $address . $fingerprint, 3600);
+ if (($cache = &IMP::getCacheOb())) {
+ $result = $cache->get("PGPpublicKey_" . $address . $fingerprint, 3600);
+ if ($result) {
+ Horde::logMessage('PGPpublicKey: ' . serialize($result), __FILE__, __LINE__, PEAR_LOG_DEBUG);
+ return $result;
}
}
- if ($result) {
- Horde::logMessage('PGPpublicKey: ' . serialize($result), __FILE__, __LINE__, PEAR_LOG_DEBUG);
- return $result;
- }
-
/* Try retrieving by e-mail only first. */
$params = IMP_Compose::getAddressSearchParams();
$result = $GLOBALS['registry']->call('contacts/getField', array($address, self::PUBKEY_FIELD, $params['sources'], false, true));
if (empty($cache_type) ||
$cache_type == 'none' ||
- ($cache_type == 'horde_cache' &&
- $conf['cache']['driver'] == 'none')) {
+ (($cache_type == 'horde_cache') &&
+ !($cache = &self::getCacheOb()))) {
Horde::includeScriptFiles();
return;
}
break;
case 'horde_cache':
- $cache = &Horde_Cache::singleton($conf['cache']['driver'], Horde::getDriverConfig('cache', $conf['cache']['driver']));
$exists = $cache->exists($sig, empty($conf['server']['cachejsparams']['lifetime']) ? 0 : $conf['server']['cachejsparams']['lifetime']);
$js_url = IMP::getCacheURL('js', $sig);
break;
if (empty($cache_type) ||
$cache_type == 'none' ||
- ($cache_type == 'horde_cache' &&
- $conf['cache']['driver'] == 'none')) {
+ (($cache_type == 'horde_cache') &&
+ !($cache = &self::getCacheOb()))) {
$css_out = array_merge($css, $css_out);
} else {
$mtime = array(0);
break;
case 'horde_cache':
- $cache = &Horde_Cache::singleton($GLOBALS['conf']['cache']['driver'], Horde::getDriverConfig('cache', $GLOBALS['conf']['cache']['driver']));
$exists = $cache->exists($sig, empty($GLOBALS['conf']['server']['cachecssparams']['lifetime']) ? 0 : $GLOBALS['conf']['server']['cachecssparams']['lifetime']);
$css_url = IMP::getCacheURL('css', $sig);
break;
return $msglist;
}
+
+ /**
+ * Returns a Horde_Cache object (if configured) and handles any errors
+ * associated with creating the object.
+ *
+ * @return Horde_Cache A pointer to a Horde_Cache object.
+ */
+ static public function &getCacheOb()
+ {
+ global $conf;
+
+ if ($conf['cache']['driver'] == 'none') {
+ return false;
+ }
+
+ $cache = &Horde_Cache::singleton($conf['cache']['driver'], Horde::getDriverConfig('cache', $conf['cache']['driver']));
+ if (is_a($cache, 'PEAR_Error')) {
+ Horde::fatal($cache, __FILE__, __LINE__);
+ }
+
+ return $cache;
+ }
}
$this->_basepath = $basepath;
}
- $this->_cache = &Horde_Cache::singleton($GLOBALS['conf']['cache']['driver'], Horde::getDriverConfig('cache', $GLOBALS['conf']['cache']['driver']));
+
+ $this->_cache = &IMP::getCacheOb();
}
/**
/* First, check for a cached compiled version. */
$cacheid = 'horde_template|' . filemtime($file) . '|' . $file . '|'
. $this->getOption('gettext');
- if (!$force && is_null($this->_template) && isset($this->_cache)) {
+ if (!$force && is_null($this->_template) && $this->_cache) {
$this->_template = $this->_cache->get($cacheid, 0);
if ($this->_template === false) {
$this->_template = null;