function insert_create_url in Insert 6
Same name and namespace in other branches
- 7 insert.module \insert_create_url()
Utility function to create a URL for Insert.
This is modeled 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_insert_icon_link in includes/
insert.inc - Preprocess variables for the insert-icon-link.tpl.php file.
- template_preprocess_insert_image in includes/
insert.inc - Preprocess variables for the insert-image.tpl.php file.
- template_preprocess_insert_link in includes/
insert.inc - Preprocess variables for the insert-link.tpl.php file.
File
- ./
insert.module, line 394 - 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($path, $absolute = NULL) {
// Strip file_directory_path from $path. We only include relative paths in urls.
if (strpos($path, file_directory_path() . '/') === 0) {
$path = trim(substr($path, strlen(file_directory_path())), '\\/');
}
// Convert all the URL pieces to be URL-encoded.
$pieces = explode('/', $path);
foreach ($pieces as $part => $piece) {
$pieces[$part] = rawurlencode($piece);
}
$path = implode('/', $pieces);
$absolute = isset($absolute) ? $absolute : variable_get('insert_absolute_paths', FALSE);
switch (variable_get('file_downloads', FILE_DOWNLOADS_PUBLIC)) {
case FILE_DOWNLOADS_PUBLIC:
return ($absolute ? $GLOBALS['base_url'] . '/' : $GLOBALS['base_path']) . file_directory_path() . '/' . str_replace('\\', '/', $path);
case FILE_DOWNLOADS_PRIVATE:
return url('system/files/' . $path, array(
'absolute' => $absolute,
));
}
}