crabs_web_event-2.0 ©2005-2006 - Christophe CAZAJUS (crabs-mettre_le_signe_at-crabs-world.com)
1 <?php 2 // 3 // ============================================================================= 4 // crabs_web_event-2.0 : Site PHP+MySQL Evénementiel 5 // Copyright (C) 2005-2006 : 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 demoMode( $racine ) 26 { 27 clearstatcache() ; 28 return file_exists( $racine.'/demo' ) ; 29 } 30 31 function hostedMode( $racine ) 32 { 33 clearstatcache() ; 34 return file_exists( $racine.'/hosted' ) ; 35 } 36 function enTravauxMode( $racine, $what='obtenir' ) 37 { 38 clearstatcache() ; $f = $racine.'/en_travaux' ; 39 switch( $what ) 40 { 41 case 'activer' : return touch( $f ) ; 42 case 'desactiver' : return unlink( $f ) ; 43 default : return file_exists( $racine.'/en_travaux' ) ; 44 } 45 } 46 47 function relative2absolute( $r="." ) 48 { 49 $svr = $_SERVER['HTTP_HOST'] ; 50 $prt = $_SERVER['SERVER_PORT'] ; 51 if ( $r{0} == '/' ) 52 $ts = array() ; 53 else 54 { 55 $script = $_SERVER['PHP_SELF'] ; 56 $ts = explode( '/', $script ) ; 57 array_pop( $ts ) ; // supprimer le nom du script 58 array_shift( $ts ) ; // supprimer le vide initial 59 } 60 $rs = explode( '/', $r ) ; 61 for( $i=0 ; $i<count($rs); $i++ ) 62 { 63 $p = $rs[$i] ; 64 if ( $p == '' ) continue ; 65 if ( $p == '.' ) continue ; 66 if ( $p == '..' ) 67 { 68 if( count( $ts ) > 0 ) { array_pop( $ts ) ; } 69 continue ; 70 } 71 array_push( $ts, $p ) ; 72 } 73 $abs = implode( '/', $ts ) ; 74 return "http://$svr:$prt/$abs" ; 75 } 76 77 function toMySQL( $t ) 78 { 79 return addslashes( $t ) ; 80 } 81 82 function fromMySQL( $t ) 83 { 84 if ( get_magic_quotes_runtime() ) 85 $texte = stripslashes( $t ) ; 86 else 87 $texte = $t ; 88 return $texte ; 89 } 90 function fromPOST( $t, $defaut=false ) 91 { 92 if ( !array_key_exists( $t, $_POST ) ) return $defaut ; 93 if ( get_magic_quotes_gpc() ) 94 $texte = stripslashes( $_POST[$t] ) ; 95 else 96 $texte = $_POST[$t] ; 97 return $texte ; 98 } 99 100 function fromGET( $t, $defaut=false ) 101 { 102 if ( !array_key_exists( $t, $_GET ) ) return $defaut ; 103 if ( get_magic_quotes_gpc() ) 104 $texte = stripslashes( $_GET[$t] ) ; 105 else 106 $texte = $_GET[$t] ; 107 return $texte ; 108 } 109 110 function toXML( $t, $is_attribute=false ) 111 { 112 $transform = array( '<'=>'<', '>'=>'>', '&'=>'&' ) ; 113 if ( $is_attribute ) $transform['"'] = """ ; 114 return strtr( $t, $transform ) ; 115 } 116 117 function dateFromSaisie( $date ) 118 { 119 $d = explode( '/', $date ) ; 120 $c = count( $d ) ; 121 if ( $c < 1 ) $j = (int) date('d') ; else $j = (int) $d[0] ; 122 if ( $c < 2 ) $m = (int) date('m') ; else $m = (int) $d[1] ; 123 if ( $c < 3 ) $a = (int) date('Y') ; else $a = (int) $d[2] ; 124 if ( $a < 70 ) $a+=2000 ; 125 if ( ( $a>=70 ) && ( $a < 100 ) ) $a+=1900 ; 126 if ( ( $j<1 ) || ( $j>31 ) ) $j = date('d') ; 127 if ( ( $m<1 ) || ( $m>12 ) ) $m = date('m') ; 128 return sprintf( "%02d/%02d/%04d", $j, $m, $a ) ; 129 } 130 131 function heureFromSaisie( $heure ) 132 { 133 $h = explode( ':', $heure ) ; 134 $c = count( $h ) ; 135 if ( $c < 1 ) $hh = 0 ; else $hh = (int) $h[0] ; 136 if ( $c < 2 ) $mm = 0 ; else $mm = (int) $h[1] ; 137 if ( $c < 3 ) $ss = 0 ; else $ss = (int) $h[2] ; 138 if ( $hh<0 ) $hh=0 ; if ( $hh>23 ) $hh=23 ; 139 if ( $mm<0 ) $mm=0 ; if ( $mm>59 ) $mm=59 ; 140 if ( $ss<0 ) $ss=0 ; if ( $ss>59 ) $ss=59 ; 141 return sprintf( "%02d:%02d:%02d", $hh, $mm, $ss ) ; 142 } 143 144 function toDateTime( $date, $heure ) 145 { 146 list( $hh, $mm, $ss ) = explode( ':', $heure ) ; 147 list( $d, $m, $a ) = explode( '/', $date ) ; 148 return $a.'/'.$m.'/'.$a.' '.$hh.':'.$mm ; 149 } 150 function toMysqlDateTime( $date, $heure ) 151 { 152 list( $hh, $mm, $ss ) = explode( ':', $heure ) ; 153 list( $d, $m, $a ) = explode( '/', $date ) ; 154 return $a.'-'.$m.'-'.$d.' '.$hh.':'.$mm.':'.$ss ; 155 } 156 function mysqlToFr( $dt ) 157 { 158 list( $date, $heure ) = explode(' ', $dt ) ; 159 list( $a, $m, $j ) = explode( '-', $date ) ; 160 list( $hh, $mm, $ss ) = explode( ':', $heure ) ; 161 return $a.'/'.$m.'/'.$a.' '.$hh.':'.$mm ; 162 } 163 function mysqlToLiteral( $mdt, $maj=false ) 164 { 165 static $cmois, $cjour, $premier = false ; 166 if ( $premier == false ) 167 { 168 $cmois=array('','janvier','février','mars','avril','mai','juin', 169 'juillet','août','semptembre','octobre','novembre','décembre' ) ; 170 $cjour=array('dimanche','lundi','mardi','mercredi','jeudi','vendredi', 171 'samedi'); 172 $mjour=array('Dimanche','Lundi','Mardi','Mercredi','Jeudi','Vendredi', 173 'Samedi'); 174 $premier = '1<sup>er</sup>' ; 175 } 176 list( $date, $heure ) = explode(' ', $mdt ) ; 177 list( $a, $m, $j ) = explode( '-', $date ) ; 178 list( $hh, $mm, $ss ) = explode( ':', $heure ) ; 179 $t = mktime ( $hh, $mm, $ss, $m, $j, $a ) ; 180 $js = date( 'w', $t ) ; 181 $m=$m+0 ; $j=$j+0 ; $hh=$hh+0 ; 182 $r = array() ; 183 if ($maj) $r[] = $mjour[ $js ] ; else $r[] = $cjour[ $js ] ; 184 if ( $j == 1 ) $r[]=$premier; else $r[]=$j ; 185 $r[] = $cmois[ $m ] ; 186 $r[] = $a ; 187 $r[] = 'à' ; 188 $r[] = $hh.'h'.$mm ; 189 return implode( ' ', $r ) ; 190 } 191 function templateExtract( $page, $var, $val ) 192 { 193 $ret = preg_match("/<!--TMPL\|$var\|$val\|(.*)\|-->/", $page, $inc ) ; 194 if ( $ret != false ) 195 return $inc[1]; 196 else 197 return "TMPL:$var|$val absent...\n" ; 198 } 199 200 ?>
Date de génération : 22/09/2011 21:48