From: samhemelryk Date: Fri, 22 May 2009 03:26:07 +0000 (+0000) Subject: weblib.php MDL-19236 added phpdocs and copyrights X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=449611af98bb041f301c97d31714367eb9bea51f;p=moodle.git weblib.php MDL-19236 added phpdocs and copyrights --- diff --git a/lib/weblib.php b/lib/weblib.php index 2217fcb3a0..da22780081 100644 --- a/lib/weblib.php +++ b/lib/weblib.php @@ -1,27 +1,19 @@ -. /** * Library of functions for web output @@ -32,9 +24,9 @@ * Other main libraries: * - datalib.php - functions that access the database. * - moodlelib.php - general-purpose Moodle functions. - * @author Martin Dougiamas - * @version $Id$ - * @license http://www.gnu.org/copyleft/gpl.html GNU Public License + * + * @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com} + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @package moodlecore */ @@ -85,6 +77,7 @@ define('REQUIREJS_AFTERHEADER', 2); /** * Allowed tags - string of html tags that can be tested against for safe html tags * @global string $ALLOWED_TAGS + * @name $ALLOWED_TAGS */ global $ALLOWED_TAGS; $ALLOWED_TAGS = @@ -93,6 +86,7 @@ $ALLOWED_TAGS = /** * Allowed protocols - array of protocols that are safe to use in links and so on * @global string $ALLOWED_PROTOCOLS + * @name $ALLOWED_PROTOCOLS */ $ALLOWED_PROTOCOLS = array('http', 'https', 'ftp', 'news', 'mailto', 'rtsp', 'teamspeak', 'gopher', 'mms', 'color', 'callto', 'cursor', 'text-align', 'font-size', 'font-weight', 'font-style', 'font-family', @@ -107,6 +101,8 @@ $ALLOWED_PROTOCOLS = array('http', 'https', 'ftp', 'news', 'mailto', 'rtsp', 'te * Returns $var with HTML characters (like "<", ">", etc.) properly quoted. * This function is very similar to {@link p()} * + * @todo Remove obsolete param $obsolete if not used anywhere + * * @param string $var the string potentially containing HTML characters * @param boolean $obsolete no longer used. * @return string @@ -124,7 +120,10 @@ function s($var, $obsolete = false) { * Add quotes to HTML characters * * Prints $var with HTML characters (like "<", ">", etc.) properly quoted. - * This function is very similar to {@link s()} + * This function simply calls {@link s()} + * @see s() + * + * @todo Remove obsolete param $obsolete if not used anywhere * * @param string $var the string potentially containing HTML characters * @param boolean $obsolete no longer used. @@ -136,10 +135,10 @@ function p($var, $obsolete = false) { /** * Does proper javascript quoting. + * * Do not use addslashes anymore, because it does not work when magic_quotes_sybase is enabled. * - * @since 1.8 - 22/02/2007 - * @param mixed value + * @param mixed $var String, Array, or Object to add slashes to * @return mixed quoted result */ function addslashes_js($var) { @@ -165,7 +164,7 @@ function addslashes_js($var) { * Takes in a URL and returns it without the querystring portion * * @param string $url the url which may have a query string attached - * @return string + * @return string The remaining URL */ function strip_querystring($url) { @@ -178,8 +177,10 @@ function addslashes_js($var) { /** * Returns the URL of the HTTP_REFERER, less the querystring portion if required + * + * @uses $_SERVER * @param boolean $stripquery if true, also removes the query part of the url. - * @return string + * @return string The resulting referer or emtpy string */ function get_referer($stripquery=true) { if (isset($_SERVER['HTTP_REFERER'])) { @@ -196,12 +197,14 @@ function get_referer($stripquery=true) { /** * Returns the name of the current script, WITH the querystring portion. - * this function is necessary because PHP_SELF and REQUEST_URI and SCRIPT_NAME + * + * 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.) * NOTE: This function returns false if the global variables needed are not set. * - * @return string + * @global string + * @return mixed String, or false if the global variables needed are not set */ function me() { global $ME; @@ -209,9 +212,18 @@ function get_referer($stripquery=true) { } /** + * Returns the name of the current script, WITH the full URL. + * + * 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. + * NOTE: This function returns false if the global variables needed are not set. + * * Like {@link me()} but returns a full URL * @see me() - * @return string + * + * @global string + * @return mixed String, or false if the global variables needed are not set */ function qualified_me() { global $FULLME; @@ -221,9 +233,31 @@ function qualified_me() { /** * Class for creating and manipulating urls. * - * See short write up here http://docs.moodle.org/en/Development:lib/weblib.php_moodle_url + * It can be used in moodle pages where config.php has been included without any further includes. + * + * It is useful for manipulating urls with long lists of params. + * One situation where it will be useful is a page which links to itself to perfrom various actions + * and / or to process form data. A moodle_url object : + * can be created for a page to refer to itself with all the proper get params being passed from page call to + * page call and methods can be used to output a url including all the params, optionally adding and overriding + * params and can also be used to + * - output the url without any get params + * - and output the params as hidden fields to be output within a form + * + * One important usage note is that data passed to methods out, out_action, get_query_string and + * hidden_params_out affect what is returned by the function and do not change the data stored in the object. + * This is to help with typical usage of these objects where one object is used to output urls + * in many places in a page. + * + * @link http://docs.moodle.org/en/Development:lib/weblib.php_moodle_url See short write up here + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * @package moodlecore */ class moodle_url { + /** + * @var string + * @access protected + */ protected $scheme = ''; // e.g. http protected $host = ''; protected $port = ''; @@ -231,11 +265,17 @@ class moodle_url { protected $pass = ''; protected $path = ''; protected $fragment = ''; + /** + * @var array + * @access protected + */ protected $params = array(); // Associative array of query string params /** - * Pass no arguments to create a url that refers to this page. Use empty string to create empty url. + * Pass no arguments to create a url that refers to this page. + * Use empty string to create empty url. * + * @global string * @param mixed $url a number of different forms are accespted: * null - create a URL that is the same as the URL used to load this page, but with no query string * '' - and empty URL @@ -281,11 +321,12 @@ class moodle_url { } /** - * Add an array of params to the params for this page. The added params override existing ones if they - * have the same name. + * Add an array of params to the params for this page. + * + * The added params override existing ones if they have the same name. * * @param array $params Defaults to null. If null then return value of param 'name'. - * @return array params for url. + * @return array Array of Params for url. */ public function params($params = null) { if (!is_null($params)) { @@ -296,8 +337,10 @@ class moodle_url { } /** - * Remove all params if no arguments passed. Remove selected params if - * arguments are passed. Can be called as either remove_params('param1', 'param2') + * Remove all params if no arguments passed. + * Remove selected params if arguments are passed. + * + * Can be called as either remove_params('param1', 'param2') * or remove_params(array('param1', 'param2')). * * @param mixed $params either an array of param names, or a string param name, @@ -319,11 +362,13 @@ class moodle_url { } /** - * Add a param to the params for this page. The added param overrides existing one if they - * have the same name. + * Add a param to the params for this page. + * + * The added param overrides existing one if theyhave the same name. * * @param string $paramname name - * @param string $param value. Defaults to null. If null then return value of param 'name' + * @param string $param Param value. Defaults to null. If null then return value of param 'name' + * @return void|string If $param was null then the value of $paramname was returned */ public function param($paramname, $param = null) { if (!is_null($param)) { @@ -335,6 +380,7 @@ class moodle_url { /** * Get the params as as a query string. + * * @param array $overrideparams params to add to the output params, these * override existing ones with the same name. * @return string query string that can be added to a url. @@ -351,7 +397,7 @@ class moodle_url { /** * Outputs params as hidden form elements. * - * @param array $exclude params to ignore + * @param array $exclude params to ignore * @param integer $indent indentation * @param array $overrideparams params to add to the output params, these * override existing ones with the same name. @@ -375,7 +421,7 @@ class moodle_url { * * @param boolean $omitquerystring whether to output page params as a query string in the url. * @param array $overrideparams params to add to the output url, these override existing ones with the same name. - * @return string url + * @return string Resulting URL */ public function out($omitquerystring = false, $overrideparams = array()) { $uri = $this->scheme ? $this->scheme.':'.((strtolower($this->scheme) == 'mailto') ? '':'//'): ''; @@ -396,7 +442,10 @@ class moodle_url { /** * Output action url with sesskey * - * @param boolean $noquerystring whether to output page params as a query string in the url. + * Adds sesskey and overriderparams then calls {@link out()} + * @see out() + * + * @param array $overrideparams Allows you to override params * @return string url */ public function out_action($overrideparams = array()) { @@ -415,6 +464,7 @@ class moodle_url { * * Checks that submitted POST data exists and returns it as object. * + * @uses $_POST * @return mixed false or object */ function data_submitted() { @@ -476,11 +526,14 @@ function break_up_long_words($string, $maxsize=20, $cutchar=' ') { /** * This function will print a button/link/etc. form element * that will work on both Javascript and non-javascript browsers. - * Relies on the Javascript function openpopup in javascript.php * + * Relies on the Javascript function openpopup in javascript.php * All parameters default to null, only $type and $url are mandatory. * * $url must be relative to home page eg /mod/survey/stuff.php + * + * @global object + * @param string $type Can be 'button' or 'link' * @param string $url Web link. Either relative to $CFG->wwwroot, or a full URL. * @param string $name Name to be assigned to the popup window (this is used by * client-side scripts to "talk" to the popup window) @@ -489,11 +542,10 @@ function break_up_long_words($string, $maxsize=20, $cutchar=' ') { * @param int $width Height to assign to popup window * @param string $title Text to be displayed as popup page title * @param string $options List of additional options for popup window - * @param string $return If true, return as a string, otherwise print + * @param bool $return If true, return as a string, otherwise print * @param string $id id added to the element * @param string $class class added to the element * @return string - * @uses $CFG */ function element_to_popup_window ($type=null, $url=null, $name=null, $linkname=null, $height=400, $width=500, $title=null, @@ -573,8 +625,21 @@ function element_to_popup_window ($type=null, $url=null, $name=null, $linkname=n /** * Creates and displays (or returns) a link to a popup window, using element_to_popup_window function. * - * @return string html code to display a link to a popup window. + * Simply calls {@link element_to_popup_window()} with type set to 'link' * @see element_to_popup_window() + * + * @param string $url Web link. Either relative to $CFG->wwwroot, or a full URL. + * @param string $name Name to be assigned to the popup window (this is used by + * client-side scripts to "talk" to the popup window) + * @param string $linkname Text to be displayed as web link + * @param int $height Height to assign to popup window + * @param int $width Height to assign to popup window + * @param string $title Text to be displayed as popup page title + * @param string $options List of additional options for popup window + * @param bool $return If true, return as a string, otherwise print + * @param string $id id added to the element + * @param string $class class added to the element + * @return string html code to display a link to a popup window. */ function link_to_popup_window ($url, $name=null, $linkname=null, $height=400, $width=500, $title=null, @@ -586,8 +651,21 @@ function link_to_popup_window ($url, $name=null, $linkname=null, /** * Creates and displays (or returns) a buttons to a popup window, using element_to_popup_window function. * - * @return string html code to display a button to a popup window. + * Simply calls {@link element_to_popup_window()} with type set to 'button' * @see element_to_popup_window() + * + * @param string $url Web link. Either relative to $CFG->wwwroot, or a full URL. + * @param string $name Name to be assigned to the popup window (this is used by + * client-side scripts to "talk" to the popup window) + * @param string $linkname Text to be displayed as web link + * @param int $height Height to assign to popup window + * @param int $width Height to assign to popup window + * @param string $title Text to be displayed as popup page title + * @param string $options List of additional options for popup window + * @param bool $return If true, return as a string, otherwise print + * @param string $id id added to the element + * @param string $class class added to the element + * @return string html code to display a link to a popup window. */ function button_to_popup_window ($url, $name=null, $linkname=null, $height=400, $width=500, $title=null, $options=null, $return=false, @@ -599,11 +677,13 @@ function button_to_popup_window ($url, $name=null, $linkname=null, /** * Prints a simple button to close a window - * @param string $name name of the window to close + * + * @global object + * @param string $name Name of the window to close * @param boolean $return whether this function should return a string or output it. * @param boolean $reloadopener if true, clicking the button will also reload * the page that opend this popup window. - * @return string if $return is true, nothing otherwise + * @return string|void if $return is true, void otherwise */ function close_window_button($name='closewindow', $return=false, $reloadopener = false) { global $CFG; @@ -630,6 +710,11 @@ function close_window_button($name='closewindow', $return=false, $reloadopener = /* * Try and close the current window using JavaScript, either immediately, or after a delay. + * + * Echo's out the resulting XHTML & javascript + * + * @global object + * @global object * @param integer $delay a delay in seconds before closing the window. Default 0. * @param boolean $reloadopener if true, we will see if this window was a pop-up, and try * to reload the parent window before this one closes. @@ -657,6 +742,7 @@ function close_window($delay = 0, $reloadopener = false) { /** * Given an array of values, output the HTML for a select element with those options. + * * Normally, you only need to use the first few parameters. * * @param array $options The options to offer. An array of the form @@ -665,7 +751,7 @@ function close_window($delay = 0, $reloadopener = false) { * @param string $selected the option to select initially, default none. * @param string $nothing The label for the 'nothing is selected' option. Defaults to get_string('choose'). * Set this to '' if you don't want a 'nothing is selected' option. - * @param string $script in not '', then this is added to the <select> element as an onchange handler. + * @param string $script if not '', then this is added to the <select> element as an onchange handler. * @param string $nothingvalue The value corresponding to the $nothing option. Defaults to 0. * @param boolean $return if false (the default) the the output is printed directly, If true, the * generated HTML is returned as a string. @@ -680,6 +766,7 @@ function close_window($delay = 0, $reloadopener = false) { * when $listbox display is enabled * @param string $class value to use for the class attribute of the <select> element. If none is given, * then a suitable one is constructed. + * @return string|void If $return=true returns string, else echo's and returns void */ function choose_from_menu ($options, $name, $selected='', $nothing='choose', $script='', $nothingvalue='0', $return=false, $disabled=false, $tabindex=0, @@ -764,12 +851,17 @@ function choose_from_menu ($options, $name, $selected='', $nothing='choose', $sc /** * Choose value 0 or 1 from a menu with options 'No' and 'Yes'. * Other options like choose_from_menu. - * @param string $name - * @param string $selected - * @param string $string (defaults to '') - * @param boolean $return whether this function should return a string or output it (defaults to false) + * + * Calls {@link choose_from_menu()} with preset arguments + * @see choose_from_menu() + * + * @param string $name the name of this form control, as in <select name="..." ... + * @param string $selected the option to select initially, default none. + * @param string $script if not '', then this is added to the <select> element as an onchange handler. + * @param boolean $return Whether this function should return a string or output it (defaults to false) * @param boolean $disabled (defaults to false) * @param int $tabindex + * @return string|void If $return=true returns string, else echo's and returns void */ function choose_from_menu_yesno($name, $selected, $script = '', $return = false, $disabled = false, $tabindex = 0) { @@ -780,6 +872,25 @@ function choose_from_menu_yesno($name, $selected, $script = '', /** * Just like choose_from_menu, but takes a nested array (2 levels) and makes a dropdown menu * including option headings with the first level. + * + * This function is very similar to {@link choose_from_menu_yesno()} + * and {@link choose_from_menu()} + * + * @todo Add datatype handling to make sure $options is an array + * + * @param array $options An array of objects to choose from + * @param string $name The XHTML field name + * @param string $selected The value to select by default + * @param string $nothing The label for the 'nothing is selected' option. + * Defaults to get_string('choose'). + * @param string $script If not '', then this is added to the <select> element + * as an onchange handler. + * @param string $nothingvalue The value for the first `nothing` option if $nothing is set + * @param bool $return Whether this function should return a string or output + * it (defaults to false) + * @param bool $disabled Is the field disabled by default + * @param int|string $tabindex Override the tabindex attribute [numeric] + * @return string|void If $return=true returns string, else echo's and returns void */ function choose_from_menu_nested($options,$name,$selected='',$nothing='choose',$script = '', $nothingvalue=0,$return=false,$disabled=false,$tabindex=0) { @@ -836,9 +947,13 @@ function choose_from_menu_nested($options,$name,$selected='',$nothing='choose',$ /** * Given an array of values, creates a group of radio buttons to be part of a form * + * @staticvar int $idcounter * @param array $options An array of value-label pairs for the radio group (values as keys) * @param string $name Name of the radiogroup (unique in the form) * @param string $checked The value that is already checked + * @param bool $return Whether this function should return a string or output + * it (defaults to false) + * @return string|void If $return=true returns string, else echo's and returns void */ function choose_from_radio ($options, $name, $checked='', $return=false) { @@ -877,13 +992,20 @@ function choose_from_radio ($options, $name, $checked='', $return=false) { } } -/** Display an standard html checkbox with an optional label +/** + * Display an standard html checkbox with an optional label * - * @param string $name The name of the checkbox - * @param string $value The valus that the checkbox will pass when checked - * @param boolean $checked The flag to tell the checkbox initial state - * @param string $label The label to be showed near the checkbox - * @param string $alt The info to be inserted in the alt tag + * @staticvar int $idcounter + * @param string $name The name of the checkbox + * @param string $value The valus that the checkbox will pass when checked + * @param bool $checked The flag to tell the checkbox initial state + * @param string $label The label to be showed near the checkbox + * @param string $alt The info to be inserted in the alt tag + * @param string $script If not '', then this is added to the checkbox element + * as an onchange handler. + * @param bool $return Whether this function should return a string or output + * it (defaults to false) + * @return string|void If $return=true returns string, else echo's and returns void */ function print_checkbox ($name, $value, $checked = true, $label = '', $alt = '', $script='',$return=false) { @@ -921,12 +1043,17 @@ function print_checkbox ($name, $value, $checked = true, $label = '', $alt = '', } -/** Display an standard html text field with an optional label +/** + * Display an standard html text field with an optional label * - * @param string $name The name of the text field - * @param string $value The value of the text field - * @param string $label The label to be showed near the text field - * @param string $alt The info to be inserted in the alt tag + * @param string $name The name of the text field + * @param string $value The value of the text field + * @param string $alt The info to be inserted in the alt tag + * @param int $size Sets the size attribute of the field. Defaults to 50 + * @param int $maxlength Sets the maxlength attribute of the field. Not set by default + * @param bool $return Whether this function should return a string or output + * it (defaults to false) + * @return string|void If $return=true returns string, else echo's and returns void */ function print_textfield ($name, $value, $alt = '',$size=50,$maxlength=0, $return=false) { @@ -960,11 +1087,16 @@ function print_textfield ($name, $value, $alt = '',$size=50,$maxlength=0, $retur /** - * Implements a complete little form with a dropdown menu. When JavaScript is on - * selecting an option from the dropdown automatically submits the form (while - * avoiding the usual acessibility problems with this appoach). With JavaScript - * off, a 'Go' button is printed. + * Implements a complete little form with a dropdown menu. + * + * When JavaScript is on selecting an option from the dropdown automatically + * submits the form (while avoiding the usual acessibility problems with this appoach). + * With JavaScript off, a 'Go' button is printed. * + * @todo Finish documenting this function + * + * @global object + * @global object * @param string $baseurl The target URL up to the point of the variable that changes * @param array $options A list of value-label pairs for the popup list * @param string $formid id for the control. Must be unique on the page. Used in the HTML. @@ -980,8 +1112,7 @@ function print_textfield ($name, $value, $alt = '',$size=50,$maxlength=0, $retur * @param string $submitvalue Optional label for the 'Go' button. Defaults to get_string('go'). * @param boolean $disabled If true, the menu will be displayed disabled. * @param boolean $showbutton If true, the button will always be shown even if JavaScript is available - * @return string If $return is true then the entire form is returned as a string. - * @todo Finish documenting this function
+ * @return string|void If $return=true returns string, else echo's and returns void */ function popup_form($baseurl, $options, $formid, $selected='', $nothing='choose', $help='', $helptext='', $return=false, $targetwindow='self', $selectlabel='', $optionsextra=NULL, $submitvalue='', $disabled=false, $showbutton=false) { @@ -1152,7 +1283,7 @@ function popup_form($baseurl, $options, $formid, $selected='', $nothing='choose' /** - * Prints some red text + * Prints some red text using echo * * @param string $error The text to be displayed in red */ @@ -1183,6 +1314,9 @@ function validate_email($address) { * Extracts file argument either from file parameter or PATH_INFO * Note: $scriptname parameter is not needed anymore * + * @global string + * @uses $_SERVER + * @uses PARAM_PATH * @return string file path (only safe characters) */ function get_file_argument() { @@ -1227,19 +1361,25 @@ function format_text_menu() { * This function should mainly be used for long strings like posts, * answers, glossary items etc. For short strings @see format_string(). * - * @uses $CFG + * @todo Finish documenting this function + * + * @global object + * @global object + * @global object + * @global object * @uses FORMAT_MOODLE * @uses FORMAT_HTML * @uses FORMAT_PLAIN * @uses FORMAT_WIKI * @uses FORMAT_MARKDOWN + * @uses CLI_SCRIPT + * @staticvar array $croncache * @param string $text The text to be formatted. This is raw text originally from user input. * @param int $format Identifier of the text format to be used - * (FORMAT_MOODLE, FORMAT_HTML, FORMAT_PLAIN, FORMAT_WIKI, FORMAT_MARKDOWN) - * @param array $options ? - * @param int $courseid ? + * [FORMAT_MOODLE, FORMAT_HTML, FORMAT_PLAIN, FORMAT_WIKI, FORMAT_MARKDOWN] + * @param object $options ? + * @param int $courseid The courseid to use, defaults to $COURSE->courseid * @return string - * @todo Finish documenting this function */ function format_text($text, $format=FORMAT_MOODLE, $options=NULL, $courseid=NULL) { global $CFG, $COURSE, $DB, $PAGE; @@ -1413,12 +1553,18 @@ function format_text($text, $format=FORMAT_MOODLE, $options=NULL, $courseid=NULL return $text; } -/** Converts the text format from the value to the 'internal' - * name or vice versa. $key can either be the value or the name - * and you get the other back. +/** + * Converts the text format from the value to the 'internal' + * name or vice versa. * - * @param mixed int 0-4 or string one of 'moodle','html','plain','markdown' - * @return mixed as above but the other way around! + * $key can either be the value or the name and you get the other back. + * + * @uses FORMAT_MOODLE + * @uses FORMAT_HTML + * @uses FORMAT_PLAIN + * @uses FORMAT_MARKDOWN + * @param mixed $key int 0-4 or string one of 'moodle','html','plain','markdown' + * @return mixed as above but the other way around! */ function text_format_name( $key ) { $lookup = array(); @@ -1441,6 +1587,9 @@ function text_format_name( $key ) { /** * Resets all data related to filters, called during upgrade or when filter settings change. + * + * @global object + * @global object * @return void */ function reset_text_filters_cache() { @@ -1451,17 +1600,23 @@ function reset_text_filters_cache() { remove_dir($purifdir, true); } -/** Given a simple string, this function returns the string - * processed by enabled string filters if $CFG->filterall is enabled +/** + * Given a simple string, this function returns the string + * processed by enabled string filters if $CFG->filterall is enabled * - * This function should be used to print short strings (non html) that - * need filter processing e.g. activity titles, post subjects, - * glossary concepts. + * This function should be used to print short strings (non html) that + * need filter processing e.g. activity titles, post subjects, + * glossary concepts. * - * @param string $string The string to be filtered. - * @param boolean $striplinks To strip any link in the result text (Moodle 1.8 default changed from false to true! MDL-8713) - * @param int $courseid Current course as filters can, potentially, use it - * @return string + * @global object + * @global object + * @global object + * @staticvar bool $strcache + * @param string $string The string to be filtered. + * @param boolean $striplinks To strip any link in the result text. + Moodle 1.8 default changed from false to true! MDL-8713 + * @param int $courseid Current course as filters can, potentially, use it + * @return string */ function format_string($string, $striplinks=true, $courseid=NULL ) { global $CFG, $COURSE, $PAGE; @@ -1523,7 +1678,7 @@ function format_string($string, $striplinks=true, $courseid=NULL ) { * @uses FORMAT_MARKDOWN * @param string $text The text to be formatted. This is raw text originally from user input. * @param int $format Identifier of the text format to be used - * (FORMAT_MOODLE, FORMAT_HTML, FORMAT_PLAIN, FORMAT_WIKI, FORMAT_MARKDOWN) + * [FORMAT_MOODLE, FORMAT_HTML, FORMAT_PLAIN, FORMAT_WIKI, FORMAT_MARKDOWN] * @return string */ function format_text_email($text, $format) { @@ -1559,6 +1714,9 @@ function format_text_email($text, $format) { * Given some text in HTML format, this function will pass it * through any filters that have been configured for this context. * + * @global object + * @global object + * @global object * @param string $text The text to be passed through format filters * @param int $courseid The current course. * @return string the filtered string. @@ -1576,6 +1734,9 @@ function filter_text($text, $courseid=NULL) { } /** * Formats activity intro text + * + * @global object + * @uses CONTEXT_MODULE * @param string $module name of module * @param object $activity instance of activity * @param int $cmid course module id @@ -1593,6 +1754,8 @@ function format_module_intro($module, $activity, $cmid, $filter=true) { /** * Legacy function, used for cleaning of old forum and glossary text only. + * + * @global object * @param string $text text that may contain TRUSTTEXT marker * @return text without any TRUSTTEXT marker */ @@ -1612,6 +1775,7 @@ function trusttext_strip($text) { * Must be called before editing of all texts * with trust flag. Removes all XSS nasties * from texts stored in database if needed. + * * @param object $object data object with xxx, xxxformat and xxxtrust fields * @param string $field name of text field * @param object $context active context @@ -1629,9 +1793,11 @@ function trusttext_pre_edit($object, $field, $context) { } /** - * Is urrent user trusted to enter no dangerous XSS in this context? + * Is current user trusted to enter no dangerous XSS in this context? + * * Please note the user must be in fact trusted everywhere on this server!! - * @param $context + * + * @param object $context * @return bool true if user trusted */ function trusttext_trusted($context) { @@ -1640,7 +1806,9 @@ function trusttext_trusted($context) { /** * Is trusttext feature active? - * @param $context + * + * @global object + * @param object $context * @return bool */ function trusttext_active() { @@ -1655,10 +1823,11 @@ function trusttext_active() { * * @uses FORMAT_MOODLE * @uses FORMAT_PLAIN - * @uses ALLOWED_TAGS + * @global string + * @global object * @param string $text The text to be cleaned * @param int $format Identifier of the text format to be used - * (FORMAT_MOODLE, FORMAT_HTML, FORMAT_PLAIN, FORMAT_WIKI, FORMAT_MARKDOWN) + * [FORMAT_MOODLE, FORMAT_HTML, FORMAT_PLAIN, FORMAT_WIKI, FORMAT_MARKDOWN] * @return string The cleaned up text */ function clean_text($text, $format=FORMAT_MOODLE) { @@ -1704,6 +1873,9 @@ function clean_text($text, $format=FORMAT_MOODLE) { /** * KSES replacement cleaning function - uses HTML Purifier. + * + * @global object + * @param string $text The (X)HTML string to purify */ function purify_html($text) { global $CFG; @@ -1730,9 +1902,9 @@ function purify_html($text) { /** * This function takes a string and examines it for HTML tags. + * * If tags are detected it passes the string to a helper function {@link cleanAttributes2()} - * which checks for attributes and filters them for malicious content - * 17/08/2004 :: Eamon DOT Costello AT dcu DOT ie + * which checks for attributes and filters them for malicious content * * @param string $str The string to be examined for html tags * @return string @@ -1749,9 +1921,11 @@ function cleanAttributes($str){ /** * This function takes a string with an html tag and strips out any unallowed * protocols e.g. javascript: + * * It calls ancillary functions in kses which are prefixed by kses -* 17/08/2004 :: Eamon DOT Costello AT dcu DOT ie * + * @global object + * @global string * @param array $htmlArray An array from {@link cleanAttributes()}, containing in its 1st * element the html to be cleared * @return string @@ -1811,7 +1985,10 @@ function cleanAttributes2($htmlArray){ /** * Replaces all known smileys in the text with image equivalents * - * @uses $CFG + * @global object + * @staticvar array $e + * @staticvar array $img + * @staticvar array $emoticons * @param string $text Passed by reference. The string to search for smily strings. * @return string */ @@ -1881,6 +2058,8 @@ function replace_smilies(&$text) { * This code is called from help.php to inject a list of smilies into the * emoticons help file. * + * @global object + * @global object * @return string HTML for a list of smilies. */ function get_emoticons_list_for_help_file(){ @@ -1915,7 +2094,7 @@ function get_emoticons_list_for_help_file(){ * Given plain text, makes it into HTML as nicely as possible. * May contain HTML tags already * - * @uses $CFG + * @global object * @param string $text The string to convert. * @param boolean $smiley Convert any smiley characters to smiley images? * @param boolean $para If true then the returned string will be wrapped in paragraph tags @@ -1958,7 +2137,7 @@ function text_to_html($text, $smiley=true, $para=true, $newlines=true) { /** * Given Markdown formatted text, make it into XHTML using external function * - * @uses $CFG + * @global object * @param string $text The markdown formatted text to be converted. * @return string Converted text */ @@ -1973,7 +2152,7 @@ function markdown_to_html($text) { /** * Given HTML text, make it into plain text using external function * - * @uses $CFG + * @global object * @param string $html The text to be converted. * @return string */ @@ -2006,6 +2185,7 @@ function convert_urls_into_links(&$text) { /** * This function will highlight search words in a given string + * * It cares about HTML and will not ruin links. It's best to use * this function after performing any conversions to HTML. * @@ -2067,12 +2247,13 @@ function highlight($needle, $haystack, $matchcase = false, /** * This function will highlight instances of $needle in $haystack - * It's faster that the above function and doesn't care about + * + * It's faster that the above function {@link highlight()} and doesn't care about * HTML or anything. * * @param string $needle The string to search for * @param string $haystack The string to search for $needle in - * @return string + * @return string The highlighted HTML */ function highlightfast($needle, $haystack) { @@ -2102,8 +2283,9 @@ function highlightfast($needle, $haystack) { /** * Return a string containing 'lang', xml:lang and optionally 'dir' HTML attributes. * Internationalisation, for print_header and backup/restorelib. - * @param $dir Default false. - * @return string Attributes. + * + * @param bool $dir Default false + * @return string Attributes */ function get_html_lang($dir = false) { $direction = ''; @@ -2122,8 +2304,10 @@ function get_html_lang($dir = false) { /** * Return the markup for the destination of the 'Skip to main content' links. - * Accessibility improvement for keyboard-only users. - * Used in course formats, /index.php and /course/index.php + * Accessibility improvement for keyboard-only users. + * + * Used in course formats, /index.php and /course/index.php + * * @return string HTML element. */ function skip_main_destination() { @@ -2136,12 +2320,18 @@ function skip_main_destination() { /** * Print a standard header * - * @uses $USER - * @uses $CFG - * @uses $SESSION + * @global object + * @global object + * @global object + * @global object + * @global string Doesnt appear to be used here + * @global string Doesnt appear to be used here + * @global object + * @global object + * @uses $_SERVER * @param string $title Appears at the top of the window * @param string $heading Appears at the top of the page - * @param array $navigation Array of $navlinks arrays (keys: name, link, type) for use as breadcrumbs links + * @param string $navigation Array of $navlinks arrays (keys: name, link, type) for use as breadcrumbs links * @param string $focus Indicates form element to get cursor focus on load eg inputform.password * @param string $meta Meta tags to be added to the header * @param boolean $cache Should this page be cacheable? @@ -2150,6 +2340,7 @@ function skip_main_destination() { * @param boolean $usexml use XML for this page * @param string $bodytags This text will be included verbatim in the tag (useful for onload() etc) * @param bool $return If true, return the visible elements of the header instead of echoing them. + * @return string|void If return=true then string else void */ function print_header ($title='', $heading='', $navigation='', $focus='', $meta='', $cache=true, $button=' ', $menu='', @@ -2407,6 +2598,13 @@ function print_header ($title='', $heading='', $navigation='', $focus='', * $extracthtml = 2: this is used after printing the header and handles any * require_js calls that occurred within the header itself. * + * @global object + * @staticvar array $loadlib + * @staticvar int $state Defaults to REQUIREJS_BEFOREHEADER + * @staticvar string $latecode + * @uses REQUIREJS_BEFOREHEADER + * @uses REQUIREJS_INHEADER + * @uses REQUIREJS_AFTERHEADER * @param mixed $lib The library or libraries to load (a string or array of strings) * There are three way to specify the library: * 1. a shorname like 'yui_yahoo'. The list of recognised values is in lib/ajax/ajaxlib.php @@ -2476,6 +2674,8 @@ function require_js($lib, $extracthtml = 0) { /** * Should not be called directly - use require_js. This function obtains the code * (script tags) needed to include JavaScript libraries. + * + * @global object * @param array $loadlibs Array of library files to include * @return string HTML code to include them */ @@ -2507,7 +2707,7 @@ function get_require_js_code($loadlibs) { * @param string $function the name of the JavaScript function to call. * @param array $args an optional list of arguments to the function call. * @param boolean $return if true, return the HTML code, otherwise output it. - * @return mixed string if $return is true, otherwise nothing. + * @return string|void string if $return is true, otherwise nothing. */ function print_js_call($function, $args = array(), $return = false) { $quotedargs = array(); @@ -2533,7 +2733,7 @@ function print_js_call($function, $args = array(), $return = false) { * @param string $function the name of the JavaScript function to call. * @param array $args an optional list of arguments to the function call. * @param boolean $return if true, return the HTML code, otherwise output it. - * @return mixed string if $return is true, otherwise nothing. + * @return string|void string if $return is true, otherwise nothing. */ function print_delayed_js_call($delay, $function, $args = array(), $return = false) { $quotedargs = array(); @@ -2553,6 +2753,8 @@ function print_delayed_js_call($delay, $function, $args = array(), $return = fal } /** + * Create a Javascript config object for use in code + * * Sometimes you need access to some values in your JavaScript that you can only * get from PHP code. You can handle this by generating your JS in PHP, but a * better idea is to write static javascrip code that reads some configuration @@ -2602,9 +2804,12 @@ function print_js_config($settings = array(), $prefix='', $return = false) { /** * This function generates the code that defines the standard moodle_cfg object. + * * This object has a number of fields that are values that various pieces of * JavaScript code need access too. For example $CFG->wwwroot and $CFG->pixpath. * + * @global object + * @uses DEBUG_DEVELOPER * @return string a "; + * + * @global object + * @global object + * @global object + * @global object + * @uses $_COOKIE + * @uses DEBUG_DEVELOPER + * @uses DEBUG_ALL + * @param string $url The url to take the user to + * @param string $message The text message to display to the user about the redirect, if any + * @param string $delay How long before refreshing to the new page at $url? + * @return void Dies */ function redirect($url, $message='', $delay=-1) { global $CFG, $THEME, $SESSION, $PAGE; @@ -6091,10 +6500,13 @@ function redirect($url, $message='', $delay=-1) { /** * Print a bold message in an optional color. * + * @global object + * @uses CLI_SCRIPT * @param string $message The message to print out * @param string $style Optional style to display message text in * @param string $align Alignment option * @param bool $return whether to return an output string or echo now + * @return string|bool Depending on $result */ function notify($message, $style='notifyproblem', $align='center', $return=false) { global $DB; @@ -6130,7 +6542,7 @@ function notify($message, $style='notifyproblem', $align='center', $return=false * Given an email address, this function will return an obfuscated version of it * * @param string $email The email address to obfuscate - * @return string + * @return string The obfuscated email address */ function obfuscate_email($email) { @@ -6153,7 +6565,7 @@ function notify($message, $style='notifyproblem', $align='center', $return=false * with HTML entity equivalents. Return string is obviously longer. * * @param string $plaintext The text to be obfuscated - * @return string + * @return string The obfuscated text */ function obfuscate_text($plaintext) { @@ -6185,7 +6597,7 @@ function obfuscate_text($plaintext) { * @param string $email The email address to display * @param string $label The text to dispalyed as hyperlink to $email * @param boolean $dimmed If true then use css class 'dimmed' for hyperlink - * @return string + * @return string The obfuscated mailto link */ function obfuscate_mailto($email, $label='', $dimmed=false) { @@ -6215,7 +6627,7 @@ function obfuscate_mailto($email, $label='', $dimmed=false) { * @param string $pagevar This is the variable name that you use for the page number in your code (ie. 'tablepage', 'blogpage', etc) * @param bool $nocurr do not display the current page as a link * @param bool $return whether to return an output string or echo now - * @return bool or string + * @return bool|string depending on $result */ function print_paging_bar($totalcount, $page, $perpage, $baseurl, $pagevar='page',$nocurr=false, $return=false) { $maxdisplay = 18; @@ -6309,6 +6721,9 @@ function rebuildnolinktag($text) { * Prints a nice side block with an optional header. The content can either * be a block of HTML or a list of text with optional icons. * + * @todo Finish documenting this function. Show example of various attributes, etc. + * + * @static int $block_id Increments for each call to the function * @param string $heading HTML for the heading. Can include full HTML or just * plain text - plain text will automatically be enclosed in the appropriate * heading tags. @@ -6320,7 +6735,7 @@ function rebuildnolinktag($text) { * outer div of this block. If there is a class attribute ' sideblock' gets appended to it. If there isn't * already a class, class='sideblock' is used. * @param string $title Plain text title, as embedded in the $heading. - * @todo Finish documenting this function. Show example of various attributes, etc. + * @return void Echo's output */ function print_side_block($heading='', $content='', $list=NULL, $icons=NULL, $footer='', $attributes = array(), $title='') { @@ -6376,11 +6791,15 @@ function print_side_block($heading='', $content='', $list=NULL, $icons=NULL, $fo /** * Starts a nice side block with an optional header. * + * @todo Finish documenting this function + * + * @global object + * @global object * @param string $heading HTML for the heading. Can include full HTML or just * plain text - plain text will automatically be enclosed in the appropriate * heading tags. - * @param array $attributes ? - * @todo Finish documenting this function + * @param array $attributes HTML attributes to apply if possible + * @return void Echo's output */ function print_side_block_start($heading='', $attributes = array()) { @@ -6458,6 +6877,12 @@ function print_side_block_start($heading='', $attributes = array()) { /** * Print table ending tags for a side block box. + * + * @global object + * @global object + * @param array $attributes HTML attributes to apply if possible [id] + * @param string $title + * @return void Echo's output */ function print_side_block_end($attributes = array(), $title='') { global $CFG, $THEME; @@ -6482,7 +6907,10 @@ function print_side_block_end($attributes = array(), $title='') { } /** + * @todo Remove this deprecated function when no longer used * @deprecated since Moodle 2.0 - use $PAGE->pagetype instead of the . + * + * @global object * @param string $getid used to return $PAGE->pagetype. * @param string $getclass used to return $PAGE->legacyclass. */ @@ -6495,6 +6923,10 @@ function page_id_and_class(&$getid, &$getclass) { /** * Prints a maintenance message from /maintenance.html + * + * @global object + * @global object + * @return void */ function print_maintenance_message () { global $CFG, $SITE; @@ -6510,6 +6942,10 @@ function print_maintenance_message () { /** * Adjust the list of allowed tags based on $CFG->allowobjectembed and user roles (admin) + * + * @global object + * @global string + * @return void */ function adjust_allowed_tags() { @@ -6520,16 +6956,33 @@ function adjust_allowed_tags() { } } -/// Some code to print tabs - -/// A class for tabs +/** + * A class for tabs, Some code to print tabs + * + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * @package moodlecore + */ class tabobject { + /** + * @var string + */ var $id; var $link; var $text; + /** + * @var bool + */ var $linkedwhenselected; - /// A constructor just because I like constructors + /** + * A constructor just because I like constructors + * + * @param string $id + * @param string $link + * @param string $text + * @param string $title + * @param bool $linkedwhenselected + */ function tabobject ($id, $link='', $text='', $title='', $linkedwhenselected=false) { $this->id = $id; $this->link = $link; @@ -6544,11 +6997,13 @@ class tabobject { /** * Returns a string containing a nested list, suitable for formatting into tabs with CSS. * + * @global object * @param array $tabrows An array of rows where each row is an array of tab objects * @param string $selected The id of the selected tab (whatever row it's on) * @param array $inactive An array of ids of inactive tabs that are not selectable. * @param array $activated An array of ids of other tabs that are currently activated -**/ + * @param bool $return If true output is returned rather then echo'd + **/ function print_tabs($tabrows, $selected=NULL, $inactive=NULL, $activated=NULL, $return=false) { global $CFG; @@ -6581,7 +7036,13 @@ function print_tabs($tabrows, $selected=NULL, $inactive=NULL, $activated=NULL, $ echo $output; } - +/** + * Converts a nested array tree into HTML ul:li [recursive] + * + * @param array $tree A tree array to convert + * @param int $row Used in identifing the iteration level and in ul classes + * @return string HTML structure + */ function convert_tree_to_html($tree, $row=0) { $str = "\n".'\n"; @@ -7295,6 +7872,7 @@ class html_list_progress_trace extends moodle_progress_trace { /** * Return the authentication plugin title + * * @param string $authtype plugin type * @return string */ @@ -7306,5 +7884,4 @@ function auth_get_plugin_title ($authtype) { return $authtitle; } -// vim:autoindent:expandtab:shiftwidth=4:tabstop=4:tw=140: ?>