function flickr_photos_get_by_id($id)
{
    $cache_key = "photo_{$id}";
    $cache = cache_get($cache_key);
    if ($cache['ok']) {
        return $cache['data'];
    }
    $lookup = flickr_photos_lookup_photo($id);
    if (!$lookup) {
        return;
    }
    $user = users_get_by_id($lookup['user_id']);
    $cluster_id = $user['cluster_id'];
    # Temporary – this should never happen
    if (!$cluster_id) {
        return null;
    }
    $enc_id = AddSlashes($id);
    $sql = "SELECT * FROM FlickrPhotos WHERE id='{$enc_id}'";
    $rsp = db_fetch_users($cluster_id, $sql);
    $row = db_single($rsp);
    if ($row) {
        cache_set($cache_key, $row, "cache_locally");
    }
    return $row;
}
function enplacify_yelp_get_listing($listing_id)
{
    $cache_key = "enplacify_yelp_listing_{$listing_id}";
    $cache = cache_get($cache_key);
    if ($cache['ok']) {
        return $cache['data'];
    }
    $url = "http://www.yelp.com/biz/" . urlencode($listing_id);
    $headers = array();
    $more = array('follow_redirects' => 1);
    $rsp = http_get($url, $headers, $more);
    if (!$rsp['ok']) {
        return $rsp;
    }
    $vcard_rsp = vcard_parse_html($rsp['body']);
    $graph_rsp = opengraph_parse_html($rsp['body']);
    if (!$vcard_rsp['ok'] && !$graph_rsp['ok']) {
        $rsp = array('ok' => 0, 'error' => 'Failed to parse listing');
    } else {
        $listing = array_merge($vcard_rsp['vcard'], $graph_rsp['graph']);
        $listing['id'] = $listing_id;
        $rsp = array('ok' => 1, 'listing' => $listing);
    }
    cache_set($cache_key, $rsp);
    return $rsp;
}
Esempio n. 3
0
function google_get_mymaps_kml_feed($url)
{
    $cache_key = "mymaps_kml_" . md5($url);
    $cache = cache_get($cache_key);
    if ($cache['ok']) {
        return $cache['data'];
    }
    $parts = utils_parse_url($url);
    if (!google_is_mymaps_hostname($parts['host'])) {
        return null;
    }
    if ($parts['path'] != '/maps/ms') {
        return null;
    }
    $query = array();
    foreach (explode("&", $parts['query']) as $q) {
        list($key, $value) = explode("=", $q, 2);
        $query[$key] = $value;
    }
    if (!$query['msid']) {
        return null;
    }
    $query['output'] = 'kml';
    $feed_url = "http://{$parts['host']}{$parts['path']}?" . http_build_query($query);
    #
    cache_set($cache_key, $feed_url, "cache locally");
    return $feed_url;
}
 /**
  * Set config option value
  *
  * @param string $name
  * @param mixed $value
  * @return mixed
  */
 function setValue($name, $value)
 {
     $option = ConfigOptions::findByName($name);
     if (instance_of($option, 'ConfigOption')) {
         $option->setValue($value);
         $save = $option->save();
         if ($save && !is_error($save)) {
             $cached_values = cache_get('config_values');
             if (is_array($cached_values)) {
                 $cached_values[$name] = $value;
             } else {
                 $cached_values = array($name => $value);
             }
             // if
             cache_set('config_values', $cached_values);
             cache_remove(TABLE_PREFIX . 'config_options_name_' . $name);
             return $value;
         } else {
             return $save;
         }
         // if
     } else {
         return new InvalidParamError('name', $name, "System configuration option '{$name}' does not exist", true);
     }
     // if
 }
function enplacify_chowhound_get_restaurant($restaurant_id)
{
    $cache_key = "enplacify_chowhound_restaurant_{$restaurant_id}";
    $cache = cache_get($cache_key);
    if ($cache['ok']) {
        return $cache['data'];
    }
    $url = "http://www.chow.com/restaurants/" . urlencode($restaurant_id);
    $headers = array();
    $more = array('follow_redirects' => 1);
    $rsp = http_get($url, $headers, $more);
    if (!$rsp['ok']) {
        return $rsp;
    }
    $vcard_rsp = vcard_parse_html($rsp['body']);
    $graph_rsp = opengraph_parse_html($rsp['body']);
    if (!$vcard_rsp['ok'] && !$graph_rsp['ok']) {
        $rsp = array('ok' => 0, 'error' => 'Failed to parse restaurant');
    } else {
        $restaurant = array_merge($vcard_rsp['vcard'], $graph_rsp['graph']);
        $restaurant['id'] = $restaurant_id;
        $rsp = array('ok' => 1, 'restaurant' => $restaurant);
    }
    cache_set($cache_key, $rsp);
    return $rsp;
}
 /**
  * Constructor
  *
  * @param $users
  *   Mandatory - An array of integers or single integer specifying the Drupal users to notify.
  *
  * @param $defaultMessage
  *   String: The default message to send in the email, overridden with the message stored in the template_data record
  *
  * @param $defaultSubject
  *   String: The default email subject, overridden with the message stored in the template_data record
  *
  * @param $queueID
  *   Integer: The QueueID associated with the message you're sending out
  *
  * @param $type
  *   String: The actual notification type using the MaestroNotificationTypes Constants
  */
 function __construct($defaultMessage = '', $defaultSubject = '', $queueID = 0, $type = MaestroNotificationTypes::ASSIGNMENT)
 {
     $observers = array();
     $this->_notificationType = $type;
     $this->_queueID = $queueID;
     $this->getNotificationUserIDs();
     $this->setNotificationSubjectAndMessage($defaultMessage, $defaultSubject);
     //Now, lets determine if we've got our observers cached.  If not, lets rebuild that observer list
     //This is how we subscribe to becoming a notification provider for Maestro.
     $observers = cache_get('maestro_notification_observers');
     if ($observers === FALSE) {
         //build the observer cache
         //need to scan through each available class type and fetch its corresponding context menu.
         foreach (module_implements('maestro_notification_observer') as $module) {
             $function = $module . '_maestro_notification_observer';
             if ($declaredObserver = $function()) {
                 foreach ($declaredObserver as $observerToCache) {
                     $observers[] = $observerToCache;
                     $this->_observers[] = $observerToCache;
                 }
             }
         }
         cache_set('maestro_notification_observers', $observers);
     } else {
         $this->_observers = $observers->data;
     }
 }
 /**
  * Returns an associative array of classes known to extend Node.
  * Pulls this array from cache if available - if not, generates
  * and caches it.
  *
  * Class names are keyed on their machine name.
  * 
  * @access private
  * @static
  * @return array
  */
 private static function init_registry()
 {
     $cache = cache_get(self::DOODAL_CACHE_ID);
     ##
     ## Attempt to get registry from cache
     if ($cache && !empty($cache->data)) {
         return $cache->data;
     } else {
         ##
         ## Load all classes registered for autoloading not in an ignored (i.e. system) module
         $results = db_query("SELECT name FROM {registry} WHERE type = 'class' AND module != '' AND module NOT IN (:modules) ORDER BY name", array(':modules' => self::get_ignored_modules()))->fetchAll();
         ##
         ## Get subset of classes marked as "node"
         $registry = array();
         foreach ($results as $result) {
             $reflectedClass = new ReflectionAnnotatedClass($result->name);
             if ($reflectedClass->hasAnnotation('MachineName')) {
                 $registry[$reflectedClass->getAnnotation('MachineName')->value] = $result->name;
             }
         }
         ##
         ## Cache results and return
         cache_set(self::DOODAL_CACHE_ID, $registry, 'cache', CACHE_PERMANENT);
         return $registry;
     }
 }
Esempio n. 8
0
function make_captcha($id)
{
    require 'kcaptcha/kcaptcha.php';
    $captcha = new KCAPTCHA();
    cache_set('taxi_captcha_' . $id, $captcha->getKeyString());
    die;
}
function sheets_lookup_by_fingerprint($fingerprint, $user_id = 0)
{
    $cache_key = "sheets_lookup_fingerprint_{$fingerprint}";
    $cache = cache_get($cache_key);
    if ($cache['ok']) {
        return $cache['data'];
    }
    #
    $enc_fingerprint = AddSlashes($fingerprint);
    $sql = "SELECT * FROM SheetsLookup WHERE fingerprint='{$enc_fingerprint}'";
    if ($user_id) {
        $enc_id = AddSlashes($user_id);
        $sql .= " AND user_id='{$enc_id}'";
    }
    $rsp = db_fetch($sql);
    $sheets = array();
    foreach ($rsp['rows'] as $row) {
        $more = array('sheet_user_id' => $row['user_id']);
        if ($sheet = sheets_get_sheet($row['sheet_id'], $user_id, $more)) {
            $sheets[] = $sheet;
        }
    }
    cache_set($cache_key, $sheets);
    return $sheets;
}
Esempio n. 10
0
 public static function cachedRequest($url, array $options = array(), $cache_errors = FALSE)
 {
     $cid = static::cachedRequestGetCid($url, $options);
     $bin = isset($options['cache']['bin']) ? $options['cache']['bin'] : 'cache';
     if ($cid && ($cache = CacheHelper::get($cid, $bin))) {
         return $cache->data;
     } else {
         $response = drupal_http_request($url, $options);
         $response->request_url = $url;
         $response->request_options = $options;
         if (!empty($response->error)) {
             trigger_error("Error on request to {$url}: {$response->code} {$response->error}.", E_USER_WARNING);
         }
         if (!$cache_errors && !empty($response->error)) {
             $cid = FALSE;
         }
         if ($cid) {
             $expire = static::cachedRequestGetExpire($response, $options);
             if ($expire !== FALSE) {
                 cache_set($cid, $response, $bin, $expire);
             }
         }
         return $response;
     }
 }
 /**
  * Return all users assigned to a specific object
  *
  * @param ProjectObject $object
  * @return array
  */
 function findAssigneesByObject($object)
 {
     $cache_id = 'object_assignments_' . $object->getId();
     $cached_values = cache_get($cache_id);
     if (is_array($cached_values)) {
         if (count($cached_values) > 0) {
             return Users::findByIds($cached_values);
         } else {
             return null;
         }
         // if
     }
     // if
     $users_table = TABLE_PREFIX . 'users';
     $assignments_table = TABLE_PREFIX . 'assignments';
     $cached_values = array();
     $rows = db_execute_all("SELECT {$users_table}.id FROM {$users_table}, {$assignments_table} WHERE {$assignments_table}.object_id = ? AND {$assignments_table}.user_id = {$users_table}.id", $object->getId());
     if (is_foreachable($rows)) {
         foreach ($rows as $row) {
             $cached_values[] = (int) $row['id'];
         }
         // foreach
     }
     // if
     cache_set($cache_id, $cached_values);
     if (count($cached_values) > 0) {
         return Users::findByIds($cached_values);
     } else {
         return null;
     }
     // if
 }
function flickr_photos_metadata_load(&$photo)
{
    $cache_key = "photos_meta_{$photo['id']}";
    $cache = cache_get($cache_key);
    if ($cache['ok']) {
        return $cache['data'];
    }
    $meta = flickr_photos_metadata_path($photo);
    if (!file_exists($meta)) {
        return array('ok' => 0, 'error' => 'missing meta file');
    }
    $fh = fopen($meta, "r");
    $data = fread($fh, filesize($meta));
    fclose($fh);
    $data = json_decode($data, "as hash");
    # guh... just in case stuff has been double
    # json encoded; this was a by-product of moving
    # over to the http_multi stuff and not realizing
    # what I was doing (20111114/straup)
    if ($data && !is_array($data)) {
        $data = json_decode($data, "as hash");
    }
    if (!$data) {
        return array('ok' => 0, 'error' => 'failed to decode');
    }
    $rsp = array('ok' => 1, 'data' => $data);
    cache_set($cache_key, $rsp);
    return $rsp;
}
 /**
  * Return value of $name config option for a given project
  *
  * @param string $name
  * @param Project $project
  * @return mixed
  */
 function getValue($name, $project)
 {
     $cache_id = 'project_config_options_' . $project->getId();
     $cached_value = cache_get($cache_id);
     if (is_array($cached_value) && isset($cached_value[$name])) {
         return $cached_value[$name];
     }
     // if
     $option = ConfigOptions::findByName($name, PROJECT_CONFIG_OPTION);
     if (instance_of($option, 'ConfigOption')) {
         $record = db_execute_one('SELECT value FROM ' . TABLE_PREFIX . 'project_config_options WHERE project_id = ? AND name = ?', $project->getId(), $name);
         if (is_array($record) && isset($record['value'])) {
             $value = trim($record['value']) != '' ? unserialize($record['value']) : null;
         } else {
             $value = $option->getValue();
         }
         // if
         if (is_array($cached_value)) {
             $cached_value[$name] = $value;
         } else {
             $cached_value = array($name => $value);
         }
         // if
         cache_set($cache_id, $cached_value);
         return $value;
     } else {
         return new InvalidParamError('name', $name, "Project configuration option '{$name}' does not exist", true);
     }
     // if
 }
 function __construct($template_id)
 {
     $this->_template_id = $template_id;
     $context_options = cache_get('maestro_taskclass_info');
     // Test if context options are cached - if not then we will set it
     // The class function getContextMenu will read options from the cache
     if ($context_options === FALSE) {
         $context_options = array();
         // Scan through each available class type and fetch its corresponding context menu.
         foreach (module_implements('maestro_get_taskobject_info') as $module) {
             $function = $module . '_maestro_get_taskobject_info';
             if ($arr = $function()) {
                 $context_options = maestro_array_add($context_options, $arr);
             }
         }
         cache_set('maestro_taskclass_info', $context_options);
     }
     $handler_options = cache_get('maestro_handler_options');
     // Test if task type handler options are cached - if not then we will set it
     // The class function getHandlerOptions will read options from the cache
     if ($handler_options === FALSE) {
         // Scan through each available class type and fetch its corresponding context menu.
         foreach (module_implements('maestro_handler_options') as $module) {
             $function = $module . '_maestro_handler_options';
             if ($arr = $function()) {
                 $handler_options = maestro_array_merge_keys($arr, $handler_options);
             }
         }
         cache_set('maestro_handler_options', $handler_options);
     }
 }
function enplacify_flickr_get_photo($photo_id)
{
    if (!$GLOBALS['cfg']['flickr_apikey']) {
        return array('ok' => 0, 'error' => 'No Flickr API key');
    }
    $cache_key = "enplacify_flickr_photo_{$photo_id}";
    $cache = cache_get($cache_key);
    if ($cache['ok']) {
        return $cache['data'];
    }
    $url = "http://api.flickr.com/services/rest/?method=flickr.photos.getInfo";
    $url .= "&photo_id={$photo_id}";
    $url .= "&api_key={$GLOBALS['cfg']['flickr_apikey']}";
    $url .= "&format=json&nojsoncallback=1";
    $rsp = http_get($url);
    if (!$rsp['ok']) {
        return $rsp;
    }
    $json = json_decode($rsp['body'], "f**k off php");
    if ($json['stat'] != 'ok') {
        return array('ok' => 0, 'error' => 'Flickr API error');
    }
    $photo = $json['photo'];
    $rsp = array('ok' => 1, 'photo' => $json['photo']);
    cache_set($cache_key, $rsp);
    return $rsp;
}
function enplacify_dopplr_get_place($place_type, $place_id)
{
    $cache_key = "enplacify_dopplr_{$place_type}_{$place_id}";
    $cache = cache_get($cache_key);
    if ($cache['ok']) {
        return $cache['data'];
    }
    $url = "http://dplr.it/" . urlencode($place_type) . "/" . urlencode($place_id);
    $headers = array();
    $more = array('follow_redirects' => 1);
    $rsp = http_get($url, $headers, $more);
    if (!$rsp['ok']) {
        return $rsp;
    }
    # https://github.com/mncaudill/flickr-machinetag-geo/blob/master/src/parsers/dopplr.php
    if (preg_match('#pointLat:(-?\\d.*),#U', $rsp['body'], $m)) {
        $latitude = floatval($m[1]);
    }
    if (preg_match('#pointLng:(-?\\d.*),#U', $rsp['body'], $m)) {
        $longitude = floatval($m[1]);
    }
    if (!$latitude || !$longitude) {
        return array('ok' => 0, 'error' => 'failed to locate lat,lon data');
    }
    if (preg_match('#<title>(.*)\\|#U', $rsp['body'], $m)) {
        $name = trim($m[1]);
    }
    $place = array('latitude' => $latitude, 'longitude' => $longitude, 'url' => $url, 'name' => $name);
    $rsp = array('ok' => 1, 'place' => $place);
    cache_set($cache_key, $rsp);
    return $rsp;
}
Esempio n. 17
0
/**
 * Add custom PHPTemplate variable into the page template
 */
function ninesixtyrobots_preprocess_page(&$vars)
{
    // Check if the theme is using Twitter.
    $use_twitter = theme_get_setting('use_twitter');
    if (is_null($use_twitter)) {
        $use_twitter = 1;
    }
    // If the theme uses Twitter pull it in and display it in the slogan.
    if ($use_twitter) {
        if ($cache = cache_get('ninesixtyrobots_tweets')) {
            $data = $cache->data;
        } else {
            $query = theme_get_setting('twitter_search_term');
            if (is_null($query)) {
                $query = 'lullabot';
            }
            $query = drupal_urlencode($query);
            $response = drupal_http_request('http://search.twitter.com/search.json?q=' . $query);
            if ($response->code == 200) {
                $data = json_decode($response->data);
                // Set a 5 minute cache on retrieving tweets.
                // Note if this isn't updating on your site *run cron*.
                cache_set('ninesixtyrobots_tweets', $data, 'cache', 300);
            }
        }
        $tweet = $data->results[array_rand($data->results)];
        // Create the actual variable finally.
        $vars['site_slogan'] = check_plain(html_entity_decode($tweet->text));
    }
}
Esempio n. 18
0
function users_get_by_id($id)
{
    $sql = "SELECT * FROM users WHERE id=" . intval($id);
    $rsp = db_fetch_accounts($sql);
    $user = db_single($rsp);
    cache_set("USER-{$user['id']}", $user);
    return $user;
}
Esempio n. 19
0
function runtime_save()
{
    global $runtime, $g_runtime_save;
    if (!$g_runtime_save) {
        return;
    }
    $r = cache_set('runtime', $runtime);
}
Esempio n. 20
0
function log_user($user) {
  // We want to know who the hell is this
  $encoded_user = json_encode($user);
  cache_set('user:'******'id'], $encoded_user);
  
  // Log this usage
  log_insert('user_hit');
}
 public function cache_set($cid, $data, $bin = 'cache', $expire = NULL)
 {
     if ($expire === NULL) {
         return cache_set($cid, $data, $bin);
     } else {
         return cache_set($cid, $data, $bin, $expire);
     }
 }
 /**
  * Sets $this->luke with the meta-data about the index from admin/luke.
  */
 protected function setLuke($num_terms = 0)
 {
     if (empty($this->luke[$num_terms])) {
         $url = $this->_constructUrl(self::LUKE_SERVLET, array('numTerms' => "{$num_terms}", 'wt' => self::SOLR_WRITER));
         $this->luke[$num_terms] = $this->_sendRawGet($url);
         cache_set($this->luke_cid, $this->luke);
     }
 }
Esempio n. 23
0
 /**
  * Store the results of a block view() in cache.
  *
  * @param string $cid
  *   The cache ID of the data to store.
  * @param mixed $data
  *   The data to store in the cache. Complex data types will be automatically
  *   serialized before insertion. Strings will be stored as plain text and are
  *   not serialized.
  * @param int $expire
  *   One of the following values:
  *   - CACHE_PERMANENT: Indicates that the item should never be removed unless
  *     explicitly told to using cache_clear_all() with a cache ID.
  *   - CACHE_TEMPORARY: Indicates that the item should be removed at the next
  *     general cache wipe.
  *   - A Unix timestamp: Indicates that the item should be kept at least until
  *     the given time, after which it behaves like CACHE_TEMPORARY.
  */
 public static function set($cid, $data, $expire)
 {
     $known_cids = static::getCids();
     if (!isset($known_cids[$cid])) {
         $known_cids[$cid] = TRUE;
         variable_set(static::VARCIDS, $known_cids);
     }
     cache_set(static::prefixCid($cid), $data, static::BIN, $expire);
 }
Esempio n. 24
0
/**
 * 清除当前 IP 访客的登录失败次数。
 * 如果登录失败次数是 0,不管;如果不是 0,则将其设为 0,并设置一个超时时间
 */
function login_resetfail()
{
    $ip = $_SERVER['REMOTE_ADDR'];
    $num = cache_get("login_fails_{$ip}");
    if ($num != 0) {
        echo "set it to expire";
        cache_set("login_fails_{$ip}", 0, LOGIN_FAIL_ANNEAL_TIME);
    }
}
Esempio n. 25
0
function cron_run($force = 0)
{
    global $conf, $time, $forumlist, $runtime;
    $cron_1_last_date = runtime_get('cron_1_last_date');
    $cron_2_last_date = runtime_get('cron_2_last_date');
    $t = $time - $cron_1_last_date;
    if ($t > 300 || $force) {
        $lock = cache_get('cron_lock_1');
        if ($lock === NULL) {
            cache_set('cron_lock_1', 1, 10);
            // 设置 10 秒超时
            // 清理在线
            online_gc();
            runtime_set('cron_1_last_date', $time);
            cache_delete('cron_lock_1');
        }
    }
    $t = $time - $cron_2_last_date;
    if ($t > 86400 || $force) {
        $lock = cache_get('cron_lock_2');
        // 高并发下, mysql 机制实现的锁锁不住,但是没关系
        if ($lock === NULL) {
            cache_set('cron_lock_2', 1, 10);
            // 设置 10 秒超时
            // 每日统计清 0
            runtime_set('todayposts', 0);
            runtime_set('todaythreads', 0);
            runtime_set('todayusers', 0);
            foreach ($forumlist as $fid => $forum) {
                forum__update($fid, array('todayposts' => 0, 'todaythreads' => 0));
            }
            forum_list_cache_delete();
            // 清理最新发帖,只保留 100 条。
            thread_new_gc();
            thread_lastpid_gc();
            // 清理在线
            online_gc();
            // 清理临时附件
            attach_gc();
            // 清空每日 IP 限制
            ipaccess_truncate();
            // 清理游客喜欢限制
            guest_agree_truncate();
            list($y, $n, $d) = explode(' ', date('Y n j', $time));
            // 0 点
            $today = mktime(0, 0, 0, $n, $d, $y);
            // -8 hours
            runtime_set('cron_2_last_date', $today, TRUE);
            // 加到1天后
            // 每日生成最新的 sitemap
            thread_new_sitemap();
            // 往前推8个小时,尽量保证在前一天
            table_day_cron($time - 8 * 3600);
            cache_delete('cron_lock_2');
        }
    }
}
Esempio n. 26
0
function friendlink_find_cache($life = 300)
{
    $friendlinklist = cache_get('friendlinklist');
    if ($friendlinklist === NULL) {
        $friendlinklist = friendlink_find();
        cache_set('friendlinklist', $friendlinklist, $life);
    }
    return $friendlinklist;
}
function thread_top_find_cache()
{
    global $conf;
    $threadlist = cache_get('thread_top_list');
    if ($threadlist === NULL) {
        $threadlist = thread_top_find();
        cache_set('thread_top_list', $threadlist);
    }
    return $threadlist;
}
Esempio n. 28
0
 function query($iteratorClass = 'GoogleMiniResultIterator') {
   if (!db_table_exists('cache_google_appliance')) {
     $this->cache = FALSE;
   }
   if (!$this->cache) {
     return parent::query($iteratorClass);
   }
   else {
     $cached_result_obj = NULL;
     $cache_key = md5($this->buildQuery());
     $_cached_result_xml = cache_get($cache_key, 'cache_google_appliance');
     $cached_result_xml = $_cached_result_xml->data;
     $google_debug = variable_get('google_appliance_debug', 0);
     if ($cached_result_xml) {
       try {
         $google_results = GoogleMini::resultFactory($cached_result_xml, $iteratorClass);
       }
       catch (Exception $e) {
         drupal_set_message($e->getMessage(), 'error');
         watchdog('google_appliance', $e->getMessage());
         return FALSE;
       }
       if ($google_debug >= 2 ){
         if (function_exists('dpr')) {
           dpr("got cache for $cache_key");
         }
       }
       elseif ($google_debug == 1)  {
         watchdog('google_appliance', "got cache for !cache_key at !url", array('!cache_key' => $cache_key, '!url' => $_GET['q']));
       }
     }
     else {
       try {
         $google_results = parent::query($iteratorClass);
       }
       catch (Exception $e) {
         drupal_set_message($e->getMessage(), 'error');
         watchdog('google_appliance', $e->getMessage());
         return FALSE;
       }
       $timeout = variable_get('google_appliance_cache_timeout', 600); // 10 minutes by default
       cache_set($cache_key, $google_results->payload->asXML(), 'cache_google_appliance', time() + $timeout);
       $google_debug = variable_get('google_debug', 0);
       if ($google_debug >= 2 ){
         if (function_exists('dpr')) {
           dpr("setting cache for $cache_key");
         }
       }
       elseif ($google_debug == 1)  {
         watchdog('google_appliance', "setting cache for !cache_key at !url", array('!cache_key' => $cache_key, '!url' => $_GET['q']));
       }
     }
     return $google_results;
   }
 }
Esempio n. 29
0
 /**
  */
 function show()
 {
     $cache_name = 'home_page_default';
     $data = cache_get($cache_name);
     if (!$data) {
         $data = ['newest_users' => module_safe('users')->_for_home_page($this->NUM_NEWEST_USERS), 'newest_news' => module_safe('news')->_for_home_page(['num_items' => $this->NUM_NEWEST_NEWS]), 'newest_forum_posts' => module_safe('forum')->_for_home_page($this->NUM_NEWEST_FORUM_POSTS, $this->NEWEST_FORUM_TEXT_LEN), 'newest_blog_posts' => module_safe('blog')->_for_home_page($this->NUM_NEWEST_BLOG_POSTS, $this->NEWEST_BLOG_TEXT_LEN), 'newest_gallery_photo' => module_safe('gallery')->_for_home_page($this->NUM_NEWEST_GALLERY_PHOTO), 'newest_article_post' => module_safe('articles')->_for_home_page($this->NUM_NEWEST_ARTICLE_POST), 'newest_comments' => module_safe('comments')->_for_home_page($this->NUM_NEWEST_COMMENTS)];
         cache_set($cache_name, $data);
     }
     $replace =& $data;
     return tpl()->parse($_GET['object'] . '/main', $replace);
 }
function flickr_users_path_aliases_for_user(&$user)
{
    $cache_key = "flickr_user_path_aliases_user_{$user['id']}";
    $cache = cache_get($cache_key);
    if ($cache['ok']) {
        return $cache['data'];
    }
    $enc_id = AddSlashes($user['id']);
    $sql = "SELECT * FROM FlickrUsersPathAliases WHERE user_id='{$enc_id}' ORDER BY created DESC";
    $rsp = db_fetch($sql);
    cache_set($cache_key, $rsp, "cache locally");
    return $rsp;
}