]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
Autocomplete now matches remote profiles as well.
authorMikael Nordfeldth <mmn@hethane.se>
Sun, 23 Feb 2014 19:12:01 +0000 (20:12 +0100)
committerMikael Nordfeldth <mmn@hethane.se>
Sun, 23 Feb 2014 19:12:01 +0000 (20:12 +0100)
plugins/Autocomplete/actions/autocomplete.php

index 787ef15326e195c167af3b54424ff1bc049f8351..fce00145732c7065a571384d3460d3f2d5ca91a1 100644 (file)
@@ -2,7 +2,7 @@
 /**
  * StatusNet, the distributed open-source microblogging tool
  *
- * List users for autocompletion
+ * List profiles and groups for autocompletion
  *
  * PHP version 5
  *
@@ -29,7 +29,7 @@
  * @link      http://status.net/
  */
 
-if (!defined('STATUSNET') && !defined('LACONICA')) {
+if (!defined('GNUSOCIAL') && !defined('STATUSNET')) {
     exit(1);
 }
 
@@ -62,8 +62,8 @@ class AutocompleteAction extends Action
     function lastModified()
     {
         $max=0;
-        foreach($this->users as $user){
-            $max = max($max,strtotime($user->modified),strtotime($user->getProfile()->modified));
+        foreach($this->profiles as $profile){
+            $max = max($max,strtotime($user->modified),strtotime($profile->modified));
         }
         foreach($this->groups as $group){
             $max = max($max,strtotime($group->modified));
@@ -103,19 +103,22 @@ class AutocompleteAction extends Action
         }
 
         $this->groups=array();
-        $this->users=array();
+        $this->profiles=array();
         $term = $this->arg('term');
         $limit = $this->arg('limit');
         if($limit > 200) $limit=200; //prevent DOS attacks
         if(substr($term,0,1)=='@'){
-            //user search
+            //profile search
             $term=substr($term,1);
-            $user = new User();
-            $user->limit($limit);
-            $user->whereAdd('nickname like \'' . trim($user->escape($term), '\'') . '%\'');
-            if($user->find()){
-                while($user->fetch()) {
-                    $this->users[]=clone($user);
+            $profile = new Profile();
+            $profile->limit($limit);
+            $profile->whereAdd('nickname like \'' . trim($profile->escape($term), '\'') . '%\'');
+            $profile->whereAdd(sprintf('id in (SELECT id FROM user) OR '
+                               . 'id in (SELECT subscribed from subscription'
+                               . ' where subscriber = %d)', $cur->id));
+            if ($profile->find()) {
+                while($profile->fetch()) {
+                    $this->profiles[]=clone($profile);
                 }
             }
         }
@@ -139,8 +142,7 @@ class AutocompleteAction extends Action
         parent::handle();
 
         $results = array();
-        foreach($this->users as $user){
-            $profile = $user->getProfile();
+        foreach($this->profiles as $profile){
             $avatarUrl = $profile->avatarUrl(AVATAR_MINI_SIZE);
             $results[] = array(
                 'value' => '@'.$profile->nickname,