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
* 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) {
if($exceptions === true) {
* Include SIMILE Timeline JS code
if(defined('TIMELINE_DISPLAY') && TIMELINE_DISPLAY == 1) {
if(isset ($_REQUEST['rub']) && $_REQUEST['rub']== "project" && (!isset ($_REQUEST['todo']) || $_REQUEST['todo'] == 'list')) {
echo '<script src="' . SITE_ROOT_URL. 'lib/js/timeline/timeline_ajax/simile-ajax-api.js" type="text/javascript"></script>'. END_LINE;
echo '<script type="text/javascript">
Timeline_urlPrefix=\'' . SITE_ROOT_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_ROOT_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 Js & css for PHP_DEBUG
echo "<script type=\"text/javascript\">
var nicEditorLang = '". U_L. "';
echo '<script type="text/javascript" src="../lib/js/nicEdit/lang.js"></script>'. END_LINE;
echo '<script type="text/javascript" src="../lib/js/nicEdit/nicEdit.js"></script>'. END_LINE;
echo "<script type=\"text/javascript\">
bkLib.onDomLoaded(function() {
new nicEditor({iconsPath : '../lib/js/nicEdit/nicEditorIcons.gif', buttonList : ['bold','italic','underline','subscript','superscript', 'link','unlink','image','upload']}).panelInstance('". $a['id']. "');
* Include Js & css for PHP_DEBUG
if(defined('MOD_DEBUG') && MOD_DEBUG == true) {
echo '<script type="text/javascript" src="../lib/vendor/PHP_Debug/js/html_div.js"></script>'. END_LINE;
echo '<link type="text/css" rel="stylesheet" href="../lib/vendor/PHP_Debug/css/html_div.css" />'. END_LINE;
* Include jQuery tooltip plugin
* @param string $selector
$str .= '$("'. $selector. '").tooltip({ effect: "slide", opacity: 0.8});';
foreach($selector as $sel) {
$str .= '$("'. $sel. '").tooltip({ effect: "slide", opacity: 0.8});'. END_LINE;
echo '<script type="text/javascript" src="../lib/js/jquery.tools.min.js"></script>'. END_LINE;
echo '<script type="text/javascript">
$(document).ready(function() {
* Transform a list given in the form "jpg,png,gif"
* into "(jpg)|(png)|(gif)" format
* Include jQuery Fancy Upload
$rub = isset ($_REQUEST['rub']) ? $_REQUEST['rub'] : '';
$a = $GLOBALS['fancyUpload_includes'];
// security check here because uploadify is not able to handle cookie
echo '<script type="text/javascript">
var rooturl = "' . SITE_ROOT_URL. '";
var upbutton = "' . _t('divers', 'up'). '";
var delbutton = "'. _t('divers', 'delqueue'). '";
var addfiles = "' . _t('upload', 'addfiles'). '";
var succeed = "' . _t('upload', 'confirmed'). '";
var error = "' . _t('upload', 'error'). '";
var notallowed_msg = "'. sprintf(_t('upload', 'wrong_ext'), $fileDesc). '";
var maxsize = "' . MEDIA_ALLOWED_SIZE. '";
var regexpattern = "' . extRegex(MEDIA_ALLOWED_EXT). '";
var fileReplace = "' . _t('divers', 'replace_file'). '";
var cbText = "'. _t('workshop', 'share_files'). '";
<link type="text/css" rel="stylesheet" href="../lib/js/jquery-ui/css/ui-lightness/jquery-ui-1.8.16.custom.css" id="theme" />
<link type="text/css" rel="stylesheet" href="../lib/vendor/jQuery-File-Upload/jquery.fileupload-ui-l21.css" media="screen" />
<script type="text/javascript" src="../lib/js/jquery-ui/js/jquery-ui-1.8.16.custom.min.js"></script>
<script type="text/javascript" src="../lib/vendor/jQuery-File-Upload/jquery.fileupload.js"></script>
<script type="text/javascript" src="../lib/vendor/jQuery-File-Upload/jquery.fileupload-ui.js"></script>
<script type="text/javascript" src="../lib/vendor/jQuery-File-Upload/public-settings.js"></script>'. END_LINE;
* Include jQuery DragTable plugin settings
$rub = isset ($_REQUEST['rub']) ? $_REQUEST['rub'] : '';
echo '<script type="text/javascript">
$(document).ready(function(){
$("table.sortable thead tr").prepend("<td> <\/td>");
$("table.sortable tfoot tr").prepend("<td> <\/td>");
$("table.sortable tbody tr").prepend("<td class=\"dragHandle\"> <\/td>");
$("table.sortable").tableDnD({
onDrop: function(table, row) {
$.get("../admin/_ajax_sort.php?rub='. $rub. '&" + $.tableDnD.serialize(), function(data) {
if(data.class=="succeed") {
humane.success(data.msg);
* Include jQuery tree plugin
$str = '<ul id="cMenu" class="contextMenu"><li class="edit"><a href="#edit">'. _t('divers','modify'). '<\/a><\/li><li class="delete separator"><a href="#delete">'. _t('divers','delete'). '<\/a><\/li><\/ul>';
echo '<script type="text/javascript" src="../lib/js/jquery.contextMenu/jquery.contextMenu.js"></script>'. END_LINE;
echo '<link type="text/css" rel="stylesheet" href="../lib/js/jquery.contextMenu/jquery.contextMenu-l21.css" media="screen" />'. END_LINE;
echo '<script type="text/javascript" src="../lib/js/jquery.treeview/jquery.treeview.js"></script>'. END_LINE;
echo '<link type="text/css" rel="stylesheet" href="../lib/js/jquery.treeview/jquery.treeview.css" media="screen" />'. END_LINE;
echo '<script type="text/javascript">
$(document).ready(function(){
$("#tree").after(\''. $str. '\');
$("#tree ul li.contextual-menu").contextMenu({
}, function(action, el, pos) {
if(typeof $(el).children("a.ico_mod").attr("href") == "undefined") {
// not used anymore bu we keep it in case of
humane.error("'. _t('msg', 'action_not_allowed'). '");
document.location.href = $(el).children("a.ico_mod").attr("href");
if(typeof $(el).children("a.ico_sup").attr("href") == "undefined") {
// used for level - which does not have delete action
humane.error("'. _t('msg', 'action_not_allowed'). '");
document.location.href = $(el).children("a.ico_sup").attr("href");
$("#tree li a.ico_mod, #tree li a.ico_sup").css("display", "none");
* IncludeRichTextEditor()
* Include RichTextEditor if enabled
if(defined('RICH_TEXT_EDITOR') && RICH_TEXT_EDITOR != (string) 0 ) {
include('../lib/js/ckeditor/ckeditor.php');
$CKEditor = new CKEditor();
$CKEditor->basePath = SITE_ROOT_URL. 'lib/js/ckeditor/';
$CKEditor->config['customConfig'] = 'l21_config.js';
if(defined('CKFINDER_ENABLED') && CKFINDER_ENABLED == true) {
require_once '../lib/vendor/ckfinder/ckfinder.php';
CKFinder::SetupCKEditor( $CKEditor, '../lib/vendor/ckfinder/' ) ;
$CKEditor->config['filebrowserBrowseUrl'] = '../library/access.php';
$CKEditor->config['filebrowserImageBrowseUrl'] = '../library/access.php?type=images';
$CKEditor->config['filebrowserUploadUrl'] = '../library/access.php';
$CKEditor->config['filebrowserImageUploadUrl'] = '../library/access.php?type=images';
$CKEditor->config['filebrowserWindowWidth'] = '100%';
$CKEditor->config['filebrowserWindowHeight'] = '100%';
$CKEditor->replaceAll('largetextfield');
* Include Colorbox jQuery plugin
* @param string £selector
$str .= '$("'. $selector. '").colorbox({transition:"fade"});'. END_LINE;
foreach($selector as $sel) {
$str .= '$("'. $sel. '").colorbox({transition:"fade"});'. END_LINE;
echo '<script type="text/javascript" src="../lib/js/colorbox/colorbox/jquery.colorbox-min.js"></script>'. END_LINE;
echo '<link type="text/css" rel="stylesheet" href="../lib/js/colorbox/colorbox.css" />'. END_LINE;
<script type="text/javascript">
$(document).ready(function() {
* Include Lightbox jQuery plugin
* @param string £selector
* @todo Remove function - Already replaced by colorbox
<script type="text/javascript">
alert("Please, replace IncludeLightboxJs() call by IncludeColorboxJs() into your template.")
* Include jQuery TextBoxList plugin
$rub = isset ($_REQUEST['rub']) ? $_REQUEST['rub'] : '';
$todo = isset ($_REQUEST['todo']) ? $_REQUEST['todo'] : '';
$a = $GLOBALS['textboxList_includes'];
echo '<link type="text/css" rel="stylesheet" href="'. THEME_ADMIN_PATH. 'css/TextboxList.css" media="screen" />'. END_LINE;
echo '<link type="text/css" rel="stylesheet" href="'. THEME_ADMIN_PATH. 'css/TextboxList.Autocomplete.css" media="screen" />'. END_LINE;
echo '<script type="text/javascript" src="../lib/js/jquery.textboxList/GrowingInput.js"></script>'. END_LINE;
echo '<script type="text/javascript" src="../lib/js/jquery.textboxList/TextboxList.js"></script>'. END_LINE;
echo '<script type="text/javascript" src="../lib/js/jquery.textboxList/TextboxList.Autocomplete.js"></script>'. END_LINE;
* 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-ui-multiselect/src/jquery.multiselect.min.js"></script>'. END_LINE;
echo '<script type="text/javascript" src="../lib/js/jquery-ui-multiselect/src/jquery.multiselect.filter.min.js"></script>'. END_LINE;
echo '<script type="text/javascript" src="../lib/js/jquery-ui-multiselect/i18n/jquery.multiselect.'. U_L. '.js"></script>'. END_LINE;
echo '<script type="text/javascript" src="../lib/js/jquery-ui-multiselect/i18n/jquery.multiselect.filter.'. U_L. '.js"></script>'. END_LINE;
echo '<link type="text/css" rel="stylesheet" href="../lib/js/jquery-ui-multiselect/jquery.multiselect.css" />'. END_LINE;
echo '<link type="text/css" rel="stylesheet" href="../lib/js/jquery-ui-multiselect/jquery.multiselect.filter.css" />'. END_LINE;
* IncludeMappingLibraryJs()
* Include the current mapping library
* @todo not used - Gmaps is used instead
// @todo remove from here and insert into /config/define.php if used
$GLOBALS['mapping_includes'] = array('directory-detail|');
$rub = isset ($_REQUEST['rub']) ? $_REQUEST['rub'] : '';
$todo = isset ($_REQUEST['todo']) ? $_REQUEST['todo'] : '';
$a = $GLOBALS['mapping_includes'];
echo '<script type="text/javascript" src="../lib/vendor/leaflet/dist/leaflet.js" /></script>'. END_LINE;
echo '<link rel="stylesheet" type="text/css" href="../lib/vendor/leaflet/dist/leaflet.css" />'. END_LINE;
echo '<!--[if lte IE 8]><link rel="stylesheet" href="../lib/vendor/leaflet/dist/leaflet.ie.css" /><![endif]-->'. 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]);
$str = preg_replace('#<p[^>]*>(\s| ?)*</p>#', '', $str);
* Miniatures; agrandissement onclick
* @param string $alt_desc
* @return string $img_link
* @todo in 1.6 - check if still in use
$img_link = '<a href="' . $uri . '" title="' . _t('divers','enlarge_photo') . '">' . 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
* check if raw text or html text
* Formatage de texte pour affichage
* @return string $content
if(RICH_TEXT_EDITOR === 0 || isRawText($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;
* 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('distInclude() file Inclusion : '. $l10n_file);
include_once($l10n_file);
_debug('distInclude() file Inclusion : '. $l10n_file_dist);
include_once($l10n_file_dist);
_debug('distInclude() file Inclusion : '. $file);
_debug('distInclude() file Inclusion : '. $l10n_file_dist_default);
include_once($l10n_file_dist_default);
_debug('distInclude() file Inclusion : '. $file_dist_default);
include_once($file_dist_default);
* 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('themePath() returned value : '. $theme_file);
_debug('themePath() returned value : '. $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;
* 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');
* Return an array with key and value
* with ID as key and RANGE as value
for($i= 0; $i< count($data); $i++ ) {
* 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
* @todo not used anymore (verify) - can be removed
$temp_path = $short_path . "/temp_" . $filename;
* obtenir le nom de la miniature d'un fichier
* @return string $min_path
* @todo not used anymore (verify) - can be removed
$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
* @todo - Remove in 1.6 if not use anymore
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="pagination">'. 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="pagination">';
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/index.php");
return header("Location: ../admin/logout.php");
* renvoie le temps en microsecondes
return ((float) $usec + (float) $sec);
* Return available plugins
if ($handle = opendir('../plugins/')) {
while (false !== ($file = readdir($handle))) {
if (substr($file, 0, 4) == 'l21_' ) {
* @link http://fr2.php.net/manual/fr/function.mysql-query.php
$handle = @fopen($url, "r");
if($a == - 1) $a = array();
$sql_line = fgets($handle);
if (trim($sql_line) != "" && strpos($sql_line, "--") === false && strpos($sql_line, "#") === false) {
* Return a graphic progress bar
$step = $max / PROJECT_STEP;
$threshold = $value / PROJECT_STEP;
$str = '<div class="progressbar" title="'. $value. ' '. $unit. '">'. END_LINE;
for($i= 1; $i<= $step; $i++ ) {
($i <= $threshold) ? $class = 'class="completed"' : $class = '';
$str .= '<span '. $class. '> </span>';
* get Long/Latitude coordinates
$o->{'status'} = 'geocoder_disabled';
if(!defined('GEOCODER_ENABLED') || GEOCODER_ENABLED == 0)
foreach ($input as $key => $value)
* @param unknown $redirect
$page = '<?xml version="1.0" encoding="' . CHARSET . '" xml:lang="' . U_L . '"?>' . 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="' . U_L . '">' . 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_NAME. '</title>' . END_LINE;
$page .= '<div class="info" style="margin-top:10em">'. $string. END_LINE;
$page .= sprintf( _t('divers','redirect_string'), $redirect, $time);
* Display a debug message
if(isset ($GLOBALS['Dbg']))
_debug('<b>Problem loading CSS file</b> : '. $path . ' (position : '. $pos. ')');
$str = '<link type="text/css" rel="stylesheet" href="'. $path. '" />'. END_LINE;
if(isset ($GLOBALS['CSSheader']))
$GLOBALS['CSSheader'] = $str . $GLOBALS['CSSheader'];
$GLOBALS['CSSheader'] .= $str . END_LINE ;
$GLOBALS['CSSheader'] = $str;
_debug('Loading <b>CSS file</b> : '. $path . ' (position : '. $pos. ')');
_debug('<b>Problem loading JS file</b> : '. $path . ' (position : '. $pos. ')');
$str= '<script type="text/javascript" src="'. $path . '"></script>'. END_LINE;
if(isset ($GLOBALS['JSheader']))
$GLOBALS['JSheader'] = $str . $GLOBALS['JSheader'];
$GLOBALS['JSheader'] .= $str . END_LINE ;
$GLOBALS['JSheader'] = $str;
_debug('Loading <b>JS file</b> : '. $path . ' (position : '. $pos. ')');
* Add inline JS into footer
* the resulting js is wrapped with <script> tags and jQuery .ready() function
if(isset ($GLOBALS['JSInlinefooter']))
$GLOBALS['JSInlinefooter'] = $str . END_LINE. $GLOBALS['JSInlinefooter'];
$GLOBALS['JSInlinefooter'] .= $str . END_LINE ;
$GLOBALS['JSInlinefooter'] = $str. END_LINE;
_debug('Loading <b>inline JS</b> : '. cutText($str, 90) . ' (position : '. $pos. ')');
_debug('<b>Problem loading JS file</b> : '. $path . ' (position : '. $pos. ')');
$str= '<script type="text/javascript" src="'. $path . '"></script>'. END_LINE;
if(isset ($GLOBALS['JSfooter']))
$GLOBALS['JSfooter'] = $str . $GLOBALS['JSheader'];
$GLOBALS['JSfooter'] .= $str . END_LINE ;
$GLOBALS['JSfooter'] = $str . END_LINE ;
_debug('Loading <b>JS file</b> : '. $path . ' (position : '. $pos. ')');
* Display JS and CSS header
if(isset ($GLOBALS['JSheader'])) echo $GLOBALS['JSheader'];
if(isset ($GLOBALS['CSSheader'])) echo $GLOBALS['CSSheader'];
if(isset ($GLOBALS['JSfooter'])) echo $GLOBALS['JSfooter'];
if(isset ($GLOBALS['JSInlinefooter'])) {
echo '<script type="text/javascript">'. END_LINE;
echo ' $(document).ready(function() {'. END_LINE;
echo $GLOBALS['JSInlinefooter'];
* Display a link to download new version if available
throw new Exception('Version : xml file was not found');
$current_version = preg_replace("/([^0-9])/",'', LINEA_VERSION); // remove letter (if dev version)
_debug('current ver : '. $current_version);
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();
throw new Exception($name. ' plugin : xml file was not found');
$a['name'] = $flow->themename;
$a['description'] = $flow->description;
$a['version'] = $flow->version;
$a['date'] = $flow->date;
$a['compatibility'] = $flow->compatibility;
$a['author'] = $flow->author;
$a['homepage'] = $flow->homepage;
* For compatibility with PHP < 5.2
require_once __DIR__ . '/vendor/JSON/JSON.php';
return $json->decode($content);
* For compatibility with PHP < 5.2
require_once __DIR__ . '/vendor/JSON/JSON.php';
return $json->encode($content);
Validate an email address.
Provide email address (raw input)
Returns true if the email address has the email
address format and the domain exists.
@link http://www.linuxjournal.com/article/9585
if (is_bool($atIndex) && !$atIndex)
$domain = substr($email, $atIndex+ 1);
$local = substr($email, 0, $atIndex);
if ($localLen < 1 || $localLen > 64)
// local part length exceeded
else if ($domainLen < 1 || $domainLen > 255)
// domain part length exceeded
else if ($local[0] == '.' || $local[$localLen- 1] == '.')
// local part starts or ends with '.'
// local part has two consecutive dots
else if (!preg_match('/^[A-Za-z0-9\\-\\.]+$/', $domain))
// character not valid in domain part
// domain part has two consecutive dots
(!preg_match('/^(\\\\.|[A-Za-z0-9!#%&`_=\\/$\'*+?^{}|~.-])+$/',
// character not valid in local part unless
// domain not found in DNS
* Check if comment is enabled on
if(!defined('MOD_COMMENT') || MOD_COMMENT == 0) {
if(!isset ($GLOBALS['breadcrumb'])) $GLOBALS['breadcrumb']= array();
$GLOBALS['breadcrumb'] = array_merge($GLOBALS['breadcrumb'], $array);
* get the Breadcrumb for displaying
* @param string (optional)
$str = '<div id="breadcrumb">'. END_LINE;
$str.= '<li>'. $sep. ' <a href="'. SITE_ROOT_URL. 'public/">'. _t('way', 'home'). '</a></li>'. END_LINE;
foreach($GLOBALS['breadcrumb'] as $key => $value) {
if($value!= false) $str.= '<li>'. $sep. ' <a href="'. $value. '">'. $key. '</a></li>'. END_LINE;
else $str.= '<li>'. $sep. ' '. $key. '</li>'. END_LINE;
* Return an arry of filenames
function GetAllFiles($folder,$ext= array('txt'),$recursif= true) {
if ($file == '.' || $file == '..') continue;
if (is_dir($folder. '/'. $file)) {
$files[] = $folder. '/'. $file;
* Return an HTML list for a given folder
function ListDir($dir_handle,$path, $url) {
while (false !== ($file = readdir($dir_handle))) {
if(is_dir($dir) && $file != '.' && $file != '..' ) {
$handle = @opendir($dir) or die("Unable to open file $file");
} elseif($file != '.' && $file != '..' && $file != '.htaccess') {
// uncomment to reverse array
// $dirFiles= array_reverse($dirFiles);
// uncomment to sort on latest modification
// array_map( 'filemtime', $dirFiles ),
foreach($dirFiles as $dir)
$class = ($i++ & 1) ? '' : 'class="odd"';
$comment_actions = '<span class="comment_actions">';
$comment_actions .= '<a class="comment_see" href="../comment/_ajax_view.php?id='. $id. '&module=files&order_by=ASC" title="' . $file . ' - ' . _t('comment','go_to') . ' / ' . _t('comment','add') . '"><span class="cc">' . $nb . '</span><span class="textcc"> ' . _t('comment','comments'). ' - ' . _t('comment','add') . '</span></a>';
$comment_actions .= '</span>';
echo '<li '. $class. '><a href="'. $url . $dir . '">'. $file. '</a> <em>('. $size. ')</em> '. $comment_actions. '<a class="dlfile" href="'. $url . 'library/dl.php?file='. $dir . '" title="'. _t('divers','dl'). ' ' . $file. '"><span>' . _t('divers','dl'). '</span></a></li>';
if($i== 0) echo '<li>'. _t('divers','no_files'). '</li>';
* Make File size readable
$units = array('o', 'Ko', 'Mo', 'Go', 'To');
$bytes /= pow(1024, $pow);
return round($bytes, $precision) . ' ' . $units[$pow];
* Return installed themes
if ($handle = opendir('../templates/'. $f)) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != ".." && $file != ".svn") {
* Remove exotic characters form string
* same as used in filemanager
foreach ($allowed as $value) {
'Š'=> 'S', 'š'=> 's', 'Đ'=> 'Dj', 'đ'=> 'dj', 'Ž'=> 'Z', 'ž'=> 'z', 'Č'=> 'C', 'č'=> 'c', 'Ć'=> 'C', 'ć'=> 'c',
'À'=> 'A', 'Á'=> 'A', 'Â'=> 'A', 'Ã'=> 'A', 'Ä'=> 'A', 'Å'=> 'A', 'Æ'=> 'A', 'Ç'=> 'C', 'È'=> 'E', 'É'=> 'E',
'Ê'=> 'E', 'Ë'=> 'E', 'Ì'=> 'I', 'Í'=> 'I', 'Î'=> 'I', 'Ï'=> 'I', 'Ñ'=> 'N', 'Ò'=> 'O', 'Ó'=> 'O', 'Ô'=> 'O',
'Õ'=> 'O', 'Ö'=> 'O', 'Ő'=> 'O', 'Ø'=> 'O', 'Ù'=> 'U', 'Ú'=> 'U', 'Û'=> 'U', 'Ü'=> 'U', 'Ű'=> 'U', 'Ý'=> 'Y',
'Þ'=> 'B', 'ß'=> 'Ss','à'=> 'a', 'á'=> 'a', 'â'=> 'a', 'ã'=> 'a', 'ä'=> 'a', 'å'=> 'a', 'æ'=> 'a', 'ç'=> 'c',
'è'=> 'e', 'é'=> 'e', 'ê'=> 'e', 'ë'=> 'e', 'ì'=> 'i', 'í'=> 'i', 'î'=> 'i', 'ï'=> 'i', 'ð'=> 'o', 'ñ'=> 'n',
'ò'=> 'o', 'ó'=> 'o', 'ô'=> 'o', 'õ'=> 'o', 'ö'=> 'o', 'ő'=> 'o', 'ø'=> 'o', 'ù'=> 'u', 'ú'=> 'u', 'ű'=> 'u',
'û'=> 'u', 'ý'=> 'y', 'ý'=> 'y', 'þ'=> 'b', 'ÿ'=> 'y', 'Ŕ'=> 'R', 'ŕ'=> 'r', ' '=> '_', "'"=> '_', '/'=> ''
foreach ($string as $key => $clean) {
$clean = strtr($clean, $mapping);
$clean = preg_replace("/[^{$allow}_a-zA-Z0-9]/", '', $clean);
$cleaned[$key] = preg_replace('/[_]+/', '_', $clean); // remove double underscore
$string = strtr($string, $mapping);
$string = preg_replace("/[^{$allow}_a-zA-Z0-9]/", '', $string);
$cleaned = preg_replace('/[_]+/', '_', $string); // remove double underscore
* Test and sanitize user input
// we first sanitize vars
if(isset ($_REQUEST['rub']))
if(isset ($_REQUEST['name']))
if(isset ($_REQUEST['email']))
$_REQUEST['email']= strip_tags($_REQUEST['email']);
if(isset ($_REQUEST['id']) && preg_match('/[^0-9A-Za-z]/',$_REQUEST['id']))
if(isset ($_REQUEST['parentid']) && !is_numeric($_REQUEST['parentid']))
if(isset ($_REQUEST['parentparentid']) && !is_numeric($_REQUEST['parentparentid']))
if(isset ($_REQUEST['debut']) && !is_numeric($_REQUEST['debut']))
if($passed == false) die('no way!');
|