You are here

function _pathfilter_process_internal in Path Filter 5.2

Same name and namespace in other branches
  1. 5 pathfilter.module \_pathfilter_process_internal()
  2. 6.2 pathfilter.module \_pathfilter_process_internal()
  3. 6 pathfilter.module \_pathfilter_process_internal()
  4. 7 pathfilter.module \_pathfilter_process_internal()
1 call to _pathfilter_process_internal()
_pathfilter_process in ./pathfilter.module

File

./pathfilter.module, line 119
This filter takes internal Drupal paths in double quotes, written as e.g. "internal:node/99", and replaces them with the appropriate absolute http URL using Drupal's url() function [1]. E.g. for a site located at http://example.com/mysite

Code

function _pathfilter_process_internal($format, $convert_to_alias, $matches) {
  $absolute = variable_get('pathfilter_link_absolute_' . $format, 1) ? TRUE : FALSE;

  // If we are going to convert our output to the aliased version ($convert_to_alias is set to TRUE),
  // We need to pass 'alias' => true into url to tell it to not pass our URL through
  // drupal_get_path_alias() thus keeping our 'node/#' format.
  if (module_exists('i18n')) {
    if ($path = drupal_get_normal_path($matches[3])) {
      if (substr($path, 0, 5) == 'node/') {
        $nid = substr($path, 5);
      }
    }
    elseif (preg_match('/(node\\/([0-9]+))$/', $matches[3], $match)) {
      $path = $match[1];
      $nid = $match[2];
    }
    if (!empty($nid)) {
      $language = i18n_node_get_lang($nid);
      $path = $language ? i18n_path($path, $language) : $path;
      $link = url($path, $matches[4], $matches[5], $absolute);
    }
  }
  return $link ? $link : $matches[1] . url($matches[3], $matches[4], $matches[5], $absolute) . $matches[1];
}