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.
+
--
cgit v1.2.1
From 3997ffac2a2e6f422dcd5cd5bd076edee6fa91dd Mon Sep 17 00:00:00 2001
From: Vjacheslav Trushkin
Date: Thu, 15 Mar 2012 13:13:21 +0200
Subject: [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');
}
--
cgit v1.2.1
From c83f386c923fdb0e2823e7f742561a44a6f0f6ed Mon Sep 17 00:00:00 2001
From: Vjacheslav Trushkin
Date: Thu, 15 Mar 2012 13:41:23 +0200
Subject: [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);
--
cgit v1.2.1
From 8b7c2c3c6516fd4eb606054ca3822d8a7f977282 Mon Sep 17 00:00:00 2001
From: Vjacheslav Trushkin
Date: Thu, 15 Mar 2012 16:33:13 +0200
Subject: [feature/merging-style-components] Renaming style locator
Renaming style locator to style resource locator
PHPBB3-10632
---
phpBB/includes/style/locator.php | 214 ------------------------------
phpBB/includes/style/resource_locator.php | 214 ++++++++++++++++++++++++++++++
phpBB/includes/style/style.php | 2 +-
phpBB/includes/style/template.php | 6 +-
4 files changed, 218 insertions(+), 218 deletions(-)
delete mode 100644 phpBB/includes/style/locator.php
create mode 100644 phpBB/includes/style/resource_locator.php
diff --git a/phpBB/includes/style/locator.php b/phpBB/includes/style/locator.php
deleted file mode 100644
index 2d0bcce924..0000000000
--- a/phpBB/includes/style/locator.php
+++ /dev/null
@@ -1,214 +0,0 @@
-main_root_id = array_search($template, $this->roots, true);
- }
-
- /**
- * Sets the list of template paths
- *
- * These paths will be searched for template 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
- * @return null
- */
- public function set_paths($template_paths)
- {
- $this->roots = array();
- $this->files = array();
- $this->filenames = array();
- $this->main_root_id = 0;
-
- foreach ($template_paths as $path)
- {
- // Make sure $path has no ending slash
- if (substr($path, -1) === '/')
- {
- $path = substr($path, 0, -1);
- }
- $this->roots[] = $path;
- }
- }
-
- /**
- * Sets the template filenames for handles. $filename_array
- * should be a hash of handle => filename pairs.
- *
- * @param array $filname_array Should be a hash of handle => filename pairs.
- */
- public function set_filenames(array $filename_array)
- {
- foreach ($filename_array as $handle => $filename)
- {
- if (empty($filename))
- {
- trigger_error("template 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;
- }
- }
- }
-
- /**
- * Determines the filename for a template handle.
- *
- * The filename comes from array used in a set_filenames call,
- * which should have been performed prior to invoking this function.
- * Return value is a file basename (without path).
- *
- * @param $handle string Template handle
- * @return string Filename corresponding to the template handle
- */
- public function get_filename_for_handle($handle)
- {
- if (!isset($this->filename[$handle]))
- {
- trigger_error("template 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.
- *
- * This function returns the path in "primary" template 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).
- *
- * 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
- */
- 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);
- }
-
- $source_file = $this->files[$this->main_root_id][$handle];
- return $source_file;
- }
-
- /**
- * Determines the source file path for a template handle, accounting
- * for template inheritance 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
- * the template handle was never associated with a template path
- * via set_filenames or if the template file does not exist on the
- * filesystem.
- *
- * Use get_virtual_source_file_for_handle to just resolve a template
- * handle to a path without any filesystem or inheritance checks.
- *
- * @param string $handle Template handle (i.e. "friendly" template name)
- * @return string Source file path
- */
- 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]))
- {
- trigger_error("template locator: No file specified for handle $handle", E_USER_ERROR);
- }
-
- // locate a source file that exists
- $source_file = $this->files[0][$handle];
- $tried = $source_file;
- for ($i = 1, $n = count($this->roots); $i < $n && !file_exists($source_file); $i++)
- {
- $source_file = $this->files[$i][$handle];
- $tried .= ', ' . $source_file;
- }
-
- // 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);
- }
-
- return $source_file;
- }
-}
diff --git a/phpBB/includes/style/resource_locator.php b/phpBB/includes/style/resource_locator.php
new file mode 100644
index 0000000000..f36768fcd3
--- /dev/null
+++ b/phpBB/includes/style/resource_locator.php
@@ -0,0 +1,214 @@
+main_root_id = array_search($template, $this->roots, true);
+ }
+
+ /**
+ * Sets the list of template paths
+ *
+ * These paths will be searched for template 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
+ * @return null
+ */
+ public function set_paths($template_paths)
+ {
+ $this->roots = array();
+ $this->files = array();
+ $this->filenames = array();
+ $this->main_root_id = 0;
+
+ foreach ($template_paths as $path)
+ {
+ // Make sure $path has no ending slash
+ if (substr($path, -1) === '/')
+ {
+ $path = substr($path, 0, -1);
+ }
+ $this->roots[] = $path;
+ }
+ }
+
+ /**
+ * Sets the template filenames for handles. $filename_array
+ * should be a hash of handle => filename pairs.
+ *
+ * @param array $filname_array Should be a hash of handle => filename pairs.
+ */
+ public function set_filenames(array $filename_array)
+ {
+ foreach ($filename_array as $handle => $filename)
+ {
+ if (empty($filename))
+ {
+ trigger_error("template 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;
+ }
+ }
+ }
+
+ /**
+ * Determines the filename for a template handle.
+ *
+ * The filename comes from array used in a set_filenames call,
+ * which should have been performed prior to invoking this function.
+ * Return value is a file basename (without path).
+ *
+ * @param $handle string Template handle
+ * @return string Filename corresponding to the template handle
+ */
+ public function get_filename_for_handle($handle)
+ {
+ if (!isset($this->filename[$handle]))
+ {
+ trigger_error("template 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.
+ *
+ * This function returns the path in "primary" template 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).
+ *
+ * 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
+ */
+ 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);
+ }
+
+ $source_file = $this->files[$this->main_root_id][$handle];
+ return $source_file;
+ }
+
+ /**
+ * Determines the source file path for a template handle, accounting
+ * for template inheritance 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
+ * the template handle was never associated with a template path
+ * via set_filenames or if the template file does not exist on the
+ * filesystem.
+ *
+ * Use get_virtual_source_file_for_handle to just resolve a template
+ * handle to a path without any filesystem or inheritance checks.
+ *
+ * @param string $handle Template handle (i.e. "friendly" template name)
+ * @return string Source file path
+ */
+ 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]))
+ {
+ trigger_error("template locator: No file specified for handle $handle", E_USER_ERROR);
+ }
+
+ // locate a source file that exists
+ $source_file = $this->files[0][$handle];
+ $tried = $source_file;
+ for ($i = 1, $n = count($this->roots); $i < $n && !file_exists($source_file); $i++)
+ {
+ $source_file = $this->files[$i][$handle];
+ $tried .= ', ' . $source_file;
+ }
+
+ // 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);
+ }
+
+ return $source_file;
+ }
+}
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;
--
cgit v1.2.1
From c692e0d92da55944414d5f50accefdd96c2e31ee Mon Sep 17 00:00:00 2001
From: Vjacheslav Trushkin
Date: Thu, 15 Mar 2012 21:04:27 +0200
Subject: [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
---
phpBB/includes/style/extension_path_provider.php | 45 ++++++++----------
phpBB/includes/style/path_provider.php | 60 +++++++-----------------
phpBB/includes/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];
- }
-
- /**
- * Retrieves the path to the main template passed into set_templates()
- *
- * @return string Main template path
- */
- public function get_main_template_path()
- {
- return $this->main_template_path;
+ $this->paths = $styles;
+ $this->main_style_path = $this->paths[0];
}
/**
- * Converts a style name to relative (to board root or extension) path to
- * the style's template files.
+ * Retrieves the path to the main style passed into set_styles()
*
- * @param $style_name string Style name
- * @return string Path to style template files
+ * @return string Main style path
*/
- private function template_root_for_style($style_name)
+ public function get_main_style_path()
{
- return 'styles/' . $style_name . '/template';
+ return $this->main_style_path;
}
/**
- * Retrieve an iterator over all template paths
+ * Retrieve an iterator over all style 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();
}
--
cgit v1.2.1
From 0b2abe5250ebe6c75473a8d9f9be2aeb13855565 Mon Sep 17 00:00:00 2001
From: Vjacheslav Trushkin
Date: Thu, 15 Mar 2012 21:06:24 +0200
Subject: [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;
--
cgit v1.2.1
From 5b149e93b91ab1cb09e2e9c8c3c00312973c1c5e Mon Sep 17 00:00:00 2001
From: Vjacheslav Trushkin
Date: Thu, 15 Mar 2012 21:08:41 +0200
Subject: [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.
*
--
cgit v1.2.1
From 1ce4d4c4fc482f33fd061c4f718b4f8c3656dbdb Mon Sep 17 00:00:00 2001
From: Vjacheslav Trushkin
Date: Thu, 15 Mar 2012 21:09:49 +0200
Subject: [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);
+ }
}
--
cgit v1.2.1
From fd96f97dc3c659e1d2e9b58420d652ad79387fbf Mon Sep 17 00:00:00 2001
From: Vjacheslav Trushkin
Date: Thu, 15 Mar 2012 21:11:34 +0200
Subject: [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'],
--
cgit v1.2.1
From d25b607ca16bfd240f3b9cb9da7e4567b426ec26 Mon Sep 17 00:00:00 2001
From: Vjacheslav Trushkin
Date: Thu, 15 Mar 2012 21:12:13 +0200
Subject: [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()
--
cgit v1.2.1
From 97d4f168f588288df071e4a8b107b9ffb8b0355f Mon Sep 17 00:00:00 2001
From: Richard Foote
Date: Mon, 19 Mar 2012 15:08:28 -0400
Subject: [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)',
--
cgit v1.2.1
From 28fac327426de08b7a5476b2417fef4f03be6908 Mon Sep 17 00:00:00 2001
From: Bruno Ais
Date: Thu, 29 Mar 2012 15:51:06 +0100
Subject: [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.',
--
cgit v1.2.1
From d0e7b38aecbd5f357401297c8d57824a0504e9b6 Mon Sep 17 00:00:00 2001
From: Bruno Ais
Date: Thu, 29 Mar 2012 15:52:06 +0100
Subject: [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 @@
-
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.
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.
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).
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>
--
cgit v1.2.1
From bc46cfd6e5a6dd0a759c610e4654a7fad47db130 Mon Sep 17 00:00:00 2001
From: Igor Wiedler
Date: Sat, 31 Mar 2012 15:48:12 +0200
Subject: [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;
}
--
cgit v1.2.1
From 961199755200668790b243447eac6bf3374b0bb6 Mon Sep 17 00:00:00 2001
From: Vjacheslav Trushkin
Date: Sat, 31 Mar 2012 17:04:17 +0300
Subject: [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_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,
--
cgit v1.2.1
From 360312f599edd852e14fcd162552e19dd2d278a6 Mon Sep 17 00:00:00 2001
From: Vjacheslav Trushkin
Date: Sat, 31 Mar 2012 17:38:30 +0300
Subject: [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;
}
--
cgit v1.2.1
From 0540509f145d7eb9ba1fd4468399b48edcf46d23 Mon Sep 17 00:00:00 2001
From: Vjacheslav Trushkin
Date: Sat, 31 Mar 2012 17:58:17 +0300
Subject: [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',
));
--
cgit v1.2.1
From 17989c17a040a28aeeefcf55f6cca054b28c06ed Mon Sep 17 00:00:00 2001
From: Vjacheslav Trushkin
Date: Sat, 31 Mar 2012 18:10:00 +0300
Subject: [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()
--
cgit v1.2.1
From 377db78dcafb99ea65dca79777426db3117ec02c Mon Sep 17 00:00:00 2001
From: Vjacheslav Trushkin
Date: Sat, 31 Mar 2012 18:16:53 +0300
Subject: [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);
--
cgit v1.2.1
From 5d07b16ec647f51d51504cf9d6a0861a975ceb8e Mon Sep 17 00:00:00 2001
From: Igor Wiedler
Date: Sat, 31 Mar 2012 17:15:32 +0200
Subject: [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');
--
cgit v1.2.1
From 1be5bd8e1311a9dd859e6e685cdfa5979adf69a4 Mon Sep 17 00:00:00 2001
From: Vjacheslav Trushkin
Date: Sat, 31 Mar 2012 18:38:37 +0300
Subject: [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',
--
cgit v1.2.1
From 550ee7309a1d83711e4b9cf4abe3468807d84996 Mon Sep 17 00:00:00 2001
From: Vjacheslav Trushkin
Date: Sat, 31 Mar 2012 18:53:49 +0300
Subject: [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',
--
cgit v1.2.1
From 6deb7b3671c29ab7ce1db6e11b5c6be0950d265f Mon Sep 17 00:00:00 2001
From: Igor Wiedler
Date: Sat, 31 Mar 2012 02:50:19 +0200
Subject: [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:
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(
--
cgit v1.2.1
From 9236dd4c471a6f7655bd00ae422a13013a400ac4 Mon Sep 17 00:00:00 2001
From: Igor Wiedler
Date: Sat, 31 Mar 2012 02:54:39 +0200
Subject: [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.php | 1061 --------------------------------
phpBB/includes/auth/auth.php | 1061 ++++++++++++++++++++++++++++++++
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 +-
12 files changed, 1072 insertions(+), 1075 deletions(-)
delete mode 100644 phpBB/includes/auth.php
create mode 100644 phpBB/includes/auth/auth.php
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.php
deleted file mode 100644
index 11e86a50fe..0000000000
--- a/phpBB/includes/auth.php
+++ /dev/null
@@ -1,1061 +0,0 @@
-acl = $this->cache = $this->acl_options = array();
- $this->acl_forum_ids = false;
-
- if (($this->acl_options = $cache->get('_acl_options')) === false)
- {
- $sql = 'SELECT auth_option_id, auth_option, is_global, is_local
- FROM ' . ACL_OPTIONS_TABLE . '
- ORDER BY auth_option_id';
- $result = $db->sql_query($sql);
-
- $global = $local = 0;
- $this->acl_options = array();
- while ($row = $db->sql_fetchrow($result))
- {
- if ($row['is_global'])
- {
- $this->acl_options['global'][$row['auth_option']] = $global++;
- }
-
- if ($row['is_local'])
- {
- $this->acl_options['local'][$row['auth_option']] = $local++;
- }
-
- $this->acl_options['id'][$row['auth_option']] = (int) $row['auth_option_id'];
- $this->acl_options['option'][(int) $row['auth_option_id']] = $row['auth_option'];
- }
- $db->sql_freeresult($result);
-
- $cache->put('_acl_options', $this->acl_options);
- }
-
- if (!trim($userdata['user_permissions']))
- {
- $this->acl_cache($userdata);
- }
-
- // Fill ACL array
- $this->_fill_acl($userdata['user_permissions']);
-
- // Verify bitstring length with options provided...
- $renew = false;
- $global_length = sizeof($this->acl_options['global']);
- $local_length = sizeof($this->acl_options['local']);
-
- // Specify comparing length (bitstring is padded to 31 bits)
- $global_length = ($global_length % 31) ? ($global_length - ($global_length % 31) + 31) : $global_length;
- $local_length = ($local_length % 31) ? ($local_length - ($local_length % 31) + 31) : $local_length;
-
- // You thought we are finished now? Noooo... now compare them.
- foreach ($this->acl as $forum_id => $bitstring)
- {
- if (($forum_id && strlen($bitstring) != $local_length) || (!$forum_id && strlen($bitstring) != $global_length))
- {
- $renew = true;
- break;
- }
- }
-
- // If a bitstring within the list does not match the options, we have a user with incorrect permissions set and need to renew them
- if ($renew)
- {
- $this->acl_cache($userdata);
- $this->_fill_acl($userdata['user_permissions']);
- }
-
- return;
- }
-
- /**
- * Fill ACL array with relevant bitstrings from user_permissions column
- * @access private
- */
- function _fill_acl($user_permissions)
- {
- $seq_cache = array();
- $this->acl = array();
- $user_permissions = explode("\n", $user_permissions);
-
- foreach ($user_permissions as $f => $seq)
- {
- if ($seq)
- {
- $i = 0;
-
- if (!isset($this->acl[$f]))
- {
- $this->acl[$f] = '';
- }
-
- while ($subseq = substr($seq, $i, 6))
- {
- if (isset($seq_cache[$subseq]))
- {
- $converted = $seq_cache[$subseq];
- }
- else
- {
- $converted = $seq_cache[$subseq] = str_pad(base_convert($subseq, 36, 2), 31, 0, STR_PAD_LEFT);
- }
-
- // We put the original bitstring into the acl array
- $this->acl[$f] .= $converted;
- $i += 6;
- }
- }
- }
- }
-
- /**
- * Look up an option
- * if the option is prefixed with !, then the result becomes negated
- *
- * If a forum id is specified the local option will be combined with a global option if one exist.
- * If a forum id is not specified, only the global option will be checked.
- */
- function acl_get($opt, $f = 0)
- {
- $negate = false;
-
- if (strpos($opt, '!') === 0)
- {
- $negate = true;
- $opt = substr($opt, 1);
- }
-
- if (!isset($this->cache[$f][$opt]))
- {
- // We combine the global/local option with an OR because some options are global and local.
- // If the user has the global permission the local one is true too and vice versa
- $this->cache[$f][$opt] = false;
-
- // Is this option a global permission setting?
- if (isset($this->acl_options['global'][$opt]))
- {
- if (isset($this->acl[0]))
- {
- $this->cache[$f][$opt] = $this->acl[0][$this->acl_options['global'][$opt]];
- }
- }
-
- // Is this option a local permission setting?
- // But if we check for a global option only, we won't combine the options...
- if ($f != 0 && isset($this->acl_options['local'][$opt]))
- {
- if (isset($this->acl[$f]) && isset($this->acl[$f][$this->acl_options['local'][$opt]]))
- {
- $this->cache[$f][$opt] |= $this->acl[$f][$this->acl_options['local'][$opt]];
- }
- }
- }
-
- // Founder always has all global options set to true...
- return ($negate) ? !$this->cache[$f][$opt] : $this->cache[$f][$opt];
- }
-
- /**
- * Get forums with the specified permission setting
- * if the option is prefixed with !, then the result becomes nagated
- *
- * @param bool $clean set to true if only values needs to be returned which are set/unset
- */
- function acl_getf($opt, $clean = false)
- {
- $acl_f = array();
- $negate = false;
-
- if (strpos($opt, '!') === 0)
- {
- $negate = true;
- $opt = substr($opt, 1);
- }
-
- // If we retrieve a list of forums not having permissions in, we need to get every forum_id
- if ($negate)
- {
- if ($this->acl_forum_ids === false)
- {
- global $db;
-
- $sql = 'SELECT forum_id
- FROM ' . FORUMS_TABLE;
-
- if (sizeof($this->acl))
- {
- $sql .= ' WHERE ' . $db->sql_in_set('forum_id', array_keys($this->acl), true);
- }
- $result = $db->sql_query($sql);
-
- $this->acl_forum_ids = array();
- while ($row = $db->sql_fetchrow($result))
- {
- $this->acl_forum_ids[] = $row['forum_id'];
- }
- $db->sql_freeresult($result);
- }
- }
-
- if (isset($this->acl_options['local'][$opt]))
- {
- foreach ($this->acl as $f => $bitstring)
- {
- // Skip global settings
- if (!$f)
- {
- continue;
- }
-
- $allowed = (!isset($this->cache[$f][$opt])) ? $this->acl_get($opt, $f) : $this->cache[$f][$opt];
-
- if (!$clean)
- {
- $acl_f[$f][$opt] = ($negate) ? !$allowed : $allowed;
- }
- else
- {
- if (($negate && !$allowed) || (!$negate && $allowed))
- {
- $acl_f[$f][$opt] = 1;
- }
- }
- }
- }
-
- // If we get forum_ids not having this permission, we need to fill the remaining parts
- if ($negate && sizeof($this->acl_forum_ids))
- {
- foreach ($this->acl_forum_ids as $f)
- {
- $acl_f[$f][$opt] = 1;
- }
- }
-
- return $acl_f;
- }
-
- /**
- * Get local permission state for any forum.
- *
- * Returns true if user has the permission in one or more forums, false if in no forum.
- * If global option is checked it returns the global state (same as acl_get($opt))
- * Local option has precedence...
- */
- function acl_getf_global($opt)
- {
- if (is_array($opt))
- {
- // evaluates to true as soon as acl_getf_global is true for one option
- foreach ($opt as $check_option)
- {
- if ($this->acl_getf_global($check_option))
- {
- return true;
- }
- }
-
- return false;
- }
-
- if (isset($this->acl_options['local'][$opt]))
- {
- foreach ($this->acl as $f => $bitstring)
- {
- // Skip global settings
- if (!$f)
- {
- continue;
- }
-
- // as soon as the user has any permission we're done so return true
- if ((!isset($this->cache[$f][$opt])) ? $this->acl_get($opt, $f) : $this->cache[$f][$opt])
- {
- return true;
- }
- }
- }
- else if (isset($this->acl_options['global'][$opt]))
- {
- return $this->acl_get($opt);
- }
-
- return false;
- }
-
- /**
- * Get permission settings (more than one)
- */
- function acl_gets()
- {
- $args = func_get_args();
- $f = array_pop($args);
-
- if (!is_numeric($f))
- {
- $args[] = $f;
- $f = 0;
- }
-
- // alternate syntax: acl_gets(array('m_', 'a_'), $forum_id)
- if (is_array($args[0]))
- {
- $args = $args[0];
- }
-
- $acl = 0;
- foreach ($args as $opt)
- {
- $acl |= $this->acl_get($opt, $f);
- }
-
- return $acl;
- }
-
- /**
- * Get permission listing based on user_id/options/forum_ids
- *
- * Be careful when using this function with permissions a_, m_, u_ and f_ !
- * It may not work correctly. When a user group grants an a_* permission,
- * e.g. a_foo, but the user's a_foo permission is set to "Never", then
- * the user does not in fact have the a_ permission.
- * But the user will still be listed as having the a_ permission.
- *
- * For more information see: http://tracker.phpbb.com/browse/PHPBB3-10252
- */
- function acl_get_list($user_id = false, $opts = false, $forum_id = false)
- {
- if ($user_id !== false && !is_array($user_id) && $opts === false && $forum_id === false)
- {
- $hold_ary = array($user_id => $this->acl_raw_data_single_user($user_id));
- }
- else
- {
- $hold_ary = $this->acl_raw_data($user_id, $opts, $forum_id);
- }
-
- $auth_ary = array();
- foreach ($hold_ary as $user_id => $forum_ary)
- {
- foreach ($forum_ary as $forum_id => $auth_option_ary)
- {
- foreach ($auth_option_ary as $auth_option => $auth_setting)
- {
- if ($auth_setting)
- {
- $auth_ary[$forum_id][$auth_option][] = $user_id;
- }
- }
- }
- }
-
- return $auth_ary;
- }
-
- /**
- * Cache data to user_permissions row
- */
- function acl_cache(&$userdata)
- {
- global $db;
-
- // Empty user_permissions
- $userdata['user_permissions'] = '';
-
- $hold_ary = $this->acl_raw_data_single_user($userdata['user_id']);
-
- // Key 0 in $hold_ary are global options, all others are forum_ids
-
- // If this user is founder we're going to force fill the admin options ...
- if ($userdata['user_type'] == USER_FOUNDER)
- {
- foreach ($this->acl_options['global'] as $opt => $id)
- {
- if (strpos($opt, 'a_') === 0)
- {
- $hold_ary[0][$this->acl_options['id'][$opt]] = ACL_YES;
- }
- }
- }
-
- $hold_str = $this->build_bitstring($hold_ary);
-
- if ($hold_str)
- {
- $userdata['user_permissions'] = $hold_str;
-
- $sql = 'UPDATE ' . USERS_TABLE . "
- SET user_permissions = '" . $db->sql_escape($userdata['user_permissions']) . "',
- user_perm_from = 0
- WHERE user_id = " . $userdata['user_id'];
- $db->sql_query($sql);
- }
-
- return;
- }
-
- /**
- * Build bitstring from permission set
- */
- function build_bitstring(&$hold_ary)
- {
- $hold_str = '';
-
- if (sizeof($hold_ary))
- {
- ksort($hold_ary);
-
- $last_f = 0;
-
- foreach ($hold_ary as $f => $auth_ary)
- {
- $ary_key = (!$f) ? 'global' : 'local';
-
- $bitstring = array();
- foreach ($this->acl_options[$ary_key] as $opt => $id)
- {
- if (isset($auth_ary[$this->acl_options['id'][$opt]]))
- {
- $bitstring[$id] = $auth_ary[$this->acl_options['id'][$opt]];
-
- $option_key = substr($opt, 0, strpos($opt, '_') + 1);
-
- // If one option is allowed, the global permission for this option has to be allowed too
- // example: if the user has the a_ permission this means he has one or more a_* permissions
- if ($auth_ary[$this->acl_options['id'][$opt]] == ACL_YES && (!isset($bitstring[$this->acl_options[$ary_key][$option_key]]) || $bitstring[$this->acl_options[$ary_key][$option_key]] == ACL_NEVER))
- {
- $bitstring[$this->acl_options[$ary_key][$option_key]] = ACL_YES;
- }
- }
- else
- {
- $bitstring[$id] = ACL_NEVER;
- }
- }
-
- // Now this bitstring defines the permission setting for the current forum $f (or global setting)
- $bitstring = implode('', $bitstring);
-
- // The line number indicates the id, therefore we have to add empty lines for those ids not present
- $hold_str .= str_repeat("\n", $f - $last_f);
-
- // Convert bitstring for storage - we do not use binary/bytes because PHP's string functions are not fully binary safe
- for ($i = 0, $bit_length = strlen($bitstring); $i < $bit_length; $i += 31)
- {
- $hold_str .= str_pad(base_convert(str_pad(substr($bitstring, $i, 31), 31, 0, STR_PAD_RIGHT), 2, 36), 6, 0, STR_PAD_LEFT);
- }
-
- $last_f = $f;
- }
- unset($bitstring);
-
- $hold_str = rtrim($hold_str);
- }
-
- return $hold_str;
- }
-
- /**
- * Clear one or all users cached permission settings
- */
- function acl_clear_prefetch($user_id = false)
- {
- global $db, $cache;
-
- // Rebuild options cache
- $cache->destroy('_role_cache');
-
- $sql = 'SELECT *
- FROM ' . ACL_ROLES_DATA_TABLE . '
- ORDER BY role_id ASC';
- $result = $db->sql_query($sql);
-
- $this->role_cache = array();
- while ($row = $db->sql_fetchrow($result))
- {
- $this->role_cache[$row['role_id']][$row['auth_option_id']] = (int) $row['auth_setting'];
- }
- $db->sql_freeresult($result);
-
- foreach ($this->role_cache as $role_id => $role_options)
- {
- $this->role_cache[$role_id] = serialize($role_options);
- }
-
- $cache->put('_role_cache', $this->role_cache);
-
- // Now empty user permissions
- $where_sql = '';
-
- if ($user_id !== false)
- {
- $user_id = (!is_array($user_id)) ? $user_id = array((int) $user_id) : array_map('intval', $user_id);
- $where_sql = ' WHERE ' . $db->sql_in_set('user_id', $user_id);
- }
-
- $sql = 'UPDATE ' . USERS_TABLE . "
- SET user_permissions = '',
- user_perm_from = 0
- $where_sql";
- $db->sql_query($sql);
-
- return;
- }
-
- /**
- * Get assigned roles
- */
- function acl_role_data($user_type, $role_type, $ug_id = false, $forum_id = false)
- {
- global $db;
-
- $roles = array();
-
- $sql_id = ($user_type == 'user') ? 'user_id' : 'group_id';
-
- $sql_ug = ($ug_id !== false) ? ((!is_array($ug_id)) ? "AND a.$sql_id = $ug_id" : 'AND ' . $db->sql_in_set("a.$sql_id", $ug_id)) : '';
- $sql_forum = ($forum_id !== false) ? ((!is_array($forum_id)) ? "AND a.forum_id = $forum_id" : 'AND ' . $db->sql_in_set('a.forum_id', $forum_id)) : '';
-
- // Grab assigned roles...
- $sql = 'SELECT a.auth_role_id, a.' . $sql_id . ', a.forum_id
- FROM ' . (($user_type == 'user') ? ACL_USERS_TABLE : ACL_GROUPS_TABLE) . ' a, ' . ACL_ROLES_TABLE . " r
- WHERE a.auth_role_id = r.role_id
- AND r.role_type = '" . $db->sql_escape($role_type) . "'
- $sql_ug
- $sql_forum
- ORDER BY r.role_order ASC";
- $result = $db->sql_query($sql);
-
- while ($row = $db->sql_fetchrow($result))
- {
- $roles[$row[$sql_id]][$row['forum_id']] = $row['auth_role_id'];
- }
- $db->sql_freeresult($result);
-
- return $roles;
- }
-
- /**
- * Get raw acl data based on user/option/forum
- */
- function acl_raw_data($user_id = false, $opts = false, $forum_id = false)
- {
- global $db;
-
- $sql_user = ($user_id !== false) ? ((!is_array($user_id)) ? 'user_id = ' . (int) $user_id : $db->sql_in_set('user_id', array_map('intval', $user_id))) : '';
- $sql_forum = ($forum_id !== false) ? ((!is_array($forum_id)) ? 'AND a.forum_id = ' . (int) $forum_id : 'AND ' . $db->sql_in_set('a.forum_id', array_map('intval', $forum_id))) : '';
-
- $sql_opts = $sql_opts_select = $sql_opts_from = '';
- $hold_ary = array();
-
- if ($opts !== false)
- {
- $sql_opts_select = ', ao.auth_option';
- $sql_opts_from = ', ' . ACL_OPTIONS_TABLE . ' ao';
- $this->build_auth_option_statement('ao.auth_option', $opts, $sql_opts);
- }
-
- $sql_ary = array();
-
- // Grab non-role settings - user-specific
- $sql_ary[] = 'SELECT a.user_id, a.forum_id, a.auth_setting, a.auth_option_id' . $sql_opts_select . '
- FROM ' . ACL_USERS_TABLE . ' a' . $sql_opts_from . '
- WHERE a.auth_role_id = 0 ' .
- (($sql_opts_from) ? 'AND a.auth_option_id = ao.auth_option_id ' : '') .
- (($sql_user) ? 'AND a.' . $sql_user : '') . "
- $sql_forum
- $sql_opts";
-
- // Now the role settings - user-specific
- $sql_ary[] = 'SELECT a.user_id, a.forum_id, r.auth_option_id, r.auth_setting, r.auth_option_id' . $sql_opts_select . '
- FROM ' . ACL_USERS_TABLE . ' a, ' . ACL_ROLES_DATA_TABLE . ' r' . $sql_opts_from . '
- WHERE a.auth_role_id = r.role_id ' .
- (($sql_opts_from) ? 'AND r.auth_option_id = ao.auth_option_id ' : '') .
- (($sql_user) ? 'AND a.' . $sql_user : '') . "
- $sql_forum
- $sql_opts";
-
- foreach ($sql_ary as $sql)
- {
- $result = $db->sql_query($sql);
-
- while ($row = $db->sql_fetchrow($result))
- {
- $option = ($sql_opts_select) ? $row['auth_option'] : $this->acl_options['option'][$row['auth_option_id']];
- $hold_ary[$row['user_id']][$row['forum_id']][$option] = $row['auth_setting'];
- }
- $db->sql_freeresult($result);
- }
-
- $sql_ary = array();
-
- // Now grab group settings - non-role specific...
- $sql_ary[] = 'SELECT ug.user_id, a.forum_id, a.auth_setting, a.auth_option_id' . $sql_opts_select . '
- FROM ' . ACL_GROUPS_TABLE . ' a, ' . USER_GROUP_TABLE . ' ug, ' . GROUPS_TABLE . ' g' . $sql_opts_from . '
- WHERE a.auth_role_id = 0 ' .
- (($sql_opts_from) ? 'AND a.auth_option_id = ao.auth_option_id ' : '') . '
- AND a.group_id = ug.group_id
- AND g.group_id = ug.group_id
- AND ug.user_pending = 0
- AND NOT (ug.group_leader = 1 AND g.group_skip_auth = 1)
- ' . (($sql_user) ? 'AND ug.' . $sql_user : '') . "
- $sql_forum
- $sql_opts";
-
- // Now grab group settings - role specific...
- $sql_ary[] = 'SELECT ug.user_id, a.forum_id, r.auth_setting, r.auth_option_id' . $sql_opts_select . '
- FROM ' . ACL_GROUPS_TABLE . ' a, ' . USER_GROUP_TABLE . ' ug, ' . GROUPS_TABLE . ' g, ' . ACL_ROLES_DATA_TABLE . ' r' . $sql_opts_from . '
- WHERE a.auth_role_id = r.role_id ' .
- (($sql_opts_from) ? 'AND r.auth_option_id = ao.auth_option_id ' : '') . '
- AND a.group_id = ug.group_id
- AND g.group_id = ug.group_id
- AND ug.user_pending = 0
- AND NOT (ug.group_leader = 1 AND g.group_skip_auth = 1)
- ' . (($sql_user) ? 'AND ug.' . $sql_user : '') . "
- $sql_forum
- $sql_opts";
-
- foreach ($sql_ary as $sql)
- {
- $result = $db->sql_query($sql);
-
- while ($row = $db->sql_fetchrow($result))
- {
- $option = ($sql_opts_select) ? $row['auth_option'] : $this->acl_options['option'][$row['auth_option_id']];
-
- if (!isset($hold_ary[$row['user_id']][$row['forum_id']][$option]) || (isset($hold_ary[$row['user_id']][$row['forum_id']][$option]) && $hold_ary[$row['user_id']][$row['forum_id']][$option] != ACL_NEVER))
- {
- $hold_ary[$row['user_id']][$row['forum_id']][$option] = $row['auth_setting'];
-
- // If we detect ACL_NEVER, we will unset the flag option (within building the bitstring it is correctly set again)
- if ($row['auth_setting'] == ACL_NEVER)
- {
- $flag = substr($option, 0, strpos($option, '_') + 1);
-
- if (isset($hold_ary[$row['user_id']][$row['forum_id']][$flag]) && $hold_ary[$row['user_id']][$row['forum_id']][$flag] == ACL_YES)
- {
- unset($hold_ary[$row['user_id']][$row['forum_id']][$flag]);
-
-/* if (in_array(ACL_YES, $hold_ary[$row['user_id']][$row['forum_id']]))
- {
- $hold_ary[$row['user_id']][$row['forum_id']][$flag] = ACL_YES;
- }
-*/
- }
- }
- }
- }
- $db->sql_freeresult($result);
- }
-
- return $hold_ary;
- }
-
- /**
- * Get raw user based permission settings
- */
- function acl_user_raw_data($user_id = false, $opts = false, $forum_id = false)
- {
- global $db;
-
- $sql_user = ($user_id !== false) ? ((!is_array($user_id)) ? 'user_id = ' . (int) $user_id : $db->sql_in_set('user_id', array_map('intval', $user_id))) : '';
- $sql_forum = ($forum_id !== false) ? ((!is_array($forum_id)) ? 'AND a.forum_id = ' . (int) $forum_id : 'AND ' . $db->sql_in_set('a.forum_id', array_map('intval', $forum_id))) : '';
-
- $sql_opts = '';
- $hold_ary = $sql_ary = array();
-
- if ($opts !== false)
- {
- $this->build_auth_option_statement('ao.auth_option', $opts, $sql_opts);
- }
-
- // Grab user settings - non-role specific...
- $sql_ary[] = 'SELECT a.user_id, a.forum_id, a.auth_setting, a.auth_option_id, ao.auth_option
- FROM ' . ACL_USERS_TABLE . ' a, ' . ACL_OPTIONS_TABLE . ' ao
- WHERE a.auth_role_id = 0
- AND a.auth_option_id = ao.auth_option_id ' .
- (($sql_user) ? 'AND a.' . $sql_user : '') . "
- $sql_forum
- $sql_opts
- ORDER BY a.forum_id, ao.auth_option";
-
- // Now the role settings - user-specific
- $sql_ary[] = 'SELECT a.user_id, a.forum_id, r.auth_option_id, r.auth_setting, r.auth_option_id, ao.auth_option
- FROM ' . ACL_USERS_TABLE . ' a, ' . ACL_ROLES_DATA_TABLE . ' r, ' . ACL_OPTIONS_TABLE . ' ao
- WHERE a.auth_role_id = r.role_id
- AND r.auth_option_id = ao.auth_option_id ' .
- (($sql_user) ? 'AND a.' . $sql_user : '') . "
- $sql_forum
- $sql_opts
- ORDER BY a.forum_id, ao.auth_option";
-
- foreach ($sql_ary as $sql)
- {
- $result = $db->sql_query($sql);
-
- while ($row = $db->sql_fetchrow($result))
- {
- $hold_ary[$row['user_id']][$row['forum_id']][$row['auth_option']] = $row['auth_setting'];
- }
- $db->sql_freeresult($result);
- }
-
- return $hold_ary;
- }
-
- /**
- * Get raw group based permission settings
- */
- function acl_group_raw_data($group_id = false, $opts = false, $forum_id = false)
- {
- global $db;
-
- $sql_group = ($group_id !== false) ? ((!is_array($group_id)) ? 'group_id = ' . (int) $group_id : $db->sql_in_set('group_id', array_map('intval', $group_id))) : '';
- $sql_forum = ($forum_id !== false) ? ((!is_array($forum_id)) ? 'AND a.forum_id = ' . (int) $forum_id : 'AND ' . $db->sql_in_set('a.forum_id', array_map('intval', $forum_id))) : '';
-
- $sql_opts = '';
- $hold_ary = $sql_ary = array();
-
- if ($opts !== false)
- {
- $this->build_auth_option_statement('ao.auth_option', $opts, $sql_opts);
- }
-
- // Grab group settings - non-role specific...
- $sql_ary[] = 'SELECT a.group_id, a.forum_id, a.auth_setting, a.auth_option_id, ao.auth_option
- FROM ' . ACL_GROUPS_TABLE . ' a, ' . ACL_OPTIONS_TABLE . ' ao
- WHERE a.auth_role_id = 0
- AND a.auth_option_id = ao.auth_option_id ' .
- (($sql_group) ? 'AND a.' . $sql_group : '') . "
- $sql_forum
- $sql_opts
- ORDER BY a.forum_id, ao.auth_option";
-
- // Now grab group settings - role specific...
- $sql_ary[] = 'SELECT a.group_id, a.forum_id, r.auth_setting, r.auth_option_id, ao.auth_option
- FROM ' . ACL_GROUPS_TABLE . ' a, ' . ACL_ROLES_DATA_TABLE . ' r, ' . ACL_OPTIONS_TABLE . ' ao
- WHERE a.auth_role_id = r.role_id
- AND r.auth_option_id = ao.auth_option_id ' .
- (($sql_group) ? 'AND a.' . $sql_group : '') . "
- $sql_forum
- $sql_opts
- ORDER BY a.forum_id, ao.auth_option";
-
- foreach ($sql_ary as $sql)
- {
- $result = $db->sql_query($sql);
-
- while ($row = $db->sql_fetchrow($result))
- {
- $hold_ary[$row['group_id']][$row['forum_id']][$row['auth_option']] = $row['auth_setting'];
- }
- $db->sql_freeresult($result);
- }
-
- return $hold_ary;
- }
-
- /**
- * Get raw acl data based on user for caching user_permissions
- * This function returns the same data as acl_raw_data(), but without the user id as the first key within the array.
- */
- function acl_raw_data_single_user($user_id)
- {
- global $db, $cache;
-
- // Check if the role-cache is there
- if (($this->role_cache = $cache->get('_role_cache')) === false)
- {
- $this->role_cache = array();
-
- // We pre-fetch roles
- $sql = 'SELECT *
- FROM ' . ACL_ROLES_DATA_TABLE . '
- ORDER BY role_id ASC';
- $result = $db->sql_query($sql);
-
- while ($row = $db->sql_fetchrow($result))
- {
- $this->role_cache[$row['role_id']][$row['auth_option_id']] = (int) $row['auth_setting'];
- }
- $db->sql_freeresult($result);
-
- foreach ($this->role_cache as $role_id => $role_options)
- {
- $this->role_cache[$role_id] = serialize($role_options);
- }
-
- $cache->put('_role_cache', $this->role_cache);
- }
-
- $hold_ary = array();
-
- // Grab user-specific permission settings
- $sql = 'SELECT forum_id, auth_option_id, auth_role_id, auth_setting
- FROM ' . ACL_USERS_TABLE . '
- WHERE user_id = ' . $user_id;
- $result = $db->sql_query($sql);
-
- while ($row = $db->sql_fetchrow($result))
- {
- // If a role is assigned, assign all options included within this role. Else, only set this one option.
- if ($row['auth_role_id'])
- {
- $hold_ary[$row['forum_id']] = (empty($hold_ary[$row['forum_id']])) ? unserialize($this->role_cache[$row['auth_role_id']]) : $hold_ary[$row['forum_id']] + unserialize($this->role_cache[$row['auth_role_id']]);
- }
- else
- {
- $hold_ary[$row['forum_id']][$row['auth_option_id']] = $row['auth_setting'];
- }
- }
- $db->sql_freeresult($result);
-
- // Now grab group-specific permission settings
- $sql = 'SELECT a.forum_id, a.auth_option_id, a.auth_role_id, a.auth_setting
- FROM ' . ACL_GROUPS_TABLE . ' a, ' . USER_GROUP_TABLE . ' ug, ' . GROUPS_TABLE . ' g
- WHERE a.group_id = ug.group_id
- AND g.group_id = ug.group_id
- AND ug.user_pending = 0
- AND NOT (ug.group_leader = 1 AND g.group_skip_auth = 1)
- AND ug.user_id = ' . $user_id;
- $result = $db->sql_query($sql);
-
- while ($row = $db->sql_fetchrow($result))
- {
- if (!$row['auth_role_id'])
- {
- $this->_set_group_hold_ary($hold_ary[$row['forum_id']], $row['auth_option_id'], $row['auth_setting']);
- }
- else if (!empty($this->role_cache[$row['auth_role_id']]))
- {
- foreach (unserialize($this->role_cache[$row['auth_role_id']]) as $option_id => $setting)
- {
- $this->_set_group_hold_ary($hold_ary[$row['forum_id']], $option_id, $setting);
- }
- }
- }
- $db->sql_freeresult($result);
-
- return $hold_ary;
- }
-
- /**
- * Private function snippet for setting a specific piece of the hold_ary
- */
- function _set_group_hold_ary(&$hold_ary, $option_id, $setting)
- {
- if (!isset($hold_ary[$option_id]) || (isset($hold_ary[$option_id]) && $hold_ary[$option_id] != ACL_NEVER))
- {
- $hold_ary[$option_id] = $setting;
-
- // If we detect ACL_NEVER, we will unset the flag option (within building the bitstring it is correctly set again)
- if ($setting == ACL_NEVER)
- {
- $flag = substr($this->acl_options['option'][$option_id], 0, strpos($this->acl_options['option'][$option_id], '_') + 1);
- $flag = (int) $this->acl_options['id'][$flag];
-
- if (isset($hold_ary[$flag]) && $hold_ary[$flag] == ACL_YES)
- {
- unset($hold_ary[$flag]);
-
-/* This is uncommented, because i suspect this being slightly wrong due to mixed permission classes being possible
- if (in_array(ACL_YES, $hold_ary))
- {
- $hold_ary[$flag] = ACL_YES;
- }*/
- }
- }
- }
- }
-
- /**
- * Authentication plug-ins is largely down to Sergey Kanareykin, our thanks to him.
- */
- function login($username, $password, $autologin = false, $viewonline = 1, $admin = 0)
- {
- global $config, $db, $user, $phpbb_root_path, $phpEx;
-
- $method = trim(basename($config['auth_method']));
- include_once($phpbb_root_path . 'includes/auth/auth_' . $method . '.' . $phpEx);
-
- $method = 'login_' . $method;
- if (function_exists($method))
- {
- $login = $method($username, $password, $user->ip, $user->browser, $user->forwarded_for);
-
- // If the auth module wants us to create an empty profile do so and then treat the status as LOGIN_SUCCESS
- if ($login['status'] == LOGIN_SUCCESS_CREATE_PROFILE)
- {
- // we are going to use the user_add function so include functions_user.php if it wasn't defined yet
- if (!function_exists('user_add'))
- {
- include($phpbb_root_path . 'includes/functions_user.' . $phpEx);
- }
-
- user_add($login['user_row'], (isset($login['cp_data'])) ? $login['cp_data'] : false);
-
- $sql = 'SELECT user_id, username, user_password, user_passchg, user_email, user_type
- FROM ' . USERS_TABLE . "
- WHERE username_clean = '" . $db->sql_escape(utf8_clean_string($username)) . "'";
- $result = $db->sql_query($sql);
- $row = $db->sql_fetchrow($result);
- $db->sql_freeresult($result);
-
- if (!$row)
- {
- return array(
- 'status' => LOGIN_ERROR_EXTERNAL_AUTH,
- 'error_msg' => 'AUTH_NO_PROFILE_CREATED',
- 'user_row' => array('user_id' => ANONYMOUS),
- );
- }
-
- $login = array(
- 'status' => LOGIN_SUCCESS,
- 'error_msg' => false,
- 'user_row' => $row,
- );
- }
-
- // If login succeeded, we will log the user in... else we pass the login array through...
- if ($login['status'] == LOGIN_SUCCESS)
- {
- $old_session_id = $user->session_id;
-
- if ($admin)
- {
- global $SID, $_SID;
-
- $cookie_expire = time() - 31536000;
- $user->set_cookie('u', '', $cookie_expire);
- $user->set_cookie('sid', '', $cookie_expire);
- unset($cookie_expire);
-
- $SID = '?sid=';
- $user->session_id = $_SID = '';
- }
-
- $result = $user->session_create($login['user_row']['user_id'], $admin, $autologin, $viewonline);
-
- // Successful session creation
- if ($result === true)
- {
- // If admin re-authentication we remove the old session entry because a new one has been created...
- if ($admin)
- {
- // the login array is used because the user ids do not differ for re-authentication
- $sql = 'DELETE FROM ' . SESSIONS_TABLE . "
- WHERE session_id = '" . $db->sql_escape($old_session_id) . "'
- AND session_user_id = {$login['user_row']['user_id']}";
- $db->sql_query($sql);
- }
-
- return array(
- 'status' => LOGIN_SUCCESS,
- 'error_msg' => false,
- 'user_row' => $login['user_row'],
- );
- }
-
- return array(
- 'status' => LOGIN_BREAK,
- 'error_msg' => $result,
- 'user_row' => $login['user_row'],
- );
- }
-
- return $login;
- }
-
- trigger_error('Authentication method not found', E_USER_ERROR);
- }
-
- /**
- * Fill auth_option statement for later querying based on the supplied options
- */
- function build_auth_option_statement($key, $auth_options, &$sql_opts)
- {
- global $db;
-
- if (!is_array($auth_options))
- {
- if (strpos($auth_options, '%') !== false)
- {
- $sql_opts = "AND $key " . $db->sql_like_expression(str_replace('%', $db->any_char, $auth_options));
- }
- else
- {
- $sql_opts = "AND $key = '" . $db->sql_escape($auth_options) . "'";
- }
- }
- else
- {
- $is_like_expression = false;
-
- foreach ($auth_options as $option)
- {
- if (strpos($option, '%') !== false)
- {
- $is_like_expression = true;
- }
- }
-
- if (!$is_like_expression)
- {
- $sql_opts = 'AND ' . $db->sql_in_set($key, $auth_options);
- }
- else
- {
- $sql = array();
-
- foreach ($auth_options as $option)
- {
- if (strpos($option, '%') !== false)
- {
- $sql[] = $key . ' ' . $db->sql_like_expression(str_replace('%', $db->any_char, $option));
- }
- else
- {
- $sql[] = $key . " = '" . $db->sql_escape($option) . "'";
- }
- }
-
- $sql_opts = 'AND (' . implode(' OR ', $sql) . ')';
- }
- }
- }
-}
diff --git a/phpBB/includes/auth/auth.php b/phpBB/includes/auth/auth.php
new file mode 100644
index 0000000000..e3bccaf47b
--- /dev/null
+++ b/phpBB/includes/auth/auth.php
@@ -0,0 +1,1061 @@
+acl = $this->cache = $this->acl_options = array();
+ $this->acl_forum_ids = false;
+
+ if (($this->acl_options = $cache->get('_acl_options')) === false)
+ {
+ $sql = 'SELECT auth_option_id, auth_option, is_global, is_local
+ FROM ' . ACL_OPTIONS_TABLE . '
+ ORDER BY auth_option_id';
+ $result = $db->sql_query($sql);
+
+ $global = $local = 0;
+ $this->acl_options = array();
+ while ($row = $db->sql_fetchrow($result))
+ {
+ if ($row['is_global'])
+ {
+ $this->acl_options['global'][$row['auth_option']] = $global++;
+ }
+
+ if ($row['is_local'])
+ {
+ $this->acl_options['local'][$row['auth_option']] = $local++;
+ }
+
+ $this->acl_options['id'][$row['auth_option']] = (int) $row['auth_option_id'];
+ $this->acl_options['option'][(int) $row['auth_option_id']] = $row['auth_option'];
+ }
+ $db->sql_freeresult($result);
+
+ $cache->put('_acl_options', $this->acl_options);
+ }
+
+ if (!trim($userdata['user_permissions']))
+ {
+ $this->acl_cache($userdata);
+ }
+
+ // Fill ACL array
+ $this->_fill_acl($userdata['user_permissions']);
+
+ // Verify bitstring length with options provided...
+ $renew = false;
+ $global_length = sizeof($this->acl_options['global']);
+ $local_length = sizeof($this->acl_options['local']);
+
+ // Specify comparing length (bitstring is padded to 31 bits)
+ $global_length = ($global_length % 31) ? ($global_length - ($global_length % 31) + 31) : $global_length;
+ $local_length = ($local_length % 31) ? ($local_length - ($local_length % 31) + 31) : $local_length;
+
+ // You thought we are finished now? Noooo... now compare them.
+ foreach ($this->acl as $forum_id => $bitstring)
+ {
+ if (($forum_id && strlen($bitstring) != $local_length) || (!$forum_id && strlen($bitstring) != $global_length))
+ {
+ $renew = true;
+ break;
+ }
+ }
+
+ // If a bitstring within the list does not match the options, we have a user with incorrect permissions set and need to renew them
+ if ($renew)
+ {
+ $this->acl_cache($userdata);
+ $this->_fill_acl($userdata['user_permissions']);
+ }
+
+ return;
+ }
+
+ /**
+ * Fill ACL array with relevant bitstrings from user_permissions column
+ * @access private
+ */
+ function _fill_acl($user_permissions)
+ {
+ $seq_cache = array();
+ $this->acl = array();
+ $user_permissions = explode("\n", $user_permissions);
+
+ foreach ($user_permissions as $f => $seq)
+ {
+ if ($seq)
+ {
+ $i = 0;
+
+ if (!isset($this->acl[$f]))
+ {
+ $this->acl[$f] = '';
+ }
+
+ while ($subseq = substr($seq, $i, 6))
+ {
+ if (isset($seq_cache[$subseq]))
+ {
+ $converted = $seq_cache[$subseq];
+ }
+ else
+ {
+ $converted = $seq_cache[$subseq] = str_pad(base_convert($subseq, 36, 2), 31, 0, STR_PAD_LEFT);
+ }
+
+ // We put the original bitstring into the acl array
+ $this->acl[$f] .= $converted;
+ $i += 6;
+ }
+ }
+ }
+ }
+
+ /**
+ * Look up an option
+ * if the option is prefixed with !, then the result becomes negated
+ *
+ * If a forum id is specified the local option will be combined with a global option if one exist.
+ * If a forum id is not specified, only the global option will be checked.
+ */
+ function acl_get($opt, $f = 0)
+ {
+ $negate = false;
+
+ if (strpos($opt, '!') === 0)
+ {
+ $negate = true;
+ $opt = substr($opt, 1);
+ }
+
+ if (!isset($this->cache[$f][$opt]))
+ {
+ // We combine the global/local option with an OR because some options are global and local.
+ // If the user has the global permission the local one is true too and vice versa
+ $this->cache[$f][$opt] = false;
+
+ // Is this option a global permission setting?
+ if (isset($this->acl_options['global'][$opt]))
+ {
+ if (isset($this->acl[0]))
+ {
+ $this->cache[$f][$opt] = $this->acl[0][$this->acl_options['global'][$opt]];
+ }
+ }
+
+ // Is this option a local permission setting?
+ // But if we check for a global option only, we won't combine the options...
+ if ($f != 0 && isset($this->acl_options['local'][$opt]))
+ {
+ if (isset($this->acl[$f]) && isset($this->acl[$f][$this->acl_options['local'][$opt]]))
+ {
+ $this->cache[$f][$opt] |= $this->acl[$f][$this->acl_options['local'][$opt]];
+ }
+ }
+ }
+
+ // Founder always has all global options set to true...
+ return ($negate) ? !$this->cache[$f][$opt] : $this->cache[$f][$opt];
+ }
+
+ /**
+ * Get forums with the specified permission setting
+ * if the option is prefixed with !, then the result becomes nagated
+ *
+ * @param bool $clean set to true if only values needs to be returned which are set/unset
+ */
+ function acl_getf($opt, $clean = false)
+ {
+ $acl_f = array();
+ $negate = false;
+
+ if (strpos($opt, '!') === 0)
+ {
+ $negate = true;
+ $opt = substr($opt, 1);
+ }
+
+ // If we retrieve a list of forums not having permissions in, we need to get every forum_id
+ if ($negate)
+ {
+ if ($this->acl_forum_ids === false)
+ {
+ global $db;
+
+ $sql = 'SELECT forum_id
+ FROM ' . FORUMS_TABLE;
+
+ if (sizeof($this->acl))
+ {
+ $sql .= ' WHERE ' . $db->sql_in_set('forum_id', array_keys($this->acl), true);
+ }
+ $result = $db->sql_query($sql);
+
+ $this->acl_forum_ids = array();
+ while ($row = $db->sql_fetchrow($result))
+ {
+ $this->acl_forum_ids[] = $row['forum_id'];
+ }
+ $db->sql_freeresult($result);
+ }
+ }
+
+ if (isset($this->acl_options['local'][$opt]))
+ {
+ foreach ($this->acl as $f => $bitstring)
+ {
+ // Skip global settings
+ if (!$f)
+ {
+ continue;
+ }
+
+ $allowed = (!isset($this->cache[$f][$opt])) ? $this->acl_get($opt, $f) : $this->cache[$f][$opt];
+
+ if (!$clean)
+ {
+ $acl_f[$f][$opt] = ($negate) ? !$allowed : $allowed;
+ }
+ else
+ {
+ if (($negate && !$allowed) || (!$negate && $allowed))
+ {
+ $acl_f[$f][$opt] = 1;
+ }
+ }
+ }
+ }
+
+ // If we get forum_ids not having this permission, we need to fill the remaining parts
+ if ($negate && sizeof($this->acl_forum_ids))
+ {
+ foreach ($this->acl_forum_ids as $f)
+ {
+ $acl_f[$f][$opt] = 1;
+ }
+ }
+
+ return $acl_f;
+ }
+
+ /**
+ * Get local permission state for any forum.
+ *
+ * Returns true if user has the permission in one or more forums, false if in no forum.
+ * If global option is checked it returns the global state (same as acl_get($opt))
+ * Local option has precedence...
+ */
+ function acl_getf_global($opt)
+ {
+ if (is_array($opt))
+ {
+ // evaluates to true as soon as acl_getf_global is true for one option
+ foreach ($opt as $check_option)
+ {
+ if ($this->acl_getf_global($check_option))
+ {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ if (isset($this->acl_options['local'][$opt]))
+ {
+ foreach ($this->acl as $f => $bitstring)
+ {
+ // Skip global settings
+ if (!$f)
+ {
+ continue;
+ }
+
+ // as soon as the user has any permission we're done so return true
+ if ((!isset($this->cache[$f][$opt])) ? $this->acl_get($opt, $f) : $this->cache[$f][$opt])
+ {
+ return true;
+ }
+ }
+ }
+ else if (isset($this->acl_options['global'][$opt]))
+ {
+ return $this->acl_get($opt);
+ }
+
+ return false;
+ }
+
+ /**
+ * Get permission settings (more than one)
+ */
+ function acl_gets()
+ {
+ $args = func_get_args();
+ $f = array_pop($args);
+
+ if (!is_numeric($f))
+ {
+ $args[] = $f;
+ $f = 0;
+ }
+
+ // alternate syntax: acl_gets(array('m_', 'a_'), $forum_id)
+ if (is_array($args[0]))
+ {
+ $args = $args[0];
+ }
+
+ $acl = 0;
+ foreach ($args as $opt)
+ {
+ $acl |= $this->acl_get($opt, $f);
+ }
+
+ return $acl;
+ }
+
+ /**
+ * Get permission listing based on user_id/options/forum_ids
+ *
+ * Be careful when using this function with permissions a_, m_, u_ and f_ !
+ * It may not work correctly. When a user group grants an a_* permission,
+ * e.g. a_foo, but the user's a_foo permission is set to "Never", then
+ * the user does not in fact have the a_ permission.
+ * But the user will still be listed as having the a_ permission.
+ *
+ * For more information see: http://tracker.phpbb.com/browse/PHPBB3-10252
+ */
+ function acl_get_list($user_id = false, $opts = false, $forum_id = false)
+ {
+ if ($user_id !== false && !is_array($user_id) && $opts === false && $forum_id === false)
+ {
+ $hold_ary = array($user_id => $this->acl_raw_data_single_user($user_id));
+ }
+ else
+ {
+ $hold_ary = $this->acl_raw_data($user_id, $opts, $forum_id);
+ }
+
+ $auth_ary = array();
+ foreach ($hold_ary as $user_id => $forum_ary)
+ {
+ foreach ($forum_ary as $forum_id => $auth_option_ary)
+ {
+ foreach ($auth_option_ary as $auth_option => $auth_setting)
+ {
+ if ($auth_setting)
+ {
+ $auth_ary[$forum_id][$auth_option][] = $user_id;
+ }
+ }
+ }
+ }
+
+ return $auth_ary;
+ }
+
+ /**
+ * Cache data to user_permissions row
+ */
+ function acl_cache(&$userdata)
+ {
+ global $db;
+
+ // Empty user_permissions
+ $userdata['user_permissions'] = '';
+
+ $hold_ary = $this->acl_raw_data_single_user($userdata['user_id']);
+
+ // Key 0 in $hold_ary are global options, all others are forum_ids
+
+ // If this user is founder we're going to force fill the admin options ...
+ if ($userdata['user_type'] == USER_FOUNDER)
+ {
+ foreach ($this->acl_options['global'] as $opt => $id)
+ {
+ if (strpos($opt, 'a_') === 0)
+ {
+ $hold_ary[0][$this->acl_options['id'][$opt]] = ACL_YES;
+ }
+ }
+ }
+
+ $hold_str = $this->build_bitstring($hold_ary);
+
+ if ($hold_str)
+ {
+ $userdata['user_permissions'] = $hold_str;
+
+ $sql = 'UPDATE ' . USERS_TABLE . "
+ SET user_permissions = '" . $db->sql_escape($userdata['user_permissions']) . "',
+ user_perm_from = 0
+ WHERE user_id = " . $userdata['user_id'];
+ $db->sql_query($sql);
+ }
+
+ return;
+ }
+
+ /**
+ * Build bitstring from permission set
+ */
+ function build_bitstring(&$hold_ary)
+ {
+ $hold_str = '';
+
+ if (sizeof($hold_ary))
+ {
+ ksort($hold_ary);
+
+ $last_f = 0;
+
+ foreach ($hold_ary as $f => $auth_ary)
+ {
+ $ary_key = (!$f) ? 'global' : 'local';
+
+ $bitstring = array();
+ foreach ($this->acl_options[$ary_key] as $opt => $id)
+ {
+ if (isset($auth_ary[$this->acl_options['id'][$opt]]))
+ {
+ $bitstring[$id] = $auth_ary[$this->acl_options['id'][$opt]];
+
+ $option_key = substr($opt, 0, strpos($opt, '_') + 1);
+
+ // If one option is allowed, the global permission for this option has to be allowed too
+ // example: if the user has the a_ permission this means he has one or more a_* permissions
+ if ($auth_ary[$this->acl_options['id'][$opt]] == ACL_YES && (!isset($bitstring[$this->acl_options[$ary_key][$option_key]]) || $bitstring[$this->acl_options[$ary_key][$option_key]] == ACL_NEVER))
+ {
+ $bitstring[$this->acl_options[$ary_key][$option_key]] = ACL_YES;
+ }
+ }
+ else
+ {
+ $bitstring[$id] = ACL_NEVER;
+ }
+ }
+
+ // Now this bitstring defines the permission setting for the current forum $f (or global setting)
+ $bitstring = implode('', $bitstring);
+
+ // The line number indicates the id, therefore we have to add empty lines for those ids not present
+ $hold_str .= str_repeat("\n", $f - $last_f);
+
+ // Convert bitstring for storage - we do not use binary/bytes because PHP's string functions are not fully binary safe
+ for ($i = 0, $bit_length = strlen($bitstring); $i < $bit_length; $i += 31)
+ {
+ $hold_str .= str_pad(base_convert(str_pad(substr($bitstring, $i, 31), 31, 0, STR_PAD_RIGHT), 2, 36), 6, 0, STR_PAD_LEFT);
+ }
+
+ $last_f = $f;
+ }
+ unset($bitstring);
+
+ $hold_str = rtrim($hold_str);
+ }
+
+ return $hold_str;
+ }
+
+ /**
+ * Clear one or all users cached permission settings
+ */
+ function acl_clear_prefetch($user_id = false)
+ {
+ global $db, $cache;
+
+ // Rebuild options cache
+ $cache->destroy('_role_cache');
+
+ $sql = 'SELECT *
+ FROM ' . ACL_ROLES_DATA_TABLE . '
+ ORDER BY role_id ASC';
+ $result = $db->sql_query($sql);
+
+ $this->role_cache = array();
+ while ($row = $db->sql_fetchrow($result))
+ {
+ $this->role_cache[$row['role_id']][$row['auth_option_id']] = (int) $row['auth_setting'];
+ }
+ $db->sql_freeresult($result);
+
+ foreach ($this->role_cache as $role_id => $role_options)
+ {
+ $this->role_cache[$role_id] = serialize($role_options);
+ }
+
+ $cache->put('_role_cache', $this->role_cache);
+
+ // Now empty user permissions
+ $where_sql = '';
+
+ if ($user_id !== false)
+ {
+ $user_id = (!is_array($user_id)) ? $user_id = array((int) $user_id) : array_map('intval', $user_id);
+ $where_sql = ' WHERE ' . $db->sql_in_set('user_id', $user_id);
+ }
+
+ $sql = 'UPDATE ' . USERS_TABLE . "
+ SET user_permissions = '',
+ user_perm_from = 0
+ $where_sql";
+ $db->sql_query($sql);
+
+ return;
+ }
+
+ /**
+ * Get assigned roles
+ */
+ function acl_role_data($user_type, $role_type, $ug_id = false, $forum_id = false)
+ {
+ global $db;
+
+ $roles = array();
+
+ $sql_id = ($user_type == 'user') ? 'user_id' : 'group_id';
+
+ $sql_ug = ($ug_id !== false) ? ((!is_array($ug_id)) ? "AND a.$sql_id = $ug_id" : 'AND ' . $db->sql_in_set("a.$sql_id", $ug_id)) : '';
+ $sql_forum = ($forum_id !== false) ? ((!is_array($forum_id)) ? "AND a.forum_id = $forum_id" : 'AND ' . $db->sql_in_set('a.forum_id', $forum_id)) : '';
+
+ // Grab assigned roles...
+ $sql = 'SELECT a.auth_role_id, a.' . $sql_id . ', a.forum_id
+ FROM ' . (($user_type == 'user') ? ACL_USERS_TABLE : ACL_GROUPS_TABLE) . ' a, ' . ACL_ROLES_TABLE . " r
+ WHERE a.auth_role_id = r.role_id
+ AND r.role_type = '" . $db->sql_escape($role_type) . "'
+ $sql_ug
+ $sql_forum
+ ORDER BY r.role_order ASC";
+ $result = $db->sql_query($sql);
+
+ while ($row = $db->sql_fetchrow($result))
+ {
+ $roles[$row[$sql_id]][$row['forum_id']] = $row['auth_role_id'];
+ }
+ $db->sql_freeresult($result);
+
+ return $roles;
+ }
+
+ /**
+ * Get raw acl data based on user/option/forum
+ */
+ function acl_raw_data($user_id = false, $opts = false, $forum_id = false)
+ {
+ global $db;
+
+ $sql_user = ($user_id !== false) ? ((!is_array($user_id)) ? 'user_id = ' . (int) $user_id : $db->sql_in_set('user_id', array_map('intval', $user_id))) : '';
+ $sql_forum = ($forum_id !== false) ? ((!is_array($forum_id)) ? 'AND a.forum_id = ' . (int) $forum_id : 'AND ' . $db->sql_in_set('a.forum_id', array_map('intval', $forum_id))) : '';
+
+ $sql_opts = $sql_opts_select = $sql_opts_from = '';
+ $hold_ary = array();
+
+ if ($opts !== false)
+ {
+ $sql_opts_select = ', ao.auth_option';
+ $sql_opts_from = ', ' . ACL_OPTIONS_TABLE . ' ao';
+ $this->build_auth_option_statement('ao.auth_option', $opts, $sql_opts);
+ }
+
+ $sql_ary = array();
+
+ // Grab non-role settings - user-specific
+ $sql_ary[] = 'SELECT a.user_id, a.forum_id, a.auth_setting, a.auth_option_id' . $sql_opts_select . '
+ FROM ' . ACL_USERS_TABLE . ' a' . $sql_opts_from . '
+ WHERE a.auth_role_id = 0 ' .
+ (($sql_opts_from) ? 'AND a.auth_option_id = ao.auth_option_id ' : '') .
+ (($sql_user) ? 'AND a.' . $sql_user : '') . "
+ $sql_forum
+ $sql_opts";
+
+ // Now the role settings - user-specific
+ $sql_ary[] = 'SELECT a.user_id, a.forum_id, r.auth_option_id, r.auth_setting, r.auth_option_id' . $sql_opts_select . '
+ FROM ' . ACL_USERS_TABLE . ' a, ' . ACL_ROLES_DATA_TABLE . ' r' . $sql_opts_from . '
+ WHERE a.auth_role_id = r.role_id ' .
+ (($sql_opts_from) ? 'AND r.auth_option_id = ao.auth_option_id ' : '') .
+ (($sql_user) ? 'AND a.' . $sql_user : '') . "
+ $sql_forum
+ $sql_opts";
+
+ foreach ($sql_ary as $sql)
+ {
+ $result = $db->sql_query($sql);
+
+ while ($row = $db->sql_fetchrow($result))
+ {
+ $option = ($sql_opts_select) ? $row['auth_option'] : $this->acl_options['option'][$row['auth_option_id']];
+ $hold_ary[$row['user_id']][$row['forum_id']][$option] = $row['auth_setting'];
+ }
+ $db->sql_freeresult($result);
+ }
+
+ $sql_ary = array();
+
+ // Now grab group settings - non-role specific...
+ $sql_ary[] = 'SELECT ug.user_id, a.forum_id, a.auth_setting, a.auth_option_id' . $sql_opts_select . '
+ FROM ' . ACL_GROUPS_TABLE . ' a, ' . USER_GROUP_TABLE . ' ug, ' . GROUPS_TABLE . ' g' . $sql_opts_from . '
+ WHERE a.auth_role_id = 0 ' .
+ (($sql_opts_from) ? 'AND a.auth_option_id = ao.auth_option_id ' : '') . '
+ AND a.group_id = ug.group_id
+ AND g.group_id = ug.group_id
+ AND ug.user_pending = 0
+ AND NOT (ug.group_leader = 1 AND g.group_skip_auth = 1)
+ ' . (($sql_user) ? 'AND ug.' . $sql_user : '') . "
+ $sql_forum
+ $sql_opts";
+
+ // Now grab group settings - role specific...
+ $sql_ary[] = 'SELECT ug.user_id, a.forum_id, r.auth_setting, r.auth_option_id' . $sql_opts_select . '
+ FROM ' . ACL_GROUPS_TABLE . ' a, ' . USER_GROUP_TABLE . ' ug, ' . GROUPS_TABLE . ' g, ' . ACL_ROLES_DATA_TABLE . ' r' . $sql_opts_from . '
+ WHERE a.auth_role_id = r.role_id ' .
+ (($sql_opts_from) ? 'AND r.auth_option_id = ao.auth_option_id ' : '') . '
+ AND a.group_id = ug.group_id
+ AND g.group_id = ug.group_id
+ AND ug.user_pending = 0
+ AND NOT (ug.group_leader = 1 AND g.group_skip_auth = 1)
+ ' . (($sql_user) ? 'AND ug.' . $sql_user : '') . "
+ $sql_forum
+ $sql_opts";
+
+ foreach ($sql_ary as $sql)
+ {
+ $result = $db->sql_query($sql);
+
+ while ($row = $db->sql_fetchrow($result))
+ {
+ $option = ($sql_opts_select) ? $row['auth_option'] : $this->acl_options['option'][$row['auth_option_id']];
+
+ if (!isset($hold_ary[$row['user_id']][$row['forum_id']][$option]) || (isset($hold_ary[$row['user_id']][$row['forum_id']][$option]) && $hold_ary[$row['user_id']][$row['forum_id']][$option] != ACL_NEVER))
+ {
+ $hold_ary[$row['user_id']][$row['forum_id']][$option] = $row['auth_setting'];
+
+ // If we detect ACL_NEVER, we will unset the flag option (within building the bitstring it is correctly set again)
+ if ($row['auth_setting'] == ACL_NEVER)
+ {
+ $flag = substr($option, 0, strpos($option, '_') + 1);
+
+ if (isset($hold_ary[$row['user_id']][$row['forum_id']][$flag]) && $hold_ary[$row['user_id']][$row['forum_id']][$flag] == ACL_YES)
+ {
+ unset($hold_ary[$row['user_id']][$row['forum_id']][$flag]);
+
+/* if (in_array(ACL_YES, $hold_ary[$row['user_id']][$row['forum_id']]))
+ {
+ $hold_ary[$row['user_id']][$row['forum_id']][$flag] = ACL_YES;
+ }
+*/
+ }
+ }
+ }
+ }
+ $db->sql_freeresult($result);
+ }
+
+ return $hold_ary;
+ }
+
+ /**
+ * Get raw user based permission settings
+ */
+ function acl_user_raw_data($user_id = false, $opts = false, $forum_id = false)
+ {
+ global $db;
+
+ $sql_user = ($user_id !== false) ? ((!is_array($user_id)) ? 'user_id = ' . (int) $user_id : $db->sql_in_set('user_id', array_map('intval', $user_id))) : '';
+ $sql_forum = ($forum_id !== false) ? ((!is_array($forum_id)) ? 'AND a.forum_id = ' . (int) $forum_id : 'AND ' . $db->sql_in_set('a.forum_id', array_map('intval', $forum_id))) : '';
+
+ $sql_opts = '';
+ $hold_ary = $sql_ary = array();
+
+ if ($opts !== false)
+ {
+ $this->build_auth_option_statement('ao.auth_option', $opts, $sql_opts);
+ }
+
+ // Grab user settings - non-role specific...
+ $sql_ary[] = 'SELECT a.user_id, a.forum_id, a.auth_setting, a.auth_option_id, ao.auth_option
+ FROM ' . ACL_USERS_TABLE . ' a, ' . ACL_OPTIONS_TABLE . ' ao
+ WHERE a.auth_role_id = 0
+ AND a.auth_option_id = ao.auth_option_id ' .
+ (($sql_user) ? 'AND a.' . $sql_user : '') . "
+ $sql_forum
+ $sql_opts
+ ORDER BY a.forum_id, ao.auth_option";
+
+ // Now the role settings - user-specific
+ $sql_ary[] = 'SELECT a.user_id, a.forum_id, r.auth_option_id, r.auth_setting, r.auth_option_id, ao.auth_option
+ FROM ' . ACL_USERS_TABLE . ' a, ' . ACL_ROLES_DATA_TABLE . ' r, ' . ACL_OPTIONS_TABLE . ' ao
+ WHERE a.auth_role_id = r.role_id
+ AND r.auth_option_id = ao.auth_option_id ' .
+ (($sql_user) ? 'AND a.' . $sql_user : '') . "
+ $sql_forum
+ $sql_opts
+ ORDER BY a.forum_id, ao.auth_option";
+
+ foreach ($sql_ary as $sql)
+ {
+ $result = $db->sql_query($sql);
+
+ while ($row = $db->sql_fetchrow($result))
+ {
+ $hold_ary[$row['user_id']][$row['forum_id']][$row['auth_option']] = $row['auth_setting'];
+ }
+ $db->sql_freeresult($result);
+ }
+
+ return $hold_ary;
+ }
+
+ /**
+ * Get raw group based permission settings
+ */
+ function acl_group_raw_data($group_id = false, $opts = false, $forum_id = false)
+ {
+ global $db;
+
+ $sql_group = ($group_id !== false) ? ((!is_array($group_id)) ? 'group_id = ' . (int) $group_id : $db->sql_in_set('group_id', array_map('intval', $group_id))) : '';
+ $sql_forum = ($forum_id !== false) ? ((!is_array($forum_id)) ? 'AND a.forum_id = ' . (int) $forum_id : 'AND ' . $db->sql_in_set('a.forum_id', array_map('intval', $forum_id))) : '';
+
+ $sql_opts = '';
+ $hold_ary = $sql_ary = array();
+
+ if ($opts !== false)
+ {
+ $this->build_auth_option_statement('ao.auth_option', $opts, $sql_opts);
+ }
+
+ // Grab group settings - non-role specific...
+ $sql_ary[] = 'SELECT a.group_id, a.forum_id, a.auth_setting, a.auth_option_id, ao.auth_option
+ FROM ' . ACL_GROUPS_TABLE . ' a, ' . ACL_OPTIONS_TABLE . ' ao
+ WHERE a.auth_role_id = 0
+ AND a.auth_option_id = ao.auth_option_id ' .
+ (($sql_group) ? 'AND a.' . $sql_group : '') . "
+ $sql_forum
+ $sql_opts
+ ORDER BY a.forum_id, ao.auth_option";
+
+ // Now grab group settings - role specific...
+ $sql_ary[] = 'SELECT a.group_id, a.forum_id, r.auth_setting, r.auth_option_id, ao.auth_option
+ FROM ' . ACL_GROUPS_TABLE . ' a, ' . ACL_ROLES_DATA_TABLE . ' r, ' . ACL_OPTIONS_TABLE . ' ao
+ WHERE a.auth_role_id = r.role_id
+ AND r.auth_option_id = ao.auth_option_id ' .
+ (($sql_group) ? 'AND a.' . $sql_group : '') . "
+ $sql_forum
+ $sql_opts
+ ORDER BY a.forum_id, ao.auth_option";
+
+ foreach ($sql_ary as $sql)
+ {
+ $result = $db->sql_query($sql);
+
+ while ($row = $db->sql_fetchrow($result))
+ {
+ $hold_ary[$row['group_id']][$row['forum_id']][$row['auth_option']] = $row['auth_setting'];
+ }
+ $db->sql_freeresult($result);
+ }
+
+ return $hold_ary;
+ }
+
+ /**
+ * Get raw acl data based on user for caching user_permissions
+ * This function returns the same data as acl_raw_data(), but without the user id as the first key within the array.
+ */
+ function acl_raw_data_single_user($user_id)
+ {
+ global $db, $cache;
+
+ // Check if the role-cache is there
+ if (($this->role_cache = $cache->get('_role_cache')) === false)
+ {
+ $this->role_cache = array();
+
+ // We pre-fetch roles
+ $sql = 'SELECT *
+ FROM ' . ACL_ROLES_DATA_TABLE . '
+ ORDER BY role_id ASC';
+ $result = $db->sql_query($sql);
+
+ while ($row = $db->sql_fetchrow($result))
+ {
+ $this->role_cache[$row['role_id']][$row['auth_option_id']] = (int) $row['auth_setting'];
+ }
+ $db->sql_freeresult($result);
+
+ foreach ($this->role_cache as $role_id => $role_options)
+ {
+ $this->role_cache[$role_id] = serialize($role_options);
+ }
+
+ $cache->put('_role_cache', $this->role_cache);
+ }
+
+ $hold_ary = array();
+
+ // Grab user-specific permission settings
+ $sql = 'SELECT forum_id, auth_option_id, auth_role_id, auth_setting
+ FROM ' . ACL_USERS_TABLE . '
+ WHERE user_id = ' . $user_id;
+ $result = $db->sql_query($sql);
+
+ while ($row = $db->sql_fetchrow($result))
+ {
+ // If a role is assigned, assign all options included within this role. Else, only set this one option.
+ if ($row['auth_role_id'])
+ {
+ $hold_ary[$row['forum_id']] = (empty($hold_ary[$row['forum_id']])) ? unserialize($this->role_cache[$row['auth_role_id']]) : $hold_ary[$row['forum_id']] + unserialize($this->role_cache[$row['auth_role_id']]);
+ }
+ else
+ {
+ $hold_ary[$row['forum_id']][$row['auth_option_id']] = $row['auth_setting'];
+ }
+ }
+ $db->sql_freeresult($result);
+
+ // Now grab group-specific permission settings
+ $sql = 'SELECT a.forum_id, a.auth_option_id, a.auth_role_id, a.auth_setting
+ FROM ' . ACL_GROUPS_TABLE . ' a, ' . USER_GROUP_TABLE . ' ug, ' . GROUPS_TABLE . ' g
+ WHERE a.group_id = ug.group_id
+ AND g.group_id = ug.group_id
+ AND ug.user_pending = 0
+ AND NOT (ug.group_leader = 1 AND g.group_skip_auth = 1)
+ AND ug.user_id = ' . $user_id;
+ $result = $db->sql_query($sql);
+
+ while ($row = $db->sql_fetchrow($result))
+ {
+ if (!$row['auth_role_id'])
+ {
+ $this->_set_group_hold_ary($hold_ary[$row['forum_id']], $row['auth_option_id'], $row['auth_setting']);
+ }
+ else if (!empty($this->role_cache[$row['auth_role_id']]))
+ {
+ foreach (unserialize($this->role_cache[$row['auth_role_id']]) as $option_id => $setting)
+ {
+ $this->_set_group_hold_ary($hold_ary[$row['forum_id']], $option_id, $setting);
+ }
+ }
+ }
+ $db->sql_freeresult($result);
+
+ return $hold_ary;
+ }
+
+ /**
+ * Private function snippet for setting a specific piece of the hold_ary
+ */
+ function _set_group_hold_ary(&$hold_ary, $option_id, $setting)
+ {
+ if (!isset($hold_ary[$option_id]) || (isset($hold_ary[$option_id]) && $hold_ary[$option_id] != ACL_NEVER))
+ {
+ $hold_ary[$option_id] = $setting;
+
+ // If we detect ACL_NEVER, we will unset the flag option (within building the bitstring it is correctly set again)
+ if ($setting == ACL_NEVER)
+ {
+ $flag = substr($this->acl_options['option'][$option_id], 0, strpos($this->acl_options['option'][$option_id], '_') + 1);
+ $flag = (int) $this->acl_options['id'][$flag];
+
+ if (isset($hold_ary[$flag]) && $hold_ary[$flag] == ACL_YES)
+ {
+ unset($hold_ary[$flag]);
+
+/* This is uncommented, because i suspect this being slightly wrong due to mixed permission classes being possible
+ if (in_array(ACL_YES, $hold_ary))
+ {
+ $hold_ary[$flag] = ACL_YES;
+ }*/
+ }
+ }
+ }
+ }
+
+ /**
+ * Authentication plug-ins is largely down to Sergey Kanareykin, our thanks to him.
+ */
+ function login($username, $password, $autologin = false, $viewonline = 1, $admin = 0)
+ {
+ global $config, $db, $user, $phpbb_root_path, $phpEx;
+
+ $method = trim(basename($config['auth_method']));
+ include_once($phpbb_root_path . 'includes/auth/auth_' . $method . '.' . $phpEx);
+
+ $method = 'login_' . $method;
+ if (function_exists($method))
+ {
+ $login = $method($username, $password, $user->ip, $user->browser, $user->forwarded_for);
+
+ // If the auth module wants us to create an empty profile do so and then treat the status as LOGIN_SUCCESS
+ if ($login['status'] == LOGIN_SUCCESS_CREATE_PROFILE)
+ {
+ // we are going to use the user_add function so include functions_user.php if it wasn't defined yet
+ if (!function_exists('user_add'))
+ {
+ include($phpbb_root_path . 'includes/functions_user.' . $phpEx);
+ }
+
+ user_add($login['user_row'], (isset($login['cp_data'])) ? $login['cp_data'] : false);
+
+ $sql = 'SELECT user_id, username, user_password, user_passchg, user_email, user_type
+ FROM ' . USERS_TABLE . "
+ WHERE username_clean = '" . $db->sql_escape(utf8_clean_string($username)) . "'";
+ $result = $db->sql_query($sql);
+ $row = $db->sql_fetchrow($result);
+ $db->sql_freeresult($result);
+
+ if (!$row)
+ {
+ return array(
+ 'status' => LOGIN_ERROR_EXTERNAL_AUTH,
+ 'error_msg' => 'AUTH_NO_PROFILE_CREATED',
+ 'user_row' => array('user_id' => ANONYMOUS),
+ );
+ }
+
+ $login = array(
+ 'status' => LOGIN_SUCCESS,
+ 'error_msg' => false,
+ 'user_row' => $row,
+ );
+ }
+
+ // If login succeeded, we will log the user in... else we pass the login array through...
+ if ($login['status'] == LOGIN_SUCCESS)
+ {
+ $old_session_id = $user->session_id;
+
+ if ($admin)
+ {
+ global $SID, $_SID;
+
+ $cookie_expire = time() - 31536000;
+ $user->set_cookie('u', '', $cookie_expire);
+ $user->set_cookie('sid', '', $cookie_expire);
+ unset($cookie_expire);
+
+ $SID = '?sid=';
+ $user->session_id = $_SID = '';
+ }
+
+ $result = $user->session_create($login['user_row']['user_id'], $admin, $autologin, $viewonline);
+
+ // Successful session creation
+ if ($result === true)
+ {
+ // If admin re-authentication we remove the old session entry because a new one has been created...
+ if ($admin)
+ {
+ // the login array is used because the user ids do not differ for re-authentication
+ $sql = 'DELETE FROM ' . SESSIONS_TABLE . "
+ WHERE session_id = '" . $db->sql_escape($old_session_id) . "'
+ AND session_user_id = {$login['user_row']['user_id']}";
+ $db->sql_query($sql);
+ }
+
+ return array(
+ 'status' => LOGIN_SUCCESS,
+ 'error_msg' => false,
+ 'user_row' => $login['user_row'],
+ );
+ }
+
+ return array(
+ 'status' => LOGIN_BREAK,
+ 'error_msg' => $result,
+ 'user_row' => $login['user_row'],
+ );
+ }
+
+ return $login;
+ }
+
+ trigger_error('Authentication method not found', E_USER_ERROR);
+ }
+
+ /**
+ * Fill auth_option statement for later querying based on the supplied options
+ */
+ function build_auth_option_statement($key, $auth_options, &$sql_opts)
+ {
+ global $db;
+
+ if (!is_array($auth_options))
+ {
+ if (strpos($auth_options, '%') !== false)
+ {
+ $sql_opts = "AND $key " . $db->sql_like_expression(str_replace('%', $db->any_char, $auth_options));
+ }
+ else
+ {
+ $sql_opts = "AND $key = '" . $db->sql_escape($auth_options) . "'";
+ }
+ }
+ else
+ {
+ $is_like_expression = false;
+
+ foreach ($auth_options as $option)
+ {
+ if (strpos($option, '%') !== false)
+ {
+ $is_like_expression = true;
+ }
+ }
+
+ if (!$is_like_expression)
+ {
+ $sql_opts = 'AND ' . $db->sql_in_set($key, $auth_options);
+ }
+ else
+ {
+ $sql = array();
+
+ foreach ($auth_options as $option)
+ {
+ if (strpos($option, '%') !== false)
+ {
+ $sql[] = $key . ' ' . $db->sql_like_expression(str_replace('%', $db->any_char, $option));
+ }
+ else
+ {
+ $sql[] = $key . " = '" . $db->sql_escape($option) . "'";
+ }
+ }
+
+ $sql_opts = 'AND (' . implode(' OR ', $sql) . ')';
+ }
+ }
+ }
+}
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))
--
cgit v1.2.1
From b8b342be2d238616b96ace9acbe8af2e18ba1e7a Mon Sep 17 00:00:00 2001
From: Richard Foote
Date: Sat, 31 Mar 2012 12:46:44 -0400
Subject: [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)',
--
cgit v1.2.1
From b3f46b9565117940b79c7530a1c21336cd072073 Mon Sep 17 00:00:00 2001
From: Vjacheslav Trushkin
Date: Sat, 31 Mar 2012 21:20:18 +0300
Subject: [ticket/10735] Changing locator paths structure
Changing locator paths to 2 dimensional array
PHPBB3-10735
---
phpBB/includes/extension/finder.php | 18 +++++--
phpBB/includes/style/extension_path_provider.php | 36 ++++++-------
phpBB/includes/style/path_provider.php | 16 +-----
phpBB/includes/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) . '_';
--
cgit v1.2.1
From 2ce73baeab35adc3515a04c1db38af62c98d5c93 Mon Sep 17 00:00:00 2001
From: Vjacheslav Trushkin
Date: Sat, 31 Mar 2012 22:07:04 +0300
Subject: [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;
}
}
--
cgit v1.2.1
From 5ccd6915e3e8af30856319d84a48dde074fdbaee Mon Sep 17 00:00:00 2001
From: David King
Date: Sat, 31 Mar 2012 15:52:16 -0400
Subject: [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),
+ ));
}
}
--
cgit v1.2.1
From f80512f1066ebfc09d2a4ffac412c56a3fb247de Mon Sep 17 00:00:00 2001
From: Vjacheslav Trushkin
Date: Sun, 1 Apr 2012 09:52:55 +0300
Subject: [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);
+ }
}
--
cgit v1.2.1
From 2509853ca530b3b5e0d5b2e10080eeba5a29d937 Mon Sep 17 00:00:00 2001
From: Vjacheslav Trushkin
Date: Sun, 1 Apr 2012 09:53:23 +0300
Subject: [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), '');
+ }
+}
--
cgit v1.2.1
From a7d0ef90ea921b2ed876bb933bfa022863771a6e Mon Sep 17 00:00:00 2001
From: Vjacheslav Trushkin
Date: Sun, 1 Apr 2012 10:58:24 +0300
Subject: [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:
--
cgit v1.2.1
From 2225efc5609add8baf0dc0e7867d9f9f0fae4245 Mon Sep 17 00:00:00 2001
From: Vjacheslav Trushkin
Date: Sun, 1 Apr 2012 10:58:59 +0300
Subject: [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}