EFeedItemAbstract.php
3.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
<?php
/**
* EFeedItemAbstract Class file
* @author Antonio Ramirez
* @link http://www.ramirezcobos.com
*
*
* THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/**
* EFeedItemAbstract is the base class for all Feed Items Adapters
*
*
* @author Antonio Ramirez Cobos <ramirez.cobos@gmail.com>
* @package rss
*/
abstract class EFeedItemAbstract extends CComponent {
/**
*
* All element tags of this item collection
* @var CTypedMap('EFeedTag')
*/
protected $tags;
/**
*
* CDATAEncoded items for all different adapters
* @var array
*/
protected $CDATAEncoded = array('description', 'content:encoded', 'summary');
/**
*
* Class constructor
*/
function __construct()
{
$this->tags = new CTypedMap('EFeedTag');
}
/**
*
* Adds a tag to collection
* @param string $tag name of the element
* @param string $content of the element
* @param array $attributes of the tag
*/
public function addTag($tag, $content, $attributes = array())
{
$this->tags->add($tag, new EFeedTag($tag, $content,(!is_array($attributes)? array() : $attributes)));
}
/**
*
* Returns specific tag by name
* @param string $name of the tag
* @return EFeedTag $tag
*/
public function getTag( $name )
{
return $this->tags->itemAt( $name );
}
/**
*
* Property title setter (thanks to CComponent)
* <pre>
* $feed->title = 'mytitle';
* </pre>
* @param string $title
*/
public function setTitle($title) {
$this->addTag('title', $title);
}
/**
*
* @return string title tag
*/
public function getTitle(){
return $this->tags->itemAt('title');
}
/**
*
* Property description setter
* @param string $description
*/
public function setDescription( $description ){
$this->addTag('description', $description);
}
/**
*
* @return string description tag
*/
public function getDescription( ){
return $this->tags->itemAt('description');
}
/**
*
* Property link setter
* @param string URI $link
*/
public function setLink($link) {
$validator = new CUrlValidator();
$validator->pattern = '/(((f|ht){1}tp:\/\/)[-a-zA-Z0-9@:%_\+.~#?&\/\/=]+)/i';
if(!$validator->validateValue($link))
throw new CException( Yii::t('EFeed', $link. ' does not seem to be a valid URL') );
$this->addTag('link', $link);
}
/**
*
* @return link tag
*/
public function getLink(){
return $this->tags->itemAt('link');
}
/**
*
* Abstract property setter Ddte
* @param time() integer|string $date
*/
public abstract function setDate( $date );
/**
*
* Creates a single node as xml format
* @return string formatted xml tag
*/
public abstract function getNode();
}