function textsize_admin_settings_validate in Text Size 6
Same name and namespace in other branches
- 5 includes/textsize.admin.inc \textsize_admin_settings_validate()
- 7 includes/textsize.admin.inc \textsize_admin_settings_validate()
Validate the textsize settings form.
See also
File
- includes/
textsize.admin.inc, line 420 - Provides the Text Size administrative interface.
Code
function textsize_admin_settings_validate($form, &$form_state) {
$textsize_cookie_expires = textsize_cookie_expires($mode = 'php');
$textsize_cookie_domain = variable_get('textsize_cookie_domain', base_path());
$abbr_xhtml = '<abbr title="' . t('Extensible Hypertext Markup Language') . '">XHTML</abbr>';
$abbr_css = '<abbr title="' . t('Cascading Style Sheets') . '">CSS</abbr>';
$abbr_id = '<abbr title="' . t('Identification') . '">ID</abbr>';
$link_ts_important = l(t('Overwrite text size in templates'), 'admin/settings/textsize', array(
'attributes' => array(
'title' => t('Overwrite text size in templates'),
),
'fragment' => 'edit-textsize-important',
));
$ts_el = $form_state['values']['textsize_element'];
$ts_ec = filter_xss($form_state['values']['textsize_element_class']);
$ts_in = $form_state['values']['textsize_increment'];
$ts_no = $form_state['values']['textsize_normal'];
$ts_di = $form_state['values']['textsize_display'];
$ts_mi = $form_state['values']['textsize_minimum'];
$ts_ma = $form_state['values']['textsize_maximum'];
$ts_js = $form_state['values']['textsize_javascript'];
$ts_an = $form_state['values']['textsize_animate'];
$ts_im = $form_state['values']['textsize_important'];
$ts_co_ex = $form_state['values']['textsize_cookie_expires'];
$ts_co_do = $form_state['values']['textsize_cookie_domain'];
$ts_di_in = $form_state['values']['textsize_display_increase'];
$ts_di_de = $form_state['values']['textsize_display_decrease'];
$ts_di_no = $form_state['values']['textsize_display_normal'];
$ts_no_error = FALSE;
$textsize_allowed_values = array();
if (is_numeric($ts_in) && is_numeric($ts_no) && is_numeric($ts_mi) && is_numeric($ts_ma)) {
if ($ts_in >= 1 && $ts_no >= 1 && $ts_mi >= 1 && $ts_ma >= 3) {
$ts_st = $ts_no - ceil(($ts_no - $ts_mi) / $ts_in) * $ts_in;
$ts_en = $ts_no + floor(($ts_ma - $ts_no) / $ts_in) * $ts_in;
for ($value = $ts_st; $value <= $ts_en; $value = $value + $ts_in) {
$textsize_allowed_values[] = round($value, 2);
}
}
}
if ($ts_di_in + $ts_di_de + $ts_di_no < 1 || $ts_di_in + $ts_di_de == 0 && $ts_di_no == 1) {
form_set_error('textsize_display_increase', t('Minimum 1 link "Increase Text Size" or "Decrease Text Size" is required.'));
}
if ($ts_el == "body") {
if (!empty($ts_ec)) {
form_set_error('textsize_element_class', t('The element class have to be empty for the !body element.', array(
'!body' => '<em lang="en">body</em>',
)));
}
elseif ($ts_im == 0) {
drupal_set_message(t('Delete in your theme the cascading style sheet style:', array(
'!abbr_css' => $abbr_css,
)) . ' "<code>body {font-size: ...;}</code>". ' . t('For example') . ': "<code><del>body {font-size: 12px;}</del></code>".</span>', "warning");
}
}
if ($ts_el != "body") {
if (empty($ts_ec)) {
form_set_error('textsize_element_class', t('The !abbr_xhtml !abbr_id/element class can not be empty.', array(
'!abbr_xhtml' => $abbr_xhtml,
'!abbr_id' => $abbr_id,
)) . ' ' . t('Textfield content') . ': "' . $ts_ec . '".');
}
elseif ($ts_ec[0] != "." && $ts_ec[0] != "#") {
form_set_error('textsize_element_class', t('The !abbr_xhtml element !abbr_id/class have to be start with a hash ("#") for a !abbr_id or a point (".") for a class.', array(
'!abbr_xhtml' => $abbr_xhtml,
'!abbr_id' => $abbr_id,
)));
}
elseif ($ts_ec == "." || $ts_ec == "#") {
form_set_error('textsize_element_class', t('The !abbr_xhtml element !abbr_id/class can not have only a hash ("#") or a point (".").', array(
'!abbr_xhtml' => $abbr_xhtml,
'!abbr_id' => $abbr_id,
)) . ' ' . t('Textfield content') . ': "' . $ts_ec . '".');
}
elseif ($ts_ec[0] == "#" && $ts_ec[1] == " " || $ts_ec[0] == "." && $ts_ec[1] == " ") {
form_set_error('textsize_element_class', t('The !abbr_xhtml element !abbr_id/class can not have a empty space (" ") after a hash ("#") or a point (".").', array(
'!abbr_xhtml' => $abbr_xhtml,
'!abbr_id' => $abbr_id,
)) . ' ' . t('Textfield content') . ': "' . $ts_ec . '".');
}
}
// Text Size Increment
if (!is_numeric($ts_in) || $ts_in != round($ts_in, 2) || $ts_in[0] == "+") {
form_set_error('textsize_increment', t('Please enter a number with two digits after the decimal point in:') . ' "' . t('Increases/decreases step') . '".');
}
if ($ts_in < 0.01) {
form_set_error('textsize_increment', t('The minimum step is 1% in:') . ' "' . t('Increases/decreases step') . '".');
}
// Text Size Normal
if (!is_numeric($ts_no) || $ts_no != round($ts_no, 2) || $ts_no[0] == "+") {
$ts_no_error = TRUE;
form_set_error('textsize_normal', t('Please enter a number with two digits after the decimal point in:') . ' "' . t('Normal Text Size') . '".');
}
if ($ts_no > $ts_ma - $ts_in) {
$ts_no_error = TRUE;
form_set_error('textsize_normal', t('The normal text size is bigger than the maximum normal size of: %ts_size%.', array(
'%ts_size' => $ts_ma - $ts_in,
)));
}
if ($ts_no < $ts_mi + $ts_in) {
$ts_no_error = TRUE;
form_set_error('textsize_normal', t('The normal text size is less than the minimum normal size of: %ts_size%.', array(
'%ts_size' => $ts_mi + $ts_in,
)));
}
// Text Size Minimum
if (!is_numeric($ts_mi) || $ts_mi != round($ts_mi) || $ts_mi[0] == "+") {
form_set_error('textsize_minimum', t('Please enter a integer in:') . ' "' . t('Minimum Text Size') . '".');
}
if ($ts_mi >= $ts_no) {
$ts_no_error = TRUE;
form_set_error('textsize_minimum', t('The minimum text size can not be the same or bigger value than the normal textsize.'));
}
if ($ts_mi < 0.01 || $ts_mi[0] == "-") {
form_set_error('textsize_minimum', t('The minimum size is 1% in:') . ' "' . t('Minimum Text Size') . '".');
}
// Text Size Maximum
if (!is_numeric($ts_ma) || $ts_ma != round($ts_ma, 2) || $ts_ma[0] == "+") {
form_set_error('textsize_maximum', t('Please enter a number with two digits after the decimal point in:') . ' "' . t('Maximum Text Size') . '".');
}
if ($ts_ma > 1000) {
form_set_error('textsize_minimum', t('The maximum size is 1000% in:') . ' "' . t('Maximum Text Size') . '".');
}
if ($ts_ma < 0.03 || $ts_ma[0] == "-") {
form_set_error('textsize_minimum', t('The minimum size is 3% in:') . ' "' . t('Minimum Text Size') . '".');
}
// Text Size Normal (Set cookie if changed)
if (is_numeric($ts_no) && $ts_no == round($ts_no) && in_array($_COOKIE['textsize'], $textsize_allowed_values) && $_COOKIE['textsize'] != $ts_no && $ts_no_error == FALSE) {
if ($ts_js == 0 || $ts_js == 1) {
$_SESSION['textsize'] = $ts_no;
}
setcookie("textsize", $ts_no, time() + $textsize_cookie_expires, $textsize_cookie_domain, "");
drupal_set_message(t('The text size has been saved as %ts_value% (100%).', array(
'%ts_value' => $ts_no,
)));
}
// Text Size Animate
if ($ts_an == 1 && $ts_im == 1) {
form_set_error('textsize_important', t('For JavaScript animation, desable:') . ' "' . t('Overwrite text size in templates') . '".');
}
// Text Size Cookie Expires
if (!is_numeric($ts_co_ex) || $ts_co_ex != round($ts_co_ex) || $ts_co_ex[0] == "+") {
form_set_error('textsize_cookie_expires', t('Please enter a integer in:') . ' "' . t('Cookie Expires') . '".');
}
if ($ts_co_ex < 1 || $ts_co_ex[0] == "-") {
form_set_error('textsize_cookie_expires', t('The minimum is 1 day in:') . ' "' . t('Cookie Expires') . '".');
}
if ($ts_co_ex > 3650) {
form_set_error('textsize_cookie_expires', t('The maximum is 3650 day in:') . ' "' . t('Cookie Expires') . '".');
}
// Text Size Cookie Domain
if (empty($ts_co_do[0])) {
form_set_error('textsize_cookie_domain', t('The cookie domain can not have a empty space (" ") as first in:') . ' "' . t('Cookie Domain') . '".');
}
if (!empty($ts_co_do[0])) {
if ($ts_co_do[0] != "/") {
form_set_error('textsize_cookie_domain', t('Please enter a slash "/" as first in:') . ' "' . t('Cookie Domain') . '".');
}
elseif ($ts_co_do[0] == "/") {
if (!empty($ts_co_do[1])) {
if ($ts_co_do[1] == "/") {
form_set_error('textsize_cookie_domain', t('Please enter only one slash "/" as first in:') . ' "' . t('Cookie Domain') . '".');
}
elseif ($ts_co_do[1] != "/") {
if ($ts_co_do != base_path()) {
drupal_set_message(t('Warning') . ': ' . t('The cookie domain: "%ts_co_do" is specific!', array(
'%ts_co_do' => $ts_co_do,
)), "warning");
}
elseif ($ts_co_do != variable_get('textsize_cookie_domain', base_path())) {
drupal_set_message(t('Warning') . ': ' . t('The cookie domain has been changed.') . ' ' . t('After a change, the user must store the cookie again.'), "warning");
}
}
}
}
}
// Warning
if (!in_array("100", $textsize_allowed_values) && $ts_di == 1) {
drupal_set_message(t('This configuration generate not a normal text size of 100% in the source code.'), "warning");
}
if (!in_array("100", $textsize_allowed_values) && $ts_di == 0) {
drupal_set_message(t('Warning') . ': ' . t('This configuration generate and display not a normal text size of 100%!'), "warning");
}
}