Source for file lib_common.php
Documentation is available at lib_common.php
* @author linea21 <info@linea21.com>
* @license http://opensource.org/licenses/gpl-3.0.html
$title = implode(' - ', $GLOBALS['current_title']);
* implode avec clefs associées renvoyées
* sous forme de chaîne de caractères
foreach( $array as $key => $item )
$output[] = $key . "=" . $item;
* Renvoie les paramètres HTTP
* sous forme de chaîne de caractères
* Remove PHP and HTML code
* @param string $exceptions
if(defined('RICH_TEXT_EDITOR') && RICH_TEXT_EDITOR != (string) 0) {
* Include jQuery text-resizer plugin
* if no js wysiwyg are enabled
if(defined('RICH_TEXT_EDITOR') && RICH_TEXT_EDITOR == (string) 0 )
echo '<script type="text/javascript" src="../lib/js/jquery.textarearesizer.compressed.js"></script>';
echo '<script type="text/javascript">
$(document).ready(function() {
$(\'textarea.largetextfield:not(.processed)\').TextAreaResizer();
* IncludeRichTextEditor()
* Include RichTextEditor if enabled
if(defined('RICH_TEXT_EDITOR') && RICH_TEXT_EDITOR != (string) 0 ) {
echo '<script type="text/javascript" src="../lib/js/tinymce/jscripts/tiny_mce/tiny_mce.js"></script>'. END_LINE;
echo '<script type="text/javascript" src="../lib/js/tinymce/jscripts/tiny_mce/config.js"></script>'. END_LINE;
echo '<script type="text/javascript" src="../lib/js/fckeditor/fckeditor.js"></script>'. END_LINE;
echo '<script type="text/javascript">
$(document).ready(function(){
FCKeditor.BasePath = "../lib/js/fckeditor/";
FCKeditor.MinWidth = "300px";
FCKeditor.ReplaceAllTextareas(\'largetextfield\');
* Include Lightbox jQuery plugin
$rub = isset ($_REQUEST['rub']) ? $_REQUEST['rub'] : '';
$todo = isset ($_REQUEST['todo']) ? $_REQUEST['todo'] : '';
$a = $GLOBALS['lightbox_includes'];
echo '<script type="text/javascript" src="../lib/js/jquery.lightbox-0.5.pack.js"></script>'. END_LINE;
echo '<link type="text/css" rel="stylesheet" href="../gfx/'. THEME_ADMIN. '/css/jquery.lightbox-0.5.css" />'. END_LINE;
<script type="text/javascript">
$("a.lightbox").lightBox();
* Include Lightbox jQuery date Picker
$rub = isset ($_REQUEST['rub']) ? $_REQUEST['rub'] : '';
$todo = isset ($_REQUEST['todo']) ? $_REQUEST['todo'] : '';
$a = $GLOBALS['datePicker_includes'];
echo '<script type="text/javascript" src="../lib/js/jquery.datePicker.js"></script>'. END_LINE;
echo '<link type="text/css" rel="stylesheet" href="../gfx/'. THEME_ADMIN. '/css/datePicker.css" />'. END_LINE;
echo '<script type="text/javascript" src="../lib/js/date.js"></script>'. END_LINE;
echo '<script type="text/javascript" src="../lib/js/date_'. strtolower(LANGUAGE). '.js"></script>'. END_LINE;
* Supprime le contenu d'un dossier et le dossier lui-même si précisé.
* @return integer $ver_num
if($obj== '.' || $obj== '..') continue;
* Retourne un entier comme numéro de version PHP
* @return integer $ver_num
$ver_num = $ver[0] . $ver[1] . $ver[2];
* Découpe un texte à une longeur donnée.
function cutText($content, $length, $abbr = 0, $end = '...')
if (strlen($content) > $length) {
if ($abbr == 1) $content_light = "<abbr title=\"" . $content . "\">" . substr($content, 0, $length) . $end . "</abbr>\n";
else $content_light = substr($content, 0, $length) . $end;
} else $content_light = $content;
* Renvoie un texte en 2 parties dans un tableau
$middle = (strlen($text) / 2);
$body[0] = substr($text, 0, $middle);
$body[1] = substr($text, $middle, $end);
$chaine = preg_split("/(\.(<br \/>| ))/", $body[1], 2);
$body[0] .= $chaine[0] . ".";
$body[1] = @trim($chaine[1]);
* Miniatures; agrandissement onclick
* @param string $alt_desc
* @return string $img_link
//$img_link = '<a href="' . $uri . '" title="' . $GLOBALS['lang']['divers']['enlarge_photo'] . '" onclick="displayImage(\'' . $uri . '\', \'\', \'' . $width . '\', \'' . $height . '\'); return false;">' . END_LINE;
$img_link = '<a href="' . $uri . '" title="' . $GLOBALS['lang']['divers']['enlarge_photo'] . '" class="lightbox">' . END_LINE;
$img_link .= '<img src="' . get_min_name($uri) . '" alt="' . $GLOBALS['lang']['divers']['enlarge_photo'] . ' ' . $alt_desc . '"' . $style . ' />' . END_LINE;
* Formatage des titres ( interface admin )
* @return string $content
$content = cutText($content, 70, 1);
* Formatage des listes ( interface admin )
* @return string $content
$content = cutText($content, 65, 1);
* Formatage des titres h2 ( interface admin )
* @return string $content
* Formatage de texte pour affichage
* @return string $content
$content = nl2br($content);
//$content = addslashes(trim($content));
* Remplacement des caractères invalides par leurs entités HTML
* @return string $valid_string
$htmlentities_chars = array('å' => 'Œ', 'ú' => 'œ',
'ä' => 'Š', 'ö' => 'š',
'ü' => 'Ÿ', 'à' => 'ˆ',
'ò' => '˜', 'ñ' => '–',
'ó' => '—', 'ë' => '‘',
'í' => '’', 'Ç' => '‚',
'ì' => '“', 'î' => '”',
'Ñ' => '„', 'Ü' => '†',
'á' => '‡', 'Ö' => '…',
'â' => '‰', 'É' => 'ƒ',
'ã' => '‹', 'õ' => '›',
'Ä' => '€', 'ô' => '™',
'ï' => '•', 'ò' => '˜',
//$valid_string = str_replace(array_keys($htmlentities_chars), array_values($htmlentities_chars), $str);
$search = explode(",","ç,æ,œ,á,é,í,ó,ú,à,è,ì,ò,ù,ä,ë,ï,ö,ü,ÿ,â,ê,î,ô,û,å,e,i,ø,u");
$replace = explode(",","c,ae,oe,a,e,i,o,u,a,e,i,o,u,a,e,i,o,u,y,a,e,i,o,u,a,e,i,o,u");
// strip all non word chars
// replace all white space sections with a dash
* Renvoie la date au format SQL
'mysql' => array('short'=> '%d-%m-%Y', 'long'=>
array('12' => '%d-%m-%Y %r', '24' => '%d-%m-%Y %T')),
'pgsql' => array('short'=> 'DD-MM-YYYY', 'long'=>
array('12' => 'DD-MM-YYYY HH12:MI:SS', '24' => 'DD-MM-YYYY HH24:MI:SS'))),
'mysql' => array('short'=> '%Y-%m-%d', 'long'=>
array('12' => '%Y-%m-%d %r', '24' => '%Y-%m-%d %T')),
'pgsql' => array('short'=> 'YYYY-MM-DD', 'long'=>
array('12' => 'YYYY-MM-DD HH12:MI:SS', '24' => 'YYYY-MM-DD HH24:MI:SS'))),
if($format == 'long') $s = $date_format[DATE_FORMAT][SQL][$format][TIME_FORMAT];
else $s = $date_format[DATE_FORMAT][SQL][$format];
* Compare 2 dates with a given operator.
if($date1 > $date2) return true;
if($date1 < $date2) return true;
if($date1 >= $date2) return true;
if($date1 <= $date2) return true;
if($date1 == $date2) return true;
* Include the required file
* if no user file is found,
* includes the dist/ version file.
* Renvoie la date aux formats yyyy-mm-dd ou dd-mm-yyyy suivant le cas de départ
* Si $db == true renvoie toujours la date au format yyyy-mm-dd
* @return string $new_date
@list ($part1, $part2, $part3) = explode('-', $date);
$new_date = $part3 . '-' . $part2 . '-' . $part1;
$new_date = $part1 . '-' . $part2 . '-' . $part3;
// always return yyyy-mm-dd format
$new_date = $part3 . '-' . $part2 . '-' . $part1;
$new_date = $part1 . '-' . $part2 . '-' . $part3;
if($date == '0001-01-01' || $date == '01-01-0001') {
* retourne le contenu ou N.C
* @return string $content
$content = trim($content);
if (empty($content) || isNullDate($content)) $content = $GLOBALS['lang']['divers']['nc'];
* retourne le contenu ou 'aucun'
* @return string $content
$content = trim($content);
if (empty($content)) $content = $GLOBALS['lang']['divers']['none'];
* retourne le contenu ou 0
* @return string $content
$content = trim($content);
if (empty($content)) $content = 0;
* Vérifie la validité d'une date
* @param string $msg (optionnal)
* @return boolean true or error message (string)
@list ($year, $month, $day) = explode('-', $date);
$msg .= $GLOBALS['lang']['date']['not_valid'];
if (!@checkdate($month , $day , $year)) return $msg . $GLOBALS['lang']['date']['date_do_not_exist'];
* Affichage d'un message d'erreur utilisateur
$display_it = "<div class=\"error\">\n";
$display_it .= "</div>\n";
* Affichage d'un message d'erreur syst�me
$display_it = "<div class=\"systemerror\">\n";
$display_it .= "</div>\n";
* obtenir le nom temporaire d'un fichier
* @return string $temp_path
$temp_path = $short_path . "/temp_" . $filename;
* obtenir le nom de la miniature d'un fichier
* @return string $min_path
$min_path = $short_path . "/min_" . $filename;
* Teste si une image dépasse ou non la taille autorisée (en pixels)
* @param integer $width_max
if ($width > $width_max || $height > $width_max) return true;
* renvoie les paths des photos dans un tableau
if (empty($path)) return false;
if ($opt == 'min') array_walk($tab, 'get_min_name');
* génére un bouton de retour
return '<input name="annuler" type="button" value="' . $GLOBALS['lang']['btn']['annul'] . '" class="button" id="annuler" onclick="window.location=\'' . $back_uri . '\';" />';
* renvoie les droits d'un utilisateur
if ($indice == 'U') return $GLOBALS['lang']['user']['norights'];
if ($indice == 'A') return $GLOBALS['lang']['user']['adminrights'];
if ($indice == 'O' && $module == 'dashboard') return $GLOBALS['lang']['user']['managerrights'];
if ($indice == 'O' && $module == 'workshop') return $GLOBALS['lang']['user']['animatorrights'];
if ($indice == 'O' && ($module != 'workshop' && $module != 'dashboard')) return $GLOBALS['lang']['user']['redactorrights'];
* @param array $table_link
$result = ceil($total / $pas);
if ($result <= 1) return ' ';
$link = '<div class="lienliste">'. END_LINE;
for($i = 0; $i < $result; $i++ ) {
$current_pos = ($pas * $i);
if ($debut == $current_pos) $link .= $sep. "<span>" . ($i + 1) . "</span> \n";
$array_pos = array ('debut' => $current_pos);
$new_table_link = array_merge ($table_link, $array_pos);
$link .= $sep. '<a href="'. HrefMaker($new_table_link) . '">' . ($i + 1) . '</a>'. END_LINE;
* création d'un navigateur de pages numérotées
* @param string $string_uri
function linkin_page($string_uri, $total, $debut, $pas = SELECT_LIMIT)
$result = ceil($total / $pas);
if ($result <= 1) return ' ';
if (strpos($string_uri, '?') === false) $string_uri .= '?';
else $string_uri .= '&';
$link = '<div class="lienliste">';
for($i = 0; $i < $result; $i++ ) {
$current_pos = ($pas * $i);
if ($debut == $current_pos) $link .= "<span>" . ($i + 1) . "</span> \n";
else $link .= "<a href=\"" . $string_uri . "debut=" . $current_pos . "\">" . ($i + 1) . "</a> \n";
* renvoie le statut en pleines lettres
$result = $GLOBALS['lang']['statut']['public'];
$result = $GLOBALS['lang']['statut']['draft'];
$result = $GLOBALS['lang']['statut']['E'];
$result = $GLOBALS['lang']['statut']['AA'];
$result = $GLOBALS['lang']['statut']['PA'];
$result = $GLOBALS['lang']['statut']['C'];
$result = $GLOBALS['lang']['statut']['U'];
$result = $GLOBALS['lang']['statut']['O'];
$result = $GLOBALS['lang']['statut']['A'];
$result = $GLOBALS['lang']['statut']['W'];
$result = $GLOBALS['lang']['statut']['public'];
* Cherche les liens et emails dans du contenu -> linkage
* @return string $content
if(defined('AUTO_LINK') && AUTO_LINK == 1)
if(defined('RICH_TEXT_EDITOR') && RICH_TEXT_EDITOR == (string) 0) {
if ($option == 'ALL' || $option == 'MAIL') {
$content = eregi_replace("( |<br />)+([_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)+)", '\\1<a href="mailto:\\2">\\2</a>', $content);
if ($option == 'ALL' || $option == 'LINK') {
$content = eregi_replace("(http|https|ftp|ftps)://([-a-z0-9#?/&=:,_;@%.{}]*)([a-z0-9=]{2,4})", '<a href="\\1://\\2\\3" class="out">\\1://\\2\\3</a>', $content);
* Génération de la quickbox
* @param string $suffixclass
* @return string $quickbox
function QuickBoxNow($module, $h1, $liste, $suffixclass = '')
$quickbox = "<div class=\"entete\">\n<div class=\"qb_ico\" id=\"qbico" . $suffixclass . "\" title=\"" . $module . "\"></div>\n";
$quickbox .= "<div class=\"quickbox\" id=\"qbbg" . $suffixclass . "\">\n";
$quickbox .= "<h1>" . $h1 . "</h1>\n";
* Chargement de l'index après destruction de sessions
return header("Location: ../public/logout.php");
return header("Location: ../admin/logout.php");
* renvoie le temps en microsecondes
return ((float) $usec + (float) $sec);
* @param unknown $redirect
$page = '<?xml version="1.0" encoding="ISO-8859-1" xml:lang="' . LANGUAGE . '"?>' . END_LINE;
$page .= '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">' . END_LINE;
$page .= '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="' . LANGUAGE . '">' . END_LINE;
$page .= '<meta http-equiv="content-type" content="text/html;charset=' . CHARSET . '" />' . END_LINE;
$page .= '<meta http-equiv="content-langage" content="' . CHARSET . '" />' . END_LINE;
$page .= '<meta http-equiv="refresh" content="' . $time . ';url=' . $redirect . '">' . END_LINE;
$page .= '<link rel="icon" type="image/gif" href="../gfx/' . THEME_ADMIN. '/images/admin/favicon.gif" />' . END_LINE;
$page .= '<title>'. SITE_CITY_NAME. '</title>' . END_LINE;
$page .= '<div class="info" style="margin-top:10em">'. $string. END_LINE;
$page .= sprintf( $GLOBALS['lang']['divers']['redirect_string'], $redirect, $time);
|