Boys will be boys as my dear old mom used to say :)
Someone just changed the value for page width, etc. to rediculously large absolute values (e.g. 7200 pixels).
In normal use a site administrator wouldn't hack his/her own site like that, at least not intentionally. Regardless, some sanity checking is required for page width, sidebar width and photo sizes.
I've worked up this to implement tonight or tomorrow:
// Check a value submitted from the Site Settings form:
function checkValue($string,$max_abs,$min_abs,$max_rel,$min_rel,$value) {
// If the last char of submitted string is '%' we note it then remove it:
if (substr($string, -1) == "%") {
$rel=TRUE;
$string = substr($string, 0, -1);
}
// Remove any non-numerial chars from the string:
$length = strlen($string);
$charnum = 0;
$badchars = array();
while ($charnum < $length) {
$char = substr($string, $charnum, 1);
if (!preg_match("/[0-9]/", $char)) {
array_push($badchars, $char);
}
$charnum++;
}
foreach ($badchars as $bad) {
$string = str_replace($bad,"",$string);
}
if (!$string) {
$string = "0";
}
// Check that the value falls within the set range for relative (%) values.
// If not, reset it and produce a warning message:
if ($rel) {
if ($string > $max_rel) {
$new_string = $max_rel;
$msg = "You specified $string% for $value.
The maximum allowed value is $max_rel%.";
}
elseif ($string < $min_rel) {
$new_string = $min_rel;
$msg = "You specified $string% for $value.
The minimum allowed value is $min_rel%.";
}
else {
$new_string = $string;
}
$new_string = $new_string . "%";
}
// Or check that it falls within the set range for absolute (pixel) values.
// If not, reset it and produce a warning message:
else {
if ($string > $max_abs) {
$new_string = $max_abs;
$msg = "You specified $string pixels for $value.
The maximum allowed value is $max_abs pixels.";
}
elseif ($string < $min_abs) {
$new_string = $min_abs;
$msg = "You specified $string pixels for $value.
The minimum allowed value is $min_abs pixels.";
}
else {
$new_string = string;
}
}
return array($string,$new_string,$msg);
}
If a $msg is generated, the user will be sent back to the site setting form after submitting. The msg (in red) will be inserted below the input field for the particular value, and the value in the input field willl be reset to the $new_string (sanitized) value.
If anyone has comments, suggestions they're always welcome.