Gestion simplissime des Todo

crabs_todo-2.0 ©2008-2011 - Christophe Cazajus (crabs-mettre_le_signe_at-crabs-world.com)

~~ / LIB / util.php
Makefile util.php mysql.php xml.php jquery.js no_gnu_file
    1 <?php
    2 //
    3 // =============================================================================
    4 //  crabs_todo-2.0 : Gestion simplissime des Todo
    5 //  Copyright (C) 2008-2011 : Christophe Cazajus (crabs-mettre_le_signe_at-crabs-world.com)
    6 //
    7 //  Ce source fait partie d'un projet logiciel libre. Vous pouvez le distribuer
    8 //  et/ou le modifier en respectant les termes de la GNU General Public License
    9 //  version 2 ou (suite a votre propre choix) une version ulterieure.
   10 //
   11 //  Ce programme est distribue dans l'espoir qu'il puisse etre utile, mais
   12 //  sans aucune garantie, meme si il est associe a un produit qui vous en
   13 //  propose une. Conformez-vous a la GNU General Public License pour avoir
   14 //  plus de precisions.
   15 //
   16 //  L'auteur ne peut etre tenu responsable de l'utilisation faite des
   17 //  composantes associees a ce projet (en partie ou dans leur totalite).
   18 //
   19 //  Une copie du fichier de la GNU GPL est fournie dans le repertoire DOC
   20 //  de ce projet sous le nom gnu_gpl.txt
   21 //
   22 // =============================================================================
   23 //
   24 // Cette classe fait partie du projet crabs_phplib 1.0
   25 // Timestamp [[GPLLIB_TIMESTAMP=20101218-122117]]
   26 
   27 function relative2absolute( $r=".", $only_dir=true )
   28     {
   29     $svr = $_SERVER['HTTP_HOST'] ;
   30     if ( $r{0} == '/' )
   31         $ts = array() ;
   32     else
   33         {
   34         $script = $_SERVER['PHP_SELF'] ;
   35         $ts = explode( '/', $script ) ;
   36         array_pop( $ts ) ; // supprimer le nom du script
   37         array_shift( $ts ) ; // supprimer le vide initial
   38         }
   39     $rs = explode( '/', $r ) ;
   40     for( $i=0 ; $i<count($rs); $i++ )
   41         {
   42         $p = $rs[$i] ;
   43         if ( $p == '' ) continue ;
   44         if ( $p == '.' ) continue ;
   45         if ( $p == '..' )
   46             {
   47             if( count( $ts ) > 0 ) { array_pop( $ts ) ; }
   48             continue ;
   49             }
   50         array_push( $ts, $p ) ;
   51         }
   52     $abs = implode( '/', $ts ) ;
   53     if ( $only_dir ) return "/$abs" ;
   54     return "http://$svr/$abs" ;
   55     }
   56 
   57 function toMySQL( $t )
   58     {
   59     return addslashes( $t ) ;
   60     }
   61 
   62 function fromMySQL( $t )
   63     {
   64     if ( get_magic_quotes_runtime() )
   65         $texte = stripslashes( $t ) ;
   66     else
   67         $texte = $t ;
   68     return $texte ;
   69     }
   70 function fromPOST( $t, $defaut=false )
   71     {
   72     if ( !array_key_exists( $t, $_POST ) ) return $defaut ;
   73     if ( get_magic_quotes_gpc() )
   74         $texte = stripslashes( $_POST[$t] ) ;
   75     else
   76         $texte = $_POST[$t] ;
   77     return $texte ;
   78     }
   79 
   80 function fromGET( $t, $defaut=false )
   81     {
   82     if ( !array_key_exists( $t, $_GET ) ) return $defaut ;
   83     if ( get_magic_quotes_gpc() )
   84         $texte = stripslashes( $_GET[$t] ) ;
   85     else
   86         $texte = $_GET[$t] ;
   87     return $texte ;
   88     }
   89 
   90 function toXML( $t, $is_attribute=false )
   91     {
   92     $transform = array( '<'=>'&lt;', '>'=>'&gt;', '&'=>'&amp;' ) ;
   93     if ( $is_attribute ) $transform['"'] = "&quot;" ;
   94     return strtr( $t, $transform ) ;
   95     }
   96 
   97 function fromJS( $t )
   98     {
   99     return iconv( "UTF-8", "ISO-8859-15", $t ) ;
  100     }
  101 
  102 function toJS( $t )
  103     {
  104     return iconv( "ISO-8859-15", "UTF-8", $t ) ;
  105     }
  106 
  107 function dateFromSaisie( $date )
  108     {
  109     $d = explode( '/', $date ) ;
  110     $c = count( $d ) ;
  111     if ( $c < 1 ) $j = (int) date('d') ; else $j = (int) $d[0] ;
  112     if ( $c < 2 ) $m = (int) date('m') ; else $m = (int) $d[1] ;
  113     if ( $c < 3 ) $a = (int) date('Y') ; else $a = (int) $d[2] ;
  114     if ( $a < 70 ) $a+=2000 ;
  115     if ( ( $a>=70 ) && ( $a < 100 ) ) $a+=1900 ;
  116     if ( ( $j<1 ) || ( $j>31 ) ) $j = date('d') ;
  117     if ( ( $m<1 ) || ( $m>12 ) ) $m = date('m') ;
  118     return sprintf( "%02d/%02d/%04d", $j, $m, $a ) ;
  119     }
  120 function toMysqlDate( $date )
  121     {
  122     list( $d, $m, $a ) = explode( '/', $date ) ;
  123     return $a.'-'.$m.'-'.$d ;
  124     }
  125 
  126 function espaceInsecable( $txt )
  127     {
  128     static $meta = array(
  129         ' ?'=>'&#160;?',
  130         ' !'=>'&#160;!',
  131         ' :'=>'&#160;:',
  132         ' ;'=>'&#160;;',
  133         '( '=>'(&#160;',
  134         ' )'=>'&#160;)'
  135         ) ;
  136     return strtr( $txt, $meta ) ;
  137     }
  138 
  139 // Inspired from
  140 // http://www.thefutureoftheweb.com/blog/use-accept-language-header
  141 function acceptLang()
  142     {
  143     $langs = array() ;
  144     if ( isset( $_SERVER['HTTP_ACCEPT_LANGUAGE'] ) )
  145         {
  146         // break up string into pieces (languages and q factors)
  147         preg_match_all(
  148             '/([a-z]{1,8}(-[a-z]{1,8})?)\s*(;\s*q\s*=\s*(1|0\.[0-9]+))?/i',
  149             $_SERVER['HTTP_ACCEPT_LANGUAGE'],
  150             $lang_parse
  151             ) ;
  152 
  153         if (count($lang_parse[1]))
  154             {
  155             // create a list like "en" => 0.8
  156             $langs_lcl = array_combine($lang_parse[1], $lang_parse[4]);
  157 
  158             // set default to 1 for any without q factor
  159             foreach ($langs_lcl as $lang => $val)
  160                 {
  161                 if ($val === '') $val = 1;
  162                 $langs[ strtr( $lang, '/', '-' ) ] = $val ;
  163                 }
  164 
  165             // sort list based on value
  166             arsort($langs, SORT_NUMERIC);
  167             }
  168         }
  169     return $langs ;
  170     }
  171 
  172 ?>
Makefile util.php mysql.php xml.php jquery.js no_gnu_file
~~ / LIB / util.php

Haut de page

Contacter crabs

Date de génération : 22/09/2011 21:49