* $options = clean_param($options, PARAM_INT);
*
@@ -726,15 +737,17 @@ function validate_param($param, $type, $allownull=NULL_NOT_ALLOWED, $debuginfo='
* @param string $type expected format of param after cleaning.
* @param bool $recursive clean recursive arrays
* @return array
+ * @throws coding_exception
*/
function clean_param_array(array $param = null, $type, $recursive = false) {
- $param = (array)$param; // convert null to empty array
+ // Convert null to empty array.
+ $param = (array)$param;
foreach ($param as $key => $value) {
if (is_array($value)) {
if ($recursive) {
$param[$key] = clean_param_array($value, $type, true);
} else {
- throw new coding_exception('clean_param_array() can not process multidimensional arrays when $recursive is false.');
+ throw new coding_exception('clean_param_array can not process multidimensional arrays when $recursive is false.');
}
} else {
$param[$key] = clean_param($value, $type);
@@ -749,15 +762,15 @@ function clean_param_array(array $param = null, $type, $recursive = false) {
* an options field.
*
* $course->format = clean_param($course->format, PARAM_ALPHA);
- * $selectedgrade_item = clean_param($selectedgrade_item, PARAM_INT);
+ * $selectedgradeitem = clean_param($selectedgradeitem, PARAM_INT);
*
*
* @param mixed $param the variable we are cleaning
* @param string $type expected format of param after cleaning.
* @return mixed
+ * @throws coding_exception
*/
function clean_param($param, $type) {
-
global $CFG;
if (is_array($param)) {
@@ -771,49 +784,63 @@ function clean_param($param, $type) {
}
switch ($type) {
- case PARAM_RAW: // no cleaning at all
+ case PARAM_RAW:
+ // No cleaning at all.
$param = fix_utf8($param);
return $param;
- case PARAM_RAW_TRIMMED: // no cleaning, but strip leading and trailing whitespace.
+ case PARAM_RAW_TRIMMED:
+ // No cleaning, but strip leading and trailing whitespace.
$param = fix_utf8($param);
return trim($param);
- case PARAM_CLEAN: // General HTML cleaning, try to use more specific type if possible
- // this is deprecated!, please use more specific type instead
+ case PARAM_CLEAN:
+ // General HTML cleaning, try to use more specific type if possible this is deprecated!
+ // Please use more specific type instead.
if (is_numeric($param)) {
return $param;
}
$param = fix_utf8($param);
- return clean_text($param); // Sweep for scripts, etc
+ // Sweep for scripts, etc.
+ return clean_text($param);
- case PARAM_CLEANHTML: // clean html fragment
+ case PARAM_CLEANHTML:
+ // Clean html fragment.
$param = fix_utf8($param);
- $param = clean_text($param, FORMAT_HTML); // Sweep for scripts, etc
+ // Sweep for scripts, etc.
+ $param = clean_text($param, FORMAT_HTML);
return trim($param);
case PARAM_INT:
- return (int)$param; // Convert to integer
+ // Convert to integer.
+ return (int)$param;
case PARAM_FLOAT:
- return (float)$param; // Convert to float
+ // Convert to float.
+ return (float)$param;
- case PARAM_ALPHA: // Remove everything not a-z
+ case PARAM_ALPHA:
+ // Remove everything not `a-z`.
return preg_replace('/[^a-zA-Z]/i', '', $param);
- case PARAM_ALPHAEXT: // Remove everything not a-zA-Z_- (originally allowed "/" too)
+ case PARAM_ALPHAEXT:
+ // Remove everything not `a-zA-Z_-` (originally allowed "/" too).
return preg_replace('/[^a-zA-Z_-]/i', '', $param);
- case PARAM_ALPHANUM: // Remove everything not a-zA-Z0-9
+ case PARAM_ALPHANUM:
+ // Remove everything not `a-zA-Z0-9`.
return preg_replace('/[^A-Za-z0-9]/i', '', $param);
- case PARAM_ALPHANUMEXT: // Remove everything not a-zA-Z0-9_-
+ case PARAM_ALPHANUMEXT:
+ // Remove everything not `a-zA-Z0-9_-`.
return preg_replace('/[^A-Za-z0-9_-]/i', '', $param);
- case PARAM_SEQUENCE: // Remove everything not 0-9,
+ case PARAM_SEQUENCE:
+ // Remove everything not `0-9,`.
return preg_replace('/[^0-9,]/i', '', $param);
- case PARAM_BOOL: // Convert to 1 or 0
+ case PARAM_BOOL:
+ // Convert to 1 or 0.
$tempstr = strtolower($param);
if ($tempstr === 'on' or $tempstr === 'yes' or $tempstr === 'true') {
$param = 1;
@@ -824,18 +851,19 @@ function clean_param($param, $type) {
}
return $param;
- case PARAM_NOTAGS: // Strip all tags
+ case PARAM_NOTAGS:
+ // Strip all tags.
$param = fix_utf8($param);
return strip_tags($param);
- case PARAM_TEXT: // leave only tags needed for multilang
+ case PARAM_TEXT:
+ // Leave only tags needed for multilang.
$param = fix_utf8($param);
- // if the multilang syntax is not correct we strip all tags
- // because it would break xhtml strict which is required for accessibility standards
- // please note this cleaning does not strip unbalanced '>' for BC compatibility reasons
+ // If the multilang syntax is not correct we strip all tags because it would break xhtml strict which is required
+ // for accessibility standards please note this cleaning does not strip unbalanced '>' for BC compatibility reasons.
do {
if (strpos($param, '') !== false) {
- // old and future mutilang syntax
+ // Old and future mutilang syntax.
$param = strip_tags($param, '$module
"; - foreach ($backtraces as $backtrace) { - $details .= "$module
"; + foreach ($backtraces as $backtrace) { + $details .= "