}
/**
- * 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));
}
}
protected $_cacheid;
/**
+ * Is this a complete representation of the theme?
+ *
+ * @var boolean
+ */
+ protected $_complete = false;
+
+ /**
* Theme data.
*
* @var array
/**
* 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);
}
/**
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
));
}
*/
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'];
}
}