}
}
+class JSonView implements PlView
+{
+ private $set;
+
+ public function __construct(PlSet $set, array $params)
+ {
+ $this->set = $set;
+ }
+
+ public function apply(PlPage $page)
+ {
+ $export = array();
+ $profiles = $this->set->get(new PlLimit());
+ while ($profile = $profiles->next()) {
+ $export[] = $profile->export();
+ }
+ $page->jsonAssign('profiles', $export);
+ }
+
+ public function args()
+ {
+ return $this->set->args();
+ }
+}
+
// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
?>
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),
);
}
// This handler supports the following URL patterns:
// /api/1/user/{forlife}/isRegistered
- function handler_user(PlPage& $page, PlUser& $authUser, $payload, $user = null, $selector = null)
+ function handler_user(PlPage $page, PlUser $authUser, $payload, $user = null, $selector = null)
{
// Retrieve the PlUser referenced in the request. Note that this is the
// target user, not the authenticated user.
return PL_NOT_FOUND;
}
}
+
+ function handler_search(PlPage $page, PlUser $authUser, $payload, $mode = 'quick')
+ {
+ if (!isset($payload['quick'])) {
+ $page->trigError('Malformed search query');
+ return PL_BAD_REQUEST;
+ }
+ Env::set('quick', $payload['quick']);
+ foreach (array('with_soundex', 'exact') as $key) {
+ if (isset($payload[$key])) {
+ Env::set($key, $payload[$key]);
+ }
+ }
+
+ require_once 'userset.inc.php';
+ $view = new QuickSearchSet();
+ $view->addMod('json', 'JSon', true, array('with_score' => true, 'starts_with' => $byletter));
+ $view->apply('api/1/search', $page, 'json');
+ return PL_JSON;
+ }
}
// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
</p>
<p class="center">
+ <a id="blah">Blah </a>
+
+ <script type="text/javascript">//<![CDATA[
+ {literal}
+ $($("#blah").click(function() {
+ $.xapi('1/search?token={/literal}{$smarty.session.xsrf_token}{literal}',
+ { 'quick': 'fruneau' },
+ function(data) { alert(JSON.stringify(data)); });
+ return false;
+ }));
+ {/literal}
+ //]]></script>
+
{icon name=page_edit}
<a href="events/submit">Proposer une information événementielle</a> •
<a href="nl/submit">Proposer un article pour la Lettre mensuelle</a>