You are here

function _pathfilter_base_files_url_re in Path Filter 6.2

Same name and namespace in other branches
  1. 5.2 pathfilter.module \_pathfilter_base_files_url_re()
  2. 7 pathfilter.module \_pathfilter_base_files_url_re()

Generates the regular expression that will be used to find a url that should have 'files:'.

1 call to _pathfilter_base_files_url_re()
_pathfilter_internalize in ./pathfilter.module
Internalizes all urls in a string automatically, doing the user's job for them.

File

./pathfilter.module, line 349
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_base_files_url_re() {
  static $base_files_url_re;
  if ($base_files_url_re != '') {
    return $base_files_url_re;
  }

  //Taken from file_create_url() http://api.drupal.org/api/function/file_create_url
  switch (variable_get('file_downloads', FILE_DOWNLOADS_PUBLIC)) {
    case FILE_DOWNLOADS_PUBLIC:
      $files_url = file_directory_path() . '/';
      break;
    case FILE_DOWNLOADS_PRIVATE:
      $files_url = 'system/files/';
      break;
  }
  global $base_url;
  $base_path = base_path();
  if ($base_path != '/') {
    $tmp_base_url = str_replace($base_path, '', $base_url . '/');
  }
  else {
    $tmp_base_url = $base_url;
  }
  $base_files_url_re = array(
    0 => '/^(' . preg_quote($tmp_base_url, '/') . ')?' . preg_quote($base_path . $files_url, '/') . '/',
    1 => '/^(' . preg_quote($tmp_base_url, '/') . ')?' . preg_quote(drupal_urlencode($base_path . $files_url), '/') . '/',
  );
  return $base_files_url_re;
}