Esempio n. 1
0
 public function get($options)
 {
     $url = $options['url'];
     $limit = array_key_exists('limit', $options) ? NumberHelper::makeNumeric($options['limit']) : null;
     $offset = array_key_exists('offset', $options) ? NumberHelper::makeNumeric($options['offset']) : 0;
     // Check to see if the response is cached
     $cachedResponse = craft()->fileCache->get($url);
     if ($cachedResponse) {
         return $cachedResponse;
     }
     try {
         $client = new \Guzzle\Http\Client();
         $request = $client->get($url);
         $response = $request->send();
         if (!$response->isSuccessful()) {
             return;
         }
         $items = $response->json();
         // Cache the response
         craft()->fileCache->set($url, $items);
         // Apply the limit and offset
         $items = array_slice($items, $offset, $limit);
         return $items;
     } catch (\Exception $e) {
         return;
     }
 }
Esempio n. 2
0
 /**
  * @param string $url
  * @param int    $limit
  * @param int    $offset
  * @param null   $cacheDuration
  *
  * @return array
  */
 public function getFeedItems($url, $limit = 0, $offset = 0, $cacheDuration = null)
 {
     $limit = NumberHelper::makeNumeric($limit);
     $offset = NumberHelper::makeNumeric($offset);
     $items = craft()->feeds->getFeedItems($url, $limit, $offset, $cacheDuration);
     // Prevent everyone from having to use the |raw filter when outputting the title and content
     $rawProperties = array('title', 'content', 'summary');
     foreach ($items as &$item) {
         foreach ($rawProperties as $prop) {
             $item[$prop] = TemplateHelper::getRaw($item[$prop]);
         }
     }
     return $items;
 }
Esempio n. 3
0
 /**
  * @return array
  */
 public function getFeedItems($url, $limit = 0, $offset = 0)
 {
     $limit = NumberHelper::makeNumeric($limit);
     $offset = NumberHelper::makeNumeric($offset);
     $items = craft()->feeds->getFeedItems($url, $limit, $offset);
     // Prevent everyone from having to use the |raw filter when outputting the title and content
     $rawProperties = array('title', 'content', 'summary');
     $charset = craft()->templates->getTwig()->getCharset();
     foreach ($items as &$item) {
         foreach ($rawProperties as $prop) {
             $item[$prop] = new \Twig_Markup($item[$prop], $charset);
         }
     }
     return $items;
 }