<?php\r
/**\r
* Univarsel Feed Writer\r
- * \r
+ *\r
* FeedItem class - Used as feed element in FeedWriter class\r
*\r
* @package UnivarselFeedWriter\r
*/\r
class FeedItem\r
{\r
- private $elements = array(); //Collection of feed elements\r
- private $version;\r
- \r
- /**\r
- * Constructor \r
- * \r
- * @param contant (RSS1/RSS2/ATOM) RSS2 is default. \r
- */ \r
- function __construct($version = RSS2)\r
- { \r
- $this->version = $version;\r
- }\r
-\r
- /**\r
- * Set element (overwrites existing elements with $elementName)\r
- * \r
- * @access public\r
- * @param srting The tag name of an element\r
- * @param srting The content of tag\r
- * @param array Attributes(if any) in 'attrName' => 'attrValue' format\r
- * @return void\r
- */\r
- public function setElement($elementName, $content, $attributes = null)\r
- {\r
- if (isset($this->elements[$elementName])) {\r
- unset($this->elements[$elementName]);\r
- }\r
- $this->addElement($elementName, $content, $attributes);\r
- } \r
- \r
- /**\r
- * Add an element to elements array\r
- * \r
- * @access public\r
- * @param srting The tag name of an element\r
- * @param srting The content of tag\r
- * @param array Attributes(if any) in 'attrName' => 'attrValue' format\r
- * @return void\r
- */\r
- public function addElement($elementName, $content, $attributes = null)\r
- {\r
- $i = 0;\r
- if (isset($this->elements[$elementName])) {\r
- $i = count($this->elements[$elementName]);\r
- } else {\r
- $this->elements[$elementName] = array();\r
- }\r
- $this->elements[$elementName][$i]['name'] = $elementName;\r
- $this->elements[$elementName][$i]['content'] = $content;\r
- $this->elements[$elementName][$i]['attributes'] = $attributes;\r
- }\r
- \r
- /**\r
- * Set multiple feed elements from an array. \r
- * Elements which have attributes cannot be added by this method\r
- * \r
- * @access public\r
- * @param array array of elements in 'tagName' => 'tagContent' format.\r
- * @return void\r
- */\r
- public function addElementArray($elementArray)\r
- {\r
- if(! is_array($elementArray)) return;\r
- foreach ($elementArray as $elementName => $content) \r
- {\r
- $this->addElement($elementName, $content);\r
- }\r
- }\r
- \r
- /**\r
- * Return the collection of elements in this feed item\r
- * \r
- * @access public\r
- * @return array\r
- */\r
- public function getElements()\r
- {\r
- return $this->elements;\r
- }\r
- \r
- // Wrapper functions ------------------------------------------------------\r
- \r
- /**\r
- * Set the 'dscription' element of feed item\r
- * \r
- * @access public\r
- * @param string The content of 'description' element\r
- * @return void\r
- */\r
- public function setDescription($description) \r
- {\r
- $tag = 'description'; \r
- $this->setElement($tag, $description);\r
- }\r
- \r
- /**\r
- * @desc Set the 'title' element of feed item\r
- * @access public\r
- * @param string The content of 'title' element\r
- * @return void\r
- */\r
- public function setTitle($title) \r
- {\r
- $this->setElement('title', $title); \r
- }\r
- \r
- /**\r
- * Set the 'date' element of feed item\r
- * \r
- * @access public\r
- * @param string The content of 'date' element\r
- * @return void\r
- */\r
- public function setDate($date) \r
- {\r
- if(! is_numeric($date))\r
- {\r
- $date = strtotime($date);\r
- }\r
- \r
- if($this->version == RSS2) \r
- {\r
- $tag = 'pubDate';\r
- $value = date(DATE_RSS, $date);\r
- }\r
- else \r
- {\r
- $tag = 'dc:date';\r
- $value = date("Y-m-d", $date);\r
- }\r
- \r
- $this->setElement($tag, $value); \r
- }\r
- \r
- /**\r
- * Set the 'link' element of feed item\r
- * \r
- * @access public\r
- * @param string The content of 'link' element\r
- * @return void\r
- */\r
- public function setLink($link) \r
- {\r
- if($this->version == RSS2 || $this->version == RSS1)\r
- {\r
- $this->setElement('link', $link);\r
- $this->setElement('guid', $link);\r
- }\r
- else\r
- {\r
- $this->setElement('link','',array('href'=>$link));\r
- $this->setElement('id', FeedWriter::uuid($link,'urn:uuid:'));\r
- } \r
- \r
- }\r
- \r
- /**\r
- * Set the 'encloser' element of feed item\r
- * For RSS 2.0 only\r
- * \r
- * @access public\r
- * @param string The url attribute of encloser tag\r
- * @param string The length attribute of encloser tag\r
- * @param string The type attribute of encloser tag\r
- * @return void\r
- */\r
- public function setEncloser($url, $length, $type)\r
- {\r
- $attributes = array('url'=>$url, 'length'=>$length, 'type'=>$type);\r
- $this->setElement('enclosure','',$attributes);\r
- }\r
- \r
+ private $elements = array(); //Collection of feed elements\r
+ private $version;\r
+\r
+ /**\r
+ * Constructor\r
+ *\r
+ * @param contant (RSS1/RSS2/ATOM) RSS2 is default.\r
+ */\r
+ function __construct($version = RSS2)\r
+ {\r
+ $this->version = $version;\r
+ }\r
+\r
+ /**\r
+ * Set element (overwrites existing elements with $elementName)\r
+ *\r
+ * @access public\r
+ * @param srting The tag name of an element\r
+ * @param srting The content of tag\r
+ * @param array Attributes(if any) in 'attrName' => 'attrValue' format\r
+ * @return void\r
+ */\r
+ public function setElement($elementName, $content, $attributes = null)\r
+ {\r
+ if (isset($this->elements[$elementName])) {\r
+ unset($this->elements[$elementName]);\r
+ }\r
+ $this->addElement($elementName, $content, $attributes);\r
+ }\r
+\r
+ /**\r
+ * Add an element to elements array\r
+ *\r
+ * @access public\r
+ * @param srting The tag name of an element\r
+ * @param srting The content of tag\r
+ * @param array Attributes(if any) in 'attrName' => 'attrValue' format\r
+ * @return void\r
+ */\r
+ public function addElement($elementName, $content, $attributes = null)\r
+ {\r
+ $i = 0;\r
+ if (isset($this->elements[$elementName])) {\r
+ $i = count($this->elements[$elementName]);\r
+ } else {\r
+ $this->elements[$elementName] = array();\r
+ }\r
+ $this->elements[$elementName][$i]['name'] = $elementName;\r
+ $this->elements[$elementName][$i]['content'] = $content;\r
+ $this->elements[$elementName][$i]['attributes'] = $attributes;\r
+ }\r
+\r
+ /**\r
+ * Set multiple feed elements from an array.\r
+ * Elements which have attributes cannot be added by this method\r
+ *\r
+ * @access public\r
+ * @param array array of elements in 'tagName' => 'tagContent' format.\r
+ * @return void\r
+ */\r
+ public function addElementArray($elementArray)\r
+ {\r
+ if(! is_array($elementArray)) return;\r
+ foreach ($elementArray as $elementName => $content)\r
+ {\r
+ $this->addElement($elementName, $content);\r
+ }\r
+ }\r
+\r
+ /**\r
+ * Return the collection of elements in this feed item\r
+ *\r
+ * @access public\r
+ * @return array\r
+ */\r
+ public function getElements()\r
+ {\r
+ return $this->elements;\r
+ }\r
+\r
+ // Wrapper functions ------------------------------------------------------\r
+\r
+ /**\r
+ * Set the 'dscription' element of feed item\r
+ *\r
+ * @access public\r
+ * @param string The content of 'description' element\r
+ * @return void\r
+ */\r
+ public function setDescription($description)\r
+ {\r
+ $tag = ($this->version == ATOM)? 'summary' : 'description';\r
+ $this->setElement($tag, $description);\r
+ }\r
+\r
+ /**\r
+ * @desc Set the 'title' element of feed item\r
+ * @access public\r
+ * @param string The content of 'title' element\r
+ * @return void\r
+ */\r
+ public function setTitle($title)\r
+ {\r
+ $this->setElement('title', $title);\r
+ }\r
+\r
+ /**\r
+ * Set the 'date' element of feed item\r
+ *\r
+ * @access public\r
+ * @param string The content of 'date' element\r
+ * @return void\r
+ */\r
+ public function setDate($date)\r
+ {\r
+ if(! is_numeric($date))\r
+ {\r
+ $date = strtotime($date);\r
+ }\r
+\r
+ if($this->version == ATOM)\r
+ {\r
+ $tag = 'updated';\r
+ $value = date(DATE_ATOM, $date);\r
+ }\r
+ elseif($this->version == RSS2)\r
+ {\r
+ $tag = 'pubDate';\r
+ $value = date(DATE_RSS, $date);\r
+ }\r
+ else\r
+ {\r
+ $tag = 'dc:date';\r
+ $value = date("Y-m-d", $date);\r
+ }\r
+\r
+ $this->setElement($tag, $value);\r
+ }\r
+\r
+ /**\r
+ * Set the 'link' element of feed item\r
+ *\r
+ * @access public\r
+ * @param string The content of 'link' element\r
+ * @return void\r
+ */\r
+ public function setLink($link)\r
+ {\r
+ if($this->version == RSS2 || $this->version == RSS1)\r
+ {\r
+ $this->setElement('link', $link);\r
+ $this->setElement('guid', $link);\r
+ }\r
+ else\r
+ {\r
+ $this->setElement('link','',array('href'=>$link));\r
+ $this->setElement('id', FeedWriter::uuid($link,'urn:uuid:'));\r
+ }\r
+\r
+ }\r
+\r
+ /**\r
+ * Set the 'source' element of feed item\r
+ *\r
+ * @access public\r
+ * @param string The content of 'source' element\r
+ * @return void\r
+ */\r
+ public function setSource($link)\r
+ {\r
+ $attributes = array('url'=>$link);\r
+ $this->setElement('source', "wallabag",$attributes);\r
+ }\r
+\r
+ /**\r
+ * Set the 'encloser' element of feed item\r
+ * For RSS 2.0 only\r
+ *\r
+ * @access public\r
+ * @param string The url attribute of encloser tag\r
+ * @param string The length attribute of encloser tag\r
+ * @param string The type attribute of encloser tag\r
+ * @return void\r
+ */\r
+ public function setEncloser($url, $length, $type)\r
+ {\r
+ $attributes = array('url'=>$url, 'length'=>$length, 'type'=>$type);\r
+ $this->setElement('enclosure','',$attributes);\r
+ }\r
+\r
} // end of class FeedItem\r
-?>\r
+?>
\ No newline at end of file