X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=lib%2Ftheme.php;h=0be8c3b9dfaa8ba2631bb67e08cbfb49b36ceb60;hb=cac6d4234a4ef8fea1d487f44062ae06dd9c0c52;hp=c658058ffcc134841e50174c75ee4fc711c1776f;hpb=111f6a775daf9334adb05c9f8e539d682238f4dd;p=quix0rs-gnu-social.git diff --git a/lib/theme.php b/lib/theme.php index c658058ffc..0be8c3b9df 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; @@ -114,9 +110,20 @@ class Theme $server = common_config('site', 'server'); } - // XXX: protocol + $ssl = common_config('theme', 'ssl'); + + if (is_null($ssl)) { // null -> guess + if (common_config('site', 'ssl') == 'always' && + !common_config('theme', 'server')) { + $ssl = true; + } else { + $ssl = false; + } + } - $this->path = 'http://'.$server.$path.$name; + $protocol = ($ssl) ? 'https' : 'http'; + + $this->path = $protocol . '://'.$server.$path.$name; } } @@ -175,4 +182,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; + } }