mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-28 14:18:52 +00:00
Merge remote-tracking branch 'EXreaction/ticket/11628' into develop
This commit is contained in:
commit
afc12906b9
28 changed files with 278 additions and 1376 deletions
|
@ -50,7 +50,7 @@ $module_id = request_var('i', '');
|
||||||
$mode = request_var('mode', '');
|
$mode = request_var('mode', '');
|
||||||
|
|
||||||
// Set custom style for admin area
|
// Set custom style for admin area
|
||||||
$phpbb_style->set_custom_style('admin', $phpbb_admin_path . 'style', array(), '');
|
$template->set_custom_style('admin', $phpbb_admin_path . 'style');
|
||||||
$template->assign_var('T_ASSETS_PATH', $phpbb_root_path . 'assets');
|
$template->assign_var('T_ASSETS_PATH', $phpbb_root_path . 'assets');
|
||||||
$template->assign_var('T_TEMPLATE_PATH', $phpbb_admin_path . 'style');
|
$template->assign_var('T_TEMPLATE_PATH', $phpbb_admin_path . 'style');
|
||||||
|
|
||||||
|
|
|
@ -22,7 +22,7 @@ $auth->acl($user->data);
|
||||||
$user->setup();
|
$user->setup();
|
||||||
|
|
||||||
// Set custom template for admin area
|
// Set custom template for admin area
|
||||||
$phpbb_style->set_custom_style('admin', $phpbb_admin_path . 'style', array(), '');
|
$template->set_custom_style('admin', $phpbb_admin_path . 'style');
|
||||||
|
|
||||||
$template->set_filenames(array(
|
$template->set_filenames(array(
|
||||||
'body' => 'colour_swatch.html')
|
'body' => 'colour_swatch.html')
|
||||||
|
|
|
@ -121,7 +121,6 @@ $phpbb_extension_manager = $phpbb_container->get('ext.manager');
|
||||||
$phpbb_subscriber_loader = $phpbb_container->get('event.subscriber_loader');
|
$phpbb_subscriber_loader = $phpbb_container->get('event.subscriber_loader');
|
||||||
|
|
||||||
$template = $phpbb_container->get('template');
|
$template = $phpbb_container->get('template');
|
||||||
$phpbb_style = $phpbb_container->get('style');
|
|
||||||
|
|
||||||
// Add own hook handler
|
// Add own hook handler
|
||||||
require($phpbb_root_path . 'includes/hooks/index.' . $phpEx);
|
require($phpbb_root_path . 'includes/hooks/index.' . $phpEx);
|
||||||
|
|
|
@ -98,7 +98,7 @@ services:
|
||||||
arguments:
|
arguments:
|
||||||
- @user
|
- @user
|
||||||
- @service_container
|
- @service_container
|
||||||
- @style
|
- @template
|
||||||
|
|
||||||
cron.task_collection:
|
cron.task_collection:
|
||||||
class: phpbb_di_service_collection
|
class: phpbb_di_service_collection
|
||||||
|
@ -251,30 +251,6 @@ services:
|
||||||
request:
|
request:
|
||||||
class: phpbb_request
|
class: phpbb_request
|
||||||
|
|
||||||
style:
|
|
||||||
class: phpbb_style
|
|
||||||
arguments:
|
|
||||||
- %core.root_path%
|
|
||||||
- %core.php_ext%
|
|
||||||
- @config
|
|
||||||
- @user
|
|
||||||
- @style.resource_locator
|
|
||||||
- @style.path_provider_ext
|
|
||||||
- @template
|
|
||||||
|
|
||||||
style.resource_locator:
|
|
||||||
class: phpbb_style_resource_locator
|
|
||||||
|
|
||||||
style.path_provider_ext:
|
|
||||||
class: phpbb_style_extension_path_provider
|
|
||||||
arguments:
|
|
||||||
- @ext.manager
|
|
||||||
- @style.path_provider
|
|
||||||
- %core.root_path%
|
|
||||||
|
|
||||||
style.path_provider:
|
|
||||||
class: phpbb_style_path_provider
|
|
||||||
|
|
||||||
template:
|
template:
|
||||||
class: phpbb_template_twig
|
class: phpbb_template_twig
|
||||||
arguments:
|
arguments:
|
||||||
|
|
|
@ -132,11 +132,8 @@ class bbcode
|
||||||
{
|
{
|
||||||
$this->template_bitfield = new bitfield($user->style['bbcode_bitfield']);
|
$this->template_bitfield = new bitfield($user->style['bbcode_bitfield']);
|
||||||
|
|
||||||
$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(), $phpbb_root_path);
|
|
||||||
$template = new phpbb_template_twig($phpbb_root_path, $phpEx, $config, $user, new phpbb_template_context(), $phpbb_extension_manager);
|
$template = new phpbb_template_twig($phpbb_root_path, $phpEx, $config, $user, new phpbb_template_context(), $phpbb_extension_manager);
|
||||||
$style = new phpbb_style($phpbb_root_path, $phpEx, $config, $user, $style_resource_locator, $style_path_provider, $template);
|
$template->set_style();
|
||||||
$style->set_style();
|
|
||||||
$template->set_filenames(array('bbcode.html' => 'bbcode.html'));
|
$template->set_filenames(array('bbcode.html' => 'bbcode.html'));
|
||||||
$this->template_filename = $template->get_source_file_for_handle('bbcode.html');
|
$this->template_filename = $template->get_source_file_for_handle('bbcode.html');
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,7 +21,7 @@ if (!defined('IN_PHPBB'))
|
||||||
*/
|
*/
|
||||||
class messenger
|
class messenger
|
||||||
{
|
{
|
||||||
var $vars, $msg, $extra_headers, $replyto, $from, $subject;
|
var $msg, $extra_headers, $replyto, $from, $subject;
|
||||||
var $addresses = array();
|
var $addresses = array();
|
||||||
|
|
||||||
var $mail_priority = MAIL_NORMAL_PRIORITY;
|
var $mail_priority = MAIL_NORMAL_PRIORITY;
|
||||||
|
@ -53,7 +53,7 @@ class messenger
|
||||||
function reset()
|
function reset()
|
||||||
{
|
{
|
||||||
$this->addresses = $this->extra_headers = array();
|
$this->addresses = $this->extra_headers = array();
|
||||||
$this->vars = $this->msg = $this->replyto = $this->from = '';
|
$this->msg = $this->replyto = $this->from = '';
|
||||||
$this->mail_priority = MAIL_NORMAL_PRIORITY;
|
$this->mail_priority = MAIL_NORMAL_PRIORITY;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -258,8 +258,6 @@ class messenger
|
||||||
'body' => $template_file . '.txt',
|
'body' => $template_file . '.txt',
|
||||||
));
|
));
|
||||||
|
|
||||||
$this->vars = $this->template->get_template_vars();
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -288,26 +286,11 @@ class messenger
|
||||||
global $config, $user;
|
global $config, $user;
|
||||||
|
|
||||||
// We add some standard variables we always use, no need to specify them always
|
// We add some standard variables we always use, no need to specify them always
|
||||||
if (!isset($this->vars['U_BOARD']))
|
$this->assign_vars(array(
|
||||||
{
|
'U_BOARD' => generate_board_url(),
|
||||||
$this->assign_vars(array(
|
'EMAIL_SIG' => str_replace('<br />', "\n", "-- \n" . htmlspecialchars_decode($config['board_email_sig'])),
|
||||||
'U_BOARD' => generate_board_url(),
|
'SITENAME' => htmlspecialchars_decode($config['sitename']),
|
||||||
));
|
));
|
||||||
}
|
|
||||||
|
|
||||||
if (!isset($this->vars['EMAIL_SIG']))
|
|
||||||
{
|
|
||||||
$this->assign_vars(array(
|
|
||||||
'EMAIL_SIG' => str_replace('<br />', "\n", "-- \n" . htmlspecialchars_decode($config['board_email_sig'])),
|
|
||||||
));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!isset($this->vars['SITENAME']))
|
|
||||||
{
|
|
||||||
$this->assign_vars(array(
|
|
||||||
'SITENAME' => htmlspecialchars_decode($config['sitename']),
|
|
||||||
));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Parse message through template
|
// Parse message through template
|
||||||
$this->msg = trim($this->template->assign_display('body'));
|
$this->msg = trim($this->template->assign_display('body'));
|
||||||
|
@ -660,7 +643,7 @@ class messenger
|
||||||
{
|
{
|
||||||
$this->setup_template();
|
$this->setup_template();
|
||||||
|
|
||||||
$this->template->set_style_names(array($path_name), $paths);
|
$this->template->set_custom_style($path_name, $paths);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -455,7 +455,7 @@ class p_master
|
||||||
*/
|
*/
|
||||||
function load_active($mode = false, $module_url = false, $execute_module = true)
|
function load_active($mode = false, $module_url = false, $execute_module = true)
|
||||||
{
|
{
|
||||||
global $phpbb_root_path, $phpbb_admin_path, $phpEx, $user, $phpbb_style;
|
global $phpbb_root_path, $phpbb_admin_path, $phpEx, $user, $template;
|
||||||
|
|
||||||
$module_path = $this->include_path . $this->p_class;
|
$module_path = $this->include_path . $this->p_class;
|
||||||
$icat = request_var('icat', '');
|
$icat = request_var('icat', '');
|
||||||
|
@ -508,7 +508,7 @@ class p_master
|
||||||
|
|
||||||
if (is_dir($module_style_dir))
|
if (is_dir($module_style_dir))
|
||||||
{
|
{
|
||||||
$phpbb_style->set_custom_style('admin', array($module_style_dir, $phpbb_admin_path . 'style'), array(), '');
|
$template->set_custom_style('admin', array($module_style_dir, $phpbb_admin_path . 'style'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -537,7 +537,7 @@ class p_master
|
||||||
|
|
||||||
if (is_dir($phpbb_root_path . $module_style_dir))
|
if (is_dir($phpbb_root_path . $module_style_dir))
|
||||||
{
|
{
|
||||||
$phpbb_style->set_style(array($module_style_dir, 'styles'));
|
$template->set_style(array($module_style_dir, 'styles'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -244,15 +244,10 @@ $config = new phpbb_config(array(
|
||||||
'load_tplcompile' => '1'
|
'load_tplcompile' => '1'
|
||||||
));
|
));
|
||||||
|
|
||||||
$phpbb_style_resource_locator = new phpbb_style_resource_locator();
|
|
||||||
$phpbb_style_path_provider = new phpbb_style_path_provider();
|
|
||||||
$template = new phpbb_template_twig($phpbb_root_path, $phpEx, $config, $user, new phpbb_template_context());
|
$template = new phpbb_template_twig($phpbb_root_path, $phpEx, $config, $user, new phpbb_template_context());
|
||||||
$phpbb_style = new phpbb_style($phpbb_root_path, $phpEx, $config, $user, $phpbb_style_resource_locator, $phpbb_style_path_provider, $template);
|
|
||||||
$phpbb_style->set_ext_dir_prefix('adm/');
|
|
||||||
|
|
||||||
$paths = array($phpbb_root_path . 'install/update/new/adm/style', $phpbb_admin_path . 'style');
|
$paths = array($phpbb_root_path . 'install/update/new/adm/style', $phpbb_admin_path . 'style');
|
||||||
$paths = array_filter($paths, 'is_dir');
|
$paths = array_filter($paths, 'is_dir');
|
||||||
$phpbb_style->set_custom_style('admin', $paths, array(), '');
|
$template->set_custom_style('admin', $paths);
|
||||||
|
|
||||||
$template->assign_var('T_ASSETS_PATH', '../assets');
|
$template->assign_var('T_ASSETS_PATH', '../assets');
|
||||||
$template->assign_var('T_TEMPLATE_PATH', $phpbb_admin_path . 'style');
|
$template->assign_var('T_TEMPLATE_PATH', $phpbb_admin_path . 'style');
|
||||||
|
|
|
@ -70,7 +70,7 @@ class install_update extends module
|
||||||
|
|
||||||
function main($mode, $sub)
|
function main($mode, $sub)
|
||||||
{
|
{
|
||||||
global $phpbb_style, $template, $phpEx, $phpbb_root_path, $user, $db, $config, $cache, $auth, $language;
|
global $template, $phpEx, $phpbb_root_path, $user, $db, $config, $cache, $auth, $language;
|
||||||
global $request, $phpbb_admin_path, $phpbb_adm_relative_path, $phpbb_container;
|
global $request, $phpbb_admin_path, $phpbb_adm_relative_path, $phpbb_container;
|
||||||
|
|
||||||
// We must enable super globals, otherwise creating a new instance of the request class,
|
// We must enable super globals, otherwise creating a new instance of the request class,
|
||||||
|
@ -143,7 +143,7 @@ class install_update extends module
|
||||||
// Set custom template again. ;)
|
// Set custom template again. ;)
|
||||||
$paths = array($phpbb_root_path . 'install/update/new/adm/style', $phpbb_admin_path . 'style');
|
$paths = array($phpbb_root_path . 'install/update/new/adm/style', $phpbb_admin_path . 'style');
|
||||||
$paths = array_filter($paths, 'is_dir');
|
$paths = array_filter($paths, 'is_dir');
|
||||||
$phpbb_style->set_custom_style('admin', $paths, array(), '');
|
$template->set_custom_style('admin', $paths);
|
||||||
|
|
||||||
$template->assign_vars(array(
|
$template->assign_vars(array(
|
||||||
'S_USER_LANG' => $user->lang['USER_LANG'],
|
'S_USER_LANG' => $user->lang['USER_LANG'],
|
||||||
|
|
|
@ -38,23 +38,23 @@ class phpbb_controller_resolver implements ControllerResolverInterface
|
||||||
protected $container;
|
protected $container;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* phpbb_style object
|
* phpbb_template object
|
||||||
* @var phpbb_style
|
* @var phpbb_template
|
||||||
*/
|
*/
|
||||||
protected $style;
|
protected $template;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Construct method
|
* Construct method
|
||||||
*
|
*
|
||||||
* @param phpbb_user $user User Object
|
* @param phpbb_user $user User Object
|
||||||
* @param ContainerInterface $container ContainerInterface object
|
* @param ContainerInterface $container ContainerInterface object
|
||||||
* @param phpbb_style $style
|
* @param phpbb_template $template
|
||||||
*/
|
*/
|
||||||
public function __construct(phpbb_user $user, ContainerInterface $container, phpbb_style $style = null)
|
public function __construct(phpbb_user $user, ContainerInterface $container, phpbb_template $template = null)
|
||||||
{
|
{
|
||||||
$this->user = $user;
|
$this->user = $user;
|
||||||
$this->container = $container;
|
$this->container = $container;
|
||||||
$this->style = $style;
|
$this->template = $template;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -96,13 +96,13 @@ class phpbb_controller_resolver implements ControllerResolverInterface
|
||||||
$controller_dir = explode('_', get_class($controller_object));
|
$controller_dir = explode('_', get_class($controller_object));
|
||||||
|
|
||||||
// 0 phpbb, 1 ext, 2 vendor, 3 extension name, ...
|
// 0 phpbb, 1 ext, 2 vendor, 3 extension name, ...
|
||||||
if (!is_null($this->style) && isset($controller_dir[3]) && $controller_dir[1] === 'ext')
|
if (!is_null($this->template) && isset($controller_dir[3]) && $controller_dir[1] === 'ext')
|
||||||
{
|
{
|
||||||
$controller_style_dir = 'ext/' . $controller_dir[2] . '/' . $controller_dir[3] . '/styles';
|
$controller_style_dir = 'ext/' . $controller_dir[2] . '/' . $controller_dir[3] . '/styles';
|
||||||
|
|
||||||
if (is_dir($controller_style_dir))
|
if (is_dir($controller_style_dir))
|
||||||
{
|
{
|
||||||
$this->style->set_style(array($controller_style_dir, 'styles'));
|
$this->template->set_style(array($controller_style_dir, 'styles'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,137 +0,0 @@
|
||||||
<?php
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @package phpBB3
|
|
||||||
* @copyright (c) 2011 phpBB Group
|
|
||||||
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @ignore
|
|
||||||
*/
|
|
||||||
if (!defined('IN_PHPBB'))
|
|
||||||
{
|
|
||||||
exit;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Provides a style resource locator with core style paths and extension style paths
|
|
||||||
*
|
|
||||||
* 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 style paths searched within extensions.
|
|
||||||
*
|
|
||||||
* Empty by default. Relative to the extension directory. As an example, it
|
|
||||||
* could be adm/ for admin style.
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
protected $ext_dir_prefix = '';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A provider of paths to be searched for styles
|
|
||||||
* @var phpbb_style_path_provider
|
|
||||||
*/
|
|
||||||
protected $base_path_provider;
|
|
||||||
|
|
||||||
/** @var string */
|
|
||||||
protected $phpbb_root_path;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructor stores extension manager
|
|
||||||
*
|
|
||||||
* @param phpbb_extension_manager $extension_manager phpBB extension manager
|
|
||||||
* @param phpbb_style_path_provider $base_path_provider A simple path provider
|
|
||||||
* to provide paths to be located in extensions
|
|
||||||
* @param string $phpbb_root_path phpBB root path
|
|
||||||
*/
|
|
||||||
public function __construct(phpbb_extension_manager $extension_manager, phpbb_style_path_provider $base_path_provider, $phpbb_root_path)
|
|
||||||
{
|
|
||||||
parent::__construct($extension_manager);
|
|
||||||
$this->base_path_provider = $base_path_provider;
|
|
||||||
$this->phpbb_root_path = $phpbb_root_path;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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 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
|
|
||||||
*/
|
|
||||||
public function set_ext_dir_prefix($ext_dir_prefix)
|
|
||||||
{
|
|
||||||
$this->ext_dir_prefix = $ext_dir_prefix;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Finds style paths using the extension manager
|
|
||||||
*
|
|
||||||
* 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 style paths
|
|
||||||
*/
|
|
||||||
public function find()
|
|
||||||
{
|
|
||||||
$directories = array();
|
|
||||||
|
|
||||||
$finder = $this->extension_manager->get_finder();
|
|
||||||
foreach ($this->base_path_provider as $key => $paths)
|
|
||||||
{
|
|
||||||
if ($key == 'style')
|
|
||||||
{
|
|
||||||
foreach ($paths as $path)
|
|
||||||
{
|
|
||||||
$directories['style'][] = $path;
|
|
||||||
if ($path && !phpbb_is_absolute($path))
|
|
||||||
{
|
|
||||||
// Remove phpBB root path from the style path,
|
|
||||||
// so the finder is able to find extension styles,
|
|
||||||
// when the root path is not ./
|
|
||||||
if (strpos($path, $this->phpbb_root_path) === 0)
|
|
||||||
{
|
|
||||||
$path = substr($path, strlen($this->phpbb_root_path));
|
|
||||||
}
|
|
||||||
|
|
||||||
$result = $finder->directory('/' . $this->ext_dir_prefix . $path)
|
|
||||||
->get_directories(true, false, true);
|
|
||||||
foreach ($result as $ext => $ext_path)
|
|
||||||
{
|
|
||||||
// Make sure $ext_path has no ending slash
|
|
||||||
if (substr($ext_path, -1) === '/')
|
|
||||||
{
|
|
||||||
$ext_path = substr($ext_path, 0, -1);
|
|
||||||
}
|
|
||||||
$directories[$ext][] = $ext_path;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $directories;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Overwrites the current style paths
|
|
||||||
*
|
|
||||||
* @param array $styles An array of style paths. The first element is the main style.
|
|
||||||
* @return null
|
|
||||||
*/
|
|
||||||
public function set_styles(array $styles)
|
|
||||||
{
|
|
||||||
$this->base_path_provider->set_styles($styles);
|
|
||||||
$this->items = null;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,62 +0,0 @@
|
||||||
<?php
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @package phpBB3
|
|
||||||
* @copyright (c) 2011 phpBB Group
|
|
||||||
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @ignore
|
|
||||||
*/
|
|
||||||
if (!defined('IN_PHPBB'))
|
|
||||||
{
|
|
||||||
exit;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Provides a style resource locator with paths
|
|
||||||
*
|
|
||||||
* 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 $paths = array();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Ignores the extension dir prefix
|
|
||||||
*
|
|
||||||
* @param string $ext_dir_prefix The prefix including trailing slash
|
|
||||||
* @return null
|
|
||||||
*/
|
|
||||||
public function set_ext_dir_prefix($ext_dir_prefix)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Overwrites the current style paths
|
|
||||||
*
|
|
||||||
* The first element of the passed styles map, is considered the main
|
|
||||||
* 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 = array('style' => $styles);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Retrieve an iterator over all style paths
|
|
||||||
*
|
|
||||||
* @return ArrayIterator An iterator for the array of style paths
|
|
||||||
*/
|
|
||||||
public function getIterator()
|
|
||||||
{
|
|
||||||
return new ArrayIterator($this->paths);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,42 +0,0 @@
|
||||||
<?php
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @package phpBB3
|
|
||||||
* @copyright (c) 2011 phpBB Group
|
|
||||||
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @ignore
|
|
||||||
*/
|
|
||||||
if (!defined('IN_PHPBB'))
|
|
||||||
{
|
|
||||||
exit;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Provides a style resource locator with paths
|
|
||||||
*
|
|
||||||
* 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 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);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Overwrites the current style paths
|
|
||||||
*
|
|
||||||
* @param array $styles An array of style paths. The first element is the main style.
|
|
||||||
* @return null
|
|
||||||
*/
|
|
||||||
public function set_styles(array $styles);
|
|
||||||
}
|
|
|
@ -1,348 +0,0 @@
|
||||||
<?php
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @package phpBB3
|
|
||||||
* @copyright (c) 2011 phpBB Group
|
|
||||||
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @ignore
|
|
||||||
*/
|
|
||||||
if (!defined('IN_PHPBB'))
|
|
||||||
{
|
|
||||||
exit;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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.
|
|
||||||
*
|
|
||||||
* 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 implements phpbb_template_locator
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Paths to style directories.
|
|
||||||
* @var array
|
|
||||||
*/
|
|
||||||
private $roots = array();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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
|
|
||||||
*/
|
|
||||||
private $template_path;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Map from root index to handles to source template file paths.
|
|
||||||
* Normally it only contains paths for handles that are used
|
|
||||||
* (or are likely to be used) by the page being rendered and not
|
|
||||||
* all templates that exist on the filesystem.
|
|
||||||
* @var array
|
|
||||||
*/
|
|
||||||
private $files = array();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Map from handles to source template file names.
|
|
||||||
* Covers the same data as $files property but maps to basenames
|
|
||||||
* instead of paths.
|
|
||||||
* @var array
|
|
||||||
*/
|
|
||||||
private $filenames = array();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructor.
|
|
||||||
*
|
|
||||||
* Sets default template path to template/.
|
|
||||||
*/
|
|
||||||
public function __construct()
|
|
||||||
{
|
|
||||||
$this->set_default_template_path();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the list of style paths
|
|
||||||
*
|
|
||||||
* 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 $style_paths An array of paths to style directories
|
|
||||||
* @return null
|
|
||||||
*/
|
|
||||||
public function set_paths($style_paths)
|
|
||||||
{
|
|
||||||
$this->roots = array();
|
|
||||||
$this->files = array();
|
|
||||||
$this->filenames = array();
|
|
||||||
|
|
||||||
foreach ($style_paths as $key => $paths)
|
|
||||||
{
|
|
||||||
foreach ($paths as $path)
|
|
||||||
{
|
|
||||||
// Make sure $path has no ending slash
|
|
||||||
if (substr($path, -1) === '/')
|
|
||||||
{
|
|
||||||
$path = substr($path, 0, -1);
|
|
||||||
}
|
|
||||||
$this->roots[$key][] = $path;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the location of templates directory within style directories.
|
|
||||||
*
|
|
||||||
* The location must be a relative path, with a trailing slash.
|
|
||||||
* Typically it is one directory level deep, e.g. "template/".
|
|
||||||
*
|
|
||||||
* @param string $template_path Relative path to templates directory within style directories
|
|
||||||
* @return null
|
|
||||||
*/
|
|
||||||
public function set_template_path($template_path)
|
|
||||||
{
|
|
||||||
$this->template_path = $template_path;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the location of templates directory within style directories
|
|
||||||
* to the default, which is "template/".
|
|
||||||
*
|
|
||||||
* @return null
|
|
||||||
*/
|
|
||||||
public function set_default_template_path()
|
|
||||||
{
|
|
||||||
$this->template_path = 'template/';
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
public function set_filenames(array $filename_array)
|
|
||||||
{
|
|
||||||
foreach ($filename_array as $handle => $filename)
|
|
||||||
{
|
|
||||||
if (empty($filename))
|
|
||||||
{
|
|
||||||
trigger_error("style resource locator: set_filenames: Empty filename specified for $handle", E_USER_ERROR);
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->filename[$handle] = $filename;
|
|
||||||
|
|
||||||
foreach ($this->roots as $root_key => $root_paths)
|
|
||||||
{
|
|
||||||
foreach ($root_paths as $root_index => $root)
|
|
||||||
{
|
|
||||||
$this->files[$root_key][$root_index][$handle] = $root . '/' . $this->template_path . $filename;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
public function get_filename_for_handle($handle)
|
|
||||||
{
|
|
||||||
if (!isset($this->filename[$handle]))
|
|
||||||
{
|
|
||||||
trigger_error("style resource locator: get_filename_for_handle: No file specified for handle $handle", E_USER_ERROR);
|
|
||||||
}
|
|
||||||
return $this->filename[$handle];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
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['style'][0][$handle]))
|
|
||||||
{
|
|
||||||
trigger_error("style resource locator: No file specified for handle $handle", E_USER_ERROR);
|
|
||||||
}
|
|
||||||
|
|
||||||
$source_file = $this->files['style'][0][$handle];
|
|
||||||
return $source_file;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
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]))
|
|
||||||
{
|
|
||||||
trigger_error("style resource locator: No file specified for handle $handle", E_USER_ERROR);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 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))
|
|
||||||
{
|
|
||||||
$found = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if ($found)
|
|
||||||
{
|
|
||||||
if ($find_all)
|
|
||||||
{
|
|
||||||
$found_all[] = $source_file;
|
|
||||||
$found = false;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// search failed
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Obtains filesystem path for a template file.
|
|
||||||
*
|
|
||||||
* The simplest use is specifying a single template file as a string
|
|
||||||
* in the first argument. This template file should be a basename
|
|
||||||
* of a template file in the selected style, or its parent styles
|
|
||||||
* if template inheritance is being utilized.
|
|
||||||
*
|
|
||||||
* Note: "selected style" is whatever style the style resource locator
|
|
||||||
* is configured for.
|
|
||||||
*
|
|
||||||
* The return value then will be a path, relative to the current
|
|
||||||
* directory or absolute, to the template file in the selected style
|
|
||||||
* or its closest parent.
|
|
||||||
*
|
|
||||||
* If the selected style does not have the template file being searched,
|
|
||||||
* (and if inheritance is involved, none of the parents have it either),
|
|
||||||
* false will be returned.
|
|
||||||
*
|
|
||||||
* Specifying true for $return_default will cause the function to
|
|
||||||
* return the first path which was checked for existence in the event
|
|
||||||
* that the template file was not found, instead of false.
|
|
||||||
* This is the path in the selected style itself, not any of its
|
|
||||||
* parents.
|
|
||||||
*
|
|
||||||
* $files can be given an array of templates instead of a single
|
|
||||||
* template. When given an array, the function will try to resolve
|
|
||||||
* each template in the array to a path, and will return the first
|
|
||||||
* path that exists, or false if none exist.
|
|
||||||
*
|
|
||||||
* If $files is an array and template inheritance is involved, first
|
|
||||||
* each of the files will be checked in the selected style, then each
|
|
||||||
* of the files will be checked in the immediate parent, and so on.
|
|
||||||
*
|
|
||||||
* If $return_full_path is false, then instead of returning a usable
|
|
||||||
* path (when the template is found) only the template's basename
|
|
||||||
* will be returned. This can be used to check which of the templates
|
|
||||||
* specified in $files exists. Naturally more than one template must
|
|
||||||
* be given in $files.
|
|
||||||
*
|
|
||||||
* This function works identically to get_first_file_location except
|
|
||||||
* it operates on a list of templates, not files. Practically speaking,
|
|
||||||
* the templates given in the first argument first are prepended with
|
|
||||||
* the template path (property in this class), then given to
|
|
||||||
* get_first_file_location for the rest of the processing.
|
|
||||||
*
|
|
||||||
* Templates given to this function can be relative paths for templates
|
|
||||||
* located in subdirectories of the template directories. The paths
|
|
||||||
* should be relative to the templates directory (template/ by default).
|
|
||||||
*
|
|
||||||
* @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 get_first_template_location($templates, $return_default = false, $return_full_path = true)
|
|
||||||
{
|
|
||||||
// add template path prefix
|
|
||||||
$files = array();
|
|
||||||
if (is_string($templates))
|
|
||||||
{
|
|
||||||
$files[] = $this->template_path . $templates;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
foreach ($templates as $template)
|
|
||||||
{
|
|
||||||
$files[] = $this->template_path . $template;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->get_first_file_location($files, $return_default, $return_full_path);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,241 +0,0 @@
|
||||||
<?php
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @package phpBB3
|
|
||||||
* @copyright (c) 2005 phpBB Group, sections (c) 2001 ispi of Lincoln Inc
|
|
||||||
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @ignore
|
|
||||||
*/
|
|
||||||
if (!defined('IN_PHPBB'))
|
|
||||||
{
|
|
||||||
exit;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Base Style class.
|
|
||||||
* @package phpBB3
|
|
||||||
*/
|
|
||||||
class phpbb_style
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Template class.
|
|
||||||
* Handles everything related to templates.
|
|
||||||
* @var phpbb_template
|
|
||||||
*/
|
|
||||||
private $template;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* phpBB root path
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
private $phpbb_root_path;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* PHP file extension
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
private $php_ext;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* phpBB config instance
|
|
||||||
* @var phpbb_config
|
|
||||||
*/
|
|
||||||
private $config;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Current user
|
|
||||||
* @var phpbb_user
|
|
||||||
*/
|
|
||||||
private $user;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Style resource locator
|
|
||||||
* @var phpbb_style_resource_locator
|
|
||||||
*/
|
|
||||||
private $locator;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Style path provider
|
|
||||||
* @var phpbb_style_path_provider
|
|
||||||
*/
|
|
||||||
private $provider;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructor.
|
|
||||||
*
|
|
||||||
* @param string $phpbb_root_path phpBB root path
|
|
||||||
* @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_template $template template
|
|
||||||
*/
|
|
||||||
public function __construct($phpbb_root_path, $php_ext, $config, $user, phpbb_style_resource_locator $locator, phpbb_style_path_provider_interface $provider, phpbb_template $template)
|
|
||||||
{
|
|
||||||
$this->phpbb_root_path = $phpbb_root_path;
|
|
||||||
$this->php_ext = $php_ext;
|
|
||||||
$this->config = $config;
|
|
||||||
$this->user = $user;
|
|
||||||
$this->locator = $locator;
|
|
||||||
$this->provider = $provider;
|
|
||||||
$this->template = $template;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the style tree of the style preferred by the current user
|
|
||||||
*
|
|
||||||
* @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 bool true
|
|
||||||
*/
|
|
||||||
public function set_style($style_directories = array('styles'))
|
|
||||||
{
|
|
||||||
$this->names = $this->get_user_style();
|
|
||||||
|
|
||||||
$paths = array();
|
|
||||||
foreach ($style_directories as $directory)
|
|
||||||
{
|
|
||||||
foreach ($this->names as $name)
|
|
||||||
{
|
|
||||||
$path = $this->get_style_path($name, $directory);
|
|
||||||
|
|
||||||
if (is_dir($path))
|
|
||||||
{
|
|
||||||
$paths[] = $path;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->provider->set_styles($paths);
|
|
||||||
$this->locator->set_paths($this->provider);
|
|
||||||
|
|
||||||
$new_paths = array();
|
|
||||||
foreach ($paths as $path)
|
|
||||||
{
|
|
||||||
$new_paths[] = $path . '/template/';
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->template->set_style_names($this->names, $new_paths, ($style_directories === array('styles')));
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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 array $names Array of names of templates in inheritance tree order, used by extensions. If empty, $name will be used.
|
|
||||||
* @param string $template_path Path to templates, relative to style directory. False if path should be set to default (templates/).
|
|
||||||
* @return bool true
|
|
||||||
*/
|
|
||||||
public function set_custom_style($name, $paths, $names = array(), $template_path = false)
|
|
||||||
{
|
|
||||||
if (is_string($paths))
|
|
||||||
{
|
|
||||||
$paths = array($paths);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (empty($names))
|
|
||||||
{
|
|
||||||
$names = array($name);
|
|
||||||
}
|
|
||||||
$this->names = $names;
|
|
||||||
|
|
||||||
$this->provider->set_styles($paths);
|
|
||||||
$this->locator->set_paths($this->provider);
|
|
||||||
|
|
||||||
if ($template_path !== false)
|
|
||||||
{
|
|
||||||
$this->locator->set_template_path($template_path);
|
|
||||||
}
|
|
||||||
|
|
||||||
$new_paths = array();
|
|
||||||
foreach ($paths as $path)
|
|
||||||
{
|
|
||||||
$new_paths[] = $path . '/' . (($template_path !== false) ? $template_path : 'template/');
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->template->set_style_names($names, $new_paths);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get location of style directory for specific style_path
|
|
||||||
*
|
|
||||||
* @param string $path Style path, such as "prosilver"
|
|
||||||
* @param string $style_base_directory The base directory the style is in
|
|
||||||
* E.g. 'styles', 'ext/foo/bar/styles'
|
|
||||||
* Default: 'styles'
|
|
||||||
* @return string Path to style directory, relative to current path
|
|
||||||
*/
|
|
||||||
public function get_style_path($path, $style_base_directory = 'styles')
|
|
||||||
{
|
|
||||||
return $this->phpbb_root_path . trim($style_base_directory, '/') . '/' . $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);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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);
|
|
||||||
}
|
|
||||||
}
|
|
148
phpBB/phpbb/template/base.php
Normal file
148
phpBB/phpbb/template/base.php
Normal file
|
@ -0,0 +1,148 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @package phpBB3
|
||||||
|
* @copyright (c) 2013 phpBB Group
|
||||||
|
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ignore
|
||||||
|
*/
|
||||||
|
if (!defined('IN_PHPBB'))
|
||||||
|
{
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
abstract class phpbb_template_base implements phpbb_template
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Template context.
|
||||||
|
* Stores template data used during template rendering.
|
||||||
|
*
|
||||||
|
* @var phpbb_template_context
|
||||||
|
*/
|
||||||
|
protected $context;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Array of filenames assigned to set_filenames
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
protected $filenames = array();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function set_filenames(array $filename_array)
|
||||||
|
{
|
||||||
|
$this->filenames = array_merge($this->filenames, $filename_array);
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function destroy()
|
||||||
|
{
|
||||||
|
$this->context->clear();
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function destroy_block_vars($blockname)
|
||||||
|
{
|
||||||
|
$this->context->destroy_block_vars($blockname);
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function assign_vars(array $vararray)
|
||||||
|
{
|
||||||
|
foreach ($vararray as $key => $val)
|
||||||
|
{
|
||||||
|
$this->assign_var($key, $val);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function assign_var($varname, $varval)
|
||||||
|
{
|
||||||
|
$this->context->assign_var($varname, $varval);
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function append_var($varname, $varval)
|
||||||
|
{
|
||||||
|
$this->context->append_var($varname, $varval);
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function assign_block_vars($blockname, array $vararray)
|
||||||
|
{
|
||||||
|
$this->context->assign_block_vars($blockname, $vararray);
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function alter_block_array($blockname, array $vararray, $key = false, $mode = 'insert')
|
||||||
|
{
|
||||||
|
return $this->context->alter_block_array($blockname, $vararray, $key, $mode);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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;
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,163 +0,0 @@
|
||||||
<?php
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @package phpBB3
|
|
||||||
* @copyright (c) 2011 phpBB Group
|
|
||||||
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @ignore
|
|
||||||
*/
|
|
||||||
if (!defined('IN_PHPBB'))
|
|
||||||
{
|
|
||||||
exit;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Resource locator interface.
|
|
||||||
*
|
|
||||||
* Objects implementing this interface maintain mapping from template handles
|
|
||||||
* to source template file paths and locate templates.
|
|
||||||
*
|
|
||||||
* Locates style files.
|
|
||||||
*
|
|
||||||
* 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
|
|
||||||
*/
|
|
||||||
interface phpbb_template_locator
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Sets the template filenames for handles. $filename_array
|
|
||||||
* should be a hash of handle => filename pairs.
|
|
||||||
*
|
|
||||||
* @param array $filename_array Should be a hash of handle => filename pairs.
|
|
||||||
*/
|
|
||||||
public function set_filenames(array $filename_array);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Determines the source file path for a template handle without
|
|
||||||
* regard for styles tree.
|
|
||||||
*
|
|
||||||
* 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 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 style directory
|
|
||||||
*/
|
|
||||||
public function get_virtual_source_file_for_handle($handle);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Determines the source file path for a template handle, accounting
|
|
||||||
* 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
|
|
||||||
* 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 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, $find_all = false);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Obtains a complete filesystem path for a file in a style.
|
|
||||||
*
|
|
||||||
* This function traverses the style tree (selected style and
|
|
||||||
* its parents in order, if inheritance is being used) and finds
|
|
||||||
* the first file on the filesystem matching specified relative path,
|
|
||||||
* or the first of the specified paths if more than one path is given.
|
|
||||||
*
|
|
||||||
* This function can be used to determine filesystem path of any
|
|
||||||
* file under any style, with the consequence being that complete
|
|
||||||
* relative to the style directory path must be provided as an argument.
|
|
||||||
*
|
|
||||||
* In particular, this function can be used to locate templates
|
|
||||||
* and javascript files.
|
|
||||||
*
|
|
||||||
* For locating templates get_first_template_location should be used
|
|
||||||
* as it prepends the configured template path to the template basename.
|
|
||||||
*
|
|
||||||
* Note: "selected style" is whatever style the style resource locator
|
|
||||||
* is configured for.
|
|
||||||
*
|
|
||||||
* The return value then will be a path, relative to the current
|
|
||||||
* directory or absolute, to the first existing file in the selected
|
|
||||||
* style or its closest parent.
|
|
||||||
*
|
|
||||||
* If the selected style does not have the file being searched,
|
|
||||||
* (and if inheritance is involved, none of the parents have it either),
|
|
||||||
* false will be returned.
|
|
||||||
*
|
|
||||||
* Multiple files can be specified, in which case the first file in
|
|
||||||
* the list that can be found on the filesystem is returned.
|
|
||||||
*
|
|
||||||
* If multiple files are specified and inheritance is involved,
|
|
||||||
* first each of the specified files is checked in the selected style,
|
|
||||||
* then each of the specified files is checked in the immediate parent,
|
|
||||||
* etc.
|
|
||||||
*
|
|
||||||
* Specifying true for $return_default will cause the function to
|
|
||||||
* return the first path which was checked for existence in the event
|
|
||||||
* that the template file was not found, instead of false.
|
|
||||||
* This is always a path in the selected style itself, not any of its
|
|
||||||
* parents.
|
|
||||||
*
|
|
||||||
* If $return_full_path is false, then instead of returning a usable
|
|
||||||
* path (when the file is found) the file's path relative to the style
|
|
||||||
* directory will be returned. This is the same path as was given to
|
|
||||||
* the function as a parameter. This can be used to check which of the
|
|
||||||
* files specified in $files exists. Naturally this requires passing
|
|
||||||
* more than one file in $files.
|
|
||||||
*
|
|
||||||
* @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);
|
|
||||||
}
|
|
|
@ -34,14 +34,32 @@ interface phpbb_template
|
||||||
public function set_filenames(array $filename_array);
|
public function set_filenames(array $filename_array);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the style names/paths corresponding to style hierarchy being compiled
|
* Get the style tree of the style preferred by the current user
|
||||||
* and/or rendered.
|
|
||||||
*
|
*
|
||||||
* @param array $style_names List of style names in inheritance tree order
|
* @return array Style tree, most specific first
|
||||||
* @param array $style_paths List of style paths in inheritance tree order
|
*/
|
||||||
|
public function get_user_style();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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
|
* @return phpbb_template $this
|
||||||
*/
|
*/
|
||||||
public function set_style_names(array $style_names, array $style_paths);
|
public function set_style($style_directories = array('styles'));
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set custom style location (able to use directory outside of phpBB).
|
||||||
|
*
|
||||||
|
* 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_custom_style($names, $paths);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Clears all variables and blocks assigned to this template.
|
* Clears all variables and blocks assigned to this template.
|
||||||
|
|
|
@ -19,15 +19,8 @@ if (!defined('IN_PHPBB'))
|
||||||
* Twig Template class.
|
* Twig Template class.
|
||||||
* @package phpBB3
|
* @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
|
* Path of the cache directory for the template
|
||||||
*
|
*
|
||||||
|
@ -43,12 +36,6 @@ class phpbb_template_twig implements phpbb_template
|
||||||
*/
|
*/
|
||||||
protected $phpbb_root_path;
|
protected $phpbb_root_path;
|
||||||
|
|
||||||
/**
|
|
||||||
* adm relative path
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
protected $adm_relative_path;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* PHP file extension
|
* PHP file extension
|
||||||
* @var string
|
* @var string
|
||||||
|
@ -74,16 +61,6 @@ class phpbb_template_twig implements phpbb_template
|
||||||
*/
|
*/
|
||||||
protected $extension_manager;
|
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
|
* Twig Environment
|
||||||
*
|
*
|
||||||
|
@ -91,13 +68,6 @@ class phpbb_template_twig implements phpbb_template
|
||||||
*/
|
*/
|
||||||
protected $twig;
|
protected $twig;
|
||||||
|
|
||||||
/**
|
|
||||||
* Array of filenames assigned to set_filenames
|
|
||||||
*
|
|
||||||
* @var array
|
|
||||||
*/
|
|
||||||
protected $filenames = array();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor.
|
* 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)
|
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->phpbb_root_path = $phpbb_root_path;
|
||||||
$this->adm_relative_path = $adm_relative_path;
|
|
||||||
$this->php_ext = $php_ext;
|
$this->php_ext = $php_ext;
|
||||||
$this->config = $config;
|
$this->config = $config;
|
||||||
$this->user = $user;
|
$this->user = $user;
|
||||||
|
@ -147,6 +116,12 @@ class phpbb_template_twig implements phpbb_template
|
||||||
$lexer = new phpbb_template_twig_lexer($this->twig);
|
$lexer = new phpbb_template_twig_lexer($this->twig);
|
||||||
|
|
||||||
$this->twig->setLexer($lexer);
|
$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
|
* @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;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the style names/paths corresponding to style hierarchy being compiled
|
* Set custom style location (able to use directory outside of phpBB).
|
||||||
* and/or rendered.
|
|
||||||
*
|
*
|
||||||
* @param array $style_names List of style names in inheritance tree order
|
* Note: Templates are still compiled to phpBB's cache directory.
|
||||||
* @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
|
* @param string|array $names Array of names or string of name of template(s) in inheritance tree order, used by extensions.
|
||||||
* Core means the main phpBB template files
|
* @param string|array or string $paths Array of style paths, relative to current root directory
|
||||||
* @return phpbb_template $this
|
* @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
|
// Set as __main__ namespace
|
||||||
$this->twig->getLoader()->setPaths($style_paths);
|
$this->twig->getLoader()->setPaths($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');
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add all namespaces for all extensions
|
// Add all namespaces for all extensions
|
||||||
if ($this->extension_manager instanceof phpbb_extension_manager)
|
if ($this->extension_manager instanceof phpbb_extension_manager)
|
||||||
{
|
{
|
||||||
$style_names[] = 'all';
|
$names[] = 'all';
|
||||||
|
|
||||||
foreach ($this->extension_manager->all_enabled() as $ext_namespace => $ext_path)
|
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);
|
$namespace = str_replace('/', '_', $ext_namespace);
|
||||||
$paths = array();
|
$paths = array();
|
||||||
|
|
||||||
foreach ($style_names as $style_name)
|
foreach ($names as $style_name)
|
||||||
{
|
{
|
||||||
$ext_style_path = $ext_path . 'styles/' . $style_name . '/template';
|
$ext_style_path = $ext_path . 'styles/' . $style_name . '/template';
|
||||||
|
|
||||||
|
@ -234,31 +248,6 @@ class phpbb_template_twig implements phpbb_template
|
||||||
return $this;
|
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.
|
* Display a template for provided handle.
|
||||||
*
|
*
|
||||||
|
@ -282,28 +271,6 @@ class phpbb_template_twig implements phpbb_template
|
||||||
return $this;
|
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
|
* Display the handle and assign the output to a template variable
|
||||||
* or return the compiled result.
|
* or return the compiled result.
|
||||||
|
@ -325,105 +292,12 @@ class phpbb_template_twig implements phpbb_template
|
||||||
return $this;
|
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)
|
* Get template vars in a format Twig will use (from the context)
|
||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function get_template_vars()
|
protected function get_template_vars()
|
||||||
{
|
{
|
||||||
$context_vars = $this->context->get_data_ref();
|
$context_vars = $this->context->get_data_ref();
|
||||||
|
|
||||||
|
@ -442,17 +316,6 @@ class phpbb_template_twig implements phpbb_template
|
||||||
return $vars;
|
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)
|
* Get path to template for handle (required for BBCode parser)
|
||||||
*
|
*
|
||||||
|
|
|
@ -75,7 +75,7 @@ class phpbb_user extends phpbb_session
|
||||||
*/
|
*/
|
||||||
function setup($lang_set = false, $style_id = false)
|
function setup($lang_set = false, $style_id = false)
|
||||||
{
|
{
|
||||||
global $db, $phpbb_style, $template, $config, $auth, $phpEx, $phpbb_root_path, $cache;
|
global $db, $template, $config, $auth, $phpEx, $phpbb_root_path, $cache;
|
||||||
global $phpbb_dispatcher;
|
global $phpbb_dispatcher;
|
||||||
|
|
||||||
if ($this->data['user_id'] != ANONYMOUS)
|
if ($this->data['user_id'] != ANONYMOUS)
|
||||||
|
@ -251,7 +251,7 @@ class phpbb_user extends phpbb_session
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$phpbb_style->set_style();
|
$template->set_style();
|
||||||
|
|
||||||
$this->img_lang = $this->lang_name;
|
$this->img_lang = $this->lang_name;
|
||||||
|
|
||||||
|
|
|
@ -48,12 +48,8 @@ class phpbb_controller_helper_url_test extends phpbb_test_case
|
||||||
global $phpbb_dispatcher, $phpbb_root_path, $phpEx;
|
global $phpbb_dispatcher, $phpbb_root_path, $phpEx;
|
||||||
|
|
||||||
$phpbb_dispatcher = new phpbb_mock_event_dispatcher;
|
$phpbb_dispatcher = new phpbb_mock_event_dispatcher;
|
||||||
$this->style_resource_locator = new phpbb_style_resource_locator();
|
|
||||||
$this->user = $this->getMock('phpbb_user');
|
$this->user = $this->getMock('phpbb_user');
|
||||||
$this->template = new phpbb_template_twig($phpbb_root_path, $phpEx, $config, $this->user, new phpbb_template_context());
|
$this->template = new phpbb_template_twig($phpbb_root_path, $phpEx, $config, $this->user, new phpbb_template_context());
|
||||||
$this->style_resource_locator = new phpbb_style_resource_locator();
|
|
||||||
$this->style_provider = new phpbb_style_path_provider();
|
|
||||||
$this->style = new phpbb_style($phpbb_root_path, $phpEx, new phpbb_config(array()), $this->user, $this->style_resource_locator, $this->style_provider, $this->template);
|
|
||||||
|
|
||||||
$helper = new phpbb_controller_helper($this->template, $this->user, '', 'php');
|
$helper = new phpbb_controller_helper($this->template, $this->user, '', 'php');
|
||||||
$this->assertEquals($helper->url($route, $params, $is_amp, $session_id), $expected);
|
$this->assertEquals($helper->url($route, $params, $is_amp, $session_id), $expected);
|
||||||
|
|
|
@ -1,50 +0,0 @@
|
||||||
<?php
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @package testing
|
|
||||||
* @copyright (c) 2013 phpBB Group
|
|
||||||
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php';
|
|
||||||
|
|
||||||
class phpbb_extension_style_path_provider_test extends phpbb_test_case
|
|
||||||
{
|
|
||||||
protected $relative_root_path;
|
|
||||||
protected $root_path;
|
|
||||||
|
|
||||||
public function setUp()
|
|
||||||
{
|
|
||||||
$this->relative_root_path = './';
|
|
||||||
$this->root_path = dirname(__FILE__) . '/';
|
|
||||||
}
|
|
||||||
|
|
||||||
public function test_find()
|
|
||||||
{
|
|
||||||
$phpbb_style_path_provider = new phpbb_style_path_provider();
|
|
||||||
$phpbb_style_path_provider->set_styles(array($this->relative_root_path . 'styles/prosilver'));
|
|
||||||
$phpbb_style_extension_path_provider = new phpbb_style_extension_path_provider(new phpbb_mock_extension_manager(
|
|
||||||
$this->root_path,
|
|
||||||
array(
|
|
||||||
'foo' => array(
|
|
||||||
'ext_name' => 'foo',
|
|
||||||
'ext_active' => '1',
|
|
||||||
'ext_path' => 'ext/foo/',
|
|
||||||
),
|
|
||||||
'bar' => array(
|
|
||||||
'ext_name' => 'bar',
|
|
||||||
'ext_active' => '1',
|
|
||||||
'ext_path' => 'ext/bar/',
|
|
||||||
),
|
|
||||||
)), $phpbb_style_path_provider, $this->relative_root_path);
|
|
||||||
|
|
||||||
$this->assertEquals(array(
|
|
||||||
'style' => array(
|
|
||||||
$this->relative_root_path . 'styles/prosilver',
|
|
||||||
),
|
|
||||||
'bar' => array(
|
|
||||||
$this->root_path . 'ext/bar/styles/prosilver',
|
|
||||||
),
|
|
||||||
), $phpbb_style_extension_path_provider->find());
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,18 +0,0 @@
|
||||||
<?php
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @package testing
|
|
||||||
* @copyright (c) 2013 phpBB Group
|
|
||||||
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
require_once dirname(__FILE__) . '/../style_path_provider_test.php';
|
|
||||||
|
|
||||||
class phpbb_extension_subdir_style_path_provider_test extends phpbb_extension_style_path_provider_test
|
|
||||||
{
|
|
||||||
public function setUp()
|
|
||||||
{
|
|
||||||
$this->relative_root_path = '../';
|
|
||||||
$this->root_path = dirname(__FILE__) . '/../';
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -46,7 +46,7 @@ class phpbb_template_includephp_test extends phpbb_template_template_test_case
|
||||||
|
|
||||||
$this->setup_engine(array('tpl_allow_php' => true));
|
$this->setup_engine(array('tpl_allow_php' => true));
|
||||||
|
|
||||||
$this->style->set_custom_style('tests', $cache_dir, array(), '');
|
$this->template->set_custom_style('tests', $cache_dir);
|
||||||
|
|
||||||
$this->run_template('includephp_absolute.html', array(), array(), array(), "Path is absolute.\ntesting included php");
|
$this->run_template('includephp_absolute.html', array(), array(), array(), "Path is absolute.\ntesting included php");
|
||||||
|
|
||||||
|
|
|
@ -113,13 +113,10 @@ Zeta test event in all',
|
||||||
$config = new phpbb_config(array_merge($defaults, $new_config));
|
$config = new phpbb_config(array_merge($defaults, $new_config));
|
||||||
|
|
||||||
$this->template_path = dirname(__FILE__) . "/datasets/$dataset/styles/silver/template";
|
$this->template_path = dirname(__FILE__) . "/datasets/$dataset/styles/silver/template";
|
||||||
$this->style_resource_locator = new phpbb_style_resource_locator();
|
|
||||||
$this->extension_manager = new phpbb_mock_filesystem_extension_manager(
|
$this->extension_manager = new phpbb_mock_filesystem_extension_manager(
|
||||||
dirname(__FILE__) . "/datasets/$dataset/"
|
dirname(__FILE__) . "/datasets/$dataset/"
|
||||||
);
|
);
|
||||||
$this->template = new phpbb_template_twig($phpbb_root_path, $phpEx, $config, $user, new phpbb_template_context, $this->extension_manager);
|
$this->template = new phpbb_template_twig($phpbb_root_path, $phpEx, $config, $user, new phpbb_template_context, $this->extension_manager);
|
||||||
$this->style_provider = new phpbb_style_path_provider();
|
$this->template->set_custom_style(((!empty($style_names)) ? $style_names : 'silver'), array($this->template_path));
|
||||||
$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('silver', array($this->template_path), $style_names, '');
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -410,7 +410,7 @@ class phpbb_template_template_test extends phpbb_template_template_test_case
|
||||||
|
|
||||||
$this->setup_engine(array('tpl_allow_php' => true));
|
$this->setup_engine(array('tpl_allow_php' => true));
|
||||||
|
|
||||||
$this->style->set_custom_style('tests', $cache_dir, array(), '');
|
$this->template->set_custom_style('tests', $cache_dir);
|
||||||
|
|
||||||
$this->run_template('php.html', array(), array(), array(), 'test');
|
$this->run_template('php.html', array(), array(), array(), 'test');
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,11 +11,8 @@ require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php';
|
||||||
|
|
||||||
class phpbb_template_template_test_case extends phpbb_test_case
|
class phpbb_template_template_test_case extends phpbb_test_case
|
||||||
{
|
{
|
||||||
protected $style;
|
|
||||||
protected $template;
|
protected $template;
|
||||||
protected $template_path;
|
protected $template_path;
|
||||||
protected $style_resource_locator;
|
|
||||||
protected $style_provider;
|
|
||||||
protected $user;
|
protected $user;
|
||||||
|
|
||||||
protected $test_path = 'tests/template';
|
protected $test_path = 'tests/template';
|
||||||
|
@ -67,11 +64,8 @@ class phpbb_template_template_test_case extends phpbb_test_case
|
||||||
$this->user = new phpbb_user;
|
$this->user = new phpbb_user;
|
||||||
|
|
||||||
$this->template_path = $this->test_path . '/templates';
|
$this->template_path = $this->test_path . '/templates';
|
||||||
$this->style_resource_locator = new phpbb_style_resource_locator();
|
|
||||||
$this->style_provider = new phpbb_style_path_provider();
|
|
||||||
$this->template = new phpbb_template_twig($phpbb_root_path, $phpEx, $config, $this->user, new phpbb_template_context());
|
$this->template = new phpbb_template_twig($phpbb_root_path, $phpEx, $config, $this->user, new phpbb_template_context());
|
||||||
$this->style = new phpbb_style($phpbb_root_path, $phpEx, $config, $this->user, $this->style_resource_locator, $this->style_provider, $this->template);
|
$this->template->set_custom_style('tests', $this->template_path);
|
||||||
$this->style->set_custom_style('tests', $this->template_path, array(), '');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function setUp()
|
protected function setUp()
|
||||||
|
|
|
@ -20,10 +20,7 @@ class phpbb_template_template_test_case_with_tree extends phpbb_template_templat
|
||||||
|
|
||||||
$this->template_path = $this->test_path . '/templates';
|
$this->template_path = $this->test_path . '/templates';
|
||||||
$this->parent_template_path = $this->test_path . '/parent_templates';
|
$this->parent_template_path = $this->test_path . '/parent_templates';
|
||||||
$this->style_resource_locator = new phpbb_style_resource_locator();
|
|
||||||
$this->style_provider = new phpbb_style_path_provider();
|
|
||||||
$this->template = new phpbb_template_twig($phpbb_root_path, $phpEx, $config, $user, new phpbb_template_context());
|
$this->template = new phpbb_template_twig($phpbb_root_path, $phpEx, $config, $user, new phpbb_template_context());
|
||||||
$this->style = new phpbb_style($phpbb_root_path, $phpEx, $config, $user, $this->style_resource_locator, $this->style_provider, $this->template);
|
$this->template->set_custom_style('tests', array($this->template_path, $this->parent_template_path));
|
||||||
$this->style->set_custom_style('tests', array($this->template_path, $this->parent_template_path), array(), '');
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue