Example #1
0
 /**
  * [categories description]
  * @param  [type] $selected [description]
  * @return [type]           [description]
  */
 public function categories()
 {
     $cache = new Cache();
     $cache->setCacheDirectory($this->cacheDir);
     $data = $cache->getOrCreate('google-feed-taxonomy.txt', array('max-age' => '860400'), function () {
         return file_get_contents("http://www.google.com/basepages/producttype/taxonomy.en-GB.txt");
     });
     return explode("\n", trim($data));
 }
Example #2
0
<?php

include '../autoload.php';
// If using composer
use Gregwar\Cache\Cache;
$cache = new Cache();
$cache->setCacheDirectory('cache');
// This is the default
// If the cache exists, this will return it, else, the closure will be called
// to create this image
$file = $cache->getOrCreateFile('red-square.png', array(), function ($filename) {
    $i = imagecreatetruecolor(100, 100);
    imagefill($i, 0, 0, 0xff0000);
    file_put_contents($filename, 'abc');
    imagepng($i, 'a.png');
    imagepng($i, $filename);
});
echo $file, "\n";
 /**
  * Retrieve Google product categories from internet and cache the result
  * @param string $languageISO639
  * @return array
  */
 public function categories($languageISO639 = 'gb')
 {
     //map two letter language to culture
     $languageMap = array('au' => 'en-AU', 'br' => 'pt-BR', 'cn' => 'zh-CN', 'cz' => 'cs-CZ', 'de' => 'de-DE', 'dk' => 'da-DK', 'es' => 'es-ES', 'fr' => 'fr-FR', 'gb' => 'en-GB', 'it' => 'it-IT', 'jp' => 'ja-JP', 'nl' => 'nl-NL', 'no' => 'no-NO', 'pl' => 'pl-PL', 'ru' => 'ru-RU', 'sw' => 'sv-SE', 'tr' => 'tr-TR', 'us' => 'en-US');
     //set default language to gb for backward compatibility
     $languageCulture = $languageMap['gb'];
     if (array_key_exists($languageISO639, $languageMap)) {
         $languageCulture = $languageMap[$languageISO639];
     }
     var_dump($languageISO639, $languageCulture);
     $cache = new Cache();
     $cache->setCacheDirectory($this->cacheDir);
     $data = $cache->getOrCreate('google-feed-taxonomy.' . $languageISO639 . '.txt', array('max-age' => '86400'), function () use($languageCulture) {
         return file_get_contents("http://www.google.com/basepages/producttype/taxonomy." . $languageCulture . ".txt");
     });
     return explode("\n", trim($data));
 }