Weblog.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486
  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-2015 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id$
  21. */
  22. /**
  23. * @see Zend_Service_Technorati_Author
  24. */
  25. require_once 'Zend/Service/Technorati/Author.php';
  26. /**
  27. * @see Zend_Service_Technorati_Utils
  28. */
  29. require_once 'Zend/Service/Technorati/Utils.php';
  30. /**
  31. * Represents a Weblog object successful recognized by Technorati.
  32. *
  33. * @category Zend
  34. * @package Zend_Service
  35. * @subpackage Technorati
  36. * @copyright Copyright (c) 2005-2015 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_Weblog
  40. {
  41. /**
  42. * Blog name as written in the feed.
  43. *
  44. * @var string
  45. * @access protected
  46. */
  47. protected $_name;
  48. /**
  49. * Base blog URL.
  50. *
  51. * @var Zend_Uri_Http
  52. * @access protected
  53. */
  54. protected $_url;
  55. /**
  56. * RSS feed URL, if any.
  57. *
  58. * @var null|Zend_Uri_Http
  59. * @access protected
  60. */
  61. protected $_rssUrl;
  62. /**
  63. * Atom feed URL, if any.
  64. *
  65. * @var null|Zend_Uri_Http
  66. * @access protected
  67. */
  68. protected $_atomUrl;
  69. /**
  70. * Number of unique blogs linking this blog.
  71. *
  72. * @var integer
  73. * @access protected
  74. */
  75. protected $_inboundBlogs;
  76. /**
  77. * Number of incoming links to this blog.
  78. *
  79. * @var integer
  80. * @access protected
  81. */
  82. protected $_inboundLinks;
  83. /**
  84. * Last blog update UNIX timestamp.
  85. *
  86. * @var null|Zend_Date
  87. * @access protected
  88. */
  89. protected $_lastUpdate;
  90. /**
  91. * Technorati rank value for this weblog.
  92. *
  93. * Note. This property has no official documentation.
  94. *
  95. * @var integer
  96. * @access protected
  97. */
  98. protected $_rank;
  99. /**
  100. * Blog latitude coordinate.
  101. *
  102. * Note. This property has no official documentation.
  103. *
  104. * @var float
  105. * @access protected
  106. */
  107. protected $_lat;
  108. /**
  109. * Blog longitude coordinate.
  110. *
  111. * Note. This property has no official documentation.
  112. *
  113. * @var float
  114. * @access protected
  115. */
  116. protected $_lon;
  117. /**
  118. * Whether the author who claimed this weblog has a photo.
  119. *
  120. * Note. This property has no official documentation.
  121. *
  122. * @var bool
  123. * @access protected
  124. * @see Zend_Service_Technorati_Author::$thumbnailPicture
  125. */
  126. protected $_hasPhoto = false;
  127. /**
  128. * An array of Zend_Service_Technorati_Author who claimed this blog
  129. *
  130. * @var array
  131. * @access protected
  132. */
  133. protected $_authors = array();
  134. /**
  135. * Constructs a new object from DOM Element.
  136. *
  137. * @param DomElement $dom the ReST fragment for this object
  138. */
  139. public function __construct(DomElement $dom)
  140. {
  141. $xpath = new DOMXPath($dom->ownerDocument);
  142. $result = $xpath->query('./name/text()', $dom);
  143. if ($result->length == 1) $this->setName($result->item(0)->data);
  144. $result = $xpath->query('./url/text()', $dom);
  145. if ($result->length == 1) $this->setUrl($result->item(0)->data);
  146. $result = $xpath->query('./inboundblogs/text()', $dom);
  147. if ($result->length == 1) $this->setInboundBlogs($result->item(0)->data);
  148. $result = $xpath->query('./inboundlinks/text()', $dom);
  149. if ($result->length == 1) $this->setInboundLinks($result->item(0)->data);
  150. $result = $xpath->query('./lastupdate/text()', $dom);
  151. if ($result->length == 1) $this->setLastUpdate($result->item(0)->data);
  152. /* The following elements need more attention */
  153. $result = $xpath->query('./rssurl/text()', $dom);
  154. if ($result->length == 1) $this->setRssUrl($result->item(0)->data);
  155. $result = $xpath->query('./atomurl/text()', $dom);
  156. if ($result->length == 1) $this->setAtomUrl($result->item(0)->data);
  157. $result = $xpath->query('./author', $dom);
  158. if ($result->length >= 1) {
  159. foreach ($result as $author) {
  160. $this->_authors[] = new Zend_Service_Technorati_Author($author);
  161. }
  162. }
  163. /**
  164. * The following are optional elements
  165. *
  166. * I can't find any official documentation about the following properties
  167. * however they are included in response DTD and/or test responses.
  168. */
  169. $result = $xpath->query('./rank/text()', $dom);
  170. if ($result->length == 1) $this->setRank($result->item(0)->data);
  171. $result = $xpath->query('./lat/text()', $dom);
  172. if ($result->length == 1) $this->setLat($result->item(0)->data);
  173. $result = $xpath->query('./lon/text()', $dom);
  174. if ($result->length == 1) $this->setLon($result->item(0)->data);
  175. $result = $xpath->query('./hasphoto/text()', $dom);
  176. if ($result->length == 1) $this->setHasPhoto($result->item(0)->data);
  177. }
  178. /**
  179. * Returns weblog name.
  180. *
  181. * @return string Weblog name
  182. */
  183. public function getName()
  184. {
  185. return $this->_name;
  186. }
  187. /**
  188. * Returns weblog URL.
  189. *
  190. * @return null|Zend_Uri_Http object representing weblog base URL
  191. */
  192. public function getUrl()
  193. {
  194. return $this->_url;
  195. }
  196. /**
  197. * Returns number of unique blogs linking this blog.
  198. *
  199. * @return integer the number of inbound blogs
  200. */
  201. public function getInboundBlogs()
  202. {
  203. return $this->_inboundBlogs;
  204. }
  205. /**
  206. * Returns number of incoming links to this blog.
  207. *
  208. * @return integer the number of inbound links
  209. */
  210. public function getInboundLinks()
  211. {
  212. return $this->_inboundLinks;
  213. }
  214. /**
  215. * Returns weblog Rss URL.
  216. *
  217. * @return null|Zend_Uri_Http object representing the URL
  218. * of the RSS feed for given blog
  219. */
  220. public function getRssUrl()
  221. {
  222. return $this->_rssUrl;
  223. }
  224. /**
  225. * Returns weblog Atom URL.
  226. *
  227. * @return null|Zend_Uri_Http object representing the URL
  228. * of the Atom feed for given blog
  229. */
  230. public function getAtomUrl()
  231. {
  232. return $this->_atomUrl;
  233. }
  234. /**
  235. * Returns UNIX timestamp of the last weblog update.
  236. *
  237. * @return integer UNIX timestamp of the last weblog update
  238. */
  239. public function getLastUpdate()
  240. {
  241. return $this->_lastUpdate;
  242. }
  243. /**
  244. * Returns weblog rank value.
  245. *
  246. * Note. This property is not documented.
  247. *
  248. * @return integer weblog rank value
  249. */
  250. public function getRank()
  251. {
  252. return $this->_rank;
  253. }
  254. /**
  255. * Returns weblog latitude coordinate.
  256. *
  257. * Note. This property is not documented.
  258. *
  259. * @return float weblog latitude coordinate
  260. */
  261. public function getLat() {
  262. return $this->_lat;
  263. }
  264. /**
  265. * Returns weblog longitude coordinate.
  266. *
  267. * Note. This property is not documented.
  268. *
  269. * @return float weblog longitude coordinate
  270. */
  271. public function getLon()
  272. {
  273. return $this->_lon;
  274. }
  275. /**
  276. * Returns whether the author who claimed this weblog has a photo.
  277. *
  278. * Note. This property is not documented.
  279. *
  280. * @return bool TRUE if the author who claimed this weblog has a photo,
  281. * FALSE otherwise.
  282. */
  283. public function hasPhoto()
  284. {
  285. return (bool) $this->_hasPhoto;
  286. }
  287. /**
  288. * Returns the array of weblog authors.
  289. *
  290. * @return array of Zend_Service_Technorati_Author authors
  291. */
  292. public function getAuthors()
  293. {
  294. return (array) $this->_authors;
  295. }
  296. /**
  297. * Sets weblog name.
  298. *
  299. * @param string $name
  300. * @return Zend_Service_Technorati_Weblog $this instance
  301. */
  302. public function setName($name)
  303. {
  304. $this->_name = (string) $name;
  305. return $this;
  306. }
  307. /**
  308. * Sets weblog URL.
  309. *
  310. * @param string|Zend_Uri_Http $url
  311. * @return void
  312. * @throws Zend_Service_Technorati_Exception if $input is an invalid URI
  313. * (via Zend_Service_Technorati_Utils::normalizeUriHttp)
  314. */
  315. public function setUrl($url)
  316. {
  317. $this->_url = Zend_Service_Technorati_Utils::normalizeUriHttp($url);
  318. return $this;
  319. }
  320. /**
  321. * Sets number of inbound blogs.
  322. *
  323. * @param integer $number
  324. * @return Zend_Service_Technorati_Weblog $this instance
  325. */
  326. public function setInboundBlogs($number)
  327. {
  328. $this->_inboundBlogs = (int) $number;
  329. return $this;
  330. }
  331. /**
  332. * Sets number of Iinbound links.
  333. *
  334. * @param integer $number
  335. * @return Zend_Service_Technorati_Weblog $this instance
  336. */
  337. public function setInboundLinks($number)
  338. {
  339. $this->_inboundLinks = (int) $number;
  340. return $this;
  341. }
  342. /**
  343. * Sets weblog Rss URL.
  344. *
  345. * @param string|Zend_Uri_Http $url
  346. * @return Zend_Service_Technorati_Weblog $this instance
  347. * @throws Zend_Service_Technorati_Exception if $input is an invalid URI
  348. * (via Zend_Service_Technorati_Utils::normalizeUriHttp)
  349. */
  350. public function setRssUrl($url)
  351. {
  352. $this->_rssUrl = Zend_Service_Technorati_Utils::normalizeUriHttp($url);
  353. return $this;
  354. }
  355. /**
  356. * Sets weblog Atom URL.
  357. *
  358. * @param string|Zend_Uri_Http $url
  359. * @return Zend_Service_Technorati_Weblog $this instance
  360. * @throws Zend_Service_Technorati_Exception if $input is an invalid URI
  361. * (via Zend_Service_Technorati_Utils::normalizeUriHttp)
  362. */
  363. public function setAtomUrl($url)
  364. {
  365. $this->_atomUrl = Zend_Service_Technorati_Utils::normalizeUriHttp($url);
  366. return $this;
  367. }
  368. /**
  369. * Sets weblog Last Update timestamp.
  370. *
  371. * $datetime can be any value supported by
  372. * Zend_Service_Technorati_Utils::normalizeDate().
  373. *
  374. * @param mixed $datetime A string representing the last update date time
  375. * in a valid date time format
  376. * @return Zend_Service_Technorati_Weblog $this instance
  377. * @throws Zend_Service_Technorati_Exception
  378. */
  379. public function setLastUpdate($datetime)
  380. {
  381. $this->_lastUpdate = Zend_Service_Technorati_Utils::normalizeDate($datetime);
  382. return $this;
  383. }
  384. /**
  385. * Sets weblog Rank.
  386. *
  387. * @param integer $rank
  388. * @return Zend_Service_Technorati_Weblog $this instance
  389. */
  390. public function setRank($rank)
  391. {
  392. $this->_rank = (int) $rank;
  393. return $this;
  394. }
  395. /**
  396. * Sets weblog latitude coordinate.
  397. *
  398. * @param float $coordinate
  399. * @return Zend_Service_Technorati_Weblog $this instance
  400. */
  401. public function setLat($coordinate)
  402. {
  403. $this->_lat = (float) $coordinate;
  404. return $this;
  405. }
  406. /**
  407. * Sets weblog longitude coordinate.
  408. *
  409. * @param float $coordinate
  410. * @return Zend_Service_Technorati_Weblog $this instance
  411. */
  412. public function setLon($coordinate)
  413. {
  414. $this->_lon = (float) $coordinate;
  415. return $this;
  416. }
  417. /**
  418. * Sets hasPhoto property.
  419. *
  420. * @param bool $hasPhoto
  421. * @return Zend_Service_Technorati_Weblog $this instance
  422. */
  423. public function setHasPhoto($hasPhoto)
  424. {
  425. $this->_hasPhoto = (bool) $hasPhoto;
  426. return $this;
  427. }
  428. }