diff --git a/includes/common.inc b/includes/common.inc index 1e40cb2..c128d96 100644 --- a/includes/common.inc +++ b/includes/common.inc @@ -2198,23 +2198,13 @@ function url_is_external($path) { } /** - * Returns a local path corresponding to a given URL, if possible. - * - * Finds the configuration directory matching the given URL, and compares it - * to the current configuration directory. Returns a local file path if they - * match, and FALSE if they don't. - * - * In a properly-configured multisite installation, this function helps answer - * the question, "Could this URL match a file or path within my site?" - * - * Whether the URL does in fact resolve to this site, or at all, cannot be - * determined within Drupal itself. This is only a sanity check. + * Returns an absolute local path corresponding to a given URL, if possible. * * For example, when looking for image URLs within an HTML Mail body for * possible conversion to inline attachments, the following code might be used: * @code * if ( !url_is_external($url) - * && ($path = url_to_path($url)) + * && ($path = url_to_realpath($url)) * && file_exists($path) ) { * // Attach $path and replace $url. * ... @@ -2228,7 +2218,37 @@ function url_is_external($path) { * FALSE if $url contains a host/port that does not match the current site, * or else a local path such as "/path/to/drupal/node/34". * - * @see conf_path() + * @see url_to_path() + */ +function url_to_realpath($url) { + $path = url_to_path($url); + if ($path) { + return realpath('./' . $path); + } + return FALSE; +} + +/** + * Returns an local relative url corresponding to a given URL, if possible. + * + * Finds the configuration directory matching the given URL, and compares it + * to the current configuration directory. Returns a local relative url if they + * match, and FALSE if they don't. + * + * In a properly-configured multisite installation, this function helps answer + * the question, "Could this URL match a file or path within my site?" + * + * Whether the URL does in fact resolve to this site, or at all, cannot be + * determined within Drupal itself. This is only a sanity check. + * + * @param $url + * The internal path or external URL being linked to, such as "node/34" or + * "http://example.com/foo". + * @return + * FALSE if $url contains a host/port that does not match the current site, + * or else a local url such as "node/34" or "foo". + * + * @see conf_path(), find_conf_path() */ function url_to_path($url) { $local = &drupal_static(__FUNCTION__, array()); @@ -2249,7 +2269,7 @@ function url_to_path($url) { ); } return $local[$path] - ? realpath('.' . $script_name) : FALSE; + ? substr($script_name,1) : FALSE; } /**