Entry.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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_Feed_Reader
  17. * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com)
  18. * @license http://framework.zend.com/license/new-bsd New BSD License
  19. * @version $Id$
  20. */
  21. /**
  22. * @see Zend_Feed_Reader
  23. */
  24. require_once 'Zend/Feed/Reader.php';
  25. /**
  26. * @see Zend_Feed_Reader_Extension_EntryAbstract
  27. */
  28. require_once 'Zend/Feed/Reader/Extension/EntryAbstract.php';
  29. /**
  30. * @category Zend
  31. * @package Zend_Feed_Reader
  32. * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com)
  33. * @license http://framework.zend.com/license/new-bsd New BSD License
  34. */
  35. class Zend_Feed_Reader_Extension_Slash_Entry
  36. extends Zend_Feed_Reader_Extension_EntryAbstract
  37. {
  38. /**
  39. * Get the entry section
  40. *
  41. * @return string|null
  42. */
  43. public function getSection()
  44. {
  45. return $this->_getData('section');
  46. }
  47. /**
  48. * Get the entry department
  49. *
  50. * @return string|null
  51. */
  52. public function getDepartment()
  53. {
  54. return $this->_getData('department');
  55. }
  56. /**
  57. * Get the entry hit_parade
  58. *
  59. * @return array
  60. */
  61. public function getHitParade()
  62. {
  63. $name = 'hit_parade';
  64. if (isset($this->_data[$name])) {
  65. return $this->_data[$name];
  66. }
  67. $stringParade = $this->_getData($name);
  68. $hitParade = array();
  69. if (!empty($stringParade)) {
  70. $stringParade = explode(',', $stringParade);
  71. foreach ($stringParade as $hit)
  72. $hitParade[] = $hit + 0; //cast to integer
  73. }
  74. $this->_data[$name] = $hitParade;
  75. return $hitParade;
  76. }
  77. /**
  78. * Get the entry comments
  79. *
  80. * @return int
  81. */
  82. public function getCommentCount()
  83. {
  84. $name = 'comments';
  85. if (isset($this->_data[$name])) {
  86. return $this->_data[$name];
  87. }
  88. $comments = $this->_getData($name, 'string');
  89. if (!$comments) {
  90. $this->_data[$name] = null;
  91. return $this->_data[$name];
  92. }
  93. return $comments;
  94. }
  95. /**
  96. * Get the entry data specified by name
  97. * @param string $name
  98. * @param string $type
  99. *
  100. * @return mixed|null
  101. */
  102. protected function _getData($name, $type = 'string')
  103. {
  104. if (array_key_exists($name, $this->_data)) {
  105. return $this->_data[$name];
  106. }
  107. $data = $this->_xpath->evaluate($type . '(' . $this->getXpathPrefix() . '/slash10:' . $name . ')');
  108. if (!$data) {
  109. $data = null;
  110. }
  111. $this->_data[$name] = $data;
  112. return $data;
  113. }
  114. /**
  115. * Register Slash namespaces
  116. *
  117. * @return void
  118. */
  119. protected function _registerNamespaces()
  120. {
  121. $this->_xpath->registerNamespace('slash10', 'http://purl.org/rss/1.0/modules/slash/');
  122. }
  123. }