From cbae1b0c8b18de0b6643e066c89578523c5e8002 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Sun, 8 Nov 2009 17:16:50 -0500 Subject: add utilities for calculating local and installation theme root dirs --- lib/theme.php | 36 ++++++++++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 6 deletions(-) (limited to 'lib/theme.php') diff --git a/lib/theme.php b/lib/theme.php index c658058ff..e5fad2316 100644 --- a/lib/theme.php +++ b/lib/theme.php @@ -70,7 +70,7 @@ class Theme // Check to see if it's in the local dir - $localroot = INSTALLDIR.'/local/theme'; + $localroot = Theme::localRoot(); $fulldir = $localroot.'/'.$name; @@ -82,11 +82,7 @@ class Theme // Check to see if it's in the distribution dir - $instroot = common_config('theme', 'dir'); - - if (empty($instroot)) { - $instroot = INSTALLDIR.'/theme'; - } + $instroot = Theme::installRoot(); $fulldir = $instroot.'/'.$name; @@ -175,4 +171,32 @@ class Theme $theme = new Theme($name); return $theme->getPath($relative); } + + /** + * Local root dir for themes + * + * @return string local root dir for themes + */ + + protected static function localRoot() + { + return INSTALLDIR.'/local/theme'; + } + + /** + * Root dir for themes that are shipped with StatusNet + * + * @return string root dir for StatusNet themes + */ + + protected static function installRoot() + { + $instroot = common_config('theme', 'dir'); + + if (empty($instroot)) { + $instroot = INSTALLDIR.'/theme'; + } + + return $instroot; + } } -- cgit v1.2.3-54-g00ecf From f086dddf43a8e1593a615e77c2fdd605623acf49 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Sun, 8 Nov 2009 21:18:57 -0500 Subject: add a method to Theme class to list available themes --- lib/theme.php | 49 +++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 47 insertions(+), 2 deletions(-) (limited to 'lib/theme.php') diff --git a/lib/theme.php b/lib/theme.php index e5fad2316..020ce1ac4 100644 --- a/lib/theme.php +++ b/lib/theme.php @@ -70,7 +70,7 @@ class Theme // Check to see if it's in the local dir - $localroot = Theme::localRoot(); + $localroot = self::localRoot(); $fulldir = $localroot.'/'.$name; @@ -82,7 +82,7 @@ class Theme // Check to see if it's in the distribution dir - $instroot = Theme::installRoot(); + $instroot = self::installRoot(); $fulldir = $instroot.'/'.$name; @@ -172,6 +172,51 @@ class Theme return $theme->getPath($relative); } + /** + * list available theme names + * + * @return array list of available theme names + */ + + static function listAvailable() + { + $local = self::subdirsOf(self::localRoot()); + $install = self::subdirsOf(self::installRoot()); + + $i = array_search('base', $install); + + unset($install[$i]); + + return array_merge($local, $install); + } + + /** + * Utility for getting subdirs of a directory + * + * @param string $dir full path to directory to check + * + * @return array relative filenames of subdirs, or empty array + */ + + protected static function subdirsOf($dir) + { + $subdirs = array(); + + if (is_dir($dir)) { + if ($dh = opendir($dir)) { + while (($filename = readdir($dh)) !== false) { + if ($filename != '..' && $filename !== '.' && + is_dir($dir.'/'.$filename)) { + $subdirs[] = $filename; + } + } + closedir($dh); + } + } + + return $subdirs; + } + /** * Local root dir for themes * -- cgit v1.2.3-54-g00ecf