$auth = required_param('auth', PARAM_SAFEDIR);
-$CFG->pagepath = 'auth/' . $auth;
+$PAGE->set_pagetype('auth-' . $auth);
admin_externalpage_setup('authsetting'.$auth);
}
admin_externalpage_setup('mnetenrol');
- $CFG->pagepath = 'admin/mnet';
+ $PAGE->set_pagetype('admin-mnet');
require_once("$CFG->dirroot/enrol/enrol.class.php"); /// Open the factory class
$enrolment = enrolment_factory::factory('mnet');
admin_externalpage_setup('mnetenrol');
- $CFG->pagepath = 'admin/mnet';
+ $PAGE->set_pagetype('admin-mnet');
require_once("$CFG->dirroot/enrol/enrol.class.php"); /// Open the factory class
$enrolment = enrolment_factory::factory('mnet');
require_once($CFG->libdir.'/adminlib.php');
admin_externalpage_setup('mnetenrol');
- $CFG->pagepath = 'admin/mnet';
-
+ $PAGE->set_pagetype('admin-mnet');
require_once("$CFG->dirroot/enrol/enrol.class.php"); /// Open the factory class
define('ADMIN_STICKYBLOCKS',$pt);
$PAGE = page_create_object($pt, SITEID);
- $blocks = blocks_setup($PAGE,BLOCKS_PINNED_TRUE);
+ $blocks = blocks_setup($PAGE, BLOCKS_PINNED_TRUE);
$blocks_preferred_width = bounded_number(180, blocks_preferred_width($blocks[BLOCK_POS_LEFT]), 210);
$navlinks = array(array('name' => get_string('administration'),
var $filterselect = NULL;
var $tagid = NULL;
- // we have no format type, use 'blog'
- //I think it's a bug, but if this is left the default NULL value then pages can
- //fail to load completely
- function get_format_name() {
- global $CFG;
- require_once($CFG->dirroot .'/blog/lib.php');
- return PAGE_BLOG_VIEW;
- }
-
// Do any validation of the officially recognized bits of the data and forward to parent.
// Do NOT load up "expensive" resouces (e.g. SQL data) here!
function init_quick($data) {
$strdeletecheck = get_string('deletecheck', '', $fullmodulename);
$strdeletecheckfull = get_string('deletecheckfull', '', "$fullmodulename '$cm->name'");
- $CFG->pagepath = 'mod/'.$cm->modname.'/delete';
+ $PAGE->set_pagetype('mod-' . $cm->modname . '-delete');
print_header_simple($strdeletecheck, '', build_navigation(array(array('name'=>$strdeletecheck, 'link'=>'', 'type'=>'misc'))));
$pageheading = get_string('addinganew', 'moodle', $fullmodulename);
}
- $CFG->pagepath = 'mod/'.$module->name;
+ $pagepath = 'mod-' . $module->name . '-';
if (!empty($type)) {
- $CFG->pagepath .= '/'.$type;
+ $pagepath .= $type;
} else {
- $CFG->pagepath .= '/mod';
+ $pagepath .= 'mod';
}
+ $PAGE->set_pagetype($pagepath);
$navlinksinstancename = '';
$missingblocks = array();
$allblocks = blocks_get_record();
- $pageformat = $page->get_format_name();
+ $pageformat = $page->pagetype;
if(!empty($allblocks)) {
foreach($allblocks as $block) {
return;
}
- if(($pageformat = $page->get_format_name()) == NULL) {
+ if(($pageformat = $page->pagetype) == NULL) {
return;
}
include_once($CFG->dirroot.'/my/pagelib.php');
$coursecontext = get_context_instance(CONTEXT_COURSE, $COURSE->id);
- $myownblogpage = (isset($page->filtertype) && isset($page->filterselect) && $page->type=='blog-view' && $page->filtertype=='user' && $page->filterselect == $USER->id);
+ $myownblogpage = (isset($page->filtertype) && isset($page->filterselect) && $page->pagetype=='blog-view' && $page->filtertype=='user' && $page->filterselect == $USER->id);
$managecourseblocks = has_capability('moodle/site:manageblocks', $coursecontext);
- $editmymoodle = $page->type == PAGE_MY_MOODLE && has_capability('moodle/my:manageblocks', $coursecontext);
+ $editmymoodle = $page->pagetype == PAGE_MY_MOODLE && has_capability('moodle/my:manageblocks', $coursecontext);
if ($page->blocks_default_position() == $position &&
$page->user_is_editing() &&
protected $_pagetype = null;
+ protected $_legacyclass = null;
+
/**
* @return integer one of the STATE_... constants. You should not normally need
* to use this in your code. It is indended for internal use by this class
* @return string e.g. 'my-index' or 'mod-quiz-attempt'. Same as the id attribute on <body>.
*/
public function get_pagetype() {
- if (is_null($this->_pagetype)) {
- throw new coding_exception('$PAGE->pagetype accessed before it was known.');
+ if (is_null($this->_pagetype) || isset($CFG->pagepath)) {
+ $this->initialise_default_pagetype();
}
return $this->_pagetype;
}
}
}
+ /**
+ * Sets ->pagetype from the script name. For example, if the script that was
+ * run is mod/quiz/view.php, ->pagetype will be set to 'mod-quiz-view'.
+ * @param string $script the path to the script that should be used to
+ * initialise ->pagetype. If not passed the $SCRIPT global will be used.
+ * If legacy code has set $CFG->pagepath that will be used instead, and a
+ * developer warning issued.
+ */
+ protected function initialise_default_pagetype($script = '') {
+ global $CFG, $SCRIPT;
+
+ if (isset($CFG->pagepath)) {
+ debugging('Some code appears to have set $CFG->pagepath. That was a horrible deprecated thing. ' .
+ 'Don\'t do it! Try calling $PAGE->set_pagetype() instead.');
+ $script = $CFG->pagepath;
+ unset($CFG->pagepath);
+ }
+
+ if (empty($script)) {
+ $script = ltrim($SCRIPT, '/');
+ $len = strlen($CFG->admin);
+ if (substr($script, 0, $len) == $CFG->admin) {
+ $script = 'admin' . substr($script, $len);
+ }
+ }
+
+ $path = str_replace('.php', '', $script);
+ if (substr($path, -1) == '/') {
+ $path .= 'index';
+ }
+
+ if (empty($path) || $path == 'index') {
+ $this->_pagetype = 'site-index';
+ } else {
+ $this->_pagetype = str_replace('/', '-', $path);
+ }
+ }
+
/// Deperecated fields and methods for backwards compatibility =================
+
/**
* @deprecated since Moodle 2.0 - use $PAGE->pagetype instead.
* @return string page type.
debugging('Call to deprecated method moodle_page::get_type. Please use $PAGE->pagetype instead.');
return $this->get_pagetype();
}
+
+ /**
+ * @deprecated since Moodle 2.0 - use $PAGE->pagetype instead.
+ * @return string this is what page_id_and_class used to return via the $getclass parameter.
+ */
+ function get_format_name() {
+ return $this->get_pagetype();
+ }
+
/**
* @deprecated since Moodle 2.0 - use $PAGE->course instead.
* @return object course.
debugging('Call to deprecated method moodle_page::get_courserecord. Please use $PAGE->course instead.');
return $this->get_course();
}
+
+ /**
+ * @deprecated since Moodle 2.0
+ * @return string this is what page_id_and_class used to return via the $getclass parameter.
+ */
+ public function get_legacyclass() {
+ if (is_null($this->_legacyclass)) {
+ $pagetype = $this->pagetype;
+ if ($pagetype == 'site-index') {
+ $this->_legacyclass = 'course';
+ } else if (substr($pagetype, 0, 6) == 'admin-') {
+ $this->_legacyclass = 'admin';
+ } else {
+ $this->_legacyclass = substr($pagetype, 0, strrpos($pagetype, '-'));
+ }
+ }
+ debugging('Call to deprecated method moodle_page::get_legacyclass.');
+ return $this->_legacyclass;
+ }
}
/**
*/
function page_import_types($path) {
global $CFG;
-
debugging('Call to deprecated function page_import_types.', DEBUG_DEVELOPER);
}
/**
- * Factory function page_create_object(). Called with a numeric ID for a page, it autodetects
- * the page type, constructs the correct object and returns it.
+ * @deprecated since Moodle 2.0
+ * @param integer $instance legacy page instance id.
+ * @return the global $PAGE object.
*/
function page_create_instance($instance) {
- page_id_and_class($id, $class);
- return page_create_object($id, $instance);
+ return page_create_object($PAGE->pagetype, $instance);
}
/**
*/
var $full_init_done = false;
- /**
- * The class attribute that Moodle has to assign to the BODY tag for this page.
- * @var string $body_class
- */
- var $body_class = NULL;
-
- /**
- * The id attribute that Moodle has to assign to the BODY tag for this page.
- * @var string $body_id
- */
- var $body_id = NULL;
-
/// Class Functions
- // CONSTRUCTION
-
- // A whole battery of functions to allow standardized-name constructors in all versions of PHP.
- // The constructor is actually called construct()
- function __construct() {
- $this->construct();
- }
-
- function construct() {
- page_id_and_class($this->body_id, $this->body_class);
- }
-
// USER-RELATED THINGS
// By default, no user is editing anything and none CAN edit anything. Developers
return $this->id;
}
- // "Sensible default" case here. Take it from the body id.
- function get_format_name() {
- return $this->body_id;
- }
-
// Initialize the data members of the parent class
function init_quick($data) {
$this->type = $data->pagetype;
// this is a _very_ expensive check - so cache it during execution
//
function user_allowed_editing() {
-
$this->init_full();
if (isset($this->_user_allowed_editing)) {
}
if (has_capability('moodle/site:manageblocks', get_context_instance(CONTEXT_SYSTEM))
- && defined('ADMIN_STICKYBLOCKS')) {
+ && defined('ADMIN_STICKYBLOCKS')) {
$this->_user_allowed_editing = true;
return true;
}
// SELF-REPORTING SECTION
- // This is like the "category" of a page of this "type". For example, if the type is PAGE_COURSE_VIEW
- // the format_name is the actual name of the course format. If the type were PAGE_ACTIVITY_VIEW, then
- // the format_name might be that activity's name etc.
- function get_format_name() {
- $this->init_full();
- if (defined('ADMIN_STICKYBLOCKS')) {
- return PAGE_COURSE_VIEW;
- }
- if($this->id == SITEID) {
- return parent::get_format_name();
- }
- // This needs to reflect the path hierarchy under Moodle root.
- return 'course-view-'.$this->course->format;
- }
-
// This should return a fully qualified path to the URL which is responsible for displaying us.
function url_get_path() {
global $CFG;
// Create class and id for this page
- page_id_and_class($pageid, $pageclass);
+ $pageid = $PAGE->pagetype;
+ $pageclass = $PAGE->legacyclass;
$pageclass .= ' course-'.$COURSE->id;
}
-
+/**
+ * @deprecated since Moodle 2.0 - use $PAGE->pagetype instead of the .
+ * @param string $getid used to return $PAGE->pagetype.
+ * @param string $getclass used to return $PAGE->legacyclass.
+ */
function page_id_and_class(&$getid, &$getclass) {
- // Create class and id for this page
- global $CFG, $SCRIPT;
-
- static $class = NULL;
- static $id = NULL;
-
- if (empty($CFG->pagepath)) {
- $CFG->pagepath = ltrim($SCRIPT, '/');
- }
-
- if (empty($class) || empty($id)) {
- $path = str_replace('.php', '', $CFG->pagepath);
- if (substr($path, -1) == '/') {
- $path .= 'index';
- }
- if (empty($path) || $path == 'index') {
- $id = 'site-index';
- $class = 'course';
- } else if (substr($path, 0, 5) == 'admin') {
- $id = str_replace('/', '-', $path);
- $class = 'admin';
- } else {
- $id = str_replace('/', '-', $path);
- $class = explode('-', $id);
- array_pop($class);
- $class = implode('-', $class);
- }
- }
-
- $getid = $id;
- $getclass = $class;
+ global $PAGE;
+ debugging('Call to deprecated function page_id_and_class. Please use $PAGE->pagetype instead.', DEBUG_DEVELOPER);
+ $getid = $PAGE->pagetype;
+ $getclass = $PAGE->legacyclass;
}
/**
$loginguest = optional_param('loginguest', 0, PARAM_BOOL); // determines whether visitors are logged in as guest automatically
$testcookies = optional_param('testcookies', 0, PARAM_BOOL); // request cookie test
+ $context = get_context_instance(CONTEXT_SYSTEM);
+ $PAGE->set_context($context);
+
//initialize variables
$errormsg = '';
$errorcode = 0;
}
/// Go to my-moodle page instead of homepage if mymoodleredirect enabled
- if (!has_capability('moodle/site:config',get_context_instance(CONTEXT_SYSTEM)) and !empty($CFG->mymoodleredirect) and !isguest()) {
+ if (!has_capability('moodle/site:config', $context) and !empty($CFG->mymoodleredirect) and !isguest()) {
if ($urltogo == $CFG->wwwroot or $urltogo == $CFG->wwwroot.'/' or $urltogo == $CFG->wwwroot.'/index.php') {
$urltogo = $CFG->wwwroot.'/my/';
}
}
asort($menufield); //sort in alphabetical order
-
+ $PAGE->set_pagetype('mod-data-field-' . $newtype);
if (($mode == 'new') && (!empty($newtype)) && confirm_sesskey()) { /// Adding a new field
- $CFG->pagepath='mod/data/field/'.$newtype;
- data_print_header($course,$cm,$data,'fields');
+ data_print_header($course, $cm, $data,'fields');
$field = data_get_field_new($newtype, $data);
$field->display_edit_field();
} else if ($mode == 'display' && confirm_sesskey()) { /// Display/edit existing field
- $CFG->pagepath='mod/data/field/'.$newtype;
- data_print_header($course,$cm,$data,'fields');
+ data_print_header($course, $cm, $data,'fields');
$field = data_get_field_from_id($fid, $data);
$field->display_edit_field();
} else { /// Display the main listing of all fields
-
- $CFG->pagepath='mod/data/field/'.$newtype;
- data_print_header($course,$cm,$data,'fields');
-
+ data_print_header($course, $cm, $data,'fields');
if (!$DB->record_exists('data_fields', array('dataid'=>$data->id))) {
notify(get_string('nofieldindatabase','data')); // nothing in database
// insert hot-potatoes.js
$hp->insert_script(HOTPOT_JS);
// get Moodle pageid and pageclass
- $pageid = '';
- $pageclass = '';
- if (function_exists('page_id_and_class')) {
- page_id_and_class($pageid, $pageclass);
- }
+ $pageid = $PAGE->pagetype;
+
// extract first <head> tag
$head = '';
$pattern = '|<head([^>]*)>(.*?)</head>|is';
* @package lesson
**/
- $CFG->pagepath = 'mod/lesson/addbranchtable';
-
// first get the preceeding page
$pageid = required_param('pageid', PARAM_INT);
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
* @package lesson
**/
- $CFG->pagepath = 'mod/lesson/addpage';
-
// first get the preceeding page
$pageid = required_param('pageid', PARAM_INT);
$qtype = optional_param('qtype', LESSON_MULTICHOICE, PARAM_INT);
class page_my_moodle extends page_base {
function user_allowed_editing() {
- page_id_and_class($id,$class);
- if ($id == PAGE_MY_MOODLE) {
+ if ($PAGE->pagetype == PAGE_MY_MOODLE) {
return true;
} else if (has_capability('moodle/my:manageblocks', get_context_instance(CONTEXT_SYSTEM)) && defined('ADMIN_STICKYBLOCKS')) {
return true;
function url_get_path() {
global $CFG;
- page_id_and_class($id,$class);
- if ($id == PAGE_MY_MOODLE) {
+ if ($PAGE->pagetype == PAGE_MY_MOODLE) {
return $CFG->wwwroot.'/my/index.php';
} elseif (defined('ADMIN_STICKYBLOCKS')){
return $CFG->wwwroot.'/'.$CFG->admin.'/stickyblocks.php';
}
return $instance->position;
}
-
- function get_format_name() {
- return MY_MOODLE_FORMAT;
- }
}
if (!isset($QTYPES[$question->qtype])) {
print_error('unknownquestiontype', 'question', $returnurl, $question->qtype);
}
-$CFG->pagepath = 'question/type/' . $question->qtype;
+$PAGE->set_pagetype('question-type-' . $question->qtype);
// Create the question editing form.
if ($wizardnow!=='' && !$movecontext){
return $instance->position;
}
- function get_format_name() {
- return TAG_FORMAT;
- }
-
//----------- printing funtions -----------
-
+
function print_header() {
global $USER, $CFG;