You are here

function insert_create_url in Insert 7

Same name and namespace in other branches
  1. 6 insert.module \insert_create_url()

Utility function to create a URL for Insert.

This is modelled after file_create_url(), but with the modification that it will consistently use absolute or relative URLs, depending on the Insert setting.

3 calls to insert_create_url()
template_preprocess_image_insert_image in includes/image.inc
Theme the content that will be inserted for Image styles.
template_preprocess_insert_image in includes/insert.inc
Preprocess variables for the insert-image.tpl.php file.
_insert_default_vars in includes/insert.inc
Aggregates default variables to be sent to every template.

File

./insert.module, line 485
Allows insertion of files, images, and other media directly into the body field by using an "Insert" button next to the uploaded file.

Code

function insert_create_url($uri, $absolute = NULL, $clean_urls = TRUE) {
  $absolute = isset($absolute) ? $absolute : variable_get('insert_absolute_paths', FALSE);

  // If not using clean URLs, the image derivative callback is only available
  // with the query string. Always use the non-clean URL in the event that the
  // image cache is flushed and needs to be regenerated. See image_style_url().
  if (!$clean_urls && file_uri_scheme($uri) == 'public') {
    $directory_path = file_stream_wrapper_get_instance_by_uri($uri)
      ->getDirectoryPath();
    $url = url($directory_path . '/' . file_uri_target($uri), array(
      'absolute' => TRUE,
    ));
  }
  else {
    $url = file_create_url($uri);
  }
  if (!$absolute && strpos($url, $GLOBALS['base_url']) === 0) {
    $url = base_path() . ltrim(str_replace($GLOBALS['base_url'], '', $url), '/');
  }
  return $url;
}