]>
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 $tag = 'description';
105 $this->setElement($tag, $description);
109 * @desc Set the 'title' element of feed item
111 * @param string The content of 'title' element
114 public function setTitle($title)
116 $this->setElement('title', $title);
120 * Set the 'date' element of feed item
123 * @param string The content of 'date' element
126 public function setDate($date)
128 if(! is_numeric($date))
130 $date = strtotime($date);
133 if($this->version
== RSS2
)
136 $value = date(DATE_RSS
, $date);
141 $value = date("Y-m-d", $date);
144 $this->setElement($tag, $value);
148 * Set the 'link' element of feed item
151 * @param string The content of 'link' element
154 public function setLink($link)
156 if($this->version
== RSS2
|| $this->version
== RSS1
)
158 $this->setElement('link', $link);
159 $this->setElement('guid', $link);
163 $this->setElement('link','',array('href'=>$link));
164 $this->setElement('id', FeedWriter
::uuid($link,'urn:uuid:'));
170 * Set the 'encloser' element of feed item
174 * @param string The url attribute of encloser tag
175 * @param string The length attribute of encloser tag
176 * @param string The type attribute of encloser tag
179 public function setEncloser($url, $length, $type)
181 $attributes = array('url'=>$url, 'length'=>$length, 'type'=>$type);
182 $this->setElement('enclosure','',$attributes);
185 } // end of class FeedItem