Permalink
Browse files

OK a number of small changes here.

Firstly, I'm replacing all use of old-style global variables like
$HTTY_REFERER with their new-style equivalent $_SERVER["HTTP_REFERER"]
Also using $_POST instead $HTTP_POST_VARS  etc

Secondly, if gdversion == 0 (ie GD is not installed) then:

 - users are not even allowed to upload new images
 - graphs now just print a message instead of failing.

this allows Moodle to still be used even if GD is not present
  • Loading branch information...
1 parent 3b7c1de commit 607809b3bafb9e49c6d8e5107c8a794fe6fb8ea5 moodler committed Jan 5, 2003
View
@@ -130,8 +130,8 @@
} else if ($mode == "compare") {
- if (isset($HTTP_POST_VARS['file'])){ // Save a file
- $newstrings = $HTTP_POST_VARS;
+ if (isset($_POST['file'])){ // Save a file
+ $newstrings = $_POST;
$file = $newstrings['file'];
unset($newstrings['file']);
if (lang_save_file($langdir, $file, $newstrings)) {
View
@@ -756,7 +756,11 @@ function print_course_categories($categories, $selected="none", $width=180) {
function print_log_graph($course, $userid=0, $type="course.png", $date=0) {
global $CFG;
- echo "<IMG BORDER=0 SRC=\"$CFG->wwwroot/course/loggraph.php?id=$course->id&user=$userid&type=$type&date=$date\">";
+ if (empty($CFG->gdversion)) {
+ echo "(".get_string("gdneed").")";
+ } else {
+ echo "<IMG BORDER=0 SRC=\"$CFG->wwwroot/course/loggraph.php?id=$course->id&user=$userid&type=$type&date=$date\">";
+ }
}
View
@@ -19,7 +19,7 @@
$USER->loggedin = true;
$USER->site = $CFG->wwwroot;
save_session("USER");
- redirect($HTTP_REFERER);
+ redirect($_SERVER["HTTP_REFERER"]);
exit;
}
View
@@ -17,14 +17,14 @@
}
- if (isset($course) && isset($HTTP_POST_VARS)) { // add or update form submitted
+ if (isset($_POST["course"])) { // add or update form submitted
if (isset($SESSION->modform)) { // Variables are stored in the session
$mod = $SESSION->modform;
unset($SESSION->modform);
save_session("SESSION");
} else {
- $mod = (object)$HTTP_POST_VARS;
+ $mod = (object)$_POST;
}
require_login($mod->course);
@@ -118,7 +118,7 @@
error("Could not cache module information!");
}
- redirect($HTTP_REFERER);
+ redirect($_SERVER["HTTP_REFERER"]);
exit;
} else if (isset($delete)) { // value = course module
@@ -218,7 +218,7 @@
} else if (isset($add)) {
if (!$add) {
- redirect($HTTP_REFERER);
+ redirect($_SERVER["HTTP_REFERER"]);
die;
}
View
@@ -163,7 +163,7 @@ function html_header($course, $wdir, $formfield=""){
} else {
html_header($course, $wdir);
- if (setfilelist($HTTP_POST_VARS)) {
+ if (setfilelist($_POST)) {
echo "<P ALIGN=CENTER>You are about to delete:</P>";
print_simple_box_start("center");
printfilelist($USER->filelist);
@@ -181,7 +181,7 @@ function html_header($course, $wdir, $formfield=""){
case "move":
html_header($course, $wdir);
- if ($count = setfilelist($HTTP_POST_VARS)) {
+ if ($count = setfilelist($_POST)) {
$USER->fileop = $action;
$USER->filesource = $wdir;
save_session("USER");
@@ -348,7 +348,7 @@ function html_header($course, $wdir, $formfield=""){
} else {
html_header($course, $wdir, "form.name");
- if (setfilelist($HTTP_POST_VARS)) {
+ if (setfilelist($_POST)) {
echo "<P ALIGN=CENTER>You are about create a zip file containing:</P>";
print_simple_box_start("center");
printfilelist($USER->filelist);
View
@@ -81,6 +81,7 @@
$string['processingpost'] = "Processing post \$a";
$string['rate'] = "Rate";
$string['ratings'] = "Ratings";
+$string['ratingssaved'] = "Ratings saved";
$string['readtherest'] = "Read the rest of this topic";
$string['re'] = "Re:"; // Put in front of subjects that are replies to another post
$string['repliesmany'] = "\$a replies so far";
View
@@ -192,6 +192,7 @@
$string['fullsitename'] = "Full site name";
$string['gd1'] = "GD 1.x is installed";
$string['gd2'] = "GD 2.x is installed";
+$string['gdneed'] = "GD must be installed to see this graph";
$string['gdnot'] = "GD is not installed";
$string['gpl'] = "Copyright (C) 2001-2002 Martin Dougiamas (http://dougiamas.com)
View
@@ -254,12 +254,12 @@ function require_login($courseid=0) {
/// whether they are "logged in" or allowed to be in a particular course.
/// If not, then it redirects them to the site login or course enrolment.
- global $CFG, $SESSION, $USER, $FULLME, $HTTP_REFERER, $PHPSESSID;
+ global $CFG, $SESSION, $USER, $FULLME, $PHPSESSID;
// First check that the user is logged in to the site.
if (! (isset($USER->loggedin) and $USER->confirmed and ($USER->site == $CFG->wwwroot)) ) { // They're not
$SESSION->wantsurl = $FULLME;
- $SESSION->fromurl = $HTTP_REFERER;
+ $SESSION->fromurl = $_SERVER["HTTP_REFERER"];
save_session("SESSION");
$USER = NULL;
save_session("USER");
@@ -458,9 +458,7 @@ function get_moodle_cookie() {
$cookiename = "MOODLEID{$CFG->prefix}";
- global $$cookiename;
-
- return rc4decrypt($$cookiename);
+ return rc4decrypt($_COOKIE[$cookiename]);
}
@@ -1124,12 +1122,11 @@ function check_php_version($version="4.1.0") {
function check_browser_version($brand="MSIE", $version=5.5) {
/// Checks to see if is a browser matches the specified
/// brand and is equal or better version.
- global $HTTP_USER_AGENT;
- if (!$HTTP_USER_AGENT) {
+ if (empty($_SERVER["HTTP_USER_AGENT"])) {
return false;
}
- $string = explode(";", $HTTP_USER_AGENT);
+ $string = explode(";", $_SERVER["HTTP_USER_AGENT"]);
if (!isset($string[1])) {
return false;
}
View
@@ -120,9 +120,7 @@ function strip_querystring($url) {
function get_referer() {
/// returns the URL of the HTTP_REFERER, less the querystring portion
- global $HTTP_REFERER;
-
- return strip_querystring(nvl($HTTP_REFERER));
+ return strip_querystring(nvl($_SERVER["HTTP_REFERER"]));
}
@@ -132,16 +130,14 @@ function me() {
/// return different things depending on a lot of things like your OS, Web
/// server, and the way PHP is compiled (ie. as a CGI, module, ISAPI, etc.)
- global $REQUEST_URI, $PATH_INFO, $PHP_SELF;
-
- if ($REQUEST_URI) {
- return $REQUEST_URI;
+ if (!empty($_SERVER["REQUEST_URI"])) {
+ return $_SERVER["REQUEST_URI"];
- } else if ($PATH_INFO) {
- return $PATH_INFO;
+ } else if (!empty($_SERVER["PATH_INFO"])) {
+ return $_SERVER["PATH_INFO"];
- } else if ($PHP_SELF) {
- return $PHP_SELF;
+ } else if (!empty($_SERVER["PHP_SELF"])) {
+ return $_SERVER["PHP_SELF"];
} else {
notify("Error: Could not find any of these web server variables: \$REQUEST_URI, \$PATH_INFO or \$PHP_SELF");
@@ -152,14 +148,12 @@ function me() {
function qualified_me() {
/// like me() but returns a full URL
- global $HTTPS, $HTTP_HOST;
-
- if (!$HTTP_HOST) {
+ if (empty($_SERVER["HTTP_HOST"])) {
notify("Error: could not find web server variable: \$HTTP_HOST");
}
- $protocol = (isset($HTTPS) && $HTTPS == "on") ? "https://" : "http://";
- $url_prefix = "$protocol$HTTP_HOST";
+ $protocol = (isset($_SERVER["HTTPS"]) and $_SERVER["HTTPS"] == "on") ? "https://" : "http://";
+ $url_prefix = "$protocol".$_SERVER["HTTP_HOST"];
return $url_prefix . me();
}
@@ -182,18 +176,19 @@ function match_referer($good_referer = "") {
function data_submitted($url="") {
/// Used on most forms in Moodle to check for data
/// Returns the data as an object, if it's found.
+/// This object can be used in foreach loops without
+/// casting because it's cast to (array) automatically
///
/// Checks that submitted POST data exists, and also
/// checks the referer against the given url (it uses
/// the current page if none was specified.
- global $HTTP_POST_VARS, $CFG;
-
- if (empty($HTTP_POST_VARS)) {
+ if (empty($_POST)) {
return false;
+
} else {
if (match_referer($url)) {
- return (object)$HTTP_POST_VARS;
+ return (object)$_POST;
} else {
if ($CFG->debug > 10) {
notice("The form did not come from this page! (referer = ".get_referer().")");
@@ -306,15 +301,17 @@ function choose_from_menu ($options, $name, $selected="", $nothing="choose", $sc
}
$output .= ">$nothing</OPTION>\n";
}
- foreach ($options as $value => $label) {
- $output .= " <OPTION VALUE=\"$value\"";
- if ($value == $selected) {
- $output .= " SELECTED";
- }
- if ($label) {
- $output .= ">$label</OPTION>\n";
- } else {
- $output .= ">$value</OPTION>\n";
+ if (!empty($options)) {
+ foreach ($options as $value => $label) {
+ $output .= " <OPTION VALUE=\"$value\"";
+ if ($value == $selected) {
+ $output .= " SELECTED";
+ }
+ if ($label) {
+ $output .= ">$label</OPTION>\n";
+ } else {
+ $output .= ">$value</OPTION>\n";
+ }
}
}
$output .= "</SELECT>\n";
@@ -674,10 +671,9 @@ function print_heading_with_help($text, $helppage, $module="moodle") {
}
function print_continue($link) {
- global $HTTP_REFERER;
if (!$link) {
- $link = $HTTP_REFERER;
+ $link = $_SERVER["HTTP_REFERER"];
}
print_heading("<A HREF=\"$link\">".get_string("continue")."</A>");
@@ -1080,10 +1076,10 @@ function helpbutton ($page, $title="", $module="moodle", $image=true, $linktext=
}
function notice ($message, $link="") {
- global $THEME, $HTTP_REFERER;
+ global $THEME;
if (!$link) {
- $link = $HTTP_REFERER;
+ $link = $_SERVER["HTTP_REFERER"];
}
echo "<BR>";
View
@@ -79,7 +79,7 @@
}
if (empty($SESSION->wantsurl)) {
- $SESSION->wantsurl = $HTTP_REFERER;
+ $SESSION->wantsurl = $_SERVER["HTTP_REFERER"];
save_session("SESSION");
}
View
@@ -1061,12 +1061,12 @@ function forum_print_search_form($course, $search="", $return=false, $type="") {
function forum_set_return() {
- global $CFG, $SESSION, $HTTP_REFERER;
+ global $CFG, $SESSION;
if (! isset($SESSION->fromdiscussion)) {
// If the referer is NOT a login screen then save it.
- if (! strncasecmp("$CFG->wwwroot/login", $HTTP_REFERER, 300)) {
- $SESSION->fromdiscussion = $HTTP_REFERER;
+ if (! strncasecmp("$CFG->wwwroot/login", $_SERVER["HTTP_REFERER"], 300)) {
+ $SESSION->fromdiscussion = $_SERVER["HTTP_REFERER"];
save_session("SESSION");
}
}
View
@@ -7,7 +7,7 @@
require("lib.php");
if (isguest()) {
- error(get_string("noguestpost", "forum"), $HTTP_REFERER);
+ error(get_string("noguestpost", "forum"), $_SERVER["HTTP_REFERER"]);
}
if ($post = data_submitted()) {
@@ -73,7 +73,7 @@
if (isset($forum)) { // User is starting a new discussion in a forum
- $SESSION->fromurl = $HTTP_REFERER;
+ $SESSION->fromurl = $_SERVER["HTTP_REFERER"];
save_session("SESSION");
if (! $forum = get_record("forum", "id", $forum)) {
@@ -227,7 +227,7 @@
print_header();
notice_yesno(get_string("deletesure", "forum"),
"post.php?delete=$delete&confirm=$delete",
- $HTTP_REFERER);
+ $_SERVER["HTTP_REFERER"]);
echo "<CENTER><HR>";
forum_print_post($post, $forum->course, $ownpost=false, $reply=false, $link=false);
View
@@ -7,7 +7,7 @@
require("lib.php");
if (isguest()) {
- error("Guests are not allowed to rate posts.", $HTTP_REFERER);
+ error("Guests are not allowed to rate posts.", $_SERVER["HTTP_REFERER"]);
}
require_variable($id); // The course these ratings are part of
@@ -18,9 +18,9 @@
require_login($course->id);
- if (isset($HTTP_POST_VARS)) { // form submitted
+ if ($data = data_submitted("$CFG->wwwroot/mod/forum/discuss.php")) { // form submitted
- foreach ($HTTP_POST_VARS as $post => $rating) {
+ foreach ($data as $post => $rating) {
if ($post == "id") {
continue;
}
@@ -40,7 +40,7 @@
}
}
}
- redirect($HTTP_REFERER, "Ratings saved");
+ redirect($_SERVER["HTTP_REFERER"], get_string("ratingssaved", "forum"));
} else {
error("This page was not accessed correctly");
@@ -10,7 +10,7 @@
optional_variable($user); // Force everyone to be subscribed to this forum?
if (isguest()) {
- error("Guests are not allowed to subscribe to posts.", $HTTP_REFERER);
+ error("Guests are not allowed to subscribe to posts.", $_SERVER["HTTP_REFERER"]);
}
if (! $forum = get_record("forum", "id", $id)) {
@@ -68,15 +68,15 @@
add_to_log($course->id, "forum", "unsubscribe", "view.php?f=$forum->id", "$forum->id");
redirect($returnto, get_string("nownotsubscribed", "forum", $info), 1);
} else {
- error("Could not unsubscribe you from that forum", "$HTTP_REFERER");
+ error("Could not unsubscribe you from that forum", $_SERVER["HTTP_REFERER"]);
}
} else { // subscribe
if (forum_subscribe($user->id, $forum->id) ) {
add_to_log($course->id, "forum", "subscribe", "view.php?f=$forum->id", "$forum->id");
redirect($returnto, get_string("nowsubscribed", "forum", $info), 1);
} else {
- error("Could not subscribe you to that forum", "$HTTP_REFERER");
+ error("Could not subscribe you to that forum", $_SERVER["HTTP_REFERER"]);
}
}
@@ -15,7 +15,7 @@
require_login($course->id);
if (isguest()) {
- error("Guests are not allowed to edit journals", $HTTP_REFERER);
+ error("Guests are not allowed to edit journals", $_SERVER["HTTP_REFERER"]);
}
if (! $journal = get_record("journal", "id", $cm->instance)) {
Oops, something went wrong.

0 comments on commit 607809b

Please sign in to comment.