Esempio n. 1
0
 function handler_search(PlPage $page, PlUser $authUser, $payload, $mode = 'quick')
 {
     if (!isset($payload['quick'])) {
         $page->trigError('Malformed search query');
         return PL_BAD_REQUEST;
     }
     $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]);
         }
     }
     require_once 'userset.inc.php';
     $view = new QuickSearchSet();
     $view->addMod('json', 'JSon', true, $payload);
     $view->apply('api/1/search', $page, 'json');
     return PL_JSON;
 }
Esempio n. 2
0
 function handler_ig_search($page)
 {
     if (Env::has('quick') && Env::s('quick') != '') {
         global $globals;
         require_once 'userset.inc.php';
         $view = new QuickSearchSet();
         $view->addMod('gadget', 'Gadget', true);
         $view->apply(null, $page);
         $nb_tot = $view->count();
         $page->assign('result_count', $nb_tot);
         if (!S::logged() && $nb_tot > $globals->search->public_max) {
             $page->assign('error', 'Votre recherche a généré trop de résultats pour un affichage public.');
         } elseif ($nb_tot > $globals->search->private_max) {
             $page->assign('error', 'Recherche trop générale.');
         } elseif (empty($nb_tot)) {
             $page->assign('error', 'Il n\'existe personne correspondant à ces critères dans la base !');
         } else {
             $page->assign('error', false);
         }
     }
     require_once 'gadgets/gadgets.inc.php';
     init_igoogle_html('gadgets/ig-search.tpl', AUTH_PUBLIC);
 }
Esempio n. 3
0
 /** 
  * $model: The way of presenting the results: minifiche, trombi, geoloc.
  * $byletter: Show only names beginning with this letter
  */
 function handler_quick($page, $model = null, $byletter = null)
 {
     global $globals;
     if (Env::has('quick') || $model == 'geoloc') {
         $quick = Env::t('quick');
         if (S::logged() && !Env::has('page')) {
             S::logger()->log('search', 'quick=' . $quick);
         }
         if ($quick == '') {
             $page->trigWarning('Aucun critère de recherche n\'est spécifié.');
             $page->changeTpl('search/index.tpl');
             $page->setTitle('Annuaire');
             $page->assign('formulaire', 1);
             return;
         }
         $list = 'profile|prf|fiche|fic|referent|ref|mentor';
         if (S::admin()) {
             $list .= '|admin|adm|ax';
         }
         $suffixes = array_keys(DirEnum::getOptions(DirEnum::ACCOUNTTYPES));
         $suffixes = implode('|', $suffixes);
         if (preg_match('/^(' . $list . '):([-a-z]+(\\.[-a-z]+(\\.(?:[md]?\\d{2,4}|' . $suffixes . '))?)?)$/', replace_accent($quick), $matches)) {
             $login = $matches[2];
             switch ($matches[1]) {
                 case 'admin':
                 case 'adm':
                     $base = 'admin/user/';
                     break;
                 case 'ax':
                     $base = 'profile/ax/';
                     break;
                 case 'profile':
                 case 'prf':
                 case 'fiche':
                 case 'fic':
                     $base = 'profile/';
                     break;
                 case 'referent':
                 case 'ref':
                 case 'mentor':
                     $base = 'referent/';
                     break;
             }
             $user = User::getSilent($login);
             if ($user) {
                 pl_redirect($base . $user->login());
             }
             Get::set('quick', $login);
         } elseif (strpos($quick, 'doc:') === 0) {
             $url = 'Docs/Recherche?';
             $url .= 'action=search&q=' . urlencode(substr($quick, 4));
             $url .= '&group=' . urlencode('-Equipe,-Main,-PmWiki,-Site,-Review');
             pl_redirect($url);
         } elseif (strpos($quick, 'trombi:') === 0) {
             $promo = substr($quick, 7);
             $res = XDB::query("SELECT  diminutif\n                                     FROM  groups\n                                    WHERE  cat = 'Promotions' AND diminutif = {?}", $promo);
             if ($res->numRows() == 0) {
                 $page->trigWarning("La promotion demandée n'est pas valide: {$promo}");
             } else {
                 http_redirect('http://www.polytechnique.net/login/' . $promo . '/annuaire/trombi');
             }
         }
         $page->assign('formulaire', 0);
         require_once 'userset.inc.php';
         $view = new QuickSearchSet();
         $view->addMod('minifiche', 'Mini-fiches', true, array('with_score' => true, 'starts_with' => $byletter));
         $view->addMod('map', 'Planisphère');
         if (S::logged() && !Env::i('nonins')) {
             $view->addMod('trombi', 'Trombinoscope', false, array('with_promo' => true, 'with_score' => true));
         }
         $view->apply('search', $page, $model);
         $nb_tot = $view->count();
         $page->assign('search_results_nb', $nb_tot);
         if (!S::logged() && $nb_tot > $globals->search->public_max) {
             $page->trigError('Votre recherche a généré trop de résultats pour un affichage public.');
         } elseif ($nb_tot > $globals->search->private_max) {
             $page->trigError('Recherche trop générale. Une <a href="search/adv">recherche avancée</a> permet de préciser la recherche.');
         } elseif (empty($nb_tot)) {
             $page->trigError('Il n\'existe personne correspondant à ces critères dans la base !');
         }
     } else {
         $page->assign('formulaire', 1);
     }
     $page->changeTpl('search/index.tpl');
     $page->setTitle('Annuaire');
 }