diff --git a/lib/weblib.php b/lib/weblib.php index a58b7a57209..88b8fab9394 100644 --- a/lib/weblib.php +++ b/lib/weblib.php @@ -62,13 +62,13 @@ function p($var) { } function nvl(&$var, $default="") { -/// if $var is undefined, return $default, otherwise return $var +/// if $var is undefined, return $default, otherwise return $var return isset($var) ? $var : $default; } function strip_querystring($url) { -/// takes a URL and returns it without the querystring portion +/// takes a URL and returns it without the querystring portion if ($commapos = strpos($url, '?')) { return substr($url, 0, $commapos); @@ -78,7 +78,7 @@ function strip_querystring($url) { } function get_referer() { -/// returns the URL of the HTTP_REFERER, less the querystring portion +/// returns the URL of the HTTP_REFERER, less the querystring portion return strip_querystring(nvl($_SERVER["HTTP_REFERER"])); } @@ -88,7 +88,7 @@ function me() { /// returns the name of the current script, WITH the querystring portion. /// this function is necessary because PHP_SELF and REQUEST_URI and SCRIPT_NAME /// 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.) +/// server, and the way PHP is compiled (ie. as a CGI, module, ISAPI, etc.) if (!empty($_SERVER["REQUEST_URI"])) { return $_SERVER["REQUEST_URI"]; @@ -113,7 +113,7 @@ function me() { function qualified_me() { -/// like me() but returns a full URL +/// like me() but returns a full URL if (!empty($_SERVER["HTTP_HOST"])) { $hostname = $_SERVER["HTTP_HOST"]; @@ -136,7 +136,7 @@ function qualified_me() { function match_referer($goodreferer = "") { /// returns true if the referer is the same as the goodreferer. If -/// goodreferer is not specified, use qualified_me as the goodreferer +/// goodreferer is not specified, use qualified_me as the goodreferer global $CFG; if (empty($CFG->secureforms)) { // Don't bother checking referer @@ -147,8 +147,8 @@ function match_referer($goodreferer = "") { return true; } - if (empty($goodreferer)) { - $goodreferer = qualified_me(); + if (empty($goodreferer)) { + $goodreferer = qualified_me(); } return $goodreferer == get_referer(); } @@ -158,9 +158,9 @@ function data_submitted($url="") { /// 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 +/// +/// 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 $CFG; @@ -181,9 +181,9 @@ function data_submitted($url="") { } function stripslashes_safe($string) { -/// stripslashes() removes ALL backslashes even from strings +/// stripslashes() removes ALL backslashes even from strings /// so C:\temp becomes C:temp ... this isn't good. -/// The following should work as a fairly safe replacement +/// The following should work as a fairly safe replacement /// to be called on quoted AND unquoted strings (to be sure) $string = str_replace("\\'", "'", $string); @@ -194,7 +194,7 @@ function stripslashes_safe($string) { function break_up_long_words($string, $maxsize=20, $cutchar=' ') { -/// Given some normal text, this function will break up any +/// Given some normal text, this function will break up any /// long words to a given size, by inserting the given character $output = ''; @@ -270,7 +270,7 @@ function read_template($filename, &$var) { /// the variables interpolated. all the variables must be in the $var[] array or /// object (whatever you decide to use). /// -/// WARNING: do not use this on big files!! +/// WARNING: do not use this on big files!! $temp = str_replace("\\", "\\\\", implode(file($filename), "")); $temp = str_replace('"', '\"', $temp); @@ -281,7 +281,7 @@ function read_template($filename, &$var) { function checked(&$var, $set_value = 1, $unset_value = 0) { /// if variable is set, set it to the set_value otherwise set it to the /// unset_value. used to handle checkboxes when you are expecting them from -/// a form +/// a form if (empty($var)) { $var = $unset_value; @@ -292,7 +292,7 @@ function checked(&$var, $set_value = 1, $unset_value = 0) { function frmchecked(&$var, $true_value = "checked", $false_value = "") { /// prints the word "checked" if a variable is true, otherwise prints nothing, -/// used for printing the word "checked" in a checkbox form input +/// used for printing the word "checked" in a checkbox form input if ($var) { echo $true_value; @@ -302,9 +302,9 @@ function frmchecked(&$var, $true_value = "checked", $false_value = "") { } -function link_to_popup_window ($url, $name="popup", $linkname="click here", +function link_to_popup_window ($url, $name="popup", $linkname="click here", $height=400, $width=500, $title="Popup window", $options="none") { -/// This will create a HTML link that will work on both +/// This will create a HTML link that will work on both /// Javascript and non-javascript browsers. /// Relies on the Javascript function openpopup in javascript.php /// $url must be relative to home page eg /mod/survey/stuff.php @@ -321,9 +321,9 @@ function link_to_popup_window ($url, $name="popup", $linkname="click here", } -function button_to_popup_window ($url, $name="popup", $linkname="click here", +function button_to_popup_window ($url, $name="popup", $linkname="click here", $height=400, $width=500, $title="Popup window", $options="none") { -/// This will create a HTML link that will work on both +/// This will create a HTML link that will work on both /// Javascript and non-javascript browsers. /// Relies on the Javascript function openpopup in javascript.php /// $url must be relative to home page eg /mod/survey/stuff.php @@ -361,7 +361,7 @@ function close_window_button() { function choose_from_menu ($options, $name, $selected="", $nothing="choose", $script="", $nothingvalue="0", $return=false) { /// Given an array of value, creates a popup menu to be part of a form /// $options["value"]["label"] - + if ($nothing == "choose") { $nothing = get_string("choose")."..."; } @@ -400,7 +400,7 @@ function choose_from_menu ($options, $name, $selected="", $nothing="choose", $sc } else { echo $output; } -} +} function popup_form ($common, $options, $formname, $selected="", $nothing="choose", $help="", $helptext="", $return=false, $targetwindow="self") { /// Implements a complete little popup form @@ -411,16 +411,42 @@ function popup_form ($common, $options, $formname, $selected="", $nothing="choos /// $nothing = The label for the "no choice" option /// $help = The name of a help page if help is required /// $helptext = The name of the label for the help button -/// $return = Boolean indicating whether the function should return the text +/// $return = Boolean indicating whether the function should return the text /// as a string or echo it directly to the page being rendered +// TODO: +// +// * Make sure it's W3C conformant (
'; +// + global $CFG; if ($nothing == "choose") { $nothing = get_string("choose")."..."; } - $startoutput = "