set_cache_location() public method

Set the file system location where the cached files should be stored
public set_cache_location ( string $location = './cache' )
$location string The file system location.
Esempio n. 1
0
 /**
  * Display a wildcard in the back end
  *
  * @return string
  */
 public function generate()
 {
     if (TL_MODE == 'BE') {
         /** @var \BackendTemplate|object $objTemplate */
         $objTemplate = new \BackendTemplate('be_wildcard');
         $objTemplate->wildcard = '### ' . utf8_strtoupper($GLOBALS['TL_LANG']['FMD']['rss_reader'][0]) . ' ###';
         $objTemplate->title = $this->headline;
         $objTemplate->id = $this->id;
         $objTemplate->link = $this->name;
         $objTemplate->href = '' . $GLOBALS['TL_CONFIG']['backendPath'] . '/main.php?do=themes&table=tl_module&act=edit&id=' . $this->id;
         return $objTemplate->parse();
     }
     $this->objFeed = new \SimplePie();
     $arrUrls = trimsplit('[\\n\\t ]', trim($this->rss_feed));
     if (count($arrUrls) > 1) {
         $this->objFeed->set_feed_url($arrUrls);
     } else {
         $this->objFeed->set_feed_url($arrUrls[0]);
     }
     $this->objFeed->set_output_encoding(\Config::get('characterSet'));
     $this->objFeed->set_cache_location(TL_ROOT . '/system/tmp');
     $this->objFeed->enable_cache(false);
     if ($this->rss_cache > 0) {
         $this->objFeed->enable_cache(true);
         $this->objFeed->set_cache_duration($this->rss_cache);
     }
     if (!$this->objFeed->init()) {
         $this->log('Error importing RSS feed "' . $this->rss_feed . '"', __METHOD__, TL_ERROR);
         return '';
     }
     $this->objFeed->handle_content_type();
     return parent::generate();
 }
Esempio n. 2
0
 public function html()
 {
     // Get settings
     $settings = $this->config;
     // Define Simplepie
     $feed = new \SimplePie();
     $feed->set_feed_url($settings['feed']);
     $feed->enable_cache($settings['enable_cache']);
     $feed->set_cache_location(cache_path());
     $feed->set_cache_duration(60 * 60 * 12);
     $feed->set_output_encoding($settings['charset']);
     $feed->init();
     $title = $settings['title'];
     $data = [];
     foreach ($feed->get_items($settings['offset'], $settings['limit']) as $key => $item) {
         $data[$key]['title'] = $item->get_title();
         $data[$key]['permalink'] = $item->get_permalink();
         $data[$key]['date'] = $item->get_date();
         $data[$key]['updated_date'] = $item->get_updated_date();
         $data[$key]['author'] = $item->get_author();
         $data[$key]['category'] = $item->get_category();
         $data[$key]['description'] = $item->get_description();
         $data[$key]['content'] = $item->get_content();
     }
     return $this->view('rssfeed', compact('title', 'data'));
 }
Esempio n. 3
0
function flickr_photos($feed_url, $max_items = 10)
{
    //$items = combine_feeds( array($feed_url), $max_items, '~', false);
    $feed = new SimplePie();
    $feed->set_feed_url($feed_url);
    $feed->set_cache_location(ABSPATH . '/cache');
    $feed->set_output_encoding('ISO-8859-1');
    $feed->init();
    $html = '';
    if ($feed->data) {
        foreach ($feed->get_items(0, $max_items) as $item) {
            $image = $item->get_description();
            $image = substr($image, strpos($image, 'src=') + 4);
            // '<img') + 10);
            $image = trim(substr($image, 0, strpos($image, '.jpg') + 4));
            // , "\" width")));
            $healthy = array("%3A", "%2F", '"', 'm.jpg');
            $yummy = array(":", "/", '', 's.jpg');
            $image = str_replace($healthy, $yummy, $image);
            //$image = str_replace('m.jpg', 's.jpg', $image);
            $html .= '<a href="' . $item->get_permalink() . '">';
            $html .= '<img src="' . $image . '" alt="[flickr photo: ' . $item->get_title() . ']" title="' . $item->get_title() . '" />';
            $html .= "</a>\n";
        }
    }
    return $html;
}
Esempio n. 4
0
 public function respond()
 {
     $url = trim($this->matches[1]);
     $index = 0;
     if (isset($this->matches[2])) {
         $index = intval(trim($this->matches[2]));
         $index = $index - 1;
         $index = max(0, $index);
     }
     $error_level = error_reporting();
     error_reporting($error_level ^ E_USER_NOTICE);
     $feed = new \SimplePie();
     if ($this->cacheEnabled()) {
         $feed->set_cache_location($this->config['cache_directory']);
         $feed->set_cache_duration(600);
     }
     $feed->set_feed_url($url);
     $feed->init();
     $feed->handle_content_type();
     if ($index > $feed->get_item_quantity() - 1) {
         $index = $feed->get_item_quantity() - 1;
     }
     $item = $feed->get_item($index);
     $result = null;
     if ($item) {
         $title = html_entity_decode($item->get_title());
         $link = $item->get_permalink();
         $date = $item->get_date();
         $i = $index + 1;
         $result = "[{$i}] {$date} - {$title} - {$link}";
     }
     error_reporting($error_level);
     return $result;
 }
Esempio n. 5
0
 public function addSystemMessages()
 {
     if ($GLOBALS['TL_CONFIG']['be_rss_src'] == '') {
         return '';
     }
     $feed = new \SimplePie();
     $feed->set_feed_url(html_entity_decode($GLOBALS['TL_CONFIG']['be_rss_src']));
     $feed->set_output_encoding(\Config::get('characterSet'));
     $feed->set_cache_location(TL_ROOT . '/system/tmp');
     $feed->enable_cache(true);
     if (!$feed->init()) {
         $this->log('Error importing RSS feed "' . $this->rss_feed . '"', __METHOD__, TL_ERROR);
         return '';
     }
     $items = $feed->get_items(0, $GLOBALS['TL_CONFIG']['be_rss_max'] ? $GLOBALS['TL_CONFIG']['be_rss_max'] : 3);
     $output = '';
     if ($items) {
         $user = \BackendUser::getInstance();
         foreach ($items as $item) {
             $template = new \BackendTemplate('be_rss_item');
             $template->title = $item->get_title();
             $template->link = $item->get_link();
             $template->content = $item->get_content();
             $template->date = $item->get_date($GLOBALS['TL_CONFIG']['datimFormat']);
             $template->class = $item->get_date('U') > $user->lastLogin ? 'new' : 'message';
             $output .= $template->parse();
         }
     }
     $template = new \BackendTemplate('be_rss');
     $template->headline = $GLOBALS['TL_CONFIG']['be_rss_headline'];
     $template->items = $output;
     return $template->parse();
 }
 /**
  * Loads a newsfeed object.
  * @param string $feed
  * @return SimplePie $feed
  */
 public function load($feedurl)
 {
     $feed = new SimplePie();
     $feed->set_feed_url($feedurl);
     $feed->set_cache_location(DIR_FILES_CACHE);
     return $feed;
 }
Esempio n. 7
0
 /**
  * Fetches and parses an RSS or Atom feed, and returns its items.
  *
  * Each element in the returned array will have the following keys:
  *
  * - **authors** – An array of the item’s authors, where each sub-element has the following keys:
  *     - **name** – The author’s name
  *     - **url** – The author’s URL
  *     - **email** – The author’s email
  * - **categories** – An array of the item’s categories, where each sub-element has the following keys:
  *     - **term** – The category’s term
  *     - **scheme** – The category’s scheme
  *     - **label** – The category’s label
  * - **content** – The item’s main content.
  * - **contributors** – An array of the item’s contributors, where each sub-element has the following keys:
  *     - **name** – The contributor’s name
  *     - **url** – The contributor’s URL
  *     - **email** – The contributor’s email
  * - **date** – A {@link DateTime} object representing the item’s date.
  * - **dateUpdated** – A {@link DateTime} object representing the item’s last updated date.
  * - **permalink** – The item’s URL.
  * - **summary** – The item’s summary content.
  * - **title** – The item’s title.
  *
  * @param string $url           The feed’s URL.
  * @param int    $limit         The maximum number of items to return. Default is 0 (no limit).
  * @param int    $offset        The number of items to skip. Defaults to 0.
  * @param string $cacheDuration Any valid [PHP time format](http://www.php.net/manual/en/datetime.formats.time.php).
  *
  * @return array|string The list of feed items.
  */
 public function getFeedItems($url, $limit = 0, $offset = 0, $cacheDuration = null)
 {
     $items = array();
     if (!extension_loaded('dom')) {
         Craft::log('Craft needs the PHP DOM extension (http://www.php.net/manual/en/book.dom.php) enabled to parse feeds.', LogLevel::Warning);
         return $items;
     }
     if (!$cacheDuration) {
         $cacheDuration = craft()->config->getCacheDuration();
     } else {
         $cacheDuration = DateTimeHelper::timeFormatToSeconds($cacheDuration);
     }
     $feed = new \SimplePie();
     $feed->set_feed_url($url);
     $feed->set_cache_location(craft()->path->getCachePath());
     $feed->set_cache_duration($cacheDuration);
     $feed->init();
     // Something went wrong.
     if ($feed->error()) {
         Craft:
         log('There was a problem parsing the feed: ' . $feed->error(), LogLevel::Warning);
         return array();
     }
     foreach ($feed->get_items($offset, $limit) as $item) {
         $date = $item->get_date('U');
         $dateUpdated = $item->get_updated_date('U');
         $items[] = array('authors' => $this->_getItemAuthors($item->get_authors()), 'categories' => $this->_getItemCategories($item->get_categories()), 'content' => $item->get_content(true), 'contributors' => $this->_getItemAuthors($item->get_contributors()), 'date' => $date ? new DateTime('@' . $date) : null, 'dateUpdated' => $dateUpdated ? new DateTime('@' . $dateUpdated) : null, 'permalink' => $item->get_permalink(), 'summary' => $item->get_description(true), 'title' => $item->get_title(), 'enclosures' => $this->_getEnclosures($item->get_enclosures()));
     }
     return $items;
 }
Esempio n. 8
0
 public function __construct($url)
 {
     $simplePie = new \SimplePie();
     $simplePie->set_cache_location(getcwd() . '/cache');
     $simplePie->set_feed_url($url);
     $simplePie->init();
     $simplePie->handle_content_type();
     $this->rawData = $simplePie;
 }
Esempio n. 9
0
 public function __construct($url)
 {
     $simplePie = new \SimplePie();
     $simplePie->set_cache_location($_SERVER['DOCUMENT_ROOT'] . '/zowcast/rest/cache');
     $simplePie->set_feed_url($url);
     $simplePie->init();
     $simplePie->handle_content_type();
     $this->rawData = $simplePie;
 }
Esempio n. 10
0
 public function __construct(array $feedUrls)
 {
     require_once __DIR__ . '/../autoloader.php';
     $feed = new \SimplePie();
     $feed->set_cache_location(__DIR__ . '/cache');
     $feed->set_feed_url($feedUrls);
     $feed->init();
     $feed->handle_content_type();
     $this->feed = $feed;
 }
Esempio n. 11
0
 function fetchRss($url)
 {
     $feed = new SimplePie();
     $feed->set_feed_url($url);
     $feed->set_output_encoding("UTF-8");
     $feed->enable_order_by_date(false);
     $feed->set_cache_location(Configure::read('Rss.cache_path'));
     $feed->init();
     return $feed->get_items();
 }
 private function loadFromWebService()
 {
     $feed = new \SimplePie();
     $feed->set_feed_url($this->endPoint);
     $feed->set_cache_location(THELIA_ROOT . 'cache/feeds');
     $feed->init();
     $feed->handle_content_type();
     $feed->set_timeout(10);
     $this->data = $feed->get_items();
 }
Esempio n. 13
0
 public function createSimplePieObject($fileName)
 {
     $filePath = self::calcFixtureFilePath($fileName);
     $feed = new SimplePie();
     $feed->set_file(new SimplePie_File($filePath));
     $feed->set_cache_location(sfConfig::get('sf_cache_dir'));
     if (!@$feed->init()) {
         return false;
     }
     return $feed;
 }
 protected function fetch_rss()
 {
     include_once ABSPATH . WPINC . '/class-simplepie.php';
     $feed = new SimplePie();
     $feed->set_feed_url($this->feed_url);
     $feed->enable_cache(true);
     $feed->set_cache_location($this->cache_directory);
     $feed->set_cache_duration($this->cache_duration);
     $feed->init();
     $this->feed = $feed;
     return $this;
 }
Esempio n. 15
0
 /**
  * fetchFeed method
  *
  * @return void
  */
 public function fetchFeed($url = false)
 {
     if (!is_string($url)) {
         return false;
     }
     $feed = new SimplePie();
     $feed->set_cache_location(CACHE);
     $feed->set_feed_url($url);
     $feed->init();
     $feed->handle_content_type();
     return $feed;
 }
Esempio n. 16
0
 /**
  * Runs RSS combine
  */
 public function run()
 {
     $feed = new \SimplePie();
     $feed->set_feed_url($this->feeds);
     $feed->set_cache_location(\Yii::getAlias('@runtime') . '/cache/feed');
     $feed->set_item_limit($this->itemLimit);
     $success = $feed->init();
     if ($success) {
         $feed->handle_content_type();
         $items = $feed->get_items($this->from, $this->to);
         return $this->render('rss', ['items' => $items, 'options' => $this->options]);
     }
 }
Esempio n. 17
0
 public function displayslideshow()
 {
     $this->load->library('simplepie');
     $simplepie = new SimplePie();
     $simplepie->set_cache_location(APPPATH . '/cache');
     $simplepie->set_feed_url('http://feeds.feedburner.com/the99percent/DPIn');
     $simplepie->init();
     //echo $simplepie->get_title();
     $simplepie->handle_content_type();
     $data['feed'] = $simplepie;
     //$this->load->view("/feed/listing.php", $data);
     $this->load->view("/feed/slideshow.php", $data);
 }
 public static function create($cacheEnabled, $cacheDir, $cacheDuration)
 {
     $feed = new \SimplePie();
     $feed->enable_cache($cacheEnabled);
     $feed->set_cache_duration($cacheDuration);
     $feed->set_cache_location($cacheDir);
     // Create dir if not exists
     if ($cacheEnabled && !is_dir($cacheDir)) {
         $fileSystem = new Filesystem();
         $fileSystem->mkdir($cacheDir);
     }
     return $feed;
 }
Esempio n. 19
0
 private function setFeeds()
 {
     $feeds = $this->_db->queryAll('SELECT id, url FROM feeds WHERE user = ?', $this->getIdUser());
     for ($i = 0, $e = sizeof($feeds); $i < $e; ++$i) {
         $feed = $feeds[$i];
         $pie = new SimplePie();
         $pie->set_feed_url($feed['url']);
         $pie->set_cache_location(rtrim(DIR_TPL_COMPILE, '/'));
         $pie->init();
         $pie->handle_content_type();
         $this->feeds[] = array('feed' => $pie, 'id' => $feed['id']);
     }
 }
Esempio n. 20
0
 /**
  * Render a newsletter
  * @return string the newsletter.
  */
 public function make()
 {
     $module = Yii::app()->controller->module;
     require_once 'protected/vendors/simplepie/autoloader.php';
     require_once 'protected/vendors/simplepie/idn/idna_convert.class.php';
     $timeLimit = KeyValue::model()->findByPk('newsletter_execution_time')->value;
     $simplePie = new SimplePie();
     $simplePie->set_cache_location('./protected/cache/simplepie');
     $simplePie->set_cache_duration(1);
     // 1 seconde
     // This makes sure that the content is sent to the browser as
     // text/html and the UTF-8 character set (since we didn't change it).
     $simplePie->handle_content_type();
     if ($module->multiLang) {
         if (isset($this->language)) {
             $feeds = $module->feeds[$this->language];
             $renderLanguage = $this->language;
         } else {
             $feeds = $module->feeds[Yii::app()->language];
             $renderLanguage = Yii::app()->language;
         }
     } else {
         $feeds = $module->feeds;
         $renderLanguage = Yii::app()->language;
     }
     $atLeastOne = false;
     for ($i = 0; $i < count($feeds); $i++) {
         if (isset($feeds[$i]['expression'])) {
             $feeds[$i]['content'] = $this->evaluateExpression($feeds[$i]['expression'], array('timeLimit' => $timeLimit, 'language' => $renderLanguage));
             if ($feeds[$i]['content'] != '') {
                 $atLeastOne = true;
             }
         } else {
             $simplePie->set_feed_url($feeds[$i]['url']);
             $simplePie->init();
             $feeds[$i]['link'] = $simplePie->get_permalink();
             $feeds[$i]['items'] = array();
             foreach ($simplePie->get_items(0, $feeds[$i]['limit']) as $item) {
                 if ($item->get_date('U') > strtotime($timeLimit)) {
                     $feeds[$i]['items'][] = $item;
                     $atLeastOne = true;
                 }
             }
         }
     }
     if ($atLeastOne) {
         return Yii::app()->controller->renderPartial('newsletter.components.views.newsletter', array('feeds' => $feeds, 'language' => $renderLanguage), true);
     } else {
         return false;
     }
 }
Esempio n. 21
0
 public function loadPath($str, $duration)
 {
     // declare the namespaces
     require_once 'simplepie-master/autoloader.php';
     $cache = dirname(__FILE__);
     $cache .= $this->cache;
     $feed = new SimplePie();
     $feed->set_feed_url($str);
     $feed->set_cache_location($cache);
     $feed->set_cache_duration($duration);
     $feed->init();
     $feed->handle_content_type();
     return $feed;
 }
Esempio n. 22
0
 static function read($feed)
 {
     $parser = new SimplePie();
     $parser->set_feed_url($feed);
     $parser->set_cache_location(storage_path() . '/cache');
     $parser->set_cache_duration(100);
     $success = $parser->init();
     $parser->handle_content_type();
     if ($parser->error() || !$success) {
         return null;
     } else {
         return $parser->get_items();
     }
 }
Esempio n. 23
0
 /**
  * Includes the SimplePie RSS file and sets the cache
  *
  * @param string $feed
  * @param bool $cache
  * @param int $cache_duration
  *
  * @return object|false $sp
  */
 public function newSimplePie($feed = '', $cache = RSS_CACHE, $cache_duration = RSS_CACHE_DURATION)
 {
     include_once EXTENSIONS . "SimplePie/simplepie.inc";
     if ($feed != '') {
         $sp = new \SimplePie();
         $sp->set_feed_url($feed);
         $sp->set_cache_location(CACHE . "rss_cache/");
         $sp->set_cache_duration($cache_duration);
         $sp->enable_cache($cache === 'true');
         $sp->handle_content_type();
         return $sp;
     }
     return FALSE;
 }
Esempio n. 24
0
 public function createSimplePieObject($rssUrl)
 {
     $feed = new SimplePie();
     if (sfConfig::get('op_http_proxy')) {
         $proxy = sfConfig::get('op_http_proxy');
         $feed->set_proxy($proxy);
     }
     $feed->set_feed_url($rssUrl);
     $feed->set_cache_location(sfConfig::get('sf_cache_dir'));
     if (!@$feed->init()) {
         return false;
     }
     return $feed;
 }
Esempio n. 25
0
 /**
  * Make sure that the model is configured with a valid URL.
  *
  * @return mixed model data
  */
 function build()
 {
     if ($url = $this->config('url')) {
         $simplepie = new SimplePie();
         $simplepie->set_feed_url($this->config('url'));
         $simplepie->set_cache_location($this->config('cache_directory'));
         $simplepie->set_cache_duration($this->config('cache_duration'));
         $simplepie->init();
         $simplepie->handle_content_type();
         // is this needed?
         return $simplepie;
     } else {
         trigger_error('The ReasonSimplepieFeedModel must be configured with a feed url.', FATAL);
     }
 }
Esempio n. 26
0
function getFeed($url, $length)
{
    global $config;
    $value = "";
    $value .= "<ul>";
    $feed = new SimplePie();
    $feed->set_cache_location($config["SimplePie cache"]);
    $feed->set_feed_url($url);
    $feed->init();
    $feed->handle_content_type();
    foreach ($feed->get_items(0, 5) as $item) {
        $value .= "<li>" . $item->get_date() . ":<br> <a href='" . $item->get_link() . "'>" . $item->get_title() . "</a></li>";
    }
    $value .= "</ul>";
    return $value;
}
Esempio n. 27
0
function get_feed_items()
{
    // go through all the feed urls
    $items = array();
    $feeds = ORM::for_table('feeds')->find_many();
    foreach ($feeds as $feed_loc) {
        $feed = new SimplePie();
        $feed->set_feed_url($feed_loc->location);
        $feed->set_cache_location("mysql://" . DB_USER . ":" . DB_PASS . "@" . DB_HOST . ":3306/" . DB_NAME);
        $feed->set_item_class('MyItemClass');
        $feed->init();
        $feed->handle_content_type();
        $items = array_merge($items, $feed->get_items());
    }
    return $items;
}
Esempio n. 28
0
 /**
  * (AJAX Action) 
  * Action to get feed and render it for an AJAX call.
  * 
  * @param string  $url   - url of the feed to process
  * @param integer $limit - how many items to grab from the feed
  * 
  * @return null; 
  */
 public function actionGetFeed($url, $limit, $layout = 'pc')
 {
     $feed = new SimplePie();
     // Set which feed to process.
     $feed->set_feed_url($url);
     //set the cache directory
     $feed->set_cache_location(Yii::getPathOfAlias('ext.yii-feed-widget') . DIRECTORY_SEPARATOR . 'cache');
     //$feed->set_item_limit(3);
     // Run SimplePie.
     $feed->init();
     // This makes sure that the content is sent to the browser as
     // text/html and the UTF-8 character set (since we didn't change it).
     $feed->handle_content_type();
     $items = $feed->get_items(0, (int) $limit);
     $this->renderPartial('ext.yii-feed-widget.views._YiiFeeds', array('items' => $items, 'layout' => $layout));
 }
Esempio n. 29
0
 public function buildArray()
 {
     $cachedir = THELIA_ROOT . 'cache/feeds';
     if (!is_dir($cachedir)) {
         if (!mkdir($cachedir)) {
             throw new \Exception(sprintf("Failed to create cache directory '%s'", $cachedir));
         }
     }
     $feed = new \SimplePie();
     $feed->set_feed_url($this->getUrl());
     $feed->set_cache_location(THELIA_ROOT . 'cache/feeds');
     $feed->init();
     $feed->handle_content_type();
     $feed->set_timeout($this->getTimeout());
     $items = $feed->get_items();
     return $items;
 }
Esempio n. 30
0
 /**
  * Implementation of IParser::GetAndParse
  * @param string[][] $parameters
  * Required Parameter Values =
  *  'feedUrl' = The url to the RSS feed
  */
 public function GetAndParse($parameters)
 {
     //Extract the required variables
     $feedUrl = $parameters["feedUrl"];
     if (!isset($feedUrl) || $feedUrl == "") {
         return null;
     }
     //Create the source that will be used by all the content items
     //Passing in the feed uri which can be used to uniquly
     //identify the source of the content
     $source = new \Swiftriver\Core\ObjectModel\Source($feedUrl);
     //Include the Simple Pie Framework to get and parse feeds
     $config = \Swiftriver\Core\Setup::Configuration();
     include_once $config->ModulesDirectory . "/SimplePie/simplepie.inc";
     //Construct a new SimplePie Parsaer
     $feed = new \SimplePie();
     //Set the caching directory
     $feed->set_cache_location($config->CachingDirectory);
     //Pass the feed URL to the SImplePie object
     $feed->set_feed_url($feedUrl);
     //Run the SimplePie
     $feed->init();
     //Create the Content array
     $contentItems = array();
     //Loop throught the Feed Items
     foreach ($feed->get_items() as $feedItem) {
         //Extract all the relevant feedItem info
         $id = \Swiftriver\Core\ObjectModel\Content::GenerateUniqueId();
         $title = $feedItem->get_title();
         $description = $feedItem->get_description();
         $contentLink = $feedItem->get_permalink();
         //Create a new Content item
         $item = new \Swiftriver\Core\ObjectModel\Content();
         //Fill the COntenty Item
         $item->SetId($id);
         $item->SetTitle($title);
         $item->SetLink($contentLink);
         $item->SetText(array($description));
         $item->SetSource($source);
         //Add the item to the Content array
         $contentItems[] = $item;
     }
     //return the content array
     return $contentItems;
 }