From eda1d40861fb5a2b74e7e5ade618cc9fa83cafd1 Mon Sep 17 00:00:00 2001 From: Henry Sudhof Date: Mon, 28 Jul 2008 14:24:37 +0000 Subject: Okay. Frozen, we never said anything about it being permafrost. Also, this is not 100% tested, expect troubel with store_db (I'm waiting for the bug reports) git-svn-id: file:///svn/phpbb/branches/phpBB-3_0_0@8697 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/includes/template.php | 129 ++++++++++++++++++++++++++++++++++++-------- 1 file changed, 108 insertions(+), 21 deletions(-) (limited to 'phpBB/includes/template.php') diff --git a/phpBB/includes/template.php b/phpBB/includes/template.php index 2e60beb658..d17ad55691 100644 --- a/phpBB/includes/template.php +++ b/phpBB/includes/template.php @@ -36,6 +36,9 @@ class template var $cachepath = ''; var $files = array(); var $filename = array(); + var $files_inherit = array(); + var $files_template = array(); + var $inherit_root = ''; // this will hash handle names to the compiled/uncompiled code for that handle. var $compiled_code = array(); @@ -52,6 +55,11 @@ class template { $this->root = $phpbb_root_path . 'styles/' . $user->theme['template_path'] . '/template'; $this->cachepath = $phpbb_root_path . 'cache/tpl_' . $user->theme['template_path'] . '_'; + + if ($user->theme['template_inherits_id']) + { + $this->inherit_root = $phpbb_root_path . 'styles/' . $user->theme['template_inherit_path'] . '/template'; + } } else { @@ -88,7 +96,6 @@ class template { return false; } - foreach ($filename_array as $handle => $filename) { if (empty($filename)) @@ -98,8 +105,13 @@ class template $this->filename[$handle] = $filename; $this->files[$handle] = $this->root . '/' . $filename; + + if ($this->inherit_root) + { + $this->files_inherit[$handle] = $this->inherit_root . '/' . $filename; + } } - + return true; } @@ -197,7 +209,7 @@ class template return true; } - + /** * Load a compiled template if possible, if not, recompile it * @access private @@ -207,9 +219,24 @@ class template global $user, $phpEx, $config; $filename = $this->cachepath . str_replace('/', '.', $this->filename[$handle]) . '.' . $phpEx; - - $recompile = (($config['load_tplcompile'] && @filemtime($filename) < filemtime($this->files[$handle])) || !file_exists($filename) || @filesize($filename) === 0) ? true : false; - + $this->files_template[$handle] = $user->theme['template_id']; + + $recompile = false; + if (!file_exists($filename) || @filesize($filename) === 0) + { + $recompile = true; + } + else if ($config['load_tplcompile']) + { + // No way around it: we need to check inheritance here + if ($user->theme['template_inherits_id'] && !file_exists($this->files[$handle])) + { + $this->files[$handle] = $this->files_inherit[$handle]; + $this->files_template[$handle] = $user->theme['template_inherits_id']; + } + $recompile = (@filemtime($filename) < filemtime($this->files[$handle])) ? true : false; + } + // Recompile page if the original template is newer, otherwise load the compiled version if (!$recompile) { @@ -222,7 +249,14 @@ class template { include($phpbb_root_path . 'includes/functions_template.' . $phpEx); } - + + // Inheritance - we point to another template file for this one. Equality is also used for store_db + if (isset($user->theme['template_inherits_id']) && $user->theme['template_inherits_id'] && !file_exists($this->files[$handle])) + { + $this->files[$handle] = $this->files_inherit[$handle]; + $this->files_template[$handle] = $user->theme['template_inherits_id']; + } + $compile = new template_compile($this); // If we don't have a file assigned to this handle, die. @@ -240,28 +274,70 @@ class template if (isset($user->theme['template_storedb']) && $user->theme['template_storedb']) { - $sql = 'SELECT * + $rows = array(); + $ids = array(); + // Inheritance + if (isset($user->theme['template_inherits_id']) && $user->theme['template_inherits_id']) + { + $ids[] = $user->theme['template_inherits_id']; + } + $ids[] = $user->theme['template_id']; + + foreach ($ids as $id) + { + $sql = 'SELECT * FROM ' . STYLES_TEMPLATE_DATA_TABLE . ' - WHERE template_id = ' . $user->theme['template_id'] . " + WHERE template_id = ' . $id . " AND (template_filename = '" . $db->sql_escape($this->filename[$handle]) . "' OR template_included " . $db->sql_like_expression($db->any_char . $this->filename[$handle] . ':' . $db->any_char) . ')'; - $result = $db->sql_query($sql); - $row = $db->sql_fetchrow($result); - - if ($row) + + $result = $db->sql_query($sql); + while ($row = $db->sql_fetchrow($result)) + { + $rows[$row['template_filename']] = $row; + } + $db->sql_freeresult($result); + } + + if (sizeof($rows)) { - do + foreach ($rows as $row) { - if ($row['template_mtime'] < filemtime($phpbb_root_path . 'styles/' . $user->theme['template_path'] . '/template/' . $row['template_filename'])) + $file = $this->root . '/' . $row['template_filename']; + $force_reload = false; + if ($row['template_id'] != $user->theme['template_id']) + { + // make sure that we are not overlooking a file not in the db yet + if (isset($user->theme['template_inherits_id']) && $user->theme['template_inherits_id'] && !file_exists($file)) + { + $file = $this->inherit_root . '/' . $row['template_filename']; + $this->files[$row['template_filename']] = $file; + $this->files_inherit[$row['template_filename']] = $file; + $this->files_template[$row['template_filename']] = $user->theme['template_inherits_id']; + } + else if (isset($user->theme['template_inherits_id']) && $user->theme['template_inherits_id']) + { + // Ok, we have a situation. There is a file in the subtemplate, but nothing in the DB. We have to fix that. + $force_reload = true; + $this->files_template[$row['template_filename']] = $user->theme['template_inherits_id']; + } + } + else + { + $this->files_template[$row['template_filename']] = $user->theme['template_id']; + } + + if ($force_reload || $row['template_mtime'] < filemtime($file)) { if ($row['template_filename'] == $this->filename[$handle]) { - $compile->_tpl_load_file($handle); + $compile->_tpl_load_file($handle, true); } else { - $this->files[$row['template_filename']] = $this->root . '/' . $row['template_filename']; - $compile->_tpl_load_file($row['template_filename']); + $this->files[$row['template_filename']] = $file; + $this->filename[$row['template_filename']] = $row['template_filename']; + $compile->_tpl_load_file($row['template_filename'], true); unset($this->compiled_code[$row['template_filename']]); unset($this->files[$row['template_filename']]); unset($this->filename[$row['template_filename']]); @@ -284,15 +360,22 @@ class template } } } - while ($row = $db->sql_fetchrow($result)); } else { + $file = $this->root . '/' . $row['template_filename']; + + if (isset($user->theme['template_inherits_id']) && $user->theme['template_inherits_id'] && !file_exists($file)) + { + $file = $this->inherit_root . '/' . $row['template_filename']; + $this->files[$row['template_filename']] = $file; + $this->files_inherit[$row['template_filename']] = $file; + $this->files_template[$row['template_filename']] = $user->theme['template_inherits_id']; + } // Try to load from filesystem and instruct to insert into the styles table... $compile->_tpl_load_file($handle, true); return false; } - $db->sql_freeresult($result); return false; } @@ -512,8 +595,12 @@ class template $handle = $filename; $this->filename[$handle] = $filename; $this->files[$handle] = $this->root . '/' . $filename; + if ($this->inherit_root) + { + $this->files_inherit[$handle] = $this->inherit_root . '/' . $filename; + } - $filename = $this->_tpl_load($handle); + $filename = $this->_tpl_load($handle); if ($include) { -- cgit v1.2.1 From 2bf9ea373b22dd8e2481085a98548599c134f570 Mon Sep 17 00:00:00 2001 From: Meik Sievertsen Date: Fri, 26 Sep 2008 13:09:56 +0000 Subject: Fix problems with styles using an underscore within the filename. (Bug #34315) - Also display inheriting template on style installation (previously, it was only displayed on template installs) - Fixes undefined variable in error message if inheriting style does not work - Fixes export of styles/templates and correctly set inherit_from variable git-svn-id: file:///svn/phpbb/branches/phpBB-3_0_0@8943 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/includes/template.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'phpBB/includes/template.php') diff --git a/phpBB/includes/template.php b/phpBB/includes/template.php index d17ad55691..0098c484bd 100644 --- a/phpBB/includes/template.php +++ b/phpBB/includes/template.php @@ -54,7 +54,7 @@ class template if (file_exists($phpbb_root_path . 'styles/' . $user->theme['template_path'] . '/template')) { $this->root = $phpbb_root_path . 'styles/' . $user->theme['template_path'] . '/template'; - $this->cachepath = $phpbb_root_path . 'cache/tpl_' . $user->theme['template_path'] . '_'; + $this->cachepath = $phpbb_root_path . 'cache/tpl_' . str_replace('_', '-', $user->theme['template_path']) . '_'; if ($user->theme['template_inherits_id']) { @@ -80,7 +80,7 @@ class template global $phpbb_root_path; $this->root = $template_path; - $this->cachepath = $phpbb_root_path . 'cache/ctpl_' . $template_name . '_'; + $this->cachepath = $phpbb_root_path . 'cache/ctpl_' . str_replace('_', '-', $template_name) . '_'; return true; } -- cgit v1.2.1 From 7d605da65bda85c26d13c810bbfc051b3495b76d Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 19 Jun 2009 22:07:27 +0000 Subject: Fix bug #45805 - INCLUDEPHP not depending on phpbb_root_path Authorised by: acydburn git-svn-id: file:///svn/phpbb/branches/phpBB-3_0_0@9633 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/includes/template.php | 47 +++++++++++++++++++++++++++++++-------------- 1 file changed, 33 insertions(+), 14 deletions(-) (limited to 'phpBB/includes/template.php') diff --git a/phpBB/includes/template.php b/phpBB/includes/template.php index 0098c484bd..0263783849 100644 --- a/phpBB/includes/template.php +++ b/phpBB/includes/template.php @@ -55,7 +55,7 @@ class template { $this->root = $phpbb_root_path . 'styles/' . $user->theme['template_path'] . '/template'; $this->cachepath = $phpbb_root_path . 'cache/tpl_' . str_replace('_', '-', $user->theme['template_path']) . '_'; - + if ($user->theme['template_inherits_id']) { $this->inherit_root = $phpbb_root_path . 'styles/' . $user->theme['template_inherit_path'] . '/template'; @@ -105,13 +105,13 @@ class template $this->filename[$handle] = $filename; $this->files[$handle] = $this->root . '/' . $filename; - + if ($this->inherit_root) { $this->files_inherit[$handle] = $this->inherit_root . '/' . $filename; } } - + return true; } @@ -209,7 +209,7 @@ class template return true; } - + /** * Load a compiled template if possible, if not, recompile it * @access private @@ -220,7 +220,7 @@ class template $filename = $this->cachepath . str_replace('/', '.', $this->filename[$handle]) . '.' . $phpEx; $this->files_template[$handle] = $user->theme['template_id']; - + $recompile = false; if (!file_exists($filename) || @filesize($filename) === 0) { @@ -236,7 +236,7 @@ class template } $recompile = (@filemtime($filename) < filemtime($this->files[$handle])) ? true : false; } - + // Recompile page if the original template is newer, otherwise load the compiled version if (!$recompile) { @@ -249,14 +249,14 @@ class template { include($phpbb_root_path . 'includes/functions_template.' . $phpEx); } - + // Inheritance - we point to another template file for this one. Equality is also used for store_db if (isset($user->theme['template_inherits_id']) && $user->theme['template_inherits_id'] && !file_exists($this->files[$handle])) { $this->files[$handle] = $this->files_inherit[$handle]; $this->files_template[$handle] = $user->theme['template_inherits_id']; } - + $compile = new template_compile($this); // If we don't have a file assigned to this handle, die. @@ -282,7 +282,7 @@ class template $ids[] = $user->theme['template_inherits_id']; } $ids[] = $user->theme['template_id']; - + foreach ($ids as $id) { $sql = 'SELECT * @@ -290,7 +290,7 @@ class template WHERE template_id = ' . $id . " AND (template_filename = '" . $db->sql_escape($this->filename[$handle]) . "' OR template_included " . $db->sql_like_expression($db->any_char . $this->filename[$handle] . ':' . $db->any_char) . ')'; - + $result = $db->sql_query($sql); while ($row = $db->sql_fetchrow($result)) { @@ -298,7 +298,7 @@ class template } $db->sql_freeresult($result); } - + if (sizeof($rows)) { foreach ($rows as $row) @@ -326,7 +326,7 @@ class template { $this->files_template[$row['template_filename']] = $user->theme['template_id']; } - + if ($force_reload || $row['template_mtime'] < filemtime($file)) { if ($row['template_filename'] == $this->filename[$handle]) @@ -468,7 +468,7 @@ class template { unset($this->_tpldata[$blockname][($s_row_count - 1)]['S_LAST_ROW']); } - + // Add a new iteration to this block with the variable assignments we were given. $this->_tpldata[$blockname][] = $vararray; } @@ -511,7 +511,7 @@ class template // Nested blocks are not supported return false; } - + // Change key to zero (change first position) if false and to last position if true if ($key === false || $key === true) { @@ -614,6 +614,25 @@ class template eval(' ?>' . $this->compiled_code[$handle] . '_php_include(): File ' . htmlspecialchars($file) . ' does not exist or is empty'; + return; + } + include($file); + } } ?> \ No newline at end of file -- cgit v1.2.1 From b613781d3af6d7c5e5d9d0fa1592e78b54647c0f Mon Sep 17 00:00:00 2001 From: Meik Sievertsen Date: Tue, 21 Jul 2009 10:58:31 +0000 Subject: Preserve newlines in template files (one newline had been always dropped after a template variable due to PHP's handling of closing tags) git-svn-id: file:///svn/phpbb/branches/phpBB-3_0_0@9811 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/includes/template.php | 2 ++ 1 file changed, 2 insertions(+) (limited to 'phpBB/includes/template.php') diff --git a/phpBB/includes/template.php b/phpBB/includes/template.php index 0263783849..7cf865072f 100644 --- a/phpBB/includes/template.php +++ b/phpBB/includes/template.php @@ -82,6 +82,8 @@ class template $this->root = $template_path; $this->cachepath = $phpbb_root_path . 'cache/ctpl_' . str_replace('_', '-', $template_name) . '_'; + $this->_rootref = &$this->_tpldata['.'][0]; + return true; } -- cgit v1.2.1 From 89332c00b7198b5bd07fdb98b21d4734c300da15 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 24 Jul 2009 08:47:10 +0000 Subject: Fix Bug #40515 - Fix set_custom_template for database-stored styles Authorised by: AcydBurn git-svn-id: file:///svn/phpbb/branches/phpBB-3_0_0@9839 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/includes/template.php | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'phpBB/includes/template.php') diff --git a/phpBB/includes/template.php b/phpBB/includes/template.php index 7cf865072f..fa7cf437fd 100644 --- a/phpBB/includes/template.php +++ b/phpBB/includes/template.php @@ -39,6 +39,8 @@ class template var $files_inherit = array(); var $files_template = array(); var $inherit_root = ''; + var $orig_tpl_storedb = 'undefined'; + var $orig_tpl_inherits_id = 'undefined'; // this will hash handle names to the compiled/uncompiled code for that handle. var $compiled_code = array(); @@ -55,6 +57,16 @@ class template { $this->root = $phpbb_root_path . 'styles/' . $user->theme['template_path'] . '/template'; $this->cachepath = $phpbb_root_path . 'cache/tpl_' . str_replace('_', '-', $user->theme['template_path']) . '_'; + if ($this->orig_tpl_storedb == 'undefined') + { + $this->orig_tpl_storedb = $user->theme['template_storedb']; + } + if ($this->orig_tpl_inherits_id == 'undefined') + { + $this->orig_tpl_inherits_id = $user->theme['template_inherits_id']; + } + $user->theme['template_storedb'] = $this->orig_tpl_storedb; + $user->theme['template_inherits_id'] = $this->orig_tpl_inherits_id; if ($user->theme['template_inherits_id']) { @@ -77,10 +89,12 @@ class template */ function set_custom_template($template_path, $template_name) { - global $phpbb_root_path; + global $phpbb_root_path, $user; $this->root = $template_path; $this->cachepath = $phpbb_root_path . 'cache/ctpl_' . str_replace('_', '-', $template_name) . '_'; + $user->theme['template_storedb'] = false; + $user->theme['template_inherits_id'] = false; $this->_rootref = &$this->_tpldata['.'][0]; -- cgit v1.2.1 From b902fc20ae78438af7eb44e9b1f078cdcc213e16 Mon Sep 17 00:00:00 2001 From: Chris Smith Date: Sat, 25 Jul 2009 10:16:13 +0000 Subject: Small change to r9839 git-svn-id: file:///svn/phpbb/branches/phpBB-3_0_0@9847 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/includes/template.php | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'phpBB/includes/template.php') diff --git a/phpBB/includes/template.php b/phpBB/includes/template.php index fa7cf437fd..fece30e4cd 100644 --- a/phpBB/includes/template.php +++ b/phpBB/includes/template.php @@ -39,8 +39,8 @@ class template var $files_inherit = array(); var $files_template = array(); var $inherit_root = ''; - var $orig_tpl_storedb = 'undefined'; - var $orig_tpl_inherits_id = 'undefined'; + var $orig_tpl_storedb; + var $orig_tpl_inherits_id; // this will hash handle names to the compiled/uncompiled code for that handle. var $compiled_code = array(); @@ -57,14 +57,17 @@ class template { $this->root = $phpbb_root_path . 'styles/' . $user->theme['template_path'] . '/template'; $this->cachepath = $phpbb_root_path . 'cache/tpl_' . str_replace('_', '-', $user->theme['template_path']) . '_'; - if ($this->orig_tpl_storedb == 'undefined') + + if ($this->orig_tpl_storedb === null) { $this->orig_tpl_storedb = $user->theme['template_storedb']; } - if ($this->orig_tpl_inherits_id == 'undefined') + + if ($this->orig_tpl_inherits_id === null) { $this->orig_tpl_inherits_id = $user->theme['template_inherits_id']; } + $user->theme['template_storedb'] = $this->orig_tpl_storedb; $user->theme['template_inherits_id'] = $this->orig_tpl_inherits_id; -- cgit v1.2.1 From edc5061f1df0fd3ce6f307b91f309a52e037cf73 Mon Sep 17 00:00:00 2001 From: Meik Sievertsen Date: Thu, 20 Aug 2009 14:53:25 +0000 Subject: Check for valid $template_path in includes/template.php - Bug #50055 git-svn-id: file:///svn/phpbb/branches/phpBB-3_0_0@10036 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/includes/template.php | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'phpBB/includes/template.php') diff --git a/phpBB/includes/template.php b/phpBB/includes/template.php index fece30e4cd..80434aca4c 100644 --- a/phpBB/includes/template.php +++ b/phpBB/includes/template.php @@ -94,6 +94,12 @@ class template { global $phpbb_root_path, $user; + // Make sure $template_path has no ending slash + if (substr($template_path, -1) == '/') + { + $template_path = substr($template_path, 0, -1); + } + $this->root = $template_path; $this->cachepath = $phpbb_root_path . 'cache/ctpl_' . str_replace('_', '-', $template_name) . '_'; $user->theme['template_storedb'] = false; -- cgit v1.2.1 From 697fd5a134bde47006f57b6dd8df4e2dec6a7f3d Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 16 Sep 2009 08:11:52 +0000 Subject: Fix #51285 and more issues with template inherence on set_custom_template Conflict introduced with r9839 and r9823 Authorised by: AcydBurn git-svn-id: file:///svn/phpbb/branches/phpBB-3_0_0@10150 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/includes/template.php | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'phpBB/includes/template.php') diff --git a/phpBB/includes/template.php b/phpBB/includes/template.php index 80434aca4c..648af61c00 100644 --- a/phpBB/includes/template.php +++ b/phpBB/includes/template.php @@ -90,7 +90,7 @@ class template * Set custom template location (able to use directory outside of phpBB) * @access public */ - function set_custom_template($template_path, $template_name) + function set_custom_template($template_path, $template_name, $template_mode = 'template') { global $phpbb_root_path, $user; @@ -102,8 +102,13 @@ class template $this->root = $template_path; $this->cachepath = $phpbb_root_path . 'cache/ctpl_' . str_replace('_', '-', $template_name) . '_'; - $user->theme['template_storedb'] = false; - $user->theme['template_inherits_id'] = false; + + // As the template-engine is used for more than the template (emails, etc.), we should not set $user->theme in all cases, but only on the real template. + if ($template_mode == 'template') + { + $user->theme['template_storedb'] = false; + $user->theme['template_inherits_id'] = false; + } $this->_rootref = &$this->_tpldata['.'][0]; -- cgit v1.2.1 From d5fe2e7db7bf84add27feaa4ac429346c539636c Mon Sep 17 00:00:00 2001 From: Meik Sievertsen Date: Mon, 5 Oct 2009 16:22:21 +0000 Subject: bugfix for non-existent handles and theme data (we really need to clean this up, template_files feels quite furry) git-svn-id: file:///svn/phpbb/branches/phpBB-3_0_0@10213 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/includes/template.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'phpBB/includes/template.php') diff --git a/phpBB/includes/template.php b/phpBB/includes/template.php index 648af61c00..7d09694e2a 100644 --- a/phpBB/includes/template.php +++ b/phpBB/includes/template.php @@ -248,8 +248,13 @@ class template { global $user, $phpEx, $config; + if (!isset($this->filename[$handle])) + { + trigger_error("template->_tpl_load(): No file specified for handle $handle", E_USER_ERROR); + } + $filename = $this->cachepath . str_replace('/', '.', $this->filename[$handle]) . '.' . $phpEx; - $this->files_template[$handle] = $user->theme['template_id']; + $this->files_template[$handle] = (isset($user->theme['template_id'])) ? $user->theme['template_id'] : 0; $recompile = false; if (!file_exists($filename) || @filesize($filename) === 0) -- cgit v1.2.1 From 9ccd209930bdbaff937911899e4e4f3b223d90ba Mon Sep 17 00:00:00 2001 From: Meik Sievertsen Date: Fri, 9 Oct 2009 11:12:37 +0000 Subject: fix bug #52605 - regression from r9811 git-svn-id: file:///svn/phpbb/branches/phpBB-3_0_0@10217 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/includes/template.php | 1 + 1 file changed, 1 insertion(+) (limited to 'phpBB/includes/template.php') diff --git a/phpBB/includes/template.php b/phpBB/includes/template.php index 7d09694e2a..af5c9d3a47 100644 --- a/phpBB/includes/template.php +++ b/phpBB/includes/template.php @@ -152,6 +152,7 @@ class template function destroy() { $this->_tpldata = array('.' => array(0 => array())); + $this->_rootref = &$this->_tpldata['.'][0]; } /** -- cgit v1.2.1 From 6e31ce85733a3269261e005a90d0291bf6e0a36b Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Tue, 26 Jan 2010 16:52:46 +0000 Subject: Do not store email templates in database. [Bug #54505] To explain what this is about, first a short phpBB code history lesson: ;-) r9823 originally introduced the usage of our template class for emails. The messenger class uses set_custom_template() to initialise the template object which neither disables storedb nor inheritance. These two values are set in $user->theme rather than inside a particular template instance (quite a design failure if I may add). Thus the html page that is displayed to the user also determines these settings for the email templates. This obviously causes problems because both emails and other custom templates can quite simply not be stored in the database because the db table only stores the filename, not the path and requires a template id. r9839 then generally disabled storedb and template inheritance for custom templates to fix Bug #40515. This works for custom templates, but not for emails where lots of template objects are created. In such a situation the last call to set(_custom)_template() would now determine the values of storedb and inheritance in _tpl_load. So any page sending emails would neither load its template from the database nor use template inheritance. The same revision also introduced orig_tpl_* variables in set_template() which on their own are very much pointless, but could allow resetting the storedb and inheritance values if they were used to reset $user->theme just before template execution in _tpl_load. In r10150 these orig_tpl_* variables are correctly used to access information about the template of the page being displayed - contrary to the last template used - from within the bbcode, fixing Bug #51285. However r10150 also introduces a pointless $template_mode parameter for set_custom_template(). $template_mode is really just a boolean flag (value you can be 'template' or an arbitrary other value) that if it set circumvents the unsetting of storedb and template inheritance. The very code that had been added to prevent issues with emails and custom templates. Fixing the problem introduced by r8839 but at the same time reintroducing the much greater problem from the original implementation of email templates. And now an explanation of what I did: Based on this I have now changed the set_custom_template method to always disable storedb. It can now properly use inheritance, you simply tell it the path where the parent template can be found, by default the path is false which will turn inheritance off. To make this work the template class now always overwrites $user->theme storedb and inheritance variabbles with orig_tpl_* just before rendering a template in _tpl_load. This way they are guaranteed to always contain the value they had at the time set_template/set_custom_template were called. This fixes [Bug #54505]. In summary, using global state is simply a horrible idea in object oriented programming. Always Pass values, that an object depends on, as parameters - never through magic global variables. Following this principle will safe you from a lot of headaches. Please test this patch as much as possible to make sure templates still work properly for you, focus on multiple languages, missing language files, and custom templates in systems that make use of the template class outside of phpBB itself. git-svn-id: file:///svn/phpbb/branches/phpBB-3_0_0@10460 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/includes/template.php | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) (limited to 'phpBB/includes/template.php') diff --git a/phpBB/includes/template.php b/phpBB/includes/template.php index af5c9d3a47..f1c8094a9b 100644 --- a/phpBB/includes/template.php +++ b/phpBB/includes/template.php @@ -90,7 +90,7 @@ class template * Set custom template location (able to use directory outside of phpBB) * @access public */ - function set_custom_template($template_path, $template_name, $template_mode = 'template') + function set_custom_template($template_path, $template_name, $fallback_template_path = false) { global $phpbb_root_path, $user; @@ -103,13 +103,25 @@ class template $this->root = $template_path; $this->cachepath = $phpbb_root_path . 'cache/ctpl_' . str_replace('_', '-', $template_name) . '_'; - // As the template-engine is used for more than the template (emails, etc.), we should not set $user->theme in all cases, but only on the real template. - if ($template_mode == 'template') + if ($fallback_template_path !== false) { - $user->theme['template_storedb'] = false; - $user->theme['template_inherits_id'] = false; + if (substr($fallback_template_path, -1) == '/') + { + $fallback_template_path = substr($fallback_template_path, 0, -1); + } + + $this->inherit_root = $fallback_template_path; + $this->orig_tpl_inherits_id = true; + } + else + { + $this->orig_tpl_inherits_id = false; } + // the database does not store the path or name of a custom template + // so there is no way we can properly store custom templates there + $this->orig_tpl_storedb = false; + $this->_rootref = &$this->_tpldata['.'][0]; return true; @@ -254,6 +266,12 @@ class template trigger_error("template->_tpl_load(): No file specified for handle $handle", E_USER_ERROR); } + // reload these settings to have the values they had when this object was initialised + // using set_template or set_custom_template, they might otherwise have been overwritten + // by other template class instances in between. + $user->theme['template_storedb'] = $this->orig_tpl_storedb; + $user->theme['template_inherits_id'] = $this->orig_tpl_inherits_id; + $filename = $this->cachepath . str_replace('/', '.', $this->filename[$handle]) . '.' . $phpEx; $this->files_template[$handle] = (isset($user->theme['template_id'])) ? $user->theme['template_id'] : 0; -- cgit v1.2.1