'minuscules',
'strtoupper',
'strtoupper' => 'majuscules',
'ucfirst',
'ucfirst' => 'maj_premiere_lettre',
'ucwords',
'str_rot13',
'str_shuffle',
'htmlentities',
'htmlspecialchars',
'trim',
'ltrim',
'rtrim',
'lcfirst',
'md5',
'sha1',
'metaphone',
'nl2br',
'soundex',
'str_split',
'str_word_count',
'strrev',
'strlen',
'wordwrap',
'strip_tags' => 'supprimer_tags',
'var_dump',
);
static public $modifiers_aliases = array(
'!=' => 'different_de',
'==' => 'egal_a',
'?' => 'choixsivide',
'>' => 'superieur_a',
'>=' => 'superieur_ou_egal_a',
'<' => 'inferieur_a',
'<=' => 'inferieur_ou_egal_a',
'yes' => 'oui',
'no' => 'non',
'and' => 'et',
'or' => 'ou',
'xor' => 'xou',
);
static public function date_en_francais($date)
{
return strtolower(utils::french_strftime('%A %e %B %Y', $date));
}
static public function heure_en_francais($date)
{
return utils::french_strftime('%Hh%M', $date);
}
static public function mois_en_francais($date)
{
return utils::french_strftime('%B %Y', $date);
}
static public function date_perso($date, $format)
{
return utils::french_strftime($format, $date);
}
static public function date_intelligente($date)
{
if (date('Ymd', $date) == date('Ymd'))
return 'Aujourd\'hui, '.date('H\hi', $date);
elseif (date('Ymd', $date) == date('Ymd', strtotime('yesterday')))
return 'Hier, '.date('H\hi', $date);
elseif (date('Y', $date) == date('Y'))
return strtolower(utils::french_strftime('%e %B, %Hh%M', $date));
else
return strtolower(utils::french_strftime('%e %B %Y', $date));
}
static public function alterner($v, $name, $valeur1, $valeur2)
{
if (!array_key_exists($name, self::$alt))
{
self::$alt[$name] = 0;
}
if (self::$alt[$name]++ % 2 == 0)
return $valeur1;
else
return $valeur2;
}
static public function proteger_contact($contact)
{
if (!trim($contact))
return '';
if (strpos($contact, '@'))
return ''.htmlspecialchars(strrev($contact), ENT_QUOTES, 'UTF-8').'';
else
return ''.htmlspecialchars($contact, ENT_QUOTES, 'UTF-8').'';
/*
$email = str_split($email, 2);
$email = implode(''.chr(mt_rand(97, 122)).chr(mt_rand(97, 122)).'', $email);
*/
}
static public function entites_html($texte)
{
return htmlspecialchars($texte, ENT_COMPAT, 'UTF-8');
}
static public function formatter_texte($texte)
{
if (is_null(self::$g2x))
{
require_once LENCRIER_ROOT . '/include/garbage2xhtml/lib.garbage2xhtml.php';
self::$g2x = new garbage2xhtml;
}
$texte = htmlspecialchars_decode($texte, ENT_QUOTES);
$texte = preg_replace('!
\n!i', '
', $texte);
if (self::$journal)
{
$journal = self::$journal;
$texte = preg_replace('!image:\[([^\]]+)\]!', utils::getJournalDatasURL($journal, 'documents') . 'images/$1', $texte);
$texte = preg_replace('!document:\[([^\]]+)\]!', utils::getJournalDatasURL($journal, 'documents') . '$1', $texte);
$texte = preg_replace_callback('!href="(\d+)"!', function ($match) use ($journal) {
return 'href="'.utils::getEcritURL($journal, (int)$match[1]).'"';
}, $texte);
}
$texte = self::$g2x->process($texte);
$texte = self::typo_fr($texte);
return $texte;
}
static public function typo_fr($str, $html = true)
{
$space = $html ? ' ' : ' ';
$str = preg_replace('/(?:[\h]| )*([?!:»])(\s+|$)/u', $space.'\\1\\2', $str);
$str = preg_replace('/(^|\s+)([«])(?:[\h]| )*/u', '\\1\\2'.$space, $str);
$str = preg_replace('/(?<=\w)(?:\'|')(?=\w)/iu', '’', $str);
$str = preg_replace('/(?<=\w)[.]{3}(?=\s|$)/iu', '…', $str);
return $str;
}
static public function formatter_texte_minimal($texte)
{
if (is_null(self::$g2x))
{
require_once LENCRIER_ROOT . '/include/garbage2xhtml/lib.garbage2xhtml.php';
self::$g2x = new garbage2xhtml;
}
$old_block = self::$g2x->block_tags;
$old_inline = self::$g2x->inline_tags;
self::$g2x->block_tags = array('p' => true, 'blockquote'=> array('cite'), 'br' => false);
self::$g2x->inline_tags = array('a' => array('href', 'hreflang', 'rel'));
$texte = self::$g2x->process($texte);
$texte = self::typo_fr($texte);
self::$g2x->block_tags = $old_block;
self::$g2x->inline_tags = $old_inline;
return $texte;
}
static public function pagination($total, $debut, $par_page)
{
$max_page = ceil($total / $par_page);
if ($max_page <= 1) return '';
$current = ($debut > 0) ? ceil($debut / $par_page) + 1 : 1;
$out = '';
if ($current > 1)
{
$out .= '« Page précédente - ';
}
for ($i = 1; $i <= $max_page; $i++)
{
$link = ($i == 1) ? './' : './+' . (($i - 1) * $par_page);
if ($i == $current)
$out .= ''.$i.' - ';
else
$out .= ''.$i.' - ';
}
if ($current < $max_page)
{
$out .= 'Page suivante »';
}
else
{
$out = substr($out, 0, -3);
}
return $out;
}
static public function reconnaitre_urls($str)
{
return preg_replace_callback('!(?<=\s|^)((?:(ftp|https?|file|ed2k|ircs?)://|(magnet|mailto|data|tel|fax|geo|sips?|xmpp):)([^\s<]+))!',
function ($match) {
$proto = $match[2] ?: $match[3];
$text = ($proto == 'http' || $proto == 'mailto') ? $match[4] : $match[1];
return ''.htmlspecialchars($text, ENT_QUOTES, 'UTF-8').'';
}, $str);
}
// Compatibilité SPIP
static public function egal_a($value, $test)
{
if ($value == $test)
return true;
else
return false;
}
static public function different_de($value, $test)
{
if ($value != $test)
return true;
else
return false;
}
// disponible aussi avec : | ?{sioui, sinon}
static public function choixsivide($value, $un, $deux = '')
{
if (empty($value) || !trim($value))
return $deux;
else
return $un;
}
static public function sinon($value, $sinon = '')
{
if ($value)
return $value;
else
return $sinon;
}
static public function choixsiegal($value, $test, $un, $deux)
{
return ($value == $test) ? $un : $deux;
}
static public function supprimer_tags($value, $replace = '')
{
return preg_replace('!<[^>]*>!', $replace, $value);
}
static public function couper($texte, $taille, $etc = ' (...)')
{
if (strlen($texte) > $taille)
{
$texte = substr($texte, 0, $taille);
$taille -= ($taille * 0.1);
$texte = preg_replace('!([\s.,;:\!?])[^\s.,;:\!?]*?$!', '\\1', $texte);
$texte.= $etc;
}
return $texte;
}
static public function replace($texte, $expression, $replace, $modif='UsimsS')
{
return preg_replace('/'.$expression.'/'.$modif, $replace, $texte);
}
static public function plus($a, $b)
{
return $a + $b;
}
static public function moins($a, $b)
{
return $a - $b;
}
static public function mult($a, $b)
{
return $a * $b;
}
static public function div($a, $b)
{
return $b ? $a / $b : 0;
}
static public function modulo($a, $mod, $add)
{
return ($mod ? $nb % $mod : 0) + $add;
}
static public function vide($value)
{
return '';
}
static public function concat()
{
return implode('', func_get_args());
}
static public function singulier_ou_pluriel($nb, $singulier, $pluriel, $var = null)
{
if (!$nb)
return '';
if ($nb == 1)
return str_replace('@'.$var.'@', $nb, $singulier);
else
return str_replace('@'.$var.'@', $nb, $pluriel);
}
static public function date_w3c($date)
{
return date(DATE_W3C, $date);
}
static public function et($value, $test)
{
return ($value && $test);
}
static public function ou($value, $test)
{
return ($value || $test);
}
static public function xou($value, $test)
{
return ($value XOR $test);
}
static public function oui($value)
{
return $value ? true : false;
}
static public function non($value)
{
return !$value ? true : false;
}
static public function superieur_a($value, $test)
{
return ($value > $test) ? true : false;
}
static public function superieur_ou_egal_a($value, $test)
{
return ($value >= $test) ? true : false;
}
static public function inferieur_a($value, $test)
{
return ($value < $test) ? true : false;
}
static public function inferieur_ou_egal_a($value, $test)
{
return ($value <= $test) ? true : false;
}
}
?>