Class and ID elements for body return wrong strings

Class and ID elements for body return wrong strings

by Mark Pearson -
Number of replies: 1
I've spent all afternoon trying to suss this one out with no success ... Plus no clues from a trawl of the discussion fora.

Problem:
All pages on my new Moodle site have a similar body element to this:
<body  class="http:--ec281.lly.earlham.edu:16080-nitle_moodle- course-1" 
id
="http:--ec281.lly.earlham.edu:16080-nitle_moodle--index">
It doesn't seem to do any damage apart from screwing up Urs Hunkler's very impressive Accordion system.
The body element *should* look like:
<body class="course course-1" id="site-index">
I traced the problem back to function print_header in weblib.php. The class and id attributes for the body element are generated by the function page_id_and_class on line 1872,
page_id_and_class($pageid, $pageclass);
This function is located at line 4378 in weblib.php.
What this function should return in normal circumstances is $id='site-index' and $class='course'. But instead the whole URL is returned. I'm sure it has something to do with the global $ME variable but I cannot find a reference to where this is set. Relevant lines from the Moodle config.php:

$CFG->wwwroot   = 'http://ec281.lly.earlham.edu/nitle_moodle';
$CFG->dirroot   = '/Library/WebServer/Documents/nitle_moodle';
$CFG->dataroot  = '/Library/WebServer/nitlemoodle_data'; 
Here's what the page_id_and_class function is doing:

function page_id_and_class(&$getid, &$getclass) {
// Create class and id for this page
global $CFG, $ME;
static $class = NULL;
static $id = NULL;

if(empty($class) || empty($id)) {

SOmething weird happens here
$path = str_replace($CFG->httpswwwroot.'/', '', $ME); //Because the page could be HTTPSPAGEREQUIRED

$path = str_replace('.php', '', $path);
if (substr($path, -1) == '/') {
$path .= 'index';
}
if (empty($path) || $path == 'index') {

This should be what gets set
:
$id = 'site-index';
$class = 'course';

} else if (substr($path, 0, 5) == 'admin') {
$id = str_replace('/', '-', $path);
$id = str_replace('admin2', 'admin', $id);
$class = 'admin';
} else {

But this happens instead and I don't know why:
$id = str_replace('/', '-', $path);
$class = explode('-', $id);
array_pop($class);
$class = implode('-', $class);

}
}
$getid = $id;
$getclass = $class;
}

Any assistance would be gratefully received.

Mark Pearson


                        
Average of ratings: -
In reply to Mark Pearson

Re: Class and ID elements for body return wrong strings

by John Papaioannou -
I remember this having been discussed somewhere, most probably on some old bug. No wonder you couldn't find the information as the current bug tracker isn't the most helpful tool out there. mixed

In short, the problem lies with the :16080 part of your web URL. Set your $CFG->wwwroot to "http://ec281.lly.earlham.edu:16080/nitle_moodle" and it should be fixed. Sorry for not providing more info, but I 'm terribly short on time. Cheers!

Jon