diff options
author | plegall <plg@piwigo.org> | 2010-03-13 00:00:52 +0000 |
---|---|---|
committer | plegall <plg@piwigo.org> | 2010-03-13 00:00:52 +0000 |
commit | 14778ce673277f2df41f963aa70df1cbed427294 (patch) | |
tree | 8c723d4d9827876dbf19d2bd581405fc50910860 /include | |
parent | c396f08708d431c6f7e8656eaca4fd8e440fdd39 (diff) |
feature 1502: based on Dotclear model, P@t has reorganized the way Piwigo
manages template/theme in a simpler "theme only level" architecture. It
supports multiple level inheritance.
git-svn-id: http://piwigo.org/svn/trunk@5123 68402e56-0260-453c-a942-63ccdbb3a9ee
Diffstat (limited to '')
-rw-r--r-- | include/common.inc.php | 8 | ||||
-rw-r--r-- | include/config_default.inc.php | 5 | ||||
-rw-r--r-- | include/functions.inc.php | 22 | ||||
-rw-r--r-- | include/functions_mail.inc.php | 76 | ||||
-rw-r--r-- | include/functions_user.inc.php | 10 | ||||
-rw-r--r-- | include/template.class.php | 64 |
6 files changed, 96 insertions, 89 deletions
diff --git a/include/common.inc.php b/include/common.inc.php index 814eaaf40..9a5ccac90 100644 --- a/include/common.inc.php +++ b/include/common.inc.php @@ -158,15 +158,11 @@ if (is_a_guest()) if (( defined('IN_ADMIN') and IN_ADMIN ) or (defined('PWG_HELP') and PWG_HELP)) {// Admin template - list($user['admin_template'], $user['admin_theme']) = - explode ('/', $conf['admin_layout']); - $template = new Template(PHPWG_ROOT_PATH.'admin/template/' - . $user['admin_template'], $user['admin_theme'] ); + $template = new Template(PHPWG_ROOT_PATH.'admin/themes', $conf['admin_theme']); } else { // Classic template - $template = new Template(PHPWG_ROOT_PATH.'template/' - . $user['template'], $user['theme'] ); + $template = new Template(PHPWG_ROOT_PATH.'themes', $user['theme'] ); } if (isset($user['internal_status']['guest_must_be_guest']) diff --git a/include/config_default.inc.php b/include/config_default.inc.php index 0ad708777..dcf94dc84 100644 --- a/include/config_default.inc.php +++ b/include/config_default.inc.php @@ -335,6 +335,9 @@ $conf['insensitive_case_logon'] = false; // 'filename' $conf['uniqueness_mode'] = 'md5sum'; +// Define default theme for your gallery +$conf['default_theme'] = 'Sylvia'; + // +-----------------------------------------------------------------------+ // | metadata | // +-----------------------------------------------------------------------+ @@ -676,7 +679,7 @@ $conf['rss_feed_author'] = 'Piwigo notifier'; // | Set admin layout | // +-----------------------------------------------------------------------+ -$conf['admin_layout'] = 'goto/roma'; +$conf['admin_theme'] = 'roma'; // should we load the active plugins ? true=Yes, false=No $conf['enable_plugins']=true; diff --git a/include/functions.inc.php b/include/functions.inc.php index 6659d582e..7eee41d57 100644 --- a/include/functions.inc.php +++ b/include/functions.inc.php @@ -611,12 +611,11 @@ function redirect_html( $url , $msg = '', $refresh_time = 0) load_language('common.lang'); trigger_action('loading_lang'); load_language('local.lang', '', array('no_fallback'=>true) ); - list($tmpl, $thm) = explode('/', get_default_template()); - $template = new Template(PHPWG_ROOT_PATH.'template/'.$tmpl, $thm); + $template = new Template(PHPWG_ROOT_PATH.'themes', get_default_theme()); } else { - $template = new Template(PHPWG_ROOT_PATH.'template/'.$user['template'], $user['theme']); + $template = new Template(PHPWG_ROOT_PATH.'themes', $user['theme']); } if (empty($msg)) @@ -710,24 +709,21 @@ function url_is_remote($url) } /** - * returns available template/theme + * returns available themes */ function get_pwg_themes() { global $conf; $themes = array(); - $template_dir = PHPWG_ROOT_PATH.'template'; + $template_dir = PHPWG_ROOT_PATH.'themes'; - foreach (get_dirs($template_dir) as $template) + foreach (get_dirs($template_dir) as $theme) { - if ( $template != 'default' ) - { - foreach (get_dirs($template_dir.'/'.$template.'/theme') as $theme) - { - array_push($themes, $template.'/'.$theme); - } - } + if ( $theme != 'default' ) + { + array_push($themes, $theme); + } } // plugins want remove some themes based on user status maybe? diff --git a/include/functions_mail.inc.php b/include/functions_mail.inc.php index c550d6857..b55d55366 100644 --- a/include/functions_mail.inc.php +++ b/include/functions_mail.inc.php @@ -152,12 +152,12 @@ function get_strict_email_list($email_list) /** * Returns an completed array template/theme - * completed with get_default_template() + * completed with get_default_theme() * * @params: * - args: incompleted array of template/theme - * o template: template to use [default get_default_template()] - * o theme: template to use [default get_default_template()] + * o template: template to use [default get_default_theme()] + * o theme: template to use [default get_default_theme()] */ function get_array_template_theme($args = array()) { @@ -167,7 +167,7 @@ function get_array_template_theme($args = array()) if (empty($args['template']) or empty($args['theme'])) { - list($res['template'], $res['theme']) = explode('/', get_default_template()); + list($res['template'], $res['theme']) = explode('/', get_default_theme()); } if (!empty($args['template'])) @@ -189,15 +189,18 @@ function get_array_template_theme($args = array()) * @params: * - email_format: mail format * - args: function params of mail function: - * o template: template to use [default get_default_template()] - * o theme: template to use [default get_default_template()] + * o template: template to use [default get_default_theme()] + * o theme: template to use [default get_default_theme()] */ -function & get_mail_template($email_format, $args = array()) +function & get_mail_template($email_format, $theme='') { - $args = get_array_template_theme($args); + if (empty($theme)) + { + $theme = get_default_theme(); + } + + $mail_template = new Template(PHPWG_ROOT_PATH.'themes', $theme, 'template/mail/'.$email_format); - $mail_template = new Template(PHPWG_ROOT_PATH.'template/'.$args['template'], $args['theme']); - $mail_template->set_template_dir(PHPWG_ROOT_PATH.'template/'.$args['template'].'/mail/'.$email_format); return $mail_template; } @@ -417,7 +420,7 @@ function pwg_mail_group( $query = ' SELECT - distinct language, template + distinct language, theme FROM '.USER_GROUP_TABLE.' as ug INNER JOIN '.USERS_TABLE.' as u ON '.$conf['user_fields']['id'].' = ug.user_id @@ -442,8 +445,6 @@ WHERE $list = array(); while ($row = pwg_db_fetch_assoc($result)) { - $row['template_theme'] = $row['template']; - list($row['template'], $row['theme']) = explode('/', $row['template_theme']); $list[] = $row; } @@ -461,7 +462,7 @@ WHERE '.$conf['user_fields']['email'].' IS NOT NULL AND group_id = '.$group_id.' AND language = \''.$elem['language'].'\' - AND template = \''.$elem['template_theme'].'\' + AND theme = \''.$elem['theme'].'\' ;'; $result = pwg_query($query); @@ -481,7 +482,7 @@ WHERE { switch_lang_to($elem['language']); - $mail_template = get_mail_template($email_format, $elem); + $mail_template = get_mail_template($email_format, $elem['theme']); $mail_template->set_filename($tpl_shortname, $tpl_shortname.'.tpl'); $mail_template->assign( @@ -497,7 +498,6 @@ WHERE 'email_format' => $email_format, 'content' => $mail_template->parse($tpl_shortname, true), 'content_format' => $email_format, - 'template' => $elem['template'], 'theme' => $elem['theme'] ) ) and $return; @@ -524,8 +524,7 @@ WHERE * o content: content of mail [default value ''] * o content_format: format of mail content [default value 'text/plain'] * o email_format: global mail format [default value $conf_mail['default_email_format']] - * o template: template to use [default get_default_template()] - * o theme: template to use [default get_default_template()] + * o theme: template to use [default get_default_theme()] * * @return boolean (Ok or not) */ @@ -584,7 +583,10 @@ function pwg_mail($to, $args = array()) $args['Bcc'][] = $conf_mail['formated_email_webmaster']; } - $args = array_merge($args, get_array_template_theme($args)); + if (empty($args['theme'])) + { + $args['theme'] = get_default_theme(); + } $headers = 'From: '.$args['from']."\n"; $headers.= 'Reply-To: '.$args['from']."\n"; @@ -617,19 +619,19 @@ function pwg_mail($to, $args = array()) foreach (array_unique($content_type_list) as $content_type) { // key compose of indexes witch allow ti cache mail data - $cache_key = $content_type.'-'.$lang_info['code'].'-'.$args['template'].'-'.$args['theme']; + $cache_key = $content_type.'-'.$lang_info['code'].'-'.$args['theme']; if (!isset($conf_mail[$cache_key])) { - if (!isset($conf_mail[$cache_key]['template'])) + if (!isset($conf_mail[$cache_key]['theme'])) { - $conf_mail[$cache_key]['template'] = get_mail_template($content_type); + $conf_mail[$cache_key]['theme'] = get_mail_template($content_type); } - $conf_mail[$cache_key]['template']->set_filename('mail_header', 'header.tpl'); - $conf_mail[$cache_key]['template']->set_filename('mail_footer', 'footer.tpl'); + $conf_mail[$cache_key]['theme']->set_filename('mail_header', 'header.tpl'); + $conf_mail[$cache_key]['theme']->set_filename('mail_footer', 'footer.tpl'); - $conf_mail[$cache_key]['template']->assign( + $conf_mail[$cache_key]['theme']->assign( array( //Header 'BOUNDARY_KEY' => $conf_mail['boundary_key'], @@ -652,36 +654,37 @@ function pwg_mail($to, $args = array()) if ($content_type == 'text/html') { - if (is_file($conf_mail[$cache_key]['template']->get_template_dir().'/global-mail-css.tpl')) + /* + if (is_file($conf_mail[$cache_key]['theme']->get_template_dir().'/global-mail-css.tpl')) { - $conf_mail[$cache_key]['template']->set_filename('css', 'global-mail-css.tpl'); - $conf_mail[$cache_key]['template']->assign_var_from_handle('GLOBAL_MAIL_CSS', 'css'); + $conf_mail[$cache_key]['theme']->set_filename('css', 'global-mail-css.tpl'); + $conf_mail[$cache_key]['theme']->assign_var_from_handle('GLOBAL_MAIL_CSS', 'css'); } + */ - $root_abs_path = dirname(dirname(__FILE__)); - - $file = $root_abs_path.'/template/'.$args['template'].'/theme/'.$args['theme'].'/mail-css.tpl'; + $file = PHPWG_ROOT_PATH.'themes/'.$args['theme'].'/mail-css.tpl'; if (is_file($file)) { - $conf_mail[$cache_key]['template']->set_filename('css', $file); - $conf_mail[$cache_key]['template']->assign_var_from_handle('MAIL_CSS', 'css'); + $conf_mail[$cache_key]['theme']->set_filename('css', realpath($file)); + $conf_mail[$cache_key]['theme']->assign_var_from_handle('MAIL_CSS', 'css'); } - + /* $file = $root_abs_path.'/template-common/local-mail-css.tpl'; if (is_file($file)) { $conf_mail[$cache_key]['template']->set_filename('css', $file); $conf_mail[$cache_key]['template']->assign_var_from_handle('LOCAL_MAIL_CSS', 'css'); } + */ } // what are displayed on the header of each mail ? $conf_mail[$cache_key]['header'] = - $conf_mail[$cache_key]['template']->parse('mail_header', true); + $conf_mail[$cache_key]['theme']->parse('mail_header', true); // what are displayed on the footer of each mail ? $conf_mail[$cache_key]['footer'] = - $conf_mail[$cache_key]['template']->parse('mail_footer', true); + $conf_mail[$cache_key]['theme']->parse('mail_footer', true); } // Header @@ -714,7 +717,6 @@ function pwg_mail($to, $args = array()) $content.= "\n".'-----='.$conf_mail['boundary_key'].'--'."\n"; } - //~ // Close boundary //~ $content.= "\n".'-----='.$conf_mail['boundary_key'].'--'."\n"; diff --git a/include/functions_user.inc.php b/include/functions_user.inc.php index 3a4d17549..f3eb0b172 100644 --- a/include/functions_user.inc.php +++ b/include/functions_user.inc.php @@ -245,7 +245,11 @@ function build_user( $user_id, $use_cache ) // calculation of the number of picture to display per page $user['nb_image_page'] = $user['nb_image_line'] * $user['nb_line_page']; - list($user['template'], $user['theme']) = explode('/', $user['template']); + // Check user theme + if (!file_exists(PHPWG_ROOT_PATH.'themes/'.$user['theme'].'/themeconf.inc.php')) + { + $user['theme'] = $conf['default_theme']; + } return $user; } @@ -841,9 +845,9 @@ function get_default_user_value($value_name, $sos_value) * Returns the default template value * */ -function get_default_template() +function get_default_theme() { - return get_default_user_value('template', PHPWG_DEFAULT_TEMPLATE); + return get_default_user_value('theme', PHPWG_DEFAULT_TEMPLATE); } /* diff --git a/include/template.class.php b/include/template.class.php index 2fb4ac7d8..c31c50d2e 100644 --- a/include/template.class.php +++ b/include/template.class.php @@ -52,7 +52,7 @@ class Template { // used by html_head smarty block to add content before </head> var $html_head_elements = array(); - function Template($root = ".", $theme= "") + function Template($root = ".", $theme= "", $path = "template") { global $conf, $lang_info; @@ -77,16 +77,14 @@ class Template { $this->smarty->register_prefilter( array('Template', 'prefilter_language') ); } + $this->smarty->template_dir = array(); if ( !empty($theme) ) { - include($root.'/theme/'.$theme.'/themeconf.inc.php'); - $this->smarty->assign('themeconf', $themeconf); + $this->set_theme($root, $theme, $path); } $this->smarty->assign('lang_info', $lang_info); - $this->set_template_dir($root); - if (!defined('IN_ADMIN') and isset($conf['extents_for_templates'])) { $tpl_extents = unserialize($conf['extents_for_templates']); @@ -95,32 +93,38 @@ class Template { } /** - * Sets the template root directory for this Template object. - * Revised from Piwigo 2.1 to add modeling support + * Load theme's parameters. */ + function set_theme($root, $theme, $path) + { + $this->set_template_dir($root.'/'.$theme.'/'.$path); + + include($root.'/'.$theme.'/themeconf.inc.php'); + + if (isset($themeconf['parent'])) + { + $this->set_theme($root, $themeconf['parent'], $path); + } + + $tpl_var = array('name' => $themeconf['theme']); + if (file_exists($root.'/'.$theme.'/local_head.tpl')) + { + $tpl_var['local_head'] = realpath($root.'/'.$theme.'/local_head.tpl'); + } + $this->smarty->append('themes', $tpl_var); + $this->smarty->append('themeconf', $themeconf, true); + } + function set_template_dir($dir) { - $modeling = $this->get_themeconf('modeling'); - if (!defined('IN_ADMIN') and ($modeling !== false)) - { // Modeling is active only on gallery side and never in admin - // Set the normal directory - $this->smarty->template_dir = array($dir); - // Modeling by theme parameter - $model = './template/' . $modeling; - if ( $model != './template/' and is_dir($model)) - { - $this->smarty->template_dir[] = $model; - } - // Default template directory - $this->smarty->template_dir[] = './template/default'; - } - else - { - $this->smarty->template_dir = $dir; - } - $real_dir = realpath($dir); - $compile_id = crc32( $real_dir===false ? $dir : $real_dir); - $this->smarty->compile_id = base_convert($compile_id, 10, 36 ); + $this->smarty->template_dir[] = $dir; + + if (!isset($this->smarty->compile_id)) + { + $real_dir = realpath($dir); + $compile_id = crc32( $real_dir===false ? $dir : $real_dir); + $this->smarty->compile_id = base_convert($compile_id, 10, 36 ); + } } /** @@ -196,6 +200,8 @@ class Template { */ function set_extents($filename_array, $dir='', $overwrite=true) { + global $user; + if (!is_array($filename_array)) { return false; @@ -220,7 +226,7 @@ class Template { } if ((stripos(implode('',array_keys($_GET)), '/'.$param) !== false or $param == 'N/A') - and (preg_match('/'.preg_quote($tpl,'/').'$/', $this->get_template_dir()) or $tpl == 'N/A') + and ($tpl == $user['theme'] or $tpl == 'N/A') and (!isset($this->extents[$handle]) or $overwrite) and file_exists($dir . $filename)) { |