X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=modules%2Fapi.php;h=edbc2cdac0b97d3cc4b61b53cbd402987b449b33;hb=5cfb3dd10421468779a740595b3e5e68aba9838e;hp=5caedbf46deb6c673478336d9393a1796849d13b;hpb=e6a2c4d5def68dda8e88816acbcdb1955dae1b56;p=platal.git diff --git a/modules/api.php b/modules/api.php index 5caedbf..edbc2cd 100644 --- a/modules/api.php +++ b/modules/api.php @@ -26,7 +26,7 @@ class ApiModule extends PlModule return array( // TODO(vzanotti): Extend the plat/al engine to support placeholders // in handler urls, for instance "api/1/user/%forlife/isRegistered". - 'api/1/user' => $this->make_api_hook('user', AUTH_COOKIE, 'api_user_readonly'), + 'api/1/user' => $this->make_api_hook('user', AUTH_COOKIE, 'api_user_readonly'), 'api/1/search' => $this->make_api_hook('search', AUTH_COOKIE), ); } @@ -56,7 +56,30 @@ class ApiModule extends PlModule $page->trigError('Malformed search query'); return PL_BAD_REQUEST; } - Env::set('quick', $payload['quick']); + + $query = trim($payload['quick']); + if (@$payload['allow_special']) { + if (starts_with($query, 'admin:')) { + $page->jsonAssign('link_type', 'admin'); + $query = substr($query, 6); + } else if (starts_with($query, 'adm:')) { + $page->jsonAssign('link_type', 'admin'); + $query = substr($query, 4); + } else if (starts_with('admin', $query) || strpos($query, ':') !== false) { + $page->jsonAssign('profile_count', -1); + $page->jsonAssign('profiles', array()); + return PL_JSON; + } else { + $page->jsonAssign('link_type', 'profile'); + } + } + if (strlen($query) < 3) { + $page->jsonAssign('profile_count', -1); + $page->jsonAssign('profiles', array()); + return PL_JSON; + } + + Env::set('quick', $query); foreach (array('with_soundex', 'exact') as $key) { if (isset($payload[$key])) { Env::set($key, $payload[$key]); @@ -65,7 +88,7 @@ class ApiModule extends PlModule require_once 'userset.inc.php'; $view = new QuickSearchSet(); - $view->addMod('json', 'JSon', true, array('with_score' => true, 'starts_with' => $byletter)); + $view->addMod('json', 'JSon', true, $payload); $view->apply('api/1/search', $page, 'json'); return PL_JSON; }