From 300d5c32db82a72309d389860864e5513ca45ce4 Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Tue, 13 May 2014 23:22:54 +0200 Subject: [PATCH 1/9] [ticket/12509] Add an option to set the path of custom file for extensions https://tracker.phpbb.com/browse/PHPBB3-12509 PHPBB3-12509 --- phpBB/includes/functions_messenger.php | 5 ++++- phpBB/phpbb/template/twig/twig.php | 18 +++++++++++++----- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/phpBB/includes/functions_messenger.php b/phpBB/includes/functions_messenger.php index 79a5aeda1a..bc5937fdc4 100644 --- a/phpBB/includes/functions_messenger.php +++ b/phpBB/includes/functions_messenger.php @@ -252,7 +252,10 @@ class messenger } } - $this->set_template_paths($template_lang . '_email', $template_paths); + $this->set_template_paths(array( + 'name' => $template_lang . '_email', + 'ext_path' => 'language/' . $template_lang . '/email' + ), $template_paths); $this->template->set_filenames(array( 'body' => $template_file . '.txt', diff --git a/phpBB/phpbb/template/twig/twig.php b/phpBB/phpbb/template/twig/twig.php index 83630f5992..9e5a572cb5 100644 --- a/phpBB/phpbb/template/twig/twig.php +++ b/phpBB/phpbb/template/twig/twig.php @@ -211,8 +211,8 @@ class twig extends \phpbb\template\base * * Note: Templates are still compiled to phpBB's cache directory. * - * @param string|array $names Array of names or string of name of template(s) in inheritance tree order, used by extensions. - * @param string|array or string $paths Array of style paths, relative to current root directory + * @param string|array $names Array of names (or detailed names) or string of name of template(s) in inheritance tree order, used by extensions. + * @param string|array of string $paths Array of style paths, relative to current root directory * @return phpbb_template $this */ public function set_custom_style($names, $paths) @@ -234,10 +234,18 @@ class twig extends \phpbb\template\base $namespace = str_replace('/', '_', $ext_namespace); $paths = array(); - foreach ($names as $style_name) + foreach ($names as $template_dir) { - $ext_style_path = $ext_path . 'styles/' . $style_name . '/'; - $ext_style_template_path = $ext_style_path . 'template/'; + if (is_array($template_dir) && isset($template_dir['ext_path'])) + { + $ext_style_template_path = $ext_path . $template_dir['ext_path']; + $ext_style_path = dirname($ext_style_template_path); + } + else + { + $ext_style_path = $ext_path . 'styles/' . $template_dir . '/'; + $ext_style_template_path = $ext_style_path . 'template/'; + } if (is_dir($ext_style_template_path)) { From 910b9b59b39ffab0614a310cfa9ddcf42723fe89 Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Tue, 13 May 2014 23:25:44 +0200 Subject: [PATCH 2/9] [ticket/12509] Update acp custom_style setter PHPBB3-12509 --- phpBB/adm/index.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/phpBB/adm/index.php b/phpBB/adm/index.php index c1e8edbd03..973ce8fe5d 100644 --- a/phpBB/adm/index.php +++ b/phpBB/adm/index.php @@ -50,7 +50,11 @@ $module_id = request_var('i', ''); $mode = request_var('mode', ''); // Set custom style for admin area -$template->set_custom_style('adm', $phpbb_admin_path . 'style'); +$template->set_custom_style(array( + 'name' => 'adm', + 'ex_path' => 'adm/', +), $phpbb_admin_path . 'style'); + $template->assign_var('T_ASSETS_PATH', $phpbb_root_path . 'assets'); $template->assign_var('T_TEMPLATE_PATH', $phpbb_admin_path . 'style'); From 1e427fa031eea8dd6a1e04f1407f996d1d948203 Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Tue, 13 May 2014 23:39:42 +0200 Subject: [PATCH 3/9] [ticket/12509] Fix the call to set_custom_file in adm/index and messenger PHPBB3-12509 --- phpBB/adm/index.php | 6 ++++-- phpBB/includes/functions_messenger.php | 6 ++++-- phpBB/phpbb/template/twig/twig.php | 14 +++++++++++--- 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/phpBB/adm/index.php b/phpBB/adm/index.php index 973ce8fe5d..31965cec28 100644 --- a/phpBB/adm/index.php +++ b/phpBB/adm/index.php @@ -51,8 +51,10 @@ $mode = request_var('mode', ''); // Set custom style for admin area $template->set_custom_style(array( - 'name' => 'adm', - 'ex_path' => 'adm/', + array( + 'name' => 'adm', + 'ex_path' => 'adm/', + ) ), $phpbb_admin_path . 'style'); $template->assign_var('T_ASSETS_PATH', $phpbb_root_path . 'assets'); diff --git a/phpBB/includes/functions_messenger.php b/phpBB/includes/functions_messenger.php index bc5937fdc4..482f95dd99 100644 --- a/phpBB/includes/functions_messenger.php +++ b/phpBB/includes/functions_messenger.php @@ -253,8 +253,10 @@ class messenger } $this->set_template_paths(array( - 'name' => $template_lang . '_email', - 'ext_path' => 'language/' . $template_lang . '/email' + array( + 'name' => $template_lang . '_email', + 'ext_path' => 'language/' . $template_lang . '/email' + ) ), $template_paths); $this->template->set_filenames(array( diff --git a/phpBB/phpbb/template/twig/twig.php b/phpBB/phpbb/template/twig/twig.php index 9e5a572cb5..a084245918 100644 --- a/phpBB/phpbb/template/twig/twig.php +++ b/phpBB/phpbb/template/twig/twig.php @@ -236,10 +236,18 @@ class twig extends \phpbb\template\base foreach ($names as $template_dir) { - if (is_array($template_dir) && isset($template_dir['ext_path'])) + if (is_array($template_dir)) { - $ext_style_template_path = $ext_path . $template_dir['ext_path']; - $ext_style_path = dirname($ext_style_template_path); + if (isset($template_dir['ext_path'])) + { + $ext_style_template_path = $ext_path . $template_dir['ext_path']; + $ext_style_path = dirname($ext_style_template_path); + } + else + { + $ext_style_path = $ext_path . 'styles/' . $template_dir['name'] . '/'; + $ext_style_template_path = $ext_style_path . 'template/'; + } } else { From 9fc2063d8623149ec6f8e359c87d626fcc5eeb88 Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Tue, 13 May 2014 23:49:21 +0200 Subject: [PATCH 4/9] [ticket/12509] Fix doc block PHPBB3-12509 --- phpBB/phpbb/template/twig/twig.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/phpbb/template/twig/twig.php b/phpBB/phpbb/template/twig/twig.php index a084245918..fc6e9eacd8 100644 --- a/phpBB/phpbb/template/twig/twig.php +++ b/phpBB/phpbb/template/twig/twig.php @@ -213,7 +213,7 @@ class twig extends \phpbb\template\base * * @param string|array $names Array of names (or detailed names) or string of name of template(s) in inheritance tree order, used by extensions. * @param string|array of string $paths Array of style paths, relative to current root directory - * @return phpbb_template $this + * @return \phpbb\template\template $this */ public function set_custom_style($names, $paths) { From 57d08dc77b61157ee53272ec0ba0154d7a416f0c Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Wed, 14 May 2014 00:27:04 +0200 Subject: [PATCH 5/9] [ticket/12509] Fix typo in adm/index.php PHPBB3-12509 --- phpBB/adm/index.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/adm/index.php b/phpBB/adm/index.php index 31965cec28..f83a491e97 100644 --- a/phpBB/adm/index.php +++ b/phpBB/adm/index.php @@ -53,7 +53,7 @@ $mode = request_var('mode', ''); $template->set_custom_style(array( array( 'name' => 'adm', - 'ex_path' => 'adm/', + 'ext_path' => 'adm/', ) ), $phpbb_admin_path . 'style'); From c8080d6464a406deaa4b5b2d375eea119f049dff Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Wed, 14 May 2014 01:11:43 +0200 Subject: [PATCH 6/9] [ticket/12509] Fix path in adm/index.php PHPBB3-12509 --- phpBB/adm/index.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/adm/index.php b/phpBB/adm/index.php index f83a491e97..19482b6d6a 100644 --- a/phpBB/adm/index.php +++ b/phpBB/adm/index.php @@ -53,7 +53,7 @@ $mode = request_var('mode', ''); $template->set_custom_style(array( array( 'name' => 'adm', - 'ext_path' => 'adm/', + 'ext_path' => 'adm/style/', ) ), $phpbb_admin_path . 'style'); From 9d7c36041e0dac509476069ee5bbce92e841f33e Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Wed, 14 May 2014 02:16:32 +0200 Subject: [PATCH 7/9] [ticket/12509] Update calls to set_custom_style in forgotten places PHPBB3-12509 --- phpBB/includes/functions_module.php | 7 ++++++- phpBB/install/index.php | 7 ++++++- phpBB/install/install_update.php | 7 ++++++- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/phpBB/includes/functions_module.php b/phpBB/includes/functions_module.php index 04efcb7b2e..9ef0754120 100644 --- a/phpBB/includes/functions_module.php +++ b/phpBB/includes/functions_module.php @@ -581,7 +581,12 @@ class p_master if (is_dir($module_style_dir)) { - $template->set_custom_style('adm', array($module_style_dir, $phpbb_admin_path . 'style')); + $template->set_custom_style(array( + array( + 'name' => 'adm', + 'ext_path' => 'adm/style/', + ) + ), array($module_style_dir, $phpbb_admin_path . 'style')); } } diff --git a/phpBB/install/index.php b/phpBB/install/index.php index 66c8559e98..8d13c182d8 100644 --- a/phpBB/install/index.php +++ b/phpBB/install/index.php @@ -250,7 +250,12 @@ $phpbb_path_helper = $phpbb_container->get('path_helper'); $template = new \phpbb\template\twig\twig($phpbb_path_helper, $config, $user, new \phpbb\template\context()); $paths = array($phpbb_root_path . 'install/update/new/adm/style', $phpbb_admin_path . 'style'); $paths = array_filter($paths, 'is_dir'); -$template->set_custom_style('adm', $paths); +$template->set_custom_style(array( + array( + 'name' => 'adm', + 'ext_path' => 'adm/style/', + ) +), $paths); $path = array_shift($paths); diff --git a/phpBB/install/install_update.php b/phpBB/install/install_update.php index 87b7d8d703..ab276624ee 100644 --- a/phpBB/install/install_update.php +++ b/phpBB/install/install_update.php @@ -141,7 +141,12 @@ class install_update extends module // Set custom template again. ;) $paths = array($phpbb_root_path . 'install/update/new/adm/style', $phpbb_admin_path . 'style'); $paths = array_filter($paths, 'is_dir'); - $template->set_custom_style('adm', $paths); + $template->set_custom_style(array( + array( + 'name' => 'adm', + 'ext_path' => 'adm/style/', + ) + ), $paths); $template->assign_vars(array( 'S_USER_LANG' => $user->lang['USER_LANG'], From 9a846e447ba98b175c510d9fbe7741648296a1ba Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Mon, 26 May 2014 23:44:30 +0200 Subject: [PATCH 8/9] [ticket/12509] Add missing ',' in arrays PHPBB3-12509 --- phpBB/adm/index.php | 2 +- phpBB/includes/functions_messenger.php | 2 +- phpBB/includes/functions_module.php | 2 +- phpBB/install/index.php | 2 +- phpBB/install/install_update.php | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/phpBB/adm/index.php b/phpBB/adm/index.php index 19482b6d6a..b87b43945c 100644 --- a/phpBB/adm/index.php +++ b/phpBB/adm/index.php @@ -54,7 +54,7 @@ $template->set_custom_style(array( array( 'name' => 'adm', 'ext_path' => 'adm/style/', - ) + ), ), $phpbb_admin_path . 'style'); $template->assign_var('T_ASSETS_PATH', $phpbb_root_path . 'assets'); diff --git a/phpBB/includes/functions_messenger.php b/phpBB/includes/functions_messenger.php index 482f95dd99..4a3f2ec73a 100644 --- a/phpBB/includes/functions_messenger.php +++ b/phpBB/includes/functions_messenger.php @@ -256,7 +256,7 @@ class messenger array( 'name' => $template_lang . '_email', 'ext_path' => 'language/' . $template_lang . '/email' - ) + ), ), $template_paths); $this->template->set_filenames(array( diff --git a/phpBB/includes/functions_module.php b/phpBB/includes/functions_module.php index 9ef0754120..86d3a3a077 100644 --- a/phpBB/includes/functions_module.php +++ b/phpBB/includes/functions_module.php @@ -585,7 +585,7 @@ class p_master array( 'name' => 'adm', 'ext_path' => 'adm/style/', - ) + ), ), array($module_style_dir, $phpbb_admin_path . 'style')); } } diff --git a/phpBB/install/index.php b/phpBB/install/index.php index 8d13c182d8..d38c5fa676 100644 --- a/phpBB/install/index.php +++ b/phpBB/install/index.php @@ -254,7 +254,7 @@ $template->set_custom_style(array( array( 'name' => 'adm', 'ext_path' => 'adm/style/', - ) + ), ), $paths); $path = array_shift($paths); diff --git a/phpBB/install/install_update.php b/phpBB/install/install_update.php index ab276624ee..c2f7b191a7 100644 --- a/phpBB/install/install_update.php +++ b/phpBB/install/install_update.php @@ -145,7 +145,7 @@ class install_update extends module array( 'name' => 'adm', 'ext_path' => 'adm/style/', - ) + ), ), $paths); $template->assign_vars(array( From 05cd25a88b551d7338596cc6634e95cb371f565d Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Tue, 27 May 2014 00:05:12 +0200 Subject: [PATCH 9/9] [ticket/12509] Add example in doc block PHPBB3-12509 --- phpBB/phpbb/template/twig/twig.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/phpBB/phpbb/template/twig/twig.php b/phpBB/phpbb/template/twig/twig.php index fc6e9eacd8..9ea5121553 100644 --- a/phpBB/phpbb/template/twig/twig.php +++ b/phpBB/phpbb/template/twig/twig.php @@ -212,6 +212,10 @@ class twig extends \phpbb\template\base * Note: Templates are still compiled to phpBB's cache directory. * * @param string|array $names Array of names (or detailed names) or string of name of template(s) in inheritance tree order, used by extensions. + * E.g. array( + * 'name' => 'adm', + * 'ext_path' => 'adm/style/', + * ) * @param string|array of string $paths Array of style paths, relative to current root directory * @return \phpbb\template\template $this */