5 class Squelette_Filtres
7 static private $g2x = null;
8 static private $alt = [];
10 static public $filtres_php = [
33 'strip_tags' => 'supprimer_tags',
37 static public $filtres_alias = [
38 '!=' => 'different_de',
42 '>=' => 'superieur_ou_egal_a',
44 '<=' => 'inferieur_ou_egal_a',
52 static public $desactiver_defaut = [
59 static public function date_en_francais($date)
61 return ucfirst(strtolower(utils
::strftime_fr('%A %e %B %Y', $date)));
64 static public function heure_en_francais($date)
66 return utils
::strftime_fr('%Hh%I', $date);
69 static public function mois_en_francais($date)
71 return utils
::strftime_fr('%B %Y', $date);
74 static public function date_perso($date, $format)
76 return utils
::strftime_fr($format, $date);
79 static public function date_intelligente($date)
81 if (date('Ymd', $date) == date('Ymd'))
82 return 'Aujourd\'hui, '.date('H\hi', $date);
83 elseif (date('Ymd', $date) == date('Ymd', strtotime('yesterday')))
84 return 'Hier, '.date('H\hi', $date);
85 elseif (date('Y', $date) == date('Y'))
86 return strtolower(utils
::strftime_fr('%e %B, %Hh%M', $date));
88 return strtolower(utils
::strftime_fr('%e %B %Y', $date));
91 static public function date_atom($date)
93 return date(DATE_ATOM
, $date);
96 static public function alterner($v, $name, $valeur1, $valeur2)
98 if (!array_key_exists($name, self
::$alt))
100 self
::$alt[$name] = 0;
103 if (self
::$alt[$name]++ %
2 == 0)
109 static public function proteger_contact($contact)
114 if (strpos($contact, '@'))
115 return '<span style="unicode-bidi:bidi-override;direction: rtl;">'.htmlspecialchars(strrev($contact), ENT_QUOTES
, 'UTF-8').'</span>';
117 return '<a href="'.htmlspecialchars($contact, ENT_QUOTES
, 'UTF-8').'">'.htmlspecialchars($contact, ENT_QUOTES
, 'UTF-8').'</a>';
120 static public function entites_html($texte)
122 return htmlspecialchars($texte, ENT_QUOTES
, 'UTF-8');
125 static public function echapper_xml($texte)
127 return str_replace(''', ''', htmlspecialchars($texte, ENT_QUOTES
, 'UTF-8'));
130 static public function formatter_texte($texte)
132 $texte = utils
::htmlLinksOnUrls($texte);
133 $texte = utils
::htmlSpip($texte);
134 $texte = utils
::htmlGarbage2xhtml($texte);
136 $texte = self
::typo_fr($texte);
141 static public function typo_fr($str, $html = true)
143 $space = $html ?
' ' : ' ';
144 $str = preg_replace('/(?:[\h]| )*([?!:»])(\s+|$)/u', $space.'\\1\\2', $str);
145 $str = preg_replace('/(^|\s+)([«])(?:[\h]| )*/u', '\\1\\2'.$space, $str);
149 static public function pagination($total, $debut, $par_page)
151 $max_page = ceil($total / $par_page);
152 $current = ($debut > 0) ?
ceil($debut / $par_page) +
1 : 1;
157 $out .= '<a href="./'.($current > 2 ?
'+' . ($debut - $par_page) : '').'">« Page précédente</a> - ';
160 for ($i = 1; $i <= $max_page; $i++
)
162 $link = ($i == 1) ?
'./' : './+' . (($i - 1) * $par_page);
165 $out .= '<strong>'.$i.'</strong> - ';
167 $out .= '<a href="'.$link.'">'.$i.'</a> - ';
170 if ($current < $max_page)
172 $out .= '<a href="./+'.($debut +
$par_page).'">Page suivante »</a>';
176 $out = substr($out, 0, -3);
182 // Compatibilité SPIP
184 static public function egal_a($value, $test)
192 static public function different_de($value, $test)
200 // disponible aussi avec : | ?{sioui, sinon}
201 static public function choixsivide($value, $un, $deux = '')
203 if (empty($value) ||
!trim($value))
209 static public function sinon($value, $sinon = '')
217 static public function choixsiegal($value, $test, $un, $deux)
219 return ($value == $test) ?
$un : $deux;
222 static public function supprimer_tags($value, $replace = '')
224 return preg_replace('!<[^>]*>!', $replace, $value);
227 static public function supprimer_spip($value)
229 $value = preg_replace('!\[([^\]]+)(?:->[^\]]*)?\]!U', '$1', $value);
230 $value = preg_replace('!\{+([^\}]*)\}+!', '$1', $value);
234 static public function couper($texte, $taille, $etc = ' (...)')
236 if (strlen($texte) > $taille)
238 $texte = substr($texte, 0, $taille);
239 $taille -= ($taille * 0.1);
241 $texte = preg_replace('!([\s.,;:\!?])[^\s.,;:\!?]*?$!', '\\1', $texte);
248 static public function replace($texte, $expression, $replace, $modif='UsimsS')
250 return preg_replace('/'.$expression.'/'.$modif, $replace, $texte);
253 static public function plus($a, $b)
258 static public function moins($a, $b)
263 static public function mult($a, $b)
268 static public function div($a, $b)
270 return $b ?
$a / $b : 0;
273 static public function modulo($a, $mod, $add)
275 return ($mod ?
$nb %
$mod : 0) +
$add;
278 static public function vide($value)
283 static public function concat()
285 return implode('', func_get_args());
288 static public function singulier_ou_pluriel($nb, $singulier, $pluriel, $var = null)
294 return str_replace('@'.$var.'@', $nb, $singulier);
296 return str_replace('@'.$var.'@', $nb, $pluriel);
299 static public function date_w3c($date)
301 return date(DATE_W3C
, $date);
304 static public function et($value, $test)
306 return ($value && $test);
309 static public function ou($value, $test)
311 return ($value ||
$test);
314 static public function xou($value, $test)
316 return ($value XOR $test);
319 static public function oui($value)
321 return $value ?
true : false;
324 static public function non($value)
326 return !$value ?
true : false;
329 static public function superieur_a($value, $test)
331 return ($value > $test) ?
true : false;
334 static public function superieur_ou_egal_a($value, $test)
336 return ($value >= $test) ?
true : false;
339 static public function inferieur_a($value, $test)
341 return ($value < $test) ?
true : false;
344 static public function inferieur_ou_egal_a($value, $test)
346 return ($value <= $test) ?
true : false;