You are here

function _pathologic_url in Pathologic 6.2

Same name and namespace in other branches
  1. 5 pathologic.module \_pathologic_url()
  2. 6 pathologic.module \_pathologic_url()

Run the path parts through url() to puild a correct URL if the path looks like it links to a local Drupal path.

Otherwise, it's a link to a file or something -- try to return it in one piece.

Parameters

$path: The path to check.

$query: The query fragment of the path, if any (comes after ?).

$fragment: The anchor fragment of the path, if any (comes after #).

Return value

string The corrected path, if necessary. Else, the reconstructed path.

4 calls to _pathologic_url()
pathologic_filter in ./pathologic.module
Implementation of hook_filter().
_pathologic_abs_regex in ./pathologic.module
Return the hard part of the regular expression to be used when making paths relative.
_pathologic_do_href in ./pathologic.module
Properly format an HREF element.
_pathologic_do_src in ./pathologic.module
Return a formatted SRC attribute.

File

./pathologic.module, line 175
Pathologic text filter for Drupal.

Code

function _pathologic_url($path, $query = NULL, $fragment = NULL) {

  // We're unescaping HTML entities like & in the hope of avoiding double-
  // encoding. See: http://drupal.org/node/665900
  $path = html_entity_decode($path, ENT_COMPAT, 'UTF-8');

  // Does this look like an internal URL?
  if ($path !== '<front>' && !menu_get_item($path) && !drupal_lookup_path('source', $path)) {

    // It's not.
    global $base_url;
    $return = $base_url . '/' . $path;
    if ($query !== NULL && $query !== '') {
      $return .= '?' . $query;
    }
    if ($fragment !== NULL && $fragment !== '') {
      $return .= '#' . $fragment;
    }
    return $return;
  }
  return url($path, array(
    'query' => $query,
    'fragment' => $fragment,
    'absolute' => TRUE,
  ));
}