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); } }
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); }
/** * @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; }
public function testGetEncoding() { $feed = Zend_Feed_Reader::importString(file_get_contents(dirname(__FILE__) . '/Reader/Entry/_files/Atom/title/plain/atom10.xml')); $this->assertEquals('utf-8', $feed->getEncoding()); $this->assertEquals('utf-8', $feed->current()->getEncoding()); }
/** * @group ZFWCHARDATA01 */ public function testCategoriesCharDataEncoding() { $this->_validEntry->addCategories(array(array('term' => '<>&\'"áéíóú', 'label' => 'Cats & Dogs', 'scheme' => 'http://example.com/schema1'), array('term' => 'cat_dog2'))); $renderer = new Zend_Feed_Writer_Renderer_Feed_Rss($this->_validWriter); $feed = Zend_Feed_Reader::importString($renderer->render()->saveXml()); $entry = $feed->current(); $expected = array(array('term' => '<>&\'"áéíóú', 'label' => '<>&\'"áéíóú', 'scheme' => 'http://example.com/schema1'), array('term' => 'cat_dog2', 'label' => 'cat_dog2', 'scheme' => null)); $this->assertEquals($expected, (array) $entry->getCategories()); }
public function testGetsCategoriesFromRss10_None() { $feed = Zend_Feed_Reader::importString(file_get_contents($this->_feedSamplePath . '/category/plain/none/rss10.xml')); $entry = $feed->current(); $this->assertEquals(array(), (array) $entry->getCategories()); $this->assertEquals(array(), array_values($entry->getCategories()->getValues())); }
public function testGetsEnclosure() { $feed = Zend_Feed_Reader::importString(file_get_contents($this->_feedSamplePath)); $entry = $feed->current(); $expected = new stdClass(); $expected->url = 'http://example.com/podcasts/everything/AllAboutEverythingEpisode3.m4a'; $expected->length = '8727310'; $expected->type = 'audio/x-m4a'; $this->assertEquals($expected, $entry->getEnclosure()); }
public function testFeedIdDefaultIsUsedIfNotSetByHand() { $atomFeed = new Zend_Feed_Writer_Renderer_Feed_Atom($this->_validWriter); $atomFeed->render(); $feed = Zend_Feed_Reader::importString($atomFeed->saveXml()); $this->assertEquals($feed->getLink(), $feed->getId()); }
public function testGetsIconFromAtom10_None() { $feed = Zend_Feed_Reader::importString(file_get_contents($this->_feedSamplePath . '/icon/plain/none/atom10.xml')); $this->assertEquals(null, $feed->getIcon()); }
public function testGetsImageFromRss090_None() { $feed = Zend_Feed_Reader::importString(file_get_contents($this->_feedSamplePath . '/image/plain/none/rss090.xml')); $this->assertEquals(null, $feed->getImage()); }
public function testXxePreventionOnFeedParsing() { $string = file_get_contents($this->_feedSamplePath . '/Reader/xxe-atom10.xml'); $string = str_replace('XXE_URI', $this->_feedSamplePath . '/Reader/xxe-info.txt', $string); $this->setExpectedException('Zend_Feed_Exception'); $feed = Zend_Feed_Reader::importString($string); }
public function testHubsCanBeSet() { $this->_validWriter->addHubs(array('http://www.example.com/hub', 'http://www.example.com/hub2')); $rssFeed = new Zend_Feed_Writer_Renderer_Feed_Rss($this->_validWriter); $rssFeed->render(); $feed = Zend_Feed_Reader::importString($rssFeed->saveXml()); $expected = array('http://www.example.com/hub', 'http://www.example.com/hub2'); $this->assertEquals($expected, (array) $feed->getHubs()); }
public function testCommentFeedLinksRendered() { $renderer = new Zend_Feed_Writer_Renderer_Feed_Atom($this->_validWriter); $this->_validEntry->setCommentFeedLinks(array(array('uri' => 'http://www.example.com/atom/id/1', 'type' => 'atom'), array('uri' => 'http://www.example.com/rss/id/1', 'type' => 'rss'))); $feed = Zend_Feed_Reader::importString($renderer->render()->saveXml()); $entry = $feed->current(); // Skipped over due to ZFR bug (detects Atom in error when RSS requested) //$this->assertEquals('http://www.example.com/rss/id/1', $entry->getCommentFeedLink('rss')); $this->assertEquals('http://www.example.com/atom/id/1', $entry->getCommentFeedLink('atom')); }
private function update_feed($rssId, $url, $actions) { global $tikilib; $filter = new DeclFilter(); $filter->addStaticKeyFilters(array('url' => 'url', 'title' => 'striptags', 'author' => 'striptags', 'description' => 'striptags', 'content' => 'purifier')); $guidFilter = TikiFilter::get('url'); try { $content = $tikilib->httprequest($url); $feed = Zend_Feed_Reader::importString($content); } catch (Zend_Exception $e) { $this->modules->update(array('lastUpdated' => $tikilib->now, 'sitetitle' => 'N/A', 'siteurl' => '#'), array('rssId' => $rssId)); return; } $siteTitle = TikiFilter::get('striptags')->filter($feed->getTitle()); $siteUrl = TikiFilter::get('url')->filter($feed->getLink()); $this->modules->update(array('lastUpdated' => $tikilib->now, 'sitetitle' => $siteTitle, 'siteurl' => $siteUrl), array('rssId' => $rssId)); foreach ($feed as $entry) { // TODO: optimize. Atom entries have an 'updated' element which can be used to only update updated entries $guid = $guidFilter->filter($entry->getId()); $authors = $entry->getAuthors(); $data = $filter->filter(array('title' => $entry->getTitle(), 'url' => $entry->getLink(), 'description' => $entry->getDescription(), 'content' => $entry->getContent(), 'author' => $authors ? implode(', ', $authors->getValues()) : '')); $data['guid'] = $guid; if (method_exists($entry, 'getDateCreated') && ($createdDate = $entry->getDateCreated())) { $data['publication_date'] = $createdDate->get(Zend_Date::TIMESTAMP); } else { global $tikilib; $data['publication_date'] = $tikilib->now; } $count = $this->items->fetchCount(array('rssId' => $rssId, 'guid' => $guid)); if (0 == $count) { $this->insert_item($rssId, $data, $actions); } else { $this->update_item($rssId, $data['guid'], $data); } } }
/** * Get category data */ public function testGetsCategoriesFromAtom10() { $feed = Zend_Feed_Reader::importString(file_get_contents($this->_feedSamplePath . '/category/atom10.xml')); $source = $feed->current()->getSource(); $this->assertEquals($this->_expectedCats, (array) $source->getCategories()); $this->assertEquals(array('topic1', 'Cat & Dog'), array_values($source->getCategories()->getValues())); }
public function testGetsEntryEncoding() { $feed = Zend_Feed_Reader::importString(file_get_contents($this->_feedSamplePath)); $entry = $feed->current(); $this->assertEquals('UTF-8', $entry->getEncoding()); }
public function testIconCanBeSet() { $this->_validWriter->setIcon(array('uri' => 'http://www.example.com/logo.gif')); $atomFeed = new Zend_Feed_Writer_Renderer_Feed_Atom($this->_validWriter); $atomFeed->render(); $feed = Zend_Feed_Reader::importString($atomFeed->saveXml()); $expected = array('uri' => 'http://www.example.com/logo.gif'); $this->assertEquals($expected, $feed->getIcon()); }
/** * @group ZF-8213 */ public function testReturnsEncodingOfFeedAsUtf8IfUndefined() { $feed = Zend_Feed_Reader::importString(file_get_contents($this->_feedSamplePath . '/atom_noencodingdefined.xml')); $this->assertEquals('UTF-8', $feed->getEncoding()); }
public function testImageCanBeSetWithOnlyRequiredElements() { $this->_validWriter->setImage(array('uri' => 'http://www.example.com/logo.gif', 'link' => 'http://www.example.com', 'title' => 'Image ALT')); $rssFeed = new Zend_Feed_Writer_Renderer_Feed_Rss($this->_validWriter); $rssFeed->render(); $feed = Zend_Feed_Reader::importString($rssFeed->saveXml()); $expected = array('uri' => 'http://www.example.com/logo.gif', 'link' => 'http://www.example.com', 'title' => 'Image ALT'); $this->assertEquals($expected, $feed->getImage()); }