Crabs Contents Management System

crabs_cms-1.0.4 ©2006-2008 - Christophe Cazajus (crabs-mettre_le_signe_at-crabs-world.com)

~~ / LIB / util.php
Makefile util.php mysql.php xml.php xml_session.php only_session.php xml_publie.php generer.php forum.php xml_post_session.php xml_post_only_session.php httprequest.js
    1 <?php
    2 //
    3 // =============================================================================
    4 //  crabs_cms-1.0.4 : Crabs Contents Management System
    5 //  Copyright (C) 2006-2008 : 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 
   25 function relative2absolute( $r=".", $only_dir=true )
   26     {
   27     $svr = $_SERVER['HTTP_HOST'] ;
   28     if ( $r{0} == '/' )
   29         $ts = array() ;
   30     else
   31         {
   32         $script = $_SERVER['PHP_SELF'] ;
   33         $ts = explode( '/', $script ) ;
   34         array_pop( $ts ) ; // supprimer le nom du script
   35         array_shift( $ts ) ; // supprimer le vide initial
   36         }
   37     $rs = explode( '/', $r ) ;
   38     for( $i=0 ; $i<count($rs); $i++ )
   39         {
   40         $p = $rs[$i] ;
   41         if ( $p == '' ) continue ;
   42         if ( $p == '.' ) continue ;
   43         if ( $p == '..' )
   44             {
   45             if( count( $ts ) > 0 ) { array_pop( $ts ) ; }
   46             continue ;
   47             }
   48         array_push( $ts, $p ) ;
   49         }
   50     $abs = implode( '/', $ts ) ;
   51     if ( $only_dir ) return "/$abs" ;
   52     return "http://$svr/$abs" ;
   53     }
   54 
   55 function toMySQL( $t )
   56     {
   57     return addslashes( $t ) ;
   58     }
   59 
   60 function fromMySQL( $t )
   61     {
   62     if ( get_magic_quotes_runtime() )
   63         $texte = stripslashes( $t ) ;
   64     else
   65         $texte = $t ;
   66     return $texte ;
   67     }
   68 function fromPOST( $t, $defaut=false )
   69     {
   70     if ( !array_key_exists( $t, $_POST ) ) return $defaut ;
   71     if ( get_magic_quotes_gpc() )
   72         $texte = stripslashes( $_POST[$t] ) ;
   73     else
   74         $texte = $_POST[$t] ;
   75     return $texte ;
   76     }
   77 
   78 function fromGET( $t, $defaut=false )
   79     {
   80     if ( !array_key_exists( $t, $_GET ) ) return $defaut ;
   81     if ( get_magic_quotes_gpc() )
   82         $texte = stripslashes( $_GET[$t] ) ;
   83     else
   84         $texte = $_GET[$t] ;
   85     return $texte ;
   86     }
   87 
   88 function toXML( $t, $is_attribute=false )
   89     {
   90     $transform = array( '<'=>'&lt;', '>'=>'&gt;', '&'=>'&amp;' ) ;
   91     if ( $is_attribute ) $transform['"'] = "&quot;" ;
   92     return strtr( $t, $transform ) ;
   93     }
   94 
   95 function fromJS( $t )
   96     {
   97     return iconv( "UTF-8", "ISO-8859-15", $t ) ;
   98     }
   99 
  100 function toJS( $t )
  101     {
  102     return iconv( "ISO-8859-15", "UTF-8", $t ) ;
  103     }
  104 
  105 function toDateTime( $date, $heure )
  106     {
  107     list( $hh, $mm, $ss ) = explode( ':', $heure ) ;
  108     list( $d, $m, $a ) = explode( '/', $date ) ;
  109     return $a.'/'.$m.'/'.$a.' '.$hh.':'.$mm ;
  110     }
  111 function toMysqlDateTime( $date, $heure )
  112     {
  113     list( $hh, $mm, $ss ) = explode( ':', $heure ) ;
  114     list( $d, $m, $a ) = explode( '/', $date ) ;
  115     return $a.'-'.$m.'-'.$d.' '.$hh.':'.$mm.':'.$ss ;
  116     }
  117 function mysqlToFr( $dt )
  118     {
  119     list( $date, $heure ) = explode(' ', $dt ) ;
  120     list( $a, $m, $j ) = explode( '-', $date ) ;
  121     list( $hh, $mm, $ss ) = explode( ':', $heure ) ;
  122     return $a.'/'.$m.'/'.$a.' '.$hh.':'.$mm ;
  123     }
  124 
  125 function espaceInsecable( $txt )
  126     {
  127     static $meta = array(
  128         ' ?'=>'&#160;?',
  129         ' !'=>'&#160;!',
  130         ' :'=>'&#160;:',
  131         ' ;'=>'&#160;;',
  132         '( '=>'(&#160;',
  133         ' )'=>'&#160;)'
  134         ) ;
  135     return strtr( $txt, $meta ) ;
  136     }
  137 ?>
Makefile util.php mysql.php xml.php xml_session.php only_session.php xml_publie.php generer.php forum.php xml_post_session.php xml_post_only_session.php httprequest.js
~~ / LIB / util.php

Haut de page

Contacter crabs

Date de génération : 24/10/2008 21:34