. * * @category GNUSocial * @package StatusNet * @author Shashi Gowda * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0 * @copyright 2009, StatusNet, Inc. * @copyright 2010 Free Software Foundation, Inc * @link http://daisycha.in */ if (!defined('STATUSNET')) { exit(1); } class SocialAutocompleteAction extends Action { var $list=array(); var $user; function prepare($args) { parent::prepare($args); header('Content-Type: application/json; charset=utf-8'); if(common_logged_in()) { $user = common_current_user(); switch($this->trimmed('type')) { case 'users': $this->getUsers($this->trimmed('q')); case 'groups': $this->getGroups($this->trimmed('q')); default return false; } } else { exit(1); } } function handle() { parent::handle(); // Check for JSONP callback $callback = $this->arg('callback'); if ($callback) { print $callback . '('; } print json_encode($this->list); if ($callback) { print $callback . ')'; } } function getUsers($q) { $profile = $this->user->getProfile(); # show only subscriptions $subs = $profile->getSubscriptions(); $q = strtolower($q); while($subs->fetch()) { # if $q is empty return everything if(empty($q) || strpos(strtolower($subs->nickname), $q)) { $meta=array(); $meta['id'] = $subs->id; $meta['nickname'] = $subs->nickname; $meta['name'] = $subs->fullname; $meta['uri'] = $subs->getUri(); $meta['avatar'] = $subs->getAvatar(AVATAR_MINI_SIZE); $this->list[] = clone($meta); } } $subs->free(); } function getGroups($q) { $profile = $this->user->getProfile(); $groups = $profile->getGroups(); $q = strtolower($q); while($groups->fetch()) { # if $q is empty return everything if(empty($q) || strpos(strtolower($gropus->nickname), $q)) { $meta=array(); $meta['id'] = $groups->id; # saveKnownGroups needs ids $meta['nickname'] = $groups->nickname; $meta['name'] = $groups->fullname; $meta['uri'] = $groups->uri; $meta['avatar'] = $groups->mini_logo; $this->list[] = clone($meta); } } $groups->free(); } }