PageRenderTime 49ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/library/Zend/Gdata/App/FeedEntryParent.php

https://bitbucket.org/luizbrandaoj/mini-blog
PHP | 681 lines | 297 code | 55 blank | 329 comment | 27 complexity | fdc7017588fcad75d119d89dd2c80311 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_Gdata
  17. * @subpackage App
  18. * @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id: FeedEntryParent.php 23775 2011-03-01 17:25:24Z ralph $
  21. */
  22. /**
  23. * @see Zend_Gdata_App_Extension_Element
  24. */
  25. require_once 'Zend/Gdata/App/Extension/Element.php';
  26. /**
  27. * @see Zend_Gdata_App_Extension_Author
  28. */
  29. require_once 'Zend/Gdata/App/Extension/Author.php';
  30. /**
  31. * @see Zend_Gdata_App_Extension_Category
  32. */
  33. require_once 'Zend/Gdata/App/Extension/Category.php';
  34. /**
  35. * @see Zend_Gdata_App_Extension_Contributor
  36. */
  37. require_once 'Zend/Gdata/App/Extension/Contributor.php';
  38. /**
  39. * @see Zend_Gdata_App_Extension_Id
  40. */
  41. require_once 'Zend/Gdata/App/Extension/Id.php';
  42. /**
  43. * @see Zend_Gdata_App_Extension_Link
  44. */
  45. require_once 'Zend/Gdata/App/Extension/Link.php';
  46. /**
  47. * @see Zend_Gdata_App_Extension_Rights
  48. */
  49. require_once 'Zend/Gdata/App/Extension/Rights.php';
  50. /**
  51. * @see Zend_Gdata_App_Extension_Title
  52. */
  53. require_once 'Zend/Gdata/App/Extension/Title.php';
  54. /**
  55. * @see Zend_Gdata_App_Extension_Updated
  56. */
  57. require_once 'Zend/Gdata/App/Extension/Updated.php';
  58. /**
  59. * Zend_Version
  60. */
  61. require_once 'Zend/Version.php';
  62. /**
  63. * Abstract class for common functionality in entries and feeds
  64. *
  65. * @category Zend
  66. * @package Zend_Gdata
  67. * @subpackage App
  68. * @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
  69. * @license http://framework.zend.com/license/new-bsd New BSD License
  70. */
  71. abstract class Zend_Gdata_App_FeedEntryParent extends Zend_Gdata_App_Base
  72. {
  73. /**
  74. * Service instance used to make network requests.
  75. *
  76. * @see setService(), getService()
  77. */
  78. protected $_service = null;
  79. /**
  80. * The HTTP ETag associated with this entry. Used for optimistic
  81. * concurrency in protoco v2 or greater.
  82. *
  83. * @var string|null
  84. */
  85. protected $_etag = NULL;
  86. protected $_author = array();
  87. protected $_category = array();
  88. protected $_contributor = array();
  89. protected $_id = null;
  90. protected $_link = array();
  91. protected $_rights = null;
  92. protected $_title = null;
  93. protected $_updated = null;
  94. /**
  95. * Indicates the major protocol version that should be used.
  96. * At present, recognized values are either 1 or 2. However, any integer
  97. * value >= 1 is considered valid.
  98. *
  99. * @see setMajorProtocolVersion()
  100. * @see getMajorProtocolVersion()
  101. */
  102. protected $_majorProtocolVersion = 1;
  103. /**
  104. * Indicates the minor protocol version that should be used. Can be set
  105. * to either an integer >= 0, or NULL if no minor version should be sent
  106. * to the server.
  107. *
  108. * @see setMinorProtocolVersion()
  109. * @see getMinorProtocolVersion()
  110. */
  111. protected $_minorProtocolVersion = null;
  112. /**
  113. * Constructs a Feed or Entry
  114. */
  115. public function __construct($element = null)
  116. {
  117. if (!($element instanceof DOMElement)) {
  118. if ($element) {
  119. $this->transferFromXML($element);
  120. }
  121. } else {
  122. $this->transferFromDOM($element);
  123. }
  124. }
  125. /**
  126. * Set the HTTP client instance
  127. *
  128. * Sets the HTTP client object to use for retrieving the feed.
  129. *
  130. * @deprecated Deprecated as of Zend Framework 1.7. Use
  131. * setService() instead.
  132. * @param Zend_Http_Client $httpClient
  133. * @return Zend_Gdata_App_FeedEntryParent Provides a fluent interface
  134. */
  135. public function setHttpClient(Zend_Http_Client $httpClient)
  136. {
  137. if (!$this->_service) {
  138. $this->_service = new Zend_Gdata_App();
  139. }
  140. $this->_service->setHttpClient($httpClient);
  141. return $this;
  142. }
  143. /**
  144. * Gets the HTTP client object. If none is set, a new Zend_Http_Client
  145. * will be used.
  146. *
  147. * @deprecated Deprecated as of Zend Framework 1.7. Use
  148. * getService() instead.
  149. * @return Zend_Http_Client_Abstract
  150. */
  151. public function getHttpClient()
  152. {
  153. if (!$this->_service) {
  154. $this->_service = new Zend_Gdata_App();
  155. }
  156. $client = $this->_service->getHttpClient();
  157. return $client;
  158. }
  159. /**
  160. * Set the active service instance for this object. This will be used to
  161. * perform network requests, such as when calling save() and delete().
  162. *
  163. * @param Zend_Gdata_App $instance The new service instance.
  164. * @return Zend_Gdata_App_FeedEntryParent Provides a fluent interface.
  165. */
  166. public function setService($instance)
  167. {
  168. $this->_service = $instance;
  169. return $this;
  170. }
  171. /**
  172. * Get the active service instance for this object. This will be used to
  173. * perform network requests, such as when calling save() and delete().
  174. *
  175. * @return Zend_Gdata_App|null The current service instance, or null if
  176. * not set.
  177. */
  178. public function getService()
  179. {
  180. return $this->_service;
  181. }
  182. public function getDOM($doc = null, $majorVersion = 1, $minorVersion = null)
  183. {
  184. $element = parent::getDOM($doc, $majorVersion, $minorVersion);
  185. foreach ($this->_author as $author) {
  186. $element->appendChild($author->getDOM($element->ownerDocument));
  187. }
  188. foreach ($this->_category as $category) {
  189. $element->appendChild($category->getDOM($element->ownerDocument));
  190. }
  191. foreach ($this->_contributor as $contributor) {
  192. $element->appendChild($contributor->getDOM($element->ownerDocument));
  193. }
  194. if ($this->_id != null) {
  195. $element->appendChild($this->_id->getDOM($element->ownerDocument));
  196. }
  197. foreach ($this->_link as $link) {
  198. $element->appendChild($link->getDOM($element->ownerDocument));
  199. }
  200. if ($this->_rights != null) {
  201. $element->appendChild($this->_rights->getDOM($element->ownerDocument));
  202. }
  203. if ($this->_title != null) {
  204. $element->appendChild($this->_title->getDOM($element->ownerDocument));
  205. }
  206. if ($this->_updated != null) {
  207. $element->appendChild($this->_updated->getDOM($element->ownerDocument));
  208. }
  209. return $element;
  210. }
  211. protected function takeChildFromDOM($child)
  212. {
  213. $absoluteNodeName = $child->namespaceURI . ':' . $child->localName;
  214. switch ($absoluteNodeName) {
  215. case $this->lookupNamespace('atom') . ':' . 'author':
  216. $author = new Zend_Gdata_App_Extension_Author();
  217. $author->transferFromDOM($child);
  218. $this->_author[] = $author;
  219. break;
  220. case $this->lookupNamespace('atom') . ':' . 'category':
  221. $category = new Zend_Gdata_App_Extension_Category();
  222. $category->transferFromDOM($child);
  223. $this->_category[] = $category;
  224. break;
  225. case $this->lookupNamespace('atom') . ':' . 'contributor':
  226. $contributor = new Zend_Gdata_App_Extension_Contributor();
  227. $contributor->transferFromDOM($child);
  228. $this->_contributor[] = $contributor;
  229. break;
  230. case $this->lookupNamespace('atom') . ':' . 'id':
  231. $id = new Zend_Gdata_App_Extension_Id();
  232. $id->transferFromDOM($child);
  233. $this->_id = $id;
  234. break;
  235. case $this->lookupNamespace('atom') . ':' . 'link':
  236. $link = new Zend_Gdata_App_Extension_Link();
  237. $link->transferFromDOM($child);
  238. $this->_link[] = $link;
  239. break;
  240. case $this->lookupNamespace('atom') . ':' . 'rights':
  241. $rights = new Zend_Gdata_App_Extension_Rights();
  242. $rights->transferFromDOM($child);
  243. $this->_rights = $rights;
  244. break;
  245. case $this->lookupNamespace('atom') . ':' . 'title':
  246. $title = new Zend_Gdata_App_Extension_Title();
  247. $title->transferFromDOM($child);
  248. $this->_title = $title;
  249. break;
  250. case $this->lookupNamespace('atom') . ':' . 'updated':
  251. $updated = new Zend_Gdata_App_Extension_Updated();
  252. $updated->transferFromDOM($child);
  253. $this->_updated = $updated;
  254. break;
  255. default:
  256. parent::takeChildFromDOM($child);
  257. break;
  258. }
  259. }
  260. /**
  261. * @return Zend_Gdata_App_Extension_Author
  262. */
  263. public function getAuthor()
  264. {
  265. return $this->_author;
  266. }
  267. /**
  268. * Sets the list of the authors of this feed/entry. In an atom feed, each
  269. * author is represented by an atom:author element
  270. *
  271. * @param array $value
  272. * @return Zend_Gdata_App_FeedEntryParent Provides a fluent interface
  273. */
  274. public function setAuthor($value)
  275. {
  276. $this->_author = $value;
  277. return $this;
  278. }
  279. /**
  280. * Returns the array of categories that classify this feed/entry. Each
  281. * category is represented in an atom feed by an atom:category element.
  282. *
  283. * @return array Array of Zend_Gdata_App_Extension_Category
  284. */
  285. public function getCategory()
  286. {
  287. return $this->_category;
  288. }
  289. /**
  290. * Sets the array of categories that classify this feed/entry. Each
  291. * category is represented in an atom feed by an atom:category element.
  292. *
  293. * @param array $value Array of Zend_Gdata_App_Extension_Category
  294. * @return Zend_Gdata_App_FeedEntryParent Provides a fluent interface
  295. */
  296. public function setCategory($value)
  297. {
  298. $this->_category = $value;
  299. return $this;
  300. }
  301. /**
  302. * Returns the array of contributors to this feed/entry. Each contributor
  303. * is represented in an atom feed by an atom:contributor XML element
  304. *
  305. * @return array An array of Zend_Gdata_App_Extension_Contributor
  306. */
  307. public function getContributor()
  308. {
  309. return $this->_contributor;
  310. }
  311. /**
  312. * Sets the array of contributors to this feed/entry. Each contributor
  313. * is represented in an atom feed by an atom:contributor XML element
  314. *
  315. * @param array $value
  316. * @return Zend_Gdata_App_FeedEntryParent Provides a fluent interface
  317. */
  318. public function setContributor($value)
  319. {
  320. $this->_contributor = $value;
  321. return $this;
  322. }
  323. /**
  324. * @return Zend_Gdata_App_Extension_Id
  325. */
  326. public function getId()
  327. {
  328. return $this->_id;
  329. }
  330. /**
  331. * @param Zend_Gdata_App_Extension_Id $value
  332. * @return Zend_Gdata_App_FeedEntryParent Provides a fluent interface
  333. */
  334. public function setId($value)
  335. {
  336. $this->_id = $value;
  337. return $this;
  338. }
  339. /**
  340. * Given a particular 'rel' value, this method returns a matching
  341. * Zend_Gdata_App_Extension_Link element. If the 'rel' value
  342. * is not provided, the full array of Zend_Gdata_App_Extension_Link
  343. * elements is returned. In an atom feed, each link is represented
  344. * by an atom:link element. The 'rel' value passed to this function
  345. * is the atom:link/@rel attribute. Example rel values include 'self',
  346. * 'edit', and 'alternate'.
  347. *
  348. * @param string $rel The rel value of the link to be found. If null,
  349. * the array of Zend_Gdata_App_Extension_link elements is returned
  350. * @return mixed Either a single Zend_Gdata_App_Extension_link element,
  351. * an array of the same or null is returned depending on the rel value
  352. * supplied as the argument to this function
  353. */
  354. public function getLink($rel = null)
  355. {
  356. if ($rel == null) {
  357. return $this->_link;
  358. } else {
  359. foreach ($this->_link as $link) {
  360. if ($link->rel == $rel) {
  361. return $link;
  362. }
  363. }
  364. return null;
  365. }
  366. }
  367. /**
  368. * Returns the Zend_Gdata_App_Extension_Link element which represents
  369. * the URL used to edit this resource. This link is in the atom feed/entry
  370. * as an atom:link with a rel attribute value of 'edit'.
  371. *
  372. * @return Zend_Gdata_App_Extension_Link The link, or null if not found
  373. */
  374. public function getEditLink()
  375. {
  376. return $this->getLink('edit');
  377. }
  378. /**
  379. * Returns the Zend_Gdata_App_Extension_Link element which represents
  380. * the URL used to retrieve the next chunk of results when paging through
  381. * a feed. This link is in the atom feed as an atom:link with a
  382. * rel attribute value of 'next'.
  383. *
  384. * @return Zend_Gdata_App_Extension_Link The link, or null if not found
  385. */
  386. public function getNextLink()
  387. {
  388. return $this->getLink('next');
  389. }
  390. /**
  391. * Returns the Zend_Gdata_App_Extension_Link element which represents
  392. * the URL used to retrieve the previous chunk of results when paging
  393. * through a feed. This link is in the atom feed as an atom:link with a
  394. * rel attribute value of 'previous'.
  395. *
  396. * @return Zend_Gdata_App_Extension_Link The link, or null if not found
  397. */
  398. public function getPreviousLink()
  399. {
  400. return $this->getLink('previous');
  401. }
  402. /**
  403. * @return Zend_Gdata_App_Extension_Link
  404. */
  405. public function getLicenseLink()
  406. {
  407. return $this->getLink('license');
  408. }
  409. /**
  410. * Returns the Zend_Gdata_App_Extension_Link element which represents
  411. * the URL used to retrieve the entry or feed represented by this object
  412. * This link is in the atom feed/entry as an atom:link with a
  413. * rel attribute value of 'self'.
  414. *
  415. * @return Zend_Gdata_App_Extension_Link The link, or null if not found
  416. */
  417. public function getSelfLink()
  418. {
  419. return $this->getLink('self');
  420. }
  421. /**
  422. * Returns the Zend_Gdata_App_Extension_Link element which represents
  423. * the URL for an alternate view of the data represented by this feed or
  424. * entry. This alternate view is commonly a user-facing webpage, blog
  425. * post, etc. The MIME type for the data at the URL is available from the
  426. * returned Zend_Gdata_App_Extension_Link element.
  427. * This link is in the atom feed/entry as an atom:link with a
  428. * rel attribute value of 'self'.
  429. *
  430. * @return Zend_Gdata_App_Extension_Link The link, or null if not found
  431. */
  432. public function getAlternateLink()
  433. {
  434. return $this->getLink('alternate');
  435. }
  436. /**
  437. * @param array $value The array of Zend_Gdata_App_Extension_Link elements
  438. * @return Zend_Gdata_App_FeedEntryParent Provides a fluent interface
  439. */
  440. public function setLink($value)
  441. {
  442. $this->_link = $value;
  443. return $this;
  444. }
  445. /**
  446. * @return Zend_Gdata_AppExtension_Rights
  447. */
  448. public function getRights()
  449. {
  450. return $this->_rights;
  451. }
  452. /**
  453. * @param Zend_Gdata_App_Extension_Rights $value
  454. * @return Zend_Gdata_App_FeedEntryParent Provides a fluent interface
  455. */
  456. public function setRights($value)
  457. {
  458. $this->_rights = $value;
  459. return $this;
  460. }
  461. /**
  462. * Returns the title of this feed or entry. The title is an extremely
  463. * short textual representation of this resource and is found as
  464. * an atom:title element in a feed or entry
  465. *
  466. * @return Zend_Gdata_App_Extension_Title
  467. */
  468. public function getTitle()
  469. {
  470. return $this->_title;
  471. }
  472. /**
  473. * Returns a string representation of the title of this feed or entry.
  474. * The title is an extremely short textual representation of this
  475. * resource and is found as an atom:title element in a feed or entry
  476. *
  477. * @return string
  478. */
  479. public function getTitleValue()
  480. {
  481. if (($titleObj = $this->getTitle()) != null) {
  482. return $titleObj->getText();
  483. } else {
  484. return null;
  485. }
  486. }
  487. /**
  488. * Returns the title of this feed or entry. The title is an extremely
  489. * short textual representation of this resource and is found as
  490. * an atom:title element in a feed or entry
  491. *
  492. * @param Zend_Gdata_App_Extension_Title $value
  493. * @return Zend_Gdata_App_FeedEntryParent Provides a fluent interface
  494. */
  495. public function setTitle($value)
  496. {
  497. $this->_title = $value;
  498. return $this;
  499. }
  500. /**
  501. * @return Zend_Gdata_App_Extension_Updated
  502. */
  503. public function getUpdated()
  504. {
  505. return $this->_updated;
  506. }
  507. /**
  508. * @param Zend_Gdata_App_Extension_Updated $value
  509. * @return Zend_Gdata_App_FeedEntryParent Provides a fluent interface
  510. */
  511. public function setUpdated($value)
  512. {
  513. $this->_updated = $value;
  514. return $this;
  515. }
  516. /**
  517. * Set the Etag for the current entry to $value. Setting $value to null
  518. * unsets the Etag.
  519. *
  520. * @param string|null $value
  521. * @return Zend_Gdata_App_Entry Provides a fluent interface
  522. */
  523. public function setEtag($value) {
  524. $this->_etag = $value;
  525. return $this;
  526. }
  527. /**
  528. * Return the Etag for the current entry, or null if not set.
  529. *
  530. * @return string|null
  531. */
  532. public function getEtag() {
  533. return $this->_etag;
  534. }
  535. /**
  536. * Set the major protocol version that should be used. Values < 1
  537. * (excluding NULL) will cause a Zend_Gdata_App_InvalidArgumentException
  538. * to be thrown.
  539. *
  540. * @see _majorProtocolVersion
  541. * @param (int|NULL) $value The major protocol version to use.
  542. * @throws Zend_Gdata_App_InvalidArgumentException
  543. */
  544. public function setMajorProtocolVersion($value)
  545. {
  546. if (!($value >= 1) && ($value !== null)) {
  547. require_once('Zend/Gdata/App/InvalidArgumentException.php');
  548. throw new Zend_Gdata_App_InvalidArgumentException(
  549. 'Major protocol version must be >= 1');
  550. }
  551. $this->_majorProtocolVersion = $value;
  552. }
  553. /**
  554. * Get the major protocol version that is in use.
  555. *
  556. * @see _majorProtocolVersion
  557. * @return (int|NULL) The major protocol version in use.
  558. */
  559. public function getMajorProtocolVersion()
  560. {
  561. return $this->_majorProtocolVersion;
  562. }
  563. /**
  564. * Set the minor protocol version that should be used. If set to NULL, no
  565. * minor protocol version will be sent to the server. Values < 0 will
  566. * cause a Zend_Gdata_App_InvalidArgumentException to be thrown.
  567. *
  568. * @see _minorProtocolVersion
  569. * @param (int|NULL) $value The minor protocol version to use.
  570. * @throws Zend_Gdata_App_InvalidArgumentException
  571. */
  572. public function setMinorProtocolVersion($value)
  573. {
  574. if (!($value >= 0)) {
  575. require_once('Zend/Gdata/App/InvalidArgumentException.php');
  576. throw new Zend_Gdata_App_InvalidArgumentException(
  577. 'Minor protocol version must be >= 0 or null');
  578. }
  579. $this->_minorProtocolVersion = $value;
  580. }
  581. /**
  582. * Get the minor protocol version that is in use.
  583. *
  584. * @see _minorProtocolVersion
  585. * @return (int|NULL) The major protocol version in use, or NULL if no
  586. * minor version is specified.
  587. */
  588. public function getMinorProtocolVersion()
  589. {
  590. return $this->_minorProtocolVersion;
  591. }
  592. /**
  593. * Get the full version of a namespace prefix
  594. *
  595. * Looks up a prefix (atom:, etc.) in the list of registered
  596. * namespaces and returns the full namespace URI if
  597. * available. Returns the prefix, unmodified, if it's not
  598. * registered.
  599. *
  600. * The current entry or feed's version will be used when performing the
  601. * namespace lookup unless overridden using $majorVersion and
  602. * $minorVersion. If the entry/fee has a null version, then the latest
  603. * protocol version will be used by default.
  604. *
  605. * @param string $prefix The namespace prefix to lookup.
  606. * @param integer $majorVersion The major protocol version in effect.
  607. * Defaults to null (auto-select).
  608. * @param integer $minorVersion The minor protocol version in effect.
  609. * Defaults to null (auto-select).
  610. * @return string
  611. */
  612. public function lookupNamespace($prefix,
  613. $majorVersion = null,
  614. $minorVersion = null)
  615. {
  616. // Auto-select current version
  617. if ($majorVersion === null) {
  618. $majorVersion = $this->getMajorProtocolVersion();
  619. }
  620. if ($minorVersion === null) {
  621. $minorVersion = $this->getMinorProtocolVersion();
  622. }
  623. // Perform lookup
  624. return parent::lookupNamespace($prefix, $majorVersion, $minorVersion);
  625. }
  626. }