From 3a15cdcd6e375b230d64ba54b62acd6a20754a16 Mon Sep 17 00:00:00 2001 From: Ralf Becker Date: Wed, 2 Jun 2010 10:59:58 +0000 Subject: [PATCH] Finding of templates and their themes, if they are packaged in dirs as apps --- phpgwapi/inc/class.common.inc.php | 68 ------------------ phpgwapi/inc/class.egw_framework.inc.php | 72 +++++++++++++++++++ .../inc/class.preferences_hooks.inc.php | 17 +---- 3 files changed, 74 insertions(+), 83 deletions(-) diff --git a/phpgwapi/inc/class.common.inc.php b/phpgwapi/inc/class.common.inc.php index e47b2547af..87efd7a7b9 100644 --- a/phpgwapi/inc/class.common.inc.php +++ b/phpgwapi/inc/class.common.inc.php @@ -572,74 +572,6 @@ class common } } - /** - * list themes available - * - * themes can either be css file like in HEAD (if the template has a css-dir and has css-files in is) \ - * or ordinary .14 themes-files - */ - function list_themes() - { - $tpl_dir = self::get_tpl_dir('phpgwapi'); - - if ($dh = @opendir($tpl_dir . SEP . 'css')) - { - while ($file = readdir($dh)) - { - if (preg_match('/'."\.css$".'/i', $file) && $file != 'phpgw.css') - { - $list[] = substr($file,0,strpos($file,'.')); - } - } - closedir($dh); - } - if(!is_array($list)) - { - $dh = opendir(EGW_SERVER_ROOT . '/phpgwapi/themes'); - while ($file = readdir($dh)) - { - if (preg_match('/'."\.theme$".'/i', $file)) - { - $list[] = substr($file,0,strpos($file,'.')); - } - } - closedir($dh); - } - reset ($list); - return $list; - } - - /** - * List available templates - * - * @returns array alphabetically sorted list of templates - */ - function list_templates() - { - $list = array(); - $d = dir(EGW_SERVER_ROOT . '/phpgwapi/templates'); - while (($entry=$d->read())) - { - if ($entry != '..' && file_exists(EGW_SERVER_ROOT . '/phpgwapi/templates/' . $entry .'/class.'.$entry.'_framework.inc.php')) - { - $list[$entry]['name'] = $entry; - if (file_exists ($f = EGW_SERVER_ROOT . '/phpgwapi/templates/' . $entry . '/setup/setup.inc.php')) - { - include($f); - $list[$entry]['title'] = $GLOBALS['egw_info']['template'][$entry]['title']; - } - else - { - $list[$entry]['title'] = $entry; - } - } - } - $d->close(); - ksort($list); - - return $list; - } - /** * get template dir of an application * diff --git a/phpgwapi/inc/class.egw_framework.inc.php b/phpgwapi/inc/class.egw_framework.inc.php index 7b394b50fd..9d2ca4dba8 100644 --- a/phpgwapi/inc/class.egw_framework.inc.php +++ b/phpgwapi/inc/class.egw_framework.inc.php @@ -780,6 +780,78 @@ abstract class egw_framework return ''; } } + + /** + * List available themes + * + * Themes are css file in the template directory + * + * @param string $themes_dir='css' + */ + function list_themes() + { + $list = array(); + if (($dh = @opendir(EGW_SERVER_ROOT.$this->template_dir . SEP . 'css'))) + { + while (($file = readdir($dh))) + { + if (preg_match('/'."\.css$".'/i', $file)) + { + list($name) = explode('.',$file); + $list[$name] = $name; + } + } + closedir($dh); + } + return $list; + } + + /** + * List available templates + * + * @returns array alphabetically sorted list of templates + */ + static function list_templates() + { + $list = array(); + // templates packaged in the api + $d = dir(EGW_SERVER_ROOT . '/phpgwapi/templates'); + while (($entry=$d->read())) + { + if ($entry != '..' && file_exists(EGW_SERVER_ROOT . '/phpgwapi/templates/' . $entry .'/class.'.$entry.'_framework.inc.php')) + { + if (file_exists ($f = EGW_SERVER_ROOT . '/phpgwapi/templates/' . $entry . '/setup/setup.inc.php')) + { + include($f); + $list[$entry] = $GLOBALS['egw_info']['template'][$entry]['title']; + } + else + { + $list[$entry] = $entry; + } + } + } + $d->close(); + // templates packaged like apps in own directories (containing as setup/setup.inc.php file!) + $d = dir(EGW_SERVER_ROOT); + while (($entry=$d->read())) + { + if ($entry != '..' && !isset($GLOBALS['egw_info']['apps'][$entry]) && + file_exists(EGW_SERVER_ROOT . '/' . $entry .'/setup/setup.inc.php')) + { + include($f); + if (isset($GLOBALS['egw_info']['template'][$entry])) + { + $list[$entry] = $GLOBALS['egw_info']['template'][$entry]['title']; + } + } + } + $d->close(); + ksort($list); + + return $list; + } + } /** diff --git a/preferences/inc/class.preferences_hooks.inc.php b/preferences/inc/class.preferences_hooks.inc.php index 46c87133a1..e6e8b616d9 100644 --- a/preferences/inc/class.preferences_hooks.inc.php +++ b/preferences/inc/class.preferences_hooks.inc.php @@ -21,19 +21,6 @@ class preferences_hooks */ static public function settings($hook_data) { - // Setup some values to fill the array of this app's settings below - $templates = common::list_templates(); - foreach($templates as $var => $value) - { - $_templates[$var] = $templates[$var]['title']; - } - - $themes = common::list_themes(); - foreach($themes as $value) - { - $_themes[$value] = $value; - } - $navbar_format = array( 'icons' => lang('Icons only'), 'icons_and_text' => lang('Icons and text'), @@ -135,7 +122,7 @@ class preferences_hooks 'type' => 'select', 'label' => 'Interface/Template Selection', 'name' => 'template_set', - 'values' => $_templates, + 'values' => egw_framework::list_templates(), 'help' => 'A template defines the layout of eGroupWare and it contains icons for each application.', 'xmlrpc' => True, 'admin' => False, @@ -145,7 +132,7 @@ class preferences_hooks 'type' => 'select', 'label' => 'Theme (colors/fonts) Selection', 'name' => 'theme', - 'values' => $_themes, + 'values' => isset($GLOBALS['egw']->framework) ? $GLOBALS['egw']->framework->list_themes() : array(), 'help' => 'A theme defines the colors and fonts used by the template.', 'xmlrpc' => True, 'admin' => False,