Add get_file_url() theme function
This commit is contained in:
parent
5396e2c1e6
commit
d8e5845184
4
.gitignore
vendored
4
.gitignore
vendored
@ -6,7 +6,3 @@ nbproject/private
|
|||||||
GeoLite2-City.mmdb
|
GeoLite2-City.mmdb
|
||||||
public/files/*
|
public/files/*
|
||||||
!public/files/.htaccess
|
!public/files/.htaccess
|
||||||
public/themes/*
|
|
||||||
!public/themes/bootstrap/*
|
|
||||||
!public/themes/identity/*
|
|
||||||
!public/themes/verti/*
|
|
@ -281,6 +281,32 @@ function get_url_or_slug($str, $echo = true) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a valid URL for a given file path.
|
||||||
|
* Detects if the file is uploaded via SiteWriter and acts accordingly.
|
||||||
|
* @param string $file
|
||||||
|
* @param boolean $echo
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
function get_file_url($file, $echo = true) {
|
||||||
|
$url = "file.php?file=$file";
|
||||||
|
$base = FILE_UPLOAD_PATH;
|
||||||
|
$filepath = $base . $file;
|
||||||
|
if (!file_exists($filepath) || is_dir($filepath)) {
|
||||||
|
$url = $file;
|
||||||
|
} else {
|
||||||
|
if (strpos(realpath($filepath), FILE_UPLOAD_PATH) !== 0) {
|
||||||
|
$url = $file;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($echo) {
|
||||||
|
echo $url;
|
||||||
|
} else {
|
||||||
|
return $url;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Shortcut for get_component("content").
|
* Shortcut for get_component("content").
|
||||||
* @param string $slug Get the content for the passed page instead of the current.
|
* @param string $slug Get the content for the passed page instead of the current.
|
||||||
@ -304,7 +330,7 @@ function get_header() {
|
|||||||
* Echoes invisible page footer content.
|
* Echoes invisible page footer content.
|
||||||
*/
|
*/
|
||||||
function get_footer() {
|
function get_footer() {
|
||||||
// placeholder stub
|
// placeholder stub
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user