Пример #1
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);
     }
 }
Пример #2
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);
 }
Пример #3
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;
 }
 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());
 }
Пример #5
0
 /**
  * @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());
 }
Пример #6
0
 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()));
 }
Пример #7
0
 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());
 }
Пример #8
0
 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());
 }
Пример #9
0
 public function testGetsIconFromAtom10_None()
 {
     $feed = Zend_Feed_Reader::importString(file_get_contents($this->_feedSamplePath . '/icon/plain/none/atom10.xml'));
     $this->assertEquals(null, $feed->getIcon());
 }
Пример #10
0
 public function testGetsImageFromRss090_None()
 {
     $feed = Zend_Feed_Reader::importString(file_get_contents($this->_feedSamplePath . '/image/plain/none/rss090.xml'));
     $this->assertEquals(null, $feed->getImage());
 }
Пример #11
0
 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);
 }
Пример #12
0
 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());
 }
Пример #13
0
 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'));
 }
Пример #14
0
 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());
 }
Пример #17
0
 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());
 }
Пример #18
0
 /**
  * @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());
 }
Пример #19
0
 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());
 }