From 11c5a6621389af854170d3190432d3f414c77618 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Sat, 18 Feb 2012 23:31:31 +0100 Subject: [PATCH 001/114] [ticket/10658] Use get_user_rank() for group ranks on group view. The old code was buggy because it did not prefix the path with the phpBB root path which causes problems with bridges and other URL rewriting. PHPBB3-10658 --- phpBB/memberlist.php | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/phpBB/memberlist.php b/phpBB/memberlist.php index b3c0bae16a..cfa1631dbe 100644 --- a/phpBB/memberlist.php +++ b/phpBB/memberlist.php @@ -1221,21 +1221,16 @@ switch ($mode) // Misusing the avatar function for displaying group avatars... $avatar_img = get_user_avatar($group_row['group_avatar'], $group_row['group_avatar_type'], $group_row['group_avatar_width'], $group_row['group_avatar_height'], 'GROUP_AVATAR'); + // ... same for group rank $rank_title = $rank_img = $rank_img_src = ''; if ($group_row['group_rank']) { - if (isset($ranks['special'][$group_row['group_rank']])) + get_user_rank($group_row['group_rank'], false, $rank_title, $rank_img, $rank_img_src); + + if ($rank_img) { - $rank_title = $ranks['special'][$group_row['group_rank']]['rank_title']; + $rank_img .= '
'; } - $rank_img = (!empty($ranks['special'][$group_row['group_rank']]['rank_image'])) ? '' . $ranks['special'][$group_row['group_rank']]['rank_title'] . '
' : ''; - $rank_img_src = (!empty($ranks['special'][$group_row['group_rank']]['rank_image'])) ? $config['ranks_path'] . '/' . $ranks['special'][$group_row['group_rank']]['rank_image'] : ''; - } - else - { - $rank_title = ''; - $rank_img = ''; - $rank_img_src = ''; } $template->assign_vars(array( From bb7e86c2b1920c5820d4c9cca7ec76bd25835fa1 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Thu, 8 Mar 2012 15:19:15 +0100 Subject: [PATCH 002/114] [ticket/10658] Do not fetch ranks into the $ranks array, it is no longer used. PHPBB3-10658 --- phpBB/memberlist.php | 5 ----- 1 file changed, 5 deletions(-) diff --git a/phpBB/memberlist.php b/phpBB/memberlist.php index cfa1631dbe..3dd5bd24b6 100644 --- a/phpBB/memberlist.php +++ b/phpBB/memberlist.php @@ -62,11 +62,6 @@ $default_key = 'c'; $sort_key = request_var('sk', $default_key); $sort_dir = request_var('sd', 'a'); - -// Grab rank information for later -$ranks = $cache->obtain_ranks(); - - // What do you want to do today? ... oops, I think that line is taken ... switch ($mode) { From 7d414d04ca80b3dc5efc7ece4c3c28123a4e7e89 Mon Sep 17 00:00:00 2001 From: Vjacheslav Trushkin Date: Wed, 14 Mar 2012 22:57:58 +0200 Subject: [PATCH 003/114] [feature/merging-style-components] Moving template classes to style Moving includes/template/ to includes/style/, adding template_ prefix to classes that deal only with templates PHPBB3-10632 --- phpBB/includes/{template => style}/extension_path_provider.php | 0 phpBB/includes/{template => style}/locator.php | 0 phpBB/includes/{template => style}/path_provider.php | 0 phpBB/includes/{template => style}/path_provider_interface.php | 0 phpBB/includes/{template => style}/template.php | 0 .../includes/{template/compile.php => style/template_compile.php} | 0 .../includes/{template/context.php => style/template_context.php} | 0 phpBB/includes/{template/filter.php => style/template_filter.php} | 0 .../{template/renderer.php => style/template_renderer.php} | 0 .../renderer_eval.php => style/template_renderer_eval.php} | 0 .../renderer_include.php => style/template_renderer_include.php} | 0 11 files changed, 0 insertions(+), 0 deletions(-) rename phpBB/includes/{template => style}/extension_path_provider.php (100%) rename phpBB/includes/{template => style}/locator.php (100%) rename phpBB/includes/{template => style}/path_provider.php (100%) rename phpBB/includes/{template => style}/path_provider_interface.php (100%) rename phpBB/includes/{template => style}/template.php (100%) rename phpBB/includes/{template/compile.php => style/template_compile.php} (100%) rename phpBB/includes/{template/context.php => style/template_context.php} (100%) rename phpBB/includes/{template/filter.php => style/template_filter.php} (100%) rename phpBB/includes/{template/renderer.php => style/template_renderer.php} (100%) rename phpBB/includes/{template/renderer_eval.php => style/template_renderer_eval.php} (100%) rename phpBB/includes/{template/renderer_include.php => style/template_renderer_include.php} (100%) diff --git a/phpBB/includes/template/extension_path_provider.php b/phpBB/includes/style/extension_path_provider.php similarity index 100% rename from phpBB/includes/template/extension_path_provider.php rename to phpBB/includes/style/extension_path_provider.php diff --git a/phpBB/includes/template/locator.php b/phpBB/includes/style/locator.php similarity index 100% rename from phpBB/includes/template/locator.php rename to phpBB/includes/style/locator.php diff --git a/phpBB/includes/template/path_provider.php b/phpBB/includes/style/path_provider.php similarity index 100% rename from phpBB/includes/template/path_provider.php rename to phpBB/includes/style/path_provider.php diff --git a/phpBB/includes/template/path_provider_interface.php b/phpBB/includes/style/path_provider_interface.php similarity index 100% rename from phpBB/includes/template/path_provider_interface.php rename to phpBB/includes/style/path_provider_interface.php diff --git a/phpBB/includes/template/template.php b/phpBB/includes/style/template.php similarity index 100% rename from phpBB/includes/template/template.php rename to phpBB/includes/style/template.php diff --git a/phpBB/includes/template/compile.php b/phpBB/includes/style/template_compile.php similarity index 100% rename from phpBB/includes/template/compile.php rename to phpBB/includes/style/template_compile.php diff --git a/phpBB/includes/template/context.php b/phpBB/includes/style/template_context.php similarity index 100% rename from phpBB/includes/template/context.php rename to phpBB/includes/style/template_context.php diff --git a/phpBB/includes/template/filter.php b/phpBB/includes/style/template_filter.php similarity index 100% rename from phpBB/includes/template/filter.php rename to phpBB/includes/style/template_filter.php diff --git a/phpBB/includes/template/renderer.php b/phpBB/includes/style/template_renderer.php similarity index 100% rename from phpBB/includes/template/renderer.php rename to phpBB/includes/style/template_renderer.php diff --git a/phpBB/includes/template/renderer_eval.php b/phpBB/includes/style/template_renderer_eval.php similarity index 100% rename from phpBB/includes/template/renderer_eval.php rename to phpBB/includes/style/template_renderer_eval.php diff --git a/phpBB/includes/template/renderer_include.php b/phpBB/includes/style/template_renderer_include.php similarity index 100% rename from phpBB/includes/template/renderer_include.php rename to phpBB/includes/style/template_renderer_include.php From b7d84a586c1e253ff7075e80ab721db5c1101c9f Mon Sep 17 00:00:00 2001 From: Vjacheslav Trushkin Date: Wed, 14 Mar 2012 23:12:11 +0200 Subject: [PATCH 004/114] [feature/merging-style-components] Renaming template classes Changing template classes prefixes from phpbb_template to phpbb_style (for classes that will work with styles) or phpbb_style_template (for classes that are specific to templates) PHPBB3-10632 --- phpBB/common.php | 6 ++-- phpBB/includes/bbcode.php | 6 ++-- phpBB/includes/functions_messenger.php | 6 ++-- .../style/extension_path_provider.php | 8 ++--- phpBB/includes/style/locator.php | 2 +- phpBB/includes/style/path_provider.php | 2 +- .../style/path_provider_interface.php | 2 +- phpBB/includes/style/template.php | 34 +++++++++---------- phpBB/includes/style/template_compile.php | 4 +-- phpBB/includes/style/template_context.php | 4 +-- phpBB/includes/style/template_filter.php | 2 +- phpBB/includes/style/template_renderer.php | 4 +-- .../includes/style/template_renderer_eval.php | 6 ++-- .../style/template_renderer_include.php | 4 +-- phpBB/install/index.php | 6 ++-- tests/template/renderer_eval_test.php | 4 +-- tests/template/template_compile_test.php | 2 +- tests/template/template_inheritance_test.php | 6 ++-- tests/template/template_test_case.php | 6 ++-- 19 files changed, 57 insertions(+), 57 deletions(-) diff --git a/phpBB/common.php b/phpBB/common.php index b308037a0e..a38a986280 100644 --- a/phpBB/common.php +++ b/phpBB/common.php @@ -120,9 +120,9 @@ set_config_count(null, null, null, $config); // load extensions $phpbb_extension_manager = new phpbb_extension_manager($db, EXT_TABLE, $phpbb_root_path, ".$phpEx", $cache->get_driver()); -$phpbb_template_locator = new phpbb_template_locator(); -$phpbb_template_path_provider = new phpbb_template_extension_path_provider($phpbb_extension_manager, new phpbb_template_path_provider()); -$template = new phpbb_template($phpbb_root_path, $phpEx, $config, $user, $phpbb_template_locator, $phpbb_template_path_provider); +$phpbb_style_locator = new phpbb_style_locator(); +$phpbb_style_path_provider = new phpbb_style_extension_path_provider($phpbb_extension_manager, new phpbb_style_path_provider()); +$template = new phpbb_style_template($phpbb_root_path, $phpEx, $config, $user, $phpbb_style_locator, $phpbb_style_path_provider); // Add own hook handler require($phpbb_root_path . 'includes/hooks/index.' . $phpEx); diff --git a/phpBB/includes/bbcode.php b/phpBB/includes/bbcode.php index 60274a308d..61271545bd 100644 --- a/phpBB/includes/bbcode.php +++ b/phpBB/includes/bbcode.php @@ -132,9 +132,9 @@ class bbcode { $this->template_bitfield = new bitfield($user->theme['bbcode_bitfield']); - $template_locator = new phpbb_template_locator(); - $template_path_provider = new phpbb_template_extension_path_provider($phpbb_extension_manager, new phpbb_template_path_provider()); - $template = new phpbb_template($phpbb_root_path, $phpEx, $config, $user, $template_locator, $template_path_provider); + $template_locator = new phpbb_style_locator(); + $template_path_provider = new phpbb_style_extension_path_provider($phpbb_extension_manager, new phpbb_style_path_provider()); + $template = new phpbb_style_template($phpbb_root_path, $phpEx, $config, $user, $template_locator, $template_path_provider); $template->set_template(); $template_locator->set_filenames(array('bbcode.html' => 'bbcode.html')); $this->template_filename = $template_locator->get_source_file_for_handle('bbcode.html'); diff --git a/phpBB/includes/functions_messenger.php b/phpBB/includes/functions_messenger.php index f4e49b1b18..1fb5f15879 100644 --- a/phpBB/includes/functions_messenger.php +++ b/phpBB/includes/functions_messenger.php @@ -208,9 +208,9 @@ class messenger // tpl_msg now holds a template object we can use to parse the template file if (!isset($this->tpl_msg[$template_lang . $template_file])) { - $template_locator = new phpbb_template_locator(); - $template_path_provider = new phpbb_template_extension_path_provider($phpbb_extension_manager, new phpbb_template_path_provider()); - $this->tpl_msg[$template_lang . $template_file] = new phpbb_template($phpbb_root_path, $phpEx, $config, $user, $template_locator, $template_path_provider); + $template_locator = new phpbb_style_locator(); + $template_path_provider = new phpbb_style_extension_path_provider($phpbb_extension_manager, new phpbb_style_path_provider()); + $this->tpl_msg[$template_lang . $template_file] = new phpbb_style_template($phpbb_root_path, $phpEx, $config, $user, $template_locator, $template_path_provider); $tpl = &$this->tpl_msg[$template_lang . $template_file]; $fallback_template_path = false; diff --git a/phpBB/includes/style/extension_path_provider.php b/phpBB/includes/style/extension_path_provider.php index 2897f60ac1..05dc5661f6 100644 --- a/phpBB/includes/style/extension_path_provider.php +++ b/phpBB/includes/style/extension_path_provider.php @@ -22,7 +22,7 @@ if (!defined('IN_PHPBB')) * * @package phpBB3 */ -class phpbb_template_extension_path_provider extends phpbb_extension_provider implements phpbb_template_path_provider_interface +class phpbb_style_extension_path_provider extends phpbb_extension_provider implements phpbb_style_path_provider_interface { /** * Optional prefix for template paths searched within extensions. @@ -36,7 +36,7 @@ class phpbb_template_extension_path_provider extends phpbb_extension_provider im /** * A provider of paths to be searched for templates - * @var phpbb_template_path_provider + * @var phpbb_style_path_provider */ protected $base_path_provider; @@ -44,10 +44,10 @@ class phpbb_template_extension_path_provider extends phpbb_extension_provider im * Constructor stores extension manager * * @param phpbb_extension_manager $extension_manager phpBB extension manager - * @param phpbb_template_path_provider $base_path_provider A simple path provider + * @param phpbb_style_path_provider $base_path_provider A simple path provider * to provide paths to be located in extensions */ - public function __construct(phpbb_extension_manager $extension_manager, phpbb_template_path_provider $base_path_provider) + public function __construct(phpbb_extension_manager $extension_manager, phpbb_style_path_provider $base_path_provider) { parent::__construct($extension_manager); $this->base_path_provider = $base_path_provider; diff --git a/phpBB/includes/style/locator.php b/phpBB/includes/style/locator.php index d4502d7984..2d0bcce924 100644 --- a/phpBB/includes/style/locator.php +++ b/phpBB/includes/style/locator.php @@ -25,7 +25,7 @@ if (!defined('IN_PHPBB')) * * @package phpBB3 */ -class phpbb_template_locator +class phpbb_style_locator { /** * Paths to directories that templates are stored in. diff --git a/phpBB/includes/style/path_provider.php b/phpBB/includes/style/path_provider.php index b0b545973d..649797df41 100644 --- a/phpBB/includes/style/path_provider.php +++ b/phpBB/includes/style/path_provider.php @@ -22,7 +22,7 @@ if (!defined('IN_PHPBB')) * * @package phpBB3 */ -class phpbb_template_path_provider implements IteratorAggregate, phpbb_template_path_provider_interface +class phpbb_style_path_provider implements IteratorAggregate, phpbb_style_path_provider_interface { protected $main_template_name = ''; protected $paths = array(); diff --git a/phpBB/includes/style/path_provider_interface.php b/phpBB/includes/style/path_provider_interface.php index 8b3a406d2a..e65c037dcc 100644 --- a/phpBB/includes/style/path_provider_interface.php +++ b/phpBB/includes/style/path_provider_interface.php @@ -22,7 +22,7 @@ if (!defined('IN_PHPBB')) * * @package phpBB3 */ -interface phpbb_template_path_provider_interface extends Traversable +interface phpbb_style_path_provider_interface extends Traversable { /** * Defines a prefix to use for template paths in extensions diff --git a/phpBB/includes/style/template.php b/phpBB/includes/style/template.php index bac5445511..a8c5139dd0 100644 --- a/phpBB/includes/style/template.php +++ b/phpBB/includes/style/template.php @@ -29,10 +29,10 @@ if (!defined('IN_PHPBB')) * Base Template class. * @package phpBB3 */ -class phpbb_template +class phpbb_style_template { /** - * @var phpbb_template_context Template context. + * @var phpbb_style_template_context Template context. * Stores template data used during template rendering. */ private $context; @@ -64,13 +64,13 @@ class phpbb_template /** * Template locator - * @var phpbb_template_locator + * @var phpbb_style_locator */ private $locator; /** * Template path provider - * @var phpbb_template_path_provider + * @var phpbb_style_path_provider */ private $provider; @@ -79,10 +79,10 @@ class phpbb_template * * @param string $phpbb_root_path phpBB root path * @param user $user current user - * @param phpbb_template_locator $locator template locator - * @param phpbb_template_path_provider $provider template path provider + * @param phpbb_style_locator $locator template locator + * @param phpbb_style_path_provider $provider template path provider */ - public function __construct($phpbb_root_path, $phpEx, $config, $user, phpbb_template_locator $locator, phpbb_template_path_provider_interface $provider) + public function __construct($phpbb_root_path, $phpEx, $config, $user, phpbb_style_locator $locator, phpbb_style_path_provider_interface $provider) { $this->phpbb_root_path = $phpbb_root_path; $this->phpEx = $phpEx; @@ -139,7 +139,7 @@ class phpbb_template $this->cachepath = $this->phpbb_root_path . 'cache/tpl_' . str_replace('_', '-', $template_name) . '_'; - $this->context = new phpbb_template_context(); + $this->context = new phpbb_style_template_context(); return true; } @@ -298,15 +298,15 @@ class phpbb_template * configuration setting may be used to force templates to be always * recompiled. * - * Returns an object implementing phpbb_template_renderer, or null + * Returns an object implementing phpbb_style_template_renderer, or null * if template loading or compilation failed. Call render() on the * renderer to display the template. This will result in template * contents sent to the output stream (unless, of course, output * buffering is in effect). * * @param string $handle Handle of the template to load - * @return phpbb_template_renderer Template renderer object, or null on failure - * @uses phpbb_template_compile is used to compile template source + * @return phpbb_style_template_renderer Template renderer object, or null on failure + * @uses phpbb_style_template_compile is used to compile template source */ private function _tpl_load($handle) { @@ -330,18 +330,18 @@ class phpbb_template // Recompile page if the original template is newer, otherwise load the compiled version if (!$recompile) { - return new phpbb_template_renderer_include($output_file, $this); + return new phpbb_style_template_renderer_include($output_file, $this); } - $compile = new phpbb_template_compile($this->config['tpl_allow_php']); + $compile = new phpbb_style_template_compile($this->config['tpl_allow_php']); if ($compile->compile_file_to_file($source_file, $output_file) !== false) { - $renderer = new phpbb_template_renderer_include($output_file, $this); + $renderer = new phpbb_style_template_renderer_include($output_file, $this); } else if (($code = $compile->compile_file($source_file)) !== false) { - $renderer = new phpbb_template_renderer_eval($code, $this); + $renderer = new phpbb_style_template_renderer_eval($code, $this); } else { @@ -403,7 +403,7 @@ class phpbb_template $this->context->append_var($varname, $varval); } - // Docstring is copied from phpbb_template_context method with the same name. + // Docstring is copied from phpbb_style_template_context method with the same name. /** * Assign key variable pairs from an array to a specified block * @param string $blockname Name of block to assign $vararray to @@ -414,7 +414,7 @@ class phpbb_template return $this->context->assign_block_vars($blockname, $vararray); } - // Docstring is copied from phpbb_template_context method with the same name. + // Docstring is copied from phpbb_style_template_context method with the same name. /** * Change already assigned key variable pair (one-dimensional - single loop entry) * diff --git a/phpBB/includes/style/template_compile.php b/phpBB/includes/style/template_compile.php index b0009421c5..3ef3fffc00 100644 --- a/phpBB/includes/style/template_compile.php +++ b/phpBB/includes/style/template_compile.php @@ -15,7 +15,7 @@ if (!defined('IN_PHPBB')) exit; } -stream_filter_register('phpbb_template', 'phpbb_template_filter'); +stream_filter_register('phpbb_template', 'phpbb_style_template_filter'); /** * Extension of template class - Functions needed for compiling templates only. @@ -23,7 +23,7 @@ stream_filter_register('phpbb_template', 'phpbb_template_filter'); * @package phpBB3 * @uses template_filter As a PHP stream filter to perform compilation of templates */ -class phpbb_template_compile +class phpbb_style_template_compile { /** * Whether tags are allowed diff --git a/phpBB/includes/style/template_context.php b/phpBB/includes/style/template_context.php index ec09da1cf3..b22f77da2e 100644 --- a/phpBB/includes/style/template_context.php +++ b/phpBB/includes/style/template_context.php @@ -20,7 +20,7 @@ if (!defined('IN_PHPBB')) * * @package phpBB3 */ -class phpbb_template_context +class phpbb_style_template_context { /** * variable that holds all the data we'll be substituting into @@ -86,7 +86,7 @@ class phpbb_template_context * Returns a reference to template data array. * * This function is public so that template renderer may invoke it. - * Users should alter template variables via functions in phpbb_template. + * Users should alter template variables via functions in phpbb_style_template. * * Note: modifying returned array will affect data stored in the context. * diff --git a/phpBB/includes/style/template_filter.php b/phpBB/includes/style/template_filter.php index f55c8d7e9c..04fe85e07f 100644 --- a/phpBB/includes/style/template_filter.php +++ b/phpBB/includes/style/template_filter.php @@ -35,7 +35,7 @@ if (!defined('IN_PHPBB')) * @see template_compile * @package phpBB3 */ -class phpbb_template_filter extends php_user_filter +class phpbb_style_template_filter extends php_user_filter { const REGEX_NS = '[a-z_][a-z_0-9]+'; diff --git a/phpBB/includes/style/template_renderer.php b/phpBB/includes/style/template_renderer.php index 30e234a733..bd2a786e86 100644 --- a/phpBB/includes/style/template_renderer.php +++ b/phpBB/includes/style/template_renderer.php @@ -23,12 +23,12 @@ if (!defined('IN_PHPBB')) * * @package phpBB3 */ -interface phpbb_template_renderer +interface phpbb_style_template_renderer { /** * Displays the template managed by this renderer. * - * @param phpbb_template_context $context Template context to use + * @param phpbb_style_template_context $context Template context to use * @param array $lang Language entries to use */ public function render($context, $lang); diff --git a/phpBB/includes/style/template_renderer_eval.php b/phpBB/includes/style/template_renderer_eval.php index f8e4cb7b10..3e08b06e69 100644 --- a/phpBB/includes/style/template_renderer_eval.php +++ b/phpBB/includes/style/template_renderer_eval.php @@ -21,7 +21,7 @@ if (!defined('IN_PHPBB')) * * @package phpBB3 */ -class phpbb_template_renderer_eval implements phpbb_template_renderer +class phpbb_style_template_renderer_eval implements phpbb_style_template_renderer { /** * Template code to be eval'ed. @@ -33,7 +33,7 @@ class phpbb_template_renderer_eval implements phpbb_template_renderer * Template includes are delegated to template object $template. * * @param string $code php code of the template - * @param phpbb_template $template template object + * @param phpbb_style_template $template template object */ public function __construct($code, $template) { @@ -45,7 +45,7 @@ class phpbb_template_renderer_eval implements phpbb_template_renderer * Displays the template managed by this renderer by eval'ing php code * of the template. * - * @param phpbb_template_context $context Template context to use + * @param phpbb_style_template_context $context Template context to use * @param array $lang Language entries to use */ public function render($context, $lang) diff --git a/phpBB/includes/style/template_renderer_include.php b/phpBB/includes/style/template_renderer_include.php index f5c9026abf..91c1a1bb65 100644 --- a/phpBB/includes/style/template_renderer_include.php +++ b/phpBB/includes/style/template_renderer_include.php @@ -22,7 +22,7 @@ if (!defined('IN_PHPBB')) * * @package phpBB3 */ -class phpbb_template_renderer_include implements phpbb_template_renderer +class phpbb_style_template_renderer_include implements phpbb_style_template_renderer { /** * Template path to be included. @@ -45,7 +45,7 @@ class phpbb_template_renderer_include implements phpbb_template_renderer * Displays the template managed by this renderer by including * the php file containing the template. * - * @param phpbb_template_context $context Template context to use + * @param phpbb_style_template_context $context Template context to use * @param array $lang Language entries to use */ public function render($context, $lang) diff --git a/phpBB/install/index.php b/phpBB/install/index.php index 9d003ba6ab..9b0dde1009 100644 --- a/phpBB/install/index.php +++ b/phpBB/install/index.php @@ -201,9 +201,9 @@ $config = new phpbb_config(array( 'load_tplcompile' => '1' )); -$phpbb_template_locator = new phpbb_template_locator(); -$phpbb_template_path_provider = new phpbb_template_path_provider(); -$template = new phpbb_template($phpbb_root_path, $phpEx, $config, $user, $phpbb_template_locator, $phpbb_template_path_provider); +$phpbb_style_locator = new phpbb_style_locator(); +$phpbb_style_path_provider = new phpbb_style_path_provider(); +$template = new phpbb_style_template($phpbb_root_path, $phpEx, $config, $user, $phpbb_style_locator, $phpbb_style_path_provider); $template->set_ext_dir_prefix('adm/'); $template->set_custom_template('../adm/style', 'admin'); $template->assign_var('T_ASSETS_PATH', '../assets'); diff --git a/tests/template/renderer_eval_test.php b/tests/template/renderer_eval_test.php index 7ebb8b9bda..9b4f74c824 100644 --- a/tests/template/renderer_eval_test.php +++ b/tests/template/renderer_eval_test.php @@ -13,8 +13,8 @@ class phpbb_template_renderer_eval_test extends phpbb_test_case { $compiled_code = ''; $valid_code = ''; - $context = new phpbb_template_context(); - $template = new phpbb_template_renderer_eval($compiled_code, NULL); + $context = new phpbb_style_template_context(); + $template = new phpbb_style_template_renderer_eval($compiled_code, NULL); ob_start(); try { diff --git a/tests/template/template_compile_test.php b/tests/template/template_compile_test.php index a5e8a5e87a..fb158cabd5 100644 --- a/tests/template/template_compile_test.php +++ b/tests/template/template_compile_test.php @@ -16,7 +16,7 @@ class phpbb_template_template_compile_test extends phpbb_test_case protected function setUp() { - $this->template_compile = new phpbb_template_compile(false); + $this->template_compile = new phpbb_style_template_compile(false); $this->template_path = dirname(__FILE__) . '/templates'; } diff --git a/tests/template/template_inheritance_test.php b/tests/template/template_inheritance_test.php index 6987ae6c73..e2a2ac2261 100644 --- a/tests/template/template_inheritance_test.php +++ b/tests/template/template_inheritance_test.php @@ -71,9 +71,9 @@ class phpbb_template_template_inheritance_test extends phpbb_template_template_t $this->template_path = dirname(__FILE__) . '/templates'; $this->parent_template_path = dirname(__FILE__) . '/parent_templates'; - $this->template_locator = new phpbb_template_locator(); - $this->template_provider = new phpbb_template_path_provider(); - $this->template = new phpbb_template($phpbb_root_path, $phpEx, $config, $user, $this->template_locator, $this->template_provider); + $this->template_locator = new phpbb_style_locator(); + $this->template_provider = new phpbb_style_path_provider(); + $this->template = new phpbb_style_template($phpbb_root_path, $phpEx, $config, $user, $this->template_locator, $this->template_provider); $this->template->set_custom_template($this->template_path, 'tests', $this->parent_template_path, 'parent'); } } diff --git a/tests/template/template_test_case.php b/tests/template/template_test_case.php index 5b60785fee..8eea11e84f 100644 --- a/tests/template/template_test_case.php +++ b/tests/template/template_test_case.php @@ -63,9 +63,9 @@ class phpbb_template_template_test_case extends phpbb_test_case $config = new phpbb_config(array_merge($defaults, $new_config)); $this->template_path = dirname(__FILE__) . '/templates'; - $this->template_locator = new phpbb_template_locator(); - $this->template_provider = new phpbb_template_path_provider(); - $this->template = new phpbb_template($phpbb_root_path, $phpEx, $config, $user, $this->template_locator, $this->template_provider); + $this->template_locator = new phpbb_style_locator(); + $this->template_provider = new phpbb_style_path_provider(); + $this->template = new phpbb_style_template($phpbb_root_path, $phpEx, $config, $user, $this->template_locator, $this->template_provider); $this->template->set_custom_template($this->template_path, 'tests'); } From ae3b0f736d45690d37a10a453a98e598166e8506 Mon Sep 17 00:00:00 2001 From: Vjacheslav Trushkin Date: Wed, 14 Mar 2012 23:18:18 +0200 Subject: [PATCH 005/114] [feature/merging-style-components] Updating database and acp modules Removing theme and template tables, adding new columns to styles table, deleting acp modules, deleting code that updates theme in updater PHPBB3-10632 --- phpBB/develop/create_schema_files.php | 37 ++---------- phpBB/develop/mysql_upgrader.php | 55 ++--------------- phpBB/install/database_update.php | 47 ++++++++++++--- phpBB/install/install_update.php | 58 ++---------------- phpBB/install/schemas/firebird_schema.sql | 57 ++---------------- phpBB/install/schemas/mssql_schema.sql | 59 ++---------------- phpBB/install/schemas/mysql_40_schema.sql | 35 ++--------- phpBB/install/schemas/mysql_41_schema.sql | 35 ++--------- phpBB/install/schemas/oracle_schema.sql | 73 ++--------------------- phpBB/install/schemas/postgres_schema.sql | 41 ++----------- phpBB/install/schemas/schema_data.sql | 8 +-- phpBB/install/schemas/sqlite_schema.sql | 31 ++-------- 12 files changed, 81 insertions(+), 455 deletions(-) diff --git a/phpBB/develop/create_schema_files.php b/phpBB/develop/create_schema_files.php index 80d6e05d09..80ba1b251a 100644 --- a/phpBB/develop/create_schema_files.php +++ b/phpBB/develop/create_schema_files.php @@ -1654,43 +1654,14 @@ function get_schema_struct() 'style_name' => array('VCHAR_UNI:255', ''), 'style_copyright' => array('VCHAR_UNI', ''), 'style_active' => array('BOOL', 1), - 'template_id' => array('UINT', 0), - 'theme_id' => array('UINT', 0), + 'style_path' => array('VCHAR:100', ''), + 'bbcode_bitfield' => array('VCHAR:255', 'kNg='), + 'style_parent_id' => array('UINT:4', 0), + 'style_parent_tree' => array('TEXT', ''), ), 'PRIMARY_KEY' => 'style_id', 'KEYS' => array( 'style_name' => array('UNIQUE', 'style_name'), - 'template_id' => array('INDEX', 'template_id'), - 'theme_id' => array('INDEX', 'theme_id'), - ), - ); - - $schema_data['phpbb_styles_template'] = array( - 'COLUMNS' => array( - 'template_id' => array('UINT', NULL, 'auto_increment'), - 'template_name' => array('VCHAR_UNI:255', ''), - 'template_copyright' => array('VCHAR_UNI', ''), - 'template_path' => array('VCHAR:100', ''), - 'bbcode_bitfield' => array('VCHAR:255', 'kNg='), - 'template_inherits_id' => array('UINT:4', 0), - 'template_inherit_path' => array('VCHAR', ''), - ), - 'PRIMARY_KEY' => 'template_id', - 'KEYS' => array( - 'tmplte_nm' => array('UNIQUE', 'template_name'), - ), - ); - - $schema_data['phpbb_styles_theme'] = array( - 'COLUMNS' => array( - 'theme_id' => array('UINT', NULL, 'auto_increment'), - 'theme_name' => array('VCHAR_UNI:255', ''), - 'theme_copyright' => array('VCHAR_UNI', ''), - 'theme_path' => array('VCHAR:100', ''), - ), - 'PRIMARY_KEY' => 'theme_id', - 'KEYS' => array( - 'theme_name' => array('UNIQUE', 'theme_name'), ), ); diff --git a/phpBB/develop/mysql_upgrader.php b/phpBB/develop/mysql_upgrader.php index 69fcd690b7..88596e9461 100644 --- a/phpBB/develop/mysql_upgrader.php +++ b/phpBB/develop/mysql_upgrader.php @@ -1091,61 +1091,14 @@ function get_schema_struct() 'style_name' => array('VCHAR_UNI:255', ''), 'style_copyright' => array('VCHAR_UNI', ''), 'style_active' => array('BOOL', 1), - 'template_id' => array('UINT', 0), - 'theme_id' => array('UINT', 0), + 'style_path' => array('VCHAR:100', ''), + 'bbcode_bitfield' => array('VCHAR:255', 'kNg='), + 'style_parent_id' => array('UINT:4', 0), + 'style_parent_tree' => array('TEXT', ''), ), 'PRIMARY_KEY' => 'style_id', 'KEYS' => array( 'style_name' => array('UNIQUE', 'style_name'), - 'template_id' => array('INDEX', 'template_id'), - 'theme_id' => array('INDEX', 'theme_id'), - ), - ); - - $schema_data['phpbb_styles_template'] = array( - 'COLUMNS' => array( - 'template_id' => array('UINT', NULL, 'auto_increment'), - 'template_name' => array('VCHAR_UNI:255', ''), - 'template_copyright' => array('VCHAR_UNI', ''), - 'template_path' => array('VCHAR:100', ''), - 'bbcode_bitfield' => array('VCHAR:255', 'kNg='), - 'template_storedb' => array('BOOL', 0), - 'template_inherits_id' => array('UINT:4', 0), - 'template_inherit_path' => array('VCHAR', ''), - ), - 'PRIMARY_KEY' => 'template_id', - 'KEYS' => array( - 'tmplte_nm' => array('UNIQUE', 'template_name'), - ), - ); - - $schema_data['phpbb_styles_template_data'] = array( - 'COLUMNS' => array( - 'template_id' => array('UINT', 0), - 'template_filename' => array('VCHAR:100', ''), - 'template_included' => array('TEXT', ''), - 'template_mtime' => array('TIMESTAMP', 0), - 'template_data' => array('MTEXT_UNI', ''), - ), - 'KEYS' => array( - 'tid' => array('INDEX', 'template_id'), - 'tfn' => array('INDEX', 'template_filename'), - ), - ); - - $schema_data['phpbb_styles_theme'] = array( - 'COLUMNS' => array( - 'theme_id' => array('UINT', NULL, 'auto_increment'), - 'theme_name' => array('VCHAR_UNI:255', ''), - 'theme_copyright' => array('VCHAR_UNI', ''), - 'theme_path' => array('VCHAR:100', ''), - 'theme_storedb' => array('BOOL', 0), - 'theme_mtime' => array('TIMESTAMP', 0), - 'theme_data' => array('MTEXT_UNI', ''), - ), - 'PRIMARY_KEY' => 'theme_id', - 'KEYS' => array( - 'theme_name' => array('UNIQUE', 'theme_name'), ), ); diff --git a/phpBB/install/database_update.php b/phpBB/install/database_update.php index 843e8c2f23..995f4c9a95 100644 --- a/phpBB/install/database_update.php +++ b/phpBB/install/database_update.php @@ -1088,6 +1088,12 @@ function database_update_info() PROFILE_FIELDS_TABLE => array( 'field_show_on_pm' => array('BOOL', 0), ), + STYLES_TABLE => array( + 'style_path' => array('VCHAR:100', ''), + 'bbcode_bitfield' => array('VCHAR:255', 'kNg='), + 'style_parent_id' => array('UINT:4', 0), + 'style_parent_tree' => array('TEXT', ''), + ), ), 'change_columns' => array( GROUPS_TABLE => array( @@ -1097,20 +1103,16 @@ function database_update_info() 'drop_columns' => array( STYLES_TABLE => array( 'imageset_id', + 'template_id', + 'theme_id', ), - STYLES_TEMPLATE_TABLE => array( - 'template_storedb', - ), - STYLES_THEME_TABLE => array( - 'theme_storedb', - 'theme_mtime', - 'theme_data', - ), ), 'drop_tables' => array( STYLES_IMAGESET_TABLE, STYLES_IMAGESET_DATA_TABLE, + STYLES_TEMPLATE_TABLE, STYLES_TEMPLATE_DATA_TABLE, + STYLES_THEME_TABLE, ), ), ); @@ -2267,12 +2269,33 @@ function change_database_data(&$no_updates, $version) 'auth' => 'acl_a_attach', 'cat' => 'ACP_ATTACHMENTS', ), + 'install' => array( + 'base' => 'acp_styles' + 'class' => 'acp', + 'title' => 'ACP_STYLES_INSTALL', + 'auth' => 'acl_a_styles', + 'cat' => 'ACP_STYLE_MANAGEMENT', + ), + 'edit' => array( + 'base' => 'acp_styles' + 'class' => 'acp', + 'title' => 'ACP_STYLES_EDIT', + 'auth' => 'acl_a_styles', + 'cat' => 'ACP_STYLE_MANAGEMENT', + ), + 'cache' => array( + 'base' => 'acp_styles' + 'class' => 'acp', + 'title' => 'ACP_STYLES_CACHE', + 'auth' => 'acl_a_styles', + 'cat' => 'ACP_STYLE_MANAGEMENT', + ), ); _add_modules($modules_to_install); $sql = 'DELETE FROM ' . MODULES_TABLE . " - WHERE module_basename = 'styles' AND module_mode = 'imageset'"; + WHERE (module_basename = 'styles' OR module_basename = 'acp_styles') AND (module_mode = 'imageset' OR module_mode = 'theme' OR module_mode = 'template')"; _sql($sql, $errored, $error_ary); // Localise Global Announcements @@ -2362,7 +2385,13 @@ function change_database_data(&$no_updates, $version) { set_config('teampage_memberships', '1'); } + + // Clear styles table and add prosilver entry + _sql('DELETE FROM ' . STYLES_TABLE, $errored, $error_ary); + $sql = 'INSERT INTO ' . STYLES_TABLE . " (style_name, style_copyright, style_active, style_path, bbcode_bitfield, style_parent_id, style_parent_tree) VALUES ('prosilver', '© phpBB Group', 1, 'prosilver', 'kNg=', 0, '')"; + _sql($sql, $errored, $error_ary); + $no_updates = false; break; diff --git a/phpBB/install/install_update.php b/phpBB/install/install_update.php index 9f50a56595..aba692aa62 100644 --- a/phpBB/install/install_update.php +++ b/phpBB/install/install_update.php @@ -504,56 +504,6 @@ class install_update extends module // Add database update to log add_log('admin', 'LOG_UPDATE_PHPBB', $this->current_version, $this->update_to_version); - // Refresh prosilver css data - this may cause some unhappy users, but - $sql = 'SELECT * - FROM ' . STYLES_THEME_TABLE . " - WHERE LOWER(theme_name) = 'prosilver'"; - $result = $db->sql_query($sql); - $theme = $db->sql_fetchrow($result); - $db->sql_freeresult($result); - - if ($theme) - { - $recache = (empty($theme['theme_data'])) ? true : false; - $update_time = time(); - - // We test for stylesheet.css because it is faster and most likely the only file changed on common themes - if (!$recache && $theme['theme_mtime'] < @filemtime("{$phpbb_root_path}styles/" . $theme['theme_path'] . '/theme/stylesheet.css')) - { - $recache = true; - $update_time = @filemtime("{$phpbb_root_path}styles/" . $theme['theme_path'] . '/theme/stylesheet.css'); - } - else if (!$recache) - { - $last_change = $theme['theme_mtime']; - $dir = @opendir("{$phpbb_root_path}styles/{$theme['theme_path']}/theme"); - - if ($dir) - { - while (($entry = readdir($dir)) !== false) - { - if (substr(strrchr($entry, '.'), 1) == 'css' && $last_change < @filemtime("{$phpbb_root_path}styles/{$theme['theme_path']}/theme/{$entry}")) - { - $recache = true; - break; - } - } - closedir($dir); - } - } - - if ($recache) - { - // Instead of re-caching here, we simply remove theme_data... HAR HAR HAR (think about a carribean pirate) - $sql = 'UPDATE ' . STYLES_THEME_TABLE . " SET theme_data = '' - WHERE theme_id = " . $theme['theme_id']; - $db->sql_query($sql); - - $cache->destroy('sql', STYLES_THEME_TABLE); - $cache->destroy('sql', STYLES_TABLE); - } - } - $db->sql_return_on_error(true); $db->sql_query('DELETE FROM ' . CONFIG_TABLE . " WHERE config_name = 'version_update_from'"); $db->sql_return_on_error(false); @@ -1694,9 +1644,9 @@ class install_update extends module $info['custom'] = array(); /* // Get custom installed styles... - $sql = 'SELECT template_name, template_path - FROM ' . STYLES_TEMPLATE_TABLE . " - WHERE LOWER(template_name) NOT IN ('subsilver2', 'prosilver')"; + $sql = 'SELECT style_name, style_path + FROM ' . STYLES_TABLE . " + WHERE LOWER(style_name) NOT IN ('subsilver2', 'prosilver')"; $result = $db->sql_query($sql); $templates = array(); @@ -1715,7 +1665,7 @@ class install_update extends module { foreach ($templates as $row) { - $info['custom'][$filename][] = str_replace('/prosilver/', '/' . $row['template_path'] . '/', $filename); + $info['custom'][$filename][] = str_replace('/prosilver/', '/' . $row['style_path'] . '/', $filename); } } } diff --git a/phpBB/install/schemas/firebird_schema.sql b/phpBB/install/schemas/firebird_schema.sql index daeba45864..adea0b4cc2 100644 --- a/phpBB/install/schemas/firebird_schema.sql +++ b/phpBB/install/schemas/firebird_schema.sql @@ -1086,15 +1086,15 @@ CREATE TABLE phpbb_styles ( style_name VARCHAR(255) CHARACTER SET UTF8 DEFAULT '' NOT NULL COLLATE UNICODE, style_copyright VARCHAR(255) CHARACTER SET UTF8 DEFAULT '' NOT NULL COLLATE UNICODE, style_active INTEGER DEFAULT 1 NOT NULL, - template_id INTEGER DEFAULT 0 NOT NULL, - theme_id INTEGER DEFAULT 0 NOT NULL + style_path VARCHAR(100) CHARACTER SET NONE DEFAULT '' NOT NULL, + bbcode_bitfield VARCHAR(255) CHARACTER SET NONE DEFAULT 'kNg=' NOT NULL, + style_parent_id INTEGER DEFAULT 0 NOT NULL, + style_parent_tree BLOB SUB_TYPE TEXT CHARACTER SET NONE DEFAULT '' NOT NULL );; ALTER TABLE phpbb_styles ADD PRIMARY KEY (style_id);; CREATE UNIQUE INDEX phpbb_styles_style_name ON phpbb_styles(style_name);; -CREATE INDEX phpbb_styles_template_id ON phpbb_styles(template_id);; -CREATE INDEX phpbb_styles_theme_id ON phpbb_styles(theme_id);; CREATE GENERATOR phpbb_styles_gen;; SET GENERATOR phpbb_styles_gen TO 0;; @@ -1107,55 +1107,6 @@ BEGIN END;; -# Table: 'phpbb_styles_template' -CREATE TABLE phpbb_styles_template ( - template_id INTEGER NOT NULL, - template_name VARCHAR(255) CHARACTER SET UTF8 DEFAULT '' NOT NULL COLLATE UNICODE, - template_copyright VARCHAR(255) CHARACTER SET UTF8 DEFAULT '' NOT NULL COLLATE UNICODE, - template_path VARCHAR(100) CHARACTER SET NONE DEFAULT '' NOT NULL, - bbcode_bitfield VARCHAR(255) CHARACTER SET NONE DEFAULT 'kNg=' NOT NULL, - template_inherits_id INTEGER DEFAULT 0 NOT NULL, - template_inherit_path VARCHAR(255) CHARACTER SET NONE DEFAULT '' NOT NULL -);; - -ALTER TABLE phpbb_styles_template ADD PRIMARY KEY (template_id);; - -CREATE UNIQUE INDEX phpbb_styles_template_tmplte_nm ON phpbb_styles_template(template_name);; - -CREATE GENERATOR phpbb_styles_template_gen;; -SET GENERATOR phpbb_styles_template_gen TO 0;; - -CREATE TRIGGER t_phpbb_styles_template FOR phpbb_styles_template -BEFORE INSERT -AS -BEGIN - NEW.template_id = GEN_ID(phpbb_styles_template_gen, 1); -END;; - - -# Table: 'phpbb_styles_theme' -CREATE TABLE phpbb_styles_theme ( - theme_id INTEGER NOT NULL, - theme_name VARCHAR(255) CHARACTER SET UTF8 DEFAULT '' NOT NULL COLLATE UNICODE, - theme_copyright VARCHAR(255) CHARACTER SET UTF8 DEFAULT '' NOT NULL COLLATE UNICODE, - theme_path VARCHAR(100) CHARACTER SET NONE DEFAULT '' NOT NULL -);; - -ALTER TABLE phpbb_styles_theme ADD PRIMARY KEY (theme_id);; - -CREATE UNIQUE INDEX phpbb_styles_theme_theme_name ON phpbb_styles_theme(theme_name);; - -CREATE GENERATOR phpbb_styles_theme_gen;; -SET GENERATOR phpbb_styles_theme_gen TO 0;; - -CREATE TRIGGER t_phpbb_styles_theme FOR phpbb_styles_theme -BEFORE INSERT -AS -BEGIN - NEW.theme_id = GEN_ID(phpbb_styles_theme_gen, 1); -END;; - - # Table: 'phpbb_topics' CREATE TABLE phpbb_topics ( topic_id INTEGER NOT NULL, diff --git a/phpBB/install/schemas/mssql_schema.sql b/phpBB/install/schemas/mssql_schema.sql index 736917fdcb..292a85b816 100644 --- a/phpBB/install/schemas/mssql_schema.sql +++ b/phpBB/install/schemas/mssql_schema.sql @@ -1322,8 +1322,10 @@ CREATE TABLE [phpbb_styles] ( [style_name] [varchar] (255) DEFAULT ('') NOT NULL , [style_copyright] [varchar] (255) DEFAULT ('') NOT NULL , [style_active] [int] DEFAULT (1) NOT NULL , - [template_id] [int] DEFAULT (0) NOT NULL , - [theme_id] [int] DEFAULT (0) NOT NULL + [style_path] [varchar] (100) DEFAULT ('') NOT NULL , + [bbcode_bitfield] [varchar] (255) DEFAULT ('kNg=') NOT NULL , + [style_parent_id] [int] DEFAULT (0) NOT NULL , + [style_parent_tree] [varchar] (8000) DEFAULT ('') NOT NULL ) ON [PRIMARY] GO @@ -1337,59 +1339,6 @@ GO CREATE UNIQUE INDEX [style_name] ON [phpbb_styles]([style_name]) ON [PRIMARY] GO -CREATE INDEX [template_id] ON [phpbb_styles]([template_id]) ON [PRIMARY] -GO - -CREATE INDEX [theme_id] ON [phpbb_styles]([theme_id]) ON [PRIMARY] -GO - - -/* - Table: 'phpbb_styles_template' -*/ -CREATE TABLE [phpbb_styles_template] ( - [template_id] [int] IDENTITY (1, 1) NOT NULL , - [template_name] [varchar] (255) DEFAULT ('') NOT NULL , - [template_copyright] [varchar] (255) DEFAULT ('') NOT NULL , - [template_path] [varchar] (100) DEFAULT ('') NOT NULL , - [bbcode_bitfield] [varchar] (255) DEFAULT ('kNg=') NOT NULL , - [template_inherits_id] [int] DEFAULT (0) NOT NULL , - [template_inherit_path] [varchar] (255) DEFAULT ('') NOT NULL -) ON [PRIMARY] -GO - -ALTER TABLE [phpbb_styles_template] WITH NOCHECK ADD - CONSTRAINT [PK_phpbb_styles_template] PRIMARY KEY CLUSTERED - ( - [template_id] - ) ON [PRIMARY] -GO - -CREATE UNIQUE INDEX [tmplte_nm] ON [phpbb_styles_template]([template_name]) ON [PRIMARY] -GO - - -/* - Table: 'phpbb_styles_theme' -*/ -CREATE TABLE [phpbb_styles_theme] ( - [theme_id] [int] IDENTITY (1, 1) NOT NULL , - [theme_name] [varchar] (255) DEFAULT ('') NOT NULL , - [theme_copyright] [varchar] (255) DEFAULT ('') NOT NULL , - [theme_path] [varchar] (100) DEFAULT ('') NOT NULL -) ON [PRIMARY] -GO - -ALTER TABLE [phpbb_styles_theme] WITH NOCHECK ADD - CONSTRAINT [PK_phpbb_styles_theme] PRIMARY KEY CLUSTERED - ( - [theme_id] - ) ON [PRIMARY] -GO - -CREATE UNIQUE INDEX [theme_name] ON [phpbb_styles_theme]([theme_name]) ON [PRIMARY] -GO - /* Table: 'phpbb_topics' diff --git a/phpBB/install/schemas/mysql_40_schema.sql b/phpBB/install/schemas/mysql_40_schema.sql index 97c378621b..13d0199b8a 100644 --- a/phpBB/install/schemas/mysql_40_schema.sql +++ b/phpBB/install/schemas/mysql_40_schema.sql @@ -760,37 +760,12 @@ CREATE TABLE phpbb_styles ( style_name blob NOT NULL, style_copyright blob NOT NULL, style_active tinyint(1) UNSIGNED DEFAULT '1' NOT NULL, - template_id mediumint(8) UNSIGNED DEFAULT '0' NOT NULL, - theme_id mediumint(8) UNSIGNED DEFAULT '0' NOT NULL, - PRIMARY KEY (style_id), - UNIQUE style_name (style_name(255)), - KEY template_id (template_id), - KEY theme_id (theme_id) -); - - -# Table: 'phpbb_styles_template' -CREATE TABLE phpbb_styles_template ( - template_id mediumint(8) UNSIGNED NOT NULL auto_increment, - template_name blob NOT NULL, - template_copyright blob NOT NULL, - template_path varbinary(100) DEFAULT '' NOT NULL, + style_path varbinary(100) DEFAULT '' NOT NULL, bbcode_bitfield varbinary(255) DEFAULT 'kNg=' NOT NULL, - template_inherits_id int(4) UNSIGNED DEFAULT '0' NOT NULL, - template_inherit_path varbinary(255) DEFAULT '' NOT NULL, - PRIMARY KEY (template_id), - UNIQUE tmplte_nm (template_name(255)) -); - - -# Table: 'phpbb_styles_theme' -CREATE TABLE phpbb_styles_theme ( - theme_id mediumint(8) UNSIGNED NOT NULL auto_increment, - theme_name blob NOT NULL, - theme_copyright blob NOT NULL, - theme_path varbinary(100) DEFAULT '' NOT NULL, - PRIMARY KEY (theme_id), - UNIQUE theme_name (theme_name(255)) + style_parent_id int(4) UNSIGNED DEFAULT '0' NOT NULL, + style_parent_tree blob NOT NULL, + PRIMARY KEY (style_id), + UNIQUE style_name (style_name(255)) ); diff --git a/phpBB/install/schemas/mysql_41_schema.sql b/phpBB/install/schemas/mysql_41_schema.sql index 9615905625..c26cb89f37 100644 --- a/phpBB/install/schemas/mysql_41_schema.sql +++ b/phpBB/install/schemas/mysql_41_schema.sql @@ -760,37 +760,12 @@ CREATE TABLE phpbb_styles ( style_name varchar(255) DEFAULT '' NOT NULL, style_copyright varchar(255) DEFAULT '' NOT NULL, style_active tinyint(1) UNSIGNED DEFAULT '1' NOT NULL, - template_id mediumint(8) UNSIGNED DEFAULT '0' NOT NULL, - theme_id mediumint(8) UNSIGNED DEFAULT '0' NOT NULL, - PRIMARY KEY (style_id), - UNIQUE style_name (style_name), - KEY template_id (template_id), - KEY theme_id (theme_id) -) CHARACTER SET `utf8` COLLATE `utf8_bin`; - - -# Table: 'phpbb_styles_template' -CREATE TABLE phpbb_styles_template ( - template_id mediumint(8) UNSIGNED NOT NULL auto_increment, - template_name varchar(255) DEFAULT '' NOT NULL, - template_copyright varchar(255) DEFAULT '' NOT NULL, - template_path varchar(100) DEFAULT '' NOT NULL, + style_path varchar(100) DEFAULT '' NOT NULL, bbcode_bitfield varchar(255) DEFAULT 'kNg=' NOT NULL, - template_inherits_id int(4) UNSIGNED DEFAULT '0' NOT NULL, - template_inherit_path varchar(255) DEFAULT '' NOT NULL, - PRIMARY KEY (template_id), - UNIQUE tmplte_nm (template_name) -) CHARACTER SET `utf8` COLLATE `utf8_bin`; - - -# Table: 'phpbb_styles_theme' -CREATE TABLE phpbb_styles_theme ( - theme_id mediumint(8) UNSIGNED NOT NULL auto_increment, - theme_name varchar(255) DEFAULT '' NOT NULL, - theme_copyright varchar(255) DEFAULT '' NOT NULL, - theme_path varchar(100) DEFAULT '' NOT NULL, - PRIMARY KEY (theme_id), - UNIQUE theme_name (theme_name) + style_parent_id int(4) UNSIGNED DEFAULT '0' NOT NULL, + style_parent_tree text NOT NULL, + PRIMARY KEY (style_id), + UNIQUE style_name (style_name) ) CHARACTER SET `utf8` COLLATE `utf8_bin`; diff --git a/phpBB/install/schemas/oracle_schema.sql b/phpBB/install/schemas/oracle_schema.sql index 5d60d2a19e..23bdebdb8a 100644 --- a/phpBB/install/schemas/oracle_schema.sql +++ b/phpBB/install/schemas/oracle_schema.sql @@ -1444,17 +1444,15 @@ CREATE TABLE phpbb_styles ( style_name varchar2(765) DEFAULT '' , style_copyright varchar2(765) DEFAULT '' , style_active number(1) DEFAULT '1' NOT NULL, - template_id number(8) DEFAULT '0' NOT NULL, - theme_id number(8) DEFAULT '0' NOT NULL, + style_path varchar2(100) DEFAULT '' , + bbcode_bitfield varchar2(255) DEFAULT 'kNg=' NOT NULL, + style_parent_id number(4) DEFAULT '0' NOT NULL, + style_parent_tree clob DEFAULT '' , CONSTRAINT pk_phpbb_styles PRIMARY KEY (style_id), CONSTRAINT u_phpbb_style_name UNIQUE (style_name) ) / -CREATE INDEX phpbb_styles_template_id ON phpbb_styles (template_id) -/ -CREATE INDEX phpbb_styles_theme_id ON phpbb_styles (theme_id) -/ CREATE SEQUENCE phpbb_styles_seq / @@ -1472,69 +1470,6 @@ END; / -/* - Table: 'phpbb_styles_template' -*/ -CREATE TABLE phpbb_styles_template ( - template_id number(8) NOT NULL, - template_name varchar2(765) DEFAULT '' , - template_copyright varchar2(765) DEFAULT '' , - template_path varchar2(100) DEFAULT '' , - bbcode_bitfield varchar2(255) DEFAULT 'kNg=' NOT NULL, - template_inherits_id number(4) DEFAULT '0' NOT NULL, - template_inherit_path varchar2(255) DEFAULT '' , - CONSTRAINT pk_phpbb_styles_template PRIMARY KEY (template_id), - CONSTRAINT u_phpbb_tmplte_nm UNIQUE (template_name) -) -/ - - -CREATE SEQUENCE phpbb_styles_template_seq -/ - -CREATE OR REPLACE TRIGGER t_phpbb_styles_template -BEFORE INSERT ON phpbb_styles_template -FOR EACH ROW WHEN ( - new.template_id IS NULL OR new.template_id = 0 -) -BEGIN - SELECT phpbb_styles_template_seq.nextval - INTO :new.template_id - FROM dual; -END; -/ - - -/* - Table: 'phpbb_styles_theme' -*/ -CREATE TABLE phpbb_styles_theme ( - theme_id number(8) NOT NULL, - theme_name varchar2(765) DEFAULT '' , - theme_copyright varchar2(765) DEFAULT '' , - theme_path varchar2(100) DEFAULT '' , - CONSTRAINT pk_phpbb_styles_theme PRIMARY KEY (theme_id), - CONSTRAINT u_phpbb_theme_name UNIQUE (theme_name) -) -/ - - -CREATE SEQUENCE phpbb_styles_theme_seq -/ - -CREATE OR REPLACE TRIGGER t_phpbb_styles_theme -BEFORE INSERT ON phpbb_styles_theme -FOR EACH ROW WHEN ( - new.theme_id IS NULL OR new.theme_id = 0 -) -BEGIN - SELECT phpbb_styles_theme_seq.nextval - INTO :new.theme_id - FROM dual; -END; -/ - - /* Table: 'phpbb_topics' */ diff --git a/phpBB/install/schemas/postgres_schema.sql b/phpBB/install/schemas/postgres_schema.sql index d7377ac2e6..d18cb08539 100644 --- a/phpBB/install/schemas/postgres_schema.sql +++ b/phpBB/install/schemas/postgres_schema.sql @@ -994,47 +994,14 @@ CREATE TABLE phpbb_styles ( style_name varchar(255) DEFAULT '' NOT NULL, style_copyright varchar(255) DEFAULT '' NOT NULL, style_active INT2 DEFAULT '1' NOT NULL CHECK (style_active >= 0), - template_id INT4 DEFAULT '0' NOT NULL CHECK (template_id >= 0), - theme_id INT4 DEFAULT '0' NOT NULL CHECK (theme_id >= 0), + style_path varchar(100) DEFAULT '' NOT NULL, + bbcode_bitfield varchar(255) DEFAULT 'kNg=' NOT NULL, + style_parent_id INT4 DEFAULT '0' NOT NULL CHECK (style_parent_id >= 0), + style_parent_tree varchar(8000) DEFAULT '' NOT NULL, PRIMARY KEY (style_id) ); CREATE UNIQUE INDEX phpbb_styles_style_name ON phpbb_styles (style_name); -CREATE INDEX phpbb_styles_template_id ON phpbb_styles (template_id); -CREATE INDEX phpbb_styles_theme_id ON phpbb_styles (theme_id); - -/* - Table: 'phpbb_styles_template' -*/ -CREATE SEQUENCE phpbb_styles_template_seq; - -CREATE TABLE phpbb_styles_template ( - template_id INT4 DEFAULT nextval('phpbb_styles_template_seq'), - template_name varchar(255) DEFAULT '' NOT NULL, - template_copyright varchar(255) DEFAULT '' NOT NULL, - template_path varchar(100) DEFAULT '' NOT NULL, - bbcode_bitfield varchar(255) DEFAULT 'kNg=' NOT NULL, - template_inherits_id INT4 DEFAULT '0' NOT NULL CHECK (template_inherits_id >= 0), - template_inherit_path varchar(255) DEFAULT '' NOT NULL, - PRIMARY KEY (template_id) -); - -CREATE UNIQUE INDEX phpbb_styles_template_tmplte_nm ON phpbb_styles_template (template_name); - -/* - Table: 'phpbb_styles_theme' -*/ -CREATE SEQUENCE phpbb_styles_theme_seq; - -CREATE TABLE phpbb_styles_theme ( - theme_id INT4 DEFAULT nextval('phpbb_styles_theme_seq'), - theme_name varchar(255) DEFAULT '' NOT NULL, - theme_copyright varchar(255) DEFAULT '' NOT NULL, - theme_path varchar(100) DEFAULT '' NOT NULL, - PRIMARY KEY (theme_id) -); - -CREATE UNIQUE INDEX phpbb_styles_theme_theme_name ON phpbb_styles_theme (theme_name); /* Table: 'phpbb_topics' diff --git a/phpBB/install/schemas/schema_data.sql b/phpBB/install/schemas/schema_data.sql index 3255cafea2..43b09c97f7 100644 --- a/phpBB/install/schemas/schema_data.sql +++ b/phpBB/install/schemas/schema_data.sql @@ -437,13 +437,7 @@ INSERT INTO phpbb_acl_roles (role_name, role_description, role_type, role_order) INSERT INTO phpbb_acl_roles (role_name, role_description, role_type, role_order) VALUES ('ROLE_FORUM_NEW_MEMBER', 'ROLE_DESCRIPTION_FORUM_NEW_MEMBER', 'f_', 10); # -- phpbb_styles -INSERT INTO phpbb_styles (style_name, style_copyright, style_active, template_id, theme_id) VALUES ('prosilver', '© phpBB Group', 1, 1, 1); - -# -- phpbb_styles_template -INSERT INTO phpbb_styles_template (template_name, template_copyright, template_path, bbcode_bitfield) VALUES ('prosilver', '© phpBB Group', 'prosilver', 'lNg='); - -# -- phpbb_styles_theme -INSERT INTO phpbb_styles_theme (theme_name, theme_copyright, theme_path) VALUES ('prosilver', '© phpBB Group', 'prosilver'); +INSERT INTO phpbb_styles (style_name, style_copyright, style_active, style_path, bbcode_bitfield, style_parent_id, style_parent_tree) VALUES ('prosilver', '© phpBB Group', 1, 'prosilver', 'kNg=', 0, ''); # -- Forums INSERT INTO phpbb_forums (forum_name, forum_desc, left_id, right_id, parent_id, forum_type, forum_posts, forum_topics, forum_topics_real, forum_last_post_id, forum_last_poster_id, forum_last_poster_name, forum_last_poster_colour, forum_last_post_time, forum_link, forum_password, forum_image, forum_rules, forum_rules_link, forum_rules_uid, forum_desc_uid, prune_days, prune_viewed, forum_parents) VALUES ('{L_FORUMS_FIRST_CATEGORY}', '', 1, 4, 0, 0, 1, 1, 1, 1, 2, 'Admin', 'AA0000', 972086460, '', '', '', '', '', '', '', 0, 0, ''); diff --git a/phpBB/install/schemas/sqlite_schema.sql b/phpBB/install/schemas/sqlite_schema.sql index 257937275c..c5f417961d 100644 --- a/phpBB/install/schemas/sqlite_schema.sql +++ b/phpBB/install/schemas/sqlite_schema.sql @@ -736,36 +736,13 @@ CREATE TABLE phpbb_styles ( style_name varchar(255) NOT NULL DEFAULT '', style_copyright varchar(255) NOT NULL DEFAULT '', style_active INTEGER UNSIGNED NOT NULL DEFAULT '1', - template_id INTEGER UNSIGNED NOT NULL DEFAULT '0', - theme_id INTEGER UNSIGNED NOT NULL DEFAULT '0' + style_path varchar(100) NOT NULL DEFAULT '', + bbcode_bitfield varchar(255) NOT NULL DEFAULT 'kNg=', + style_parent_id INTEGER UNSIGNED NOT NULL DEFAULT '0', + style_parent_tree text(65535) NOT NULL DEFAULT '' ); CREATE UNIQUE INDEX phpbb_styles_style_name ON phpbb_styles (style_name); -CREATE INDEX phpbb_styles_template_id ON phpbb_styles (template_id); -CREATE INDEX phpbb_styles_theme_id ON phpbb_styles (theme_id); - -# Table: 'phpbb_styles_template' -CREATE TABLE phpbb_styles_template ( - template_id INTEGER PRIMARY KEY NOT NULL , - template_name varchar(255) NOT NULL DEFAULT '', - template_copyright varchar(255) NOT NULL DEFAULT '', - template_path varchar(100) NOT NULL DEFAULT '', - bbcode_bitfield varchar(255) NOT NULL DEFAULT 'kNg=', - template_inherits_id INTEGER UNSIGNED NOT NULL DEFAULT '0', - template_inherit_path varchar(255) NOT NULL DEFAULT '' -); - -CREATE UNIQUE INDEX phpbb_styles_template_tmplte_nm ON phpbb_styles_template (template_name); - -# Table: 'phpbb_styles_theme' -CREATE TABLE phpbb_styles_theme ( - theme_id INTEGER PRIMARY KEY NOT NULL , - theme_name varchar(255) NOT NULL DEFAULT '', - theme_copyright varchar(255) NOT NULL DEFAULT '', - theme_path varchar(100) NOT NULL DEFAULT '' -); - -CREATE UNIQUE INDEX phpbb_styles_theme_theme_name ON phpbb_styles_theme (theme_name); # Table: 'phpbb_topics' CREATE TABLE phpbb_topics ( From 234e5d6402978ba1a7cfbb3d163512657c7b87fc Mon Sep 17 00:00:00 2001 From: Vjacheslav Trushkin Date: Wed, 14 Mar 2012 23:22:02 +0200 Subject: [PATCH 006/114] [feature/merging-style-components] Implementing unlimited parent templates Implementing possibility of unlimited levels of parent templates. Paths are stored in style_parent_tree, entries are separated by / PHPBB3-10632 --- phpBB/includes/style/template.php | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/phpBB/includes/style/template.php b/phpBB/includes/style/template.php index a8c5139dd0..02fa0bd250 100644 --- a/phpBB/includes/style/template.php +++ b/phpBB/includes/style/template.php @@ -97,8 +97,8 @@ class phpbb_style_template */ public function set_template() { - $template_name = $this->user->theme['template_path']; - $fallback_name = ($this->user->theme['template_inherits_id']) ? $this->user->theme['template_inherit_path'] : false; + $template_name = $this->user->theme['style_path']; + $fallback_name = ($this->user->theme['style_parent_id']) ? array_reverse(explode('/', $this->user->theme['style_parent_tree'])) : false; return $this->set_custom_template(false, $template_name, false, $fallback_name); } @@ -121,17 +121,26 @@ class phpbb_style_template * * @param string $template_path Path to template directory * @param string $template_name Name of template - * @param string $fallback_template_path Path to fallback template - * @param string $fallback_template_name Name of fallback template + * @param string or array $fallback_template_path Path to fallback template + * @param string or array $fallback_template_name Name of fallback template */ public function set_custom_template($template_path, $template_name, $fallback_template_path = false, $fallback_template_name = false) { $templates = array($template_name => $template_path); - if ($fallback_template_name !== false) + if (is_string($fallback_template_name)) { $templates[$fallback_template_name] = $fallback_template_path; } + if (is_array($fallback_template_name)) + { + $i = 0; + foreach ($fallback_template_name as $fallback_template_name_item) + { + $templates[$fallback_template_name_item] = is_array($fallback_template_path) ? $fallback_template_path[$i] : $fallback_template_path; + $i ++; + } + } $this->provider->set_templates($templates, $this->phpbb_root_path); $this->locator->set_paths($this->provider); From ae7d290a2222455589d1dcbfba650f789acda508 Mon Sep 17 00:00:00 2001 From: Vjacheslav Trushkin Date: Wed, 14 Mar 2012 23:24:16 +0200 Subject: [PATCH 007/114] [feature/merging-style-components] Updating PHP files Removing theme and template entries in all files, except for acp styles section PHPBB3-10632 --- phpBB/includes/functions.php | 22 +++++++++++----------- phpBB/includes/session.php | 16 ++++++---------- 2 files changed, 17 insertions(+), 21 deletions(-) diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 9913a80a70..bd6272792b 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -3092,9 +3092,9 @@ function parse_cfg_file($filename, $lines = false) $parsed_items[$key] = $value; } - if (isset($parsed_items['inherit_from']) && isset($parsed_items['name']) && $parsed_items['inherit_from'] == $parsed_items['name']) + if (isset($parsed_items['parent']) && isset($parsed_items['name']) && $parsed_items['parent'] == $parsed_items['name']) { - unset($parsed_items['inherit_from']); + unset($parsed_items['parent']); } return $parsed_items; @@ -4728,9 +4728,9 @@ function page_header($page_title = '', $display_online_list = true, $item_id = 0 'S_SEARCH_HIDDEN_FIELDS' => build_hidden_fields($s_search_hidden_fields), 'T_ASSETS_PATH' => "{$web_path}assets", - 'T_THEME_PATH' => "{$web_path}styles/" . rawurlencode($user->theme['theme_path']) . '/theme', - 'T_TEMPLATE_PATH' => "{$web_path}styles/" . rawurlencode($user->theme['template_path']) . '/template', - 'T_SUPER_TEMPLATE_PATH' => (isset($user->theme['template_inherit_path']) && $user->theme['template_inherit_path']) ? "{$web_path}styles/" . rawurlencode($user->theme['template_inherit_path']) . '/template' : "{$web_path}styles/" . rawurlencode($user->theme['template_path']) . '/template', + 'T_THEME_PATH' => "{$web_path}styles/" . rawurlencode($user->theme['style_path']) . '/theme', + 'T_TEMPLATE_PATH' => "{$web_path}styles/" . rawurlencode($user->theme['style_path']) . '/template', + 'T_SUPER_TEMPLATE_PATH' => ($user->theme['style_parent_id']) ? "{$web_path}styles/" . rawurlencode($user->theme['style_parent_tree']) . '/template' : "{$web_path}styles/" . rawurlencode($user->theme['style_path']) . '/template', 'T_IMAGES_PATH' => "{$web_path}images/", 'T_SMILIES_PATH' => "{$web_path}{$config['smilies_path']}/", 'T_AVATAR_PATH' => "{$web_path}{$config['avatar_path']}/", @@ -4738,16 +4738,16 @@ function page_header($page_title = '', $display_online_list = true, $item_id = 0 'T_ICONS_PATH' => "{$web_path}{$config['icons_path']}/", 'T_RANKS_PATH' => "{$web_path}{$config['ranks_path']}/", 'T_UPLOAD_PATH' => "{$web_path}{$config['upload_path']}/", - 'T_STYLESHEET_LINK' => "{$web_path}styles/" . rawurlencode($user->theme['theme_path']) . '/theme/stylesheet.css', - 'T_STYLESHEET_LANG_LINK' => "{$web_path}styles/" . rawurlencode($user->theme['theme_path']) . '/theme/' . $user->lang_name . '/stylesheet.css', - 'T_STYLESHEET_NAME' => $user->theme['theme_name'], + 'T_STYLESHEET_LINK' => "{$web_path}styles/" . rawurlencode($user->theme['style_path']) . '/theme/stylesheet.css', + 'T_STYLESHEET_LANG_LINK' => "{$web_path}styles/" . rawurlencode($user->theme['style_path']) . '/theme/' . $user->lang_name . '/stylesheet.css', + 'T_STYLESHEET_NAME' => $user->theme['style_name'], 'T_JQUERY_LINK' => ($config['load_jquery_cdn'] && !empty($config['load_jquery_url'])) ? $config['load_jquery_url'] : "{$web_path}assets/javascript/jquery.js", 'S_JQUERY_FALLBACK' => ($config['load_jquery_cdn']) ? true : false, - 'T_THEME_NAME' => rawurlencode($user->theme['theme_path']), + 'T_THEME_NAME' => rawurlencode($user->theme['style_path']), 'T_THEME_LANG_NAME' => $user->data['user_lang'], - 'T_TEMPLATE_NAME' => $user->theme['template_path'], - 'T_SUPER_TEMPLATE_NAME' => rawurlencode((isset($user->theme['template_inherit_path']) && $user->theme['template_inherit_path']) ? $user->theme['template_inherit_path'] : $user->theme['template_path']), + 'T_TEMPLATE_NAME' => $user->theme['style_path'], + 'T_SUPER_TEMPLATE_NAME' => rawurlencode((isset($user->theme['style_parent_tree']) && $user->theme['style_parent_tree']) ? $user->theme['style_parent_tree'] : $user->theme['style_path']), 'T_IMAGES' => 'images', 'T_SMILIES' => $config['smilies_path'], 'T_AVATAR' => $config['avatar_path'], diff --git a/phpBB/includes/session.php b/phpBB/includes/session.php index 6dad068ecb..cd6f17154a 100644 --- a/phpBB/includes/session.php +++ b/phpBB/includes/session.php @@ -1653,11 +1653,9 @@ class user extends session $style = ($style) ? $style : ((!$config['override_user_style']) ? $this->data['user_style'] : $config['default_style']); } - $sql = 'SELECT s.style_id, t.template_path, t.template_id, t.bbcode_bitfield, t.template_inherits_id, t.template_inherit_path, c.theme_path, c.theme_name, c.theme_id - FROM ' . STYLES_TABLE . ' s, ' . STYLES_TEMPLATE_TABLE . ' t, ' . STYLES_THEME_TABLE . " c - WHERE s.style_id = $style - AND t.template_id = s.template_id - AND c.theme_id = s.theme_id"; + $sql = 'SELECT * + FROM ' . STYLES_TABLE . " s + WHERE s.style_id = $style"; $result = $db->sql_query($sql, 3600); $this->theme = $db->sql_fetchrow($result); $db->sql_freeresult($result); @@ -1672,11 +1670,9 @@ class user extends session WHERE user_id = {$this->data['user_id']}"; $db->sql_query($sql); - $sql = 'SELECT s.style_id, t.template_path, t.template_id, t.bbcode_bitfield, c.theme_path, c.theme_name, c.theme_id - FROM ' . STYLES_TABLE . ' s, ' . STYLES_TEMPLATE_TABLE . ' t, ' . STYLES_THEME_TABLE . " c - WHERE s.style_id = $style - AND t.template_id = s.template_id - AND c.theme_id = s.theme_id"; + $sql = 'SELECT * + FROM ' . STYLES_TABLE . " s + WHERE s.style_id = $style"; $result = $db->sql_query($sql, 3600); $this->theme = $db->sql_fetchrow($result); $db->sql_freeresult($result); From 68336ab137432ecf9322474a7853d5d16e660fb2 Mon Sep 17 00:00:00 2001 From: Vjacheslav Trushkin Date: Wed, 14 Mar 2012 23:25:07 +0200 Subject: [PATCH 008/114] [feature/merging-style-components] Updating coding guidelines Updating template inheritance section in coding guidelines PHPBB3-10632 --- phpBB/docs/coding-guidelines.html | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/phpBB/docs/coding-guidelines.html b/phpBB/docs/coding-guidelines.html index 55fbf6d4e8..e85be02d45 100644 --- a/phpBB/docs/coding-guidelines.html +++ b/phpBB/docs/coding-guidelines.html @@ -71,7 +71,7 @@
  • Templating
    1. General Templating
    2. -
    3. Template Inheritance
    4. +
    5. Styles Tree
  • Character Sets and Encodings
  • Translation (i18n/L10n) Guidelines @@ -1623,24 +1623,25 @@ div </form>
    -

    4.ii. Template Inheritance

    -

    When basing a new style on an existing one, it is not necessary to provide all the template files. By declaring the base style name in the inherit_from field in the template configuration file, the style can be set to inherit template files from the base style. The limitation on this is that the base style has to be installed and complete, meaning that it is not itself inheriting.

    +

    4.ii. Styles Tree

    +

    When basing a new style on an existing one, it is not necessary to provide all the template files. By declaring the base style name in the parent field in the style configuration file, the style can be set to reuse template files from the parent style.

    -

    The effect of doing so is that the template engine will use the template files in the new style where they exist, but fall back to files in the base style otherwise. Declaring a style to inherit from another also causes it to use some of the configuration settings of the base style, notably database storage.

    +

    The effect of doing so is that the template engine will use the template files in the new style where they exist, but fall back to files in the parent style otherwise.

    -

    We strongly encourage the use of inheritance for styles based on the bundled styles, as it will ease the update procedure.

    +

    We strongly encourage the use of parent styles for styles based on the bundled styles, as it will ease the update procedure.

    -        # General Information about this template
    -        name = inherits
    -        copyright = © phpBB Group, 2007
    -        version = 3.0.3
    +# General Information about this style
    +name = Custom Style
    +copyright = &copy; phpBB Group, 2007
    +version = 3.1.0
     
    -        # Defining a different template bitfield
    -        template_bitfield = lNg=
    +# Defining a different template bitfield
    +# template_bitfield = lNg=
     
    -        # Are we inheriting?
    -        inherit_from = prosilver
    +# Parent style
    +# Set value to empty or to this style's name if this style does not have a parent style
    +parent = prosilver
     		
    From 1cc9f60f959730c8432a8489527ce9e1606a7ebd Mon Sep 17 00:00:00 2001 From: Vjacheslav Trushkin Date: Wed, 14 Mar 2012 23:26:01 +0200 Subject: [PATCH 009/114] [feature/merging-style-components] Removing theme.cfg and template.cfg Removing theme.cfg and template.cfg PHPBB3-10632 --- phpBB/styles/prosilver/template/template.cfg | 30 ------------------- phpBB/styles/prosilver/theme/theme.cfg | 21 ------------- phpBB/styles/subsilver2/template/template.cfg | 27 ----------------- phpBB/styles/subsilver2/theme/theme.cfg | 21 ------------- 4 files changed, 99 deletions(-) delete mode 100644 phpBB/styles/prosilver/template/template.cfg delete mode 100644 phpBB/styles/prosilver/theme/theme.cfg delete mode 100644 phpBB/styles/subsilver2/template/template.cfg delete mode 100644 phpBB/styles/subsilver2/theme/theme.cfg diff --git a/phpBB/styles/prosilver/template/template.cfg b/phpBB/styles/prosilver/template/template.cfg deleted file mode 100644 index 22ca73b487..0000000000 --- a/phpBB/styles/prosilver/template/template.cfg +++ /dev/null @@ -1,30 +0,0 @@ -# -# phpBB Template Configuration File -# -# @package phpBB3 -# @copyright (c) 2006 phpBB Group -# @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 -# -# -# At the left is the name, please do not change this -# At the right the value is entered -# For on/off options the valid values are on, off, 1, 0, true and false -# -# Values get trimmed, if you want to add a space in front or at the end of -# the value, then enclose the value with single or double quotes. -# Single and double quotes do not need to be escaped. -# -# - -# General Information about this template -name = prosilver -copyright = © phpBB Group, 2007 -version = 3.1.0-dev - -# Defining a different template bitfield -template_bitfield = lNg= - -# Template inheritance -# See http://blog.phpbb.com/2008/07/31/templating-just-got-easier/ -# Set value to empty to ignore template inheritance -inherit_from = prosilver diff --git a/phpBB/styles/prosilver/theme/theme.cfg b/phpBB/styles/prosilver/theme/theme.cfg deleted file mode 100644 index eced2a665e..0000000000 --- a/phpBB/styles/prosilver/theme/theme.cfg +++ /dev/null @@ -1,21 +0,0 @@ -# -# phpBB Theme Configuration File -# -# @package phpBB3 -# @copyright (c) 2006 phpBB Group -# @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 -# -# -# At the left is the name, please do not change this -# At the right the value is entered -# For on/off options the valid values are on, off, 1, 0, true and false -# -# Values get trimmed, if you want to add a space in front or at the end of -# the value, then enclose the value with single or double quotes. -# Single and double quotes do not need to be escaped. -# - -# General Information about this theme -name = prosilver -copyright = © phpBB Group, 2007 -version = 3.1.0-dev diff --git a/phpBB/styles/subsilver2/template/template.cfg b/phpBB/styles/subsilver2/template/template.cfg deleted file mode 100644 index cf5562a8a4..0000000000 --- a/phpBB/styles/subsilver2/template/template.cfg +++ /dev/null @@ -1,27 +0,0 @@ -# -# phpBB Template Configuration File -# -# @package phpBB3 -# @copyright (c) 2005 phpBB Group -# @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 -# -# -# At the left is the name, please do not change this -# At the right the value is entered -# For on/off options the valid values are on, off, 1, 0, true and false -# -# Values get trimmed, if you want to add a space in front or at the end of -# the value, then enclose the value with single or double quotes. -# Single and double quotes do not need to be escaped. -# -# - -# General Information about this template -name = subsilver2 -copyright = © phpBB Group, 2003 -version = 3.1.0-dev - -# Template inheritance -# See http://blog.phpbb.com/2008/07/31/templating-just-got-easier/ -# Set value to empty to ignore template inheritance -inherit_from = subsilver2 diff --git a/phpBB/styles/subsilver2/theme/theme.cfg b/phpBB/styles/subsilver2/theme/theme.cfg deleted file mode 100644 index 16d66c844a..0000000000 --- a/phpBB/styles/subsilver2/theme/theme.cfg +++ /dev/null @@ -1,21 +0,0 @@ -# -# phpBB Theme Configuration File -# -# @package phpBB3 -# @copyright (c) 2005 phpBB Group -# @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 -# -# -# At the left is the name, please do not change this -# At the right the value is entered -# For on/off options the valid values are on, off, 1, 0, true and false -# -# Values get trimmed, if you want to add a space in front or at the end of -# the value, then enclose the value with single or double quotes. -# Single and double quotes do not need to be escaped. -# - -# General Information about this theme -name = subsilver2 -copyright = © phpBB Group, 2003 -version = 3.1.0-dev From 95a69639fdc8491e47386dcc7e95e715fe769aed Mon Sep 17 00:00:00 2001 From: Vjacheslav Trushkin Date: Wed, 14 Mar 2012 23:26:23 +0200 Subject: [PATCH 010/114] [feature/merging-style-components] Adding template information to style.cfg Adding template data to style.cfg and removing obsolete comments PHPBB3-10632 --- phpBB/styles/prosilver/style.cfg | 8 +++++++- phpBB/styles/subsilver2/style.cfg | 8 +++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/phpBB/styles/prosilver/style.cfg b/phpBB/styles/prosilver/style.cfg index 538e167df6..a80f1ed537 100644 --- a/phpBB/styles/prosilver/style.cfg +++ b/phpBB/styles/prosilver/style.cfg @@ -8,7 +8,6 @@ # # At the left is the name, please do not change this # At the right the value is entered -# For on/off options the valid values are on, off, 1, 0, true and false # # Values get trimmed, if you want to add a space in front or at the end of # the value, then enclose the value with single or double quotes. @@ -20,3 +19,10 @@ name = prosilver copyright = © phpBB Group, 2007 version = 3.1.0-dev + +# Defining a different template bitfield +# template_bitfield = lNg= + +# Parent style +# Set value to empty or to this style's name if this style does not have a parent style +parent = prosilver diff --git a/phpBB/styles/subsilver2/style.cfg b/phpBB/styles/subsilver2/style.cfg index 0804a27082..1a71e7254d 100644 --- a/phpBB/styles/subsilver2/style.cfg +++ b/phpBB/styles/subsilver2/style.cfg @@ -8,7 +8,6 @@ # # At the left is the name, please do not change this # At the right the value is entered -# For on/off options the valid values are on, off, 1, 0, true and false # # Values get trimmed, if you want to add a space in front or at the end of # the value, then enclose the value with single or double quotes. @@ -20,3 +19,10 @@ name = subsilver2 copyright = © 2005 phpBB Group version = 3.1.0-dev + +# Defining a different template bitfield +# template_bitfield = lNg= + +# Parent style +# Set value to empty or to this style's name if this style does not have a parent style +parent = subsilver2 From f32cc3ae8fc3fbd28f4fe9e6b7e2a4eb27cfac03 Mon Sep 17 00:00:00 2001 From: Vjacheslav Trushkin Date: Sat, 18 Feb 2012 01:20:21 +0200 Subject: [PATCH 011/114] [feature/merging-style-components] Admin.css additions for acp_styles Adding background colors for row iterations and font color for disabled rows to admin control panel css. PHPBB3-10632 --- phpBB/adm/style/admin.css | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/phpBB/adm/style/admin.css b/phpBB/adm/style/admin.css index ceda824e5a..14a2b6dded 100644 --- a/phpBB/adm/style/admin.css +++ b/phpBB/adm/style/admin.css @@ -626,12 +626,29 @@ td.name { .col1 { background-color: #DCEBFE; } .col2 { background-color: #F9F9F9; } +/* 4 row background colours for trees */ +.row1a { background-color: #F9F9F9; } +.row1b { background-color: #F6F6F6; } +.row2a { background-color: #E7EEF4; } +.row2b { background-color: #E3EBF2; } + .spacer { background-color: #DBDFE2; height: 1px; line-height: 1px; } +/* Deactivated row */ +.row-inactive { + color: #999; +} +.row-inactive a, .row-inactive strong { + color: #888; +} +.row-inactive a:hover { + color: #BC2A4D; +} + /* General form styles ----------------------------------------*/ fieldset { From ce215658eb70a2dab7309c5f949ceb9b3e1c5a29 Mon Sep 17 00:00:00 2001 From: Vjacheslav Trushkin Date: Sat, 18 Feb 2012 02:01:35 +0200 Subject: [PATCH 012/114] [feature/merging-style-components] Adjusting unit tests Adjusting unit tests for new styles table structure PHPBB3-10632 --- tests/dbal/fixtures/styles.xml | 24 ++++++++++++++++-------- tests/dbal/order_lower_test.php | 18 ++++++++++++------ 2 files changed, 28 insertions(+), 14 deletions(-) diff --git a/tests/dbal/fixtures/styles.xml b/tests/dbal/fixtures/styles.xml index 36fc22a48f..dcbe39d3b0 100644 --- a/tests/dbal/fixtures/styles.xml +++ b/tests/dbal/fixtures/styles.xml @@ -5,31 +5,39 @@ style_name style_copyright style_active - template_id - theme_id + style_path + bbcode_bitfield + style_parent_id + style_parent_tree 1 prosilver &copy; phpBB Group 1 - 1 - 1 + prosilver + kNg= + 0 + 2 prosilver2 &copy; phpBB Group 0 - 2 - 2 + prosilver2 + kNg= + 0 + 3 Prosilver1 &copy; phpBB Group 0 - 3 - 3 + prosilver1 + kNg= + 1 + prosilver diff --git a/tests/dbal/order_lower_test.php b/tests/dbal/order_lower_test.php index eaf5211508..e16c0c20ee 100644 --- a/tests/dbal/order_lower_test.php +++ b/tests/dbal/order_lower_test.php @@ -33,24 +33,30 @@ class phpbb_dbal_order_lower_test extends phpbb_database_test_case 'style_name' => 'prosilver', 'style_copyright' => '© phpBB Group', 'style_active' => 1, - 'template_id' => 1, - 'theme_id' => 1, + 'style_path' => 'prosilver', + 'bbcode_bitfield' => 'kNg=', + 'style_parent_id' => 0, + 'style_parent_tree' => '', ), array( 'style_id' => 3, 'style_name' => 'Prosilver1', 'style_copyright' => '© phpBB Group', 'style_active' => 0, - 'template_id' => 3, - 'theme_id' => 3, + 'style_path' => 'prosilver1', + 'bbcode_bitfield' => 'kNg=', + 'style_parent_id' => 1, + 'style_parent_tree' => 'prosilver', ), array( 'style_id' => 2, 'style_name' => 'prosilver2', 'style_copyright' => '© phpBB Group', 'style_active' => 0, - 'template_id' => 2, - 'theme_id' => 2, + 'style_path' => 'prosilver2', + 'bbcode_bitfield' => 'kNg=', + 'style_parent_id' => 0, + 'style_parent_tree' => '', ) ), $db->sql_fetchrowset($result) From 0c6955e73c72d69c91548bb0c3106e39ce166b70 Mon Sep 17 00:00:00 2001 From: Vjacheslav Trushkin Date: Wed, 14 Mar 2012 23:45:54 +0200 Subject: [PATCH 013/114] [feature/merging-style-components] Adding new language variables Adding new language variables for acp_styles and removing some unused variables PHPBB3-10632 --- phpBB/language/en/acp/common.php | 2 + phpBB/language/en/acp/styles.php | 64 +++++++++++++------------------- 2 files changed, 28 insertions(+), 38 deletions(-) diff --git a/phpBB/language/en/acp/common.php b/phpBB/language/en/acp/common.php index 7f1ecb5c01..254cd473a5 100644 --- a/phpBB/language/en/acp/common.php +++ b/phpBB/language/en/acp/common.php @@ -168,6 +168,8 @@ $lang = array_merge($lang, array( 'ACP_STYLE_COMPONENTS' => 'Style components', 'ACP_STYLE_MANAGEMENT' => 'Style management', 'ACP_STYLES' => 'Styles', + 'ACP_STYLES_CACHE' => 'Purge Cache', + 'ACP_STYLES_INSTALL' => 'Install Styles', 'ACP_SUBMIT_CHANGES' => 'Submit changes', diff --git a/phpBB/language/en/acp/styles.php b/phpBB/language/en/acp/styles.php index 59df82477e..fe7fae5808 100644 --- a/phpBB/language/en/acp/styles.php +++ b/phpBB/language/en/acp/styles.php @@ -35,15 +35,9 @@ if (empty($lang) || !is_array($lang)) // in a url you again do not need to specify an order e.g., 'Click %sHERE%s' is fine $lang = array_merge($lang, array( - 'ACP_STYLES_EXPLAIN' => 'Here you can manage the available styles on your board. A style consists of a template and theme. You may alter existing styles, delete, deactivate, reactivate, create or import new ones. You can also see what a style will look like using the preview function. The current default style is noted by the presence of an asterisk (*). Also listed is the total user count for each style, note that overriding user styles will not be reflected here.', - 'ACP_TEMPLATES_EXPLAIN' => 'A template set comprises all the markup used to generate the layout of your board. Here you can edit existing template sets, delete, export, import and preview sets. You can also modify the templating code used to generate BBCode.', - 'ACP_THEMES_EXPLAIN' => 'From here you can create, install, edit, delete and export themes. A theme is the combination of colours and images that are applied to your templates to define the basic look of your board. The range of options open to you depends on the configuration of your server and phpBB installation, see the manual for further details. Please note that when creating new themes the use of an existing theme as a basis is optional.', - 'ADD_STYLE' => 'Create style', - 'ADD_STYLE_EXPLAIN' => 'Here you can create a new style. Depending on your server configuration and file permissions you may have additional options. For example you may be able to base this style on an existing one. You may also be able to upload or import (from the store directory) a style archive. If you upload or import an archive the style name will be determined automatically.', + 'ACP_STYLES_EXPLAIN' => 'Here you can manage the available styles on your board. You may alter existing styles, delete, deactivate, reactivate, install new ones. You can also see what a style will look like using the preview function. Also listed is the total user count for each style, note that overriding user styles will not be reflected here.', 'ADD_TEMPLATE' => 'Create template', 'ADD_TEMPLATE_EXPLAIN' => 'Here you can add a new template. Depending on your server configuration and file permissions you may have additional options here. For example you may be able to base this template set on an existing one. You may also be able to upload or import (from the store directory) a template archive. If you upload or import an archive the template name can be optionally taken from the archive name (to do this leave the template name blank).', - 'ADD_THEME' => 'Create theme', - 'ADD_THEME_EXPLAIN' => 'Here you can add a new theme. Depending on your server configuration and file permissions you may have additional options here. For example you may be able to base this theme on an existing one. You may also be able to upload or import (from the store directory) a theme archive. If you upload or import an archive the theme name can be optionally taken from the archive name (to do this leave the theme name blank).', 'ARCHIVE_FORMAT' => 'Archive file type', 'AUTOMATIC_EXPLAIN' => 'Leave blank to attempt automatic detection.', @@ -58,7 +52,9 @@ $lang = array_merge($lang, array( 'CACHE_FILENAME' => 'Template file', 'CACHE_FILESIZE' => 'File size', 'CACHE_MODIFIED' => 'Modified', + 'CANNOT_BE_INSTALLED' => 'Cannot be installed', 'CONFIRM_TEMPLATE_CLEAR_CACHE' => 'Are you sure you wish to clear all cached versions of your template files?', + 'CONFIRM_DELETE_STYLES' => 'Are you sure you wish to delete selected styles?', 'COPYRIGHT' => 'Copyright', 'CREATE_STYLE' => 'Create new style', 'CREATE_TEMPLATE' => 'Create new template set', @@ -66,13 +62,14 @@ $lang = array_merge($lang, array( 'CURRENT_IMAGE' => 'Current image', 'DEACTIVATE_DEFAULT' => 'You cannot deactivate the default style.', + 'DELETE_DEFAULT' => 'You cannot delete the default style.', 'DELETE_FROM_FS' => 'Delete from filesystem', 'DELETE_STYLE' => 'Delete style', 'DELETE_STYLE_EXPLAIN' => 'Here you can remove the selected style. Take care in deleting styles, there is no undo capability.', + 'DELETE_STYLE_FILES_FAILED' => 'Error deleting files for style "%s".', + 'DELETE_STYLE_FILES_SUCCESS' => 'Files for style "%s" have been deleted.', 'DELETE_TEMPLATE' => 'Delete template', 'DELETE_TEMPLATE_EXPLAIN' => 'Here you can remove the selected template set from the database. Please note that there is no undo capability. It is recommended that you first export your set for possible future use.', - 'DELETE_THEME' => 'Delete theme', - 'DELETE_THEME_EXPLAIN' => 'Here you can remove the selected theme from the database. Please note that there is no undo capability. It is recommended that you first export your theme for possible future use.', 'DETAILS' => 'Details', 'DIMENSIONS_EXPLAIN' => 'Selecting yes here will include width/height parameters.', @@ -239,17 +236,10 @@ $lang = array_merge($lang, array( 'INCLUDE_THEME' => 'Include theme', 'INHERITING_FROM' => 'Inherits from', 'INSTALL_STYLE' => 'Install style', - 'INSTALL_STYLE_EXPLAIN' => 'Here you can install a new style and if appropriate the corresponding style elements. If you already have the relevant style elements installed they will not be overwritten. Some styles require existing style elements to already be installed. If you try installing such a style and do not have the required elements you will be notified.', - 'INSTALL_TEMPLATE' => 'Install Template', - 'INSTALL_TEMPLATE_EXPLAIN' => 'Here you can install a new template set. Depending on your server configuration you may have a number of options here.', - 'INSTALL_THEME' => 'Install theme', - 'INSTALL_THEME_EXPLAIN' => 'Here you can install your selected theme. You can edit certain details if you wish or use the installation defaults.', + 'INSTALL_STYLES' => 'Install styles', + 'INSTALL_STYLES_EXPLAIN' => 'Here you can install new styles.
    If you cannot find a specific style in list below, check if that style is already installed. If it is not installed, check if it was uploaded correctly.', 'INSTALLED_STYLE' => 'Installed styles', - 'INSTALLED_TEMPLATE' => 'Installed templates', - 'INSTALLED_THEME' => 'Installed themes', - - 'KEEP_TEMPLATE' => 'Keep “%s” template', - 'KEEP_THEME' => 'Keep “%s” theme', + 'INVALID_STYLE_ID' => 'Invalid style ID.', 'LINE_SPACING' => 'Line spacing', 'LOCALISED_IMAGES' => 'Localised', @@ -257,18 +247,17 @@ $lang = array_merge($lang, array( 'NO_CLASS' => 'Cannot find class in stylesheet.', 'NO_IMAGE' => 'No image', 'NO_IMAGE_ERROR' => 'Cannot find image on filesystem.', + 'NO_MATCHING_STYLES_FOUND' => 'No styles match your query.', 'NO_STYLE' => 'Cannot find style on filesystem.', 'NO_TEMPLATE' => 'Cannot find template on filesystem.', 'NO_THEME' => 'Cannot find theme on filesystem.', 'NO_UNINSTALLED_STYLE' => 'No uninstalled styles detected.', - 'NO_UNINSTALLED_TEMPLATE' => 'No uninstalled templates detected.', - 'NO_UNINSTALLED_THEME' => 'No uninstalled themes detected.', 'NO_UNIT' => 'None', 'ONLY_STYLE' => 'This is the only remaining style, you cannot delete it.', - 'ONLY_TEMPLATE' => 'This is the only remaining template set, you cannot delete it.', - 'ONLY_THEME' => 'This is the only remaining theme, you cannot delete it.', - 'OPTIONAL_BASIS' => 'Optional basis', + + 'PARENT_STYLE_NOT_FOUND' => 'Parent style was not found. This style may not work correctly. Please uninstall it.', + 'PURGED_CACHE' => 'Cache was purged.', 'REFRESH' => 'Refresh', 'REPEAT_NO' => 'None', @@ -282,8 +271,7 @@ $lang = array_merge($lang, array( 'REPLACE_THEME' => 'Replace theme with', 'REPLACE_THEME_EXPLAIN' => 'This theme will replace the one you are deleting in any styles that use it.', 'REPLACE_WITH_OPTION' => 'Replace with “%s”', - 'REQUIRES_TEMPLATE' => 'This style requires the %s template set to be installed.', - 'REQUIRES_THEME' => 'This style requires the %s theme to be installed.', + 'REQUIRES_STYLE' => 'This style requires the style "%s" to be installed.', 'SELECT_IMAGE' => 'Select image', 'SELECT_TEMPLATE' => 'Select template file', @@ -299,21 +287,31 @@ $lang = array_merge($lang, array( 'STYLE_ADDED' => 'Style added successfully.', 'STYLE_DEACTIVATE' => 'Deactivate', 'STYLE_DEFAULT' => 'Make default style', - 'STYLE_DELETED' => 'Style deleted successfully.', + 'STYLE_DEFAULT_CHANGE' => 'Change default style', + 'STYLE_DEFAULT_CHANGE_INACTIVE' => 'You must activate style before making it default style.', + 'STYLE_DELETE_DEPENDENT' => 'Style "%s" cannot be deleted because it has one or more child styles.', + 'STYLE_DELETED' => 'Style "%s" deleted successfully.', 'STYLE_DETAILS_UPDATED' => 'Style edited successfully.', 'STYLE_ERR_ARCHIVE' => 'Please select an archive method.', 'STYLE_ERR_COPY_LONG' => 'The copyright can be no longer than 60 characters.', + 'STYLE_ERR_INVALID_PARENT' => 'Invalid parent style.', 'STYLE_ERR_MORE_ELEMENTS' => 'You must select at least one style element.', 'STYLE_ERR_NAME_CHARS' => 'The style name can only contain alphanumeric characters, -, +, _ and space.', 'STYLE_ERR_NAME_EXIST' => 'A style with that name already exists.', 'STYLE_ERR_NAME_LONG' => 'The style name can be no longer than 30 characters.', - 'STYLE_ERR_NO_IDS' => 'You must select a template and theme for this style.', 'STYLE_ERR_NOT_STYLE' => 'The imported or uploaded file did not contain a valid style archive.', 'STYLE_ERR_STYLE_NAME' => 'You must supply a name for this style.', 'STYLE_EXPORT' => 'Export style', 'STYLE_EXPORT_EXPLAIN' => 'Here you can export a style in the form of an archive. A style does not need to contain all elements but it must contain at least one. For example if you have created a new theme for a commonly used template you could simply export the theme and omit the template. You may select whether to download the file directly or to place it in your store folder for download later or via FTP.', 'STYLE_EXPORTED' => 'Style exported successfully and stored in %s.', + 'STYLE_INSTALLED' => 'Style "%s" has been installed.', + 'STYLE_INSTALLED_EDIT_DETAILS' => 'Click here to edit style details or to change default style.', + 'STYLE_INSTALLED_RETURN_STYLES' => 'Click here to return to installed styles list.', + 'STYLE_INSTALLED_RETURN_UNINSTALLED' => 'Click here to install more styles.', 'STYLE_NAME' => 'Style name', + 'STYLE_NOT_INSTALLED' => 'Style "%s" was not installed.', + 'STYLE_PATH' => 'Style path:', + 'STYLE_PARENT' => 'Parent style:', 'STYLE_TEMPLATE' => 'Template', 'STYLE_THEME' => 'Theme', 'STYLE_USED_BY' => 'Used by (including robots)', @@ -323,8 +321,6 @@ $lang = array_merge($lang, array( 'TEMPLATE_CACHE_EXPLAIN' => 'By default phpBB caches the compiled version of its templates. This decreases the load on the server each time a page is viewed and thus may reduce the page generation time. Here you can view the cache status of each file and delete individual files or the entire cache.', 'TEMPLATE_CACHE_CLEARED' => 'Template cache cleared successfully.', 'TEMPLATE_CACHE_EMPTY' => 'There are no cached templates.', - 'TEMPLATE_DELETED' => 'Template set deleted successfully.', - 'TEMPLATE_DELETE_DEPENDENT' => 'The template set cannot be deleted as there are one or more other template sets inheriting from it:', 'TEMPLATE_DELETED_FS' => 'Template set removed from database but files remain on the filesystem.', 'TEMPLATE_DETAILS_UPDATED' => 'Template details successfully updated.', 'TEMPLATE_EDITOR' => 'Raw HTML template editor', @@ -333,17 +329,12 @@ $lang = array_merge($lang, array( 'TEMPLATE_ERR_CACHE_READ' => 'The cache directory used to store cached versions of template files could not be opened.', 'TEMPLATE_ERR_COPY_LONG' => 'The copyright can be no longer than 60 characters.', 'TEMPLATE_ERR_NAME_CHARS' => 'The template name can only contain alphanumeric characters, -, +, _ and space.', - 'TEMPLATE_ERR_NAME_EXIST' => 'A template set with that name already exists.', 'TEMPLATE_ERR_NAME_LONG' => 'The template name can be no longer than 30 characters.', - 'TEMPLATE_ERR_NOT_TEMPLATE' => 'The archive you specified does not contain a valid template set.', - 'TEMPLATE_ERR_REQUIRED_OR_INCOMPLETE' => 'The new template set requires the template %s to be installed and not inheriting itself.', 'TEMPLATE_ERR_STYLE_NAME' => 'You must supply a name for this template.', - 'TEMPLATE_EXPORT' => 'Export templates', 'TEMPLATE_EXPORT_EXPLAIN' => 'Here you can export a template set in the form of an archive. This archive will contain all the files necessary to install the templates on another board. You may select whether to download the file directly or to place it in your store folder for download later or via FTP.', 'TEMPLATE_EXPORTED' => 'Templates exported successfully and stored in %s.', 'TEMPLATE_FILE' => 'Template file', 'TEMPLATE_FILE_UPDATED' => 'Template file updated successfully.', - 'TEMPLATE_INHERITS' => 'This template sets inherits from %s and thus cannot have a different storage setting than its super template.', 'TEMPLATE_NAME' => 'Template name', 'TEMPLATE_FILE_NOT_WRITABLE'=> 'Unable to write to template file %s. Please check the permissions for the directory and the files.', @@ -371,9 +362,6 @@ $lang = array_merge($lang, array( 'THEME_UPDATED' => 'Theme updated successfully.', 'UNDERLINE' => 'Underline', - 'UNINSTALLED_STYLE' => 'Uninstalled styles', - 'UNINSTALLED_TEMPLATE' => 'Uninstalled templates', - 'UNINSTALLED_THEME' => 'Uninstalled themes', 'UNSET' => 'Undefined', )); From e35a20f957342a320a7c11b0cee1b94025848813 Mon Sep 17 00:00:00 2001 From: Vjacheslav Trushkin Date: Wed, 14 Mar 2012 23:47:57 +0200 Subject: [PATCH 014/114] [feature/merging-style-components] New acp_styles New acp_styles, completely rewritten PHPBB3-10632 --- phpBB/includes/acp/acp_styles.php | 3837 ++++++++---------------- phpBB/includes/acp/info/acp_styles.php | 6 +- 2 files changed, 1273 insertions(+), 2570 deletions(-) diff --git a/phpBB/includes/acp/acp_styles.php b/phpBB/includes/acp/acp_styles.php index 7b449d3b35..acd010b77e 100644 --- a/phpBB/includes/acp/acp_styles.php +++ b/phpBB/includes/acp/acp_styles.php @@ -21,16 +21,1278 @@ if (!defined('IN_PHPBB')) class acp_styles { var $u_action; - - var $style_cfg; - var $template_cfg; - var $theme_cfg; + var $u_base_action; + var $s_hidden_fields; + var $mode; + var $styles_path; + var $styles_path_absolute = 'styles'; function main($id, $mode) { - global $db, $user, $auth, $template, $cache; - global $config, $phpbb_root_path, $phpbb_admin_path, $phpEx; + global $user, $phpbb_admin_path, $phpbb_root_path, $phpEx, $template, $request; + $this->styles_path = $phpbb_root_path . $this->styles_path_absolute . '/'; + + $this->u_base_action = append_sid("{$phpbb_admin_path}index.$phpEx", "i={$id}"); + $this->s_hidden_fields = array( + 'mode' => $mode, + ); + + $user->add_lang('acp/styles'); + + $this->tpl_name = 'acp_styles'; + $this->page_title = 'ACP_CAT_STYLES'; + $this->mode = $mode; + + $action = $request->variable('action', ''); + $post_actions = array('install', 'activate', 'deactivate', 'delete'); + foreach ($post_actions as $key) + { + if (isset($_POST[$key])) + { + $action = $key; + } + } + if ($action != '') + { + $this->s_hidden_fields['action'] = $action; + } + + $template->assign_vars(array( + 'U_ACTION' => $this->u_base_action, + 'S_HIDDEN_FIELDS' => build_hidden_fields($this->s_hidden_fields) + ) + ); + + // Execute actions + switch ($action) + { + case 'install': + $this->action_install(); + return; + case 'delete': + $this->action_delete(); + return; + case 'activate': + $this->action_activate(); + return; + case 'deactivate': + $this->action_deactivate(); + return; + case 'details': + $this->action_details(); + return; + default: + $this->frontend(); + } + } + + /** + * Main page + */ + function frontend() + { + // Check mode + switch ($this->mode) + { + case 'style': + $this->welcome_message('ACP_STYLES', 'ACP_STYLES_EXPLAIN'); + $this->show_installed(); + return; + case 'install': + $this->welcome_message('INSTALL_STYLES', 'INSTALL_STYLES_EXPLAIN'); + $this->show_available(); + return; + case 'cache': + $this->action_cache(); + return; + } + global $user; + trigger_error($user->lang['NO_MODE'] . adm_back_link($this->u_action), E_USER_WARNING); + } + + /** + * Purge cache + */ + function action_cache() + { + global $cache, $auth, $user; + + $cache->purge(); + + // Clear permissions + $auth->acl_clear_prefetch(); + cache_moderators(); + + add_log('admin', 'LOG_PURGE_CACHE'); + + trigger_error($user->lang['PURGED_CACHE'] . adm_back_link($this->u_base_action), E_USER_NOTICE); + } + + /** + * Install style(s) + */ + function action_install() + { + global $user; + + // Get list of styles to install + $dirs = $this->request_vars('dir', '', true); + + // Get list of styles that can be installed + $styles = $this->find_available(false); + + // Install each style + $messages = array(); + $installed_names = array(); + $installed_dirs = array(); + $last_installed = false; + foreach ($dirs as $dir) + { + $found = false; + foreach ($styles as &$style) + { + // Check if: + // 1. Directory matches directory we are looking for + // 2. Style is not installed yet + // 3. Style with same name or directory hasn't been installed already within this function + if ($style['style_path'] == $dir && empty($style['_installed']) && !in_array($style['style_path'], $installed_dirs) && !in_array($style['style_name'], $installed_names)) + { + // Install style + $style['style_active'] = 1; + $style['style_id'] = $this->install_style($style); + $style['_installed'] = true; + $found = true; + $last_installed = $style['style_id']; + $installed_names[] = $style['style_name']; + $installed_dirs[] = $style['style_path']; + $messages[] = sprintf($user->lang['STYLE_INSTALLED'], htmlspecialchars($style['style_name'])); + } + } + if (!$found) + { + $messages[] = sprintf($user->lang['STYLE_NOT_INSTALLED'], htmlspecialchars($dir)); + } + } + + // Show message + if (!count($messages)) + { + trigger_error($user->lang['NO_MATCHING_STYLES_FOUND'] . adm_back_link($this->u_action), E_USER_WARNING); + } + $message = implode('
    ', $messages); + if (count($messages) == 1 && $last_installed !== false) + { + $message .= '

    ' . sprintf($user->lang['STYLE_INSTALLED_EDIT_DETAILS'], $this->u_base_action . '&mode=style&action=details&id=' . $last_installed); + } + $message .= '

    ' . sprintf($user->lang['STYLE_INSTALLED_RETURN_STYLES'], $this->u_base_action . '&mode=style'); + $message .= '

    ' . sprintf($user->lang['STYLE_INSTALLED_RETURN_UNINSTALLED'], $this->u_base_action . '&mode=install'); + trigger_error($message, E_USER_NOTICE); + } + + /** + * Confirm styles deletion + */ + function action_delete() + { + global $user, $config, $template, $request; + + // Get list of styles to delete + $ids = $this->request_vars('id', 0, true); + + // Check if confirmation box was submitted + if (confirm_box(true)) + { + // Delete + $this->action_delete_confirmed($ids, $request->variable('confirm_delete_files', false)); + return; + } + + // Confirm box + $s_hidden = build_hidden_fields(array( + 'action' => 'delete', + 'ids' => $ids + )); + $template->assign_var('S_CONFIRM_DELETE', true); + confirm_box(false, $user->lang['CONFIRM_DELETE_STYLES'], $s_hidden, 'acp_styles.html'); + + // Canceled - show styles list + $this->frontend(); + } + + /** + * Delete styles(s) + * + * @param array $ids List of style IDs + * @param bool $delete_files If true, script will attempt to remove files for selected styles + */ + function action_delete_confirmed($ids, $delete_files) + { + global $db, $user, $cache; + + $default = $config['default_style']; + $deleted = array(); + $messages = array(); + + // Check styles list + foreach ($ids as $id) + { + if (!$id) + { + trigger_error($user->lang['INVALID_STYLE_ID'] . adm_back_link($this->u_action), E_USER_WARNING); + } + if ($id == $default) + { + trigger_error($user->lang['DELETE_DEFAULT'] . adm_back_link($this->u_action), E_USER_WARNING); + } + $deleted[$id] = false; + } + + // Order by reversed style_id, so parent styles would be removed after child styles + // This way parent and child styles can be removed in same function call + $sql = 'SELECT * + FROM ' . STYLES_TABLE . ' + WHERE style_id IN (' . implode(', ', $ids) . ') + ORDER BY style_id DESC'; + $result = $db->sql_query($sql); + + $rows = $db->sql_fetchrowset($result); + $db->sql_freeresult($result); + + // Delete each style + $deleted = array(); + foreach ($rows as $style) + { + $result = $this->delete_style($style, $delete_files); + + if (is_string($result)) + { + $messages[] = $result; + continue; + } + $messages[] = sprintf($user->lang['STYLE_DELETED'], $style['style_name']); + $deleted[] = $style['style_name']; + + // Attempt to delete files + if ($delete_files) + { + $messages[] = sprintf($user->lang[$this->delete_style_files($style['style_path']) ? 'DELETE_STYLE_FILES_SUCCESS' : 'DELETE_STYLE_FILES_FAILED'], $style['style_name']); + } + } + + if (empty($messages)) + { + // Nothing to delete? + trigger_error($user->lang['NO_MATCHING_STYLES_FOUND'] . adm_back_link($this->u_action), E_USER_WARNING); + } + + // Log action + if (count($deleted)) + { + add_log('admin', 'LOG_STYLE_DELETE', implode(', ', $deleted)); + } + + // Clear cache + $cache->purge(); + + // Show message + trigger_error(implode('
    ', $messages) . adm_back_link($this->u_action), E_USER_NOTICE); + } + + /** + * Activate styles + */ + function action_activate() + { + global $user, $config, $cache, $db; + + // Get list of styles to activate + $ids = $this->request_vars('id', 0, true); + + // Activate styles + $sql = 'UPDATE ' . STYLES_TABLE . ' + SET style_active = 1 + WHERE style_id IN (' . implode(', ', $ids) . ')'; + $db->sql_query($sql); + + // Purge cache + $cache->destroy('sql', STYLES_TABLE); + + // Show styles list + $this->frontend(); + } + + /** + * Deactivate styles + */ + function action_deactivate() + { + global $user, $config, $cache, $db; + + // Get list of styles to deactivate + $ids = $this->request_vars('id', 0, true); + + // Check for default style + foreach ($ids as $id) + { + if ($id == $config['default_style']) + { + trigger_error($user->lang['DEACTIVATE_DEFAULT'] . adm_back_link($this->u_action), E_USER_WARNING); + } + } + + // Reset default style for users who use selected styles + $sql = 'UPDATE ' . USERS_TABLE . ' + SET user_style = 0 + WHERE user_style IN (' . implode(', ', $ids) . ')'; + $db->sql_query($sql); + + // Deactivate styles + $sql = 'UPDATE ' . STYLES_TABLE . ' + SET style_active = 0 + WHERE style_id IN (' . implode(', ', $ids) . ')'; + $db->sql_query($sql); + + // Purge cache + $cache->destroy('sql', STYLES_TABLE); + + // Show styles list + $this->frontend(); + } + + /** + * Show style details + */ + function action_details() + { + global $user, $config, $db, $request, $template, $cache; + + $id = $request->variable('id', 0); + if (!$id) + { + trigger_error($user->lang['NO_MATCHING_STYLES_FOUND'] . adm_back_link($this->u_action), E_USER_WARNING); + } + + // Get all styles + $styles = $this->get_styles(); + usort($styles, 'acp_styles::sort_styles'); + + // Find current style + $style = false; + foreach ($styles as $row) + { + if ($row['style_id'] == $id) + { + $style = $row; + break; + } + } + + if ($style === false) + { + trigger_error($user->lang['NO_MATCHING_STYLES_FOUND'] . adm_back_link($this->u_action), E_USER_WARNING); + } + + // Find all available parent styles + $list = $this->find_possible_parents($styles, $id); + + // Change data + if ($request->variable('update', false)) + { + $update = array( + 'style_name' => trim($request->variable('style_name', $style['style_name'])), + 'style_parent_id' => $request->variable('style_parent', (int) $style['style_parent_id']), + 'style_active' => $request->variable('style_active', (int) $style['style_active']), + ); + $update_action = $this->u_action . '&action=details&id=' . $id; + + // Check style name + if ($update['style_name'] != $style['style_name']) + { + if (!strlen($update['style_name'])) + { + trigger_error($user->lang['STYLE_ERR_STYLE_NAME'] . adm_back_link($update_action), E_USER_WARNING); + } + foreach ($styles as $row) + { + if ($row['style_name'] == $update['style_name']) + { + trigger_error($user->lang['STYLE_ERR_NAME_EXIST'] . adm_back_link($update_action), E_USER_WARNING); + } + } + } + else + { + unset($update['style_name']); + } + + // Check parent style id + if ($update['style_parent_id'] != $style['style_parent_id']) + { + if ($update['style_parent_id'] != 0) + { + $found = false; + foreach ($list as $row) + { + if ($row['style_id'] == $update['style_parent_id']) + { + $found = true; + $update['style_parent_tree'] = ($row['style_parent_tree'] != '' ? $row['style_parent_tree'] . '/' : '') . $row['style_path']; + break; + } + } + if (!$found) + { + trigger_error($user->lang['STYLE_ERR_INVALID_PARENT'] . adm_back_link($update_action), E_USER_WARNING); + } + } + else + { + $update['style_parent_tree'] = ''; + } + } + else + { + unset($update['style_parent_id']); + } + + // Check style_active + if ($update['style_active'] != $style['style_active']) + { + if (!$update['style_active'] && $config['default_style'] == $style['style_id']) + { + trigger_error($user->lang['DEACTIVATE_DEFAULT'] . adm_back_link($update_action), E_USER_WARNING); + } + } + else + { + unset($update['style_active']); + } + + // Update data + if (count($update)) + { + $sql = 'UPDATE ' . STYLES_TABLE . ' + SET ' . $db->sql_build_array('UPDATE', $update) . " + WHERE style_id = $id"; + $db->sql_query($sql); + + $style = array_merge($style, $update); + + if (isset($update['style_parent_id'])) + { + // Update styles tree + $styles = $this->get_styles(); + if ($this->update_styles_tree(&$styles, $style)) + { + // Something was changed in styles tree, purge all cache + $cache->purge(); + } + } + add_log('admin', 'LOG_STYLE_EDIT_DETAILS', $style['style_name']); + } + + // Update default style + $default = $request->variable('style_default', 0); + if ($default) + { + if (!$style['style_active']) + { + trigger_error($user->lang['STYLE_DEFAULT_CHANGE_INACTIVE'] . adm_back_link($update_action), E_USER_WARNING); + } + set_config('default_style', $id); + $cache->purge(); + } + + // Show styles list + $this->frontend(); + return; + } + + // Show parent styles + foreach ($list as $row) + { + $template->assign_block_vars('parent_styles', array( + 'STYLE_ID' => $row['style_id'], + 'STYLE_NAME' => htmlspecialchars($row['style_name']), + 'LEVEL' => $row['level'], + 'SPACER' => str_repeat('  ', $row['level']), + ) + ); + } + + // Show style details + $template->assign_vars(array( + 'S_STYLE_DETAILS' => true, + 'STYLE_ID' => $style['style_id'], + 'STYLE_NAME' => htmlspecialchars($style['style_name']), + 'STYLE_PATH' => htmlspecialchars($style['style_path']), + 'STYLE_COPYRIGHT' => strip_tags($style['style_copyright']), + 'STYLE_PARENT' => $style['style_parent_id'], + 'S_STYLE_ACTIVE' => $style['style_active'], + 'S_STYLE_DEFAULT' => ($style['style_id'] == $config['default_style']) + ) + ); + } + + /** + * List installed styles + */ + function show_installed() + { + global $user, $template; + + // Get all installed styles + $styles = $this->get_styles(); + + if (!count($styles)) + { + trigger_error($user->lang['NO_MATCHING_STYLES_FOUND'] . adm_back_link($this->u_action), E_USER_WARNING); + } + + usort($styles, 'acp_styles::sort_styles'); + + // Get users + $users = $this->get_users(); + + // Add users counter to rows + foreach ($styles as &$style) + { + $style['_users'] = isset($users[$style['style_id']]) ? $users[$style['style_id']] : 0; + } + + // Set up styles list variables + // Addons should increase this number and update template variable + $this->styles_list_cols = 4; + $template->assign_var('STYLES_LIST_COLS', $this->styles_list_cols); + + // Show styles list + $this->show_styles_list(&$styles, 0, 0); + + // Show styles with invalid inherits_id + foreach ($styles as $style) + { + if (empty($style['_shown'])) + { + $style['_note'] = sprintf($user->lang['REQUIRES_STYLE'], htmlspecialchars($style['style_parent_tree'])); + $this->list_style($style, 0); + } + } + + // Add buttons + $template->assign_block_vars('extra_actions', array( + 'ACTION_NAME' => 'activate', + 'L_ACTION' => $user->lang['STYLE_ACTIVATE'], + ) + ); + + $template->assign_block_vars('extra_actions', array( + 'ACTION_NAME' => 'deactivate', + 'L_ACTION' => $user->lang['STYLE_DEACTIVATE'], + ) + ); + + if (isset($this->style_counters) && $this->style_counters['total'] > 1) + { + $template->assign_block_vars('extra_actions', array( + 'ACTION_NAME' => 'delete', + 'L_ACTION' => $user->lang['DELETE'], + ) + ); + } + } + + /** + * Show list of styles that can be installed + */ + function show_available() + { + global $user, $template; + + // Get list of styles + $styles = $this->find_available(true); + + // Show styles + if (empty($styles)) + { + trigger_error($user->lang['NO_UNINSTALLED_STYLE'] . adm_back_link($this->u_action), E_USER_NOTICE); + } + + usort($styles, 'acp_styles::sort_styles'); + + $this->styles_list_cols = 3; + $template->assign_vars(array( + 'STYLES_LIST_COLS' => $this->styles_list_cols, + 'STYLES_LIST_HIDE_COUNT' => true + ) + ); + + // Show styles + foreach ($styles as &$style) + { + // Check if style has a parent style in styles list + $has_parent = false; + if ($style['_inherit_name'] != '') + { + foreach ($styles as $parent_style) + { + if ($parent_style['style_name'] == $style['_inherit_name'] && empty($parent_style['_shown'])) + { + // Show parent style first + $has_parent = true; + } + } + } + if (!$has_parent) + { + $this->list_style(&$style, 0); + $this->show_available_child_styles(&$styles, $style['style_name'], 1); + } + } + + // Show styles that do not have parent style in styles list + foreach ($styles as $style) + { + if (empty($style['_shown'])) + { + $this->list_style(&$style, 0); + } + } + + // Add button + if (isset($this->style_counters) && $this->style_counters['caninstall'] > 0) + { + $template->assign_block_vars('extra_actions', array( + 'ACTION_NAME' => 'install', + 'L_ACTION' => $user->lang['INSTALL_STYLES'], + ) + ); + } + } + + /** + * Find styles available for installation + * + * @param bool $all if true, function will return all installable styles. if false, function will return only styles that can be installed + * @returns array list of styles + */ + function find_available($all) + { + global $user; + + // Get list of installed styles + $installed = $this->get_styles(); + + $installed_dirs = array(); + $installed_names = array(); + foreach ($installed as $style) + { + $installed_dirs[] = $style['style_path']; + $installed_names[$style['style_name']] = array( + 'path' => $style['style_path'], + 'id' => $style['style_id'], + 'parent' => $style['style_parent_id'], + 'tree' => (strlen($style['style_parent_tree']) ? $style['style_parent_tree'] . '/' : '') . $style['style_path'], + ); + } + + // Get list of directories + $dirs = $this->find_style_dirs(); + + // Find styles that can be installed + $styles = array(); + foreach ($dirs as $dir) + { + if (in_array($dir, $installed_dirs)) + { + // Style is already installed + continue; + } + $cfg = $this->read_style_cfg($dir); + if ($cfg === false) + { + // Invalid style.cfg + continue; + } + + // Style should be available for installation + $parent = $cfg['parent']; + $style = array( + 'style_id' => 0, + 'style_name' => $cfg['name'], + 'style_copyright' => $cfg['copyright'], + 'style_active' => 0, + 'style_path' => $dir, + 'bbcode_bitfield' => $cfg['template_bitfield'], + 'style_parent_id' => 0, + 'style_parent_tree' => '', + // Extra values for styles list + // All extra variable start with _ so they won't be confused with data that can be added to styles table + '_inherit_name' => $parent, + '_available' => true, + '_note' => '', + ); + + // Check style inheritance + if ($parent != '') + { + if (isset($installed_names[$parent])) + { + // Parent style is installed + $row = $installed_names[$parent]; + $style['style_parent_id'] = $row['id']; + $style['style_parent_tree'] = $row['tree']; + } + else + { + // Parent style is not installed yet + $style['_available'] = false; + $style['_note'] = sprintf($user->lang['REQUIRES_STYLE'], htmlspecialchars($parent)); + } + } + + if ($all || $style['_available']) + { + $styles[] = $style; + } + } + + return $styles; + } + + /** + * Show styles list + * + * @param array $styles styles list + * @param int $parent parent style id + * @param int $level style inheritance level + */ + function show_styles_list($styles, $parent, $level) + { + foreach ($styles as &$style) + { + if (empty($style['_shown']) && $style['style_parent_id'] == $parent) + { + $this->list_style(&$style, $level); + $this->show_styles_list(&$styles, $style['style_id'], $level + 1); + } + } + } + + /** + * Show available styles tree + * + * @param array $styles Styles list, passed as reference + * @param string $name Name of parent style + * @param string $level Styles tree level + */ + function show_available_child_styles($styles, $name, $level) + { + foreach ($styles as &$style) + { + if (empty($style['_shown']) && $style['_inherit_name'] == $name) + { + $this->list_style(&$style, $level); + $this->show_available_child_styles(&$styles, $style['style_name'], $level + 1); + } + } + } + + /** + * Update styles tree + * + * @param array $styles Styles list, passed as reference + * @param array $style Current style, false if root + * @returns true if something was updated, false if not + */ + function update_styles_tree($styles, $style = false) + { + $parent_id = ($style === false) ? 0 : $style['style_id']; + $parent_tree = ($style === false) ? '' : ($style['style_parent_tree'] == '' ? '' : $style['style_parent_tree']) . $style['style_path']; + $update = false; + $updated = false; + foreach ($styles as &$row) + { + if ($row['style_parent_id'] == $parent_id) + { + if ($row['style_parent_tree'] != $parent_tree) + { + $row['style_parent_tree'] = $parent_tree; + $update = true; + } + $updated |= $this->update_styles_tree(&$styles, $row); + } + } + if ($update) + { + global $db; + $sql = 'UPDATE ' . STYLES_TABLE . " + SET style_parent_tree = '" . $db->sql_escape($parent_tree) . "' + WHERE style_parent_id = {$parent_id}"; + $db->sql_query($sql); + $updated = true; + } + return $updated; + } + + /** + * Find all possible parent styles for style + * + * @param array $styles list of styles + * @param int $id id of style + * @param int $parent current parent style id + * @param int $level current tree level + * @returns array of style ids, names and levels + */ + function find_possible_parents($styles, $id = -1, $parent = 0, $level = 0) + { + $results = array(); + foreach ($styles as $style) + { + if ($style['style_id'] != $id && $style['style_parent_id'] == $parent) + { + $results[] = array( + 'style_id' => $style['style_id'], + 'style_name' => $style['style_name'], + 'style_path' => $style['style_path'], + 'style_parent_id' => $style['style_parent_id'], + 'style_parent_tree' => $style['style_parent_tree'], + 'level' => $level + ); + $results = array_merge($results, $this->find_possible_parents($styles, $id, $style['style_id'], $level + 1)); + } + } + return $results; + } + + /** + * Show item in styles list + * + * @param array $style style row + * @param array $level style inheritance level + */ + function list_style($style, $level) + { + global $template, $config, $db, $user, $phpbb_root_path, $phpEx; + + // Mark row as shown + if (!empty($style['_shown'])) return; + $style['_shown'] = true; + + // Generate template variables + $actions = array(); + $row = array( + // Style data + 'STYLE_ID' => $style['style_id'], + 'STYLE_NAME' => htmlspecialchars($style['style_name']), + 'STYLE_PATH' => htmlspecialchars($style['style_path']), + 'STYLE_COPYRIGHT' => strip_tags($style['style_copyright']), + 'STYLE_ACTIVE' => $style['style_active'], + + // Additional data + 'DEFAULT' => ($style['style_id'] && $style['style_id'] == $config['default_style']), + 'USERS' => $style['_users'], + 'LEVEL' => $level, + 'PADDING' => (4 + 16 * $level), + 'SHOW_COPYRIGHT' => ($style['style_id']) ? false : true, + 'STYLE_PATH_FULL' => htmlspecialchars($this->styles_path_absolute . '/' . $style['style_path']) . '/', + + // Comment to show below style + 'COMMENT' => (isset($style['_note'])) ? $style['_note'] : '', + + // The following variables should be used by hooks to add custom HTML code + 'EXTRA' => '', + 'EXTRA_OPTIONS' => '' + ); + + // Status specific data + if ($style['style_id']) + { + // Style is installed + + // Details + $actions[] = array( + 'U_ACTION' => $this->u_action . '&action=details&id=' . $style['style_id'], + 'L_ACTION' => $user->lang['DETAILS'] + ); + + // Activate + $actions[] = array( + 'U_ACTION' => $this->u_action . '&action=' . ($style['style_active'] ? 'de' : '') . 'activate&id=' . $style['style_id'], + 'L_ACTION' => $user->lang['STYLE_' . ($style['style_active'] ? 'DE' : '') . 'ACTIVATE'] + ); + +/* // Export + $actions[] = array( + 'U_ACTION' => $this->u_action . '&action=export&id=' . $style['style_id'], + 'L_ACTION' => $user->lang['EXPORT'] + ); */ + + // Delete + $actions[] = array( + 'U_ACTION' => $this->u_action . '&action=delete&id=' . $style['style_id'], + 'L_ACTION' => $user->lang['DELETE'] + ); + + // Preview + $actions[] = array( + 'U_ACTION' => append_sid("{$phpbb_root_path}index.$phpEx", 'style=' . $style['style_id']), + 'L_ACTION' => $user->lang['PREVIEW'] + ); + } + else + { + // Style is not installed + if (empty($style['_available'])) + { + $actions[] = array( + 'HTML' => $user->lang['CANNOT_BE_INSTALLED'] + ); + } + else + { + $actions[] = array( + 'U_ACTION' => $this->u_action . '&action=install&dir=' . urlencode($style['style_path']), + 'L_ACTION' => $user->lang['INSTALL_STYLE'] + ); + } + } + + // todo: add hook + + // Assign template variables + $template->assign_block_vars('styles_list', $row); + foreach($actions as $action) + { + $template->assign_block_vars('styles_list.actions', $action); + } + + // Increase counters + $counter = ($style['style_id']) ? ($style['style_active'] ? 'active' : 'inactive') : (empty($style['_available']) ? 'cannotinstall' : 'caninstall'); + if (!isset($this->style_counters)) + { + $this->style_counters = array( + 'total' => 0, + 'active' => 0, + 'inactive' => 0, + 'caninstall' => 0, + 'cannotinstall' => 0 + ); + } + $this->style_counters[$counter] ++; + $this->style_counters['total'] ++; + } + + /** + * Show welcome message + * + * @param string $title main title + * @param string $description page description + */ + function welcome_message($title, $description) + { + global $user, $template; + $template->assign_vars(array( + 'L_TITLE' => (isset($user->lang[$title])) ? $user->lang[$title] : $title, + 'L_EXPLAIN' => (isset($user->lang[$description])) ? $user->lang[$description] : $description + ) + ); + } + + /** + * Find all directories that have styles + * + * @returns array of directory names + */ + function find_style_dirs() + { + $styles = array(); + + $dp = @opendir($this->styles_path); + if ($dp) + { + while (($file = readdir($dp)) !== false) + { + $dir = $this->styles_path . $file; + if ($file[0] == '.' || !is_dir($dir)) + { + continue; + } + + if (file_exists("{$dir}/style.cfg")) + { + $styles[] = $file; + } + } + closedir($dp); + } + + return $styles; + } + + /** + * Sort styles + */ + function sort_styles($style1, $style2) + { + if ($style1['style_active'] != $style2['style_active']) + { + return ($style1['style_active']) ? -1 : 1; + } + if (isset($style1['_available']) && $style1['_available'] != $style2['_available']) + { + return ($style1['_available']) ? -1 : 1; + } + return strcasecmp(isset($style1['style_name']) ? $style1['style_name'] : $style1['name'], isset($style2['style_name']) ? $style2['style_name'] : $style2['name']); + } + + /** + * Read style configuration file + * + * @param string $dir style directory + * @returns array of style data + * @returns false on error + */ + function read_style_cfg($dir) + { + static $required = array('name', 'version', 'copyright'); + $cfg = parse_cfg_file($this->styles_path . $dir . '/style.cfg'); + + // Check if it is a valid file + foreach ($required as $key) + { + if (!isset($cfg[$key])) + { + return false; + } + } + + // Check data + if (!isset($cfg['parent']) || !is_string($cfg['parent']) || $cfg['parent'] == $cfg['name']) + { + $cfg['parent'] = ''; + } + if (!isset($cfg['template_bitfield'])) + { + $cfg['template_bitfield'] = $this->default_bitfield(); + } + + return $cfg; + } + + /** + * Install style + * + * @param $style style data + * @returns int style id + */ + function install_style($style) + { + global $db; + + // Generate row + $sql_ary = array(); + foreach ($style as $key => $value) + { + if ($key != 'style_id' && substr($key, 0, 1) != '_') + { + $sql_ary[$key] = $value; + } + } + + // Add to database + $db->sql_transaction('begin'); + + $sql = 'INSERT INTO ' . STYLES_TABLE . ' + ' . $db->sql_build_array('INSERT', $sql_ary); + $db->sql_query($sql); + + $id = $db->sql_nextid(); + + $db->sql_transaction('commit'); + + add_log('admin', 'LOG_STYLE_ADD', $sql_ary['style_name']); + + return $id; + } + + /** + * Lists all styles + * + * @returns array of rows with styles data + */ + function get_styles() + { + global $db; + + $sql = 'SELECT * + FROM ' . STYLES_TABLE; + $result = $db->sql_query($sql); + + $rows = $db->sql_fetchrowset($result); + $db->sql_freeresult($result); + + return $rows; + } + + /** + * Count users for each style + * + * @returns array of styles in following format: [style_id] = number of users + */ + function get_users() + { + global $db; + + $sql = 'SELECT user_style, COUNT(user_style) AS style_count + FROM ' . USERS_TABLE . ' + GROUP BY user_style'; + $result = $db->sql_query($sql); + + $style_count = array(); + while ($row = $db->sql_fetchrow($result)) + { + $style_count[$row['user_style']] = $row['style_count']; + } + $db->sql_freeresult($result); + + return $style_count; + } + + /** + * Delete style + * + * @param array $style Style data + * @returns true on success, error message on error + */ + function delete_style($style) + { + global $db, $user; + + $id = $style['style_id']; + $path = $style['style_path']; + + // Check if style has child styles + $sql = 'SELECT style_id + FROM ' . STYLES_TABLE . ' + WHERE style_parent_id = ' . $id . " OR style_parent_tree = '" . $db->sql_escape($path) . "'"; + $result = $db->sql_query($sql); + + $conflict = $db->sql_fetchrow($result); + $db->sql_freeresult($result); + + if ($conflict !== false) + { + return sprintf($user->lang['STYLE_DELETE_DEPENDENT'], $style['style_name']); + } + + // Change default style for users + $sql = 'UPDATE ' . USERS_TABLE . ' + SET user_style = 0 + WHERE user_style = ' . $id; + $db->sql_query($sql); + + // Delete style + $sql = 'DELETE FROM ' . STYLES_TABLE . ' + WHERE style_id = ' . $id; + $db->sql_query($sql); + return true; + } + + /** + * Delete all files in style directory + * + * @param string $path Style directory + * @param string $dir Directory to remove inside style's directory + * @returns true on success, false on error + */ + function delete_style_files($path, $dir = '') + { + $dirname = $this->styles_path . $path . $dir; + $result = true; + + $dp = @opendir($dirname); + + if ($dp) + { + while (($file = readdir($dp)) !== false) + { + if ($file == '.' || $file == '..') + { + continue; + } + $filename = $dirname . '/' . $file; + if (is_dir($filename)) + { + if (!$this->delete_style_files($path, $dir . '/' . $file)) + { + $result = false; + } + } + else + { + if (!@unlink($filename)) + { + $result = false; + } + } + } + closedir($dp); + } + if (!@rmdir($dirname)) + { + return false; + } + + return $result; + } + + /** + * Get list of items from posted data + * + * @param string $name Variable name + * @param $default Default value for array: string or number + * @param bool $error If true, error will be triggered if list is empty + * @returns array of items + */ + function request_vars($name, $default, $error = false) + { + global $request, $user; + + $item = $request->variable($name, $default); + $items = $request->variable($name . 's', array($default)); + + if (count($items) == 1 && $items[0] == $default) + { + $items = array(); + } + + if ($item != $default && !count($items)) + { + $items[] = $item; + } + + if ($error && !count($items)) + { + trigger_error($user->lang['NO_MATCHING_STYLES_FOUND'] . adm_back_link($this->u_action), E_USER_WARNING); + } + + return $items; + } + + /** + * Generates hardcoded bitfield + * + * @returns bitfield string + */ + function default_bitfield() + { + static $value; + if(isset($value)) + { + return $value; + } + // Hardcoded template bitfield to add for new templates $bitfield = new bitfield(); $bitfield->set(0); @@ -42,2567 +1304,8 @@ class acp_styles $bitfield->set(9); $bitfield->set(11); $bitfield->set(12); - $this->template_bitfield = $bitfield->get_base64(); - unset($bitfield); - - $user->add_lang('acp/styles'); - - $this->tpl_name = 'acp_styles'; - $this->page_title = 'ACP_CAT_STYLES'; - - $action = request_var('action', ''); - $action = (isset($_POST['add'])) ? 'add' : $action; - $style_id = request_var('id', 0); - - // Fill the configuration variables - $this->style_cfg = $this->template_cfg = $this->theme_cfg = ' -# -# phpBB {MODE} configuration file -# -# @package phpBB3 -# @copyright (c) 2005 phpBB Group -# @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 -# -# -# At the left is the name, please do not change this -# At the right the value is entered -# For on/off options the valid values are on, off, 1, 0, true and false -# -# Values get trimmed, if you want to add a space in front or at the end of -# the value, then enclose the value with single or double quotes. -# Single and double quotes do not need to be escaped. -# -# - -# General Information about this {MODE} -name = {NAME} -copyright = {COPYRIGHT} -version = {VERSION} -'; - - $this->template_cfg .= ' -# Some configuration options - -# Template inheritance -# See http://blog.phpbb.com/2008/07/31/templating-just-got-easier/ -# Set value to empty or this template name to ignore template inheritance. -inherit_from = {INHERIT_FROM} -'; - - // Execute overall actions - switch ($action) - { - case 'delete': - if ($style_id) - { - $this->remove($mode, $style_id); - return; - } - break; - - case 'export': - if ($style_id) - { - $this->export($mode, $style_id); - return; - } - break; - - case 'install': - $this->install($mode); - return; - break; - - case 'add': - $this->add($mode); - return; - break; - - case 'details': - if ($style_id) - { - $this->details($mode, $style_id); - return; - } - break; - - case 'edit': - if ($style_id) - { - switch ($mode) - { - case 'template': - return $this->edit_template($style_id); - case 'theme': - return $this->edit_theme($style_id); - } - } - break; - - case 'cache': - if ($style_id) - { - switch ($mode) - { - case 'template': - return $this->template_cache($style_id); - } - } - break; - } - - switch ($mode) - { - case 'style': - - switch ($action) - { - case 'activate': - case 'deactivate': - - if ($style_id == $config['default_style']) - { - trigger_error($user->lang['DEACTIVATE_DEFAULT'] . adm_back_link($this->u_action), E_USER_WARNING); - } - - if (($action == 'deactivate' && confirm_box(true)) || $action == 'activate') - { - $sql = 'UPDATE ' . STYLES_TABLE . ' - SET style_active = ' . (($action == 'activate') ? 1 : 0) . ' - WHERE style_id = ' . $style_id; - $db->sql_query($sql); - - // Set style to default for any member using deactivated style - if ($action == 'deactivate') - { - $sql = 'UPDATE ' . USERS_TABLE . ' - SET user_style = ' . $config['default_style'] . " - WHERE user_style = $style_id"; - $db->sql_query($sql); - - $sql = 'UPDATE ' . FORUMS_TABLE . ' - SET forum_style = 0 - WHERE forum_style = ' . $style_id; - $db->sql_query($sql); - } - } - else if ($action == 'deactivate') - { - $s_hidden_fields = array( - 'i' => $id, - 'mode' => $mode, - 'action' => $action, - 'style_id' => $style_id, - ); - confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields($s_hidden_fields)); - } - break; - } - - $this->frontend('style', array('details'), array('export', 'delete')); - break; - - case 'template': - - switch ($action) - { - // Clear cache - case 'refresh': - - $sql = 'SELECT * - FROM ' . STYLES_TEMPLATE_TABLE . " - WHERE template_id = $style_id"; - $result = $db->sql_query($sql); - $template_row = $db->sql_fetchrow($result); - $db->sql_freeresult($result); - - if (!$template_row) - { - trigger_error($user->lang['NO_TEMPLATE'] . adm_back_link($this->u_action), E_USER_WARNING); - } - - if (confirm_box(true)) - { - $this->clear_template_cache($template_row); - - trigger_error($user->lang['TEMPLATE_CACHE_CLEARED'] . adm_back_link($this->u_action)); - } - else - { - confirm_box(false, $user->lang['CONFIRM_TEMPLATE_CLEAR_CACHE'], build_hidden_fields(array( - 'i' => $id, - 'mode' => $mode, - 'action' => $action, - 'id' => $style_id - ))); - } - - break; - } - - $this->frontend('template', array('edit', 'cache', 'details'), array('refresh', 'export', 'delete')); - break; - - case 'theme': - $this->frontend('theme', array('edit', 'details'), array('export', 'delete')); - break; - } + $value = $bitfield->get_base64(); + return $value; } - /** - * Build Frontend with supplied options - */ - function frontend($mode, $options, $actions) - { - global $user, $template, $db, $config, $phpbb_root_path, $phpEx; - - $sql_from = ''; - $sql_sort = 'LOWER(' . $mode . '_name)'; - $style_count = array(); - - switch ($mode) - { - case 'style': - $sql_from = STYLES_TABLE; - $sql_sort = 'style_active DESC, ' . $sql_sort; - - $sql = 'SELECT user_style, COUNT(user_style) AS style_count - FROM ' . USERS_TABLE . ' - GROUP BY user_style'; - $result = $db->sql_query($sql); - - while ($row = $db->sql_fetchrow($result)) - { - $style_count[$row['user_style']] = $row['style_count']; - } - $db->sql_freeresult($result); - - break; - - case 'template': - $sql_from = STYLES_TEMPLATE_TABLE; - break; - - case 'theme': - $sql_from = STYLES_THEME_TABLE; - break; - - default: - trigger_error($user->lang['NO_MODE'] . adm_back_link($this->u_action), E_USER_WARNING); - } - - $l_prefix = strtoupper($mode); - - $this->page_title = 'ACP_' . $l_prefix . 'S'; - - $template->assign_vars(array( - 'S_FRONTEND' => true, - 'S_STYLE' => ($mode == 'style') ? true : false, - - 'L_TITLE' => $user->lang[$this->page_title], - 'L_EXPLAIN' => $user->lang[$this->page_title . '_EXPLAIN'], - 'L_NAME' => $user->lang[$l_prefix . '_NAME'], - 'L_INSTALLED' => $user->lang['INSTALLED_' . $l_prefix], - 'L_UNINSTALLED' => $user->lang['UNINSTALLED_' . $l_prefix], - 'L_NO_UNINSTALLED' => $user->lang['NO_UNINSTALLED_' . $l_prefix], - 'L_CREATE' => $user->lang['CREATE_' . $l_prefix], - - 'U_ACTION' => $this->u_action, - ) - ); - - $sql = "SELECT * - FROM $sql_from - ORDER BY $sql_sort ASC"; - $result = $db->sql_query($sql); - - $installed = array(); - - $basis_options = ''; - while ($row = $db->sql_fetchrow($result)) - { - $installed[] = $row[$mode . '_name']; - $basis_options .= ''; - - $stylevis = ($mode == 'style' && !$row['style_active']) ? 'activate' : 'deactivate'; - - $s_options = array(); - foreach ($options as $option) - { - $s_options[] = '' . $user->lang[strtoupper($option)] . ''; - } - - $s_actions = array(); - foreach ($actions as $option) - { - $s_actions[] = '' . $user->lang[strtoupper($option)] . ''; - } - - $template->assign_block_vars('installed', array( - 'S_DEFAULT_STYLE' => ($mode == 'style' && $row['style_id'] == $config['default_style']) ? true : false, - 'U_EDIT' => $this->u_action . '&action=' . (($mode == 'style') ? 'details' : 'edit') . '&id=' . $row[$mode . '_id'], - 'U_STYLE_ACT_DEACT' => $this->u_action . '&action=' . $stylevis . '&id=' . $row[$mode . '_id'], - 'L_STYLE_ACT_DEACT' => $user->lang['STYLE_' . strtoupper($stylevis)], - 'S_OPTIONS' => implode(' | ', $s_options), - 'S_ACTIONS' => implode(' | ', $s_actions), - 'U_PREVIEW' => ($mode == 'style') ? append_sid("{$phpbb_root_path}index.$phpEx", "$mode=" . $row[$mode . '_id']) : '', - - 'NAME' => $row[$mode . '_name'], - 'STYLE_COUNT' => ($mode == 'style' && isset($style_count[$row['style_id']])) ? $style_count[$row['style_id']] : 0, - - 'S_INACTIVE' => ($mode == 'style' && !$row['style_active']) ? true : false, - ) - ); - } - $db->sql_freeresult($result); - - // Grab uninstalled items - $new_ary = $cfg = array(); - - $dp = @opendir("{$phpbb_root_path}styles"); - - if ($dp) - { - while (($file = readdir($dp)) !== false) - { - if ($file[0] == '.' || !is_dir($phpbb_root_path . 'styles/' . $file)) - { - continue; - } - - $subpath = ($mode != 'style') ? "$mode/" : ''; - if (file_exists("{$phpbb_root_path}styles/$file/$subpath$mode.cfg")) - { - if ($cfg = file("{$phpbb_root_path}styles/$file/$subpath$mode.cfg")) - { - $items = parse_cfg_file('', $cfg); - $name = (isset($items['name'])) ? trim($items['name']) : false; - - if ($name && !in_array($name, $installed)) - { - $new_ary[] = array( - 'path' => $file, - 'name' => $name, - 'copyright' => $items['copyright'], - ); - } - } - } - } - closedir($dp); - } - - unset($installed); - - if (sizeof($new_ary)) - { - foreach ($new_ary as $cfg) - { - $template->assign_block_vars('uninstalled', array( - 'NAME' => $cfg['name'], - 'COPYRIGHT' => $cfg['copyright'], - 'U_INSTALL' => $this->u_action . '&action=install&path=' . urlencode($cfg['path'])) - ); - } - } - unset($new_ary); - - $template->assign_vars(array( - 'S_BASIS_OPTIONS' => $basis_options) - ); - - } - - /** - * Provides a template editor which allows saving changes to template files on the filesystem or in the database. - * - * @param int $template_id specifies which template set is being edited - */ - function edit_template($template_id) - { - global $phpbb_root_path, $phpEx, $config, $db, $cache, $user, $template, $safe_mode; - - if (defined('PHPBB_DISABLE_ACP_EDITOR')) - { - trigger_error($user->lang['EDITOR_DISABLED'] . adm_back_link($this->u_action)); - } - - $this->page_title = 'EDIT_TEMPLATE'; - - $filelist = $filelist_cats = array(); - - $template_data = utf8_normalize_nfc(request_var('template_data', '', true)); - $template_data = htmlspecialchars_decode($template_data); - $template_file = utf8_normalize_nfc(request_var('template_file', '', true)); - $text_rows = max(5, min(999, request_var('text_rows', 20))); - $save_changes = (isset($_POST['save'])) ? true : false; - - // make sure template_file path doesn't go upwards - $template_file = preg_replace('#\.{2,}#', '.', $template_file); - - // Retrieve some information about the template - $sql = 'SELECT template_path, template_name - FROM ' . STYLES_TEMPLATE_TABLE . " - WHERE template_id = $template_id"; - $result = $db->sql_query($sql); - $template_info = $db->sql_fetchrow($result); - $db->sql_freeresult($result); - - if (!$template_info) - { - trigger_error($user->lang['NO_TEMPLATE'] . adm_back_link($this->u_action), E_USER_WARNING); - } - - // Get the filesystem location of the current file - $template_path = "{$phpbb_root_path}styles/{$template_info['template_path']}/template"; - $file = "$template_path/$template_file"; - - if ($template_file) - { - $l_not_writable = sprintf($user->lang['TEMPLATE_FILE_NOT_WRITABLE'], htmlspecialchars($template_file)) . adm_back_link($this->u_action); - - if ($safe_mode) - { - trigger_error($l_not_writable, E_USER_WARNING); - } - - if (file_exists($file) && is_file($file) && is_readable($file)) - { - if (!phpbb_is_writable($file)) - { - trigger_error($l_not_writable, E_USER_WARNING); - } - } - else - { - trigger_error($user->lang['NO_TEMPLATE'] . adm_back_link($this->u_action), E_USER_WARNING); - } - } - - if ($save_changes && !check_form_key('acp_styles')) - { - trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action), E_USER_WARNING); - } - else if (!$save_changes) - { - add_form_key('acp_styles'); - } - - // save changes to the template if the user submitted any - if ($save_changes && $template_file) - { - // Try to write the file - if (!($fp = @fopen($file, 'wb'))) - { - // File exists and is writeable, but still not able to be written to - trigger_error($l_not_writable, E_USER_WARNING); - } - fwrite($fp, $template_data); - fclose($fp); - - // destroy the cached version of the template (filename without extension) - $this->clear_template_cache($template_info, array(substr($template_file, 0, -5))); - - $cache->destroy('sql', STYLES_TABLE); - - add_log('admin', 'LOG_TEMPLATE_EDIT', $template_info['template_name'], $template_file); - trigger_error($user->lang['TEMPLATE_FILE_UPDATED'] . adm_back_link($this->u_action . "&action=edit&id=$template_id&text_rows=$text_rows&template_file=$template_file")); - } - - // Generate a category array containing template filenames - - $filelist = filelist($template_path, '', 'html'); - $filelist[''] = array_diff($filelist[''], array('bbcode.html')); - - if ($template_file) - { - $template_data = file_get_contents($file); - - if (!$template_data) - { - trigger_error($user->lang['NO_TEMPLATE'] . adm_back_link($this->u_action), E_USER_WARNING); - } - } - - if (empty($filelist[''])) - { - trigger_error($user->lang['NO_TEMPLATE'] . adm_back_link($this->u_action), E_USER_WARNING); - } - - // Now create the categories - $filelist_cats[''] = array(); - foreach ($filelist as $pathfile => $file_ary) - { - // Use the directory name as category name - if (!empty($pathfile)) - { - $filelist_cats[$pathfile] = array(); - foreach ($file_ary as $file) - { - $filelist_cats[$pathfile][$pathfile . $file] = $file; - } - } - // or if it's in the main category use the word before the first underscore to group files - else - { - $cats = array(); - foreach ($file_ary as $file) - { - $cats[] = substr($file, 0, strpos($file, '_')); - $filelist_cats[substr($file, 0, strpos($file, '_'))][$file] = $file; - } - - $cats = array_values(array_unique($cats)); - - // we don't need any single element categories so put them into the misc '' category - for ($i = 0, $n = sizeof($cats); $i < $n; $i++) - { - if (sizeof($filelist_cats[$cats[$i]]) == 1 && $cats[$i] !== '') - { - $filelist_cats[''][key($filelist_cats[$cats[$i]])] = current($filelist_cats[$cats[$i]]); - unset($filelist_cats[$cats[$i]]); - } - } - unset($cats); - } - } - unset($filelist); - - // Generate list of categorised template files - $tpl_options = ''; - ksort($filelist_cats); - foreach ($filelist_cats as $category => $tpl_ary) - { - ksort($tpl_ary); - - if (!empty($category)) - { - $tpl_options .= ''; - } - - foreach ($tpl_ary as $filename => $file) - { - $selected = ($template_file == $filename) ? ' selected="selected"' : ''; - $tpl_options .= ''; - } - } - - $template->assign_vars(array( - 'S_EDIT_TEMPLATE' => true, - 'S_HIDDEN_FIELDS' => build_hidden_fields(array('template_file' => $template_file)), - 'S_TEMPLATES' => $tpl_options, - - 'U_ACTION' => $this->u_action . "&action=edit&id=$template_id&text_rows=$text_rows", - 'U_BACK' => $this->u_action, - - 'L_EDIT' => $user->lang['EDIT_TEMPLATE'], - 'L_EDIT_EXPLAIN' => $user->lang['EDIT_TEMPLATE_EXPLAIN'], - 'L_EDITOR' => $user->lang['TEMPLATE_EDITOR'], - 'L_EDITOR_HEIGHT' => $user->lang['TEMPLATE_EDITOR_HEIGHT'], - 'L_FILE' => $user->lang['TEMPLATE_FILE'], - 'L_SELECT' => $user->lang['SELECT_TEMPLATE'], - 'L_SELECTED' => $user->lang['SELECTED_TEMPLATE'], - 'L_SELECTED_FILE' => $user->lang['SELECTED_TEMPLATE_FILE'], - - 'SELECTED_TEMPLATE' => $template_info['template_name'], - 'TEMPLATE_FILE' => $template_file, - 'TEMPLATE_DATA' => utf8_htmlspecialchars($template_data), - 'TEXT_ROWS' => $text_rows) - ); - } - - /** - * Allows the admin to view cached versions of template files and clear single template cache files - * - * @param int $template_id specifies which template's cache is shown - */ - function template_cache($template_id) - { - global $phpbb_root_path, $phpEx, $config, $db, $cache, $user, $template; - - $source = str_replace('/', '.', request_var('source', '')); - $file_ary = array_diff(request_var('delete', array('')), array('')); - $submit = isset($_POST['submit']) ? true : false; - - $sql = 'SELECT * - FROM ' . STYLES_TEMPLATE_TABLE . " - WHERE template_id = $template_id"; - $result = $db->sql_query($sql); - $template_row = $db->sql_fetchrow($result); - $db->sql_freeresult($result); - - if (!$template_row) - { - trigger_error($user->lang['NO_TEMPLATE'] . adm_back_link($this->u_action), E_USER_WARNING); - } - - // User wants to delete one or more files ... - if ($submit && $file_ary) - { - $this->clear_template_cache($template_row, $file_ary); - trigger_error($user->lang['TEMPLATE_CACHE_CLEARED'] . adm_back_link($this->u_action . "&action=cache&id=$template_id")); - } - - $cache_prefix = 'tpl_' . str_replace('_', '-', $template_row['template_path']); - - // Someone wants to see the cached source ... so we'll highlight it, - // add line numbers and indent it appropriately. This could be nasty - // on larger source files ... - if ($source && file_exists("{$phpbb_root_path}cache/{$cache_prefix}_$source.html.$phpEx")) - { - adm_page_header($user->lang['TEMPLATE_CACHE']); - - $template->set_filenames(array( - 'body' => 'viewsource.html') - ); - - $template->assign_vars(array( - 'FILENAME' => str_replace('.', '/', $source) . '.html') - ); - - $code = str_replace(array("\r\n", "\r"), array("\n", "\n"), file_get_contents("{$phpbb_root_path}cache/{$cache_prefix}_$source.html.$phpEx")); - - $conf = array('highlight.bg', 'highlight.comment', 'highlight.default', 'highlight.html', 'highlight.keyword', 'highlight.string'); - foreach ($conf as $ini_var) - { - @ini_set($ini_var, str_replace('highlight.', 'syntax', $ini_var)); - } - - $marker = 'MARKER' . time(); - $code = highlight_string(str_replace("\n", $marker, $code), true); - $code = str_replace($marker, "\n", $code); - $str_from = array('', '', '','[', ']', '.', ':'); - $str_to = array('', '', '', '[', ']', '.', ':'); - - $code = str_replace($str_from, $str_to, $code); - $code = preg_replace('#^()\n?(.*?)\n?()$#ism', '$1$2$3', $code); - $code = substr($code, strlen('')); - $code = substr($code, 0, -1 * strlen('')); - $code = explode("\n", $code); - - foreach ($code as $key => $line) - { - $template->assign_block_vars('source', array( - 'LINENUM' => $key + 1, - 'LINE' => preg_replace('#([^ ;]) ([^ &])#', '$1 $2', $line)) - ); - unset($code[$key]); - } - - adm_page_footer(); - } - - // Get a list of cached template files and then retrieve additional information about them - $file_ary = $this->template_cache_filelist($template_row['template_path']); - - foreach ($file_ary as $file) - { - $file = str_replace('/', '.', $file); - - // perform some dirty guessing to get the path right. - // We assume that three dots in a row were '../' - $tpl_file = str_replace('.', '/', $file); - $tpl_file = str_replace('///', '../', $tpl_file); - - $filename = "{$cache_prefix}_$file.html.$phpEx"; - - if (!file_exists("{$phpbb_root_path}cache/$filename")) - { - continue; - } - - $file_tpl = "{$phpbb_root_path}styles/{$template_row['template_path']}/template/$tpl_file.html"; - $inherited = false; - - if (isset($template_row['template_inherits_id']) && $template_row['template_inherits_id'] && !file_exists($file_tpl)) - { - $file_tpl = "{$phpbb_root_path}styles/{$template_row['template_inherit_path']}/template/$tpl_file.html"; - $inherited = true; - } - - $template->assign_block_vars('file', array( - 'U_VIEWSOURCE' => $this->u_action . "&action=cache&id=$template_id&source=$file", - - 'CACHED' => $user->format_date(filemtime("{$phpbb_root_path}cache/$filename")), - 'FILENAME' => $file, - 'FILENAME_PATH' => $file_tpl, - 'FILESIZE' => get_formatted_filesize(filesize("{$phpbb_root_path}cache/$filename")), - 'MODIFIED' => $user->format_date(filemtime($file_tpl)), - )); - } - - $template->assign_vars(array( - 'S_CACHE' => true, - 'S_TEMPLATE' => true, - - 'U_ACTION' => $this->u_action . "&action=cache&id=$template_id", - 'U_BACK' => $this->u_action) - ); - } - - /** - * Provides a css editor and a basic easier to use stylesheet editing tool for less experienced (or lazy) users - * - * @param int $theme_id specifies which theme is being edited - */ - function edit_theme($theme_id) - { - global $phpbb_root_path, $phpEx, $config, $db, $cache, $user, $template, $safe_mode; - - $this->page_title = 'EDIT_THEME'; - - $filelist = $filelist_cats = array(); - - $theme_data = utf8_normalize_nfc(request_var('template_data', '', true)); - $theme_data = htmlspecialchars_decode($theme_data); - $theme_file = utf8_normalize_nfc(request_var('template_file', '', true)); - $text_rows = max(5, min(999, request_var('text_rows', 20))); - $save_changes = (isset($_POST['save'])) ? true : false; - - // make sure theme_file path doesn't go upwards - $theme_file = str_replace('..', '.', $theme_file); - - // Retrieve some information about the theme - $sql = 'SELECT theme_path, theme_name - FROM ' . STYLES_THEME_TABLE . " - WHERE theme_id = $theme_id"; - $result = $db->sql_query($sql); - - if (!($theme_info = $db->sql_fetchrow($result))) - { - trigger_error($user->lang['NO_THEME'] . adm_back_link($this->u_action), E_USER_WARNING); - } - $db->sql_freeresult($result); - - // Get the filesystem location of the current file - $theme_path = "{$phpbb_root_path}styles/{$theme_info['theme_path']}/theme"; - $file = "$theme_path/$theme_file"; - - if ($theme_file) - { - $l_not_writable = sprintf($user->lang['THEME_FILE_NOT_WRITABLE'], htmlspecialchars($theme_file)) . adm_back_link($this->u_action); - - if ($safe_mode) - { - trigger_error($l_not_writable, E_USER_WARNING); - } - - if (file_exists($file) && is_file($file) && is_readable($file)) - { - if (!phpbb_is_writable($file)) - { - trigger_error($l_not_writable, E_USER_WARNING); - } - } - else - { - trigger_error($user->lang['NO_THEME'] . adm_back_link($this->u_action), E_USER_WARNING); - } - } - - // save changes to the theme if the user submitted any - if ($save_changes && $theme_file) - { - $message = $user->lang['THEME_UPDATED']; - - if (!($fp = @fopen($file, 'wb'))) - { - trigger_error($l_not_writable, E_USER_WARNING); - } - fwrite($fp, $theme_data); - fclose($fp); - - $cache->destroy('sql', STYLES_THEME_TABLE); - add_log('admin', 'LOG_THEME_EDIT_FILE', $theme_info['theme_name'], $theme_file); - - trigger_error($message . adm_back_link($this->u_action . "&action=edit&id=$theme_id&template_file=$theme_file&text_rows=$text_rows")); - } - - // Generate a category array containing theme filenames - $filelist = filelist($theme_path, '', 'css'); - - if ($theme_file) - { - $theme_data = file_get_contents($file); - - if (!$theme_data) - { - trigger_error($user->lang['NO_THEME'] . adm_back_link($this->u_action), E_USER_WARNING); - } - } - - // Now create the categories - $filelist_cats[''] = array(); - foreach ($filelist as $pathfile => $file_ary) - { - // Use the directory name as category name - if (!empty($pathfile)) - { - $filelist_cats[$pathfile] = array(); - foreach ($file_ary as $file) - { - $filelist_cats[$pathfile][$pathfile . $file] = $file; - } - } - // or if it's in the main category use the word before the first underscore to group files - else - { - $cats = array(); - foreach ($file_ary as $file) - { - $cats[] = substr($file, 0, strpos($file, '_')); - $filelist_cats[substr($file, 0, strpos($file, '_'))][$file] = $file; - } - - $cats = array_values(array_unique($cats)); - - // we don't need any single element categories so put them into the misc '' category - for ($i = 0, $n = sizeof($cats); $i < $n; $i++) - { - if (sizeof($filelist_cats[$cats[$i]]) == 1 && $cats[$i] !== '') - { - $filelist_cats[''][key($filelist_cats[$cats[$i]])] = current($filelist_cats[$cats[$i]]); - unset($filelist_cats[$cats[$i]]); - } - } - unset($cats); - } - } - unset($filelist); - - // Generate list of categorised theme files - $tpl_options = ''; - ksort($filelist_cats); - foreach ($filelist_cats as $category => $tpl_ary) - { - ksort($tpl_ary); - - if (!empty($category)) - { - $tpl_options .= ''; - } - - foreach ($tpl_ary as $filename => $file) - { - $selected = ($theme_file == $filename) ? ' selected="selected"' : ''; - $tpl_options .= ''; - } - } - - $template->assign_vars(array( - 'S_EDIT_THEME' => true, - 'S_HIDDEN_FIELDS' => build_hidden_fields(array('template_file' => $theme_file)), - 'S_TEMPLATES' => $tpl_options, - - 'U_ACTION' => $this->u_action . "&action=edit&id=$theme_id&text_rows=$text_rows", - 'U_BACK' => $this->u_action, - - 'L_EDIT' => $user->lang['EDIT_THEME'], - 'L_EDIT_EXPLAIN' => $user->lang['EDIT_THEME_EXPLAIN'], - 'L_EDITOR' => $user->lang['THEME_EDITOR'], - 'L_EDITOR_HEIGHT' => $user->lang['THEME_EDITOR_HEIGHT'], - 'L_FILE' => $user->lang['THEME_FILE'], - 'L_SELECT' => $user->lang['SELECT_THEME'], - 'L_SELECTED' => $user->lang['SELECTED_THEME'], - 'L_SELECTED_FILE' => $user->lang['SELECTED_THEME_FILE'], - - 'SELECTED_TEMPLATE' => $theme_info['theme_name'], - 'TEMPLATE_FILE' => $theme_file, - 'TEMPLATE_DATA' => utf8_htmlspecialchars($theme_data), - 'TEXT_ROWS' => $text_rows, - )); - } - - /** - * Remove style/template/theme - */ - function remove($mode, $style_id) - { - global $db, $template, $user, $phpbb_root_path, $cache, $config; - - $new_id = request_var('new_id', 0); - $update = (isset($_POST['update'])) ? true : false; - $sql_where = ''; - - switch ($mode) - { - case 'style': - $sql_from = STYLES_TABLE; - $sql_select = 'style_id, style_name, template_id, theme_id'; - $sql_where = 'AND style_active = 1'; - break; - - case 'template': - $sql_from = STYLES_TEMPLATE_TABLE; - $sql_select = 'template_id, template_name, template_path'; - break; - - case 'theme': - $sql_from = STYLES_THEME_TABLE; - $sql_select = 'theme_id, theme_name, theme_path'; - break; - } - - if ($mode === 'template' && ($conflicts = $this->check_inheritance($mode, $style_id))) - { - $l_type = strtoupper($mode); - $msg = $user->lang[$l_type . '_DELETE_DEPENDENT']; - foreach ($conflicts as $id => $values) - { - $msg .= '
    ' . $values['template_name']; - } - - trigger_error($msg . adm_back_link($this->u_action), E_USER_WARNING); - } - - $l_prefix = strtoupper($mode); - - $sql = "SELECT $sql_select - FROM $sql_from - WHERE {$mode}_id = $style_id"; - $result = $db->sql_query($sql); - $style_row = $db->sql_fetchrow($result); - $db->sql_freeresult($result); - - if (!$style_row) - { - trigger_error($user->lang['NO_' . $l_prefix] . adm_back_link($this->u_action), E_USER_WARNING); - } - - $s_only_component = $this->display_component_options($mode, $style_row[$mode . '_id'], $style_row); - - if ($s_only_component) - { - trigger_error($user->lang['ONLY_' . $l_prefix] . adm_back_link($this->u_action), E_USER_WARNING); - } - - if ($update) - { - if ($mode == 'style') - { - $sql = "DELETE FROM $sql_from - WHERE {$mode}_id = $style_id"; - $db->sql_query($sql); - - $sql = 'UPDATE ' . USERS_TABLE . " - SET user_style = $new_id - WHERE user_style = $style_id"; - $db->sql_query($sql); - - $sql = 'UPDATE ' . FORUMS_TABLE . " - SET forum_style = $new_id - WHERE forum_style = $style_id"; - $db->sql_query($sql); - - if ($style_id == $config['default_style']) - { - set_config('default_style', $new_id); - } - - // Remove the components - $components = array('template', 'theme'); - foreach ($components as $component) - { - $new_id = request_var('new_' . $component . '_id', 0); - $component_id = $style_row[$component . '_id']; - $this->remove_component($component, $component_id, $new_id, $style_id); - } - } - else - { - $this->remove_component($mode, $style_id, $new_id); - } - - $cache->destroy('sql', STYLES_TABLE); - - add_log('admin', 'LOG_' . $l_prefix . '_DELETE', $style_row[$mode . '_name']); - $message = ($mode != 'style') ? $l_prefix . '_DELETED_FS' : $l_prefix . '_DELETED'; - trigger_error($user->lang[$message] . adm_back_link($this->u_action)); - } - - $this->page_title = 'DELETE_' . $l_prefix; - - $template->assign_vars(array( - 'S_DELETE' => true, - - 'L_TITLE' => $user->lang[$this->page_title], - 'L_EXPLAIN' => $user->lang[$this->page_title . '_EXPLAIN'], - 'L_NAME' => $user->lang[$l_prefix . '_NAME'], - 'L_REPLACE' => $user->lang['REPLACE_' . $l_prefix], - 'L_REPLACE_EXPLAIN' => $user->lang['REPLACE_' . $l_prefix . '_EXPLAIN'], - - 'U_ACTION' => $this->u_action . "&action=delete&id=$style_id", - 'U_BACK' => $this->u_action, - - 'NAME' => $style_row[$mode . '_name'], - ) - ); - - if ($mode == 'style') - { - $template->assign_vars(array( - 'S_DELETE_STYLE' => true, - )); - } - } - - /** - * Remove template/theme entry from the database - */ - function remove_component($component, $component_id, $new_id, $style_id = false) - { - global $db; - - if (($new_id == 0) || ($component === 'template' && ($conflicts = $this->check_inheritance($component, $component_id)))) - { - // We can not delete the template, as the user wants to keep the component or an other template is inheriting from this one. - return; - } - - $component_in_use = array(); - if ($component != 'style') - { - $component_in_use = $this->component_in_use($component, $component_id, $style_id); - } - - if (($new_id == -1) && !empty($component_in_use)) - { - // We can not delete the component, as it is still in use - return; - } - - switch ($component) - { - case 'template': - $sql_from = STYLES_TEMPLATE_TABLE; - break; - - case 'theme': - $sql_from = STYLES_THEME_TABLE; - break; - } - - $sql = "DELETE FROM $sql_from - WHERE {$component}_id = $component_id"; - $db->sql_query($sql); - - $sql = 'UPDATE ' . STYLES_TABLE . " - SET {$component}_id = $new_id - WHERE {$component}_id = $component_id"; - $db->sql_query($sql); - } - - /** - * Display the options which can be used to replace a style/template/theme - * - * @return boolean Returns true if the component is the only component and can not be deleted. - */ - function display_component_options($component, $component_id, $style_row = false, $style_id = false) - { - global $db, $template, $user; - - $is_only_component = true; - $component_in_use = array(); - if ($component != 'style') - { - $component_in_use = $this->component_in_use($component, $component_id, $style_id); - } - - $sql_where = ''; - switch ($component) - { - case 'style': - $sql_from = STYLES_TABLE; - $sql_where = 'WHERE style_active = 1'; - break; - - case 'template': - $sql_from = STYLES_TEMPLATE_TABLE; - $sql_where = 'WHERE template_inherits_id <> ' . $component_id; - break; - - case 'theme': - $sql_from = STYLES_THEME_TABLE; - break; - } - - $s_options = ''; - if (($component != 'style') && empty($component_in_use)) - { - // If it is not in use, there must be another component - $is_only_component = false; - - $sql = "SELECT {$component}_id, {$component}_name - FROM $sql_from - WHERE {$component}_id = {$component_id}"; - $result = $db->sql_query($sql); - $row = $db->sql_fetchrow($result); - $db->sql_freeresult($result); - - $s_options .= ''; - $s_options .= ''; - } - else - { - $sql = "SELECT {$component}_id, {$component}_name - FROM $sql_from - $sql_where - ORDER BY {$component}_name ASC"; - $result = $db->sql_query($sql); - - $s_keep_option = $s_options = ''; - while ($row = $db->sql_fetchrow($result)) - { - if ($row[$component . '_id'] != $component_id) - { - $is_only_component = false; - $s_options .= ''; - } - else if ($component != 'style') - { - $s_keep_option = ''; - } - } - $db->sql_freeresult($result); - $s_options = $s_keep_option . $s_options; - } - - if (!$style_row) - { - $template->assign_var('S_REPLACE_' . strtoupper($component) . '_OPTIONS', $s_options); - } - else - { - $template->assign_var('S_REPLACE_OPTIONS', $s_options); - if ($component == 'style') - { - $components = array('template', 'theme'); - foreach ($components as $component) - { - $this->display_component_options($component, $style_row[$component . '_id'], false, $component_id, true); - } - } - } - - return $is_only_component; - } - - /** - * Check whether the component is still used by another style or component - */ - function component_in_use($component, $component_id, $style_id = false) - { - global $db; - - $component_in_use = array(); - - if ($style_id) - { - $sql = 'SELECT style_id, style_name - FROM ' . STYLES_TABLE . " - WHERE {$component}_id = {$component_id} - AND style_id <> {$style_id} - ORDER BY style_name ASC"; - } - else - { - $sql = 'SELECT style_id, style_name - FROM ' . STYLES_TABLE . " - WHERE {$component}_id = {$component_id} - ORDER BY style_name ASC"; - } - $result = $db->sql_query($sql); - while ($row = $db->sql_fetchrow($result)) - { - $component_in_use[] = $row['style_name']; - } - $db->sql_freeresult($result); - - if ($component === 'template' && ($conflicts = $this->check_inheritance($component, $component_id))) - { - foreach ($conflicts as $temp_id => $conflict_data) - { - $component_in_use[] = $conflict_data['template_name']; - } - } - - return $component_in_use; - } - - /** - * Export style or style elements - */ - function export($mode, $style_id) - { - global $db, $template, $user, $phpbb_root_path, $cache, $phpEx, $config; - - $update = (isset($_POST['update'])) ? true : false; - - $inc_template = request_var('inc_template', 0); - $inc_theme = request_var('inc_theme', 0); - $store = request_var('store', 0); - $format = request_var('format', ''); - - $error = array(); - $methods = array('tar'); - - $available_methods = array('tar.gz' => 'zlib', 'tar.bz2' => 'bz2', 'zip' => 'zlib'); - foreach ($available_methods as $type => $module) - { - if (!@extension_loaded($module)) - { - continue; - } - - $methods[] = $type; - } - - if (!in_array($format, $methods)) - { - $format = 'tar'; - } - - switch ($mode) - { - case 'style': - if ($update && ($inc_template + $inc_theme) < 1) - { - $error[] = $user->lang['STYLE_ERR_MORE_ELEMENTS']; - } - - $name = 'style_name'; - - $sql_select = 's.style_id, s.style_name, s.style_copyright'; - $sql_select .= ($inc_template) ? ', t.*' : ', t.template_name'; - $sql_select .= ($inc_theme) ? ', c.*' : ', c.theme_name'; - $sql_from = STYLES_TABLE . ' s, ' . STYLES_TEMPLATE_TABLE . ' t, ' . STYLES_THEME_TABLE . ' c'; - $sql_where = "s.style_id = $style_id AND t.template_id = s.template_id AND c.theme_id = s.theme_id"; - - $l_prefix = 'STYLE'; - break; - - case 'template': - $name = 'template_name'; - - $sql_select = '*'; - $sql_from = STYLES_TEMPLATE_TABLE; - $sql_where = "template_id = $style_id"; - - $l_prefix = 'TEMPLATE'; - break; - - case 'theme': - $name = 'theme_name'; - - $sql_select = '*'; - $sql_from = STYLES_THEME_TABLE; - $sql_where = "theme_id = $style_id"; - - $l_prefix = 'THEME'; - break; - } - - if ($update && !sizeof($error)) - { - $sql = "SELECT $sql_select - FROM $sql_from - WHERE $sql_where"; - $result = $db->sql_query($sql); - $style_row = $db->sql_fetchrow($result); - $db->sql_freeresult($result); - - if (!$style_row) - { - trigger_error($user->lang['NO_' . $l_prefix] . adm_back_link($this->u_action), E_USER_WARNING); - } - - $var_ary = array('style_id', 'style_name', 'style_copyright', 'template_id', 'template_name', 'template_path', 'template_copyright', 'template_inherits_id', 'bbcode_bitfield', 'theme_id', 'theme_name', 'theme_path', 'theme_copyright'); - - foreach ($var_ary as $var) - { - if (!isset($style_row[$var])) - { - $style_row[$var] = ''; - } - } - - $files = $data = array(); - - if ($mode == 'style') - { - $style_cfg = str_replace(array('{MODE}', '{NAME}', '{COPYRIGHT}', '{VERSION}'), array($mode, $style_row['style_name'], $style_row['style_copyright'], $config['version']), $this->style_cfg); - - $style_cfg .= (!$inc_template) ? "\nrequired_template = {$style_row['template_name']}" : ''; - $style_cfg .= (!$inc_theme) ? "\nrequired_theme = {$style_row['theme_name']}" : ''; - - $data[] = array( - 'src' => $style_cfg, - 'prefix' => 'style.cfg' - ); - - unset($style_cfg); - } - - // Export template core code - if ($mode == 'template' || $inc_template) - { - $use_template_name = $style_row['template_name']; - - // Add the inherit from variable, depending on it's use... - if ($style_row['template_inherits_id']) - { - // Get the template name - $sql = 'SELECT template_name - FROM ' . STYLES_TEMPLATE_TABLE . ' - WHERE template_id = ' . (int) $style_row['template_inherits_id']; - $result = $db->sql_query($sql); - $use_template_name = (string) $db->sql_fetchfield('template_name'); - $db->sql_freeresult($result); - } - - $template_cfg = str_replace(array('{MODE}', '{NAME}', '{COPYRIGHT}', '{VERSION}', '{INHERIT_FROM}'), array($mode, $style_row['template_name'], $style_row['template_copyright'], $config['version'], $use_template_name), $this->template_cfg); - - $template_cfg .= "\n\nbbcode_bitfield = {$style_row['bbcode_bitfield']}"; - - $data[] = array( - 'src' => $template_cfg, - 'prefix' => 'template/template.cfg' - ); - - // This is potentially nasty memory-wise ... - $files[] = array( - 'src' => "styles/{$style_row['template_path']}/template/", - 'prefix-' => "styles/{$style_row['template_path']}/", - 'prefix+' => false, - 'exclude' => 'template.cfg' - ); - unset($template_cfg); - } - - // Export theme core code - if ($mode == 'theme' || $inc_theme) - { - $theme_cfg = str_replace(array('{MODE}', '{NAME}', '{COPYRIGHT}', '{VERSION}'), array($mode, $style_row['theme_name'], $style_row['theme_copyright'], $config['version']), $this->theme_cfg); - - // Read old cfg file - $items = $cache->obtain_cfg_items($style_row); - $items = $items['theme']; - - $files[] = array( - 'src' => "styles/{$style_row['theme_path']}/theme/", - 'prefix-' => "styles/{$style_row['theme_path']}/", - 'prefix+' => false, - 'exclude' => 'theme.cfg', - ); - - $data[] = array( - 'src' => $theme_cfg, - 'prefix' => 'theme/theme.cfg', - ); - - unset($items, $theme_cfg); - } - - switch ($format) - { - case 'tar': - $ext = '.tar'; - break; - - case 'zip': - $ext = '.zip'; - break; - - case 'tar.gz': - $ext = '.tar.gz'; - break; - - case 'tar.bz2': - $ext = '.tar.bz2'; - break; - - default: - $error[] = $user->lang[$l_prefix . '_ERR_ARCHIVE']; - } - - if (!sizeof($error)) - { - include($phpbb_root_path . 'includes/functions_compress.' . $phpEx); - - if ($mode == 'style') - { - $path = preg_replace('#[^\w-]+#', '_', $style_row['style_name']); - } - else - { - $path = $style_row[$mode . '_path']; - } - - if ($format == 'zip') - { - $compress = new compress_zip('w', $phpbb_root_path . "store/$path$ext"); - } - else - { - $compress = new compress_tar('w', $phpbb_root_path . "store/$path$ext", $ext); - } - - if (sizeof($files)) - { - foreach ($files as $file_ary) - { - $compress->add_file($file_ary['src'], $file_ary['prefix-'], $file_ary['prefix+'], $file_ary['exclude']); - } - } - - if (sizeof($data)) - { - foreach ($data as $data_ary) - { - $compress->add_data($data_ary['src'], $data_ary['prefix']); - } - } - - $compress->close(); - - add_log('admin', 'LOG_' . $l_prefix . '_EXPORT', $style_row[$mode . '_name']); - - if (!$store) - { - $compress->download($path); - @unlink("{$phpbb_root_path}store/$path$ext"); - exit; - } - - trigger_error(sprintf($user->lang[$l_prefix . '_EXPORTED'], "store/$path$ext") . adm_back_link($this->u_action)); - } - } - - $sql = "SELECT {$mode}_id, {$mode}_name - FROM " . (($mode == 'style') ? STYLES_TABLE : $sql_from) . " - WHERE {$mode}_id = $style_id"; - $result = $db->sql_query($sql); - $style_row = $db->sql_fetchrow($result); - $db->sql_freeresult($result); - - if (!$style_row) - { - trigger_error($user->lang['NO_' . $l_prefix] . adm_back_link($this->u_action), E_USER_WARNING); - } - - $this->page_title = $l_prefix . '_EXPORT'; - - $format_buttons = ''; - foreach ($methods as $method) - { - $format_buttons .= ''; - } - - $template->assign_vars(array( - 'S_EXPORT' => true, - 'S_ERROR_MSG' => (sizeof($error)) ? true : false, - 'S_STYLE' => ($mode == 'style') ? true : false, - - 'L_TITLE' => $user->lang[$this->page_title], - 'L_EXPLAIN' => $user->lang[$this->page_title . '_EXPLAIN'], - 'L_NAME' => $user->lang[$l_prefix . '_NAME'], - - 'U_ACTION' => $this->u_action . '&action=export&id=' . $style_id, - 'U_BACK' => $this->u_action, - - 'ERROR_MSG' => (sizeof($error)) ? implode('
    ', $error) : '', - 'NAME' => $style_row[$mode . '_name'], - 'FORMAT_BUTTONS' => $format_buttons) - ); - } - - /** - * Display details - */ - function details($mode, $style_id) - { - global $template, $db, $config, $user, $safe_mode, $cache, $phpbb_root_path; - - $update = (isset($_POST['update'])) ? true : false; - $l_type = strtoupper($mode); - - $error = array(); - $element_ary = array('template' => STYLES_TEMPLATE_TABLE, 'theme' => STYLES_THEME_TABLE); - - switch ($mode) - { - case 'style': - $sql_from = STYLES_TABLE; - break; - - case 'template': - $sql_from = STYLES_TEMPLATE_TABLE; - break; - - case 'theme': - $sql_from = STYLES_THEME_TABLE; - break; - } - - $sql = "SELECT * - FROM $sql_from - WHERE {$mode}_id = $style_id"; - $result = $db->sql_query($sql); - $style_row = $db->sql_fetchrow($result); - $db->sql_freeresult($result); - - if (!$style_row) - { - trigger_error($user->lang['NO_' . $l_type] . adm_back_link($this->u_action), E_USER_WARNING); - } - - $style_row['style_default'] = ($mode == 'style' && $config['default_style'] == $style_id) ? 1 : 0; - - if ($update) - { - $name = utf8_normalize_nfc(request_var('name', '', true)); - $copyright = utf8_normalize_nfc(request_var('copyright', '', true)); - - $template_id = request_var('template_id', 0); - $theme_id = request_var('theme_id', 0); - - $style_active = request_var('style_active', 0); - $style_default = request_var('style_default', 0); - - // If the admin selected the style to be the default style, but forgot to activate it... we will do it for him - if ($style_default) - { - $style_active = 1; - } - - $sql = "SELECT {$mode}_id, {$mode}_name - FROM $sql_from - WHERE {$mode}_id <> $style_id - AND LOWER({$mode}_name) = '" . $db->sql_escape(strtolower($name)) . "'"; - $result = $db->sql_query($sql); - $conflict = $db->sql_fetchrow($result); - $db->sql_freeresult($result); - - if ($mode == 'style' && (!$template_id || !$theme_id)) - { - $error[] = $user->lang['STYLE_ERR_NO_IDS']; - } - - if ($mode == 'style' && $style_row['style_active'] && !$style_active && $config['default_style'] == $style_id) - { - $error[] = $user->lang['DEACTIVATE_DEFAULT']; - } - - if (!$name || $conflict) - { - $error[] = $user->lang[$l_type . '_ERR_STYLE_NAME']; - } - - if (!sizeof($error)) - { - // Check length settings - if (utf8_strlen($name) > 30) - { - $error[] = $user->lang[$l_type . '_ERR_NAME_LONG']; - } - - if (utf8_strlen($copyright) > 60) - { - $error[] = $user->lang[$l_type . '_ERR_COPY_LONG']; - } - } - } - - if ($update && sizeof($error)) - { - $style_row = array_merge($style_row, array( - 'template_id' => $template_id, - 'theme_id' => $theme_id, - 'style_active' => $style_active, - $mode . '_name' => $name, - $mode . '_copyright' => $copyright) - ); - } - - // User has submitted form and no errors have occurred - if ($update && !sizeof($error)) - { - $sql_ary = array( - $mode . '_name' => $name, - $mode . '_copyright' => $copyright - ); - - switch ($mode) - { - case 'style': - - $sql_ary += array( - 'template_id' => (int) $template_id, - 'theme_id' => (int) $theme_id, - 'style_active' => (int) $style_active, - ); - break; - - case 'theme': - break; - - case 'template': - break; - } - - if (sizeof($sql_ary)) - { - $sql = "UPDATE $sql_from - SET " . $db->sql_build_array('UPDATE', $sql_ary) . " - WHERE {$mode}_id = $style_id"; - $db->sql_query($sql); - - // Making this the default style? - if ($mode == 'style' && $style_default) - { - set_config('default_style', $style_id); - } - } - - $cache->destroy('sql', STYLES_TABLE); - - add_log('admin', 'LOG_' . $l_type . '_EDIT_DETAILS', $name); - if (sizeof($error)) - { - trigger_error(implode('
    ', $error) . adm_back_link($this->u_action), E_USER_WARNING); - } - else - { - trigger_error($user->lang[$l_type . '_DETAILS_UPDATED'] . adm_back_link($this->u_action)); - } - } - - if ($mode == 'style') - { - foreach ($element_ary as $element => $table) - { - $sql = "SELECT {$element}_id, {$element}_name - FROM $table - ORDER BY {$element}_id ASC"; - $result = $db->sql_query($sql); - - ${$element . '_options'} = ''; - while ($row = $db->sql_fetchrow($result)) - { - $selected = ($row[$element . '_id'] == $style_row[$element . '_id']) ? ' selected="selected"' : ''; - ${$element . '_options'} .= ''; - } - $db->sql_freeresult($result); - } - } - - if ($mode == 'template') - { - $super = array(); - if (isset($style_row[$mode . '_inherits_id']) && $style_row['template_inherits_id']) - { - $super = $this->get_super($mode, $style_row['template_id']); - } - } - - $this->page_title = 'EDIT_DETAILS_' . $l_type; - - $template->assign_vars(array( - 'S_DETAILS' => true, - 'S_ERROR_MSG' => (sizeof($error)) ? true : false, - 'S_STYLE' => ($mode == 'style') ? true : false, - 'S_TEMPLATE' => ($mode == 'template') ? true : false, - 'S_THEME' => ($mode == 'theme') ? true : false, - 'S_STYLE_ACTIVE' => (isset($style_row['style_active'])) ? $style_row['style_active'] : 0, - 'S_STYLE_DEFAULT' => (isset($style_row['style_default'])) ? $style_row['style_default'] : 0, - 'S_SUPERTEMPLATE' => (isset($style_row[$mode . '_inherits_id']) && $style_row[$mode . '_inherits_id']) ? $super['template_name'] : 0, - - 'S_TEMPLATE_OPTIONS' => ($mode == 'style') ? $template_options : '', - 'S_THEME_OPTIONS' => ($mode == 'style') ? $theme_options : '', - - 'U_ACTION' => $this->u_action . '&action=details&id=' . $style_id, - 'U_BACK' => $this->u_action, - - 'L_TITLE' => $user->lang[$this->page_title], - 'L_EXPLAIN' => $user->lang[$this->page_title . '_EXPLAIN'], - 'L_NAME' => $user->lang[$l_type . '_NAME'], - - 'ERROR_MSG' => (sizeof($error)) ? implode('
    ', $error) : '', - 'NAME' => $style_row[$mode . '_name'], - 'COPYRIGHT' => $style_row[$mode . '_copyright'], - ) - ); - } - - /** - * Load css file contents - */ - function load_css_file($path, $filename) - { - global $phpbb_root_path; - - $file = "{$phpbb_root_path}styles/$path/theme/$filename"; - - if (file_exists($file) && ($content = file_get_contents($file))) - { - $content = trim($content); - } - else - { - $content = ''; - } - if (defined('DEBUG')) - { - $content = "/* BEGIN @include $filename */ \n $content \n /* END @include $filename */ \n"; - } - - return $content; - } - - /** - * Returns a string containing the value that should be used for the theme_data column in the theme database table. - * Includes contents of files loaded via @import - * - * @param array $theme_row is an associative array containing the theme's current database entry - * @param mixed $stylesheet can either be the new content for the stylesheet or false to load from the standard file - * @param string $root_path should only be used in case you want to use a different root path than "{$phpbb_root_path}styles/{$theme_row['theme_path']}" - * - * @return string Stylesheet data for theme_data column in the theme table - */ - function db_theme_data($theme_row, $stylesheet = false, $root_path = '') - { - global $phpbb_root_path; - - if (!$root_path) - { - $root_path = $phpbb_root_path . 'styles/' . $theme_row['theme_path']; - } - - if (!$stylesheet) - { - $stylesheet = ''; - if (file_exists($root_path . '/theme/stylesheet.css')) - { - $stylesheet = file_get_contents($root_path . '/theme/stylesheet.css'); - } - } - - // Match CSS imports - $matches = array(); - preg_match_all('/@import url\((["\'])(.*)\1\);/i', $stylesheet, $matches); - - // remove commented stylesheets (very simple parser, allows only whitespace - // around an @import statement) - preg_match_all('#/\*\s*@import url\((["\'])(.*)\1\);\s\*/#i', $stylesheet, $commented); - $matches[2] = array_diff($matches[2], $commented[2]); - - if (sizeof($matches)) - { - foreach ($matches[0] as $idx => $match) - { - if (isset($matches[2][$idx])) - { - $stylesheet = str_replace($match, acp_styles::load_css_file($theme_row['theme_path'], $matches[2][$idx]), $stylesheet); - } - } - } - - // adjust paths - return str_replace('./', 'styles/' . $theme_row['theme_path'] . '/theme/', $stylesheet); - } - - /** - * Returns an array containing all template filenames for one template that are currently cached. - * - * @param string $template_path contains the name of the template's folder in /styles/ - * - * @return array of filenames that exist in /styles/$template_path/template/ (without extension!) - */ - function template_cache_filelist($template_path) - { - global $phpbb_root_path, $phpEx, $user; - - $cache_prefix = 'tpl_' . str_replace('_', '-', $template_path); - - if (!($dp = @opendir("{$phpbb_root_path}cache"))) - { - trigger_error($user->lang['TEMPLATE_ERR_CACHE_READ'] . adm_back_link($this->u_action), E_USER_WARNING); - } - - $file_ary = array(); - while ($file = readdir($dp)) - { - if ($file[0] == '.') - { - continue; - } - - if (is_file($phpbb_root_path . 'cache/' . $file) && (strpos($file, $cache_prefix) === 0)) - { - $file_ary[] = str_replace('.', '/', preg_replace('#^' . preg_quote($cache_prefix, '#') . '_(.*?)\.html\.' . $phpEx . '$#i', '\1', $file)); - } - } - closedir($dp); - - return $file_ary; - } - - /** - * Destroys cached versions of template files - * - * @param array $template_row contains the template's row in the STYLES_TEMPLATE_TABLE database table - * @param mixed $file_ary is optional and may contain an array of template file names which should be refreshed in the cache. - * The file names should be the original template file names and not the cache file names. - */ - function clear_template_cache($template_row, $file_ary = false) - { - global $phpbb_root_path, $phpEx, $user; - - $cache_prefix = 'tpl_' . str_replace('_', '-', $template_row['template_path']); - - if (!$file_ary || !is_array($file_ary)) - { - $file_ary = $this->template_cache_filelist($template_row['template_path']); - $log_file_list = $user->lang['ALL_FILES']; - } - else - { - $log_file_list = implode(', ', $file_ary); - } - - foreach ($file_ary as $file) - { - $file = str_replace('/', '.', $file); - - $file = "{$phpbb_root_path}cache/{$cache_prefix}_$file.html.$phpEx"; - if (file_exists($file) && is_file($file)) - { - @unlink($file); - } - } - unset($file_ary); - - add_log('admin', 'LOG_TEMPLATE_CACHE_CLEARED', $template_row['template_name'], $log_file_list); - } - - /** - * Install Style/Template/Theme - */ - function install($mode) - { - global $phpbb_root_path, $phpEx, $config, $db, $cache, $user, $template; - - $l_type = strtoupper($mode); - - $error = $installcfg = $style_row = array(); - $root_path = $cfg_file = ''; - $element_ary = array('template' => STYLES_TEMPLATE_TABLE, 'theme' => STYLES_THEME_TABLE); - - $install_path = request_var('path', ''); - $update = (isset($_POST['update'])) ? true : false; - - // Installing, obtain cfg file contents - if ($install_path) - { - $root_path = $phpbb_root_path . 'styles/' . $install_path . '/'; - $cfg_file = ($mode == 'style') ? "$root_path$mode.cfg" : "$root_path$mode/$mode.cfg"; - - if (!file_exists($cfg_file)) - { - $error[] = $user->lang[$l_type . '_ERR_NOT_' . $l_type]; - } - else - { - $installcfg = parse_cfg_file($cfg_file); - } - } - - // Installing - if (sizeof($installcfg)) - { - $name = $installcfg['name']; - $copyright = $installcfg['copyright']; - $version = $installcfg['version']; - - $style_row = array( - $mode . '_id' => 0, - $mode . '_name' => '', - $mode . '_copyright' => '' - ); - - switch ($mode) - { - case 'style': - - $style_row = array( - 'style_id' => 0, - 'style_name' => $installcfg['name'], - 'style_copyright' => $installcfg['copyright'] - ); - - $reqd_template = (isset($installcfg['required_template'])) ? $installcfg['required_template'] : false; - $reqd_theme = (isset($installcfg['required_theme'])) ? $installcfg['required_theme'] : false; - - // Check to see if each element is already installed, if it is grab the id - foreach ($element_ary as $element => $table) - { - $style_row = array_merge($style_row, array( - $element . '_id' => 0, - $element . '_name' => '', - $element . '_copyright' => '') - ); - - $this->test_installed($element, $error, (${'reqd_' . $element}) ? $phpbb_root_path . 'styles/' . $reqd_template . '/' : $root_path, ${'reqd_' . $element}, $style_row[$element . '_id'], $style_row[$element . '_name'], $style_row[$element . '_copyright']); - - if (!$style_row[$element . '_name']) - { - $style_row[$element . '_name'] = $reqd_template; - } - - // Merge other information to installcfg... if present - $cfg_file = $phpbb_root_path . 'styles/' . $install_path . '/' . $element . '/' . $element . '.cfg'; - - if (file_exists($cfg_file)) - { - $cfg_contents = parse_cfg_file($cfg_file); - - // Merge only specific things. We may need them later. - foreach (array('inherit_from') as $key) - { - if (!empty($cfg_contents[$key]) && !isset($installcfg[$key])) - { - $installcfg[$key] = $cfg_contents[$key]; - } - } - } - } - - break; - - case 'template': - $this->test_installed('template', $error, $root_path, false, $style_row['template_id'], $style_row['template_name'], $style_row['template_copyright']); - break; - - case 'theme': - $this->test_installed('theme', $error, $root_path, false, $style_row['theme_id'], $style_row['theme_name'], $style_row['theme_copyright']); - break; - } - } - else - { - trigger_error($user->lang['NO_' . $l_type] . adm_back_link($this->u_action), E_USER_WARNING); - } - - $style_row['style_active'] = request_var('style_active', 1); - $style_row['style_default'] = request_var('style_default', 0); - - // User has submitted form and no errors have occurred - if ($update && !sizeof($error)) - { - if ($mode == 'style') - { - foreach ($element_ary as $element => $table) - { - ${$element . '_root_path'} = (${'reqd_' . $element}) ? $phpbb_root_path . 'styles/' . ${'reqd_' . $element} . '/' : false; - ${$element . '_path'} = (${'reqd_' . $element}) ? ${'reqd_' . $element} : false; - } - $this->install_style($error, 'install', $root_path, $style_row['style_id'], $style_row['style_name'], $install_path, $style_row['style_copyright'], $style_row['style_active'], $style_row['style_default'], $style_row, $template_root_path, $template_path, $theme_root_path, $theme_path); - } - else - { - $this->install_element($mode, $error, 'install', $root_path, $style_row[$mode . '_id'], $style_row[$mode . '_name'], $install_path, $style_row[$mode . '_copyright']); - } - - if (!sizeof($error)) - { - $cache->destroy('sql', STYLES_TABLE); - - trigger_error($user->lang[$l_type . '_ADDED'] . adm_back_link($this->u_action)); - } - } - - $this->page_title = 'INSTALL_' . $l_type; - - $template->assign_vars(array( - 'S_DETAILS' => true, - 'S_INSTALL' => true, - 'S_ERROR_MSG' => (sizeof($error)) ? true : false, - 'S_LOCATION' => (isset($installcfg['inherit_from']) && $installcfg['inherit_from']) ? false : true, - 'S_STYLE' => ($mode == 'style') ? true : false, - 'S_TEMPLATE' => ($mode == 'template') ? true : false, - 'S_SUPERTEMPLATE' => (isset($installcfg['inherit_from'])) ? $installcfg['inherit_from'] : '', - 'S_THEME' => ($mode == 'theme') ? true : false, - - 'S_STYLE_ACTIVE' => (isset($style_row['style_active'])) ? $style_row['style_active'] : 0, - 'S_STYLE_DEFAULT' => (isset($style_row['style_default'])) ? $style_row['style_default'] : 0, - - 'U_ACTION' => $this->u_action . "&action=install&path=" . urlencode($install_path), - 'U_BACK' => $this->u_action, - - 'L_TITLE' => $user->lang[$this->page_title], - 'L_EXPLAIN' => $user->lang[$this->page_title . '_EXPLAIN'], - 'L_NAME' => $user->lang[$l_type . '_NAME'], - - 'ERROR_MSG' => (sizeof($error)) ? implode('
    ', $error) : '', - 'NAME' => $style_row[$mode . '_name'], - 'COPYRIGHT' => $style_row[$mode . '_copyright'], - 'TEMPLATE_NAME' => ($mode == 'style') ? $style_row['template_name'] : '', - 'THEME_NAME' => ($mode == 'style') ? $style_row['theme_name'] : '') - ); - } - - /** - * Add new style - */ - function add($mode) - { - global $phpbb_root_path, $phpEx, $config, $db, $cache, $user, $template; - - $l_type = strtoupper($mode); - $element_ary = array('template' => STYLES_TEMPLATE_TABLE, 'theme' => STYLES_THEME_TABLE); - $error = array(); - - $style_row = array( - $mode . '_name' => utf8_normalize_nfc(request_var('name', '', true)), - $mode . '_copyright' => utf8_normalize_nfc(request_var('copyright', '', true)), - 'template_id' => 0, - 'theme_id' => 0, - 'style_active' => request_var('style_active', 1), - 'style_default' => request_var('style_default', 0), - ); - - $basis = request_var('basis', 0); - $update = (isset($_POST['update'])) ? true : false; - - if ($basis) - { - switch ($mode) - { - case 'style': - $sql_select = 'template_id, theme_id'; - $sql_from = STYLES_TABLE; - break; - - case 'template': - $sql_select = 'template_id'; - $sql_from = STYLES_TEMPLATE_TABLE; - break; - - case 'theme': - $sql_select = 'theme_id'; - $sql_from = STYLES_THEME_TABLE; - break; - } - - $sql = "SELECT $sql_select - FROM $sql_from - WHERE {$mode}_id = $basis"; - $result = $db->sql_query($sql); - $row = $db->sql_fetchrow($result); - $db->sql_freeresult($result); - - if (!$row) - { - $error[] = $user->lang['NO_' . $l_type]; - } - - if (!sizeof($error)) - { - $style_row['template_id'] = (isset($row['template_id'])) ? $row['template_id'] : $style_row['template_id']; - $style_row['theme_id'] = (isset($row['theme_id'])) ? $row['theme_id'] : $style_row['theme_id']; - } - } - - if ($update) - { - $style_row['template_id'] = request_var('template_id', $style_row['template_id']); - $style_row['theme_id'] = request_var('theme_id', $style_row['theme_id']); - - if ($mode == 'style' && (!$style_row['template_id'] || !$style_row['theme_id'])) - { - $error[] = $user->lang['STYLE_ERR_NO_IDS']; - } - } - - // User has submitted form and no errors have occurred - if ($update && !sizeof($error)) - { - if ($mode == 'style') - { - $style_row['style_id'] = 0; - - $this->install_style($error, 'add', '', $style_row['style_id'], $style_row['style_name'], '', $style_row['style_copyright'], $style_row['style_active'], $style_row['style_default'], $style_row); - } - - if (!sizeof($error)) - { - $cache->destroy('sql', STYLES_TABLE); - - trigger_error($user->lang[$l_type . '_ADDED'] . adm_back_link($this->u_action)); - } - } - - if ($mode == 'style') - { - foreach ($element_ary as $element => $table) - { - $sql = "SELECT {$element}_id, {$element}_name - FROM $table - ORDER BY {$element}_id ASC"; - $result = $db->sql_query($sql); - - ${$element . '_options'} = ''; - while ($row = $db->sql_fetchrow($result)) - { - $selected = ($row[$element . '_id'] == $style_row[$element . '_id']) ? ' selected="selected"' : ''; - ${$element . '_options'} .= ''; - } - $db->sql_freeresult($result); - } - } - - $this->page_title = 'ADD_' . $l_type; - - $template->assign_vars(array( - 'S_DETAILS' => true, - 'S_ADD' => true, - 'S_ERROR_MSG' => (sizeof($error)) ? true : false, - 'S_STYLE' => ($mode == 'style') ? true : false, - 'S_TEMPLATE' => ($mode == 'template') ? true : false, - 'S_THEME' => ($mode == 'theme') ? true : false, - 'S_BASIS' => ($basis) ? true : false, - - 'S_STYLE_ACTIVE' => (isset($style_row['style_active'])) ? $style_row['style_active'] : 0, - 'S_STYLE_DEFAULT' => (isset($style_row['style_default'])) ? $style_row['style_default'] : 0, - 'S_TEMPLATE_OPTIONS' => ($mode == 'style') ? $template_options : '', - 'S_THEME_OPTIONS' => ($mode == 'style') ? $theme_options : '', - - 'U_ACTION' => $this->u_action . '&action=add&basis=' . $basis, - 'U_BACK' => $this->u_action, - - 'L_TITLE' => $user->lang[$this->page_title], - 'L_EXPLAIN' => $user->lang[$this->page_title . '_EXPLAIN'], - 'L_NAME' => $user->lang[$l_type . '_NAME'], - - 'ERROR_MSG' => (sizeof($error)) ? implode('
    ', $error) : '', - 'NAME' => $style_row[$mode . '_name'], - 'COPYRIGHT' => $style_row[$mode . '_copyright']) - ); - - } - - /** - - $reqd_template = (isset($installcfg['required_template'])) ? $installcfg['required_template'] : false; - $reqd_theme = (isset($installcfg['required_theme'])) ? $installcfg['required_theme'] : false; - - // Check to see if each element is already installed, if it is grab the id - foreach ($element_ary as $element => $table) - { - $style_row = array_merge($style_row, array( - $element . '_id' => 0, - $element . '_name' => '', - $element . '_copyright' => '') - ); - - $this->test_installed($element, $error, $root_path, ${'reqd_' . $element}, $style_row[$element . '_id'], $style_row[$element . '_name'], $style_row[$element . '_copyright']); - * Is this element installed? If not, grab its cfg details - */ - function test_installed($element, &$error, $root_path, $reqd_name, &$id, &$name, &$copyright) - { - global $db, $user; - - switch ($element) - { - case 'template': - $sql_from = STYLES_TEMPLATE_TABLE; - break; - - case 'theme': - $sql_from = STYLES_THEME_TABLE; - break; - } - - $l_element = strtoupper($element); - - $chk_name = ($reqd_name !== false) ? $reqd_name : $name; - - $sql = "SELECT {$element}_id, {$element}_name - FROM $sql_from - WHERE {$element}_name = '" . $db->sql_escape($chk_name) . "'"; - $result = $db->sql_query($sql); - - if ($row = $db->sql_fetchrow($result)) - { - $name = $row[$element . '_name']; - $id = $row[$element . '_id']; - } - else - { - if (!($cfg = @file("$root_path$element/$element.cfg"))) - { - $error[] = sprintf($user->lang['REQUIRES_' . $l_element], $reqd_name); - return false; - } - - $cfg = parse_cfg_file("$root_path$element/$element.cfg", $cfg); - - $name = $cfg['name']; - $copyright = $cfg['copyright']; - $id = 0; - - unset($cfg); - } - $db->sql_freeresult($result); - } - - /** - * Install/Add style - */ - function install_style(&$error, $action, $root_path, &$id, $name, $path, $copyright, $active, $default, &$style_row, $template_root_path = false, $template_path = false, $theme_root_path = false, $theme_path = false) - { - global $config, $db, $user; - - $element_ary = array('template', 'theme'); - - if (!$name) - { - $error[] = $user->lang['STYLE_ERR_STYLE_NAME']; - } - - // Check length settings - if (utf8_strlen($name) > 30) - { - $error[] = $user->lang['STYLE_ERR_NAME_LONG']; - } - - if (utf8_strlen($copyright) > 60) - { - $error[] = $user->lang['STYLE_ERR_COPY_LONG']; - } - - // Check if the name already exist - $sql = 'SELECT style_id - FROM ' . STYLES_TABLE . " - WHERE style_name = '" . $db->sql_escape($name) . "'"; - $result = $db->sql_query($sql); - $row = $db->sql_fetchrow($result); - $db->sql_freeresult($result); - - if ($row) - { - $error[] = $user->lang['STYLE_ERR_NAME_EXIST']; - } - - if (sizeof($error)) - { - return false; - } - - foreach ($element_ary as $element) - { - // Zero id value ... need to install element ... run usual checks - // and do the install if necessary - if (!$style_row[$element . '_id']) - { - $this->install_element($element, $error, $action, (${$element . '_root_path'}) ? ${$element . '_root_path'} : $root_path, $style_row[$element . '_id'], $style_row[$element . '_name'], (${$element . '_path'}) ? ${$element . '_path'} : $path, $style_row[$element . '_copyright']); - } - } - - if (!$style_row['template_id'] || !$style_row['theme_id']) - { - $error[] = $user->lang['STYLE_ERR_NO_IDS']; - } - - if (sizeof($error)) - { - return false; - } - - $db->sql_transaction('begin'); - - $sql_ary = array( - 'style_name' => $name, - 'style_copyright' => $copyright, - 'style_active' => (int) $active, - 'template_id' => (int) $style_row['template_id'], - 'theme_id' => (int) $style_row['theme_id'], - ); - - $sql = 'INSERT INTO ' . STYLES_TABLE . ' - ' . $db->sql_build_array('INSERT', $sql_ary); - $db->sql_query($sql); - - $id = $db->sql_nextid(); - - if ($default) - { - $sql = 'UPDATE ' . USERS_TABLE . " - SET user_style = $id - WHERE user_style = " . $config['default_style']; - $db->sql_query($sql); - - set_config('default_style', $id); - } - - $db->sql_transaction('commit'); - - add_log('admin', 'LOG_STYLE_ADD', $name); - } - - /** - * Install/add an element, doing various checks as we go - */ - function install_element($mode, &$error, $action, $root_path, &$id, $name, $path, $copyright) - { - global $phpbb_root_path, $db, $user; - - // we parse the cfg here (again) - $cfg_data = parse_cfg_file("$root_path$mode/$mode.cfg"); - - switch ($mode) - { - case 'template': - $sql_from = STYLES_TEMPLATE_TABLE; - break; - - case 'theme': - $sql_from = STYLES_THEME_TABLE; - break; - } - - $l_type = strtoupper($mode); - - if (!$name) - { - $error[] = $user->lang[$l_type . '_ERR_STYLE_NAME']; - } - - // Check length settings - if (utf8_strlen($name) > 30) - { - $error[] = $user->lang[$l_type . '_ERR_NAME_LONG']; - } - - if (utf8_strlen($copyright) > 60) - { - $error[] = $user->lang[$l_type . '_ERR_COPY_LONG']; - } - - // Check if the name already exist - $sql = "SELECT {$mode}_id - FROM $sql_from - WHERE {$mode}_name = '" . $db->sql_escape($name) . "'"; - $result = $db->sql_query($sql); - $row = $db->sql_fetchrow($result); - $db->sql_freeresult($result); - - if ($row) - { - // If it exist, we just use the style on installation - if ($action == 'install') - { - $id = $row[$mode . '_id']; - return false; - } - - $error[] = $user->lang[$l_type . '_ERR_NAME_EXIST']; - } - - if (isset($cfg_data['inherit_from']) && $cfg_data['inherit_from']) - { - if ($mode === 'template') - { - $select_bf = ', bbcode_bitfield'; - } - else - { - $select_bf = ''; - } - - $sql = "SELECT {$mode}_id, {$mode}_name, {$mode}_path $select_bf - FROM $sql_from - WHERE {$mode}_name = '" . $db->sql_escape($cfg_data['inherit_from']) . "' - AND {$mode}_inherits_id = 0"; - $result = $db->sql_query($sql); - $row = $db->sql_fetchrow($result); - $db->sql_freeresult($result); - if (!$row) - { - $error[] = sprintf($user->lang[$l_type . '_ERR_REQUIRED_OR_INCOMPLETE'], $cfg_data['inherit_from']); - } - else - { - $inherit_id = $row["{$mode}_id"]; - $inherit_path = $row["{$mode}_path"]; - $inherit_bf = ($mode === 'template') ? $row["bbcode_bitfield"] : false; - } - } - else - { - $inherit_id = 0; - $inherit_path = ''; - $inherit_bf = false; - } - - if (sizeof($error)) - { - return false; - } - - $sql_ary = array( - $mode . '_name' => $name, - $mode . '_copyright' => $copyright, - $mode . '_path' => $path, - ); - - switch ($mode) - { - case 'template': - // We check if the template author defined a different bitfield - if (!empty($cfg_data['template_bitfield'])) - { - $sql_ary['bbcode_bitfield'] = $cfg_data['template_bitfield']; - } - else if ($inherit_bf) - { - $sql_ary['bbcode_bitfield'] = $inherit_bf; - } - else - { - $sql_ary['bbcode_bitfield'] = $this->template_bitfield; - } - - if (isset($cfg_data['inherit_from']) && $cfg_data['inherit_from']) - { - $sql_ary += array( - 'template_inherits_id' => $inherit_id, - 'template_inherit_path' => $inherit_path, - ); - } - break; - - case 'theme': - break; - } - - $db->sql_transaction('begin'); - - $sql = "INSERT INTO $sql_from - " . $db->sql_build_array('INSERT', $sql_ary); - $db->sql_query($sql); - - $id = $db->sql_nextid(); - - $db->sql_transaction('commit'); - - add_log('admin', 'LOG_' . $l_type . '_ADD_FS', $name); - } - - /** - * Checks downwards dependencies - * - * @access public - * @param string $mode The element type to check - only template is supported - * @param int $id The template id - * @returns false if no component inherits, array with name, path and id for each subtemplate otherwise - */ - function check_inheritance($mode, $id) - { - global $db; - - $l_type = strtoupper($mode); - - switch ($mode) - { - case 'template': - $sql_from = STYLES_TEMPLATE_TABLE; - break; - - case 'theme': - $sql_from = STYLES_THEME_TABLE; - break; - } - - $sql = "SELECT {$mode}_id, {$mode}_name, {$mode}_path - FROM $sql_from - WHERE {$mode}_inherits_id = " . (int) $id; - $result = $db->sql_query($sql); - - $names = array(); - while ($row = $db->sql_fetchrow($result)) - { - - $names[$row["{$mode}_id"]] = array( - "{$mode}_id" => $row["{$mode}_id"], - "{$mode}_name" => $row["{$mode}_name"], - "{$mode}_path" => $row["{$mode}_path"], - ); - } - $db->sql_freeresult($result); - - if (sizeof($names)) - { - return $names; - } - else - { - return false; - } - } - - /** - * Checks upwards dependencies - * - * @access public - * @param string $mode The element type to check - only template is supported - * @param int $id The template id - * @returns false if the component does not inherit, array with name, path and id otherwise - */ - function get_super($mode, $id) - { - global $db; - - $l_type = strtoupper($mode); - - switch ($mode) - { - case 'template': - $sql_from = STYLES_TEMPLATE_TABLE; - break; - - case 'theme': - $sql_from = STYLES_THEME_TABLE; - break; - } - - $sql = "SELECT {$mode}_inherits_id - FROM $sql_from - WHERE {$mode}_id = " . (int) $id; - $result = $db->sql_query_limit($sql, 1); - - if ($row = $db->sql_fetchrow($result)) - { - $db->sql_freeresult($result); - } - else - { - return false; - } - - $super_id = $row["{$mode}_inherits_id"]; - - $sql = "SELECT {$mode}_id, {$mode}_name, {$mode}_path - FROM $sql_from - WHERE {$mode}_id = " . (int) $super_id; - - $result = $db->sql_query_limit($sql, 1); - if ($row = $db->sql_fetchrow($result)) - { - $db->sql_freeresult($result); - return $row; - } - - return false; - } } diff --git a/phpBB/includes/acp/info/acp_styles.php b/phpBB/includes/acp/info/acp_styles.php index 221371c4cb..3137c4781b 100644 --- a/phpBB/includes/acp/info/acp_styles.php +++ b/phpBB/includes/acp/info/acp_styles.php @@ -17,11 +17,11 @@ class acp_styles_info return array( 'filename' => 'acp_styles', 'title' => 'ACP_CAT_STYLES', - 'version' => '1.0.0', + 'version' => '2.0.0', 'modes' => array( 'style' => array('title' => 'ACP_STYLES', 'auth' => 'acl_a_styles', 'cat' => array('ACP_STYLE_MANAGEMENT')), - 'template' => array('title' => 'ACP_TEMPLATES', 'auth' => 'acl_a_styles', 'cat' => array('ACP_STYLE_COMPONENTS')), - 'theme' => array('title' => 'ACP_THEMES', 'auth' => 'acl_a_styles', 'cat' => array('ACP_STYLE_COMPONENTS')), + 'install' => array('title' => 'ACP_STYLES_INSTALL', 'auth' => 'acl_a_styles', 'cat' => array('ACP_STYLE_MANAGEMENT')), + 'cache' => array('title' => 'ACP_STYLES_CACHE', 'auth' => 'acl_a_styles', 'cat' => array('ACP_STYLE_MANAGEMENT')), ), ); } From 39944a08b9ea031dfc156f61ad0d8f4c594882e5 Mon Sep 17 00:00:00 2001 From: Vjacheslav Trushkin Date: Thu, 15 Mar 2012 00:20:11 +0200 Subject: [PATCH 015/114] [feature/merging-style-components] New acp_styles template New acp_styles.html, completely rewritten PHPBB3-10632 --- phpBB/adm/style/acp_styles.html | 500 +++++++++----------------------- 1 file changed, 134 insertions(+), 366 deletions(-) diff --git a/phpBB/adm/style/acp_styles.html b/phpBB/adm/style/acp_styles.html index dc89aa247a..b09cbafc95 100644 --- a/phpBB/adm/style/acp_styles.html +++ b/phpBB/adm/style/acp_styles.html @@ -2,399 +2,167 @@ - + +
    - « {L_BACK} +
    +

    {MESSAGE_TITLE}

    +

    {MESSAGE_TEXT}

    + + + -

    {L_TITLE}

    + {S_HIDDEN_FIELDS} -

    {L_EXPLAIN}

    +
    +   + +
    - +
    + +
    + +

    {L_TITLE}

    + +

    {L_EXPLAIN}

    + +
    +{S_HIDDEN_FIELDS} +{S_FORM_TOKEN} + + +
    - {L_TITLE}
    -
    -
    {NAME}
    +
    +
    -

    {L_REPLACE_EXPLAIN}
    -
    -
    - -
    -
    -

    {L_REPLACE_TEMPLATE_EXPLAIN}
    -
    -
    -
    -

    {L_REPLACE_THEME_EXPLAIN}
    -
    -
    - - -

    - - {S_FORM_TOKEN} -

    -
    -
    - - - - « {L_BACK} - -

    {L_EDIT}

    - -

    {L_EDIT_EXPLAIN}

    - -

    {L_SELECTED}: {SELECTED_TEMPLATE}

    - -
    - - -
    - {L_SELECT} -
    -
    -
    -
    - {S_FORM_TOKEN} -
    - -
    - - - - -
    - -
    - {L_EDITOR} - -
    -
    -
    {TEMPLATE_FILE}
    -
    - -
    -
    -
    -
    - -
    - -
    - {L_SUBMIT} - {S_HIDDEN_FIELDS} - {S_FORM_TOKEN} - -
    -
    - - - - - « {L_BACK} - -

    {L_TEMPLATE_CACHE}

    - -

    {L_TEMPLATE_CACHE_EXPLAIN}

    - -
    -
    - {L_TEMPLATE_CACHE} - - - - - - - - - - - - - - - - - - - - - - - - - - -
    {L_CACHE_FILENAME}{L_CACHE_FILESIZE}{L_CACHE_CACHED}{L_CACHE_MODIFIED}{L_MARK}
    {file.FILENAME_PATH}{file.FILESIZE}{file.CACHED}{file.MODIFIED}
    {L_TEMPLATE_CACHE_EMPTY}
    - -

    - {L_MARK_ALL} :: {L_UNMARK_ALL}
    - {S_FORM_TOKEN} - -

    -
    -
    - - - - « {L_BACK} - -

    {L_TITLE}

    - -

    {L_EXPLAIN}

    - - -
    -

    {L_WARNING}

    -

    {ERROR_MSG}

    -
    - - -
    - -
    - {L_TITLE} -
    -
    -
    {NAME}
    -
    - -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    - -
    -

    {L_DOWNLOAD_STORE_EXPLAIN}
    -
    -
    +
    +
    {STYLE_PATH}
    -
    -
    {FORMAT_BUTTONS}
    -
    - -

    - {S_FORM_TOKEN} - -

    -
    - - -
    - - - -

    {L_TITLE}

    - -

    {L_EXPLAIN}

    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - colspan="2">{uninstalled.NAME}
    {L_COPYRIGHT}: {uninstalled.COPYRIGHT} -
    - - - -
    {L_NAME}{L_STYLE_USED_BY}{L_OPTIONS}{L_ACTIONS}
    {L_INSTALLED}
    {L_INACTIVE_STYLES}
    {installed.NAME} *{installed.STYLE_COUNT} - {installed.S_OPTIONS} - - - {installed.L_STYLE_ACT_DEACT} | - - {installed.S_ACTIONS} - - | {L_PREVIEW} - -
    {L_UNINSTALLED}
    {L_NO_UNINSTALLED}
    {L_INSTALL}
    - - -
    - -
    - {L_CREATE} - {L_CREATE}: {L_FROM} -
    - -
    - - - - - « {L_BACK} - -

    {L_TITLE}

    - -

    {L_EXPLAIN}

    - - -
    -

    {L_WARNING}

    -

    {ERROR_MSG}

    -
    - - -
    - -
    - {L_TITLE} -
    -
    -
    {NAME}
    +
    +
    {STYLE_COPYRIGHT}
    -
    -
    {COPYRIGHT}
    +
    +
    -
    -
    -
    {S_SUPERTEMPLATE}
    +
    +
    +
    - - +
    -
    -
    {TEMPLATE_NAME}
    +
    +
    +
    -
    -
    -
    {THEME_NAME}
    -
    - - -
    - -
    - {L_OPTIONS} -
    -
    -
    -
    -
    - -
    -
    -
    -
    -
    -
    {L_SUBMIT} + {L_BACK} {S_FORM_TOKEN}
    + -
    + + + + + + + + {STYLES_LIST_EXTRA} + + + + + + class="row-inactive"> + + + + + + + + + + + {styles_list.EXTRA} + + + + +
    {L_STYLE_NAME}{L_STYLE_USED_BY}{L_ACTIONS} 
    + + + + + {styles_list.STYLE_NAME} +
    {styles_list.STYLE_COPYRIGHT}
    + + {styles_list.STYLE_NAME} + + +
    {styles_list.COMMENT}
    + + +
    {L_STYLE_PATH} {styles_list.STYLE_PATH_FULL}
    + +
    {styles_list.USERS} + + | + + {styles_list.actions.L_ACTION} + + {styles_list.actions.HTML} + + + + + + +   + + + + +
    + + + +
    + + + +
    + + + +
    + + {extra_links.L_ACTION} + +
    + + + From 3997ffac2a2e6f422dcd5cd5bd076edee6fa91dd Mon Sep 17 00:00:00 2001 From: Vjacheslav Trushkin Date: Thu, 15 Mar 2012 13:13:21 +0200 Subject: [PATCH 016/114] [feature/merging-style-components] Creating style class Creating phpbb_style class, changing template initialization to style initialization PHPBB3-10632 --- phpBB/common.php | 6 +- phpBB/includes/bbcode.php | 9 +- phpBB/includes/functions_messenger.php | 6 +- phpBB/includes/style/style.php | 89 ++++++++++++++++++++ phpBB/install/index.php | 5 +- tests/template/template_inheritance_test.php | 5 +- tests/template/template_test_case.php | 8 +- 7 files changed, 106 insertions(+), 22 deletions(-) create mode 100644 phpBB/includes/style/style.php diff --git a/phpBB/common.php b/phpBB/common.php index a38a986280..dd49b29528 100644 --- a/phpBB/common.php +++ b/phpBB/common.php @@ -120,9 +120,9 @@ set_config_count(null, null, null, $config); // load extensions $phpbb_extension_manager = new phpbb_extension_manager($db, EXT_TABLE, $phpbb_root_path, ".$phpEx", $cache->get_driver()); -$phpbb_style_locator = new phpbb_style_locator(); -$phpbb_style_path_provider = new phpbb_style_extension_path_provider($phpbb_extension_manager, new phpbb_style_path_provider()); -$template = new phpbb_style_template($phpbb_root_path, $phpEx, $config, $user, $phpbb_style_locator, $phpbb_style_path_provider); +// Initialize style +$style = new phpbb_style($phpbb_root_path, $phpEx, $config, $user, $phpbb_extension_manager); +$template = $style->template; // Add own hook handler require($phpbb_root_path . 'includes/hooks/index.' . $phpEx); diff --git a/phpBB/includes/bbcode.php b/phpBB/includes/bbcode.php index 61271545bd..3831cb03ad 100644 --- a/phpBB/includes/bbcode.php +++ b/phpBB/includes/bbcode.php @@ -132,12 +132,11 @@ class bbcode { $this->template_bitfield = new bitfield($user->theme['bbcode_bitfield']); - $template_locator = new phpbb_style_locator(); - $template_path_provider = new phpbb_style_extension_path_provider($phpbb_extension_manager, new phpbb_style_path_provider()); - $template = new phpbb_style_template($phpbb_root_path, $phpEx, $config, $user, $template_locator, $template_path_provider); + $style = new phpbb_style($phpbb_root_path, $phpEx, $config, $user, $phpbb_extension_manager); + $template = $style->template; $template->set_template(); - $template_locator->set_filenames(array('bbcode.html' => 'bbcode.html')); - $this->template_filename = $template_locator->get_source_file_for_handle('bbcode.html'); + $template->set_filenames(array('bbcode.html' => 'bbcode.html')); + $this->template_filename = $style->locator->get_source_file_for_handle('bbcode.html'); } $bbcode_ids = $rowset = $sql = array(); diff --git a/phpBB/includes/functions_messenger.php b/phpBB/includes/functions_messenger.php index 1fb5f15879..4e1ec160af 100644 --- a/phpBB/includes/functions_messenger.php +++ b/phpBB/includes/functions_messenger.php @@ -208,10 +208,9 @@ class messenger // tpl_msg now holds a template object we can use to parse the template file if (!isset($this->tpl_msg[$template_lang . $template_file])) { - $template_locator = new phpbb_style_locator(); - $template_path_provider = new phpbb_style_extension_path_provider($phpbb_extension_manager, new phpbb_style_path_provider()); - $this->tpl_msg[$template_lang . $template_file] = new phpbb_style_template($phpbb_root_path, $phpEx, $config, $user, $template_locator, $template_path_provider); + $this->tpl_msg[$template_lang . $template_file] = new phpbb_style($phpbb_root_path, $phpEx, $config, $user, $phpbb_extension_manager); $tpl = &$this->tpl_msg[$template_lang . $template_file]; + $tpl = $tpl->template; $fallback_template_path = false; @@ -237,6 +236,7 @@ class messenger } $this->tpl_obj = &$this->tpl_msg[$template_lang . $template_file]; + $this->tpl_obj = $this->tpl_obj->template; $this->vars = &$this->tpl_obj->_rootref; $this->tpl_msg = ''; diff --git a/phpBB/includes/style/style.php b/phpBB/includes/style/style.php new file mode 100644 index 0000000000..217a70e237 --- /dev/null +++ b/phpBB/includes/style/style.php @@ -0,0 +1,89 @@ +phpbb_root_path = $phpbb_root_path; + $this->phpEx = $phpEx; + $this->config = $config; + $this->user = $user; + $this->locator = new phpbb_style_locator(); + $this->provider = new phpbb_style_path_provider(); + if ($phpbb_extension_manager !== false) + { + $this->provider = new phpbb_style_extension_path_provider($phpbb_extension_manager, $this->provider); + } + $this->template = new phpbb_style_template($this->phpbb_root_path, $this->phpEx, $this->config, $this->user, $this->locator, $this->provider); + } +} diff --git a/phpBB/install/index.php b/phpBB/install/index.php index 9b0dde1009..7c6dd10d03 100644 --- a/phpBB/install/index.php +++ b/phpBB/install/index.php @@ -201,9 +201,8 @@ $config = new phpbb_config(array( 'load_tplcompile' => '1' )); -$phpbb_style_locator = new phpbb_style_locator(); -$phpbb_style_path_provider = new phpbb_style_path_provider(); -$template = new phpbb_style_template($phpbb_root_path, $phpEx, $config, $user, $phpbb_style_locator, $phpbb_style_path_provider); +$style = new phpbb_style($phpbb_root_path, $phpEx, $config, $user, false); +$template = $style->template; $template->set_ext_dir_prefix('adm/'); $template->set_custom_template('../adm/style', 'admin'); $template->assign_var('T_ASSETS_PATH', '../assets'); diff --git a/tests/template/template_inheritance_test.php b/tests/template/template_inheritance_test.php index e2a2ac2261..2c67b38641 100644 --- a/tests/template/template_inheritance_test.php +++ b/tests/template/template_inheritance_test.php @@ -71,9 +71,8 @@ class phpbb_template_template_inheritance_test extends phpbb_template_template_t $this->template_path = dirname(__FILE__) . '/templates'; $this->parent_template_path = dirname(__FILE__) . '/parent_templates'; - $this->template_locator = new phpbb_style_locator(); - $this->template_provider = new phpbb_style_path_provider(); - $this->template = new phpbb_style_template($phpbb_root_path, $phpEx, $config, $user, $this->template_locator, $this->template_provider); + $this->style = new phpbb_style($phpbb_root_path, $phpEx, $config, $user, false); + $this->template = $this->style->template; $this->template->set_custom_template($this->template_path, 'tests', $this->parent_template_path, 'parent'); } } diff --git a/tests/template/template_test_case.php b/tests/template/template_test_case.php index 8eea11e84f..a0e980621d 100644 --- a/tests/template/template_test_case.php +++ b/tests/template/template_test_case.php @@ -12,10 +12,9 @@ require_once dirname(__FILE__) . '/../mock/extension_manager.php'; class phpbb_template_template_test_case extends phpbb_test_case { + protected $style; protected $template; protected $template_path; - protected $template_locator; - protected $template_provider; // Keep the contents of the cache for debugging? const PRESERVE_CACHE = true; @@ -63,9 +62,8 @@ class phpbb_template_template_test_case extends phpbb_test_case $config = new phpbb_config(array_merge($defaults, $new_config)); $this->template_path = dirname(__FILE__) . '/templates'; - $this->template_locator = new phpbb_style_locator(); - $this->template_provider = new phpbb_style_path_provider(); - $this->template = new phpbb_style_template($phpbb_root_path, $phpEx, $config, $user, $this->template_locator, $this->template_provider); + $this->style = new phpbb_style($phpbb_root_path, $phpEx, $config, $user, false); + $this->template = $this->style->template; $this->template->set_custom_template($this->template_path, 'tests'); } From c83f386c923fdb0e2823e7f742561a44a6f0f6ed Mon Sep 17 00:00:00 2001 From: Vjacheslav Trushkin Date: Thu, 15 Mar 2012 13:41:23 +0200 Subject: [PATCH 017/114] [feature/merging-style-components] Changing $style to $style_id Changing $style to $style_id in user::setup to avoid conflict with new global style variable PHPBB3-10632 --- phpBB/includes/session.php | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/phpBB/includes/session.php b/phpBB/includes/session.php index cd6f17154a..f2956243e2 100644 --- a/phpBB/includes/session.php +++ b/phpBB/includes/session.php @@ -1568,7 +1568,7 @@ class user extends session /** * Setup basic user-specific items (style, language, ...) */ - function setup($lang_set = false, $style = false) + function setup($lang_set = false, $style_id = false) { global $db, $template, $config, $auth, $phpEx, $phpbb_root_path, $cache; @@ -1643,36 +1643,36 @@ class user extends session { global $SID, $_EXTRA_URL; - $style = $style_request; - $SID .= '&style=' . $style; - $_EXTRA_URL = array('style=' . $style); + $style_id = $style_request; + $SID .= '&style=' . $style_id; + $_EXTRA_URL = array('style=' . $style_id); } else { // Set up style - $style = ($style) ? $style : ((!$config['override_user_style']) ? $this->data['user_style'] : $config['default_style']); + $style_id = ($style_id) ? $style_id : ((!$config['override_user_style']) ? $this->data['user_style'] : $config['default_style']); } $sql = 'SELECT * FROM ' . STYLES_TABLE . " s - WHERE s.style_id = $style"; + WHERE s.style_id = $style_id"; $result = $db->sql_query($sql, 3600); $this->theme = $db->sql_fetchrow($result); $db->sql_freeresult($result); // User has wrong style - if (!$this->theme && $style == $this->data['user_style']) + if (!$this->theme && $style_id == $this->data['user_style']) { - $style = $this->data['user_style'] = $config['default_style']; + $style_id = $this->data['user_style'] = $config['default_style']; $sql = 'UPDATE ' . USERS_TABLE . " - SET user_style = $style + SET user_style = $style_id WHERE user_id = {$this->data['user_id']}"; $db->sql_query($sql); $sql = 'SELECT * FROM ' . STYLES_TABLE . " s - WHERE s.style_id = $style"; + WHERE s.style_id = $style_id"; $result = $db->sql_query($sql, 3600); $this->theme = $db->sql_fetchrow($result); $db->sql_freeresult($result); From 8b7c2c3c6516fd4eb606054ca3822d8a7f977282 Mon Sep 17 00:00:00 2001 From: Vjacheslav Trushkin Date: Thu, 15 Mar 2012 16:33:13 +0200 Subject: [PATCH 018/114] [feature/merging-style-components] Renaming style locator Renaming style locator to style resource locator PHPBB3-10632 --- phpBB/includes/style/{locator.php => resource_locator.php} | 2 +- phpBB/includes/style/style.php | 2 +- phpBB/includes/style/template.php | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) rename phpBB/includes/style/{locator.php => resource_locator.php} (99%) diff --git a/phpBB/includes/style/locator.php b/phpBB/includes/style/resource_locator.php similarity index 99% rename from phpBB/includes/style/locator.php rename to phpBB/includes/style/resource_locator.php index 2d0bcce924..f36768fcd3 100644 --- a/phpBB/includes/style/locator.php +++ b/phpBB/includes/style/resource_locator.php @@ -25,7 +25,7 @@ if (!defined('IN_PHPBB')) * * @package phpBB3 */ -class phpbb_style_locator +class phpbb_style_resource_locator { /** * Paths to directories that templates are stored in. diff --git a/phpBB/includes/style/style.php b/phpBB/includes/style/style.php index 217a70e237..b134b4f76f 100644 --- a/phpBB/includes/style/style.php +++ b/phpBB/includes/style/style.php @@ -78,7 +78,7 @@ class phpbb_style $this->phpEx = $phpEx; $this->config = $config; $this->user = $user; - $this->locator = new phpbb_style_locator(); + $this->locator = new phpbb_style_resource_locator(); $this->provider = new phpbb_style_path_provider(); if ($phpbb_extension_manager !== false) { diff --git a/phpBB/includes/style/template.php b/phpBB/includes/style/template.php index 02fa0bd250..076b9e05ea 100644 --- a/phpBB/includes/style/template.php +++ b/phpBB/includes/style/template.php @@ -64,7 +64,7 @@ class phpbb_style_template /** * Template locator - * @var phpbb_style_locator + * @var phpbb_style_resource_locator */ private $locator; @@ -79,10 +79,10 @@ class phpbb_style_template * * @param string $phpbb_root_path phpBB root path * @param user $user current user - * @param phpbb_style_locator $locator template locator + * @param phpbb_style_resource_locator $locator template locator * @param phpbb_style_path_provider $provider template path provider */ - public function __construct($phpbb_root_path, $phpEx, $config, $user, phpbb_style_locator $locator, phpbb_style_path_provider_interface $provider) + public function __construct($phpbb_root_path, $phpEx, $config, $user, phpbb_style_resource_locator $locator, phpbb_style_path_provider_interface $provider) { $this->phpbb_root_path = $phpbb_root_path; $this->phpEx = $phpEx; From c692e0d92da55944414d5f50accefdd96c2e31ee Mon Sep 17 00:00:00 2001 From: Vjacheslav Trushkin Date: Thu, 15 Mar 2012 21:04:27 +0200 Subject: [PATCH 019/114] [feature/merging-style-components] Changing path provider Changing set_templates() to set_style() and removing second parameter, changing get_main_template_path() to get_main_style_path(), removing template_root_for_style(), updating docblocks PHPBB3-10632 --- .../style/extension_path_provider.php | 45 +++++++------- phpBB/includes/style/path_provider.php | 60 +++++-------------- .../style/path_provider_interface.php | 23 +++---- 3 files changed, 45 insertions(+), 83 deletions(-) diff --git a/phpBB/includes/style/extension_path_provider.php b/phpBB/includes/style/extension_path_provider.php index 05dc5661f6..1fb6580ce1 100644 --- a/phpBB/includes/style/extension_path_provider.php +++ b/phpBB/includes/style/extension_path_provider.php @@ -16,26 +16,26 @@ if (!defined('IN_PHPBB')) } /** -* Provides a template locator with core template paths and extension template paths +* Provides a style resource locator with core style paths and extension style paths * -* Finds installed template paths and makes them available to the locator. +* Finds installed style paths and makes them available to the resource locator. * * @package phpBB3 */ class phpbb_style_extension_path_provider extends phpbb_extension_provider implements phpbb_style_path_provider_interface { /** - * Optional prefix for template paths searched within extensions. + * Optional prefix for style paths searched within extensions. * * Empty by default. Relative to the extension directory. As an example, it - * could be adm/ for admin templates. + * could be adm/ for admin style. * * @var string */ protected $ext_dir_prefix = ''; /** - * A provider of paths to be searched for templates + * A provider of paths to be searched for styles * @var phpbb_style_path_provider */ protected $base_path_provider; @@ -54,11 +54,11 @@ class phpbb_style_extension_path_provider extends phpbb_extension_provider imple } /** - * Sets a prefix for template paths searched within extensions. + * Sets a prefix for style paths searched within extensions. * * The prefix is inserted between the extension's path e.g. ext/foo/ and - * the looked up template path, e.g. styles/bar/template/some.html. So it - * should not have a leading slash, but should have a trailing slash. + * the looked up style path, e.g. styles/bar/. So it should not have a + * leading slash, but should have a trailing slash. * * @param string $ext_dir_prefix The prefix including trailing slash * @return null @@ -69,13 +69,13 @@ class phpbb_style_extension_path_provider extends phpbb_extension_provider imple } /** - * Finds template paths using the extension manager + * Finds style paths using the extension manager * - * Locates a path (e.g. styles/prosilver/template/) in all active extensions. - * Then appends the core template paths based in the current working + * Locates a path (e.g. styles/prosilver/) in all active extensions. + * Then appends the core style paths based in the current working * directory. * - * @return array List of template paths + * @return array List of style paths */ public function find() { @@ -102,29 +102,24 @@ class phpbb_style_extension_path_provider extends phpbb_extension_provider imple } /** - * Overwrites the current template names and paths + * Overwrites the current style paths * - * @param array $templates An associative map from template names to paths. - * The first element is the main template. - * If the path is false, it will be generated from - * the supplied name. - * @param string $style_root_path The root directory for styles identified - * by name only. + * @param array $styles An array of style paths. The first element is the main style. * @return null */ - public function set_templates(array $templates, $style_root_path) + public function set_styles(array $styles) { - $this->base_path_provider->set_templates($templates, $style_root_path); + $this->base_path_provider->set_styles($styles); $this->items = null; } /** - * Retrieves the path to the main template passed into set_templates() + * Retrieves the path to the main style passed into set_styles() * - * @return string Main template path + * @return string Main style path */ - public function get_main_template_path() + public function get_main_style_path() { - return $this->base_path_provider->get_main_template_path(); + return $this->base_path_provider->get_main_style_path(); } } diff --git a/phpBB/includes/style/path_provider.php b/phpBB/includes/style/path_provider.php index 649797df41..c229af92ba 100644 --- a/phpBB/includes/style/path_provider.php +++ b/phpBB/includes/style/path_provider.php @@ -16,15 +16,15 @@ if (!defined('IN_PHPBB')) } /** -* Provides a template locator with paths +* Provides a style resource locator with paths * -* Finds installed template paths and makes them available to the locator. +* Finds installed style paths and makes them available to the resource locator. * * @package phpBB3 */ class phpbb_style_path_provider implements IteratorAggregate, phpbb_style_path_provider_interface { - protected $main_template_name = ''; + protected $main_style_name = ''; protected $paths = array(); /** @@ -38,62 +38,34 @@ class phpbb_style_path_provider implements IteratorAggregate, phpbb_style_path_p } /** - * Overwrites the current template names and paths + * Overwrites the current style paths * - * The first element of the passed templates map, is considered the main - * template and can be retrieved through get_main_template_path(). + * The first element of the passed styles map, is considered the main + * style and can be retrieved through get_main_style_path(). * - * @param array $templates An associative map from template names to paths. - * The first element is the main template. - * If the path is false, it will be generated from - * the supplied name. - * @param string $style_root_path The root directory for styles identified - * by name only. + * @param array $styles An array of style paths. The first element is the main style. * @return null */ - public function set_templates(array $templates, $style_root_path) + public function set_styles(array $styles) { - $this->paths = array(); - - foreach ($templates as $name => $path) - { - if (!$path) - { - $path = $style_root_path . $this->template_root_for_style($name); - } - - $this->paths[] = $path; - } - - $this->main_template_path = $this->paths[0]; + $this->paths = $styles; + $this->main_style_path = $this->paths[0]; } /** - * Retrieves the path to the main template passed into set_templates() + * Retrieves the path to the main style passed into set_styles() * - * @return string Main template path + * @return string Main style path */ - public function get_main_template_path() + public function get_main_style_path() { - return $this->main_template_path; + return $this->main_style_path; } /** - * Converts a style name to relative (to board root or extension) path to - * the style's template files. + * Retrieve an iterator over all style paths * - * @param $style_name string Style name - * @return string Path to style template files - */ - private function template_root_for_style($style_name) - { - return 'styles/' . $style_name . '/template'; - } - - /** - * Retrieve an iterator over all template paths - * - * @return ArrayIterator An iterator for the array of template paths + * @return ArrayIterator An iterator for the array of style paths */ public function getIterator() { diff --git a/phpBB/includes/style/path_provider_interface.php b/phpBB/includes/style/path_provider_interface.php index e65c037dcc..7ae94e17f4 100644 --- a/phpBB/includes/style/path_provider_interface.php +++ b/phpBB/includes/style/path_provider_interface.php @@ -16,16 +16,16 @@ if (!defined('IN_PHPBB')) } /** -* Provides a template locator with paths +* Provides a style resource locator with paths * -* Finds installed template paths and makes them available to the locator. +* Finds installed style paths and makes them available to the resource locator. * * @package phpBB3 */ interface phpbb_style_path_provider_interface extends Traversable { /** - * Defines a prefix to use for template paths in extensions + * Defines a prefix to use for style paths in extensions * * @param string $ext_dir_prefix The prefix including trailing slash * @return null @@ -33,22 +33,17 @@ interface phpbb_style_path_provider_interface extends Traversable public function set_ext_dir_prefix($ext_dir_prefix); /** - * Overwrites the current template names and paths + * Overwrites the current style paths * - * @param array $templates An associative map from template names to paths. - * The first element is the main template. - * If the path is false, it will be generated from - * the supplied name. - * @param string $style_root_path The root directory for styles identified - * by name only. + * @param array $styles An array of style paths. The first element is the main style. * @return null */ - public function set_templates(array $templates, $style_root_path); + public function set_styles(array $styles); /** - * Retrieves the path to the main template passed into set_templates() + * Retrieves the path to the main style passed into set_styles() * - * @return string Main template path + * @return string Main style path */ - public function get_main_template_path(); + public function get_main_style_path(); } From 0b2abe5250ebe6c75473a8d9f9be2aeb13855565 Mon Sep 17 00:00:00 2001 From: Vjacheslav Trushkin Date: Thu, 15 Mar 2012 21:06:24 +0200 Subject: [PATCH 020/114] [feature/merging-style-components] Changing resource locator Changing "template" to "style" in all functions that deal with styles, changing error messages, updating docblocks PHPBB3-10632 --- phpBB/includes/style/resource_locator.php | 67 ++++++++++++++--------- 1 file changed, 40 insertions(+), 27 deletions(-) diff --git a/phpBB/includes/style/resource_locator.php b/phpBB/includes/style/resource_locator.php index f36768fcd3..af261534c3 100644 --- a/phpBB/includes/style/resource_locator.php +++ b/phpBB/includes/style/resource_locator.php @@ -17,28 +17,41 @@ if (!defined('IN_PHPBB')) /** -* Template locator. Maintains mapping from template handles to source paths. +* Style resource locator. +* Maintains mapping from template handles to source template file paths. +* Locates style files: resources (such as .js and .css files) and templates. * -* Template locator is aware of template inheritance, and can return actual -* filesystem paths (i.e., the "primary" template or the "parent" template) +* Style resource locator is aware of styles tree, and can return actual +* filesystem paths (i.e., the "child" style or the "parent" styles) * depending on what files exist. * +* Root paths stored in locator are paths to style directories. Templates are +* stored in subdirectory that $template_path points to. +* * @package phpBB3 */ class phpbb_style_resource_locator { /** - * Paths to directories that templates are stored in. + * Paths to style directories. * @var array */ private $roots = array(); /** - * Index of the main template in the roots array + * Index of the main style in the roots array. * @var int */ private $main_root_id = 0; + /** + * Location of templates directory within style directories. + * Must have trailing slash. Empty if templates are stored in root + * style directory, such as admin control panel templates. + * @var string + */ + public $template_path = 'template/'; + /** * Map from root index to handles to source template file paths. * Normally it only contains paths for handles that are used @@ -57,34 +70,34 @@ class phpbb_style_resource_locator private $filenames = array(); /** - * Set main template location (must have been added through set_paths first). + * Set main style location (must have been added through set_paths first). * - * @param string $template_path Path to template directory + * @param string $style_path Path to style directory * @return null */ - public function set_main_template($template) + public function set_main_style($style_path) { - $this->main_root_id = array_search($template, $this->roots, true); + $this->main_root_id = array_search($style_path, $this->roots, true); } /** - * Sets the list of template paths + * Sets the list of style paths * - * These paths will be searched for template files in the provided order. + * These paths will be searched for style files in the provided order. * Paths may be outside of phpBB, but templates loaded from these paths * will still be cached. * - * @param array $template_paths An array of paths to template directories + * @param array $style_paths An array of paths to style directories * @return null */ - public function set_paths($template_paths) + public function set_paths($style_paths) { $this->roots = array(); $this->files = array(); $this->filenames = array(); $this->main_root_id = 0; - foreach ($template_paths as $path) + foreach ($style_paths as $path) { // Make sure $path has no ending slash if (substr($path, -1) === '/') @@ -107,14 +120,14 @@ class phpbb_style_resource_locator { if (empty($filename)) { - trigger_error("template locator: set_filenames: Empty filename specified for $handle", E_USER_ERROR); + trigger_error("style resource locator: set_filenames: Empty filename specified for $handle", E_USER_ERROR); } $this->filename[$handle] = $filename; foreach ($this->roots as $root_index => $root) { - $this->files[$root_index][$handle] = $root . '/' . $filename; + $this->files[$root_index][$handle] = $root . '/' . $this->template_path . $filename; } } } @@ -133,37 +146,37 @@ class phpbb_style_resource_locator { if (!isset($this->filename[$handle])) { - trigger_error("template locator: get_filename_for_handle: No file specified for handle $handle", E_USER_ERROR); + trigger_error("style resource locator: get_filename_for_handle: No file specified for handle $handle", E_USER_ERROR); } return $this->filename[$handle]; } /** * Determines the source file path for a template handle without - * regard for template inheritance. + * regard for styles tree. * - * This function returns the path in "primary" template directory + * This function returns the path in "primary" style directory * corresponding to the given template handle. That path may or * may not actually exist on the filesystem. Because this function * does not perform stat calls to determine whether the path it * returns actually exists, it is faster than get_source_file_for_handle. * * Use get_source_file_for_handle to obtain the actual path that is - * guaranteed to exist (which might come from the parent/fallback - * template directory if template inheritance is used). + * guaranteed to exist (which might come from the parent style + * directory if primary style has parent styles). * * This function will trigger an error if the handle was never * associated with a template file via set_filenames. * * @param $handle string Template handle - * @return string Path to source file path in primary template directory + * @return string Path to source file path in primary style directory */ public function get_virtual_source_file_for_handle($handle) { // If we don't have a file assigned to this handle, die. if (!isset($this->files[$this->main_root_id][$handle])) { - trigger_error("template locator: No file specified for handle $handle", E_USER_ERROR); + trigger_error("style resource locator: No file specified for handle $handle", E_USER_ERROR); } $source_file = $this->files[$this->main_root_id][$handle]; @@ -172,7 +185,7 @@ class phpbb_style_resource_locator /** * Determines the source file path for a template handle, accounting - * for template inheritance and verifying that the path exists. + * for styles tree and verifying that the path exists. * * This function returns the actual path that may be compiled for * the specified template handle. It will trigger an error if @@ -181,7 +194,7 @@ class phpbb_style_resource_locator * filesystem. * * Use get_virtual_source_file_for_handle to just resolve a template - * handle to a path without any filesystem or inheritance checks. + * handle to a path without any filesystem or styles tree checks. * * @param string $handle Template handle (i.e. "friendly" template name) * @return string Source file path @@ -191,7 +204,7 @@ class phpbb_style_resource_locator // If we don't have a file assigned to this handle, die. if (!isset($this->files[$this->main_root_id][$handle])) { - trigger_error("template locator: No file specified for handle $handle", E_USER_ERROR); + trigger_error("style resource locator: No file specified for handle $handle", E_USER_ERROR); } // locate a source file that exists @@ -206,7 +219,7 @@ class phpbb_style_resource_locator // search failed if (!file_exists($source_file)) { - trigger_error("template locator: File for handle $handle does not exist. Could not find: $tried", E_USER_ERROR); + trigger_error("style resource locator: File for handle $handle does not exist. Could not find: $tried", E_USER_ERROR); } return $source_file; From 5b149e93b91ab1cb09e2e9c8c3c00312973c1c5e Mon Sep 17 00:00:00 2001 From: Vjacheslav Trushkin Date: Thu, 15 Mar 2012 21:08:41 +0200 Subject: [PATCH 021/114] [feature/merging-style-components] Changing template class Removing functions that are now handled by phpbb_style class, allowing to write $context, updating docblocks PHPBB3-10632 --- phpBB/includes/style/template.php | 76 +++++-------------------------- 1 file changed, 11 insertions(+), 65 deletions(-) diff --git a/phpBB/includes/style/template.php b/phpBB/includes/style/template.php index 076b9e05ea..21a2e821dd 100644 --- a/phpBB/includes/style/template.php +++ b/phpBB/includes/style/template.php @@ -35,7 +35,7 @@ class phpbb_style_template * @var phpbb_style_template_context Template context. * Stores template data used during template rendering. */ - private $context; + public $context; /** * @var string Path of the cache directory for the template @@ -63,7 +63,7 @@ class phpbb_style_template private $user; /** - * Template locator + * Style resource locator * @var phpbb_style_resource_locator */ private $locator; @@ -74,13 +74,19 @@ class phpbb_style_template */ private $provider; + /** + * Location of templates directory within style directories + * @var string + */ + public $template_path = 'template/'; + /** * Constructor. * * @param string $phpbb_root_path phpBB root path * @param user $user current user - * @param phpbb_style_resource_locator $locator template locator - * @param phpbb_style_path_provider $provider template path provider + * @param phpbb_style_resource_locator $locator style resource locator + * @param phpbb_style_path_provider $provider style path provider */ public function __construct($phpbb_root_path, $phpEx, $config, $user, phpbb_style_resource_locator $locator, phpbb_style_path_provider_interface $provider) { @@ -89,70 +95,10 @@ class phpbb_style_template $this->config = $config; $this->user = $user; $this->locator = $locator; + $this->template_path = $this->locator->template_path; $this->provider = $provider; } - /** - * Set template location based on (current) user's chosen style. - */ - public function set_template() - { - $template_name = $this->user->theme['style_path']; - $fallback_name = ($this->user->theme['style_parent_id']) ? array_reverse(explode('/', $this->user->theme['style_parent_tree'])) : false; - - return $this->set_custom_template(false, $template_name, false, $fallback_name); - } - - /** - * Defines a prefix to use for template paths in extensions - * - * @param string $ext_dir_prefix The prefix including trailing slash - * @return null - */ - public function set_ext_dir_prefix($ext_dir_prefix) - { - $this->provider->set_ext_dir_prefix($ext_dir_prefix); - } - - /** - * Set custom template location (able to use directory outside of phpBB). - * - * Note: Templates are still compiled to phpBB's cache directory. - * - * @param string $template_path Path to template directory - * @param string $template_name Name of template - * @param string or array $fallback_template_path Path to fallback template - * @param string or array $fallback_template_name Name of fallback template - */ - public function set_custom_template($template_path, $template_name, $fallback_template_path = false, $fallback_template_name = false) - { - $templates = array($template_name => $template_path); - - if (is_string($fallback_template_name)) - { - $templates[$fallback_template_name] = $fallback_template_path; - } - if (is_array($fallback_template_name)) - { - $i = 0; - foreach ($fallback_template_name as $fallback_template_name_item) - { - $templates[$fallback_template_name_item] = is_array($fallback_template_path) ? $fallback_template_path[$i] : $fallback_template_path; - $i ++; - } - } - - $this->provider->set_templates($templates, $this->phpbb_root_path); - $this->locator->set_paths($this->provider); - $this->locator->set_main_template($this->provider->get_main_template_path()); - - $this->cachepath = $this->phpbb_root_path . 'cache/tpl_' . str_replace('_', '-', $template_name) . '_'; - - $this->context = new phpbb_style_template_context(); - - return true; - } - /** * Sets the template filenames for handles. * From 1ce4d4c4fc482f33fd061c4f718b4f8c3656dbdb Mon Sep 17 00:00:00 2001 From: Vjacheslav Trushkin Date: Thu, 15 Mar 2012 21:09:49 +0200 Subject: [PATCH 022/114] [feature/merging-style-components] Changing style class Moving functions that deal with styles from template to style class, updating docblocks PHPBB3-10632 --- phpBB/includes/style/style.php | 75 +++++++++++++++++++++++++++++++--- 1 file changed, 70 insertions(+), 5 deletions(-) diff --git a/phpBB/includes/style/style.php b/phpBB/includes/style/style.php index b134b4f76f..5dee0a138c 100644 --- a/phpBB/includes/style/style.php +++ b/phpBB/includes/style/style.php @@ -27,11 +27,6 @@ class phpbb_style */ public $template; - /** - * @var string Path of the cache directory for the template - */ - public $cachepath = ''; - /** * @var string phpBB root path */ @@ -86,4 +81,74 @@ class phpbb_style } $this->template = new phpbb_style_template($this->phpbb_root_path, $this->phpEx, $this->config, $this->user, $this->locator, $this->provider); } + + /** + * Set style location based on (current) user's chosen style. + */ + public function set_style() + { + $style_name = $this->user->theme['style_path']; + $style_dirs = ($this->user->theme['style_parent_id']) ? array_reverse(explode('/', $this->user->theme['style_parent_tree'])) : array(); + $paths = array($this->get_style_path($style_name)); + foreach ($style_dirs as $dir) + { + $paths[] = $this->get_style_path($dir); + } + + return $this->set_custom_style($style_name, $paths); + } + + /** + * Set custom style location (able to use directory outside of phpBB). + * + * Note: Templates are still compiled to phpBB's cache directory. + * + * @param string $name Name of style, used for cache prefix. Examples: "admin", "prosilver" + * @param array or string $paths Array of style paths, relative to current root directory + * @param string $template_path Path to templates, relative to style directory. False if path should not be changed. + */ + public function set_custom_style($name, $paths, $template_path = false) + { + if (is_string($paths)) + { + $paths = array($paths); + } + + $this->provider->set_styles($paths); + $this->locator->set_paths($this->provider); + $this->locator->set_main_style($this->provider->get_main_style_path()); + + $this->template->cachepath = $this->phpbb_root_path . 'cache/tpl_' . str_replace('_', '-', $name) . '_'; + + $this->template->context = new phpbb_style_template_context(); + + if ($template_path !== false) + { + $this->template->template_path = $this->locator->template_path = $template_path; + } + + return true; + } + + /** + * Get location of style directory for specific style_path + * + * @param string $path Style path, such as "prosilver" + * @return string Path to style directory, relative to current path + */ + public function get_style_path($path) + { + return $this->phpbb_root_path . 'styles/' . $path; + } + + /** + * Defines a prefix to use for style paths in extensions + * + * @param string $ext_dir_prefix The prefix including trailing slash + * @return null + */ + public function set_ext_dir_prefix($ext_dir_prefix) + { + $this->provider->set_ext_dir_prefix($ext_dir_prefix); + } } From fd96f97dc3c659e1d2e9b58420d652ad79387fbf Mon Sep 17 00:00:00 2001 From: Vjacheslav Trushkin Date: Thu, 15 Mar 2012 21:11:34 +0200 Subject: [PATCH 023/114] [feature/merging-style-components] Updating style initialization Changing template initialization to style initialization. PHPBB3-10632 --- phpBB/adm/index.php | 6 +++--- phpBB/includes/bbcode.php | 2 +- phpBB/includes/functions_messenger.php | 8 ++++---- phpBB/includes/session.php | 4 ++-- phpBB/install/index.php | 4 ++-- phpBB/install/install_update.php | 4 ++-- 6 files changed, 14 insertions(+), 14 deletions(-) diff --git a/phpBB/adm/index.php b/phpBB/adm/index.php index e7168b210b..91894e5aec 100644 --- a/phpBB/adm/index.php +++ b/phpBB/adm/index.php @@ -50,9 +50,9 @@ $file_uploads = (@ini_get('file_uploads') == '1' || strtolower(@ini_get('file_up $module_id = request_var('i', ''); $mode = request_var('mode', ''); -// Set custom template for admin area -$template->set_ext_dir_prefix('adm/'); -$template->set_custom_template($phpbb_admin_path . 'style', 'admin'); +// Set custom style for admin area +$style->set_ext_dir_prefix('adm/'); +$style->set_custom_style('admin', $phpbb_admin_path . 'style', ''); $template->assign_var('T_ASSETS_PATH', $phpbb_root_path . 'assets'); $template->assign_var('T_TEMPLATE_PATH', $phpbb_admin_path . 'style'); diff --git a/phpBB/includes/bbcode.php b/phpBB/includes/bbcode.php index 3831cb03ad..5e3bfed5ec 100644 --- a/phpBB/includes/bbcode.php +++ b/phpBB/includes/bbcode.php @@ -133,8 +133,8 @@ class bbcode $this->template_bitfield = new bitfield($user->theme['bbcode_bitfield']); $style = new phpbb_style($phpbb_root_path, $phpEx, $config, $user, $phpbb_extension_manager); + $style->set_style(); $template = $style->template; - $template->set_template(); $template->set_filenames(array('bbcode.html' => 'bbcode.html')); $this->template_filename = $style->locator->get_source_file_for_handle('bbcode.html'); } diff --git a/phpBB/includes/functions_messenger.php b/phpBB/includes/functions_messenger.php index 4e1ec160af..a5e7ad75ca 100644 --- a/phpBB/includes/functions_messenger.php +++ b/phpBB/includes/functions_messenger.php @@ -201,7 +201,7 @@ class messenger { // fall back to board default language if the user's language is // missing $template_file. If this does not exist either, - // $tpl->set_custom_template will do a trigger_error + // $tpl->set_filenames will do a trigger_error $template_lang = basename($config['default_lang']); } @@ -209,8 +209,8 @@ class messenger if (!isset($this->tpl_msg[$template_lang . $template_file])) { $this->tpl_msg[$template_lang . $template_file] = new phpbb_style($phpbb_root_path, $phpEx, $config, $user, $phpbb_extension_manager); - $tpl = &$this->tpl_msg[$template_lang . $template_file]; - $tpl = $tpl->template; + $stl = &$this->tpl_msg[$template_lang . $template_file]; + $tpl = $stl->template; $fallback_template_path = false; @@ -228,7 +228,7 @@ class messenger } } - $tpl->set_custom_template($template_path, $template_lang . '_email', $fallback_template_path); + $stl->set_custom_style($template_lang . '_email', array($template_path, $fallback_template_path), ''); $tpl->set_filenames(array( 'body' => $template_file . '.txt', diff --git a/phpBB/includes/session.php b/phpBB/includes/session.php index f2956243e2..2fd2efe9b2 100644 --- a/phpBB/includes/session.php +++ b/phpBB/includes/session.php @@ -1570,7 +1570,7 @@ class user extends session */ function setup($lang_set = false, $style_id = false) { - global $db, $template, $config, $auth, $phpEx, $phpbb_root_path, $cache; + global $db, $style, $template, $config, $auth, $phpEx, $phpbb_root_path, $cache; if ($this->data['user_id'] != ANONYMOUS) { @@ -1704,7 +1704,7 @@ class user extends session } } - $template->set_template(); + $style->set_style(); $this->img_lang = $this->lang_name; diff --git a/phpBB/install/index.php b/phpBB/install/index.php index 7c6dd10d03..1f013df72b 100644 --- a/phpBB/install/index.php +++ b/phpBB/install/index.php @@ -202,9 +202,9 @@ $config = new phpbb_config(array( )); $style = new phpbb_style($phpbb_root_path, $phpEx, $config, $user, false); +$style->set_ext_dir_prefix('adm/'); +$style->set_custom_style('admin', '../adm/style', ''); $template = $style->template; -$template->set_ext_dir_prefix('adm/'); -$template->set_custom_template('../adm/style', 'admin'); $template->assign_var('T_ASSETS_PATH', '../assets'); $template->assign_var('T_TEMPLATE_PATH', '../adm/style'); diff --git a/phpBB/install/install_update.php b/phpBB/install/install_update.php index aba692aa62..dcf01e5cc8 100644 --- a/phpBB/install/install_update.php +++ b/phpBB/install/install_update.php @@ -71,7 +71,7 @@ class install_update extends module function main($mode, $sub) { - global $template, $phpEx, $phpbb_root_path, $user, $db, $config, $cache, $auth, $language; + global $style, $template, $phpEx, $phpbb_root_path, $user, $db, $config, $cache, $auth, $language; global $request; $this->tpl_name = 'install_update'; @@ -131,7 +131,7 @@ class install_update extends module } // Set custom template again. ;) - $template->set_custom_template('../adm/style', 'admin'); + $style->set_custom_style('admin', '../adm/style', ''); $template->assign_vars(array( 'S_USER_LANG' => $user->lang['USER_LANG'], From d25b607ca16bfd240f3b9cb9da7e4567b426ec26 Mon Sep 17 00:00:00 2001 From: Vjacheslav Trushkin Date: Thu, 15 Mar 2012 21:12:13 +0200 Subject: [PATCH 024/114] [feature/merging-style-components] Updating test cases Updating code in test cases for new template classes. PHPBB3-10632 --- tests/template/includephp_test.php | 2 +- tests/template/template_inheritance_test.php | 2 +- tests/template/template_test.php | 4 ++-- tests/template/template_test_case.php | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/template/includephp_test.php b/tests/template/includephp_test.php index 28ea118a13..626735f15f 100644 --- a/tests/template/includephp_test.php +++ b/tests/template/includephp_test.php @@ -36,7 +36,7 @@ class phpbb_template_includephp_test extends phpbb_template_template_test_case $this->setup_engine(array('tpl_allow_php' => true)); - $this->template->set_custom_template($cache_dir, 'tests'); + $this->style->set_custom_style('tests', $cache_dir); $cache_file = $this->template->cachepath . 'includephp_absolute.html.php'; $this->run_template('includephp_absolute.html', array(), array(), array(), "Path is absolute.\ntesting included php", $cache_file); diff --git a/tests/template/template_inheritance_test.php b/tests/template/template_inheritance_test.php index 2c67b38641..f7bd38cc08 100644 --- a/tests/template/template_inheritance_test.php +++ b/tests/template/template_inheritance_test.php @@ -72,7 +72,7 @@ class phpbb_template_template_inheritance_test extends phpbb_template_template_t $this->template_path = dirname(__FILE__) . '/templates'; $this->parent_template_path = dirname(__FILE__) . '/parent_templates'; $this->style = new phpbb_style($phpbb_root_path, $phpEx, $config, $user, false); + $this->style->set_custom_style('tests', array($this->template_path, $this->parent_template_path), ''); $this->template = $this->style->template; - $this->template->set_custom_template($this->template_path, 'tests', $this->parent_template_path, 'parent'); } } diff --git a/tests/template/template_test.php b/tests/template/template_test.php index 76b1af68d8..edf621e16c 100644 --- a/tests/template/template_test.php +++ b/tests/template/template_test.php @@ -277,7 +277,7 @@ class phpbb_template_template_test extends phpbb_template_template_test_case $this->template->set_filenames(array('test' => $filename)); $this->assertFileNotExists($this->template_path . '/' . $filename, 'Testing missing file, file cannot exist'); - $expecting = sprintf('template locator: File for handle test does not exist. Could not find: %s', realpath($this->template_path . '/../') . '/templates/' . $filename); + $expecting = sprintf('style resource locator: File for handle test does not exist. Could not find: %s', realpath($this->template_path . '/../') . '/templates/' . $filename); $this->setExpectedTriggerError(E_USER_ERROR, $expecting); $this->display('test'); @@ -285,7 +285,7 @@ class phpbb_template_template_test extends phpbb_template_template_test_case public function test_empty_file() { - $expecting = 'template locator: set_filenames: Empty filename specified for test'; + $expecting = 'style resource locator: set_filenames: Empty filename specified for test'; $this->setExpectedTriggerError(E_USER_ERROR, $expecting); $this->template->set_filenames(array('test' => '')); diff --git a/tests/template/template_test_case.php b/tests/template/template_test_case.php index a0e980621d..5884225a54 100644 --- a/tests/template/template_test_case.php +++ b/tests/template/template_test_case.php @@ -63,8 +63,8 @@ class phpbb_template_template_test_case extends phpbb_test_case $this->template_path = dirname(__FILE__) . '/templates'; $this->style = new phpbb_style($phpbb_root_path, $phpEx, $config, $user, false); + $this->style->set_custom_style('tests', $this->template_path, ''); $this->template = $this->style->template; - $this->template->set_custom_template($this->template_path, 'tests'); } protected function setUp() From 97d4f168f588288df071e4a8b107b9ffb8b0355f Mon Sep 17 00:00:00 2001 From: Richard Foote Date: Mon, 19 Mar 2012 15:08:28 -0400 Subject: [PATCH 025/114] [ticket/10675] Add disk full language string when posting attachments Add language string visible by admins only for when the disk does not have enough free space to upload attachments. PHPBB3-10675 --- phpBB/includes/functions_posting.php | 9 ++++++++- phpBB/language/en/posting.php | 1 + 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/phpBB/includes/functions_posting.php b/phpBB/includes/functions_posting.php index f920be9c4b..b40fd67927 100644 --- a/phpBB/includes/functions_posting.php +++ b/phpBB/includes/functions_posting.php @@ -497,7 +497,14 @@ function upload_attachment($form_name, $forum_id, $local = false, $local_storage { if ($free_space <= $file->get('filesize')) { - $filedata['error'][] = $user->lang['ATTACH_QUOTA_REACHED']; + if ($auth->acl_get('a_')) + { + $filedata['error'][] = $user->lang['ATTACH_DISK_FULL']; + } + else + { + $filedata['error'][] = $user->lang['ATTACH_QUOTA_REACHED']; + } $filedata['post_attach'] = false; $file->remove(); diff --git a/phpBB/language/en/posting.php b/phpBB/language/en/posting.php index f8d265dddd..dd0ba7fc6d 100644 --- a/phpBB/language/en/posting.php +++ b/phpBB/language/en/posting.php @@ -42,6 +42,7 @@ $lang = array_merge($lang, array( 'ADD_POLL' => 'Poll creation', 'ADD_POLL_EXPLAIN' => 'If you do not want to add a poll to your topic leave the fields blank.', 'ALREADY_DELETED' => 'Sorry but this message is already deleted.', + 'ATTACH_DISK_FULL' => 'There is not enough free disk space to post this attachment', 'ATTACH_QUOTA_REACHED' => 'Sorry, the board attachment quota has been reached.', 'ATTACH_SIG' => 'Attach a signature (signatures can be altered via the UCP)', From 28fac327426de08b7a5476b2417fef4f03be6908 Mon Sep 17 00:00:00 2001 From: Bruno Ais Date: Thu, 29 Mar 2012 15:51:06 +0100 Subject: [PATCH 026/114] [ticket/10705] Change WARNINGS_ZERO_TOTAL in en language Located the WARNINGS_ZERO_TOTAL in the language and replaced it with NO_WARNINGS PHPBB3-10705 --- phpBB/language/en/mcp.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/language/en/mcp.php b/phpBB/language/en/mcp.php index 664365b1ec..d57036cc0e 100644 --- a/phpBB/language/en/mcp.php +++ b/phpBB/language/en/mcp.php @@ -388,7 +388,7 @@ $lang = array_merge($lang, array( 'WARNING_PM_BODY' => 'The following is a warning which has been issued to you by an administrator or moderator of this site.[quote]%s[/quote]', 'WARNING_PM_SUBJECT' => 'Board warning issued', 'WARNING_POST_DEFAULT' => 'This is a warning regarding the following post made by you: %s .', - 'WARNINGS_ZERO_TOTAL' => 'No warnings exist.', + 'NO_WARNINGS' => 'No warnings exist.', 'YOU_SELECTED_TOPIC' => 'You selected topic number %d: %s.', From d0e7b38aecbd5f357401297c8d57824a0504e9b6 Mon Sep 17 00:00:00 2001 From: Bruno Ais Date: Thu, 29 Mar 2012 15:52:06 +0100 Subject: [PATCH 027/114] [ticket/10705] Change WARNINGS_ZERO_TOTAL in prosilver Located the L_WARNINGS_ZERO_TOTAL in prosilver and replaced it with L_NO_WARNINGS PHPBB3-10705 --- phpBB/styles/prosilver/template/mcp_warn_front.html | 4 ++-- phpBB/styles/prosilver/template/mcp_warn_list.html | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/phpBB/styles/prosilver/template/mcp_warn_front.html b/phpBB/styles/prosilver/template/mcp_warn_front.html index 8f42e28cc0..2f7d939b16 100644 --- a/phpBB/styles/prosilver/template/mcp_warn_front.html +++ b/phpBB/styles/prosilver/template/mcp_warn_front.html @@ -55,7 +55,7 @@ -

    {L_WARNINGS_ZERO_TOTAL}

    +

    {L_NO_WARNINGS}

    @@ -88,7 +88,7 @@ -

    {L_WARNINGS_ZERO_TOTAL}

    +

    {L_NO_WARNINGS}

    diff --git a/phpBB/styles/prosilver/template/mcp_warn_list.html b/phpBB/styles/prosilver/template/mcp_warn_list.html index d9c0bce088..5e43903f11 100644 --- a/phpBB/styles/prosilver/template/mcp_warn_list.html +++ b/phpBB/styles/prosilver/template/mcp_warn_list.html @@ -53,7 +53,7 @@
  • -

    {L_WARNINGS_ZERO_TOTAL}

    +

    {L_NO_WARNINGS}

    From 56629d8e3c80cd490b8ec39d4fa102d0303f9a4b Mon Sep 17 00:00:00 2001 From: Bruno Ais Date: Thu, 29 Mar 2012 15:52:28 +0100 Subject: [PATCH 028/114] [ticket/10705] Change WARNINGS_ZERO_TOTAL in subsilver2 Located the L_WARNINGS_ZERO_TOTAL in subsilver2 and replaced it with L_NO_WARNINGS PHPBB3-10705 --- phpBB/styles/subsilver2/template/mcp_warn_front.html | 4 ++-- phpBB/styles/subsilver2/template/mcp_warn_list.html | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/phpBB/styles/subsilver2/template/mcp_warn_front.html b/phpBB/styles/subsilver2/template/mcp_warn_front.html index 417355d537..020a79f419 100644 --- a/phpBB/styles/subsilver2/template/mcp_warn_front.html +++ b/phpBB/styles/subsilver2/template/mcp_warn_front.html @@ -38,7 +38,7 @@ - {L_WARNINGS_ZERO_TOTAL} + {L_NO_WARNINGS} @@ -64,7 +64,7 @@ - {L_WARNINGS_ZERO_TOTAL} + {L_NO_WARNINGS} diff --git a/phpBB/styles/subsilver2/template/mcp_warn_list.html b/phpBB/styles/subsilver2/template/mcp_warn_list.html index 6ed0b68bd5..0b0cfa8a45 100644 --- a/phpBB/styles/subsilver2/template/mcp_warn_list.html +++ b/phpBB/styles/subsilver2/template/mcp_warn_list.html @@ -21,7 +21,7 @@ - {L_WARNINGS_ZERO_TOTAL} + {L_NO_WARNINGS} From 506951e8aff98582ebc56fcda9ed0626497ade77 Mon Sep 17 00:00:00 2001 From: Vjacheslav Trushkin Date: Fri, 30 Mar 2012 16:13:16 +0300 Subject: [PATCH 029/114] [feature/merging-style-components] Changing acp_styles text Changing acp styles welcome message a little bit. PHPBB3-10632 --- phpBB/language/en/acp/styles.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/language/en/acp/styles.php b/phpBB/language/en/acp/styles.php index fe7fae5808..8a4a8e7308 100644 --- a/phpBB/language/en/acp/styles.php +++ b/phpBB/language/en/acp/styles.php @@ -237,7 +237,7 @@ $lang = array_merge($lang, array( 'INHERITING_FROM' => 'Inherits from', 'INSTALL_STYLE' => 'Install style', 'INSTALL_STYLES' => 'Install styles', - 'INSTALL_STYLES_EXPLAIN' => 'Here you can install new styles.
    If you cannot find a specific style in list below, check if that style is already installed. If it is not installed, check if it was uploaded correctly.', + 'INSTALL_STYLES_EXPLAIN' => 'Here you can install new styles.
    If you cannot find a specific style in list below, check to make sure style is already installed. If it is not installed, check if it was uploaded correctly.', 'INSTALLED_STYLE' => 'Installed styles', 'INVALID_STYLE_ID' => 'Invalid style ID.', From 9391d423c05818e5f18ddbe051e1713c835f4404 Mon Sep 17 00:00:00 2001 From: Michael Cullum Date: Fri, 30 Mar 2012 19:04:20 +0100 Subject: [PATCH 030/114] [feature/event-dispatcher] Adding composer.phar to .gitignore for olympus To keep the .gitignore's the same. PHPBB3-9550 --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index e6e017f85e..de26e1dd1e 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,7 @@ /phpBB/cache/*.html /phpBB/cache/*.php /phpBB/cache/queue.php.lock +/phpBB/composer.phar /phpBB/config.php /phpBB/config_dev.php /phpBB/config_test.php From a7045e65724481002e232a7d143b7cc2ed6acb3a Mon Sep 17 00:00:00 2001 From: David King Date: Fri, 30 Mar 2012 21:43:00 -0400 Subject: [PATCH 031/114] [feature/qrpreview] Preview from Quick Reply PHPBB3-10726 --- phpBB/language/en/viewtopic.php | 2 +- phpBB/posting.php | 2 +- phpBB/styles/prosilver/template/ajax.js | 11 +++++++++++ .../styles/prosilver/template/quickreply_editor.html | 4 ++-- .../styles/subsilver2/template/quickreply_editor.html | 4 ++-- 5 files changed, 17 insertions(+), 6 deletions(-) diff --git a/phpBB/language/en/viewtopic.php b/phpBB/language/en/viewtopic.php index 1460490672..184f88ed3c 100644 --- a/phpBB/language/en/viewtopic.php +++ b/phpBB/language/en/viewtopic.php @@ -62,7 +62,7 @@ $lang = array_merge($lang, array( 'FILE_NOT_FOUND_404' => 'The file %s does not exist.', 'FORK_TOPIC' => 'Copy topic', - 'FULL_EDITOR' => 'Full Editor', + 'FULL_EDITOR' => 'Full Editor & Preview', 'LINKAGE_FORBIDDEN' => 'You are not authorised to view, download or link from/to this site.', 'LOGIN_NOTIFY_TOPIC' => 'You have been notified about this topic, please login to view it.', diff --git a/phpBB/posting.php b/phpBB/posting.php index 56fb7832f2..71ba353e89 100644 --- a/phpBB/posting.php +++ b/phpBB/posting.php @@ -38,7 +38,7 @@ $load = (isset($_POST['load'])) ? true : false; $delete = (isset($_POST['delete'])) ? true : false; $cancel = (isset($_POST['cancel']) && !isset($_POST['save'])) ? true : false; -$refresh = (isset($_POST['add_file']) || isset($_POST['delete_file']) || isset($_POST['full_editor']) || isset($_POST['cancel_unglobalise']) || $save || $load) ? true : false; +$refresh = (isset($_POST['add_file']) || isset($_POST['delete_file']) || isset($_POST['cancel_unglobalise']) || $save || $load) ? true : false; $mode = ($delete && !$preview && !$refresh && $submit) ? 'delete' : request_var('mode', ''); $error = $post_data = array(); diff --git a/phpBB/styles/prosilver/template/ajax.js b/phpBB/styles/prosilver/template/ajax.js index cc886c42b1..54f34e4204 100644 --- a/phpBB/styles/prosilver/template/ajax.js +++ b/phpBB/styles/prosilver/template/ajax.js @@ -66,6 +66,17 @@ $('[data-ajax]').each(function() { }); +/** + * This simply appends #preview to the action of the + * QR action when you click the Full Editor & Preview button + */ +$('#qr_full_editor').click(function() { + $('#qr_postform').attr('action', function(i, val) { + return val + '#preview'; + }); +}); + + /** * This AJAXifies the quick-mod tools. The reason it cannot be a standard diff --git a/phpBB/styles/prosilver/template/quickreply_editor.html b/phpBB/styles/prosilver/template/quickreply_editor.html index 4cd5eedd3e..c7d998eca5 100644 --- a/phpBB/styles/prosilver/template/quickreply_editor.html +++ b/phpBB/styles/prosilver/template/quickreply_editor.html @@ -14,8 +14,8 @@
    {S_FORM_TOKEN} {QR_HIDDEN_FIELDS} -   -   +   +  
    diff --git a/phpBB/styles/subsilver2/template/quickreply_editor.html b/phpBB/styles/subsilver2/template/quickreply_editor.html index de5017280c..4c3f7a3d0b 100644 --- a/phpBB/styles/subsilver2/template/quickreply_editor.html +++ b/phpBB/styles/subsilver2/template/quickreply_editor.html @@ -14,8 +14,8 @@ -   - +   + {S_FORM_TOKEN} {QR_HIDDEN_FIELDS} From 0c8d0a82de69277d090907618eee71f815f12436 Mon Sep 17 00:00:00 2001 From: David King Date: Fri, 30 Mar 2012 21:46:20 -0400 Subject: [PATCH 032/114] [feature/qrpreview] Add id qr_postform to prosilver QR PHPBB3-10726 --- phpBB/styles/prosilver/template/quickreply_editor.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/styles/prosilver/template/quickreply_editor.html b/phpBB/styles/prosilver/template/quickreply_editor.html index c7d998eca5..a08b5dc3cc 100644 --- a/phpBB/styles/prosilver/template/quickreply_editor.html +++ b/phpBB/styles/prosilver/template/quickreply_editor.html @@ -1,4 +1,4 @@ -
    +

    {L_QUICKREPLY}

    From e13e4d92061df3a49cc5dbf7724f232ab927018a Mon Sep 17 00:00:00 2001 From: Vjacheslav Trushkin Date: Sat, 31 Mar 2012 16:33:30 +0300 Subject: [PATCH 033/114] [feature/merging-style-components] Updating styles in coding guidelines Updating styles section in coding guidelines PHPBB3-10632 --- phpBB/docs/coding-guidelines.html | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/phpBB/docs/coding-guidelines.html b/phpBB/docs/coding-guidelines.html index f8aaf77441..e6dfe579e9 100644 --- a/phpBB/docs/coding-guidelines.html +++ b/phpBB/docs/coding-guidelines.html @@ -1144,15 +1144,19 @@ append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=group&amp;

    3.i. Style Config Files

    -

    Style cfg files are simple name-value lists with the information necessary for installing a style. Similar cfg files exist for templates, themes and imagesets. These follow the same principle and will not be introduced individually. Styles can use installed components by using the required_theme/required_template/required_imageset entries. The important part of the style configuration file is assigning an unique name.

    +

    Style cfg files are simple name-value lists with the information necessary for installing a style. The important part of the style configuration file is assigning an unique name.

    -        # General Information about this style
    -        name = prosilver_duplicate
    -        copyright = © phpBB Group, 2007
    -        version = 3.0.3
    -        required_template = prosilver
    -        required_theme = prosilver
    -        required_imageset = prosilver
    +# General Information about this style
    +name = prosilver_duplicate
    +copyright = © phpBB Group, 2007
    +version = 3.1.0
    +
    +# Defining a different template bitfield
    +# template_bitfield = lNg=
    +
    +# Parent style
    +# Set value to empty or to this style's name if this style does not have a parent style
    +parent = prosilver
     	

    3.2. General Styling Rules

    Templates should be produced in a consistent manner. Where appropriate they should be based off an existing copy, e.g. index, viewforum or viewtopic (the combination of which implement a range of conditional and variable forms). Please also note that the indentation and coding guidelines also apply to templates where possible.

    @@ -1175,7 +1179,7 @@ append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=group&amp;

    Row colours/classes are now defined by the template, use an IF S_ROW_COUNT switch, see viewtopic or viewforum for an example.

    -

    Remember block level ordering is important ... while not all pages validate as XHTML 1.0 Strict compliant it is something we're trying to work on.

    +

    Remember block level ordering is important.

    Use a standard cellpadding of 2 and cellspacing of 0 on outer tables. Inner tables can vary from 0 to 3 or even 4 depending on the need.

    @@ -1243,13 +1247,13 @@ append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=group&amp;

    A bit later loops will be explained further. To not irritate you we will explain conditionals as well as other statements first.

    Including files

    -

    Something that existed in 2.0.x which no longer exists in 3.0.x is the ability to assign a template to a variable. This was used (for example) to output the jumpbox. Instead (perhaps better, perhaps not but certainly more flexible) we now have INCLUDE. This takes the simple form:

    +

    Something that existed in 2.0.x which no longer exists in 3.x is the ability to assign a template to a variable. This was used (for example) to output the jumpbox. Instead (perhaps better, perhaps not but certainly more flexible) we now have INCLUDE. This takes the simple form:

     <!-- INCLUDE filename -->
     
    -

    You will note in the 3.0 templates the major sources start with <!-- INCLUDE overall_header.html --> or <!-- INCLUDE simple_header.html -->, etc. In 2.0.x control of "which" header to use was defined entirely within the code. In 3.0.x the template designer can output what they like. Note that you can introduce new templates (i.e. other than those in the default set) using this system and include them as you wish ... perhaps useful for a common "menu" bar or some such. No need to modify loads of files as with 2.0.x.

    +

    You will note in the 3.x templates the major sources start with <!-- INCLUDE overall_header.html --> or <!-- INCLUDE simple_header.html -->, etc. In 2.0.x control of "which" header to use was defined entirely within the code. In 3.x the template designer can output what they like. Note that you can introduce new templates (i.e. other than those in the default set) using this system and include them as you wish ... perhaps useful for a common "menu" bar or some such. No need to modify loads of files as with 2.0.x.

    Added in 3.0.6 is the ability to include a file using a template variable to specify the file, this functionality only works for root variables (i.e. not block variables).

    @@ -1281,7 +1285,7 @@ append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=group&amp;
     

    it will be included and executed inline.

    A note, it is very much encouraged that template designers do not include PHP. The ability to include raw PHP was introduced primarily to allow end users to include banner code, etc. without modifying multiple files (as with 2.0.x). It was not intended for general use ... hence www.phpbb.com will not make available template sets which include PHP. And by default templates will have PHP disabled (the admin will need to specifically activate PHP for a template).

    Conditionals/Control structures

    -

    The most significant addition to 3.0.x are conditions or control structures, "if something then do this else do that". The system deployed is very similar to Smarty. This may confuse some people at first but it offers great potential and great flexibility with a little imagination. In their most simple form these constructs take the form:

    +

    The most significant addition to 3.x are conditions or control structures, "if something then do this else do that". The system deployed is very similar to Smarty. This may confuse some people at first but it offers great potential and great flexibility with a little imagination. In their most simple form these constructs take the form:

     <!-- IF expr -->
    @@ -1352,7 +1356,7 @@ div
     <!-- ENDIF -->
     
    -

    Each statement will be tested in turn and the relevant output generated when a match (if a match) is found. It is not necessary to always use ELSEIF, ELSE can be used alone to match "everything else".

    So what can you do with all this? Well take for example the colouration of rows in viewforum. In 2.0.x row colours were predefined within the source as either row color1, row color2 or row class1, row class2. In 3.0.x this is moved to the template, it may look a little daunting at first but remember control flows from top to bottom and it's not too difficult:

    +

    Each statement will be tested in turn and the relevant output generated when a match (if a match) is found. It is not necessary to always use ELSEIF, ELSE can be used alone to match "everything else".

    So what can you do with all this? Well take for example the colouration of rows in viewforum. In 2.0.x row colours were predefined within the source as either row color1, row color2 or row class1, row class2. In 3.x this is moved to the template, it may look a little daunting at first but remember control flows from top to bottom and it's not too difficult:

     <table>
    
    From bc46cfd6e5a6dd0a759c610e4654a7fad47db130 Mon Sep 17 00:00:00 2001
    From: Igor Wiedler 
    Date: Sat, 31 Mar 2012 15:48:12 +0200
    Subject: [PATCH 034/114] [feature/merging-style-components] Fix notices in
     acp_styles
    
    PHPBB3-10632
    ---
     phpBB/includes/acp/acp_styles.php | 5 +++--
     1 file changed, 3 insertions(+), 2 deletions(-)
    
    diff --git a/phpBB/includes/acp/acp_styles.php b/phpBB/includes/acp/acp_styles.php
    index acd010b77e..123725ef1d 100644
    --- a/phpBB/includes/acp/acp_styles.php
    +++ b/phpBB/includes/acp/acp_styles.php
    @@ -228,7 +228,7 @@ class acp_styles
     	*/
     	function action_delete_confirmed($ids, $delete_files)
     	{
    -		global $db, $user, $cache;
    +		global $db, $user, $cache, $config;
     
     		$default = $config['default_style'];
     		$deleted = array();
    @@ -556,6 +556,7 @@ class acp_styles
     		$users = $this->get_users();
     		
     		// Add users counter to rows
    +		$style['_users'] = array();
     		foreach ($styles as &$style)
     		{
     			$style['_users'] = isset($users[$style['style_id']]) ? $users[$style['style_id']] : 0;
    @@ -1288,7 +1289,7 @@ class acp_styles
     	function default_bitfield()
     	{
     		static $value;
    -		if(isset($value))
    +		if (isset($value))
     		{
     			return $value;
     		}
    
    From 961199755200668790b243447eac6bf3374b0bb6 Mon Sep 17 00:00:00 2001
    From: Vjacheslav Trushkin 
    Date: Sat, 31 Mar 2012 17:04:17 +0300
    Subject: [PATCH 035/114] [feature/merging-style-components] Fixing few errors
     in acp_styles
    
    Fixing notices and usability issues
    
    PHPBB3-10632
    ---
     phpBB/includes/acp/acp_styles.php | 7 +------
     1 file changed, 1 insertion(+), 6 deletions(-)
    
    diff --git a/phpBB/includes/acp/acp_styles.php b/phpBB/includes/acp/acp_styles.php
    index 123725ef1d..5ff79b0c19 100644
    --- a/phpBB/includes/acp/acp_styles.php
    +++ b/phpBB/includes/acp/acp_styles.php
    @@ -181,10 +181,6 @@ class acp_styles
     			trigger_error($user->lang['NO_MATCHING_STYLES_FOUND'] . adm_back_link($this->u_action), E_USER_WARNING);
     		}
     		$message = implode('
    ', $messages); - if (count($messages) == 1 && $last_installed !== false) - { - $message .= '

    ' . sprintf($user->lang['STYLE_INSTALLED_EDIT_DETAILS'], $this->u_base_action . '&mode=style&action=details&id=' . $last_installed); - } $message .= '

    ' . sprintf($user->lang['STYLE_INSTALLED_RETURN_STYLES'], $this->u_base_action . '&mode=style'); $message .= '

    ' . sprintf($user->lang['STYLE_INSTALLED_RETURN_UNINSTALLED'], $this->u_base_action . '&mode=install'); trigger_error($message, E_USER_NOTICE); @@ -556,7 +552,6 @@ class acp_styles $users = $this->get_users(); // Add users counter to rows - $style['_users'] = array(); foreach ($styles as &$style) { $style['_users'] = isset($users[$style['style_id']]) ? $users[$style['style_id']] : 0; @@ -892,7 +887,7 @@ class acp_styles // Additional data 'DEFAULT' => ($style['style_id'] && $style['style_id'] == $config['default_style']), - 'USERS' => $style['_users'], + 'USERS' => (isset($style['_users'])) ? $style['_users'] : '', 'LEVEL' => $level, 'PADDING' => (4 + 16 * $level), 'SHOW_COPYRIGHT' => ($style['style_id']) ? false : true, From 360312f599edd852e14fcd162552e19dd2d278a6 Mon Sep 17 00:00:00 2001 From: Vjacheslav Trushkin Date: Sat, 31 Mar 2012 17:38:30 +0300 Subject: [PATCH 036/114] [feature/merging-style-components] Initializing locator and provider separately Moving locator and path provider initialization out of style class PHPBB3-10632 --- phpBB/common.php | 4 +++- phpBB/includes/bbcode.php | 6 ++++-- phpBB/includes/functions_messenger.php | 4 +++- phpBB/includes/style/style.php | 16 ++++++---------- phpBB/install/index.php | 4 +++- tests/template/template_inheritance_test.php | 4 +++- tests/template/template_test_case.php | 6 +++++- 7 files changed, 27 insertions(+), 17 deletions(-) diff --git a/phpBB/common.php b/phpBB/common.php index 3f039e49c0..1e3f787611 100644 --- a/phpBB/common.php +++ b/phpBB/common.php @@ -124,7 +124,9 @@ set_config_count(null, null, null, $config); $phpbb_extension_manager = new phpbb_extension_manager($db, EXT_TABLE, $phpbb_root_path, ".$phpEx", $cache->get_driver()); // Initialize style -$style = new phpbb_style($phpbb_root_path, $phpEx, $config, $user, $phpbb_extension_manager); +$phpbb_style_resource_locator = new phpbb_style_resource_locator(); +$phpbb_style_path_provider = new phpbb_style_extension_path_provider($phpbb_extension_manager, new phpbb_style_path_provider()); +$style = new phpbb_style($phpbb_root_path, $phpEx, $config, $user, $phpbb_style_resource_locator, $phpbb_style_path_provider); $template = $style->template; $phpbb_subscriber_loader = new phpbb_event_extension_subscriber_loader($phpbb_dispatcher, $phpbb_extension_manager); diff --git a/phpBB/includes/bbcode.php b/phpBB/includes/bbcode.php index 5e3bfed5ec..2cae38022e 100644 --- a/phpBB/includes/bbcode.php +++ b/phpBB/includes/bbcode.php @@ -132,11 +132,13 @@ class bbcode { $this->template_bitfield = new bitfield($user->theme['bbcode_bitfield']); - $style = new phpbb_style($phpbb_root_path, $phpEx, $config, $user, $phpbb_extension_manager); + $style_resource_locator = new phpbb_style_resource_locator(); + $style_path_provider = new phpbb_style_extension_path_provider($phpbb_extension_manager, new phpbb_style_path_provider()); + $style = new phpbb_style($phpbb_root_path, $phpEx, $config, $user, $style_resource_locator, $style_path_provider); $style->set_style(); $template = $style->template; $template->set_filenames(array('bbcode.html' => 'bbcode.html')); - $this->template_filename = $style->locator->get_source_file_for_handle('bbcode.html'); + $this->template_filename = $style_resource_locator->get_source_file_for_handle('bbcode.html'); } $bbcode_ids = $rowset = $sql = array(); diff --git a/phpBB/includes/functions_messenger.php b/phpBB/includes/functions_messenger.php index a5e7ad75ca..4d076a7957 100644 --- a/phpBB/includes/functions_messenger.php +++ b/phpBB/includes/functions_messenger.php @@ -208,7 +208,9 @@ class messenger // tpl_msg now holds a template object we can use to parse the template file if (!isset($this->tpl_msg[$template_lang . $template_file])) { - $this->tpl_msg[$template_lang . $template_file] = new phpbb_style($phpbb_root_path, $phpEx, $config, $user, $phpbb_extension_manager); + $style_resource_locator = new phpbb_style_resource_locator(); + $style_path_provider = new phpbb_style_extension_path_provider($phpbb_extension_manager, new phpbb_style_path_provider()); + $this->tpl_msg[$template_lang . $template_file] = new phpbb_style($phpbb_root_path, $phpEx, $config, $user, $style_resource_locator, $style_path_provider); $stl = &$this->tpl_msg[$template_lang . $template_file]; $tpl = $stl->template; diff --git a/phpBB/includes/style/style.php b/phpBB/includes/style/style.php index 5dee0a138c..265a45eca7 100644 --- a/phpBB/includes/style/style.php +++ b/phpBB/includes/style/style.php @@ -50,9 +50,8 @@ class phpbb_style /** * Style resource locator * @var phpbb_style_resource_locator - * This item is temporary public, until locate() function is implemented */ - public $locator; + private $locator; /** * Style path provider @@ -65,20 +64,17 @@ class phpbb_style * * @param string $phpbb_root_path phpBB root path * @param user $user current user - * @param phpbb_extension_manager $phpbb_extension_manager extension manager. Set it to false if extension manager should not be used. + * @param phpbb_style_resource_locator $locator style resource locator + * @param phpbb_style_path_provider $provider style path provider */ - public function __construct($phpbb_root_path, $phpEx, $config, $user, $phpbb_extension_manager = false) + public function __construct($phpbb_root_path, $phpEx, $config, $user, phpbb_style_resource_locator $locator, phpbb_style_path_provider_interface $provider) { $this->phpbb_root_path = $phpbb_root_path; $this->phpEx = $phpEx; $this->config = $config; $this->user = $user; - $this->locator = new phpbb_style_resource_locator(); - $this->provider = new phpbb_style_path_provider(); - if ($phpbb_extension_manager !== false) - { - $this->provider = new phpbb_style_extension_path_provider($phpbb_extension_manager, $this->provider); - } + $this->locator = $locator; + $this->provider = $provider; $this->template = new phpbb_style_template($this->phpbb_root_path, $this->phpEx, $this->config, $this->user, $this->locator, $this->provider); } diff --git a/phpBB/install/index.php b/phpBB/install/index.php index 49f7847489..fdce7234e5 100644 --- a/phpBB/install/index.php +++ b/phpBB/install/index.php @@ -202,7 +202,9 @@ $config = new phpbb_config(array( 'load_tplcompile' => '1' )); -$style = new phpbb_style($phpbb_root_path, $phpEx, $config, $user, false); +$phpbb_style_resource_locator = new phpbb_style_resource_locator(); +$phpbb_style_path_provider = new phpbb_style_path_provider(); +$style = new phpbb_style($phpbb_root_path, $phpEx, $config, $user, $phpbb_style_resource_locator, $phpbb_style_path_provider); $style->set_ext_dir_prefix('adm/'); $style->set_custom_style('admin', '../adm/style', ''); $template = $style->template; diff --git a/tests/template/template_inheritance_test.php b/tests/template/template_inheritance_test.php index f7bd38cc08..aa527a3eb5 100644 --- a/tests/template/template_inheritance_test.php +++ b/tests/template/template_inheritance_test.php @@ -71,7 +71,9 @@ class phpbb_template_template_inheritance_test extends phpbb_template_template_t $this->template_path = dirname(__FILE__) . '/templates'; $this->parent_template_path = dirname(__FILE__) . '/parent_templates'; - $this->style = new phpbb_style($phpbb_root_path, $phpEx, $config, $user, false); + $this->style_resource_locator = new phpbb_style_path_provider(); + $this->style_provider = new phpbb_style_path_provider(); + $this->style = new phpbb_style($phpbb_root_path, $phpEx, $config, $user, $this->style_resource_locator, $this->style_provider); $this->style->set_custom_style('tests', array($this->template_path, $this->parent_template_path), ''); $this->template = $this->style->template; } diff --git a/tests/template/template_test_case.php b/tests/template/template_test_case.php index 5884225a54..f324736ba4 100644 --- a/tests/template/template_test_case.php +++ b/tests/template/template_test_case.php @@ -15,6 +15,8 @@ class phpbb_template_template_test_case extends phpbb_test_case protected $style; protected $template; protected $template_path; + protected $style_resource_locator; + protected $style_provider; // Keep the contents of the cache for debugging? const PRESERVE_CACHE = true; @@ -62,7 +64,9 @@ class phpbb_template_template_test_case extends phpbb_test_case $config = new phpbb_config(array_merge($defaults, $new_config)); $this->template_path = dirname(__FILE__) . '/templates'; - $this->style = new phpbb_style($phpbb_root_path, $phpEx, $config, $user, false); + $this->style_resource_locator = new phpbb_style_path_provider(); + $this->style_provider = new phpbb_style_path_provider(); + $this->style = new phpbb_style($phpbb_root_path, $phpEx, $config, $user, $this->style_resource_locator, $this->style_provider); $this->style->set_custom_style('tests', $this->template_path, ''); $this->template = $this->style->template; } From 0540509f145d7eb9ba1fd4468399b48edcf46d23 Mon Sep 17 00:00:00 2001 From: Vjacheslav Trushkin Date: Sat, 31 Mar 2012 17:58:17 +0300 Subject: [PATCH 037/114] [feature/merging-style-components] Renaming "delete" to "uninstall" for styles Changing from "delete" to "uninstall" in acp_styles to avoid confusing users PHPBB3-10632 --- phpBB/includes/acp/acp_styles.php | 64 +++++++++++++++---------------- phpBB/language/en/acp/styles.php | 7 +++- 2 files changed, 37 insertions(+), 34 deletions(-) diff --git a/phpBB/includes/acp/acp_styles.php b/phpBB/includes/acp/acp_styles.php index 5ff79b0c19..9345ad470a 100644 --- a/phpBB/includes/acp/acp_styles.php +++ b/phpBB/includes/acp/acp_styles.php @@ -45,7 +45,7 @@ class acp_styles $this->mode = $mode; $action = $request->variable('action', ''); - $post_actions = array('install', 'activate', 'deactivate', 'delete'); + $post_actions = array('install', 'activate', 'deactivate', 'uninstall'); foreach ($post_actions as $key) { if (isset($_POST[$key])) @@ -70,8 +70,8 @@ class acp_styles case 'install': $this->action_install(); return; - case 'delete': - $this->action_delete(); + case 'uninstall': + $this->action_uninstall(); return; case 'activate': $this->action_activate(); @@ -187,47 +187,47 @@ class acp_styles } /** - * Confirm styles deletion + * Confirm styles removal */ - function action_delete() + function action_uninstall() { global $user, $config, $template, $request; - // Get list of styles to delete + // Get list of styles to uninstall $ids = $this->request_vars('id', 0, true); // Check if confirmation box was submitted if (confirm_box(true)) { - // Delete - $this->action_delete_confirmed($ids, $request->variable('confirm_delete_files', false)); + // Uninstall + $this->action_uninstall_confirmed($ids, $request->variable('confirm_delete_files', false)); return; } // Confirm box $s_hidden = build_hidden_fields(array( - 'action' => 'delete', + 'action' => 'uninstall', 'ids' => $ids )); $template->assign_var('S_CONFIRM_DELETE', true); - confirm_box(false, $user->lang['CONFIRM_DELETE_STYLES'], $s_hidden, 'acp_styles.html'); + confirm_box(false, $user->lang['CONFIRM_UNINSTALL_STYLES'], $s_hidden, 'acp_styles.html'); // Canceled - show styles list $this->frontend(); } /** - * Delete styles(s) + * Uninstall styles(s) * * @param array $ids List of style IDs * @param bool $delete_files If true, script will attempt to remove files for selected styles */ - function action_delete_confirmed($ids, $delete_files) + function action_uninstall_confirmed($ids, $delete_files) { global $db, $user, $cache, $config; $default = $config['default_style']; - $deleted = array(); + $uninstalled = array(); $messages = array(); // Check styles list @@ -239,9 +239,9 @@ class acp_styles } if ($id == $default) { - trigger_error($user->lang['DELETE_DEFAULT'] . adm_back_link($this->u_action), E_USER_WARNING); + trigger_error($user->lang['UNINSTALL_DEFAULT'] . adm_back_link($this->u_action), E_USER_WARNING); } - $deleted[$id] = false; + $uninstalled[$id] = false; } // Order by reversed style_id, so parent styles would be removed after child styles @@ -255,19 +255,19 @@ class acp_styles $rows = $db->sql_fetchrowset($result); $db->sql_freeresult($result); - // Delete each style - $deleted = array(); + // Uinstall each style + $uninstalled = array(); foreach ($rows as $style) { - $result = $this->delete_style($style, $delete_files); + $result = $this->uninstall_style($style, $delete_files); if (is_string($result)) { $messages[] = $result; continue; } - $messages[] = sprintf($user->lang['STYLE_DELETED'], $style['style_name']); - $deleted[] = $style['style_name']; + $messages[] = sprintf($user->lang['STYLE_UNINSTALLED'], $style['style_name']); + $uninstalled[] = $style['style_name']; // Attempt to delete files if ($delete_files) @@ -278,14 +278,14 @@ class acp_styles if (empty($messages)) { - // Nothing to delete? + // Nothing to uninstall? trigger_error($user->lang['NO_MATCHING_STYLES_FOUND'] . adm_back_link($this->u_action), E_USER_WARNING); } // Log action - if (count($deleted)) + if (count($uninstalled)) { - add_log('admin', 'LOG_STYLE_DELETE', implode(', ', $deleted)); + add_log('admin', 'LOG_STYLE_DELETE', implode(', ', $uninstalled)); } // Clear cache @@ -591,8 +591,8 @@ class acp_styles if (isset($this->style_counters) && $this->style_counters['total'] > 1) { $template->assign_block_vars('extra_actions', array( - 'ACTION_NAME' => 'delete', - 'L_ACTION' => $user->lang['DELETE'], + 'ACTION_NAME' => 'uninstall', + 'L_ACTION' => $user->lang['STYLE_UNINSTALL'], ) ); } @@ -924,10 +924,10 @@ class acp_styles 'L_ACTION' => $user->lang['EXPORT'] ); */ - // Delete + // Uninstall $actions[] = array( - 'U_ACTION' => $this->u_action . '&action=delete&id=' . $style['style_id'], - 'L_ACTION' => $user->lang['DELETE'] + 'U_ACTION' => $this->u_action . '&action=uninstall&id=' . $style['style_id'], + 'L_ACTION' => $user->lang['STYLE_UNINSTALL'] ); // Preview @@ -1156,12 +1156,12 @@ class acp_styles } /** - * Delete style + * Uninstall style * * @param array $style Style data * @returns true on success, error message on error */ - function delete_style($style) + function uninstall_style($style) { global $db, $user; @@ -1179,7 +1179,7 @@ class acp_styles if ($conflict !== false) { - return sprintf($user->lang['STYLE_DELETE_DEPENDENT'], $style['style_name']); + return sprintf($user->lang['STYLE_UNINSTALL_DEPENDENT'], $style['style_name']); } // Change default style for users @@ -1188,7 +1188,7 @@ class acp_styles WHERE user_style = ' . $id; $db->sql_query($sql); - // Delete style + // Uninstall style $sql = 'DELETE FROM ' . STYLES_TABLE . ' WHERE style_id = ' . $id; $db->sql_query($sql); diff --git a/phpBB/language/en/acp/styles.php b/phpBB/language/en/acp/styles.php index 1a6335cdbf..f5bab1d76f 100644 --- a/phpBB/language/en/acp/styles.php +++ b/phpBB/language/en/acp/styles.php @@ -55,6 +55,7 @@ $lang = array_merge($lang, array( 'CANNOT_BE_INSTALLED' => 'Cannot be installed', 'CONFIRM_TEMPLATE_CLEAR_CACHE' => 'Are you sure you wish to clear all cached versions of your template files?', 'CONFIRM_DELETE_STYLES' => 'Are you sure you wish to delete selected styles?', + 'CONFIRM_UNINSTALL_STYLES' => 'Are you sure you wish to uninstall selected styles?', 'COPYRIGHT' => 'Copyright', 'CREATE_STYLE' => 'Create new style', 'CREATE_TEMPLATE' => 'Create new template set', @@ -62,7 +63,6 @@ $lang = array_merge($lang, array( 'CURRENT_IMAGE' => 'Current image', 'DEACTIVATE_DEFAULT' => 'You cannot deactivate the default style.', - 'DELETE_DEFAULT' => 'You cannot delete the default style.', 'DELETE_FROM_FS' => 'Delete from filesystem', 'DELETE_STYLE' => 'Delete style', 'DELETE_STYLE_EXPLAIN' => 'Here you can remove the selected style. Take care in deleting styles, there is no undo capability.', @@ -291,7 +291,6 @@ $lang = array_merge($lang, array( 'STYLE_DEFAULT' => 'Make default style', 'STYLE_DEFAULT_CHANGE' => 'Change default style', 'STYLE_DEFAULT_CHANGE_INACTIVE' => 'You must activate style before making it default style.', - 'STYLE_DELETE_DEPENDENT' => 'Style "%s" cannot be deleted because it has one or more child styles.', 'STYLE_DELETED' => 'Style "%s" deleted successfully.', 'STYLE_DETAILS_UPDATED' => 'Style edited successfully.', 'STYLE_ERR_ARCHIVE' => 'Please select an archive method.', @@ -316,6 +315,9 @@ $lang = array_merge($lang, array( 'STYLE_PARENT' => 'Parent style:', 'STYLE_TEMPLATE' => 'Template', 'STYLE_THEME' => 'Theme', + 'STYLE_UNINSTALL' => 'Uninstall', + 'STYLE_UNINSTALL_DEPENDENT' => 'Style "%s" cannot be uninstalled because it has one or more child styles.', + 'STYLE_UNINSTALLED' => 'Style "%s" uninstalled successfully.', 'STYLE_USED_BY' => 'Used by (including robots)', 'TEMPLATE_ADDED' => 'Template set added.', @@ -364,6 +366,7 @@ $lang = array_merge($lang, array( 'THEME_UPDATED' => 'Theme updated successfully.', 'UNDERLINE' => 'Underline', + 'UNINSTALL_DEFAULT' => 'You cannot uninstall the default style.', 'UNSET' => 'Undefined', )); From 17989c17a040a28aeeefcf55f6cca054b28c06ed Mon Sep 17 00:00:00 2001 From: Vjacheslav Trushkin Date: Sat, 31 Mar 2012 18:10:00 +0300 Subject: [PATCH 038/114] [feature/merging-style-components] Moving template initialization out of style Moving template initialization out of style constructor PHPBB3-10632 --- phpBB/common.php | 4 ++-- phpBB/includes/bbcode.php | 4 ++-- phpBB/includes/functions_messenger.php | 7 +++---- phpBB/includes/style/style.php | 7 ++++--- phpBB/install/index.php | 4 ++-- tests/template/template_inheritance_test.php | 4 ++-- tests/template/template_test_case.php | 4 ++-- 7 files changed, 17 insertions(+), 17 deletions(-) diff --git a/phpBB/common.php b/phpBB/common.php index 1e3f787611..c11d39d9a1 100644 --- a/phpBB/common.php +++ b/phpBB/common.php @@ -126,8 +126,8 @@ $phpbb_extension_manager = new phpbb_extension_manager($db, EXT_TABLE, $phpbb_ro // Initialize style $phpbb_style_resource_locator = new phpbb_style_resource_locator(); $phpbb_style_path_provider = new phpbb_style_extension_path_provider($phpbb_extension_manager, new phpbb_style_path_provider()); -$style = new phpbb_style($phpbb_root_path, $phpEx, $config, $user, $phpbb_style_resource_locator, $phpbb_style_path_provider); -$template = $style->template; +$template = new phpbb_style_template($phpbb_root_path, $phpEx, $config, $user, $phpbb_style_resource_locator, $phpbb_style_path_provider); +$style = new phpbb_style($phpbb_root_path, $phpEx, $config, $user, $phpbb_style_resource_locator, $phpbb_style_path_provider, $template); $phpbb_subscriber_loader = new phpbb_event_extension_subscriber_loader($phpbb_dispatcher, $phpbb_extension_manager); $phpbb_subscriber_loader->load(); diff --git a/phpBB/includes/bbcode.php b/phpBB/includes/bbcode.php index 2cae38022e..612ced8ad6 100644 --- a/phpBB/includes/bbcode.php +++ b/phpBB/includes/bbcode.php @@ -134,9 +134,9 @@ class bbcode $style_resource_locator = new phpbb_style_resource_locator(); $style_path_provider = new phpbb_style_extension_path_provider($phpbb_extension_manager, new phpbb_style_path_provider()); - $style = new phpbb_style($phpbb_root_path, $phpEx, $config, $user, $style_resource_locator, $style_path_provider); + $template = new phpbb_style_template($phpbb_root_path, $phpEx, $config, $user, $style_resource_locator, $style_path_provider); + $style = new phpbb_style($phpbb_root_path, $phpEx, $config, $user, $style_resource_locator, $style_path_provider, $template); $style->set_style(); - $template = $style->template; $template->set_filenames(array('bbcode.html' => 'bbcode.html')); $this->template_filename = $style_resource_locator->get_source_file_for_handle('bbcode.html'); } diff --git a/phpBB/includes/functions_messenger.php b/phpBB/includes/functions_messenger.php index 4d076a7957..aae200df55 100644 --- a/phpBB/includes/functions_messenger.php +++ b/phpBB/includes/functions_messenger.php @@ -210,9 +210,9 @@ class messenger { $style_resource_locator = new phpbb_style_resource_locator(); $style_path_provider = new phpbb_style_extension_path_provider($phpbb_extension_manager, new phpbb_style_path_provider()); - $this->tpl_msg[$template_lang . $template_file] = new phpbb_style($phpbb_root_path, $phpEx, $config, $user, $style_resource_locator, $style_path_provider); - $stl = &$this->tpl_msg[$template_lang . $template_file]; - $tpl = $stl->template; + $tpl = new phpbb_style_template($phpbb_root_path, $phpEx, $config, $user, $style_resource_locator, $style_path_provider); + $stl = new phpbb_style($phpbb_root_path, $phpEx, $config, $user, $style_resource_locator, $style_path_provider, $tpl); + $this->tpl_msg[$template_lang . $template_file] = $tpl; $fallback_template_path = false; @@ -238,7 +238,6 @@ class messenger } $this->tpl_obj = &$this->tpl_msg[$template_lang . $template_file]; - $this->tpl_obj = $this->tpl_obj->template; $this->vars = &$this->tpl_obj->_rootref; $this->tpl_msg = ''; diff --git a/phpBB/includes/style/style.php b/phpBB/includes/style/style.php index 265a45eca7..539a2642ee 100644 --- a/phpBB/includes/style/style.php +++ b/phpBB/includes/style/style.php @@ -25,7 +25,7 @@ class phpbb_style * @var phpbb_style_template Template class. * Handles everything related to templates. */ - public $template; + private $template; /** * @var string phpBB root path @@ -66,8 +66,9 @@ class phpbb_style * @param user $user current user * @param phpbb_style_resource_locator $locator style resource locator * @param phpbb_style_path_provider $provider style path provider + * @param phpbb_style_template $template template */ - public function __construct($phpbb_root_path, $phpEx, $config, $user, phpbb_style_resource_locator $locator, phpbb_style_path_provider_interface $provider) + public function __construct($phpbb_root_path, $phpEx, $config, $user, phpbb_style_resource_locator $locator, phpbb_style_path_provider_interface $provider, phpbb_style_template $template) { $this->phpbb_root_path = $phpbb_root_path; $this->phpEx = $phpEx; @@ -75,7 +76,7 @@ class phpbb_style $this->user = $user; $this->locator = $locator; $this->provider = $provider; - $this->template = new phpbb_style_template($this->phpbb_root_path, $this->phpEx, $this->config, $this->user, $this->locator, $this->provider); + $this->template = $template; } /** diff --git a/phpBB/install/index.php b/phpBB/install/index.php index fdce7234e5..6c32a322f8 100644 --- a/phpBB/install/index.php +++ b/phpBB/install/index.php @@ -204,10 +204,10 @@ $config = new phpbb_config(array( $phpbb_style_resource_locator = new phpbb_style_resource_locator(); $phpbb_style_path_provider = new phpbb_style_path_provider(); -$style = new phpbb_style($phpbb_root_path, $phpEx, $config, $user, $phpbb_style_resource_locator, $phpbb_style_path_provider); +$template = new phpbb_style_template($phpbb_root_path, $phpEx, $config, $user, $phpbb_style_resource_locator, $phpbb_style_path_provider); +$style = new phpbb_style($phpbb_root_path, $phpEx, $config, $user, $phpbb_style_resource_locator, $phpbb_style_path_provider, $template); $style->set_ext_dir_prefix('adm/'); $style->set_custom_style('admin', '../adm/style', ''); -$template = $style->template; $template->assign_var('T_ASSETS_PATH', '../assets'); $template->assign_var('T_TEMPLATE_PATH', '../adm/style'); diff --git a/tests/template/template_inheritance_test.php b/tests/template/template_inheritance_test.php index aa527a3eb5..3f5ec53953 100644 --- a/tests/template/template_inheritance_test.php +++ b/tests/template/template_inheritance_test.php @@ -73,8 +73,8 @@ class phpbb_template_template_inheritance_test extends phpbb_template_template_t $this->parent_template_path = dirname(__FILE__) . '/parent_templates'; $this->style_resource_locator = new phpbb_style_path_provider(); $this->style_provider = new phpbb_style_path_provider(); - $this->style = new phpbb_style($phpbb_root_path, $phpEx, $config, $user, $this->style_resource_locator, $this->style_provider); + $this->template = new phpbb_style_template($phpbb_root_path, $phpEx, $config, $user, $this->style_resource_locator, $this->style_provider); + $this->style = new phpbb_style($phpbb_root_path, $phpEx, $config, $user, $this->style_resource_locator, $this->style_provider, $this->template); $this->style->set_custom_style('tests', array($this->template_path, $this->parent_template_path), ''); - $this->template = $this->style->template; } } diff --git a/tests/template/template_test_case.php b/tests/template/template_test_case.php index f324736ba4..a2aedec41d 100644 --- a/tests/template/template_test_case.php +++ b/tests/template/template_test_case.php @@ -66,9 +66,9 @@ class phpbb_template_template_test_case extends phpbb_test_case $this->template_path = dirname(__FILE__) . '/templates'; $this->style_resource_locator = new phpbb_style_path_provider(); $this->style_provider = new phpbb_style_path_provider(); - $this->style = new phpbb_style($phpbb_root_path, $phpEx, $config, $user, $this->style_resource_locator, $this->style_provider); + $this->template = new phpbb_style_template($phpbb_root_path, $phpEx, $config, $user, $this->style_resource_locator, $this->style_provider); + $this->style = new phpbb_style($phpbb_root_path, $phpEx, $config, $user, $this->style_resource_locator, $this->style_provider, $this->template); $this->style->set_custom_style('tests', $this->template_path, ''); - $this->template = $this->style->template; } protected function setUp() From 377db78dcafb99ea65dca79777426db3117ec02c Mon Sep 17 00:00:00 2001 From: Vjacheslav Trushkin Date: Sat, 31 Mar 2012 18:16:53 +0300 Subject: [PATCH 039/114] [feature/merging-style-components] Fix for unit tests Fixing typo in template unit tests PHPBB3-10632 --- tests/template/template_inheritance_test.php | 2 +- tests/template/template_test_case.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/template/template_inheritance_test.php b/tests/template/template_inheritance_test.php index 3f5ec53953..7348da9a4a 100644 --- a/tests/template/template_inheritance_test.php +++ b/tests/template/template_inheritance_test.php @@ -71,7 +71,7 @@ class phpbb_template_template_inheritance_test extends phpbb_template_template_t $this->template_path = dirname(__FILE__) . '/templates'; $this->parent_template_path = dirname(__FILE__) . '/parent_templates'; - $this->style_resource_locator = new phpbb_style_path_provider(); + $this->style_resource_locator = new phpbb_style_resource_locator(); $this->style_provider = new phpbb_style_path_provider(); $this->template = new phpbb_style_template($phpbb_root_path, $phpEx, $config, $user, $this->style_resource_locator, $this->style_provider); $this->style = new phpbb_style($phpbb_root_path, $phpEx, $config, $user, $this->style_resource_locator, $this->style_provider, $this->template); diff --git a/tests/template/template_test_case.php b/tests/template/template_test_case.php index a2aedec41d..a87e531a07 100644 --- a/tests/template/template_test_case.php +++ b/tests/template/template_test_case.php @@ -64,7 +64,7 @@ class phpbb_template_template_test_case extends phpbb_test_case $config = new phpbb_config(array_merge($defaults, $new_config)); $this->template_path = dirname(__FILE__) . '/templates'; - $this->style_resource_locator = new phpbb_style_path_provider(); + $this->style_resource_locator = new phpbb_style_resource_locator(); $this->style_provider = new phpbb_style_path_provider(); $this->template = new phpbb_style_template($phpbb_root_path, $phpEx, $config, $user, $this->style_resource_locator, $this->style_provider); $this->style = new phpbb_style($phpbb_root_path, $phpEx, $config, $user, $this->style_resource_locator, $this->style_provider, $this->template); From 5d07b16ec647f51d51504cf9d6a0861a975ceb8e Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Sat, 31 Mar 2012 17:15:32 +0200 Subject: [PATCH 040/114] [feature/merging-style-components] Fix back link on install page When on install page and all styles are installed, fix back link to go to main styles page. PHPBB3-10632 --- phpBB/includes/acp/acp_styles.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/includes/acp/acp_styles.php b/phpBB/includes/acp/acp_styles.php index 9345ad470a..2772fb2217 100644 --- a/phpBB/includes/acp/acp_styles.php +++ b/phpBB/includes/acp/acp_styles.php @@ -611,7 +611,7 @@ class acp_styles // Show styles if (empty($styles)) { - trigger_error($user->lang['NO_UNINSTALLED_STYLE'] . adm_back_link($this->u_action), E_USER_NOTICE); + trigger_error($user->lang['NO_UNINSTALLED_STYLE'] . adm_back_link($this->u_base_action), E_USER_NOTICE); } usort($styles, 'acp_styles::sort_styles'); From 1be5bd8e1311a9dd859e6e685cdfa5979adf69a4 Mon Sep 17 00:00:00 2001 From: Vjacheslav Trushkin Date: Sat, 31 Mar 2012 18:38:37 +0300 Subject: [PATCH 041/114] [feature/merging-style-components] Fixing typo in database updater Fixing typo in database_update.php PHPBB3-10632 --- phpBB/install/database_update.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/install/database_update.php b/phpBB/install/database_update.php index 18ca4870fb..3235731d28 100644 --- a/phpBB/install/database_update.php +++ b/phpBB/install/database_update.php @@ -2274,7 +2274,7 @@ function change_database_data(&$no_updates, $version) 'cat' => 'ACP_ATTACHMENTS', ), 'install' => array( - 'base' => 'acp_styles' + 'base' => 'acp_styles', 'class' => 'acp', 'title' => 'ACP_STYLES_INSTALL', 'auth' => 'acl_a_styles', From 550ee7309a1d83711e4b9cf4abe3468807d84996 Mon Sep 17 00:00:00 2001 From: Vjacheslav Trushkin Date: Sat, 31 Mar 2012 18:53:49 +0300 Subject: [PATCH 042/114] [feature/merging-style-components] Fixing typos in database updater Yes, I failed... again. Fixing 2 more typos in database_update.php PHPBB3-10632 --- phpBB/install/database_update.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/phpBB/install/database_update.php b/phpBB/install/database_update.php index 3235731d28..583574a245 100644 --- a/phpBB/install/database_update.php +++ b/phpBB/install/database_update.php @@ -2281,14 +2281,14 @@ function change_database_data(&$no_updates, $version) 'cat' => 'ACP_STYLE_MANAGEMENT', ), 'edit' => array( - 'base' => 'acp_styles' + 'base' => 'acp_styles', 'class' => 'acp', 'title' => 'ACP_STYLES_EDIT', 'auth' => 'acl_a_styles', 'cat' => 'ACP_STYLE_MANAGEMENT', ), 'cache' => array( - 'base' => 'acp_styles' + 'base' => 'acp_styles', 'class' => 'acp', 'title' => 'ACP_STYLES_CACHE', 'auth' => 'acl_a_styles', From 6deb7b3671c29ab7ce1db6e11b5c6be0950d265f Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Sat, 31 Mar 2012 02:50:19 +0200 Subject: [PATCH 043/114] [feature/class-prefix] Rename user and session to phpbb_* PHPBB-10609 --- phpBB/common.php | 3 +- phpBB/docs/coding-guidelines.html | 2 +- phpBB/docs/hook_system.html | 4 +- phpBB/includes/functions.php | 2 +- phpBB/includes/functions_profile_fields.php | 2 +- phpBB/includes/session.php | 838 +----------------- phpBB/includes/user.php | 851 +++++++++++++++++++ phpBB/install/database_update.php | 3 +- phpBB/install/index.php | 3 +- tests/mock/session_testable.php | 3 +- tests/security/base.php | 4 +- tests/security/extract_current_page_test.php | 5 +- tests/security/redirect_test.php | 1 - tests/user/lang_test.php | 6 +- 14 files changed, 867 insertions(+), 860 deletions(-) create mode 100644 phpBB/includes/user.php diff --git a/phpBB/common.php b/phpBB/common.php index c11d39d9a1..c4430208dc 100644 --- a/phpBB/common.php +++ b/phpBB/common.php @@ -74,7 +74,6 @@ if (!empty($load_extensions) && function_exists('dl')) // Include files require($phpbb_root_path . 'includes/class_loader.' . $phpEx); -require($phpbb_root_path . 'includes/session.' . $phpEx); require($phpbb_root_path . 'includes/auth.' . $phpEx); require($phpbb_root_path . 'includes/functions.' . $phpEx); @@ -102,7 +101,7 @@ $phpbb_class_loader->set_cache($cache->get_driver()); // Instantiate some basic classes $phpbb_dispatcher = new phpbb_event_dispatcher(); $request = new phpbb_request(); -$user = new user(); +$user = new phpbb_user(); $auth = new auth(); $db = new $sql_db(); diff --git a/phpBB/docs/coding-guidelines.html b/phpBB/docs/coding-guidelines.html index e6dfe579e9..6d428916c7 100644 --- a/phpBB/docs/coding-guidelines.html +++ b/phpBB/docs/coding-guidelines.html @@ -248,7 +248,7 @@ PHPBB_QA (Set board to QA-Mode, which means the updater also c

    If the PHPBB_USE_BOARD_URL_PATH constant is set to true, phpBB uses generate_board_url() (this will return the boards url with the script path included) on all instances where web-accessible images are loaded. The exact locations are:

      -
    • /includes/session.php - user::img()
    • +
    • /includes/user.php - phpbb_user::img()
    • /includes/functions_content.php - smiley_text()
    diff --git a/phpBB/docs/hook_system.html b/phpBB/docs/hook_system.html index 1ac45e0cb5..6dd84bfc23 100644 --- a/phpBB/docs/hook_system.html +++ b/phpBB/docs/hook_system.html @@ -368,7 +368,7 @@ a:active { color: #368AD2; }

    In phpBB3 there are four functions you are able to hook into with your custom functions:

    -

    phpbb_user_session_handler(); which is called within user::setup after the session and the user object is correctly initialized.
    +

    phpbb_user_session_handler(); which is called within phpbb_user::setup after the session and the user object is correctly initialized.
    append_sid($url, $params = false, $is_amp = true, $session_id = false); which is called for building urls (appending the session id)
    $template->display($handle, $template); which is called directly before outputting the (not-yet-compiled) template.
    exit_handler(); which is called at the very end of phpBB3's execution.

    @@ -388,7 +388,7 @@ PHPBB_USE_BOARD_URL_PATH (use generate_board_url() for image paths instead of $p

    If the PHPBB_USE_BOARD_URL_PATH constant is set to true, phpBB uses generate_board_url() (this will return the boards url with the script path included) on all instances where web-accessible images are loaded. The exact locations are:

      -
    • /includes/session.php - user::img()
    • +
    • /includes/user.php - phpbb_user::img()
    • /includes/functions_content.php - smiley_text()
    diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 99740b753b..74db8cb8fd 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -4949,7 +4949,7 @@ function exit_handler() } /** -* Handler for init calls in phpBB. This function is called in user::setup(); +* Handler for init calls in phpBB. This function is called in phpbb_user::setup(); * This function supports hooks. */ function phpbb_user_session_handler() diff --git a/phpBB/includes/functions_profile_fields.php b/phpBB/includes/functions_profile_fields.php index 34d973b3a6..3399334f94 100644 --- a/phpBB/includes/functions_profile_fields.php +++ b/phpBB/includes/functions_profile_fields.php @@ -555,7 +555,7 @@ class custom_profile { global $user; // Date should display as the same date for every user regardless of timezone, so remove offset - // to compensate for the offset added by user::format_date() + // to compensate for the offset added by phpbb_user::format_date() return $user->format_date(gmmktime(0, 0, 0, $month, $day, $year) - ($user->timezone + $user->dst), $user->lang['DATE_FORMAT'], true); } diff --git a/phpBB/includes/session.php b/phpBB/includes/session.php index 2fd2efe9b2..bcdff54457 100644 --- a/phpBB/includes/session.php +++ b/phpBB/includes/session.php @@ -19,7 +19,7 @@ if (!defined('IN_PHPBB')) * Session class * @package phpBB3 */ -class session +class phpbb_session { var $cookie_data = array(); var $page = array(); @@ -1511,839 +1511,3 @@ class session $db->sql_query($sql); } } - - -/** -* Base user class -* -* This is the overarching class which contains (through session extend) -* all methods utilised for user functionality during a session. -* -* @package phpBB3 -*/ -class user extends session -{ - var $lang = array(); - var $help = array(); - var $theme = array(); - var $date_format; - var $timezone; - var $dst; - - var $lang_name = false; - var $lang_id = false; - var $lang_path; - var $img_lang; - var $img_array = array(); - - // Able to add new options (up to id 31) - var $keyoptions = array('viewimg' => 0, 'viewflash' => 1, 'viewsmilies' => 2, 'viewsigs' => 3, 'viewavatars' => 4, 'viewcensors' => 5, 'attachsig' => 6, 'bbcode' => 8, 'smilies' => 9, 'popuppm' => 10, 'sig_bbcode' => 15, 'sig_smilies' => 16, 'sig_links' => 17); - - /** - * Constructor to set the lang path - */ - function user() - { - global $phpbb_root_path; - - $this->lang_path = $phpbb_root_path . 'language/'; - } - - /** - * Function to set custom language path (able to use directory outside of phpBB) - * - * @param string $lang_path New language path used. - * @access public - */ - function set_custom_lang_path($lang_path) - { - $this->lang_path = $lang_path; - - if (substr($this->lang_path, -1) != '/') - { - $this->lang_path .= '/'; - } - } - - /** - * Setup basic user-specific items (style, language, ...) - */ - function setup($lang_set = false, $style_id = false) - { - global $db, $style, $template, $config, $auth, $phpEx, $phpbb_root_path, $cache; - - if ($this->data['user_id'] != ANONYMOUS) - { - $this->lang_name = (file_exists($this->lang_path . $this->data['user_lang'] . "/common.$phpEx")) ? $this->data['user_lang'] : basename($config['default_lang']); - - $this->date_format = $this->data['user_dateformat']; - $this->timezone = $this->data['user_timezone'] * 3600; - $this->dst = $this->data['user_dst'] * 3600; - } - else - { - $this->lang_name = basename($config['default_lang']); - $this->date_format = $config['default_dateformat']; - $this->timezone = $config['board_timezone'] * 3600; - $this->dst = $config['board_dst'] * 3600; - - /** - * If a guest user is surfing, we try to guess his/her language first by obtaining the browser language - * If re-enabled we need to make sure only those languages installed are checked - * Commented out so we do not loose the code. - - if ($request->header('Accept-Language')) - { - $accept_lang_ary = explode(',', $request->header('Accept-Language')); - - foreach ($accept_lang_ary as $accept_lang) - { - // Set correct format ... guess full xx_YY form - $accept_lang = substr($accept_lang, 0, 2) . '_' . strtoupper(substr($accept_lang, 3, 2)); - $accept_lang = basename($accept_lang); - - if (file_exists($this->lang_path . $accept_lang . "/common.$phpEx")) - { - $this->lang_name = $config['default_lang'] = $accept_lang; - break; - } - else - { - // No match on xx_YY so try xx - $accept_lang = substr($accept_lang, 0, 2); - $accept_lang = basename($accept_lang); - - if (file_exists($this->lang_path . $accept_lang . "/common.$phpEx")) - { - $this->lang_name = $config['default_lang'] = $accept_lang; - break; - } - } - } - } - */ - } - - // We include common language file here to not load it every time a custom language file is included - $lang = &$this->lang; - - // Do not suppress error if in DEBUG_EXTRA mode - $include_result = (defined('DEBUG_EXTRA')) ? (include $this->lang_path . $this->lang_name . "/common.$phpEx") : (@include $this->lang_path . $this->lang_name . "/common.$phpEx"); - - if ($include_result === false) - { - die('Language file ' . $this->lang_path . $this->lang_name . "/common.$phpEx" . " couldn't be opened."); - } - - $this->add_lang($lang_set); - unset($lang_set); - - $style_request = request_var('style', 0); - if ($style_request && $auth->acl_get('a_styles') && !defined('ADMIN_START')) - { - global $SID, $_EXTRA_URL; - - $style_id = $style_request; - $SID .= '&style=' . $style_id; - $_EXTRA_URL = array('style=' . $style_id); - } - else - { - // Set up style - $style_id = ($style_id) ? $style_id : ((!$config['override_user_style']) ? $this->data['user_style'] : $config['default_style']); - } - - $sql = 'SELECT * - FROM ' . STYLES_TABLE . " s - WHERE s.style_id = $style_id"; - $result = $db->sql_query($sql, 3600); - $this->theme = $db->sql_fetchrow($result); - $db->sql_freeresult($result); - - // User has wrong style - if (!$this->theme && $style_id == $this->data['user_style']) - { - $style_id = $this->data['user_style'] = $config['default_style']; - - $sql = 'UPDATE ' . USERS_TABLE . " - SET user_style = $style_id - WHERE user_id = {$this->data['user_id']}"; - $db->sql_query($sql); - - $sql = 'SELECT * - FROM ' . STYLES_TABLE . " s - WHERE s.style_id = $style_id"; - $result = $db->sql_query($sql, 3600); - $this->theme = $db->sql_fetchrow($result); - $db->sql_freeresult($result); - } - - if (!$this->theme) - { - trigger_error('Could not get style data', E_USER_ERROR); - } - - // Now parse the cfg file and cache it - $parsed_items = $cache->obtain_cfg_items($this->theme); - - // We are only interested in the theme configuration for now - $parsed_items = $parsed_items['theme']; - - $check_for = array( - 'pagination_sep' => (string) ', ' - ); - - foreach ($check_for as $key => $default_value) - { - $this->theme[$key] = (isset($parsed_items[$key])) ? $parsed_items[$key] : $default_value; - settype($this->theme[$key], gettype($default_value)); - - if (is_string($default_value)) - { - $this->theme[$key] = htmlspecialchars($this->theme[$key]); - } - } - - $style->set_style(); - - $this->img_lang = $this->lang_name; - - // Call phpbb_user_session_handler() in case external application want to "bend" some variables or replace classes... - // After calling it we continue script execution... - phpbb_user_session_handler(); - - // If this function got called from the error handler we are finished here. - if (defined('IN_ERROR_HANDLER')) - { - return; - } - - // Disable board if the install/ directory is still present - // For the brave development army we do not care about this, else we need to comment out this everytime we develop locally - if (!defined('DEBUG_EXTRA') && !defined('ADMIN_START') && !defined('IN_INSTALL') && !defined('IN_LOGIN') && file_exists($phpbb_root_path . 'install') && !is_file($phpbb_root_path . 'install')) - { - // Adjust the message slightly according to the permissions - if ($auth->acl_gets('a_', 'm_') || $auth->acl_getf_global('m_')) - { - $message = 'REMOVE_INSTALL'; - } - else - { - $message = (!empty($config['board_disable_msg'])) ? $config['board_disable_msg'] : 'BOARD_DISABLE'; - } - trigger_error($message); - } - - // Is board disabled and user not an admin or moderator? - if ($config['board_disable'] && !defined('IN_LOGIN') && !$auth->acl_gets('a_', 'm_') && !$auth->acl_getf_global('m_')) - { - if ($this->data['is_bot']) - { - send_status_line(503, 'Service Unavailable'); - } - - $message = (!empty($config['board_disable_msg'])) ? $config['board_disable_msg'] : 'BOARD_DISABLE'; - trigger_error($message); - } - - // Is load exceeded? - if ($config['limit_load'] && $this->load !== false) - { - if ($this->load > floatval($config['limit_load']) && !defined('IN_LOGIN') && !defined('IN_ADMIN')) - { - // Set board disabled to true to let the admins/mods get the proper notification - $config['board_disable'] = '1'; - - if (!$auth->acl_gets('a_', 'm_') && !$auth->acl_getf_global('m_')) - { - if ($this->data['is_bot']) - { - send_status_line(503, 'Service Unavailable'); - } - trigger_error('BOARD_UNAVAILABLE'); - } - } - } - - if (isset($this->data['session_viewonline'])) - { - // Make sure the user is able to hide his session - if (!$this->data['session_viewonline']) - { - // Reset online status if not allowed to hide the session... - if (!$auth->acl_get('u_hideonline')) - { - $sql = 'UPDATE ' . SESSIONS_TABLE . ' - SET session_viewonline = 1 - WHERE session_user_id = ' . $this->data['user_id']; - $db->sql_query($sql); - $this->data['session_viewonline'] = 1; - } - } - else if (!$this->data['user_allow_viewonline']) - { - // the user wants to hide and is allowed to -> cloaking device on. - if ($auth->acl_get('u_hideonline')) - { - $sql = 'UPDATE ' . SESSIONS_TABLE . ' - SET session_viewonline = 0 - WHERE session_user_id = ' . $this->data['user_id']; - $db->sql_query($sql); - $this->data['session_viewonline'] = 0; - } - } - } - - - // Does the user need to change their password? If so, redirect to the - // ucp profile reg_details page ... of course do not redirect if we're already in the ucp - if (!defined('IN_ADMIN') && !defined('ADMIN_START') && $config['chg_passforce'] && !empty($this->data['is_registered']) && $auth->acl_get('u_chgpasswd') && $this->data['user_passchg'] < time() - ($config['chg_passforce'] * 86400)) - { - if (strpos($this->page['query_string'], 'mode=reg_details') === false && $this->page['page_name'] != "ucp.$phpEx") - { - redirect(append_sid("{$phpbb_root_path}ucp.$phpEx", 'i=profile&mode=reg_details')); - } - } - - return; - } - - /** - * More advanced language substitution - * Function to mimic sprintf() with the possibility of using phpBB's language system to substitute nullar/singular/plural forms. - * Params are the language key and the parameters to be substituted. - * This function/functionality is inspired by SHS` and Ashe. - * - * Example call: $user->lang('NUM_POSTS_IN_QUEUE', 1); - * - * If the first parameter is an array, the elements are used as keys and subkeys to get the language entry: - * Example: $user->lang(array('datetime', 'AGO'), 1) uses $user->lang['datetime']['AGO'] as language entry. - */ - function lang() - { - $args = func_get_args(); - $key = $args[0]; - - if (is_array($key)) - { - $lang = &$this->lang[array_shift($key)]; - - foreach ($key as $_key) - { - $lang = &$lang[$_key]; - } - } - else - { - $lang = &$this->lang[$key]; - } - - // Return if language string does not exist - if (!isset($lang) || (!is_string($lang) && !is_array($lang))) - { - return $key; - } - - // If the language entry is a string, we simply mimic sprintf() behaviour - if (is_string($lang)) - { - if (sizeof($args) == 1) - { - return $lang; - } - - // Replace key with language entry and simply pass along... - $args[0] = $lang; - return call_user_func_array('sprintf', $args); - } - else if (sizeof($lang) == 0) - { - // If the language entry is an empty array, we just return the language key - return $args[0]; - } - - // It is an array... now handle different nullar/singular/plural forms - $key_found = false; - - // We now get the first number passed and will select the key based upon this number - for ($i = 1, $num_args = sizeof($args); $i < $num_args; $i++) - { - if (is_int($args[$i]) || is_float($args[$i])) - { - if ($args[$i] == 0 && isset($lang[0])) - { - // We allow each translation using plural forms to specify a version for the case of 0 things, - // so that "0 users" may be displayed as "No users". - $key_found = 0; - break; - } - else - { - $use_plural_form = $this->get_plural_form($args[$i]); - if (isset($lang[$use_plural_form])) - { - // The key we should use exists, so we use it. - $key_found = $use_plural_form; - } - else - { - // If the key we need to use does not exist, we fall back to the previous one. - $numbers = array_keys($lang); - - foreach ($numbers as $num) - { - if ($num > $use_plural_form) - { - break; - } - - $key_found = $num; - } - } - break; - } - } - } - - // Ok, let's check if the key was found, else use the last entry (because it is mostly the plural form) - if ($key_found === false) - { - $numbers = array_keys($lang); - $key_found = end($numbers); - } - - // Use the language string we determined and pass it to sprintf() - $args[0] = $lang[$key_found]; - return call_user_func_array('sprintf', $args); - } - - /** - * Determine which plural form we should use. - * For some languages this is not as simple as for English. - * - * @param $number int|float The number we want to get the plural case for. Float numbers are floored. - * @param $force_rule mixed False to use the plural rule of the language package - * or an integer to force a certain plural rule - * @return int The plural-case we need to use for the number plural-rule combination - */ - function get_plural_form($number, $force_rule = false) - { - $number = (int) $number; - - // Default to English system - $plural_rule = ($force_rule !== false) ? $force_rule : ((isset($this->lang['PLURAL_RULE'])) ? $this->lang['PLURAL_RULE'] : 1); - - return phpbb_get_plural_form($plural_rule, $number); - } - - /** - * Add Language Items - use_db and use_help are assigned where needed (only use them to force inclusion) - * - * @param mixed $lang_set specifies the language entries to include - * @param bool $use_db internal variable for recursion, do not use - * @param bool $use_help internal variable for recursion, do not use - * @param string $ext_name The extension to load language from, or empty for core files - * - * Examples: - * - * $lang_set = array('posting', 'help' => 'faq'); - * $lang_set = array('posting', 'viewtopic', 'help' => array('bbcode', 'faq')) - * $lang_set = array(array('posting', 'viewtopic'), 'help' => array('bbcode', 'faq')) - * $lang_set = 'posting' - * $lang_set = array('help' => 'faq', 'db' => array('help:faq', 'posting')) - * - */ - function add_lang($lang_set, $use_db = false, $use_help = false, $ext_name = '') - { - global $phpEx; - - if (is_array($lang_set)) - { - foreach ($lang_set as $key => $lang_file) - { - // Please do not delete this line. - // We have to force the type here, else [array] language inclusion will not work - $key = (string) $key; - - if ($key == 'db') - { - $this->add_lang($lang_file, true, $use_help, $ext_name); - } - else if ($key == 'help') - { - $this->add_lang($lang_file, $use_db, true, $ext_name); - } - else if (!is_array($lang_file)) - { - $this->set_lang($this->lang, $this->help, $lang_file, $use_db, $use_help, $ext_name); - } - else - { - $this->add_lang($lang_file, $use_db, $use_help, $ext_name); - } - } - unset($lang_set); - } - else if ($lang_set) - { - $this->set_lang($this->lang, $this->help, $lang_set, $use_db, $use_help, $ext_name); - } - } - - /** - * Add Language Items from an extension - use_db and use_help are assigned where needed (only use them to force inclusion) - * - * @param string $ext_name The extension to load language from, or empty for core files - * @param mixed $lang_set specifies the language entries to include - * @param bool $use_db internal variable for recursion, do not use - * @param bool $use_help internal variable for recursion, do not use - */ - function add_lang_ext($ext_name, $lang_set, $use_db = false, $use_help = false) - { - if ($ext_name === '/') - { - $ext_name = ''; - } - - $this->add_lang($lang_set, $use_db, $use_help, $ext_name); - } - - /** - * Set language entry (called by add_lang) - * @access private - */ - function set_lang(&$lang, &$help, $lang_file, $use_db = false, $use_help = false, $ext_name = '') - { - global $phpbb_root_path, $phpEx; - - // Make sure the language name is set (if the user setup did not happen it is not set) - if (!$this->lang_name) - { - global $config; - $this->lang_name = basename($config['default_lang']); - } - - // $lang == $this->lang - // $help == $this->help - // - add appropriate variables here, name them as they are used within the language file... - if (!$use_db) - { - if ($use_help && strpos($lang_file, '/') !== false) - { - $filename = dirname($lang_file) . '/help_' . basename($lang_file); - } - else - { - $filename = (($use_help) ? 'help_' : '') . $lang_file; - } - - if ($ext_name) - { - global $phpbb_extension_manager; - $ext_path = $phpbb_extension_manager->get_extension_path($ext_name, true); - - $lang_path = $ext_path . 'language/'; - } - else - { - $lang_path = $this->lang_path; - } - - if (strpos($phpbb_root_path . $filename, $lang_path . $this->lang_name . '/') === 0) - { - $language_filename = $phpbb_root_path . $filename; - } - else - { - $language_filename = $lang_path . $this->lang_name . '/' . $filename . '.' . $phpEx; - } - - if (!file_exists($language_filename)) - { - global $config; - - if ($this->lang_name == 'en') - { - // The user's selected language is missing the file, the board default's language is missing the file, and the file doesn't exist in /en. - $language_filename = str_replace($lang_path . 'en', $lang_path . $this->data['user_lang'], $language_filename); - trigger_error('Language file ' . $language_filename . ' couldn\'t be opened.', E_USER_ERROR); - } - else if ($this->lang_name == basename($config['default_lang'])) - { - // Fall back to the English Language - $this->lang_name = 'en'; - $this->set_lang($lang, $help, $lang_file, $use_db, $use_help, $ext_name); - } - else if ($this->lang_name == $this->data['user_lang']) - { - // Fall back to the board default language - $this->lang_name = basename($config['default_lang']); - $this->set_lang($lang, $help, $lang_file, $use_db, $use_help, $ext_name); - } - - // Reset the lang name - $this->lang_name = (file_exists($lang_path . $this->data['user_lang'] . "/common.$phpEx")) ? $this->data['user_lang'] : basename($config['default_lang']); - return; - } - - // Do not suppress error if in DEBUG_EXTRA mode - $include_result = (defined('DEBUG_EXTRA')) ? (include $language_filename) : (@include $language_filename); - - if ($include_result === false) - { - trigger_error('Language file ' . $language_filename . ' couldn\'t be opened.', E_USER_ERROR); - } - } - else if ($use_db) - { - // Get Database Language Strings - // Put them into $lang if nothing is prefixed, put them into $help if help: is prefixed - // For example: help:faq, posting - } - } - - /** - * Format user date - * - * @param int $gmepoch unix timestamp - * @param string $format date format in date() notation. | used to indicate relative dates, for example |d m Y|, h:i is translated to Today, h:i. - * @param bool $forcedate force non-relative date format. - * - * @return mixed translated date - */ - function format_date($gmepoch, $format = false, $forcedate = false) - { - static $midnight; - static $date_cache; - - $format = (!$format) ? $this->date_format : $format; - $now = time(); - $delta = $now - $gmepoch; - - if (!isset($date_cache[$format])) - { - // Is the user requesting a friendly date format (i.e. 'Today 12:42')? - $date_cache[$format] = array( - 'is_short' => strpos($format, '|'), - 'format_short' => substr($format, 0, strpos($format, '|')) . '||' . substr(strrchr($format, '|'), 1), - 'format_long' => str_replace('|', '', $format), - 'lang' => $this->lang['datetime'], - ); - - // Short representation of month in format? Some languages use different terms for the long and short format of May - if ((strpos($format, '\M') === false && strpos($format, 'M') !== false) || (strpos($format, '\r') === false && strpos($format, 'r') !== false)) - { - $date_cache[$format]['lang']['May'] = $this->lang['datetime']['May_short']; - } - } - - // Zone offset - $zone_offset = $this->timezone + $this->dst; - - // Show date < 1 hour ago as 'xx min ago' but not greater than 60 seconds in the future - // A small tolerence is given for times in the future but in the same minute are displayed as '< than a minute ago' - if ($delta < 3600 && $delta > -60 && ($delta >= -5 || (($now / 60) % 60) == (($gmepoch / 60) % 60)) && $date_cache[$format]['is_short'] !== false && !$forcedate && isset($this->lang['datetime']['AGO'])) - { - return $this->lang(array('datetime', 'AGO'), max(0, (int) floor($delta / 60))); - } - - if (!$midnight) - { - list($d, $m, $y) = explode(' ', gmdate('j n Y', time() + $zone_offset)); - $midnight = gmmktime(0, 0, 0, $m, $d, $y) - $zone_offset; - } - - if ($date_cache[$format]['is_short'] !== false && !$forcedate && !($gmepoch < $midnight - 86400 || $gmepoch > $midnight + 172800)) - { - $day = false; - - if ($gmepoch > $midnight + 86400) - { - $day = 'TOMORROW'; - } - else if ($gmepoch > $midnight) - { - $day = 'TODAY'; - } - else if ($gmepoch > $midnight - 86400) - { - $day = 'YESTERDAY'; - } - - if ($day !== false) - { - return str_replace('||', $this->lang['datetime'][$day], strtr(@gmdate($date_cache[$format]['format_short'], $gmepoch + $zone_offset), $date_cache[$format]['lang'])); - } - } - - return strtr(@gmdate($date_cache[$format]['format_long'], $gmepoch + $zone_offset), $date_cache[$format]['lang']); - } - - /** - * Get language id currently used by the user - */ - function get_iso_lang_id() - { - global $config, $db; - - if (!empty($this->lang_id)) - { - return $this->lang_id; - } - - if (!$this->lang_name) - { - $this->lang_name = $config['default_lang']; - } - - $sql = 'SELECT lang_id - FROM ' . LANG_TABLE . " - WHERE lang_iso = '" . $db->sql_escape($this->lang_name) . "'"; - $result = $db->sql_query($sql); - $this->lang_id = (int) $db->sql_fetchfield('lang_id'); - $db->sql_freeresult($result); - - return $this->lang_id; - } - - /** - * Get users profile fields - */ - function get_profile_fields($user_id) - { - global $db; - - if (isset($this->profile_fields)) - { - return; - } - - $sql = 'SELECT * - FROM ' . PROFILE_FIELDS_DATA_TABLE . " - WHERE user_id = $user_id"; - $result = $db->sql_query_limit($sql, 1); - $this->profile_fields = (!($row = $db->sql_fetchrow($result))) ? array() : $row; - $db->sql_freeresult($result); - } - - /** - * Specify/Get image - */ - function img($img, $alt = '') - { - $alt = (!empty($this->lang[$alt])) ? $this->lang[$alt] : $alt; - return '' . $alt . ''; - } - - /** - * Get option bit field from user options. - * - * @param int $key option key, as defined in $keyoptions property. - * @param int $data bit field value to use, or false to use $this->data['user_options'] - * @return bool true if the option is set in the bit field, false otherwise - */ - function optionget($key, $data = false) - { - $var = ($data !== false) ? $data : $this->data['user_options']; - return phpbb_optionget($this->keyoptions[$key], $var); - } - - /** - * Set option bit field for user options. - * - * @param int $key Option key, as defined in $keyoptions property. - * @param bool $value True to set the option, false to clear the option. - * @param int $data Current bit field value, or false to use $this->data['user_options'] - * @return int|bool If $data is false, the bit field is modified and - * written back to $this->data['user_options'], and - * return value is true if the bit field changed and - * false otherwise. If $data is not false, the new - * bitfield value is returned. - */ - function optionset($key, $value, $data = false) - { - $var = ($data !== false) ? $data : $this->data['user_options']; - - $new_var = phpbb_optionset($this->keyoptions[$key], $value, $var); - - if ($data === false) - { - if ($new_var != $var) - { - $this->data['user_options'] = $new_var; - return true; - } - else - { - return false; - } - } - else - { - return $new_var; - } - } - - /** - * Funtion to make the user leave the NEWLY_REGISTERED system group. - * @access public - */ - function leave_newly_registered() - { - global $db; - - if (empty($this->data['user_new'])) - { - return false; - } - - if (!function_exists('remove_newly_registered')) - { - global $phpbb_root_path, $phpEx; - - include($phpbb_root_path . 'includes/functions_user.' . $phpEx); - } - if ($group = remove_newly_registered($this->data['user_id'], $this->data)) - { - $this->data['group_id'] = $group; - - } - $this->data['user_permissions'] = ''; - $this->data['user_new'] = 0; - - return true; - } - - /** - * Returns all password protected forum ids the user is currently NOT authenticated for. - * - * @return array Array of forum ids - * @access public - */ - function get_passworded_forums() - { - global $db; - - $sql = 'SELECT f.forum_id, fa.user_id - FROM ' . FORUMS_TABLE . ' f - LEFT JOIN ' . FORUMS_ACCESS_TABLE . " fa - ON (fa.forum_id = f.forum_id - AND fa.session_id = '" . $db->sql_escape($this->session_id) . "') - WHERE f.forum_password <> ''"; - $result = $db->sql_query($sql); - - $forum_ids = array(); - while ($row = $db->sql_fetchrow($result)) - { - $forum_id = (int) $row['forum_id']; - - if ($row['user_id'] != $this->data['user_id']) - { - $forum_ids[$forum_id] = $forum_id; - } - } - $db->sql_freeresult($result); - - return $forum_ids; - } -} diff --git a/phpBB/includes/user.php b/phpBB/includes/user.php new file mode 100644 index 0000000000..1676f82ccb --- /dev/null +++ b/phpBB/includes/user.php @@ -0,0 +1,851 @@ + 0, 'viewflash' => 1, 'viewsmilies' => 2, 'viewsigs' => 3, 'viewavatars' => 4, 'viewcensors' => 5, 'attachsig' => 6, 'bbcode' => 8, 'smilies' => 9, 'popuppm' => 10, 'sig_bbcode' => 15, 'sig_smilies' => 16, 'sig_links' => 17); + + /** + * Constructor to set the lang path + */ + function __construct() + { + global $phpbb_root_path; + + $this->lang_path = $phpbb_root_path . 'language/'; + } + + /** + * Function to set custom language path (able to use directory outside of phpBB) + * + * @param string $lang_path New language path used. + * @access public + */ + function set_custom_lang_path($lang_path) + { + $this->lang_path = $lang_path; + + if (substr($this->lang_path, -1) != '/') + { + $this->lang_path .= '/'; + } + } + + /** + * Setup basic user-specific items (style, language, ...) + */ + function setup($lang_set = false, $style_id = false) + { + global $db, $style, $template, $config, $auth, $phpEx, $phpbb_root_path, $cache; + + if ($this->data['user_id'] != ANONYMOUS) + { + $this->lang_name = (file_exists($this->lang_path . $this->data['user_lang'] . "/common.$phpEx")) ? $this->data['user_lang'] : basename($config['default_lang']); + + $this->date_format = $this->data['user_dateformat']; + $this->timezone = $this->data['user_timezone'] * 3600; + $this->dst = $this->data['user_dst'] * 3600; + } + else + { + $this->lang_name = basename($config['default_lang']); + $this->date_format = $config['default_dateformat']; + $this->timezone = $config['board_timezone'] * 3600; + $this->dst = $config['board_dst'] * 3600; + + /** + * If a guest user is surfing, we try to guess his/her language first by obtaining the browser language + * If re-enabled we need to make sure only those languages installed are checked + * Commented out so we do not loose the code. + + if ($request->header('Accept-Language')) + { + $accept_lang_ary = explode(',', $request->header('Accept-Language')); + + foreach ($accept_lang_ary as $accept_lang) + { + // Set correct format ... guess full xx_YY form + $accept_lang = substr($accept_lang, 0, 2) . '_' . strtoupper(substr($accept_lang, 3, 2)); + $accept_lang = basename($accept_lang); + + if (file_exists($this->lang_path . $accept_lang . "/common.$phpEx")) + { + $this->lang_name = $config['default_lang'] = $accept_lang; + break; + } + else + { + // No match on xx_YY so try xx + $accept_lang = substr($accept_lang, 0, 2); + $accept_lang = basename($accept_lang); + + if (file_exists($this->lang_path . $accept_lang . "/common.$phpEx")) + { + $this->lang_name = $config['default_lang'] = $accept_lang; + break; + } + } + } + } + */ + } + + // We include common language file here to not load it every time a custom language file is included + $lang = &$this->lang; + + // Do not suppress error if in DEBUG_EXTRA mode + $include_result = (defined('DEBUG_EXTRA')) ? (include $this->lang_path . $this->lang_name . "/common.$phpEx") : (@include $this->lang_path . $this->lang_name . "/common.$phpEx"); + + if ($include_result === false) + { + die('Language file ' . $this->lang_path . $this->lang_name . "/common.$phpEx" . " couldn't be opened."); + } + + $this->add_lang($lang_set); + unset($lang_set); + + $style_request = request_var('style', 0); + if ($style_request && $auth->acl_get('a_styles') && !defined('ADMIN_START')) + { + global $SID, $_EXTRA_URL; + + $style_id = $style_request; + $SID .= '&style=' . $style_id; + $_EXTRA_URL = array('style=' . $style_id); + } + else + { + // Set up style + $style_id = ($style_id) ? $style_id : ((!$config['override_user_style']) ? $this->data['user_style'] : $config['default_style']); + } + + $sql = 'SELECT * + FROM ' . STYLES_TABLE . " s + WHERE s.style_id = $style_id"; + $result = $db->sql_query($sql, 3600); + $this->theme = $db->sql_fetchrow($result); + $db->sql_freeresult($result); + + // User has wrong style + if (!$this->theme && $style_id == $this->data['user_style']) + { + $style_id = $this->data['user_style'] = $config['default_style']; + + $sql = 'UPDATE ' . USERS_TABLE . " + SET user_style = $style_id + WHERE user_id = {$this->data['user_id']}"; + $db->sql_query($sql); + + $sql = 'SELECT * + FROM ' . STYLES_TABLE . " s + WHERE s.style_id = $style_id"; + $result = $db->sql_query($sql, 3600); + $this->theme = $db->sql_fetchrow($result); + $db->sql_freeresult($result); + } + + if (!$this->theme) + { + trigger_error('Could not get style data', E_USER_ERROR); + } + + // Now parse the cfg file and cache it + $parsed_items = $cache->obtain_cfg_items($this->theme); + + // We are only interested in the theme configuration for now + $parsed_items = $parsed_items['theme']; + + $check_for = array( + 'pagination_sep' => (string) ', ' + ); + + foreach ($check_for as $key => $default_value) + { + $this->theme[$key] = (isset($parsed_items[$key])) ? $parsed_items[$key] : $default_value; + settype($this->theme[$key], gettype($default_value)); + + if (is_string($default_value)) + { + $this->theme[$key] = htmlspecialchars($this->theme[$key]); + } + } + + $style->set_style(); + + $this->img_lang = $this->lang_name; + + // Call phpbb_user_session_handler() in case external application want to "bend" some variables or replace classes... + // After calling it we continue script execution... + phpbb_user_session_handler(); + + // If this function got called from the error handler we are finished here. + if (defined('IN_ERROR_HANDLER')) + { + return; + } + + // Disable board if the install/ directory is still present + // For the brave development army we do not care about this, else we need to comment out this everytime we develop locally + if (!defined('DEBUG_EXTRA') && !defined('ADMIN_START') && !defined('IN_INSTALL') && !defined('IN_LOGIN') && file_exists($phpbb_root_path . 'install') && !is_file($phpbb_root_path . 'install')) + { + // Adjust the message slightly according to the permissions + if ($auth->acl_gets('a_', 'm_') || $auth->acl_getf_global('m_')) + { + $message = 'REMOVE_INSTALL'; + } + else + { + $message = (!empty($config['board_disable_msg'])) ? $config['board_disable_msg'] : 'BOARD_DISABLE'; + } + trigger_error($message); + } + + // Is board disabled and user not an admin or moderator? + if ($config['board_disable'] && !defined('IN_LOGIN') && !$auth->acl_gets('a_', 'm_') && !$auth->acl_getf_global('m_')) + { + if ($this->data['is_bot']) + { + send_status_line(503, 'Service Unavailable'); + } + + $message = (!empty($config['board_disable_msg'])) ? $config['board_disable_msg'] : 'BOARD_DISABLE'; + trigger_error($message); + } + + // Is load exceeded? + if ($config['limit_load'] && $this->load !== false) + { + if ($this->load > floatval($config['limit_load']) && !defined('IN_LOGIN') && !defined('IN_ADMIN')) + { + // Set board disabled to true to let the admins/mods get the proper notification + $config['board_disable'] = '1'; + + if (!$auth->acl_gets('a_', 'm_') && !$auth->acl_getf_global('m_')) + { + if ($this->data['is_bot']) + { + send_status_line(503, 'Service Unavailable'); + } + trigger_error('BOARD_UNAVAILABLE'); + } + } + } + + if (isset($this->data['session_viewonline'])) + { + // Make sure the user is able to hide his session + if (!$this->data['session_viewonline']) + { + // Reset online status if not allowed to hide the session... + if (!$auth->acl_get('u_hideonline')) + { + $sql = 'UPDATE ' . SESSIONS_TABLE . ' + SET session_viewonline = 1 + WHERE session_user_id = ' . $this->data['user_id']; + $db->sql_query($sql); + $this->data['session_viewonline'] = 1; + } + } + else if (!$this->data['user_allow_viewonline']) + { + // the user wants to hide and is allowed to -> cloaking device on. + if ($auth->acl_get('u_hideonline')) + { + $sql = 'UPDATE ' . SESSIONS_TABLE . ' + SET session_viewonline = 0 + WHERE session_user_id = ' . $this->data['user_id']; + $db->sql_query($sql); + $this->data['session_viewonline'] = 0; + } + } + } + + + // Does the user need to change their password? If so, redirect to the + // ucp profile reg_details page ... of course do not redirect if we're already in the ucp + if (!defined('IN_ADMIN') && !defined('ADMIN_START') && $config['chg_passforce'] && !empty($this->data['is_registered']) && $auth->acl_get('u_chgpasswd') && $this->data['user_passchg'] < time() - ($config['chg_passforce'] * 86400)) + { + if (strpos($this->page['query_string'], 'mode=reg_details') === false && $this->page['page_name'] != "ucp.$phpEx") + { + redirect(append_sid("{$phpbb_root_path}ucp.$phpEx", 'i=profile&mode=reg_details')); + } + } + + return; + } + + /** + * More advanced language substitution + * Function to mimic sprintf() with the possibility of using phpBB's language system to substitute nullar/singular/plural forms. + * Params are the language key and the parameters to be substituted. + * This function/functionality is inspired by SHS` and Ashe. + * + * Example call: $user->lang('NUM_POSTS_IN_QUEUE', 1); + * + * If the first parameter is an array, the elements are used as keys and subkeys to get the language entry: + * Example: $user->lang(array('datetime', 'AGO'), 1) uses $user->lang['datetime']['AGO'] as language entry. + */ + function lang() + { + $args = func_get_args(); + $key = $args[0]; + + if (is_array($key)) + { + $lang = &$this->lang[array_shift($key)]; + + foreach ($key as $_key) + { + $lang = &$lang[$_key]; + } + } + else + { + $lang = &$this->lang[$key]; + } + + // Return if language string does not exist + if (!isset($lang) || (!is_string($lang) && !is_array($lang))) + { + return $key; + } + + // If the language entry is a string, we simply mimic sprintf() behaviour + if (is_string($lang)) + { + if (sizeof($args) == 1) + { + return $lang; + } + + // Replace key with language entry and simply pass along... + $args[0] = $lang; + return call_user_func_array('sprintf', $args); + } + else if (sizeof($lang) == 0) + { + // If the language entry is an empty array, we just return the language key + return $args[0]; + } + + // It is an array... now handle different nullar/singular/plural forms + $key_found = false; + + // We now get the first number passed and will select the key based upon this number + for ($i = 1, $num_args = sizeof($args); $i < $num_args; $i++) + { + if (is_int($args[$i]) || is_float($args[$i])) + { + if ($args[$i] == 0 && isset($lang[0])) + { + // We allow each translation using plural forms to specify a version for the case of 0 things, + // so that "0 users" may be displayed as "No users". + $key_found = 0; + break; + } + else + { + $use_plural_form = $this->get_plural_form($args[$i]); + if (isset($lang[$use_plural_form])) + { + // The key we should use exists, so we use it. + $key_found = $use_plural_form; + } + else + { + // If the key we need to use does not exist, we fall back to the previous one. + $numbers = array_keys($lang); + + foreach ($numbers as $num) + { + if ($num > $use_plural_form) + { + break; + } + + $key_found = $num; + } + } + break; + } + } + } + + // Ok, let's check if the key was found, else use the last entry (because it is mostly the plural form) + if ($key_found === false) + { + $numbers = array_keys($lang); + $key_found = end($numbers); + } + + // Use the language string we determined and pass it to sprintf() + $args[0] = $lang[$key_found]; + return call_user_func_array('sprintf', $args); + } + + /** + * Determine which plural form we should use. + * For some languages this is not as simple as for English. + * + * @param $number int|float The number we want to get the plural case for. Float numbers are floored. + * @param $force_rule mixed False to use the plural rule of the language package + * or an integer to force a certain plural rule + * @return int The plural-case we need to use for the number plural-rule combination + */ + function get_plural_form($number, $force_rule = false) + { + $number = (int) $number; + + // Default to English system + $plural_rule = ($force_rule !== false) ? $force_rule : ((isset($this->lang['PLURAL_RULE'])) ? $this->lang['PLURAL_RULE'] : 1); + + return phpbb_get_plural_form($plural_rule, $number); + } + + /** + * Add Language Items - use_db and use_help are assigned where needed (only use them to force inclusion) + * + * @param mixed $lang_set specifies the language entries to include + * @param bool $use_db internal variable for recursion, do not use + * @param bool $use_help internal variable for recursion, do not use + * @param string $ext_name The extension to load language from, or empty for core files + * + * Examples: + * + * $lang_set = array('posting', 'help' => 'faq'); + * $lang_set = array('posting', 'viewtopic', 'help' => array('bbcode', 'faq')) + * $lang_set = array(array('posting', 'viewtopic'), 'help' => array('bbcode', 'faq')) + * $lang_set = 'posting' + * $lang_set = array('help' => 'faq', 'db' => array('help:faq', 'posting')) + * + */ + function add_lang($lang_set, $use_db = false, $use_help = false, $ext_name = '') + { + global $phpEx; + + if (is_array($lang_set)) + { + foreach ($lang_set as $key => $lang_file) + { + // Please do not delete this line. + // We have to force the type here, else [array] language inclusion will not work + $key = (string) $key; + + if ($key == 'db') + { + $this->add_lang($lang_file, true, $use_help, $ext_name); + } + else if ($key == 'help') + { + $this->add_lang($lang_file, $use_db, true, $ext_name); + } + else if (!is_array($lang_file)) + { + $this->set_lang($this->lang, $this->help, $lang_file, $use_db, $use_help, $ext_name); + } + else + { + $this->add_lang($lang_file, $use_db, $use_help, $ext_name); + } + } + unset($lang_set); + } + else if ($lang_set) + { + $this->set_lang($this->lang, $this->help, $lang_set, $use_db, $use_help, $ext_name); + } + } + + /** + * Add Language Items from an extension - use_db and use_help are assigned where needed (only use them to force inclusion) + * + * @param string $ext_name The extension to load language from, or empty for core files + * @param mixed $lang_set specifies the language entries to include + * @param bool $use_db internal variable for recursion, do not use + * @param bool $use_help internal variable for recursion, do not use + */ + function add_lang_ext($ext_name, $lang_set, $use_db = false, $use_help = false) + { + if ($ext_name === '/') + { + $ext_name = ''; + } + + $this->add_lang($lang_set, $use_db, $use_help, $ext_name); + } + + /** + * Set language entry (called by add_lang) + * @access private + */ + function set_lang(&$lang, &$help, $lang_file, $use_db = false, $use_help = false, $ext_name = '') + { + global $phpbb_root_path, $phpEx; + + // Make sure the language name is set (if the user setup did not happen it is not set) + if (!$this->lang_name) + { + global $config; + $this->lang_name = basename($config['default_lang']); + } + + // $lang == $this->lang + // $help == $this->help + // - add appropriate variables here, name them as they are used within the language file... + if (!$use_db) + { + if ($use_help && strpos($lang_file, '/') !== false) + { + $filename = dirname($lang_file) . '/help_' . basename($lang_file); + } + else + { + $filename = (($use_help) ? 'help_' : '') . $lang_file; + } + + if ($ext_name) + { + global $phpbb_extension_manager; + $ext_path = $phpbb_extension_manager->get_extension_path($ext_name, true); + + $lang_path = $ext_path . 'language/'; + } + else + { + $lang_path = $this->lang_path; + } + + if (strpos($phpbb_root_path . $filename, $lang_path . $this->lang_name . '/') === 0) + { + $language_filename = $phpbb_root_path . $filename; + } + else + { + $language_filename = $lang_path . $this->lang_name . '/' . $filename . '.' . $phpEx; + } + + if (!file_exists($language_filename)) + { + global $config; + + if ($this->lang_name == 'en') + { + // The user's selected language is missing the file, the board default's language is missing the file, and the file doesn't exist in /en. + $language_filename = str_replace($lang_path . 'en', $lang_path . $this->data['user_lang'], $language_filename); + trigger_error('Language file ' . $language_filename . ' couldn\'t be opened.', E_USER_ERROR); + } + else if ($this->lang_name == basename($config['default_lang'])) + { + // Fall back to the English Language + $this->lang_name = 'en'; + $this->set_lang($lang, $help, $lang_file, $use_db, $use_help, $ext_name); + } + else if ($this->lang_name == $this->data['user_lang']) + { + // Fall back to the board default language + $this->lang_name = basename($config['default_lang']); + $this->set_lang($lang, $help, $lang_file, $use_db, $use_help, $ext_name); + } + + // Reset the lang name + $this->lang_name = (file_exists($lang_path . $this->data['user_lang'] . "/common.$phpEx")) ? $this->data['user_lang'] : basename($config['default_lang']); + return; + } + + // Do not suppress error if in DEBUG_EXTRA mode + $include_result = (defined('DEBUG_EXTRA')) ? (include $language_filename) : (@include $language_filename); + + if ($include_result === false) + { + trigger_error('Language file ' . $language_filename . ' couldn\'t be opened.', E_USER_ERROR); + } + } + else if ($use_db) + { + // Get Database Language Strings + // Put them into $lang if nothing is prefixed, put them into $help if help: is prefixed + // For example: help:faq, posting + } + } + + /** + * Format user date + * + * @param int $gmepoch unix timestamp + * @param string $format date format in date() notation. | used to indicate relative dates, for example |d m Y|, h:i is translated to Today, h:i. + * @param bool $forcedate force non-relative date format. + * + * @return mixed translated date + */ + function format_date($gmepoch, $format = false, $forcedate = false) + { + static $midnight; + static $date_cache; + + $format = (!$format) ? $this->date_format : $format; + $now = time(); + $delta = $now - $gmepoch; + + if (!isset($date_cache[$format])) + { + // Is the user requesting a friendly date format (i.e. 'Today 12:42')? + $date_cache[$format] = array( + 'is_short' => strpos($format, '|'), + 'format_short' => substr($format, 0, strpos($format, '|')) . '||' . substr(strrchr($format, '|'), 1), + 'format_long' => str_replace('|', '', $format), + 'lang' => $this->lang['datetime'], + ); + + // Short representation of month in format? Some languages use different terms for the long and short format of May + if ((strpos($format, '\M') === false && strpos($format, 'M') !== false) || (strpos($format, '\r') === false && strpos($format, 'r') !== false)) + { + $date_cache[$format]['lang']['May'] = $this->lang['datetime']['May_short']; + } + } + + // Zone offset + $zone_offset = $this->timezone + $this->dst; + + // Show date < 1 hour ago as 'xx min ago' but not greater than 60 seconds in the future + // A small tolerence is given for times in the future but in the same minute are displayed as '< than a minute ago' + if ($delta < 3600 && $delta > -60 && ($delta >= -5 || (($now / 60) % 60) == (($gmepoch / 60) % 60)) && $date_cache[$format]['is_short'] !== false && !$forcedate && isset($this->lang['datetime']['AGO'])) + { + return $this->lang(array('datetime', 'AGO'), max(0, (int) floor($delta / 60))); + } + + if (!$midnight) + { + list($d, $m, $y) = explode(' ', gmdate('j n Y', time() + $zone_offset)); + $midnight = gmmktime(0, 0, 0, $m, $d, $y) - $zone_offset; + } + + if ($date_cache[$format]['is_short'] !== false && !$forcedate && !($gmepoch < $midnight - 86400 || $gmepoch > $midnight + 172800)) + { + $day = false; + + if ($gmepoch > $midnight + 86400) + { + $day = 'TOMORROW'; + } + else if ($gmepoch > $midnight) + { + $day = 'TODAY'; + } + else if ($gmepoch > $midnight - 86400) + { + $day = 'YESTERDAY'; + } + + if ($day !== false) + { + return str_replace('||', $this->lang['datetime'][$day], strtr(@gmdate($date_cache[$format]['format_short'], $gmepoch + $zone_offset), $date_cache[$format]['lang'])); + } + } + + return strtr(@gmdate($date_cache[$format]['format_long'], $gmepoch + $zone_offset), $date_cache[$format]['lang']); + } + + /** + * Get language id currently used by the user + */ + function get_iso_lang_id() + { + global $config, $db; + + if (!empty($this->lang_id)) + { + return $this->lang_id; + } + + if (!$this->lang_name) + { + $this->lang_name = $config['default_lang']; + } + + $sql = 'SELECT lang_id + FROM ' . LANG_TABLE . " + WHERE lang_iso = '" . $db->sql_escape($this->lang_name) . "'"; + $result = $db->sql_query($sql); + $this->lang_id = (int) $db->sql_fetchfield('lang_id'); + $db->sql_freeresult($result); + + return $this->lang_id; + } + + /** + * Get users profile fields + */ + function get_profile_fields($user_id) + { + global $db; + + if (isset($this->profile_fields)) + { + return; + } + + $sql = 'SELECT * + FROM ' . PROFILE_FIELDS_DATA_TABLE . " + WHERE user_id = $user_id"; + $result = $db->sql_query_limit($sql, 1); + $this->profile_fields = (!($row = $db->sql_fetchrow($result))) ? array() : $row; + $db->sql_freeresult($result); + } + + /** + * Specify/Get image + */ + function img($img, $alt = '') + { + $alt = (!empty($this->lang[$alt])) ? $this->lang[$alt] : $alt; + return '' . $alt . ''; + } + + /** + * Get option bit field from user options. + * + * @param int $key option key, as defined in $keyoptions property. + * @param int $data bit field value to use, or false to use $this->data['user_options'] + * @return bool true if the option is set in the bit field, false otherwise + */ + function optionget($key, $data = false) + { + $var = ($data !== false) ? $data : $this->data['user_options']; + return phpbb_optionget($this->keyoptions[$key], $var); + } + + /** + * Set option bit field for user options. + * + * @param int $key Option key, as defined in $keyoptions property. + * @param bool $value True to set the option, false to clear the option. + * @param int $data Current bit field value, or false to use $this->data['user_options'] + * @return int|bool If $data is false, the bit field is modified and + * written back to $this->data['user_options'], and + * return value is true if the bit field changed and + * false otherwise. If $data is not false, the new + * bitfield value is returned. + */ + function optionset($key, $value, $data = false) + { + $var = ($data !== false) ? $data : $this->data['user_options']; + + $new_var = phpbb_optionset($this->keyoptions[$key], $value, $var); + + if ($data === false) + { + if ($new_var != $var) + { + $this->data['user_options'] = $new_var; + return true; + } + else + { + return false; + } + } + else + { + return $new_var; + } + } + + /** + * Funtion to make the user leave the NEWLY_REGISTERED system group. + * @access public + */ + function leave_newly_registered() + { + global $db; + + if (empty($this->data['user_new'])) + { + return false; + } + + if (!function_exists('remove_newly_registered')) + { + global $phpbb_root_path, $phpEx; + + include($phpbb_root_path . 'includes/functions_user.' . $phpEx); + } + if ($group = remove_newly_registered($this->data['user_id'], $this->data)) + { + $this->data['group_id'] = $group; + + } + $this->data['user_permissions'] = ''; + $this->data['user_new'] = 0; + + return true; + } + + /** + * Returns all password protected forum ids the user is currently NOT authenticated for. + * + * @return array Array of forum ids + * @access public + */ + function get_passworded_forums() + { + global $db; + + $sql = 'SELECT f.forum_id, fa.user_id + FROM ' . FORUMS_TABLE . ' f + LEFT JOIN ' . FORUMS_ACCESS_TABLE . " fa + ON (fa.forum_id = f.forum_id + AND fa.session_id = '" . $db->sql_escape($this->session_id) . "') + WHERE f.forum_password <> ''"; + $result = $db->sql_query($sql); + + $forum_ids = array(); + while ($row = $db->sql_fetchrow($result)) + { + $forum_id = (int) $row['forum_id']; + + if ($row['user_id'] != $this->data['user_id']) + { + $forum_ids[$forum_id] = $forum_id; + } + } + $db->sql_freeresult($result); + + return $forum_ids; + } +} diff --git a/phpBB/install/database_update.php b/phpBB/install/database_update.php index 18ca4870fb..fb5e79358d 100644 --- a/phpBB/install/database_update.php +++ b/phpBB/install/database_update.php @@ -84,7 +84,6 @@ if (!empty($load_extensions) && function_exists('dl')) // Include files require($phpbb_root_path . 'includes/class_loader.' . $phpEx); -require($phpbb_root_path . 'includes/session.' . $phpEx); require($phpbb_root_path . 'includes/auth.' . $phpEx); require($phpbb_root_path . 'includes/functions.' . $phpEx); @@ -122,7 +121,7 @@ $phpbb_class_loader->set_cache($cache->get_driver()); $phpbb_dispatcher = new phpbb_event_dispatcher(); $request = new phpbb_request(); -$user = new user(); +$user = new phpbb_user(); $db = new $sql_db(); // make sure request_var uses this request instance diff --git a/phpBB/install/index.php b/phpBB/install/index.php index 6c32a322f8..d3cb68e82e 100644 --- a/phpBB/install/index.php +++ b/phpBB/install/index.php @@ -76,7 +76,6 @@ require($phpbb_root_path . 'includes/functions.' . $phpEx); phpbb_require_updated('includes/functions_content.' . $phpEx, true); include($phpbb_root_path . 'includes/auth.' . $phpEx); -include($phpbb_root_path . 'includes/session.' . $phpEx); include($phpbb_root_path . 'includes/functions_admin.' . $phpEx); include($phpbb_root_path . 'includes/utf/utf_tools.' . $phpEx); require($phpbb_root_path . 'includes/functions_install.' . $phpEx); @@ -178,7 +177,7 @@ $sub = request_var('sub', ''); // Set PHP error handler to ours set_error_handler(defined('PHPBB_MSG_HANDLER') ? PHPBB_MSG_HANDLER : 'msg_handler'); -$user = new user(); +$user = new phpbb_user(); $auth = new auth(); // Add own hook handler, if present. :o diff --git a/tests/mock/session_testable.php b/tests/mock/session_testable.php index 70a58fb6cc..56ff8c8b32 100644 --- a/tests/mock/session_testable.php +++ b/tests/mock/session_testable.php @@ -8,7 +8,6 @@ */ require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php'; -require_once dirname(__FILE__) . '/../../phpBB/includes/session.php'; /** * Extends the session class to overwrite the setting of cookies. @@ -17,7 +16,7 @@ require_once dirname(__FILE__) . '/../../phpBB/includes/session.php'; * test it without warnings about sent headers. This class only stores cookie * data for later verification. */ -class phpbb_mock_session_testable extends session +class phpbb_mock_session_testable extends phpbb_session { private $_cookies = array(); diff --git a/tests/security/base.php b/tests/security/base.php index f7f3f9f661..82e4dda9d0 100644 --- a/tests/security/base.php +++ b/tests/security/base.php @@ -41,13 +41,13 @@ abstract class phpbb_security_test_base extends phpbb_test_case $request = new phpbb_mock_request(array(), array(), array(), $server); // Set no user and trick a bit to circumvent errors - $user = new user(); + $user = new phpbb_user(); $user->lang = true; $user->browser = $server['HTTP_USER_AGENT']; $user->referer = ''; $user->forwarded_for = ''; $user->host = $server['HTTP_HOST']; - $user->page = session::extract_current_page($phpbb_root_path); + $user->page = phpbb_session::extract_current_page($phpbb_root_path); } protected function tearDown() diff --git a/tests/security/extract_current_page_test.php b/tests/security/extract_current_page_test.php index 00fc3b5841..b4a475ffb3 100644 --- a/tests/security/extract_current_page_test.php +++ b/tests/security/extract_current_page_test.php @@ -10,7 +10,6 @@ require_once dirname(__FILE__) . '/base.php'; require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php'; -require_once dirname(__FILE__) . '/../../phpBB/includes/session.php'; class phpbb_security_extract_current_page_test extends phpbb_security_test_base { @@ -34,7 +33,7 @@ class phpbb_security_extract_current_page_test extends phpbb_security_test_base 'QUERY_STRING' => $query_string, )); - $result = session::extract_current_page('./'); + $result = phpbb_session::extract_current_page('./'); $label = 'Running extract_current_page on ' . $query_string . ' with PHP_SELF filled.'; $this->assertEquals($expected, $result['query_string'], $label); @@ -52,7 +51,7 @@ class phpbb_security_extract_current_page_test extends phpbb_security_test_base 'QUERY_STRING' => $query_string, )); - $result = session::extract_current_page('./'); + $result = phpbb_session::extract_current_page('./'); $label = 'Running extract_current_page on ' . $query_string . ' with REQUEST_URI filled.'; $this->assertEquals($expected, $result['query_string'], $label); diff --git a/tests/security/redirect_test.php b/tests/security/redirect_test.php index 634a506ab9..da318209e2 100644 --- a/tests/security/redirect_test.php +++ b/tests/security/redirect_test.php @@ -10,7 +10,6 @@ require_once dirname(__FILE__) . '/base.php'; require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php'; -require_once dirname(__FILE__) . '/../../phpBB/includes/session.php'; class phpbb_security_redirect_test extends phpbb_security_test_base { diff --git a/tests/user/lang_test.php b/tests/user/lang_test.php index f0ea76f342..d7ff451a70 100644 --- a/tests/user/lang_test.php +++ b/tests/user/lang_test.php @@ -7,13 +7,11 @@ * */ -require_once dirname(__FILE__) . '/../../phpBB/includes/session.php'; - class phpbb_user_lang_test extends phpbb_test_case { public function test_user_lang_sprintf() { - $user = new user; + $user = new phpbb_user; $user->lang = array( 'FOO' => 'BAR', 'BARZ' => 'PENG', @@ -95,7 +93,7 @@ class phpbb_user_lang_test extends phpbb_test_case $this->assertEquals($user->lang('ARRY', 1, 's', 2), '1 post'); // ticket PHPBB3-10345 - different plural rules, not just 0/1/2+ - $user = new user; + $user = new phpbb_user; $user->lang = array( 'PLURAL_RULE' => 13, 'ARRY' => array( From 9236dd4c471a6f7655bd00ae422a13013a400ac4 Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Sat, 31 Mar 2012 02:54:39 +0200 Subject: [PATCH 044/114] [feature/class-prefix] Rename auth => phpbb_auth PHPBB3-10609 --- phpBB/common.php | 3 +-- phpBB/docs/auth_api.html | 2 +- phpBB/includes/acp/acp_permissions.php | 2 +- phpBB/includes/acp/acp_users.php | 2 +- phpBB/includes/acp/auth.php | 4 ++-- phpBB/includes/{ => auth}/auth.php | 2 +- phpBB/includes/functions_privmsgs.php | 2 +- phpBB/includes/mcp/mcp_warn.php | 4 ++-- phpBB/includes/ucp/ucp_remind.php | 2 +- phpBB/install/database_update.php | 1 - phpBB/install/index.php | 3 +-- 11 files changed, 12 insertions(+), 15 deletions(-) rename phpBB/includes/{ => auth}/auth.php (99%) diff --git a/phpBB/common.php b/phpBB/common.php index c4430208dc..b3b8d7e4f7 100644 --- a/phpBB/common.php +++ b/phpBB/common.php @@ -74,7 +74,6 @@ if (!empty($load_extensions) && function_exists('dl')) // Include files require($phpbb_root_path . 'includes/class_loader.' . $phpEx); -require($phpbb_root_path . 'includes/auth.' . $phpEx); require($phpbb_root_path . 'includes/functions.' . $phpEx); require($phpbb_root_path . 'includes/functions_content.' . $phpEx); @@ -102,7 +101,7 @@ $phpbb_class_loader->set_cache($cache->get_driver()); $phpbb_dispatcher = new phpbb_event_dispatcher(); $request = new phpbb_request(); $user = new phpbb_user(); -$auth = new auth(); +$auth = new phpbb_auth(); $db = new $sql_db(); // make sure request_var uses this request instance diff --git a/phpBB/docs/auth_api.html b/phpBB/docs/auth_api.html index 40a63eaa9d..2302140030 100644 --- a/phpBB/docs/auth_api.html +++ b/phpBB/docs/auth_api.html @@ -86,7 +86,7 @@

    To use any methods contained with the auth class it first needs to be instantiated. This is best achieved early in the execution of the script in the following manner:

    -$auth = new auth();
    +$auth = new phpbb_auth();
     	

    Once an instance of the class has been created you are free to call the various methods it contains. Please note that should you wish to use the auth_admin methods you will need to instantiate this separately but in the same way.

    diff --git a/phpBB/includes/acp/acp_permissions.php b/phpBB/includes/acp/acp_permissions.php index 150b67b8f7..d728744c04 100644 --- a/phpBB/includes/acp/acp_permissions.php +++ b/phpBB/includes/acp/acp_permissions.php @@ -1105,7 +1105,7 @@ class acp_permissions { if ($user_id != $user->data['user_id']) { - $auth2 = new auth(); + $auth2 = new phpbb_auth(); $auth2->acl($userdata); $auth_setting = $auth2->acl_get($permission); } diff --git a/phpBB/includes/acp/acp_users.php b/phpBB/includes/acp/acp_users.php index cf6716c322..44717452e8 100644 --- a/phpBB/includes/acp/acp_users.php +++ b/phpBB/includes/acp/acp_users.php @@ -1554,7 +1554,7 @@ class acp_users || $user_row['user_allow_viewonline'] && !$sql_ary['user_allow_viewonline']) { // We also need to check if the user has the permission to cloak. - $user_auth = new auth(); + $user_auth = new phpbb_auth(); $user_auth->acl($user_row); $session_sql_ary = array( diff --git a/phpBB/includes/acp/auth.php b/phpBB/includes/acp/auth.php index 8f99450776..7d9fd267ff 100644 --- a/phpBB/includes/acp/auth.php +++ b/phpBB/includes/acp/auth.php @@ -19,7 +19,7 @@ if (!defined('IN_PHPBB')) * ACP Permission/Auth class * @package phpBB3 */ -class auth_admin extends auth +class auth_admin extends phpbb_auth { /** * Init auth settings @@ -130,7 +130,7 @@ class auth_admin extends auth { if ($user->data['user_id'] != $userdata['user_id']) { - $auth2 = new auth(); + $auth2 = new phpbb_auth(); $auth2->acl($userdata); } else diff --git a/phpBB/includes/auth.php b/phpBB/includes/auth/auth.php similarity index 99% rename from phpBB/includes/auth.php rename to phpBB/includes/auth/auth.php index 11e86a50fe..e3bccaf47b 100644 --- a/phpBB/includes/auth.php +++ b/phpBB/includes/auth/auth.php @@ -19,7 +19,7 @@ if (!defined('IN_PHPBB')) * Permission/Auth class * @package phpBB3 */ -class auth +class phpbb_auth { var $acl = array(); var $cache = array(); diff --git a/phpBB/includes/functions_privmsgs.php b/phpBB/includes/functions_privmsgs.php index a6fb87536a..434349714b 100644 --- a/phpBB/includes/functions_privmsgs.php +++ b/phpBB/includes/functions_privmsgs.php @@ -343,7 +343,7 @@ function check_rule(&$rules, &$rule_row, &$message_row, $user_id) $userdata = $db->sql_fetchrow($result); $db->sql_freeresult($result); - $auth2 = new auth(); + $auth2 = new phpbb_auth(); $auth2->acl($userdata); if (!$auth2->acl_get('a_') && !$auth2->acl_get('m_') && !$auth2->acl_getf_global('m_')) diff --git a/phpBB/includes/mcp/mcp_warn.php b/phpBB/includes/mcp/mcp_warn.php index d8e655000f..9d838790a0 100644 --- a/phpBB/includes/mcp/mcp_warn.php +++ b/phpBB/includes/mcp/mcp_warn.php @@ -251,7 +251,7 @@ class mcp_warn // Check if can send a notification if ($config['allow_privmsg']) { - $auth2 = new auth(); + $auth2 = new phpbb_auth(); $auth2->acl($user_row); $s_can_notify = ($auth2->acl_get('u_readpm')) ? true : false; unset($auth2); @@ -374,7 +374,7 @@ class mcp_warn // Check if can send a notification if ($config['allow_privmsg']) { - $auth2 = new auth(); + $auth2 = new phpbb_auth(); $auth2->acl($user_row); $s_can_notify = ($auth2->acl_get('u_readpm')) ? true : false; unset($auth2); diff --git a/phpBB/includes/ucp/ucp_remind.php b/phpBB/includes/ucp/ucp_remind.php index bcd4e261fe..4f65ed1866 100644 --- a/phpBB/includes/ucp/ucp_remind.php +++ b/phpBB/includes/ucp/ucp_remind.php @@ -66,7 +66,7 @@ class ucp_remind } // Check users permissions - $auth2 = new auth(); + $auth2 = new phpbb_auth(); $auth2->acl($user_row); if (!$auth2->acl_get('u_chgpasswd')) diff --git a/phpBB/install/database_update.php b/phpBB/install/database_update.php index fb5e79358d..96d984c04c 100644 --- a/phpBB/install/database_update.php +++ b/phpBB/install/database_update.php @@ -84,7 +84,6 @@ if (!empty($load_extensions) && function_exists('dl')) // Include files require($phpbb_root_path . 'includes/class_loader.' . $phpEx); -require($phpbb_root_path . 'includes/auth.' . $phpEx); require($phpbb_root_path . 'includes/functions.' . $phpEx); diff --git a/phpBB/install/index.php b/phpBB/install/index.php index d3cb68e82e..13ab30a9fa 100644 --- a/phpBB/install/index.php +++ b/phpBB/install/index.php @@ -75,7 +75,6 @@ require($phpbb_root_path . 'includes/functions.' . $phpEx); phpbb_require_updated('includes/functions_content.' . $phpEx, true); -include($phpbb_root_path . 'includes/auth.' . $phpEx); include($phpbb_root_path . 'includes/functions_admin.' . $phpEx); include($phpbb_root_path . 'includes/utf/utf_tools.' . $phpEx); require($phpbb_root_path . 'includes/functions_install.' . $phpEx); @@ -178,7 +177,7 @@ $sub = request_var('sub', ''); set_error_handler(defined('PHPBB_MSG_HANDLER') ? PHPBB_MSG_HANDLER : 'msg_handler'); $user = new phpbb_user(); -$auth = new auth(); +$auth = new phpbb_auth(); // Add own hook handler, if present. :o if (file_exists($phpbb_root_path . 'includes/hooks/index.' . $phpEx)) From b8b342be2d238616b96ace9acbe8af2e18ba1e7a Mon Sep 17 00:00:00 2001 From: Richard Foote Date: Sat, 31 Mar 2012 12:46:44 -0400 Subject: [PATCH 045/114] [Ticket/10675] Correct language string ATTACH_DISK_FULL Add period to ATTACH_DISK_FULL language string PHPBB3-10675 --- phpBB/language/en/posting.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/language/en/posting.php b/phpBB/language/en/posting.php index dd0ba7fc6d..24f3204c57 100644 --- a/phpBB/language/en/posting.php +++ b/phpBB/language/en/posting.php @@ -42,7 +42,7 @@ $lang = array_merge($lang, array( 'ADD_POLL' => 'Poll creation', 'ADD_POLL_EXPLAIN' => 'If you do not want to add a poll to your topic leave the fields blank.', 'ALREADY_DELETED' => 'Sorry but this message is already deleted.', - 'ATTACH_DISK_FULL' => 'There is not enough free disk space to post this attachment', + 'ATTACH_DISK_FULL' => 'There is not enough free disk space to post this attachment.', 'ATTACH_QUOTA_REACHED' => 'Sorry, the board attachment quota has been reached.', 'ATTACH_SIG' => 'Attach a signature (signatures can be altered via the UCP)', From b3f46b9565117940b79c7530a1c21336cd072073 Mon Sep 17 00:00:00 2001 From: Vjacheslav Trushkin Date: Sat, 31 Mar 2012 21:20:18 +0300 Subject: [PATCH 046/114] [ticket/10735] Changing locator paths structure Changing locator paths to 2 dimensional array PHPBB3-10735 --- phpBB/includes/extension/finder.php | 18 +++-- .../style/extension_path_provider.php | 36 +++++----- phpBB/includes/style/path_provider.php | 16 +---- .../style/path_provider_interface.php | 7 -- phpBB/includes/style/resource_locator.php | 66 ++++++++----------- phpBB/includes/style/style.php | 4 +- 6 files changed, 62 insertions(+), 85 deletions(-) diff --git a/phpBB/includes/extension/finder.php b/phpBB/includes/extension/finder.php index 23b9f1c658..87ca40917d 100644 --- a/phpBB/includes/extension/finder.php +++ b/phpBB/includes/extension/finder.php @@ -270,11 +270,12 @@ class phpbb_extension_finder * Finds all directories matching the configured options * * @param bool $cache Whether the result should be cached + * @param bool $extension_keys Whether the result should have extension name as array key * @return array An array of paths to found directories */ - public function get_directories($cache = true) + public function get_directories($cache = true, $extension_keys = false) { - return $this->find_with_root_path($cache, true); + return $this->find_with_root_path($cache, true, $extension_keys); } /** @@ -294,16 +295,25 @@ class phpbb_extension_finder * @param bool $cache Whether the result should be cached * @param bool $is_dir Directories will be returned when true, only files * otherwise + * @param bool $extension_keys If true, result will be associative array + * with extension name as key * @return array An array of paths to found items */ - protected function find_with_root_path($cache = true, $is_dir = false) + protected function find_with_root_path($cache = true, $is_dir = false, $extension_keys = false) { $items = $this->find($cache, $is_dir); $result = array(); foreach ($items as $item => $ext_name) { - $result[] = $this->phpbb_root_path . $item; + if ($extension_keys) + { + $result[$ext_name] = $this->phpbb_root_path . $item; + } + else + { + $result[] = $this->phpbb_root_path . $item; + } } return $result; diff --git a/phpBB/includes/style/extension_path_provider.php b/phpBB/includes/style/extension_path_provider.php index 1fb6580ce1..4eac300424 100644 --- a/phpBB/includes/style/extension_path_provider.php +++ b/phpBB/includes/style/extension_path_provider.php @@ -82,22 +82,26 @@ class phpbb_style_extension_path_provider extends phpbb_extension_provider imple $directories = array(); $finder = $this->extension_manager->get_finder(); - foreach ($this->base_path_provider as $path) + foreach ($this->base_path_provider as $key => $paths) { - if ($path && !phpbb_is_absolute($path)) + if ($key == 'style') { - $directories = array_merge($directories, $finder - ->directory('/' . $this->ext_dir_prefix . $path) - ->get_directories() - ); + foreach ($paths as $path) + { + $directories['style'][] = $path; + if ($path && !phpbb_is_absolute($path)) + { + $result = $finder->directory('/' . $this->ext_dir_prefix . $path) + ->get_directories(true, true); + foreach ($result as $ext => $ext_path) + { + $directories[$ext][] = $ext_path; + } + } + } } } - foreach ($this->base_path_provider as $path) - { - $directories[] = $path; - } - return $directories; } @@ -112,14 +116,4 @@ class phpbb_style_extension_path_provider extends phpbb_extension_provider imple $this->base_path_provider->set_styles($styles); $this->items = null; } - - /** - * Retrieves the path to the main style passed into set_styles() - * - * @return string Main style path - */ - public function get_main_style_path() - { - return $this->base_path_provider->get_main_style_path(); - } } diff --git a/phpBB/includes/style/path_provider.php b/phpBB/includes/style/path_provider.php index c229af92ba..731d682e88 100644 --- a/phpBB/includes/style/path_provider.php +++ b/phpBB/includes/style/path_provider.php @@ -24,7 +24,6 @@ if (!defined('IN_PHPBB')) */ class phpbb_style_path_provider implements IteratorAggregate, phpbb_style_path_provider_interface { - protected $main_style_name = ''; protected $paths = array(); /** @@ -41,25 +40,14 @@ class phpbb_style_path_provider implements IteratorAggregate, phpbb_style_path_p * Overwrites the current style paths * * The first element of the passed styles map, is considered the main - * style and can be retrieved through get_main_style_path(). + * style. * * @param array $styles An array of style paths. The first element is the main style. * @return null */ public function set_styles(array $styles) { - $this->paths = $styles; - $this->main_style_path = $this->paths[0]; - } - - /** - * Retrieves the path to the main style passed into set_styles() - * - * @return string Main style path - */ - public function get_main_style_path() - { - return $this->main_style_path; + $this->paths = array('style' => $styles); } /** diff --git a/phpBB/includes/style/path_provider_interface.php b/phpBB/includes/style/path_provider_interface.php index 7ae94e17f4..1a6153a4d3 100644 --- a/phpBB/includes/style/path_provider_interface.php +++ b/phpBB/includes/style/path_provider_interface.php @@ -39,11 +39,4 @@ interface phpbb_style_path_provider_interface extends Traversable * @return null */ public function set_styles(array $styles); - - /** - * Retrieves the path to the main style passed into set_styles() - * - * @return string Main style path - */ - public function get_main_style_path(); } diff --git a/phpBB/includes/style/resource_locator.php b/phpBB/includes/style/resource_locator.php index af261534c3..39505cedb5 100644 --- a/phpBB/includes/style/resource_locator.php +++ b/phpBB/includes/style/resource_locator.php @@ -38,12 +38,6 @@ class phpbb_style_resource_locator */ private $roots = array(); - /** - * Index of the main style in the roots array. - * @var int - */ - private $main_root_id = 0; - /** * Location of templates directory within style directories. * Must have trailing slash. Empty if templates are stored in root @@ -69,17 +63,6 @@ class phpbb_style_resource_locator */ private $filenames = array(); - /** - * Set main style location (must have been added through set_paths first). - * - * @param string $style_path Path to style directory - * @return null - */ - public function set_main_style($style_path) - { - $this->main_root_id = array_search($style_path, $this->roots, true); - } - /** * Sets the list of style paths * @@ -95,16 +78,18 @@ class phpbb_style_resource_locator $this->roots = array(); $this->files = array(); $this->filenames = array(); - $this->main_root_id = 0; - foreach ($style_paths as $path) + foreach ($style_paths as $key => $paths) { - // Make sure $path has no ending slash - if (substr($path, -1) === '/') + foreach ($paths as $path) { - $path = substr($path, 0, -1); + // Make sure $path has no ending slash + if (substr($path, -1) === '/') + { + $path = substr($path, 0, -1); + } + $this->roots[$key][] = $path; } - $this->roots[] = $path; } } @@ -125,9 +110,12 @@ class phpbb_style_resource_locator $this->filename[$handle] = $filename; - foreach ($this->roots as $root_index => $root) + foreach ($this->roots as $root_key => $root_paths) { - $this->files[$root_index][$handle] = $root . '/' . $this->template_path . $filename; + foreach ($root_paths as $root_index => $root) + { + $this->files[$root_key][$root_index][$handle] = $root . '/' . $this->template_path . $filename; + } } } } @@ -174,12 +162,12 @@ class phpbb_style_resource_locator public function get_virtual_source_file_for_handle($handle) { // If we don't have a file assigned to this handle, die. - if (!isset($this->files[$this->main_root_id][$handle])) + if (!isset($this->files['style'][0][$handle])) { trigger_error("style resource locator: No file specified for handle $handle", E_USER_ERROR); } - $source_file = $this->files[$this->main_root_id][$handle]; + $source_file = $this->files['style'][0][$handle]; return $source_file; } @@ -202,26 +190,28 @@ class phpbb_style_resource_locator public function get_source_file_for_handle($handle) { // If we don't have a file assigned to this handle, die. - if (!isset($this->files[$this->main_root_id][$handle])) + if (!isset($this->files['style'][0][$handle])) { trigger_error("style resource locator: No file specified for handle $handle", E_USER_ERROR); } // locate a source file that exists - $source_file = $this->files[0][$handle]; + $source_file = $this->files['style'][0][$handle]; $tried = $source_file; - for ($i = 1, $n = count($this->roots); $i < $n && !file_exists($source_file); $i++) + foreach ($this->roots as $root_key => $root_paths) { - $source_file = $this->files[$i][$handle]; - $tried .= ', ' . $source_file; + foreach ($root_paths as $root_index => $root) + { + $source_file = $this->files[$root_key][$root_index][$handle]; + if (file_exists($source_file)) + { + return $source_file; + } + $tried .= ', ' . $source_file; + } } // search failed - if (!file_exists($source_file)) - { - trigger_error("style resource locator: File for handle $handle does not exist. Could not find: $tried", E_USER_ERROR); - } - - return $source_file; + trigger_error("style resource locator: File for handle $handle does not exist. Could not find: $tried", E_USER_ERROR); } } diff --git a/phpBB/includes/style/style.php b/phpBB/includes/style/style.php index 539a2642ee..dc1e71dff6 100644 --- a/phpBB/includes/style/style.php +++ b/phpBB/includes/style/style.php @@ -92,6 +92,9 @@ class phpbb_style $paths[] = $this->get_style_path($dir); } + // Add 'all' path, used as last fallback path by hooks and extensions + $paths[] = $this->get_style_path('all'); + return $this->set_custom_style($style_name, $paths); } @@ -113,7 +116,6 @@ class phpbb_style $this->provider->set_styles($paths); $this->locator->set_paths($this->provider); - $this->locator->set_main_style($this->provider->get_main_style_path()); $this->template->cachepath = $this->phpbb_root_path . 'cache/tpl_' . str_replace('_', '-', $name) . '_'; From 2ce73baeab35adc3515a04c1db38af62c98d5c93 Mon Sep 17 00:00:00 2001 From: Vjacheslav Trushkin Date: Sat, 31 Mar 2012 22:07:04 +0300 Subject: [PATCH 047/114] [ticket/10733] Extending get_source_file_for_handle Extending resource locator's function get_source_file_for_handle to find all files. This modified function should be used by template events to locate all templates before compiling them. PHPBB3-10733 --- phpBB/includes/style/resource_locator.php | 31 ++++++++++++++++++++--- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/phpBB/includes/style/resource_locator.php b/phpBB/includes/style/resource_locator.php index 39505cedb5..1b35752111 100644 --- a/phpBB/includes/style/resource_locator.php +++ b/phpBB/includes/style/resource_locator.php @@ -185,9 +185,12 @@ class phpbb_style_resource_locator * handle to a path without any filesystem or styles tree checks. * * @param string $handle Template handle (i.e. "friendly" template name) + * @param bool $find_all If true, each root path will be checked and function + * will return array of files instead of string and will not + * trigger a error if template does not exist * @return string Source file path */ - public function get_source_file_for_handle($handle) + public function get_source_file_for_handle($handle, $find_all = false) { // If we don't have a file assigned to this handle, die. if (!isset($this->files['style'][0][$handle])) @@ -198,20 +201,40 @@ class phpbb_style_resource_locator // locate a source file that exists $source_file = $this->files['style'][0][$handle]; $tried = $source_file; + $found = false; + $found_all = array(); foreach ($this->roots as $root_key => $root_paths) { foreach ($root_paths as $root_index => $root) { $source_file = $this->files[$root_key][$root_index][$handle]; + $tried .= ', ' . $source_file; if (file_exists($source_file)) { - return $source_file; + $found = true; + break; + } + } + if ($found) + { + if ($find_all) + { + $found_all[] = $source_file; + $found = false; + } + else + { + break; } - $tried .= ', ' . $source_file; } } // search failed - trigger_error("style resource locator: File for handle $handle does not exist. Could not find: $tried", E_USER_ERROR); + if (!$found && !$find_all) + { + trigger_error("style resource locator: File for handle $handle does not exist. Could not find: $tried", E_USER_ERROR); + } + + return ($find_all) ? $found_all : $source_file; } } From 5ccd6915e3e8af30856319d84a48dde074fdbaee Mon Sep 17 00:00:00 2001 From: David King Date: Sat, 31 Mar 2012 15:52:16 -0400 Subject: [PATCH 048/114] [feature/qrpreview] Do not error or show preview if no text is entered PHPBB3-10726 --- phpBB/posting.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/phpBB/posting.php b/phpBB/posting.php index 71ba353e89..7f57f693af 100644 --- a/phpBB/posting.php +++ b/phpBB/posting.php @@ -38,7 +38,7 @@ $load = (isset($_POST['load'])) ? true : false; $delete = (isset($_POST['delete'])) ? true : false; $cancel = (isset($_POST['cancel']) && !isset($_POST['save'])) ? true : false; -$refresh = (isset($_POST['add_file']) || isset($_POST['delete_file']) || isset($_POST['cancel_unglobalise']) || $save || $load) ? true : false; +$refresh = (isset($_POST['add_file']) || isset($_POST['delete_file']) || isset($_POST['cancel_unglobalise']) || $save || $load || $preview) ? true : false; $mode = ($delete && !$preview && !$refresh && $submit) ? 'delete' : request_var('mode', ''); $error = $post_data = array(); @@ -1198,8 +1198,8 @@ if (!sizeof($error) && $preview) 'PREVIEW_MESSAGE' => $preview_message, 'PREVIEW_SIGNATURE' => $preview_signature, - 'S_DISPLAY_PREVIEW' => true) - ); + 'S_DISPLAY_PREVIEW' => !empty($preview_message), + )); } } From f80512f1066ebfc09d2a4ffac412c56a3fb247de Mon Sep 17 00:00:00 2001 From: Vjacheslav Trushkin Date: Sun, 1 Apr 2012 09:52:55 +0300 Subject: [PATCH 049/114] [ticket/10733] Adding functions to locate resources Adding $style->locate() and $template->locate() functions PHPBB3-10733 --- phpBB/includes/style/resource_locator.php | 51 +++++++++++++++++++++++ phpBB/includes/style/style.php | 28 +++++++++++++ phpBB/includes/style/template.php | 36 ++++++++++++++++ 3 files changed, 115 insertions(+) diff --git a/phpBB/includes/style/resource_locator.php b/phpBB/includes/style/resource_locator.php index 1b35752111..3e6dd5d6aa 100644 --- a/phpBB/includes/style/resource_locator.php +++ b/phpBB/includes/style/resource_locator.php @@ -237,4 +237,55 @@ class phpbb_style_resource_locator return ($find_all) ? $found_all : $source_file; } + + /** + * Locates source file path, accounting for styles tree and verifying that + * the path exists. + * + * Unlike previous functions, this function works without template handle + * and it can search for more than one file. If more than one file name is + * specified, it will return location of file that it finds first. + * + * @param array $files List of files to locate. + * @param bool $return_default Determines what to return if file does not + * exist. If true, function will return location where file is + * supposed to be. If false, function will return false. + * @param bool $return_full_path If true, function will return full path + * to file. If false, function will return file name. This + * parameter can be used to check which one of set of files + * is available. + * @return string or boolean Source file path if file exists or $return_default is + * true. False if file does not exist and $return_default is false + */ + public function get_first_file_location($files, $return_default = false, $return_full_path = true) + { + // set default value + $default_result = false; + + // check all available paths + foreach ($this->roots as $root_paths) + { + foreach ($root_paths as $path) + { + // check all files + foreach ($files as $filename) + { + $source_file = $path . '/' . $filename; + if (file_exists($source_file)) + { + return ($return_full_path) ? $source_file : $filename; + } + + // assign first file as result if $return_default is true + if ($return_default && $default_result === false) + { + $default_result = $source_file; + } + } + } + } + + // search failed + return $default_result; + } } diff --git a/phpBB/includes/style/style.php b/phpBB/includes/style/style.php index dc1e71dff6..5ac61c9f10 100644 --- a/phpBB/includes/style/style.php +++ b/phpBB/includes/style/style.php @@ -150,4 +150,32 @@ class phpbb_style { $this->provider->set_ext_dir_prefix($ext_dir_prefix); } + + /** + * Locates source file path, accounting for styles tree and verifying that + * the path exists. + * + * @param string or array $files List of files to locate. If there is only + * one file, $files can be a string to make code easier to read. + * @param bool $return_default Determines what to return if file does not + * exist. If true, function will return location where file is + * supposed to be. If false, function will return false. + * @param bool $return_full_path If true, function will return full path + * to file. If false, function will return file name. This + * parameter can be used to check which one of set of files + * is available. + * @return string or boolean Source file path if file exists or $return_default is + * true. False if file does not exist and $return_default is false + */ + public function locate($files, $return_default = false, $return_full_path = true) + { + // convert string to array + if (is_string($files)) + { + $files = array($files); + } + + // use resource locator to find files + return $this->locator->get_first_file_location($files, $return_default, $return_full_path); + } } diff --git a/phpBB/includes/style/template.php b/phpBB/includes/style/template.php index 21a2e821dd..aebf1da603 100644 --- a/phpBB/includes/style/template.php +++ b/phpBB/includes/style/template.php @@ -456,4 +456,40 @@ class phpbb_style_template } include($file); } + + /** + * Locates source template path, accounting for styles tree and verifying that + * the path exists. + * + * @param string or array $files List of templates to locate. If there is only + * one template, $files can be a string to make code easier to read. + * @param bool $return_default Determines what to return if template does not + * exist. If true, function will return location where template is + * supposed to be. If false, function will return false. + * @param bool $return_full_path If true, function will return full path + * to template. If false, function will return template file name. + * This parameter can be used to check which one of set of template + * files is available. + * @return string or boolean Source template path if template exists or $return_default is + * true. False if template does not exist and $return_default is false + */ + public function locate($files, $return_default = false, $return_full_path = true) + { + // add tempalte path prefix + $templates = array(); + if (is_string($files)) + { + $templates[] = $this->template_path . $files; + } + else + { + foreach ($files as $file) + { + $templates[] = $this->template_path . $file; + } + } + + // use resource locator to find files + return $this->locator->get_first_file_location($templates, $return_default, $return_full_path); + } } From 2509853ca530b3b5e0d5b2e10080eeba5a29d937 Mon Sep 17 00:00:00 2001 From: Vjacheslav Trushkin Date: Sun, 1 Apr 2012 09:53:23 +0300 Subject: [PATCH 050/114] [ticket/10733] Adding test for locator Adding test for $template->locate PHPBB3-10733 --- tests/template/template_locate_test.php | 84 +++++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 tests/template/template_locate_test.php diff --git a/tests/template/template_locate_test.php b/tests/template/template_locate_test.php new file mode 100644 index 0000000000..591a6afe0c --- /dev/null +++ b/tests/template/template_locate_test.php @@ -0,0 +1,84 @@ +setup_engine(); + + // Locate template + $result = $this->template->locate($files, $return_default, $return_full_path); + $this->assertEquals($result, $expected); + } + + protected function setup_engine(array $new_config = array()) + { + global $phpbb_root_path, $phpEx, $user; + + $defaults = $this->config_defaults(); + $config = new phpbb_config(array_merge($defaults, $new_config)); + + $this->template_path = dirname(__FILE__) . '/templates'; + $this->parent_template_path = dirname(__FILE__) . '/parent_templates'; + $this->style_resource_locator = new phpbb_style_resource_locator(); + $this->style_provider = new phpbb_style_path_provider(); + $this->template = new phpbb_style_template($phpbb_root_path, $phpEx, $config, $user, $this->style_resource_locator, $this->style_provider); + $this->style = new phpbb_style($phpbb_root_path, $phpEx, $config, $user, $this->style_resource_locator, $this->style_provider, $this->template); + $this->style->set_custom_style('tests', array($this->template_path, $this->parent_template_path), ''); + } +} From a7d0ef90ea921b2ed876bb933bfa022863771a6e Mon Sep 17 00:00:00 2001 From: Vjacheslav Trushkin Date: Sun, 1 Apr 2012 10:58:24 +0300 Subject: [PATCH 051/114] [ticket/10665] INCLUDEJS template tag Implementing INLCUDEJS template tag in style classes PHPBB3-10665 --- phpBB/includes/style/template.php | 21 +++++++- phpBB/includes/style/template_compile.php | 32 +++++++++++- phpBB/includes/style/template_filter.php | 61 ++++++++++++++++++++++- 3 files changed, 109 insertions(+), 5 deletions(-) diff --git a/phpBB/includes/style/template.php b/phpBB/includes/style/template.php index aebf1da603..4586e8dbf9 100644 --- a/phpBB/includes/style/template.php +++ b/phpBB/includes/style/template.php @@ -288,7 +288,7 @@ class phpbb_style_template return new phpbb_style_template_renderer_include($output_file, $this); } - $compile = new phpbb_style_template_compile($this->config['tpl_allow_php']); + $compile = new phpbb_style_template_compile($this->config['tpl_allow_php'], $this->locator, $this->phpbb_root_path); if ($compile->compile_file_to_file($source_file, $output_file) !== false) { @@ -492,4 +492,23 @@ class phpbb_style_template // use resource locator to find files return $this->locator->get_first_file_location($templates, $return_default, $return_full_path); } + + /** + * Include JS file + * + * @param string $file file name + * @param bool $locate True if file needs to be located + */ + function _js_include($file, $locate = false) + { + // Locate file + if ($locate) + { + $file = $this->locator->get_first_file_location(array($file), true, true); + } + + // Add HTML code + $code = ''; + $this->context->append_var('SCRIPTS', $code); + } } diff --git a/phpBB/includes/style/template_compile.php b/phpBB/includes/style/template_compile.php index 3ef3fffc00..bd9e18e102 100644 --- a/phpBB/includes/style/template_compile.php +++ b/phpBB/includes/style/template_compile.php @@ -25,6 +25,13 @@ stream_filter_register('phpbb_template', 'phpbb_style_template_filter'); */ class phpbb_style_template_compile { + /** + * Array of parameters to forward to template filter + * + * @var array + */ + private $filter_params; + /** * Whether tags are allowed * @@ -32,14 +39,31 @@ class phpbb_style_template_compile */ private $allow_php; + /** + * Style resource locator + * + * @var phpbb_style_resource_locator + */ + private $locator; + + /** + * @var string phpBB root path + */ + private $phpbb_root_path; + /** * Constructor. * * @param bool @allow_php Whether PHP code will be allowed in templates (inline PHP code, PHP tag and INCLUDEPHP tag) + * @param phpbb_style_resource_locator $locator Resource locator + * @param string $phpbb_root_path Path to phpBB root directory */ - public function __construct($allow_php) + public function __construct($allow_php, $locator, $phpbb_root_path) { + $this->filter_params = array(); $this->allow_php = $allow_php; + $this->locator = $locator; + $this->phpbb_root_path = $phpbb_root_path; } /** @@ -116,7 +140,11 @@ class phpbb_style_template_compile */ private function compile_stream_to_stream($source_stream, $dest_stream) { - stream_filter_append($source_stream, 'phpbb_template', null, array('allow_php' => $this->allow_php)); + $params = $this->filter_params; + $params['allow_php'] = $this->allow_php; + $params['locator'] = $this->locator; + $params['phpbb_root_path'] = $this->phpbb_root_path; + stream_filter_append($source_stream, 'phpbb_template', null, $params); stream_copy_to_stream($source_stream, $dest_stream); } } diff --git a/phpBB/includes/style/template_filter.php b/phpBB/includes/style/template_filter.php index 04fe85e07f..d62ad0ba1e 100644 --- a/phpBB/includes/style/template_filter.php +++ b/phpBB/includes/style/template_filter.php @@ -75,6 +75,18 @@ class phpbb_style_template_filter extends php_user_filter */ private $allow_php; + /** + * Resource locator. + * + * @var phpbb_template_locator + */ + private $locator; + + /** + * @var string phpBB root path + */ + private $phpbb_root_path; + /** * Stream filter * @@ -126,14 +138,16 @@ class phpbb_style_template_filter extends php_user_filter /** * Initializer, called on creation. * - * Get the allow_php option from params, which is passed - * to stream_filter_append. + * Get the allow_php option, root directory and locator from params, + * which are passed to stream_filter_append. */ public function onCreate() { $this->chunk = ''; $this->in_php = false; $this->allow_php = $this->params['allow_php']; + $this->locator = $this->params['locator']; + $this->phpbb_root_path = $this->params['phpbb_root_path']; return true; } @@ -281,6 +295,10 @@ class phpbb_style_template_filter extends php_user_filter return ($this->allow_php) ? 'compile_tag_include_php($matches[2]) . ' ?>' : ''; break; + case 'INCLUDEJS': + return 'compile_tag_include_js($matches[2]) . ' ?>'; + break; + case 'PHP': if ($this->allow_php) { @@ -856,6 +874,45 @@ class phpbb_style_template_filter extends php_user_filter return $tokens; } + /** + * Compile INCLUDEJS tag + * + * @param string $tag_args Expression given with INCLUDEJS in source template + * @return string compiled template code + */ + private function compile_tag_include_js($tag_args) + { + // Process dynamic includes + if ($tag_args[0] == '{') + { + $var = $this->get_varref($tag_args, $is_expr); + if (!$is_expr) + { + return " \$_template->_js_include($var, true);"; + } + return ''; + } + + // Locate file + $filename = $this->locator->get_first_file_location(array($tag_args), false, true); + + if ($filename === false) + { + // File does not exist, find it during run time + return ' $_template->_js_include(\'' . addslashes($tag_args) . '\', true); '; + } + + if (substr($filename, 0, strlen($this->phpbb_root_path)) != $this->phpbb_root_path) + { + // Absolute path, include as is + return ' $_template->_js_include(\'' . addslashes($filename) . '\', false); '; + } + + // Relative path, remove root path from it + $filename = substr($filename, strlen($this->phpbb_root_path)); + return ' global $phpbb_root_path; $_template->_js_include($phpbb_root_path . \'' . addslashes($filename) . '\', false); '; + } + /** * Generates a reference to the given variable inside the given (possibly nested) * block namespace. This is a string of the form: From 2225efc5609add8baf0dc0e7867d9f9f0fae4245 Mon Sep 17 00:00:00 2001 From: Vjacheslav Trushkin Date: Sun, 1 Apr 2012 10:58:59 +0300 Subject: [PATCH 052/114] [ticket/10665] INCLUDEJS template changes Implementing INLCUDEJS template tag in styles PHPBB3-10665 --- phpBB/styles/prosilver/template/overall_footer.html | 3 ++- phpBB/styles/prosilver/template/simple_footer.html | 1 + phpBB/styles/subsilver2/template/overall_footer.html | 1 + phpBB/styles/subsilver2/template/simple_footer.html | 1 + 4 files changed, 5 insertions(+), 1 deletion(-) diff --git a/phpBB/styles/prosilver/template/overall_footer.html b/phpBB/styles/prosilver/template/overall_footer.html index 1561bae26a..47071ba4df 100644 --- a/phpBB/styles/prosilver/template/overall_footer.html +++ b/phpBB/styles/prosilver/template/overall_footer.html @@ -52,7 +52,8 @@ - + +{SCRIPTS} diff --git a/phpBB/styles/prosilver/template/simple_footer.html b/phpBB/styles/prosilver/template/simple_footer.html index 3458d02495..549c31cfb6 100644 --- a/phpBB/styles/prosilver/template/simple_footer.html +++ b/phpBB/styles/prosilver/template/simple_footer.html @@ -8,6 +8,7 @@ +{SCRIPTS} diff --git a/phpBB/styles/subsilver2/template/overall_footer.html b/phpBB/styles/subsilver2/template/overall_footer.html index 9b0b95372e..77b11034b9 100644 --- a/phpBB/styles/subsilver2/template/overall_footer.html +++ b/phpBB/styles/subsilver2/template/overall_footer.html @@ -10,6 +10,7 @@ +{SCRIPTS} diff --git a/phpBB/styles/subsilver2/template/simple_footer.html b/phpBB/styles/subsilver2/template/simple_footer.html index b51be3ac4c..4a65bafd1c 100644 --- a/phpBB/styles/subsilver2/template/simple_footer.html +++ b/phpBB/styles/subsilver2/template/simple_footer.html @@ -7,6 +7,7 @@ +{SCRIPTS} From 38c988fb5997f947976ca4c12e3e0d57d1e82b60 Mon Sep 17 00:00:00 2001 From: Vjacheslav Trushkin Date: Sun, 1 Apr 2012 11:16:57 +0300 Subject: [PATCH 053/114] [ticket/10665] Changing template compiler test Adding new constructor parameters to template compiler test PHPBB3-10665 --- tests/template/template_compile_test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/template/template_compile_test.php b/tests/template/template_compile_test.php index fb158cabd5..e2264fb1b7 100644 --- a/tests/template/template_compile_test.php +++ b/tests/template/template_compile_test.php @@ -16,7 +16,7 @@ class phpbb_template_template_compile_test extends phpbb_test_case protected function setUp() { - $this->template_compile = new phpbb_style_template_compile(false); + $this->template_compile = new phpbb_style_template_compile(false, null, ''); $this->template_path = dirname(__FILE__) . '/templates'; } From 4b2ede433e9336cf115fdd41e5c88738b03aa448 Mon Sep 17 00:00:00 2001 From: Vjacheslav Trushkin Date: Sun, 1 Apr 2012 11:17:13 +0300 Subject: [PATCH 054/114] [ticket/10665] INCLUDEJS unit test Adding INLCUDEJS test PHPBB3-10665 --- tests/template/template_includejs_test.php | 48 ++++++++++++++++++++++ tests/template/templates/includejs.html | 5 +++ 2 files changed, 53 insertions(+) create mode 100644 tests/template/template_includejs_test.php create mode 100644 tests/template/templates/includejs.html diff --git a/tests/template/template_includejs_test.php b/tests/template/template_includejs_test.php new file mode 100644 index 0000000000..e0229e978b --- /dev/null +++ b/tests/template/template_includejs_test.php @@ -0,0 +1,48 @@ +setup_engine(); + + // Prepare correct result + $dir = dirname(__FILE__); + $scripts = array( + '', + '', + '' + ); + + // Run test + $cache_file = $this->template->cachepath . 'includejs.html.php'; + $this->run_template('includejs.html', array('PARENT' => 'parent_only.html'), array(), array(), implode('', $scripts), $cache_file); + } + + protected function setup_engine(array $new_config = array()) + { + global $phpbb_root_path, $phpEx, $user; + + $defaults = $this->config_defaults(); + $config = new phpbb_config(array_merge($defaults, $new_config)); + + $this->template_path = dirname(__FILE__) . '/templates'; + $this->parent_template_path = dirname(__FILE__) . '/parent_templates'; + $this->style_resource_locator = new phpbb_style_resource_locator(); + $this->style_provider = new phpbb_style_path_provider(); + $this->template = new phpbb_style_template($phpbb_root_path, $phpEx, $config, $user, $this->style_resource_locator, $this->style_provider); + $this->style = new phpbb_style($phpbb_root_path, $phpEx, $config, $user, $this->style_resource_locator, $this->style_provider, $this->template); + $this->style->set_custom_style('tests', array($this->template_path, $this->parent_template_path), ''); + $this->template->set_filenames(array('body' => 'includejs.html')); + } +} diff --git a/tests/template/templates/includejs.html b/tests/template/templates/includejs.html new file mode 100644 index 0000000000..186fc30b43 --- /dev/null +++ b/tests/template/templates/includejs.html @@ -0,0 +1,5 @@ + + + + +{SCRIPTS} \ No newline at end of file From e7cf4bfb2ed2b549e567c7237df799b6af0977ae Mon Sep 17 00:00:00 2001 From: Hari Sankar R Date: Sun, 1 Apr 2012 18:25:50 +0530 Subject: [PATCH 055/114] [ticket/10731] Fixed addquote() to work on opera browser. In opera, window.getSelection() returned incorrect values, should be using document.getSelection() instead. Fixed in prosilver and subsilver2 templates. PHPBB3-10731 --- phpBB/styles/prosilver/template/editor.js | 2 +- phpBB/styles/subsilver2/template/editor.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/phpBB/styles/prosilver/template/editor.js b/phpBB/styles/prosilver/template/editor.js index 2c41b543b5..c16b0ef703 100644 --- a/phpBB/styles/prosilver/template/editor.js +++ b/phpBB/styles/prosilver/template/editor.js @@ -219,7 +219,7 @@ function addquote(post_id, username, l_wrote) // Get text selection - not only the post content :( // IE9 must use the document.selection method but has the *.getSelection so we just force no IE - if (window.getSelection && !is_ie) + if (window.getSelection && !is_ie && !window.opera) { theSelection = window.getSelection().toString(); } diff --git a/phpBB/styles/subsilver2/template/editor.js b/phpBB/styles/subsilver2/template/editor.js index b47583ec75..151cf53ff1 100644 --- a/phpBB/styles/subsilver2/template/editor.js +++ b/phpBB/styles/subsilver2/template/editor.js @@ -221,7 +221,7 @@ function addquote(post_id, username, l_wrote) // Get text selection - not only the post content :( // IE9 must use the document.selection method but has the *.getSelection so we just force no IE - if (window.getSelection && !is_ie) + if (window.getSelection && !is_ie && !window.opera) { theSelection = window.getSelection().toString(); } From 48616c7cf25555f2a5ae681a245ac0da9e812d89 Mon Sep 17 00:00:00 2001 From: Hari Sankar R Date: Sun, 1 Apr 2012 18:33:18 +0530 Subject: [PATCH 056/114] [ticket/10740] Changed styling of phpbb_alert box, to be centered. Changed the styling of the phpbb.alert() and phpbb.confirm() dialogue boxes to me more centered on a page. PHPBB3-10740 --- phpBB/styles/prosilver/theme/common.css | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/phpBB/styles/prosilver/theme/common.css b/phpBB/styles/prosilver/theme/common.css index 31015b28f9..e154db236f 100644 --- a/phpBB/styles/prosilver/theme/common.css +++ b/phpBB/styles/prosilver/theme/common.css @@ -594,9 +594,10 @@ li.pagination { border: 1px solid transparent; position: fixed; display: none; - top: 100px; - left: 35%; + top: 40%; + left: 50%; width: 30%; + margin-left: -15%; z-index: 50; padding: 25px; padding: 0 25px 20px 25px; From b1b530f92cca7eb115e096ea8901133d421771d2 Mon Sep 17 00:00:00 2001 From: Hari Sankar R Date: Sun, 1 Apr 2012 18:25:50 +0530 Subject: [PATCH 057/114] [ticket/10731] Fixed addquote() to work on opera browser. In opera, window.getSelection() returned incorrect values, should be using document.getSelection() instead. Fixed in prosilver and subsilver2 templates. PHPBB3-10731 --- phpBB/styles/prosilver/template/editor.js | 4 ++-- phpBB/styles/subsilver2/template/editor.js | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/phpBB/styles/prosilver/template/editor.js b/phpBB/styles/prosilver/template/editor.js index cfdb54f54b..c16b0ef703 100644 --- a/phpBB/styles/prosilver/template/editor.js +++ b/phpBB/styles/prosilver/template/editor.js @@ -219,7 +219,7 @@ function addquote(post_id, username, l_wrote) // Get text selection - not only the post content :( // IE9 must use the document.selection method but has the *.getSelection so we just force no IE - if (window.getSelection && !is_ie) + if (window.getSelection && !is_ie && !window.opera) { theSelection = window.getSelection().toString(); } @@ -456,4 +456,4 @@ function getCaretPosition(txtarea) } return caretPos; -} \ No newline at end of file +} diff --git a/phpBB/styles/subsilver2/template/editor.js b/phpBB/styles/subsilver2/template/editor.js index 7cc5de9034..151cf53ff1 100644 --- a/phpBB/styles/subsilver2/template/editor.js +++ b/phpBB/styles/subsilver2/template/editor.js @@ -221,7 +221,7 @@ function addquote(post_id, username, l_wrote) // Get text selection - not only the post content :( // IE9 must use the document.selection method but has the *.getSelection so we just force no IE - if (window.getSelection && !is_ie) + if (window.getSelection && !is_ie && !window.opera) { theSelection = window.getSelection().toString(); } @@ -459,4 +459,4 @@ function getCaretPosition(txtarea) } return caretPos; -} \ No newline at end of file +} From f5bac7686b1678dbd33eddd368d845237bb18943 Mon Sep 17 00:00:00 2001 From: Vjacheslav Trushkin Date: Sun, 1 Apr 2012 19:14:53 +0300 Subject: [PATCH 058/114] [ticket/10733] Removing static from data providers Removing static from data provider functions PHPBB3-10733 --- tests/dbal/select_test.php | 14 +++++++------- tests/dbal/write_test.php | 4 ++-- tests/group_positions/group_positions_test.php | 14 +++++++------- tests/request/request_var_test.php | 4 ++-- tests/security/extract_current_page_test.php | 2 +- tests/security/redirect_test.php | 2 +- tests/template/template_inheritance_test.php | 2 +- tests/template/template_locate_test.php | 2 +- tests/template/template_test.php | 4 ++-- tests/text_processing/make_clickable_test.php | 2 +- tests/utf/utf8_clean_string_test.php | 2 +- 11 files changed, 26 insertions(+), 26 deletions(-) diff --git a/tests/dbal/select_test.php b/tests/dbal/select_test.php index 21b12777dc..cc213f09bc 100644 --- a/tests/dbal/select_test.php +++ b/tests/dbal/select_test.php @@ -17,7 +17,7 @@ class phpbb_dbal_select_test extends phpbb_database_test_case return $this->createXMLDataSet(dirname(__FILE__).'/fixtures/three_users.xml'); } - public static function return_on_error_select_data() + public function return_on_error_select_data() { return array( array('phpbb_users', "username_clean = 'bertie'", array(array('username_clean' => 'bertie'))), @@ -44,7 +44,7 @@ class phpbb_dbal_select_test extends phpbb_database_test_case $this->assertEquals($expected, $db->sql_fetchrowset($result)); } - public static function fetchrow_data() + public function fetchrow_data() { return array( array('', array(array('username_clean' => 'barfoo'), @@ -95,7 +95,7 @@ class phpbb_dbal_select_test extends phpbb_database_test_case $db->sql_freeresult($result); } - public static function fetchfield_data() + public function fetchfield_data() { return array( array('', array('barfoo', 'foobar', 'bertie')), @@ -125,7 +125,7 @@ class phpbb_dbal_select_test extends phpbb_database_test_case $this->assertEquals($expected, $ary); } - public static function query_limit_data() + public function query_limit_data() { return array( array(0, 0, array(array('username_clean' => 'barfoo'), @@ -166,7 +166,7 @@ class phpbb_dbal_select_test extends phpbb_database_test_case $this->assertEquals($expected, $ary); } - public static function like_expression_data() + public function like_expression_data() { // * = any_char; # = one_char return array( @@ -203,7 +203,7 @@ class phpbb_dbal_select_test extends phpbb_database_test_case $db->sql_freeresult($result); } - public static function in_set_data() + public function in_set_data() { return array( array('user_id', 3, false, false, array(array('username_clean' => 'bertie'))), @@ -277,7 +277,7 @@ class phpbb_dbal_select_test extends phpbb_database_test_case $db->sql_freeresult($result); } - public static function build_array_data() + public function build_array_data() { return array( array(array('username_clean' => 'barfoo'), array(array('username_clean' => 'barfoo'))), diff --git a/tests/dbal/write_test.php b/tests/dbal/write_test.php index 596c50a220..987161a831 100644 --- a/tests/dbal/write_test.php +++ b/tests/dbal/write_test.php @@ -16,7 +16,7 @@ class phpbb_dbal_write_test extends phpbb_database_test_case return $this->createXMLDataSet(dirname(__FILE__).'/fixtures/config.xml'); } - public static function build_array_insert_data() + public function build_array_insert_data() { return array( array(array( @@ -104,7 +104,7 @@ class phpbb_dbal_write_test extends phpbb_database_test_case $db->sql_freeresult($result); } - public static function update_data() + public function update_data() { return array( array( diff --git a/tests/group_positions/group_positions_test.php b/tests/group_positions/group_positions_test.php index fd9f57e78f..c17e25511b 100644 --- a/tests/group_positions/group_positions_test.php +++ b/tests/group_positions/group_positions_test.php @@ -15,7 +15,7 @@ class phpbb_group_positions_test extends phpbb_database_test_case return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/group_positions.xml'); } - public static function get_group_value_data() + public function get_group_value_data() { return array( array('teampage', 1, 0), @@ -38,7 +38,7 @@ class phpbb_group_positions_test extends phpbb_database_test_case $this->assertEquals($expected, $test_class->get_group_value($group_id)); } - public static function get_group_count_data() + public function get_group_count_data() { return array( array('teampage', 2), @@ -59,7 +59,7 @@ class phpbb_group_positions_test extends phpbb_database_test_case $this->assertEquals($expected, $test_class->get_group_count()); } - public static function add_group_data() + public function add_group_data() { return array( array('teampage', 1, array( @@ -93,7 +93,7 @@ class phpbb_group_positions_test extends phpbb_database_test_case $this->assertEquals($expected, $db->sql_fetchrowset($result)); } - public static function delete_group_data() + public function delete_group_data() { return array( array('teampage', 1, false, array( @@ -147,7 +147,7 @@ class phpbb_group_positions_test extends phpbb_database_test_case $this->assertEquals($expected, $db->sql_fetchrowset($result)); } - public static function move_up_data() + public function move_up_data() { return array( array('teampage', 1, array( @@ -186,7 +186,7 @@ class phpbb_group_positions_test extends phpbb_database_test_case $this->assertEquals($expected, $db->sql_fetchrowset($result)); } - public static function move_down_data() + public function move_down_data() { return array( array('teampage', 1, array( @@ -225,7 +225,7 @@ class phpbb_group_positions_test extends phpbb_database_test_case $this->assertEquals($expected, $db->sql_fetchrowset($result)); } - public static function move_data() + public function move_data() { return array( array('teampage', 1, 1, array( diff --git a/tests/request/request_var_test.php b/tests/request/request_var_test.php index 1fa0afae13..0e85d4694b 100644 --- a/tests/request/request_var_test.php +++ b/tests/request/request_var_test.php @@ -112,7 +112,7 @@ class phpbb_request_var_test extends phpbb_test_case $this->assertEquals($expected, $result, 'Testing deep access to multidimensional input arrays: ' . $path); } - public static function deep_access() + public function deep_access() { return array( // array(path, default, expected result) @@ -123,7 +123,7 @@ class phpbb_request_var_test extends phpbb_test_case ); } - public static function request_variables() + public function request_variables() { return array( // strings diff --git a/tests/security/extract_current_page_test.php b/tests/security/extract_current_page_test.php index b4a475ffb3..d77cbbcaf3 100644 --- a/tests/security/extract_current_page_test.php +++ b/tests/security/extract_current_page_test.php @@ -13,7 +13,7 @@ require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php'; class phpbb_security_extract_current_page_test extends phpbb_security_test_base { - public static function security_variables() + public function security_variables() { return array( array('http://localhost/phpBB/index.php', 'mark=forums&x=">', 'mark=forums&x=%22%3E%3Cscript%3Ealert(/XSS/);%3C/script%3E'), diff --git a/tests/security/redirect_test.php b/tests/security/redirect_test.php index da318209e2..1325466137 100644 --- a/tests/security/redirect_test.php +++ b/tests/security/redirect_test.php @@ -13,7 +13,7 @@ require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php'; class phpbb_security_redirect_test extends phpbb_security_test_base { - public static function provider() + public function provider() { // array(Input -> redirect(), expected triggered error (else false), expected returned result url (else false)) return array( diff --git a/tests/template/template_inheritance_test.php b/tests/template/template_inheritance_test.php index 7348da9a4a..a76658701a 100644 --- a/tests/template/template_inheritance_test.php +++ b/tests/template/template_inheritance_test.php @@ -14,7 +14,7 @@ class phpbb_template_template_inheritance_test extends phpbb_template_template_t /** * @todo put test data into templates/xyz.test */ - public static function template_data() + public function template_data() { return array( // First element of the array is test name - keep them distinct diff --git a/tests/template/template_locate_test.php b/tests/template/template_locate_test.php index 591a6afe0c..8edbd6a008 100644 --- a/tests/template/template_locate_test.php +++ b/tests/template/template_locate_test.php @@ -11,7 +11,7 @@ require_once dirname(__FILE__) . '/template_test_case.php'; class phpbb_template_template_locate_test extends phpbb_template_template_test_case { - public static function template_data() + public function template_data() { return array( // First element of the array is test name - keep them distinct diff --git a/tests/template/template_test.php b/tests/template/template_test.php index edf621e16c..739bbe9387 100644 --- a/tests/template/template_test.php +++ b/tests/template/template_test.php @@ -15,7 +15,7 @@ class phpbb_template_template_test extends phpbb_template_template_test_case /** * @todo put test data into templates/xyz.test */ - public static function template_data() + public function template_data() { return array( /* @@ -394,7 +394,7 @@ class phpbb_template_template_test extends phpbb_template_template_test_case $this->run_template('php.html', array(), array(), array(), 'test', $cache_file); } - public static function alter_block_array_data() + public function alter_block_array_data() { return array( array( diff --git a/tests/text_processing/make_clickable_test.php b/tests/text_processing/make_clickable_test.php index 8697907311..d94fac2ae4 100644 --- a/tests/text_processing/make_clickable_test.php +++ b/tests/text_processing/make_clickable_test.php @@ -12,7 +12,7 @@ require_once dirname(__FILE__) . '/../../phpBB/includes/functions_content.php'; class phpbb_text_processing_make_clickable_test extends phpbb_test_case { - public static function make_clickable_data() + public function make_clickable_data() { // value => whether it should work $prefix_texts = array( diff --git a/tests/utf/utf8_clean_string_test.php b/tests/utf/utf8_clean_string_test.php index 70bd549d5b..ae11e00fbd 100644 --- a/tests/utf/utf8_clean_string_test.php +++ b/tests/utf/utf8_clean_string_test.php @@ -11,7 +11,7 @@ require_once dirname(__FILE__) . '/../../phpBB/includes/utf/utf_tools.php'; class phpbb_utf_utf8_clean_string_test extends phpbb_test_case { - public static function cleanable_strings() + public function cleanable_strings() { return array( array('MiXed CaSe', 'mixed case', 'Checking case folding'), From eaba2ed9ca6025358de0432bb569cfb2e3ca6985 Mon Sep 17 00:00:00 2001 From: Vjacheslav Trushkin Date: Sun, 1 Apr 2012 19:20:42 +0300 Subject: [PATCH 059/114] [ticket/10733] Fixing test Changing expected and result in locator test PHPBB3-10733 --- tests/template/template_locate_test.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/tests/template/template_locate_test.php b/tests/template/template_locate_test.php index 8edbd6a008..89a4ae6fb1 100644 --- a/tests/template/template_locate_test.php +++ b/tests/template/template_locate_test.php @@ -17,38 +17,38 @@ class phpbb_template_template_locate_test extends phpbb_template_template_test_c // First element of the array is test name - keep them distinct array( 'simple inheritance - only parent template exists', + dirname(__FILE__) . '/parent_templates/parent_only.html', 'parent_only.html', false, true, - dirname(__FILE__) . '/parent_templates/parent_only.html', ), array( 'simple inheritance - only child template exists', + dirname(__FILE__) . '/templates/child_only.html', 'child_only.html', false, true, - dirname(__FILE__) . '/templates/child_only.html', ), array( 'simple inheritance - both parent and child templates exist', + dirname(__FILE__) . '/templates/parent_and_child.html', 'parent_and_child.html', false, true, - dirname(__FILE__) . '/templates/parent_and_child.html', ), array( 'find first template - only child template exists in main style', + 'child_only.html', array('parent_only.html', 'child_only.html'), false, false, - 'child_only.html', ), array( 'find first template - both templates exist in main style', + 'parent_and_child.html', array('parent_and_child.html', 'child_only.html'), false, false, - 'parent_and_child.html', ), ); } @@ -56,14 +56,14 @@ class phpbb_template_template_locate_test extends phpbb_template_template_test_c /** * @dataProvider template_data */ - public function test_template($name, $files, $return_default, $return_full_path, $expected) + public function test_template($name, $expected, $files, $return_default, $return_full_path) { // Reset the engine state $this->setup_engine(); // Locate template $result = $this->template->locate($files, $return_default, $return_full_path); - $this->assertEquals($result, $expected); + $this->assertSame($expected, $result); } protected function setup_engine(array $new_config = array()) From f36a6f0ae35107ac75be3cffff2f0f341baee7a8 Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Sun, 1 Apr 2012 18:44:05 +0200 Subject: [PATCH 060/114] [ticket/10740] Revert margin-left changes of previous commit PHPBB3-10740 --- phpBB/styles/prosilver/theme/common.css | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/phpBB/styles/prosilver/theme/common.css b/phpBB/styles/prosilver/theme/common.css index e154db236f..77e2b8c0c6 100644 --- a/phpBB/styles/prosilver/theme/common.css +++ b/phpBB/styles/prosilver/theme/common.css @@ -595,9 +595,8 @@ li.pagination { position: fixed; display: none; top: 40%; - left: 50%; + left: 35%; width: 30%; - margin-left: -15%; z-index: 50; padding: 25px; padding: 0 25px 20px 25px; From fb0df8d2e398a634457b317a721734e53596f002 Mon Sep 17 00:00:00 2001 From: Vjacheslav Trushkin Date: Sun, 1 Apr 2012 20:19:07 +0300 Subject: [PATCH 061/114] [ticket/10665] Moving filter parameters to one array Moving filter parameters to one array in template compiler class PHPBB3-10665 --- phpBB/includes/style/template_compile.php | 34 ++++------------------- 1 file changed, 6 insertions(+), 28 deletions(-) diff --git a/phpBB/includes/style/template_compile.php b/phpBB/includes/style/template_compile.php index bd9e18e102..fa0928f424 100644 --- a/phpBB/includes/style/template_compile.php +++ b/phpBB/includes/style/template_compile.php @@ -32,25 +32,6 @@ class phpbb_style_template_compile */ private $filter_params; - /** - * Whether tags are allowed - * - * @var bool - */ - private $allow_php; - - /** - * Style resource locator - * - * @var phpbb_style_resource_locator - */ - private $locator; - - /** - * @var string phpBB root path - */ - private $phpbb_root_path; - /** * Constructor. * @@ -60,10 +41,11 @@ class phpbb_style_template_compile */ public function __construct($allow_php, $locator, $phpbb_root_path) { - $this->filter_params = array(); - $this->allow_php = $allow_php; - $this->locator = $locator; - $this->phpbb_root_path = $phpbb_root_path; + $this->filter_params = array( + 'allow_php' => $allow_php, + 'locator' => $locator, + 'phpbb_root_path' => $phpbb_root_path + ); } /** @@ -140,11 +122,7 @@ class phpbb_style_template_compile */ private function compile_stream_to_stream($source_stream, $dest_stream) { - $params = $this->filter_params; - $params['allow_php'] = $this->allow_php; - $params['locator'] = $this->locator; - $params['phpbb_root_path'] = $this->phpbb_root_path; - stream_filter_append($source_stream, 'phpbb_template', null, $params); + stream_filter_append($source_stream, 'phpbb_template', null, $this->filter_params); stream_copy_to_stream($source_stream, $dest_stream); } } From 1ffc7c1fab85b1eb732b31bfd8a0f48c7351e68a Mon Sep 17 00:00:00 2001 From: Vjacheslav Trushkin Date: Sun, 1 Apr 2012 20:29:03 +0300 Subject: [PATCH 062/114] [ticket/10665] Changing template->_js_include to public Changing template->_js_include to public function PHPBB3-10665 --- phpBB/includes/style/template.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/includes/style/template.php b/phpBB/includes/style/template.php index 4586e8dbf9..3f15355f7a 100644 --- a/phpBB/includes/style/template.php +++ b/phpBB/includes/style/template.php @@ -499,7 +499,7 @@ class phpbb_style_template * @param string $file file name * @param bool $locate True if file needs to be located */ - function _js_include($file, $locate = false) + public function _js_include($file, $locate = false) { // Locate file if ($locate) From 2d9d8d367389c6bc0cef7852849e3d43ac682789 Mon Sep 17 00:00:00 2001 From: Vjacheslav Trushkin Date: Sun, 1 Apr 2012 20:37:45 +0300 Subject: [PATCH 063/114] [ticket/10665] New test class for templates with tree New parent template test class for tests that use styles tree PHPBB3-10665 --- tests/template/template_includejs_test.php | 21 ++------------ tests/template/template_inheritance_test.php | 20 ++----------- tests/template/template_locate_test.php | 20 ++----------- .../template/template_test_case_with_tree.php | 29 +++++++++++++++++++ 4 files changed, 35 insertions(+), 55 deletions(-) create mode 100644 tests/template/template_test_case_with_tree.php diff --git a/tests/template/template_includejs_test.php b/tests/template/template_includejs_test.php index e0229e978b..fa23837553 100644 --- a/tests/template/template_includejs_test.php +++ b/tests/template/template_includejs_test.php @@ -7,9 +7,9 @@ * */ -require_once dirname(__FILE__) . '/template_test_case.php'; +require_once dirname(__FILE__) . '/template_test_case_with_tree.php'; -class phpbb_template_template_includejs_test extends phpbb_template_template_test_case +class phpbb_template_template_includejs_test extends phpbb_template_template_test_case_with_tree { public function test_includejs_compilation() { @@ -28,21 +28,4 @@ class phpbb_template_template_includejs_test extends phpbb_template_template_tes $cache_file = $this->template->cachepath . 'includejs.html.php'; $this->run_template('includejs.html', array('PARENT' => 'parent_only.html'), array(), array(), implode('', $scripts), $cache_file); } - - protected function setup_engine(array $new_config = array()) - { - global $phpbb_root_path, $phpEx, $user; - - $defaults = $this->config_defaults(); - $config = new phpbb_config(array_merge($defaults, $new_config)); - - $this->template_path = dirname(__FILE__) . '/templates'; - $this->parent_template_path = dirname(__FILE__) . '/parent_templates'; - $this->style_resource_locator = new phpbb_style_resource_locator(); - $this->style_provider = new phpbb_style_path_provider(); - $this->template = new phpbb_style_template($phpbb_root_path, $phpEx, $config, $user, $this->style_resource_locator, $this->style_provider); - $this->style = new phpbb_style($phpbb_root_path, $phpEx, $config, $user, $this->style_resource_locator, $this->style_provider, $this->template); - $this->style->set_custom_style('tests', array($this->template_path, $this->parent_template_path), ''); - $this->template->set_filenames(array('body' => 'includejs.html')); - } } diff --git a/tests/template/template_inheritance_test.php b/tests/template/template_inheritance_test.php index a76658701a..febfed9ef0 100644 --- a/tests/template/template_inheritance_test.php +++ b/tests/template/template_inheritance_test.php @@ -7,9 +7,9 @@ * */ -require_once dirname(__FILE__) . '/template_test_case.php'; +require_once dirname(__FILE__) . '/template_test_case_with_tree.php'; -class phpbb_template_template_inheritance_test extends phpbb_template_template_test_case +class phpbb_template_template_inheritance_test extends phpbb_template_template_test_case_with_tree { /** * @todo put test data into templates/xyz.test @@ -61,20 +61,4 @@ class phpbb_template_template_inheritance_test extends phpbb_template_template_t $this->run_template($file, $vars, $block_vars, $destroy, $expected, $cache_file); } - - protected function setup_engine(array $new_config = array()) - { - global $phpbb_root_path, $phpEx, $user; - - $defaults = $this->config_defaults(); - $config = new phpbb_config(array_merge($defaults, $new_config)); - - $this->template_path = dirname(__FILE__) . '/templates'; - $this->parent_template_path = dirname(__FILE__) . '/parent_templates'; - $this->style_resource_locator = new phpbb_style_resource_locator(); - $this->style_provider = new phpbb_style_path_provider(); - $this->template = new phpbb_style_template($phpbb_root_path, $phpEx, $config, $user, $this->style_resource_locator, $this->style_provider); - $this->style = new phpbb_style($phpbb_root_path, $phpEx, $config, $user, $this->style_resource_locator, $this->style_provider, $this->template); - $this->style->set_custom_style('tests', array($this->template_path, $this->parent_template_path), ''); - } } diff --git a/tests/template/template_locate_test.php b/tests/template/template_locate_test.php index 89a4ae6fb1..d6e2e82a47 100644 --- a/tests/template/template_locate_test.php +++ b/tests/template/template_locate_test.php @@ -7,9 +7,9 @@ * */ -require_once dirname(__FILE__) . '/template_test_case.php'; +require_once dirname(__FILE__) . '/template_test_case_with_tree.php'; -class phpbb_template_template_locate_test extends phpbb_template_template_test_case +class phpbb_template_template_locate_test extends phpbb_template_template_test_case_with_tree { public function template_data() { @@ -65,20 +65,4 @@ class phpbb_template_template_locate_test extends phpbb_template_template_test_c $result = $this->template->locate($files, $return_default, $return_full_path); $this->assertSame($expected, $result); } - - protected function setup_engine(array $new_config = array()) - { - global $phpbb_root_path, $phpEx, $user; - - $defaults = $this->config_defaults(); - $config = new phpbb_config(array_merge($defaults, $new_config)); - - $this->template_path = dirname(__FILE__) . '/templates'; - $this->parent_template_path = dirname(__FILE__) . '/parent_templates'; - $this->style_resource_locator = new phpbb_style_resource_locator(); - $this->style_provider = new phpbb_style_path_provider(); - $this->template = new phpbb_style_template($phpbb_root_path, $phpEx, $config, $user, $this->style_resource_locator, $this->style_provider); - $this->style = new phpbb_style($phpbb_root_path, $phpEx, $config, $user, $this->style_resource_locator, $this->style_provider, $this->template); - $this->style->set_custom_style('tests', array($this->template_path, $this->parent_template_path), ''); - } } diff --git a/tests/template/template_test_case_with_tree.php b/tests/template/template_test_case_with_tree.php new file mode 100644 index 0000000000..e76d9436cf --- /dev/null +++ b/tests/template/template_test_case_with_tree.php @@ -0,0 +1,29 @@ +config_defaults(); + $config = new phpbb_config(array_merge($defaults, $new_config)); + + $this->template_path = dirname(__FILE__) . '/templates'; + $this->parent_template_path = dirname(__FILE__) . '/parent_templates'; + $this->style_resource_locator = new phpbb_style_resource_locator(); + $this->style_provider = new phpbb_style_path_provider(); + $this->template = new phpbb_style_template($phpbb_root_path, $phpEx, $config, $user, $this->style_resource_locator, $this->style_provider); + $this->style = new phpbb_style($phpbb_root_path, $phpEx, $config, $user, $this->style_resource_locator, $this->style_provider, $this->template); + $this->style->set_custom_style('tests', array($this->template_path, $this->parent_template_path), ''); + } +} From c89ea703bda1006b382f8cc0da292f6e2a3701f5 Mon Sep 17 00:00:00 2001 From: Vjacheslav Trushkin Date: Sun, 1 Apr 2012 20:46:10 +0300 Subject: [PATCH 064/114] [ticket/10665] Solution for T_SUPER_TEMPLATE_PATH Temporary solution for T_SUPER_TEMPLATE_PATH pointing to wrong directory, variable will be completely removed later because it will be obsolete PHPBB3-10665 --- phpBB/includes/functions.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 74db8cb8fd..a44ebb04e8 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -4770,7 +4770,7 @@ function page_header($page_title = '', $display_online_list = true, $item_id = 0 'T_ASSETS_PATH' => "{$web_path}assets", 'T_THEME_PATH' => "{$web_path}styles/" . rawurlencode($user->theme['style_path']) . '/theme', 'T_TEMPLATE_PATH' => "{$web_path}styles/" . rawurlencode($user->theme['style_path']) . '/template', - 'T_SUPER_TEMPLATE_PATH' => ($user->theme['style_parent_id']) ? "{$web_path}styles/" . rawurlencode($user->theme['style_parent_tree']) . '/template' : "{$web_path}styles/" . rawurlencode($user->theme['style_path']) . '/template', + 'T_SUPER_TEMPLATE_PATH' => "{$web_path}styles/" . rawurlencode($user->theme['style_path']) . '/template', 'T_IMAGES_PATH' => "{$web_path}images/", 'T_SMILIES_PATH' => "{$web_path}{$config['smilies_path']}/", 'T_AVATAR_PATH' => "{$web_path}{$config['avatar_path']}/", From 37480e5594145bbead07c8f70644d52983f92913 Mon Sep 17 00:00:00 2001 From: Vjacheslav Trushkin Date: Sun, 1 Apr 2012 20:50:59 +0300 Subject: [PATCH 065/114] [ticket/10665] Adding includejs to acp templates Adding includejs to acp overall_footer.html PHPBB3-10665 --- phpBB/adm/style/overall_footer.html | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/phpBB/adm/style/overall_footer.html b/phpBB/adm/style/overall_footer.html index 0337080f3d..a486a69514 100644 --- a/phpBB/adm/style/overall_footer.html +++ b/phpBB/adm/style/overall_footer.html @@ -39,7 +39,8 @@ - + +{SCRIPTS} From 06d26ef46e914c823889dab37627e7fa39d883ce Mon Sep 17 00:00:00 2001 From: Hari Sankar R Date: Mon, 2 Apr 2012 00:35:39 +0530 Subject: [PATCH 066/114] [ticket/10438] Alligning the Smileys on the same line as the text. Changed the styling of smilies to appear at the same level as text, by adding vertical-align: text-bottom css property to all smilies. Edited functions_content.php to add class="smilies" to all parsed smilies. PHPBB3-10438 --- phpBB/includes/functions_content.php | 2 +- phpBB/styles/prosilver/theme/common.css | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/phpBB/includes/functions_content.php b/phpBB/includes/functions_content.php index f2faf20f43..6b2ee98d7a 100644 --- a/phpBB/includes/functions_content.php +++ b/phpBB/includes/functions_content.php @@ -739,7 +739,7 @@ function smiley_text($text, $force_option = false) else { $root_path = (defined('PHPBB_USE_BOARD_URL_PATH') && PHPBB_USE_BOARD_URL_PATH) ? generate_board_url() . '/' : $phpbb_root_path; - return preg_replace('#', $text); + return preg_replace('#

    {L_TOPIC}: {TOPIC_TITLE}