function piwik_admin_settings_form_validate in Piwik Web Analytics 7.2
Same name and namespace in other branches
- 5 piwik.module \piwik_admin_settings_form_validate()
- 6.2 piwik.admin.inc \piwik_admin_settings_form_validate()
- 6 piwik.admin.inc \piwik_admin_settings_form_validate()
- 7 piwik.admin.inc \piwik_admin_settings_form_validate()
File
- ./
piwik.admin.inc, line 430 - Administrative page callbacks for the piwik module.
Code
function piwik_admin_settings_form_validate($form, &$form_state) {
// Custom variables validation.
foreach ($form_state['values']['piwik_custom_var']['slots'] as $custom_var) {
$form_state['values']['piwik_custom_var']['slots'][$custom_var['slot']]['name'] = trim($custom_var['name']);
$form_state['values']['piwik_custom_var']['slots'][$custom_var['slot']]['value'] = trim($custom_var['value']);
// Validate empty names/values.
if (empty($custom_var['name']) && !empty($custom_var['value'])) {
form_set_error("piwik_custom_var][slots][" . $custom_var['slot'] . "][name", t('The custom variable @slot-number requires a <em>Name</em> if a <em>Value</em> has been provided.', array(
'@slot-number' => $custom_var['slot'],
)));
}
elseif (!empty($custom_var['name']) && empty($custom_var['value'])) {
form_set_error("piwik_custom_var][slots][" . $custom_var['slot'] . "][value", t('The custom variable @slot-number requires a <em>Value</em> if a <em>Name</em> has been provided.', array(
'@slot-number' => $custom_var['slot'],
)));
}
}
// Trim some text area values.
$form_state['values']['piwik_site_id'] = trim($form_state['values']['piwik_site_id']);
$form_state['values']['piwik_pages'] = trim($form_state['values']['piwik_pages']);
$form_state['values']['piwik_codesnippet_before'] = trim($form_state['values']['piwik_codesnippet_before']);
$form_state['values']['piwik_codesnippet_after'] = trim($form_state['values']['piwik_codesnippet_after']);
if (!preg_match('/^\\d{1,}$/', $form_state['values']['piwik_site_id'])) {
form_set_error('piwik_site_id', t('A valid Piwik site ID is an integer only.'));
}
$piwik_url = $form_state['values']['piwik_url_http'];
if ('/' != drupal_substr($piwik_url, -1, 1)) {
$piwik_url = $piwik_url . '/';
$form_state['values']['piwik_url_http'] = $piwik_url;
}
$url = $piwik_url . 'piwik.php';
$result = drupal_http_request($url);
if ($result->code != 200 && $form_state['values']['piwik_url_skiperror'] == FALSE) {
form_set_error('piwik_url_http', t('The validation of "@url" failed with error "@error" (HTTP code @code).', array(
'@url' => check_url($url),
'@error' => $result->error,
'@code' => $result->code,
)));
}
if (!empty($form_state['values']['piwik_url_https'])) {
$piwik_url = $form_state['values']['piwik_url_https'];
if ('/' != drupal_substr($piwik_url, -1, 1)) {
$piwik_url = $piwik_url . '/';
$form_state['values']['piwik_url_https'] = $piwik_url;
}
$url = $piwik_url . 'piwik.php';
$result = drupal_http_request($url);
if ($result->code != 200 && $form_state['values']['piwik_url_skiperror'] == FALSE) {
form_set_error('piwik_url_https', t('The validation of "@url" failed with error "@error" (HTTP code @code).', array(
'@url' => check_url($url),
'@error' => $result->error,
'@code' => $result->code,
)));
}
}
// Delete obsolete local cache file.
if (empty($form_state['values']['piwik_cache']) && $form['advanced']['piwik_cache']['#default_value']) {
piwik_clear_js_cache();
}
// This is for the Newbie's who cannot read a text area description.
if (preg_match('/(.*)<\\/?script(.*)>(.*)/i', $form_state['values']['piwik_codesnippet_before'])) {
form_set_error('piwik_codesnippet_before', t('Do not include the <script> tags in the javascript code snippets.'));
}
if (preg_match('/(.*)<\\/?script(.*)>(.*)/i', $form_state['values']['piwik_codesnippet_after'])) {
form_set_error('piwik_codesnippet_after', t('Do not include the <script> tags in the javascript code snippets.'));
}
}