From 222ac91bc9136cb103a58c554882069b02f9473e Mon Sep 17 00:00:00 2001
From: gustav_delius
Date: Sun, 29 Aug 2004 14:15:40 +0000
Subject: [PATCH] removed unnecessary calls to get_site()
---
course/lib.php | 7 +-
course/mod.php | 21 ++----
files/index.php | 8 +-
filter/activitynames/filter.php | 4 +-
lib/datalib.php | 22 +++---
lib/editor/coursefiles.php | 4 -
lib/editor/courseimages.php | 90 +++++++++++-----------
lib/moodlelib.php | 17 ++---
login/change_password.php | 3 +-
login/index.php | 3 +-
mod/assignment/lib.php | 15 ++--
mod/attendance/lib.php | 3 +-
mod/dialogue/locallib.php | 3 +-
mod/exercise/locallib.php | 21 ++----
mod/glossary/filter.php | 4 +-
mod/journal/lib.php | 6 +-
mod/resource/coursefiles.php | 76 +++++++++----------
mod/resource/filter.php | 4 +-
mod/resource/version.php | 2 +-
mod/scorm/coursefiles.php | 78 ++++++++++----------
mod/wiki/filter.php | 127 +-------------------------------
mod/wiki/lib.php | 19 ++---
mod/wiki/wikifiles.php | 76 +++++++++----------
mod/workshop/lib.php | 3 +-
mod/workshop/locallib.php | 15 ++--
user/index.php | 3 +-
26 files changed, 219 insertions(+), 415 deletions(-)
diff --git a/course/lib.php b/course/lib.php
index cb5d3abd31..b8c4ac2534 100644
--- a/course/lib.php
+++ b/course/lib.php
@@ -1252,11 +1252,6 @@ function print_course($course, $width="100%") {
$enrol = new enrolment_plugin;
}
- if (! $site = get_site()) {
- error("Could not find a site!");
- }
-
-
print_simple_box_start("center", "$width", $THEME->cellcontent, 5, "coursebox");
$linkcss = $course->visible ? "" : " class=\"dimmed\" ";
@@ -1274,7 +1269,7 @@ function print_course($course, $width="100%") {
$teacher->role = $course->teacher;
}
$fullname = fullname($teacher, isteacher($course->id)); // is the USER a teacher of that course
- echo "$teacher->role: wwwroot/user/view.php?id=$teacher->id&course=$site->id\">$fullname
";
+ echo "$teacher->role: wwwroot/user/view.php?id=$teacher->id&course=".SITEID."\">$fullname
";
}
}
echo "
";
diff --git a/course/mod.php b/course/mod.php
index 237c5208bd..0692432864 100644
--- a/course/mod.php
+++ b/course/mod.php
@@ -179,8 +179,7 @@
rebuild_course_cache($cm->course);
- $site = get_site();
- if ($site->id == $cm->course) {
+ if (SITEID == $cm->course) {
redirect($CFG->wwwroot);
} else {
redirect("view.php?id=$cm->course");
@@ -224,8 +223,7 @@
rebuild_course_cache($section->course);
- $site = get_site();
- if ($site->id == $section->course) {
+ if (SITEID == $section->course) {
redirect($CFG->wwwroot);
} else {
redirect("view.php?id=$section->course");
@@ -249,8 +247,7 @@
error("Could not update the indent level on that course module");
}
- $site = get_site();
- if ($site->id == $cm->course) {
+ if (SITEID == $cm->course) {
redirect($CFG->wwwroot);
} else {
redirect("view.php?id=$cm->course");
@@ -271,8 +268,7 @@
rebuild_course_cache($cm->course);
- $site = get_site();
- if ($site->id == $cm->course) {
+ if (SITEID == $cm->course) {
redirect($CFG->wwwroot);
} else {
redirect("view.php?id=$cm->course");
@@ -297,14 +293,12 @@
error("This module doesn't exist");
}
- $site = get_site();
-
- if ($module->visible and ($section->visible or ($site->id == $cm->course))) {
+ if ($module->visible and ($section->visible or (SITEID == $cm->course))) {
show_course_module($cm->id);
rebuild_course_cache($cm->course);
}
- if ($site->id == $cm->course) {
+ if (SITEID == $cm->course) {
redirect($CFG->wwwroot);
} else {
redirect("view.php?id=$cm->course");
@@ -325,8 +319,7 @@
rebuild_course_cache($cm->course);
- $site = get_site();
- if ($site->id == $cm->course) {
+ if (SITEID == $cm->course) {
redirect($CFG->wwwroot);
} else {
redirect("view.php?id=$cm->course");
diff --git a/files/index.php b/files/index.php
index 287d59d159..216fd09904 100644
--- a/files/index.php
+++ b/files/index.php
@@ -34,11 +34,7 @@
global $CFG;
- if (! $site = get_site()) {
- error("Invalid site!");
- }
-
- if ($course->id == $site->id) {
+ if ($course->id == SITEID) {
$strfiles = get_string("sitefiles");
} else {
$strfiles = get_string("files");
@@ -59,7 +55,7 @@
$fullnav = "id&wdir=/\">$strfiles $navigation -> ".$dirs[$numdirs-1];
}
- if ($course->id == $site->id) {
+ if ($course->id == SITEID) {
print_header("$course->shortname: $strfiles", "$course->fullname",
"admin/index.php\">".get_string("administration").
" -> $fullnav", $formfield);
diff --git a/filter/activitynames/filter.php b/filter/activitynames/filter.php
index 9e52f155c1..5c5e6cc0be 100644
--- a/filter/activitynames/filter.php
+++ b/filter/activitynames/filter.php
@@ -9,9 +9,7 @@
global $CFG;
if (empty($courseid)) {
- if ($site = get_site()) {
- $courseid = $site->id;
- }
+ $courseid = SITEID;
}
$course = get_record("course","id",$courseid);
diff --git a/lib/datalib.php b/lib/datalib.php
index 9beec5446d..16e172b485 100644
--- a/lib/datalib.php
+++ b/lib/datalib.php
@@ -1,6 +1,12 @@
admin = true;
}
- if ($site = get_site()) {
- $user->student[$site->id] = isstudent($site->id, $user->id);
- }
+ $user->student[SITEID] = isstudent(SITEID, $user->id);
/// Determine enrolments based on current enrolment module
@@ -1173,8 +1177,7 @@ function get_course_students($courseid, $sort="s.timeaccess", $dir="", $page=0,
// make sure it works on the site course
$select = "s.course = '$courseid' AND ";
- $site = get_site();
- if ($courseid == $site->id) {
+ if ($courseid == SITEID) {
$select = '';
}
@@ -1367,8 +1370,7 @@ function search_users($courseid, $groupid, $searchtext, $sort='', $exceptions=''
$order = '';
}
- $site = get_site();
- if (!$courseid or $courseid == $site->id) {
+ if (!$courseid or $courseid == SITEID) {
if (!$admins = get_records_sql("SELECT u.id, u.firstname, u.lastname, u.email
FROM {$CFG->prefix}user u,
{$CFG->prefix}user_admins s
@@ -2279,9 +2281,9 @@ function add_to_log($courseid, $module, $action, $url="", $info="", $cm=0, $user
echo "Error: Could not insert a new entry to the Moodle log
"; // Don't throw an error
}
if (!$user and isset($USER->id)) {
- $site = get_site();
- if ($courseid == $site->id) {
- update_user_in_db();
+ if ($courseid == SITEID) {
+ $db->Execute("UPDATE {$CFG->prefix}user SET lastIP='$REMOTE_ADDR', lastaccess='$timenow'
+ WHERE id = '$USER->id' ");
} else if (isstudent($courseid)) {
$db->Execute("UPDATE {$CFG->prefix}user_students SET timeaccess = '$timenow' ".
"WHERE course = '$courseid' AND userid = '$userid'");
diff --git a/lib/editor/coursefiles.php b/lib/editor/coursefiles.php
index be67d28320..517dd5c493 100644
--- a/lib/editor/coursefiles.php
+++ b/lib/editor/coursefiles.php
@@ -38,10 +38,6 @@
global $CFG;
- if (! $site = get_site()) {
- error("Invalid site!");
- }
-
?>
diff --git a/lib/editor/courseimages.php b/lib/editor/courseimages.php
index a459d8ba8f..b2bb82dbe7 100644
--- a/lib/editor/courseimages.php
+++ b/lib/editor/courseimages.php
@@ -37,11 +37,7 @@
global $CFG;
- if (! $site = get_site()) {
- error("Invalid site!");
- }
-
- if ($course->id == $site->id) {
+ if ($course->id == SITEID) {
$strfiles = get_string("sitefiles");
} else {
$strfiles = get_string("files");
@@ -64,21 +60,21 @@
print_header();
?>
-
+
';
@@ -89,7 +85,7 @@
echo '';
echo '';
- if ($course->id == $site->id) {
+ if ($course->id == SITEID) {
print_heading(get_string("publicsitefileswarning"), "center", 2);
}
@@ -544,33 +540,33 @@
break;
case "torte":
- if($_POST)
- {
- while(list($key, $val) = each($_POST))
- {
- if(ereg("file([0-9]+)", $key, $regs))
- {
- $file = $val;
- }
- }
- if(@filetype($CFG->dataroot ."/". $course->id . $file) == "file")
- {
- if(mimeinfo("icon", $file) == "image.gif")
- {
- $url = $CFG->wwwroot ."/file.php?file=/" .$course->id . $file;
- runjavascript($url);
- }
- else
- {
- print "File is not a image!";
- }
- }
- else
- {
- print "You cannot insert FOLDER into richtext editor!!!";
- }
- }
- break;
+ if($_POST)
+ {
+ while(list($key, $val) = each($_POST))
+ {
+ if(ereg("file([0-9]+)", $key, $regs))
+ {
+ $file = $val;
+ }
+ }
+ if(@filetype($CFG->dataroot ."/". $course->id . $file) == "file")
+ {
+ if(mimeinfo("icon", $file) == "image.gif")
+ {
+ $url = $CFG->wwwroot ."/file.php?file=/" .$course->id . $file;
+ runjavascript($url);
+ }
+ else
+ {
+ print "File is not a image!";
+ }
+ }
+ else
+ {
+ print "You cannot insert FOLDER into richtext editor!!!";
+ }
+ }
+ break;
case "cancel";
clearfilelist();
diff --git a/lib/moodlelib.php b/lib/moodlelib.php
index 78865a8eb5..82bd6c09f3 100644
--- a/lib/moodlelib.php
+++ b/lib/moodlelib.php
@@ -383,8 +383,7 @@ function require_login($courseid=0, $autologinguest=true) {
// Check that the user account is properly set up
if (user_not_fully_set_up($USER)) {
- $site = get_site();
- redirect("$CFG->wwwroot/user/edit.php?id=$USER->id&course=$site->id");
+ redirect("$CFG->wwwroot/user/edit.php?id=$USER->id&course=SITEID");
die;
}
@@ -588,8 +587,7 @@ function isstudent($courseid, $userid=0) {
return false;
}
- $site = get_site();
- if ($courseid == $site->id) {
+ if ($courseid == SITEID) {
if (!$userid) {
$userid = $USER->id;
}
@@ -968,9 +966,8 @@ function add_admin($userid) {
$admin->userid = $userid;
// any admin is also a teacher on the site course
- $site = get_site();
- if (!record_exists('user_teachers', 'course', $site->id, 'userid', $userid)) {
- if (!add_teacher($userid, $site->id)) {
+ if (!record_exists('user_teachers', 'course', SITEID, 'userid', $userid)) {
+ if (!add_teacher($userid, SITEID)) {
return false;
}
}
@@ -987,8 +984,7 @@ function remove_admin($userid) {
global $db;
// remove also from the list of site teachers
- $site = get_site();
- remove_teacher($userid, $site->id);
+ remove_teacher($userid, SITEID);
return delete_records("user_admins", "userid", $userid);
}
@@ -1534,8 +1530,7 @@ function email_to_user($user, $from, $subject, $messagetext, $messagehtml="", $a
return true;
} else {
mtrace("ERROR: $mail->ErrorInfo");
- $site = get_site();
- add_to_log($site->id, "library", "mailer", $_SERVER["REQUEST_URI"], "ERROR: $mail->ErrorInfo");
+ add_to_log(SITEID, "library", "mailer", $_SERVER["REQUEST_URI"], "ERROR: $mail->ErrorInfo");
return false;
}
}
diff --git a/login/change_password.php b/login/change_password.php
index b31e8b4b85..8b93c58c8b 100644
--- a/login/change_password.php
+++ b/login/change_password.php
@@ -53,8 +53,7 @@
wwwroot/user/view.php?id=$USER->id&course=$course->id\">$fullname -> $strpasswordchanged", $focus);
notice($strpasswordchanged, "$CFG->wwwroot/user/view.php?id=$USER->id&course=$id");
} else {
- $site = get_site();
- add_to_log($site->id, "user", "change password", "view.php?id=$user->id&course=$site->id", "$course->id");
+ add_to_log(SITEID, "user", "change password", "view.php?id=$user->id&course=".SITEID, "$course->id");
print_header($strpasswordchanged, $strpasswordchanged, $strpasswordchanged, "");
notice($strpasswordchanged, "$CFG->wwwroot/");
}
diff --git a/login/index.php b/login/index.php
index 6a4df7f3d7..0aca572490 100644
--- a/login/index.php
+++ b/login/index.php
@@ -74,8 +74,7 @@
$SESSION->justloggedin = true;
if (user_not_fully_set_up($USER)) {
- $site = get_site();
- redirect("$CFG->wwwroot/user/edit.php?id=$USER->id&course=$site->id");
+ redirect("$CFG->wwwroot/user/edit.php?id=$USER->id&course=".SITEID);
} else if (strpos($wantsurl, $CFG->wwwroot) === 0) { /// Matches site address
redirect($wantsurl);
diff --git a/mod/assignment/lib.php b/mod/assignment/lib.php
index 234c83daa9..b5de966de9 100644
--- a/mod/assignment/lib.php
+++ b/mod/assignment/lib.php
@@ -425,8 +425,7 @@ function assignment_count_real_submissions($assignment, $groupid=0) {
AND a.userid = g.userid ");
} else {
$select = "s.course = '$assignment->course' AND";
- $site = get_site();
- if ($assignment->course == $site->id) {
+ if ($assignment->course == SITEID) {
$select = '';
}
return count_records_sql("SELECT COUNT(*)
@@ -451,8 +450,7 @@ function assignment_get_all_submissions($assignment, $sort="", $dir="DESC") {
}
$select = "s.course = '$assignment->course' AND";
- $site = get_site();
- if ($assignment->course == $site->id) {
+ if ($assignment->course == SITEID) {
$select = '';
}
return get_records_sql("SELECT a.*
@@ -470,8 +468,7 @@ function assignment_get_users_done($assignment) {
global $CFG;
$select = "s.course = '$assignment->course' AND";
- $site = get_site();
- if ($assignment->course == $site->id) {
+ if ($assignment->course == SITEID) {
$select = '';
}
return get_records_sql("SELECT u.*
@@ -497,8 +494,8 @@ function assignment_get_unmailed_submissions($cutofftime) {
AND s.assignment = a.id
AND s.userid = us.userid
AND a.course = us.course");
- $site = get_site();
- if (record_exists('assignment', 'course', $site->id)) {
+ $siteid = SITEID;
+ if (record_exists('assignment', 'course', $siteid)) {
$records += get_records_sql("SELECT s.*, a.course, a.name
FROM {$CFG->prefix}assignment_submissions s,
{$CFG->prefix}assignment a,
@@ -508,7 +505,7 @@ function assignment_get_unmailed_submissions($cutofftime) {
AND s.timemarked > 0
AND s.assignment = a.id
AND s.userid = us.userid
- AND a.course = $site->id");
+ AND a.course = $siteid");
}
}
diff --git a/mod/attendance/lib.php b/mod/attendance/lib.php
index bee964aff2..da704bef82 100755
--- a/mod/attendance/lib.php
+++ b/mod/attendance/lib.php
@@ -387,8 +387,7 @@ function attendance_get_course_students($courseid, $sort="u.lastaccess DESC") {
// make sure it works on the site course
$select = "s.course = '$courseid' AND";
- $site = get_site();
- if ($courseid == $site->id) {
+ if ($courseid == SITEID) {
$select = '';
}
return get_records_sql("SELECT u.id, u.username, u.firstname, u.lastname, u.maildisplay, u.mailformat,
diff --git a/mod/dialogue/locallib.php b/mod/dialogue/locallib.php
index 3db4752417..c20294794e 100644
--- a/mod/dialogue/locallib.php
+++ b/mod/dialogue/locallib.php
@@ -235,8 +235,7 @@ function dialogue_get_users_done($dialogue) {
// make sure it works on the site course
$select = "s.course = '$dialogue->course' AND";
- $site = get_site();
- if ($courseid == $site->id) {
+ if ($courseid == SITEID) {
$select = '';
}
if (!$students = get_records_sql("SELECT u.*
diff --git a/mod/exercise/locallib.php b/mod/exercise/locallib.php
index 49d5bb86db..0d4a3ae624 100644
--- a/mod/exercise/locallib.php
+++ b/mod/exercise/locallib.php
@@ -239,8 +239,7 @@ function exercise_count_student_submissions($exercise) {
// make sure it works on the site course
$select = "u.course = '$exercise->course' AND";
- $site = get_site();
- if ($exercise->course == $site->id) {
+ if ($exercise->course == SITEID) {
$select = '';
}
@@ -489,8 +488,7 @@ function exercise_get_best_submission_grades($exercise) {
// make sure it works on the site course
$select = "u.course = '$exercise->course' AND";
- $site = get_site();
- if ($exercise->course == $site->id) {
+ if ($exercise->course == SITEID) {
$select = '';
}
@@ -543,8 +541,7 @@ function exercise_get_student_submissions($exercise, $order = "time", $groupid =
// make sure it works on the site course
$select = "u.course = '$exercise->course' AND";
- $site = get_site();
- if ($exercise->course == $site->id) {
+ if ($exercise->course == SITEID) {
$select = '';
}
@@ -570,8 +567,7 @@ function exercise_get_student_submissions($exercise, $order = "time", $groupid =
// make sure it works on the site course
$select = "u.course = '$exercise->course' AND";
- $site = get_site();
- if ($exercise->course == $site->id) {
+ if ($exercise->course == SITEID) {
$select = '';
}
@@ -591,8 +587,7 @@ function exercise_get_student_submissions($exercise, $order = "time", $groupid =
// make sure it works on the site course
$select = "u.course = '$exercise->course' AND";
- $site = get_site();
- if ($exercise->course == $site->id) {
+ if ($exercise->course == SITEID) {
$select = '';
}
@@ -615,8 +610,7 @@ function exercise_get_student_submissions($exercise, $order = "time", $groupid =
// make sure it works on the site course
$select = "u.course = '$exercise->course' AND";
- $site = get_site();
- if ($exercise->course == $site->id) {
+ if ($exercise->course == SITEID) {
$select = '';
}
@@ -670,8 +664,7 @@ function exercise_get_ungraded_assessments_student($exercise) {
// make sure it works on the site course
$select = "u.course = '$exercise->course' AND";
- $site = get_site();
- if ($exercise->course == $site->id) {
+ if ($exercise->course == SITEID) {
$select = '';
}
diff --git a/mod/glossary/filter.php b/mod/glossary/filter.php
index 3544778d4d..05bd8baed9 100644
--- a/mod/glossary/filter.php
+++ b/mod/glossary/filter.php
@@ -4,9 +4,7 @@
global $CFG;
if (empty($courseid)) {
- if ($site = get_site()) {
- $courseid = $site->id;
- }
+ $courseid = SITEID;
}
$GLOSSARY_CONCEPT_IS_ENTRY = 0;
diff --git a/mod/journal/lib.php b/mod/journal/lib.php
index 073c75091c..f33270355a 100644
--- a/mod/journal/lib.php
+++ b/mod/journal/lib.php
@@ -316,8 +316,7 @@ function journal_get_users_done($journal) {
// make sure it works on the site course
$select = "s.course = '$journal->course' AND";
- $site = get_site();
- if ($journal->course == $site->id) {
+ if ($journal->course == SITEID) {
$select = '';
}
@@ -369,8 +368,7 @@ function journal_count_entries($journal, $groupid=0) {
// make sure it works on the site course
$select = "s.course = '$journal->course' AND";
- $site = get_site();
- if ($journal->course == $site->id) {
+ if ($journal->course == SITEID) {
$select = '';
}
diff --git a/mod/resource/coursefiles.php b/mod/resource/coursefiles.php
index f9d92a3b00..8dff0964c8 100644
--- a/mod/resource/coursefiles.php
+++ b/mod/resource/coursefiles.php
@@ -37,11 +37,7 @@
global $CFG,$THEME;
- if (! $site = get_site()) {
- error("Invalid site!");
- }
-
- if ($course->id == $site->id) {
+ if ($course->id == SITEID) {
$strfiles = get_string("sitefiles");
} else {
$strfiles = get_string("files");
@@ -64,14 +60,14 @@
print_header();
?>
-
+
';
@@ -82,7 +78,7 @@
echo '';
echo '';
- if ($course->id == $site->id) {
+ if ($course->id == SITEID) {
print_heading(get_string("publicsitefileswarning"), "center", 2);
}
@@ -537,33 +533,33 @@
break;
case "torte":
- if($_POST)
- {
- while(list($key, $val) = each($_POST))
- {
- if(ereg("file([0-9]+)", $key, $regs))
- {
- $file = $val;
- }
- }
- if(@filetype($CFG->dataroot ."/". $course->id . $file) == "file")
- {
- if(mimeinfo("icon", $file) == "image.gif")
- {
- $url = $CFG->wwwroot ."/file.php?file=/" .$course->id . $file;
- runjavascript($url);
- }
- else
- {
- print "File is not a image!";
- }
- }
- else
- {
- print "You cannot insert FOLDER into richtext editor!!!";
- }
- }
- break;
+ if($_POST)
+ {
+ while(list($key, $val) = each($_POST))
+ {
+ if(ereg("file([0-9]+)", $key, $regs))
+ {
+ $file = $val;
+ }
+ }
+ if(@filetype($CFG->dataroot ."/". $course->id . $file) == "file")
+ {
+ if(mimeinfo("icon", $file) == "image.gif")
+ {
+ $url = $CFG->wwwroot ."/file.php?file=/" .$course->id . $file;
+ runjavascript($url);
+ }
+ else
+ {
+ print "File is not a image!";
+ }
+ }
+ else
+ {
+ print "You cannot insert FOLDER into richtext editor!!!";
+ }
+ }
+ break;
case "cancel";
clearfilelist();
diff --git a/mod/resource/filter.php b/mod/resource/filter.php
index 4a98198118..5b59d5303d 100644
--- a/mod/resource/filter.php
+++ b/mod/resource/filter.php
@@ -9,9 +9,7 @@
global $CFG;
if (empty($courseid)) {
- if ($site = get_site()) {
- $courseid = $site->id;
- }
+ $courseid = SITEID;
}
switch ($CFG->dbtype) {
diff --git a/mod/resource/version.php b/mod/resource/version.php
index 2d3595a7c1..af6468dcdc 100644
--- a/mod/resource/version.php
+++ b/mod/resource/version.php
@@ -6,7 +6,7 @@
////////////////////////////////////////////////////////////////////////////////
$module->version = 2004080801;
-$module->requires = 2004073000; // Requires this Moodle version
+$module->requires = 2004092901; // Requires this Moodle version
$module->cron = 0;
?>
diff --git a/mod/scorm/coursefiles.php b/mod/scorm/coursefiles.php
index b514910f05..b922736b97 100755
--- a/mod/scorm/coursefiles.php
+++ b/mod/scorm/coursefiles.php
@@ -37,11 +37,7 @@
global $CFG,$THEME,$ME;
- if (! $site = get_site()) {
- error("Invalid site!");
- }
-
- if ($course->id == $site->id) {
+ if ($course->id == SITEID) {
$strfiles = get_string("sitefiles");
} else {
$strfiles = get_string("files");
@@ -64,14 +60,14 @@
print_header();
?>
-
+
';
@@ -82,7 +78,7 @@
echo '';
echo '';
- if ($course->id == $site->id) {
+ if ($course->id == SITEID) {
print_heading(get_string("publicsitefileswarning"), "center", 2);
}
@@ -537,33 +533,33 @@
break;
case "torte":
- if($_POST)
- {
- while(list($key, $val) = each($_POST))
- {
- if(ereg("file([0-9]+)", $key, $regs))
- {
- $file = $val;
- }
- }
- if(@filetype($CFG->dataroot ."/". $course->id . $file) == "file")
- {
- if(mimeinfo("icon", $file) == "image.gif")
- {
- $url = $CFG->wwwroot ."/file.php?file=/" .$course->id . $file;
- runjavascript($url);
- }
- else
- {
- print "File is not a image!";
- }
- }
- else
- {
- print "You cannot insert FOLDER into richtext editor!!!";
- }
- }
- break;
+ if($_POST)
+ {
+ while(list($key, $val) = each($_POST))
+ {
+ if(ereg("file([0-9]+)", $key, $regs))
+ {
+ $file = $val;
+ }
+ }
+ if(@filetype($CFG->dataroot ."/". $course->id . $file) == "file")
+ {
+ if(mimeinfo("icon", $file) == "image.gif")
+ {
+ $url = $CFG->wwwroot ."/file.php?file=/" .$course->id . $file;
+ runjavascript($url);
+ }
+ else
+ {
+ print "File is not a image!";
+ }
+ }
+ else
+ {
+ print "You cannot insert FOLDER into richtext editor!!!";
+ }
+ }
+ break;
case "cancel";
clearfilelist();
@@ -684,7 +680,7 @@ function displaydir ($wdir) {
$dirlist[] = $file;
} else {
if ((basename(strtolower($file),".zip") != basename(strtolower($file))) || (basename(strtolower($file),".pif") != basename(strtolower($file))))
- $filelist[] = $file;
+ $filelist[] = $file;
}
}
closedir($directory);
diff --git a/mod/wiki/filter.php b/mod/wiki/filter.php
index 6243e5d361..78a327c34c 100755
--- a/mod/wiki/filter.php
+++ b/mod/wiki/filter.php
@@ -1,126 +1 @@
-dirroot.'/mod/wiki/lib.php');
-
- function wiki_filter($courseid, $text) {
-
- global $CFG;
-
- if (empty($courseid)) {
- if ($site = get_site()) {
- $courseid = $site->id;
- }
- }
-
- if (!($course = get_record('course', 'id', $courseid))) {
- return $text;
- }
-
-// Get all wikis for this course.
- $wikis = wiki_get_course_wikis($courseid);
- if (empty($wikis)) {
- return $text;
- }
-
-// Walk through each wiki, and get entries.
- foreach ($wikis as $wiki) {
- if ($wiki_entries = wiki_get_entries($wiki)) {
-
-// Walk through each entry and get the pages.
- foreach ($wiki_entries as $wiki_entry) {
- if ($wiki_pages = get_records('wiki_pages', 'wiki', $wiki_entry->id)) {
-
-// Walk through each page and filter.
- foreach ($wiki_pages as $wiki_page) {
- $startlink = '';
- $text = wiki_link_names($text, $wiki_page->pagename, $startlink, '');
- }
- }
- }
- }
- }
-
- return $text;
- }
-
- function wiki_link_names($text,$name,$href_tag_begin,$href_tag_end = "") {
-
- $list_of_words_cp = strip_tags($name);
-
- $list_of_words_cp = trim($list_of_words_cp,'|');
-
- $list_of_words_cp = trim($list_of_words_cp);
-
- $list_of_words_cp = preg_quote($list_of_words_cp,'/');
-
- $invalidprefixs = "([a-zA-Z0-9])";
- $invalidsufixs = "([a-zA-Z0-9])";
-
- //Avoid seaching in the string if it's inside invalidprefixs and invalidsufixs
- $words = array();
- $regexp = '/'.$invalidprefixs.'('.$list_of_words_cp.')|('.$list_of_words_cp.')'.$invalidsufixs.'/is';
- preg_match_all($regexp,$text,$list_of_words);
-
- foreach (array_unique($list_of_words[0]) as $key=>$value) {
- $words['<*'.$key.'*>'] = $value;
- }
- if (!empty($words)) {
- $text = str_replace($words,array_keys($words),$text);
- }
-
- //Now avoid searching inside the tag
- $excludes = array();
- preg_match_all('/(.+?)<\/nolink>/is',$text,$list_of_excludes);
- foreach (array_unique($list_of_excludes[0]) as $key=>$value) {
- $excludes['<+'.$key.'+>'] = $value;
- }
- if (!empty($excludes)) {
- $text = str_replace($excludes,array_keys($excludes),$text);
- }
-
- //Now avoid searching inside links
- $links = array();
- preg_match_all('/(.+?)<\/A>/is',$text,$list_of_links);
- foreach (array_unique($list_of_links[0]) as $key=>$value) {
- $links['<@'.$key.'@>'] = $value;
- }
- if (!empty($links)) {
- $text = str_replace($links,array_keys($links),$text);
- }
-
- //Now avoid searching inside every tag
- $final = array();
- preg_match_all('/<(.+?)>/is',$text,$list_of_tags);
- foreach (array_unique($list_of_tags[0]) as $key=>$value) {
- $final['<|'.$key.'|>'] = $value;
- }
- if (!empty($final)) {
- $text = str_replace($final,array_keys($final),$text);
- }
-
- $text = preg_replace('/('.$list_of_words_cp.')/is', $href_tag_begin.'$1'.$href_tag_end,$text);
-
- //Now rebuild excluded areas
- if (!empty($final)) {
- $text = str_replace(array_keys($final),$final,$text);
- }
- if (!empty($links)) {
- $text = str_replace(array_keys($links),$links,$text);
- }
- if (!empty($excludes)) {
- $text = str_replace(array_keys($excludes),$excludes,$text);
- }
- if (!empty($words)) {
- $text = str_replace(array_keys($words),$words,$text);
- }
- return $text;
- }
-?>
+dirroot.'/mod/wiki/lib.php');
function wiki_filter($courseid, $text) {
global $CFG;
if (empty($courseid)) {
$courseid = SITEID;
}
}
if (!($course = get_record('course', 'id', $courseid))) {
return $text;
}
// Get all wikis for this course.
$wikis = wiki_get_course_wikis($courseid);
if (empty($wikis)) {
return $text;
}
// Walk through each wiki, and get entries.
foreach ($wikis as $wiki) {
if ($wiki_entries = wiki_get_entries($wiki)) {
// Walk through each entry and get the pages.
foreach ($wiki_entries as $wiki_entry) {
if ($wiki_pages = get_records('wiki_pages', 'wiki', $wiki_entry->id)) {
// Walk through each page and filter.
foreach ($wiki_pages as $wiki_page) {
$startlink = '';
$text = wiki_link_names($text, $wiki_page->pagename, $startlink, '');
}
}
}
}
}
return $text;
}
function wiki_link_names($text,$name,$href_tag_begin,$href_tag_end = "") {
$list_of_words_cp = strip_tags($name);
$list_of_words_cp = trim($list_of_words_cp,'|');
$list_of_words_cp = trim($list_of_words_cp);
$list_of_words_cp = preg_quote($list_of_words_cp,'/');
$invalidprefixs = "([a-zA-Z0-9])";
$invalidsufixs = "([a-zA-Z0-9])";
//Avoid seaching in the string if it's inside invalidprefixs and invalidsufixs
$words = array();
$regexp = '/'.$invalidprefixs.'('.$list_of_words_cp.')|('.$list_of_words_cp.')'.$invalidsufixs.'/is';
preg_match_all($regexp,$text,$list_of_words);
foreach (array_unique($list_of_words[0]) as $key=>$value) {
$words['<*'.$key.'*>'] = $value;
}
if (!empty($words)) {
$text = str_replace($words,array_keys($words),$text);
}
//Now avoid searching inside the tag
$excludes = array();
preg_match_all('/(.+?)<\/nolink>/is',$text,$list_of_excludes);
foreach (array_unique($list_of_excludes[0]) as $key=>$value) {
$excludes['<+'.$key.'+>'] = $value;
}
if (!empty($excludes)) {
$text = str_replace($excludes,array_keys($excludes),$text);
}
//Now avoid searching inside links
$links = array();
preg_match_all('/(.+?)<\/A>/is',$text,$list_of_links);
foreach (array_unique($list_of_links[0]) as $key=>$value) {
$links['<@'.$key.'@>'] = $value;
}
if (!empty($links)) {
$text = str_replace($links,array_keys($links),$text);
}
//Now avoid searching inside every tag
$final = array();
preg_match_all('/<(.+?)>/is',$text,$list_of_tags);
foreach (array_unique($list_of_tags[0]) as $key=>$value) {
$final['<|'.$key.'|>'] = $value;
}
if (!empty($final)) {
$text = str_replace($final,array_keys($final),$text);
}
$text = preg_replace('/('.$list_of_words_cp.')/is', $href_tag_begin.'$1'.$href_tag_end,$text);
//Now rebuild excluded areas
if (!empty($final)) {
$text = str_replace(array_keys($final),$final,$text);
}
if (!empty($links)) {
$text = str_replace(array_keys($links),$links,$text);
}
if (!empty($excludes)) {
$text = str_replace(array_keys($excludes),$excludes,$text);
}
if (!empty($words)) {
$text = str_replace(array_keys($words),$words,$text);
}
return $text;
}
?>
\ No newline at end of file
diff --git a/mod/wiki/lib.php b/mod/wiki/lib.php
index 5871d2db50..c8db5620d6 100644
--- a/mod/wiki/lib.php
+++ b/mod/wiki/lib.php
@@ -407,18 +407,17 @@ function wiki_get_other_wikis(&$wiki, &$user, &$course, $currentid=0) {
$mygroupid = mygroupid($course->id);
$isteacher = isteacher($course->id, $user->id);
$isteacheredit = isteacheredit($course->id, $user->id);
- $site = get_site();
switch ($wiki->wtype) {
case 'student':
/// Get all the existing entries for this wiki.
$wiki_entries = wiki_get_entries($wiki, 'student');
- if ($isteacher and ($site->id != $course->id)) {
+ if ($isteacher and (SITEID != $course->id)) {
/// If the user is an editing teacher, or a non-editing teacher not assigned to a group, show all student
/// wikis, regardless of creation.
- if (($site->id != $course->id) and ($isteacheredit or ($groupmode == NOGROUPS))) {
+ if ((SITEID != $course->id) and ($isteacheredit or ($groupmode == NOGROUPS))) {
if ($students = get_course_students($course->id)) {
/// Default pagename is dependent on the wiki settings.
@@ -494,7 +493,7 @@ function wiki_get_other_wikis(&$wiki, &$user, &$course, $currentid=0) {
/// group (for separate groups) or there are visible groups, or if this is
/// a site-level wiki, and they are an administrator.
if (($groupmode == VISIBLEGROUPS) or
- (($site->id == $course->id) and isadmin())) {
+ ((SITEID == $course->id) and isadmin())) {
$viewall = true;
}
else if ($groupmode == SEPARATEGROUPS) {
@@ -706,7 +705,6 @@ function wiki_can_add_entry(&$wiki, &$user, &$course, $userid=0, $groupid=0) {
/// Get the groupmode. It's been added to the wiki object.
$groupmode = groupmode($course, $wiki);
$mygroupid = mygroupid($course->id);
- $site = get_site();
switch ($wiki->wtype) {
@@ -715,7 +713,7 @@ function wiki_can_add_entry(&$wiki, &$user, &$course, $userid=0, $groupid=0) {
/// A user can create their own wiki at the site level.
if ($userid == 0) {
return (isstudent($course->id, $user->id) or
- (($site->id == $course->id) and !empty($user) and !isguest()));
+ ((SITEID == $course->id) and !empty($user) and !isguest()));
}
/// An editing teacher can create any student wiki, or
/// a non-editing teacher, if not assigned to a group can create any student wiki, or if assigned to a group can
@@ -730,7 +728,7 @@ function wiki_can_add_entry(&$wiki, &$user, &$course, $userid=0, $groupid=0) {
/// If mode is 'nogroups', then all participants can add wikis.
if (!$groupmode) {
return (isstudent($course->id, $user->id) or isteacher($course->id, $user->id) or
- (($site->id == $course->id) and !empty($user) and !isguest()));
+ ((SITEID == $course->id) and !empty($user) and !isguest()));
}
/// If not requesting a group, must be a member of a group.
else if ($groupid == 0) {
@@ -747,7 +745,7 @@ function wiki_can_add_entry(&$wiki, &$user, &$course, $userid=0, $groupid=0) {
case 'teacher':
/// If mode is 'nogroups', then all teachers can add wikis.
if (!$groupmode) {
- return (isteacher($course->id, $user->id) or (($site->id == $course->id) and isadmin()));
+ return (isteacher($course->id, $user->id) or ((SITEID == $course->id) and isadmin()));
}
/// If not requesting a group, must be a member of a group.
else if ($groupid == 0) {
@@ -771,7 +769,6 @@ function wiki_can_edit_entry(&$wiki_entry, &$wiki, &$user, &$course) {
$can_edit = false;
$groupmode = groupmode($course, $wiki);
$mygroupid = mygroupid($course->id);
- $site = get_site();
/// Editing teacher's and admins can edit all wikis, non-editing teachers can edit wikis in their groups,
/// or all wikis if group mode is 'no groups' or they don't belong to a group.
@@ -798,7 +795,7 @@ function wiki_can_edit_entry(&$wiki_entry, &$wiki, &$user, &$course) {
/// If mode is 'nogroups', then all participants can edit the wiki.
else {
$can_edit = (isstudent($course->id, $user->id) or isteacher($course->id, $user->id) or
- (($site->id == $course->id) and !empty($user) and !isguest()));
+ ((SITEID == $course->id) and !empty($user) and !isguest()));
}
break;
@@ -809,7 +806,7 @@ function wiki_can_edit_entry(&$wiki_entry, &$wiki, &$user, &$course) {
$can_edit = (isteacher($course->id, $user->id) and ismember($wiki_entry->groupid, $user->id));
}
else {
- $can_edit = (isteacher($course->id, $user->id) or (($site->id == $course->id) and isadmin()));
+ $can_edit = (isteacher($course->id, $user->id) or ((SITEID == $course->id) and isadmin()));
}
break;
}
diff --git a/mod/wiki/wikifiles.php b/mod/wiki/wikifiles.php
index c903eff33a..5fd2582cfe 100755
--- a/mod/wiki/wikifiles.php
+++ b/mod/wiki/wikifiles.php
@@ -37,11 +37,7 @@
global $CFG, $THEME, $ME;
- if (! $site = get_site()) {
- error("Invalid site!");
- }
-
- if ($course->id == $site->id) {
+ if ($course->id == SITEID) {
$strfiles = get_string("sitefiles");
} else {
$strfiles = get_string("files");
@@ -64,14 +60,14 @@
print_header();
?>
-
+
';
@@ -82,7 +78,7 @@
echo '';
echo '';
- if ($course->id == $site->id) {
+ if ($course->id == SITEID) {
print_heading(get_string("publicsitefileswarning"), "center", 2);
}
@@ -531,33 +527,33 @@
break;
case "torte":
- if($_POST)
- {
- while(list($key, $val) = each($_POST))
- {
- if(ereg("file([0-9]+)", $key, $regs))
- {
- $file = $val;
- }
- }
- if(@filetype($CFG->dataroot ."/". $course->id . $file) == "file")
- {
- if(mimeinfo("icon", $file) == "image.gif")
- {
- $url = $CFG->wwwroot ."/file.php?file=/" .$course->id . $file;
- runjavascript($url);
- }
- else
- {
- print "File is not a image!";
- }
- }
- else
- {
- print "You cannot insert FOLDER into richtext editor!!!";
- }
- }
- break;
+ if($_POST)
+ {
+ while(list($key, $val) = each($_POST))
+ {
+ if(ereg("file([0-9]+)", $key, $regs))
+ {
+ $file = $val;
+ }
+ }
+ if(@filetype($CFG->dataroot ."/". $course->id . $file) == "file")
+ {
+ if(mimeinfo("icon", $file) == "image.gif")
+ {
+ $url = $CFG->wwwroot ."/file.php?file=/" .$course->id . $file;
+ runjavascript($url);
+ }
+ else
+ {
+ print "File is not a image!";
+ }
+ }
+ else
+ {
+ print "You cannot insert FOLDER into richtext editor!!!";
+ }
+ }
+ break;
case "cancel";
clearfilelist();
diff --git a/mod/workshop/lib.php b/mod/workshop/lib.php
index 93523ba138..b4bed7af64 100644
--- a/mod/workshop/lib.php
+++ b/mod/workshop/lib.php
@@ -1205,8 +1205,7 @@ function workshop_get_student_submissions($workshop, $order = "title") {
// make sure it works on the site course
$select = "u.course = '$workshop->course' AND";
- $site = get_site();
- if ($workshop->course == $site->id) {
+ if ($workshop->course == SITEID) {
$select = '';
}
diff --git a/mod/workshop/locallib.php b/mod/workshop/locallib.php
index d3d93ba39f..fb6f270294 100644
--- a/mod/workshop/locallib.php
+++ b/mod/workshop/locallib.php
@@ -250,8 +250,7 @@ function workshop_count_student_submissions($workshop) {
// make sure it works on the site course
$select = "s.course = '$workshop->course' AND";
- $site = get_site();
- if ($workshop->course == $site->id) {
+ if ($workshop->course == SITEID) {
$select = '';
}
@@ -515,8 +514,7 @@ function workshop_get_student_assessments($workshop, $user) {
// make sure it works on the site course
$select = "u.course = '$workshop->course' AND";
- $site = get_site();
- if ($workshop->course == $site->id) {
+ if ($workshop->course == SITEID) {
$select = '';
}
@@ -538,8 +536,7 @@ function workshop_get_student_submission_assessments($workshop) {
// make sure it works on the site course
$select = "u.course = '$workshop->course' AND";
- $site = get_site();
- if ($workshop->course == $site->id) {
+ if ($workshop->course == SITEID) {
$select = '';
}
@@ -608,8 +605,7 @@ function workshop_get_ungraded_assessments_student($workshop) {
// make sure it works on the site course
$select = "u.course = '$workshop->course' AND";
- $site = get_site();
- if ($workshop->course == $site->id) {
+ if ($workshop->course == SITEID) {
$select = '';
}
@@ -668,8 +664,7 @@ function workshop_get_users_done($workshop) {
// make sure it works on the site course
$select = "s.course = '$workshop->course' AND";
- $site = get_site();
- if ($workshop->course == $site->id) {
+ if ($workshop->course == SITEID) {
$select = '';
}
diff --git a/user/index.php b/user/index.php
index 037e3b2ded..7f7d2ebd9c 100644
--- a/user/index.php
+++ b/user/index.php
@@ -68,8 +68,7 @@
$guest = get_guest();
$exceptions .= $guest->id;
- $site = get_site();
- if ($course->id == $site->id) { // Show all site users (even unconfirmed)
+ if ($course->id == SITEID) { // Show all site users (even unconfirmed)
$students = get_users(true, '', true, $exceptions, $sort.' '.$dir, $firstinitial, $lastinitial, $page*$perpage, $perpage);
$totalcount = get_users(false, '', true, '', '', '', '') - 1; // -1 to not count guest user
if ($firstinitial or $lastinitial) {
--
2.39.5