]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - lib/popularnoticesection.php
Start tracking alpha release numbers
[quix0rs-gnu-social.git] / lib / popularnoticesection.php
index f70a972efe90b89974f810f6643abd81159704fa..2000d302d48fa95b12b46dcea5d48d60758fe244 100644 (file)
@@ -22,7 +22,7 @@
  * @category  Widget
  * @package   StatusNet
  * @author    Evan Prodromou <evan@status.net>
- * @copyright 2009 StatusNet, Inc.
+ * @copyright 2009,2011 StatusNet, Inc.
  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
  * @link      http://status.net/
  */
@@ -43,51 +43,25 @@ if (!defined('STATUSNET') && !defined('LACONICA')) {
  * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
  * @link     http://status.net/
  */
-
 class PopularNoticeSection extends NoticeSection
 {
-    function getNotices()
-    {
-        // @fixme there should be a common func for this
-        if (common_config('db', 'type') == 'pgsql') {
-            if (!empty($this->out->tag)) {
-                $tag = pg_escape_string($this->out->tag);
-            }
-        } else {
-            if (!empty($this->out->tag)) {
-                 $tag = mysql_escape_string($this->out->tag);
-            }
-        }
-        $weightexpr = common_sql_weight('fave.modified', common_config('popular', 'dropoff'));
-        $cutoff = sprintf("fave.modified > '%s'",
-                          common_sql_date(time() - common_config('popular', 'cutoff')));
-        $qry = "SELECT notice.*, $weightexpr as weight ";
-        if(isset($tag)) {
-            $qry .= 'FROM notice_tag, notice JOIN fave ON notice.id = fave.notice_id ' .
-                    "WHERE $cutoff and notice.id = notice_tag.notice_id and '$tag' = notice_tag.tag";
-        } else {
-            $qry .= 'FROM notice JOIN fave ON notice.id = fave.notice_id ' .
-                    "WHERE $cutoff";
-        }
-        $qry .= ' GROUP BY notice.id,notice.profile_id,notice.content,notice.uri,' .
-                'notice.rendered,notice.url,notice.created,notice.modified,' .
-                'notice.reply_to,notice.is_local,notice.source,notice.conversation, ' .
-                'notice.lat,notice.lon,location_id,location_ns,notice.repeat_of' .
-                ' ORDER BY weight DESC';
+    protected $viewer;
 
-        $offset = 0;
-        $limit  = NOTICES_PER_SECTION + 1;
-
-        $qry .= ' LIMIT ' . $limit . ' OFFSET ' . $offset;
+    function __construct($out, $viewer)
+    {
+        parent::__construct($out);
+        $this->viewer = $viewer;
+    }
 
-        $notice = Memcached_DataObject::cachedQuery('Notice',
-                                                    $qry,
-                                                    1200);
-        return $notice;
+    function getNotices()
+    {
+        $stream = new PopularNoticeStream($this->viewer);
+        return $stream->getNotices(0, NOTICES_PER_SECTION + 1);
     }
 
     function title()
     {
+        // TRANS: Title for favourited notices section.
         return _('Popular notices');
     }
 
@@ -98,6 +72,12 @@ class PopularNoticeSection extends NoticeSection
 
     function moreUrl()
     {
-        return common_local_url('favorited');
+        if (common_config('singleuser', 'enabled')) {
+            $user = User::singleUser();
+            common_local_url('showfavorites', array('nickname' =>
+                                                    $user->nickname));
+        } else {
+            return common_local_url('favorited');
+        }
     }
 }