forked from moodle/moodle
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MDL-56041 error: Enable custom 404 and 500 error pages
- Loading branch information
1 parent
49a9e8b
commit 43999a3
Showing
9 changed files
with
272 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,60 +1,101 @@ | ||
<?php | ||
// This file is part of Moodle - http://moodle.org/ | ||
// | ||
// Moodle is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// Moodle is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU General Public License | ||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
require('../config.php'); | ||
|
||
// Form submitted, do not check referer (original page unknown). | ||
if ($form = data_submitted()) { | ||
// Only deal with real users. | ||
if (!isloggedin()) { | ||
redirect($CFG->wwwroot); | ||
} | ||
|
||
// Send the message and redirect. | ||
$eventdata = new \core\message\message(); | ||
$eventdata->courseid = SITEID; | ||
$eventdata->component = 'moodle'; | ||
$eventdata->name = 'errors'; | ||
$eventdata->userfrom = $USER; | ||
$eventdata->userto = core_user::get_support_user(); | ||
$eventdata->subject = 'Error: '. $form->referer .' -> '. $form->requested; | ||
$eventdata->fullmessage = $form->text; | ||
$eventdata->fullmessageformat = FORMAT_PLAIN; | ||
$eventdata->fullmessagehtml = ''; | ||
$eventdata->smallmessage = ''; | ||
message_send($eventdata); | ||
|
||
redirect($CFG->wwwroot .'/course/', 'Message sent, thanks', 3); | ||
exit; | ||
} | ||
/** | ||
* Moodle 404 Error page | ||
* | ||
* This is for 404 error pages served by the webserver and then passed | ||
* to Moodle to be rendered using the site theme. | ||
* | ||
* ErrorDocument 404 /error/index.php | ||
* | ||
* @package core | ||
* @copyright 2020 Brendan Heywood <[email protected]> | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
|
||
$site = get_site(); | ||
$redirecturl = empty($_SERVER['REDIRECT_URL']) ? '' : $_SERVER['REDIRECT_URL']; | ||
$httpreferer = get_local_referer(false); | ||
$requesturi = empty($_SERVER['REQUEST_URI']) ? '' : $_SERVER['REQUEST_URI']; | ||
|
||
header("HTTP/1.0 404 Not Found"); | ||
header("Status: 404 Not Found"); | ||
|
||
$PAGE->set_url('/error/'); | ||
$PAGE->set_context(context_system::instance()); | ||
$PAGE->set_title($site->fullname .':Error'); | ||
$PAGE->set_heading($site->fullname .': Error 404'); | ||
$PAGE->navbar->add('Error 404 - File not Found'); | ||
echo $OUTPUT->header(); | ||
echo $OUTPUT->box(get_string('pagenotexist', 'error'). '<br />'.s($requesturi), 'generalbox boxaligncenter'); | ||
|
||
if (isloggedin()) { | ||
?> | ||
<p><?php echo get_string('pleasereport', 'error'); ?> | ||
<p><form action="<?php echo $CFG->wwwroot ?>/error/index.php" method="post"> | ||
<textarea rows="3" cols="50" name="text" id="text" spellcheck="true"></textarea><br /> | ||
<input type="hidden" name="referer" value="<?php p($httpreferer) ?>"> | ||
<input type="hidden" name="requested" value="<?php p($requesturi) ?>"> | ||
<input type="submit" value="<?php echo get_string('sendmessage', 'error'); ?>"> | ||
</form> | ||
<?php | ||
} else { | ||
echo $OUTPUT->continue_button($CFG->wwwroot); | ||
// @codingStandardsIgnoreStart | ||
require('../config.php'); | ||
// @codingStandardsIgnoreEnd | ||
|
||
$context = context_system::instance(); | ||
$title = get_string('pagenotexisttitle', 'error'); | ||
$PAGE->set_url('/error/index.php'); | ||
$PAGE->set_context($context); | ||
$PAGE->set_title($title); | ||
$PAGE->set_heading($title); | ||
$PAGE->navbar->add($title); | ||
|
||
$canmessage = has_capability('moodle/site:senderrormessage', $context); | ||
|
||
$supportuser = core_user::get_support_user(); | ||
|
||
// We can only message support if both the user has the capability | ||
// and the support user is a real user. | ||
if ($canmessage) { | ||
$canmessage = core_user::is_real_user($supportuser->id); | ||
} | ||
|
||
$mform = new \core\form\error_feedback($CFG->wwwroot . '/error/index.php'); | ||
|
||
if ($data = $mform->get_data()) { | ||
|
||
if (!$canmessage) { | ||
redirect($CFG->wwwroot); | ||
} | ||
echo $OUTPUT->footer(); | ||
?> | ||
|
||
// Send the message and redirect. | ||
$message = new \core\message\message(); | ||
$message->courseid = SITEID; | ||
$message->component = 'moodle'; | ||
$message->name = 'errors'; | ||
$message->userfrom = $USER; | ||
$message->userto = core_user::get_support_user(); | ||
$message->subject = 'Error: '. $data->referer .' -> '. $data->requested; | ||
$message->fullmessage = $data->text; | ||
$message->fullmessageformat = FORMAT_PLAIN; | ||
$message->fullmessagehtml = ''; | ||
$message->smallmessage = ''; | ||
$message->contexturl = $data->requested; | ||
message_send($message); | ||
|
||
redirect($CFG->wwwroot, get_string('sendmessagesent', 'error', $data->requested), 5); | ||
exit; | ||
} | ||
|
||
echo $OUTPUT->header(); | ||
echo $OUTPUT->notification(get_string('pagenotexist', 'error', s($ME)), 'error'); | ||
|
||
if (!empty($CFG->supportpage)) { | ||
echo \html_writer::tag('h4', get_string('supportpage', 'admin')); | ||
$link = \html_writer::link($CFG->supportpage, $CFG->supportpage); | ||
echo \html_writer::tag('p', $link); | ||
} | ||
if (!empty($CFG->supportemail)) { | ||
echo \html_writer::tag('h4', get_string('supportemail', 'admin')); | ||
$link = \html_writer::link('mailto:' . $CFG->supportemail, $CFG->supportemail); | ||
echo \html_writer::tag('p', $link); | ||
} | ||
|
||
if ($canmessage) { | ||
echo \html_writer::tag('h4', get_string('sendmessage', 'error')); | ||
$mform->display(); | ||
} else { | ||
echo $OUTPUT->continue_button($CFG->wwwroot); | ||
} | ||
|
||
echo $OUTPUT->footer(); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
<?php | ||
// This file is part of Moodle - http://moodle.org/ | ||
// | ||
// Moodle is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// Moodle is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU General Public License | ||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
/** | ||
* Moodle Generic plain page | ||
* | ||
* This is used for various pages, usually errors, early in the Moodle | ||
* bootstrap. It can be safetly customized by editing this file directly | ||
* but it MUST NOT contain any Moodle resources such as theme files generated | ||
* by php, it can only contain references to static css and images, and as a | ||
* precaution its recommended that everything is inlined rather than | ||
* references. This is why this file is located here as it cannot be inside | ||
* a Moodle theme. | ||
* | ||
* @package core | ||
* @copyright 2020 Brendan Heywood <[email protected]> | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
|
||
// @codingStandardsIgnoreStart | ||
?> | ||
<!DOCTYPE html> | ||
<html <?php echo $htmllang ?>> | ||
<head> | ||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> | ||
<?php echo $meta ?> | ||
<title><?php echo $title ?></title> | ||
<style> | ||
<?php | ||
// This is a very small modified subset of the bootstrap / boost css classes. | ||
?> | ||
body { | ||
margin: 0; | ||
font-family: -apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,"Helvetica Neue",Arial,"Noto Sans",sans-serif,"Apple Color Emoji","Segoe UI Emoji","Segoe UI Symbol","Noto Color Emoji"; | ||
font-size: .9375rem; | ||
font-weight: 400; | ||
line-height: 1.5; | ||
color: #343a40; | ||
text-align: left; | ||
background-color: #f2f2f2; | ||
} | ||
#page { | ||
margin-top: 15px; | ||
background: white; | ||
max-width: 600px; | ||
margin: 0 auto; | ||
padding: 15px; | ||
} | ||
#region-main { | ||
margin: 0 auto; | ||
border: 1px solid rgba(0,0,0,.125); | ||
padding: 1rem 1.25rem 1.25rem; | ||
background-color: #fff; | ||
} | ||
h1 { | ||
font-size: 2.34rem; | ||
margin: 0 0 .5rem; | ||
font-weight: 300; | ||
line-height: 1.2; | ||
} | ||
.alert-danger { | ||
color: #6e211e; | ||
background-color: #f6d9d8; | ||
border-color: #f3c9c8; | ||
padding: .75rem 1.25rem; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<div id="page"> | ||
<div id="region-main"> | ||
<h1><?php echo $title ?></h1> | ||
<?php echo $content ?> | ||
<?php echo $footer ?> | ||
</div> | ||
</div> | ||
</body> | ||
</html> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<?php | ||
// This file is part of Moodle - http://moodle.org/ | ||
// | ||
// Moodle is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// Moodle is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU General Public License | ||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
/** | ||
* Moodle 404 Error page feedback form | ||
* | ||
* @package core | ||
* @copyright 2020 Brendan Heywood <[email protected]> | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
|
||
namespace core\form; | ||
defined('MOODLE_INTERNAL') || die(); | ||
|
||
use moodleform; | ||
|
||
require_once($CFG->libdir.'/formslib.php'); | ||
|
||
/** | ||
* Moodle 404 Error page feedback form | ||
* | ||
* @package core | ||
* @copyright 2020 Brendan Heywood <[email protected]> | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
class error_feedback extends moodleform { | ||
|
||
/** | ||
* Error form definition | ||
*/ | ||
public function definition() { | ||
global $CFG; | ||
|
||
$mform = $this->_form; | ||
$mform->addElement('hidden', 'referer', get_local_referer(false)); | ||
$mform->setType('referer', PARAM_URL); | ||
|
||
$mform->addElement('hidden', 'requested', (empty($_SERVER['REDIRECT_URL']) ? '' : $_SERVER['REDIRECT_URL'])); | ||
$mform->setType('requested', PARAM_URL); | ||
|
||
$mform->addElement('textarea', 'text', get_string('pleasereport', 'error'), 'wrap="virtual" rows="10" cols="50"'); | ||
$mform->addElement('submit', 'submitbutton', get_string('sendmessage', 'error')); | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.