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

Documentation generated on Mon, 08 Apr 2013 18:15:15 +0200 by phpDocumentor 1.4.1