Mercurial > SimpleWebPresenter
comparison common-functions.inc @ 5:18aafb1a8986
Better handling of errors and globals.
| author | Tom Fredrik "BFG" Klaussen <bfg@blenning.no> |
|---|---|
| date | Fri, 20 May 2011 13:25:53 +0200 |
| parents | 74196528fc64 |
| children | 6c0162497d56 |
comparison
equal
deleted
inserted
replaced
| 4:74196528fc64 | 5:18aafb1a8986 |
|---|---|
| 1 <?php | 1 <?php |
| 2 include_once 'http-response-status-codes.inc'; | |
| 3 | |
| 2 function loadFile($sFilename, $sCharset = 'UTF-8') | 4 function loadFile($sFilename, $sCharset = 'UTF-8') |
| 3 { | 5 { |
| 4 if (floatval(phpversion()) >= 4.3) { | 6 if (floatval(phpversion()) >= 4.3) { |
| 5 if (!file_exists($sFilename)) return -3; | 7 if (!file_exists($sFilename)) return -3; |
| 6 $sData = file_get_contents($sFilename); | 8 $sData = file_get_contents($sFilename); |
| 19 $sData = mb_convert_encoding($sData, $sCharset, $sEncoding); | 21 $sData = mb_convert_encoding($sData, $sCharset, $sEncoding); |
| 20 } | 22 } |
| 21 } | 23 } |
| 22 return $sData; | 24 return $sData; |
| 23 } | 25 } |
| 26 | |
| 27 function errorPage($errorText, $errorCode=403) | |
| 28 { | |
| 29 header(StatusCodes::httpHeaderFor($errorCode)); | |
| 30 print "<div id=\"page\"><h1>${errorText}</h1></div>"; | |
| 31 exit; | |
| 32 } | |
| 33 | |
| 34 function genUrl($keys=array()) { | |
| 35 $out="?"; | |
| 36 $first=1; | |
| 37 $URL_PARAMS=$GLOBALS['URL_PARAMS']; | |
| 38 $new_params=array(); | |
| 39 foreach($URL_PARAMS as $param) { | |
| 40 $new_params[$param]=$GLOBALS[$param]; | |
| 41 } | |
| 42 foreach($keys as $param => $val) { | |
| 43 $new_params[$param]=$val; | |
| 44 } | |
| 45 foreach($new_params as $param => $val) { | |
| 46 if($first) | |
| 47 $first=0; | |
| 48 else | |
| 49 $out.="&"; | |
| 50 $out.=urlencode($param).'='.urlencode($val); | |
| 51 } | |
| 52 return $out; | |
| 53 } | |
| 24 ?> | 54 ?> |
