}
/**
+ * Returns a list of available themes.
+ *
+ * @return array Keys are theme names, values are theme descriptions.
+ * @throws UnexpectedValueException
+ */
+ static public function themeList()
+ {
+ $out = array();
+
+ // Throws UnexpectedValueException
+ $di = new DirectoryIterator($GLOBALS['registry']->get('themesfs', 'horde'));
+
+ foreach ($di as $val) {
+ $theme_name = null;
+
+ if ($val->isDir() &&
+ !$di->isDot() &&
+ (@include $val->getPathname() . '/info.php')) {
+ $out[strval($val)] = $theme_name;
+ }
+ }
+
+ asort($out);
+
+ return $out;
+ }
+
+ /**
* Returns a list of available sounds for a theme.
*
* @param string $app The app to search in.
*/
public function prefsEnum($ui)
{
- global $prefs, $registry;
+ global $injector, $notification, $prefs, $registry;
switch ($ui->group) {
case 'display':
$out = array();
$apps = $registry->listApps(array('active'));
foreach ($apps as $a) {
- $perms = $GLOBALS['injector']->getInstance('Horde_Perms');
+ $perms = $injector->getInstance('Horde_Perms');
if (file_exists($registry->get('fileroot', $a)) &&
- (($perms->exists($a) && ($perms->hasPermission($a, $GLOBALS['registry']->getAuth(), Horde_Perms::READ) || $registry->isAdmin())) ||
+ (($perms->exists($a) && ($perms->hasPermission($a, $registry->getAuth(), Horde_Perms::READ) || $registry->isAdmin())) ||
!$perms->exists($a))) {
$out[$a] = $registry->get('name', $a);
}
}
if (!$prefs->isLocked('theme')) {
- $out = array();
- $theme_base = $registry->get('themesfs', 'horde');
- $dh = @opendir($theme_base);
- if (!$dh) {
- $GLOBALS['notification']->push(_("Theme directory can't be opened"), 'horde.error');
- } else {
- while (($dir = readdir($dh)) !== false) {
- if ($dir == '.' || $dir == '..') {
- continue;
- }
-
- $theme_name = null;
- @include $theme_base . '/' . $dir . '/info.php';
- if (!empty($theme_name)) {
- $out[$dir] = $theme_name;
- }
- }
+ try {
+ $ui->override['theme'] = Horde_Themes::themeList();
+ } catch (UnexpectedValueException $e) {
+ $notification->push(_("Theme directory can't be opened"), 'horde.error');
}
-
- asort($out);
- $ui->override['theme'] = $out;
}
break;