[ Index ] |
|
Code source de Dotclear 1.2.5 |
1 <?php 2 # ***** BEGIN LICENSE BLOCK ***** 3 # This file is part of DotClear. 4 # Copyright (c) 2004 Olivier Meunier and contributors. All rights 5 # reserved. 6 # 7 # DotClear is free software; you can redistribute it and/or modify 8 # it under the terms of the GNU General Public License as published by 9 # the Free Software Foundation; either version 2 of the License, or 10 # (at your option) any later version. 11 # 12 # DotClear is distributed in the hope that it will be useful, 13 # but WITHOUT ANY WARRANTY; without even the implied warranty of 14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 # GNU General Public License for more details. 16 # 17 # You should have received a copy of the GNU General Public License 18 # along with DotClear; if not, write to the Free Software 19 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 20 # 21 # ***** END LICENSE BLOCK ***** 22 23 class util 24 { 25 # Retourne une paire de l'élément suivant ou précédent d'un tableau à 26 # un indice donné 27 function getNextPrev($array,$key,$mode) 28 { 29 $keys = array_keys($array); 30 $values = array_values($array); 31 $p = array_flip($keys); 32 $pos = !empty($p[$key]) ? $p[$key] : 0; 33 34 35 if($mode == 'next') { 36 return ($pos+1 < count($array)) ? array($keys[$pos+1] => $values[$pos+1]) : NULL; 37 } else { 38 return ($pos > 0) ? array($keys[$pos-1] => $values[$pos-1]) : NULL; 39 } 40 } 41 42 # Obtenir l'host complet 43 function getHost() 44 { 45 $server_name = explode(':',$_SERVER['HTTP_HOST']); 46 $server_name = $server_name[0]; 47 if (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') 48 { 49 $scheme = 'https'; 50 $port = ($_SERVER['SERVER_PORT'] != '443') ? ':'.$_SERVER['SERVER_PORT'] : ''; 51 } 52 else 53 { 54 $scheme = 'http'; 55 $port = ($_SERVER['SERVER_PORT'] != '80') ? ':'.$_SERVER['SERVER_PORT'] : ''; 56 } 57 58 return $scheme.'://'.$server_name.$port; 59 } 60 61 # Obtenir l'url complète de la page 62 function getPageURL($uri=NULL) 63 { 64 if ($uri == NULL) { 65 $uri = htmlspecialchars($_SERVER['REQUEST_URI']); 66 } 67 68 return util::getHost().$uri; 69 } 70 71 # Couper une chaîne aux espaces 72 function cutString($str,$l) 73 { 74 $s = preg_split('/([\s]+)/',$str,-1,PREG_SPLIT_DELIM_CAPTURE); 75 76 $res = ''; 77 $L = 0; 78 79 if (strlen($s[0]) >= $l) { 80 return substr($s[0],0,$l); 81 } 82 83 foreach ($s as $v) 84 { 85 $L = $L+strlen($v); 86 87 if ($L > $l) { 88 break; 89 } else { 90 $res .= $v; 91 } 92 } 93 94 return trim($res); 95 } 96 97 # Converti une chaîne Latin1 en UTF-8 et effectue la translation 98 # des caractères litigieux. 99 function latin1utf8($str) 100 { 101 $conv = array( 102 chr(194).chr(128) => chr(226).chr(130).chr(172), 103 chr(194).chr(130) => chr(226).chr(128).chr(154), 104 chr(194).chr(131) => chr(198).chr(146), 105 chr(194).chr(132) => chr(226).chr(128).chr(158), 106 chr(194).chr(133) => chr(226).chr(128).chr(166), 107 chr(194).chr(134) => chr(226).chr(128).chr(160), 108 chr(194).chr(135) => chr(226).chr(128).chr(161), 109 chr(194).chr(136) => chr(203).chr(134), 110 chr(194).chr(137) => chr(226).chr(128).chr(176), 111 chr(194).chr(138) => chr(197).chr(160), 112 chr(194).chr(139) => chr(226).chr(128).chr(185), 113 chr(194).chr(140) => chr(197).chr(146), 114 chr(194).chr(145) => chr(226).chr(128).chr(152), 115 chr(194).chr(146) => chr(226).chr(128).chr(153), 116 chr(194).chr(147) => chr(226).chr(128).chr(156), 117 chr(194).chr(148) => chr(226).chr(128).chr(157), 118 chr(194).chr(149) => chr(226).chr(128).chr(162), 119 chr(194).chr(150) => chr(226).chr(128).chr(147), 120 chr(194).chr(151) => chr(226).chr(128).chr(148), 121 chr(194).chr(152) => chr(203).chr(156), 122 chr(194).chr(153) => chr(226).chr(132).chr(162), 123 chr(194).chr(154) => chr(197).chr(161), 124 chr(194).chr(155) => chr(226).chr(128).chr(186), 125 chr(194).chr(156) => chr(197).chr(147), 126 chr(194).chr(159) => chr(197).chr(184) 127 ); 128 129 $str = utf8_encode($str); 130 131 return str_replace(array_keys($conv),array_values($conv),$str); 132 } 133 134 /** 135 Reconnait une chaîne en UTF-8 136 Taken from http://www.php.net/manual/fr/function.mb-detect-encoding.php#50087 137 */ 138 function isUTF8($string) 139 { 140 if (preg_match('%^(?:[\x09\x0A\x0D\x20-\x7E])*$%xs',$string)) 141 { 142 return false; 143 } 144 else 145 { 146 // From http://w3.org/International/questions/qa-forms-utf-8.html 147 return preg_match('%^(?: 148 [\x09\x0A\x0D\x20-\x7E] # ASCII 149 | [\xC2-\xDF][\x80-\xBF] # non-overlong 2-byte 150 | \xE0[\xA0-\xBF][\x80-\xBF] # excluding overlongs 151 | [\xE1-\xEC\xEE\xEF][\x80-\xBF]{2} # straight 3-byte 152 | \xED[\x80-\x9F][\x80-\xBF] # excluding surrogates 153 | \xF0[\x90-\xBF][\x80-\xBF]{2} # planes 1-3 154 | [\xF1-\xF3][\x80-\xBF]{3} # planes 4-15 155 | \xF4[\x80-\x8F][\x80-\xBF]{2} # plane 16 156 )*$%xs', $string); 157 } 158 } 159 160 /** 161 Encodage d'une chaine en mime Quoted printable 162 */ 163 function mimeEncode($s,$charset='UTF-8') 164 { 165 $s = preg_replace('/([^\x21-\x3c\x3e-\x7e])/e','"=".strtoupper(dechex(ord("\1")))',$s); 166 167 return '=?'.$charset.'?Q?'.$s.'?='; 168 } 169 } 170 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Fri Feb 23 21:40:15 2007 | par Balluche grâce à PHPXref 0.7 |