You are here

function views_rss_core_views_rss_options_form_validate in Views RSS 7.2

Same name and namespace in other branches
  1. 8.3 modules/views_rss_core/views_rss_core.module \views_rss_core_views_rss_options_form_validate()
  2. 8.2 modules/views_rss_core/views_rss_core.module \views_rss_core_views_rss_options_form_validate()
  3. 6.2 modules/views_rss_core/views_rss_core.module \views_rss_core_views_rss_options_form_validate()

Implements hook_views_rss_options_form_validate().

File

modules/views_rss_core/views_rss_core.module, line 247
Provides core <channel> and <item> elements for Views RSS module.

Code

function views_rss_core_views_rss_options_form_validate($form, &$form_state) {

  // Validate channel <image> element.
  if (!empty($form_state['values']['style_options']['channel']['core']['views_rss_core']['image'])) {

    // Do not validate absolute URLs, as this could mean external image.
    if (!valid_url($form_state['values']['style_options']['channel']['core']['views_rss_core']['image'], TRUE)) {

      // Check that image exists and is in acceptable format.
      $image = image_load($form_state['values']['style_options']['channel']['core']['views_rss_core']['image']);
      if (empty($image)) {
        form_set_error('style_options][channel][core][views_rss_core][image', t('Unable to find %image or incorrect image format.', array(
          '%image' => $form_state['values']['style_options']['channel']['core']['views_rss_core']['image'],
        )));
      }
      else {

        // Check image width.
        if ($image->info['width'] > 144) {
          form_set_error('style_options][channel][core][views_rss_core][image', t("Maximum allowed width of an image for feed channel's &lt;image&gt; element is 144 pixels. Specified %image is !width pixels wide.", array(
            '%image' => $form_state['values']['style_options']['channel']['core']['views_rss_core']['image'],
            '!width' => $image->info['width'],
          )));
        }

        // Check image height.
        if ($image->info['height'] > 400) {
          form_set_error('style_options][channel][core][views_rss_core][image', t("Maximum allowed height of an image for feed channel's &lt;image&gt; element is 400 pixels. Specified %image is !height pixels high.", array(
            '%image' => $form_state['values']['style_options']['channel']['core']['views_rss_core']['image'],
            '!height' => $image->info['height'],
          )));
        }
      }
    }
  }

  // Validate channel <docs> element.
  if (!empty($form_state['values']['style_options']['channel']['core']['views_rss_core']['docs'])) {
    if (!valid_url($form_state['values']['style_options']['channel']['core']['views_rss_core']['docs'], TRUE)) {
      form_set_error('style_options][channel][core][views_rss_core][docs', t("Not a valid URL."));
    }
  }
}