3 * StatusNet - the distributed open-source microblogging tool
4 * Copyright (C) 2008-2010, StatusNet, Inc.
6 * Peopletag autocomple action.
8 * This program is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU Affero General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU Affero General Public License for more details.
18 * You should have received a copy of the GNU Affero General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
25 * @author Shashi Gowda <connect2shashi@gmail.com>
26 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPLv3
27 * @link http://status.net/
30 if (!defined('STATUSNET')) {
34 class PeopletagautocompleteAction extends Action
41 * Check pre-requisites and instantiate attributes
43 * @param Array $args array of arguments (URL, GET, POST)
45 * @return boolean success flag
48 function prepare($args)
50 parent::prepare($args);
52 // Only for logged-in users
54 $this->user = common_current_user();
56 if (empty($this->user)) {
57 $this->clientError(_('Not logged in.'));
63 $token = $this->trimmed('token');
65 if (!$token || $token != common_session_token()) {
66 $this->clientError(_('There was a problem with your session token.'.
67 ' Try again, please.'));
71 $profile = $this->user->getProfile();
72 $tags = $profile->getOwnedTags(common_current_user());
74 $this->tags = array();
75 while ($tags->fetch()) {
77 if (empty($this->last_mod)) {
78 $this->last_mod = $tags->modified;
82 $arr['tag'] = $tags->tag;
83 $arr['mode'] = $tags->private ? 'private' : 'public';
84 // $arr['url'] = $tags->homeUrl();
85 $arr['freq'] = $tags->taggedCount();
98 * Helps in browser-caching
100 * @return String time
103 function lastModified()
105 return strtotime($this->last_mod);
111 * Print the JSON autocomplete data
113 * @param Array $args unused.
118 function handle($args)
120 //common_log(LOG_DEBUG, 'Autocomplete data: ' . json_encode($this->tags));
122 print(json_encode($this->tags));