public function processTypo($text)
 {
     $key = $this->cacheKey($text);
     if (!($html = $this->cache->load($key))) {
         $html = parent::processTypo($text);
         $this->cache->save($html);
     }
     return $html;
 }
 /**
  * Gets the current version of Code Bank
  * @return {string} Version Number Plus Build Date
  */
 protected final function getVersion()
 {
     if (CB_VERSION != '@@VERSION@@') {
         return CB_VERSION . ' ' . CB_BUILD_DATE;
     }
     // Tries to obtain version number from composer.lock if it exists
     $composerLockPath = BASE_PATH . '/composer.lock';
     if (file_exists($composerLockPath)) {
         $cache = SS_Cache::factory('CodeBank_Version');
         $cacheKey = filemtime($composerLockPath);
         $version = $cache->load($cacheKey);
         if ($version) {
             $version = $version;
         } else {
             $version = '';
         }
         if (!$version && ($jsonData = file_get_contents($composerLockPath))) {
             $lockData = json_decode($jsonData);
             if ($lockData && isset($lockData->packages)) {
                 foreach ($lockData->packages as $package) {
                     if ($package->name == 'undefinedoffset/silverstripe-codebank' && isset($package->version)) {
                         $version = $package->version;
                         break;
                     }
                 }
                 $cache->save($version, $cacheKey);
             }
         }
     }
     if (!empty($version)) {
         return $version;
     }
     return _t('CodeBank.DEVELOPMENT_BUILD', '_Development Build');
 }
 public function __call($method, $arguments)
 {
     // do not make requests with an invalid key
     if ($method != 'ping' && !$this->isApiKeyValid()) {
         return;
     }
     if ($this->getAutoCache()) {
         $cache_key = $this->makeCacheKey($method, $arguments);
         $cache = SS_Cache::factory(__CLASS__);
         if ($result = $cache->load($cache_key)) {
             return unserialize($result);
         }
     }
     try {
         $result = call_user_func_array(array($this->client, $method), $arguments);
     } catch (Exception $e) {
         if (Director::isDev() && $this->debug_exceptions) {
             var_dump($e);
         }
         $result = false;
     }
     if ($this->getAutoCache()) {
         $cache->save(serialize($result));
     }
     return $result;
 }
Example #4
0
	/**
	 * Constructs and initialises a new configuration object, either loading
	 * from the cache or re-scanning for classes.
	 *
	 * @param string $base The project base path.
	 * @param bool   $forceRegen Force the manifest to be regenerated.
	 */
	public function __construct($base, $includeTests = false, $forceRegen = false ) {
		$this->base = $base;

		// Get the Zend Cache to load/store cache into
		$this->cache = SS_Cache::factory('SS_Configuration', 'Core', array(
			'automatic_serialization' => true,
			'lifetime' => null
		));

		// Unless we're forcing regen, try loading from cache
		if (!$forceRegen) {
			// The PHP config sources are always needed
			$this->phpConfigSources = $this->cache->load('php_config_sources');
			// Get the variant key spec
			$this->variantKeySpec = $this->cache->load('variant_key_spec');
			// Try getting the pre-filtered & merged config for this variant
			if (!($this->yamlConfig = $this->cache->load('yaml_config_'.$this->variantKey()))) {
				// Otherwise, if we do have the yaml config fragments (and we should since we have a variant key spec) work out the config for this variant
				if ($this->yamlConfigFragments = $this->cache->load('yaml_config_fragments')) {
					$this->buildYamlConfigVariant();
				}
			}
		}

		// If we don't have a config yet, we need to do a full regen to get it
		if (!$this->yamlConfig) {
			$this->regenerate($includeTests);
			$this->buildYamlConfigVariant();
		}
	}
 /**
  * @return Zend_Cache_Frontend
  */
 public function getCache()
 {
     if (!$this->cache) {
         $this->cache = SS_Cache::factory('CurrencyConverter');
     }
     return $this->cache;
 }
 private function destroyJSONCahces()
 {
     $cacheNames = [EventsController::EVENTS_CACHE_NAME, EventsController::CONFIG_CACHE_NAME];
     foreach ($cacheNames as $cacheName) {
         SS_Cache::factory($cacheName)->clean(Zend_Cache::CLEANING_MODE_ALL);
     }
 }
 /**
  * @return Zend_Cache_Frontend
  */
 public function getCache()
 {
     if (!$this->cache) {
         $this->cache = SS_Cache::factory('EventSearch');
     }
     return $this->cache;
 }
 public function setUp()
 {
     parent::setUp();
     // clear cache
     SS_Cache::factory('local_cache')->clean(Zend_Cache::CLEANING_MODE_ALL);
     Member::add_extension('CacheableExtension');
 }
 /**
  * 
  * @param SS_HTTPRequest $request
  */
 public function run($request)
 {
     $newLine = CacheableNavigation_Rebuild::new_line();
     SS_Cache::pick_backend(CACHEABLE_STORE_NAME, CACHEABLE_STORE_FOR, CACHEABLE_STORE_WEIGHT);
     SS_Cache::factory(CACHEABLE_STORE_FOR)->clean('all');
     echo 'Cleanup: ' . CACHEABLE_STORE_NAME . " done." . $newLine;
 }
 /**
  *
  * @return Zend_Cache_Core
  */
 public function getCache()
 {
     if (!$this->cache) {
         $this->cache = SS_Cache::factory('restricted_perms', 'Output', array('automatic_serialization' => true, 'automatic_cleaning_factor' => 0));
     }
     return $this->cache;
 }
 public function setUp()
 {
     parent::setUp();
     $this->defaultToken = Config::inst()->get('TokenAuth', 'DevToken');
     // clear cache
     SS_Cache::factory('rest_cache')->clean(Zend_Cache::CLEANING_MODE_ALL);
 }
Example #12
0
 protected function cache()
 {
     if (!$this->cache) {
         $this->cache = \SS_Cache::factory('SocialFeed_Providers', 'Output', ['lifetime' => $this->cacheLifetime * 60 * 60]);
     }
     return $this->cache;
 }
 /**
  * @return Zend_Cache_Frontend
  */
 public static function getCache()
 {
     if (!self::$cache) {
         self::$cache = SS_Cache::factory('Geocoder');
     }
     return self::$cache;
 }
 /**
  * @return SS_Cache
  */
 protected static function get_cache()
 {
     $lifetime = Config::inst()->get(__CLASS__, 'lifetime');
     $cache = SS_Cache::factory(__CLASS__);
     $cache->setLifetime($lifetime);
     return $cache;
 }
 protected function cache()
 {
     if (!$this->cache) {
         $this->cache = Cache::factory('Milkyway_SS_InfoBoxes_Wunderlist_Provider', 'Output', ['lifetime' => $this->cacheLifetime * 60 * 60]);
     }
     return $this->cache;
 }
    /**
     *gets tracking code based on campaign
     *@return tracking javascript for pardot api
     */
    public static function GetPardotTrackingJs()
    {
        $html = false;
        $campaign = PardotConfig::getCampaignCode();
        if ($campaign) {
            $tracker_cache = SS_Cache::factory('Pardot');
            if (!($tracking_code_template = $tracker_cache->load('pardot_tracking_code_template'))) {
                $api_credentials = PardotConfig::getPardotCredentials();
                $pardot = new Pardot_API();
                if (!$pardot->is_authenticated()) {
                    $pardot->authenticate($api_credentials);
                }
                $account = $pardot->get_account();
                if (isset($account->tracking_code_template)) {
                    $tracking_code_template = $account->tracking_code_template;
                    $tracker_cache->save($tracking_code_template, 'pardot_tracking_code_template');
                }
            }
            $tracking_code_template = str_replace('%%CAMPAIGN_ID%%', $campaign + 1000, $tracking_code_template);
            $campaign = $campaign + 1000;
            $html = <<<HTML
<script> type="text/javascript">
piCId = '{$campaign}';
{$tracking_code_template}
</script>
HTML;
        }
        return $html;
    }
 /**
  * Updates the fields used in the CMS
  * @see DataExtension::updateCMSFields()     
  */
 public function updateCMSFields(FieldList $fields)
 {
     Requirements::CSS('blogcategories/css/cms-blog-categories.css');
     // Try to fetch categories from cache
     $categories = $this->getAllBlogCategories();
     if ($categories->count() >= 1) {
         $cacheKey = md5($categories->sort('LastEdited', 'DESC')->First()->LastEdited);
         $cache = SS_Cache::factory('BlogCategoriesList');
         if (!($categoryList = $cache->load($cacheKey))) {
             $categoryList = "<ul>";
             foreach ($categories->column('Title') as $title) {
                 $categoryList .= "<li>" . Convert::raw2xml($title) . "</li>";
             }
             $categoryList .= "</ul>";
             $cache->save($categoryList, $cacheKey);
         }
     } else {
         $categoryList = "<ul><li>No categories exist. Categories can be added from the BlogTree or the BlogHolder page.</li></ul>";
     }
     //categories tab
     $gridFieldConfig = GridFieldConfig_RelationEditor::create();
     $fields->addFieldToTab('Root.Categories', GridField::create('BlogCategories', 'Blog Categories', $this->owner->BlogCategories(), $gridFieldConfig));
     $fields->addFieldToTab('Root.Categories', ToggleCompositeField::create('ExistingCategories', 'View Existing Categories', array(new LiteralField("CategoryList", $categoryList)))->setHeadingLevel(4));
     // Optionally default category to current holder
     if (Config::inst()->get('BlogCategory', 'limit_to_holder')) {
         $holder = $this->owner->Parent();
         $gridFieldConfig->getComponentByType('GridFieldDetailForm')->setItemEditFormCallback(function ($form, $component) use($holder) {
             $form->Fields()->push(HiddenField::create('ParentID', false, $holder->ID));
         });
     }
 }
 /**
  * @return Zend_Cache_Frontend
  */
 public static function getCache()
 {
     if (!self::$cache) {
         self::$cache = SS_Cache::factory('Socialstream');
     }
     return self::$cache;
 }
 public function LatestTweetsList($limit = '5')
 {
     $conf = SiteConfig::current_site_config();
     if (empty($conf->TwitterName) || empty($conf->TwitterConsumerKey) || empty($conf->TwitterConsumerSecret) || empty($conf->TwitterAccessToken) || empty($conf->TwitterAccessTokenSecret)) {
         return new ArrayList();
     }
     $cache = SS_Cache::factory('LatestTweets_cache');
     if (!($results = unserialize($cache->load(__FUNCTION__)))) {
         $results = new ArrayList();
         require_once dirname(__FILE__) . '/tmhOAuth/tmhOAuth.php';
         require_once dirname(__FILE__) . '/tmhOAuth/tmhUtilities.php';
         $tmhOAuth = new tmhOAuth(array('consumer_key' => $conf->TwitterConsumerKey, 'consumer_secret' => $conf->TwitterConsumerSecret, 'user_token' => $conf->TwitterAccessToken, 'user_secret' => $conf->TwitterAccessTokenSecret, 'curl_ssl_verifypeer' => false));
         $code = $tmhOAuth->request('GET', $tmhOAuth->url('1.1/statuses/user_timeline'), array('screen_name' => $conf->TwitterName, 'count' => $limit));
         $tweets = $tmhOAuth->response['response'];
         $json = new JSONDataFormatter();
         if (($arr = $json->convertStringToArray($tweets)) && is_array($arr) && isset($arr[0]['text'])) {
             foreach ($arr as $tweet) {
                 try {
                     $here = new DateTime(SS_Datetime::now()->getValue());
                     $there = new DateTime($tweet['created_at']);
                     $there->setTimezone($here->getTimezone());
                     $date = $there->Format('Y-m-d H:i:s');
                 } catch (Exception $e) {
                     $date = 0;
                 }
                 $results->push(new ArrayData(array('Text' => nl2br(tmhUtilities::entify_with_options($tweet, array('target' => '_blank'))), 'Date' => SS_Datetime::create_field('SS_Datetime', $date))));
             }
         }
         $cache->save(serialize($results), __FUNCTION__);
     }
     return $results;
 }
 public function getEventsAction(SS_HTTPRequest $request)
 {
     // Search date
     $date = DBField::create_field("SS_Datetime", $request->param("SearchDate"));
     if (!$date->getValue()) {
         $date = SS_Datetime::now();
     }
     // Get event data
     $cache = SS_Cache::factory(self::EVENTS_CACHE_NAME);
     $cacheKey = $date->Format('Y_m_d');
     if ($result = $cache->load($cacheKey)) {
         $data = unserialize($result);
     } else {
         $data = EventsDataUtil::get_events_data_for_day($date);
         $cache->save(serialize($data), $cacheKey);
     }
     // Get init data
     if ($request->param("GetAppConfig")) {
         $cache = SS_Cache::factory(self::CONFIG_CACHE_NAME);
         $cacheKey = 'APP_CONFIG';
         if ($result = $cache->load($cacheKey)) {
             $configData = unserialize($result);
         } else {
             $configData = AppConfigDataUtil::get_config_data();
             $cache->save(serialize($configData), $cacheKey);
         }
         $data['appConfig'] = $configData;
     }
     return $this->sendResponse($data);
 }
 /**
  * Get posts for a given blog
  *
  * @param integer $limit   number of results to return, max DEFAULT_LIMIT
  * @param integer $offset  number of beginning position for retrieval 
  * @param string  $type    the type of post to retrieve, or blank for all
  * @param array   $options associative array of API options
  *
  * @return \StdClass containing json decoded API results
  */
 public function TumblrPostsList($limit = self::DEFAULT_LIMIT, $offset = 0, $type = "", $options = array())
 {
     $config = SiteConfig::current_site_config();
     if (!$this->checkConfig($config)) {
         return new ArrayList();
     } else {
         $cache_key = __FUNCTION__ . '_' . md5($limit . $offset . $type . implode($options));
         $cache = SS_Cache::factory('tumblr_api_cache');
         if (!($results = unserialize($cache->load($cache_key)))) {
             $results = new ArrayList();
             if (!empty($type) && defined('self::POST_TYPE_' . strtoupper($type))) {
                 $options[self::OPTION_TYPE] = $type;
             }
             if (is_numeric($limit) && $limit > 0 && $limit <= self::DEFAULT_LIMIT) {
                 $options[self::OPTION_LIMIT] = $limit;
             }
             if (is_numeric($offset) && $offset > 0) {
                 $options[self::OPTION_OFFSET] = $offset;
             }
             $client = new Tumblr\API\Client($config->TumblrConsumerKey, $config->TumblrConsumerSecret);
             try {
                 $response = $client->getBlogPosts($config->TumblrBlogName, $options);
                 foreach ($response->posts as $post) {
                     $results->push(self::recursive_conversion_iterator($post));
                 }
             } catch (RequestException $e) {
                 // *** maybe we should do something?
             }
             $cache->save(serialize($results), $cache_key);
         }
     }
     return $results;
 }
 /**
  * @return Zend_Cache_Frontend
  */
 public static function get_cache()
 {
     if (!self::$cache) {
         self::$cache = SS_Cache::factory('DynamicTranslations', 'Output', array('automatic_serialization' => true));
     }
     return self::$cache;
 }
 /**
  * Constructs a new template manifest. The manifest is not actually built
  * or loaded from cache until needed.
  *
  * @param bool $includeTests Include tests in the manifest.
  * @param bool $forceRegen Force the manifest to be regenerated.
  */
 public function __construct($forceRegen = false)
 {
     $this->cacheKey = 'manifest';
     $this->forceRegen = $forceRegen;
     $this->registeredEntities = new ArrayList();
     $this->cache = SS_Cache::factory('DocumentationManifest', 'Core', array('automatic_serialization' => true, 'lifetime' => null));
     $this->setupEntities();
 }
 /**
  * @param string $fragment the fragment to render the button in
  * @param string $title the text to display on the button
  * @param \FieldList|Callable|array $fields the fields to display in inline form
  */
 public function __construct($fragment = 'buttons-before-left', $title = '', $fields = null)
 {
     parent::__construct();
     $this->fragment = $fragment;
     $this->title = $title ?: _t('GridFieldExtensions.ADD', 'Add');
     $this->fields = $fields;
     $this->cache = \SS_Cache::factory($this->getCacheKey(['holder' => __CLASS__]), 'Output', ['lifetime' => 6 * 60 * 60]);
 }
 /**
  * Constructs a new template manifest. The manifest is not actually built
  * or loaded from cache until needed.
  *
  * @param string $base The base path.
  * @param bool $includeTests Include tests in the manifest.
  * @param bool $forceRegen Force the manifest to be regenerated.
  */
 public function __construct($base, $includeTests = false, $forceRegen = false)
 {
     $this->base = $base;
     $this->tests = $includeTests;
     $this->cacheKey = $this->tests ? 'manifest_tests' : 'manifest';
     $this->forceRegen = $forceRegen;
     $this->cache = SS_Cache::factory('SS_TemplateManifest', 'Core', array('automatic_serialization' => true, 'lifetime' => null));
 }
Example #26
0
 public function testCacheDefault()
 {
     SS_Cache::set_cache_lifetime('default', 1200);
     $default = SS_Cache::get_cache_lifetime('default');
     $this->assertEquals(1200, $default['lifetime']);
     $cache = SS_Cache::factory('somethingnew');
     $this->assertEquals(1200, $cache->getOption('lifetime'));
 }
 /**
  * @return Zend_XmlRpc_Client
  */
 public function getClient()
 {
     if (!$this->client) {
         $client = new Client($this->getApiUrl());
         $client->setSkipSystemLookup(true);
         $this->client = SS_Cache::factory('wordpress_posts', 'Class', array('cached_entity' => $client, 'lifetime' => $this->getCacheLifetime()));
     }
     return $this->client;
 }
 /**
  * Gets the cache to use
  * 
  * @return Zend_Cache_Frontend
  */
 protected function getCache()
 {
     $cache = \SS_Cache::factory('VersionFeed_Controller');
     $cache->setOption('automatic_serialization', true);
     // Map 0 to null for unlimited lifetime
     $lifetime = \Config::inst()->get(get_class($this), 'cache_lifetime') ?: null;
     $cache->setLifetime($lifetime);
     return $cache;
 }
 public function getProductJSON()
 {
     $cache = SS_Cache::factory('Catalog_Product');
     // Try to get JSON from the cache.
     if (!($JSON = $cache->load($this->ID))) {
         $JSON = self::updateProductCache();
     }
     return $JSON;
 }
 public function testRead()
 {
     $id = "somekey";
     $value = "Foo";
     $cache = SS_Cache::factory(self::$cache_name);
     /** @var ICacheFrontend$cache */
     $cache->save($value, $id);
     $this->assertEquals($value, $cache->load($id));
 }