From 19f46ebad24c8fd0c6067f31b6d15e1e0daffab8 Mon Sep 17 00:00:00 2001 From: Michael M Slusarz Date: Wed, 24 Nov 2010 08:54:22 -0700 Subject: [PATCH] Bug #9404: Fix sound listing This changes the serialized cache format so you will need to run: horde/bin/themes --expirecache (Not going to bother with internal cache invalidation until themes code stabilizes). --- framework/Core/lib/Horde/Themes.php | 33 +++++++------------- framework/Core/lib/Horde/Themes/Cache.php | 51 +++++++++++++++++++------------ 2 files changed, 43 insertions(+), 41 deletions(-) diff --git a/framework/Core/lib/Horde/Themes.php b/framework/Core/lib/Horde/Themes.php index 49f4ffd58..7d5685985 100644 --- a/framework/Core/lib/Horde/Themes.php +++ b/framework/Core/lib/Horde/Themes.php @@ -97,42 +97,31 @@ class Horde_Themes } /** - * Returns a list of available sounds for a theme. + * Returns a list of available sounds. * * @param string $app The app to search in. + * @param string $theme The app to search in. * * @return array An array of Horde_Themes_Sound objects. Keys are the * base filenames. */ - static public function soundList($app = null) + static public function soundList($app = null, $theme = null) { if (is_null($app)) { $app = $GLOBALS['registry']->getApp(); } - /* Do search in reverse order - app + theme sounds have the highest - * priority and will overwrite previous sound definitions. */ - $locations = array( - self::sound(null, array('app' => 'horde', 'theme' => null)), - // Placeholder for app - null, - self::sound(null, 'horde') - ); - - if ($app != 'horde') { - $locations[1] = self::sound(null, array('app' => $app, 'theme' => null)); - $locations[3] = self::sound(null, $app); + if (is_null($theme)) { + $theme = $GLOBALS['prefs']->getValue('theme'); } + $cache = $GLOBALS['injector']->getInstance('Horde_Core_Factory_ThemesCache')->create($app, $theme); + $sounds = array(); - foreach ($locations as $val) { - if ($val) { - foreach (glob($val->fs . '/*.wav') as $file) { - $file = basename($file); - if (!isset($sounds[$file])) { - $sounds[$file] = self::sound($file); - } - } + foreach ($cache->build() as $val) { + if ((strpos($val, 'sounds/') === 0) && + (substr(strrchr($val, '.'), 1) == 'wav')) { + $sounds[basename($val)] = self::sound(substr($val, 7)); } } diff --git a/framework/Core/lib/Horde/Themes/Cache.php b/framework/Core/lib/Horde/Themes/Cache.php index fc128866f..b343dc14e 100644 --- a/framework/Core/lib/Horde/Themes/Cache.php +++ b/framework/Core/lib/Horde/Themes/Cache.php @@ -43,6 +43,13 @@ class Horde_Themes_Cache implements Serializable protected $_cacheid; /** + * Is this a complete representation of the theme? + * + * @var boolean + */ + protected $_complete = false; + + /** * Theme data. * * @var array @@ -71,20 +78,25 @@ class Horde_Themes_Cache implements Serializable /** * Build the entire theme data structure. * + * @return array The list of theme files. * @throws UnexpectedValueException */ public function build() { - $this->_data = array(); + if (!$this->_complete) { + $this->_data = array(); - $this->_build('horde', 'default', self::HORDE_DEFAULT); - $this->_build('horde', $this->_theme, self::HORDE_THEME); - if ($this->_app != 'horde') { - $this->_build($this->_app, 'default', self::APP_DEFAULT); - $this->_build($this->_app, $this->_theme, self::APP_THEME); + $this->_build('horde', 'default', self::HORDE_DEFAULT); + $this->_build('horde', $this->_theme, self::HORDE_THEME); + if ($this->_app != 'horde') { + $this->_build($this->_app, 'default', self::APP_DEFAULT); + $this->_build($this->_app, $this->_theme, self::APP_THEME); + } + + $this->changed = $this->_complete = true; } - $this->changed = true; + return array_keys($this->_data); } /** @@ -246,10 +258,11 @@ class Horde_Themes_Cache implements Serializable public function serialize() { return serialize(array( - $this->getCacheId(), - $this->_app, - $this->_data, - $this->_theme + 'a' => $this->_app, + 'c' => $this->_complete, + 'd' => $this->_data, + 'id' => $this->getCacheId(), + 't' => $this->_theme )); } @@ -257,16 +270,16 @@ class Horde_Themes_Cache implements Serializable */ public function unserialize($data) { - list( - $expire_id, - $this->_app, - $this->_data, - $this->_theme - ) = unserialize($data); - - if ($expire_id && ($expire_id != $this->getCacheId())) { + $out = @unserialize($data); + + if (isset($out['id']) && ($out['id'] != $this->getCacheId())) { throw new Exception('Cache invalidated'); } + + $this->_app = $out['a']; + $this->_complete = $out['c']; + $this->_data = $out['d']; + $this->_theme = $out['t']; } } -- 2.11.0