MDL-24332 fixed incorrect fix - credit goes to Steve Massicotte
[moodle.git] / lib / setuplib.php
CommitLineData
b37eac91 1<?php
d3f9f1f8 2
b37eac91 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.
14//
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/>.
17
18
19/**
20 * These functions are required very early in the Moodle
21 * setup process, before any of the main libraries are
22 * loaded.
30fa50d0 23 *
78bfb562
PS
24 * @package core
25 * @subpackage lib
26 * @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
27 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
b37eac91 28 */
d3f9f1f8 29
78bfb562
PS
30defined('MOODLE_INTERNAL') || die();
31
c84a2dbe 32/// Debug levels ///
33/** no warnings at all */
34define ('DEBUG_NONE', 0);
35/** E_ERROR | E_PARSE */
36define ('DEBUG_MINIMAL', 5);
37/** E_ERROR | E_PARSE | E_WARNING | E_NOTICE */
38define ('DEBUG_NORMAL', 15);
39/** E_ALL without E_STRICT for now, do show recoverable fatal errors */
40define ('DEBUG_ALL', 6143);
41/** DEBUG_ALL with extra Moodle debug messages - (DEBUG_ALL | 32768) */
42define ('DEBUG_DEVELOPER', 38911);
43
6a525ce2 44/**
b08b3569 45 * Simple class. It is usually used instead of stdClass because it looks
1387fcdd 46 * more familiar to Java developers ;-) Do not use for type checking of
4f92410f 47 * function parameters. Please use stdClass instead.
b37eac91 48 *
47d2216e
PS
49 * @package core
50 * @subpackage lib
51 * @copyright 2009 Petr Skoda {@link http://skodak.org}
52 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
4f92410f 53 * @deprecated since 2.0
6a525ce2 54 */
b08b3569 55class object extends stdClass {};
6a525ce2 56
251387d0 57/**
58 * Base Moodle Exception class
b37eac91 59 *
c84a2dbe 60 * Although this class is defined here, you cannot throw a moodle_exception until
61 * after moodlelib.php has been included (which will happen very soon).
62 *
47d2216e
PS
63 * @package core
64 * @subpackage lib
65 * @copyright 2008 Petr Skoda {@link http://skodak.org}
66 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
251387d0 67 */
68class moodle_exception extends Exception {
69 public $errorcode;
70 public $module;
71 public $a;
72 public $link;
eee5d9bb 73 public $debuginfo;
251387d0 74
75 /**
76 * Constructor
77 * @param string $errorcode The name of the string from error.php to print
78 * @param string $module name of module
79 * @param string $link The url where the user will be prompted to continue. If no url is provided the user will be directed to the site index page.
80 * @param object $a Extra words and phrases that might be required in the error string
eee5d9bb 81 * @param string $debuginfo optional debugging information
251387d0 82 */
5ca18631 83 function __construct($errorcode, $module='', $link='', $a=NULL, $debuginfo=null) {
84 if (empty($module) || $module == 'moodle' || $module == 'core') {
251387d0 85 $module = 'error';
86 }
87
5ca18631 88 $this->errorcode = $errorcode;
89 $this->module = $module;
90 $this->link = $link;
91 $this->a = $a;
92 $this->debuginfo = $debuginfo;
251387d0 93
4f6be42c
DM
94 if (get_string_manager()->string_exists($errorcode, $module)) {
95 $message = get_string($errorcode, $module, $a);
96 } else {
97 $message = $module . '/' . $errorcode;
98 }
251387d0 99
100 parent::__construct($message, 0);
101 }
102}
103
df997f84
PS
104/**
105 * Course/activity access exception.
106 *
107 * This exception is thrown from require_login()
47d2216e
PS
108 *
109 * @package core
110 * @subpackage lib
111 * @copyright 2010 Petr Skoda {@link http://skodak.org}
112 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
df997f84
PS
113 */
114class require_login_exception extends moodle_exception {
115 function __construct($debuginfo) {
116 parent::__construct('requireloginerror', 'error', '', NULL, $debuginfo);
117 }
118}
119
559a5dbd 120/**
121 * Web service parameter exception class
122 *
123 * This exception must be thrown to the web service client when a web service parameter is invalid
124 * The error string is gotten from webservice.php
125 */
126class webservice_parameter_exception extends moodle_exception {
127 /**
128 * Constructor
129 * @param string $errorcode The name of the string from webservice.php to print
130 * @param string $a The name of the parameter
131 */
132 function __construct($errorcode=null, $a = '') {
133 parent::__construct($errorcode, 'webservice', '', $a, null);
134 }
135}
136
9a0df45a 137/**
138 * Exceptions indicating user does not have permissions to do something
139 * and the execution can not continue.
47d2216e
PS
140 *
141 * @package core
142 * @subpackage lib
143 * @copyright 2009 Petr Skoda {@link http://skodak.org}
144 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
9a0df45a 145 */
146class required_capability_exception extends moodle_exception {
147 function __construct($context, $capability, $errormessage, $stringfile) {
148 $capabilityname = get_capability_string($capability);
848fe203
PS
149 if ($context->contextlevel == CONTEXT_MODULE and preg_match('/:view$/', $capability)) {
150 // we can not go to mod/xx/view.php because we most probably do not have cap to view it, let's go to course instead
151 $paranetcontext = get_context_instance_by_id(get_parent_contextid($context));
152 $link = get_context_url($paranetcontext);
153 } else {
154 $link = get_context_url($context);
155 }
156 parent::__construct($errormessage, $stringfile, $link, $capabilityname);
9a0df45a 157 }
158}
159
655bbf51 160/**
cce1b0b9 161 * Exception indicating programming error, must be fixed by a programer. For example
162 * a core API might throw this type of exception if a plugin calls it incorrectly.
b37eac91 163 *
47d2216e
PS
164 * @package core
165 * @subpackage lib
166 * @copyright 2008 Petr Skoda {@link http://skodak.org}
167 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
655bbf51 168 */
169class coding_exception extends moodle_exception {
655bbf51 170 /**
171 * Constructor
172 * @param string $hint short description of problem
173 * @param string $debuginfo detailed information how to fix problem
174 */
175 function __construct($hint, $debuginfo=null) {
176 parent::__construct('codingerror', 'debug', '', $hint, $debuginfo);
a3f7cbf6 177 }
178}
179
180/**
181 * Exception indicating malformed parameter problem.
182 * This exception is not supposed to be thrown when processing
183 * user submitted data in forms. It is more suitable
184 * for WS and other low level stuff.
47d2216e
PS
185 *
186 * @package core
187 * @subpackage lib
188 * @copyright 2009 Petr Skoda {@link http://skodak.org}
189 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
a3f7cbf6 190 */
191class invalid_parameter_exception extends moodle_exception {
192 /**
193 * Constructor
194 * @param string $debuginfo some detailed information
195 */
196 function __construct($debuginfo=null) {
197 parent::__construct('invalidparameter', 'debug', '', null, $debuginfo);
655bbf51 198 }
199}
200
d07ff72d 201/**
202 * Exception indicating malformed response problem.
203 * This exception is not supposed to be thrown when processing
204 * user submitted data in forms. It is more suitable
205 * for WS and other low level stuff.
206 */
207class invalid_response_exception extends moodle_exception {
208 /**
209 * Constructor
210 * @param string $debuginfo some detailed information
211 */
212 function __construct($debuginfo=null) {
213 parent::__construct('invalidresponse', 'debug', '', null, $debuginfo);
214 }
215}
216
cce1b0b9 217/**
1387fcdd 218 * An exception that indicates something really weird happened. For example,
cce1b0b9 219 * if you do switch ($context->contextlevel), and have one case for each
220 * CONTEXT_... constant. You might throw an invalid_state_exception in the
f630a546 221 * default case, to just in case something really weird is going on, and
8dc0ae8f 222 * $context->contextlevel is invalid - rather than ignoring this possibility.
b37eac91 223 *
47d2216e
PS
224 * @package core
225 * @subpackage lib
226 * @copyright 2009 onwards Martin Dougiamas {@link http://moodle.com}
227 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
cce1b0b9 228 */
229class invalid_state_exception extends moodle_exception {
230 /**
231 * Constructor
232 * @param string $hint short description of problem
233 * @param string $debuginfo optional more detailed information
234 */
235 function __construct($hint, $debuginfo=null) {
236 parent::__construct('invalidstatedetected', 'debug', '', $hint, $debuginfo);
237 }
238}
239
4031f6a2
PS
240/**
241 * An exception that indicates incorrect permissions in $CFG->dataroot
242 *
243 * @package core
244 * @subpackage lib
245 * @copyright 2010 Petr Skoda {@link http://skodak.org}
246 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
247 */
248class invalid_dataroot_permissions extends moodle_exception {
249 /**
250 * Constructor
251 * @param string $debuginfo optional more detailed information
252 */
253 function __construct($debuginfo = NULL) {
254 parent::__construct('invaliddatarootpermissions', 'error', '', NULL, $debuginfo);
255 }
256}
257
251387d0 258/**
1387fcdd 259 * Default exception handler, uncaught exceptions are equivalent to error() in 1.9 and earlier
fd1a792e 260 *
30fa50d0 261 * @param Exception $ex
c19bc39c 262 * @return void -does not return. Terminates execution!
251387d0 263 */
c19bc39c 264function default_exception_handler($ex) {
695c5ec4 265 global $DB, $OUTPUT;
1fbdf76d 266
267 // detect active db transactions, rollback and log as error
695c5ec4 268 abort_all_db_transactions();
1fe1d104 269
c19bc39c 270 $info = get_exception_info($ex);
34a2777c 271
c19bc39c 272 if (debugging('', DEBUG_MINIMAL)) {
2e9b772f 273 $logerrmsg = "Default exception handler: ".$info->message.' Debug: '.$info->debuginfo."\n".format_backtrace($info->backtrace, true);
695c5ec4 274 error_log($logerrmsg);
fd1a792e 275 }
276
c19bc39c
PS
277 if (is_early_init($info->backtrace)) {
278 echo bootstrap_renderer::early_error($info->message, $info->moreinfourl, $info->link, $info->backtrace, $info->debuginfo);
b7009474 279 } else {
3c1ea58b 280 try {
a56c457e
PS
281 if ($DB) {
282 // If you enable db debugging and exception is thrown, the print footer prints a lot of rubbish
283 $DB->set_debug(0);
284 }
3c1ea58b
PS
285 echo $OUTPUT->fatal_error($info->message, $info->moreinfourl, $info->link, $info->backtrace, $info->debuginfo);
286 } catch (Exception $out_ex) {
287 // default exception handler MUST not throw any exceptions!!
2e9b772f 288 // the problem here is we do not know if page already started or not, we only know that somebody messed up in outputlib or theme
3c1ea58b 289 // so we just print at least something instead of "Exception thrown without a stack frame in Unknown on line 0":-(
1adaa404
PS
290 if (CLI_SCRIPT or AJAX_SCRIPT) {
291 // just ignore the error and send something back using the safest method
292 echo bootstrap_renderer::early_error($info->message, $info->moreinfourl, $info->link, $info->backtrace, $info->debuginfo);
293 } else {
294 echo bootstrap_renderer::early_error_content($info->message, $info->moreinfourl, $info->link, $info->backtrace, $info->debuginfo);
295 $outinfo = get_exception_info($out_ex);
296 echo bootstrap_renderer::early_error_content($outinfo->message, $outinfo->moreinfourl, $outinfo->link, $outinfo->backtrace, $outinfo->debuginfo);
297 }
3c1ea58b 298 }
7544d13c 299 }
300
34a2777c 301 exit(1); // General error code
302}
303
85ba1e78
PS
304/**
305 * Default error handler, prevents some white screens.
306 * @param int $errno
307 * @param string $errstr
308 * @param string $errfile
309 * @param int $errline
310 * @param array $errcontext
311 * @return bool false means use default error handler
312 */
313function default_error_handler($errno, $errstr, $errfile, $errline, $errcontext) {
314 if ($errno == 4096) {
315 //fatal catchable error
316 throw new coding_exception('PHP catchable fatal error', $errstr);
317 }
318 return false;
319}
320
695c5ec4
PS
321/**
322 * Unconditionally abort all database transactions, this function
323 * should be called from exception handlers only.
324 * @return void
325 */
326function abort_all_db_transactions() {
327 global $CFG, $DB, $SCRIPT;
328
d5a8d9aa 329 // default exception handler MUST not throw any exceptions!!
03221650 330
695c5ec4
PS
331 if ($DB && $DB->is_transaction_started()) {
332 error_log('Database transaction aborted automatically in ' . $CFG->dirroot . $SCRIPT);
d5a8d9aa
PS
333 // note: transaction blocks should never change current $_SESSION
334 $DB->force_transaction_rollback();
695c5ec4
PS
335 }
336}
337
b7009474 338/**
50764d37
PS
339 * This function encapsulates the tests for whether an exception was thrown in
340 * early init -- either during setup.php or during init of $OUTPUT.
b7009474 341 *
342 * If another exception is thrown then, and if we do not take special measures,
343 * we would just get a very cryptic message "Exception thrown without a stack
344 * frame in Unknown on line 0". That makes debugging very hard, so we do take
345 * special measures in default_exception_handler, with the help of this function.
346 *
347 * @param array $backtrace the stack trace to analyse.
348 * @return boolean whether the stack trace is somewhere in output initialisation.
349 */
50764d37 350function is_early_init($backtrace) {
b7009474 351 $dangerouscode = array(
352 array('function' => 'header', 'type' => '->'),
353 array('class' => 'bootstrap_renderer'),
50764d37 354 array('file' => dirname(__FILE__).'/setup.php'),
b7009474 355 );
356 foreach ($backtrace as $stackframe) {
357 foreach ($dangerouscode as $pattern) {
358 $matches = true;
359 foreach ($pattern as $property => $value) {
360 if (!isset($stackframe[$property]) || $stackframe[$property] != $value) {
361 $matches = false;
362 }
363 }
364 if ($matches) {
365 return true;
366 }
367 }
368 }
369 return false;
370}
371
34a2777c 372/**
cbf05caa
PS
373 * Abort execution by throwing of a general exception,
374 * default exception handler displays the error message in most cases.
34a2777c 375 *
376 * @param string $errorcode The name of the language string containing the error message.
377 * Normally this should be in the error.php lang file.
378 * @param string $module The language file to get the error message from.
379 * @param string $link The url where the user will be prompted to continue.
380 * If no url is provided the user will be directed to the site index page.
381 * @param object $a Extra words and phrases that might be required in the error string
cbf05caa
PS
382 * @param string $debuginfo optional debugging information
383 * @return void, always throws exception!
34a2777c 384 */
cbf05caa
PS
385function print_error($errorcode, $module = 'error', $link = '', $a = null, $debuginfo = null) {
386 throw new moodle_exception($errorcode, $module, $link, $a, $debuginfo);
34a2777c 387}
388
389/**
c19bc39c
PS
390 * Returns detailed information about specified exception.
391 * @param exception $ex
392 * @return object
34a2777c 393 */
c19bc39c 394function get_exception_info($ex) {
34a2777c 395 global $CFG, $DB, $SESSION;
396
c19bc39c
PS
397 if ($ex instanceof moodle_exception) {
398 $errorcode = $ex->errorcode;
399 $module = $ex->module;
400 $a = $ex->a;
401 $link = $ex->link;
402 $debuginfo = $ex->debuginfo;
403 } else {
404 $errorcode = 'generalexceptionmessage';
405 $module = 'error';
406 $a = $ex->getMessage();
407 $link = '';
408 $debuginfo = null;
34a2777c 409 }
410
c19bc39c
PS
411 $backtrace = $ex->getTrace();
412 $place = array('file'=>$ex->getFile(), 'line'=>$ex->getLine(), 'exception'=>get_class($ex));
413 array_unshift($backtrace, $place);
414
c84a2dbe 415 // Be careful, no guarantee moodlelib.php is loaded.
34a2777c 416 if (empty($module) || $module == 'moodle' || $module == 'core') {
417 $module = 'error';
418 }
4f6be42c
DM
419 if (function_exists('get_string_manager')) {
420 if (get_string_manager()->string_exists($errorcode, $module)) {
421 $message = get_string($errorcode, $module, $a);
422 } elseif ($module == 'error' && get_string_manager()->string_exists($errorcode, 'moodle')) {
c84a2dbe 423 // Search in moodle file if error specified - needed for backwards compatibility
424 $message = get_string($errorcode, 'moodle', $a);
4f6be42c
DM
425 } else {
426 $message = $module . '/' . $errorcode;
c84a2dbe 427 }
428 } else {
429 $message = $module . '/' . $errorcode;
430 }
431
432 // Be careful, no guarantee weblib.php is loaded.
433 if (function_exists('clean_text')) {
434 $message = clean_text($message);
435 } else {
436 $message = htmlspecialchars($message);
34a2777c 437 }
34a2777c 438
439 if (!empty($CFG->errordocroot)) {
440 $errordocroot = $CFG->errordocroot;
441 } else if (!empty($CFG->docroot)) {
442 $errordocroot = $CFG->docroot;
443 } else {
444 $errordocroot = 'http://docs.moodle.org';
445 }
446 if ($module === 'error') {
447 $modulelink = 'moodle';
0ae8f5fc 448 } else {
34a2777c 449 $modulelink = $module;
251387d0 450 }
34a2777c 451 $moreinfourl = $errordocroot . '/en/error/' . $modulelink . '/' . $errorcode;
452
d4a03c00 453 if (empty($link)) {
34a2777c 454 if (!empty($SESSION->fromurl)) {
455 $link = $SESSION->fromurl;
456 unset($SESSION->fromurl);
457 } else {
458 $link = $CFG->wwwroot .'/';
459 }
460 }
461
365a5941 462 $info = new stdClass();
c19bc39c
PS
463 $info->message = $message;
464 $info->errorcode = $errorcode;
465 $info->backtrace = $backtrace;
466 $info->link = $link;
467 $info->moreinfourl = $moreinfourl;
468 $info->a = $a;
469 $info->debuginfo = $debuginfo;
30fa50d0 470
c19bc39c 471 return $info;
34a2777c 472}
473
34a2777c 474/**
475 * Formats a backtrace ready for output.
476 *
477 * @param array $callers backtrace array, as returned by debug_backtrace().
478 * @param boolean $plaintext if false, generates HTML, if true generates plain text.
479 * @return string formatted backtrace, ready for output.
480 */
481function format_backtrace($callers, $plaintext = false) {
a0394be4 482 // do not use $CFG->dirroot because it might not be available in destructors
34a2777c 483 $dirroot = dirname(dirname(__FILE__));
30fa50d0 484
34a2777c 485 if (empty($callers)) {
486 return '';
487 }
488
489 $from = $plaintext ? '' : '<ul style="text-align: left">';
490 foreach ($callers as $caller) {
491 if (!isset($caller['line'])) {
492 $caller['line'] = '?'; // probably call_user_func()
493 }
494 if (!isset($caller['file'])) {
495 $caller['file'] = 'unknownfile'; // probably call_user_func()
496 }
497 $from .= $plaintext ? '* ' : '<li>';
498 $from .= 'line ' . $caller['line'] . ' of ' . str_replace($dirroot, '', $caller['file']);
499 if (isset($caller['function'])) {
500 $from .= ': call to ';
501 if (isset($caller['class'])) {
502 $from .= $caller['class'] . $caller['type'];
503 }
504 $from .= $caller['function'] . '()';
505 } else if (isset($caller['exception'])) {
506 $from .= ': '.$caller['exception'].' thrown';
507 }
508 $from .= $plaintext ? "\n" : '</li>';
509 }
510 $from .= $plaintext ? '' : '</ul>';
511
512 return $from;
251387d0 513}
6a525ce2 514
fbf2c91e 515/**
516 * This function verifies the sanity of PHP configuration
517 * and stops execution if anything critical found.
518 */
519function setup_validate_php_configuration() {
520 // this must be very fast - no slow checks here!!!
521
522 if (ini_get_bool('register_globals')) {
523 print_error('globalswarning', 'admin');
524 }
525 if (ini_get_bool('session.auto_start')) {
526 print_error('sessionautostartwarning', 'admin');
527 }
528 if (ini_get_bool('magic_quotes_runtime')) {
529 print_error('fatalmagicquotesruntime', 'admin');
530 }
531}
532
12bb0c3e
PS
533/**
534 * Initialise global $CFG variable
535 * @return void
536 */
537function initialise_cfg() {
538 global $CFG, $DB;
8b8aa060 539
12bb0c3e
PS
540 try {
541 if ($DB) {
542 $localcfg = $DB->get_records_menu('config', array(), '', 'name,value');
543 foreach ($localcfg as $name=>$value) {
544 if (property_exists($CFG, $name)) {
545 // config.php settings always take precedence
546 continue;
547 }
548 $CFG->{$name} = $value;
549 }
550 }
551 } catch (dml_read_exception $e) {
552 // most probably empty db, going to install soon
553 }
554}
555
11e7b506 556/**
75781f87 557 * Initialises $FULLME and friends. Private function. Should only be called from
558 * setup.php.
11e7b506 559 */
560function initialise_fullme() {
561 global $CFG, $FULLME, $ME, $SCRIPT, $FULLSCRIPT;
562
75781f87 563 // Detect common config error.
84b88cfd 564 if (substr($CFG->wwwroot, -1) == '/') {
565 print_error('wwwrootslash', 'error');
566 }
567
75781f87 568 if (CLI_SCRIPT) {
569 initialise_fullme_cli();
570 return;
37ccf1fe 571 }
11e7b506 572
75781f87 573 $wwwroot = parse_url($CFG->wwwroot);
574 if (!isset($wwwroot['path'])) {
575 $wwwroot['path'] = '';
576 }
577 $wwwroot['path'] .= '/';
578
579 $rurl = setup_get_remote_url();
11e7b506 580
75781f87 581 // Check that URL is under $CFG->wwwroot.
582 if (strpos($rurl['path'], $wwwroot['path']) === 0) {
583 $SCRIPT = substr($rurl['path'], strlen($wwwroot['path'])-1);
584 } else {
585 // Probably some weird external script
586 $SCRIPT = $FULLSCRIPT = $FULLME = $ME = null;
11e7b506 587 return;
588 }
589
75781f87 590 // $CFG->sslproxy specifies if external SSL appliance is used
591 // (That is, the Moodle server uses http, with an external box translating everything to https).
592 if (empty($CFG->sslproxy)) {
56048f83 593 if ($rurl['scheme'] === 'http' and $wwwroot['scheme'] === 'https') {
75781f87 594 print_error('sslonlyaccess', 'error');
595 }
56048f83
PS
596 } else {
597 if ($wwwroot['scheme'] !== 'https') {
598 throw new coding_exception('Must use https address in wwwroot when ssl proxy enabled!');
599 }
74162134 600 $rurl['scheme'] = 'https'; // make moodle believe it runs on https, squid or something else it doing it
75781f87 601 }
602
603 // $CFG->reverseproxy specifies if reverse proxy server used.
604 // Used in load balancing scenarios.
605 // Do not abuse this to try to solve lan/wan access problems!!!!!
606 if (empty($CFG->reverseproxy)) {
607 if (($rurl['host'] != $wwwroot['host']) or
608 (!empty($wwwroot['port']) and $rurl['port'] != $wwwroot['port'])) {
68a45361 609 // Explain the problem and redirect them to the right URL
df92ba9a
PS
610 if (!defined('NO_MOODLE_COOKIES')) {
611 define('NO_MOODLE_COOKIES', true);
612 }
68a45361 613 redirect($CFG->wwwroot, get_string('wwwrootmismatch', 'error', $CFG->wwwroot), 3);
75781f87 614 }
615 }
616
617 // hopefully this will stop all those "clever" admins trying to set up moodle
618 // with two different addresses in intranet and Internet
619 if (!empty($CFG->reverseproxy) && $rurl['host'] == $wwwroot['host']) {
620 print_error('reverseproxyabused', 'error');
621 }
622
623 $hostandport = $rurl['scheme'] . '://' . $wwwroot['host'];
624 if (!empty($wwwroot['port'])) {
625 $hostandport .= ':'.$wwwroot['port'];
626 }
627
628 $FULLSCRIPT = $hostandport . $rurl['path'];
629 $FULLME = $hostandport . $rurl['fullpath'];
630 $ME = $rurl['fullpath'];
631 $rurl['path'] = $rurl['fullpath'];
632}
633
634/**
635 * Initialises $FULLME and friends for command line scripts.
636 * This is a private method for use by initialise_fullme.
637 */
638function initialise_fullme_cli() {
80e30f25 639 global $CFG, $FULLME, $ME, $SCRIPT, $FULLSCRIPT;
640
75781f87 641 // Urls do not make much sense in CLI scripts
642 $backtrace = debug_backtrace();
643 $topfile = array_pop($backtrace);
644 $topfile = realpath($topfile['file']);
645 $dirroot = realpath($CFG->dirroot);
646
647 if (strpos($topfile, $dirroot) !== 0) {
648 // Probably some weird external script
649 $SCRIPT = $FULLSCRIPT = $FULLME = $ME = null;
650 } else {
651 $relativefile = substr($topfile, strlen($dirroot));
652 $relativefile = str_replace('\\', '/', $relativefile); // Win fix
653 $SCRIPT = $FULLSCRIPT = $relativefile;
654 $FULLME = $ME = null;
655 }
656}
657
658/**
659 * Get the URL that PHP/the web server thinks it is serving. Private function
660 * used by initialise_fullme. In your code, use $PAGE->url, $SCRIPT, etc.
661 * @return array in the same format that parse_url returns, with the addition of
662 * a 'fullpath' element, which includes any slasharguments path.
663 */
664function setup_get_remote_url() {
11e7b506 665 $rurl = array();
75781f87 666 list($rurl['host']) = explode(':', $_SERVER['HTTP_HOST']);
11e7b506 667 $rurl['port'] = $_SERVER['SERVER_PORT'];
75781f87 668 $rurl['path'] = $_SERVER['SCRIPT_NAME']; // Script path without slash arguments
11e7b506 669
670 if (stripos($_SERVER['SERVER_SOFTWARE'], 'apache') !== false) {
671 //Apache server
672 $rurl['scheme'] = empty($_SERVER['HTTPS']) ? 'http' : 'https';
f49b359b 673 $rurl['fullpath'] = $_SERVER['REQUEST_URI'];
7e13a265 674
11e7b506 675 } else if (stripos($_SERVER['SERVER_SOFTWARE'], 'iis') !== false) {
199c1981 676 //IIS - needs a lot of tweaking to make it work
11e7b506 677 $rurl['scheme'] = ($_SERVER['HTTPS'] == 'off') ? 'http' : 'https';
678 $rurl['fullpath'] = $_SERVER['SCRIPT_NAME'];
679
680 // NOTE: ignore PATH_INFO because it is incorrectly encoded using 8bit filesystem legacy encoding in IIS
681 // since 2.0 we rely on iis rewrite extenssion like Helicon ISAPI_rewrite
21517960 682 // example rule: RewriteRule ^([^\?]+?\.php)(\/.+)$ $1\?file=$2 [QSA]
11e7b506 683
684 if ($_SERVER['QUERY_STRING'] != '') {
991ec2ee 685 $rurl['fullpath'] .= '?'.$_SERVER['QUERY_STRING'];
11e7b506 686 }
687 $_SERVER['REQUEST_URI'] = $rurl['fullpath']; // extra IIS compatibility
688
f49b359b
PS
689/* NOTE: following servers are not fully tested! */
690
691 } else if (stripos($_SERVER['SERVER_SOFTWARE'], 'lighttpd') !== false) {
692 //lighttpd - not officially supported
693 $rurl['scheme'] = empty($_SERVER['HTTPS']) ? 'http' : 'https';
694 $rurl['fullpath'] = $_SERVER['REQUEST_URI']; // TODO: verify this is always properly encoded
695
696 } else if (stripos($_SERVER['SERVER_SOFTWARE'], 'nginx') !== false) {
697 //nginx - not officially supported
698 $rurl['scheme'] = empty($_SERVER['HTTPS']) ? 'http' : 'https';
699 $rurl['fullpath'] = $_SERVER['REQUEST_URI']; // TODO: verify this is always properly encoded
700
199c1981
PS
701 } else if (stripos($_SERVER['SERVER_SOFTWARE'], 'cherokee') !== false) {
702 //cherokee - not officially supported
703 $rurl['scheme'] = ($_SERVER['HTTPS'] == 'off') ? 'http' : 'https';
704 $rurl['fullpath'] = $_SERVER['REQUEST_URI']; // TODO: verify this is always properly encoded
705
8b8aa060
PS
706 } else if (stripos($_SERVER['SERVER_SOFTWARE'], 'zeus') !== false) {
707 //zeus - not officially supported
708 $rurl['scheme'] = ($_SERVER['HTTPS'] == 'off') ? 'http' : 'https';
709 $rurl['fullpath'] = $_SERVER['REQUEST_URI']; // TODO: verify this is always properly encoded
710
f49b359b
PS
711 } else if (stripos($_SERVER['SERVER_SOFTWARE'], 'LiteSpeed') !== false) {
712 //LiteSpeed - not officially supported
713 $rurl['scheme'] = ($_SERVER['HTTPS'] == 'off') ? 'http' : 'https';
714 $rurl['fullpath'] = $_SERVER['REQUEST_URI']; // TODO: verify this is always properly encoded
715
8b8aa060 716 } else {
75781f87 717 throw new moodle_exception('unsupportedwebserver', 'error', '', $_SERVER['SERVER_SOFTWARE']);
11e7b506 718 }
75781f87 719 return $rurl;
11e7b506 720}
721
d3f9f1f8 722/**
723 * Initializes our performance info early.
724 *
725 * Pairs up with get_performance_info() which is actually
251387d0 726 * in moodlelib.php. This function is here so that we can
727 * call it before all the libs are pulled in.
d3f9f1f8 728 *
729 * @uses $PERF
730 */
731function init_performance_info() {
732
6fc4ad72 733 global $PERF, $CFG, $USER;
251387d0 734
365a5941 735 $PERF = new stdClass();
d3f9f1f8 736 $PERF->logwrites = 0;
737 if (function_exists('microtime')) {
738 $PERF->starttime = microtime();
c84a2dbe 739 }
d3f9f1f8 740 if (function_exists('memory_get_usage')) {
741 $PERF->startmemory = memory_get_usage();
742 }
743 if (function_exists('posix_times')) {
251387d0 744 $PERF->startposixtimes = posix_times();
d3f9f1f8 745 }
b65567f4 746 if (function_exists('apd_set_pprof_trace')) {
747 // APD profiling
6fc4ad72 748 if ($USER->id > 0 && $CFG->perfdebug >= 15) {
251387d0 749 $tempdir = $CFG->dataroot . '/temp/profile/' . $USER->id;
6fc4ad72 750 mkdir($tempdir);
751 apd_set_pprof_trace($tempdir);
752 $PERF->profiling = true;
753 }
b65567f4 754 }
d3f9f1f8 755}
756
31a99877 757/**
758 * Indicates whether we are in the middle of the initial Moodle install.
759 *
760 * Very occasionally it is necessary avoid running certain bits of code before the
761 * Moodle installation has completed. The installed flag is set in admin/index.php
762 * after Moodle core and all the plugins have been installed, but just before
763 * the person doing the initial install is asked to choose the admin password.
764 *
765 * @return boolean true if the initial install is not complete.
766 */
767function during_initial_install() {
768 global $CFG;
769 return empty($CFG->rolesactive);
770}
771
76f3815b 772/**
773 * Function to raise the memory limit to a new value.
774 * Will respect the memory limit if it is higher, thus allowing
775 * settings in php.ini, apache conf or command line switches
776 * to override it
777 *
778 * The memory limit should be expressed with a string (eg:'64M')
779 *
780 * @param string $newlimit the new memory limit
781 * @return bool
782 */
11e7b506 783function raise_memory_limit($newlimit) {
76f3815b 784
785 if (empty($newlimit)) {
786 return false;
787 }
788
789 $cur = @ini_get('memory_limit');
790 if (empty($cur)) {
791 // if php is compiled without --enable-memory-limits
792 // apparently memory_limit is set to ''
793 $cur=0;
794 } else {
795 if ($cur == -1){
796 return true; // unlimited mem!
797 }
798 $cur = get_real_size($cur);
799 }
800
801 $new = get_real_size($newlimit);
802 if ($new > $cur) {
803 ini_set('memory_limit', $newlimit);
7022dd39 804 return true;
805 }
806 return false;
807}
808
809/**
810 * Function to reduce the memory limit to a new value.
811 * Will respect the memory limit if it is lower, thus allowing
812 * settings in php.ini, apache conf or command line switches
813 * to override it
814 *
815 * The memory limit should be expressed with a string (eg:'64M')
816 *
817 * @param string $newlimit the new memory limit
818 * @return bool
819 */
f630a546 820function reduce_memory_limit($newlimit) {
7022dd39 821 if (empty($newlimit)) {
822 return false;
823 }
824 $cur = @ini_get('memory_limit');
825 if (empty($cur)) {
826 // if php is compiled without --enable-memory-limits
827 // apparently memory_limit is set to ''
828 $cur=0;
829 } else {
830 if ($cur == -1){
831 return true; // unlimited mem!
832 }
833 $cur = get_real_size($cur);
834 }
835
836 $new = get_real_size($newlimit);
837 // -1 is smaller, but it means unlimited
838 if ($new < $cur && $new != -1) {
839 ini_set('memory_limit', $newlimit);
76f3815b 840 return true;
841 }
842 return false;
843}
844
845/**
846 * Converts numbers like 10M into bytes.
847 *
848 * @param mixed $size The size to be converted
849 * @return mixed
850 */
851function get_real_size($size=0) {
852 if (!$size) {
853 return 0;
854 }
11e7b506 855 $scan = array();
76f3815b 856 $scan['MB'] = 1048576;
857 $scan['Mb'] = 1048576;
858 $scan['M'] = 1048576;
859 $scan['m'] = 1048576;
860 $scan['KB'] = 1024;
861 $scan['Kb'] = 1024;
862 $scan['K'] = 1024;
863 $scan['k'] = 1024;
864
865 while (list($key) = each($scan)) {
866 if ((strlen($size)>strlen($key))&&(substr($size, strlen($size) - strlen($key))==$key)) {
867 $size = substr($size, 0, strlen($size) - strlen($key)) * $scan[$key];
868 break;
869 }
870 }
871 return $size;
872}
873
5e39d7aa 874/**
875 * Check whether a major upgrade is needed. That is defined as an upgrade that
876 * changes something really fundamental in the database, so nothing can possibly
877 * work until the database has been updated, and that is defined by the hard-coded
878 * version number in this function.
879 */
880function redirect_if_major_upgrade_required() {
881 global $CFG;
64f93798 882 $lastmajordbchanges = 2010070300;
5e39d7aa 883 if (empty($CFG->version) or (int)$CFG->version < $lastmajordbchanges or
884 during_initial_install() or !empty($CFG->adminsetuppending)) {
885 try {
886 @session_get_instance()->terminate_current();
887 } catch (Exception $e) {
888 // Ignore any errors, redirect to upgrade anyway.
889 }
a38c7a10 890 $url = $CFG->wwwroot . '/' . $CFG->admin . '/index.php';
5e39d7aa 891 @header($_SERVER['SERVER_PROTOCOL'] . ' 303 See Other');
a38c7a10
PS
892 @header('Location: ' . $url);
893 echo bootstrap_renderer::plain_redirect_message(htmlspecialchars($url));
5e39d7aa 894 exit;
895 }
896}
897
d3f9f1f8 898/**
4031f6a2
PS
899 * Function to check if a directory exists and by default create it if not exists.
900 *
901 * Previously this was accepting paths only from dataroot, but we now allow
902 * files outside of dataroot if you supply custom paths for some settings in config.php.
903 * This function does not verify that the directory is writable.
d3f9f1f8 904 *
4031f6a2
PS
905 * @param string $dir absolute directory path
906 * @param boolean $create directory if does not exist
907 * @param boolean $recursive create directory recursively
908 * @return boolean true if directory exists or created, false otherwise
d3f9f1f8 909 */
4031f6a2 910function check_dir_exists($dir, $create = true, $recursive = true) {
d3f9f1f8 911 global $CFG;
912
4031f6a2 913 umask(0000); // just in case some evil code changed it
d3f9f1f8 914
4031f6a2
PS
915 if (is_dir($dir)) {
916 return true;
917 }
d3f9f1f8 918
4031f6a2
PS
919 if (!$create) {
920 return false;
d100b8a0 921 }
922
4031f6a2
PS
923 return mkdir($dir, $CFG->directorypermissions, $recursive);
924}
925
926/**
927 * Create a directory in dataroot and make sure it is writable.
928 *
929 * @param string $directory a string of directory names under $CFG->dataroot eg temp/something
930 * @param bool $exceptiononerror throw exception if error encountered
931 * @return string|false Returns full path to directory if successful, false if not; may throw exception
932 */
933function make_upload_directory($directory, $exceptiononerror = true) {
934 global $CFG;
935
936 // Make sure a .htaccess file is here, JUST IN CASE the files area is in the open and .htaccess is supported
937 if (!file_exists("$CFG->dataroot/.htaccess")) {
938 if ($handle = fopen("$CFG->dataroot/.htaccess", 'w')) { // For safety
edaf04d4 939 @fwrite($handle, "deny from all\r\nAllowOverride None\r\nNote: this file is broken intentionally, we do not want anybody to undo it in subdirectory!\r\n");
d3f9f1f8 940 @fclose($handle);
941 }
942 }
943
4031f6a2 944 $dir = "$CFG->dataroot/$directory";
d3f9f1f8 945
4031f6a2
PS
946 if (file_exists($dir) and !is_dir($dir)) {
947 if ($exceptiononerror) {
948 throw new coding_exception($dir.' directory can not be created, file with the same name already exists.');
949 } else {
950 return false;
951 }
952 }
953
954 umask(0000); // just in case some evil code changed it
955
956 if (!file_exists($dir)) {
957 if (!mkdir($dir, $CFG->directorypermissions, true)) {
958 if ($exceptiononerror) {
959 throw new invalid_dataroot_permissions($dir.' can not be created, check permissions.');
960 } else {
d3f9f1f8 961 return false;
962 }
d3f9f1f8 963 }
964 }
965
4031f6a2
PS
966 if (!is_writable($dir)) {
967 if ($exceptiononerror) {
968 throw new invalid_dataroot_permissions($dir.' is not writable, check permissions.');
969 } else {
970 return false;
971 }
972 }
973
974 return $dir;
d3f9f1f8 975}
976
419e1d93 977function init_memcached() {
978 global $CFG, $MCACHE;
979
f917d0ea 980 include_once($CFG->libdir . '/memcached.class.php');
981 $MCACHE = new memcached;
982 if ($MCACHE->status()) {
983 return true;
251387d0 984 }
f917d0ea 985 unset($MCACHE);
251387d0 986 return false;
419e1d93 987}
988
2142d492 989function init_eaccelerator() {
990 global $CFG, $MCACHE;
991
992 include_once($CFG->libdir . '/eaccelerator.class.php');
993 $MCACHE = new eaccelerator;
f917d0ea 994 if ($MCACHE->status()) {
2142d492 995 return true;
251387d0 996 }
2142d492 997 unset($MCACHE);
998 return false;
999}
1000
1001
c84a2dbe 1002/**
1003 * This class solves the problem of how to initialise $OUTPUT.
1004 *
1005 * The problem is caused be two factors
1006 * <ol>
1007 * <li>On the one hand, we cannot be sure when output will start. In particular,
30fa50d0 1008 * an error, which needs to be displayed, could be thrown at any time.</li>
c84a2dbe 1009 * <li>On the other hand, we cannot be sure when we will have all the information
1010 * necessary to correctly initialise $OUTPUT. $OUTPUT depends on the theme, which
1011 * (potentially) depends on the current course, course categories, and logged in user.
1012 * It also depends on whether the current page requires HTTPS.</li>
1013 * </ol>
1014 *
1015 * So, it is hard to find a single natural place during Moodle script execution,
1016 * which we can guarantee is the right time to initialise $OUTPUT. Instead we
1017 * adopt the following strategy
1018 * <ol>
1019 * <li>We will initialise $OUTPUT the first time it is used.</li>
1020 * <li>If, after $OUTPUT has been initialised, the script tries to change something
7e0d6675 1021 * that $OUTPUT depends on, we throw an exception making it clear that the script
c84a2dbe 1022 * did something wrong.
1023 * </ol>
1024 *
1025 * The only problem with that is, how do we initialise $OUTPUT on first use if,
1026 * it is going to be used like $OUTPUT->somthing(...)? Well that is where this
1027 * class comes in. Initially, we set up $OUTPUT = new bootstrap_renderer(). Then,
1028 * when any method is called on that object, we initialise $OUTPUT, and pass the call on.
1029 *
1030 * Note that this class is used before lib/outputlib.php has been loaded, so we
1387fcdd 1031 * must be careful referring to classes/functions from there, they may not be
c84a2dbe 1032 * defined yet, and we must avoid fatal errors.
1033 *
1034 * @copyright 2009 Tim Hunt
1035 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
1036 * @since Moodle 2.0
1037 */
1038class bootstrap_renderer {
1039 /**
1040 * Handles re-entrancy. Without this, errors or debugging output that occur
1041 * during the initialisation of $OUTPUT, cause infinite recursion.
1042 * @var boolean
1043 */
1044 protected $initialising = false;
1045
b7009474 1046 /**
1047 * Have we started output yet?
1048 * @return boolean true if the header has been printed.
1049 */
1050 public function has_started() {
1051 return false;
1052 }
1053
c84a2dbe 1054 public function __call($method, $arguments) {
b7009474 1055 global $OUTPUT, $PAGE;
c84a2dbe 1056
87b6851c 1057 $recursing = false;
1058 if ($method == 'notification') {
1387fcdd 1059 // Catch infinite recursion caused by debugging output during print_header.
87b6851c 1060 $backtrace = debug_backtrace();
1061 array_shift($backtrace);
1062 array_shift($backtrace);
50764d37 1063 $recursing = is_early_init($backtrace);
87b6851c 1064 }
1065
eb5bdb35
PS
1066 $earlymethods = array(
1067 'fatal_error' => 'early_error',
1068 'notification' => 'early_notification',
1069 );
1070
c84a2dbe 1071 // If lib/outputlib.php has been loaded, call it.
87b6851c 1072 if (!empty($PAGE) && !$recursing) {
eb5bdb35
PS
1073 if (array_key_exists($method, $earlymethods)) {
1074 //prevent PAGE->context warnings - exceptions might appear before we set any context
1075 $PAGE->set_context(null);
1076 }
b7009474 1077 $PAGE->initialise_theme_and_output();
1078 return call_user_func_array(array($OUTPUT, $method), $arguments);
c84a2dbe 1079 }
2142d492 1080
c84a2dbe 1081 $this->initialising = true;
eb5bdb35 1082
c84a2dbe 1083 // Too soon to initialise $OUTPUT, provide a couple of key methods.
c84a2dbe 1084 if (array_key_exists($method, $earlymethods)) {
1085 return call_user_func_array(array('bootstrap_renderer', $earlymethods[$method]), $arguments);
1086 }
1087
1088 throw new coding_exception('Attempt to start output before enough information is known to initialise the theme.');
1089 }
1090
1091 /**
1387fcdd 1092 * Returns nicely formatted error message in a div box.
30fa50d0 1093 * @return string
c84a2dbe 1094 */
3c1ea58b 1095 public static function early_error_content($message, $moreinfourl, $link, $backtrace, $debuginfo = null) {
b7009474 1096 global $CFG;
1097
3c1ea58b
PS
1098 $content = '<div style="margin-top: 6em; margin-left:auto; margin-right:auto; color:#990000; text-align:center; font-size:large; border-width:1px;
1099border-color:black; background-color:#ffffee; border-style:solid; border-radius: 20px; border-collapse: collapse;
1100width: 80%; -moz-border-radius: 20px; padding: 15px">
1101' . $message . '
1102</div>';
1103 if (!empty($CFG->debug) && $CFG->debug >= DEBUG_DEVELOPER) {
1104 if (!empty($debuginfo)) {
c5d18164
PS
1105 $debuginfo = s($debuginfo); // removes all nasty JS
1106 $debuginfo = str_replace("\n", '<br />', $debuginfo); // keep newlines
1107 $content .= '<div class="notifytiny">Debug info: ' . $debuginfo . '</div>';
3c1ea58b
PS
1108 }
1109 if (!empty($backtrace)) {
1110 $content .= '<div class="notifytiny">Stack trace: ' . format_backtrace($backtrace, false) . '</div>';
1111 }
1112 }
1113
1114 return $content;
1115 }
1116
1117 /**
1118 * This function should only be called by this class, or from exception handlers
1119 * @return string
1120 */
1121 public static function early_error($message, $moreinfourl, $link, $backtrace, $debuginfo = null) {
1adaa404
PS
1122 global $CFG;
1123
1124 if (CLI_SCRIPT) {
1125 echo "!!! $message !!!\n";
1126 if (!empty($CFG->debug) and $CFG->debug >= DEBUG_DEVELOPER) {
1127 if (!empty($debuginfo)) {
1128 echo "\nDebug info: $debuginfo";
1129 }
1130 if (!empty($backtrace)) {
1131 echo "\nStack trace: " . format_backtrace($backtrace, true);
1132 }
1133 }
1134 return;
1135
1136 } else if (AJAX_SCRIPT) {
1137 $e = new stdClass();
1138 $e->error = $message;
1139 $e->stacktrace = NULL;
1140 $e->debuginfo = NULL;
1141 if (!empty($CFG->debug) and $CFG->debug >= DEBUG_DEVELOPER) {
1142 if (!empty($debuginfo)) {
1143 $e->debuginfo = $debuginfo;
1144 }
1145 if (!empty($backtrace)) {
1146 $e->stacktrace = format_backtrace($backtrace, true);
1147 }
1148 }
6db3eee0 1149 @header('Content-Type: application/json');
1adaa404
PS
1150 echo json_encode($e);
1151 return;
1152 }
1153
c84a2dbe 1154 // In the name of protocol correctness, monitoring and performance
1387fcdd 1155 // profiling, set the appropriate error headers for machine consumption
c84a2dbe 1156 if (isset($_SERVER['SERVER_PROTOCOL'])) {
1157 // Avoid it with cron.php. Note that we assume it's HTTP/1.x
1387fcdd 1158 // The 503 ode here means our Moodle does not work at all, the error happened too early
c84a2dbe 1159 @header($_SERVER['SERVER_PROTOCOL'] . ' 503 Service Unavailable');
1160 }
1161
1162 // better disable any caching
1163 @header('Content-Type: text/html; charset=utf-8');
1164 @header('Cache-Control: no-store, no-cache, must-revalidate');
1165 @header('Cache-Control: post-check=0, pre-check=0', false);
1166 @header('Pragma: no-cache');
1167 @header('Expires: Mon, 20 Aug 1969 09:23:00 GMT');
1168 @header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
1169
5e39d7aa 1170 if (function_exists('get_string')) {
c84a2dbe 1171 $strerror = get_string('error');
1172 } else {
c84a2dbe 1173 $strerror = 'Error';
1174 }
1175
3c1ea58b 1176 $content = self::early_error_content($message, $moreinfourl, $link, $backtrace, $debuginfo);
5e39d7aa 1177
1178 return self::plain_page($strerror, $content);
c84a2dbe 1179 }
1180
1181 public static function early_notification($message, $classes = 'notifyproblem') {
1182 return '<div class="' . $classes . '">' . $message . '</div>';
1183 }
5e39d7aa 1184
1185 public static function plain_redirect_message($encodedurl) {
1186 $message = '<p>' . get_string('pageshouldredirect') . '</p><p><a href="'.
1187 $encodedurl .'">'. get_string('continue') .'</a></p>';
a0a268d5 1188 return self::plain_page(get_string('redirect'), $message);
5e39d7aa 1189 }
1190
1191 protected static function plain_page($title, $content) {
1192 if (function_exists('get_string') && function_exists('get_html_lang')) {
1193 $htmllang = get_html_lang();
1194 } else {
1195 $htmllang = '';
1196 }
1197
1198 return '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
1199<html xmlns="http://www.w3.org/1999/xhtml" ' . $htmllang . '>
1200<head>
1201<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
1202<title>' . $title . '</title>
1203</head><body>' . $content . '</body></html>';
1204 }
c84a2dbe 1205}