]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - plugins/Autocomplete/actions/autocomplete.php
split() is deprecated and should be explode()
[quix0rs-gnu-social.git] / plugins / Autocomplete / actions / autocomplete.php
index fce00145732c7065a571384d3460d3f2d5ca91a1..04acaefd38c5a5557035ac79b4af1f78fcc93194 100644 (file)
@@ -29,9 +29,7 @@
  * @link      http://status.net/
  */
 
-if (!defined('GNUSOCIAL') && !defined('STATUSNET')) {
-    exit(1);
-}
+if (!defined('GNUSOCIAL')) { exit(1); }
 
 /**
  * List users for autocompletion
@@ -63,7 +61,7 @@ class AutocompleteAction extends Action
     {
         $max=0;
         foreach($this->profiles as $profile){
-            $max = max($max,strtotime($user->modified),strtotime($profile->modified));
+            $max = max($max, strtotime($profile->modified));
         }
         foreach($this->groups as $group){
             $max = max($max,strtotime($group->modified));
@@ -92,16 +90,10 @@ class AutocompleteAction extends Action
     protected function prepare(array $args=array())
     {
         // If we die, show short error messages.
-        StatusNet::setApi(true);
+        GNUsocial::setApi(true);
 
         parent::prepare($args);
 
-        $cur = common_current_user();
-        if (!$cur) {
-            // TRANS: Client exception in autocomplete plugin.
-            throw new ClientException(_m('Access forbidden.'), true);
-        }
-
         $this->groups=array();
         $this->profiles=array();
         $term = $this->arg('term');
@@ -115,7 +107,7 @@ class AutocompleteAction extends Action
             $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));
+                               . ' where subscriber = %d)', $this->scoped->id));
             if ($profile->find()) {
                 while($profile->fetch()) {
                     $this->profiles[]=clone($profile);
@@ -128,6 +120,9 @@ class AutocompleteAction extends Action
             $group = new User_group();
             $group->limit($limit);
             $group->whereAdd('nickname like \'' . trim($group->escape($term), '\'') . '%\'');
+            //Can't post to groups we're not subscribed to...:
+            $group->whereAdd(sprintf('id in (SELECT group_id FROM group_member'
+                             . ' WHERE profile_id = %d)', $this->scoped->id));
             if($group->find()){
                 while($group->fetch()) {
                     $this->groups[]=clone($group);
@@ -144,25 +139,32 @@ class AutocompleteAction extends Action
         $results = array();
         foreach($this->profiles as $profile){
             $avatarUrl = $profile->avatarUrl(AVATAR_MINI_SIZE);
+            $acct = $profile->getAcctUri();
+            $identifier = explode(':', $profile->getAcctUri(), 2)[1];
             $results[] = array(
-                'value' => '@'.$profile->nickname,
-                'nickname' => $profile->nickname,
-                'label'=> $profile->getFancyName(),
+                'value' => '@'.$identifier,
+                'nickname' => $profile->getNickname(),
+                'acct_uri' => $acct,
+                'label'=> "${identifier} (".$profile->getFullname().")",
                 'avatar' => $avatarUrl,
                 'type' => 'user'
             );
         }
         foreach($this->groups as $group){
+            $profile = $group->getProfile();
             // sigh.... encapsulate this upstream!
             if ($group->mini_logo) {
                 $avatarUrl = $group->mini_logo;
             } else {
                 $avatarUrl = User_group::defaultLogo(AVATAR_MINI_SIZE);
             }
+            $acct = $profile->getAcctUri();
+            $identifier = explode(':', $profile->getAcctUri(), 2)[1];
             $results[] = array(
-                'value' => '!'.$group->nickname,
-                'nickname' => $group->nickname,
-                'label'=> $group->getFancyName(),
+                'value' => '!'.$group->getNickname(),
+                'nickname' => $group->getNickname(),
+                'acct_uri' => $acct,
+                'label'=> "${identifier} (".$group->getFullname().")",
                 'avatar' => $avatarUrl,
                 'type' => 'group');
         }