summaryrefslogtreecommitdiff
path: root/plugins/SocialLayout/SocialAutocompleteAction.php
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/SocialLayout/SocialAutocompleteAction.php')
-rw-r--r--plugins/SocialLayout/SocialAutocompleteAction.php127
1 files changed, 127 insertions, 0 deletions
diff --git a/plugins/SocialLayout/SocialAutocompleteAction.php b/plugins/SocialLayout/SocialAutocompleteAction.php
new file mode 100644
index 000000000..1f82548fd
--- /dev/null
+++ b/plugins/SocialLayout/SocialAutocompleteAction.php
@@ -0,0 +1,127 @@
+<?php
+/**
+ * StatusNet - the distributed open-source microblogging tool
+ * Copyright (C) 2009, StatusNet, Inc.
+ *
+ * Show JSON for autocompleting replies (usernames) and groups form fields
+ *
+ * PHP version 5
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * @category GNUSocial
+ * @package StatusNet
+ * @author Shashi Gowda <connect2shashi@gmail.com>
+ * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
+ * @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();
+ }
+}