Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

fct.inc.php

Go to the documentation of this file.
00001 <?php 00002 /* 00003 a(tom)Blog is a atom powered weblog system. 00004 Copyright (C) 2004 Yoan BLANC 00005 00006 This program is free software; you can redistribute it and/or 00007 modify it under the terms of the GNU General Public License 00008 as published by the Free Software Foundation; either version 2 00009 of the License, or (at your option) any later version. 00010 00011 This program is distributed in the hope that it will be useful, 00012 but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 GNU General Public License for more details. 00015 00016 You should have received a copy of the GNU General Public License 00017 along with this program; if not, write to the Free Software 00018 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00019 */ 00020 00022 if (!function_exists('file_put_contents')) { 00023 define('FILE_APPEND', 1); 00024 function file_put_contents($filename, $content, $flags = 0) { 00025 if (!($file = fopen($filename, ($flags & FILE_APPEND) ? 'a' : 'w'))) 00026 return false; 00027 $n = fwrite($file, $content); 00028 fclose($file); 00029 return $n ? $n : false; 00030 } 00031 } 00032 00034 if (!function_exists('file_get_contents')) 00035 { 00036 function file_get_contents($filename, $use_include_path = 0) 00037 { 00038 $file = @fopen($filename, 'ab', $use_include_path); 00039 if ($file) 00040 { 00041 if ($fsize = @filesize($filename)) 00042 { 00043 $data = fread($file, $fsize); 00044 } 00045 else 00046 { 00047 while (!feof($file)) 00048 { 00049 $data .= fread($file, 1024); 00050 } 00051 } 00052 fclose($file); 00053 } 00054 return $data; 00055 } 00056 } 00057 00059 if (!function_exists('str_split')) { 00060 function str_split($string, $chunksize=1) { 00061 preg_match_all('/('.str_repeat('.', $chunksize).')/Uims', $string, $matches); 00062 return $matches[1]; 00063 } 00064 } 00065 00071 function captureInfo() 00072 { 00073 $info = array(); 00074 00075 if(isset($_SERVER['REQUEST_METHOD'])) 00076 $info['method'] = $_SERVER['REQUEST_METHOD']; 00077 if(isset($_SERVER['CONTENT_TYPE'])) 00078 $info['type'] = $_SERVER['CONTENT_TYPE']; 00079 00080 if(isset($_SERVER['CONTENT_LENGTH'])) 00081 $info['length'] = $_SERVER['CONTENT_LENGTH']; 00082 00083 if(isset($_SERVER['USER_AGENT'])) 00084 $info['agent'] = $_SERVER['USER_AGENT']; 00085 00086 if(isset($_SERVER['REQUEST_URI'])) 00087 $info['url'] = $_SERVER['REQUEST_URI']; 00088 00089 if(isset($_SERVER['HTTP_X_ATOM_AUTHENTICATION'])) 00090 { 00091 $info['x-atom-authentication']['all'] = stripslashes($_SERVER['HTTP_X_ATOM_AUTHENTICATION']); 00092 $tmp = explode('", ',$info['x-atom-authentication']['all']); 00093 foreach($tmp as $elem) 00094 { 00095 $tinytmp = explode('="',$elem); 00096 $val = str_replace('"','',$tinytmp[1]); 00097 00098 switch(trim($tinytmp[0])) 00099 { 00100 case "Atom username": 00101 $info['x-atom-authentication']['user'] = $val; 00102 break; 00103 case "realm": 00104 $info['x-atom-authentication']['realm'] = $val; 00105 break; 00106 case "nonce": 00107 $info['x-atom-authentication']['nonce'] = $val; 00108 break; 00109 case "cnonce": 00110 $info['x-atom-authentication']['cnonce'] = $val; 00111 break; 00112 case "uri": 00113 $info['x-atom-authentication']['uri'] = $val; 00114 break; 00115 case "qop": 00116 $info['x-atom-authentication']['qop'] = $val; 00117 break; 00118 case "nc": 00119 $info['x-atom-authentication']['nc'] = $val; 00120 break; 00121 case "response": 00122 $info['x-atom-authentication']['response'] = $val; 00123 break; 00124 } 00125 } 00126 } 00127 00128 if(isset($info['method']) && (strtoupper($info['method']) == 'PUT' || strtoupper($info['method']) == 'POST')) 00129 { 00130 $info['data'] = implode(file("php://input"),''); 00131 } 00132 00133 return $info; 00134 } 00135 00141 function captureGet() 00142 { 00143 $out['request'] = $_SERVER['REQUEST_URI']; 00144 00145 $data = (explode("/",$out['request'])); 00146 //$out['data'] = $data; 00147 00148 $out['mode'] = 'help'; 00149 00150 if(isset($data[2]) && !empty($data[2])) 00151 { 00152 $out['login'] = $data[2]; 00153 $out['mode'] = 'user'; 00154 00155 if(isset($data[3]) && !empty($data[3]) && file_exists('atomServer/data/'.$out['login'])) 00156 { 00157 $out['method'] = $data[3]; 00158 if((int)$out['method'] >= 1970 && (int)$out['method'] <= 2070) 00159 { 00160 $out['mode'] = 'year'; 00161 $out['date'] = (int)$out['method']; 00162 // month 00163 if(isset($data[4]) && !empty($data[4]) && 00164 strlen($data[4]) == 2 && 00165 (int)$data[4] > 0 && (int)$data[4] <= 12) 00166 { 00167 $out['mode'] = 'month'; 00168 $out['date'] .= '/'.$data[4]; 00169 // day 00170 if(isset($data[5]) && !empty($data[5]) && 00171 strlen($data[5]) == 2 && 00172 (int)$data[5] > 0 && (int)$data[5] <= 31) 00173 { 00174 $out['mode'] = 'day'; 00175 $out['date'] .= '/'.$data[5]; 00176 if(isset($data[6]) && !empty($data[6])) 00177 { 00178 $out['mode'] = 'entry'; 00179 $out['entry'] = $data[6]; 00180 if(ereg('.xml$',$data[6])) 00181 { 00182 $out['method'] = 'atom'; 00183 } 00184 elseif(ereg('.html$',$data[6])) 00185 { 00186 $out['entry'] = ereg_replace('.html','.xml',$out['entry']); 00187 $out['method'] = 'html'; 00188 } 00189 elseif(strlen($data[6]) == 6) 00190 { 00191 $out['entry'] .= '.xml'; 00192 $out['method'] = 'html'; 00193 } 00194 else 00195 { 00196 redirect('/'.$data[1].'/'.$data[2].'/'.$data[3].'/'.$data[4].'/'.$data[5]); 00197 } 00198 } 00199 elseif(!isset($data[6])) 00200 { 00201 redirect($out['request'].'/'); 00202 } 00203 } 00204 else if(isset($data[5]) && !empty($data[5])) 00205 { 00206 redirect('/'.$data[1].'/'.$data[2].'/'.$data[3].'/'.$data[4].'/'); 00207 } 00208 elseif(!isset($data[5])) 00209 { 00210 redirect($out['request'].'/'); 00211 } 00212 00213 } 00214 else if(isset($data[4]) && !empty($data[4])) 00215 { 00216 redirect('/'.$data[1].'/'.$data[2].'/'.$data[3].'/'); 00217 } 00218 else if(!isset($data[4])) 00219 { 00220 redirect($out['request'].'/'); 00221 } 00222 } 00223 else if(substr($out['method'],-4,4) == '.xml') 00224 { 00225 $out['mode'] = 'feed'; 00226 switch($out['method']) 00227 { 00228 case 'atom.xml': 00229 $out['method']='atom'; 00230 break; 00231 case 'rss091.xml': 00232 $out['method']='rss091'; 00233 break; 00234 case 'introspection.xml': 00235 $out['mode']='introspection'; 00236 break; 00237 default: 00238 unset($out['mode']); 00239 unset($out['method']); 00240 } 00241 } 00242 elseif(isset($data[3]) && !empty($data[3])) 00243 { 00244 redirect('/'.$data[1].'/'.$data[2].'/'); 00245 } 00246 } 00247 else if(!isset($data[3])) 00248 { 00249 redirect($out['request'].'/'); 00250 } 00251 else if(!file_exists('atomServer/data/'.$out['login'])) 00252 { 00253 $out = '<error><msg>no user</msg></error>'; 00254 } 00255 } 00256 else 00257 { 00258 redirect('/'); 00259 } 00260 00261 return $out; 00262 } 00263 00269 function redirect($url) 00270 { 00271 $urlroot = 'http://atom.dosimple.ch'; 00272 //echo "<p><strong>Redirection :</strong> <tt>".$url."</tt></p>"; 00273 header("Moved Permanently", TRUE, 301); 00274 header("Location : ".$urlroot.$url); 00275 header("Connection: close");//*/ 00276 } 00277 00284 function emailformat($mail) 00285 { 00286 return '<a href="mailto:'.hex_encode($mail).'">'.str_replace('@',' [at] ',$mail).'</a>'; 00287 } 00288 00295 function hex_encode ($str) 00296 { 00297 $encoded = bin2hex($str); 00298 $encoded = chunk_split($encoded, 2, '%'); 00299 $encoded = '%'.substr($encoded, 0, strlen($encoded) - 1); 00300 return $encoded; 00301 } 00302 00309 function antiSpam($str) 00310 { 00311 return 'href="mailto:'.hex_encode($str[1]).'"'; 00312 } 00313 00322 function deldir($dir) 00323 { 00324 $handle = opendir($dir); 00325 while (false!==($FolderOrFile = readdir($handle))) 00326 { 00327 if($FolderOrFile != "." && $FolderOrFile != "..") 00328 { 00329 if(is_dir("$dir/$FolderOrFile")) 00330 { deldir("$dir/$FolderOrFile"); } // recursive 00331 else 00332 { unlink("$dir/$FolderOrFile"); } 00333 } 00334 } 00335 closedir($handle); 00336 if(rmdir($dir)) 00337 { $success = true; } 00338 return $success; 00339 } 00340 00347 function htmlent($txt) 00348 { 00349 //return htmlentities($txt,ENT_QUOTES,'UTF-8'); 00350 00351 // \s any whitespace character 00352 // \S any character that is not a whitespace character 00353 // \w any word character 00354 //`` 00355 $txt = preg_replace("/(\W)\"(\w)/si",'\1“\2',$txt); 00356 //'' 00357 $txt = preg_replace("/(\S)\"(\s)/si",'\1”\2',$txt); 00358 //` 00359 $txt = preg_replace("/(\s)'(\S)/si",'\1‘\2',$txt); 00360 //' 00361 $txt = preg_replace("/(\S)'(\s)/si",'\1’\2',$txt); 00362 $txt = preg_replace("/(\S)'(\S)/si",'\1’\2',$txt); 00363 // et le reste. 00364 $txt = str_replace("'","’",$txt); 00365 $txt = str_replace('"',"”",$txt); 00366 return $txt; 00367 } 00368 ?>

Generated on Fri Jun 25 00:00:22 2004 for a(tom)Blog by doxygen 1.3.7