get_items() public method

This is better suited for {@link http://php.net/for for()} loops, whereas {@see \get_items()} is better suited for {@link http://php.net/foreach foreach()} loops.
See also: get_item_quantity
public get_items ( integer $start, integer $end ) : SimplePie_Item[] | null
$start integer Index to start at
$end integer Number of items to return. 0 for all items after `$start`
return SimplePie_Item[] | null List of {@see \SimplePie_Item} objects
 public function getItems()
 {
     $retVal = [];
     foreach ($this->simplePie->get_items() as $item) {
         /** @var \SimplePie_Item[] $item */
         $retVal[] = ['uuid' => $item->get_id(), 'author' => $item->get_author() ? $item->get_author()->get_name() : null, 'title' => $item->get_title(), 'content' => $item->get_content(), 'url' => $item->get_link(), 'date' => ($timeStamp = strtotime($item->get_gmdate())) > 0 ? $timeStamp : time()];
     }
     return $retVal;
 }
 /**
  * Return an array of consumed Tweets from the RSS feed
  *
  * @access public
  * @return array
  **/
 public function get_news_feed($add_news_to_db = TRUE)
 {
     // Use SimplePie to get the RSS feed
     $feed = new SimplePie();
     $feed->set_feed_url(array($this->search_query));
     $feed->set_item_limit(50);
     $feed->handle_content_type();
     $feed->enable_cache(false);
     $feed->init();
     // Get the feed and create the SimplePie feed object
     $this->feed = $feed->get_items();
     $post = array();
     // Array to hold all the tweet info for returning as an array
     $retval = array();
     // Set up two counters (1 for use in the return array and 1 for counting the number of inserted posts if applicable)
     $n = 0;
     $i = 0;
     // Array to hold the stored hashtags
     $hashes = explode(',', $this->options["hashtags"]);
     foreach ($feed->get_items() as $item) {
         // Get the Twitter status id from the status href
         $twitter_status_id = explode("/", $item->get_id());
         // Check to see if the username is in the user profile meta data
         $post["user_id"] = (int) $this->options["user"];
         $user_id = $this->map_twitter_to_user($twitter_status_id[3]);
         if (!$user_id == NULL) {
             $post["user_id"] = (int) $user_id;
         }
         // Add individual Tweet data to array
         $post["date"] = date("Y-m-d H:i:", strtotime($item->get_date()));
         $post["link"] = $item->get_id();
         $post["id"] = $twitter_status_id[count($twitter_status_id) - 1];
         $post["description"] = $item->get_description();
         $post["description_filtered"] = $this->strip_hashes($item->get_description(), $hashes);
         $post["twitter_username"] = $twitter_status_id[3];
         $post["twitter_username_link"] = $this->create_twitter_link($twitter_status_id[3]);
         $post["post_type"] = "twitter";
         // Add the new post to the db?
         if ($add_news_to_db) {
             if ($this->add_item_as_post($post)) {
                 $i++;
             }
         }
         // Add the Tweet to the return array
         $retval[$n] = $post;
         $n++;
     }
     // Return correct values depending on the $add_news_to_db boolean
     if ($add_news_to_db) {
         return $i;
     } else {
         return $retval;
     }
 }
示例#3
0
 public function item_content($index = 0)
 {
     $this->fetch_feed();
     if (!$this->feed) {
         return false;
     }
     /** @var SimplePie_Item[] $items */
     $items = $this->feed->get_items($index, 1);
     if (empty($items)) {
         return false;
     }
     return $items[0]->get_content();
 }
示例#4
0
 /**
  * Test that the we have post collections
  */
 public function testListPosts()
 {
     $available = self::getCollectionsFromDocument($this->document);
     $names = array();
     foreach ($available as $name => $collection) {
         if (in_array(AtomPubHelper::AtomEntryMediaType, $collection['accepted'])) {
             $names[] = $name;
         }
     }
     $this->assertNotEmpty($available);
     Gorilla::$runner->reportList(Gorilla_Runner::REPORT_INFO, 'Post collections found:', $names);
     $collection = $available[$names[0]];
     Gorilla::$runner->report(Gorilla_Runner::REPORT_INFO, 'Using ' . $collection['name'] . ' at ' . $collection['href']);
     Gorilla::$runner->report(Gorilla_Runner::REPORT_INFO, 'Checking current');
     $current = Requests::get($collection['href'], array(), array(), $this->requestsOptions());
     $this->assertEquals(200, $current->status_code, 'Could not retrieve current posts: ' . $current->body);
     $feed = new SimplePie();
     $feed->set_raw_data($current->body);
     $feed->set_stupidly_fast();
     $feed->init();
     $this->assertNull($feed->error(), 'Error reading feed of current: ' . $feed->error());
     $current = $feed->get_items();
     $ids = array();
     if (!empty($current)) {
         foreach ($current as &$item) {
             Gorilla::$runner->report(Gorilla_Runner::REPORT_DEBUG, 'Found post: ' . $item->get_title());
             $ids[] = $item->get_id();
         }
     } else {
         Gorilla::$runner->report(Gorilla_Runner::REPORT_INFO, 'No posts found');
     }
 }
 /**
  * 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;
 }
 function rss_to_activity_streams($data)
 {
     //
     $feed = new SimplePie();
     $feed->set_raw_data($data);
     //
     unset($data);
     //
     $feed->set_stupidly_fast(true);
     $feed->init();
     $feed->handle_content_type();
     //
     $id = md5($url);
     $title = 'submit';
     $link = 'http://' . $_SERVER["SERVER_NAME"] . $_SERVER["REQUEST_URI"];
     $activityStream = new ActivityStreamsDoc($id, $title, $link);
     //
     foreach ($feed->get_items() as $item) {
         $author = $item->get_author();
         if (!$author) {
             $author = $feed->get_author();
         }
         //
         $activityStream->entry($item->get_id(), date("r", $item->get_date()), $author ? $author->get_name() : null, $author ? $author->get_link() : null, $item->get_title(), $item->get_permalink(), $item->get_description());
     }
     return $activityStream;
 }
示例#7
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();
 }
示例#8
0
function show_news($newsfeed, $newsitems, $newsprefiximage, $newssuffiximage)
{
    $rss = new SimplePie($newsfeed, dirname(__FILE__) . '/cache');
    $rss->force_feed(true);
    // MAKE IT WORK
    $rss->set_cache_duration(60 * 5);
    $rss->init();
    $rss->handle_content_type();
    // 	if ($rss->error()) {
    // 	   echo htmlentities($rss->error());
    // 	   return;
    //     }
    foreach ($rss->get_items(0, $newsitems) as $item) {
        $title = $item->get_title();
        $url = $item->get_permalink();
        if ($newsprefiximage != '') {
            echo "<img src='{$newsprefiximage}'>";
        }
        echo "<a href={$url}>{$title}</a>";
        if ($newssuffiximage != '') {
            echo "<img src='{$newssuffiximage}'>";
        }
        echo "<br />";
    }
}
示例#9
0
 /**
  * Fetches the latest entry from the source's feed
  **/
 function fetchfeed()
 {
     require_once SIMPLEPIEPATH;
     $feed = $this->select();
     if (preg_match('/twitter\\.com/', $feed[0]->feed_url) == true) {
         $istwitter = 1;
     }
     $feed_path = $feed[0]->feed_url;
     $feed = new SimplePie((string) $feed_path, TEMPLATEPATH . (string) '/app/cache/activity');
     SourceAdmin::clean_dir();
     $feed->handle_content_type();
     if ($feed->data) {
         foreach ($feed->get_items() as $entry) {
             $name = $stream->title;
             $update[]['name'] = (string) $name;
             $update[]['title'] = $entry->get_title();
             $update[]['link'] = $entry->get_permalink();
             $update[]['date'] = strtotime(substr($entry->get_date(), 0, 25));
         }
         $return = array_slice($update, 0, 5);
         // This auto-hyperlinks URLs
         $return[1]['title'] = preg_replace('((?:\\S)+://\\S+[[:alnum:]]/?)', '<a href="\\0">\\0</a>', $return[1]['title']);
         /**
          * If Twitter is the source, then we hyperlink any '@username's
          * to that user's Twitter address.
          **/
         if ($istwitter == 1) {
             $return[1]['title'] = preg_replace('/(@)([A-Za-z0-9_-]+)/', '<a href="http://twitter.com/\\2">\\0</a>', $return[1]['title']);
         }
         return substr($return[1]['title'], 0, 1000) . ' &mdash; <a href="' . $return[2]['link'] . '" title="">' . date('g:ia', $return[3]['date']) . '</a>';
     } else {
         return "Thanks for exploring my world! Can you believe this avatar is talking to you?";
     }
 }
示例#10
0
 /**
  * Generate the module
  */
 protected function compile()
 {
     /** @var PageModel $objPage */
     global $objPage;
     if ($this->rss_template != 'rss_default') {
         $this->strTemplate = $this->rss_template;
         /** @var FrontendTemplate|object $objTemplate */
         $objTemplate = new \FrontendTemplate($this->strTemplate);
         $this->Template = $objTemplate;
         $this->Template->setData($this->arrData);
     }
     $this->Template->link = $this->objFeed->get_link();
     $this->Template->title = $this->objFeed->get_title();
     $this->Template->language = $this->objFeed->get_language();
     $this->Template->description = $this->objFeed->get_description();
     $this->Template->copyright = $this->objFeed->get_copyright();
     // Add image
     if ($this->objFeed->get_image_url()) {
         $this->Template->image = true;
         $this->Template->src = $this->objFeed->get_image_url();
         $this->Template->alt = $this->objFeed->get_image_title();
         $this->Template->href = $this->objFeed->get_image_link();
         $this->Template->height = $this->objFeed->get_image_height();
         $this->Template->width = $this->objFeed->get_image_width();
     }
     // Get the items (see #6107)
     $arrItems = array_slice($this->objFeed->get_items(0, intval($this->numberOfItems) + intval($this->skipFirst)), intval($this->skipFirst), intval($this->numberOfItems) ?: null);
     $limit = count($arrItems);
     $offset = 0;
     // Split pages
     if ($this->perPage > 0) {
         // Get the current page
         $id = 'page_r' . $this->id;
         $page = \Input::get($id) !== null ? \Input::get($id) : 1;
         // Do not index or cache the page if the page number is outside the range
         if ($page < 1 || $page > max(ceil(count($arrItems) / $this->perPage), 1)) {
             throw new PageNotFoundException('Page not found: ' . \Environment::get('uri'));
         }
         // Set limit and offset
         $offset = ($page - 1) * $this->perPage;
         $limit = $this->perPage + $offset;
         $objPagination = new \Pagination(count($arrItems), $this->perPage, \Config::get('maxPaginationLinks'), $id);
         $this->Template->pagination = $objPagination->generate("\n  ");
     }
     $items = array();
     $last = min($limit, count($arrItems)) - 1;
     /** @var \SimplePie_Item[] $arrItems */
     for ($i = $offset, $c = count($arrItems); $i < $limit && $i < $c; $i++) {
         $items[$i] = array('link' => $arrItems[$i]->get_link(), 'title' => $arrItems[$i]->get_title(), 'permalink' => $arrItems[$i]->get_permalink(), 'description' => str_replace(array('<?', '?>'), array('&lt;?', '?&gt;'), $arrItems[$i]->get_description()), 'class' => ($i == 0 ? ' first' : '') . ($i == $last ? ' last' : '') . ($i % 2 == 0 ? ' even' : ' odd'), 'pubdate' => \Date::parse($objPage->datimFormat, $arrItems[$i]->get_date('U')), 'category' => $arrItems[$i]->get_category(0), 'object' => $arrItems[$i]);
         // Add author
         if (($objAuthor = $arrItems[$i]->get_author(0)) != false) {
             $items[$i]['author'] = trim($objAuthor->name . ' ' . $objAuthor->email);
         }
         // Add enclosure
         if (($objEnclosure = $arrItems[$i]->get_enclosure(0)) != false) {
             $items[$i]['enclosure'] = $objEnclosure->get_link();
         }
     }
     $this->Template->items = array_values($items);
 }
示例#11
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'));
 }
示例#12
0
文件: GitHub.php 项目: rmccue/Murray
	public function update() {
		$feed = new SimplePie();
		$feed->set_feed_url('https://github.com/' . $this->user . '.atom');
		$feed->enable_cache(false);
		$feed->set_stupidly_fast(true);
		$feed->init();

		foreach ($feed->get_items() as $item) {
			$id = $item->get_id();
			$title = substr($item->get_title(), strlen($this->user) + 1);
			$title = sprintf('<a href="%s">%s</a>', $item->get_permalink(), $title);
			$data = array(
				'id' => $id,
				'title' => $title,
				'content' => $item->get_content(),
				'source' => 'github',
				'timestamp' => $item->get_date('U')
			);

			/*$type = substr($id, 20, strpos($id, '/'));
			switch ($type) {
				case 'PushEvent':
				case 'IssueCommentEvent':
				case 'PullRequestEvent':
				case 'IssuesEvent':
				default:
					// no-op, standard stuff will work fine
					break;
			}*/
			Murray_Entry::create($data);
		}

	}
示例#13
0
文件: functions.php 项目: vertino/pez
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;
}
示例#14
0
 function showBlogLastArticles()
 {
     $content = '';
     $feed = new SimplePie();
     $feed->set_feed_url(array('http://bilboplanet.com/feed/'));
     $feed->set_cache_duration(600);
     #	$feed->enable_xml_dump(isset($_GET['xmldump']) ? true : false);
     $success = $feed->init();
     $feed->handle_content_type();
     if ($success) {
         $content .= '<div class="box-dashboard"><div class="top-box-dashboard">' . T_('BilboPlanet news - Official Website :') . '</div>';
         $content .= '<ul>';
         $itemlimit = 0;
         foreach ($feed->get_items() as $item) {
             if ($itemlimit == 4) {
                 break;
             }
             $content .= '<li>' . $item->get_date('j/m/y') . ' : ';
             $content .= '<a class="tips" rel="' . $item->get_title() . '" href="' . $item->get_permalink() . '" target="_blank">' . $item->get_title() . '</a>';
             $content .= '</li>';
             $itemlimit = $itemlimit + 1;
         }
         $content .= '</ul></div>';
     }
     return $content;
 }
示例#15
0
文件: Twitter.php 项目: rmccue/Murray
	public function update() {
		$feed = new SimplePie();
		$feed->set_feed_url('http://api.twitter.com/1/statuses/user_timeline.atom?screen_name=' . $this->user);
		$feed->enable_cache(false);
		$feed->set_stupidly_fast(true);
		$feed->init();

		foreach ($feed->get_items() as $item) {
			$title = substr($item->get_title(), strlen($this->user) + 2);
			$title = sprintf('<blockquote>%s</blockquote>', $title);
			$data = array(
				'id' => $item->get_id(),
				'title' => Twitter_Autolink::create($title)
					->setTarget(false)
					->setExternal(false)
					->addLinks(),
				'content' => '',
				'source' => 'twitter',
				'timestamp' => $item->get_date('U')
			);

			Murray_Entry::create($data);
		}


	}
示例#16
0
 function getContent()
 {
     $hp = Codendi_HTMLPurifier::instance();
     $content = '';
     if ($this->rss_url) {
         require_once 'common/rss/libs/SimplePie/simplepie.inc';
         if (!is_dir($GLOBALS['codendi_cache_dir'] . '/rss')) {
             mkdir($GLOBALS['codendi_cache_dir'] . '/rss');
         }
         $rss = new SimplePie($this->rss_url, $GLOBALS['codendi_cache_dir'] . '/rss', null, $GLOBALS['sys_proxy']);
         $max_items = 10;
         $items = array_slice($rss->get_items(), 0, $max_items);
         $content .= '<table width="100%">';
         $i = 0;
         foreach ($items as $item) {
             $content .= '<tr class="' . util_get_alt_row_color($i++) . '"><td WIDTH="99%">';
             if ($image = $item->get_link(0, 'image')) {
                 //hack to display twitter avatar
                 $content .= '<img src="' . $hp->purify($image, CODENDI_PURIFIER_CONVERT_HTML) . '" width="48" height="48" style="float:left; margin-right:1em;" />';
             }
             $content .= '<a href="' . $item->get_link() . '">' . $hp->purify($item->get_title(), CODENDI_PURIFIER_STRIP_HTML) . '</a>';
             if ($item->get_date()) {
                 $content .= '<span style="color:#999;" title="' . format_date($GLOBALS['Language']->getText('system', 'datefmt'), $item->get_date('U')) . '"> - ' . DateHelper::timeAgoInWords($item->get_date('U')) . '</span>';
             }
             $content .= '</td></tr>';
         }
         $content .= '</table>';
     }
     return $content;
 }
示例#17
0
 /**
  * RSS news page
  *
  * @param Request $request
  * @param Application $app
  */
 public function newsRss(Request $request, Application $app)
 {
     $simplePie = new \SimplePie();
     $simplePie->set_feed_url($app['resources']['news_rss']);
     $simplePie->init();
     $items = $simplePie->get_items();
     return $app['twig']->render('main/news-rss.twig', ['items' => $items]);
 }
示例#18
0
 /**
  * Initialize our class and load the items in
  *
  * {@internal Long Description Missing}}
  */
 public function init()
 {
     if (is_null($this->simplepie)) {
         $this->load();
     }
     $this->simplepie_items =& $this->simplepie->get_items();
     /** Run through each item at least once */
     foreach ($this->simplepie_items as $item) {
         $new_item = $this->normalise($item);
         $this->items[$new_item->hash] = $new_item;
     }
     uasort($this->items, array($this, 'sort_items'));
     $this->simplepie->__destruct();
     unset($this->simplepie);
     unset($this->simplepie_items);
     return $this->items;
 }
示例#19
0
function lire_feed($url, $nb = 3)
{
    $feed = new SimplePie($url, '../client/cache/flux');
    $feed->init();
    $feed->handle_content_type();
    $tab = $feed->get_items();
    return count($tab) > 0 ? array_slice($tab, 0, 3) : false;
}
示例#20
0
文件: loader.php 项目: roka371/Ego
 function feed($feed_type, $id, $init)
 {
     require_once 'inc/simplepie.inc';
     $this->load->model('loader_model');
     if ($feed_type == 'label') {
         if ($id == 'all_feeds') {
             $url = $this->loader_model->get_feeds_all($this->session->userdata('username'));
         } else {
             $label = $this->loader_model->select_label($this->session->userdata('username'), $id);
             $url = $this->loader_model->get_feeds_forLabel($this->session->userdata('username'), $label->label);
         }
     } else {
         $feed = $this->loader_model->select_feed($id);
         if ($feed->type == 'site') {
             $url = $feed->url;
         } else {
             if ($feed->type == 'keyword') {
                 $url = 'feed://news.google.com/news/feeds?gl=us&pz=1&cf=all&ned=us&hl=en&q=' . $feed->url . '&output=rss';
             }
         }
     }
     $feed = new SimplePie($url);
     $feed->enable_cache(true);
     $feed->set_cache_location('cache');
     $feed->set_cache_duration(600);
     //default: 10 minutes
     $feed->set_item_limit(11);
     $feed->init();
     $feed->handle_content_type();
     if ($init == "quantity") {
         echo $feed->get_item_quantity();
     } else {
         if ($init == "discovery") {
             if ($feed_type == 'label') {
                 $data['entries'] = $feed->get_items(0, 20);
             } else {
                 $data['entries'] = $feed->get_items();
             }
             $this->load->view('loader/discovery_viewer', $data);
         } else {
             $data['entries'] = $feed->get_items($init, $init + 10);
             $this->load->view('loader/feed_viewer', $data);
         }
     }
 }
示例#21
0
 function get_items($start = 0, $end = 0)
 {
     // Allow filters to set up for, or pre-empt, SimplePie handling
     $ret = apply_filters('feedwordpie_get_items', NULL, $start, $end, $this);
     if (is_null($ret)) {
         $ret = parent::get_items();
     }
     return $ret;
 }
示例#22
0
 /**
  * Fetches the specified number of feed items from the resource.
  *
  * This is a wrapper around \SimplePie::get_items(), except that it also
  * keys the array by each feed's unique identifier. This method can also be
  * used to warm the cache in parallel indexing configurations.
  *
  * @param int $limit
  *   The maximum number of feeds to process, defaults to no limit which will
  *   pull whatever the resource has published.
  *
  * @return array
  *   An array of \SimplePie_Item objects keyed by the feed item's unique
  *   identifier.
  */
 public function fetchFeedItems($limit = CollectionAgentAbstract::NO_LIMIT)
 {
     $end = $limit != CollectionAgentAbstract::NO_LIMIT ? $limit : 0;
     // Get the array of feed items.
     $this->_feed->init();
     $items = $this->_feed->get_items(0, $end);
     if (null === $items) {
         // @todo Log the error?
         $items = array();
     }
     // Key the array by the feed's unique ID.
     foreach ($items as $key => $item) {
         $item_id = $item->get_id();
         $items[$item_id] = $item;
         unset($items[$key]);
     }
     return $items;
 }
示例#23
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();
 }
示例#25
0
 public function getNews()
 {
     $feed = new SimplePie();
     $feed->set_feed_url('http://feeds.rapidfeeds.com/54082/');
     $success = $feed->init();
     if (!$success) {
         throw new Exception('couldnt init blog feed');
     }
     return $feed->get_items();
 }
 static function parseFeed($url, $omitDB = false)
 {
     global $wgOut;
     //reset array
     self::$data = array('feedTitle' => '', 'images' => array());
     if (!$omitDB) {
         //check DB for this URL - we might have it already (background task will refresh it)
         $data = self::getDataByUrl($url);
     }
     if ($omitDB || is_null($data)) {
         //no data in DB - fetch from feed
         $itemCount = 0;
         $rssContent = Http::get($url);
         $feed = new SimplePie();
         $feed->set_raw_data($rssContent);
         $feed->init();
         self::$data['feedTitle'] = $feed->get_title();
         foreach ($feed->get_items() as $item) {
             $enclosures = $item->get_enclosures();
             $enclosuresFound = false;
             //we have enclosures - use them instead of content of feed (usually there are bigger image while content uses thumbnails)
             if (!is_null($enclosures)) {
                 foreach ($enclosures as $enclosure) {
                     $type = $enclosure->get_type();
                     if (!empty($type) && substr($type, 0, 6) === 'image/') {
                         self::$data['images'][] = array('src' => $enclosure->get_link(), 'caption' => $item->get_title(), 'link' => $item->get_link());
                         $enclosuresFound = true;
                         break;
                         //one image per feed
                     }
                 }
             }
             //if enclosures has not been found or doesn't contain any images - use regular method
             if (!$enclosuresFound) {
                 //look for <img /> tags
                 $description = $item->get_description();
                 preg_match('/<img .*?src=([\'"])(.*?\\.(?:jpg|jpeg|gif|png))\\1/', $description, $matches);
                 if (!empty($matches[2])) {
                     self::$data['images'][] = array('src' => $matches[2], 'caption' => $item->get_title(), 'link' => $item->get_link());
                 }
             }
             if (count(self::$data['images']) >= 20 || ++$itemCount > 50) {
                 break;
                 //take up to 20 images, from up to 50 articles.
             }
         }
         //store data in DB only if valid rss (images found)
         if (count(self::$data['images'])) {
             self::setData($url, self::$data);
         }
     } else {
         self::$data = $data;
     }
     return self::$data;
 }
示例#27
0
function rss($url)
{
    $feed = new SimplePie();
    $feed->set_feed_url($url);
    $feed->handle_content_type();
    // Display content:
    echo '<h2>' . $feed->get_title() . '<br />';
    foreach ($feed->get_items() as $item) {
        echo $item->get_title();
    }
}
示例#28
0
 public function addAllGroupFeed()
 {
     if (OW::getConfig()->getValue('grouprss', 'disablePosting') == '1') {
         return;
     }
     $commentService = BOL_CommentService::getInstance();
     $newsfeedService = NEWSFEED_BOL_Service::getInstance();
     $router = OW::getRouter();
     $displayText = OW::getLanguage()->text('grouprss', 'feed_display_text');
     $location = OW::getConfig()->getValue('grouprss', 'postLocation');
     include_once 'autoloader.php';
     $allFeeds = $this->feeddao->findAll();
     foreach ($allFeeds as $feed) {
         $simplefeed = new SimplePie();
         $simplefeed->set_feed_url($feed->feedUrl);
         $simplefeed->set_stupidly_fast(true);
         $simplefeed->enable_cache(false);
         $simplefeed->init();
         $simplefeed->handle_content_type();
         $items = $simplefeed->get_items(0, $feed->feedCount);
         foreach ($items as $item) {
             $content = UTIL_HtmlTag::autoLink($item->get_content());
             if ($location == 'wall' && !$this->isDuplicateComment($feed->groupId, $content)) {
                 $commentService->addComment('groups_wal', $feed->groupId, 'groups', $feed->userId, $content);
             }
             if (trim($location) == 'newsfeed' && !$this->isDuplicateFeed($feed->groupId, $content)) {
                 $statusObject = $newsfeedService->saveStatus('groups', (int) $feed->groupId, $content);
                 $content = UTIL_HtmlTag::autoLink($content);
                 $action = new NEWSFEED_BOL_Action();
                 $action->entityId = $statusObject->id;
                 $action->entityType = "groups-status";
                 $action->pluginKey = "newsfeed";
                 $data = array("string" => $content, "content" => "[ph:attachment]", "view" => array("iconClass" => "ow_ic_comment"), "attachment" => array("oembed" => null, "url" => null, "attachId" => null), "data" => array("userId" => $feed->userId), "actionDto" => null, "context" => array("label" => $displayText, "url" => $router->urlForRoute('groups-view', array('groupId' => $feed->groupId))));
                 $action->data = json_encode($data);
                 $actionObject = $newsfeedService->saveAction($action);
                 $activity = new NEWSFEED_BOL_Activity();
                 $activity->activityType = NEWSFEED_BOL_Service::SYSTEM_ACTIVITY_CREATE;
                 $activity->activityId = $feed->userId;
                 $activity->actionId = $actionObject->id;
                 $activity->privacy = NEWSFEED_BOL_Service::PRIVACY_EVERYBODY;
                 $activity->userId = $feed->userId;
                 $activity->visibility = NEWSFEED_BOL_Service::VISIBILITY_FULL;
                 $activity->timeStamp = time();
                 $activity->data = json_encode(array());
                 $activityObject = $newsfeedService->saveActivity($activity);
                 $newsfeedService->addActivityToFeed($activity, 'groups', $feed->groupId);
             }
         }
         $simplefeed->__destruct();
         unset($feed);
     }
 }
function rssmaker_plugin_action($_, $myUser)
{
    if ($_['action'] == 'show_folder_rss') {
        header('Content-Type: text/xml; charset=utf-8');
        $feedManager = new Feed();
        $feeds = $feedManager->loadAll(array('folder' => $_['id']));
        $items = array();
        foreach ($feeds as $feed) {
            $parsing = new SimplePie();
            $parsing->set_feed_url($feed->getUrl());
            $parsing->init();
            $parsing->set_useragent('Mozilla/4.0 Leed (LightFeed Agregator) ' . VERSION_NAME . ' by idleman http://projet.idleman.fr/leed');
            $parsing->handle_content_type();
            // UTF-8 par défaut pour SimplePie
            $items = array_merge($parsing->get_items(), $items);
        }
        $link = 'http://projet.idleman.fr/leed';
        echo '<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/">
	<channel>
				<title>Leed dossier ' . $_['name'] . '</title>
				<atom:link href="' . $link . '" rel="self" type="application/rss+xml"/>
				<link>' . $link . '</link>
				<description>Aggrégation des flux du dossier leed ' . $_['name'] . '</description>
				<language>fr-fr</language>
				<copyright>DWTFYW</copyright>
				<pubDate>' . date('r', gmstrftime(time())) . '</pubDate>
				<lastBuildDate>' . date('r', gmstrftime(time())) . '</lastBuildDate>
				<sy:updatePeriod>hourly</sy:updatePeriod>
				<sy:updateFrequency>1</sy:updateFrequency>
				<generator>Leed (LightFeed Agregator) ' . VERSION_NAME . '</generator>';
        usort($items, 'rssmaker_plugin_compare');
        foreach ($items as $item) {
            echo '<item>
				<title><![CDATA[' . $item->get_title() . ']]></title>
				<link>' . $item->get_permalink() . '</link>
				<pubDate>' . date('r', gmstrftime(strtotime($item->get_date()))) . '</pubDate>
				<guid isPermaLink="true">' . $item->get_permalink() . '</guid>

				<description>
				<![CDATA[
				' . $item->get_description() . '
				]]>
				</description>
				<content:encoded><![CDATA[' . $item->get_content() . ']]></content:encoded>

				<dc:creator>' . ('' == $item->get_author() ? 'Anonyme' : $item->get_author()->name) . '</dc:creator>
				</item>';
        }
        echo '</channel></rss>';
    }
}
示例#30
0
 protected function fetchSite($site)
 {
     $feed = new \SimplePie();
     $feed->force_feed(true);
     $feed->set_item_limit(20);
     $feed->set_feed_url($site);
     $feed->enable_cache(false);
     $feed->set_output_encoding('utf-8');
     $feed->init();
     foreach ($feed->get_items() as $item) {
         $this->outputItem(['site' => $site, 'title' => $item->get_title(), 'link' => $item->get_permalink(), 'date' => new \Carbon\Carbon($item->get_date()), 'content' => $item->get_content()]);
     }
 }