]> git.mjollnir.org Git - moodle.git/commitdiff
Adding that nifty BODY id and class detection code to pages... I have the
authordefacer <defacer>
Wed, 26 Jan 2005 15:33:50 +0000 (15:33 +0000)
committerdefacer <defacer>
Wed, 26 Jan 2005 15:33:50 +0000 (15:33 +0000)
feeling that this is the way to go, as more Moodle things will be converted
to use $PAGE in the future.

lib/pagelib.php

index ea9ee147791af126014177fef4575b7e4d385c9e..098372ffba941cf47153eecb92e3f3619e889570 100644 (file)
@@ -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.