You are here

function views_rss_rewrite_relative_paths in Views RSS 8.2

Same name and namespace in other branches
  1. 8.3 views_rss.module \views_rss_rewrite_relative_paths()
  2. 6.2 views_rss.module \views_rss_rewrite_relative_paths()
  3. 7.2 views_rss.module \views_rss_rewrite_relative_paths()

Element preprocess callback: replaces relative paths with absolute URLs.

Based on preg_match from rel_to_abs module by lourenzo, with added patch from issue #1335734 by joelstein.

See also

http://drupal.org/project/rel_to_abs

http://drupal.org/node/1335734

3 string references to 'views_rss_rewrite_relative_paths'
views_rss_core_views_rss_channel_elements in modules/views_rss_core/views_rss_core.module
Implements hook_views_rss_item_elements().
views_rss_core_views_rss_item_elements in modules/views_rss_core/views_rss_core.module
Implements hook_views_rss_item_elements().
views_rss_dc_views_rss_item_elements in modules/views_rss_dc/views_rss_dc.module
Implements hook_views_rss_item_elements().

File

./views_rss.module, line 111
Module providing fields-based views style plugin for RSS feed generation.

Code

function views_rss_rewrite_relative_paths(&$variables) {

  // Rewriting relative paths should be enabled by default,
  // so rewrite relative paths even if option value is not set.
  if (!isset($variables['view']->style_plugin->options['feed_settings']['absolute_paths']) || !empty($variables['view']->style_plugin->options['feed_settings']['absolute_paths'])) {
    global $base_path;
    foreach ($variables['elements'] as $delta => $element) {
      if (isset($element['value'])) {

        // Value is an array, so this is a set of subelements.
        if (is_array($element['value'])) {
          views_rss_rewrite_relative_paths($variables['elements'][$delta]['value']);
        }
        else {
          $pattern = '/(data-src|srcset|src|href)=(\'|")' . preg_quote($base_path, '/') . '(?!\\/)/';
          $replacement = '$1=$2' . $GLOBALS['base_url'] . '/';
          $variables['elements'][$delta]['value'] = preg_replace($pattern, $replacement, $element['value']);
        }
      }
    }
  }
}