]> git.immae.eu Git - github/wallabag/wallabag.git/blobdiff - inc/3rdparty/libraries/feedwriter/FeedItem.php
[change] we now use Full-Text RSS 3.1, thank you so much @fivefilters
[github/wallabag/wallabag.git] / inc / 3rdparty / libraries / feedwriter / FeedItem.php
similarity index 70%
rename from inc/3rdparty/feedwriter/FeedItem.php
rename to inc/3rdparty/libraries/feedwriter/FeedItem.php
index 71e6e98cee8cdf02c98692e434f8cebf7b2de6b9..6761eb0ed1f9e96a14d7d08d9d03ceb928cbb966 100644 (file)
-<?php
- /**
- * Univarsel Feed Writer
- * 
- * FeedItem class - Used as feed element in FeedWriter class
- *
- * @package         UnivarselFeedWriter
- * @author          Anis uddin Ahmad <anisniit@gmail.com>
- * @link            http://www.ajaxray.com/projects/rss
- */
- class FeedItem
- {
-       private $elements = array();    //Collection of feed elements
-       private $version;
-       
-       /**
-       * Constructor 
-       * 
-       * @param    contant     (RSS1/RSS2/ATOM) RSS2 is default. 
-       */ 
-       function __construct($version = RSS2)
-       {    
-               $this->version = $version;
-       }
-       
-       /**
-       * Add an element to elements array
-       * 
-       * @access   public
-       * @param    srting  The tag name of an element
-       * @param    srting  The content of tag
-       * @param    array   Attributes(if any) in 'attrName' => 'attrValue' format
-       * @return   void
-       */
-       public function addElement($elementName, $content, $attributes = null)
-       {
-               $this->elements[$elementName]['name']       = $elementName;
-               $this->elements[$elementName]['content']    = $content;
-               $this->elements[$elementName]['attributes'] = $attributes;
-       }
-       
-       /**
-       * Set multiple feed elements from an array. 
-       * Elements which have attributes cannot be added by this method
-       * 
-       * @access   public
-       * @param    array   array of elements in 'tagName' => 'tagContent' format.
-       * @return   void
-       */
-       public function addElementArray($elementArray)
-       {
-               if(! is_array($elementArray)) return;
-               foreach ($elementArray as $elementName => $content) 
-               {
-                       $this->addElement($elementName, $content);
-               }
-       }
-       
-       /**
-       * Return the collection of elements in this feed item
-       * 
-       * @access   public
-       * @return   array
-       */
-       public function getElements()
-       {
-               return $this->elements;
-       }
-       
-       // Wrapper functions ------------------------------------------------------
-       
-       /**
-       * Set the 'dscription' element of feed item
-       * 
-       * @access   public
-       * @param    string  The content of 'description' element
-       * @return   void
-       */
-       public function setDescription($description) 
-       {
-               $tag = ($this->version == ATOM)? 'summary' : 'description'; 
-               $this->addElement($tag, $description);
-       }
-       
-       /**
-       * @desc     Set the 'title' element of feed item
-       * @access   public
-       * @param    string  The content of 'title' element
-       * @return   void
-       */
-       public function setTitle($title) 
-       {
-               $this->addElement('title', $title);     
-       }
-       
-       /**
-       * Set the 'date' element of feed item
-       * 
-       * @access   public
-       * @param    string  The content of 'date' element
-       * @return   void
-       */
-       public function setDate($date) 
-       {
-               if(! is_numeric($date))
-               {
-                       $date = strtotime($date);
-               }
-               
-               if($this->version == ATOM)
-               {
-                       $tag    = 'updated';
-                       $value  = date(DATE_ATOM, $date);
-               }        
-               elseif($this->version == RSS2) 
-               {
-                       $tag    = 'pubDate';
-                       $value  = date(DATE_RSS, $date);
-               }
-               else                                
-               {
-                       $tag    = 'dc:date';
-                       $value  = date("Y-m-d", $date);
-               }
-               
-               $this->addElement($tag, $value);    
-       }
-       
-       /**
-       * Set the 'link' element of feed item
-       * 
-       * @access   public
-       * @param    string  The content of 'link' element
-       * @return   void
-       */
-       public function setLink($link) 
-       {
-               if($this->version == RSS2 || $this->version == RSS1)
-               {
-                       $this->addElement('link', $link);
-               }
-               else
-               {
-                       $this->addElement('link','',array('href'=>$link));
-                       $this->addElement('id', FeedWriter::uuid($link,'urn:uuid:'));
-               } 
-               
-       }
-       
-       /**
-       * Set the 'encloser' element of feed item
-       * For RSS 2.0 only
-       * 
-       * @access   public
-       * @param    string  The url attribute of encloser tag
-       * @param    string  The length attribute of encloser tag
-       * @param    string  The type attribute of encloser tag
-       * @return   void
-       */
-       public function setEncloser($url, $length, $type)
-       {
-               $attributes = array('url'=>$url, 'length'=>$length, 'type'=>$type);
-               $this->addElement('enclosure','',$attributes);
-       }
-       
- } // end of class FeedItem
-?>
+<?php\r
+ /**\r
+ * Univarsel Feed Writer\r
+ * \r
+ * FeedItem class - Used as feed element in FeedWriter class\r
+ *\r
+ * @package         UnivarselFeedWriter\r
+ * @author          Anis uddin Ahmad <anisniit@gmail.com>\r
+ * @link            http://www.ajaxray.com/projects/rss\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 = ($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
+               }\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
+ } // end of class FeedItem\r
+?>\r