From 2c22dee1767a07b529c310bf31471e328238d8eb Mon Sep 17 00:00:00 2001 From: ajshort Date: Wed, 23 Mar 2011 14:43:07 +1100 Subject: [PATCH] API CHANGE: Updated i18n::get_owner_module() to only search classes, since it is never used to search for templates. --- core/i18n.php | 44 ++++++++++++++------------------------------ 1 file changed, 14 insertions(+), 30 deletions(-) diff --git a/core/i18n.php b/core/i18n.php index a2cfe7d14..cc95e30a8 100644 --- a/core/i18n.php +++ b/core/i18n.php @@ -1680,41 +1680,25 @@ class i18n extends Object { } /** - * Given a file name (a php class name, without the .php ext, or a template name, including the .ss extension) - * this helper function determines the module where this file is located + * Given a PHP class name, finds the module where it's located. * - * @param string $name php class name or template file name (including *.ss extension) - * @return string Module where the file is located + * @param string $name + * @return string */ public static function get_owner_module($name) { - // if $name is a template file - if(substr($name,-3) == '.ss') { - global $_TEMPLATE_MANIFEST; - $templateManifest = $_TEMPLATE_MANIFEST[substr($name,0,-3)]; - if(is_array($templateManifest) && isset($templateManifest['themes'])) { - $absolutePath = $templateManifest['themes'][SSViewer::current_theme()]; - } else { - $absolutePath = $templateManifest; - } - - $path = str_replace('\\','/',Director::makeRelative(current($absolutePath))); - - ereg('/([^/]+)/',$path,$module); - } - // $name is assumed to be a PHP class - else { - $classes = SS_ClassLoader::instance()->getManifest()->getClasses(); - if(strpos($name,'_') !== false) $name = strtok($name,'_'); - $name = strtolower($name); // Necessary because of r101131 - if(isset($classes[$name])) { - $path = str_replace('\\','/',Director::makeRelative($classes[$name])); - ereg('/([^/]+)/', $path, $module); - } - } - return (isset($module)) ? $module[1] : false; + $manifest = SS_ClassLoader::instance()->getManifest(); + $path = $manifest->getItemPath($name); + if (!$path) { + return false; + } + + $path = Director::makeRelative($path); + $path = str_replace('\\', '/', $path); + + return substr($path, 0, strpos($path, '/')); } - + /** * Validates a "long" locale format (e.g. "en_US") * by checking it against {@link $all_locales}.