Ejemplo n.º 1
0
 public function getData()
 {
     $Cache_Lite = new Cache_Lite(parent::getCacheOptions());
     $url = sprintf('https://readitlaterlist.com/v2/get?username=%s&password=%s&apikey=%s&count=%s&format=json', $this->config['username'], $this->config['password'], $this->config['apikey'], $this->config['total']);
     $id = $url;
     if ($data = $Cache_Lite->get($id)) {
         $data = json_decode($data);
     } else {
         $Cache_Lite->get($id);
         PubwichLog::log(2, Pubwich::_('Rebuilding cache for a Readitlater'));
         PubwichLog::log(2, $this->url);
         $data = file_get_contents($url);
         $data = json_decode($data);
         foreach ($data->list as $item) {
             // Default value
             $item->title = parse_url($item->url, PHP_URL_HOST);
             // If check page title
             if (!empty($this->config['getTitle'])) {
                 $file = @fopen($item->url, "r");
                 if ($file) {
                     $text = fread($file, 1024 * 3);
                     if (preg_match('/<title>(.*?)<\\/title>/is', $text, $found)) {
                         $item->title = $found[1];
                     }
                 }
             }
         }
         // Write cache
         $cacheWrite = $Cache_Lite->save(json_encode($data));
     }
     return $data->list;
 }
Ejemplo n.º 2
0
 public static function init()
 {
     if (PUBWICH_LOGTOFILE === true && PUBWICH_LOGLEVEL > 0) {
         $log_dir = dirname(__FILE__) . '/../logs';
         if (!is_dir($log_dir)) {
             mkdir($log_dir);
         }
         $log_file = $log_dir . '/pubwich-' . date('Y-m-d') . '.log';
         self::$file = fopen($log_file, 'a+');
         // what will happen if several sessions are started simultaneously?
         //self::log( 0, '----[ Log for Pubwich session ('.date('Y-m-d h:i:s').') ]-----------------------------', true );
     }
 }
Ejemplo n.º 3
0
 /**
  * [@param Cache_Lite $Cache_Lite]
  * @return void
  */
 public function buildCache($Cache_Lite = null)
 {
     PubwichLog::log(2, sprintf(Pubwich::_('Rebuilding the cache for %s service'), get_class($this)));
     $url = $this->getURL();
     if (!$Cache_Lite) {
         $Cache_Lite = new Cache_Lite($this->cache_options);
         $Cache_Lite->get($this->cache_id);
     }
     $content = FileFetcher::get($url, $this->http_headers);
     if ($content !== false) {
         $cacheWrite = $Cache_Lite->save($content);
         if (PEAR::isError($cacheWrite)) {
             /*var_dump( $cacheWrite->getMessage() );*/
         }
         libxml_use_internal_errors(true);
         $this->data = call_user_func($this->callback_function, $content);
     } else {
         $this->data = false;
     }
 }
Ejemplo n.º 4
0
 /**
  * [@param Cache_Lite $Cache_Lite]
  * @return void
  */
 public function buildCache($Cache_Lite = null)
 {
     PubwichLog::log(2, sprintf(Pubwich::_('Rebuilding the cache for %s service'), get_class($this)));
     $url = $this->getURL();
     if (!$Cache_Lite) {
         $Cache_Lite = new Cache_Lite($this->cache_options);
         $Cache_Lite->get($this->cache_id);
     }
     if (!$this->callback_getdata) {
         $content = FileFetcher::get($url, $this->http_headers);
     } else {
         $content = call_user_func($this->callback_getdata[0], $this->callback_getdata[1]);
     }
     if ($content !== false) {
         $cacheWrite = $Cache_Lite->save($content);
         libxml_use_internal_errors(true);
         $this->data = $content;
         if (is_string($this->data)) {
             $this->data = call_user_func($this->callback_function, $this->data);
         }
     } else {
         $this->data = false;
     }
 }
Ejemplo n.º 5
0
 /**
  * Rebuild the cache for each defined service
  *
  * @return void
  */
 public static function rebuildCache()
 {
     PubwichLog::log(1, Pubwich::_("Building application cache"));
     // First, let’s flush the cache directory
     $files = scandir(CACHE_LOCATION);
     foreach ($files as $file) {
         if (substr($file, 0, 1) != ".") {
             unlink(CACHE_LOCATION . $file);
         }
     }
     // Then, we fetch everything
     foreach (self::$classes as &$classe) {
         $classe->buildCache();
     }
 }
Ejemplo n.º 6
0
 /**
  * @param SimpleXMLElement $album
  * [@param bool $rebuildCache]
  * @return void
  */
 public function fetchPhotoGeoData($photo, $rebuildCache = false)
 {
     $Cache_Lite = new Cache_Lite(parent::getCacheOptions());
     $id = $photo["id"];
     if (!$rebuildCache && ($data = $Cache_Lite->get($id))) {
         $this->photogeodata["{$id}"] = simplexml_load_string($data);
     } else {
         $Cache_Lite->get($id);
         PubwichLog::log(2, Pubwich::_('Rebuilding geo cache for a Flickr Photo'));
         $url = sprintf('http://api.flickr.com/services/rest/?method=flickr.photos.geo.getLocation&api_key=%s&photo_id=%s', $this->apikey, $id);
         $fdata = FileFetcher::get($url);
         $cacheWrite = $Cache_Lite->save($fdata);
         if (PEAR::isError($cacheWrite)) {
             //var_dump( $cacheWrite );
         }
         $pdata = simplexml_load_string($fdata);
         $this->photogeodata["{$id}"] = $pdata;
     }
 }
Ejemplo n.º 7
0
 /**
  * @return void
  */
 public static function rebuildCache()
 {
     PubwichLog::log(1, Pubwich::_("Building application cache"));
     // On vide le contenu du dossier de cache
     $fichiers = scandir(CACHE_LOCATION);
     foreach ($fichiers as $fichier) {
         // on ne supprime pas les fichiers cachés...
         if (substr($fichier, 0, 1) != ".") {
             unlink(CACHE_LOCATION . $fichier);
         }
     }
     // On rebâtit tout!
     foreach (self::$classes as &$classe) {
         $classe->buildCache();
     }
 }
Ejemplo n.º 8
0
 /**
  * @param SimpleXMLElement $album
  * [@param bool $rebuildCache]
  * @return void
  */
 public function fetchAlbum($album, $rebuildCache = false)
 {
     $Cache_Lite = new Cache_Lite(parent::getCacheOptions());
     $id = $this->buildAlbumId($album);
     if (!$rebuildCache && ($data = $Cache_Lite->get($id))) {
         $this->albumdata[$id] = simplexml_load_string($data);
     } else {
         $Cache_Lite->get($id);
         PubwichLog::log(2, Pubwich::_('Rebuilding cache for a Last.fm album'));
         $url = sprintf("http://ws.audioscrobbler.com/2.0/?method=album.getinfo&api_key=%s&artist=%s&album=%s", $this->key, urlencode($album->artist), urlencode($album->name));
         $data = FileFetcher::get($url);
         $cacheWrite = $Cache_Lite->save($data);
         if (PEAR::isError($cacheWrite)) {
             //var_dump( $cacheWrite );
         }
         $this->albumdata[$id] = simplexml_load_string($data);
     }
 }