Exemplo n.º 1
0
 protected function buildUFC(UserFilterBuilder $ufb)
 {
     $r = $s = $this->val;
     /** Admin: Email, IP
      */
     if (S::admin() && strpos($s, '@') !== false) {
         return new UFC_Email($s);
     } else {
         if (S::admin() && preg_match('/[0-9]+\\.([0-9]+|%)\\.([0-9]+|%)\\.([0-9]+|%)/', $s)) {
             return new UFC_Ip($s);
         }
     }
     $conds = new PFC_And();
     /** Name
      */
     $s = preg_replace('!\\d+!', ' ', $s);
     $strings = preg_split("![^a-z%]+!i", $s, -1, PREG_SPLIT_NO_EMPTY);
     foreach ($strings as $key => $string) {
         if (strlen($string) < 2) {
             unset($strings[$key]);
         }
     }
     if (count($strings) > 5) {
         Platal::page()->trigWarning("Tu as indiqué trop d'éléments dans ta recherche, seuls les 5 premiers seront pris en compte");
         $strings = array_slice($strings, 0, 5);
     }
     if (count($strings)) {
         if (S::user() != null && S::user()->checkPerms('directory_private')) {
             $flags = array();
         } else {
             $flags = array('public');
         }
         $exact = $ufb->b('exact');
         $conds->addChild(new UFC_NameTokens($strings, $flags, $ufb->b('with_soundex'), $exact));
         $ufb->addOrder(new UFO_Score());
     }
     /** Promo ranges
      */
     $s = preg_replace('! *- *!', '-', $r);
     $s = preg_replace('!([<>]) *!', ' \\1', $s);
     $s = preg_replace('![^0-9xmd\\-><]!i', ' ', $s);
     $s = preg_replace('![<>\\-] !', '', $s);
     $ranges = preg_split('! +!', strtolower($s), -1, PREG_SPLIT_NO_EMPTY);
     $grades = array('' => UserFilter::GRADE_ING, 'x' => UserFilter::GRADE_ING, 'm' => UserFilter::GRADE_MST, 'd' => UserFilter::GRADE_PHD);
     foreach ($ranges as $r) {
         if (preg_match('!^([xmd]?)(\\d{4})$!', $r, $matches)) {
             $conds->addChild(new UFC_Promo('=', $grades[$matches[1]], $matches[2]));
         } elseif (preg_match('!^([xmd]?)(\\d{4})-\\1(\\d{4})$!', $r, $matches)) {
             $p1 = min(intval($matches[2]), intval($matches[3]));
             $p2 = max(intval($matches[2]), intval($matches[3]));
             $conds->addChild(new PFC_And(new UFC_Promo('>=', $grades[$matches[1]], $p1), new UFC_Promo('<=', $grades[$matches[1]], $p2)));
         } elseif (preg_match('!^<([xmd]?)(\\d{4})!', $r, $matches)) {
             $conds->addChild(new UFC_Promo('<=', $grades[$matches[1]], $matches[2]));
         } elseif (preg_match('!^>([xmd]?)(\\d{4})!', $r, $matches)) {
             $conds->addChild(new UFC_Promo('>=', $grades[$matches[1]], $matches[2]));
         }
     }
     /** Phone number
      */
     $t = preg_replace('!([xmd]?\\d{4}-|>|<|)[xmd]?\\d{4}!i', '', $s);
     $t = preg_replace('![<>\\- ]!', '', $t);
     if (strlen($t) > 4) {
         $conds->addChild(new UFC_Phone($t));
     }
     return $conds;
 }