]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - actions/showfavorites.php
Revert "Revert "Return a 404 when a page is request that has no notices""
[quix0rs-gnu-social.git] / actions / showfavorites.php
index 585b3b75ab8809a6c6ff68c5693d30bee1cb0952..91287cc9630b802a4b1887abb0a11b4343bcd994 100644 (file)
@@ -45,7 +45,7 @@ require_once INSTALLDIR.'/lib/feedlist.php';
  * @link     http://laconi.ca/
  */
 
-class ShowfavoritesAction extends Action
+class ShowfavoritesAction extends OwnerDesignAction
 {
     /** User we're getting the faves of */
     var $user = null;
@@ -58,7 +58,7 @@ class ShowfavoritesAction extends Action
      * @return boolean true
      */
 
-    function isReadOnly()
+    function isReadOnly($args)
     {
         return true;
     }
@@ -74,9 +74,9 @@ class ShowfavoritesAction extends Action
     function title()
     {
         if ($this->page == 1) {
-            return sprintf(_("%s favorite notices"), $this->user->nickname);
+            return sprintf(_("%s's favorite notices"), $this->user->nickname);
         } else {
-            return sprintf(_("%s favorite notices, page %d"),
+            return sprintf(_("%s's favorite notices, page %d"),
                            $this->user->nickname,
                            $this->page);
         }
@@ -113,7 +113,30 @@ class ShowfavoritesAction extends Action
         }
 
         common_set_returnto($this->selfUrl());
-        
+
+        $cur = common_current_user();
+
+        if (!empty($cur) && $cur->id == $this->user->id) {
+
+            // Show imported/gateway notices as well as local if
+            // the user is looking at his own favorites
+
+            $this->notice = $this->user->favoriteNotices(($this->page-1)*NOTICES_PER_PAGE,
+                                                   NOTICES_PER_PAGE + 1, true);
+        } else {
+            $this->notice = $this->user->favoriteNotices(($this->page-1)*NOTICES_PER_PAGE,
+                                                   NOTICES_PER_PAGE + 1, false);
+        }
+
+        if (empty($this->notice)) {
+            $this->serverError(_('Could not retrieve favorite notices.'));
+            return;
+        }
+
+        if($this->page > 1 && $this->notice->N == 0){
+            $this->serverError(_('No such page'),$code=404);
+        }
+
         return true;
     }
 
@@ -136,10 +159,10 @@ class ShowfavoritesAction extends Action
     /**
      * Feeds for the <head> section
      *
-     * @return void
+     * @return array Feed objects to show
      */
 
-    function showFeeds()
+    function getFeeds()
     {
         $feedurl   = common_local_url('favoritesrss',
                                       array('nickname' =>
@@ -147,24 +170,9 @@ class ShowfavoritesAction extends Action
         $feedtitle = sprintf(_('Feed for favorites of %s'),
                              $this->user->nickname);
 
-        $this->element('link', array('rel' => 'alternate',
-                                     'href' => $feedurl,
-                                     'type' => 'application/rss+xml',
-                                     'title' => $feedtitle));
-    }
-
-    /**
-     * Output document relationship links
-     *
-     * @return void
-     */
-    function showRelationshipLinks()
-    {
-        $this->sequenceRelationships($this->page > 1, $this->count > NOTICES_PER_PAGE, // FIXME
-                                     $this->page, 'showfavorites', array('nickname' => $this->user->nickname));
+        return array(new Feed(Feed::RSS1, $feedurl, $feedtitle));
     }
 
-
     /**
      * show the personal group nav
      *
@@ -177,26 +185,25 @@ class ShowfavoritesAction extends Action
         $nav->show();
     }
 
-    /**
-     * Show the replies feed links
-     *
-     * @return void
-     */
-
-    function showExportData()
+    function showEmptyListMessage()
     {
-        $feedurl = common_local_url('favoritesrss',
-                                    array('nickname' =>
-                                          $this->user->nickname));
-
-        $fl = new FeedList($this);
-
-        // XXX: I18N
+        if (common_logged_in()) {
+            $current_user = common_current_user();
+            if ($this->user->id === $current_user->id) {
+                $message = _('You haven\'t chosen any favorite notices yet. Click the fave button on notices you like to bookmark them for later or shed a spotlight on them.');
+            } else {
+                $message = sprintf(_('%s hasn\'t added any notices to his favorites yet. Post something interesting they would add to their favorites :)'), $this->user->nickname);
+            }
+        }
+        else {
+            $message = sprintf(_('%s hasn\'t added any notices to his favorites yet. Why not [register an account](%%%%action.%s%%%%) and then post something interesting they would add to their favorites :)'),
+                               $this->user->nickname,
+                               (!common_config('site','openidonly')) ? 'register' : 'openidlogin');
+        }
 
-        $fl->show(array(0=>array('href'=> $feedurl,
-                                 'type' => 'rss',
-                                 'version' => 'RSS 1.0',
-                                 'item' => 'Favorites')));
+        $this->elementStart('div', 'guide');
+        $this->raw(common_markup_to_html($message));
+        $this->elementEnd('div');
     }
 
     /**
@@ -209,20 +216,20 @@ class ShowfavoritesAction extends Action
 
     function showContent()
     {
-        $notice = $this->user->favoriteNotices(($this->page-1)*NOTICES_PER_PAGE,
-                                               NOTICES_PER_PAGE + 1);
-
-        if (!$notice) {
-            $this->serverError(_('Could not retrieve favorite notices.'));
-            return;
-        }
-
-        $nl = new NoticeList($notice, $this);
+        $nl = new NoticeList($this->notice, $this);
 
         $cnt = $nl->show();
+        if (0 == $cnt) {
+            $this->showEmptyListMessage();
+        }
 
         $this->pagination($this->page > 1, $cnt > NOTICES_PER_PAGE,
                           $this->page, 'showfavorites',
                           array('nickname' => $this->user->nickname));
     }
+
+    function showPageNotice() {
+        $this->element('p', 'instructions', _('This is a way to share what you like.'));
+    }
 }
+