|
Moodle
2.2.1
http://www.collinsharper.com
|
00001 <?php 00002 00003 // This file is part of Moodle - http://moodle.org/ 00004 // 00005 // Moodle is free software: you can redistribute it and/or modify 00006 // it under the terms of the GNU General Public License as published by 00007 // the Free Software Foundation, either version 3 of the License, or 00008 // (at your option) any later version. 00009 // 00010 // Moodle is distributed in the hope that it will be useful, 00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 // GNU General Public License for more details. 00014 // 00015 // You should have received a copy of the GNU General Public License 00016 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 00017 00038 function min_optional_param($name, $default, $type) { 00039 $value = $default; 00040 if (isset($_GET[$name])) { 00041 $value = $_GET[$name]; 00042 00043 } else if (isset($_GET['amp;'.$name])) { 00044 // very, very, very ugly hack, unfortunately $OUTPUT->pix_url() is not used properly in javascript code :-( 00045 $value = $_GET['amp;'.$name]; 00046 } 00047 00048 return min_clean_param($value, $type); 00049 } 00050 00059 function min_clean_param($value, $type) { 00060 switch($type) { 00061 case 'RAW': $value = iconv('UTF-8', 'UTF-8//IGNORE', $value); 00062 break; 00063 case 'INT': $value = (int)$value; 00064 break; 00065 case 'SAFEDIR': $value = preg_replace('/[^a-zA-Z0-9_-]/', '', $value); 00066 break; 00067 case 'SAFEPATH': $value = preg_replace('/[^a-zA-Z0-9\/\._-]/', '', $value); 00068 $value = preg_replace('/\.+/', '.', $value); 00069 $value = preg_replace('#/+#', '/', $value); 00070 break; 00071 default: die("Coding error: incorrect parameter type specified ($type)."); 00072 } 00073 00074 return $value; 00075 } 00076 00085 function min_enable_zlib_compression() { 00086 00087 if (headers_sent()) { 00088 return false; 00089 } 00090 00091 // zlib.output_compression is preferred over ob_gzhandler() 00092 if (!empty($_SERVER['HTTP_USER_AGENT'])) { 00093 $agent = $_SERVER['HTTP_USER_AGENT']; 00094 // try to detect IE6 and prevent gzip because it is extremely buggy browser 00095 $parts = explode(';', $agent); 00096 if (isset($parts[1])) { 00097 $parts = explode(' ', trim($parts[1])); 00098 if (count($parts) > 1) { 00099 if ($parts[0] === 'MSIE' and (float)$parts[1] < 7) { 00100 @ini_set('zlib.output_compression', '0'); 00101 return false; 00102 } 00103 } 00104 } 00105 } 00106 00107 @ini_set('output_handler', ''); 00108 00109 /* 00110 * docs clearly say 'on' means enable and number means size of buffer, 00111 * but unfortunately some PHP version break when we set 'on' here. 00112 * 1 probably sets chunk size to 4096. our CSS and JS scripts are much bigger, 00113 * so let's try some bigger sizes. 00114 */ 00115 @ini_set('zlib.output_compression', 65536); 00116 00117 return true; 00118 }