123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114 |
- <?php
- if (!defined('STATUSNET')) {
- exit(1);
- }
- class UserautocompleteAction extends Action
- {
- var $query;
-
- function prepare(array $args = array())
- {
- parent::prepare($args);
- $this->query = $this->trimmed('term');
- return true;
- }
-
- function handle()
- {
- parent::handle();
- $this->showResults();
- }
-
- function showResults()
- {
- $people = array();
- $profile = new Profile();
- $search_engine = $profile->getSearchEngine('profile');
- $search_engine->set_sort_mode('nickname_desc');
- $search_engine->limit(0, 10);
- $search_engine->query(strtolower($this->query . '*'));
- $cnt = $profile->find();
- if ($cnt > 0) {
- $sql = 'SELECT profile.* FROM profile, user WHERE profile.id = user.id '
- . ' AND LEFT(LOWER(profile.nickname), '
- . strlen($this->query)
- . ') = \'%s\' '
- . ' LIMIT 0, 10';
- $profile->query(sprintf($sql, $this->query));
- }
-
- while ($profile->fetch()) {
- $people[] = $profile->nickname;
- }
- header('Content-Type: application/json; charset=utf-8');
- print json_encode($people);
- }
-
- function isReadOnly($args)
- {
- return true;
- }
- }
|