]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
Added personal tag page: http://example.com/MY_NICK/tag/A_TAG
authorRobin Millette <millette@controlyourself.ca>
Mon, 18 May 2009 21:18:57 +0000 (17:18 -0400)
committerRobin Millette <millette@controlyourself.ca>
Mon, 18 May 2009 21:18:57 +0000 (17:18 -0400)
actions/showstream.php
classes/Notice.php
classes/Profile.php
classes/User.php
lib/profileaction.php
lib/router.php
lib/tagcloudsection.php

index 82665e5b8b3841f1c68015ecb0be4359a617128b..1654f589c64ea4267a8a16e6f57e275a5bec17f9 100644 (file)
@@ -68,6 +68,9 @@ class ShowstreamAction extends ProfileAction
         } else {
             $base = $this->user->nickname;
         }
+        if (!empty($this->tag)) {
+            $base .= sprintf(_(' tagged %s'), $this->tag);
+        }
 
         if ($this->page == 1) {
             return $base;
@@ -363,7 +366,9 @@ class ShowstreamAction extends ProfileAction
 
     function showNotices()
     {
-        $notice = $this->user->getNotices(($this->page-1)*NOTICES_PER_PAGE, NOTICES_PER_PAGE + 1);
+        $notice = empty($this->tag)
+            ? $this->user->getNotices(($this->page-1)*NOTICES_PER_PAGE, NOTICES_PER_PAGE + 1)
+            : $this->user->getTaggedNotices(($this->page-1)*NOTICES_PER_PAGE, NOTICES_PER_PAGE + 1, 0, 0, null, $this->tag);
 
         $pnl = new ProfileNoticeList($notice, $this);
         $cnt = $pnl->show();
index f6ac4f7802f13f8ba698ec7f55c40e6601707f44..1b5c0ab0a55afdc53592b860ec71ca414fa615a5 100644 (file)
@@ -1024,7 +1024,7 @@ class Notice extends Memcached_DataObject
         }
     }
 
-    function stream($fn, $args, $cachekey, $offset=0, $limit=20, $since_id=0, $before_id=0, $since=null)
+    function stream($fn, $args, $cachekey, $offset=0, $limit=20, $since_id=0, $before_id=0, $since=null, $tag=null)
     {
         $cache = common_memcache();
 
@@ -1032,7 +1032,7 @@ class Notice extends Memcached_DataObject
             $since_id != 0 || $before_id != 0 || !is_null($since) ||
             ($offset + $limit) > NOTICE_CACHE_WINDOW) {
             return call_user_func_array($fn, array_merge($args, array($offset, $limit, $since_id,
-                                                                      $before_id, $since)));
+                                                                      $before_id, $since, $tag)));
         }
 
         $idkey = common_cache_key($cachekey);
@@ -1052,7 +1052,7 @@ class Notice extends Memcached_DataObject
             $window = explode(',', $laststr);
             $last_id = $window[0];
             $new_ids = call_user_func_array($fn, array_merge($args, array(0, NOTICE_CACHE_WINDOW,
-                                                                          $last_id, 0, null)));
+                                                                          $last_id, 0, null, $tag)));
 
             $new_window = array_merge($new_ids, $window);
 
@@ -1067,7 +1067,7 @@ class Notice extends Memcached_DataObject
         }
 
         $window = call_user_func_array($fn, array_merge($args, array(0, NOTICE_CACHE_WINDOW,
-                                                                     0, 0, null)));
+                                                                     0, 0, null, $tag)));
 
         $windowstr = implode(',', $window);
 
index ae5641d79d69bb2a03d2faa6b1a3b9e43d992cc3..afc0ea4f74557b29824ef266a54be6fd59d81202 100644 (file)
@@ -153,18 +153,66 @@ class Profile extends Memcached_DataObject
         return null;
     }
 
-    function getNotices($offset=0, $limit=NOTICES_PER_PAGE, $since_id=0, $before_id=0)
+    function getTaggedNotices($offset=0, $limit=NOTICES_PER_PAGE, $since_id=0, $before_id=0, $since=null, $tag=null)
+    {
+        // XXX: I'm not sure this is going to be any faster. It probably isn't.
+        $ids = Notice::stream(array($this, '_streamTaggedDirect'),
+                              array(),
+                              'profile:notice_ids:' . $this->id,
+                              $offset, $limit, $since_id, $before_id, $since, $tag);
+        common_debug(print_r($ids, true));
+        return Notice::getStreamByIds($ids);
+    }
+
+    function getNotices($offset=0, $limit=NOTICES_PER_PAGE, $since_id=0, $before_id=0, $since=null)
     {
         // XXX: I'm not sure this is going to be any faster. It probably isn't.
         $ids = Notice::stream(array($this, '_streamDirect'),
                               array(),
                               'profile:notice_ids:' . $this->id,
-                              $offset, $limit, $since_id, $before_id);
+                              $offset, $limit, $since_id, $before_id, $since);
 
         return Notice::getStreamByIds($ids);
     }
 
-    function _streamDirect($offset, $limit, $since_id, $before_id, $since)
+    function _streamTaggedDirect($offset, $limit, $since_id, $before_id, $since=null, $tag=null)
+    {
+        common_debug('_streamTaggedDirect()');
+        $notice = new Notice();
+        $notice->profile_id = $this->id;
+        $query = "select id from notice join notice_tag on id=notice_id where tag='" . $notice->escape($tag) . "' and profile_id=" . $notice->escape($notice->profile_id);
+        if ($since_id != 0) {
+            $query .= " and id > $since_id";
+        }
+
+        if ($before_id != 0) {
+            $query .= " and id < $before_id";
+        }
+
+        if (!is_null($since)) {
+            $query .= " and created > '" . date('Y-m-d H:i:s', $since) . "'";
+        }
+
+        $query .= ' order by id DESC';
+
+        if (!is_null($offset)) {
+            $query .= " limit $offset, $limit";
+        }
+        $notice->query($query);
+        $ids = array();
+
+        while ($notice->fetch()) {
+            common_debug(print_r($notice, true));
+            $ids[] = $notice->id;
+        }
+
+        return $ids;
+    }
+
+
+
+
+    function _streamDirect($offset, $limit, $since_id, $before_id, $since = null)
     {
         $notice = new Notice();
 
index b5ac7b22061d7fbbb37c9fc7d9d019fee1c2224d..ea8ba40817ac74c3901c9f8f519deb677f616339 100644 (file)
@@ -407,13 +407,22 @@ class User extends Memcached_DataObject
         return Notice::getStreamByIds($ids);
     }
 
+    function getTaggedNotices($tag, $offset=0, $limit=NOTICES_PER_PAGE, $since_id=0, $before_id=0, $since=null) {
+        $profile = $this->getProfile();
+        if (!$profile) {
+            return null;
+        } else {
+            return $profile->getTaggedNotices($tag, $offset, $limit, $since_id, $before_id, $since);
+        }
+    }
+
     function getNotices($offset=0, $limit=NOTICES_PER_PAGE, $since_id=0, $before_id=0, $since=null)
     {
         $profile = $this->getProfile();
         if (!$profile) {
             return null;
         } else {
-            return $profile->getNotices($offset, $limit, $since_id, $before_id);
+            return $profile->getNotices($offset, $limit, $since_id, $before_id, $since);
         }
     }
 
index 1f2e309945c2ca3af30ba054c277b95445c7a25c..a3437ff4ddbec567d630c3f25e4985aa8b3f73a8 100644 (file)
@@ -49,16 +49,17 @@ require_once INSTALLDIR.'/lib/groupminilist.php';
 
 class ProfileAction extends Action
 {
-    var $user = null;
-    var $page = null;
+    var $user    = null;
+    var $page    = null;
     var $profile = null;
+    var $tag     = null;
 
     function prepare($args)
     {
         parent::prepare($args);
 
         $nickname_arg = $this->arg('nickname');
-        $nickname = common_canonical_nickname($nickname_arg);
+        $nickname     = common_canonical_nickname($nickname_arg);
 
         // Permanent redirect on non-canonical nickname
 
@@ -85,10 +86,9 @@ class ProfileAction extends Action
             return false;
         }
 
+        $this->tag = $this->trimmed('tag');
         $this->page = ($this->arg('page')) ? ($this->arg('page')+0) : 1;
-
         common_set_returnto($this->selfUrl());
-
         return true;
     }
 
@@ -244,4 +244,5 @@ class ProfileAction extends Action
 
         $this->elementEnd('div');
     }
-}
\ No newline at end of file
+}
+
index 635e1d77e09dddde427d2e9d1c8a971bc0683250..f07e5937342cdf09dc9f780ff8db2c359f74389b 100644 (file)
@@ -426,6 +426,11 @@ class Router
                     array('size' => '(original|96|48|24)',
                           'nickname' => '[a-zA-Z0-9]{1,64}'));
 
+        $m->connect(':nickname/tag/:tag',
+                    array('action' => 'showstream'),
+                    array('nickname' => '[a-zA-Z0-9]{1,64}'),
+                    array('tag' => '[a-zA-Z0-9]+'));
+
         $m->connect(':nickname',
                     array('action' => 'showstream'),
                     array('nickname' => '[a-zA-Z0-9]{1,64}'));
index ff2aca6d6ec06eae34895ac3691fdb240aebcd80..62f7d8961282659f7c12a4b0db2b57840cfc74da 100644 (file)
@@ -114,7 +114,11 @@ class TagCloudSection extends Section
 
     function tagUrl($tag)
     {
-        return common_local_url('tag', array('tag' => $tag));
+        if ('showstream' === $this->out->trimmed('action')) {
+            return common_local_url('showstream', array('nickname' => $this->out->profile->nickname, 'tag' => $tag));
+        } else {
+            return common_local_url('tag', array('tag' => $tag));
+        }
     }
 
     function divId()