From: martin Date: Thu, 11 Jul 2002 05:30:10 +0000 (+0000) Subject: Consistent use of get_site() instead of checking course->category directly X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=a83fded1a9b5144f92b547b51c1e348cf094006d;p=moodle.git Consistent use of get_site() instead of checking course->category directly --- diff --git a/admin/index.php b/admin/index.php index 05e7e76dfb..887b800384 100644 --- a/admin/index.php +++ b/admin/index.php @@ -79,7 +79,7 @@ } // Set up the overall site name etc. - if (! $course = get_record("course", "category", 0)) { + if (! $site = get_site()) { redirect("site.php"); } @@ -93,7 +93,7 @@ // At this point, the databases exist, and the user is an admin - print_header("$course->fullname: Administration Page","$course->fullname: Administration Page", "Admin"); + print_header("$site->fullname: Administration Page","$site->fullname: Administration Page", "Admin"); echo ""; - print_footer(); ?> diff --git a/admin/site.php b/admin/site.php index 25beac9e44..946b132835 100644 --- a/admin/site.php +++ b/admin/site.php @@ -2,7 +2,7 @@ require("../config.php"); - $course = get_record("course", "category", 0); + $course = get_site(); /// If data submitted, then process and store. diff --git a/admin/user.php b/admin/user.php index eabbf8ebc5..56853008b4 100644 --- a/admin/user.php +++ b/admin/user.php @@ -28,7 +28,7 @@ error("User ID was incorrect (can't find it)"); } - if (! $course = get_record("course", "category", 0)) { + if (! $course = get_site()) { error("Could not find site-level course"); } diff --git a/course/edit.php b/course/edit.php index 97bb32155e..0db5511ccb 100644 --- a/course/edit.php +++ b/course/edit.php @@ -22,7 +22,7 @@ error("Only administrators can use this page"); } - if (! $site = get_record("course", "category", 0)) { + if (! $site = get_site()) { redirect("$CFG->wwwroot/admin/"); } } diff --git a/course/enrol.php b/course/enrol.php index 257a8d7bf5..2ac8dc9e79 100644 --- a/course/enrol.php +++ b/course/enrol.php @@ -43,7 +43,7 @@ } - if (! $site = get_record("course", "category", "0") ) { + if (! $site = get_site()) { error("Could not find a site!"); } diff --git a/course/lib.php b/course/lib.php index d0f2e7fb97..492edc4933 100644 --- a/course/lib.php +++ b/course/lib.php @@ -192,7 +192,7 @@ function print_course($course) { global $CFG; - if (! $site = get_record("course", "category", "0") ) { + if (! $site = get_site()) { error("Could not find a site!"); } diff --git a/lib/moodlelib.php b/lib/moodlelib.php index 6d1679b06b..370e7a0278 100644 --- a/lib/moodlelib.php +++ b/lib/moodlelib.php @@ -54,7 +54,7 @@ function print_navigation ($navigation) { global $CFG; if ($navigation) { - if (! $site = get_record("course", "category", 0)) { + if (! $site = get_site()) { $site->shortname = get_string("home");; } echo "wwwroot/\">$site->shortname -> $navigation"; @@ -749,7 +749,7 @@ function get_user_info_from_db($field, $value) { $rs->MoveNext(); } - if ($course = get_record("course", "category", 0)) { + if ($course = get_site()) { // Everyone is always a member of the top course $user->student["$course->id"] = true; } @@ -1094,16 +1094,19 @@ function get_directory_list( $rootdir ) { /// STRING TRANSLATION //////////////////////////////////////// -function print_string($identifier, $module="", $a="", $b="", $c="") { - echo get_string($identifier, $module, $a, $b, $c); +function print_string($identifier, $module="", $a=NULL) { + echo get_string($identifier, $module, $a); } -function get_string($identifier, $module="", $a="", $b="", $c="") { +function get_string($identifier, $module="", $a=NULL) { // Return the translated string specified by $identifier as // for $module. Uses the same format files as STphp. -// $a, $b and $c are optional variables that may be used +// $a is an object, string or number that can be used // within translation strings +// +// eg "hello \$a->firstname \$a->lastname" +// or "hello \$a" global $CFG, $USER; @@ -1153,20 +1156,6 @@ function get_string($identifier, $module="", $a="", $b="", $c="") { } -function get_string_variable_list($string) { -// This function is only used from get_string_from_file(). - if (empty ($string)) - return; - - // Match on all variables in $string - $count = preg_match_all("/\\\$[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*/", - $string, $matches); - - // Return array of matches ($matches[0] is most useful) - return $matches; -} - - function get_string_from_file($identifier, $langfile, $destination) { // This function is only used from get_string(). include ($langfile); @@ -1175,18 +1164,7 @@ function get_string_from_file($identifier, $langfile, $destination) { return false; } - $value = "sprintf(\"".$string[$identifier]."\");"; - $variables = get_string_variable_list($value); - if (empty($variables[0])) - return "$destination = $value"; - else { - foreach ($variables[0] as $variable) { - $variablecheck .= "if (!isset ($variable))\n" . - "die (\"Variable specified in translation " . - "not set.\");\n"; - } - return "$variablecheck $destination = $value"; - } + return "$destination = sprintf(\"".$string[$identifier]."\");"; }