MDL-31914 db fix - cannot use table aliases on DELETE statements. Credit goes to...
[moodle.git] / lib / configonlylib.php
blob62391626d2dde660d7b0c3b6a87a40ad82d26408
1 <?php
3 // This file is part of Moodle - http://moodle.org/
4 //
5 // Moodle is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
9 //
10 // Moodle is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
18 /**
19 * Minimalistic library, usable even when no other moodle libs are loaded.
21 * The only library that gets loaded if you define ABORT_AFTER_CONFIG
22 * before including main config.php. You can resume normal script operation
23 * if you define ABORT_AFTER_CONFIG_CANCEL and require the setup.php
25 * @package core
26 * @copyright 2009 Petr Skoda (skodak)
27 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
30 /**
31 * Minimalistic parameter validation function.
32 * Can not use optional param because moodlelib.php is not loaded yet
33 * @param string $name
34 * @param mixed $default
35 * @param string $type
36 * @return mixed
38 function min_optional_param($name, $default, $type) {
39 $value = $default;
40 if (isset($_GET[$name])) {
41 $value = $_GET[$name];
43 } else if (isset($_GET['amp;'.$name])) {
44 // very, very, very ugly hack, unfortunately $OUTPUT->pix_url() is not used properly in javascript code :-(
45 $value = $_GET['amp;'.$name];
48 return min_clean_param($value, $type);
51 /**
52 * Minimalistic parameter cleaning function.
53 * Can not use optional param because moodlelib.php is not loaded yet
54 * @param string $name
55 * @param mixed $default
56 * @param string $type
57 * @return mixed
59 function min_clean_param($value, $type) {
60 switch($type) {
61 case 'RAW': $value = iconv('UTF-8', 'UTF-8//IGNORE', $value);
62 break;
63 case 'INT': $value = (int)$value;
64 break;
65 case 'SAFEDIR': $value = preg_replace('/[^a-zA-Z0-9_-]/', '', $value);
66 break;
67 case 'SAFEPATH': $value = preg_replace('/[^a-zA-Z0-9\/\._-]/', '', $value);
68 $value = preg_replace('/\.+/', '.', $value);
69 $value = preg_replace('#/+#', '/', $value);
70 break;
71 default: die("Coding error: incorrect parameter type specified ($type).");
74 return $value;
77 /**
78 * This method tries to enable output compression if possible.
79 * This function must be called before any output or headers.
81 * (IE6 is not supported at all.)
83 * @return boolean, true if compression enabled
85 function min_enable_zlib_compression() {
87 if (headers_sent()) {
88 return false;
91 // zlib.output_compression is preferred over ob_gzhandler()
92 if (!empty($_SERVER['HTTP_USER_AGENT'])) {
93 $agent = $_SERVER['HTTP_USER_AGENT'];
94 // try to detect IE6 and prevent gzip because it is extremely buggy browser
95 $parts = explode(';', $agent);
96 if (isset($parts[1])) {
97 $parts = explode(' ', trim($parts[1]));
98 if (count($parts) > 1) {
99 if ($parts[0] === 'MSIE' and (float)$parts[1] < 7) {
100 @ini_set('zlib.output_compression', '0');
101 return false;
107 @ini_set('output_handler', '');
110 * docs clearly say 'on' means enable and number means size of buffer,
111 * but unfortunately some PHP version break when we set 'on' here.
112 * 1 probably sets chunk size to 4096. our CSS and JS scripts are much bigger,
113 * so let's try some bigger sizes.
115 @ini_set('zlib.output_compression', 65536);
117 return true;