mirror of
https://github.com/phpbb/phpbb.git
synced 2025-08-13 04:04:12 +02:00
Merge branch 'develop' of github.com:phpbb/phpbb3 into ticket/11816
# By David King (16) and others # Via David King (13) and others * 'develop' of github.com:phpbb/phpbb3: (67 commits) [ticket/11825] Move schema_data.php into includes/ instead of phpbb/ [ticket/11215] Remove unnecessary comment [ticket/11755] MySQL upgrader out of date [prep-release-3.0.12] Update Changelog for 3.0.12-RC3 release. [prep-release-3.0.12] Bumping version number for 3.0.12-RC3. [ticket/11823] Set up nginx server to match PHP files with characters after .php [ticket/11812] Fix empty define [ticket/11818] Update Symfony dependencies to 2.3.* [ticket/11791] Load adm/ events from styles/adm/event/ [ticket/11215] Fix helper_url_test.php tests [ticket/11215] Add newline back to .htaccess, fix wording [ticket/11215] Update comment in .htaccess [ticket/11215] Uncomment rewrite rules in .htaccess [ticket/11215] Make controller helper url() method use correct format [ticket/11215] Add commented-out URL rewrite capability to .htaccess [ticket/11821] Fix comma usage next to "You are receiving this notification". [ticket/11769] Allow using 0 as poster name [ticket/11769] Allow '0' as username [ticket/11215] Use new URL structure for controllers [ticket/11215] Everything appears to be working... ... Conflicts: phpBB/phpbb/template/twig/lexer.php tests/template/template_test.php
This commit is contained in:
@@ -130,7 +130,7 @@ class phpbb_template_twig_lexer extends Twig_Lexer
|
||||
// E.g. 'asdf'"' -> asdf'"
|
||||
// E.g. "asdf'"" -> asdf'"
|
||||
// E.g. 'asdf'" -> 'asdf'"
|
||||
$matches[2] = preg_replace('#^([\'"])?(.+?)\1$#', '$2', $matches[2]);
|
||||
$matches[2] = preg_replace('#^([\'"])?(.*?)\1$#', '$2', $matches[2]);
|
||||
|
||||
// Replace template variables with start/end to parse variables (' ~ TEST ~ '.html)
|
||||
$matches[2] = preg_replace('#{([a-zA-Z0-9_\.$]+)}#', "'~ \$1 ~'", $matches[2]);
|
||||
@@ -219,6 +219,12 @@ class phpbb_template_twig_lexer extends Twig_Lexer
|
||||
*/
|
||||
protected function fix_if_tokens($code)
|
||||
{
|
||||
// Replace ELSE IF with ELSEIF
|
||||
$code = preg_replace('#<!-- ELSE IF (.+?) -->#', '<!-- ELSEIF $1 -->', $code);
|
||||
|
||||
// Replace our "div by" with Twig's divisibleby (Twig does not like test names with spaces)
|
||||
$code = preg_replace('# div by ([0-9]+)#', ' divisibleby($1)', $code);
|
||||
|
||||
$callback = function($matches)
|
||||
{
|
||||
$inner = $matches[2];
|
||||
@@ -234,9 +240,6 @@ class phpbb_template_twig_lexer extends Twig_Lexer
|
||||
return "<!-- {$matches[1]}IF{$inner}-->";
|
||||
};
|
||||
|
||||
// Replace our "div by" with Twig's divisibleby (Twig does not like test names with spaces)
|
||||
$code = preg_replace('# div by ([0-9]+)#', ' divisibleby($1)', $code);
|
||||
|
||||
return preg_replace_callback('#<!-- (ELSE)?IF((.*) \(?!?[\$|\.]([^\s]+)(.*))-->#', $callback, $code);
|
||||
}
|
||||
|
||||
|
@@ -19,15 +19,8 @@ if (!defined('IN_PHPBB'))
|
||||
* Twig Template class.
|
||||
* @package phpBB3
|
||||
*/
|
||||
class phpbb_template_twig implements phpbb_template
|
||||
class phpbb_template_twig extends phpbb_template_base
|
||||
{
|
||||
/**
|
||||
* Template context.
|
||||
* Stores template data used during template rendering.
|
||||
* @var phpbb_template_context
|
||||
*/
|
||||
protected $context;
|
||||
|
||||
/**
|
||||
* Path of the cache directory for the template
|
||||
*
|
||||
@@ -43,12 +36,6 @@ class phpbb_template_twig implements phpbb_template
|
||||
*/
|
||||
protected $phpbb_root_path;
|
||||
|
||||
/**
|
||||
* adm relative path
|
||||
* @var string
|
||||
*/
|
||||
protected $adm_relative_path;
|
||||
|
||||
/**
|
||||
* PHP file extension
|
||||
* @var string
|
||||
@@ -74,16 +61,6 @@ class phpbb_template_twig implements phpbb_template
|
||||
*/
|
||||
protected $extension_manager;
|
||||
|
||||
/**
|
||||
* Name of the style that the template being compiled and/or rendered
|
||||
* belongs to, and its parents, in inheritance tree order.
|
||||
*
|
||||
* Used to invoke style-specific template events.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $style_names;
|
||||
|
||||
/**
|
||||
* Twig Environment
|
||||
*
|
||||
@@ -91,13 +68,6 @@ class phpbb_template_twig implements phpbb_template
|
||||
*/
|
||||
protected $twig;
|
||||
|
||||
/**
|
||||
* Array of filenames assigned to set_filenames
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $filenames = array();
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
@@ -112,7 +82,6 @@ class phpbb_template_twig implements phpbb_template
|
||||
public function __construct($phpbb_root_path, $php_ext, $config, $user, phpbb_template_context $context, phpbb_extension_manager $extension_manager = null, $adm_relative_path = null)
|
||||
{
|
||||
$this->phpbb_root_path = $phpbb_root_path;
|
||||
$this->adm_relative_path = $adm_relative_path;
|
||||
$this->php_ext = $php_ext;
|
||||
$this->config = $config;
|
||||
$this->user = $user;
|
||||
@@ -147,6 +116,12 @@ class phpbb_template_twig implements phpbb_template
|
||||
$lexer = new phpbb_template_twig_lexer($this->twig);
|
||||
|
||||
$this->twig->setLexer($lexer);
|
||||
|
||||
// Add admin namespace
|
||||
if ($adm_relative_path !== null && is_dir($this->phpbb_root_path . $adm_relative_path . 'style/'))
|
||||
{
|
||||
$this->twig->getLoader()->setPaths($this->phpbb_root_path . $adm_relative_path . 'style/', 'admin');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -165,51 +140,90 @@ class phpbb_template_twig implements phpbb_template
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the template filenames for handles.
|
||||
* Get the style tree of the style preferred by the current user
|
||||
*
|
||||
* @param array $filename_array Should be a hash of handle => filename pairs.
|
||||
* @return array Style tree, most specific first
|
||||
*/
|
||||
public function get_user_style()
|
||||
{
|
||||
$style_list = array(
|
||||
$this->user->style['style_path'],
|
||||
);
|
||||
|
||||
if ($this->user->style['style_parent_id'])
|
||||
{
|
||||
$style_list = array_merge($style_list, array_reverse(explode('/', $this->user->style['style_parent_tree'])));
|
||||
}
|
||||
|
||||
return $style_list;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set style location based on (current) user's chosen style.
|
||||
*
|
||||
* @param array $style_directories The directories to add style paths for
|
||||
* E.g. array('ext/foo/bar/styles', 'styles')
|
||||
* Default: array('styles') (phpBB's style directory)
|
||||
* @return phpbb_template $this
|
||||
*/
|
||||
public function set_filenames(array $filename_array)
|
||||
public function set_style($style_directories = array('styles'))
|
||||
{
|
||||
$this->filenames = array_merge($this->filenames, $filename_array);
|
||||
if ($style_directories !== array('styles') && $this->twig->getLoader()->getPaths('core') === array())
|
||||
{
|
||||
// We should set up the core styles path since not already setup
|
||||
$this->set_style();
|
||||
}
|
||||
|
||||
$names = $this->get_user_style();
|
||||
|
||||
$paths = array();
|
||||
foreach ($style_directories as $directory)
|
||||
{
|
||||
foreach ($names as $name)
|
||||
{
|
||||
$path = $this->phpbb_root_path . trim($directory, '/') . "/{$name}/template/";
|
||||
|
||||
if (is_dir($path))
|
||||
{
|
||||
$paths[] = $path;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// If we're setting up the main phpBB styles directory and the core
|
||||
// namespace isn't setup yet, we will set it up now
|
||||
if ($style_directories === array('styles') && $this->twig->getLoader()->getPaths('core') === array())
|
||||
{
|
||||
// Set up the core style paths namespace
|
||||
$this->twig->getLoader()->setPaths($paths, 'core');
|
||||
}
|
||||
|
||||
$this->set_custom_style($names, $paths);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the style names/paths corresponding to style hierarchy being compiled
|
||||
* and/or rendered.
|
||||
* Set custom style location (able to use directory outside of phpBB).
|
||||
*
|
||||
* @param array $style_names List of style names in inheritance tree order
|
||||
* @param array $style_paths List of style paths in inheritance tree order
|
||||
* @param bool $is_core True if the style names are the "core" styles for this page load
|
||||
* Core means the main phpBB template files
|
||||
* Note: Templates are still compiled to phpBB's cache directory.
|
||||
*
|
||||
* @param string|array $names Array of names or string of name of template(s) in inheritance tree order, used by extensions.
|
||||
* @param string|array or string $paths Array of style paths, relative to current root directory
|
||||
* @return phpbb_template $this
|
||||
*/
|
||||
public function set_style_names(array $style_names, array $style_paths, $is_core = false)
|
||||
public function set_custom_style($names, $paths)
|
||||
{
|
||||
$this->style_names = $style_names;
|
||||
$paths = (is_string($paths)) ? array($paths) : $paths;
|
||||
$names = (is_string($names)) ? array($names) : $names;
|
||||
|
||||
// Set as __main__ namespace
|
||||
$this->twig->getLoader()->setPaths($style_paths);
|
||||
|
||||
// Core style namespace from phpbb_style::set_style()
|
||||
if ($is_core)
|
||||
{
|
||||
$this->twig->getLoader()->setPaths($style_paths, 'core');
|
||||
}
|
||||
|
||||
// Add admin namespace
|
||||
if (is_dir($this->phpbb_root_path . $this->adm_relative_path . 'style/'))
|
||||
{
|
||||
$this->twig->getLoader()->setPaths($this->phpbb_root_path . $this->adm_relative_path . 'style/', 'admin');
|
||||
}
|
||||
$this->twig->getLoader()->setPaths($paths);
|
||||
|
||||
// Add all namespaces for all extensions
|
||||
if ($this->extension_manager instanceof phpbb_extension_manager)
|
||||
{
|
||||
$style_names[] = 'all';
|
||||
$names[] = 'all';
|
||||
|
||||
foreach ($this->extension_manager->all_enabled() as $ext_namespace => $ext_path)
|
||||
{
|
||||
@@ -217,7 +231,7 @@ class phpbb_template_twig implements phpbb_template
|
||||
$namespace = str_replace('/', '_', $ext_namespace);
|
||||
$paths = array();
|
||||
|
||||
foreach ($style_names as $style_name)
|
||||
foreach ($names as $style_name)
|
||||
{
|
||||
$ext_style_path = $ext_path . 'styles/' . $style_name . '/template';
|
||||
|
||||
@@ -234,31 +248,6 @@ class phpbb_template_twig implements phpbb_template
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears all variables and blocks assigned to this template.
|
||||
*
|
||||
* @return phpbb_template $this
|
||||
*/
|
||||
public function destroy()
|
||||
{
|
||||
$this->context = array();
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset/empty complete block
|
||||
*
|
||||
* @param string $blockname Name of block to destroy
|
||||
* @return phpbb_template $this
|
||||
*/
|
||||
public function destroy_block_vars($blockname)
|
||||
{
|
||||
$this->context->destroy_block_vars($blockname);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a template for provided handle.
|
||||
*
|
||||
@@ -282,28 +271,6 @@ class phpbb_template_twig implements phpbb_template
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calls hook if any is defined.
|
||||
*
|
||||
* @param string $handle Template handle being displayed.
|
||||
* @param string $method Method name of the caller.
|
||||
*/
|
||||
protected function call_hook($handle, $method)
|
||||
{
|
||||
global $phpbb_hook;
|
||||
|
||||
if (!empty($phpbb_hook) && $phpbb_hook->call_hook(array(__CLASS__, $method), $handle, $this))
|
||||
{
|
||||
if ($phpbb_hook->hook_return(array(__CLASS__, $method)))
|
||||
{
|
||||
$result = $phpbb_hook->hook_return_result(array(__CLASS__, $method));
|
||||
return array($result);
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the handle and assign the output to a template variable
|
||||
* or return the compiled result.
|
||||
@@ -325,105 +292,12 @@ class phpbb_template_twig implements phpbb_template
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Assign key variable pairs from an array
|
||||
*
|
||||
* @param array $vararray A hash of variable name => value pairs
|
||||
* @return phpbb_template $this
|
||||
*/
|
||||
public function assign_vars(array $vararray)
|
||||
{
|
||||
foreach ($vararray as $key => $val)
|
||||
{
|
||||
$this->assign_var($key, $val);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Assign a single scalar value to a single key.
|
||||
*
|
||||
* Value can be a string, an integer or a boolean.
|
||||
*
|
||||
* @param string $varname Variable name
|
||||
* @param string $varval Value to assign to variable
|
||||
* @return phpbb_template $this
|
||||
*/
|
||||
public function assign_var($varname, $varval)
|
||||
{
|
||||
$this->context->assign_var($varname, $varval);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Append text to the string value stored in a key.
|
||||
*
|
||||
* Text is appended using the string concatenation operator (.).
|
||||
*
|
||||
* @param string $varname Variable name
|
||||
* @param string $varval Value to append to variable
|
||||
* @return phpbb_template $this
|
||||
*/
|
||||
public function append_var($varname, $varval)
|
||||
{
|
||||
$this->context->append_var($varname, $varval);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Assign key variable pairs from an array to a specified block
|
||||
* @param string $blockname Name of block to assign $vararray to
|
||||
* @param array $vararray A hash of variable name => value pairs
|
||||
* @return phpbb_template $this
|
||||
*/
|
||||
public function assign_block_vars($blockname, array $vararray)
|
||||
{
|
||||
$this->context->assign_block_vars($blockname, $vararray);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change already assigned key variable pair (one-dimensional - single loop entry)
|
||||
*
|
||||
* An example of how to use this function:
|
||||
* {@example alter_block_array.php}
|
||||
*
|
||||
* @param string $blockname the blockname, for example 'loop'
|
||||
* @param array $vararray the var array to insert/add or merge
|
||||
* @param mixed $key Key to search for
|
||||
*
|
||||
* array: KEY => VALUE [the key/value pair to search for within the loop to determine the correct position]
|
||||
*
|
||||
* int: Position [the position to change or insert at directly given]
|
||||
*
|
||||
* If key is false the position is set to 0
|
||||
* If key is true the position is set to the last entry
|
||||
*
|
||||
* @param string $mode Mode to execute (valid modes are 'insert' and 'change')
|
||||
*
|
||||
* If insert, the vararray is inserted at the given position (position counting from zero).
|
||||
* If change, the current block gets merged with the vararray (resulting in new key/value pairs be added and existing keys be replaced by the new value).
|
||||
*
|
||||
* Since counting begins by zero, inserting at the last position will result in this array: array(vararray, last positioned array)
|
||||
* and inserting at position 1 will result in this array: array(first positioned array, vararray, following vars)
|
||||
*
|
||||
* @return bool false on error, true on success
|
||||
*/
|
||||
public function alter_block_array($blockname, array $vararray, $key = false, $mode = 'insert')
|
||||
{
|
||||
return $this->context->alter_block_array($blockname, $vararray, $key, $mode);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get template vars in a format Twig will use (from the context)
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_template_vars()
|
||||
protected function get_template_vars()
|
||||
{
|
||||
$context_vars = $this->context->get_data_ref();
|
||||
|
||||
@@ -442,17 +316,6 @@ class phpbb_template_twig implements phpbb_template
|
||||
return $vars;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a filename from the handle
|
||||
*
|
||||
* @param string $handle
|
||||
* @return string
|
||||
*/
|
||||
protected function get_filename_from_handle($handle)
|
||||
{
|
||||
return (isset($this->filenames[$handle])) ? $this->filenames[$handle] : $handle;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get path to template for handle (required for BBCode parser)
|
||||
*
|
||||
|
Reference in New Issue
Block a user