本文整理汇总了PHP中Zend_Feed类的典型用法代码示例。如果您正苦于以下问题:PHP Zend_Feed类的具体用法?PHP Zend_Feed怎么用?PHP Zend_Feed使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Zend_Feed类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: toXml
/**
* Get xml from feed data
*
* @codeCoverageIgnore due to static method call (\Zend_Feed::importArray)
*
* @param FeedInterface $feed
* @return string
*/
public function toXml(FeedInterface $feed)
{
$data = ['title' => $feed->getTitle(), 'link' => $feed->getLink(), 'charset' => 'UTF-8', 'description' => $feed->getDescription()];
$rssFeedFromArray = $this->zendFeed->importArray($data, 'rss');
$xml = $rssFeedFromArray->saveXML();
return $xml;
}
示例2: index
function index()
{
$this->load->library('zend', 'Zend/Feed');
$this->load->library('zend', 'Zend/Search/Lucene');
$this->load->library('zend');
$this->zend->load('Zend/Feed');
$this->zend->load('Zend/Search/Lucene');
//Create index.
$index = new Zend_Search_Lucene('C:\\xampp\\xampp\\htdocs\\controle_frota\\lucene\\feeds_index', true);
$feeds = array('http://oglobo.globo.com/rss.xml?limite=50');
//grab each feed.
foreach ($feeds as $feed) {
$channel = Zend_Feed::import($feed);
echo $channel->title() . '<br />';
//index each item.
foreach ($channel->items as $item) {
if ($item->link() && $item->title() && $item->description()) {
//create an index doc.
$doc = new Zend_Search_Lucene_Document();
$doc->addField(Zend_Search_Lucene_Field::Keyword('link', $this->sanitize($item->link())));
$doc->addField(Zend_Search_Lucene_Field::Text('title', $this->sanitize($item->title())));
$doc->addField(Zend_Search_Lucene_Field::Unstored('contents', $this->sanitize($item->description())));
echo "\tAdding: " . $item->title() . '<br />';
$index->addDocument($doc);
}
}
}
$index->commit();
echo $index->count() . ' Documents indexed.<br />';
}
示例3: __construct
/**
* Zend_Feed_Entry_Abstract constructor
*
* The Zend_Feed_Entry_Abstract constructor takes the URI of the feed the entry
* is part of, and optionally an XML construct (usually a
* SimpleXMLElement, but it can be an XML string or a DOMNode as
* well) that contains the contents of the entry.
*
* @param string $uri
* @param SimpleXMLElement|DOMNode|string $element
* @return void
*/
public function __construct($uri = null, $element = null)
{
if (!$element instanceof DOMElement) {
if ($element) {
// Load the feed as an XML DOMDocument object
@ini_set('track_errors', 1);
$doc = new DOMDocument();
$success = @$doc->loadXML($element);
@ini_restore('track_errors');
if (!$success) {
throw new Zend_Feed_Exception("DOMDocument cannot parse XML: {$php_errormsg}");
}
$element = $doc->getElementsByTagName($this->_rootElement)->item(0);
if (!$element) {
throw new Zend_Feed_Exception('No root <' . $this->_rootElement . '> element found, cannot parse feed.');
}
} else {
$doc = new DOMDocument('1.0', 'utf-8');
if ($this->_rootNamespace !== null) {
$element = $doc->createElementNS(Zend_Feed::lookupNamespace($this->_rootNamespace), $this->_rootElement);
} else {
$element = $doc->createElement($this->_rootElement);
}
}
}
parent::__construct($element);
}
示例4: _getFeedXml
private function _getFeedXml()
{
$host = isset($_SERVER['HTTP_HOST']) ? 'http://' . $_SERVER['HTTP_HOST'] : '';
$feedArray = array('title' => $this->_getRssTitle(), 'link' => $host . $this->getUrl(), 'charset' => 'utf-8', 'description' => '', 'copyright' => Zend_Registry::get('config')->application->name, 'generator' => 'Koala Framework', 'language' => $this->getData()->getLanguage(), 'entries' => $this->_getRssEntries());
$feed = Zend_Feed::importArray($feedArray, 'rss');
return $feed->saveXml();
}
示例5: recentlyAdded
function recentlyAdded()
{
// redirect user if not logged in
if ($this->request->config->get('pawtucket_requires_login') && !$this->request->isLoggedIn() || $this->request->config->get('show_bristol_only') && !$this->request->isLoggedIn()) {
$this->response->setRedirect(caNavUrl($this->request, "", "LoginReg", "form"));
} elseif ($this->request->config->get('show_bristol_only') && $this->request->isLoggedIn()) {
$this->response->setRedirect(caNavUrl($this->request, "bristol", "Show", "Index"));
}
$t_object = new ca_objects();
if (($vn_num_items = (int) $this->request->config->get('rss_number_of_items')) <= 0) {
$vn_num_items = 10;
}
$va_recently_added_objects = $t_object->getRecentlyAddedItems($vn_num_items, array('checkAccess' => caGetUserAccessValues($this->request)));
$va_entries = array();
$va_object_ids = array();
foreach ($va_recently_added_objects as $va_object) {
$va_object_ids[] = $va_object['object_id'];
}
$qr_res = $t_object->makeSearchResult('ca_objects', $va_object_ids);
$vs_description_bundle = $this->request->config->get('rss_description');
while ($qr_res->nextHit()) {
$vn_object_id = $qr_res->get('ca_objects.object_id');
if (!($vn_creation_time = $t_object->getCreationTimestamp($vn_object_id, array('timestampOnly' => true)))) {
$vn_creation_time = time();
}
if (!($vn_update_time = $t_object->getLastChangeTimestamp($vn_object_id, array('timestampOnly' => true)))) {
$vn_update_time = time();
}
$va_entries[] = array('title' => $qr_res->get('ca_objects.preferred_labels.name'), 'link' => $vs_link = $this->request->config->get('site_host') . caNavUrl($this->request, '', 'Detail/Object', 'Index', array('object_id' => $vn_object_id)), 'guid' => $vs_link, 'lastUpdate' => $vn_update_time, 'description' => $vs_description_bundle ? $qr_res->getMediaTag("ca_object_representations.media", "preview") . "\n" . $qr_res->get($vs_description_bundle) : '', 'pubDate' => $vn_creation_time);
}
$va_feed_data = array('title' => _t('Recently added'), 'link' => $this->request->getRequestUrl(true), 'charset' => 'UTF-8', 'entries' => $va_entries);
$o_feed = Zend_Feed::importArray($va_feed_data, 'rss');
$this->view->setVar('feed', $o_feed);
$this->render('Feed/feed_recently_added_xml.php');
}
示例6: getFeed
/**
* Get a feed
*
* @param int $id
* @return Feed
*/
public function getFeed($url)
{
$feed = $this->dbService->getByField(array('url' => $url), 'Feed');
$update = $feed == null || strtotime($feed->updated) < time() - 60 * 15;
if ($feed == null) {
$feed = new Feed();
}
if ($update) {
$this->log->debug("Loading feed {$url}");
// make the request!
// $feed->content =
$content = null;
try {
$client = Zend_Feed::getHttpClient();
$client->setUri($url);
$response = $client->request('GET');
if ($response->getStatus() !== 200) {
throw new Zend_Feed_Exception('Feed failed to load, got response code ' . $response->getStatus());
}
$content = $response->getBody();
} catch (Exception $zfe) {
$this->log->err("Failed loading feed from {$url}");
return $content;
}
$feed->content = $content;
$feed->url = $url;
$this->dbService->saveObject($feed);
}
return $feed;
}
示例7: displayRss
/**
* Display RSS Data
*/
public function displayRss($array, $type = 'rss')
{
$this->loadZend();
$feed = Zend_Feed::importArray($array, $type);
$feed->send();
exit;
}
示例8: __construct
/**
* Feed constructor
*
* The Zend_Feed_Abstract constructor takes the URI of a feed or a
* feed represented as a string and loads it as XML.
*
* @param string $uri The full URI of the feed to load, or NULL if not retrieved via HTTP or as an array.
* @param string $string The feed as a string, or NULL if retrieved via HTTP or as an array.
* @param Zend_Feed_Builder_Interface $builder The feed as a builder instance or NULL if retrieved as a string or via HTTP.
* @return void
* @throws Zend_Feed_Exception If loading the feed failed.
*/
public function __construct($uri = null, $string = null, Zend_Feed_Builder_Interface $builder = null)
{
if ($uri !== null) {
// Retrieve the feed via HTTP
$client = Zend_Feed::getHttpClient();
$client->setUri($uri);
$response = $client->request('GET');
if ($response->getStatus() !== 200) {
/**
* @see Zend_Feed_Exception
*/
#require_once 'Zend/Feed/Exception.php';
throw new Zend_Feed_Exception('Feed failed to load, got response code ' . $response->getStatus());
}
$this->_element = $response->getBody();
$this->__wakeup();
} elseif ($string !== null) {
// Retrieve the feed from $string
$this->_element = $string;
$this->__wakeup();
} else {
// Generate the feed from the array
$header = $builder->getHeader();
$this->_element = new DOMDocument('1.0', $header['charset']);
$root = $this->_mapFeedHeaders($header);
$this->_mapFeedEntries($root, $builder->getEntries());
$this->_element = $root;
$this->_buildEntryCache();
}
}
示例9: feedAction
public function feedAction()
{
$woeid = $this->_request->getParam('woeid');
$ad_type = $this->_request->getParam('ad_type');
$status = $this->_request->getParam('status');
$modelAd = new Model_Ad();
$this->ads = $modelAd->getAdList($woeid, $ad_type, $status, 35);
$rss['title'] = $this->view->translate($ad_type) . ' ' . $this->view->translate((string) $status) . ' - ' . $this->_helper->woeid->name($woeid, $this->lang) . ' | nolotiro.org';
$rss['link'] = 'http://' . $_SERVER['HTTP_HOST'] . '/' . $this->lang . '/rss/feed/woeid/' . $woeid . '/ad_type/' . $ad_type . '/status/' . $status;
$rss['charset'] = 'utf-8';
$rss['description'] = 'nolotiro.org - ' . $this->_helper->woeid->name($woeid, $this->lang);
$rss['language'] = $this->lang;
$rss['generator'] = 'nolotiro.org';
$rss['entries'] = array();
foreach ($this->ads as $value) {
$entry = array();
$entry['title'] = $value['title'];
$entry['link'] = 'http://' . $_SERVER['HTTP_HOST'] . '/' . $this->lang . '/ad/' . $value['id'] . '/' . $this->view->slugTitle($value['title']);
$entry['description'] = $this->view->escapeEmail($value['body']);
$entry['lastUpdate'] = strtotime($value['date_created']);
$rss['entries'][] = $entry;
}
$feedObj = Zend_Feed::importArray($rss, 'rss');
return $feedObj->send();
}
示例10: get
function get()
{
require_once 'Zend/Feed.php';
try {
$rss = Zend_Feed::import($this->url);
} catch (Zend_Feed_Exception $e) {
echo "Error while importing feed: {$e->getMessage()}\n";
exit;
}
$output = '<div style="padding:10px 15px;"><ul class="rss">';
$i = 0;
foreach ($rss as $post) {
$title = $post->title();
$date = strftime("%B %e, %Y", strtotime($post->pubDate()));
$link = $post->link();
$output .= '<li><a class="rss-title" title="" href="' . $link . '">' . $title . '</a>' . '<span class="rss-date">' . $date . '</span>';
if ($this->showDescription) {
$output .= '<div class="rss-description">' . $post->description() . '</div>';
}
if ($this->showContent) {
$output .= '<div class="rss-content">' . $post->content() . '</div>';
}
$output .= '</li>';
if (++$i == $this->count) {
break;
}
}
$output .= '</ul></div>';
return $output;
}
示例11: feed
public static function feed()
{
$ncsu = new Tweetgater_Twitter();
$down = false;
try {
$timeline = $ncsu->getTimeline();
} catch (Exception $e) {
$down = true;
}
$config = $ncsu->getConfigFile();
$fa = array();
$fa['title'] = $config->feed->title;
$fa['link'] = $config->site->url . '/feed.php';
$fa['charset'] = 'UTF-8';
$fa['author'] = $config->feed->title;
$entries = array();
if (!$down) {
foreach ($timeline as $t) {
$temp = array();
$temp['title'] = 'Tweet by @' . $t['user-screen_name'];
$temp['link'] = 'http://www.twitter.com/' . $t['user-screen_name'] . '/status/' . $t['id'];
$temp['description'] = $t['text'] . '<br /><br />Follow @<a href="http://www.twitter.com/' . $t['user-screen_name'] . '">' . $t['user-screen_name'] . '</a>';
$temp['lastUpdate'] = strtotime($t['created_at']);
$entries[] = $temp;
}
}
$fa['entries'] = $entries;
// importing a rss feed from an array
$rssFeed = Zend_Feed::importArray($fa, 'rss');
// send http headers and dump the feed
$rssFeed->send();
}
示例12: rssAction
public function rssAction()
{
$this->_helper->layout->setLayout('rss');
//Create an array for our feed
$feed = array();
//Setup some info about our feed
$feed['title'] = "IllustratedPortland.com RSS Feed";
$feed['link'] = 'feed://illustratedportland.com/blog/rss';
$feed['charset'] = 'utf-8';
$feed['language'] = 'en-us';
//$feed['published'] = time();
$feed['entries'] = array();
//Holds the actual items
foreach ($this->blog_model->getAll() as $story) {
$entry = array();
//Container for the entry before we add it on
$entry['title'] = $story['title'];
//The title that will be displayed for the entry
$entry['guide'] = $story['id'];
$entry['published'] = $story['date'];
$entry['link'] = 'http://illustratedportland.com/blog/single/id/' . $story['id'];
//The url of the entry
$entry['url'] = 'http://illustratedportland.com/blog/single/id/' . $story['id'];
//The url of the entry
$entry['description'] = $story['description'];
//Short description of the entry
$entry['content'] = $story['content'];
//Long description of the entry
$feed['entries'][] = $entry;
}
$feedObj = Zend_Feed::importArray($feed, 'rss');
$this->view->feed = $feedObj->send();
}
示例13: indexAction
public function indexAction()
{
$this->view->version = Application::VERSION;
try {
$feed = Zend_Feed::import('http://source.keyboard-monkeys.org/projects/communityid/news?format=atom');
} catch (Zend_Exception $e) {
// feed import failed
$obj = new StdClass();
$obj->link = array('href' => '');
$obj->title = $this->view->translate('Could not retrieve news items');
$obj->updated = '';
$obj->content = '';
$feed = array($obj);
}
$this->view->news = array();
$i = 0;
foreach ($feed as $item) {
if ($i++ >= self::NEWS_NUM_ITEMS) {
break;
}
// ATOM uses <link href="foo" />, while RSS uses <link>foo</link>
$item->link = $item->link['href'] ? $item->link['href'] : $item->link;
if (strlen($item->content) > self::NEWS_CONTENT_MAX_LENGTH) {
$item->content = substr($item->content, 0, self::NEWS_CONTENT_MAX_LENGTH) . '...<br /><a class="readMore" href="' . $item->link . '">' . $this->view->translate('Read More') . '</a>';
}
$this->view->news[] = $item;
}
$this->_helper->actionStack('index', 'login', 'users');
}
示例14: rssAction
public function rssAction()
{
// build the feed array
$feedArray = array();
// the title and link are required
$feedArray['title'] = 'Recent Pages';
$feedArray['link'] = 'http://localhost';
// the published timestamp is optional
$feedArray['published'] = Zend_Date::now()->toString(Zend_Date::TIMESTAMP);
// the charset is required
$feedArray['charset'] = 'UTF8';
// first get the most recent pages
$mdlPage = new Model_Page();
$recentPages = $mdlPage->getRecentPages();
//add the entries
if (is_array($recentPages) && count($recentPages) > 0) {
foreach ($recentPages as $page) {
// create the entry
$entry = array();
$entry['guid'] = $page->id;
$entry['title'] = $page->headline;
$entry['link'] = 'http://localhost/page/open/title/' . $page->name;
$entry['description'] = $page->description;
$entry['content'] = $page->content;
// add it to the feed
$feedArray['entries'][] = $entry;
}
}
// create an RSS feed from the array
$feed = Zend_Feed::importArray($feedArray, 'rss');
// now send the feed
$this->_helper->viewRenderer->setNoRender();
$this->_helper->layout->disableLayout();
$feed->send();
}
示例15: indexAction
public function indexAction()
{
$format = $this->_request->getParam('format');
if (in_array($format, array('georss', 'rss', 'atom'))) {
$news = new News();
$news = $news->getNews();
// prepare an array that our feed is based on
$feedArray = array('title' => 'Latest news from the Portable Antiquities Scheme', 'link' => Zend_Registry::get('siteurl') . '/news/', 'charset' => 'utf-8', 'description' => 'The latest news stories published by the Portable Antiquities Scheme', 'author' => 'The Portable Antiquities Scheme', 'image' => Zend_Registry::get('siteurl') . '/images/logos/pas.gif', 'email' => 'info@finds.org.uk', 'copyright' => 'Creative Commons Licenced', 'generator' => 'The Scheme database powered by Zend Framework and Dan\'s magic', 'language' => 'en', 'entries' => array());
foreach ($news as $new) {
$auth = Zend_Auth::getInstance();
//$latlong = $new['declat'] .' ' .$new['declong'];
$feedArray['entries'][] = array('title' => $new['title'], 'link' => Zend_Registry::get('siteurl') . '/news/story/id/' . $new['id'], 'guid' => Zend_Registry::get('siteurl') . '/news/story/id/' . $new['id'], 'description' => $this->EllipsisString($new['contents'], 200), 'lastUpdate' => strtotime($new['datePublished']));
/*if($object['i'] != NULL) {
$feedArray['enclosure'][] = array(array(
'url' => 'http://www.findsdatabase.org.uk/view/thumbnails/pas/'.$object['i'].'.jpg',
'type' => 'image/jpeg' //always sets to jpeg as the thumbnails are derived from there.
));
}*/
}
$feed = Zend_Feed::importArray($feedArray, $format);
$feed->send();
} else {
$this->_redirect('/news/');
}
}