?
SearchResultSet.php 0000666 00000005126 15125353743 0010355 0 ustar 00 <?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Service
* @subpackage Technorati
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: SearchResultSet.php 8064 2008-02-16 10:58:39Z thomas $
*/
/**
* @see Zend_Service_Technorati_ResultSet
*/
require_once 'Zend/Service/Technorati/ResultSet.php';
/**
* Represents a Technorati Search query result set.
*
* @category Zend
* @package Zend_Service
* @subpackage Technorati
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Service_Technorati_SearchResultSet extends Zend_Service_Technorati_ResultSet
{
/**
* Number of query results.
*
* @var int
* @access protected
*/
protected $_queryCount;
/**
* Parses the search response and retrieve the results for iteration.
*
* @param DomDocument $dom the ReST fragment for this object
* @param array $options query options as associative array
*/
public function __construct(DomDocument $dom, $options = array())
{
parent::__construct($dom, $options);
$result = $this->_xpath->query('/tapi/document/result/querycount/text()');
if ($result->length == 1) $this->_queryCount = (int) $result->item(0)->data;
$this->_totalResultsReturned = (int) $this->_xpath->evaluate("count(/tapi/document/item)");
$this->_totalResultsAvailable = (int) $this->_queryCount;
}
/**
* Implements Zend_Service_Technorati_ResultSet::current().
*
* @return Zend_Service_Technorati_SearchResult current result
*/
public function current()
{
/**
* @see Zend_Service_Technorati_SearchResult
*/
require_once 'Zend/Service/Technorati/SearchResult.php';
return new Zend_Service_Technorati_SearchResult($this->_results->item($this->_currentIndex));
}
}
BlogInfoResult.php 0000666 00000011230 15125353743 0010164 0 ustar 00 <?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Service
* @subpackage Technorati
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: BlogInfoResult.php 8064 2008-02-16 10:58:39Z thomas $
*/
/**
* @see Zend_Service_Technorati_Utils
*/
require_once 'Zend/Service/Technorati/Utils.php';
/**
* Represents a single Technorati BlogInfo query result object.
*
* @category Zend
* @package Zend_Service
* @subpackage Technorati
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Service_Technorati_BlogInfoResult
{
/**
* Technorati weblog url, if queried URL is a valid weblog.
*
* @var Zend_Uri_Http
* @access protected
*/
protected $_url;
/**
* Technorati weblog, if queried URL is a valid weblog.
*
* @var Zend_Service_Technorati_Weblog
* @access protected
*/
protected $_weblog;
/**
* Number of unique blogs linking this blog
*
* @var integer
* @access protected
*/
protected $_inboundBlogs;
/**
* Number of incoming links to this blog
*
* @var integer
* @access protected
*/
protected $_inboundLinks;
/**
* Constructs a new object object from DOM Document.
*
* @param DomDocument $dom the ReST fragment for this object
*/
public function __construct(DomDocument $dom)
{
$xpath = new DOMXPath($dom);
/**
* @see Zend_Service_Technorati_Weblog
*/
require_once 'Zend/Service/Technorati/Weblog.php';
$result = $xpath->query('//result/weblog');
if ($result->length == 1) {
$this->_weblog = new Zend_Service_Technorati_Weblog($result->item(0));
} else {
// follow the same behavior of blogPostTags
// and raise an Exception if the URL is not a valid weblog
/**
* @see Zend_Service_Technorati_Exception
*/
require_once 'Zend/Service/Technorati/Exception.php';
throw new Zend_Service_Technorati_Exception(
"Your URL is not a recognized Technorati weblog");
}
$result = $xpath->query('//result/url/text()');
if ($result->length == 1) {
try {
// fetched URL often doens't include schema
// and this issue causes the following line to fail
$this->_url = Zend_Service_Technorati_Utils::normalizeUriHttp($result->item(0)->data);
} catch(Zend_Service_Technorati_Exception $e) {
if ($this->getWeblog() instanceof Zend_Service_Technorati_Weblog) {
$this->_url = $this->getWeblog()->getUrl();
}
}
}
$result = $xpath->query('//result/inboundblogs/text()');
if ($result->length == 1) $this->_inboundBlogs = (int) $result->item(0)->data;
$result = $xpath->query('//result/inboundlinks/text()');
if ($result->length == 1) $this->_inboundLinks = (int) $result->item(0)->data;
}
/**
* Returns the weblog URL.
*
* @return Zend_Uri_Http
*/
public function getUrl() {
return $this->_url;
}
/**
* Returns the weblog.
*
* @return Zend_Service_Technorati_Weblog
*/
public function getWeblog() {
return $this->_weblog;
}
/**
* Returns number of unique blogs linking this blog.
*
* @return integer the number of inbound blogs
*/
public function getInboundBlogs()
{
return (int) $this->_inboundBlogs;
}
/**
* Returns number of incoming links to this blog.
*
* @return integer the number of inbound links
*/
public function getInboundLinks()
{
return (int) $this->_inboundLinks;
}
}
TagsResult.php 0000666 00000004771 15125353743 0007377 0 ustar 00 <?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Service
* @subpackage Technorati
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: TagsResult.php 8064 2008-02-16 10:58:39Z thomas $
*/
/**
* @see Zend_Service_Technorati_Result
*/
require_once 'Zend/Service/Technorati/Result.php';
/**
* Represents a single Technorati TopTags or BlogPostTags query result object.
* It is never returned as a standalone object,
* but it always belongs to a valid Zend_Service_Technorati_TagsResultSet object.
*
* @category Zend
* @package Zend_Service
* @subpackage Technorati
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Service_Technorati_TagsResult extends Zend_Service_Technorati_Result
{
/**
* Name of the tag.
*
* @var string
* @access protected
*/
protected $_tag;
/**
* Number of posts containing this tag.
*
* @var int
* @access protected
*/
protected $_posts;
/**
* Constructs a new object object from DOM Document.
*
* @param DomElement $dom the ReST fragment for this object
*/
public function __construct(DomElement $dom)
{
$this->_fields = array( '_tag' => 'tag',
'_posts' => 'posts');
parent::__construct($dom);
// filter fields
$this->_tag = (string) $this->_tag;
$this->_posts = (int) $this->_posts;
}
/**
* Returns the tag name.
*
* @return string
*/
public function getTag() {
return $this->_tag;
}
/**
* Returns the number of posts.
*
* @return int
*/
public function getPosts() {
return $this->_posts;
}
}
Exception.php 0000666 00000002306 15125353743 0007230 0 ustar 00 <?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Service
* @subpackage Technorati
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Exception.php 8064 2008-02-16 10:58:39Z thomas $
*/
/**
* @see Zend_Service_Exception
*/
require_once 'Zend/Service/Exception.php';
/**
* @category Zend
* @package Zend_Service
* @subpackage Technorati
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Service_Technorati_Exception extends Zend_Service_Exception
{}
GetInfoResult.php 0000666 00000005520 15125353743 0010025 0 ustar 00 <?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Service
* @subpackage Technorati
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: GetInfoResult.php 8064 2008-02-16 10:58:39Z thomas $
*/
/**
* Represents a single Technorati GetInfo query result object.
*
* @category Zend
* @package Zend_Service
* @subpackage Technorati
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Service_Technorati_GetInfoResult
{
/**
* Technorati author
*
* @var Zend_Service_Technorati_Author
* @access protected
*/
protected $_author;
/**
* A list of weblogs claimed by this author
*
* @var array
* @access protected
*/
protected $_weblogs = array();
/**
* Constructs a new object object from DOM Document.
*
* @param DomDocument $dom the ReST fragment for this object
*/
public function __construct(DomDocument $dom)
{
$xpath = new DOMXPath($dom);
/**
* @see Zend_Service_Technorati_Author
*/
require_once 'Zend/Service/Technorati/Author.php';
$result = $xpath->query('//result');
if ($result->length == 1) {
$this->_author = new Zend_Service_Technorati_Author($result->item(0));
}
/**
* @see Zend_Service_Technorati_Weblog
*/
require_once 'Zend/Service/Technorati/Weblog.php';
$result = $xpath->query('//item/weblog');
if ($result->length >= 1) {
foreach ($result as $weblog) {
$this->_weblogs[] = new Zend_Service_Technorati_Weblog($weblog);
}
}
}
/**
* Returns the author associated with queried username.
*
* @return Zend_Service_Technorati_Author
*/
public function getAuthor() {
return $this->_author;
}
/**
* Returns the collection of weblogs authored by queried username.
*
* @return array of Zend_Service_Technorati_Weblog
*/
public function getWeblogs() {
return $this->_weblogs;
}
}
KeyInfoResult.php 0000666 00000006376 15125353743 0010050 0 ustar 00 <?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Service
* @subpackage Technorati
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: KeyInfoResult.php 8064 2008-02-16 10:58:39Z thomas $
*/
/**
* Represents a single Technorati KeyInfo query result object.
* It provides information about your Technorati API Key daily usage.
*
* @category Zend
* @package Zend_Service
* @subpackage Technorati
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Service_Technorati_KeyInfoResult
{
/**
* Technorati API key
*
* @var string
* @access protected
*/
protected $_apiKey;
/**
* Number of queries used today
*
* @var int
* @access protected
*/
protected $_apiQueries;
/**
* Total number of available queries per day
*
* @var int
* @access protected
*/
protected $_maxQueries;
/**
* Constructs a new object from DOM Element.
* Parses given Key element from $dom and sets API key string.
*
* @param DomElement $dom the ReST fragment for this object
* @param string $apiKey the API Key string
*/
public function __construct(DomDocument $dom, $apiKey = null)
{
// $this->_dom = $dom;
// $this->_xpath = new DOMXPath($dom);
$xpath = new DOMXPath($dom);
$this->_apiQueries = (int) $xpath->query('/tapi/document/result/apiqueries/text()')->item(0)->data;
$this->_maxQueries = (int) $xpath->query('/tapi/document/result/maxqueries/text()')->item(0)->data;
$this->setApiKey($apiKey);
}
/**
* Returns API Key string.
*
* @return string API Key string
*/
public function getApiKey() {
return $this->_apiKey;
}
/**
* Returns the number of queries sent today.
*
* @return int number of queries sent today
*/
public function getApiQueries() {
return $this->_apiQueries;
}
/**
* Returns Key's daily query limit.
*
* @return int maximum number of available queries per day
*/
public function getMaxQueries() {
return $this->_maxQueries;
}
/**
* Sets API Key string.
*
* @param string $apiKey the API Key
* @return Zend_Service_Technorati_KeyInfoResult $this instance
*/
public function setApiKey($apiKey) {
$this->_apiKey = $apiKey;
return $this;
}
}
DailyCountsResultSet.php 0000666 00000007311 15125353743 0011404 0 ustar 00 <?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Service
* @subpackage Technorati
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: DailyCountsResultSet.php 8064 2008-02-16 10:58:39Z thomas $
*/
/**
* @see Zend_Date
*/
require_once 'Zend/Date.php';
/**
* @see Zend_Service_Technorati_ResultSet
*/
require_once 'Zend/Service/Technorati/ResultSet.php';
/**
* @see Zend_Service_Technorati_Utils
*/
require_once 'Zend/Service/Technorati/Utils.php';
/**
* Represents a Technorati Tag query result set.
*
* @category Zend
* @package Zend_Service
* @subpackage Technorati
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Service_Technorati_DailyCountsResultSet extends Zend_Service_Technorati_ResultSet
{
/**
* Technorati search URL for given query.
*
* @var Zend_Uri_Http
* @access protected
*/
protected $_searchUrl;
/**
* Number of days for which counts provided.
*
* @var Zend_Service_Technorati_Weblog
* @access protected
*/
protected $_days;
/**
* Parses the search response and retrieve the results for iteration.
*
* @param DomDocument $dom the ReST fragment for this object
* @param array $options query options as associative array
*/
public function __construct(DomDocument $dom, $options = array())
{
parent::__construct($dom, $options);
// default locale prevent Zend_Date to fail
// when script is executed via shell
// Zend_Locale::setDefault('en');
$result = $this->_xpath->query('/tapi/document/result/days/text()');
if ($result->length == 1) $this->_days = (int) $result->item(0)->data;
$result = $this->_xpath->query('/tapi/document/result/searchurl/text()');
if ($result->length == 1) {
$this->_searchUrl = Zend_Service_Technorati_Utils::normalizeUriHttp($result->item(0)->data);
}
$this->_totalResultsReturned = (int) $this->_xpath->evaluate("count(/tapi/document/items/item)");
$this->_totalResultsAvailable = (int) $this->getDays();
}
/**
* Returns the search URL for given query.
*
* @return Zend_Uri_Http
*/
public function getSearchUrl() {
return $this->_searchUrl;
}
/**
* Returns the number of days for which counts provided.
*
* @return int
*/
public function getDays() {
return $this->_days;
}
/**
* Implements Zend_Service_Technorati_ResultSet::current().
*
* @return Zend_Service_Technorati_DailyCountsResult current result
*/
public function current()
{
/**
* @see Zend_Service_Technorati_DailyCountsResult
*/
require_once 'Zend/Service/Technorati/DailyCountsResult.php';
return new Zend_Service_Technorati_DailyCountsResult($this->_results->item($this->_currentIndex));
}
}
Result.php 0000666 00000007074 15125353743 0006557 0 ustar 00 <?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Service
* @subpackage Technorati
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Result.php 8064 2008-02-16 10:58:39Z thomas $
*/
/**
* Represents a single Technorati Search query result object.
* It is never returned as a standalone object,
* but it always belongs to a valid Zend_Service_Technorati_SearchResultSet object.
*
* @category Zend
* @package Zend_Service
* @subpackage Technorati
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @abstract
*/
abstract class Zend_Service_Technorati_Result
{
/**
* An associative array of 'fieldName' => 'xmlfieldtag'
*
* @var array
* @access protected
*/
protected $_fields;
/**
* The ReST fragment for this result object
*
* @var DomElement
* @access protected
*/
protected $_dom;
/**
* Object for $this->_dom
*
* @var DOMXpath
* @access protected
*/
protected $_xpath;
/**
* Constructs a new object from DOM Element.
* Properties are automatically fetched from XML
* according to array of $_fields to be read.
*
* @param DomElement $result the ReST fragment for this object
*/
public function __construct(DomElement $dom)
{
$this->_xpath = new DOMXPath($dom->ownerDocument);
$this->_dom = $dom;
// default fields for all search results
$fields = array();
// merge with child's object fields
$this->_fields = array_merge($this->_fields, $fields);
// add results to appropriate fields
foreach($this->_fields as $phpName => $xmlName) {
$query = "./$xmlName/text()";
$node = $this->_xpath->query($query, $this->_dom);
if ($node->length == 1) {
$this->{$phpName} = (string) $node->item(0)->data;
}
}
}
/**
* Parses weblog node and sets weblog object.
*
* @return void
*/
protected function _parseWeblog()
{
// weblog object field
$result = $this->_xpath->query('./weblog', $this->_dom);
if ($result->length == 1) {
/**
* @see Zend_Service_Technorati_Weblog
*/
require_once 'Zend/Service/Technorati/Weblog.php';
$this->_weblog = new Zend_Service_Technorati_Weblog($result->item(0));
} else {
$this->_weblog = null;
}
}
/**
* Returns the document fragment for this object as XML string.
*
* @return string the document fragment for this object
* converted into XML format
*/
public function getXml()
{
return $this->_dom->ownerDocument->saveXML($this->_dom);
}
}
TagsResultSet.php 0000666 00000004315 15125353743 0010045 0 ustar 00 <?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Service
* @subpackage Technorati
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: TagsResultSet.php 8064 2008-02-16 10:58:39Z thomas $
*/
/**
* @see Zend_Service_Technorati_ResultSet
*/
require_once 'Zend/Service/Technorati/ResultSet.php';
/**
* Represents a Technorati TopTags or BlogPostTags queries result set.
*
* @category Zend
* @package Zend_Service
* @subpackage Technorati
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Service_Technorati_TagsResultSet extends Zend_Service_Technorati_ResultSet
{
/**
* Constructs a new object object from DOM Document.
*
* @param DomDocument $dom the ReST fragment for this object
*/
public function __construct(DomDocument $dom, $options = array())
{
parent::__construct($dom, $options);
$this->_totalResultsReturned = (int) $this->_xpath->evaluate("count(/tapi/document/item)");
$this->_totalResultsAvailable = (int) $this->_totalResultsReturned;
}
/**
* Implements Zend_Service_Technorati_ResultSet::current().
*
* @return Zend_Service_Technorati_TagsResult current result
*/
public function current()
{
/**
* @see Zend_Service_Technorati_TagsResult
*/
require_once 'Zend/Service/Technorati/TagsResult.php';
return new Zend_Service_Technorati_TagsResult($this->_results->item($this->_currentIndex));
}
}
Utils.php 0000666 00000010456 15125353743 0006377 0 ustar 00 <?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Service
* @subpackage Technorati
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Utils.php 8064 2008-02-16 10:58:39Z thomas $
*/
/**
* Collection of utilities for various Zend_Service_Technorati classes.
*
* @category Zend
* @package Zend_Service
* @subpackage Technorati
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Service_Technorati_Utils
{
/**
* Parses, validates and returns a valid Zend_Uri object
* from given $input.
*
* @param string|Zend_Uri_Http $input
* @return null|Zend_Uri_Http
* @throws Zend_Service_Technorati_Exception
* @static
*/
public static function normalizeUriHttp($input)
{
// allow null as value
if ($input === null) {
return null;
}
/**
* @see Zend_Uri
*/
require_once 'Zend/Uri.php';
if ($input instanceof Zend_Uri_Http) {
$uri = $input;
} else {
try {
$uri = Zend_Uri::factory((string) $input);
}
// wrap exception under Zend_Service_Technorati_Exception object
catch (Exception $e) {
/**
* @see Zend_Service_Technorati_Exception
*/
require_once 'Zend/Service/Technorati/Exception.php';
throw new Zend_Service_Technorati_Exception($e->getMessage());
}
}
// allow inly Zend_Uri_Http objects or child classes
if (!($uri instanceof Zend_Uri_Http)) {
/**
* @see Zend_Service_Technorati_Exception
*/
require_once 'Zend/Service/Technorati/Exception.php';
throw new Zend_Service_Technorati_Exception(
"Invalid URL $uri, only HTTP(S) protocols can be used");
}
return $uri;
}
/**
* Parses, validates and returns a valid Zend_Date object
* from given $input.
*
* $input can be either a string, an integer or a Zend_Date object.
* If $input is string or int, it will be provided to Zend_Date as it is.
* If $input is a Zend_Date object, the object instance will be returned.
*
* @param mixed|Zend_Date $input
* @return null|Zend_Date
* @throws Zend_Service_Technorati_Exception
* @static
*/
public static function normalizeDate($input)
{
/**
* @see Zend_Date
*/
require_once 'Zend/Date.php';
/**
* @see Zend_Locale
*/
require_once 'Zend/Locale.php';
// allow null as value and return valid Zend_Date objects
if (($input === null) || ($input instanceof Zend_Date)) {
return $input;
}
// due to a BC break as of ZF 1.5 it's not safe to use Zend_Date::isDate() here
// see ZF-2524, ZF-2334
if (@strtotime($input) !== FALSE) {
return new Zend_Date($input);
} else {
/**
* @see Zend_Service_Technorati_Exception
*/
require_once 'Zend/Service/Technorati/Exception.php';
throw new Zend_Service_Technorati_Exception("'$input' is not a valid Date/Time");
}
}
/**
* @todo public static function xpathQueryAndSet() {}
*/
/**
* @todo public static function xpathQueryAndSetIf() {}
*/
/**
* @todo public static function xpathQueryAndSetUnless() {}
*/
}
ResultSet.php 0000666 00000017237 15125353743 0007235 0 ustar 00 <?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Service
* @subpackage Technorati
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: ResultSet.php 8064 2008-02-16 10:58:39Z thomas $
*/
/**
* @see Zend_Service_Technorati_Result
*/
require_once 'Zend/Service/Technorati/Result.php';
/**
* This is the most essential result set.
* The scope of this class is to be extended by a query-specific child result set class,
* and it should never be used to initialize a standalone object.
*
* Each of the specific result sets represents a collection of query-specific
* Zend_Service_Technorati_Result objects.
*
* @category Zend
* @package Zend_Service
* @subpackage Technorati
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @abstract
*/
abstract class Zend_Service_Technorati_ResultSet implements SeekableIterator
{
/**
* The total number of results available
*
* @var int
* @access protected
*/
protected $_totalResultsAvailable;
/**
* The number of results in this result set
*
* @var int
* @access protected
*/
protected $_totalResultsReturned;
/**
* The offset in the total result set of this search set
*
* @var int
* @todo
*/
// public $firstResultPosition;
/**
* A DomNodeList of results
*
* @var DomNodeList
* @access protected
*/
protected $_results;
/**
* Technorati API response document
*
* @var DomDocument
* @access protected
*/
protected $_dom;
/**
* Object for $this->_dom
*
* @var DOMXpath
* @access protected
*/
protected $_xpath;
/**
* XML string representation for $this->_dom
*
* @var string
* @access protected
*/
protected $_xml;
/**
* Current Item
*
* @var int
* @access protected
*/
protected $_currentIndex = 0;
/**
* Parses the search response and retrieves the results for iteration.
*
* @param DomDocument $dom the ReST fragment for this object
* @param array $options query options as associative array
*/
public function __construct(DomDocument $dom, $options = array())
{
$this->_init($dom, $options);
// Technorati loves to make developer's life really hard
// I must read query options in order to normalize a single way
// to display start and limit.
// The value is printed out in XML using many different tag names,
// too hard to get it from XML
// Additionally, the following tags should be always available
// according to API documentation but... this is not the truth!
// - querytime
// - limit
// - start (sometimes rankingstart)
// query tag is only available for some requests, the same for url.
// For now ignore them.
//$start = isset($options['start']) ? $options['start'] : 1;
//$limit = isset($options['limit']) ? $options['limit'] : 20;
//$this->_firstResultPosition = $start;
}
/**
* Initializes this object from a DomDocument response.
*
* Because __construct and __wakeup shares some common executions,
* it's useful to group them in a single initialization method.
* This method is called once each time a new instance is created
* or a serialized object is unserialized.
*
* @param DomDocument $dom the ReST fragment for this object
* @param array $options query options as associative array
* * @return void
*/
protected function _init(DomDocument $dom, $options = array())
{
$this->_dom = $dom;
$this->_xpath = new DOMXPath($dom);
$this->_results = $this->_xpath->query("//item");
}
/**
* Number of results returned.
*
* @return int total number of results returned
*/
public function totalResults()
{
return (int) $this->_totalResultsReturned;
}
/**
* Number of available results.
*
* @return int total number of available results
*/
public function totalResultsAvailable()
{
return (int) $this->_totalResultsAvailable;
}
/**
* Implements SeekableIterator::current().
*
* @return void
* @throws Zend_Service_Exception
* @abstract
*/
// abstract public function current();
/**
* Implements SeekableIterator::key().
*
* @return int
*/
public function key()
{
return $this->_currentIndex;
}
/**
* Implements SeekableIterator::next().
*
* @return void
*/
public function next()
{
$this->_currentIndex += 1;
}
/**
* Implements SeekableIterator::rewind().
*
* @return bool
*/
public function rewind()
{
$this->_currentIndex = 0;
return true;
}
/**
* Implement SeekableIterator::seek().
*
* @param int $index
* @return void
* @throws OutOfBoundsException
*/
public function seek($index)
{
$indexInt = (int) $index;
if ($indexInt >= 0 && $indexInt < $this->_results->length) {
$this->_currentIndex = $indexInt;
} else {
throw new OutOfBoundsException("Illegal index '$index'");
}
}
/**
* Implement SeekableIterator::valid().
*
* @return boolean
*/
public function valid()
{
return null !== $this->_results && $this->_currentIndex < $this->_results->length;
}
/**
* Returns the response document as XML string.
*
* @return string the response document converted into XML format
*/
public function getXml()
{
return $this->_dom->saveXML();
}
/**
* Overwrites standard __sleep method to make this object serializable.
*
* DomDocument and DOMXpath objects cannot be serialized.
* This method converts them back to an XML string.
*
* @return void
*/
public function __sleep() {
$this->_xml = $this->getXml();
$vars = array_keys(get_object_vars($this));
return array_diff($vars, array('_dom', '_xpath'));
}
/**
* Overwrites standard __wakeup method to make this object unserializable.
*
* Restores object status before serialization.
* Converts XML string into a DomDocument object and creates a valid
* DOMXpath instance for given DocDocument.
*
* @return void
*/
public function __wakeup() {
$dom = new DOMDocument();
$dom->loadXml($this->_xml);
$this->_init($dom);
$this->_xml = null; // reset XML content
}
}
Author.php 0000666 00000014761 15125353743 0006544 0 ustar 00 <?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Service
* @subpackage Technorati
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Author.php 8064 2008-02-16 10:58:39Z thomas $
*/
/**
* @see Zend_Service_Technorati_Utils
*/
require_once 'Zend/Service/Technorati/Utils.php';
/**
* Represents a weblog Author object. It usually belongs to a Technorati account.
*
* @category Zend
* @package Zend_Service
* @subpackage Technorati
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Service_Technorati_Author
{
/**
* Author first name
*
* @var string
* @access protected
*/
protected $_firstName;
/**
* Author last name
*
* @var string
* @access protected
*/
protected $_lastName;
/**
* Technorati account username
*
* @var string
* @access protected
*/
protected $_username;
/**
* Technorati account description
*
* @var string
* @access protected
*/
protected $_description;
/**
* Technorati account biography
*
* @var string
* @access protected
*/
protected $_bio;
/**
* Technorati account thumbnail picture URL, if any
*
* @var null|Zend_Uri_Http
* @access protected
*/
protected $_thumbnailPicture;
/**
* Constructs a new object from DOM Element.
*
* @param DomElement $dom the ReST fragment for this object
*/
public function __construct(DomElement $dom)
{
$xpath = new DOMXPath($dom->ownerDocument);
$result = $xpath->query('./firstname/text()', $dom);
if ($result->length == 1) $this->setFirstName($result->item(0)->data);
$result = $xpath->query('./lastname/text()', $dom);
if ($result->length == 1) $this->setLastName($result->item(0)->data);
$result = $xpath->query('./username/text()', $dom);
if ($result->length == 1) $this->setUsername($result->item(0)->data);
$result = $xpath->query('./description/text()', $dom);
if ($result->length == 1) $this->setDescription($result->item(0)->data);
$result = $xpath->query('./bio/text()', $dom);
if ($result->length == 1) $this->setBio($result->item(0)->data);
$result = $xpath->query('./thumbnailpicture/text()', $dom);
if ($result->length == 1) $this->setThumbnailPicture($result->item(0)->data);
}
/**
* Returns Author first name.
*
* @return string Author first name
*/
public function getFirstName() {
return $this->_firstName;
}
/**
* Returns Author last name.
*
* @return string Author last name
*/
public function getLastName() {
return $this->_lastName;
}
/**
* Returns Technorati account username.
*
* @return string Technorati account username
*/
public function getUsername() {
return $this->_username;
}
/**
* Returns Technorati account description.
*
* @return string Technorati account description
*/
public function getDescription() {
return $this->_description;
}
/**
* Returns Technorati account biography.
*
* @return string Technorati account biography
*/
public function getBio() {
return $this->_bio;
}
/**
* Returns Technorati account thumbnail picture.
*
* @return null|Zend_Uri_Http Technorati account thumbnail picture
*/
public function getThumbnailPicture() {
return $this->_thumbnailPicture;
}
/**
* Sets author first name.
*
* @param string $input first Name input value
* @return Zend_Service_Technorati_Author $this instance
*/
public function setFirstName($input) {
$this->_firstName = (string) $input;
return $this;
}
/**
* Sets author last name.
*
* @param string $input last Name input value
* @return Zend_Service_Technorati_Author $this instance
*/
public function setLastName($input) {
$this->_lastName = (string) $input;
return $this;
}
/**
* Sets Technorati account username.
*
* @param string $input username input value
* @return Zend_Service_Technorati_Author $this instance
*/
public function setUsername($input) {
$this->_username = (string) $input;
return $this;
}
/**
* Sets Technorati account biography.
*
* @param string $input biography input value
* @return Zend_Service_Technorati_Author $this instance
*/
public function setBio($input) {
$this->_bio = (string) $input;
return $this;
}
/**
* Sets Technorati account description.
*
* @param string $input description input value
* @return Zend_Service_Technorati_Author $this instance
*/
public function setDescription($input) {
$this->_description = (string) $input;
return $this;
}
/**
* Sets Technorati account thumbnail picture.
*
* @param string|Zend_Uri_Http $input thumbnail picture URI
* @return Zend_Service_Technorati_Author $this instance
* @throws Zend_Service_Technorati_Exception if $input is an invalid URI
* (via Zend_Service_Technorati_Utils::normalizeUriHttp)
*/
public function setThumbnailPicture($input) {
$this->_thumbnailPicture = Zend_Service_Technorati_Utils::normalizeUriHttp($input);
return $this;
}
}