From eaba9c851014c9bc091fb5a5f1ba2145435626e1 Mon Sep 17 00:00:00 2001 From: defacer Date: Wed, 26 Jan 2005 15:33:50 +0000 Subject: [PATCH] Adding that nifty BODY id and class detection code to pages... I have the feeling that this is the way to go, as more Moodle things will be converted to use $PAGE in the future. --- lib/pagelib.php | 54 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/lib/pagelib.php b/lib/pagelib.php index ea9ee14779..098372ffba 100644 --- a/lib/pagelib.php +++ b/lib/pagelib.php @@ -102,8 +102,52 @@ class page_base { */ 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 page_base() { + $this->construct(); + } + + function __construct() { + $this->construct(); + } + + 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); + } + } + // USER-RELATED THINGS // By default, no user is editing anything and none CAN edit anything. Developers @@ -126,6 +170,16 @@ 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. -- 2.39.5