diff --git a/modules/views_rss_core/views_rss_core.inc b/modules/views_rss_core/views_rss_core.inc index 0f37c7b..24fcfc2 100644 --- a/modules/views_rss_core/views_rss_core.inc +++ b/modules/views_rss_core/views_rss_core.inc @@ -5,7 +5,7 @@ * Preprocess functions for Views RSS: Core Elements module. */ -use Drupal\Component\Utility\String; +use Drupal\Component\Utility\SafeMarkup; use Drupal\Component\Utility\UrlHelper; use Drupal\taxonomy\Entity\Term; @@ -25,7 +25,7 @@ function views_rss_core_preprocess_channel_title(&$variables) { $title = $variables['view']->getTitle(); } - $variables['elements'][0]['value'] = String::checkPlain($title); + $variables['elements'][0]['value'] = SafeMarkup::checkPlain($title); } /** @@ -68,7 +68,7 @@ function views_rss_core_preprocess_channel_atom_link(&$variables) { */ function views_rss_core_preprocess_channel_language(&$variables) { if (empty($variables['elements'][0]['value'])) { - $variables['elements'][0]['value'] = String::checkPlain(\Drupal::languageManager()->getCurrentLanguage()->getId()); + $variables['elements'][0]['value'] = SafeMarkup::checkPlain(\Drupal::languageManager()->getCurrentLanguage()->getId()); } } @@ -360,6 +360,6 @@ function views_rss_core_preprocess_item_source(&$variables) { $url_options['query'] = $input; } - $variables['elements'][0]['value'] = String::checkPlain($title); + $variables['elements'][0]['value'] = SafeMarkup::checkPlain($title); $variables['elements'][0]['attributes'] = array('url' => _url($variables['view']->getUrl(), $url_options)); } diff --git a/modules/views_rss_core/views_rss_core.module b/modules/views_rss_core/views_rss_core.module index bc0ca4f..deaa2b4 100644 --- a/modules/views_rss_core/views_rss_core.module +++ b/modules/views_rss_core/views_rss_core.module @@ -6,6 +6,7 @@ */ use Drupal\Core\Url; +use Drupal\Component\Utility\UrlHelper; /** * Include file with all preprocess functions. @@ -255,32 +256,33 @@ function views_rss_core_views_query_alter($view, $query) { /** * Implements hook_views_rss_options_form_validate(). */ -function views_rss_core_views_rss_options_form_validate($form, &$form_state) { +function views_rss_core_views_rss_options_form_validate($form, $form_state) { + $form_state_values = $form_state->getValues(); // Validate channel element. - if (!empty($form_state['values']['style_options']['channel']['core']['views_rss_core']['image'])) { + 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)) { + if (!UrlHelper::isValid($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'], + $image = \Drupal::service('image.factory')->get($form_state_values['style_options']['channel']['core']['views_rss_core']['image']); + if (!$image->isValid()) { + $form_state->setErrorByName('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 <image> 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'], + if ($image->getWidth() > 144) { + $form_state->setErrorByName('style_options][channel][core][views_rss_core][image', t("Maximum allowed width of an image for feed channel's <image> 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->getWidth(), ))); } // 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 <image> 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'], + $form_state->setErrorByName('style_options][channel][core][views_rss_core][image', t("Maximum allowed height of an image for feed channel's <image> 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->getHeight(), ))); } } @@ -288,9 +290,9 @@ function views_rss_core_views_rss_options_form_validate($form, &$form_state) { } // Validate channel 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.")); + if (!empty($form_state_values['style_options']['channel']['core']['views_rss_core']['docs'])) { + if (!UrlHelper::isValid($form_state_values['style_options']['channel']['core']['views_rss_core']['docs'], TRUE)) { + $form_state->setErrorByName('style_options][channel][core][views_rss_core][docs', t("Not a valid URL.")); } } } diff --git a/modules/views_rss_format/views_rss_format.module b/modules/views_rss_format/views_rss_format.module index dcf268c..1d4437e 100644 --- a/modules/views_rss_format/views_rss_format.module +++ b/modules/views_rss_format/views_rss_format.module @@ -7,7 +7,6 @@ * template_preprocess_views_view_row_rss() implementation. */ -use Drupal\Component\Utility\String; use Drupal\Component\Utility\SafeMarkup; use Drupal\Core\Template\Attribute; @@ -42,7 +41,7 @@ function views_rss_format_xml_elements($array) { } if (isset($value['value']) && $value['value'] != '') { - $output .= '>' . (is_array($value['value']) ? views_rss_format_xml_elements($value['value']) : (!empty($value['encoded']) ? $value['value'] : String::checkPlain($value['value']))) . '\n"; + $output .= '>' . (is_array($value['value']) ? views_rss_format_xml_elements($value['value']) : (!empty($value['encoded']) ? $value['value'] : SafeMarkup::checkPlain($value['value']))) . '\n"; } else { $output .= " />\n"; @@ -50,7 +49,7 @@ function views_rss_format_xml_elements($array) { } } else { - $output .= ' <' . $key . '>' . (is_array($value) ? views_rss_format_xml_elements($value) : String::checkPlain($value)) . "\n"; + $output .= ' <' . $key . '>' . (is_array($value) ? views_rss_format_xml_elements($value) : SafeMarkup::checkPlain($value)) . "\n"; } } // @todo This is marking the output string as safe HTML, but we have only @@ -79,8 +78,8 @@ function views_rss_format_xml_elements($array) { function views_rss_format_preprocess_views_view_row_rss(&$variables) { $item = $variables['row']; - $variables['title'] = String::checkPlain($item->title); + $variables['title'] = SafeMarkup::checkPlain($item->title); $variables['link'] = check_url($item->link); - $variables['description'] = String::checkPlain($item->description); + $variables['description'] = SafeMarkup::checkPlain($item->description); $variables['item_elements'] = empty($item->elements) ? '' : views_rss_format_xml_elements($item->elements); }