/** * Outputs the page's footer * @return string HTML fragment */ public function footer() { global $CFG, $DB, $USER; $output = $this->container_end_all(true); $footer = $this->opencontainers->pop('header/footer'); if (debugging() and $DB and $DB->is_transaction_started()) { // TODO: MDL-20625 print warning - transaction will be rolled back } // Provide some performance info if required $performanceinfo = ''; if (defined('MDL_PERF') || (!empty($CFG->perfdebug) and $CFG->perfdebug > 7)) { $perf = get_performance_info(); if (defined('MDL_PERFTOLOG') && !function_exists('register_shutdown_function')) { error_log("PERF: " . $perf['txt']); } if (defined('MDL_PERFTOFOOT') || debugging() || $CFG->perfdebug > 7) { $performanceinfo = krystle_performance_output($perf); } } $perftoken = property_exists($this, "unique_performance_info_token") ? $this->unique_performance_info_token : self::PERFORMANCE_INFO_TOKEN; $endhtmltoken = property_exists($this, "unique_end_html_token") ? $this->unique_end_html_token : self::END_HTML_TOKEN; $footer = str_replace($perftoken, $performanceinfo, $footer); $footer = str_replace($endhtmltoken, $this->page->requires->get_end_code(), $footer); $this->page->set_state(moodle_page::STATE_DONE); if (!empty($this->page->theme->settings->persistentedit) && property_exists($USER, 'editing') && $USER->editing && !$this->really_editing) { $USER->editing = false; } return $output . $footer; }
/** * Outputs the page's footer * @return string HTML fragment */ public function footer() { global $CFG, $DB; $output = $this->container_end_all(true); $footer = $this->opencontainers->pop('header/footer'); if (debugging() and $DB and $DB->is_transaction_started()) { // TODO: MDL-20625 print warning - transaction will be rolled back } // Provide some performance info if required $performanceinfo = ''; if (defined('MDL_PERF') || (!empty($CFG->perfdebug) and $CFG->perfdebug > 7)) { $perf = get_performance_info(); if (defined('MDL_PERFTOLOG') && !function_exists('register_shutdown_function')) { error_log("PERF: " . $perf['txt']); } if (defined('MDL_PERFTOFOOT') || debugging() || $CFG->perfdebug > 7) { $performanceinfo = krystle2_performance_output($perf); } } $footer = str_replace(self::PERFORMANCE_INFO_TOKEN, $performanceinfo, $footer); $footer = str_replace(self::END_HTML_TOKEN, $this->page->requires->get_end_code(), $footer); $this->page->set_state(moodle_page::STATE_DONE); return $output . $footer; }
/** * Dwoo {mahara_performance_info} function plugin * * Type: function<br> * Name: mahara_performance_info<br> * Date: June 22, 2006<br> * Purpose: Fetch internationalized strings * @author Catalyst IT Ltd * @version 1.0 * @return html to display in the footer. */ function Dwoo_Plugin_mahara_performance_info(Dwoo $dwoo) { if (!get_config('perftofoot') && !get_config('perftolog')) { return; } $info = get_performance_info(); $dwoo = smarty_core(); foreach ($info as $key => $value) { if ($key == 'realtime') { $value = round($value, 3); } $dwoo->assign('perf_' . $key, $value); } // extras $dwoo->assign('perf_memory_total_display', display_size($info['memory_total'])); $dwoo->assign('perf_memory_growth_display', display_size($info['memory_growth'])); if (get_config('perftolog')) { perf_to_log($info); } if (get_config('perftofoot')) { return $dwoo->fetch('performancefooter.tpl'); } }
/** * Outputs the page's footer * @return string HTML fragment */ public function footer() { global $CFG, $USER; $output = $this->container_end_all(true); $footer = $this->opencontainers->pop('header/footer'); // Provide some performance info if required $performanceinfo = ''; if (defined('MDL_PERF') || (!empty($CFG->perfdebug) and $CFG->perfdebug > 7)) { $perf = get_performance_info(); if (defined('MDL_PERFTOLOG') && !function_exists('register_shutdown_function')) { error_log("PERF: " . $perf['txt']); } if (defined('MDL_PERFTOFOOT') || debugging() || $CFG->perfdebug > 7) { $performanceinfo = essential_performance_output($perf); } } $footer = str_replace($this->unique_performance_info_token, $performanceinfo, $footer); $footer = str_replace($this->unique_end_html_token, $this->page->requires->get_end_code(), $footer); $this->page->set_state(moodle_page::STATE_DONE); if (!empty($this->page->theme->settings->persistentedit) && property_exists($USER, 'editing') && $USER->editing && !$this->really_editing) { $USER->editing = false; } return $output . $footer; }
/** * Outputs the page's footer * * @return string HTML fragment */ public function footer() { global $CFG, $DB; $output = $this->container_end_all(true); $footer = $this->opencontainers->pop('header/footer'); if (debugging() and $DB and $DB->is_transaction_started()) { // TODO: MDL-20625 print warning - transaction will be rolled back } // Provide some performance info if required $performanceinfo = ''; if (defined('MDL_PERF') || (!empty($CFG->perfdebug) and $CFG->perfdebug > 7)) { $perf = get_performance_info(); if (defined('MDL_PERFTOFOOT') || debugging() || $CFG->perfdebug > 7) { $performanceinfo = $perf['html']; } } // We always want performance data when running a performance test, even if the user is redirected to another page. if (MDL_PERF_TEST && strpos($footer, $this->unique_performance_info_token) === false) { $footer = $this->unique_performance_info_token . $footer; } $footer = str_replace($this->unique_performance_info_token, $performanceinfo, $footer); $footer = str_replace($this->unique_end_html_token, $this->page->requires->get_end_code(), $footer); $this->page->set_state(moodle_page::STATE_DONE); return $output . $footer; }
/** * Outputs the page's footer * @return string HTML fragment */ public function footer() { global $CFG; $output = $this->container_end_all(true); $footer = $this->opencontainers->pop('header/footer'); // Provide some performance info if required. $performanceinfo = ''; if (defined('MDL_PERF') || (!empty($CFG->perfdebug) and $CFG->perfdebug > 7)) { $perf = get_performance_info(); if (defined('MDL_PERFTOLOG') && !function_exists('register_shutdown_function')) { // @codingStandardsIgnoreStart error_log("PERF: " . $perf['txt']); // @codingStandardsIgnoreEnd } if (defined('MDL_PERFTOFOOT') || debugging() || $CFG->perfdebug > 7) { $performanceinfo = $this->performance_output($perf, \theme_essential\toolbox::get_setting('perfinfo')); } } $footer = str_replace($this->unique_performance_info_token, $performanceinfo, $footer); $footer = str_replace($this->unique_end_html_token, $this->page->requires->get_end_code(), $footer); $this->page->set_state(moodle_page::STATE_DONE); $info = '<!-- Essential theme version: ' . $this->page->theme->settings->version . ', developed, enhanced and maintained by Gareth J Barnard: about.me/gjbarnard -->'; return $output . $footer . $info; }
/** * Redirects the user to another page, after printing a notice * * @param string $url The url to take the user to * @param string $message The text message to display to the user about the redirect, if any * @param string $delay How long before refreshing to the new page at $url? * @todo '&' needs to be encoded into '&' for XHTML compliance, * however, this is not true for javascript. Therefore we * first decode all entities in $url (since we cannot rely on) * the correct input) and then encode for where it's needed * echo "<script type='text/javascript'>alert('Redirect $url');</script>"; */ function redirect($url, $message = '', $delay = -1) { global $CFG, $THEME, $SESSION, $PAGE; if (!empty($CFG->usesid) && !isset($_COOKIE[session_name()])) { $url = $SESSION->sid_process_url($url); } $message = clean_text($message); $encodedurl = preg_replace("/\\&(?![a-zA-Z0-9#]{1,8};)/", "&", $url); $encodedurl = preg_replace('/^.*href="([^"]*)".*$/', "\\1", clean_text('<a href="' . $encodedurl . '" />')); $url = str_replace('&', '&', $encodedurl); /// At developer debug level. Don't redirect if errors have been printed on screen. /// Currenly only works in PHP 5.2+; we do not want strict PHP5 errors $lasterror = error_get_last(); $error = defined('DEBUGGING_PRINTED') or !empty($lasterror) && $lasterror['type'] & DEBUG_DEVELOPER; $errorprinted = debugging('', DEBUG_ALL) && $CFG->debugdisplay && $error; if ($errorprinted) { $message = "<strong>Error output, so disabling automatic redirect.</strong></p><p>" . $message; } $performanceinfo = ''; if (defined('MDL_PERF') || (!empty($CFG->perfdebug) and $CFG->perfdebug > 7)) { if (defined('MDL_PERFTOLOG') && !function_exists('register_shutdown_function')) { $perf = get_performance_info(); error_log("PERF: " . $perf['txt']); } } /// when no message and header printed yet, try to redirect if (empty($message) and !$PAGE->headerprinted) { // Technically, HTTP/1.1 requires Location: header to contain // the absolute path. (In practice browsers accept relative // paths - but still, might as well do it properly.) // This code turns relative into absolute. if (!preg_match('|^[a-z]+:|', $url)) { // Get host name http://www.wherever.com $hostpart = preg_replace('|^(.*?[^:/])/.*$|', '$1', $CFG->wwwroot); if (preg_match('|^/|', $url)) { // URLs beginning with / are relative to web server root so we just add them in $url = $hostpart . $url; } else { // URLs not beginning with / are relative to path of current script, so add that on. $url = $hostpart . preg_replace('|\\?.*$|', '', me()) . '/../' . $url; } // Replace all ..s while (true) { $newurl = preg_replace('|/(?!\\.\\.)[^/]*/\\.\\./|', '/', $url); if ($newurl == $url) { break; } $url = $newurl; } } $delay = 0; //try header redirection first @header($_SERVER['SERVER_PROTOCOL'] . ' 303 See Other'); //302 might not work for POST requests, 303 is ignored by obsolete clients @header('Location: ' . $url); //another way for older browsers and already sent headers (eg trailing whitespace in config.php) echo '<meta http-equiv="refresh" content="' . $delay . '; url=' . $encodedurl . '" />'; print_js_call('document.location.replace', array($url)); die; } if ($delay == -1) { $delay = 3; // if no delay specified wait 3 seconds } if (!$PAGE->headerprinted) { // this type of redirect might not be working in some browsers - such as lynx :-( print_header('', '', '', '', $errorprinted ? '' : '<meta http-equiv="refresh" content="' . $delay . '; url=' . $encodedurl . '" />'); $delay += 3; // double redirect prevention, it was sometimes breaking upgrades before 1.7 } else { print_container_end_all(false, $THEME->open_header_containers); } echo '<div id="redirect">'; echo '<div id="message">' . $message . '</div>'; echo '<div id="continue">( <a href="' . $encodedurl . '">' . get_string('continue') . '</a> )</div>'; echo '</div>'; if (!$errorprinted) { print_delayed_js_call($delay, 'document.location.replace', array($url)); } $CFG->docroot = false; // to prevent the link to moodle docs from being displayed on redirect page. print_footer('none'); die; }
function moodle_request_shutdown() { global $CFG; // initially, we are only ever called under apache // but check just in case if (function_exists('apache_child_terminate') && function_exists('memory_get_usage') && ini_get_bool('child_terminate')) { if (empty($CFG->apachemaxmem)) { $CFG->apachemaxmem = 25000000; // default 25MiB } if (memory_get_usage() > (int) $CFG->apachemaxmem) { trigger_error('Mem usage over $CFG->apachemaxmem: marking child for reaping.'); @apache_child_terminate(); } } if (defined('MDL_PERF') || (!empty($CFG->perfdebug) and $CFG->perfdebug > 7)) { if (defined('MDL_PERFTOLOG')) { $perf = get_performance_info(); error_log("PERF: " . $perf['txt']); } if (defined('MDL_PERFINC')) { $inc = get_included_files(); $ts = 0; foreach ($inc as $f) { if (preg_match(':^/:', $f)) { $fs = filesize($f); $ts += $fs; $hfs = display_size($fs); error_log(substr($f, strlen($CFG->dirroot)) . " size: {$fs} ({$hfs})", NULL, NULL, 0); } else { error_log($f, NULL, NULL, 0); } } if ($ts > 0) { $hts = display_size($ts); error_log("Total size of files included: {$ts} ({$hts})"); } } } }
/** * This function expects to called during shutdown * should be set via register_shutdown_function() * in lib/setup.php . * * @return void */ function moodle_request_shutdown() { global $CFG; // help apache server if possible $apachereleasemem = false; if (function_exists('apache_child_terminate') && function_exists('memory_get_usage') && ini_get_bool('child_terminate')) { $limit = empty($CFG->apachemaxmem) ? 64 * 1024 * 1024 : $CFG->apachemaxmem; //64MB default if (memory_get_usage() > get_real_size($limit)) { $apachereleasemem = $limit; @apache_child_terminate(); } } // deal with perf logging if (defined('MDL_PERF') || (!empty($CFG->perfdebug) and $CFG->perfdebug > 7)) { if ($apachereleasemem) { error_log('Mem usage over ' . $apachereleasemem . ': marking Apache child for reaping.'); } if (defined('MDL_PERFTOLOG')) { $perf = get_performance_info(); error_log("PERF: " . $perf['txt']); } if (defined('MDL_PERFINC')) { $inc = get_included_files(); $ts = 0; foreach ($inc as $f) { if (preg_match(':^/:', $f)) { $fs = filesize($f); $ts += $fs; $hfs = display_size($fs); error_log(substr($f, strlen($CFG->dirroot)) . " size: {$fs} ({$hfs})", NULL, NULL, 0); } else { error_log($f, NULL, NULL, 0); } } if ($ts > 0) { $hts = display_size($ts); error_log("Total size of files included: {$ts} ({$hts})"); } } } }
/** * Redirects the user to another page, after printing a notice * * @param string $url The url to take the user to * @param string $message The text message to display to the user about the redirect, if any * @param string $delay How long before refreshing to the new page at $url? * @todo '&' needs to be encoded into '&' for XHTML compliance, * however, this is not true for javascript. Therefore we * first decode all entities in $url (since we cannot rely on) * the correct input) and then encode for where it's needed * echo "<script type='text/javascript'>alert('Redirect $url');</script>"; */ function redirect($url, $message = '', $delay = -1, $adminroot = '') { global $CFG; if (!empty($CFG->usesid) && !isset($_COOKIE[session_name()])) { $url = sid_process_url($url); } $message = clean_text($message); $url = html_entity_decode($url); $url = str_replace(array("\n", "\r"), '', $url); // some more cleaning $encodedurl = htmlentities($url); $tmpstr = clean_text('<a href="' . $encodedurl . '" />'); //clean encoded URL $encodedurl = substr($tmpstr, 9, strlen($tmpstr) - 13); $url = html_entity_decode($encodedurl); $surl = addslashes($url); $performanceinfo = ''; if (defined('MDL_PERF') || (!empty($CFG->perfdebug) and $CFG->perfdebug > 7)) { if (defined('MDL_PERFTOLOG') && !function_exists('register_shutdown_function')) { $perf = get_performance_info(); error_log("PERF: " . $perf['txt']); } } /// when no message and header printed yet, try to redirect if (empty($message) and !defined('HEADER_PRINTED')) { // Technically, HTTP/1.1 requires Location: header to contain // the absolute path. (In practice browsers accept relative // paths - but still, might as well do it properly.) // This code turns relative into absolute. if (!preg_match('|^[a-z]+:|', $url)) { // Get host name http://www.wherever.com $hostpart = preg_replace('|^(.*?[^:/])/.*$|', '$1', $CFG->wwwroot); if (preg_match('|^/|', $url)) { // URLs beginning with / are relative to web server root so we just add them in $url = $hostpart . $url; } else { // URLs not beginning with / are relative to path of current script, so add that on. $url = $hostpart . preg_replace('|\\?.*$|', '', me()) . '/../' . $url; } // Replace all ..s while (true) { $newurl = preg_replace('|/(?!\\.\\.)[^/]*/\\.\\./|', '/', $url); if ($newurl == $url) { break; } $url = $newurl; } } $delay = 0; //try header redirection first @header($_SERVER['SERVER_PROTOCOL'] . ' 303 See Other'); //302 might not work for POST requests, 303 is ignored by obsolete clients @header('Location: ' . $url); //another way for older browsers and already sent headers (eg trailing whitespace in config.php) echo '<meta http-equiv="refresh" content="' . $delay . '; url=' . $encodedurl . '" />'; echo '<script type="text/javascript">' . "\n" . '//<![CDATA[' . "\n" . "location.replace('{$surl}');" . "\n" . '//]]>' . "\n" . '</script>'; // To cope with Mozilla bug die; } if ($delay == -1) { $delay = 3; // if no delay specified wait 3 seconds } if (!defined('HEADER_PRINTED')) { // this type of redirect might not be working in some browsers - such as lynx :-( print_header('', '', '', '', '<meta http-equiv="refresh" content="' . $delay . '; url=' . $encodedurl . '" />'); $delay += 3; // double redirect prevention, it was sometimes breaking upgrades before 1.7 } echo '<div style="text-align:center">'; echo '<div>' . $message . '</div>'; echo '<div>( <a href="' . $encodedurl . '">' . get_string('continue') . '</a> )</div>'; echo '</div>'; // it might be better not to set timeout the same for both types of redirect, so that we can be sure which one wins ?> <script type="text/javascript"> //<![CDATA[ function redirect() { document.location.replace('<?php echo $surl; ?> '); } setTimeout("redirect()", <?php echo $delay * 1000; ?> ); //]]> </script> <?php $CFG->docroot = false; // to prevent the link to moodle docs from being displayed on redirect page. // fix for MDL-8517, admin pages redirections causes bad xhtml if ($adminroot) { admin_externalpage_print_footer($adminroot); } else { print_footer('none'); } die; }
function perf_to_log($info = null) { if (!get_config('perftolog')) { return true; } if (empty($info)) { $info = get_performance_info(); } $logstring = 'PERF: ' . strip_querystring(get_script_path()) . ': '; $logstring .= ' memory_total: ' . $info['memory_total'] . 'B (' . display_size($info['memory_total']) . ') memory_growth: ' . $info['memory_growth'] . 'B (' . display_size($info['memory_growth']) . ')'; $logstring .= ' time: ' . $info['realtime'] . 's'; $logstring .= ' includecount: ' . $info['includecount']; $logstring .= ' dbqueries: ' . $info['dbreads'] . ' reads, ' . $info['dbwrites'] . ' writes, ' . $info['dbcached'] . ' cached'; $logstring .= ' ticks: ' . $info['ticks'] . ' user: '******'utime'] . ' sys: ' . $info['stime'] . ' cuser: '******'cutime'] . ' csys: ' . $info['cstime']; $logstring .= ' serverload: ' . $info['serverload']; log_debug($logstring); }
function templates_variables_substitute($param) { global $CFG; $variables = $param[0]; $template_variable = $param[1]; $run_result = ''; // Substitute variables in templates: // where {{variablename}} is found in the template, this function is passed // "variablename" and returns the proper variable global $menubar; global $submenubar; global $metatags; global $PAGE; global $template_id; //error_log("tvs " . print_r($template_variable,1)); if (isset($variables[$template_variable])) { return $variables[$template_variable]; } else { switch ($template_variable) { case "username": if (logged_on) { return $_SESSION['username']; } else { return gettext("Guest"); } break; case "userfullname": if (logged_on) { return htmlspecialchars($_SESSION['name'], ENT_COMPAT, 'utf-8'); } else { return gettext("Guest") . " [<a href=\"" . url . "login/index.php\">" . gettext("Log in") . "</a>]"; } break; // case "userfullname": // global $page_owner; // if (!isset($page_owner) || $page_owner == -1) { // return ""; // } else { // return run("users:id_to_name", $page_owner); // } // break; // case "userfullname": // global $page_owner; // if (!isset($page_owner) || $page_owner == -1) { // return ""; // } else { // return run("users:id_to_name", $page_owner); // } // break; case "menu": if (logged_on) { return templates_draw(array('menuitems' => menu_join('', $PAGE->menu), 'context' => 'menu')); } break; case "submenu": return templates_draw(array('submenuitems' => menu_join(' | ', $PAGE->menu_sub), 'context' => 'submenu')); break; case "topmenu": if (logged_on) { return templates_draw(array('topmenuitems' => menu_join('', $PAGE->menu_top), 'context' => 'topmenu')); } break; case "url": return url; break; case "metatags": // $run_result = "<link href=\"/".$template_variable.".css\" rel=\"stylesheet\" type=\"text/css\" />"; return "<style type=\"text/css\"><!--\n" . templates_draw(array('template' => $template_id, 'context' => 'css')) . "// -->\n</style>\n" . $metatags; break; case 'perf': $perf = get_performance_info(); if (defined('ELGG_PERFTOLOG')) { error_log("PERF: " . $perf['txt']); } if (defined('ELGG_PERFTOFOOT') || $CFG->debug > 7 || $CFG->perfdebug > 7) { return $perf['html']; } break; } } return $run_result; }
/** * Output basic html page. * @static * @param string $title page title * @param string $content page content * @param string $meta meta tag * @return string html page */ public static function plain_page($title, $content, $meta = '') { if (function_exists('get_string') && function_exists('get_html_lang')) { $htmllang = get_html_lang(); } else { $htmllang = ''; } $footer = ''; if (MDL_PERF_TEST) { $perfinfo = get_performance_info(); $footer = '<footer>' . $perfinfo['html'] . '</footer>'; } return '<!DOCTYPE html> <html ' . $htmllang . '> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> ' . $meta . ' <title>' . $title . '</title> </head><body>' . $content . $footer . '</body></html>'; }
/** * Outputs the page's footer * @return string HTML fragment */ public function footer() { $output = $this->opencontainers->pop_all_but_last(true); $footer = $this->opencontainers->pop('header/footer'); // Provide some performance info if required $performanceinfo = ''; if (defined('MDL_PERF') || (!empty($CFG->perfdebug) and $CFG->perfdebug > 7)) { $perf = get_performance_info(); if (defined('MDL_PERFTOLOG') && !function_exists('register_shutdown_function')) { error_log("PERF: " . $perf['txt']); } if (defined('MDL_PERFTOFOOT') || debugging() || $CFG->perfdebug > 7) { $performanceinfo = $perf['html']; } } $footer = str_replace(self::PERFORMANCE_INFO_TOKEN, $performanceinfo, $footer); $footer = str_replace(self::END_HTML_TOKEN, $this->page->requires->get_end_code(), $footer); $this->page->set_state(moodle_page::STATE_DONE); return $output . $footer; }
/** * Returns html to render footer * * @return string */ public function footer() { global $CFG; $output = $this->container_end_all(true); $footer = $this->opencontainers->pop('header/footer'); // Provide some performance info if required. $performanceinfo = ''; if (defined('MDL_PERF') || (!empty($CFG->perfdebug) and $CFG->perfdebug > 7)) { $perf = get_performance_info(); // Deprecated function. Display: The use of function error_log() is forbidden. // if (defined('MDL_PERFTOLOG') && !function_exists('register_shutdown_function')) {. // error_log("PERF: " . $perf['txt']);. // }. if (defined('MDL_PERFTOFOOT') || debugging() || $CFG->perfdebug > 7) { $performanceinfo = theme_adaptable_performance_output($perf); } } $footer = str_replace($this->unique_performance_info_token, $performanceinfo, $footer); $footer = str_replace($this->unique_end_html_token, $this->page->requires->get_end_code(), $footer); $this->page->set_state(moodle_page::STATE_DONE); return $output . $footer; }
function templates_variables_substitute($param) { global $CFG; $variables = $param[0]; $template_variable = $param[1]; $run_result = ''; // Substitute variables in templates: // where {{variablename}} is found in the template, this function is passed // "variablename" and returns the proper variable global $menubar; global $submenubar; global $metatags; global $PAGE; global $template_id; global $template_name; global $db; //error_log("tvs " . print_r($template_variable,1)); $result = ""; if (isset($variables[$template_variable])) { $result .= $variables[$template_variable]; } else { $vars = array(); if (substr_count($template_variable, ":") > 0) { $vars = explode(":", $template_variable); $template_variable = $vars[0]; } switch ($template_variable) { case "username": if (logged_on) { $result = $_SESSION['username']; } else { $result = __gettext("Guest"); } break; case "usericonid": if (logged_on) { $result = user_info("icon", $_SESSION['userid']); } else { $result = 0; } break; case "name": if (logged_on) { $result = htmlspecialchars($_SESSION['name'], ENT_COMPAT, 'utf-8'); } else { $result = __gettext("Guest"); } break; case "userfullname": if (logged_on) { $result = __gettext("Welcome") . " " . htmlspecialchars($_SESSION['name'], ENT_COMPAT, 'utf-8'); } else { $result = __gettext("Welcome") . " " . __gettext("Guest") . " [<a href=\"" . url . "login/index.php\">" . __gettext("Log in") . "</a>]"; } break; case "menu": if (logged_on) { $result = templates_draw(array('menuitems' => menu_join('', $PAGE->menu), 'context' => 'menu')); } break; case "submenu": $result = templates_draw(array('submenuitems' => menu_join(' | ', $PAGE->menu_sub), 'context' => 'submenu')); break; case "topmenu": $result = templates_draw(array('topmenuitems' => menu_join('', $PAGE->menu_top), 'context' => 'topmenu')); break; case "url": $result = url; break; case "sitename": $result = $CFG->sitename; break; case "tagline": $result = $CFG->tagline; break; case "metatags": if (!empty($template_name)) { // use a defined style $result = '<link href="' . $CFG->wwwroot . '_templates/css/' . $template_name . '" rel="stylesheet" type="text/css" />' . "\n"; } else { // use whatever's in $template['css'] $result = "<style type=\"text/css\">\n" . templates_draw(array('template' => $template_name, 'context' => 'css')) . "\n</style>\n"; } // locate css at end $result = $metatags . "\n" . $result; break; case 'perf': $perf = get_performance_info(); if (defined('ELGG_PERFTOLOG')) { error_log("PERF: " . $perf['txt']); } if (defined('ELGG_PERFTOFOOT') || $CFG->debug > 7 || $CFG->perfdebug > 7) { $result = $perf['html']; } break; case 'randomusers': $result = ""; if (isset($vars[1])) { $vars[1] = (int) $vars[1]; } else { $vars[1] = 3; } if ($users = get_records_sql("SELECT DISTINCT u.*,i.filename AS iconfile, " . $db->random . " as rand \n FROM " . $CFG->prefix . "profile_data t JOIN " . $CFG->prefix . "users u ON u.ident = t.owner\n LEFT JOIN " . $CFG->prefix . "icons i ON i.ident = u.icon \n WHERE t.name IN (?,?,?) AND u.icon != ? AND t.access = ? AND u.user_type = ? \n ORDER BY rand LIMIT " . $vars[1], array('biography', 'minibio', 'interests', -1, 'PUBLIC', 'person'))) { $usercount = 0; foreach ($users as $user) { if ($usercount > 0) { $result .= ", "; } else { $result .= " "; } $result .= "<a href=\"" . $CFG->wwwroot . $user->username . "/\">" . $user->name . "</a>"; $usercount++; } } else { $result .= __gettext("Sorry, no users have filled in their profiles yet."); } break; case 'people': $result = ""; if (isset($vars[1])) { $vars[1] = $db->qstr($vars[1]); } else { $vars[1] = "'interests'"; } if (isset($vars[2])) { $vars[2] = $db->qstr($vars[2]); } else { $vars[2] = "'foo'"; } if (isset($vars[3])) { $vars[3] = (int) $vars[3]; } else { $vars[3] = 5; } $users = get_records_sql("SELECT users.*, icons.filename as iconfile, icons.ident as iconid FROM " . $CFG->prefix . "tags LEFT JOIN " . $CFG->prefix . "users ON users.ident = tags.owner left join " . $CFG->prefix . "icons on icons.ident = users.icon WHERE tags.tag = " . $vars[2] . " AND tags.tagtype = " . $vars[1] . " AND users.icon != -1 AND tags.access = 'PUBLIC' and users.user_type = 'person' ORDER BY rand( ) LIMIT " . $vars[3]); if (sizeof($users) > 0 && is_array($users)) { $result .= <<<END <table width="550px" border="0" cellpadding="0" cellspacing="0"> <tr> END; foreach ($users as $user) { $icon_html = user_icon_html($user->ident, 67); $result .= <<<END <td align="center"> <div class="image_holder"> <a href="{$CFG->wwwroot}{$user->username}/">{$icon_html}</a> </div> <div class="userdetails"> <p><a href="{$CFG->wwwroot}{$user->username}/">{$user->name}</a></p> </div> END; } $result .= <<<END <tr> </table> END; } break; case "toptags": if (isset($vars[1])) { $vars[1] = $db->qstr($vars[1]); } else { $vars[1] = "'town'"; } if ($tags = get_records_sql("SELECT tag, count(ident) as numtags FROM `" . $CFG->prefix . "tags` WHERE access = 'public' and tagtype=" . $vars[1] . " group by tag order by numtags desc limit 20")) { $tag_count = 0; foreach ($tags as $tag) { $result .= "<a href=\"" . url . "tag/" . urlencode(htmlspecialchars(strtolower($tag->tag), ENT_COMPAT, 'utf-8')) . "\" title=\"" . htmlspecialchars($tag->tag, ENT_COMPAT, 'utf-8') . " (" . $tag->numtags . ")\">"; $result .= $tag->tag . "</a>"; if ($tag_count < sizeof($tags) - 1) { $result .= ", "; } $tag_count++; } } break; case "populartags": $result = ""; if ($tags = get_records_sql("SELECT tag, count(ident) as numtags FROM `" . $CFG->prefix . "tags` WHERE access = 'public' and tag!='' group by tag having numtags > 1 order by ident desc limit 20")) { $max = 0; foreach ($tags as $tag) { if ($tag->numtags > $max) { $max = $tag->numtags; } } $tag_count = 0; foreach ($tags as $tag) { if ($max > 1) { $size = round(log($tag->numtags) / log($max) * 300); } else { $size = 100; } $result .= "<a href=\"" . url . "tag/" . urlencode(htmlspecialchars(strtolower($tag->tag), ENT_COMPAT, 'utf-8')) . "\" style=\"font-size: {$size}%\" title=\"" . htmlspecialchars($tag->tag, ENT_COMPAT, 'utf-8') . " (" . $tag->numtags . ")\">"; $result .= $tag->tag . "</a>"; if ($tag_count < sizeof($tags) - 1) { $result .= ", "; } $tag_count++; } } break; default: break; } } if (!empty($CFG->templates->variables_substitute) && !empty($CFG->templates->variables_substitute[$template_variable])) { if (is_array($CFG->templates->variables_substitute[$template_variable])) { foreach ($CFG->templates->variables_substitute[$template_variable] as $sub_function) { $result .= $sub_function($vars); } } elseif (is_callable($CFG->templates->variables_substitute[$template_variable])) { $result .= $CFG->templates->variables_substitute[$template_variable]($vars); } } $run_result .= $result; return $run_result; }
/** * Redirects the user to another page, after printing a notice * * This function calls the OUTPUT redirect method, echo's the output * and then dies to ensure nothing else happens. * * <strong>Good practice:</strong> You should call this method before starting page * output by using any of the OUTPUT methods. * * @param moodle_url $url A moodle_url to redirect to. Strings are not to be trusted! * @param string $message The message to display to the user * @param int $delay The delay before redirecting * @return void */ function redirect($url, $message = '', $delay = -1) { global $OUTPUT, $SESSION, $CFG; if ($url instanceof moodle_url) { $url = $url->out(false, array(), false); } if (!empty($CFG->usesid) && !isset($_COOKIE[session_name()])) { $url = $SESSION->sid_process_url($url); } $lasterror = error_get_last(); $debugdisableredirect = defined('DEBUGGING_PRINTED') || !empty($CFG->debugdisplay) && !empty($lasterror) && $lasterror['type'] & DEBUG_DEVELOPER; $usingmsg = false; if (!empty($message)) { if ($delay === -1 || !is_numeric($delay)) { $delay = 3; } $message = clean_text($message); } else { $message = get_string('pageshouldredirect'); $delay = 0; // We are going to try to use a HTTP redirect, so we need a full URL. if (!preg_match('|^[a-z]+:|', $url)) { // Get host name http://www.wherever.com $hostpart = preg_replace('|^(.*?[^:/])/.*$|', '$1', $CFG->wwwroot); if (preg_match('|^/|', $url)) { // URLs beginning with / are relative to web server root so we just add them in $url = $hostpart . $url; } else { // URLs not beginning with / are relative to path of current script, so add that on. $url = $hostpart . preg_replace('|\\?.*$|', '', me()) . '/../' . $url; } // Replace all ..s while (true) { $newurl = preg_replace('|/(?!\\.\\.)[^/]*/\\.\\./|', '/', $url); if ($newurl == $url) { break; } $url = $newurl; } } } if (defined('MDL_PERF') || (!empty($CFG->perfdebug) and $CFG->perfdebug > 7)) { if (defined('MDL_PERFTOLOG') && !function_exists('register_shutdown_function')) { $perf = get_performance_info(); error_log("PERF: " . $perf['txt']); } } $encodedurl = preg_replace("/\\&(?![a-zA-Z0-9#]{1,8};)/", "&", $url); $encodedurl = preg_replace('/^.*href="([^"]*)".*$/', "\\1", clean_text('<a href="' . $encodedurl . '" />')); if ($delay == 0 && !$debugdisableredirect && !headers_sent()) { //302 might not work for POST requests, 303 is ignored by obsolete clients. @header($_SERVER['SERVER_PROTOCOL'] . ' 303 See Other'); @header('Location: ' . $url); echo bootstrap_renderer::plain_redirect_message($encodedurl); exit; } // Include a redirect message, even with a HTTP redirect, because that is recommended practice. $CFG->docroot = false; // to prevent the link to moodle docs from being displayed on redirect page. echo $OUTPUT->redirect_message($encodedurl, $message, $delay, $debugdisableredirect); exit; }
/** * Redirects the user to another page, after printing a notice * * This function calls the OUTPUT redirect method, echo's the output * and then dies to ensure nothing else happens. * * <strong>Good practice:</strong> You should call this method before starting page * output by using any of the OUTPUT methods. * * @param moodle_url|string $url A moodle_url to redirect to. Strings are not to be trusted! * @param string $message The message to display to the user * @param int $delay The delay before redirecting * @return void - does not return! */ function redirect($url, $message = '', $delay = -1) { global $OUTPUT, $PAGE, $SESSION, $CFG; if (CLI_SCRIPT or AJAX_SCRIPT) { // this is wrong - developers should not use redirect in these scripts, // but it should not be very likely throw new moodle_exception('redirecterrordetected', 'error'); } // prevent debug errors - make sure context is properly initialised if ($PAGE) { $PAGE->set_context(null); } if ($url instanceof moodle_url) { $url = $url->out(false); } if (!empty($CFG->usesid) && !isset($_COOKIE[session_name()])) { $url = $SESSION->sid_process_url($url); } $debugdisableredirect = false; do { if (defined('DEBUGGING_PRINTED')) { // some debugging already printed, no need to look more $debugdisableredirect = true; break; } if (empty($CFG->debugdisplay) or empty($CFG->debug)) { // no errors should be displayed break; } if (!function_exists('error_get_last') or !($lasterror = error_get_last())) { break; } if (!($lasterror['type'] & $CFG->debug)) { //last error not interesting break; } // watch out here, @hidden() errors are returned from error_get_last() too if (headers_sent()) { //we already started printing something - that means errors likely printed $debugdisableredirect = true; break; } if (ob_get_level() and ob_get_contents()) { // there is something waiting to be printed, hopefully it is the errors, // but it might be some error hidden by @ too - such as the timezone mess from setup.php $debugdisableredirect = true; break; } } while (false); if (!empty($message)) { if ($delay === -1 || !is_numeric($delay)) { $delay = 3; } $message = clean_text($message); } else { $message = get_string('pageshouldredirect'); $delay = 0; // We are going to try to use a HTTP redirect, so we need a full URL. if (!preg_match('|^[a-z]+:|', $url)) { // Get host name http://www.wherever.com $hostpart = preg_replace('|^(.*?[^:/])/.*$|', '$1', $CFG->wwwroot); if (preg_match('|^/|', $url)) { // URLs beginning with / are relative to web server root so we just add them in $url = $hostpart . $url; } else { // URLs not beginning with / are relative to path of current script, so add that on. $url = $hostpart . preg_replace('|\\?.*$|', '', me()) . '/../' . $url; } // Replace all ..s while (true) { $newurl = preg_replace('|/(?!\\.\\.)[^/]*/\\.\\./|', '/', $url); if ($newurl == $url) { break; } $url = $newurl; } } } if (defined('MDL_PERF') || (!empty($CFG->perfdebug) and $CFG->perfdebug > 7)) { if (defined('MDL_PERFTOLOG') && !function_exists('register_shutdown_function')) { $perf = get_performance_info(); error_log("PERF: " . $perf['txt']); } } $encodedurl = preg_replace("/\\&(?![a-zA-Z0-9#]{1,8};)/", "&", $url); $encodedurl = preg_replace('/^.*href="([^"]*)".*$/', "\\1", clean_text('<a href="' . $encodedurl . '" />')); if ($delay == 0 && !$debugdisableredirect && !headers_sent()) { // workaround for IIS bug http://support.microsoft.com/kb/q176113/ if (session_id()) { session_get_instance()->write_close(); } //302 might not work for POST requests, 303 is ignored by obsolete clients. @header($_SERVER['SERVER_PROTOCOL'] . ' 303 See Other'); @header('Location: ' . $url); echo bootstrap_renderer::plain_redirect_message($encodedurl); exit; } // Include a redirect message, even with a HTTP redirect, because that is recommended practice. $PAGE->set_pagelayout('redirect'); // No header and footer needed $CFG->docroot = false; // to prevent the link to moodle docs from being displayed on redirect page. echo $OUTPUT->redirect_message($encodedurl, $message, $delay, $debugdisableredirect); exit; }
function moodle_request_shutdown() { global $CFG; // initially, we are only ever called under apache // but check just in case if (function_exists('apache_child_terminate') && function_exists('memory_get_usage') && ini_get_bool('child_terminate')) { if (empty($CFG->apachemaxmem)) { $CFG->apachemaxmem = 25000000; // default 25MiB } if (memory_get_usage() > (int) $CFG->apachemaxmem) { trigger_error('Mem usage over $CFG->apachemaxmem: marking child for reaping.'); @apache_child_terminate(); } } if (defined('MDL_PERF') || (!empty($CFG->perfdebug) and $CFG->perfdebug > 7)) { if (defined('MDL_PERFTOLOG')) { $perf = get_performance_info(); error_log("PERF: " . $perf['txt']); } } }