Add Horde_Themes::themeList()
authorMichael M Slusarz <slusarz@curecanti.org>
Sun, 21 Nov 2010 20:52:32 +0000 (13:52 -0700)
committerMichael M Slusarz <slusarz@curecanti.org>
Mon, 22 Nov 2010 18:33:20 +0000 (11:33 -0700)
framework/Core/lib/Horde/Themes.php
horde/lib/Prefs/Ui.php

index dcbc24b..2808d5c 100644 (file)
@@ -68,6 +68,34 @@ class Horde_Themes
     }
 
     /**
+     * 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.
index 4e08280..950f2f3 100644 (file)
@@ -19,7 +19,7 @@ class Horde_Prefs_Ui
      */
     public function prefsEnum($ui)
     {
-        global $prefs, $registry;
+        global $injector, $notification, $prefs, $registry;
 
         switch ($ui->group) {
         case 'display':
@@ -27,9 +27,9 @@ class Horde_Prefs_Ui
                 $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);
                     }
@@ -39,27 +39,11 @@ class Horde_Prefs_Ui
             }
 
             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;