当前位置: 首页>>代码示例>>PHP>>正文


PHP Zend_Feed::importString方法代码示例

本文整理汇总了PHP中Zend_Feed::importString方法的典型用法代码示例。如果您正苦于以下问题:PHP Zend_Feed::importString方法的具体用法?PHP Zend_Feed::importString怎么用?PHP Zend_Feed::importString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Zend_Feed的用法示例。


在下文中一共展示了Zend_Feed::importString方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: testCanGetItemRss2OutputItem

 public function testCanGetItemRss2OutputItem()
 {
     $this->dispatch('items/browse?output=rss2');
     $string = $this->response->getBody();
     try {
         $feed = Zend_Feed::importString($string);
     } catch (Zend_Feed_Exception $e) {
         $this->fail("Feed does not load properly.");
     }
     $item = $feed->current();
     if (!$item) {
         $this->fail("Feed does not have an item");
     }
 }
开发者ID:emhoracek,项目名称:Omeka,代码行数:14,代码来源:ItemRss2Test.php

示例2: import

 public function import($feed)
 {
     // download XML
     try {
         $xml = $this->_fetch($feed->url);
         $rss = Zend_Feed::importString($xml);
     } catch (Exception $e) {
         throw new Yadda_Feed_Exception('Error getting feed: ' . (string) $e);
     }
     $stubs = array();
     // iterate over each entry
     foreach ($rss as $entry) {
         $stub = new Yadda_Feed_Stub();
         $guid = $entry->guid();
         if (empty($guid)) {
             $guid = $entry->link();
         }
         $stub->setGuid($guid);
         $title = trim(html_entity_decode($entry->title(), ENT_QUOTES, 'utf-8'));
         $stub->setTitle($title);
         $stub->setLink($entry->link());
         $description = trim(html_entity_decode(strip_tags($entry->description()), ENT_QUOTES, 'utf-8'));
         if (!empty($description)) {
             $stub->setDescription($description);
         }
         $date = $entry->pubDate();
         if (!empty($date)) {
             $stub->setDate(date('Y-m-d H:i:s', strtotime($date)));
         }
         $price = $this->_getPrice($title . ' ' . (string) $description);
         if ($price !== null) {
             $stub->setPrice($price);
         }
         // images
         $description = $entry->description();
         if (!empty($description)) {
             $matches = array();
             preg_match_all('#src="(https?://[^"]+)"#', $description, $matches);
             if (isset($matches[1]) && sizeof($matches[1]) > 0) {
                 $stub->addImage($matches[1][0]);
             }
         }
         $stubs[] = $stub;
     }
     return $stubs;
 }
开发者ID:neilgarb,项目名称:yadda,代码行数:46,代码来源:Rss.php

示例3: __construct

 public function __construct($xml = null)
 {
     if ($xml) {
         // first, lets find the cmis namespace to use
         $sx = new SimpleXMLElement($xml);
         $namespaces = $sx->getDocNamespaces();
         $ns = isset($namespaces['cmis']) ? $namespaces['cmis'] : 'http://docs.oasis-open.org/ns/cmis/core/200901';
         // go through the XML and pull out the things we're interested in
         Zend_Feed::registerNamespace('cmis', $ns);
         // 'http://www.cmis.org/2008/05');
         $this->rawXml = $xml;
         $feed = Zend_Feed::importString($this->rawXml);
         foreach ($feed as $item) {
             $this->loadFromFeed($item);
         }
     }
 }
开发者ID:nyeholt,项目名称:silverstripe-cmis-connector,代码行数:17,代码来源:SeaMistObject.php

示例4: __construct

 function __construct($xml)
 {
     parent::__construct();
     if ($xml) {
         // first, lets find the cmis namespace to use
         $sx = new SimpleXMLElement($xml);
         $namespaces = $sx->getDocNamespaces();
         $ns = isset($namespaces['cmis']) ? $namespaces['cmis'] : 'http://docs.oasis-open.org/ns/cmis/core/200901';
         // go through the entries and create some objects
         Zend_Feed::registerNamespace('cmis', $ns);
         // 'http://www.cmis.org/2008/05');
         $this->rawXml = $xml;
         $feed = Zend_Feed::importString($this->rawXml);
         foreach ($feed as $entry) {
             $obj = new SeaMistObject();
             $obj->loadFromFeed($entry);
             $this[] = $obj;
         }
     }
 }
开发者ID:nyeholt,项目名称:silverstripe-cmis-connector,代码行数:20,代码来源:SeaMistObjectList.php

示例5: testAtomGetLink

 /**
  * Test the return of a link() call (atom)
  */
 public function testAtomGetLink()
 {
     $feed = Zend_Feed::importBuilder(new Zend_Feed_Builder($this->_getFullArray()), 'atom');
     $this->assertTrue($feed instanceof Zend_Feed_Atom);
     $feed = Zend_Feed::importString($feed->saveXML());
     $this->assertTrue($feed instanceof Zend_Feed_Atom);
     $href = $feed->link('self');
     $this->assertTrue($href == 'http://www.example.com');
 }
开发者ID:jorgenils,项目名称:zend-framework,代码行数:12,代码来源:ImportTest.php

示例6: search

 /**
  * Performs a Twitter search query.
  *
  * @throws Zend_Http_Client_Exception
  */
 public function search($query, array $params = array())
 {
     $_query = array();
     $_query['q'] = $query;
     foreach ($params as $key => $param) {
         switch ($key) {
             case 'geocode':
             case 'lang':
             case 'since_id':
                 $_query[$key] = $param;
                 break;
             case 'rpp':
                 $_query[$key] = intval($param) > 100 ? 100 : intval($param);
                 break;
             case 'page':
                 $_query[$key] = intval($param);
                 break;
             case 'show_user':
                 $_query[$key] = 'true';
         }
     }
     $response = $this->restGet('/search.' . $this->_responseType, $_query);
     switch ($this->_responseType) {
         case 'json':
             return Zend_Json::decode($response->getBody());
             break;
         case 'atom':
             return Zend_Feed::importString($response->getBody());
             break;
     }
     return;
 }
开发者ID:Simarpreet05,项目名称:joomla,代码行数:37,代码来源:Search.php

示例7: testAtomGetLink

 /**
  * Test the return of a link() call (atom)
  */
 public function testAtomGetLink()
 {
     $feed = Zend_Feed::importBuilder(new Zend_Feed_Builder($this->_getFullArray()), 'atom');
     $this->assertType('Zend_Feed_Atom', $feed);
     $feed = Zend_Feed::importString($feed->saveXml());
     $this->assertType('Zend_Feed_Atom', $feed);
     $href = $feed->link('self');
     $this->assertEquals('http://www.example.com', $href);
 }
开发者ID:travisj,项目名称:zf,代码行数:12,代码来源:ImportTest.php

示例8: parseFeed

 /**
  * Handles (RSS & Atom) Type.FEED parsing using Zend's feed parser
  *
  * @param RemoteContentRequest $result
  * @param string $url
  * @param int $numEntries
  * @param boolean $getSummaries
  * @return response string, either a json encoded feed structure or an error message
  */
 private function parseFeed($result, $url, $numEntries = 3, $getSummaries = false)
 {
     require 'external/Zend/Feed.php';
     $channel = array();
     if ((int) $result->getHttpCode() == 200) {
         $content = $result->getResponseContent();
         try {
             $feed = Zend_Feed::importString($content);
             if ($feed instanceof Zend_Feed_Rss) {
                 // Try get author
                 if ($feed->author()) {
                     $author = $feed->author();
                 } else {
                     if ($feed->creator()) {
                         $author = $feed->creator();
                     } else {
                         $author = null;
                     }
                 }
                 // Loop over each channel item and store relevant data
                 $counter = 0;
                 $channel['Entry'] = array();
                 foreach ($feed as $item) {
                     if ($counter >= $numEntries) {
                         break;
                     }
                     $_entry = array();
                     $_entry['Title'] = $item->title();
                     $_entry['Link'] = $item->link();
                     if (!is_string($_entry['Link']) && isset($_entry['Link'][1]) && $_entry['Link'][1] instanceof DOMElement) {
                         $_entry['Link'] = $_entry['Link'][1]->getAttribute('href');
                     }
                     if ($getSummaries && $item->description()) {
                         $_entry['Summary'] = $item->description();
                     }
                     $date = 0;
                     if ($item->date()) {
                         $date = strtotime($item->date());
                     } else {
                         if ($item->pubDate()) {
                             $date = strtotime($item->pubDate());
                         }
                     }
                     $_entry['Date'] = $date;
                     $channel['Entry'][] = $_entry;
                     // Remember author if first found
                     if (empty($author) && $item->author()) {
                         $author = $item->author();
                     } else {
                         if ($item->creator()) {
                             $author = $item->creator();
                         }
                     }
                     $counter++;
                 }
                 $channel['Title'] = $feed->title();
                 $channel['URL'] = $url;
                 $channel['Description'] = $feed->description();
                 if ($feed->link()) {
                     if (is_array($feed->link())) {
                         foreach ($feed->link() as $_link) {
                             if ($_link->nodeValue) {
                                 $channel['Link'] = $_link->nodeValue;
                             }
                         }
                     } else {
                         $channel['Link'] = $feed->link();
                     }
                 }
                 if ($author != null) {
                     $channel['Author'] = $author;
                 }
             } elseif ($feed instanceof Zend_Feed_Atom) {
                 // Try get author
                 if ($feed->author()) {
                     if ($feed->author->name()) {
                         $author = $feed->author->name();
                     } else {
                         if ($feed->author->email()) {
                             $author = $feed->author->email();
                         } else {
                             $author = $feed->author();
                         }
                     }
                 } else {
                     $author = null;
                 }
                 // Loop over each entries and store relevant data
                 $counter = 0;
                 $channel['Entry'] = array();
                 foreach ($feed as $entry) {
//.........这里部分代码省略.........
开发者ID:newlongwhitecloudy,项目名称:OpenConext-engineblock,代码行数:101,代码来源:MakeRequest.php

示例9: fetchJson

 /**
  * Fetches content and returns it in JSON format
  *
  * @param string $url the url to fetch
  * @param GadgetSigner $signer the request signer to use
  * @param string $method the http method to use (get or post) in making the request
  */
 public function fetchJson($url, $signer, $method)
 {
     try {
         $token = $this->context->extractAndValidateToken($signer);
     } catch (Exception $e) {
         $token = '';
         // no token given, safe to ignore
     }
     $url = $this->validateUrl($url);
     // Fetch the content and convert it into JSON.
     // TODO: Fetcher needs to handle variety of HTTP methods.
     $result = $this->fetchContentDivert($url, $method, $signer);
     if (!isset($result)) {
         //OAuthFetcher only
         $metadata = $this->oauthFetcher->getResponseMetadata();
         $json = array($url => $metadata);
         $json = json_encode($json);
         $output = UNPARSEABLE_CRUFT . $json;
         $this->setCachingHeaders();
         header("Content-Type: application/json; charset=utf-8", true);
         echo $output;
         $this->end();
     }
     $status = (int) $result->getHttpCode();
     //header("HTTP/1.1 $status", true);
     if ($status == 200) {
         $output = '';
         if (isset($_REQUEST['contentType']) && $_REQUEST['contentType'] == 'FEED') {
             require 'external/Zend/Feed.php';
             $numEntries = $_REQUEST['numEntries'];
             $getSummaries = !empty($_REQUEST['getSummaries']) && $_REQUEST['getSummaries'] != 'false' ? true : false;
             $channel = array();
             $request = new RemoteContentRequest($url);
             $request = $this->context->getHttpFetcher()->fetch($request, $this->context);
             if ((int) $result->getHttpCode() == 200) {
                 $content = $result->getResponseContent();
                 try {
                     $feed = Zend_Feed::importString($content);
                     if ($feed instanceof Zend_Feed_Rss) {
                         // Try get author
                         if ($feed->author()) {
                             $author = $feed->author();
                         } else {
                             if ($feed->creator()) {
                                 $author = $feed->creator();
                             } else {
                                 $author = null;
                             }
                         }
                         // Loop over each channel item and store relevant data
                         $counter = 0;
                         $channel['Entry'] = array();
                         foreach ($feed as $item) {
                             if ($counter >= $numEntries) {
                                 break;
                             }
                             $_entry = array();
                             $_entry['Title'] = $item->title();
                             $_entry['Link'] = $item->link();
                             if ($getSummaries && $item->description()) {
                                 $_entry['Summary'] = $item->description();
                             }
                             $date = 0;
                             if ($item->date()) {
                                 $date = strtotime($item->date());
                             } else {
                                 if ($item->pubDate()) {
                                     $date = strtotime($item->pubDate());
                                 }
                             }
                             $_entry['Date'] = $date;
                             $channel['Entry'][] = $_entry;
                             // Remember author if first found
                             if (empty($author) && $item->author()) {
                                 $author = $item->author();
                             } else {
                                 if ($item->creator()) {
                                     $author = $item->creator();
                                 }
                             }
                             $counter++;
                         }
                         $channel['Title'] = $feed->title();
                         $channel['URL'] = $url;
                         $channel['Description'] = $feed->description();
                         if ($feed->link()) {
                             if (is_array($feed->link())) {
                                 foreach ($feed->link() as $_link) {
                                     if ($_link->nodeValue) {
                                         $channel['Link'] = $_link->nodeValue;
                                     }
                                 }
                             } else {
//.........这里部分代码省略.........
开发者ID:jakob-stoeck,项目名称:os_poker,代码行数:101,代码来源:ProxyHandler.php

示例10: fetchJson

 /**
  * Fetches content and returns it in JSON format
  *
  * @param string $url the url to fetch
  * @param GadgetSigner $signer the request signer to use
  * @param string $method the http method to use (get or post) in making the request
  */
 public function fetchJson($url, $signer, $method)
 {
     try {
         $token = $this->context->extractAndValidateToken($signer);
     } catch (Exception $e) {
         $token = '';
         // no token given, safe to ignore
     }
     $url = $this->validateUrl($url);
     // Fetch the content and convert it into JSON.
     // TODO: Fetcher needs to handle variety of HTTP methods.
     $result = $this->fetchContentDivert($url, $method, $signer);
     if (!isset($result)) {
         //OAuthFetcher only
         $metadata = $this->oauthFetcher->getResponseMetadata();
         $json = array($url => $metadata);
         $json = json_encode($json);
         $output = UNPARSEABLE_CRUFT . $json;
         $this->setCachingHeaders();
         header("Content-Type: application/json; charset=utf-8", true);
         echo $output;
         die;
     }
     $status = (int) $result->getHttpCode();
     //header("HTTP/1.1 $status", true);
     if ($status == 200) {
         $output = '';
         if (isset($_GET['contentType']) && $_GET['contentType'] == 'FEED') {
             require 'src/common/Zend/Feed.php';
             $numEntries = $_GET['numEntries'];
             $getSummaries = $_GET['getSummaries'];
             $channel = array();
             $request = new RemoteContentRequest($url);
             $request = $this->context->getHttpFetcher()->fetch($request, $this->context);
             if ((int) $result->getHttpCode() == 200) {
                 $content = $result->getResponseContent();
                 try {
                     $feed = Zend_Feed::importString($content);
                     if ($feed instanceof Zend_Feed_Rss) {
                         $channel = array('title' => $feed->title(), 'link' => $feed->link(), 'description' => $feed->description(), 'pubDate' => $feed->pubDate(), 'language' => $feed->language(), 'category' => $feed->category(), 'items' => array());
                         // Loop over each channel item and store relevant data
                         $counter = 0;
                         foreach ($feed as $item) {
                             if ($counter >= $numEntries) {
                                 break;
                             }
                             $counter++;
                             $channel['items'][] = array('title' => $item->title(), 'link' => $item->link(), 'author' => $item->author(), 'description' => $getSummaries ? $item->description() : '', 'category' => $item->category(), 'comments' => $item->comments(), 'pubDate' => $item->pubDate());
                         }
                     } elseif ($feed instanceof Zend_Feed_Atom) {
                         $channel = array('title' => $feed->title(), 'link' => $feed->link(), 'id' => $feed->id(), 'subtitle' => $feed->subtitle(), 'items' => array());
                         $counter = 0;
                         foreach ($feed as $entry) {
                             if ($counter >= $numEntries) {
                                 break;
                             }
                             $channel['items'][] = array('id' => $entry->id(), 'title' => $entry->title(), 'link' => $entry->link(), 'summary' => $entry->summary(), 'content' => $entry->content(), 'author' => $entry->author(), 'published' => $entry->published(), 'updated' => $entry->updated());
                         }
                     } else {
                         throw new Exception('Invalid feed type');
                     }
                     $resp = json_encode($channel);
                 } catch (Zend_Feed_Exception $e) {
                     $resp = 'Error parsing feed: ' . $e->getMessage();
                 }
             } else {
                 // feed import failed
                 $resp = "Error fetching feed, response code: " . $result->getHttpCode();
             }
         } else {
             $resp = $result->getResponseContent();
         }
         $json = array($url => array('body' => $resp, 'rc' => $status));
         $json = json_encode($json);
         $output = UNPARSEABLE_CRUFT . $json;
         $this->setCachingHeaders();
         header("Content-Type: application/json; charset=utf-8", true);
         echo $output;
     } else {
         @ob_end_clean();
         header("HTTP/1.0 404 Not Found", true);
         echo "<html><body><h1>404 - Not Found</h1></body></html>";
     }
     die;
 }
开发者ID:ahmedadham88,项目名称:enhanced-social-network,代码行数:92,代码来源:ProxyHandler.php

示例11: uploadAction

 /**
  * Upload action
  * 
  * Handles atom file uploading, not pretty but gets the work done for now.
  * 
  * @return void
  */
 public function uploadAction()
 {
     try {
         $this->_helper->viewRenderer->setNoRender();
         $feed = Zend_Feed::importString($this->_request->getRawBody());
     } catch (Exception $e) {
         $this->_response->setHttpResponseCode(400);
         // 415 unsuported media?
         $this->_response->setHeader('Status', '400 Unable to read feed', true);
         $this->view->errorMessages = array('Unable to read feed');
         return $this->_forward('error');
     }
     $photoModel = $this->_getPhotoModel();
     $id = null;
     foreach ($feed as $entry) {
         //
         // Entry is related to another entry
         //
         if (isset($entry->link)) {
             // Set description
             if ('' != $entry->content() && $entry->content->offsetGet('mode') == 'xml') {
                 $description = (string) $entry->content;
             }
             // Set tags
             if ('' != ($tags = $entry->{"dc:subject"})) {
                 $tags = implode(',', explode(' ', $tags));
             }
             $entryData = array();
             if (!is_array($entry->link)) {
                 $id = $entry->link('related');
                 $photo = $photoModel->fetchEntry($id);
                 $entryData = $photo->toArray();
                 $entryData['description'] = $description;
                 $entryData['tags'] = $tags;
                 $photoModel->update($entryData, $id);
             } else {
                 foreach ($entry->link as $link) {
                     $id = $link->getDom()->getAttribute('href');
                     try {
                         $photo = $photoModel->fetchEntry($id);
                         $entryData = $photo->toArray();
                         $entryData['description'] = $description;
                         $entryData['tags'] = $tags;
                         $photoModel->update($entryData, $id);
                     } catch (Exception $e) {
                         // TODO: Log....
                     }
                 }
             }
             //
             // A new entry is uploaded
             //
         } else {
             if ('' != $entry->content()) {
                 $file = $this->_createTmpFile(base64_decode($entry->content()));
                 $entryData = array();
                 $entryData['title'] = $entry->title;
                 $entryData['created_on'] = date('Y-m-d H:i:s', strtotime($entry->issued));
                 $id = $photoModel->add($entryData, $file);
             } else {
                 continue;
             }
         }
         $url = 'http://' . $this->_request->getHttpHost() . $this->_request->getBaseUrl();
         $this->_response->setHttpResponseCode(201);
         $this->_response->setHeader('Status', '201 Created');
         $this->_response->setHeader('Location', $url . $this->_helper->url('show', 'photo', null, array('id' => $id)));
         $this->view->url = $url;
         $this->view->photo = $photoModel->fetchEntry($id);
         $this->render('upload');
     }
 }
开发者ID:johannilsson,项目名称:yag,代码行数:79,代码来源:AtomController.php

示例12: read

 /**
  * Reads the content of the RSS feed and cache it in the database
  * @return Zend_Feed_Abstract - the feed object
  * @throws FeedReadException in case of failure
  */
 public function read($feedId)
 {
     $rowSet = $this->find($feedId);
     if (!count($rowSet)) {
         throw new FeedReadException("Feed id {$feedId} not found in db.");
     }
     $row = $rowSet->current();
     $cache = $this->getFeedsCache();
     if (!($xml = $cache->load($feedId))) {
         $xml = file_get_contents($row->url);
         if (!$xml) {
             throw new FeedReadException("Failed retrieving content for feed " . $row->url);
         }
         $date = new Zend_Date();
         $row->updated = $date->get(Zend_Date::W3C);
         $cache->save($xml, $feedId);
     }
     try {
         $feed = Zend_Feed::importString($xml);
     } catch (Zend_Exception $e) {
         return null;
     }
     return $feed;
 }
开发者ID:BGCX261,项目名称:zportal-svn-to-git,代码行数:29,代码来源:Feeds.php


注:本文中的Zend_Feed::importString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。