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.  * optimize()
  13.  * callback method
  14.  * to ob_start()
  15.  * @param string $buffer 
  16.  * @return string 
  17.  */
  18. function optimize($buffer{
  19.  
  20.   $title implode(' - '$GLOBALS['current_title']);
  21.  
  22.  
  23.   return str_replace('##TITLE##'$title$buffer);
  24. }
  25.  
  26. /**
  27.  * implode_with_keys()
  28.  * implode avec clefs associées renvoyées
  29.  * sous forme de chaîne de caractères
  30.  * @param string $glue 
  31.  * @param string $array 
  32.  * @return string 
  33.  */
  34. function implode_with_keys($glue$array{
  35.   $output array();
  36.   foreach$array as $key => $item )
  37.   $output[$key "=" $item;
  38.  
  39.   return implode($glue$output);
  40. }
  41.  
  42. /**
  43.  * getHttpParameters()
  44.  * Renvoie les paramètres HTTP
  45.  * sous forme de chaîne de caractères
  46.  * @return string 
  47.  */
  48. function getHttpParameters($prefix '?'{
  49.  
  50.   return $prefix. (string) implode_with_keys('&'$_REQUEST);
  51. }
  52.  
  53. /**
  54.  * strip_input()
  55.  * Remove PHP and HTML code
  56.  * @param string $str 
  57.  * @param string $exceptions 
  58.  * @return string 
  59.  */
  60. function strip_input($str$exceptions false{
  61.  
  62.   if(defined('RICH_TEXT_EDITOR'&& RICH_TEXT_EDITOR != (string) 0{
  63.     return $str;
  64.   }
  65.   else {
  66.     if($exceptions)  {
  67.       return strip_tags($strALLOWABLE_TAGS);
  68.     }
  69.     else {
  70.       return strip_tags($str);
  71.     }
  72.   }
  73.  
  74. }
  75.  
  76. /**
  77.  * IncludeTimeline()
  78.  * Include SIMILE Timeline JS code
  79.  * if needed
  80.  * @return void 
  81.  */
  82. function IncludeTimeline({
  83.   if(defined('TIMELINE_DISPLAY'&& TIMELINE_DISPLAY == && (MOD_DEBUG != || MOD_DEBUG_HIDDEN != 0)) {
  84.     if(isset($_REQUEST['rub']&& $_REQUEST['rub']=="project" && (!isset($_REQUEST['todo']|| $_REQUEST['todo'== 'list')) {
  85.         echo '<script src="' .SITE_CITY_URL'../lib/js/timeline/timeline_ajax/simile-ajax-api.js" type="text/javascript"></script>'.END_LINE
  86.         echo '<script type="text/javascript">
  87.              Timeline_urlPrefix=\'' .SITE_CITY_URL'../lib/js/timeline/timeline_js/\';       
  88.              Timeline_parameters=\'bundle=true\';
  89.              $(function() {
  90.              $("#content").prepend(\'<div id="my-timeline" style="height: 250px; border-bottom: 1px solid #aaa"></div>\');
  91.              });
  92.              
  93.           </script>';
  94.         echo '<script src="' .SITE_CITY_URL'../lib/js/timeline/timeline_js/timeline-api.js" type="text/javascript"></script>'.END_LINE
  95.         echo '<script type="text/javascript" src="../lib/js/timeline.js"></script>'END_LINE;
  96.     }
  97.   }
  98. }
  99.  
  100. /**
  101.  * IncludeTextResizerJs()
  102.  * Include jQuery text-resizer plugin
  103.  * if no js wysiwyg are enabled
  104.  * @return void 
  105.  */
  106. function IncludeTextResizerJs({
  107.  
  108.   if(!defined('RICH_TEXT_EDITOR'|| RICH_TEXT_EDITOR == (string) )
  109.   {
  110.     echo '<script type="text/javascript" src="../lib/js/jquery.textarearesizer.compressed.js"></script>';
  111.     echo '<script type="text/javascript">
  112.               $(document).ready(function() {
  113.                 $(\'textarea.largetextfield:not(.processed)\').TextAreaResizer();
  114.             })
  115.               </script>'.END_LINE;
  116.   }
  117. }
  118.  
  119. /**
  120.  * IncludeTextCornerJs()
  121.  * Include jQuery text-corner plugin
  122.  * if no js wysiwyg are enabled
  123.  * @return void 
  124.  */
  125. function IncludeTextCornerJs({
  126.   echo '<script type="text/javascript" src="../lib/js/jquery.corner.js"></script>'.END_LINE;
  127.   echo '<script type="text/javascript" src="../lib/js/jquery.corner.config.js"></script>'.END_LINE;
  128. }
  129. /**
  130.  * IncludeJsTreeJs()
  131.  * Include jQuery Jstree plugin
  132.  * @return void 
  133.  */
  134. function IncludeJsTreeJs({
  135.   echo '<script type="text/javascript" src="../lib/js/jstree/jquery.tree.min.js"></script>'.END_LINE;
  136.   echo '<script type="text/javascript" src="../lib/js/jstree/plugins/jquery.tree.contextmenu.js"></script>'.END_LINE;
  137.   echo '<script type="text/javascript">
  138.               msg_mod = "'_t('divers','modify').'";
  139.               msg_del = "'_t('divers','delete').'";
  140.               </script>'.END_LINE;
  141.   echo '<script type="text/javascript" src="../lib/js/jstree/config.js"></script>'.END_LINE;
  142. }
  143.  
  144. /**
  145.  * IncludeRichTextEditor()
  146.  * Include RichTextEditor if enabled
  147.  * @return void 
  148.  */
  149. function IncludeRichTextEditor({
  150.  
  151.   if(defined('RICH_TEXT_EDITOR'&& RICH_TEXT_EDITOR != (string) )  {
  152.     if(strtolower(RICH_TEXT_EDITOR== 'tinymce')
  153.     {
  154.       echo '<script type="text/javascript" src="'.themePath('../lib/js/tinymce/jscripts/tiny_mce/tiny_mce.js'THEME_ADMIN_PATH).'"></script>'.END_LINE;
  155.       echo '<script type="text/javascript" src="'.themePath('../lib/js/tinymce/jscripts/tiny_mce/config.js'THEME_ADMIN_PATH).'"></script>'.END_LINE;
  156.     }
  157.     if(strtolower(RICH_TEXT_EDITOR== 'fck')
  158.     {
  159.        
  160.       echo '<script type="text/javascript" src="../lib/js/fckeditor/fckeditor.js"></script>'.END_LINE;
  161.       echo '<script type="text/javascript">
  162.               $(document).ready(function(){
  163.             
  164.               FCKeditor.BasePath = "../lib/js/fckeditor/";
  165.               FCKeditor.MinWidth = "300px";
  166.             FCKeditor.ReplaceAllTextareas(\'largetextfield\');
  167.     
  168.  
  169.               });
  170.               </script>'.END_LINE;
  171.     }
  172.   }
  173.  
  174. }
  175.  
  176.  
  177. /**
  178.  * IncludeLightboxJs()
  179.  * Include Lightbox jQuery plugin
  180.  * if needed
  181.  * @return void 
  182.  */
  183. function IncludeLightboxJs({
  184.  
  185.   echo '<script type="text/javascript" src="../lib/js/jquery.lightbox-0.5.pack.js"></script>'.END_LINE;
  186.   echo '<link type="text/css" rel="stylesheet" href="'.THEME_ADMIN_PATH.'css/jquery.lightbox-0.5.css" />'.END_LINE;
  187.   echo '
  188.         <script type="text/javascript">
  189.     $(function() {
  190.         $("a.lightbox").lightBox();
  191.     });
  192.     </script>'END_LINE;
  193.  
  194. }
  195.  
  196. /**
  197.  * IncludeMultiSelectJs()
  198.  * Include jQuery multiSelect plugin
  199.  * if needed
  200.  * @return void 
  201.  */
  202. function IncludeMultiSelectJs({
  203.  
  204.   $rub = isset($_REQUEST['rub']$_REQUEST['rub''';
  205.   $todo = isset($_REQUEST['todo']$_REQUEST['todo''';
  206.  
  207.   if(ActiveItemKey($rub)) $rub ActiveItemKey($rub);
  208.   $s $rub '|' $todo;
  209.   $a $GLOBALS['multiSelect_includes'];
  210.  
  211.   if(in_array($s$a)) {
  212.     echo '<script type="text/javascript" src="../lib/js/jquery.multiSelect/jquery.multiSelect.js"></script>'.END_LINE;
  213.     echo '<script type="text/javascript" src="../lib/js/jquery.multiSelect/jquery.bgiframe.min.js"></script>'.END_LINE;
  214.     echo '<link type="text/css" rel="stylesheet" href="'.THEME_ADMIN_PATH.'/css/jquery.multiSelect.css" />'.END_LINE;
  215.   }
  216. }
  217.  
  218. /**
  219.  * IncludedatePickerJs()
  220.  * Include jQuery date Picker
  221.  * if needed
  222.  * @return void 
  223.  */
  224. function IncludedatePickerJs({
  225.  
  226.   $rub = isset($_REQUEST['rub']$_REQUEST['rub''';
  227.   $todo = isset($_REQUEST['todo']$_REQUEST['todo''';
  228.  
  229.   if(ActiveItemKey($rub)) $rub ActiveItemKey($rub);
  230.   $s $rub '|' $todo;
  231.   $a $GLOBALS['datePicker_includes'];
  232.  
  233.   if(in_array($s$a)) {
  234.     echo '<script type="text/javascript" src="../lib/js/jquery.datePicker.js"></script>'.END_LINE;
  235.     echo '<link type="text/css" rel="stylesheet" href="'.THEME_ADMIN_PATH.'/css/datePicker.css" />'.END_LINE;
  236.     echo '<script type="text/javascript" src="../lib/js/date.js"></script>'.END_LINE;
  237.     if(LANGUAGE != 'en'{
  238.       echo '<script type="text/javascript" src="'.themePath('../lib/js/date_'strtolower(LANGUAGE).'.js'THEME_ADMIN_PATH).'"></script>'END_LINE;
  239.     }
  240.   }
  241. }
  242.  
  243. /**
  244.  * SureCreateDir()
  245.  * Créer un dossier s'il n'existe pas.
  246.  * @param string $pathname 
  247.  * @param integer $perms 
  248.  * @return integer $ver_num
  249.  */
  250. function SureCreateDir($pathname$perms{
  251.   if(!file_exists($pathname)) {
  252.     return mkdir ($pathname$permstrue);
  253.   else {
  254.     return true;
  255.   }
  256. }
  257.  
  258.  
  259. /**
  260.  * SureRemoveDir()
  261.  * Supprime le contenu d'un dossier et le dossier lui-même si précisé.
  262.  *
  263.  * @return integer $ver_num
  264.  */
  265. function SureRemoveDir($dir$DeleteMe{
  266.   if(!$dh @opendir($dir)) return;
  267.   while (($obj readdir($dh))) {
  268.     if($obj=='.' || $obj=='..'continue;
  269.     if (!@unlink($dir.'/'.$obj)) SureRemoveDir($dir.'/'.$objtrue);
  270.   }
  271.   if ($DeleteMe){
  272.     closedir($dh);
  273.     @rmdir($dir);
  274.   }
  275. }
  276.  
  277. /**
  278.  * num_phpversion()
  279.  * Retourne un entier comme numéro de version PHP
  280.  *
  281.  * @return integer $ver_num
  282.  */
  283. function num_phpversion({
  284.   $ver explode'.'phpversion() );
  285.   $ver_num $ver[0$ver[1$ver[2];
  286.  
  287.   return $ver_num;
  288. }
  289.  
  290. /**
  291.  * cutText()
  292.  * Découpe un texte à une longeur donnée.
  293.  *
  294.  * @param string $content 
  295.  * @param integer $length 
  296.  * @param integer $abbr 
  297.  * @param string $end 
  298.  * @return 
  299.  */
  300. function cutText($content$length$abbr 0$end '...')
  301. {
  302.   // fix bug #16
  303.   if(function_exists('mb_substr')) $substr mb_substr($content0$lengthCHARSET);
  304.   else  $substr substr($content0$length);
  305.   if (strlen($content$length{
  306.     if ($abbr == 1$content_light "<abbr title=\"" $content "\">" $substr $end "</abbr>\n";
  307.     else $content_light $substr $end;
  308.   else $content_light $content;
  309.   return $content_light;
  310. }
  311.  
  312. /**
  313.  * cutBody()
  314.  * Renvoie un texte en 2 parties dans un tableau
  315.  *
  316.  * @param string $text 
  317.  * @return array $body
  318.  */
  319. function cutBody($text)
  320. {
  321.   $middle (strlen($text2);
  322.   $end strlen($text);
  323.   $body[0substr($text0$middle);
  324.   $body[1substr($text$middle$end);
  325.   $chaine preg_split("/(\.(<br \/>| ))/"$body[1]2);
  326.  
  327.   $body[0.= $chaine[0".";
  328.   $body[1@trim($chaine[1]);
  329.  
  330.   return $body;
  331. }
  332.  
  333. /**
  334.  * EnlargeImage()
  335.  * Miniatures; agrandissement onclick
  336.  *
  337.  * @param string $uri 
  338.  * @param string $style 
  339.  * @param string $alt_desc 
  340.  * @return string $img_link
  341.  */
  342. function EnlargeImage($uri$style ''$alt_desc '')
  343. {
  344.   list($width$height$type$attrgetimagesize($uri);
  345.   //$img_link = '<a href="' . $uri . '" title="' . _t('divers','enlarge_photo') . '" onclick="displayImage(\'' . $uri . '\', \'\', \'' . $width . '\', \'' . $height . '\'); return false;">' . END_LINE;
  346.   $img_link '<a href="' $uri '" title="' _t('divers','enlarge_photo''" class="lightbox">' END_LINE;
  347.  
  348.   $img_link .= '<img src="' get_min_name($uri'" alt="' _t('divers','enlarge_photo'' ' $alt_desc '"' $style ' />' END_LINE;
  349.   $img_link .= '</a>' END_LINE;
  350.  
  351.   return $img_link;
  352. }
  353.  
  354. /**
  355.  * formatNavTitle()
  356.  * Formatage des titres ( interface admin )
  357.  *
  358.  * @param string $content 
  359.  * @return string $content
  360.  */
  361. function formatNavTitle($content)
  362. {
  363.   $content formatText($content'2HTML');
  364.   $content cutText($content701);
  365.  
  366.   return $content;
  367. }
  368.  
  369. /**
  370.  * formatTextli()
  371.  * Formatage des listes ( interface admin )
  372.  *
  373.  * @param string $content 
  374.  * @return string $content
  375.  */
  376. function formatTextli($content)
  377. {
  378.   $content formatText($content'2HTML');
  379.   $content cutText($content651);
  380.   return $content;
  381. }
  382.  
  383. /**
  384.  * formatTitleh2()
  385.  * Formatage des titres h2 ( interface admin )
  386.  *
  387.  * @param string $content 
  388.  * @return string $content
  389.  */
  390. function formatTitleh2($content)
  391. {
  392.   $content formatText($content'2HTML');
  393.   return $content;
  394. }
  395.  
  396. /**
  397.  * formatText()
  398.  * Formatage de texte pour affichage
  399.  *
  400.  * @param  $content 
  401.  * @param string $format 
  402.  * @return string $content
  403.  */
  404. function formatText($content$format = -1)
  405. {
  406.   $content stripslashes(trim($content));
  407.   switch ($format{
  408.     case '2HTML':
  409.       $content nl2br($content);
  410.       break;
  411.     case '2FIELD':
  412.       $content htmlentities($contentENT_QUOTES'utf-8');
  413.       break;
  414.     case '2ATT':
  415.       $content htmlentities($contentENT_QUOTES'utf-8');
  416.       break;
  417.     case '2XML':
  418.       $content strip_tags($content);
  419.       break;
  420.     case '2FILE':
  421.       //$content = addslashes(trim($content));
  422.       $content htmlspecialchars($contentENT_QUOTES'utf-8');
  423.       break;
  424.     default:
  425.   }
  426.   return $content;
  427. }
  428.  
  429. /**
  430.  * ReplaceInvalidChars()
  431.  * Remplacement des caractères invalides  par leurs entités HTML
  432.  *
  433.  * @param string $str 
  434.  * @return string $valid_string
  435.  */
  436. function ReplaceInvalidChars($str)
  437. {
  438.   $htmlentities_chars array('å' => '&#338;''ú' => '&#339;',
  439.         'ä' => '&#352;''ö' => '&#353;',
  440.         'ü' => '&#376;''à' => '&#710;',
  441.         'ò' => '&#732;''ñ' => '&#8211;',
  442.         'ó' => '&#8212;''ë' => '&#8216;',
  443.         'í' => '&#8217;''Ç' => '&#8218;',
  444.         'ì' => '&#8220;''î' => '&#8221;',
  445.         'Ñ' => '&#8222;''Ü' => '&#8224;',
  446.         'á' => '&#8225;''Ö' => '&#8230;',
  447.         'â' => '&#8240;''É' => '&#402;',
  448.         'ã' => '&#8249;''õ' => '&#8250;',
  449.         'Ä' => '&#8364;''ô' => '&#8482;',
  450.         'ï' => '&#8226;''ò' => '&#732;',
  451.         'ô' => '&#8482;');
  452.  
  453.   //$valid_string = str_replace(array_keys($htmlentities_chars), array_values($htmlentities_chars), $str);
  454.   //return $valid_string;
  455.   return $str;
  456. }
  457.  
  458. function stripAccents($string{
  459.  
  460.   $search explode(",","ç,æ,œ,á,é,í,ó,ú,à,è,ì,ò,ù,ä,ë,ï,ö,ü,ÿ,â,ê,î,ô,û,å,e,i,ø,u");
  461.   $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");
  462.  
  463.   return str_replace($search$replace$string);
  464.  
  465.  
  466. }
  467.  
  468. function stripText($text{
  469.  
  470.   $text strtolower($text);
  471.  
  472.   // strip all non word chars
  473.   $text preg_replace('/\W/'' '$text);
  474.   // replace all white space sections with a dash
  475.   $text preg_replace('/\ +/''-'$text);
  476.   // trim dashes
  477.   $text preg_replace('/\-$/'''$text);
  478.   $text preg_replace('/^\-/'''$text);
  479.  
  480.   return $text;
  481. }
  482.  
  483. /**
  484.  * toStringSqlDate()
  485.  * Renvoie la date au format SQL
  486.  *
  487.  * @param string $format 
  488.  * @return string $s
  489.  */
  490. function toStringSqlDate($format 'short')
  491. {
  492.   $date_format =   array(
  493.                    'dd-mm-yyyy' => array(
  494.                           'mysql' => array('short'=> '%d-%m-%Y''long'=> 
  495.   array('12' => '%d-%m-%Y  %r''24' => '%d-%m-%Y  %T')),
  496.                         'pgsql' => array('short'=> 'DD-MM-YYYY''long'=> 
  497.   array('12' => 'DD-MM-YYYY HH12:MI:SS''24' => 'DD-MM-YYYY HH24:MI:SS'))),
  498.                     'yyyy-mm-dd' => array(
  499.                           'mysql' => array('short'=> '%Y-%m-%d''long'=> 
  500.   array('12' => '%Y-%m-%d  %r''24' => '%Y-%m-%d  %T')),
  501.                         'pgsql' => array('short'=> 'YYYY-MM-DD''long'=> 
  502.   array('12' => 'YYYY-MM-DD HH12:MI:SS''24' => 'YYYY-MM-DD HH24:MI:SS'))),
  503.  
  504.   );
  505.    
  506.   if($format == 'long'$s $date_format[DATE_FORMAT][SQL][$format][TIME_FORMAT];
  507.   else $s $date_format[DATE_FORMAT][SQL][$format];
  508.  
  509.   return $s;
  510. }
  511.  
  512.  
  513. /**
  514.  * date_compare()
  515.  * Compare 2 dates with a given operator.
  516.  * @param  $date1 
  517.  * @param  $date2 
  518.  * @param  $op 
  519.  * @return boolean 
  520.  */
  521. function date_compare($date1$date2$op{
  522.  
  523.   $date1strtotime(formatDate($date1true));
  524.   $date2strtotime(formatDate($date2true));
  525.  
  526.   switch($op{
  527.     case '>':
  528.       if($date1 $date2return true;
  529.       else return false;
  530.       break;
  531.     case '<':
  532.       if($date1 $date2return true;
  533.       else return false;
  534.     case '>=':
  535.       if($date1 >= $date2return true;
  536.       else return false;
  537.       break;
  538.     case '<=':
  539.       if($date1 <= $date2return true;
  540.       else return false;
  541.     case '==':
  542.       if($date1 == $date2return true;
  543.       else return false;
  544.     default:
  545.       return false;
  546.   }
  547. }
  548.  
  549. /**
  550.  * ln10filename()
  551.  * Build a localized filename
  552.  * according to the cuurent language
  553.  *
  554.  * @param string $file 
  555.  * @return string 
  556.  */
  557. function ln10filename($file)
  558. {
  559.  
  560.   $tmp=@explode("."$file);
  561.   $total count($tmp1;
  562.   $ext $tmp[$total];
  563.   unset($tmp[$total]);
  564.  
  565.   return @implode("."$tmp)'.' LANGUAGE'.' .$ext;
  566. }
  567.  
  568.  
  569. /**
  570.  * distInclude()
  571.  * Include the required file
  572.  * if no user file is found,
  573.  * includes the dist/ version file.
  574.  * Localized files have the priority
  575.  *
  576.  * @param string $file 
  577.  * @return void 
  578.  */
  579. function distInclude($file$default_dist)
  580. {
  581.   $l10n_file ln10filename($file);
  582.   $l10n_file_dist =  dirname($l10n_file).'/dist/'.basename($l10n_file);
  583.  
  584.   $file_dist_default =  $default_dist.'dist/'.basename($file);
  585.   $l10n_file_dist_default $default_dist.'dist/'.basename($l10n_file);
  586.  
  587.   if(file_exists($l10n_file)) {
  588.     _debug($l10n_file"override");
  589.     include_once($l10n_file);
  590.  
  591.   elseif(file_exists($l10n_file_dist))  {
  592.     _debug($l10n_file_dist"override");
  593.     include_once($l10n_file_dist);
  594.   }
  595.   elseif(file_exists($file)) {
  596.     _debug($file"override");
  597.     include_once($file);
  598.   }
  599.   elseif(file_exists($l10n_file_dist_default)) {
  600.     _debug($l10n_file_dist_default"override");
  601.     include_once($l10n_file_dist_default);
  602.   }
  603.   elseif(file_exists($file_dist_default)) {
  604.     _debug($file_dist_default"override");
  605.     include_once($file_dist_default);
  606.   }
  607.   else {
  608.     _debug(dirname($file).'/dist/'.basename($file)"override");
  609.     include_once(dirname($file).'/dist/'.basename($file));
  610.   }
  611.  
  612. }
  613.  
  614. /**
  615.  * themeInclude()
  616.  * Include the required file
  617.  * if no user file is found in theme,
  618.  * includes the default module version file.
  619.  *
  620.  * @param string $file 
  621.  * @param string $path 
  622.  * @return void 
  623.  */
  624. function themeInclude($file$path0)
  625. {
  626.   if($path == 0$path THEME_PUBLIC_PATH;
  627.   $theme_file $path.'override/'.str_replace('../'''$file);
  628.  
  629.   if(file_exists($theme_file)) {
  630.     _debug($theme_file"override");
  631.     include_once($theme_file);
  632.  
  633.   else {
  634.     _debug($file"override");
  635.     include_once($file);
  636.   }
  637.  
  638. }
  639.  
  640. /**
  641.  * themePath()
  642.  * check if a template file version exists or not
  643.  * if no user file is found in theme,
  644.  * return the default module version file.
  645.  *
  646.  * @param string $file 
  647.  * @param string $path 
  648.  * @return string 
  649.  */
  650. function themePath($file$path0)
  651. {
  652.   if($path == 0$path THEME_PUBLIC_PATH;
  653.   $theme_file $path.'override/'.str_replace('../'''$file);
  654.   if(file_exists($theme_file)) {
  655.     _debug($theme_file"override");
  656.     return $theme_file;
  657.  
  658.   else {
  659.     _debug($file"override");
  660.     return $file;
  661.   }
  662.  
  663. }
  664.  
  665. /**
  666.  * formatDate()
  667.  * Renvoie la date aux formats yyyy-mm-dd ou dd-mm-yyyy suivant le cas de départ
  668.  * Si $db == true renvoie toujours la date au format yyyy-mm-dd
  669.  *
  670.  * @param string $date 
  671.  * @param boolean $db 
  672.  * @return string $new_date
  673.  */
  674. function formatDate($date$db false)
  675. {
  676.   @list($part1$part2$part3explode('-'$date);
  677.   if(strlen($part1== 2{
  678.     $new_date $part3 '-' $part2 '-' $part1;
  679.   else {
  680.     $new_date $part1 '-' $part2 '-' $part3;
  681.   }
  682.   if($db == true{
  683.     // always return yyyy-mm-dd format
  684.     if(strlen($part1== 2{
  685.       $new_date $part3 '-' $part2 '-' $part1;
  686.     else {
  687.       $new_date $part1 '-' $part2 '-' $part3;
  688.     }
  689.   }
  690.  
  691.   return $new_date;
  692. }
  693.  
  694.  
  695. /**
  696.  * date_rfc2822()
  697.  * Format date to RFC 2822 date format
  698.  * @param string $date 
  699.  * @return string (exemple : Thu, 21 Dec 2000 16:01:07 +0200)
  700.  */
  701. function date_rfc2822($date{
  702.   if(!isNullDate($date)) {
  703.     $tmp_date formatDate($datetrue);
  704.     @list($y$m$dexplode('-'$tmp_date);
  705.     return date("r"mktime(300$m$d$y));
  706.   else {
  707.     return false;
  708.   }
  709. }
  710.  
  711.  
  712. function isNullDate($date)
  713. {
  714.   if($date == '0001-01-01' || $date == '01-01-0001'{
  715.     return true;
  716.   else return false;
  717.  
  718. }
  719.  
  720. /**
  721.  * empty_nc()
  722.  * retourne le contenu ou N.C
  723.  *
  724.  * @param string $content 
  725.  * @return string $content
  726.  */
  727. function empty_nc($content)
  728. {
  729.   $content trim($content);
  730.   if (empty($content|| isNullDate($content)) $content _t('divers','nc');
  731.  
  732.   return $content;
  733. }
  734.  
  735. /**
  736.  * empty_none()
  737.  * retourne le contenu ou 'aucun'
  738.  *
  739.  * @param string $content 
  740.  * @return string $content
  741.  */
  742. function empty_none($content)
  743. {
  744.   $content trim($content);
  745.   if (empty($content)) $content _t('divers','none');
  746.  
  747.   return $content;
  748. }
  749.  
  750. /**
  751.  * empty_none()
  752.  * retourne le contenu ou 0
  753.  *
  754.  * @param string $content 
  755.  * @return string $content
  756.  */
  757. function empty_numeric($content)
  758. {
  759.   $content trim($content);
  760.   if (empty($content)) $content 0;
  761.  
  762.   return $content;
  763. }
  764.  
  765. /**
  766.  * checkdate_validity()
  767.  * Vérifie la validité d'une date
  768.  *
  769.  * @param string $date 
  770.  * @param string $msg (optionnal)
  771.  * @return boolean true or error message (string)
  772.  */
  773. function checkdate_validity($date$msg'')
  774. {
  775.  
  776.   $date=formatDate($datetrue);
  777.   @list($year$month$dayexplode('-'$date);
  778.  
  779.   if(!preg_match('/^\d{4}-\d\d-\d\d$/'$date)) {
  780.     $msg .= _t('date','not_valid');
  781.     return $msg;
  782.   }
  783.  
  784.   if (!@checkdate($month $day $year)) return $msg _t('date','date_do_not_exist');
  785.   return true;
  786. }
  787.  
  788. /**
  789.  * display_errors()
  790.  * Affichage d'un message d'erreur utilisateur
  791.  *
  792.  * @param string $msg 
  793.  * @return void (echo)
  794.  */
  795. function display_errors($msg)
  796. {
  797.   $display_it "<div class=\"error\">\n";
  798.   $display_it .= $msg;
  799.   $display_it .= "</div>\n";
  800.   echo $display_it;
  801. }
  802.  
  803. /**
  804.  * system_error()
  805.  * Affichage d'un message d'erreur syst�me
  806.  *
  807.  * @param string $msg 
  808.  * @return void (echo)
  809.  */
  810. function system_error($msg ERROR_SYSTEM)
  811. {
  812.   $display_it "<div class=\"systemerror\">\n";
  813.   $display_it .= $msg;
  814.   $display_it .= "</div>\n";
  815.   echo $display_it;
  816.   exit;
  817. }
  818.  
  819. /**
  820.  * get_temp_name()
  821.  * obtenir le nom temporaire d'un fichier
  822.  *
  823.  * @param string $path 
  824.  * @return string $temp_path
  825.  */
  826. function get_temp_name($path)
  827. {
  828.   $short_path dirname($path);
  829.   $filename basename($path);
  830.   $temp_path $short_path "/temp_" $filename;
  831.   return $temp_path;
  832. }
  833.  
  834. /**
  835.  * get_min_name()
  836.  * obtenir le nom de la miniature d'un fichier
  837.  *
  838.  * @param string $path 
  839.  * @return string $min_path
  840.  */
  841. function get_min_name($path)
  842. {
  843.   $short_path dirname($path);
  844.   $filename basename($path);
  845.   $min_path $short_path "/min_" $filename;
  846.   return $min_path;
  847. }
  848.  
  849. /**
  850.  * ExcedMaxSize()
  851.  * Teste si une image dépasse ou non la taille autorisée (en pixels)
  852.  *
  853.  * @param string $path 
  854.  * @param integer $width_max 
  855.  * @return boolean 
  856.  */
  857. function ExcedMaxSize($path$width_max)
  858. {
  859.   list($width$height$type$attrgetimagesize($path);
  860.   if ($width $width_max || $height $width_maxreturn true;
  861.   else return false;
  862. }
  863.  
  864. /**
  865.  * GetAllPhotoUri()
  866.  * renvoie les paths des photos dans un tableau
  867.  *
  868.  * @param string $path 
  869.  * @param string $opt 
  870.  * @return array $tab
  871.  */
  872. function GetAllPhotoUri($path$opt = -1)
  873. {
  874.   if (empty($path)) return false;
  875.   else {
  876.     $tab explode('|'$path);
  877.     if ($opt == 'min'array_walk($tab'get_min_name');
  878.     return $tab;
  879.   }
  880. }
  881.  
  882. /**
  883.  * cancel_button()
  884.  * génére un bouton de retour
  885.  *
  886.  * @param  $back_uri 
  887.  * @return string 
  888.  */
  889. function cancel_button($back_uri)
  890. {
  891.   return '<input name="annuler" type="button" value="' _t('btn','annul''" class="button" id="annuler" onclick="window.location=\'' $back_uri '\';" />';
  892. }
  893.  
  894. /**
  895.  * GetDisplayUserRight()
  896.  * renvoie les droits d'un utilisateur
  897.  *
  898.  * @param string $indice 
  899.  * @param string $module 
  900.  * @return string 
  901.  */
  902. function GetDisplayUserRight($indice$module = -1)
  903. {
  904.   $indice strtoupper($indice);
  905.   if ($indice == 'U'return _t('user','norights');
  906.   if ($indice == 'A'return _t('user','adminrights');
  907.   if ($indice == 'O' && $module == 'dashboard'return _t('user','managerrights');
  908.   if ($indice == 'O' && $module == 'workshop'return _t('user','animatorrights');
  909.   if ($indice == 'O' && ($module != 'workshop' && $module != 'dashboard')) return _t('user','redactorrights');
  910. }
  911.  
  912. /**
  913.  * Display_linkin_page()
  914.  *
  915.  * @param array $table_link 
  916.  * @param integer $total 
  917.  * @param integer $debut 
  918.  * @param integer $pas 
  919.  * @return void 
  920.  ***/
  921. function Display_linkin_page($table_link$total$debut$pas SELECT_LIMIT)
  922. {
  923.   $result ceil($total $pas);
  924.   if ($result <= 1return '&nbsp;';
  925.   else {
  926.     $link '<div class="lienliste">'.END_LINE;
  927.     $link .= '&lt; &lt; ';
  928.     $sep='';
  929.     for($i 0$i $result$i++{
  930.       $current_pos ($pas $i);
  931.       if ($debut == $current_pos$link .= $sep."<span>" ($i 1"</span> \n";
  932.       else {
  933.         $array_pos array ('debut' => $current_pos);
  934.         $new_table_link array_merge ($table_link$array_pos);
  935.         $link .= $sep.'<a href="'HrefMaker($new_table_link'">' ($i 1'</a>'.END_LINE;
  936.       }
  937.       $sep=' | ';
  938.     }
  939.     $link .= ' &gt; &gt;';
  940.     $link .= '</div>'.END_LINE;
  941.     echo $link;
  942.   }
  943. }
  944.  
  945. /**
  946.  * linkin_page()
  947.  * création d'un navigateur de pages numérotées
  948.  *
  949.  * @param string $string_uri 
  950.  * @param integer $total 
  951.  * @param integer $debut 
  952.  * @param integer $pas 
  953.  * @return string $link
  954.  */
  955. function linkin_page($string_uri$total$debut$pas SELECT_LIMIT)
  956. {
  957.   $result ceil($total $pas);
  958.   if ($result <= 1return '&nbsp;';
  959.   else {
  960.     if (strpos($string_uri'?'=== false$string_uri .= '?';
  961.     else $string_uri .= '&amp;';
  962.     $link '<div class="lienliste">';
  963.     for($i 0$i $result$i++{
  964.       $current_pos ($pas $i);
  965.       if ($debut == $current_pos$link .= "<span>" ($i 1"</span> \n";
  966.       else $link .= "<a href=\"" $string_uri "debut=" $current_pos "\">" ($i 1"</a> \n";
  967.     }
  968.     $link .= '</div>';
  969.     return $link;
  970.   }
  971. }
  972.  
  973. /**
  974.  * display_statut()
  975.  * renvoie le statut en pleines lettres
  976.  *
  977.  * @param string $statut 
  978.  * @return string $result
  979.  */
  980. function display_statut($statut)
  981. {
  982.   switch ($statut{
  983.     case 'P':
  984.       $result _t('statut','public');
  985.       break;
  986.     case 'D':
  987.       $result _t('statut','draft');
  988.       break;
  989.     case 'E':
  990.       $result _t('statut','E');
  991.       break;
  992.     case 'AA':
  993.       $result _t('statut','AA');
  994.       break;
  995.     case 'PA':
  996.       $result _t('statut','PA');
  997.       break;
  998.     case 'C':
  999.       $result _t('statut','C');
  1000.       break;
  1001.     case 'U':
  1002.       $result _t('statut','U');
  1003.       break;
  1004.     case 'O':
  1005.       $result _t('statut','O');
  1006.       break;
  1007.     case 'A':
  1008.       $result _t('statut','A');
  1009.       break;
  1010.     case 'W':
  1011.       $result _t('statut','W');
  1012.       break;
  1013.     default:
  1014.       $result _t('statut','public');
  1015.   }
  1016.   return $result;
  1017. }
  1018.  
  1019. /**
  1020.  * linkin_content()
  1021.  * Cherche les liens et emails dans du contenu -> linkage
  1022.  *
  1023.  * @param string $content 
  1024.  * @param string $option 
  1025.  * @return string $content
  1026.  */
  1027. function linkin_content($content$option 'ALL')
  1028. {
  1029.   if(defined('AUTO_LINK'&& AUTO_LINK == 1)
  1030.   {
  1031.     if(defined('RICH_TEXT_EDITOR'&& RICH_TEXT_EDITOR == (string) 0{
  1032.       if ($option == 'ALL' || $option == 'MAIL'{
  1033.         $content eregi_replace("( |<br />)+([_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)+)"'\\1<a href="mailto:\\2">\\2</a>'$content);
  1034.       }
  1035.       if ($option == 'ALL' || $option == 'LINK'{
  1036.         $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);
  1037.       }
  1038.     }
  1039.   }
  1040.  
  1041.   return $content;
  1042. }
  1043.  
  1044. /**
  1045.  * QuickBoxNow()
  1046.  * Génération de la quickbox
  1047.  *
  1048.  * @param string $module 
  1049.  * @param string $h1 
  1050.  * @param string $liste 
  1051.  * @param string $suffixclass 
  1052.  * @return string $quickbox
  1053.  */
  1054. function QuickBoxNow($module$h1$liste$suffixclass '')
  1055. {
  1056.   $quickbox "<div class=\"entete\">\n<div class=\"qb_ico\" id=\"qbico" $suffixclass "\" title=\"" $module "\"></div>\n";
  1057.   $quickbox .= "<div class=\"quickbox\" id=\"qbbg" $suffixclass "\">\n";
  1058.   $quickbox .= "<h1>" $h1 "</h1>\n";
  1059.   $quickbox .= "<ul>";
  1060.   $quickbox .= $liste;
  1061.   $quickbox .= "</ul>";
  1062.   $quickbox .= "</div>";
  1063.   $quickbox .= "</div>";
  1064.  
  1065.   return $quickbox;
  1066. }
  1067.  
  1068. /**
  1069.  * ReloadIndex()
  1070.  * Chargement de l'index après destruction de sessions
  1071.  *
  1072.  * @param string $item 
  1073.  * @return void 
  1074.  */
  1075. function ReloadIndex($item)
  1076. {
  1077.   switch ($item{
  1078.     case 'public':
  1079.       return header("Location: ../public/logout.php");
  1080.       break;
  1081.     case 'admin':
  1082.       return header("Location: ../admin/logout.php");
  1083.       break;
  1084.   }
  1085. }
  1086.  
  1087. /**
  1088.  * getmicrotime()
  1089.  * renvoie le temps en microsecondes
  1090.  *
  1091.  * @return float 
  1092.  */
  1093. function getmicrotime()
  1094. {
  1095.   list($usec$secexplode(" "microtime());
  1096.   return ((float)$usec + (float)$sec);
  1097. }
  1098.  
  1099. /**
  1100.  * availableLanguages()
  1101.  * Return available languages
  1102.  * @return array 
  1103.  ***/
  1104. function availableLanguages({
  1105.   $a array();
  1106.   if ($handle opendir('../languages/')) {
  1107.       while (false !== ($file readdir($handle))) {
  1108.           if ($file != "." && $file != ".." && $file != ".svn"{
  1109.               array_push($a$file);
  1110.           }
  1111.       }
  1112.       closedir($handle);
  1113.   }
  1114.  
  1115.   return $a;
  1116. }
  1117.  
  1118.  
  1119.  
  1120. /**
  1121.  * GenerateXhtmlPage()
  1122.  *
  1123.  * @param $string 
  1124.  * @param integer $time 
  1125.  * @param unknown $redirect 
  1126.  * @return 
  1127.  ***/
  1128. function GenerateXhtmlPage($string$time 2$redirect SITE_CITY_URL)
  1129. {
  1130.  
  1131.  
  1132.   $page  '<?xml version="1.0" encoding="ISO-8859-1" xml:lang="' LANGUAGE '"?>' END_LINE;
  1133.   $page .= '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">' END_LINE;
  1134.   $page .= '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="' LANGUAGE '">' END_LINE;
  1135.   $page .= '<head>' END_LINE;
  1136.   $page .= '<meta http-equiv="content-type" content="text/html;charset=' CHARSET '" />' END_LINE;
  1137.   $page .= '<meta http-equiv="content-langage" content="' CHARSET '" />' END_LINE;
  1138.   $page .= '<meta http-equiv="refresh" content="' $time ';url=' $redirect '">' END_LINE;
  1139.   $page .= '<link rel="icon" type="image/gif" href="' .THEME_ADMIN_PATH'images/favicon.gif" />' END_LINE;
  1140.   $page .= '<title>'.SITE_CITY_NAME.'</title>' END_LINE;
  1141.   $page .= '</head>' END_LINE;
  1142.   $page .= '<body>' END_LINE;
  1143.   $page .= '<div class="info" style="margin-top:10em">'.$string.END_LINE;
  1144.   $page .= '<br />';
  1145.   $page .= sprintf_t('divers','redirect_string')$redirect$time);
  1146.   $page .= '</div>'END_LINE;
  1147.   $page .= '</body>' END_LINE;
  1148.   $page .= '</html>' END_LINE;
  1149.  
  1150.   return $page;
  1151. }
  1152.  
  1153. /**
  1154.  * debugEnabled
  1155.  * Display a debug alert
  1156.  * 
  1157.  * @return void 
  1158.  ***/
  1159. function debugEnabled({
  1160.   if(defined('MOD_DEBUG'&& MOD_DEBUG == true{
  1161.     echo '<div id="debug-enabled">DEBUG_MOD '._t('debug''enabled'.'</div>';
  1162.   }
  1163. }
  1164.  
  1165. /**
  1166.  * _debug()
  1167.  * Display a debug message in html code
  1168.  * @param $string 
  1169.  * @return void 
  1170.  ***/
  1171. function _debug($string$mode)
  1172. {
  1173.   if(defined('MOD_DEBUG'&& MOD_DEBUG == true)
  1174.   {
  1175.     if($mode == 'override' && defined('TYPE_DEBUG'&& TYPE_DEBUG == "override")
  1176.     {
  1177.     if(defined('MOD_DEBUG_HIDDEN'&& MOD_DEBUG_HIDDEN == trueecho "<!-- "else echo "<p class=\"debug\">";
  1178.     echo $string;
  1179.     if(defined('MOD_DEBUG_HIDDEN'&& MOD_DEBUG_HIDDEN == trueecho " -->"else echo END_LINE."</p>";
  1180.     }
  1181.     }
  1182. }
  1183.  
  1184. /**
  1185.  * check4newVersion()
  1186.  * Display a link to download new version if available
  1187.  * @return string 
  1188.  ***/
  1189. function check4newVersion({
  1190.   try{
  1191.     if(!@$rss=simplexml_load_file(SITE_LINEA_URL.'/linea_version.xml')){
  1192.       throw new Exception('Version : xml file was not found');
  1193.     }
  1194.  
  1195.     $latest_version str_pad(str_replace('.'''$rss->num)4'0');
  1196.     $current_version str_pad(str_replace('.'''LINEA_VERSION)4'0');
  1197.  
  1198.     if((integer)$latest_version > (integer)$current_version{
  1199.       $update '<div id="version-check">'._t('check_update','search').' : <a href="'.(string)$rss->link.'">'.sprintf(_t('check_update','dl')$rss->num).'</a></div>';
  1200.     else {
  1201.       $update '<div id="version-check">'._t('check_update','search').' : '._t('check_update','ok').'</div>';
  1202.     }
  1203.   }
  1204.   catch(Exception $e){
  1205.     $update $e->getMessage();
  1206.   }
  1207.   
  1208.   return $update;
  1209. }
  1210. ?>

Documentation generated on Fri, 16 Oct 2009 09:35:39 +0200 by phpDocumentor 1.4.1