From 28624bb8f1a153208ae811ffb56c436055f74249 Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Mon, 28 Sep 2009 09:04:44 -0700 Subject: Update the PHPDoc for gallery::find_file and convert Gallery_View::script/css to use gallery::find_file --- modules/gallery/libraries/Gallery_View.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'modules/gallery/libraries/Gallery_View.php') diff --git a/modules/gallery/libraries/Gallery_View.php b/modules/gallery/libraries/Gallery_View.php index 219cc883..f3fa970b 100644 --- a/modules/gallery/libraries/Gallery_View.php +++ b/modules/gallery/libraries/Gallery_View.php @@ -24,12 +24,12 @@ class Gallery_View_Core extends View { /** * Add a script to the combined scripts list. - * @param $file the relative path to a script from the gallery3 directory + * @param $file the file name or path of the script to include. if a path is specified then + * the location needs to be DOCROOT/lib. Just specifying a file name will result + * in searching the hierarchical file system. */ public function script($file) { - $base_file = str_replace(".js", "", $file); - if (($path = Kohana::find_file("js", $base_file, false, "js")) || - file_exists($path = DOCROOT . "lib/$file")) { + if (($path = gallery::find_file("js", $file, false))) { $this->scripts[$path] = 1; } else { Kohana::log("error", "Can't find script file: $file"); @@ -47,12 +47,12 @@ class Gallery_View_Core extends View { /** * Add a css file to the combined css list. - * @param $file the relative path to a script from the gallery3 directory + * @param $file the file name or path of a css file to include. if a path is specified then + * the location needs to be DOCROOT/lib. Just specifying a file name will result + * in searching the hierarchical file system. */ public function css($file) { - $base_file = str_replace(".css", "", $file); - if (($path = Kohana::find_file("css", $base_file, false, "css")) || - file_exists($path = DOCROOT . "lib/$file")) { + if (($path = gallery::find_file("css", $file, false))) { $this->css[$path] = 1; } else { Kohana::log("error", "Can't find css file: $file"); -- cgit v1.2.3 From a0a62a09922d855cd87d35ccc42ea7cf407a8df7 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Mon, 28 Sep 2009 19:30:34 -0700 Subject: Do a pass on the gallery::find_file and Gallery_View::{script,css} PHPdoc. --- modules/gallery/helpers/gallery.php | 9 ++++----- modules/gallery/libraries/Gallery_View.php | 12 ++++++------ 2 files changed, 10 insertions(+), 11 deletions(-) (limited to 'modules/gallery/libraries/Gallery_View.php') diff --git a/modules/gallery/helpers/gallery.php b/modules/gallery/helpers/gallery.php index 033bf4bd..4b319484 100644 --- a/modules/gallery/helpers/gallery.php +++ b/modules/gallery/helpers/gallery.php @@ -80,15 +80,14 @@ class gallery_Core { } /** - * Provide a wrapper function for Kohana::find_file, that first strips the extension and - * then calls the Kohana::find_file supply that extension + * Provide a wrapper function for Kohana::find_file that first strips the extension and + * then calls the Kohana::find_file and supplies the extension as the type. * @param string directory to search in * @param string filename to look for * @param boolean file required (optional: default false) - * @param boolean make the file name relative (optiona: default false) - * @return array if the type is config, i18n or l10n + * @return array if the extension is config, i18n or l10n * @return string if the file is found (relative to the DOCROOT) - * @return FALSE if the file is not found + * @return false if the file is not found */ static function find_file($directory, $file, $required=false) { $file_name = substr($file, 0, -strlen($ext = strrchr($file, '.'))); diff --git a/modules/gallery/libraries/Gallery_View.php b/modules/gallery/libraries/Gallery_View.php index f3fa970b..253a314f 100644 --- a/modules/gallery/libraries/Gallery_View.php +++ b/modules/gallery/libraries/Gallery_View.php @@ -24,9 +24,9 @@ class Gallery_View_Core extends View { /** * Add a script to the combined scripts list. - * @param $file the file name or path of the script to include. if a path is specified then - * the location needs to be DOCROOT/lib. Just specifying a file name will result - * in searching the hierarchical file system. + * @param $file the file name or path of the script to include. If a path is specified then + * it needs to be relative to DOCROOT. Just specifying a file name will result + * in searching Kohana's cascading file system. */ public function script($file) { if (($path = gallery::find_file("js", $file, false))) { @@ -47,9 +47,9 @@ class Gallery_View_Core extends View { /** * Add a css file to the combined css list. - * @param $file the file name or path of a css file to include. if a path is specified then - * the location needs to be DOCROOT/lib. Just specifying a file name will result - * in searching the hierarchical file system. + * @param $file the file name or path of the script to include. If a path is specified then + * it needs to be relative to DOCROOT. Just specifying a file name will result + * in searching Kohana's cascading file system. */ public function css($file) { if (($path = gallery::find_file("css", $file, false))) { -- cgit v1.2.3 From b2a9bf43afa2aaf845368ea04beef56f2ed035de Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Thu, 1 Oct 2009 12:43:30 -0700 Subject: Change gallery::find_file to not assume that the absolute path is relative to the document root. Instead ignore all th path parts until one of application, modules, themes, or libs is found. Fixes ticket #827 --- modules/gallery/helpers/gallery.php | 13 ++++++++++++- modules/gallery/libraries/Gallery_View.php | 6 ++---- 2 files changed, 14 insertions(+), 5 deletions(-) (limited to 'modules/gallery/libraries/Gallery_View.php') diff --git a/modules/gallery/helpers/gallery.php b/modules/gallery/helpers/gallery.php index b6d4fee0..37a08d08 100644 --- a/modules/gallery/helpers/gallery.php +++ b/modules/gallery/helpers/gallery.php @@ -96,7 +96,18 @@ class gallery_Core { return "lib/$file"; } - return is_string($file_name) ? substr($file_name, strlen(DOCROOT)) : $file_name; + if (is_string($file_name)) { + // make relative to DOCROOT + $parts = explode("/", $file_name); + foreach ($parts as $idx => $part) { + if (in_array($part, array("application", "modules", "themes", "lib"))) { + break; + } + unset($parts[$idx]); + } + $file_name = implode("/", $parts); + } + return $file_name; } } \ No newline at end of file diff --git a/modules/gallery/libraries/Gallery_View.php b/modules/gallery/libraries/Gallery_View.php index 253a314f..bdfd2fc9 100644 --- a/modules/gallery/libraries/Gallery_View.php +++ b/modules/gallery/libraries/Gallery_View.php @@ -85,13 +85,11 @@ class Gallery_View_Core extends View { if (empty($contents)) { $contents = ""; - $docroot_len = strlen(DOCROOT); foreach (array_keys($paths) as $path) { - $relative = substr($path, $docroot_len); if ($type == "css") { - $contents .= "/* $relative */\n" . $this->process_css($path) . "\n"; + $contents .= "/* $path */\n" . $this->process_css($path) . "\n"; } else { - $contents .= "/* $relative */\n" . file_get_contents($path) . "\n"; + $contents .= "/* $path */\n" . file_get_contents($path) . "\n"; } } -- cgit v1.2.3