Chris@0
|
1 <?php
|
Chris@0
|
2 /**
|
Chris@0
|
3 * Zend Framework (http://framework.zend.com/)
|
Chris@0
|
4 *
|
Chris@0
|
5 * @link http://github.com/zendframework/zf2 for the canonical source repository
|
Chris@0
|
6 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
Chris@0
|
7 * @license http://framework.zend.com/license/new-bsd New BSD License
|
Chris@0
|
8 */
|
Chris@0
|
9
|
Chris@0
|
10 namespace Zend\Feed\Reader\Extension\CreativeCommons;
|
Chris@0
|
11
|
Chris@0
|
12 use Zend\Feed\Reader\Extension;
|
Chris@0
|
13
|
Chris@0
|
14 class Entry extends Extension\AbstractEntry
|
Chris@0
|
15 {
|
Chris@0
|
16 /**
|
Chris@0
|
17 * Get the entry license
|
Chris@0
|
18 *
|
Chris@0
|
19 * @param int $index
|
Chris@0
|
20 * @return string|null
|
Chris@0
|
21 */
|
Chris@0
|
22 public function getLicense($index = 0)
|
Chris@0
|
23 {
|
Chris@0
|
24 $licenses = $this->getLicenses();
|
Chris@0
|
25
|
Chris@0
|
26 if (isset($licenses[$index])) {
|
Chris@0
|
27 return $licenses[$index];
|
Chris@0
|
28 }
|
Chris@0
|
29
|
Chris@0
|
30 return;
|
Chris@0
|
31 }
|
Chris@0
|
32
|
Chris@0
|
33 /**
|
Chris@0
|
34 * Get the entry licenses
|
Chris@0
|
35 *
|
Chris@0
|
36 * @return array
|
Chris@0
|
37 */
|
Chris@0
|
38 public function getLicenses()
|
Chris@0
|
39 {
|
Chris@0
|
40 $name = 'licenses';
|
Chris@0
|
41 if (array_key_exists($name, $this->data)) {
|
Chris@0
|
42 return $this->data[$name];
|
Chris@0
|
43 }
|
Chris@0
|
44
|
Chris@0
|
45 $licenses = [];
|
Chris@0
|
46 $list = $this->xpath->evaluate($this->getXpathPrefix() . '//cc:license');
|
Chris@0
|
47
|
Chris@0
|
48 if ($list->length) {
|
Chris@0
|
49 foreach ($list as $license) {
|
Chris@0
|
50 $licenses[] = $license->nodeValue;
|
Chris@0
|
51 }
|
Chris@0
|
52
|
Chris@0
|
53 $licenses = array_unique($licenses);
|
Chris@0
|
54 } else {
|
Chris@0
|
55 $cc = new Feed();
|
Chris@0
|
56 $licenses = $cc->getLicenses();
|
Chris@0
|
57 }
|
Chris@0
|
58
|
Chris@0
|
59 $this->data[$name] = $licenses;
|
Chris@0
|
60
|
Chris@0
|
61 return $this->data[$name];
|
Chris@0
|
62 }
|
Chris@0
|
63
|
Chris@0
|
64 /**
|
Chris@0
|
65 * Register Creative Commons namespaces
|
Chris@0
|
66 *
|
Chris@0
|
67 */
|
Chris@0
|
68 protected function registerNamespaces()
|
Chris@0
|
69 {
|
Chris@0
|
70 $this->xpath->registerNamespace('cc', 'http://backend.userland.com/creativeCommonsRssModule');
|
Chris@0
|
71 }
|
Chris@0
|
72 }
|