]>
git.immae.eu Git - github/wallabag/wallabag.git/blob - inc/3rdparty/libraries/feedwriter/FeedItem.php
3 * Univarsel Feed Writer
5 * FeedItem class - Used as feed element in FeedWriter class
7 * @package UnivarselFeedWriter
8 * @author Anis uddin Ahmad <anisniit@gmail.com>
9 * @link http://www.ajaxray.com/projects/rss
13 private $elements = array(); //Collection of feed elements
19 * @param contant (RSS1/RSS2/ATOM) RSS2 is default.
21 function __construct($version = RSS2
)
23 $this->version
= $version;
27 * Set element (overwrites existing elements with $elementName)
30 * @param srting The tag name of an element
31 * @param srting The content of tag
32 * @param array Attributes(if any) in 'attrName' => 'attrValue' format
35 public function setElement($elementName, $content, $attributes = null)
37 if (isset($this->elements
[$elementName])) {
38 unset($this->elements
[$elementName]);
40 $this->addElement($elementName, $content, $attributes);
44 * Add an element to elements array
47 * @param srting The tag name of an element
48 * @param srting The content of tag
49 * @param array Attributes(if any) in 'attrName' => 'attrValue' format
52 public function addElement($elementName, $content, $attributes = null)
55 if (isset($this->elements
[$elementName])) {
56 $i = count($this->elements
[$elementName]);
58 $this->elements
[$elementName] = array();
60 $this->elements
[$elementName][$i]['name'] = $elementName;
61 $this->elements
[$elementName][$i]['content'] = $content;
62 $this->elements
[$elementName][$i]['attributes'] = $attributes;
66 * Set multiple feed elements from an array.
67 * Elements which have attributes cannot be added by this method
70 * @param array array of elements in 'tagName' => 'tagContent' format.
73 public function addElementArray($elementArray)
75 if(! is_array($elementArray)) return;
76 foreach ($elementArray as $elementName => $content)
78 $this->addElement($elementName, $content);
83 * Return the collection of elements in this feed item
88 public function getElements()
90 return $this->elements
;
93 // Wrapper functions ------------------------------------------------------
96 * Set the 'dscription' element of feed item
99 * @param string The content of 'description' element
102 public function setDescription($description)
104 $this->setElement('description', $description);
108 * @desc Set the 'title' element of feed item
110 * @param string The content of 'title' element
113 public function setTitle($title)
115 $this->setElement('title', $title);
119 * Set the 'date' element of feed item
122 * @param string The content of 'date' element
125 public function setDate($date)
127 if(! is_numeric($date))
129 $date = strtotime($date);
132 if($this->version
== RSS2
)
135 $value = date(DATE_RSS
, $date);
140 $value = date("Y-m-d", $date);
143 $this->setElement($tag, $value);
147 * Set the 'link' element of feed item
150 * @param string The content of 'link' element
153 public function setLink($link)
155 if($this->version
== RSS2
|| $this->version
== RSS1
)
157 $this->setElement('link', $link);
158 $this->setElement('guid', $link);
162 $this->setElement('link','',array('href'=>$link));
163 $this->setElement('id', FeedWriter
::uuid($link,'urn:uuid:'));
169 * Set the 'source' element of feed item
172 * @param string The content of 'source' element
175 public function setSource($link)
177 $attributes = array('url'=>$link);
178 $this->setElement('source', "wallabag",$attributes);
182 * Set the 'encloser' element of feed item
186 * @param string The url attribute of encloser tag
187 * @param string The length attribute of encloser tag
188 * @param string The type attribute of encloser tag
191 public function setEncloser($url, $length, $type)
193 $attributes = array('url'=>$url, 'length'=>$length, 'type'=>$type);
194 $this->setElement('enclosure','',$attributes);
197 } // end of class FeedItem