diff --git a/bootstrap.php b/bootstrap.php index 093f7b6..566d843 100644 --- a/bootstrap.php +++ b/bootstrap.php @@ -29,6 +29,9 @@ * @var stdClass $CFG */ +// This call is required by Moodle, but this script should have been called by config.php anyway. +require_once(__DIR__.'/../../config.php'); + // This file does nothing if running from CLI. if (defined('CLI_SCRIPT') && CLI_SCRIPT) { return; @@ -40,8 +43,8 @@ if (!isset($CFG->dataroot)) { } // 1) Check and run the hook. -if (isset($auth_outage_bootstrap_callback) && is_callable($auth_outage_bootstrap_callback)) { - $auth_outage_bootstrap_callback(); +if (is_callable('auth_outage_bootstrap_callback')) { + call_user_func('auth_outage_bootstrap_callback'); } // 2) Check for allowed IPs during outages. diff --git a/classes/local/controllers/infopage.php b/classes/local/controllers/infopage.php index 11d4dd5..4c691d4 100644 --- a/classes/local/controllers/infopage.php +++ b/classes/local/controllers/infopage.php @@ -88,6 +88,7 @@ class infopage { /** * Generates and outputs the HTML for the info page. * @uses redirect + * @SuppressWarnings(PHPMD.UnusedLocalVariable) $viewbag is used inside 'require'. */ public function output() { global $PAGE, $CFG, $OUTPUT; @@ -96,11 +97,6 @@ class infopage { redirect(new moodle_url('/')); } - $viewbag = [ - 'admin' => is_siteadmin(), - 'outage' => $this->outage, - ]; - $PAGE->set_context(context_system::instance()); $PAGE->set_title($this->outage->get_title()); $PAGE->set_heading($this->outage->get_title()); @@ -110,6 +106,10 @@ class infopage { outagelib::inject(); echo $OUTPUT->header(); + $viewbag = [ + 'admin' => is_siteadmin(), + 'outage' => $this->outage, + ]; require($CFG->dirroot.'/auth/outage/views/info/content.php'); // Moodle 2.7 did not check for CLI mode, which was fixed later. diff --git a/classes/local/controllers/maintenance_static_page.php b/classes/local/controllers/maintenance_static_page.php index 4c40f06..7c2257b 100644 --- a/classes/local/controllers/maintenance_static_page.php +++ b/classes/local/controllers/maintenance_static_page.php @@ -58,7 +58,8 @@ class maintenance_static_page { } else if (PHPUNIT_TEST) { $html = ''; } else { - $data = maintenance_static_page_io::file_get_data($CFG->wwwroot.'/auth/outage/info.php?auth_outage_hide_warning=1&id='.$outage->id); + $data = maintenance_static_page_io::file_get_data( + $CFG->wwwroot.'/auth/outage/info.php?auth_outage_hide_warning=1&id='.$outage->id); $html = $data['contents']; } diff --git a/classes/local/controllers/maintenance_static_page_generator.php b/classes/local/controllers/maintenance_static_page_generator.php index e4efb00..1dd1426 100644 --- a/classes/local/controllers/maintenance_static_page_generator.php +++ b/classes/local/controllers/maintenance_static_page_generator.php @@ -116,7 +116,6 @@ class maintenance_static_page_generator { private function update_link_stylesheet() { $links = $this->dom->getElementsByTagName('link'); - /** @var DOMElement $link */ foreach ($links as $link) { $rel = $link->getAttribute("rel"); $href = $link->getAttribute("href"); @@ -137,6 +136,7 @@ class maintenance_static_page_generator { /** * Checks for urls inside filename. * @param string $filename + * @param string $baseref */ private function update_link_stylesheet_parse($filename, $baseref) { global $CFG; @@ -145,20 +145,20 @@ class maintenance_static_page_generator { if (!preg_match_all('#url\([\'"]?([^\'"\)]+)#', $contents, $matches)) { return; } - foreach ($matches[1] as $original_url) { + foreach ($matches[1] as $originalurl) { // Allow incomplete URLs in CSS, assume it is from moodle root. - if (maintenance_static_page_io::is_url($original_url)) { - $full_url = $original_url; - } else if ($original_url[0] == '/') { - $full_url = $CFG->wwwroot.$original_url; + if (maintenance_static_page_io::is_url($originalurl)) { + $fullurl = $originalurl; + } else if ($originalurl[0] == '/') { + $fullurl = $CFG->wwwroot.$originalurl; } else { - $full_url = $baseref.'/'.$original_url; + $fullurl = $baseref.'/'.$originalurl; } - $saved = $this->io->save_url_file($full_url); + $saved = $this->io->save_url_file($fullurl); if (!is_null($saved)) { - $final_url = $this->io->get_url_for_file($saved['url']); - $contents = str_replace($original_url, $final_url, $contents); + $finalurl = $this->io->get_url_for_file($saved['url']); + $contents = str_replace($originalurl, $finalurl, $contents); } } @@ -171,7 +171,6 @@ class maintenance_static_page_generator { private function update_link_favicon() { $links = $this->dom->getElementsByTagName('link'); - /** @var DOMElement $link */ foreach ($links as $link) { $rel = $link->getAttribute("rel"); $href = $link->getAttribute("href"); @@ -188,7 +187,6 @@ class maintenance_static_page_generator { private function update_images() { $links = $this->dom->getElementsByTagName('img'); - /** @var DOMElement $link */ foreach ($links as $link) { $src = $link->getAttribute("src"); if ($src == '') { diff --git a/file.php b/file.php index 725640c..799566c 100644 --- a/file.php +++ b/file.php @@ -27,6 +27,10 @@ * @var stdClass $CFG */ +// This file does not use Moodle initialization as a requirement. Supress Warning. +define('MOODLE_INTERNAL', true); +defined('MOODLE_INTERNAL') || die(); + // File should have at least 3 characters as we will check the extension below. if (!isset($_GET['file'])) { http_response_code(400); @@ -50,7 +54,7 @@ header('Pragma: '); header('Cache-Control: public, max-age='.$lifetime); header('Accept-Ranges: none'); -$auth_outage_bootstrap_callback = function () { +function auth_outage_bootstrap_callback() { global $CFG; // We are not using any external libraries or references in this file (cli maintenance is active). @@ -68,12 +72,12 @@ $auth_outage_bootstrap_callback = function () { } readfile($file); - exit(0); + die(); }; require_once(__DIR__.'/../../config.php'); // We should never reach here if config.php and auth/outage/bootstrap.php intercepted it correctly. +// If config.php did not execute the callback function we can use the debugging function here. debugging('Your config.php is not properly configured for auth/outage plugin. '. 'Please check the plugin settings for information.'); -exit(1); \ No newline at end of file diff --git a/tests/phpunit/local/controllers/maintenance_static_page_test.php b/tests/phpunit/local/controllers/maintenance_static_page_test.php index 4d3e479..637bb52 100644 --- a/tests/phpunit/local/controllers/maintenance_static_page_test.php +++ b/tests/phpunit/local/controllers/maintenance_static_page_test.php @@ -45,7 +45,8 @@ class maintenance_static_page_test extends auth_outage_base_testcase { $page = maintenance_static_page::create_from_html(''); self::assertSame($CFG->dataroot.'/climaintenance.template.html', $page->get_io()->get_template_file()); $page->get_io()->set_preview(true); - self::assertSame($CFG->dataroot.'/auth_outage/climaintenance/preview/climaintenance.html', $page->get_io()->get_template_file()); + self::assertSame($CFG->dataroot.'/auth_outage/climaintenance/preview/climaintenance.html', + $page->get_io()->get_template_file()); } public function test_resourcesfolder() { @@ -76,22 +77,22 @@ class maintenance_static_page_test extends auth_outage_base_testcase { } public function test_updatelinkstylesheet() { - $local_css_link = $this->get_fixture_path('simple.css'); - $external_css_link = 'http://google.com/coolstuff.css'; + $localcsslink = $this->get_fixture_path('simple.css'); + $externalcsslink = 'http://google.com/coolstuff.css'; $html = "\n". - '