diff -r 5b37998e522e -r 162c1de6545a web/lib/Zend/Service/Technorati/Result.php --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/web/lib/Zend/Service/Technorati/Result.php Fri Mar 11 15:05:35 2011 +0100 @@ -0,0 +1,121 @@ + '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); + } +}