You are here

function piwik_admin_settings_form_validate in Piwik Web Analytics 6

Same name and namespace in other branches
  1. 5 piwik.module \piwik_admin_settings_form_validate()
  2. 6.2 piwik.admin.inc \piwik_admin_settings_form_validate()
  3. 7.2 piwik.admin.inc \piwik_admin_settings_form_validate()
  4. 7 piwik.admin.inc \piwik_admin_settings_form_validate()

File

./piwik.admin.inc, line 223
Administrative page callbacks for the piwik module.

Code

function piwik_admin_settings_form_validate($form, &$form_state) {
  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.'));
  }
  $url = $form_state['values']['piwik_url_http'] . '/piwik.php';
  $result = drupal_http_request($url);
  if ($result->code != 200) {
    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'])) {
    $url = $form_state['values']['piwik_url_https'] . '/piwik.php';
    $result = drupal_http_request($url);
    if ($result->code != 200) {
      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 &lt;script&gt; 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 &lt;script&gt; tags in the javascript code snippets.'));
  }

  // Trim some text area values.
  $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']);
}