SimplePie_Source

Handles ``.

Defined (1)

The class is defined in the following location(s).

/wp-includes/SimplePie/Source.php  
  1. class SimplePie_Source 
  2. var $item; 
  3. var $data = array(); 
  4. protected $registry; 
  5.  
  6. public function __construct($item, $data) 
  7. $this->item = $item; 
  8. $this->data = $data; 
  9.  
  10. public function set_registry(SimplePie_Registry $registry) 
  11. $this->registry = $registry; 
  12.  
  13. public function __toString() 
  14. return md5(serialize($this->data)); 
  15.  
  16. public function get_source_tags($namespace, $tag) 
  17. if (isset($this->data['child'][$namespace][$tag])) 
  18. return $this->data['child'][$namespace][$tag]; 
  19. else 
  20. return null; 
  21.  
  22. public function get_base($element = array()) 
  23. return $this->item->get_base($element); 
  24.  
  25. public function sanitize($data, $type, $base = '') 
  26. return $this->item->sanitize($data, $type, $base); 
  27.  
  28. public function get_item() 
  29. return $this->item; 
  30.  
  31. public function get_title() 
  32. if ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'title')) 
  33. return $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_10_construct_type', array($return[0]['attribs'])), $this->get_base($return[0])); 
  34. elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'title')) 
  35. return $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_03_construct_type', array($return[0]['attribs'])), $this->get_base($return[0])); 
  36. elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'title')) 
  37. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0])); 
  38. elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'title')) 
  39. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0])); 
  40. elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'title')) 
  41. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0])); 
  42. elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_DC_11, 'title')) 
  43. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); 
  44. elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_DC_10, 'title')) 
  45. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); 
  46. else 
  47. return null; 
  48.  
  49. public function get_category($key = 0) 
  50. $categories = $this->get_categories(); 
  51. if (isset($categories[$key])) 
  52. return $categories[$key]; 
  53. else 
  54. return null; 
  55.  
  56. public function get_categories() 
  57. $categories = array(); 
  58.  
  59. foreach ((array) $this->get_source_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'category') as $category) 
  60. $term = null; 
  61. $scheme = null; 
  62. $label = null; 
  63. if (isset($category['attribs']['']['term'])) 
  64. $term = $this->sanitize($category['attribs']['']['term'], SIMPLEPIE_CONSTRUCT_TEXT); 
  65. if (isset($category['attribs']['']['scheme'])) 
  66. $scheme = $this->sanitize($category['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT); 
  67. if (isset($category['attribs']['']['label'])) 
  68. $label = $this->sanitize($category['attribs']['']['label'], SIMPLEPIE_CONSTRUCT_TEXT); 
  69. $categories[] = $this->registry->create('Category', array($term, $scheme, $label)); 
  70. foreach ((array) $this->get_source_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'category') as $category) 
  71. // This is really the label, but keep this as the term also for BC. 
  72. // Label will also work on retrieving because that falls back to term. 
  73. $term = $this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT); 
  74. if (isset($category['attribs']['']['domain'])) 
  75. $scheme = $this->sanitize($category['attribs']['']['domain'], SIMPLEPIE_CONSTRUCT_TEXT); 
  76. else 
  77. $scheme = null; 
  78. $categories[] = $this->registry->create('Category', array($term, $scheme, null)); 
  79. foreach ((array) $this->get_source_tags(SIMPLEPIE_NAMESPACE_DC_11, 'subject') as $category) 
  80. $categories[] = $this->registry->create('Category', array($this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null)); 
  81. foreach ((array) $this->get_source_tags(SIMPLEPIE_NAMESPACE_DC_10, 'subject') as $category) 
  82. $categories[] = $this->registry->create('Category', array($this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null)); 
  83.  
  84. if (!empty($categories)) 
  85. return array_unique($categories); 
  86. else 
  87. return null; 
  88.  
  89. public function get_author($key = 0) 
  90. $authors = $this->get_authors(); 
  91. if (isset($authors[$key])) 
  92. return $authors[$key]; 
  93. else 
  94. return null; 
  95.  
  96. public function get_authors() 
  97. $authors = array(); 
  98. foreach ((array) $this->get_source_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'author') as $author) 
  99. $name = null; 
  100. $uri = null; 
  101. $email = null; 
  102. if (isset($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data'])) 
  103. $name = $this->sanitize($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); 
  104. if (isset($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['uri'][0]['data'])) 
  105. $uri = $this->sanitize($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['uri'][0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['uri'][0])); 
  106. if (isset($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['email'][0]['data'])) 
  107. $email = $this->sanitize($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); 
  108. if ($name !== null || $email !== null || $uri !== null) 
  109. $authors[] = $this->registry->create('Author', array($name, $uri, $email)); 
  110. if ($author = $this->get_source_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'author')) 
  111. $name = null; 
  112. $url = null; 
  113. $email = null; 
  114. if (isset($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['name'][0]['data'])) 
  115. $name = $this->sanitize($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); 
  116. if (isset($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['url'][0]['data'])) 
  117. $url = $this->sanitize($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['url'][0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['url'][0])); 
  118. if (isset($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['email'][0]['data'])) 
  119. $email = $this->sanitize($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); 
  120. if ($name !== null || $email !== null || $url !== null) 
  121. $authors[] = $this->registry->create('Author', array($name, $url, $email)); 
  122. foreach ((array) $this->get_source_tags(SIMPLEPIE_NAMESPACE_DC_11, 'creator') as $author) 
  123. $authors[] = $this->registry->create('Author', array($this->sanitize($author['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null)); 
  124. foreach ((array) $this->get_source_tags(SIMPLEPIE_NAMESPACE_DC_10, 'creator') as $author) 
  125. $authors[] = $this->registry->create('Author', array($this->sanitize($author['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null)); 
  126. foreach ((array) $this->get_source_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'author') as $author) 
  127. $authors[] = $this->registry->create('Author', array($this->sanitize($author['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null)); 
  128.  
  129. if (!empty($authors)) 
  130. return array_unique($authors); 
  131. else 
  132. return null; 
  133.  
  134. public function get_contributor($key = 0) 
  135. $contributors = $this->get_contributors(); 
  136. if (isset($contributors[$key])) 
  137. return $contributors[$key]; 
  138. else 
  139. return null; 
  140.  
  141. public function get_contributors() 
  142. $contributors = array(); 
  143. foreach ((array) $this->get_source_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'contributor') as $contributor) 
  144. $name = null; 
  145. $uri = null; 
  146. $email = null; 
  147. if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data'])) 
  148. $name = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); 
  149. if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['uri'][0]['data'])) 
  150. $uri = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['uri'][0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['uri'][0])); 
  151. if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['email'][0]['data'])) 
  152. $email = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); 
  153. if ($name !== null || $email !== null || $uri !== null) 
  154. $contributors[] = $this->registry->create('Author', array($name, $uri, $email)); 
  155. foreach ((array) $this->get_source_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'contributor') as $contributor) 
  156. $name = null; 
  157. $url = null; 
  158. $email = null; 
  159. if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['name'][0]['data'])) 
  160. $name = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); 
  161. if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['url'][0]['data'])) 
  162. $url = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['url'][0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['url'][0])); 
  163. if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['email'][0]['data'])) 
  164. $email = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); 
  165. if ($name !== null || $email !== null || $url !== null) 
  166. $contributors[] = $this->registry->create('Author', array($name, $url, $email)); 
  167.  
  168. if (!empty($contributors)) 
  169. return array_unique($contributors); 
  170. else 
  171. return null; 
  172.  
  173. public function get_link($key = 0, $rel = 'alternate') 
  174. $links = $this->get_links($rel); 
  175. if (isset($links[$key])) 
  176. return $links[$key]; 
  177. else 
  178. return null; 
  179.  
  180. /** 
  181. * Added for parity between the parent-level and the item/entry-level. 
  182. */ 
  183. public function get_permalink() 
  184. return $this->get_link(0); 
  185.  
  186. public function get_links($rel = 'alternate') 
  187. if (!isset($this->data['links'])) 
  188. $this->data['links'] = array(); 
  189. if ($links = $this->get_source_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'link')) 
  190. foreach ($links as $link) 
  191. if (isset($link['attribs']['']['href'])) 
  192. $link_rel = (isset($link['attribs']['']['rel'])) ? $link['attribs']['']['rel'] : 'alternate'; 
  193. $this->data['links'][$link_rel][] = $this->sanitize($link['attribs']['']['href'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($link)); 
  194. if ($links = $this->get_source_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'link')) 
  195. foreach ($links as $link) 
  196. if (isset($link['attribs']['']['href'])) 
  197. $link_rel = (isset($link['attribs']['']['rel'])) ? $link['attribs']['']['rel'] : 'alternate'; 
  198. $this->data['links'][$link_rel][] = $this->sanitize($link['attribs']['']['href'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($link)); 
  199.  
  200. if ($links = $this->get_source_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'link')) 
  201. $this->data['links']['alternate'][] = $this->sanitize($links[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($links[0])); 
  202. if ($links = $this->get_source_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'link')) 
  203. $this->data['links']['alternate'][] = $this->sanitize($links[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($links[0])); 
  204. if ($links = $this->get_source_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'link')) 
  205. $this->data['links']['alternate'][] = $this->sanitize($links[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($links[0])); 
  206.  
  207. $keys = array_keys($this->data['links']); 
  208. foreach ($keys as $key) 
  209. if ($this->registry->call('Misc', 'is_isegment_nz_nc', array($key))) 
  210. if (isset($this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key])) 
  211. $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key] = array_merge($this->data['links'][$key], $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key]); 
  212. $this->data['links'][$key] =& $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key]; 
  213. else 
  214. $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key] =& $this->data['links'][$key]; 
  215. elseif (substr($key, 0, 41) === SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY) 
  216. $this->data['links'][substr($key, 41)] =& $this->data['links'][$key]; 
  217. $this->data['links'][$key] = array_unique($this->data['links'][$key]); 
  218.  
  219. if (isset($this->data['links'][$rel])) 
  220. return $this->data['links'][$rel]; 
  221. else 
  222. return null; 
  223.  
  224. public function get_description() 
  225. if ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'subtitle')) 
  226. return $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_10_construct_type', array($return[0]['attribs'])), $this->get_base($return[0])); 
  227. elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'tagline')) 
  228. return $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_03_construct_type', array($return[0]['attribs'])), $this->get_base($return[0])); 
  229. elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'description')) 
  230. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0])); 
  231. elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'description')) 
  232. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0])); 
  233. elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'description')) 
  234. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0])); 
  235. elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_DC_11, 'description')) 
  236. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); 
  237. elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_DC_10, 'description')) 
  238. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); 
  239. elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'summary')) 
  240. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_HTML, $this->get_base($return[0])); 
  241. elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'subtitle')) 
  242. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_HTML, $this->get_base($return[0])); 
  243. else 
  244. return null; 
  245.  
  246. public function get_copyright() 
  247. if ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'rights')) 
  248. return $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_10_construct_type', array($return[0]['attribs'])), $this->get_base($return[0])); 
  249. elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'copyright')) 
  250. return $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_03_construct_type', array($return[0]['attribs'])), $this->get_base($return[0])); 
  251. elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'copyright')) 
  252. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); 
  253. elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_DC_11, 'rights')) 
  254. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); 
  255. elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_DC_10, 'rights')) 
  256. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); 
  257. else 
  258. return null; 
  259.  
  260. public function get_language() 
  261. if ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'language')) 
  262. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); 
  263. elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_DC_11, 'language')) 
  264. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); 
  265. elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_DC_10, 'language')) 
  266. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); 
  267. elseif (isset($this->data['xml_lang'])) 
  268. return $this->sanitize($this->data['xml_lang'], SIMPLEPIE_CONSTRUCT_TEXT); 
  269. else 
  270. return null; 
  271.  
  272. public function get_latitude() 
  273. if ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_W3C_BASIC_GEO, 'lat')) 
  274. return (float) $return[0]['data']; 
  275. elseif (($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_GEORSS, 'point')) && preg_match('/^((?:-)?[0-9]+(?:\.[0-9]+)) ((?:-)?[0-9]+(?:\.[0-9]+))$/', trim($return[0]['data']), $match)) 
  276. return (float) $match[1]; 
  277. else 
  278. return null; 
  279.  
  280. public function get_longitude() 
  281. if ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_W3C_BASIC_GEO, 'long')) 
  282. return (float) $return[0]['data']; 
  283. elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_W3C_BASIC_GEO, 'lon')) 
  284. return (float) $return[0]['data']; 
  285. elseif (($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_GEORSS, 'point')) && preg_match('/^((?:-)?[0-9]+(?:\.[0-9]+)) ((?:-)?[0-9]+(?:\.[0-9]+))$/', trim($return[0]['data']), $match)) 
  286. return (float) $match[2]; 
  287. else 
  288. return null; 
  289.  
  290. public function get_image_url() 
  291. if ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'image')) 
  292. return $this->sanitize($return[0]['attribs']['']['href'], SIMPLEPIE_CONSTRUCT_IRI); 
  293. elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'logo')) 
  294. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($return[0])); 
  295. elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'icon')) 
  296. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($return[0])); 
  297. else 
  298. return null;