diff options
author | Brion Vibber <brion@pobox.com> | 2009-11-10 06:44:53 -0800 |
---|---|---|
committer | Brion Vibber <brion@pobox.com> | 2009-11-10 06:44:53 -0800 |
commit | 333c376c955fd2513ea168d712223f033db73356 (patch) | |
tree | 371f4e8399aa0ea44f2d30ae11d7d777ed812ee9 /lib/theme.php | |
parent | 088081675fb7d5250a9b9dfe5015de0822cb5ac2 (diff) | |
parent | 069d3f2b2f912f2e7d2289bc58270341c9b1ecc5 (diff) |
Merge remote branch 'statusnet/0.9.x' into 0.9.x
Diffstat (limited to 'lib/theme.php')
-rw-r--r-- | lib/theme.php | 81 |
1 files changed, 75 insertions, 6 deletions
diff --git a/lib/theme.php b/lib/theme.php index c658058ff..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 = INSTALLDIR.'/local/theme'; + $localroot = self::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 = self::installRoot(); $fulldir = $instroot.'/'.$name; @@ -175,4 +171,77 @@ class Theme $theme = new Theme($name); 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 + * + * @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; + } } |