]> git.immae.eu Git - github/shaarli/Shaarli.git/blobdiff - application/FeedBuilder.php
Merge pull request #1234 from virtualtam/lint
[github/shaarli/Shaarli.git] / application / FeedBuilder.php
index ddefe6ce93a83ed8f6869d1eee57941264731e72..73fafcbed31cb733ac0bf99611313d861a1b60a0 100644 (file)
@@ -62,11 +62,6 @@ class FeedBuilder
      */
     protected $hideDates;
 
-    /**
-     * @var string PubSub hub URL.
-     */
-    protected $pubsubhubUrl;
-
     /**
      * @var string server locale.
      */
@@ -102,6 +97,11 @@ class FeedBuilder
      */
     public function buildData()
     {
+        // Search for untagged links
+        if (isset($this->userInput['searchtags']) && empty($this->userInput['searchtags'])) {
+            $this->userInput['searchtags'] = false;
+        }
+
         // Optionally filter the results:
         $linksToDisplay = $this->linkDB->filterSearch($this->userInput);
 
@@ -120,11 +120,11 @@ class FeedBuilder
         }
 
         $data['language'] = $this->getTypeLanguage();
-        $data['pubsubhub_url'] = $this->pubsubhubUrl;
         $data['last_update'] = $this->getLatestDateFormatted();
         $data['show_dates'] = !$this->hideDates || $this->isLoggedIn;
         // Remove leading slash from REQUEST_URI.
-        $data['self_link'] = $pageaddr . escape(ltrim($this->serverInfo['REQUEST_URI'], '/'));
+        $data['self_link'] = escape(server_url($this->serverInfo))
+                           . escape($this->serverInfo['REQUEST_URI']);
         $data['index_url'] = $pageaddr;
         $data['usepermalinks'] = $this->usePermalinks === true;
         $data['links'] = $linkDisplayed;
@@ -142,29 +142,37 @@ class FeedBuilder
      */
     protected function buildItem($link, $pageaddr)
     {
-        $link['guid'] = $pageaddr .'?'. smallHash($link['linkdate']);
+        $link['guid'] = $pageaddr .'?'. $link['shorturl'];
         // Check for both signs of a note: starting with ? and 7 chars long.
         if ($link['url'][0] === '?' && strlen($link['url']) === 7) {
             $link['url'] = $pageaddr . $link['url'];
         }
         if ($this->usePermalinks === true) {
-            $permalink = '<a href="'. $link['url'] .'" title="Direct link">Direct link</a>';
+            $permalink = '<a href="'. $link['url'] .'" title="'. t('Direct link') .'">'. t('Direct link') .'</a>';
         } else {
-            $permalink = '<a href="'. $link['guid'] .'" title="Permalink">Permalink</a>';
+            $permalink = '<a href="'. $link['guid'] .'" title="'. t('Permalink') .'">'. t('Permalink') .'</a>';
         }
-        $link['description'] = format_description($link['description']) . PHP_EOL .'<br>&#8212; '. $permalink;
+        $link['description']  = format_description($link['description'], '', false, $pageaddr);
+        $link['description'] .= PHP_EOL .'<br>&#8212; '. $permalink;
 
-        $date = DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, $link['linkdate']);
+        $pubDate = $link['created'];
+        $link['pub_iso_date'] = $this->getIsoDate($pubDate);
 
-        if ($this->feedType == self::$FEED_RSS) {
-            $link['iso_date'] = $date->format(DateTime::RSS);
+        // atom:entry elements MUST contain exactly one atom:updated element.
+        if (!empty($link['updated'])) {
+            $upDate = $link['updated'];
+            $link['up_iso_date'] = $this->getIsoDate($upDate, DateTime::ATOM);
         } else {
-            $link['iso_date'] = $date->format(DateTime::ATOM);
+            $link['up_iso_date'] = $this->getIsoDate($pubDate, DateTime::ATOM);
+            ;
         }
 
         // Save the more recent item.
-        if (empty($this->latestDate) || $this->latestDate < $date) {
-            $this->latestDate = $date;
+        if (empty($this->latestDate) || $this->latestDate < $pubDate) {
+            $this->latestDate = $pubDate;
+        }
+        if (!empty($upDate) && $this->latestDate < $upDate) {
+            $this->latestDate = $upDate;
         }
 
         $taglist = array_filter(explode(' ', $link['tags']), 'strlen');
@@ -174,16 +182,6 @@ class FeedBuilder
         return $link;
     }
 
-    /**
-     * Assign PubSub hub URL.
-     *
-     * @param string $pubsubhubUrl PubSub hub url.
-     */
-    public function setPubsubhubUrl($pubsubhubUrl)
-    {
-        $this->pubsubhubUrl = $pubsubhubUrl;
-    }
-
     /**
      * Set this to true to use permalinks instead of direct links.
      *
@@ -249,6 +247,25 @@ class FeedBuilder
         return $this->latestDate->format($type);
     }
 
+    /**
+     * Get ISO date from DateTime according to feed type.
+     *
+     * @param DateTime    $date   Date to format.
+     * @param string|bool $format Force format.
+     *
+     * @return string Formatted date.
+     */
+    protected function getIsoDate(DateTime $date, $format = false)
+    {
+        if ($format !== false) {
+            return $date->format($format);
+        }
+        if ($this->feedType == self::$FEED_RSS) {
+            return $date->format(DateTime::RSS);
+        }
+        return $date->format(DateTime::ATOM);
+    }
+
     /**
      * Returns the number of link to display according to 'nb' user input parameter.
      *