diff --git a/.gitignore b/.gitignore index 3fce731..0ef9858 100644 --- a/.gitignore +++ b/.gitignore @@ -5,8 +5,4 @@ nbproject/private *.bak GeoLite2-City.mmdb public/files/* -!public/files/.htaccess -public/themes/* -!public/themes/bootstrap/* -!public/themes/identity/* -!public/themes/verti/* \ No newline at end of file +!public/files/.htaccess \ No newline at end of file diff --git a/lib/themefunctions.php b/lib/themefunctions.php index e0ea8a8..e5790e5 100644 --- a/lib/themefunctions.php +++ b/lib/themefunctions.php @@ -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"). * @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. */ function get_footer() { - // placeholder stub +// placeholder stub } /**