/** * TODO */ protected function _getAddressBook(array $fields = array()) { $key = 'turba_fb_getAddressBook|' . $GLOBALS['registry']->getAuth() . '|' . md5(implode('.', $fields)); if ($values = $this->_cache->get($key, 3600)) { return json_decode($values, true); } $cleanfields = implode(', ', $this->_prepareFields($fields)); try { $fql = 'SELECT ' . $cleanfields . ' FROM user WHERE uid IN (' . 'SELECT uid2 FROM friend WHERE uid1=' . $this->_facebook->auth->getLoggedInUser() . ')'; $results = $this->_facebook->fql->run($fql); } catch (Horde_Service_Facebook_Exception $e) { Horde::log($e, 'ERR'); if ($e->getCode() == Horde_Service_Facebook_ErrorCodes::API_EC_PARAM_SESSION_KEY) { throw new Turba_Exception(_("You are not connected to Facebook. Create a Facebook connection in the Global Preferences.")); } throw new Turba_Exception($e); } // Now pull out the results that are arrays $addressbook = array(); foreach ($results as &$result) { $addressbook[$result['uid']] = $this->_fqlToTurba($fields, $result); } $this->_cache->set($key, json_encode($addressbook)); return $addressbook; }
/** * Sets the cached group list. * * @param array $list A group list. * @param string $user A user name. */ protected function _setListCache(array $list, $user = null) { $sig = $this->_sig('list'); if (!is_null($user)) { $sig .= '_' . $user; } try { $this->_cache->set($sig, serialize($list)); } catch (Horde_Cache_Exception $e) { } }
/** * Get user groups */ public function getGroups() { $groups = $this->_cache->get('folksGroups' . $this->_user, $GLOBALS['conf']['cache']['default_lifetime']); if ($groups) { return unserialize($groups); } else { $groups = $this->_getGroups(); if ($groups instanceof PEAR_Error) { return $groups; } $this->_cache->set('folksGroups' . $this->_user, serialize($groups)); return $groups; } }
/** * Returns a Horde_History_Log corresponding to the named history entry, * with the data retrieved appropriately. * * @param string $guid The name of the history entry to retrieve. * * @return Horde_History_Log A Horde_History_Log object. * * @throws Horde_History_Exception */ public function getHistory($guid) { if (!is_string($guid)) { throw new Horde_History_Exception('The guid needs to be a string!'); } if ($this->_cache && ($history = @unserialize($this->_cache->get('horde:history:' . $guid, 0)))) { return $history; } $history = $this->_getHistory($guid); if ($this->_cache) { $this->_cache->set('horde:history:' . $guid, serialize($history), 0); } return $history; }
/** * List the available library descriptions. * * @return array The list of libraries from pear.horde.org. */ public function listDescriptions() { // Cache the list from pear.horde.org for one day if ($descriptions = $this->_cache->get(__CLASS__ . '::descriptions2', 86400)) { return unserialize($descriptions); } $components = $this->_getComponents(); $descriptions = array(); foreach ($components as $component) { $descriptions[$component->name] = $component->description; } ksort($descriptions); $this->_cache->set(__CLASS__ . '::descriptions2', serialize($descriptions)); return $descriptions; }
/** * Load the slicemap for a given mailbox. The slicemap contains * the uidvalidity information, the UIDs->slice lookup table, and any * metadata that needs to be saved for the mailbox. * * @param string $mailbox The mailbox. * @param integer $uidvalid The IMAP uidvalidity value of the mailbox. */ protected function _loadSliceMap($mailbox, $uidvalid = null) { if (!isset($this->_slicemap[$mailbox]) && ($data = $this->_cache->get($this->_getCid($mailbox, 'slicemap'), 0)) !== false && ($slice = @unserialize($data)) && is_array($slice)) { $this->_slicemap[$mailbox] = $slice; } if (isset($this->_slicemap[$mailbox])) { $ptr =& $this->_slicemap[$mailbox]; if (is_null($ptr['d']['uidvalid'])) { $ptr['d']['uidvalid'] = $uidvalid; return; } elseif (!is_null($uidvalid) && $ptr['d']['uidvalid'] != $uidvalid) { $this->_deleteMailbox($mailbox); } else { return; } } $this->_slicemap[$mailbox] = array('c' => 0, 'd' => array('uidvalid' => $uidvalid), 'i' => 0, 's' => array()); }
/** * Saves any changes to this object to the backend permanently. New * objects are added instead. * * @throws Horde_Perms_Exception */ public function save() { if (!isset($this->_db)) { throw new Horde_Perms_Exception('Cannot save because the DB instances has not been set in this object.'); } $name = $this->getName(); if (empty($name)) { throw new Horde_Perms_Exception('Permission names must be non-empty'); } $query = 'UPDATE horde_perms SET perm_data = ? WHERE perm_id = ?'; $params = array(serialize($this->data), $this->getId()); try { $this->_db->update($query, $params); } catch (Horde_Db_Exception $e) { throw new Horde_Perms_Exception($e); } $this->_cache->expire('perm_sql_' . $this->_cacheVersion . $name); $this->_cache->expire('perm_sql_exists_' . $this->_cacheVersion . $name); }
/** * Fetches a template from the specified file and return the parsed * contents. * * @param string $filename The file to fetch the template from. * * @return string The parsed template. */ public function fetch($filename = null) { $file = $this->_basepath . $filename; $force = $this->getOption('forcecompile'); if (!is_null($filename) && $file != $this->_templateFile) { $this->_template = $this->_templateFile = null; } /* First, check for a cached compiled version. */ $parts = array('horde_template', filemtime($file), $file); if ($this->getOption('gettext')) { $parts[] = setlocale(LC_ALL, 0); } $cacheid = implode('|', $parts); if (!$force && is_null($this->_template) && $this->_cache) { $this->_template = $this->_cache->get($cacheid, 0); if ($this->_template === false) { $this->_template = null; } } /* Parse and compile the template. */ if ($force || is_null($this->_template)) { $this->_template = str_replace("\n", " \n", file_get_contents($file)); $this->_parse(); if ($this->_cache) { $this->_cache->set($cacheid, $this->_template); if ($this->_logger) { $this->_logger->log(sprintf('Saved compiled template file for "%s".', $file), 'DEBUG'); } } } $this->_templateFile = $file; /* Template debugging. */ if ($this->getOption('debug')) { echo '<pre>' . htmlspecialchars($this->_template) . '</pre>'; } return $this->parse(); }
/** * TODO * * @param array $opts Options: * - 'file': (string) The filename to process. * REQUIRED for this driver. * - 'range': (array) The patchsets to process. * DEFAULT: None (all patchsets are processed). * - 'timezone': (string) The current timezone. * * @return Horde_Vcs_Patchset Patchset object. */ public function getPatchset($opts = array()) { $class = 'Horde_Vcs_Patchset_' . $this->_driver; if (!is_array($opts)) { $opts = array(); } ksort($opts); $cacheId = implode('|', array($class, $this->sourceroot, serialize($opts), $this->_cacheVersion)); if (!empty($this->_cache)) { if (isset($opts['file']) && file_exists($opts['file'])) { $ctime = time() - filemtime($opts['file']); } else { $ctime = 60; } if ($this->_cache->exists($cacheId, $ctime)) { return unserialize($this->_cache->get($cacheId, $ctime)); } } $ob = new $class($this, $opts); if (!empty($this->_cache)) { $this->_cache->set($cacheId, serialize($ob)); } return $ob; }
/** * Set cache value */ protected function _setCache($key, $value, $thread = 0) { $key = $this->_getCacheKey($key, $thread); return $this->_cache->set($key, $value); }
/** * Load application information from registry config files. */ protected function _loadApplications() { global $cli, $injector; if (!empty($this->_interfaces)) { return; } /* First, try to load from cache. */ if (!isset($cli) && !$this->isTest()) { if (Horde_Util::extensionExists('apc')) { $cstorage = 'Horde_Cache_Storage_Apc'; } elseif (Horde_Util::extensionExists('xcache')) { $cstorage = 'Horde_Cache_Storage_Xcache'; } else { $cstorage = 'Horde_Cache_Storage_File'; } $cache = new Horde_Cache(new $cstorage(array('no_gc' => true, 'prefix' => 'horde_registry_cache_')), array('lifetime' => 0, 'logger' => $injector->getInstance('Horde_Log_Logger'))); if (($cid = $this->_cacheId()) && ($cdata = $cache->get($cid, 0))) { try { list($this->applications, $this->_interfaces) = $injector->getInstance('Horde_Pack')->unpack($cdata); return; } catch (Horde_Pack_Exception $e) { } } } $config = new Horde_Registry_Registryconfig($this); $this->applications = $config->applications; $this->_interfaces = $config->interfaces; if (!isset($cache)) { return; } /* Need to determine hash of generated data, since it is possible that * there is dynamic data in the config files. This only needs to * be done once per session. */ $packed_data = $injector->getInstance('Horde_Pack')->pack(array($this->applications, $this->_interfaces)); $cid = $this->_cacheId($packed_data); if (!$cache->exists($cid, 0)) { $cache->set($cid, $packed_data); } }
/** * Reads values from the cache handler. * * The key is automatically prefixed to avoid collisions when using * different adapters or different configurations. * * @since Horde_Db 2.1.0 * * @param string $key A cache key. * * @return string A value. */ public function cacheRead($key) { return $this->_cache->get($this->_cacheKey($key), 0); }
/** * Create the generation hashes (arrays) for route lookups * * @return void */ protected function _createGens() { // Checked for a cached generator dictionary for $this->matchList if ($this->cache) { $cacheKey = 'horde.routes.' . sha1(serialize($this->matchList)); $cachedDict = $cache->get($cacheKey, $this->cacheLifetime); if ($gendict = @unserialize($cachedDict)) { $this->_gendict = $gendict; $this->_createdGens = true; return; } } // Use keys temporarily to assemble the list to avoid excessive // list iteration testing with foreach. We include the '*' in the // case that a generate contains a controller/action that has no // hardcodes. $actionList = $controllerList = array('*' => true); // Assemble all the hardcoded/defaulted actions/controllers used foreach ($this->matchList as $route) { if ($route->static) { continue; } if (isset($route->defaults['controller'])) { $controllerList[$route->defaults['controller']] = true; } if (isset($route->defaults['action'])) { $actionList[$route->defaults['action']] = true; } } $actionList = array_keys($actionList); $controllerList = array_keys($controllerList); // Go through our list again, assemble the controllers/actions we'll // add each route to. If its hardcoded, we only add it to that dict key. // Otherwise we add it to every hardcode since it can be changed. $gendict = array(); // Our generated two-deep hash foreach ($this->matchList as $route) { if ($route->static) { continue; } $clist = $controllerList; $alist = $actionList; if (in_array('controller', $route->hardCoded)) { $clist = array($route->defaults['controller']); } if (in_array('action', $route->hardCoded)) { $alist = array($route->defaults['action']); } foreach ($clist as $controller) { foreach ($alist as $action) { if (in_array($controller, array_keys($gendict))) { $actiondict =& $gendict[$controller]; } else { $gendict[$controller] = array(); $actiondict =& $gendict[$controller]; } if (in_array($action, array_keys($actiondict))) { $tmp = $actiondict[$action]; } else { $tmp = array(array(), array()); } $tmp[0][] = $route; $actiondict[$action] = $tmp; } } } if (!isset($gendict['*'])) { $gendict['*'] = array(); } // Write to the cache if ($this->cache) { $this->cache->set($cacheKey, serialize($gendict), $this->cacheLifetime); } $this->_gendict = $gendict; $this->_createdGens = true; }
/** * Cache list data. * * @param string $list_id ID of the connection matching the list. * @param string $data The data to be cached. * * @return NULL */ public function storeList($list_id, $data) { $this->horde_cache->set($list_id, $data, 0); }
/** * $Horde: horde/services/cacheview.php,v 1.7 2004/01/24 20:04:53 chuck Exp $ * * Copyright 2002-2004 Chuck Hagenbuch <*****@*****.**> * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html. */ @define('HORDE_BASE', dirname(__FILE__) . '/..'); require_once HORDE_BASE . '/lib/base.php'; require_once HORDE_LIBS . 'Horde/Cache.php'; $cid = Util::getFormData('cid'); if (empty($cid)) { _cacheError(); } $cache =& Horde_Cache::singleton($conf['cache']['driver'], Horde::getDriverConfig('cache', $conf['cache']['driver'])); $cdata = unserialize($cache->getData($cid, "_cacheError('{$cid}')", $conf['cache']['default_lifetime'])); $browser->downloadHeaders('cacheObject', $cdata['ctype'], true, strlen($cdata['data'])); echo $cdata['data']; /** * Output an error if no CID was specified or the data wasn't in the * cache. */ function _cacheError($cid = null) { if (!is_null($cid)) { Horde::logMessage('CID ' . $cid . ' not found in the cache, unable to display.', __FILE__, __LINE__, PEAR_LOG_ERR); } exit; }