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