本文整理汇总了PHP中Zend_Feed_Reader类的典型用法代码示例。如果您正苦于以下问题:PHP Zend_Feed_Reader类的具体用法?PHP Zend_Feed_Reader怎么用?PHP Zend_Feed_Reader使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Zend_Feed_Reader类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _parse
protected function _parse()
{
$feed = Zend_Feed_Reader::import($this->getLink());
$this->_news = new Core_Model_Default(array('title' => $feed->getTitle(), 'link' => $feed->getLink(), 'dateModified' => $feed->getDateModified(), 'description' => $feed->getDescription(), 'language' => $feed->getLanguage(), 'entries' => array()));
$data = array();
foreach ($feed as $entry) {
$picture = null;
if ($entry->getEnclosure() && $entry->getEnclosure()->url) {
$picture = $entry->getEnclosure()->url;
}
if ($entry->getDescription()) {
$content = new Dom_SmartDOMDocument();
$content->loadHTML($entry->getDescription());
$content->encoding = 'utf-8';
$description = $content->documentElement;
$imgs = $description->getElementsByTagName('img');
if ($imgs->length > 0) {
$img = $imgs->item(0);
if ($img->getAttribute('src')) {
$picture = $img->getAttribute('src');
}
}
}
$edata = new Core_Model_Default(array('title' => $entry->getTitle(), 'description' => strip_tags($entry->getDescription()), 'dateModified' => $entry->getDateModified(), 'authors' => $entry->getAuthors(), 'link' => $entry->getLink(), 'content' => strip_tags($entry->getContent()), 'enclosure' => $entry->getEnclosure(), 'timestamp' => $entry->getDateCreated()->getTimestamp(), 'picture' => $picture));
$data[] = $edata;
}
$this->_news->setEntries($data);
return $this;
}
示例2: getVideos
public function getVideos($offset)
{
if (!$this->_videos) {
$this->_videos = array();
try {
$this->_setYoutubeUrl($offset);
$feed = Zend_Feed_Reader::import($this->getLink());
} catch (Exception $e) {
$feed = array();
}
foreach ($feed as $entry) {
$params = Zend_Uri::factory($entry->getLink())->getQueryAsArray();
$image = null;
$link = null;
if (!empty($params['v'])) {
$image = "http://img.youtube.com/vi/{$params['v']}/0.jpg";
$link = "http://www.youtube.com/embed/{$params['v']}";
} else {
$link = $entry->getLink();
}
$video = new Core_Model_Default(array('video_id' => $params['v'], 'title' => $entry->getTitle(), 'description' => $entry->getContent(), 'link' => $link, 'image' => $image));
$this->_videos[] = $video;
}
}
return $this->_videos;
}
示例3: updateFeed
/**
* Add feed to system
*
* @param Feed $feed
*/
private function updateFeed(Feed $feed)
{
require_once 'Ifphp/models/Posts.php';
$feedSource = Zend_Feed_Reader::import($feed->url);
$posts = new Posts();
$tdate = $feedSource->current()->getDateModified();
$tdate = new Zend_Date($tdate);
while ($feedSource->valid() && $tdate->toValue() > $feed->lastPing && !$posts->getByLink($feedSource->current()->getPermaLink())) {
$tdate = $feedSource->current()->getDateModified();
$tdate = new Zend_Date($tdate);
$defaultFilterChain = new Zend_Filter();
$defaultFilterChain->addFilter(new Ifphp_Filter_XSSClean());
$defaultFilterChain->addFilter(new Zend_Filter_StringTrim());
$defaultFilterChain->addFilter(new Zend_Filter_StripTags());
$post = $posts->createRow();
$post->title = $defaultFilterChain->filter($feedSource->current()->getTitle());
$post->description = $defaultFilterChain->filter($feedSource->current()->getDescription());
$post->feedId = $defaultFilterChain->filter($feed->id);
$post->link = $defaultFilterChain->filter($feedSource->current()->getPermaLink());
$post->publishDate = $tdate->toValue();
$post->save();
Ifphp_Controller_Front::getInstance()->getPluginBroker()->addPost($post, $feed);
$feedSource->next();
}
$feed->lastPing = time();
$feed->save();
}
示例4: pollAction
/**
* Polls all registered feeds. The actual polling is performed by the
* retrieved Models, so all we do here is get those Models and setup
* Zend_Feed_Reader caching/conditional GET support if configured.
* Polling is NOT performed for feeds which have a confirmed Pubsubhubbub
* subscription active.
*
* @return void
*/
public function pollAction()
{
try {
$feeds = Doctrine_Query::create()->from('Zfplanet_Model_Feed f')->where('f.uri NOT IN (SELECT s.topic_url FROM Zfplanet_Model_Subscription s' . ' WHERE s.subscription_state = ?)', Zend_Feed_Pubsubhubbub::SUBSCRIPTION_VERIFIED)->execute();
if (!$feeds) {
return;
}
$chelper = $this->_helper->getHelper('Cache');
if ($chelper->hasCache('feed')) {
Zend_Feed_Reader::setCache($chelper->getCache('feed'));
Zend_Feed_Reader::useHttpConditionalGet();
}
$notifier = $this->_getTwitterNotifier();
foreach ($feeds as $feed) {
if ($notifier->isEnabled()) {
$feed->setTwitterNotifier($notifier);
}
$feed->setLuceneIndexer($this->_getLuceneIndexer());
$feed->setLogger($this->getInvokeArg('bootstrap')->getResource('ErrorLog'));
$feed->synchronise();
}
$this->_helper->getHelper('Cache')->removePagesTagged(array('allentries'));
$this->_doPubsubhubbubNotification();
echo 'Polling completed without error', PHP_EOL;
} catch (Exception $e) {
$logger = $this->getInvokeArg('bootstrap')->getResource('ErrorLog');
$message = 'Other Error/Exception: ' . get_class($e) . ': ' . $e->getMessage() . PHP_EOL . 'Stack Trace: ' . PHP_EOL . $e->getTraceAsString();
$logger->log($message, Zend_Log::ERR);
echo $message;
}
}
示例5: processAction
public function processAction()
{
if (!$this->getRequest() instanceof ZFExt_Controller_Request_Cli) {
throw new Exception('Access denied from HTTP');
}
try {
$this->getInvokeArg('bootstrap')->addOptionRules(array('key|k=s' => 'File keyname for task data (required)'));
$options = $this->getInvokeArg('bootstrap')->getGetOpt();
$path = APPLICATION_PATH . '/../data/tmp/' . $options->key;
$data = file_get_contents($path);
$feed = Zend_Feed_Reader::importString($data);
unlink($path);
$feedModel = Doctrine_Core::getTable('Zfplanet_Model_Feed')->find($feed->getId());
if ($feedModel) {
$notifier = $this->_getTwitterNotification();
if ($notifier->isEnabled()) {
$feedModel->setTwitterNotifier($notifier);
}
$feedModel->setLuceneIndexer($this->_getLuceneIndexer());
$feedModel->synchronise($feed);
$this->_helper->getHelper('Cache')->removePagesTagged(array('allentries'));
$this->_helper->notifyHub(array('http://pubsubhubbub.appspot.com/'));
} else {
throw new Exception('Feed being processed does not match a known feed ID');
}
} catch (Exception $e) {
$logger = $this->getInvokeArg('bootstrap')->getResource('ErrorLog');
$message = 'Error/Exception encountered: ' . get_class($e) . ': ' . $e->getMessage() . PHP_EOL . 'Stack Trace: ' . PHP_EOL . $e->getTraceAsString();
$logger->log($message, Zend_Log::ERR);
}
}
示例6: getAuthors
/**
* Get an array with feed authors
*
* @return array
*/
public function getAuthors()
{
if (array_key_exists('authors', $this->_data)) {
return $this->_data['authors'];
}
$authors = array();
$list = $this->_xpath->evaluate($this->getXpathPrefix() . '//dc11:creator');
if (!$list->length) {
$list = $this->_xpath->evaluate($this->getXpathPrefix() . '//dc10:creator');
}
if (!$list->length) {
$list = $this->_xpath->evaluate($this->getXpathPrefix() . '//dc11:publisher');
if (!$list->length) {
$list = $this->_xpath->evaluate($this->getXpathPrefix() . '//dc10:publisher');
}
}
if ($list->length) {
foreach ($list as $author) {
$authors[] = array('name' => $author->nodeValue);
}
$authors = new Zend_Feed_Reader_Collection_Author(Zend_Feed_Reader::arrayUnique($authors));
} else {
$authors = null;
}
$this->_data['authors'] = $authors;
return $this->_data['authors'];
}
示例7: getVideos
public function getVideos($offset)
{
$cache = Zend_Registry::get('cache');
// if(($this->_videos = $cache->load('MEDIA_VIDEOS_ITUNES_'.sha1($this->getGalleryId().$this->getParam()))) === false ) {
$this->_videos = array();
try {
$flux = Zend_Feed_Reader::import($this->getParam());
if ($flux) {
foreach ($flux as $entry) {
$image = $flux->getImage();
$podcast = $entry->getExtension('Podcast');
$extension = "";
if ($entry->getEnclosure()->url) {
$extension = explode(".", $entry->getEnclosure()->url);
$extension = $extension[count($extension) - 1];
}
$video = new Core_Model_Default(array('video_id' => $entry->getEnclosure()->url, 'title' => $entry->getTitle(), 'description' => $entry->getContent(), 'link' => $entry->getEnclosure()->url, 'extension' => $extension, 'image' => $podcast->getImage() ? $podcast->getImage() : $image['uri']));
$this->_videos[] = $video;
}
}
$cache->save($this->_videos, 'MEDIA_VIDEOS_ITUNES_' . sha1($this->getGalleryId() . $this->getParam()));
} catch (Exception $e) {
}
// }
return array_slice($this->_videos, $offset - 1, self::DISPLAYED_PER_PAGE);
}
示例8: __construct
/**
* Constructor
*
* @param DOMDocument $dom
* @param string $type
*/
public function __construct(DomDocument $dom, $type = null)
{
parent::__construct($dom, $type);
$atomClass = Zend_Feed_Reader::getPluginLoader()->getClassName('Atom_Feed');
$this->_extensions['Atom_Feed'] = new $atomClass($dom, $this->_data['type'], $this->_xpath);
foreach ($this->_extensions as $extension) {
$extension->setXpathPrefix('/atom:feed');
}
}
示例9: check
/**
* Checks the feeds for new news.
*/
protected function check()
{
foreach ($this->uris as $uri) {
$feed = Zend_Feed_Reader::import($uri);
foreach ($feed as $entry) {
$content = $this->getFixedContent($entry);
NewsEditor::create($entry->getTitle(), $content, $entry->getLink());
}
}
}
示例10: __construct
/**
* Constructor
*
* @param DOMElement $entry
* @param int $entryKey
* @param string $type
* @return void
*/
public function __construct(DOMElement $entry, $entryKey, $type = null)
{
parent::__construct($entry, $entryKey, $type);
// Everyone by now should know XPath indices start from 1 not 0
$this->_xpathQuery = '//atom:entry[' . ($this->_entryKey + 1) . ']';
$atomClass = Zend_Feed_Reader::getPluginLoader()->getClassName('Atom_Entry');
$this->_extensions['Atom_Entry'] = new $atomClass($entry, $entryKey, $type);
$threadClass = Zend_Feed_Reader::getPluginLoader()->getClassName('Thread_Entry');
$this->_extensions['Thread_Entry'] = new $threadClass($entry, $entryKey, $type);
}
示例11: indexAction
public function indexAction()
{
$feedUrl = 'http://feeds.feedburner.com/ZendScreencastsVideoTutorialsAboutTheZendPhpFrameworkForDesktop';
$feed = Zend_Feed_Reader::import($feedUrl);
$this->view->gettingStarted = array();
foreach ($feed as $entry) {
if (array_search('Getting Started', $entry->getCategories()->getValues())) {
$this->view->gettingStarted[$entry->getLink()] = $entry->getTitle();
}
}
}
示例12: isValid
/**
* Defined by Zend_Validate_Interface
*
* Returns true if and only if $value is a valid IP address
*
* @param mixed $value
* @return boolean
*/
public function isValid($value)
{
$valueString = (string) $value;
$this->_setValue($valueString);
try {
Zend_Feed_Reader::import($valueString);
} catch (Zend_Feed_Exception $e) {
$this->_error(self::NOT_URL);
return false;
}
return true;
}
示例13: _initFeed
protected function _initFeed()
{
// set cache frontend options
$frontendOptions = array('lifetime' => 86400, 'automatic_serialization' => true);
// set cache backend options
$backendOptions = array('cache_dir' => APPLICATION_PATH . '/../data/cache');
// configure cache
$cache = Zend_Cache::factory('Core', 'File', $frontendOptions, $backendOptions);
// set feed to use cache and httpConditionalGet
Zend_Feed_Reader::setCache($cache);
Zend_Feed_Reader::useHttpConditionalGet();
}
示例14: detectHubs
/**
* Simple utility function which imports any feed URL and
* determines the existence of Hub Server endpoints. This works
* best if directly given an instance of Zend_Feed_Reader_Atom|Rss
* to leverage off.
*
* @param Zend_Feed_Reader_FeedAbstract|Zend_Feed_Abstract|string $source
* @return array
*/
public static function detectHubs($source)
{
if (is_string($source)) {
$feed = Zend_Feed_Reader::import($source);
} elseif (is_object($source) && $source instanceof Zend_Feed_Reader_FeedAbstract) {
$feed = $source;
} elseif (is_object($source) && $source instanceof Zend_Feed_Abstract) {
$feed = Zend_Feed_Reader::importFeed($source);
} else {
throw new Zend_Feed_Pubsubhubbub_Exception('The source parameter was' . ' invalid, i.e. not a URL string or an instance of type' . ' Zend_Feed_Reader_FeedAbstract or Zend_Feed_Abstract');
}
return $feed->getHubs();
}
示例15: processAction
public function processAction()
{
$form = new Admin_Form_AddBlog();
if (!$this->getRequest()->isPost()) {
return $this->_forward('admin/index');
}
$flashMessenger = $this->_helper->getHelper('FlashMessenger');
if (!$form->isValid($_POST)) {
$flashMessenger->addMessage('Form data invalid: recheck details and try again.');
$flashMessenger->addMessage('error');
$this->_redirect('/admin/blog/create');
}
$values = $form->getValues();
$blog = new Zfplanet_Model_Blog();
$blog->contactName = $values['contactName'];
if (isset($values['contactEmail'])) {
$blog->contactEmail = $values['contactEmail'];
}
$blog->uri = $values['uri'];
try {
$data = Zend_Feed_Reader::import($values['feedUri']);
} catch (Exception $e) {
$flashMessenger->addMessage('Problem fetching feed: ' . $e->getMessage());
$flashMessenger->addMessage('error');
$this->_redirect('/admin/blog/create');
}
$blog->feedId = $data->getId();
$feed = new Zfplanet_Model_Feed();
$feedMeta = new Zfplanet_Model_FeedMeta();
$feed->id = $data->getId();
$feed->uri = $data->getFeedLink();
if (isset($feed->uri)) {
$feed->uri = $values['feedUri'];
}
$feed->blogId = $blog->id;
$feed->title = Zfplanet_Model_Feed::getHtmlPurifier()->purify($data->getTitle());
$feed->type = $this->_getFeedVersion($data->getType());
$feed->isActive = 1;
$feedMeta->feedId = $data->getId();
$feedMeta->title = $data->getTitle();
$feedMeta->description = $data->getDescription();
$feedMeta->link = $data->getLink();
$feedMeta->feedLink = $data->getFeedLink();
$blog->save();
$feed->save();
$feedMeta->save();
$this->_checkPubsubEnabled($data);
$flashMessenger->addMessage('Blog successfully added!');
$flashMessenger->addMessage('success');
$this->_redirect('/admin/blog/create');
}