]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - actions/favorited.php
Merge branch '0.7.x' into 0.8.x
[quix0rs-gnu-social.git] / actions / favorited.php
index 0223564f34e754fbdc27eba4bea23d723b3d29ce..c902d80f5387e2e5c4f9f50a770864380c9cbd94 100644 (file)
@@ -85,7 +85,7 @@ class FavoritedAction extends Action
      * @return boolean true
      */
 
-    function isReadOnly()
+    function isReadOnly($args)
     {
         return true;
     }
@@ -104,6 +104,9 @@ class FavoritedAction extends Action
     {
         parent::prepare($args);
         $this->page = ($this->arg('page')) ? ($this->arg('page')+0) : 1;
+
+        common_set_returnto($this->selfUrl());
+
         return true;
     }
 
@@ -142,6 +145,22 @@ class FavoritedAction extends Action
         $this->elementEnd('div');
     }
 
+    function showEmptyList()
+    {
+        $message = _('Favorite notices appear on this page but no one has favorited one yet.') . ' ';
+
+        if (common_logged_in()) {
+            $message .= _('Be the first to add a notice to your favorites by clicking the fave button next to any notice you like.');
+        }
+        else {
+            $message .= _('Why not [register an account](%%action.register%%) and be the first to add a notice to your favorites!');
+        }
+
+        $this->elementStart('div', 'guide');
+        $this->raw(common_markup_to_html($message));
+        $this->elementEnd('div');
+    }
+
     /**
      * Local navigation
      *
@@ -166,10 +185,16 @@ class FavoritedAction extends Action
 
     function showContent()
     {
+        if (common_config('db', 'type') == 'pgsql') {
+            $weightexpr='sum(exp(-extract(epoch from (now() - fave.modified)) / %s))';
+        } else {
+            $weightexpr='sum(exp(-(now() - fave.modified) / %s))';
+        }
+
         $qry = 'SELECT notice.*, '.
-          'sum(exp(-(now() - fave.modified) / %s)) as weight ' .
+          $weightexpr . ' as weight ' .
           'FROM notice JOIN fave ON notice.id = fave.notice_id ' .
-          'GROUP BY fave.notice_id ' .
+          'GROUP BY id,profile_id,uri,content,rendered,url,created,notice.modified,reply_to,is_local,source ' .
           'ORDER BY weight DESC';
 
         $offset = ($this->page - 1) * NOTICES_PER_PAGE;
@@ -181,15 +206,18 @@ class FavoritedAction extends Action
             $qry .= ' LIMIT ' . $offset . ', ' . $limit;
         }
 
-        // XXX: Figure out how to cache this query
-
-        $notice = new Notice;
-        $notice->query(sprintf($qry, common_config('popular', 'dropoff')));
+        $notice = Memcached_DataObject::cachedQuery('Notice',
+                                                    sprintf($qry, common_config('popular', 'dropoff')),
+                                                    600);
 
         $nl = new NoticeList($notice, $this);
 
         $cnt = $nl->show();
 
+        if ($cnt == 0) {
+            $this->showEmptyList();
+        }
+
         $this->pagination($this->page > 1, $cnt > NOTICES_PER_PAGE,
                           $this->page, 'favorited');
     }