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 SIMILE Timeline JS code
if(defined('TIMELINE_DISPLAY') && TIMELINE_DISPLAY == 1 && (MOD_DEBUG != 1 || MOD_DEBUG_HIDDEN != 0)) {
if(isset ($_REQUEST['rub']) && $_REQUEST['rub']== "project" && (!isset ($_REQUEST['todo']) || $_REQUEST['todo'] == 'list')) {
echo '<script src="' . SITE_CITY_URL. '../lib/js/timeline/timeline_ajax/simile-ajax-api.js" type="text/javascript"></script>'. END_LINE;
echo '<script type="text/javascript">
Timeline_urlPrefix=\'' . SITE_CITY_URL. '../lib/js/timeline/timeline_js/\';
Timeline_parameters=\'bundle=true\';
$("#content").prepend(\'<div id="my-timeline" style="height: 250px; border-bottom: 1px solid #aaa"></div>\');
echo '<script src="' . SITE_CITY_URL. '../lib/js/timeline/timeline_js/timeline-api.js" type="text/javascript"></script>'. END_LINE;
echo '<script type="text/javascript" src="../lib/js/timeline.js"></script>'. END_LINE;
* 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();
* Include jQuery text-corner plugin
* if no js wysiwyg are enabled
echo '<script type="text/javascript" src="../lib/js/jquery.corner.js"></script>'. END_LINE;
echo '<script type="text/javascript" src="../lib/js/jquery.corner.config.js"></script>'. END_LINE;
* Include jQuery Jstree plugin
echo '<script type="text/javascript" src="../lib/js/jstree/jquery.tree.min.js"></script>'. END_LINE;
echo '<script type="text/javascript" src="../lib/js/jstree/plugins/jquery.tree.contextmenu.js"></script>'. END_LINE;
echo '<script type="text/javascript">
msg_mod = "'. _t('divers','modify'). '";
msg_del = "'. _t('divers','delete'). '";
echo '<script type="text/javascript" src="../lib/js/jstree/config.js"></script>'. END_LINE;
* IncludeRichTextEditor()
* Include RichTextEditor if enabled
if(defined('RICH_TEXT_EDITOR') && RICH_TEXT_EDITOR != (string) 0 ) {
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
echo '<script type="text/javascript" src="../lib/js/jquery.lightbox-0.5.pack.js"></script>'. END_LINE;
<script type="text/javascript">
$("a.lightbox").lightBox();
* Include jQuery multiSelect plugin
$rub = isset ($_REQUEST['rub']) ? $_REQUEST['rub'] : '';
$todo = isset ($_REQUEST['todo']) ? $_REQUEST['todo'] : '';
$a = $GLOBALS['multiSelect_includes'];
echo '<script type="text/javascript" src="../lib/js/jquery.multiSelect/jquery.multiSelect.js"></script>'. END_LINE;
echo '<script type="text/javascript" src="../lib/js/jquery.multiSelect/jquery.bgiframe.min.js"></script>'. END_LINE;
* Include 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 '<script type="text/javascript" src="../lib/js/date.js"></script>'. END_LINE;
* Créer un dossier s'il n'existe pas.
* @param string $pathname
* @return integer $ver_num
return mkdir ($pathname, $perms, true);
* 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 = '...')
else $substr = substr($content, 0, $length);
if (strlen($content) > $length) {
if ($abbr == 1) $content_light = "<abbr title=\"" . $content . "\">" . $substr . $end . "</abbr>\n";
else $content_light = $substr . $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="' . _t('divers','enlarge_photo') . '" onclick="displayImage(\'' . $uri . '\', \'\', \'' . $width . '\', \'' . $height . '\'); return false;">' . END_LINE;
$img_link = '<a href="' . $uri . '" title="' . _t('divers','enlarge_photo') . '" class="lightbox">' . END_LINE;
$img_link .= '<img src="' . get_min_name($uri) . '" alt="' . _t('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;
* Build a localized filename
* according to the cuurent language
$total = count($tmp) - 1;
return @implode(".", $tmp). '.' . LANGUAGE. '.' . $ext;
* Include the required file
* if no user file is found,
* includes the dist/ version file.
* Localized files have the priority
$file_dist_default = $default_dist. 'dist/'. basename($file);
$l10n_file_dist_default = $default_dist. 'dist/'. basename($l10n_file);
_debug($l10n_file, "override");
include_once($l10n_file);
_debug($l10n_file_dist, "override");
include_once($l10n_file_dist);
_debug($l10n_file_dist_default, "override");
include_once($l10n_file_dist_default);
_debug($file_dist_default, "override");
include_once($file_dist_default);
* Include the required file
* if no user file is found in theme,
* includes the default module version file.
$theme_file = $path. 'override/'. str_replace('../', '', $file);
_debug($theme_file, "override");
include_once($theme_file);
* check if a template file version exists or not
* if no user file is found in theme,
* return the default module version file.
$theme_file = $path. 'override/'. str_replace('../', '', $file);
_debug($theme_file, "override");
* 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;
* Format date to RFC 2822 date format
* @return string (exemple : Thu, 21 Dec 2000 16:01:07 +0200)
@list ($y, $m, $d) = explode('-', $tmp_date);
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 = _t('divers','nc');
* retourne le contenu ou 'aucun'
* @return string $content
$content = trim($content);
if (empty($content)) $content = _t('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 .= _t('date','not_valid');
if (!@checkdate($month , $day , $year)) return $msg . _t('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="' . _t('btn','annul') . '" class="button" id="annuler" onclick="window.location=\'' . $back_uri . '\';" />';
* renvoie les droits d'un utilisateur
if ($indice == 'U') return _t('user','norights');
if ($indice == 'A') return _t('user','adminrights');
if ($indice == 'O' && $module == 'dashboard') return _t('user','managerrights');
if ($indice == 'O' && $module == 'workshop') return _t('user','animatorrights');
if ($indice == 'O' && ($module != 'workshop' && $module != 'dashboard')) return _t('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 = _t('statut','public');
$result = _t('statut','draft');
$result = _t('statut','E');
$result = _t('statut','AA');
$result = _t('statut','PA');
$result = _t('statut','C');
$result = _t('statut','U');
$result = _t('statut','O');
$result = _t('statut','A');
$result = _t('statut','W');
$result = _t('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);
* Return available languages
if ($handle = opendir('../languages/')) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != ".." && $file != ".svn") {
* @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 .= '<title>'. SITE_CITY_NAME. '</title>' . END_LINE;
$page .= '<div class="info" style="margin-top:10em">'. $string. END_LINE;
$page .= sprintf( _t('divers','redirect_string'), $redirect, $time);
if(defined('MOD_DEBUG') && MOD_DEBUG == true) {
echo '<div id="debug-enabled">DEBUG_MOD '. _t('debug', 'enabled') . '</div>';
* Display a debug message in html code
function _debug($string, $mode)
if(defined('MOD_DEBUG') && MOD_DEBUG == true)
if($mode == 'override' && defined('TYPE_DEBUG') && TYPE_DEBUG == "override")
if(defined('MOD_DEBUG_HIDDEN') && MOD_DEBUG_HIDDEN == true) echo "<!-- "; else echo "<p class=\"debug\">";
if(defined('MOD_DEBUG_HIDDEN') && MOD_DEBUG_HIDDEN == true) echo " -->"; else echo END_LINE. "</p>";
* Display a link to download new version if available
throw new Exception('Version : xml file was not found');
if((integer) $latest_version > (integer) $current_version) {
$update = '<div id="version-check">'. _t('check_update','search'). ' : <a href="'.(string) $rss->link. '">'. sprintf(_t('check_update','dl'), $rss->num). '</a></div>';
$update = '<div id="version-check">'. _t('check_update','search'). ' : '. _t('check_update','ok'). '</div>';
$update = $e->getMessage();
|