From 7c6c05132609f73113a95c67d95b494ebfffd329 Mon Sep 17 00:00:00 2001 From: defacer Date: Wed, 2 Feb 2005 02:32:40 +0000 Subject: [PATCH] Utilizing page_id_and_class(), make a factory function page_create_instance() that does not need the page type as an argument (autodetects from the URL). --- lib/pagelib.php | 48 +++++++++++++++++++++--------------------------- 1 file changed, 21 insertions(+), 27 deletions(-) diff --git a/lib/pagelib.php b/lib/pagelib.php index eee0dd9c46..c82df81754 100644 --- a/lib/pagelib.php +++ b/lib/pagelib.php @@ -19,6 +19,16 @@ if(record_exists('block_instance', 'pagetype', 'course')) { } // End of dirty compatibility hack -- remove this before 1.5 goes gold +/** + * 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. + */ + +function page_create_instance($instance) { + page_id_and_class($id, $class); + return page_create_object($id, $instance); +} + /** * Factory function page_create_object(). Called with a pagetype identifier and possibly with * its numeric ID. Returns a fully constructed page_base subclass you can work with. @@ -137,23 +147,7 @@ class page_base { } function construct() { - global $CFG, $ME; - - $path = substr($ME, strlen($CFG->wwwroot) + 1); - $path = str_replace('.php', '', $path); - if (substr($path, -1) == '/') { - $path .= 'index'; - } - - if (empty($path)) { - $this->body_id = 'index'; - $this->body_class = 'course-view'; - } else { - $this->body_id = str_replace('/', '-', $path); - $classarray = explode('-', $this->body_id); - array_pop($classarray); - $this->body_class = implode('-', $classarray); - } + page_id_and_class($this->body_id, $this->body_class); } // USER-RELATED THINGS @@ -178,16 +172,6 @@ class page_base { return; } - // Returns $this->body_class - function body_class() { - return $this->body_class; - } - - // Returns $this->body_id - function body_id() { - return $this->body_id; - } - // BLOCKS RELATED SECTION // By default, pages don't have any blocks. Override this in your derived class if you need blocks. @@ -270,6 +254,16 @@ class page_base { return NULL; } + // Returns $this->body_class + function get_body_class() { + return $this->body_class; + } + + // Returns $this->body_id + function get_body_id() { + return $this->body_id; + } + // Initialize the data members of the parent class function init_quick($data) { $this->type = $data->pagetype; -- 2.39.5