]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - actions/peopletagautocomplete.php
EmailSettingsAction adapted to FormAction
[quix0rs-gnu-social.git] / actions / peopletagautocomplete.php
index db11a246674a0a22787efcefdf71a22bc0128d9b..86d63545dcb0b4ed2aa4040e78aef8e8ebf9899e 100644 (file)
@@ -34,6 +34,8 @@ if (!defined('STATUSNET')) {
 class PeopletagautocompleteAction extends Action
 {
     var $user;
+    var $tags;
+    var $last_mod;
 
     /**
      * Check pre-requisites and instantiate attributes
@@ -42,7 +44,6 @@ class PeopletagautocompleteAction extends Action
      *
      * @return boolean success flag
      */
-
     function prepare($args)
     {
         parent::prepare($args);
@@ -52,8 +53,8 @@ class PeopletagautocompleteAction extends Action
         $this->user = common_current_user();
 
         if (empty($this->user)) {
+            // TRANS: Error message displayed when trying to perform an action that requires a logged in user.
             $this->clientError(_('Not logged in.'));
-            return false;
         }
 
         // CSRF protection
@@ -61,44 +62,63 @@ class PeopletagautocompleteAction extends Action
         $token = $this->trimmed('token');
 
         if (!$token || $token != common_session_token()) {
+            // TRANS: Client error displayed when the session token does not match or is not given.
             $this->clientError(_('There was a problem with your session token.'.
                                  ' Try again, please.'));
-            return false;
         }
 
+        $profile = $this->user->getProfile();
+        $tags = $profile->getLists(common_current_user());
+
+        $this->tags = array();
+        while ($tags->fetch()) {
+
+            if (empty($this->last_mod)) {
+                $this->last_mod = $tags->modified;
+            }
+
+            $arr = array();
+            $arr['tag'] = $tags->tag;
+            $arr['mode'] = $tags->private ? 'private' : 'public';
+            // $arr['url'] = $tags->homeUrl();
+            $arr['freq'] = $tags->taggedCount();
+
+            $this->tags[] = $arr;
+        }
+
+        $tags = NULL;
+
         return true;
     }
 
+    /**
+     * Last modified time
+     *
+     * Helps in browser-caching
+     *
+     * @return String time
+     */
+    function lastModified()
+    {
+        return strtotime($this->last_mod);
+    }
+
     /**
      * Handle request
      *
-     * Does the subscription and returns results.
+     * Print the JSON autocomplete data
      *
      * @param Array $args unused.
      *
      * @return void
      */
-
     function handle($args)
     {
-        $profile = $this->user->getProfile();
-        $tags = $profile->getOwnedTags(common_current_user());
-
-        $tags_array = array();
-        while ($tags->fetch()) {
-            $arr = array();
-            $arr['tag'] = $tags->tag;
-            $arr['mode'] = $tags->private ? 'private' : 'public';
-            // $arr['url'] = $tags->homeUrl();
-            $arr['freq'] = $tags->taggedCount();
-
-            $tags_array[] = $arr;
+        //common_log(LOG_DEBUG, 'Autocomplete data: ' . json_encode($this->tags));
+        if ($this->tags) {
+            print(json_encode($this->tags));
+            exit(0);
         }
-
-        $tags->free();
-
-        //common_log(LOG_DEBUG, 'Autocomplete data: ' . json_encode($tags_array));
-        print(json_encode($tags_array));
-        exit(0);
+        return false;
     }
 }