From 364fffda3b1be6c54ac318e09d3ca126edff2f95 Mon Sep 17 00:00:00 2001 From: nicolasconnault Date: Fri, 24 Aug 2007 04:22:30 +0000 Subject: [PATCH] MDL-10723 Removed all uses of print_navigation() throughout moodle, the function call is now entirely deprecated. --- index.php | 15 ++-- lib/deprecatedlib.php | 171 +++++++++++++++++++++++++++++---------- lib/moodlelib.php | 74 ----------------- lib/weblib.php | 130 ++++++++++++++--------------- theme/chameleon/header.html | 14 ++-- theme/cornflower/footer.html | 2 +- theme/cornflower/header.html | 6 +- theme/custom_corners/header.html | 4 +- theme/formal_white/footer.html | 2 +- theme/formal_white/header.html | 8 +- theme/metal/header.html | 10 +-- theme/oceanblue/footer.html | 2 +- theme/oceanblue/header.html | 10 +-- theme/orangewhite/header.html | 8 +- theme/orangewhitepda/header.html | 8 +- theme/standard/footer.html | 2 +- theme/standard/header.html | 10 +-- theme/standardblue/header.html | 10 +-- theme/standardgreen/header.html | 10 +-- theme/standardlogo/header.html | 12 +-- theme/standardred/header.html | 10 +-- theme/standardwhite/header.html | 10 +-- theme/wood/header.html | 10 +-- 23 files changed, 272 insertions(+), 266 deletions(-) diff --git a/index.php b/index.php index bd2706abf..a9aaa38ca 100644 --- a/index.php +++ b/index.php @@ -33,11 +33,11 @@ require_once('config.php'); require_once($CFG->dirroot .'/course/lib.php'); require_once($CFG->dirroot .'/lib/blocklib.php'); - + if (!empty($THEME->customcorners)) { require_once($CFG->dirroot.'/lib/custom_corners_lib.php'); } - + if (empty($SITE)) { redirect($CFG->wwwroot .'/'. $CFG->admin .'/index.php'); } @@ -81,7 +81,7 @@ } - if (get_moodle_cookie() == '') { + if (get_moodle_cookie() == '') { set_moodle_cookie('nobody'); // To help search for cookies on login page } @@ -101,12 +101,13 @@ $PAGE = page_create_object(PAGE_COURSE_VIEW, SITEID); $pageblocks = blocks_setup($PAGE); $editing = $PAGE->user_is_editing(); - $preferred_width_left = bounded_number(BLOCK_L_MIN_WIDTH, blocks_preferred_width($pageblocks[BLOCK_POS_LEFT]), + $preferred_width_left = bounded_number(BLOCK_L_MIN_WIDTH, blocks_preferred_width($pageblocks[BLOCK_POS_LEFT]), BLOCK_L_MAX_WIDTH); - $preferred_width_right = bounded_number(BLOCK_R_MIN_WIDTH, blocks_preferred_width($pageblocks[BLOCK_POS_RIGHT]), + $preferred_width_right = bounded_number(BLOCK_R_MIN_WIDTH, blocks_preferred_width($pageblocks[BLOCK_POS_RIGHT]), BLOCK_R_MAX_WIDTH); - print_header($SITE->fullname, $SITE->fullname, 'home', '', + $navigation = build_navigation(array(array('name' => get_string('home'), 'link'=> null, 'type' => 'misc'))); + print_header($SITE->fullname, $SITE->fullname, $navigation, '', '', true, '', user_login_string($SITE).$langmenu); @@ -170,7 +171,7 @@ get_all_mods($SITE->id, $mods, $modnames, $modnamesplural, $modnamesused); print_section($SITE, $section, $mods, $modnamesused, true); - + if ($editing) { print_section_add_menus($SITE, $section->section, $modnames); } diff --git a/lib/deprecatedlib.php b/lib/deprecatedlib.php index 6fdf860be..1141ddaa2 100644 --- a/lib/deprecatedlib.php +++ b/lib/deprecatedlib.php @@ -119,8 +119,8 @@ function isadmin($userid=0) { return record_exists('user_admins', 'userid', $userid); } - $context = get_context_instance(CONTEXT_SYSTEM, SITEID); - + $context = get_context_instance(CONTEXT_SYSTEM, SITEID); + return has_capability('moodle/legacy:admin', $context, $userid, false); } @@ -145,7 +145,7 @@ function isteacher($courseid=0, $userid=0, $obsolete_includeadmin=true) { if ($courseid) { $context = get_context_instance(CONTEXT_COURSE, $courseid); } else { - $context = get_context_instance(CONTEXT_SYSTEM, SITEID); + $context = get_context_instance(CONTEXT_SYSTEM, SITEID); } return (has_capability('moodle/legacy:teacher', $context, $userid, false) @@ -199,7 +199,7 @@ function isteacherinanycourse($userid=0, $includeadmin=true) { /// Include admins if required if ($includeadmin) { - $context = get_context_instance(CONTEXT_SYSTEM, SITEID); + $context = get_context_instance(CONTEXT_SYSTEM, SITEID); if (has_capability('moodle/legacy:admin', $context, $userid, false)) { return true; } @@ -223,7 +223,7 @@ function isteacheredit($courseid, $userid=0, $obsolete_ignorestudentview=false) } if (empty($courseid)) { - $context = get_context_instance(CONTEXT_SYSTEM, SITEID); + $context = get_context_instance(CONTEXT_SYSTEM, SITEID); } else { $context = get_context_instance(CONTEXT_COURSE, $courseid); } @@ -245,7 +245,7 @@ function iscreator ($userid=0) { return false; } - $context = get_context_instance(CONTEXT_SYSTEM, SITEID); + $context = get_context_instance(CONTEXT_SYSTEM, SITEID); return (has_capability('moodle/legacy:coursecreator', $context, $userid, false) or has_capability('moodle/legacy:admin', $context, $userid, false)); @@ -271,7 +271,7 @@ function isstudent($courseid=0, $userid=0) { } if ($courseid == 0) { - $context = get_context_instance(CONTEXT_SYSTEM, SITEID); + $context = get_context_instance(CONTEXT_SYSTEM, SITEID); } else { $context = get_context_instance(CONTEXT_COURSE, $courseid); } @@ -292,7 +292,7 @@ function isguest($userid=0) { return false; } - $context = get_context_instance(CONTEXT_SYSTEM); + $context = get_context_instance(CONTEXT_SYSTEM); return has_capability('moodle/legacy:guest', $context, $userid, false); } @@ -341,7 +341,7 @@ function enrol_student($userid, $courseid, $timestart=0, $timeend=0, $enrol='man */ function unenrol_student($userid, $courseid=0) { global $CFG; - + $status = true; if ($courseid) { @@ -376,7 +376,7 @@ function unenrol_student($userid, $courseid=0) { } /** - * Add a teacher to a given course + * Add a teacher to a given course * * @param int $userid The id of the user that is being tested against. Set this to 0 if you would just like to test against the currently logged in user. * @param int $courseid The id of the course that is being viewed, if any @@ -536,7 +536,7 @@ function get_teacher($courseid) { function get_recent_enrolments($courseid, $timestart) { global $CFG; - + $context = get_context_instance(CONTEXT_COURSE, $courseid); return get_records_sql("SELECT DISTINCT u.id, u.firstname, u.lastname, l.time @@ -581,9 +581,9 @@ function get_course_students($courseid, $sort='ul.timeaccess', $dir='', $page='' // make sure it works on the site course $context = get_context_instance(CONTEXT_COURSE, $courseid); - /// For the site course, old way was to check if $CFG->allusersaresitestudents was set to true. + /// For the site course, old way was to check if $CFG->allusersaresitestudents was set to true. /// The closest comparible method using roles is if the $CFG->defaultuserroleid is set to the legacy - /// student role. This function should be replaced where it is used with something more meaningful. + /// student role. This function should be replaced where it is used with something more meaningful. if (($courseid == SITEID) && !empty($CFG->defaultuserroleid) && empty($CFG->nodefaultuserrolelists)) { if ($roles = get_roles_with_capability('moodle/legacy:student', CAP_ALLOW, $context)) { $hascap = false; @@ -604,15 +604,15 @@ function get_course_students($courseid, $sort='ul.timeaccess', $dir='', $page='' $sort = $sort .' '. $dir; } // Now we have to make sure site teachers are excluded - + if ($teachers = get_course_teachers(SITEID)) { foreach ($teachers as $teacher) { $exceptions .= ','. $teacher->userid; } - $exceptions = ltrim($exceptions, ','); - - } - + $exceptions = ltrim($exceptions, ','); + + } + return get_users(true, $search, true, $exceptions, $sort, $firstinitial, $lastinitial, $page, $recordsperpage, $fields ? $fields : '*'); } @@ -629,7 +629,7 @@ function get_course_students($courseid, $sort='ul.timeaccess', $dir='', $page='' // If not site, require specific course $select.= "c.instanceid=$courseid AND "; } - $select.="rc.capability='moodle/legacy:student' AND rc.permission=".CAP_ALLOW." AND "; + $select.="rc.capability='moodle/legacy:student' AND rc.permission=".CAP_ALLOW." AND "; $select .= ' u.deleted = \'0\' '; @@ -675,7 +675,7 @@ function get_course_students($courseid, $sort='ul.timeaccess', $dir='', $page='' {$CFG->prefix}context c ON c.id=ra.contextid LEFT OUTER JOIN {$CFG->prefix}user_lastaccess ul on ul.userid=ra.userid $groupmembers - WHERE $select $search $sort $dir", $page, $recordsperpage); + WHERE $select $search $sort $dir", $page, $recordsperpage); return $students; } @@ -685,10 +685,10 @@ function get_course_students($courseid, $sort='ul.timeaccess', $dir='', $page='' * * @param object $course The course in question as a course object. * @param string $search ? - * @param string $firstinitial ? + * @param string $firstinitial ? * @param string $lastinitial ? * @param ? $group ? - * @param string $exceptions ? + * @param string $exceptions ? * @return int * @todo Finish documenting this function */ @@ -709,21 +709,21 @@ function count_course_students($course, $search='', $firstinitial='', $lastiniti * @uses $CFG * @param int $courseid The course in question. * @param string $sort ? - * @param string $exceptions ? + * @param string $exceptions ? * @return object * @todo Finish documenting this function */ function get_course_teachers($courseid, $sort='t.authority ASC', $exceptions='') { global $CFG; - + $sort = 'ul.timeaccess DESC'; - + $context = get_context_instance(CONTEXT_COURSE, $courseid); /// For the site course, if the $CFG->defaultuserroleid is set to the legacy teacher role, then all - /// users are teachers. This function should be replaced where it is used with something more - /// meaningful. + /// users are teachers. This function should be replaced where it is used with something more + /// meaningful. if (($courseid == SITEID) && !empty($CFG->defaultuserroleid) && empty($CFG->nodefaultuserrolelists)) { if ($roles = get_roles_with_capability('moodle/legacy:teacher', CAP_ALLOW, $context)) { $hascap = false; @@ -771,7 +771,7 @@ function get_course_users($courseid, $sort='ul.timeaccess DESC', $exceptions='', $context = get_context_instance(CONTEXT_COURSE, $courseid); /// If the course id is the SITEID, we need to return all the users if the "defaultuserroleid" - /// has the capbility of accessing the site course. $CFG->nodefaultuserrolelists set to true can + /// has the capbility of accessing the site course. $CFG->nodefaultuserrolelists set to true can /// over-rule using this. if (($courseid == SITEID) && !empty($CFG->defaultuserroleid) && empty($CFG->nodefaultuserrolelists)) { if ($roles = get_roles_with_capability('moodle/course:view', CAP_ALLOW, $context)) { @@ -803,7 +803,7 @@ function get_course_users($courseid, $sort='ul.timeaccess DESC', $exceptions='', * @return object (changed to groupids) */ function get_group_students($groupids, $sort='ul.timeaccess DESC') { - + if (is_array($groupids)){ $groups = $groupids; // all groups must be from one course anyway... @@ -850,7 +850,7 @@ function get_group_teachers($courseid, $groupid) { /** * Print a message in a standard themed box. - * This old function used to implement boxes using tables. Now it uses a DIV, but the old + * This old function used to implement boxes using tables. Now it uses a DIV, but the old * parameters remain. If possible, $align, $width and $color should not be defined at all. * Preferably just use print_box() in weblib.php * @@ -878,7 +878,7 @@ function print_simple_box($message, $align='', $width='', $color='', $padding=5, /** - * This old function used to implement boxes using tables. Now it uses a DIV, but the old + * This old function used to implement boxes using tables. Now it uses a DIV, but the old * parameters remain. If possible, $align, $width and $color should not be defined at all. * Even better, please use print_box_start() in weblib.php * @@ -1078,7 +1078,7 @@ function groups_members_from_sql() { * @param group ID, optional to include a test for this in the SQL. * @return SQL string. */ -function groups_members_join_sql($groupid=false) { +function groups_members_join_sql($groupid=false) { $sql = ' JOIN '.groups_members_from_sql().' ON u.id = gm.userid '; if ($groupid) { $sql = "AND gm.groupid = '$groupid' "; @@ -1090,7 +1090,7 @@ function groups_members_join_sql($groupid=false) { /** * Returns SQL for a WHERE clause testing the group ID. - * Optionally test the member's ID against another table's user ID column. + * Optionally test the member's ID against another table's user ID column. * @param groupid * @param userid_sql Optional user ID column selector, example "mdl_user.id", or false. * @return SQL string. @@ -1162,7 +1162,7 @@ function mygroupid($courseid) { } /** - * Add a user to a group, return true upon success or if user already a group + * Add a user to a group, return true upon success or if user already a group * member * * @param int $groupid The group id to add user to @@ -1187,7 +1187,7 @@ function add_user_to_group($groupid, $userid) { * @return object * @todo Finish documenting this function */ -function get_group_users($groupid, $sort='u.lastaccess DESC', $exceptions='', +function get_group_users($groupid, $sort='u.lastaccess DESC', $exceptions='', $fields='u.*') { global $CFG; if (!empty($exceptions)) { @@ -1212,7 +1212,7 @@ function get_group_users($groupid, $sort='u.lastaccess DESC', $exceptions='', /** * Returns the current group mode for a given course or activity module - * + * * Could be false, SEPARATEGROUPS or VISIBLEGROUPS (<-- Martin) */ function groupmode($course, $cm=null) { @@ -1226,11 +1226,11 @@ function groupmode($course, $cm=null) { /** * Sets the current group in the session variable - * When $SESSION->currentgroup[$courseid] is set to 0 it means, show all groups. + * When $SESSION->currentgroup[$courseid] is set to 0 it means, show all groups. * Sets currentgroup[$courseid] in the session variable appropriately. - * Does not do any permission checking. + * Does not do any permission checking. * @uses $SESSION - * @param int $courseid The course being examined - relates to id field in + * @param int $courseid The course being examined - relates to id field in * 'course' table. * @param int $groupid The group being examined. * @return int Current group id which was set by this function @@ -1242,13 +1242,13 @@ function set_current_group($courseid, $groupid) { /** - * Gets the current group - either from the session variable or from the database. + * Gets the current group - either from the session variable or from the database. * * @uses $USER * @uses $SESSION - * @param int $courseid The course being examined - relates to id field in + * @param int $courseid The course being examined - relates to id field in * 'course' table. - * @param bool $full If true, the return value is a full record object. + * @param bool $full If true, the return value is a full record object. * If false, just the id of the record. */ function get_current_group($courseid, $full = false) { @@ -1297,7 +1297,7 @@ function get_current_group($courseid, $full = false) { */ function get_and_set_current_group($course, $groupmode, $groupid=-1) { - // Sets to the specified group, provided the current user has view permission + // Sets to the specified group, provided the current user has view permission if (!$groupmode) { // Groups don't even apply return false; } @@ -1457,4 +1457,89 @@ function print_group_menu($groups, $groupmode, $currentgroup, $urlroot, $showall } +/** + * Prints breadcrumb trail of links, called in theme/-/header.html + * + * @uses $CFG + * @param mixed $navigation The breadcrumb navigation string to be printed + * @param string $separator The breadcrumb trail separator. The default 0 leads to the use + * of $THEME->rarrow, themes could use '→', '/', or '' for a style-sheet solution. + * @param boolean $return False to echo the breadcrumb string (default), true to return it. + */ +function print_navigation ($navigation, $separator=0, $return=false) { + global $CFG, $THEME; + $output = ''; + + if (0 === $separator) { + $separator = get_separator(); + } + else { + $separator = ''. $separator .''; + } + + if ($navigation) { + + if (is_newnav($navigation)) { + if ($return) { + return($navigation['navlinks']); + } else { + echo $navigation['navlinks']; + return; + } + } else { + debugging('Navigation needs to be updated to use build_navigation()', DEBUG_DEVELOPER); + } + + if (!is_array($navigation)) { + $ar = explode('->', $navigation); + $navigation = array(); + + foreach ($ar as $a) { + if (strpos($a, '') === false) { + $navigation[] = array('title' => $a, 'url' => ''); + } else { + if (preg_match('/(.*)<\/a>/', $a, $matches)) { + $navigation[] = array('title' => $matches[2], 'url' => $matches[1]); + } + } + } + } + + if (! $site = get_site()) { + $site = new object(); + $site->shortname = get_string('home'); + } + + //Accessibility: breadcrumb links now in a list, » replaced with a 'silent' character. + $nav_text = get_string('youarehere','access'); + $output .= '

'.$nav_text."

\n"; + } + + if ($return) { + return $output; + } else { + echo $output; + } +} + ?> diff --git a/lib/moodlelib.php b/lib/moodlelib.php index d3419cdea..443e375a3 100644 --- a/lib/moodlelib.php +++ b/lib/moodlelib.php @@ -7116,80 +7116,6 @@ function setup_lang_from_browser() { //////////////////////////////////////////////////////////////////////////////// -/** - * This function will build the navigation string to be used by print_header - * and others - * @uses $CFG - * @uses $THEME - * @param $extranavlinks - array of associative arrays, keys: name, link, type - * @return $navigation as an object so it can be differentiated from old style - * navigation strings. - */ -function build_navigation($extranavlinks) { - global $CFG, $COURSE; - - $navigation = ''; - $navlinks = array(); - - //Site name - if ($site = get_site()) { - $navlinks[] = array('name' => format_string($site->shortname), - 'link' => "$CFG->wwwroot/", - 'type' => 'home'); - } - - - if ($COURSE) { - if ($COURSE->id != SITEID) { - //Course - $navlinks[] = array('name' => format_string($COURSE->shortname), - 'link' => "$CFG->wwwroot/course/view.php?id=$COURSE->id", - 'type' => 'course'); - } - } - - //Merge in extra navigation links - $navlinks = array_merge($navlinks, $extranavlinks); - - //Construct an unordered list from $navlinks - //Accessibility: heading hidden from visual browsers by default. - $navigation = '

'.get_string('youarehere','access')."

"; - - return(array('newnav' => true, 'navlinks' => $navigation)); -} function is_newnav($navigation) { if (is_array($navigation) && $navigation['newnav']) { diff --git a/lib/weblib.php b/lib/weblib.php index 952d0f5cf..ea16bba34 100644 --- a/lib/weblib.php +++ b/lib/weblib.php @@ -2267,6 +2267,11 @@ function print_header ($title='', $heading='', $navigation='', $focus='', global $USER, $CFG, $THEME, $SESSION, $ME, $SITE, $COURSE; + if (gettype($navigation) == 'string' && strlen($navigation) != 0) { + debugging("print_header() was sent a string as 3rd ($navigation) parameter. " + . "This is deprecated in favour of an array built by build_navigation(). Please upgrade your code."); + } + $heading = format_string($heading); // Fix for MDL-8582 /// This makes sure that the header is never repeated twice on a page @@ -3231,93 +3236,82 @@ function get_separator() { return ' '.link_arrow_right($text='/', $url='', $accesshide=true, 'sep').' '; } - - /** - * Prints breadcrumb trail of links, called in theme/-/header.html - * + * This function will build the navigation string to be used by print_header + * and others * @uses $CFG - * @param mixed $navigation The breadcrumb navigation string to be printed - * @param string $separator The breadcrumb trail separator. The default 0 leads to the use - * of $THEME->rarrow, themes could use '→', '/', or '' for a style-sheet solution. - * @param boolean $return False to echo the breadcrumb string (default), true to return it. + * @uses $THEME + * @param $extranavlinks - array of associative arrays, keys: name, link, type + * @return $navigation as an object so it can be differentiated from old style + * navigation strings. */ -function print_navigation ($navigation, $separator=0, $return=false) { - global $CFG, $THEME; - $output = ''; +function build_navigation($extranavlinks) { + global $CFG, $COURSE; - if (0 === $separator) { - $separator = get_separator(); - } - else { - $separator = ''. $separator .''; + $navigation = ''; + $navlinks = array(); + + //Site name + if ($site = get_site()) { + $navlinks[] = array('name' => format_string($site->shortname), + 'link' => "$CFG->wwwroot/", + 'type' => 'home'); } - if ($navigation) { - if (is_newnav($navigation)) { - if ($return) { - return($navigation['navlinks']); - } else { - echo $navigation['navlinks']; - return; - } - } else { - debugging('Navigation needs to be updated to use build_navigation()', DEBUG_DEVELOPER); + if ($COURSE) { + if ($COURSE->id != SITEID) { + //Course + $navlinks[] = array('name' => format_string($COURSE->shortname), + 'link' => "$CFG->wwwroot/course/view.php?id=$COURSE->id", + 'type' => 'course'); } + } - if (!is_array($navigation)) { - $ar = explode('->', $navigation); - $navigation = array(); + //Merge in extra navigation links + $navlinks = array_merge($navlinks, $extranavlinks); - foreach ($ar as $a) { - if (strpos($a, '') === false) { - $navigation[] = array('title' => $a, 'url' => ''); - } else { - if (preg_match('/(.*)<\/a>/', $a, $matches)) { - $navigation[] = array('title' => $matches[2], 'url' => $matches[1]); - } - } - } + //Construct an unordered list from $navlinks + //Accessibility: heading hidden from visual browsers by default. + $navigation = '

'.get_string('youarehere','access')."

"; + + return(array('newnav' => true, 'navlinks' => $navigation)); } + /** * Prints a string in a specified size (retained for backward compatibility) * diff --git a/theme/chameleon/header.html b/theme/chameleon/header.html index 37f0dbb7d..ad9dccf05 100644 --- a/theme/chameleon/header.html +++ b/theme/chameleon/header.html @@ -5,7 +5,7 @@ <?php echo $title ?> - + javascript"); ?> @@ -16,19 +16,19 @@ echo " onload=\"setfocus()\""; }; ?>> - +
- -

- -

[ REPLACE ME ]

@@ -35,9 +35,9 @@ +
diff --git a/theme/custom_corners/header.html b/theme/custom_corners/header.html index 3ce57de83..458932fac 100644 --- a/theme/custom_corners/header.html +++ b/theme/custom_corners/header.html @@ -28,7 +28,7 @@ $excludelist = array('mod-chat-view', 'mod-data-view', 'mod-quiz-view', 'my-index'); - if (!empty($PAGE) && (in_array($PAGE->type, $excludelist)) && + if (!empty($PAGE) && (in_array($PAGE->type, $excludelist)) && (strstr($bodytags, ' nocoursepage'))) { $bodytags = str_replace(' nocoursepage', '', $bodytags); } @@ -81,7 +81,7 @@ diff --git a/theme/formal_white/footer.html b/theme/formal_white/footer.html index ec3b78dc3..7cac32547 100644 --- a/theme/formal_white/footer.html +++ b/theme/formal_white/footer.html @@ -11,7 +11,7 @@ diff --git a/theme/formal_white/header.html b/theme/formal_white/header.html index 28065c917..cb3530aa6 100644 --- a/theme/formal_white/header.html +++ b/theme/formal_white/header.html @@ -14,7 +14,7 @@ echo " onload=\"setfocus()\""; } ?>> - +
Moodle/logo.jpg' />
-