当前位置: 首页>>代码示例>>PHP>>正文


PHP SimplePie::get_items方法代码示例

本文整理汇总了PHP中SimplePie::get_items方法的典型用法代码示例。如果您正苦于以下问题:PHP SimplePie::get_items方法的具体用法?PHP SimplePie::get_items怎么用?PHP SimplePie::get_items使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SimplePie的用法示例。


在下文中一共展示了SimplePie::get_items方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: getItems

 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;
 }
开发者ID:nextglory,项目名称:CacoCloud,代码行数:9,代码来源:SimplePieFeedReader.php

示例2: get_news_feed

 /**
  * 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;
     }
 }
开发者ID:neojp,项目名称:wordpress-twitter-news-feed,代码行数:60,代码来源:twitter-news-feed-class.php

示例3: item_content

 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();
 }
开发者ID:postmatic,项目名称:beta-dist,代码行数:13,代码来源:feed.php

示例4: testListPosts

 /**
  * 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');
     }
 }
开发者ID:rmccue,项目名称:Gorilla,代码行数:35,代码来源:EntryPostsTest.php

示例5: getFeedItems

 /**
  * 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;
 }
开发者ID:webremote,项目名称:craft_boilerplate,代码行数:60,代码来源:FeedsService.php

示例6: SimplePie

 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;
 }
开发者ID:kga245,项目名称:echo-php-library,代码行数:27,代码来源:activitystreams.php

示例7: addSystemMessages

 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();
 }
开发者ID:mindbird,项目名称:contao-be-rss,代码行数:33,代码来源:BeRss.php

示例8: show_news

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 />";
    }
}
开发者ID:philhassey,项目名称:ludumdare,代码行数:25,代码来源:news.php

示例9: fetchfeed

 /**
  * 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?";
     }
 }
开发者ID:EddieRingle,项目名称:wicketpixie,代码行数:37,代码来源:update.php

示例10: compile

 /**
  * 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);
 }
开发者ID:contao,项目名称:core-bundle,代码行数:63,代码来源:ModuleRssReader.php

示例11: html

 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'));
 }
开发者ID:lesaff,项目名称:statamic-rssfeed,代码行数:26,代码来源:RSSFeedWidget.php

示例12: update

	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);
		}

	}
开发者ID:rmccue,项目名称:Murray,代码行数:33,代码来源:GitHub.php

示例13: flickr_photos

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;
}
开发者ID:vertino,项目名称:pez,代码行数:27,代码来源:functions.php

示例14: showBlogLastArticles

 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;
 }
开发者ID:archcidburnziso,项目名称:Bilboplanet,代码行数:26,代码来源:index.php

示例15: update

	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);
		}


	}
开发者ID:rmccue,项目名称:Murray,代码行数:26,代码来源:Twitter.php


注:本文中的SimplePie::get_items方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。