From: defacer Date: Fri, 21 May 2004 13:07:11 +0000 (+0000) Subject: Small fix (added method attribute to form) and some comments for the future X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=ab9f24ad00ca62888ed5859eaef1864be9d068c4;p=moodle.git Small fix (added method attribute to form) and some comments for the future --- diff --git a/lib/weblib.php b/lib/weblib.php index a58b7a5720..88b8fab939 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 (
has to go for example) +// * Code it in a way that doesn't require JS to be on. Example code: +// $selector .= ''; +// $selector .= ''; +// if(!empty($morevars)) { +// $getarray = explode('&', $morevars); +// foreach($getarray as $thisvar) { +// $selector .= ''; +// } +// } +// $selector .= ''; +// $selector .= ''; +// $selector .= ''; +// $selector .= '
'; +// + global $CFG; if ($nothing == "choose") { $nothing = get_string("choose")."..."; } - $startoutput = "
framename}\" name=\"$formname\">"; + $startoutput = "framename}\" name=\"$formname\">"; $output = "". "". @@ -1835,7 +1861,7 @@ function navmenu($course, $cm=NULL, $targetwindow="self") { $logslink = "framename\" href=". "\"$CFG->wwwroot/course/log.php?chooselog=1&user=0&date=0&id=$course->id&modid=$selectmod->cm\">". "pixpath/i/log.gif\">"; - + } if ($backmod) { $backmod = "wwwroot/mod/$backmod->mod/view.php\" target=\"$CFG->framename\">". @@ -1921,7 +1947,7 @@ function print_grade_menu($courseid, $name, $current, $includenograde=true) { $helpicon = "$CFG->pixpath/help.gif"; $linkobject = "\"$strscales\""; - link_to_popup_window ("/course/scales.php?id=$courseid&list=true", "ratingscales", + link_to_popup_window ("/course/scales.php?id=$courseid&list=true", "ratingscales", $linkobject, 400, 500, $strscales); } @@ -1935,7 +1961,7 @@ function print_scale_menu($courseid, $name, $current) { choose_from_menu(get_scales_menu($courseid), "$name", $current, ""); $helpicon = "$CFG->pixpath/help.gif"; $linkobject = "\"$strscales\""; - link_to_popup_window ("/course/scales.php?id=$courseid&list=true", "ratingscales", + link_to_popup_window ("/course/scales.php?id=$courseid&list=true", "ratingscales", $linkobject, 400, 500, $strscales); } @@ -1949,7 +1975,7 @@ function print_scale_menu_helpbutton($courseid, $scale) { $strscales = get_string("scales"); $helpicon = "$CFG->pixpath/help.gif"; $linkobject = "\"$scale-name\" src=\"$helpicon\" />"; - link_to_popup_window ("/course/scales.php?id=$courseid&list=true&scale=$scale->id", "ratingscale", + link_to_popup_window ("/course/scales.php?id=$courseid&list=true&scale=$scale->id", "ratingscale", $linkobject, 400, 500, $scale->name); } @@ -1960,7 +1986,7 @@ function error ($message, $link="") { print_header(get_string("error")); echo "
"; print_simple_box($message, "center", "", "#FFBBBB"); - + if (!$link) { if ( !empty($SESSION->fromurl) ) { $link = "$SESSION->fromurl"; @@ -1979,7 +2005,7 @@ function helpbutton ($page, $title="", $module="moodle", $image=true, $linktext= // $title = the title of links, rollover tips, alt tags etc // $module = which module is the page defined in // $image = use a help image for the link? (true/false/"both") - // $text = if defined then this text is used in the page, and + // $text = if defined then this text is used in the page, and // the $page variable is ignored. global $CFG, $THEME; @@ -2015,8 +2041,8 @@ function emoticonhelpbutton($form, $field) { $SESSION->inserttextfield = $field; helpbutton("emoticons", get_string("helpemoticons"), "moodle", false, true); echo " "; - link_to_popup_window ("/help.php?module=moodle&file=emoticons.html", "popup", - "pixpath/s/smiley.gif\" border=\"0\" align=\"absmiddle\" width=\"15\" height=\"15\" />", + link_to_popup_window ("/help.php?module=moodle&file=emoticons.html", "popup", + "pixpath/s/smiley.gif\" border=\"0\" align=\"absmiddle\" width=\"15\" height=\"15\" />", 400, 500, get_string("helpemoticons")); echo "
"; } @@ -2059,7 +2085,7 @@ function redirect($url, $message="", $delay="0") { echo ""; echo ""; // To cope with Mozilla bug } else { - if (empty($delay)) { + if (empty($delay)) { $delay = 3; // There's no point having a message with no delay } print_header("", "", "", "", ""); @@ -2071,7 +2097,7 @@ function redirect($url, $message="", $delay="0") { sleep($delay); echo ""; // To cope with Mozilla bug } - die; + die; } function notify ($message, $color="red", $align="center") { @@ -2132,7 +2158,7 @@ function obfuscate_mailto($email, $label="", $dimmed=false) { $title = ''; $dimmed = ''; } - return sprintf("%s", + return sprintf("%s", obfuscate_text('mailto'), obfuscate_email($email), obfuscate_text($label)); } @@ -2184,7 +2210,7 @@ function print_paging_bar($totalcount, $page, $perpage, $baseurl) { //This function is used to rebuild the tag because some formats (PLAIN and WIKI) //will transform it to html entities function rebuildnolinktag($text) { - + $text = preg_replace('/<(\/*nolink)>/i','<$1>',$text); return $text;