linea21-utils
[ class tree: linea21-utils ] [ index: linea21-utils ] [ all elements ]

Source for file lib_common.php

Documentation is available at lib_common.php

  1. <?php
  2. /**
  3.  * @package linea21.utils
  4.  * @subpackage lib
  5.  * @author linea21 <info@linea21.com>
  6.  * @version $id SVN
  7.  * @access public
  8.  * @license http://opensource.org/licenses/gpl-3.0.html
  9.  */
  10.  
  11.  
  12. /**
  13.  * implode_with_keys()
  14.  * implode avec clefs associées renvoyées
  15.  * sous forme de chaîne de caractères
  16.  * @param string $glue 
  17.  * @param string $array 
  18.  * @return string 
  19.  */
  20. function implode_with_keys($glue$array{
  21.     $output array();
  22.     foreach$array as $key => $item )
  23.         $output[$key "=" $item;
  24.  
  25.     return implode($glue$output);
  26. }
  27.  
  28. /**
  29.  * getHttpParameters()
  30.  * Renvoie les paramètres HTTP
  31.  * sous forme de chaîne de caractères
  32.  * @return string 
  33.  */
  34. function getHttpParameters($prefix '?'{
  35.  
  36.     return $prefix. (string) implode_with_keys('&'$_REQUEST);
  37. }
  38.  
  39. /**
  40.  * is_module()
  41.  * Test if the current page matches the given module and action (optionnal)
  42.  * examples :  (1) is_module('system'), (2) is_module('system/edit_files')
  43.  * interpreted as : (1) rub=system, (2) rub=system and todo=edit_files
  44.  * @param string $str 
  45.  * @return boolean 
  46.  */
  47. // @todo simo
  48. function is_module($str{
  49.     
  50.     $a explode('/'$str);
  51.     
  52.     _debug('is_module() values : ' .join(', '$a)' 'count($a));
  53.     
  54.     // handle simple case :  is_module('system')
  55.     if(!isset($_REQUEST['rub']|| strpos($a[0]$_REQUEST['rub']=== falsereturn false;
  56.     
  57.     // handle strict case : is_module('system$') $ - return false is $todo is set
  58.     if(strpos($a[0]'$'!== false && isset($_REQUEST['todo'])) return false;
  59.     
  60.     // handle case is_module('system/list')
  61.     if(isset($a[1]&& !empty($a[1])) {
  62.         if(!isset($_REQUEST['todo']|| $_REQUEST['todo'!= $a[1]return false;
  63.     }
  64.     
  65.     return true;
  66. }
  67.  
  68. /**
  69.  * strip_input()
  70.  * Remove PHP and HTML code
  71.  * @param string $str 
  72.  * @param string $exceptions 
  73.  * @return string 
  74.  */
  75. function strip_input($str$exceptions false{
  76.  
  77.     if(defined('RICH_TEXT_EDITOR'&& RICH_TEXT_EDITOR != (string) 0{
  78.         return $str;
  79.     }
  80.     else {
  81.         if(is_string($exceptions))  {
  82.             return strip_tags($str$exceptions);
  83.         }
  84.         if($exceptions === true)  {
  85.             return strip_tags($strALLOWABLE_TAGS);
  86.         }
  87.         return strip_tags($str);
  88.     }
  89.  
  90. }
  91.  
  92. /**
  93.  * IncludeTimeline()
  94.  * Include SIMILE Timeline JS code
  95.  * if needed
  96.  * @return void 
  97.  */
  98. function IncludeTimeline({
  99.     if(defined('TIMELINE_DISPLAY'&& TIMELINE_DISPLAY == 1{
  100.         if(is_module('project/list'|| is_module('project$')) {
  101.             echo '<script src="' .SITE_ROOT_URL'lib/js/timeline/timeline_ajax/simile-ajax-api.js" type="text/javascript"></script>'.END_LINE;
  102.             echo '<script type="text/javascript">
  103.             Timeline_urlPrefix=\'' .SITE_ROOT_URL'lib/js/timeline/timeline_js/\';
  104.             Timeline_parameters=\'bundle=true\';
  105.             $(function() {
  106.             $("#content").prepend(\'<div id="my-timeline" style="height: 250px; border-bottom: 1px solid #aaa"><\/div>\');
  107.         });
  108.             
  109.         </script>';
  110.             echo '<script src="' .SITE_ROOT_URL'lib/js/timeline/timeline_js/timeline-api.js" type="text/javascript"></script>'.END_LINE;
  111.             echo '<script type="text/javascript" src="../lib/js/timeline.js"></script>'END_LINE;
  112.         }
  113.     }
  114. }
  115.  
  116. /**
  117.  * IncludeLightRte()
  118.  * Include nicEdit as light RTE
  119.  * param : array $a
  120.  * @return void 
  121.  */
  122. function IncludeLightRte($a{
  123.  
  124.     echo "<script type=\"text/javascript\">
  125.                     var nicEditorLang = '".U_L."';
  126.                 </script>".END_LINE;
  127.     echo '<script type="text/javascript" src="../lib/js/nicEdit/lang.js"></script>'.END_LINE;
  128.     echo '<script type="text/javascript" src="../lib/js/nicEdit/nicEdit.min.js"></script>'.END_LINE;
  129.     echo "<script type=\"text/javascript\">
  130.                     bkLib.onDomLoaded(function() {
  131.                     new nicEditor({iconsPath : '../lib/js/nicEdit/nicEditorIcons.gif', buttonList : ['bold','italic','underline','subscript','superscript', 'link','unlink','image','upload']}).panelInstance('".$a['id']."');
  132.                 });
  133.                 </script>".END_LINE;
  134. }
  135.  
  136. /**
  137.  * IncludePHPDebug()
  138.  * Include Js & css for PHP_DEBUG
  139.  * @return void 
  140.  */
  141. function IncludePHPDebug({
  142.     if(defined('MOD_DEBUG'&& MOD_DEBUG == true{
  143.         echo '<script type="text/javascript" src="../lib/vendor/PHP_Debug/js/html_div.js"></script>'.END_LINE;
  144.         echo '<link type="text/css" rel="stylesheet" href="../lib/vendor/PHP_Debug/css/html_div.css" />'.END_LINE;
  145.     }
  146. }
  147. /**
  148.  * IncludeTooltipJs()
  149.  * Include jQuery tooltip plugin
  150.  * @param string $selector 
  151.  * @return void 
  152.  */
  153. function IncludeTooltipJs($selector{
  154.     $str='';
  155.     if(is_string($selector)) {
  156.         $str .= '$("'.$selector.'").tooltip({ effect: "slide", opacity: 0.8});';
  157.     else {
  158.         foreach($selector as $sel{
  159.             $str .= '$("'.$sel.'").tooltip({ effect: "slide", opacity: 0.8});'.END_LINE;
  160.         }
  161.     }
  162.     echo '<script type="text/javascript" src="../lib/js/jquery.tools.min.js"></script>'.END_LINE;
  163.     echo '<script type="text/javascript">
  164.     $(document).ready(function() {
  165.     '.$str.'
  166. })
  167. </script>'.END_LINE;
  168. }
  169.  
  170. /**
  171.  * extRegex()
  172.  * Transform a list given in the form "jpg,png,gif"
  173.  * into "(jpg)|(png)|(gif)" format
  174.  * @return string 
  175.  */
  176. function extRegex($list{
  177.     $a explode(','$list);
  178.     $b array();
  179.     foreach($a as $el{
  180.         array_push($b'('.$el.')');
  181.     }
  182.     return implode('|'$b);
  183. }
  184.  
  185. /**
  186.  * IncludeFancyUploadJs()
  187.  * Include jQuery Fancy Upload
  188.  * @return void 
  189.  */
  190. function IncludeFancyUploadJs({
  191.     
  192.     _debug('DEPRECATED method : IncludeFancyUploadJs() will be remove in next Linea21 version. Please remove call from template.');
  193.  
  194. }
  195.  
  196. /**
  197.  * dragTableSettings()
  198.  * Include jQuery DragTable plugin settings
  199.  * @return void 
  200.  */
  201. function dragTableSettings({
  202.  
  203.     $rub = isset($_REQUEST['rub']$_REQUEST['rub''';
  204.  
  205.     echo '<script type="text/javascript">
  206.                     $(document).ready(function(){
  207.                     $("table.sortable thead tr").prepend("<td>&nbsp;<\/td>");
  208.                     $("table.sortable tfoot tr").prepend("<td>&nbsp;<\/td>");
  209.                     $("table.sortable tbody tr").prepend("<td class=\"dragHandle\">&nbsp;<\/td>");
  210.                     $("table.sortable").tableDnD({
  211.                     onDrop: function(table, row) {
  212.                     $.get("../admin/_ajax_sort.php?rub='.$rub.'&" + $.tableDnD.serialize(), function(data) {
  213.                     // replacing data.class by data["class"] for IE8 bug fix
  214.                     if(data["class"] == "succeed") {
  215.                     humane.success = humane.spawn({ addnCls: "humane-jackedup-success"});
  216.                     humane.success(data.msg);
  217.                 } else {
  218.                     humane.error = humane.spawn({ addnCls: "humane-jackedup-error"});
  219.                     humane.error(data.msg);
  220.                 }
  221.                 },
  222.                 "json")
  223.                 },
  224.                 dragHandle: "dragHandle"
  225.                 });
  226.                 });
  227.                 </script>'.END_LINE;
  228. }
  229.  
  230. /**
  231.  * IncludeTreeJs()
  232.  * Include jQuery tree plugin
  233.  * @return void 
  234.  */
  235. function IncludeTreeJs({
  236.     $str '<ul id="cMenu" class="contextMenu"><li class="edit"><a href="#edit"><i class="icon-pencil"><\/i> '_t('divers','modify').'<\/a><\/li><li class="delete separator"><a href="#delete"><i class="icon-trash"><\/i>  '_t('divers','delete').'<\/a><\/li><\/ul>';
  237.     echo '<script type="text/javascript" src="../lib/js/jquery.contextMenu/jquery.contextMenu.js"></script>'.END_LINE;
  238.     echo '<link type="text/css" rel="stylesheet" href="../lib/js/jquery.contextMenu/jquery.contextMenu-l21.css" media="screen" />'.END_LINE;
  239.     echo '<script type="text/javascript" src="../lib/js/jquery.treeview/jquery.treeview.js"></script>'.END_LINE;
  240.     echo '<link type="text/css" rel="stylesheet" href="../lib/js/jquery.treeview/jquery.treeview.css" media="screen" />'.END_LINE;
  241.     echo '<script type="text/javascript">
  242.                     $(document).ready(function(){
  243.                     $("#tree").after(\''.$str.'\');
  244.                     $("#tree").treeview({
  245.                     animated: "fast",
  246.                     collapsed: false,
  247.                     unique: false
  248.                 });
  249.                 
  250.                 $("#tree ul li.contextual-menu").contextMenu({
  251.                 menu: "cMenu"
  252.                 }, function(action, el, pos) {
  253.                 if(action=="edit") {
  254.                 if(typeof $(el).children("a.ico_mod").attr("href") == "undefined") {
  255.                 // not used anymore bu we keep it in case of
  256.                     humane.error = humane.spawn({ addnCls: "humane-jackedup-error"});
  257.                     humane.error("'._t('msg''action_not_allowed').'");
  258.                     return 0;
  259.                 } else {
  260.                     document.location.href = $(el).children("a.ico_mod").attr("href");
  261.                 }
  262.                 }
  263.                 if(action=="delete") {
  264.                 if(typeof $(el).children("a.ico_sup").attr("href") == "undefined") {
  265.                 // used for level - which does not have delete action
  266.                     humane.error = humane.spawn({ addnCls: "humane-jackedup-error"});
  267.                     humane.error("'._t('msg''action_not_allowed').'");
  268.                 return 0;
  269.                 } else {
  270.                 document.location.href = $(el).children("a.ico_sup").attr("href");
  271.                 }
  272.                 }
  273.                 
  274.                 });
  275.                 $("#tree li a.ico_mod, #tree li a.ico_sup").css("display", "none");
  276.                 
  277.                 });
  278.                 </script>'.END_LINE;
  279. }
  280.  
  281. function includeCodeEditor({
  282.     
  283.     // we exit function if not enabled
  284.     if(!defined('EDITOR_HIGHLIGHT_CODE'|| EDITOR_HIGHLIGHT_CODE == )  return true;
  285.     
  286.     // we exit function if not the concerned module
  287.     if(!is_module('system/edit_files')) return true;
  288.     
  289.     if(isset($_REQUEST['file'])) {
  290.         $ext pathinfo($_REQUEST['file']PATHINFO_EXTENSION);
  291.     else {
  292.         $ext 'php';
  293.     }
  294.     
  295.     $header '';
  296.     
  297.     $header .=  '<link type="text/css" rel="stylesheet" href="'.override('../lib/js/CodeMirror/lib/codemirror.css'THEME_ADMIN_PATH).'" />'.END_LINE;
  298.     $header .=  '<script type="text/javascript" src="'.override('../lib/js/CodeMirror/lib/codemirror.js'THEME_ADMIN_PATH).'"></script>'.END_LINE;
  299.     $header .=  '<script type="text/javascript" src="'.override('../lib/js/codeMirror-fullscreen.js'THEME_ADMIN_PATH).'"></script>'.END_LINE;
  300.     $header .=  '<script type="text/javascript" src="'.override('../lib/js/CodeMirror/addon/selection/active-line.js'THEME_ADMIN_PATH).'"></script>'.END_LINE;
  301.     
  302.     if($ext == 'css'{
  303.         $header .=  '<script type="text/javascript" src="'.override('../lib/js/CodeMirror/mode/css/css.js'THEME_ADMIN_PATH).'"></script>'.END_LINE;
  304.         
  305.         $code 'var editor = CodeMirror.fromTextArea(document.getElementById("file_content"), {
  306.                             styleActiveLine: true,
  307.                             viewportMargin: Infinity,
  308.                             lineNumbers: true,
  309.                             extraKeys: {
  310.                         "F11": function(cm) {
  311.                           setFullScreen(cm, !isFullScreen(cm));
  312.                         },
  313.                         "Esc": function(cm) {
  314.                           if (isFullScreen(cm)) setFullScreen(cm, false);
  315.                         }
  316.                       }
  317.                         });';
  318.         
  319.         footerAddInlineJS($code);
  320.     }
  321.     
  322.     if($ext == 'php'{
  323.         $header .=  '<script type="text/javascript" src="'.override('../lib/js/CodeMirror/addon/edit/matchbrackets.js'THEME_ADMIN_PATH).'"></script>'.END_LINE;
  324.         $header .=  '<script type="text/javascript" src="'.override('../lib/js/CodeMirror/mode/htmlmixed/htmlmixed.js'THEME_ADMIN_PATH).'"></script>'.END_LINE;
  325.         $header .=  '<script type="text/javascript" src="'.override('../lib/js/CodeMirror/mode/xml/xml.js'THEME_ADMIN_PATH).'"></script>'.END_LINE;
  326.         $header .=  '<script type="text/javascript" src="'.override('../lib/js/CodeMirror/mode/javascript/javascript.js'THEME_ADMIN_PATH).'"></script>'.END_LINE;
  327.         $header .=  '<script type="text/javascript" src="'.override('../lib/js/CodeMirror/mode/css/css.js'THEME_ADMIN_PATH).'"></script>'.END_LINE;
  328.         $header .=  '<script type="text/javascript" src="'.override('../lib/js/CodeMirror/mode/clike/clike.js'THEME_ADMIN_PATH).'"></script>'.END_LINE;
  329.         $header .=  '<script type="text/javascript" src="'.override('../lib/js/CodeMirror/mode/php/php.js'THEME_ADMIN_PATH).'"></script>'.END_LINE;
  330.         
  331.         $code 'var editor = CodeMirror.fromTextArea(document.getElementById("file_content"), {
  332.                             styleActiveLine: true,
  333.                     lineNumbers: true,
  334.                     matchBrackets: true,
  335.                     mode: "application/x-httpd-php",
  336.                     indentUnit: 4,
  337.                     indentWithTabs: true,
  338.                     enterMode: "keep",
  339.                     viewportMargin: Infinity,
  340.                     tabMode: "shift",
  341.                     extraKeys: {
  342.                         "F11": function(cm) {
  343.                           setFullScreen(cm, !isFullScreen(cm));
  344.                         },
  345.                         "Esc": function(cm) {
  346.                           if (isFullScreen(cm)) setFullScreen(cm, false);
  347.                         }
  348.                       }
  349.                   });';
  350.         
  351.         footerAddInlineJS($code);
  352.     }
  353.     
  354.     echo $header;
  355.     
  356. }
  357.  
  358. function IncludeRichTextEditor({
  359.  
  360.     if(defined('RICH_TEXT_EDITOR'&& RICH_TEXT_EDITOR != (string) )  {
  361.         if(strtolower(RICH_TEXT_EDITOR== 'tinymce')
  362.         {
  363.  
  364.             if(CURRENT_APP == 'admin'{
  365.                 if(isset($_REQUEST['rub']&& $_REQUEST['rub'== 'newsletter' && file_exists(THEME_PUBLIC_PATH'css/newsletter.css')) {
  366.                     // Loads CSS files into the current document
  367.                     echo '<script type="text/javascript">
  368.                     newslettercsspath = "'THEME_PUBLIC_PATH 'css/newsletter.css";
  369.                     </script>';
  370.                 }
  371.             }
  372.             
  373.             echo '<script type="text/javascript" src="'.override('../lib/js/tinymce/js/tinymce/tinymce.min.js'THEME_ADMIN_PATH).'"></script>'.END_LINE;
  374.             echo '<script type="text/javascript" src="'.override('../lib/js/tinymce/js/tinymce/config.js'THEME_ADMIN_PATH).'"></script>'.END_LINE;
  375.         }
  376.         
  377.         if(strtolower(RICH_TEXT_EDITOR== 'cke')
  378.         {
  379.             
  380.             include('../lib/js/ckeditor/ckeditor.php');
  381.             $CKEditor new CKEditor();
  382.             $CKEditor->basePath SITE_ROOT_URL.'lib/js/ckeditor/';
  383.             $CKEditor->config['customConfig''l21_config.js';
  384.  
  385.             if(CURRENT_APP == 'admin'{
  386.                 if(isset($_REQUEST['rub']&& $_REQUEST['rub'== 'newsletter' && file_exists(THEME_PUBLIC_PATH'css/newsletter.css')) {
  387.                     $CKEditor->config['contentsCss'THEME_PUBLIC_PATH'css/newsletter.css';
  388.                 }
  389.             }
  390.  
  391.             if(defined('CKFINDER_ENABLED'&& CKFINDER_ENABLED == true{
  392.                 require_once '../lib/vendor/ckfinder/ckfinder.php';
  393.                 CKFinder::SetupCKEditor$CKEditor'../lib/vendor/ckfinder/' ;
  394.             else {
  395.                 $CKEditor->config['filebrowserBrowseUrl''../library/access.php';
  396.                 $CKEditor->config['filebrowserImageBrowseUrl''../library/access.php?type=images';
  397.                 $CKEditor->config['filebrowserWindowWidth''80%';
  398.                 $CKEditor->config['filebrowserWindowHeight''80%';
  399.             }
  400.  
  401.             $CKEditor->replaceAll('largetextfield');
  402.                 
  403.         }
  404.     }
  405.  
  406. }
  407.  
  408.  
  409. /**
  410.  * IncludeColorboxJs()
  411.  * Include Colorbox jQuery plugin
  412.  * @param string £selector
  413.  * @return void 
  414.  */
  415. function IncludeColorboxJs($selector{
  416.     $str='';
  417.     if(is_string($selector)) {
  418.         $str .= '$("'.$selector.'").not(".dlfile").colorbox({transition:"fade"});'.END_LINE;
  419.     else {
  420.         foreach($selector as $sel{
  421.             $str .= '$("'.$sel.'").not(".dlfile").colorbox({transition:"fade"});'.END_LINE;
  422.         }
  423.     }
  424.     echo '<script type="text/javascript" src="../lib/js/colorbox/jquery.colorbox-min.js"></script>'.END_LINE;
  425.     echo '<link type="text/css" rel="stylesheet" href="../lib/js/colorbox/colorbox.css" />'.END_LINE;
  426.     echo '<script type="text/javascript">
  427.                 $(document).ready(function() {
  428.                 '.$str.'
  429.             });
  430. </script>'END_LINE;
  431.  
  432. }
  433.  
  434. /**
  435.  * IncludeMappingLibraryJs()
  436.  * Include the current mapping library
  437.  * if needed
  438.  * @todo not used - Gmaps is used instead
  439.  * @return void 
  440.  */
  441.  
  442.     // @todo remove from here and insert into /config/define.php if used
  443.     $GLOBALS['mapping_includes'array('directory-detail|');
  444.     //
  445.  
  446.     $rub = isset($_REQUEST['rub']$_REQUEST['rub''';
  447.     $todo = isset($_REQUEST['todo']$_REQUEST['todo''';
  448.  
  449.     if(ActiveItemKey($rub)) $rub ActiveItemKey($rub);
  450.     $s $rub '|' $todo;
  451.     $a $GLOBALS['mapping_includes'];
  452.  
  453.     if(in_array($s$a)) {
  454.         echo '<script type="text/javascript" src="../lib/vendor/leaflet/dist/leaflet.js" /></script>'.END_LINE;
  455.         echo '<link rel="stylesheet" type="text/css" href="../lib/vendor/leaflet/dist/leaflet.css" />'.END_LINE;
  456.         echo '<!--[if lte IE 8]><link rel="stylesheet" href="../lib/vendor/leaflet/dist/leaflet.ie.css" /><![endif]-->'.END_LINE;
  457.     }
  458. }
  459.  
  460. /**
  461.  * SureCreateDir()
  462.  * Créer un dossier s'il n'existe pas.
  463.  * @param string $pathname 
  464.  * @param integer $perms 
  465.  * @return integer $ver_num
  466.  */
  467. function SureCreateDir($pathname$perms{
  468.     if(!file_exists($pathname)) {
  469.         return mkdir ($pathname$permstrue);
  470.     else {
  471.         return true;
  472.     }
  473. }
  474.  
  475.  
  476. /**
  477.  * SureRemoveDir()
  478.  * Supprime le contenu d'un dossier et le dossier lui-même si précisé.
  479.  *
  480.  * @return integer $ver_num
  481.  */
  482. function SureRemoveDir($dir$DeleteMe{
  483.     if(!$dh @opendir($dir)) return;
  484.     while (($obj readdir($dh))) {
  485.         if($obj=='.' || $obj=='..'continue;
  486.         if (!@unlink($dir.'/'.$obj)) SureRemoveDir($dir.'/'.$objtrue);
  487.     }
  488.     if ($DeleteMe){
  489.         closedir($dh);
  490.         @rmdir($dir);
  491.     }
  492. }
  493.  
  494. /**
  495.  * num_phpversion()
  496.  * Retourne un entier comme numéro de version PHP
  497.  *
  498.  * @return integer $ver_num
  499.  */
  500. function num_phpversion({
  501.     $ver explode'.'phpversion() );
  502.     $ver_num $ver[0$ver[1$ver[2];
  503.  
  504.     return $ver_num;
  505. }
  506.  
  507. /** mb_ucfirst()
  508.  * UTF-8 ucfirst function
  509.  * @param string $string 
  510.  * @param string $encoding 
  511.  * @return string 
  512.  */
  513. function mb_ucfirst($string$encoding CHARSET)
  514. {
  515.     if(function_exists('mb_strlen')) {
  516.         $strlen mb_strlen($string$encoding);
  517.         $firstChar mb_substr($string01$encoding);
  518.         $then mb_substr($string1$strlen 1$encoding);
  519.         return mb_strtoupper($firstChar$encoding$then;
  520.     else {
  521.         _debug('mb_string module not loaded');
  522.         return ucfirst($string);
  523.     }
  524. }
  525.  
  526. /**
  527.  * cutText()
  528.  * Découpe un texte à une longeur donnée.
  529.  *
  530.  * @param string $content 
  531.  * @param integer $length 
  532.  * @param integer $abbr 
  533.  * @param string $end 
  534.  * @return 
  535.  */
  536. function cutText($content$length$abbr 0$end '...')
  537. {
  538.     // fix bug #16
  539.     if(function_exists('mb_substr')) $substr mb_substr($content0$lengthCHARSET);
  540.     else  $substr substr($content0$length);
  541.     if (strlen($content$length{
  542.         if ($abbr == 1$content_light "<abbr title=\"" $content "\">" $substr $end "</abbr>\n";
  543.         else $content_light $substr $end;
  544.     else $content_light $content;
  545.     return $content_light;
  546. }
  547.  
  548. /**
  549.  * error_redirect()
  550.  * Redirect to error page
  551.  */
  552. function error_redirect($file ='error.php'{
  553.  
  554.     header("Location: " CURRENT_APP_URL $file);
  555.   exit();
  556. }
  557.  
  558. /**
  559.  * cutBody()
  560.  * Renvoie un texte en 2 parties dans un tableau
  561.  *
  562.  * @param string $text 
  563.  * @return array $body
  564.  */
  565. function cutBody($text)
  566. {
  567.     $middle (strlen($text2);
  568.     $end strlen($text);
  569.     $body[0substr($text0$middle);
  570.     $body[1substr($text$middle$end);
  571.     $chaine preg_split("/(\.(<br \/>| ))/"$body[1]2);
  572.  
  573.     $body[0.= $chaine[0".";
  574.     $body[1@trim($chaine[1]);
  575.  
  576.     return $body;
  577. }
  578.  
  579. /**
  580.  * removeEmptyP()
  581.  * Remove empty P tags
  582.  *
  583.  * @param string $text 
  584.  * @return array $body
  585.  */
  586. function removeEmptyP($str{
  587.     $str preg_replace('#<p[^>]*>(\s|&nbsp;?)*</p>#'''$str);
  588.  
  589.     return $str;
  590. }
  591.  
  592. /**
  593.  * formatNavTitle()
  594.  * Formatage des titres ( interface admin )
  595.  *
  596.  * @param string $content 
  597.  * @return string $content
  598.  */
  599. function formatNavTitle($content)
  600. {
  601.     $content formatText($content'2HTML');
  602.     $content cutText($content701);
  603.  
  604.     return $content;
  605. }
  606.  
  607. /**
  608.  * formatTextli()
  609.  * Formatage des listes ( interface admin )
  610.  *
  611.  * @param string $content 
  612.  * @return string $content
  613.  */
  614. function formatTextli($content)
  615. {
  616.     $content formatText($content'2HTML');
  617.     $content cutText($content651);
  618.     return $content;
  619. }
  620.  
  621. /**
  622.  * formatTitleh2()
  623.  * Formatage des titres h2 ( interface admin )
  624.  *
  625.  * @param string $content 
  626.  * @return string $content
  627.  */
  628. function formatTitleh2($content)
  629. {
  630.     $content formatText($content'2HTML');
  631.     return $content;
  632. }
  633.  
  634. /**
  635.  * isRawText()
  636.  * check if raw text or html text
  637.  *
  638.  * @param string $t 
  639.  * @return bool 
  640.  */
  641. function isRawText($t{
  642.     if(preg_match('/<[a-z0-9]>/i'$t== 0{
  643.         return true;
  644.     else {
  645.         return false;
  646.     }
  647. }
  648.  
  649. /**
  650.  * formatText()
  651.  * Formatage de texte pour affichage
  652.  *
  653.  * @param  $content 
  654.  * @param string $format 
  655.  * @return string $content
  656.  */
  657. function formatText($content$format = -1)
  658. {
  659.     $content stripslashes(trim($content));
  660.     switch ($format{
  661.         case '2HTML':
  662.             if(RICH_TEXT_EDITOR === || isRawText($content)) $content nl2br($content);
  663.             break;
  664.         case '2FIELD':
  665.             $content htmlentities($contentENT_QUOTES'utf-8');
  666.             break;
  667.         case '2ATT':
  668.             $content htmlentities($contentENT_QUOTES'utf-8');
  669.             break;
  670.         case '2XML':
  671.             $content strip_tags(html_entity_decode ($content));
  672.             break;
  673.         case '2FILE':
  674.             //$content = addslashes(trim($content));
  675.             $content htmlspecialchars($contentENT_QUOTES'utf-8');
  676.             break;
  677.         default:
  678.     }
  679.     return $content;
  680. }
  681.  
  682. /**
  683.  * ReplaceInvalidChars()
  684.  * Remplacement des caractères invalides  par leurs entités HTML
  685.  *
  686.  * @param string $str 
  687.  * @return string $valid_string
  688.  */
  689. function ReplaceInvalidChars($str)
  690. {
  691.     $htmlentities_chars array('å' => '&#338;''ú' => '&#339;',
  692.             'ä' => '&#352;''ö' => '&#353;',
  693.             'ü' => '&#376;''à' => '&#710;',
  694.             'ò' => '&#732;''ñ' => '&#8211;',
  695.             'ó' => '&#8212;''ë' => '&#8216;',
  696.             'í' => '&#8217;''Ç' => '&#8218;',
  697.             'ì' => '&#8220;''î' => '&#8221;',
  698.             'Ñ' => '&#8222;''Ü' => '&#8224;',
  699.             'á' => '&#8225;''Ö' => '&#8230;',
  700.             'â' => '&#8240;''É' => '&#402;',
  701.             'ã' => '&#8249;''õ' => '&#8250;',
  702.             'Ä' => '&#8364;''ô' => '&#8482;',
  703.             'ï' => '&#8226;''ò' => '&#732;',
  704.             'ô' => '&#8482;');
  705.  
  706.     //$valid_string = str_replace(array_keys($htmlentities_chars), array_values($htmlentities_chars), $str);
  707.     //return $valid_string;
  708.     return $str;
  709. }
  710.  
  711. function stripAccents($string{
  712.  
  713.     $search explode(",","ç,æ,œ,á,é,í,ó,ú,à,è,ì,ò,ù,ä,ë,ï,ö,ü,ÿ,â,ê,î,ô,û,å,e,i,ø,u");
  714.     $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");
  715.  
  716.     return str_replace($search$replace$string);
  717.  
  718.  
  719. }
  720.  
  721. function stripText($text{
  722.  
  723.     $text strtolower($text);
  724.  
  725.     // strip all non word chars
  726.     $text preg_replace('/\W/'' '$text);
  727.     // replace all white space sections with a dash
  728.     $text preg_replace('/\ +/''-'$text);
  729.     // trim dashes
  730.     $text preg_replace('/\-$/'''$text);
  731.     $text preg_replace('/^\-/'''$text);
  732.  
  733.     return $text;
  734. }
  735.  
  736. /**
  737.  * toStringSqlDate()
  738.  * Renvoie la date au format SQL
  739.  *
  740.  * @param string $format 
  741.  * @return string $s
  742.  */
  743. function toStringSqlDate($format 'short')
  744. {
  745.     $date_format =   array(
  746.             'dd-mm-yyyy' => array(
  747.                     'mysql' => array('short'=> '%d-%m-%Y''long'=>
  748.                             array('12' => '%d-%m-%Y  %r''24' => '%d-%m-%Y  %T')),
  749.                     'pgsql' => array('short'=> 'DD-MM-YYYY''long'=>
  750.                             array('12' => 'DD-MM-YYYY HH12:MI:SS''24' => 'DD-MM-YYYY HH24:MI:SS'))),
  751.             'yyyy-mm-dd' => array(
  752.                     'mysql' => array('short'=> '%Y-%m-%d''long'=>
  753.                             array('12' => '%Y-%m-%d  %r''24' => '%Y-%m-%d  %T')),
  754.                     'pgsql' => array('short'=> 'YYYY-MM-DD''long'=>
  755.                             array('12' => 'YYYY-MM-DD HH12:MI:SS''24' => 'YYYY-MM-DD HH24:MI:SS'))),
  756.  
  757.     );
  758.  
  759.     if($format == 'long'$s $date_format[DATE_FORMAT][SQL][$format][TIME_FORMAT];
  760.     else $s $date_format[DATE_FORMAT][SQL][$format];
  761.  
  762.     return $s;
  763. }
  764.  
  765.  
  766. /**
  767.  * date_compare()
  768.  * Compare 2 dates with a given operator.
  769.  * @param  $date1 
  770.  * @param  $date2 
  771.  * @param  $op 
  772.  * @return boolean 
  773.  */
  774. function date_compare($date1$date2$op{
  775.  
  776.     $date1strtotime(formatDate($date1true));
  777.     $date2strtotime(formatDate($date2true));
  778.  
  779.     switch($op{
  780.         case '>':
  781.             if($date1 $date2return true;
  782.             else return false;
  783.             break;
  784.         case '<':
  785.             if($date1 $date2return true;
  786.             else return false;
  787.         case '>=':
  788.             if($date1 >= $date2return true;
  789.             else return false;
  790.             break;
  791.         case '<=':
  792.             if($date1 <= $date2return true;
  793.             else return false;
  794.         case '==':
  795.             if($date1 == $date2return true;
  796.             else return false;
  797.         default:
  798.             return false;
  799.     }
  800. }
  801.  
  802. /**
  803.  * ln10filename()
  804.  * Build a localized filename
  805.  * according to the current language
  806.  *
  807.  * @param string $file 
  808.  * @return string 
  809.  */
  810. function ln10filename($file)
  811. {
  812.  
  813.     $tmp=@explode("."$file);
  814.     $total count($tmp1;
  815.     $ext $tmp[$total];
  816.     unset($tmp[$total]);
  817.  
  818.     return @implode("."$tmp)'.' U_L'.' .$ext;
  819. }
  820.  
  821.  
  822. /**
  823.  * distInclude()
  824.  * Include the required file
  825.  * if no user file is found,
  826.  * includes the dist/ version file.
  827.  * Localized files have the priority
  828.  *
  829.  * @param string $file 
  830.  * @return void 
  831.  */
  832. function distInclude($file$default_dist)
  833. {
  834.     $l10n_file ln10filename($file);
  835.     $l10n_file_dist =  dirname($l10n_file).'/dist/'.basename($l10n_file);
  836.  
  837.     $file_dist_default =  $default_dist.'dist/'.basename($file);
  838.     $l10n_file_dist_default $default_dist.'dist/'.basename($l10n_file);
  839.  
  840.     if(file_exists($l10n_file)) {
  841.         _debug('distInclude() file Inclusion : '.$l10n_file);
  842.         include_once($l10n_file);
  843.  
  844.     elseif(file_exists($l10n_file_dist))  {
  845.         _debug('distInclude() file Inclusion : '.$l10n_file_dist);
  846.         include_once($l10n_file_dist);
  847.     }
  848.     elseif(file_exists($file)) {
  849.         _debug('distInclude() file Inclusion : '.$file);
  850.         include_once($file);
  851.     }
  852.     elseif(file_exists($l10n_file_dist_default)) {
  853.         _debug('distInclude() file Inclusion : '.$l10n_file_dist_default);
  854.         include_once($l10n_file_dist_default);
  855.     }
  856.     elseif(file_exists($file_dist_default)) {
  857.         _debug('distInclude() file Inclusion : '.$file_dist_default);
  858.         include_once($file_dist_default);
  859.     }
  860.     else {
  861.         _debug('distInclude() file Inclusion : '.dirname($file).'/dist/'.basename($file));
  862.         include_once(dirname($file).'/dist/'.basename($file));
  863.     }
  864.  
  865. }
  866.  
  867. /**
  868.  * getOverridePluginsFiles()
  869.  * return an array of paths
  870.  * corresponding to the given filename
  871.  * and matching the array of given plugins
  872.  *
  873.  * @param array $a 
  874.  * @param string $filename 
  875.  * @return array 
  876.  */
  877. function getOverridePluginsFiles($a$filename{
  878.  
  879.     $o array();
  880.     if(count($a== 0return $o;
  881.  
  882.     foreach ($a as &$v{
  883.         $path '../plugins/'.$v.'/override/'.str_replace('../'''$filename);
  884.  
  885.         if(is_file($path&& file_exists($path)) {
  886.             array_push($o$path);
  887.         }
  888.     }
  889.     return $o;
  890.  
  891. }
  892.  
  893. /**
  894.  * override()
  895.  * check if ovveride version exists for the whole app
  896.  * then if a template file version exists or not
  897.  * finally, if no user file is found in theme,
  898.  * return the default module version file.
  899.  *
  900.  * @param string $file 
  901.  * @param string $path 
  902.  * @return string 
  903.  */
  904. function override($file$path null$default true)
  905. {
  906.     // we first check if file is handled by a plugin
  907.     $paths getOverridePluginsFiles(enabledPlugins()$file);
  908.     
  909.     if(count($paths0{
  910.         if(count($paths&& is_file($file)) {
  911.             _debug('[plugins override] possible conflicts : '.count($paths)' occurences of the same file. Loaded from '$paths[0]);
  912.         }
  913.         _debug('[plugins override] : '.$paths[0]);
  914.         return $paths[0];
  915.     }
  916.  
  917.     // if not, we check if file exists in OVERRIDE_FOLDER
  918.     $filename OVERRIDE_FOLDER.str_replace('../'''$file);
  919.     if(file_exists($filename)) {
  920.         _debug('[general override] : '.$filename);
  921.         return $filename;
  922.  
  923.     }
  924.  
  925.     // if not again we are checking into themes folders
  926.     if(is_null($path)) {
  927.         $path THEME_PUBLIC_PATH;
  928.     }
  929.  
  930.     $theme_file $path.'override/'.str_replace('../'''$file);
  931.  
  932.     if(file_exists($theme_file)) {
  933.         _debug('[thematic override] : '.$theme_file);
  934.         return $theme_file;
  935.  
  936.         // finally we include the default one if asked
  937.     }
  938.     if($default{
  939.         _debug('[no override] : '.$file);
  940.         return $file;
  941.     }
  942.  
  943.     return true;
  944.  
  945. }
  946.  
  947.  
  948. /**
  949.  * formatDate()
  950.  * Renvoie la date aux formats yyyy-mm-dd ou dd-mm-yyyy suivant le cas de départ
  951.  * Si $db == true renvoie toujours la date au format yyyy-mm-dd
  952.  *
  953.  * @param string $date 
  954.  * @param boolean $db 
  955.  * @return string $new_date
  956.  */
  957. function formatDate($date$db false)
  958. {
  959.     @list($part1$part2$part3explode('-'$date);
  960.     if(strlen($part1== 2{
  961.         $new_date $part3 '-' $part2 '-' $part1;
  962.     else {
  963.         $new_date $part1 '-' $part2 '-' $part3;
  964.     }
  965.     if($db == true{
  966.         // always return yyyy-mm-dd format
  967.         if(strlen($part1== 2{
  968.             $new_date $part3 '-' $part2 '-' $part1;
  969.         else {
  970.             $new_date $part1 '-' $part2 '-' $part3;
  971.         }
  972.     }
  973.  
  974.     return $new_date;
  975. }
  976.  
  977.  
  978. /**
  979.  * date_rfc2822()
  980.  * Format date to RFC 2822 date format
  981.  * @param string $date 
  982.  * @return string (exemple : Thu, 21 Dec 2000 16:01:07 +0200)
  983.  */
  984. function date_rfc2822($date{
  985.     if(!isNullDate($date)) {
  986.         $tmp_date formatDate($datetrue);
  987.         @list($y$m$dexplode('-'$tmp_date);
  988.         return date("r"mktime(300$m$d$y));
  989.     else {
  990.         return false;
  991.     }
  992. }
  993.  
  994.  
  995. function isNullDate($date)
  996. {
  997.     if(substr($date010== '0001-01-01' || substr($date010== '01-01-0001'{
  998.         return true;
  999.     else return false;
  1000.  
  1001. }
  1002.  
  1003. /**
  1004.  * empty_nc()
  1005.  * retourne le contenu ou N.C
  1006.  *
  1007.  * @param string $content 
  1008.  * @return string $content
  1009.  */
  1010. function empty_nc($content)
  1011. {
  1012.     $content trim($content);
  1013.     if ($content=='' || isNullDate($content)) $content _t('divers','nc');
  1014.  
  1015.     return $content;
  1016. }
  1017.  
  1018. /**
  1019.  * empty_none()
  1020.  * retourne le contenu ou 'aucun'
  1021.  *
  1022.  * @param string $content 
  1023.  * @return string $content
  1024.  */
  1025. function empty_none($content)
  1026. {
  1027.     $content trim($content);
  1028.     if (empty($content)) $content _t('divers','none');
  1029.  
  1030.     return $content;
  1031. }
  1032.  
  1033. /**
  1034.  * empty_none()
  1035.  * retourne le contenu ou 0
  1036.  *
  1037.  * @param string $content 
  1038.  * @return string $content
  1039.  */
  1040. function empty_numeric($content)
  1041. {
  1042.     $content trim($content);
  1043.     if (empty($content)) $content 0;
  1044.  
  1045.     return $content;
  1046. }
  1047.  
  1048. /**
  1049.  * checkdate_validity()
  1050.  * Vérifie la validité d'une date
  1051.  *
  1052.  * @param string $date 
  1053.  * @param string $msg (optionnal)
  1054.  * @return boolean true or error message (string)
  1055.  */
  1056. function checkdate_validity($date$msg'')
  1057. {
  1058.  
  1059.     if(empty($date)) return _t('date','do_provide');
  1060.     
  1061.     $date=formatDate($datetrue);
  1062.     @list($year$month$dayexplode('-'$date);
  1063.  
  1064.     if(!preg_match('/^\d{4}-\d\d-\d\d$/'$date)) {
  1065.         $msg .= _t('date','not_valid');
  1066.         return $msg;
  1067.     }
  1068.  
  1069.     if (!@checkdate($month $day $year)) return $msg _t('date','date_do_not_exist');
  1070.     return true;
  1071. }
  1072.  
  1073. /**
  1074.  * sortItems()
  1075.  * Return an array with key and value
  1076.  * with ID as key and RANGE as value
  1077.  * @return array 
  1078.  */
  1079. function sortItems($rub$data{
  1080.  
  1081.     $a array();
  1082.  
  1083.     for($i=0$i<count($data)$i++{
  1084.         $v $data[$i];
  1085.         $a[$v]$i+1;
  1086.     }
  1087.  
  1088.     return $a;
  1089.  
  1090. }
  1091.  
  1092. /**
  1093.  * display_errors()
  1094.  * Affichage d'un message d'erreur utilisateur
  1095.  *
  1096.  * @param string $msg 
  1097.  * @return void (echo)
  1098.  */
  1099. function display_errors($msg)
  1100. {
  1101.     $display_it "<div class=\"error\">\n";
  1102.     $display_it .= $msg;
  1103.     $display_it .= "</div>\n";
  1104.     echo $display_it;
  1105. }
  1106.  
  1107. /**
  1108.  * system_error()
  1109.  * Affichage d'un message d'erreur syst�me
  1110.  *
  1111.  * @param string $msg 
  1112.  * @return void (echo)
  1113.  */
  1114. function system_error($msg ERROR_SYSTEM)
  1115. {
  1116.     $display_it "<div class=\"systemerror\">\n";
  1117.     $display_it .= $msg;
  1118.     $display_it .= "</div>\n";
  1119.     echo $display_it;
  1120.     exit;
  1121. }
  1122.  
  1123. /**
  1124.  * get_min_name()
  1125.  * obtenir le nom de la miniature d'un fichier
  1126.  *
  1127.  * @param string $path 
  1128.  * @return string $min_path
  1129.  * @todo can be removed later / still used in class.upload.php
  1130.  */
  1131. function get_min_name($path)
  1132. {
  1133.     $short_path dirname($path);
  1134.     $filename basename($path);
  1135.     $min_path $short_path "/min_" $filename;
  1136.     return $min_path;
  1137. }
  1138.  
  1139. /**
  1140.  * ExcedMaxSize()
  1141.  * Teste si une image dépasse ou non la taille autorisée (en pixels)
  1142.  *
  1143.  * @param string $path 
  1144.  * @param integer $width_max 
  1145.  * @return boolean 
  1146.  */
  1147. function ExcedMaxSize($path$width_max)
  1148. {
  1149.     list($width$height$type$attrgetimagesize($path);
  1150.     if ($width $width_max || $height $width_maxreturn true;
  1151.     else return false;
  1152. }
  1153.  
  1154. /**
  1155.  * cancel_button()
  1156.  * génére un bouton de retour
  1157.  *
  1158.  * @param  $back_uri 
  1159.  * @return string 
  1160.  */
  1161. function cancel_button($back_uri)
  1162. {
  1163.     return '<input name="annuler" type="button" value="' _t('btn','annul''" class="button" id="annuler" onclick="window.location=\'' $back_uri '\';" />';
  1164. }
  1165.  
  1166. /**
  1167.  * GetDisplayUserRight()
  1168.  * renvoie les droits d'un utilisateur
  1169.  *
  1170.  * @param string $indice 
  1171.  * @param string $module 
  1172.  * @return string 
  1173.  */
  1174. function GetDisplayUserRight($indice$module = -1)
  1175. {
  1176.     $indice strtoupper($indice);
  1177.     if ($indice == 'U'return _t('user','norights');
  1178.     if ($indice == 'A'return _t('user','adminrights');
  1179.     if ($indice == 'O' && $module == 'dashboard'return _t('user','managerrights');
  1180.     if ($indice == 'O' && $module == 'workshop'return _t('user','animatorrights');
  1181.     if ($indice == 'O' && ($module != 'workshop' && $module != 'dashboard')) return _t('user','redactorrights');
  1182. }
  1183.  
  1184. /**
  1185.  * Display_linkin_page()
  1186.  * @todo remove
  1187.  ***/
  1188. function Display_linkin_page($table_link$total$debut$pas SELECT_LIMIT{
  1189.     // kept for compatibility 
  1190.     _debug('Display_linkin_page() method is deprecated. Will be removed');
  1191. }
  1192.  
  1193. /**
  1194.  * get_linkin_page()
  1195.  *
  1196.  * @param array $table_link 
  1197.  * @param integer $total 
  1198.  * @param integer $debut 
  1199.  * @param integer $pas 
  1200.  * @return void 
  1201.  ***/
  1202. function get_linkin_page($table_link$total$debut$pas SELECT_LIMIT)
  1203. {
  1204.     $result ceil($total $pas);
  1205.     if ($result <= 1return '&nbsp;';
  1206.     else {
  1207.         $link '<div class="pagination">'.END_LINE;
  1208.         
  1209.         // Previous arrow pagination 
  1210.         if(($debut $pas>= 0{
  1211.         $array_pos array ('debut' => $debut $pas);
  1212.         $new_table_link array_merge ($table_link$array_pos);
  1213.         $link .= '<a href="'HrefMaker($new_table_link'">«</a>'.END_LINE;
  1214.         else {
  1215.             $link .= '« ';
  1216.         }
  1217.         $sep='';
  1218.         for($i 0$i $result$i++{
  1219.             $current_pos ($pas $i);
  1220.             if ($debut == $current_pos$link .= $sep."<span>" ($i 1"</span> \n";
  1221.             else {
  1222.                 $array_pos array ('debut' => $current_pos);
  1223.                 $new_table_link array_merge ($table_link$array_pos);
  1224.                 $link .= $sep.'<a href="'HrefMaker($new_table_link'">' ($i 1'</a>'.END_LINE;
  1225.             }
  1226.             // $sep=' | ';
  1227.         }
  1228.         // Next arrow pagination 
  1229.         if(($debut $pas$total{
  1230.             $array_pos array ('debut' => $debut $pas);
  1231.             $new_table_link array_merge ($table_link$array_pos);
  1232.             $link .= '<a href="'HrefMaker($new_table_link'">»</a>'.END_LINE;
  1233.         else {
  1234.             $link .= ' »';
  1235.         }
  1236.         $link .= '</div>'.END_LINE;
  1237.         
  1238.         return $link;
  1239.     }
  1240. }
  1241.  
  1242. /**
  1243.  * linkin_page()
  1244.  * création d'un navigateur de pages numérotées
  1245.  *
  1246.  * @param string $string_uri 
  1247.  * @param integer $total 
  1248.  * @param integer $debut 
  1249.  * @param integer $pas 
  1250.  * @return string $link
  1251.  */
  1252. function linkin_page($string_uri$total$debut$pas SELECT_LIMIT)
  1253. {
  1254.     $result ceil($total $pas);
  1255.     if ($result <= 1return '&nbsp;';
  1256.     else {
  1257.         if (strpos($string_uri'?'=== false$string_uri .= '?';
  1258.         else $string_uri .= '&amp;';
  1259.         $link '<div class="pagination">';
  1260.         
  1261.         // Previous arrow pagination
  1262.         if(($debut $pas>= 0{
  1263.             $pos $debut $pas;
  1264.             $link .= '<a href="'$string_uri 'debut=' $pos '">«</a>'.END_LINE;
  1265.         else {
  1266.             $link .= '« '.END_LINE;
  1267.         }
  1268.         
  1269.         for($i 0$i $result$i++{
  1270.             $current_pos ($pas $i);
  1271.             if ($debut == $current_pos$link .= "<span>" ($i 1"</span> \n";
  1272.             else $link .= "<a href=\"" $string_uri "debut=" $current_pos "\">" ($i 1"</a> \n";
  1273.         }
  1274.         
  1275.         // Next arrow pagination
  1276.         if(($debut $pas$total{
  1277.             $pos $debut $pas;
  1278.             $link .= '<a href="'$string_uri 'debut=' $pos '">»</a>'.END_LINE;
  1279.         else {
  1280.             $link .= ' »'.END_LINE;
  1281.         }
  1282.         
  1283.         $link .= '</div>';
  1284.         return $link;
  1285.     }
  1286. }
  1287.  
  1288. /**
  1289.  * display_statut()
  1290.  * renvoie le statut en pleines lettres
  1291.  *
  1292.  * @param string $statut 
  1293.  * @return string $result
  1294.  */
  1295. function display_statut($statut)
  1296. {
  1297.     switch ($statut{
  1298.         case 'P':
  1299.             $result _t('statut','public');
  1300.             break;
  1301.         case 'D':
  1302.             $result _t('statut','draft');
  1303.             break;
  1304.         case 'E':
  1305.             $result _t('statut','E');
  1306.             break;
  1307.         case 'AA':
  1308.             $result _t('statut','AA');
  1309.             break;
  1310.         case 'PA':
  1311.             $result _t('statut','PA');
  1312.             break;
  1313.         case 'C':
  1314.             $result _t('statut','C');
  1315.             break;
  1316.         case 'U':
  1317.             $result _t('statut','U');
  1318.             break;
  1319.         case 'O':
  1320.             $result _t('statut','O');
  1321.             break;
  1322.         case 'A':
  1323.             $result _t('statut','A');
  1324.             break;
  1325.         case 'W':
  1326.             $result _t('statut','W');
  1327.             break;
  1328.         default:
  1329.             $result _t('statut','public');
  1330.     }
  1331.     return mb_ucfirst($result);
  1332. }
  1333.  
  1334. function fnumber_format($number$dec$forceprefix true{
  1335.  
  1336.     $number str_replace(' '''$number);
  1337.  
  1338.     if(!is_numeric($number)) return '';
  1339.     
  1340.     // cast to integer
  1341.     $number = (int) $number;
  1342.     
  1343.     if(LANGUAGE == "fr"{
  1344.         $number number_format($number$dec','' ');
  1345.     else {
  1346.         $number number_format($number$dec'.'',');
  1347.     }
  1348.     
  1349.     // adding space to negative symbol - removed jquery.tablesorter does not sort if there is one space
  1350.     //$number = str_replace('-', '- ', $number);
  1351.     
  1352.     // adding '+' symbol if positive
  1353.     if(is_numeric($number[0]&& $forceprefix$number '+' $number;
  1354.  
  1355.     return $number;
  1356.     
  1357. }
  1358.  
  1359. /**
  1360.  * linkin_content()
  1361.  * Cherche les liens et emails dans du contenu -> linkage
  1362.  *
  1363.  * @param string $content 
  1364.  * @param string $option 
  1365.  * @return string $content
  1366.  */
  1367. function linkin_content($content$option 'ALL')
  1368. {
  1369.     if(defined('AUTO_LINK'&& AUTO_LINK == 1)
  1370.     {
  1371.         if(defined('RICH_TEXT_EDITOR'&& RICH_TEXT_EDITOR == (string) 0{
  1372.             if ($option == 'ALL' || $option == 'MAIL'{
  1373.                 $content eregi_replace("( |<br />)+([_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)+)"'\\1<a href="mailto:\\2">\\2</a>'$content);
  1374.             }
  1375.             if ($option == 'ALL' || $option == 'LINK'{
  1376.                 $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);
  1377.             }
  1378.         }
  1379.     }
  1380.  
  1381.     return $content;
  1382. }
  1383.  
  1384. /**
  1385.  * QuickBoxNow()
  1386.  * Génération de la quickbox
  1387.  *
  1388.  * @param string $module 
  1389.  * @param string $h1 
  1390.  * @param string $liste 
  1391.  * @param string $suffixclass 
  1392.  * @return string $quickbox
  1393.  */
  1394. function QuickBoxNow($module$h1$liste$suffixclass '')
  1395. {
  1396.     $quickbox "<div class=\"entete\">\n<div class=\"qb_ico\" id=\"qbico" $suffixclass "\" title=\"" $module "\"></div>\n";
  1397.     $quickbox .= "<div class=\"quickbox\" id=\"qbbg" $suffixclass "\">\n";
  1398.     $quickbox .= "<h1>" $h1 "</h1>\n";
  1399.     $quickbox .= "<ul>";
  1400.     $quickbox .= $liste;
  1401.     $quickbox .= "</ul>";
  1402.     $quickbox .= "</div>";
  1403.     $quickbox .= "</div>";
  1404.  
  1405.     return $quickbox;
  1406. }
  1407.  
  1408. /**
  1409.  * ReloadIndex()
  1410.  * Chargement de l'index après destruction de sessions
  1411.  *
  1412.  * @param string $item 
  1413.  * @return void 
  1414.  */
  1415. function ReloadIndex($item)
  1416. {
  1417.     switch ($item{
  1418.         case 'public':
  1419.             return header("Location: ../public/index.php");
  1420.             break;
  1421.         case 'admin':
  1422.             return header("Location: ../admin/logout.php");
  1423.             break;
  1424.     }
  1425. }
  1426.  
  1427. /**
  1428.  * getmicrotime()
  1429.  * renvoie le temps en microsecondes
  1430.  *
  1431.  * @return float 
  1432.  */
  1433. function getmicrotime()
  1434. {
  1435.     list($usec$secexplode(" "microtime());
  1436.     return ((float)$usec + (float)$sec);
  1437. }
  1438.  
  1439.  
  1440. /**
  1441.  * availablePlugins()
  1442.  * Return available plugins
  1443.  * @return array 
  1444.  ***/
  1445. function availablePlugins({
  1446.     $a array();
  1447.     if ($handle opendir('../plugins/')) {
  1448.         while (false !== ($file readdir($handle))) {
  1449.             if (substr($file04== 'l21_' {
  1450.                 array_push($a$file);
  1451.             }
  1452.         }
  1453.         closedir($handle);
  1454.     }
  1455.  
  1456.     return $a;
  1457. }
  1458.  
  1459. /**
  1460.  * enabledPlugins()
  1461.  * Return available plugins
  1462.  * @return array 
  1463.  ***/
  1464. function enabledPlugins({
  1465.     $a array();
  1466.     if ($handle opendir('../plugins/')) {
  1467.         while (false !== ($file readdir($handle))) {
  1468.             if (substr($file04== 'l21_' && file_exists('../plugins/'.$file.'/.active')) {
  1469.                 array_push($a$file);
  1470.             }
  1471.         }
  1472.         closedir($handle);
  1473.     }
  1474.  
  1475.     return $a;
  1476. }
  1477.  
  1478.  
  1479.  
  1480. /**
  1481.  * sql_dump2array()
  1482.  * @param $url 
  1483.  * @param $a 
  1484.  * @return array 
  1485.  * @link http://fr2.php.net/manual/fr/function.mysql-query.php
  1486.  */
  1487. function sql_dump2array($url$a = -1{
  1488.  
  1489.     $handle @fopen($url"r");
  1490.     $query "";
  1491.     if($a == -1$a array();
  1492.  
  1493.     while(!feof($handle)) {
  1494.         $sql_line fgets($handle);
  1495.         if (trim($sql_line!= "" && strpos($sql_line"--"=== false && strpos($sql_line"#"=== false{
  1496.             array_push($a$sql_line);
  1497.         }
  1498.     }
  1499.     return $a;
  1500. }
  1501.  
  1502. /**
  1503.  * sql_status_filter()
  1504.  * @param $fieldname 
  1505.  * @param $a array
  1506.  * @return string 
  1507.  */
  1508. function sql_status_filter($fieldname$a{
  1509.     
  1510.     $str '';
  1511.     $sep '';
  1512.     
  1513.     foreach ($a as $value{
  1514.         $str.= $sep$fieldname " = '"$value ."'";
  1515.         $sep " OR ";
  1516.     }
  1517.     if(count($a1$str ='('$str .')';
  1518.     
  1519.     return $str;
  1520. }
  1521.  
  1522. /**
  1523.  * getProgressbar()
  1524.  * Return a graphic progress bar
  1525.  * @param $value integer
  1526.  * @param $max integer
  1527.  * @param $unit string
  1528.  * @return string 
  1529.  */
  1530. function getProgressbar($value$max$unit{
  1531.  
  1532.     $step $max PROJECT_STEP;
  1533.     $threshold $value PROJECT_STEP;
  1534.  
  1535.     $str   =     '<div class="progressbar" title="'.$value.' '.$unit.'">'.END_LINE;
  1536.  
  1537.     for($i=1$i<=$step$i++{
  1538.         ($i <= $threshold$class 'class="completed"' $class '';
  1539.         $str .='<span '.$class.'>&nbsp;</span>';
  1540.     }
  1541.     $str  .=    '</div>'.END_LINE;
  1542.  
  1543.     return $str;
  1544. }
  1545.  
  1546. /**
  1547.  * geocode()
  1548.  * get Long/Latitude coordinates
  1549.  * @param $address string
  1550.  * @return object 
  1551.  */
  1552. function geocode($address{
  1553.  
  1554.     $o->{'status''geocoder_disabled';
  1555.  
  1556.     if(!defined('GEOCODER_ENABLED'|| GEOCODER_ENABLED == 0)
  1557.         return $o->{'status'};
  1558.  
  1559.     $address=str_replace(" ","+",$address);
  1560.     if ($address{
  1561.         $json file_get_contents(GEOCODER_URL.'address='.$address.'&sensor=false');
  1562.  
  1563.         $o json_decode($json);
  1564.     }
  1565.  
  1566.     return $o;
  1567. }
  1568.  
  1569. /**
  1570.  * placeholderReplace()
  1571.  * format '{$key}'
  1572.  * @param $array 
  1573.  * @param $input 
  1574.  * @return array 
  1575.  */
  1576. function placeholderReplace($array$input{
  1577.     foreach ($input as $key => $value)
  1578.     {
  1579.         $array preg_replace("/{{$key}}/i"$value$array);
  1580.     }
  1581.     return $array;
  1582. }
  1583.  
  1584. /**
  1585.  * GenerateXhtmlPage()
  1586.  *
  1587.  * @param $string 
  1588.  * @param integer $time 
  1589.  * @param unknown $redirect 
  1590.  * @return 
  1591.  ***/
  1592. function GenerateXhtmlPage($string$time 2$redirect CURRENT_APP_URL)
  1593. {
  1594.  
  1595.  
  1596.     $page  '<?xml version="1.0" encoding="' CHARSET '" xml:lang="' U_L '"?>' END_LINE;
  1597.     $page .= '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">' END_LINE;
  1598.     $page .= '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="' U_L '">' END_LINE;
  1599.     $page .= '<head>' END_LINE;
  1600.     $page .= '<meta http-equiv="content-type" content="text/html;charset=' CHARSET '" />' END_LINE;
  1601.     $page .= '<meta http-equiv="content-langage" content="' CHARSET '" />' END_LINE;
  1602.     $page .= '<meta http-equiv="refresh" content="' $time ';url=' $redirect '">' END_LINE;
  1603.     $page .= '<link rel="icon" type="image/gif" href="' .THEME_ADMIN_PATH'images/favicon.gif" />' END_LINE;
  1604.     $page .= '<title>'.SITE_NAME.'</title>' END_LINE;
  1605.     $page .= '</head>' END_LINE;
  1606.     $page .= '<body>' END_LINE;
  1607.     $page .= '<div class="info" style="margin-top:10em">'.$string.END_LINE;
  1608.     $page .= '<br />';
  1609.     $page .= sprintf_t('divers','redirect_string')$redirect$time);
  1610.     $page .= '</div>'END_LINE;
  1611.     $page .= '</body>' END_LINE;
  1612.     $page .= '</html>' END_LINE;
  1613.  
  1614.     return $page;
  1615. }
  1616.  
  1617. /**
  1618.  * _debug()
  1619.  * Display a debug message
  1620.  * @param string 
  1621.  * @return void 
  1622.  ***/
  1623. function _debug($string)
  1624. {
  1625.     if(isset($GLOBALS['Dbg']))
  1626.     {
  1627.         global $Dbg;
  1628.  
  1629.         $Dbg->add(htmlentities($string));
  1630.         $Dbg->stopTimer();
  1631.     }
  1632. }
  1633.  
  1634. /**
  1635.  * headerAddCSS()
  1636.  * Add CSS into header
  1637.  * @param string 
  1638.  * @param string 
  1639.  * @return boolean 
  1640.  ***/
  1641. function headerAddCSS($path$pos 'default')
  1642. {
  1643.     if(!fopen($path'r')) {
  1644.         _debug('<b>Problem loading CSS file</b> : '.$path ' (position : '.$pos.')');
  1645.         return false;
  1646.     }
  1647.     
  1648.     if(isset($GLOBALS['CSSheader']&& is_numeric(strpos($GLOBALS['CSSheader']$path))) {
  1649.         _debug('<b>Warning : CSS file already loaded</b> :'.$path);
  1650.         return false;
  1651.     }
  1652.  
  1653.     $str '<link type="text/css" rel="stylesheet" href="'.$path.'" />'.END_LINE;
  1654.  
  1655.     if(isset($GLOBALS['CSSheader']))
  1656.     {
  1657.         if($pos == 'first'{
  1658.             $GLOBALS['CSSheader'$str $GLOBALS['CSSheader'];
  1659.         else {
  1660.             $GLOBALS['CSSheader'.= $str END_LINE ;
  1661.         }
  1662.     else {
  1663.         $GLOBALS['CSSheader'$str;
  1664.     }
  1665.     _debug('Loading <b>CSS file</b> : '.$path ' (position : '.$pos.')');
  1666.  
  1667.     return true;
  1668. }
  1669.  
  1670. /**
  1671.  * headerAddJS()
  1672.  * Add JS into header
  1673.  * @param string 
  1674.  * @param string 
  1675.  * @return boolean 
  1676.  ***/
  1677. function headerAddJS($path$pos 'default')
  1678. {
  1679.     if(!fopen($path'r')) {
  1680.         _debug('<b>Problem loading JS file</b> : '.$path ' (position : '.$pos.')');
  1681.         return false;
  1682.     }
  1683.     
  1684.     if(isset($GLOBALS['JSheader']&& in_array($path $GLOBALS['JSheader'])) {
  1685.         _debug('<b>Warning : JS file already loaded</b> :'.$path);
  1686.         return false;
  1687.     }
  1688.  
  1689.     $str'<script type="text/javascript" src="'.$path .'"></script>'.END_LINE;
  1690.  
  1691.     if(isset($GLOBALS['JSheader']))
  1692.     {
  1693.         if($pos == 'first'{
  1694.             $GLOBALS['JSheader'$str $GLOBALS['JSheader'];
  1695.         }
  1696.         else {
  1697.             $GLOBALS['JSheader'.= $str END_LINE ;
  1698.         }
  1699.     else {
  1700.         $GLOBALS['JSheader'$str;
  1701.     }
  1702.     _debug('Loading <b>JS file</b> : '.$path ' (position : '.$pos.')');
  1703.  
  1704.     return true;
  1705. }
  1706.  
  1707. /**
  1708.  * footerAddInlineJS()
  1709.  * Add inline JS into footer
  1710.  * the resulting js is wrapped with <script> tags and jQuery .ready() function if $wrap == true
  1711.  * @param string 
  1712.  * @param string 
  1713.  * @return boolean 
  1714.  ***/
  1715. function footerAddInlineJS($str$pos 'default'$wrap true)
  1716. {
  1717. if($wrap == true{
  1718.     if(isset($GLOBALS['JSInlinefooter']))
  1719.     {
  1720.         if($pos == 'first'{
  1721.             $GLOBALS['JSInlinefooter'$str END_LINE$GLOBALS['JSInlinefooter'];
  1722.         }
  1723.         else {
  1724.             $GLOBALS['JSInlinefooter'.= $str END_LINE ;
  1725.         }
  1726.     else {
  1727.         $GLOBALS['JSInlinefooter'$strEND_LINE;
  1728.     }
  1729. else {
  1730.     if(isset($GLOBALS['JSInlinefooter_nowrap']))
  1731.     {
  1732.         if($pos == 'first'{
  1733.             $GLOBALS['JSInlinefooter_nowrap'$str END_LINE$GLOBALS['JSInlinefooter_nowrap'];
  1734.         }
  1735.         else {
  1736.             $GLOBALS['JSInlinefooter_nowrap'.= $str END_LINE ;
  1737.         }
  1738.     else {
  1739.         $GLOBALS['JSInlinefooter_nowrap'$strEND_LINE;
  1740.     }
  1741. }
  1742.     _debug('Loading <b>inline JS</b> : '.cutText($str90' (position : '.$pos.')');
  1743.  
  1744.     return true;
  1745. }
  1746.  
  1747. /**
  1748.  * footerAddJS()
  1749.  * Add JS into footer
  1750.  * @param string 
  1751.  * @param string 
  1752.  * @return boolean 
  1753.  ***/
  1754. function footerAddJS($path$pos 'default')
  1755. {
  1756.     if(!fopen($path'r')) {
  1757.         _debug('<b>Problem loading JS file</b> : '.$path ' (position : '.$pos.')');
  1758.         return false;
  1759.     }
  1760.     
  1761.     if(isset($GLOBALS['JSfooter']&& is_numeric(strpos($GLOBALS['JSfooter']$path))) {
  1762.         _debug('<b>Warning : JS file already loaded</b> :'.$path);
  1763.         return false;
  1764.     }
  1765.  
  1766.     $str'<script type="text/javascript" src="'.$path .'"></script>'.END_LINE;
  1767.  
  1768.     if(isset($GLOBALS['JSfooter']))
  1769.     {
  1770.         if($pos == 'first'{
  1771.             $GLOBALS['JSfooter'$str $GLOBALS['JSheader'];
  1772.         }
  1773.         else {
  1774.             $GLOBALS['JSfooter'.= $str END_LINE ;
  1775.         }
  1776.     else {
  1777.         $GLOBALS['JSfooter'$str END_LINE ;
  1778.     }
  1779.     _debug('Loading <b>JS file</b> : '.$path ' (position : '.$pos.')');
  1780.  
  1781.     return true;
  1782. }
  1783.  
  1784. function addDynamicCSS($url{
  1785.     
  1786.     // use of document.createStyleSheet for IE8 compatibility
  1787.     $str 'if (document.createStyleSheet)
  1788.                     {
  1789.                         document.createStyleSheet("'.$url'");
  1790.                     }
  1791.                     else
  1792.                     {
  1793.                         $(\'<link rel="stylesheet" type="text/css" href="'.$url'" />\').appendTo("head");
  1794.                     }';
  1795.  
  1796.     footerAddInlineJS($str);
  1797.     
  1798. }
  1799.  
  1800. /**
  1801.  * AddDynamicHeader()
  1802.  * Display JS and CSS header
  1803.  * @return void 
  1804.  ***/
  1805. function AddDynamicHeader({
  1806.     if(isset($GLOBALS['JSheader'])) echo $GLOBALS['JSheader'];
  1807.     if(isset($GLOBALS['CSSheader']))  echo $GLOBALS['CSSheader'];
  1808. }
  1809.  
  1810. /**
  1811.  * AddDynamicFooter()
  1812.  * Display JS footer
  1813.  * @return void 
  1814.  ***/
  1815. function AddDynamicFooter({
  1816.     if(isset($GLOBALS['JSfooter'])) echo $GLOBALS['JSfooter'];
  1817.     if(isset($GLOBALS['JSInlinefooter_nowrap'])) echo $GLOBALS['JSInlinefooter_nowrap'];
  1818.     if(isset($GLOBALS['JSInlinefooter'])) {
  1819.         echo '<script type="text/javascript">'.END_LINE;
  1820.         echo '    $(document).ready(function() {'.END_LINE;
  1821.         echo $GLOBALS['JSInlinefooter'];
  1822.         echo '  });'.END_LINE;
  1823.         echo '</script>'.END_LINE;
  1824.     }
  1825. }
  1826.  
  1827. /**
  1828.  * check4newVersion()
  1829.  * Display a link to download new version if available
  1830.  * @return string 
  1831.  ***/
  1832. function check4newVersion({
  1833.     try{
  1834.         if(!@$rss=simplexml_load_file(SITE_LINEA_URL.'/linea_version.xml')){
  1835.             throw new Exception('Version : xml file was not found');
  1836.         }
  1837.         $current_version preg_replace("/(-rev|-r)([0-9])+/",''LINEA_VERSION)// remove revision number (ie "1.5-rev1815" will return "1.5.4")
  1838.         $current_version preg_replace("/([^0-9])/",''$current_version)// remove letter (if dev version)
  1839.         
  1840.         $latest_version str_pad(str_replace('.'''$rss->num)4'0');
  1841.         $current_version str_pad(str_replace('.'''$current_version)4'0');
  1842.         
  1843. //         _debug('current ver : '.$current_version . ' latest ver : '.$latest_version);
  1844.  
  1845.         if((integer)$latest_version > (integer)$current_version{
  1846.             $update '<div id="version-check">'._t('check_update','search').' : <a href="'.(string)$rss->link.'">'.sprintf(_t('check_update','dl')$rss->num).'</a></div>';
  1847.         else {
  1848.             $update '<div id="version-check">'._t('check_update','search').' : '._t('check_update','ok').'</div>';
  1849.         }
  1850.     }
  1851.     catch(Exception $e){
  1852.         $update $e->getMessage();
  1853.     }
  1854.  
  1855.     return $update;
  1856. }
  1857.  
  1858. /**
  1859.  * loadThemeInfo()
  1860.  * Load theme info
  1861.  * @param string 
  1862.  * @param string 
  1863.  * @return string 
  1864.  ***/
  1865. function loadThemeInfo($type$name{
  1866.     $a array();
  1867.     try{
  1868.         if(!@$flow=simplexml_load_file(SITE_PATH.'templates/'.$type.'/'.$name.'/theme.xml')){
  1869.             throw new Exception($name.' plugin : xml file was not found');
  1870.         }
  1871.         $a['name'$flow->themename;
  1872.         $a['description'$flow->description;
  1873.         $a['version'$flow->version;
  1874.         $a['date'$flow->date;
  1875.         $a['compatibility'$flow->compatibility;
  1876.         $a['author'$flow->author;
  1877.         $a['homepage'$flow->homepage;
  1878.  
  1879.         return $a;
  1880.     }
  1881.     catch(Exception $e){
  1882.         return $e->getMessage();
  1883.     }
  1884. }
  1885. /**
  1886.  * For compatibility with PHP < 5.2
  1887.  * json_decode
  1888.  */
  1889. if !function_exists('json_decode') ){
  1890.     function json_decode($content$assoc=false){
  1891.         require_once __DIR__ .'/vendor/JSON/JSON.php';
  1892.         if $assoc ){
  1893.             $json new Services_JSON(SERVICES_JSON_LOOSE_TYPE);
  1894.         else {
  1895.             $json new Services_JSON;
  1896.         }
  1897.         return $json->decode($content);
  1898.     }
  1899. }
  1900.  
  1901. /**
  1902.  * For compatibility with PHP < 5.2
  1903.  * json_encode
  1904.  */
  1905. if !function_exists('json_encode') ){
  1906.     function json_encode($content){
  1907.         require_once __DIR__ .'/vendor/JSON/JSON.php';
  1908.         $json new Services_JSON;
  1909.             
  1910.         return $json->encode($content);
  1911.     }
  1912. }
  1913.  
  1914. /**
  1915.  Validate an email address.
  1916.  Provide email address (raw input)
  1917.  Returns true if the email address has the email
  1918.  address format and the domain exists.
  1919.  @link http://www.linuxjournal.com/article/9585
  1920.  */
  1921. function validEmail($email)
  1922. {
  1923.     $isValid true;
  1924.     $atIndex strrpos($email"@");
  1925.     if (is_bool($atIndex&& !$atIndex)
  1926.     {
  1927.         $isValid false;
  1928.     }
  1929.     else
  1930.     {
  1931.         $domain substr($email$atIndex+1);
  1932.         $local substr($email0$atIndex);
  1933.         $localLen strlen($local);
  1934.         $domainLen strlen($domain);
  1935.         if ($localLen || $localLen 64)
  1936.         {
  1937.             // local part length exceeded
  1938.             $isValid false;
  1939.         }
  1940.         else if ($domainLen || $domainLen 255)
  1941.         {
  1942.             // domain part length exceeded
  1943.             $isValid false;
  1944.         }
  1945.         else if ($local[0== '.' || $local[$localLen-1== '.')
  1946.         {
  1947.             // local part starts or ends with '.'
  1948.             $isValid false;
  1949.         }
  1950.         else if (preg_match('/\\.\\./'$local))
  1951.         {
  1952.             // local part has two consecutive dots
  1953.             $isValid false;
  1954.         }
  1955.         else if (!preg_match('/^[A-Za-z0-9\\-\\.]+$/'$domain))
  1956.         {
  1957.             // character not valid in domain part
  1958.             $isValid false;
  1959.         }
  1960.         else if (preg_match('/\\.\\./'$domain))
  1961.         {
  1962.             // domain part has two consecutive dots
  1963.             $isValid false;
  1964.         }
  1965.         else if
  1966.         (!preg_match('/^(\\\\.|[A-Za-z0-9!#%&`_=\\/$\'*+?^{}|~.-])+$/',
  1967.                 str_replace("\\\\","",$local)))
  1968.         {
  1969.             // character not valid in local part unless
  1970.             // local part is quoted
  1971.             if (!preg_match('/^"(\\\\"|[^"])+"$/',
  1972.                     str_replace("\\\\","",$local)))
  1973.             {
  1974.                 $isValid false;
  1975.             }
  1976.         }
  1977.         if(CHECK_LINK == 1{
  1978.             if ($isValid && !(checkdnsrr($domain,"MX"|| checkdnsrr($domain,"A")))
  1979.             {
  1980.                 // domain not found in DNS
  1981.                 $isValid false;
  1982.             }
  1983.         }
  1984.     }
  1985.     return $isValid;
  1986. }
  1987.  
  1988. /**
  1989.  * commentEnabled($m)
  1990.  * Check if comment is enabled on
  1991.  * given module
  1992.  * @param string 
  1993.  * @return boolean 
  1994.  ***/
  1995. function commentEnabled($m)
  1996. {
  1997.     if(!defined('MOD_COMMENT'|| MOD_COMMENT == 0{
  1998.         return false;
  1999.     else {
  2000.         if(is_numeric(strpos(COMMENT_MODULES$m))) return true;
  2001.         else return false;
  2002.     }
  2003. }
  2004.  
  2005. /**
  2006.  * setBreadcrumb()
  2007.  * Set breadcrumb content
  2008.  * @param array 
  2009.  * @return void 
  2010.  ***/
  2011. function setBreadcrumb($array)
  2012. {
  2013.     if(!isset($GLOBALS['breadcrumb'])) $GLOBALS['breadcrumb']array();
  2014.     $GLOBALS['breadcrumb'array_merge($GLOBALS['breadcrumb']$array);
  2015. }
  2016.  
  2017. /**
  2018.  * getBreadcrumb()
  2019.  * get the Breadcrumb for displaying
  2020.  * @param string (optional)
  2021.  * @return string 
  2022.  ***/
  2023. function getBreadcrumb($sep '»')
  2024. {
  2025.     $str '<div id="breadcrumb">'.END_LINE;
  2026.     $str.= '<ul>'.END_LINE;
  2027.     $str.= '<li><span class="separator">'.$sep.' </span><a href="'.SITE_ROOT_URL.'public/">'._t('way''home').'</a></li>'.END_LINE;
  2028.     foreach($GLOBALS['breadcrumb'as $key => $value{
  2029.  
  2030.         if($value!=false$str.= '<li><span class="separator">'.$sep.' </span><a href="'.$value.'">'.$key.'</a></li>'.END_LINE;
  2031.         else $str.= '<li><span class="separator">'.$sep.' </span>'.$key.'</li>'.END_LINE;
  2032.     }
  2033.     $str.= '</ul>'.END_LINE;
  2034.     $str.= '</div>'.END_LINE;
  2035.  
  2036.     return $str;
  2037. }
  2038.  
  2039. /**
  2040.  * GetAllFiles()
  2041.  * Return an arry of filenames
  2042.  * @param string 
  2043.  * @param array 
  2044.  * @param boolean 
  2045.  * @return array 
  2046.  ***/
  2047. function GetAllFiles($folder,$ext=array('txt'),$recursif=true{
  2048.  
  2049.     $files array();
  2050.     $dir=opendir($folder);
  2051.     while ($file readdir($dir)) {
  2052.         if ($file == '.' || $file == '..'continue;
  2053.         if (is_dir($folder.'/'.$file)) {
  2054.             if ($recursif==true)
  2055.                 $files=array_merge($filesGetAllFiles($folder.'/'.$file$ext));
  2056.         else {
  2057.             foreach ($ext as $v{
  2058.                 if (strtolower($v)==strtolower(substr($file,-strlen($v)))) {
  2059.                     $files[$folder.'/'.$file;
  2060.                     break;
  2061.                 }
  2062.             }
  2063.         }
  2064.     }
  2065.     closedir($dir);
  2066.     return $files;
  2067. }
  2068.  
  2069.  
  2070. /**
  2071.  * ListDir()
  2072.  * Return an HTML list for a given folder
  2073.  * @param int 
  2074.  * @param string 
  2075.  * @param string 
  2076.  * @param boolean 
  2077.  * @return string 
  2078.  ***/
  2079. function ListDir($dir_handle,$path$url{
  2080.  
  2081.     $i0;
  2082.     $dirFiles array();
  2083.  
  2084.     // we prepare files
  2085.     while (false !== ($file readdir($dir_handle))) {
  2086.         $dir $path $file;
  2087.         if(is_dir($dir&& $file != '.' && $file !='..' {
  2088.             $handle @opendir($diror die("Unable to open file $file");
  2089.             ListDir($handle$dir.'/'$url);
  2090.         elseif($file != '.' && $file !='..' && $file !='.htaccess'{
  2091.             array_push($dirFiles$dir);
  2092.         }
  2093.     }
  2094.     closedir($dir_handle);
  2095.  
  2096.     // sort by name
  2097.     sort($dirFiles);
  2098.  
  2099.     // uncomment to reverse array
  2100.     // $dirFiles= array_reverse($dirFiles);
  2101.  
  2102.     // uncomment to sort on latest modification
  2103.     //    array_multisort(
  2104.     //      array_map( 'filemtime', $dirFiles ),
  2105.     //      SORT_NUMERIC,
  2106.     //      SORT_DESC,
  2107.     //      $dirFiles
  2108.     //    );
  2109.  
  2110.     echo "<ul>";
  2111.     foreach($dirFiles as $dir)
  2112.     {
  2113.         $sizeformatBytes(filesize($dir)2);
  2114.         $class ($i++ 1'' 'class="odd"';
  2115.         $dir str_replace('../'''$dir);
  2116.         $dir str_replace('//''/'$dir);
  2117.         $dir dirname($dir).'/'rawurlencode(basename($dir));
  2118.         $file basename(rawurldecode($dir));
  2119.         
  2120.         $comment_actions '';
  2121.  
  2122.         if(MOD_COMMENT == && commentEnabled('files')) {
  2123.             $id str_replace('library/userfiles/'''$dir);
  2124.             $nb getFileComments($id);
  2125.             $comment_actions .= '<span class="comment_actions">';
  2126.             $comment_actions .= '<a class="comment_see" href="../comment/_ajax_view.php?id='.$id.'&amp;module=files&amp;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>';
  2127.             $comment_actions .= '</span>';
  2128.         }
  2129.  
  2130.         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>';
  2131.     }
  2132.  
  2133.  
  2134.     if($i==0echo '<li>'._t('divers','no_files').'</li>';
  2135.     echo "</ul>";
  2136. }
  2137.  
  2138. /**
  2139.  * formatBytes()
  2140.  * Make File size readable
  2141.  * @param int 
  2142.  * @param int (optional)
  2143.  * @return string 
  2144.  ***/
  2145. function formatBytes($bytes$precision 2{
  2146.     $units array('o''Ko''Mo''Go''To');
  2147.  
  2148.     $bytes max($bytes0);
  2149.     $pow floor(($bytes log($bytes0log(1024));
  2150.     $pow min($powcount($units1);
  2151.  
  2152.     $bytes /= pow(1024$pow);
  2153.  
  2154.     return round($bytes$precision' ' $units[$pow];
  2155. }
  2156.  
  2157. /**
  2158.  * logfile()
  2159.  * Log into file
  2160.  * @param string 
  2161.  * @param array 
  2162.  * @return void 
  2163.  ***/
  2164. function logfile($src$a{
  2165.  
  2166.     $sep '##';
  2167.     $fp @fopen($src'a');
  2168.  
  2169.     @fwrite($fpdate('[d-m-y H:i:s]'$sep);
  2170.     
  2171.     foreach($a as $value{
  2172.         @fwrite($fp$value $sep);
  2173.     }
  2174.  
  2175.     @fwrite($fpEND_LINE);
  2176.     @fclose($fp);
  2177.  
  2178.     return true;
  2179. }
  2180.  
  2181. /**
  2182.  * getThemes()
  2183.  * Return installed themes
  2184.  * into an array
  2185.  * @param string 
  2186.  * @return array 
  2187.  ***/
  2188. function getThemes($f{
  2189.  
  2190.     $a array();
  2191.  
  2192.     if ($handle opendir('../templates/'.$f)) {
  2193.         $sep='';
  2194.         while (false !== ($file readdir($handle))) {
  2195.             if ($file != "." && $file != ".." && $file != ".svn"{
  2196.                 array_push($a$file);
  2197.             }
  2198.         }
  2199.         closedir($handle);
  2200.     }
  2201.  
  2202.     return $a;
  2203. }
  2204.  
  2205. /**
  2206.  * notifyUsersMsg()
  2207.  * @access public
  2208.  * @param array $a 
  2209.  *  $a['owner'] : item owner
  2210.  *  $a['user'] : the one who posted the item (can be an adminsitrator or animator)
  2211.  * @return boolean 
  2212.  */
  2213. function notifyUsersMsg($a{
  2214.  
  2215.     if($a['action'== 'post_alert'{
  2216.       if(ALERT_NEWPOST == 0return true;
  2217.       if(ALERT_NEWPOST == 1$m array('O');
  2218.       if(ALERT_NEWPOST == 2$m array('O''U');
  2219.  
  2220.       $wg $a['parentid'];
  2221.       $data $GLOBALS['sql_object']->DBSelect(SQL_getWorkshopDenomination($a['parentid']));
  2222.       if(count($data)==1$wname =$data[0]['workshop_denomination'];
  2223.       $wlinkforumarray('rub'=> $GLOBALS['links'][U_L]['topic']['linkvalue'],'id'=> $a['tid']'parentid' => $a['parentid']'name' => $wname'#' => 'msg-'.$a['id']);
  2224.       $users $GLOBALS['sql_object'-> DBSelect(SQL_getWorkshopUsersforNotification($a['parentid']'post')'OBJECT');
  2225.     }
  2226.  
  2227.     if($a['action'== 'topic_alert'{
  2228.       if(ALERT_NEWTOPIC == 0return true;
  2229.       if(ALERT_NEWTOPIC == 1$m array('O');
  2230.       if(ALERT_NEWTOPIC == 2$m array('O''U');
  2231.  
  2232.       $data $GLOBALS['sql_object']->DBSelect(SQL_getWorkshopDenomination($a['id']));
  2233.       if(count($data)==1$wname =$data[0]['workshop_denomination'];
  2234.  
  2235.       $wlinkforumarray('rub'=> $GLOBALS['links'][U_L]['topic-list']['linkvalue'],'id'=> $a['id']'name' => $wname);
  2236.       
  2237.       $users $GLOBALS['sql_object'-> DBSelect(SQL_getWorkshopUsersforNotification($a['id']'topic')'OBJECT');
  2238.     }
  2239.  
  2240.     if($a['action'== 'file_alert'{
  2241.       if(ALERT_NEWFILE == 0return true;
  2242.       if(ALERT_NEWFILE == 1$m array('O');
  2243.       if(ALERT_NEWFILE == 2$m array('O''U');
  2244.  
  2245.       $data $GLOBALS['sql_object']->DBSelect(SQL_getWorkshopDenomination($a['id']));
  2246.       if(count($data)==1$wname =$data[0]['workshop_denomination'];
  2247.       
  2248.       $wlinkfiles array('rub'=> $GLOBALS['links'][U_L]['files']['linkvalue'],'id'=> $a['id']'name' => $wname);
  2249.       $wlinkworkgroups array('rub'=> $GLOBALS['links'][U_L]['workgroup']['linkvalue']);
  2250.       
  2251.       if(isset($a['is_shared']&& $a['is_shared'=== true{
  2252.           // we notify all users
  2253.           $users $GLOBALS['sql_object']->DBSelect(SQL_getAllWorkshopUsersforNotification('file')'OBJECT');
  2254.       else {
  2255.           // we notify only current workgroup
  2256.           $users $GLOBALS['sql_object']->DBSelect(SQL_getWorkshopUsersforNotification($a['id']'file')'OBJECT');
  2257.       }
  2258.     }
  2259.     
  2260.     if($a['action'== 'event_alert'{
  2261.         if(ALERT_NEWEVENT == 0return true;
  2262.         if(ALERT_NEWEVENT == 1$m array('O');
  2263.         if(ALERT_NEWEVENT == 2$m array('O''U');
  2264.     
  2265.         $data $GLOBALS['sql_object']->DBSelect(SQL_getWorkshopDenomination($a['id']));
  2266.         if(count($data)==1$wname =$data[0]['workshop_denomination'];
  2267.         
  2268.         $wlinkcalendar array('rub'=> $GLOBALS['links'][U_L]['calendar']['linkvalue'],'id'=> $a['id']'name' => $wname);
  2269.         $users $GLOBALS['sql_object']->DBSelect(SQL_getWorkshopUsersforNotification($a['id']'file')'OBJECT');
  2270.     }
  2271.  
  2272.     foreach($users as $user{
  2273.       if($user->user_login != $a['user']{
  2274.         if(in_array($user->jwu_user_right$m)) {
  2275.           include(override('../workshop/mail_actions.php'));
  2276.           include(override('../mail/template.php'));
  2277.         }
  2278.       }
  2279.     }
  2280.     return true;
  2281.   }
  2282.  
  2283. /**
  2284.  * cleanString()
  2285.  * Remove exotic characters form string
  2286.  * same as used in filemanager
  2287.  * @param string 
  2288.  * @param array 
  2289.  * @return string 
  2290.  ***/
  2291. function cleanString($string$allowed array()) {
  2292.     $allow null;
  2293.  
  2294.     if (!empty($allowed)) {
  2295.         foreach ($allowed as $value{
  2296.             $allow .= "\\$value";
  2297.         }
  2298.     }
  2299.  
  2300.     $mapping array(
  2301.             'Š'=>'S''š'=>'s''Đ'=>'Dj''đ'=>'dj''Ž'=>'Z''ž'=>'z''Č'=>'C''č'=>'c''Ć'=>'C''ć'=>'c',
  2302.             'À'=>'A''Á'=>'A''Â'=>'A''Ã'=>'A''Ä'=>'A''Å'=>'A''Æ'=>'A''Ç'=>'C''È'=>'E''É'=>'E',
  2303.             'Ê'=>'E''Ë'=>'E''Ì'=>'I''Í'=>'I''Î'=>'I''Ï'=>'I''Ñ'=>'N''Ò'=>'O''Ó'=>'O''Ô'=>'O',
  2304.             'Õ'=>'O''Ö'=>'O''Ő'=>'O''Ø'=>'O''Ù'=>'U''Ú'=>'U''Û'=>'U''Ü'=>'U''Ű'=>'U''Ý'=>'Y',
  2305.             'Þ'=>'B''ß'=>'Ss','à'=>'a''á'=>'a''â'=>'a''ã'=>'a''ä'=>'a''å'=>'a''æ'=>'a''ç'=>'c',
  2306.             'è'=>'e''é'=>'e''ê'=>'e''ë'=>'e''ì'=>'i''í'=>'i''î'=>'i''ï'=>'i''ð'=>'o''ñ'=>'n',
  2307.             'ò'=>'o''ó'=>'o''ô'=>'o''õ'=>'o''ö'=>'o''ő'=>'o''ø'=>'o''ù'=>'u''ú'=>'u''ű'=>'u',
  2308.             'û'=>'u''ý'=>'y''ý'=>'y''þ'=>'b''ÿ'=>'y''Ŕ'=>'R''ŕ'=>'r'' '=>'_'"'"=>'_''/'=>''
  2309.     );
  2310.  
  2311.     if (is_array($string)) {
  2312.  
  2313.         $cleaned array();
  2314.  
  2315.         foreach ($string as $key => $clean{
  2316.             $clean strtr($clean$mapping);
  2317.             $clean preg_replace("/[^{$allow}_a-zA-Z0-9]/"''$clean);
  2318.             $cleaned[$keypreg_replace('/[_]+/''_'$clean)// remove double underscore
  2319.         }
  2320.     else {
  2321.         $string strtr($string$mapping);
  2322.         $string preg_replace("/[^{$allow}_a-zA-Z0-9]/"''$string);
  2323.         $cleaned preg_replace('/[_]+/''_'$string)// remove double underscore
  2324.     }
  2325.     return $cleaned;
  2326. }
  2327.  
  2328. // Returns the real IP address of the user
  2329. function i2c_realip()
  2330. {
  2331.     // No IP found (will be overwritten by for
  2332.     // if any IP is found behind a firewall)
  2333.     $ip false;
  2334.     // If HTTP_CLIENT_IP is set, then give it priority
  2335.     if (!empty($_SERVER["HTTP_CLIENT_IP"])) {
  2336.         $ip $_SERVER["HTTP_CLIENT_IP"];
  2337.     }
  2338.     // User is behind a proxy and check that we discard RFC1918 IP addresses
  2339.     // if they are behind a proxy then only figure out which IP belongs to the
  2340.     // user.  Might not need any more hackin if there is a squid reverse proxy
  2341.     // infront of apache.
  2342.     if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
  2343.         // Put the IP's into an array which we shall work with shortly.
  2344.         $ips explode (", "$_SERVER['HTTP_X_FORWARDED_FOR']);
  2345.         if ($ip{
  2346.             array_unshift($ips$ip);
  2347.             $ip false;
  2348.         }
  2349.  
  2350.         for ($i 0$i count($ips)$i++{
  2351.             // Skip RFC 1918 IP's 10.0.0.0/8, 172.16.0.0/12 and
  2352.             // 192.168.0.0/16 -- jim kill me later with my regexp pattern
  2353.             // below.
  2354.             if (!eregi ("^(10|172\.16|192\.168)\."$ips[$i])) {
  2355.                 $ip $ips[$i];
  2356.                 break;
  2357.             }
  2358.         }
  2359.     }
  2360.     // Return with the found IP or the remote address
  2361.     return ($ip $ip $_SERVER['REMOTE_ADDR']);
  2362. }
  2363.  
  2364. /**
  2365.  * securityCheck()
  2366.  * Test and sanitize user input
  2367.  * from request
  2368.  * @return boolean 
  2369.  ***/
  2370. function securityCheck({
  2371.  
  2372.     $passed true;
  2373.  
  2374.     // we first sanitize vars
  2375.     if(isset($_REQUEST['rub']))
  2376.         $_REQUEST['rub']strip_tags($_REQUEST['rub']);
  2377.     if(isset($_REQUEST['name']))
  2378.         $_REQUEST['name']strip_tags($_REQUEST['name']);
  2379.     if(isset($_REQUEST['newsletteremail']))
  2380.         $_REQUEST['newsletteremail']strip_tags($_REQUEST['newsletteremail']);
  2381.     // then do tests
  2382.     if(isset($_REQUEST['id']&& preg_match('/[^0-9A-Za-z]/',$_REQUEST['id']))
  2383.         $passedfalse;
  2384.     if(isset($_REQUEST['parentid']&& !is_numeric($_REQUEST['parentid']))
  2385.         $passedfalse;
  2386.     if(isset($_REQUEST['parentparentid']&& !is_numeric($_REQUEST['parentparentid']))
  2387.         $passedfalse;
  2388.     if(isset($_REQUEST['debut']&& !is_numeric($_REQUEST['debut']))
  2389.         $passedfalse;
  2390.  
  2391.     if($passed == falsedie('no way!');
  2392.     else return true;
  2393. }
  2394. ?>

Documentation generated on Thu, 20 Mar 2014 16:48:32 +0100 by phpDocumentor 1.4.1