]> git.immae.eu Git - github/wallabag/wallabag.git/commitdiff
in RSS feed, add link to wallabag URL #556 606/head
authorNicolas Lœuillet <nicolas@loeuillet.org>
Sun, 6 Apr 2014 14:39:11 +0000 (16:39 +0200)
committerNicolas Lœuillet <nicolas@loeuillet.org>
Sun, 6 Apr 2014 14:39:11 +0000 (16:39 +0200)
inc/3rdparty/libraries/feedwriter/FeedItem.php
inc/poche/Poche.class.php

index 0eae5e086b9bbfc3709822a72b29d209b92fc22a..7e467ce8562a1a47618a658d79a74337df59042e 100644 (file)
  */\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
+    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
+    * 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
+        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 '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
+        $this->setElement('source', $link);\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
index a662f695eaffd261a85514e8a7401bfc094516ae..a7bee65d6aa6f04bb8094b12e0ae9764fcbd59d3 100755 (executable)
@@ -828,7 +828,7 @@ class Poche
         define('IMPORT_LIMIT', 5);
       }
       if (!defined('IMPORT_DELAY')) {
-       define('IMPORT_DELAY', 5);
+        define('IMPORT_DELAY', 5);
       }
 
       if ( isset($_FILES['file']) ) {
@@ -844,18 +844,18 @@ class Poche
           $read = 0;
           foreach (array('ol','ul') as $list) {
             foreach ($html->find($list) as $ul) {
-               foreach ($ul->find('li') as $li) {
-                 $tmpEntry = array();
-                       $a = $li->find('a');
-                       $tmpEntry['url'] = $a[0]->href;
-                       $tmpEntry['tags'] = $a[0]->tags;
-                       $tmpEntry['is_read'] = $read;
-                       if ($tmpEntry['url']) {
-                         $data[] = $tmpEntry;
-                       }
-               }
-               # the second <ol/ul> is for read links
-               $read = ((sizeof($data) && $read)?0:1);
+                foreach ($ul->find('li') as $li) {
+                  $tmpEntry = array();
+                    $a = $li->find('a');
+                    $tmpEntry['url'] = $a[0]->href;
+                    $tmpEntry['tags'] = $a[0]->tags;
+                    $tmpEntry['is_read'] = $read;
+                    if ($tmpEntry['url']) {
+                      $data[] = $tmpEntry;
+                    }
+                }
+                # the second <ol/ul> is for read links
+                $read = ((sizeof($data) && $read)?0:1);
             }
           }
         }
@@ -866,7 +866,7 @@ class Poche
             $data[] = $record;
             foreach ($record as $record2) {
               if (is_array($record2)) {
-               $data[] = $record2;
+                $data[] = $record2;
               }
             }
           }
@@ -886,7 +886,7 @@ class Poche
               //increment no of records inserted
               $i++;
               if ( isset($record['tags']) && trim($record['tags']) ) {
-               //@TODO: set tags
+                //@TODO: set tags
 
               }
             }
@@ -919,17 +919,17 @@ class Poche
           $purifier = new HTMLPurifier($config);
 
           foreach ($items as $item) {
-               $url = new Url(base64_encode($item['url']));
-               $content = Tools::getPageContent($url);
+            $url = new Url(base64_encode($item['url']));
+            $content = Tools::getPageContent($url);
 
-               $title = (($content['rss']['channel']['item']['title'] != '') ? $content['rss']['channel']['item']['title'] : _('Untitled'));
-               $body = (($content['rss']['channel']['item']['description'] != '') ? $content['rss']['channel']['item']['description'] : _('Undefined'));
+            $title = (($content['rss']['channel']['item']['title'] != '') ? $content['rss']['channel']['item']['title'] : _('Untitled'));
+            $body = (($content['rss']['channel']['item']['description'] != '') ? $content['rss']['channel']['item']['description'] : _('Undefined'));
 
-               //clean content to prevent xss attack
-               $title = $purifier->purify($title);
-               $body = $purifier->purify($body);
+            //clean content to prevent xss attack
+            $title = $purifier->purify($title);
+            $body = $purifier->purify($body);
 
-               $this->store->updateContentAndTitle($item['id'], $title, $body, $this->user->getId());
+            $this->store->updateContentAndTitle($item['id'], $title, $body, $this->user->getId());
           }
 
         }
@@ -944,8 +944,8 @@ class Poche
      */
     public function export()
     {
-               $filename = "wallabag-export-".$this->user->getId()."-".date("Y-m-d").".json";
-               header('Content-Disposition: attachment; filename='.$filename);
+        $filename = "wallabag-export-".$this->user->getId()."-".date("Y-m-d").".json";
+        header('Content-Disposition: attachment; filename='.$filename);
 
         $entries = $this->store->retrieveAll($this->user->getId());
         echo $this->tpl->render('export.twig', array(
@@ -978,13 +978,13 @@ class Poche
     public function generateToken()
     {
         if (ini_get('open_basedir') === '') {
-                       if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
-                       echo 'This is a server using Windows!';
-                       // alternative to /dev/urandom for Windows
-                       $token = substr(base64_encode(uniqid(mt_rand(), true)), 0, 20);
-                       } else {
-                       $token = substr(base64_encode(file_get_contents('/dev/urandom', false, null, 0, 20)), 0, 15);
-                       }
+            if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
+            echo 'This is a server using Windows!';
+            // alternative to /dev/urandom for Windows
+            $token = substr(base64_encode(uniqid(mt_rand(), true)), 0, 20);
+            } else {
+            $token = substr(base64_encode(file_get_contents('/dev/urandom', false, null, 0, 20)), 0, 15);
+            }
         }
         else {
             $token = substr(base64_encode(uniqid(mt_rand(), true)), 0, 20);
@@ -1031,6 +1031,7 @@ class Poche
             foreach ($entries as $entry) {
                 $newItem = $feed->createNewItem();
                 $newItem->setTitle($entry['title']);
+                $newItem->setSource(Tools::getPocheUrl() . '?view=view&amp;id=' . $entry['id']);
                 $newItem->setLink($entry['url']);
                 $newItem->setDate(time());
                 $newItem->setDescription($entry['content']);