/library/Zend/Service/Technorati/BlogInfoResult.php

https://bitbucket.org/hamidrezas/melobit · PHP · 161 lines · 50 code · 20 blank · 91 comment · 10 complexity · e7c8924edb85cb5dd6fe30403dfcac43 MD5 · raw file

  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend_Service
  17. * @subpackage Technorati
  18. * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id: BlogInfoResult.php 24594 2012-01-05 21:27:01Z matthew $
  21. */
  22. /**
  23. * @see Zend_Service_Technorati_Utils
  24. */
  25. require_once 'Zend/Service/Technorati/Utils.php';
  26. /**
  27. * Represents a single Technorati BlogInfo query result object.
  28. *
  29. * @category Zend
  30. * @package Zend_Service
  31. * @subpackage Technorati
  32. * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
  33. * @license http://framework.zend.com/license/new-bsd New BSD License
  34. */
  35. class Zend_Service_Technorati_BlogInfoResult
  36. {
  37. /**
  38. * Technorati weblog url, if queried URL is a valid weblog.
  39. *
  40. * @var Zend_Uri_Http
  41. * @access protected
  42. */
  43. protected $_url;
  44. /**
  45. * Technorati weblog, if queried URL is a valid weblog.
  46. *
  47. * @var Zend_Service_Technorati_Weblog
  48. * @access protected
  49. */
  50. protected $_weblog;
  51. /**
  52. * Number of unique blogs linking this blog
  53. *
  54. * @var integer
  55. * @access protected
  56. */
  57. protected $_inboundBlogs;
  58. /**
  59. * Number of incoming links to this blog
  60. *
  61. * @var integer
  62. * @access protected
  63. */
  64. protected $_inboundLinks;
  65. /**
  66. * Constructs a new object object from DOM Document.
  67. *
  68. * @param DomDocument $dom the ReST fragment for this object
  69. */
  70. public function __construct(DomDocument $dom)
  71. {
  72. $xpath = new DOMXPath($dom);
  73. /**
  74. * @see Zend_Service_Technorati_Weblog
  75. */
  76. require_once 'Zend/Service/Technorati/Weblog.php';
  77. $result = $xpath->query('//result/weblog');
  78. if ($result->length == 1) {
  79. $this->_weblog = new Zend_Service_Technorati_Weblog($result->item(0));
  80. } else {
  81. // follow the same behavior of blogPostTags
  82. // and raise an Exception if the URL is not a valid weblog
  83. /**
  84. * @see Zend_Service_Technorati_Exception
  85. */
  86. require_once 'Zend/Service/Technorati/Exception.php';
  87. throw new Zend_Service_Technorati_Exception(
  88. "Your URL is not a recognized Technorati weblog");
  89. }
  90. $result = $xpath->query('//result/url/text()');
  91. if ($result->length == 1) {
  92. try {
  93. // fetched URL often doens't include schema
  94. // and this issue causes the following line to fail
  95. $this->_url = Zend_Service_Technorati_Utils::normalizeUriHttp($result->item(0)->data);
  96. } catch(Zend_Service_Technorati_Exception $e) {
  97. if ($this->getWeblog() instanceof Zend_Service_Technorati_Weblog) {
  98. $this->_url = $this->getWeblog()->getUrl();
  99. }
  100. }
  101. }
  102. $result = $xpath->query('//result/inboundblogs/text()');
  103. if ($result->length == 1) $this->_inboundBlogs = (int) $result->item(0)->data;
  104. $result = $xpath->query('//result/inboundlinks/text()');
  105. if ($result->length == 1) $this->_inboundLinks = (int) $result->item(0)->data;
  106. }
  107. /**
  108. * Returns the weblog URL.
  109. *
  110. * @return Zend_Uri_Http
  111. */
  112. public function getUrl() {
  113. return $this->_url;
  114. }
  115. /**
  116. * Returns the weblog.
  117. *
  118. * @return Zend_Service_Technorati_Weblog
  119. */
  120. public function getWeblog() {
  121. return $this->_weblog;
  122. }
  123. /**
  124. * Returns number of unique blogs linking this blog.
  125. *
  126. * @return integer the number of inbound blogs
  127. */
  128. public function getInboundBlogs()
  129. {
  130. return (int) $this->_inboundBlogs;
  131. }
  132. /**
  133. * Returns number of incoming links to this blog.
  134. *
  135. * @return integer the number of inbound links
  136. */
  137. public function getInboundLinks()
  138. {
  139. return (int) $this->_inboundLinks;
  140. }
  141. }