From f261871346373f649644bbfc390815294f4ecfeb Mon Sep 17 00:00:00 2001 From: friendica Date: Sat, 11 Aug 2012 19:28:58 -0700 Subject: cleanup all the theme include stuff - this could make Friendica themes work out of the box, maybe. --- include/plugin.php | 47 +++++++++++++++++++++++++++++++++++------------ 1 file changed, 35 insertions(+), 12 deletions(-) (limited to 'include') diff --git a/include/plugin.php b/include/plugin.php index c9490eb8a..2460e8ad6 100644 --- a/include/plugin.php +++ b/include/plugin.php @@ -422,12 +422,9 @@ function format_css_if_exists($source) { if(strpos($source[0],'/') !== false) $path = $source[0]; - elseif(file_exists('view/theme/'. current_theme() . '/css/' . $source[0])) - $path = 'view/theme/'. current_theme() . '/css/' . $source[0]; - elseif(file_exists('view/theme/'. get_app()->theme_info['extends'] . '/css/' . $source[0])) - $path = 'view/theme/'. get_app()->theme_info['extends'] . '/css/' . $source[0]; - elseif(file_exists('view/css/' . $source[0])) - $path = 'view/css/' . $source[0]; + else + $path = theme_include($source[0]); + if($path) return '' . "\r\n"; @@ -451,14 +448,40 @@ function format_js_if_exists($source) { if(strpos($source,'/') !== false) $path = $source; - elseif(file_exists('view/theme/'. current_theme() . '/js/' . $source)) - $path = 'view/theme/'. current_theme() . '/js/' . $source; - elseif(file_exists('view/theme/'. get_app()->theme_info['extends'] . '/js/' . $source)) - $path = 'view/theme/'. get_app()->theme_info['extends'] . '/js/' . $source; - elseif(file_exists('view/js/' . $source)) - $path = 'view/js/' . $source[0]; + else + $path = theme_include($source); if($path) return '' . "\r\n" ; } + +function theme_include($file) { + + $paths = array( + 'view/theme/$theme/$ext/$file', + 'view/theme/$theme/$file', + 'view/theme/$parent/$ext/$file', + 'view/theme/$parent/$file', + 'view/$ext/$file', + 'view/$file' + ); + + $parent = get_app()->theme_info['extends']; + if(! $parent) + $parent = 'NOPATH'; + + foreach($paths as $p) { + $f = replace_macros($p,array( + '$theme' => current_theme(), + '$ext' => substr($file,strrpos($file,'.')+1), + '$parent' => $parent, + '$file' => $file + )); + if(strstr($f,'NOPATH')) + continue; + if(file_exists($f)) + return $f; + } + return ''; +} -- cgit v1.2.3