Ejemplo n.º 1
0
 /**
  * loads content for given source
  * I supress all Warnings of SimplePie for ensuring
  * working plugin in PHP Strict mode
  *
  * @return void
  * @param mixed $params the params of this source
  */
 public function load($params)
 {
     // initialize simplepie feed loader
     $this->feed = @new \SimplePie();
     @$this->feed->set_cache_location(\F3::get('cache'));
     @$this->feed->set_cache_duration(1800);
     @$this->feed->set_feed_url(htmlspecialchars_decode($params['url']));
     @$this->feed->set_autodiscovery_level(SIMPLEPIE_LOCATOR_AUTODISCOVERY | SIMPLEPIE_LOCATOR_LOCAL_EXTENSION | SIMPLEPIE_LOCATOR_LOCAL_BODY);
     $this->feed->set_useragent(\helpers\WebClient::getUserAgent(array('SimplePie/' . SIMPLEPIE_VERSION)));
     // fetch items
     @$this->feed->init();
     // on error retry with force_feed
     if (@$this->feed->error()) {
         @$this->feed->set_autodiscovery_level(SIMPLEPIE_LOCATOR_NONE);
         @$this->feed->force_feed(true);
         @$this->feed->init();
     }
     // check for error
     if (@$this->feed->error()) {
         throw new \exception($this->feed->error());
     } else {
         // save fetched items
         $this->items = @$this->feed->get_items();
     }
     // return html url
     $this->htmlUrl = @$this->feed->get_link();
 }
Ejemplo n.º 2
0
 /**
  * load image
  *
  * @return bool
  * @param string $url source url
  * @param string $extension file extension of output file
  * @param int $width
  * @param int $height
  */
 public function loadImage($url, $extension = 'png', $width = false, $height = false)
 {
     // load image
     try {
         $data = \helpers\WebClient::request($url);
     } catch (\exception $e) {
         \F3::get('logger')->log("failed to retrieve image {$url}," . $e->getMessage(), \ERROR);
         return false;
     }
     // get image type
     $tmp = \F3::get('cache') . '/' . md5($url);
     file_put_contents($tmp, $data);
     $imgInfo = @getimagesize($tmp);
     if (strtolower($imgInfo['mime']) == 'image/vnd.microsoft.icon') {
         $type = 'ico';
     } elseif (strtolower($imgInfo['mime']) == 'image/png') {
         $type = 'png';
     } elseif (strtolower($imgInfo['mime']) == 'image/jpeg') {
         $type = 'jpg';
     } elseif (strtolower($imgInfo['mime']) == 'image/gif') {
         $type = 'gif';
     } elseif (strtolower($imgInfo['mime']) == 'image/x-ms-bmp') {
         $type = 'bmp';
     } else {
         @unlink($tmp);
         return false;
     }
     // convert ico to png
     if ($type == 'ico') {
         $ico = new \floIcon();
         @$ico->readICO($tmp);
         if (count($ico->images) == 0) {
             @unlink($tmp);
             return false;
         }
         ob_start();
         @imagepng($ico->images[count($ico->images) - 1]->getImageResource());
         $data = ob_get_contents();
         ob_end_clean();
     }
     // parse image for saving it later
     @unlink($tmp);
     try {
         $wideImage = \WideImage::load($data);
     } catch (\Exception $e) {
         return false;
     }
     // resize
     if ($width !== false && $height !== false) {
         if ($height !== null && $wideImage->getHeight() > $height || $width !== null && $wideImage->getWidth() > $width) {
             $wideImage = $wideImage->resize($width, $height);
         }
     }
     // return image as jpg or png
     if ($extension == 'jpg') {
         $data = $wideImage->asString('jpg', 75);
     } else {
         $data = $wideImage->asString('png', 4, PNG_NO_FILTER);
     }
     return $data;
 }
Ejemplo n.º 3
0
 /**
  * get JSON object
  * @param string $url URL
  * @return object JSON object
  */
 public function getJsonContent($url)
 {
     $content = null;
     try {
         $content = \helpers\WebClient::request($url);
     } catch (\exception $e) {
         throw new \exception('github spout error ' . $e->getMessage());
     }
     $json = @json_decode($content);
     if (empty($json)) {
         throw new \exception('github spout error: empy json');
     }
     return $json;
 }