Commit 2ab797c9 authored by Brendan Heywood's avatar Brendan Heywood
Browse files

MDL-28030 weblib: Added $CFG->urlrewriteclass in config.php

    This enables a plugin to implement rewriting rules enabling
    'clean' or 'semantic' urls such as /course/COMP100/ instead
    of /course/view.php?id=1234
parent 2f45a11a
......@@ -298,6 +298,11 @@ $CFG->admin = 'admin';
// This setting will make some graphs (eg user logs) use lines instead of bars
// $CFG->preferlinegraphs = true;
//
// This setting allows you to specify a class to rewrite outgoing urls
// enabling 'clean urls' in conjunction with an apache / nginx handler.
// The handler must implement \core\output\url_rewriter.
// $CFG->urlrewriteclass = '\local_cleanurls\url_rewriter';
//
// Enabling this will allow custom scripts to replace existing moodle scripts.
// For example: if $CFG->customscripts/course/view.php exists then
// it will be used instead of $CFG->wwwroot/course/view.php
......
<?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/>.
/**
* URL rewriter base.
*
* @package core
* @author Brendan Heywood <brendan@catalyst-au.net>
* @copyright Catalyst IT
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace core\output;
defined('MOODLE_INTERNAL') || die();
/**
* URL rewriter interface
*
* @package core
* @author Brendan Heywood <brendan@catalyst-au.net>
* @copyright Catalyst IT
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
interface url_rewriter {
/**
* Rewrite moodle_urls into another form.
*
* @param moodle_url $url a url to potentially rewrite
* @return moodle_url Returns a new, or the original, moodle_url;
*/
public static function url_rewrite(\moodle_url $url);
/**
* Gives a url rewriting plugin a chance to rewrite the current page url
* avoiding redirects and improving performance.
*
* @return void
*/
public static function html_head_setup();
}
......@@ -475,6 +475,13 @@ class core_renderer extends renderer_base {
}
$output = '';
// Allow a url_rewrite plugin to setup any dynamic head content.
if (isset($CFG->urlrewriteclass) && !isset($CFG->upgraderunning)) {
$class = $CFG->urlrewriteclass;
$output .= $class::html_head_setup();
}
$output .= '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />' . "\n";
$output .= '<meta name="keywords" content="moodle, ' . $this->page->title . '" />' . "\n";
// This is only set by the {@link redirect()} method
......
......@@ -39,6 +39,8 @@ information provided here is intended especially for developers.
Note than you will need to bump the plugin version so moodle is aware that you removed the plugin's event handlers.
* mforms validation functions are not available in the global JS namespace anymore, event listeners
are assigned to fields and buttons through a self-contained JS function.
* Added $CFG->urlrewriteclass option to config.php allowing clean / semantic urls to
be implemented in a plugin, eg local_cleanurls.
=== 3.0 ===
......
......@@ -553,6 +553,38 @@ class moodle_url {
* @return string Resulting URL
*/
public function out($escaped = true, array $overrideparams = null) {
global $CFG;
if (!is_bool($escaped)) {
debugging('Escape parameter must be of type boolean, '.gettype($escaped).' given instead.');
}
$url = $this;
// Allow url's to be rewritten by a plugin.
if (isset($CFG->urlrewriteclass) && !isset($CFG->upgraderunning)) {
$class = $CFG->urlrewriteclass;
$pluginurl = $class::url_rewrite($url);
if ($pluginurl instanceof moodle_url) {
$url = $pluginurl;
}
}
return $url->raw_out($escaped, $overrideparams);
}
/**
* Output url without any rewrites
*
* This is identical in signature and use to out() but doesn't call the rewrite handler.
*
* @param bool $escaped Use &amp; as params separator instead of plain &
* @param array $overrideparams params to add to the output url, these override existing ones with the same name.
* @return string Resulting URL
*/
public function raw_out($escaped = true, array $overrideparams = null) {
if (!is_bool($escaped)) {
debugging('Escape parameter must be of type boolean, '.gettype($escaped).' given instead.');
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment