Example #1
0
 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;
 }
Example #2
0
 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;
 }
Example #3
0
 /**
  * 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();
 }
Example #4
0
 /**
  * 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;
     }
 }
Example #5
0
 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);
     }
 }
Example #6
0
 /**
  * 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'];
 }
Example #7
0
 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);
 }
Example #8
0
 /**
  * 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');
     }
 }
Example #9
0
 /**
  * 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());
         }
     }
 }
Example #10
0
 /**
  * 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);
 }
Example #11
0
 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();
         }
     }
 }
Example #12
0
 /**
  * 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;
 }
Example #13
0
 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();
 }
 /**
  * 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();
 }
Example #15
0
 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');
 }
Example #16
0
 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;
         }
         $description = "";
         if ($entry->getContent()) {
             $content = new Dom_SmartDOMDocument();
             $content->loadHTML($entry->getContent());
             $content->encoding = 'utf-8';
             $description = $content->documentElement;
             $imgs = $description->getElementsByTagName('img');
             if ($imgs->length > 0) {
                 foreach ($imgs as $k => $img) {
                     if ($k == 0) {
                         $img = $imgs->item(0);
                         if ($img->getAttribute('src') and stripos($img->getAttribute('src'), ".gif") === false) {
                             $picture = $img->getAttribute('src');
                             $img->parentNode->removeChild($img);
                         }
                     }
                     $img->removeAttribute('width');
                     $img->removeAttribute('height');
                 }
             }
             $as = $description->getElementsByTagName('a');
             if ($as->length > 0) {
                 foreach ($as as $a) {
                     $a->setAttribute('target', '_self');
                 }
             }
             $description = $content->saveHTMLExact();
         }
         $timestamp = $entry->getDateCreated() ? $entry->getDateCreated()->getTimestamp() : null;
         $updated_at = null;
         if ($timestamp) {
             $updated_at = $this->_getUpdatedAt($timestamp);
         }
         $edata = new Core_Model_Default(array('entry_id' => $entry->getId(), 'title' => $entry->getTitle(), 'description' => $description, 'short_description' => strip_tags($description), 'dateModified' => $entry->getDateModified(), 'authors' => $entry->getAuthors(), 'link' => $entry->getLink(), 'content' => $description, 'enclosure' => $entry->getEnclosure(), 'timestamp' => $timestamp, 'updated_at' => $updated_at, 'picture' => $picture));
         $data[] = $edata;
     }
     $this->_news->setEntries($data);
     return $this;
 }
 private function _orderRssNews($rss_list)
 {
     $feeds = array();
     $errors = array();
     $id_source = 0;
     if (isset($_COOKIE['id_' . $this->_id_page])) {
         $id_source = $_COOKIE['detail_source_' . $this->_id_page];
     }
     $flag = false;
     $cache = $this->_getCache();
     foreach ($rss_list as $rss_key => $rss) {
         try {
             $cache_key = PREFIXED_CACHE_RSS_URL . md5($rss['link']);
             $rss_news = $cache->load($cache_key);
             if (!$rss_news) {
                 $feed = Zend_Feed_Reader::import($rss['link']);
                 $arrFeeds = array();
                 foreach ($feed as $entry) {
                     $itemRSS = array("title" => $entry->getTitle(), "dateModified" => $entry->getDateModified(), "description" => $entry->getDescription(), "link" => $entry->getLink(), "commentLink" => $entry->getCommentLink());
                     $arrFeeds[] = $itemRSS;
                 }
                 $rss_news = array('link' => $feed->getLink(), 'entries' => $arrFeeds);
                 $cache->save($rss_news, $cache_key, array(), TIMELIFE_CACHE_RSS_URL);
             }
             if (!$flag && $id_source == $rss['id']) {
                 $flag = true;
             }
             $entries = array();
             $index = 0;
             foreach ($rss_news["entries"] as $entry) {
                 if ($index >= $rss['num_stories']) {
                     break;
                 }
                 $news = array("title" => $entry["title"], "dateModified" => $entry["dateModified"], "description" => $entry["description"], "link" => $entry["link"], "commentLink" => $entry["commentLink"]);
                 $entries[$index] = $news;
                 $index++;
             }
             $rss_feeds = array('title' => $rss['title'], 'link' => $rss_news["link"], 'entries' => $entries, 'is_allow_comment' => $rss["is_allow_comment"]);
             $feeds[$rss['id']] = $rss_feeds;
         } catch (Exception $e) {
             $feeds[$rss['id']] = array('title' => $rss['title'], 'entries' => $this->translate('ERR_CANNOT_LOAD_DATA_FROM_RSS_LINK'));
             $errors[] = $rss['link'];
         }
     }
     if (!$flag) {
         setcookie('detail_source_' . $this->_id_page, "all", time() + 7 * 24 * 60 * 60, '/');
     }
     return $feeds;
 }
 /**
  * Constructor
  *
  * @param  Zend_Feed_Abstract $feed The source Zend_Feed object
  * @param  string $type Feed type
  * @return void
  */
 public function __construct(DomDocument $dom, $type = null, DOMXPath $xpath = null)
 {
     $this->_domDocument = $dom;
     if ($type !== null) {
         $this->_data['type'] = $type;
     } else {
         $this->_data['type'] = Zend_Feed_Reader::detectType($dom);
     }
     if ($xpath !== null) {
         $this->_xpath = $xpath;
     } else {
         $this->_xpath = new DOMXPath($this->_domDocument);
     }
     $this->_registerNamespaces();
 }
Example #19
0
 /**
  * Constructor: Create a Source object which is largely just a normal
  * Zend_Feed_Reader_FeedAbstract object only designed to retrieve feed level
  * metadata from an Atom entry's source element.
  *
  * @param DOMElement $source
  * @param string $xpathPrefix Passed from parent Entry object
  * @param string $type Nearly always Atom 1.0
  */
 public function __construct(DOMElement $source, $xpathPrefix, $type = Zend_Feed_Reader::TYPE_ATOM_10)
 {
     $this->_domDocument = $source->ownerDocument;
     $this->_xpath = new DOMXPath($this->_domDocument);
     $this->_data['type'] = $type;
     $this->_registerNamespaces();
     $this->_loadExtensions();
     $atomClass = Zend_Feed_Reader::getPluginLoader()->getClassName('Atom_Feed');
     $this->_extensions['Atom_Feed'] = new $atomClass($this->_domDocument, $this->_data['type'], $this->_xpath);
     $atomClass = Zend_Feed_Reader::getPluginLoader()->getClassName('DublinCore_Feed');
     $this->_extensions['DublinCore_Feed'] = new $atomClass($this->_domDocument, $this->_data['type'], $this->_xpath);
     foreach ($this->_extensions as $extension) {
         $extension->setXpathPrefix(rtrim($xpathPrefix, '/') . '/atom:source');
     }
 }
Example #20
0
 /**
  * Overwrite the function define in the SiteMapInterface implement in Cible_Controller_Action
  *
  * This function return the sitemap specific for this module
  *
  * @access public
  *
  * @return a string containing xml sitemap
  */
 public function homepagelistAction()
 {
     $_blockID = $this->_request->getParam('BlockID');
     $languageID = Zend_Registry::get('languageID');
     $link = Cible_FunctionsBlocks::getBlockParameter($_blockID, $languageID);
     $linkMax = Cible_FunctionsBlocks::getBlockParameter($_blockID, 3);
     $block_info = Cible_FunctionsBlocks::getBlockDetails($_blockID);
     $db = Zend_Registry::get("db");
     $feed = Zend_Feed_Reader::import($link);
     $data = array('block_title' => $block_info["BI_BlockTitle"], 'linkMax' => $linkMax, 'title' => $feed->getTitle(), 'link' => $feed->getLink(), 'dateModified' => $feed->getDateModified(), 'description' => $feed->getDescription(), 'language' => $feed->getLanguage(), 'entries' => array());
     foreach ($feed as $entry) {
         $edata = array('title' => $entry->getTitle(), 'description' => $entry->getDescription(), 'dateModified' => $entry->getDateModified(), 'authors' => $entry->getAuthors(), 'link' => $entry->getLink(), 'content' => $entry->getContent());
         $data['entries'][] = $edata;
     }
     $this->view->data = $data;
 }
Example #21
0
 /**
  * Constructor
  *
  * @param  DOMDocument $dom
  * @param  string $type
  */
 public function __construct(DomDocument $dom, $type = null)
 {
     parent::__construct($dom, $type);
     $dublinCoreClass = Zend_Feed_Reader::getPluginLoader()->getClassName('DublinCore_Feed');
     $this->_extensions['DublinCore_Feed'] = new $dublinCoreClass($dom, $this->_data['type'], $this->_xpath);
     $atomClass = Zend_Feed_Reader::getPluginLoader()->getClassName('Atom_Feed');
     $this->_extensions['Atom_Feed'] = new $atomClass($dom, $this->_data['type'], $this->_xpath);
     if ($this->getType() !== Zend_Feed_Reader::TYPE_RSS_10 && $this->getType() !== Zend_Feed_Reader::TYPE_RSS_090) {
         $xpathPrefix = '/rss/channel';
     } else {
         $xpathPrefix = '/rdf:RDF/rss:channel';
     }
     foreach ($this->_extensions as $extension) {
         $extension->setXpathPrefix($xpathPrefix);
     }
 }
Example #22
0
 public function processAction()
 {
     if (!$this->getRequest() instanceof ZFExt_Controller_Request_Cli) {
         throw new Exception('Access denied from HTTP');
     }
     $this->getInvokeArg('bootstrap')->addOptionRules(array('key|k=s' => 'File keyname for task data (required)'));
     $options = $this->getInvokeArg('bootstrap')->getGetOpt();
     $path = APPLICATION_ROOT . '/store/updates/' . $options->key;
     $data = file_get_contents($path);
     $feed = Zend_Feed_Reader::importString($data);
     /**
      * TEMP: Improve when database added
      * Store update back to a file, this time using a serialized array
      * of its main data points so changes can be tracked.
      */
     $store = array('title' => $feed->getTitle(), 'id' => $feed->getId(), 'modified_date' => $feed->getDateModified(), 'link' => $feed->getLink());
     file_put_contents(APPLICATION_ROOT . '/store/updates/' . md5($store['id']), serialize($store));
     unlink($path);
 }
Example #23
0
 /**
  * Constructor
  *
  * @param  Zend_Feed_Entry_Abstract $entry
  * @param  int $entryKey
  * @param  string $type
  * @return void
  */
 public function __construct(DOMElement $entry, $entryKey, $type = null)
 {
     $this->_entry = $entry;
     $this->_entryKey = $entryKey;
     $this->_domDocument = $entry->ownerDocument;
     if ($type !== null) {
         $this->_data['type'] = $type;
     } else {
         $this->_data['type'] = Zend_Feed_Reader::detectType($entry->ownerDocument, true);
     }
     // set the XPath query prefix for the entry being queried
     if ($this->getType() == Zend_Feed_Reader::TYPE_RSS_10 || $this->getType() == Zend_Feed_Reader::TYPE_RSS_090) {
         $this->setXpathPrefix('//rss:item[' . ($this->_entryKey + 1) . ']');
     } elseif ($this->getType() == Zend_Feed_Reader::TYPE_ATOM_10 || $this->getType() == Zend_Feed_Reader::TYPE_ATOM_03) {
         $this->setXpathPrefix('//atom:entry[' . ($this->_entryKey + 1) . ']');
     } else {
         $this->setXpathPrefix('//item[' . ($this->_entryKey + 1) . ']');
     }
 }
Example #24
0
 /**
  * @param $itemId
  * @return array|bool
  */
 function get_entry($itemId)
 {
     global $prefs;
     $arguments = array('content' => 'bib');
     if (!empty($prefs['zotero_style'])) {
         $arguments['style'] = $prefs['zotero_style'];
     }
     $oauthlib = TikiLib::lib('oauth');
     $response = $oauthlib->do_request('zotero', array('url' => "https://api.zotero.org/groups/{$prefs['zotero_group_id']}/items/" . urlencode($itemId), 'get' => $arguments));
     if ($response->isSuccessful()) {
         $entry = $response->getBody();
         $entry = str_replace('<entry ', '<feed xmlns="http://www.w3.org/2005/Atom"><entry ', $entry) . '</feed>';
         $feed = Zend_Feed_Reader::importString($entry);
         foreach ($feed as $entry) {
             return array('key' => basename($entry->getLink()), 'url' => $entry->getLink(), 'title' => $entry->getTitle(), 'content' => $entry->getContent());
         }
     }
     return false;
 }
Example #25
0
 protected function _subscribe($topic)
 {
     try {
         $feed = Zend_Feed_Reader::import($topic);
     } catch (Zend_Exception $e) {
         return false;
     }
     /**
      * Must use the URI of the feed contained in the feed itself in
      * case the original is no longer valid (e.g. feed moved and we just
      * followed a redirect to the new URI)
      */
     $feedTopicUri = $feed->getFeedLink();
     if (empty($feedTopicUri)) {
         $feedTopicUri = $topic;
     }
     /**
      * The feed may advertise one or more Hub Endpoints we can use.
      * We may subscribe to the Topic using one or more of the Hub
      * Endpoints advertised (good idea in case a Hub goes down).
      */
     $feedHubs = $feed->getHubs();
     if (is_null($feedHubs) || empty($feedHubs)) {
         return false;
     }
     /**
      * Carry out subscription operation...
      */
     $storage = new Zend_Feed_Pubsubhubbub_Storage_Filesystem();
     $storage->setDirectory(APPLICATION_ROOT . '/store/subscriptions');
     $options = array('topicUrl' => $feedTopicUri, 'hubUrls' => $feedHubs, 'storage' => $storage, 'callbackUrl' => 'http://hub.survivethedeepend.com/callback', 'usePathParameter' => true, 'authentications' => array('http://superfeedr.com/hubbub' => array('padraicb', 'password')));
     $subscriber = new Zend_Feed_Pubsubhubbub_Subscriber($options);
     $subscriber->subscribeAll();
     /**
      * Do some checking for errors...
      */
     if (!$subscriber->isSuccess()) {
         var_dump($subscriber->getErrors());
         exit;
     }
     return true;
 }
Example #26
0
 /**
  * Retrieve items from content source.
  * @return int Number of items retrieved
  */
 function fetch()
 {
     if ($this->_disabled) {
         return 0;
     }
     $this->_items = array();
     // reset
     $frontendOptions = array('lifetime' => 7200, 'automatic_serialization' => true);
     $backendOptions = array('cache_dir' => $this->_config->cacheDir);
     $cache = Zend_Cache::factory('Core', 'File', $frontendOptions, $backendOptions);
     Zend_Feed_Reader::setCache($cache);
     Zend_Feed_Reader::useHttpConditionalGet();
     $classname = $this->_getItemClass();
     foreach (Zend_Feed_Reader::import($this->_config->url) as $entry) {
         $this->_items[] = new $classname($entry, $this->_config->items);
     }
     uasort($this->_items, array('Polycast_Stalker', 'sortItems'));
     $this->_items = array_slice($this->_items, 0, $this->_config->limit, true);
     return count($this->_items);
 }
 /**
  * Fetch blogs content from rss/atom feed
  * */
 public function fetchBlogs()
 {
     foreach (Default_Model_BlogTable::getInstance()->findByLive(true) as $blog) {
         echo PHP_EOL . 'fetching blog: ' . $blog->feed . PHP_EOL;
         try {
             $rss = Zend_Feed_Reader::import($blog->feed);
         } catch (Exception $e) {
             echo ' ! cannot read feed' . PHP_EOL;
             $rss = array();
         }
         foreach ($rss as $item) {
             $tags = $this->getTags($item->getTitle() . ' ' . $item->getContent());
             if (empty($tags)) {
                 continue;
             }
             //FIXME we sometime have empty content, just drop these post while it's fixed (this is not a mission critical project :)
             $content = $this->cleanContent($item->getContent());
             if (strlen($content) < 20) {
                 continue;
             }
             $post = new Default_Model_BlogPost();
             $post['blog_id'] = $blog->id;
             $post['title'] = $item->getTitle();
             $post['content'] = $this->cleanContent($item->getContent());
             $post['url'] = $item->getLink();
             $post['posted_on'] = date('Y-m-d H:i:s', $item->getDateCreated()->getTimestamp());
             $post['guid'] = $item->getId();
             $post['tags'] = Zend_Json::encode($tags);
             try {
                 $post->save();
                 echo ' > ' . $post['title'] . PHP_EOL;
             } catch (Exception $e) {
                 if (preg_match('/^(SQLSTATE\\[23000\\]|SQLSTATE\\[HY000\\])/i', $e->getMessage())) {
                     //noop don't stop on duplicate
                 } else {
                     throw $e;
                 }
             }
         }
     }
 }
Example #28
0
 /**
  * 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
  */
 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 {
         require_once 'Zend/Feed/Pubsubhubbub/Exception.php';
         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');
     }
     $atom = $feed->getExtension('Atom');
     $hubs = array();
     $list = $atom->getXpath()->evaluate($atom->getXpathPrefix() . '//atom:link[@rel="hub"]/@href');
     if ($list->length) {
         foreach ($list as $url) {
             $hubs[] = $url->nodeValue;
         }
     }
     return $hubs;
 }
Example #29
0
 public function getImages($offset)
 {
     if (!$this->_images) {
         $this->_images = array();
         try {
             if (empty($offset)) {
                 $offset = 0;
             } else {
                 $offset += 1;
             }
             //                $orig_offset = $offset;
             $this->_setPicasaUrl($offset);
             $feed = Zend_Feed_Reader::import($this->getLink());
         } catch (Exception $e) {
             $feed = array();
         }
         $images = array();
         foreach ($feed as $key => $entry) {
             /**
              * @bug Solution provisoire en attendant que Google règle le problème du start-index
              */
             //                if($key < $offset) continue;
             $author = $entry->getAuthor();
             $image = '';
             foreach ($entry->getElement()->getElementsByTagName('content') as $content) {
                 $src = (string) $content->getAttribute('src');
                 if (!empty($src)) {
                     $image = $src;
                 }
             }
             $this->_images[] = new Core_Model_Default(array('offset' => ++$offset, 'title' => $entry->getTitle(), 'description' => $entry->getDescription(), 'author' => $author['name'], 'image' => $image));
             /**
              * @bug Solution provisoire en attendant que Google règle le problème du start-index
              */
             //                if($offset >= $orig_offset + self::DISPLAYED_PER_PAGE) break;
         }
     }
     return $this->_images;
 }
Example #30
0
 /**
  * Récupère les vidéos youtube
  *
  * @param string $search
  * @return array
  */
 public function getList($search)
 {
     if (!$this->_videos) {
         $this->_videos = array();
         try {
             $video_id = $search;
             if (Zend_Uri::check($search)) {
                 $params = Zend_Uri::factory($search)->getQueryAsArray();
                 if (!empty($params['v'])) {
                     $video_id = $params['v'];
                 }
             }
             $api_key = Api_Model_Key::findKeysFor('youtube')->getApiKey();
             $url = "https://www.googleapis.com/youtube/v3/videos?id={$video_id}&key={$api_key}&part=snippet,contentDetails,status";
             $datas = @file_get_contents($url);
             if ($datas && !empty($datas['pageInfo']['totalResults'])) {
                 $datas = Zend_Json::decode($datas);
                 $feed = array();
                 foreach ($datas['items'] as $item) {
                     $feed[] = new Core_Model_Default(array('title' => !empty($item['snippet']['title']) ? $item['snippet']['title'] : null, 'content' => !empty($item['snippet']['description']) ? $item['snippet']['description'] : null, 'link' => "http://www.youtube.com/watch?v={$video_id}"));
                 }
             } else {
                 $this->_setYoutubeUrl($search);
                 $feed = Zend_Feed_Reader::import($this->getLink());
             }
         } catch (Exception $e) {
             $feed = array();
         }
         foreach ($feed as $entry) {
             $params = Zend_Uri::factory($entry->getLink())->getQueryAsArray();
             if (empty($params['v'])) {
                 continue;
             }
             $video = new Core_Model_Default(array('id' => $params['v'], 'title' => $entry->getTitle(), 'description' => $entry->getContent(), 'link' => "http://www.youtube.com/embed/{$params['v']}", 'image' => "http://img.youtube.com/vi/{$params['v']}/0.jpg"));
             $this->_videos[] = $video;
         }
     }
     return $this->_videos;
 }