]>
git.immae.eu Git - github/wallabag/wallabag.git/blob - inc/3rdparty/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 * Add an element to elements array
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 addElement($elementName, $content, $attributes = null)
37 $this->elements
[$elementName]['name'] = $elementName;
38 $this->elements
[$elementName]['content'] = $content;
39 $this->elements
[$elementName]['attributes'] = $attributes;
43 * Set multiple feed elements from an array.
44 * Elements which have attributes cannot be added by this method
47 * @param array array of elements in 'tagName' => 'tagContent' format.
50 public function addElementArray($elementArray)
52 if(! is_array($elementArray)) return;
53 foreach ($elementArray as $elementName => $content)
55 $this->addElement($elementName, $content);
60 * Return the collection of elements in this feed item
65 public function getElements()
67 return $this->elements
;
70 // Wrapper functions ------------------------------------------------------
73 * Set the 'dscription' element of feed item
76 * @param string The content of 'description' element
79 public function setDescription($description)
81 $tag = ($this->version
== ATOM
)? 'summary' : 'description';
82 $this->addElement($tag, $description);
86 * @desc Set the 'title' element of feed item
88 * @param string The content of 'title' element
91 public function setTitle($title)
93 $this->addElement('title', $title);
97 * Set the 'date' element of feed item
100 * @param string The content of 'date' element
103 public function setDate($date)
105 if(! is_numeric($date))
107 $date = strtotime($date);
110 if($this->version
== ATOM
)
113 $value = date(DATE_ATOM
, $date);
115 elseif($this->version
== RSS2
)
118 $value = date(DATE_RSS
, $date);
123 $value = date("Y-m-d", $date);
126 $this->addElement($tag, $value);
130 * Set the 'link' element of feed item
133 * @param string The content of 'link' element
136 public function setLink($link)
138 if($this->version
== RSS2
|| $this->version
== RSS1
)
140 $this->addElement('link', $link);
144 $this->addElement('link','',array('href'=>$link));
145 $this->addElement('id', FeedWriter
::uuid($link,'urn:uuid:'));
151 * Set the 'encloser' element of feed item
155 * @param string The url attribute of encloser tag
156 * @param string The length attribute of encloser tag
157 * @param string The type attribute of encloser tag
160 public function setEncloser($url, $length, $type)
162 $attributes = array('url'=>$url, 'length'=>$length, 'type'=>$type);
163 $this->addElement('enclosure','',$attributes);
166 } // end of class FeedItem