|
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-2010 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 20096 2010-01-06 02:05:09Z bkarwin $ |
|
21 */ |
|
22 |
|
23 |
|
24 /** |
|
25 * @see Zend_Service_Technorati_Utils |
|
26 */ |
|
27 require_once 'Zend/Service/Technorati/Utils.php'; |
|
28 |
|
29 |
|
30 /** |
|
31 * Represents a single Technorati BlogInfo query result object. |
|
32 * |
|
33 * @category Zend |
|
34 * @package Zend_Service |
|
35 * @subpackage Technorati |
|
36 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) |
|
37 * @license http://framework.zend.com/license/new-bsd New BSD License |
|
38 */ |
|
39 class Zend_Service_Technorati_BlogInfoResult |
|
40 { |
|
41 /** |
|
42 * Technorati weblog url, if queried URL is a valid weblog. |
|
43 * |
|
44 * @var Zend_Uri_Http |
|
45 * @access protected |
|
46 */ |
|
47 protected $_url; |
|
48 |
|
49 /** |
|
50 * Technorati weblog, if queried URL is a valid weblog. |
|
51 * |
|
52 * @var Zend_Service_Technorati_Weblog |
|
53 * @access protected |
|
54 */ |
|
55 protected $_weblog; |
|
56 |
|
57 /** |
|
58 * Number of unique blogs linking this blog |
|
59 * |
|
60 * @var integer |
|
61 * @access protected |
|
62 */ |
|
63 protected $_inboundBlogs; |
|
64 |
|
65 /** |
|
66 * Number of incoming links to this blog |
|
67 * |
|
68 * @var integer |
|
69 * @access protected |
|
70 */ |
|
71 protected $_inboundLinks; |
|
72 |
|
73 |
|
74 /** |
|
75 * Constructs a new object object from DOM Document. |
|
76 * |
|
77 * @param DomDocument $dom the ReST fragment for this object |
|
78 */ |
|
79 public function __construct(DomDocument $dom) |
|
80 { |
|
81 $xpath = new DOMXPath($dom); |
|
82 /** |
|
83 * @see Zend_Service_Technorati_Weblog |
|
84 */ |
|
85 require_once 'Zend/Service/Technorati/Weblog.php'; |
|
86 |
|
87 $result = $xpath->query('//result/weblog'); |
|
88 if ($result->length == 1) { |
|
89 $this->_weblog = new Zend_Service_Technorati_Weblog($result->item(0)); |
|
90 } else { |
|
91 // follow the same behavior of blogPostTags |
|
92 // and raise an Exception if the URL is not a valid weblog |
|
93 /** |
|
94 * @see Zend_Service_Technorati_Exception |
|
95 */ |
|
96 require_once 'Zend/Service/Technorati/Exception.php'; |
|
97 throw new Zend_Service_Technorati_Exception( |
|
98 "Your URL is not a recognized Technorati weblog"); |
|
99 } |
|
100 |
|
101 $result = $xpath->query('//result/url/text()'); |
|
102 if ($result->length == 1) { |
|
103 try { |
|
104 // fetched URL often doens't include schema |
|
105 // and this issue causes the following line to fail |
|
106 $this->_url = Zend_Service_Technorati_Utils::normalizeUriHttp($result->item(0)->data); |
|
107 } catch(Zend_Service_Technorati_Exception $e) { |
|
108 if ($this->getWeblog() instanceof Zend_Service_Technorati_Weblog) { |
|
109 $this->_url = $this->getWeblog()->getUrl(); |
|
110 } |
|
111 } |
|
112 } |
|
113 |
|
114 $result = $xpath->query('//result/inboundblogs/text()'); |
|
115 if ($result->length == 1) $this->_inboundBlogs = (int) $result->item(0)->data; |
|
116 |
|
117 $result = $xpath->query('//result/inboundlinks/text()'); |
|
118 if ($result->length == 1) $this->_inboundLinks = (int) $result->item(0)->data; |
|
119 |
|
120 } |
|
121 |
|
122 |
|
123 /** |
|
124 * Returns the weblog URL. |
|
125 * |
|
126 * @return Zend_Uri_Http |
|
127 */ |
|
128 public function getUrl() { |
|
129 return $this->_url; |
|
130 } |
|
131 |
|
132 /** |
|
133 * Returns the weblog. |
|
134 * |
|
135 * @return Zend_Service_Technorati_Weblog |
|
136 */ |
|
137 public function getWeblog() { |
|
138 return $this->_weblog; |
|
139 } |
|
140 |
|
141 /** |
|
142 * Returns number of unique blogs linking this blog. |
|
143 * |
|
144 * @return integer the number of inbound blogs |
|
145 */ |
|
146 public function getInboundBlogs() |
|
147 { |
|
148 return (int) $this->_inboundBlogs; |
|
149 } |
|
150 |
|
151 /** |
|
152 * Returns number of incoming links to this blog. |
|
153 * |
|
154 * @return integer the number of inbound links |
|
155 */ |
|
156 public function getInboundLinks() |
|
157 { |
|
158 return (int) $this->_inboundLinks; |
|
159 } |
|
160 |
|
161 } |