本文整理汇总了PHP中Zend_Feed_Reader::importString方法的典型用法代码示例。如果您正苦于以下问题:PHP Zend_Feed_Reader::importString方法的具体用法?PHP Zend_Feed_Reader::importString怎么用?PHP Zend_Feed_Reader::importString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend_Feed_Reader
的用法示例。
在下文中一共展示了Zend_Feed_Reader::importString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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);
}
}
示例2: processAction
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: get_entry
/**
* @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;
}
示例4: testGetEncoding
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: testCategoriesCharDataEncoding
/**
* @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: testGetsCategoriesFromRss10_None
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: testGetsEnclosure
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: testFeedIdDefaultIsUsedIfNotSetByHand
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: testGetsIconFromAtom10_None
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: testGetsImageFromRss090_None
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: testXxePreventionOnFeedParsing
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: testHubsCanBeSet
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: testCommentFeedLinksRendered
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: update_feed
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);
}
}
}
示例15: testGetsCategoriesFromAtom10
/**
* 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()));
}