/** * 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); $result = $xpath->query('//result/weblog'); if ($result->length == 1) { $this->weblog = new Weblog($result->item(0)); } else { // follow the same behavior of blogPostTags // and raise an Exception if the URL is not a valid weblog throw new Exception\RuntimeException("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 = Utils::normalizeUriHttp($result->item(0)->data); } catch (Exception $e) { if ($this->getWeblog() instanceof 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; } }
/** * Constructs a new object object from DOM Element. * * @param DomElement $dom the ReST fragment for this object */ public function __construct(DomElement $dom) { $this->fields = array('permalink' => 'permalink', 'excerpt' => 'excerpt', 'created' => 'created', 'title' => 'title'); parent::__construct($dom); // weblog object field $this->parseWeblog(); // filter fields $this->permalink = Utils::normalizeUriHttp($this->permalink); $this->created = Utils::normalizeDate($this->created); }
/** * @return void */ public function testSetUriHttpInputInvalidSchemeFtpThrowsException() { $scheme = 'ftp'; $inputInvalidScheme = "{$scheme}://example.com"; try { Technorati\Utils::normalizeUriHttp($inputInvalidScheme); $this->fail('Expected Zend\\Service\\Technorati\\Exception not thrown'); } catch (Technorati\Exception\RuntimeException $e) { $this->assertContains($scheme, $e->getMessage()); } }
/** * Constructs a new object object from DOM Element. * * @param DomElement $dom the ReST fragment for this object */ public function __construct(DomElement $dom) { $this->fields = array('nearestPermalink' => 'nearestpermalink', 'excerpt' => 'excerpt', 'linkCreated' => 'linkcreated', 'linkUrl' => 'linkurl'); parent::__construct($dom); // weblog object field $this->parseWeblog(); // filter fields $this->nearestPermalink = Utils::normalizeUriHttp($this->nearestPermalink); $this->linkUrl = Utils::normalizeUriHttp($this->linkUrl); $this->linkCreated = Utils::normalizeDate($this->linkCreated); }
/** * 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/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 = Utils::normalizeUriHttp($result->item(0)->data); } $this->totalResultsReturned = (int) $this->xpath->evaluate("count(/tapi/document/items/item)"); $this->totalResultsAvailable = (int) $this->getDays(); }
/** * 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/inboundlinks/text()'); if ($result->length == 1) { $this->inboundLinks = (int) $result->item(0)->data; } $result = $this->xpath->query('/tapi/document/result/inboundblogs/text()'); if ($result->length == 1) { $this->inboundBlogs = (int) $result->item(0)->data; } $result = $this->xpath->query('/tapi/document/result/weblog'); if ($result->length == 1) { $this->weblog = new Weblog($result->item(0)); } $result = $this->xpath->query('/tapi/document/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 = Utils::normalizeUriHttp($result->item(0)->data); } catch (Exception $e) { if ($this->getWeblog() instanceof Weblog) { $this->url = $this->getWeblog()->getUrl(); } } } $this->totalResultsReturned = (int) $this->xpath->evaluate("count(/tapi/document/item)"); // total number of results depends on query type // for now check only getInboundLinks() and getInboundBlogs() value if ((int) $this->getInboundLinks() > 0) { $this->totalResultsAvailable = $this->getInboundLinks(); } elseif ((int) $this->getInboundBlogs() > 0) { $this->totalResultsAvailable = $this->getInboundBlogs(); } else { $this->totalResultsAvailable = 0; } }
/** * Sets weblog Atom URL. * * @param string|\Zend\Uri\Http $url * @return Weblog $this instance * @throws Exception\RuntimeException if $input is an invalid URI * (via Utils::normalizeUriHttp) */ public function setAtomUrl($url) { $this->atomUrl = Utils::normalizeUriHttp($url); return $this; }
/** * Sets Technorati account thumbnail picture. * * @param string|\Zend\Uri\Http $input thumbnail picture URI * @return Author $this instance * @throws Exception\RuntimeException if $input is an invalid URI * (via Utils::normalizeUriHttp) */ public function setThumbnailPicture($input) { $this->thumbnailPicture = Utils::normalizeUriHttp($input); return $this; }