1.i. Changes since 3.0.10
+1.i. Changes since 3.0.11
+ +Bug
+-
+
- [PHPBB3-6723] - Empty message in deleted messages in PM history +
- [PHPBB3-7262] - Clarify docs about is_dynamic not being updated by set_config() +
- [PHPBB3-8319] - LOCAL_URL not enforced in bbcodes +
- [PHPBB3-9551] - Mysql fulltext index creation fails due to partial collation change +
- [PHPBB3-9975] - Hard coded language in sessions.php +
- [PHPBB3-10184] - Bots can be sent private messages +
- [PHPBB3-10491] - Fatal error in functional tests when server returns 404 +
- [PHPBB3-10568] - Modify the trigger language when you edit a PM +
- [PHPBB3-10602] - A bug in mail queue processing +
- [PHPBB3-10661] - UCP > PM > Compose > enumerated recipients > BCC group misses a (prosilver) +
- [PHPBB3-10678] - Provide Firebird, Oracle, and increased MSSQL support in unit tests +
- [PHPBB3-10772] - trigger_error is using the default style +
- [PHPBB3-10789] - PM print template (prosilver) with unnecessary variables +
- [PHPBB3-10820] - Display images directly in IE9 and 10 instead of download +
- [PHPBB3-10828] - PostgreSQL dbal tests try to connect to the database named as user specified in configuration +
- [PHPBB3-10838] - Functional tests are not mentioned in RUNNING_TESTS.txt +
- [PHPBB3-10840] - If you add a member to a group, the form_token can be set to 0 if the creation_time is 0 too. Maybe even if creation_time is unchanged. +
- [PHPBB3-10848] - Wrong redirect to installer from acp +
- [PHPBB3-10850] - create_schema_files.php is not creating the oracle or postgres' schema file properly +
- [PHPBB3-10879] - prosilver: attachment-link will be displayed wrong, when filename is too long +
- [PHPBB3-10880] - m_approve should not imply f_noapprove +
- [PHPBB3-10896] - board_email & board_contact are not validated as email addresses in ACP +
- [PHPBB3-10897] - Bot Definitions are outdated +
- [PHPBB3-10918] - docs/INSTALL.html claims there are tar.gz packages +
- [PHPBB3-10943] - Search Box should display keywords entered by the user +
- [PHPBB3-10967] - PHPBB_USE_BOARD_URL_PATH not implemented in posting_gen_topic_icons +
- [PHPBB3-10986] - Invalid email message ids because config variable server_name is used even when force server URL settings is disabled +
- [PHPBB3-10995] - Return value of $db->sql_fetchrow() on empty tables is not consistent on mssqlnative +
- [PHPBB3-10996] - Travis tests fail on Postgres because database does not exist +
- [PHPBB3-11034] - The functional test case framework does not install a full board each time +
- [PHPBB3-11066] - MSSQLnative driver contains debug code error_reporting(E_ALL) +
- [PHPBB3-11069] - missing closing span in subsilver2 simple_footer.html +
- [PHPBB3-11081] - Duplicated /TD in styles/subsilver2/template/catpcha_qa.html +
- [PHPBB3-11093] - acp_users_overview.html has a wrongly placed </dd> +
- [PHPBB3-11094] - prosilver: searching for users: no textbox for Jabber +
- [PHPBB3-11105] - Missing mandatory space in meta http-equiv=refresh +
- [PHPBB3-11112] - phpBB Footer Link should be SSL +
- [PHPBB3-11122] - Update docs/AUTHORS for 3.0.12-RC1 +
- [PHPBB3-11144] - {FORUM_NAME} is not filled in login mask when logging into a password protected forum +
- [PHPBB3-11145] - ATTACHED_IMAGE_NOT_IMAGE thrown because of file limit in php.ini +
- [PHPBB3-11158] - modules table lacks acl_u_sig for signature module +
- [PHPBB3-11159] - Coding guidelines: static public +
- [PHPBB3-11164] - Composer not finding symfony/config in PHP 5.3.3 +
- [PHPBB3-11178] - database_update.php should not set error_reporting to E_ALL +
- [PHPBB3-11186] - Database unit tests fail on windows using sqlite2 +
- [PHPBB3-11190] - Functional tests do not clear the cache between each test +
- [PHPBB3-11196] - /includes/session.php sends 401 HTTP status with "Not authorized" instead of "Unauthorized" +
- [PHPBB3-11219] - Database sequences are not updated for tests using fixtures with auto_incremented columns +
- [PHPBB3-11227] - @return void -> @return null +
- [PHPBB3-11233] - Anonymous can be selected as a PM recipient +
- [PHPBB3-11248] - CRLF line endings +
- [PHPBB3-11262] - .lock files are not in .gitignore +
- [PHPBB3-11265] - Functional tests do not assert that board installation succeeded +
- [PHPBB3-11269] - Travis functional test case errors +
- [PHPBB3-11278] - Firebird tables are not removed correctly on 3.0.9-rc1 update +
- [PHPBB3-11288] - Search fooled by hyphens +
- [PHPBB3-11291] - "Could not open input file: ../composer.phar" error during phing's create-package +
- [PHPBB3-11292] - Newlines removed in display of PM reports, no clickable links in PM reports +
- [PHPBB3-11301] - "String offset cast occured" error on PHP 5.4 +
- [PHPBB3-11304] - check_form_key breaks in tests when form is submitted in the same second it is retrieved +
- [PHPBB3-11343] - Loose string comparison during new password activation +
- [PHPBB3-11355] - Incorrect error message when no user selected for action on group membership management page +
- [PHPBB3-11358] - Success message even withot selecting a user and performing a group operation +
- [PHPBB3-11361] - "Array to string conversion" error in $user->format_date() +
- [PHPBB3-11493] - Functional tests should fail if any debug output is made +
- [PHPBB3-11517] - Numbering is wrong in coding guidelines +
- [PHPBB3-11536] - Installer incorrectly removes /install from script_path +
- [PHPBB3-11537] - UCP group manage page's error box differs heavily from the rest of the UCP +
- [PHPBB3-11538] - SQL error on UCP groups manage page caused by setting color to 7 characters long string +
- [PHPBB3-11544] - Add admin_login() to 3.0 functional test case +
- [PHPBB3-11545] - is_absolute() should not depend on DIRECTORY_SEPARATOR +
- [PHPBB3-11546] - is_absolute() throws E_NOTICE for empty string +
- [PHPBB3-11547] - Test fixtures do not support utf8 characters +
- [PHPBB3-11548] - Untranslated TOO_SHORT in UCP "Manage Groups" +
- [PHPBB3-11566] - Reporting a post should require a captcha to be solved by guests +
- [PHPBB3-11568] - Functional tests fail with retrieving install pages using file_get_contents +
- [PHPBB3-11575] - phpbb_dbal_order_lower_test::test_cross_join should be called test_order_lower +
- [PHPBB3-11578] - Missing underscore after function prefix in validate_data() +
- [PHPBB3-11579] - Add unit tests for validate_data() +
- [PHPBB3-11580] - Avoid API Limit from composer downloads on github +
- [PHPBB3-11588] - install/install_update.php should use version.phpbb.com instead of www +
- [PHPBB3-11590] - Close database connections from tests whenever possible +
- [PHPBB3-11601] - Allow manual resync of database columns in unit tests not only on fixture load +
- [PHPBB3-11603] - git-tools use invalid api urls +
- [PHPBB3-11604] - Functional tests fail when phpBB can not create the config file +
- [PHPBB3-11617] - Missing U_ACTION in acp_captcha.php +
- [PHPBB3-11618] - Template tests fail on some systems due to a PHP error in glob() +
- [PHPBB3-11619] - get_remote_file() should use HTTP 1.0 +
- [PHPBB3-11630] - Improvements to the PHP lint pre-commit hook +
- [PHPBB3-11644] - Skip phpbb_dbal_order_lower_test on MySQL 5.6 +
- [PHPBB3-11662] - "occured" should be "occurred" +
Improvement
+-
+
- [PHPBB3-8743] - New topic / reply notifications do not contain author's name. +
- [PHPBB3-10050] - subsilver2: Do not show "Mark topics as read" when there are no topics +
- [PHPBB3-10205] - More informative reporting of errors when database connection fails (MySQL and others) +
- [PHPBB3-10716] - PHP-parse all php files as part of the test suite +
- [PHPBB3-10841] - Disable style and language selectors if there's only one installed. +
- [PHPBB3-10854] - sql server drop default constraint when dropping column +
- [PHPBB3-10865] - Updated and Added to docs/INSTALL.html +
- [PHPBB3-10873] - Change language entry for deleted PMs +
- [PHPBB3-10981] - Upgrade Goutte and use Composer for Installation +
- [PHPBB3-11131] - Phrasing & semantics of Board settings +
- [PHPBB3-11162] - Get rid of $db->sql_return_on_error(true) trickery when splitting/merging topics +
- [PHPBB3-11192] - Add Tebibyte to get_formatted_filesize() +
- [PHPBB3-11202] - Add response status checks to functional tests +
- [PHPBB3-11220] - Improve tooltip explaining the [list=] - BBcode +
- [PHPBB3-11238] - Specify goutte version +
- [PHPBB3-11285] - Use more granularity in dependency checks in compress test +
- [PHPBB3-11293] - Prefer mysqli over mysql due to php 5.5 alpha 2 deprecating mysql +
- [PHPBB3-11294] - Update extension list in running tests doc +
- [PHPBB3-11368] - Latest pm reports row count +
- [PHPBB3-11583] - InnoDB supports FULLTEXT index since MySQL 5.6.4. +
Sub-task
+-
+
- [PHPBB3-10974] - Move tests/mock_user.php to tests/mock/user.php +
- [PHPBB3-11009] - Backport phing build.xml from develop to develop-olympus so it uses composer. +
- [PHPBB3-11540] - Add unit tests for (phpbb_)is_absolute() +
- [PHPBB3-11541] - Add unit tests for style_select() in functions.php +
- [PHPBB3-11542] - Add unit tests for language_select() in functions.php +
- [PHPBB3-11543] - Add unit tests for obtain online functions in functions.php +
Task
+-
+
- [PHPBB3-10877] - Have bamboo generate and publish a phpBB package for every build. +
- [PHPBB3-11045] - Add unit tests for the compress class +
- [PHPBB3-11059] - Fix README logo +
- [PHPBB3-11060] - Fix travis.yml pyrus config +
- [PHPBB3-11240] - Turn on PHPUnit's verbose mode on Travis +
- [PHPBB3-11324] - Add PHP 5.5 environment on Travis-CI +
- [PHPBB3-11337] - Run functional tests on Travis CI +
- [PHPBB3-11513] - Install PHPUnit via Composer's require-dev to simplify test running (no need for pear) +
- [PHPBB3-11526] - Increase composer minimum-stability from beta to stable +
- [PHPBB3-11527] - Upgrade composer.phar to 1.0.0-alpha7 +
- [PHPBB3-11529] - Rename RUNNING_TESTS file to .md file to render it on GitHub +
- [PHPBB3-11576] - Make phpBB Test Suite MySQL behave at least as strict as phpBB MySQL driver +
1.ii. Changes since 3.0.10
Bug
-
@@ -210,7 +355,7 @@
- [PHPBB3-10909] - Update Travis Test Configuration: Travis no longer supports PHP 5.3.2
1.ii. Changes since 3.0.9
+1.iii. Changes since 3.0.9
Bug
-
@@ -346,7 +491,7 @@
- [PHPBB3-10480] - Automate changelog building
1.iii. Changes since 3.0.8
+1.iv. Changes since 3.0.8
Bug
@@ -714,7 +859,7 @@ -1.iv. Changes since 3.0.7-PL1
+1.v. Changes since 3.0.7-PL1
Security
-
@@ -1172,13 +1317,13 @@
1.iv. Changes since 3.0.7
+1.vi. Changes since 3.0.7
- [Sec] Do not expose forum content of forums with ACL entries but no actual permission in ATOM Feeds. (Bug #58595)
1.vi. Changes since 3.0.6
+1.vii. Changes since 3.0.6
- [Fix] Allow ban reason and length to be selected and copied in ACP and subsilver2 MCP. (Bug #51095) @@ -1282,7 +1427,7 @@
1.vii. Changes since 3.0.5
+1.viii. Changes since 3.0.5
- [Fix] Allow whitespaces in avatar gallery names. (Bug #44955) @@ -1504,7 +1649,7 @@
- [Feature] Send anonymous statistical information to phpBB on installation and update (optional).
1.viii. Changes since 3.0.4
+1.ix. Changes since 3.0.4
- [Fix] Delete user entry from ban list table upon user deletion (Bug #40015 - Patch by TerraFrost) @@ -1593,7 +1738,7 @@
- [Sec] Only use forum id supplied for posting if global announcement detected. (Reported by nickvergessen)
1.ix. Changes since 3.0.3
+1.x. Changes since 3.0.3
- [Fix] Allow mixed-case template directories to be inherited (Bug #36725) @@ -1625,7 +1770,7 @@
- [Sec] Ask for forum password if post within passworded forum quoted in private message. (Reported by nickvergessen)
1.x. Changes since 3.0.2
+1.xi. Changes since 3.0.2
- [Fix] Correctly set topic starter if first post in topic removed (Bug #30575 - Patch by blueray2048) @@ -1724,7 +1869,7 @@
- [Sec Precaution] Stricter validation of the HTTP_HOST header (Thanks to Techie-Micheal et al for pointing out possible issues in derived code)
1.xi. Changes since 3.0.1
+1.xii. Changes since 3.0.1
- [Fix] Ability to set permissions on non-mysql dbms (Bug #24955) @@ -1772,7 +1917,7 @@
- [Sec] Only allow urls gone through redirect() being used within login_box(). (thanks nookieman)
1.xii Changes since 3.0.0
+1.xiii Changes since 3.0.0
- [Change] Validate birthdays (Bug #15004) @@ -1843,7 +1988,7 @@
- [Fix] Find and display colliding usernames correctly when converting from one database to another (Bug #23925)
1.xiii. Changes since 3.0.RC8
+1.xiv. Changes since 3.0.RC8
- [Fix] Cleaned usernames contain only single spaces, so "a_name" and "a__name" are treated as the same name (Bug #15634) @@ -1852,7 +1997,7 @@
- [Fix] Call garbage_collection() within database updater to correctly close connections (affects Oracle for example)
1.xiv. Changes since 3.0.RC7
+1.xv. Changes since 3.0.RC7
- [Fix] Fixed MSSQL related bug in the update system @@ -1887,7 +2032,7 @@
- [Fix] No duplication of active topics (Bug #15474)
1.xv. Changes since 3.0.RC6
+1.xvi. Changes since 3.0.RC6
- [Fix] Submitting language changes using acp_language (Bug #14736) @@ -1897,7 +2042,7 @@
- [Fix] Able to request new password (Bug #14743)
1.xvi. Changes since 3.0.RC5
+1.xvii. Changes since 3.0.RC5
- [Feature] Removing constant PHPBB_EMBEDDED in favor of using an exit_handler(); the constant was meant to achive this more or less. @@ -1960,7 +2105,7 @@
- [Sec] New password hashing mechanism for storing passwords (#i42)
1.xvii. Changes since 3.0.RC4
+1.xviii. Changes since 3.0.RC4
- [Fix] MySQL, PostgreSQL and SQLite related database fixes (Bug #13862) @@ -2011,7 +2156,7 @@
- [Fix] odbc_autocommit causing existing result sets to be dropped (Bug #14182)
1.xviii. Changes since 3.0.RC3
+1.xix. Changes since 3.0.RC3
- [Fix] Fixing some subsilver2 and prosilver style issues @@ -2120,7 +2265,7 @@
1.xviv. Changes since 3.0.RC2
+1.xx. Changes since 3.0.RC2
- [Fix] Re-allow searching within the memberlist @@ -2166,7 +2311,7 @@
1.xx. Changes since 3.0.RC1
+1.xxi. Changes since 3.0.RC1
- [Fix] (X)HTML issues within the templates (Bug #11255, #11255) diff --git a/phpBB/includes/acp/acp_bbcodes.php b/phpBB/includes/acp/acp_bbcodes.php index e537d7a8b9..9c430b5a0b 100644 --- a/phpBB/includes/acp/acp_bbcodes.php +++ b/phpBB/includes/acp/acp_bbcodes.php @@ -112,8 +112,8 @@ class acp_bbcodes { $template->assign_block_vars('token', array( 'TOKEN' => '{' . $token . '}', - 'EXPLAIN' => $token_explain) - ); + 'EXPLAIN' => ($token === 'LOCAL_URL') ? sprintf($token_explain, generate_board_url() . '/') : $token_explain, + )); } return; @@ -347,6 +347,9 @@ class acp_bbcodes 'LOCAL_URL' => array( '!(' . str_replace(array('!', '\#'), array('\!', '#'), get_preg_expression('relative_url')) . ')!e' => "\$this->bbcode_specialchars('$1')" ), + 'RELATIVE_URL' => array( + '!(' . str_replace(array('!', '\#'), array('\!', '#'), get_preg_expression('relative_url')) . ')!e' => "\$this->bbcode_specialchars('$1')" + ), 'EMAIL' => array( '!(' . get_preg_expression('email') . ')!ie' => "\$this->bbcode_specialchars('$1')" ), @@ -373,6 +376,7 @@ class acp_bbcodes $sp_tokens = array( 'URL' => '(?i)((?:' . str_replace(array('!', '\#'), array('\!', '#'), get_preg_expression('url')) . ')|(?:' . str_replace(array('!', '\#'), array('\!', '#'), get_preg_expression('www_url')) . '))(?-i)', 'LOCAL_URL' => '(?i)(' . str_replace(array('!', '\#'), array('\!', '#'), get_preg_expression('relative_url')) . ')(?-i)', + 'RELATIVE_URL' => '(?i)(' . str_replace(array('!', '\#'), array('\!', '#'), get_preg_expression('relative_url')) . ')(?-i)', 'EMAIL' => '(' . get_preg_expression('email') . ')', 'TEXT' => '(.*?)', 'SIMPLETEXT' => '([a-zA-Z0-9-+.,_ ]+)', @@ -429,7 +433,11 @@ class acp_bbcodes $fp_replace = str_replace($token, $replace, $fp_replace); $sp_match = str_replace(preg_quote($token, '!'), $sp_tokens[$token_type], $sp_match); - $sp_replace = str_replace($token, '${' . ($n + 1) . '}', $sp_replace); + + // Prepend the board url to local relative links + $replace_prepend = ($token_type === 'LOCAL_URL') ? generate_board_url() . '/' : ''; + + $sp_replace = str_replace($token, $replace_prepend . '${' . ($n + 1) . '}', $sp_replace); } $fp_match = '!' . $fp_match . '!' . $modifiers; diff --git a/phpBB/includes/acp/acp_board.php b/phpBB/includes/acp/acp_board.php index 24b913260b..12e2a1bf72 100644 --- a/phpBB/includes/acp/acp_board.php +++ b/phpBB/includes/acp/acp_board.php @@ -528,10 +528,10 @@ class acp_board $old_auth_config = array(); foreach ($auth_providers as $provider) { - if ($fields = $provider->acp($this->new_config)) + if ($fields = $provider->acp()) { // Check if we need to create config fields for this plugin and save config when submit was pressed - foreach ($fields['config'] as $field) + foreach ($fields as $field) { if (!isset($config[$field])) { @@ -655,15 +655,14 @@ class acp_board foreach ($auth_providers as $provider) { - $fields = $provider->acp($this->new_config); - - if ($fields['tpl']) + $auth_tpl = $provider->get_acp_template($this->new_config); + if ($auth_tpl) { + $template->assign_vars($auth_tpl['TEMPLATE_VARS']); $template->assign_block_vars('auth_tpl', array( - 'TPL' => $fields['tpl'], + 'TEMPLATE_FILE' => $auth_tpl['TEMPLATE_FILE'], )); } - unset($fields); } } } @@ -678,8 +677,12 @@ class acp_board $auth_plugins = array(); $auth_providers = $phpbb_container->get('auth.provider_collection'); - foreach($auth_providers as $key => $value) + foreach ($auth_providers as $key => $value) { + if (!($value instanceof phpbb_auth_provider_interface)) + { + continue; + } $auth_plugins[] = str_replace('auth.provider.', '', $key); } diff --git a/phpBB/includes/acp/acp_groups.php b/phpBB/includes/acp/acp_groups.php index c79699d465..e6a36c97a8 100644 --- a/phpBB/includes/acp/acp_groups.php +++ b/phpBB/includes/acp/acp_groups.php @@ -410,7 +410,7 @@ class acp_groups if ($validation_error = validate_data($submit_ary, $validation_checks)) { // Replace "error" string with its real, localised form - $error = array_merge($error, array_map(array(&$user, 'lang'), $validation_error)); + $error = array_merge($error, $validation_error); } if (!sizeof($error)) @@ -507,6 +507,7 @@ class acp_groups if (sizeof($error)) { + $error = array_map(array(&$user, 'lang'), $error); $group_rank = $submit_ary['rank']; $group_desc_data = array( diff --git a/phpBB/includes/auth/provider/apache.php b/phpBB/includes/auth/provider/apache.php index 5f6f2862b6..2e80436f78 100644 --- a/phpBB/includes/auth/provider/apache.php +++ b/phpBB/includes/auth/provider/apache.php @@ -20,7 +20,7 @@ if (!defined('IN_PHPBB')) * * @package auth */ -class phpbb_auth_provider_apache implements phpbb_auth_provider_interface +class phpbb_auth_provider_apache extends phpbb_auth_provider_base { /** * Apache Authentication Constructor @@ -256,20 +256,4 @@ class phpbb_auth_provider_apache implements phpbb_auth_provider_interface return false; } - - /** - * {@inheritdoc} - */ - public function acp($new) - { - return; - } - - /** - * {@inheritdoc} - */ - public function logout($data, $new_session) - { - return; - } } diff --git a/phpBB/includes/auth/provider/base.php b/phpBB/includes/auth/provider/base.php new file mode 100644 index 0000000000..7eaf8bb2d3 --- /dev/null +++ b/phpBB/includes/auth/provider/base.php @@ -0,0 +1,72 @@ +php_ext = $php_ext; } - /** - * {@inheritdoc} - */ - public function init() - { - return; - } - /** * {@inheritdoc} */ @@ -302,36 +294,4 @@ class phpbb_auth_provider_db implements phpbb_auth_provider_interface 'user_row' => $row, ); } - - /** - * {@inheritdoc} - */ - public function autologin() - { - return; - } - - /** - * {@inheritdoc} - */ - public function acp($new) - { - return; - } - - /** - * {@inheritdoc} - */ - public function logout($data, $new_session) - { - return; - } - - /** - * {@inheritdoc} - */ - public function validate_session($user) - { - return; - } } diff --git a/phpBB/includes/auth/provider/interface.php b/phpBB/includes/auth/provider/interface.php index 2d1935f8f0..47043bc107 100644 --- a/phpBB/includes/auth/provider/interface.php +++ b/phpBB/includes/auth/provider/interface.php @@ -60,16 +60,28 @@ interface phpbb_auth_provider_interface * This function is used to output any required fields in the authentication * admin panel. It also defines any required configuration table fields. * - * @param array $new Contains the new configuration values that have - * been set in acp_board. * @return array|null Returns null if not implemented or an array of the - * form: + * configuration fields of the provider. + */ + public function acp(); + + /** + * This function updates the template with variables related to the acp + * options with whatever configuraton values are passed to it as an array. + * It then returns the name of the acp file related to this authentication + * provider. + * @param array $new_config Contains the new configuration values that + * have been set in acp_board. + * @return array|null Returns null if not implemented or an array with + * the template file name and an array of the vars + * that the template needs that must conform to the + * following example: * array( - * 'tpl' => string - * 'config' => array + * 'TEMPLATE_FILE' => string, + * 'TEMPLATE_VARS' => array(...), * ) */ - public function acp($new); + public function get_acp_template($new_config); /** * Performs additional actions during logout. diff --git a/phpBB/includes/auth/provider/ldap.php b/phpBB/includes/auth/provider/ldap.php index f67c1e9247..0196529408 100644 --- a/phpBB/includes/auth/provider/ldap.php +++ b/phpBB/includes/auth/provider/ldap.php @@ -22,7 +22,7 @@ if (!defined('IN_PHPBB')) * * @package auth */ -class phpbb_auth_provider_ldap implements phpbb_auth_provider_interface +class phpbb_auth_provider_ldap extends phpbb_auth_provider_base { /** * LDAP Authentication Constructor @@ -286,56 +286,32 @@ class phpbb_auth_provider_ldap implements phpbb_auth_provider_interface /** * {@inheritdoc} */ - public function autologin() + + public function acp() { - return; + // These are fields required in the config table + return array( + 'ldap_server', 'ldap_port', 'ldap_base_dn', 'ldap_uid', 'ldap_user_filter', 'ldap_email', 'ldap_user', 'ldap_password', + ); } /** * {@inheritdoc} */ - public function acp($new) + public function get_acp_template($new_config) { - $tpl = ' - -
' . $this->user->lang['LDAP_SERVER_EXPLAIN'] . '
-
-
' . $this->user->lang['LDAP_PORT_EXPLAIN'] . '
-
-
' . $this->user->lang['LDAP_DN_EXPLAIN'] . '
-
-
' . $this->user->lang['LDAP_UID_EXPLAIN'] . '
-
-
' . $this->user->lang['LDAP_USER_FILTER_EXPLAIN'] . '
-
-
' . $this->user->lang['LDAP_EMAIL_EXPLAIN'] . '
-
-
' . $this->user->lang['LDAP_USER_EXPLAIN'] . '
-
-
' . $this->user->lang['LDAP_PASSWORD_EXPLAIN'] . '
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- * if (!$offset)
- * {
- * $tag_template_php .= 'foreach (' . $varref . ' as $_' . $tag_args . '_i => $_' . $tag_args . '_val){';
- * }
- *
- */
-
- $tag_template_php .= 'for ($_' . $tag_args . '_i = ' . $loop_start . '; $_' . $tag_args . '_i < ' . $loop_end . '; ++$_' . $tag_args . '_i){';
- $tag_template_php .= '$_' . $tag_args . '_val = &' . $varref . '[$_' . $tag_args . '_i];';
-
- return $tag_template_php;
- }
-
- /**
- * Compile a general expression - much of this is from Smarty with
- * some adaptions for our block level methods
- *
- * @param string $tag_args Expression (tag arguments) in source template
- * @return string compiled template code
- */
- private function compile_expression($tag_args)
- {
- $match = array();
- preg_match_all('/(?:
- "[^"\\\\]*(?:\\\\.[^"\\\\]*)*" |
- \'[^\'\\\\]*(?:\\\\.[^\'\\\\]*)*\' |
- [(),] |
- [^\s(),]+)/x', $tag_args, $match);
-
- $tokens = $match[0];
- $is_arg_stack = array();
-
- for ($i = 0, $size = sizeof($tokens); $i < $size; $i++)
- {
- $token = &$tokens[$i];
-
- switch ($token)
- {
- case '!==':
- case '===':
- case '<<':
- case '>>':
- case '|':
- case '^':
- case '&':
- case '~':
- case ')':
- case ',':
- case '+':
- case '-':
- case '*':
- case '/':
- case '@':
- break;
-
- case '==':
- case 'eq':
- $token = '==';
- break;
-
- case '!=':
- case '<>':
- case 'ne':
- case 'neq':
- $token = '!=';
- break;
-
- case '<':
- case 'lt':
- $token = '<';
- break;
-
- case '<=':
- case 'le':
- case 'lte':
- $token = '<=';
- break;
-
- case '>':
- case 'gt':
- $token = '>';
- break;
-
- case '>=':
- case 'ge':
- case 'gte':
- $token = '>=';
- break;
-
- case '&&':
- case 'and':
- $token = '&&';
- break;
-
- case '||':
- case 'or':
- $token = '||';
- break;
-
- case '!':
- case 'not':
- $token = '!';
- break;
-
- case '%':
- case 'mod':
- $token = '%';
- break;
-
- case '(':
- array_push($is_arg_stack, $i);
- break;
-
- case 'is':
- $is_arg_start = ($tokens[$i-1] == ')') ? array_pop($is_arg_stack) : $i-1;
- $is_arg = implode(' ', array_slice($tokens, $is_arg_start, $i - $is_arg_start));
-
- $new_tokens = $this->_parse_is_expr($is_arg, array_slice($tokens, $i+1));
-
- array_splice($tokens, $is_arg_start, sizeof($tokens), $new_tokens);
-
- $i = $is_arg_start;
-
- // no break
-
- default:
- $varrefs = array();
- if (preg_match('#^((?:' . self::REGEX_NS . '\.)+)?(\$)?(?=[A-Z])([A-Z0-9\-_]+)#s', $token, $varrefs))
- {
- if (!empty($varrefs[1]))
- {
- $namespace = substr($varrefs[1], 0, -1);
- $dot_pos = strrchr($namespace, '.');
- if ($dot_pos !== false)
- {
- $namespace = substr($dot_pos, 1);
- }
-
- // S_ROW_COUNT is deceptive, it returns the current row number not the number of rows
- // hence S_ROW_COUNT is deprecated in favour of S_ROW_NUM
- switch ($varrefs[3])
- {
- case 'S_ROW_NUM':
- case 'S_ROW_COUNT':
- $token = "\$_${namespace}_i";
- break;
-
- case 'S_NUM_ROWS':
- $token = "\$_${namespace}_count";
- break;
-
- case 'S_FIRST_ROW':
- $token = "(\$_${namespace}_i == 0)";
- break;
-
- case 'S_LAST_ROW':
- $token = "(\$_${namespace}_i == \$_${namespace}_count - 1)";
- break;
-
- case 'S_BLOCK_NAME':
- $token = "'$namespace'";
- break;
-
- default:
- $token = $this->generate_block_data_ref(substr($varrefs[1], 0, -1), true, $varrefs[2]) . '[\'' . $varrefs[3] . '\']';
- $token = '(isset(' . $token . ') ? ' . $token . ' : null)';
- break;
- }
- }
- else
- {
- $token = ($varrefs[2]) ? '$_tpldata[\'DEFINE\'][\'.\'][\'' . $varrefs[3] . '\']' : '$_rootref[\'' . $varrefs[3] . '\']';
- $token = '(isset(' . $token . ') ? ' . $token . ' : null)';
- }
-
- }
- else if (preg_match('#^\.((?:' . self::REGEX_NS . '\.?)+)$#s', $token, $varrefs))
- {
- // Allow checking if loops are set with .loopname
- // It is also possible to check the loop count by doing for example
- $blocks = explode('.', $varrefs[1]);
-
- // If the block is nested, we have a reference that we can grab.
- // If the block is not nested, we just go and grab the block from _tpldata
- if (sizeof($blocks) > 1)
- {
- $block = array_pop($blocks);
- $namespace = implode('.', $blocks);
- $varref = $this->generate_block_data_ref($namespace, true);
-
- // Add the block reference for the last child.
- $varref .= "['" . $block . "']";
- }
- else
- {
- $varref = '$_tpldata';
-
- // Add the block reference for the last child.
- $varref .= "['" . $blocks[0] . "']";
- }
- $token = "(isset($varref) ? sizeof($varref) : 0)";
- }
-
- break;
- }
- }
-
- return $tokens;
- }
-
- /**
- * Compile IF tags
- *
- * @param string $tag_args Expression given with IF in source template
- * @param bool $elseif True if compiling an IF tag, false if compiling an ELSEIF tag
- * @return string compiled template code
- */
- private function compile_tag_if($tag_args, $elseif)
- {
- $tokens = $this->compile_expression($tag_args);
-
- $tpl = ($elseif) ? '} else if (' : 'if (';
-
- $tpl .= implode(' ', $tokens);
- $tpl .= ') { ';
-
- return $tpl;
- }
-
- /**
- * Compile DEFINE tags
- *
- * @param string $tag_args Expression given with DEFINE in source template
- * @param bool $op True if compiling a DEFINE tag, false if compiling an UNDEFINE tag
- * @return string compiled template code
- */
- private function compile_tag_define($tag_args, $op)
- {
- $match = array();
- preg_match('#^((?:' . self::REGEX_NS . '\.)+)?\$(?=[A-Z])([A-Z0-9_\-]*)(?: = (.*?))?$#', $tag_args, $match);
-
- if (!empty($match[2]) && !isset($match[3]) && $op)
- {
- // DEFINE tag with ENDDEFINE
- $array = "\$_tpldata['DEFINE']['.vars']";
- $code = 'ob_start(); ';
- $code .= "if (!isset($array)) { $array = array(); } ";
- $code .= "{$array}[] = '{$match[2]}'";
- return $code;
- }
-
- if (empty($match[2]) || (!isset($match[3]) && $op))
- {
- return '';
- }
-
- if (!$op)
- {
- return 'unset(' . (($match[1]) ? $this->generate_block_data_ref(substr($match[1], 0, -1), true, true) . '[\'' . $match[2] . '\']' : '$_tpldata[\'DEFINE\'][\'.\'][\'' . $match[2] . '\']') . ');';
- }
-
- /*
- * Define tags that contain template variables (enclosed in curly brackets)
- * need to be treated differently.
- */
- if (substr($match[3], 1, 1) == '{' && substr($match[3], -2, 1) == '}')
- {
- $parsed_statement = implode(' ', $this->compile_expression(substr($match[3], 2, -2)));
- }
- else
- {
- $parsed_statement = implode(' ', $this->compile_expression($match[3]));
- }
-
- return (($match[1]) ? $this->generate_block_data_ref(substr($match[1], 0, -1), true, true) . '[\'' . $match[2] . '\']' : '$_tpldata[\'DEFINE\'][\'.\'][\'' . $match[2] . '\']') . ' = ' . $parsed_statement . ';';
- }
-
- /**
- * Compile ENDDEFINE tag
- *
- * @return string compiled template code
- */
- private function compile_tag_enddefine()
- {
- $array = "\$_tpldata['DEFINE']['.vars']";
- $code = "if (!isset($array) || !sizeof($array)) { trigger_error('ENDDEFINE tag without DEFINE in ' . basename(__FILE__), E_USER_ERROR); }";
- $code .= "\$define_var = array_pop($array); ";
- $code .= "\$_tpldata['DEFINE']['.'][\$define_var] = ob_get_clean();";
- return $code;
- }
-
- /**
- * Compile INCLUDE tag
- *
- * @param string $tag_args Expression given with INCLUDE in source template
- * @return string compiled template code
- */
- private function compile_tag_include($tag_args)
- {
- // Process dynamic includes
- if (strpos($tag_args, '{') !== false)
- {
- return $this->parse_dynamic_path($tag_args, '_tpl_include');
- }
-
- return "\$_template->_tpl_include('$tag_args');";
- }
-
- /**
- * Compile INCLUDE_PHP tag
- *
- * @param string $tag_args Expression given with INCLUDEPHP in source template
- * @return string compiled template code
- */
- private function compile_tag_include_php($tag_args)
- {
- if (strpos($tag_args, '{') !== false)
- {
- return $this->parse_dynamic_path($tag_args, '_php_include');
- }
-
- return "\$_template->_php_include('$tag_args');";
- }
-
- /**
- * Compile EVENT tag.
- *
- * $tag_args should be a single string identifying the event.
- * The event name can contain letters, numbers and underscores only.
- * If an invalid event name is specified, an E_USER_ERROR will be
- * triggered.
- *
- * Event tags are only functional when the template engine has
- * an instance of the extension manager. Extension manager would
- * be called upon to find all extensions listening for the specified
- * event, and to obtain additional template fragments. All such
- * template fragments will be compiled and included in the generated
- * compiled template code for the current template being compiled.
- *
- * The above means that whenever an extension is enabled or disabled,
- * template cache should be cleared in order to update the compiled
- * template code for the active set of template event listeners.
- *
- * This also means that extensions cannot return different template
- * fragments at different times. Once templates are compiled, changing
- * such template fragments would have no effect.
- *
- * @param string $tag_args EVENT tag arguments, as a string - for EVENT this is the event name
- * @return string compiled template code
- */
- private function compile_tag_event($tag_args)
- {
- if (!preg_match('/^\w+$/', $tag_args))
- {
- // The event location is improperly formatted,
- if ($this->user)
- {
- trigger_error($this->user->lang('ERR_TEMPLATE_EVENT_LOCATION', $tag_args), E_USER_ERROR);
- }
- else
- {
- trigger_error(sprintf('The specified template event location [%s] is improperly formatted.', $tag_args), E_USER_ERROR);
- }
- }
- $location = $tag_args;
-
- if ($this->extension_manager)
- {
- $finder = $this->extension_manager->get_finder();
-
- $files = $finder
- ->extension_prefix($location)
- ->extension_suffix('.html')
- ->extension_directory("/styles/all/template")
- ->get_files();
-
- foreach ($this->style_names as $style_name)
- {
- $more_files = $finder
- ->extension_prefix($location)
- ->extension_suffix('.html')
- ->extension_directory("/styles/" . $style_name . "/template")
- ->get_files();
- if (!empty($more_files))
- {
- $files = array_merge($files, $more_files);
- break;
- }
- }
-
- $all_compiled = '';
- foreach ($files as $file)
- {
- $this->template_compile->set_filter_params(array(
- 'cleanup' => false,
- ));
-
- $compiled = $this->template_compile->compile_file($file);
-
- $this->template_compile->reset_filter_params();
-
- if ($compiled === false)
- {
- if ($this->user)
- {
- trigger_error($this->user->lang('ERR_TEMPLATE_COMPILATION', phpbb_filter_root_path($file)), E_USER_ERROR);
- }
- else
- {
- trigger_error(sprintf('The file could not be compiled: %s', phpbb_filter_root_path($file)), E_USER_ERROR);
- }
- }
-
- $all_compiled .= $compiled;
- }
- // Need spaces inside php tags as php cannot grok
- // < ?php? > sans the spaces
- return ' ?' . '>' . $all_compiled . 'parse_dynamic_path($tag_args, '_js_include');
- }
-
- // Locate file
- $filename = $this->locator->get_first_file_location(array($tag_args), false, true);
-
- if ($filename === false)
- {
- // File does not exist, find it during run time
- return ' $_template->_js_include(\'' . addslashes($tag_args) . '\', true); ';
- }
-
- if (substr($filename, 0, strlen($this->phpbb_root_path)) != $this->phpbb_root_path)
- {
- // Absolute path, include as is
- return ' $_template->_js_include(\'' . addslashes($filename) . '\', false, false); ';
- }
-
- // Relative path, remove root path from it
- $filename = substr($filename, strlen($this->phpbb_root_path));
- return ' $_template->_js_include(\'' . addslashes($filename) . '\', false, true); ';
- }
-
- /**
- * Generates a reference to the given variable inside the given (possibly nested)
- * block namespace. This is a string of the form:
- * ' . $_tpldata['parent'][$_parent_i]['$child1'][$_child1_i]['$child2'][$_child2_i]...['varname'] . '
- * It's ready to be inserted into an "echo" line in one of the templates.
- *
- * @param string $namespace Namespace to access (expects a trailing "." on the namespace)
- * @param string $varname Variable name to use
- * @param bool $expr Returns whether the source was an expression type
- * @param bool $defop If true this is a variable created with the DEFINE construct, otherwise template variable
- * @return string Code to access variable or echo it if $echo is true
- */
- private function generate_block_varref($namespace, $varname, &$expr, $defop = false)
- {
- // Strip the trailing period.
- $namespace = substr($namespace, 0, -1);
-
- if (($pos = strrpos($namespace, '.')) !== false)
- {
- $local_namespace = substr($namespace, $pos + 1);
- }
- else
- {
- $local_namespace = $namespace;
- }
-
- $expr = true;
-
- // S_ROW_COUNT is deceptive, it returns the current row number now the number of rows
- // hence S_ROW_COUNT is deprecated in favour of S_ROW_NUM
- switch ($varname)
- {
- case 'S_ROW_NUM':
- case 'S_ROW_COUNT':
- $varref = "\$_${local_namespace}_i";
- break;
-
- case 'S_NUM_ROWS':
- $varref = "\$_${local_namespace}_count";
- break;
-
- case 'S_FIRST_ROW':
- $varref = "(\$_${local_namespace}_i == 0)";
- break;
-
- case 'S_LAST_ROW':
- $varref = "(\$_${local_namespace}_i == \$_${local_namespace}_count - 1)";
- break;
-
- case 'S_BLOCK_NAME':
- $varref = "'$local_namespace'";
- break;
-
- default:
- // Get a reference to the data block for this namespace.
- $varref = $this->generate_block_data_ref($namespace, true, $defop);
- // Prepend the necessary code to stick this in an echo line.
-
- // Append the variable reference.
- $varref .= "['$varname']";
-
- $expr = false;
- break;
- }
- // @todo Test the !$expr more
-
- return $varref;
- }
-
- /**
- * Generates a reference to the array of data values for the given
- * (possibly nested) block namespace. This is a string of the form:
- * $_tpldata['parent'][$_parent_i]['$child1'][$_child1_i]['$child2'][$_child2_i]...['$childN']
- *
- * @param string $blockname Block to access (does not expect a trailing "." on the blockname)
- * @param bool $include_last_iterator If $include_last_iterator is true, then [$_childN_i] will be appended to the form shown above.
- * @param bool $defop If true this is a variable created with the DEFINE construct, otherwise template variable
- * @return string Code to access variable
- */
- private function generate_block_data_ref($blockname, $include_last_iterator, $defop = false)
- {
- // Get an array of the blocks involved.
- $blocks = explode('.', $blockname);
- $blockcount = sizeof($blocks) - 1;
-
- // DEFINE is not an element of any referenced variable, we must use _tpldata to access it
- if ($defop)
- {
- $varref = '$_tpldata[\'DEFINE\']';
- // Build up the string with everything but the last child.
- for ($i = 0; $i < $blockcount; $i++)
- {
- $varref .= "['" . $blocks[$i] . "'][\$_" . $blocks[$i] . '_i]';
- }
- // Add the block reference for the last child.
- $varref .= "['" . $blocks[$blockcount] . "']";
- // Add the iterator for the last child if requried.
- if ($include_last_iterator)
- {
- $varref .= '[$_' . $blocks[$blockcount] . '_i]';
- }
- return $varref;
- }
- else if ($include_last_iterator)
- {
- return '$_'. $blocks[$blockcount] . '_val';
- }
- else
- {
- return '$_'. $blocks[$blockcount - 1] . '_val[\''. $blocks[$blockcount]. '\']';
- }
- }
-}
diff --git a/phpBB/includes/template/renderer.php b/phpBB/includes/template/renderer.php
deleted file mode 100644
index 30e234a733..0000000000
--- a/phpBB/includes/template/renderer.php
+++ /dev/null
@@ -1,35 +0,0 @@
-code = $code;
- $this->template = $template;
- }
-
- /**
- * Displays the template managed by this renderer by eval'ing php code
- * of the template.
- *
- * @param phpbb_template_context $context Template context to use
- * @param array $lang Language entries to use
- */
- public function render($context, $lang)
- {
- $_template = $this->template;
- $_tpldata = &$context->get_data_ref();
- $_rootref = &$context->get_root_ref();
- $_lang = $lang;
-
- eval(' ?>' . $this->code . 'path = $path;
- $this->template = $template;
- }
-
- /**
- * Displays the template managed by this renderer by including
- * the php file containing the template.
- *
- * @param phpbb_template_context $context Template context to use
- * @param array $lang Language entries to use
- */
- public function render($context, $lang)
- {
- $_template = $this->template;
- $_tpldata = &$context->get_data_ref();
- $_rootref = &$context->get_root_ref();
- $_lang = $lang;
-
- include($this->path);
- }
-}
diff --git a/phpBB/includes/template/template.php b/phpBB/includes/template/template.php
index bbec768613..89a01e924d 100644
--- a/phpBB/includes/template/template.php
+++ b/phpBB/includes/template/template.php
@@ -2,7 +2,7 @@
/**
*
* @package phpBB3
-* @copyright (c) 2005 phpBB Group, sections (c) 2001 ispi of Lincoln Inc
+* @copyright (c) 2013 phpBB Group
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
@@ -15,143 +15,48 @@ if (!defined('IN_PHPBB'))
exit;
}
-/**
-* @todo
-* IMG_ for image substitution?
-* {IMG_[key]:[alt]:[type]}
-* {IMG_ICON_CONTACT:CONTACT:full} -> $user->img('icon_contact', 'CONTACT', 'full');
-*
-* More in-depth...
-* yadayada
-*/
-
-/**
-* Base Template class.
-* @package phpBB3
-*/
-class phpbb_template
+interface phpbb_template
{
- /**
- * Template context.
- * Stores template data used during template rendering.
- * @var phpbb_template_context
- */
- private $context;
/**
- * Path of the cache directory for the template
- * @var string
- */
- public $cachepath = '';
-
- /**
- * 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;
-
- /**
- * Template locator
- * @var phpbb_template_locator
- */
- private $locator;
-
- /**
- * Extension manager.
+ * Clear the cache
*
- * @var phpbb_extension_manager
+ * @return phpbb_template
*/
- private $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
- */
- private $style_names;
-
- /**
- * Constructor.
- *
- * @param string $phpbb_root_path phpBB root path
- * @param user $user current user
- * @param phpbb_template_locator $locator template locator
- * @param phpbb_template_context $context template context
- * @param phpbb_extension_manager $extension_manager extension manager, if null then template events will not be invoked
- */
- public function __construct($phpbb_root_path, $php_ext, $config, $user, phpbb_template_locator $locator, phpbb_template_context $context, phpbb_extension_manager $extension_manager = null)
- {
- $this->phpbb_root_path = $phpbb_root_path;
- $this->php_ext = $php_ext;
- $this->config = $config;
- $this->user = $user;
- $this->locator = $locator;
- $this->context = $context;
- $this->extension_manager = $extension_manager;
- }
+ public function clear_cache();
/**
* Sets the template filenames for handles.
*
* @param array $filename_array Should be a hash of handle => filename pairs.
+ * @return phpbb_template $this
*/
- public function set_filenames(array $filename_array)
- {
- $this->locator->set_filenames($filename_array);
-
- return true;
- }
+ public function set_filenames(array $filename_array);
/**
- * Sets the style names corresponding to style hierarchy being compiled
+ * Sets the style names/paths corresponding to style hierarchy being compiled
* and/or rendered.
*
* @param array $style_names List of style names in inheritance tree order
- * @return null
+ * @param array $style_paths List of style paths in inheritance tree order
+ * @return phpbb_template $this
*/
- public function set_style_names(array $style_names)
- {
- $this->style_names = $style_names;
- }
+ public function set_style_names(array $style_names, array $style_paths);
/**
* Clears all variables and blocks assigned to this template.
+ *
+ * @return phpbb_template $this
*/
- public function destroy()
- {
- $this->context->clear();
- }
+ public function destroy();
/**
* 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);
- }
+ public function destroy_block_vars($blockname);
/**
* Display a template for provided handle.
@@ -161,81 +66,9 @@ class phpbb_template
* This function calls hooks.
*
* @param string $handle Handle to display
- * @return bool True on success, false on failure
+ * @return phpbb_template $this
*/
- public function display($handle)
- {
- $result = $this->call_hook($handle, __FUNCTION__);
- if ($result !== false)
- {
- return $result[0];
- }
-
- return $this->load_and_render($handle);
- }
-
- /**
- * Loads a template for $handle, compiling it if necessary, and
- * renders the template.
- *
- * @param string $handle Template handle to render
- * @return bool True on success, false on failure
- */
- private function load_and_render($handle)
- {
- $renderer = $this->_tpl_load($handle);
-
- if ($renderer)
- {
- $renderer->render($this->context, $this->get_lang());
- return true;
- }
- else
- {
- return false;
- }
- }
-
- /**
- * Calls hook if any is defined.
- *
- * @param string $handle Template handle being displayed.
- * @param string $method Method name of the caller.
- */
- private 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;
- }
-
- /**
- * Obtains language array.
- * This is either lang property of $user property, or if
- * it is not set an empty array.
- * @return array language entries
- */
- public function get_lang()
- {
- if (isset($this->user->lang))
- {
- $lang = $this->user->lang;
- }
- else
- {
- $lang = array();
- }
- return $lang;
- }
+ public function display($handle);
/**
* Display the handle and assign the output to a template variable
@@ -244,118 +77,17 @@ class phpbb_template
* @param string $handle Handle to operate on
* @param string $template_var Template variable to assign compiled handle to
* @param bool $return_content If true return compiled handle, otherwise assign to $template_var
- * @return bool|string false on failure, otherwise if $return_content is true return string of the compiled handle, otherwise return true
+ * @return phpbb_template|string if $return_content is true return string of the compiled handle, otherwise return $this
*/
- public function assign_display($handle, $template_var = '', $return_content = true)
- {
- ob_start();
- $result = $this->display($handle);
- $contents = ob_get_clean();
- if ($result === false)
- {
- return false;
- }
-
- if ($return_content)
- {
- return $contents;
- }
-
- $this->assign_var($template_var, $contents);
-
- return true;
- }
-
- /**
- * Obtains a template renderer for a template identified by specified
- * handle. The template renderer can display the template later.
- *
- * Template source will first be compiled into php code.
- * If template cache is writable the compiled php code will be stored
- * on filesystem and template will not be subsequently recompiled.
- * If template cache is not writable template source will be recompiled
- * every time it is needed. DEBUG define and load_tplcompile
- * configuration setting may be used to force templates to be always
- * recompiled.
- *
- * Returns an object implementing phpbb_template_renderer, or null
- * if template loading or compilation failed. Call render() on the
- * renderer to display the template. This will result in template
- * contents sent to the output stream (unless, of course, output
- * buffering is in effect).
- *
- * @param string $handle Handle of the template to load
- * @return phpbb_template_renderer Template renderer object, or null on failure
- * @uses phpbb_template_compile is used to compile template source
- */
- private function _tpl_load($handle)
- {
- $output_file = $this->_compiled_file_for_handle($handle);
-
- $recompile = defined('DEBUG') ||
- !file_exists($output_file) ||
- @filesize($output_file) === 0;
-
- if ($recompile || $this->config['load_tplcompile'])
- {
- // Set only if a recompile or an mtime check are required.
- $source_file = $this->locator->get_source_file_for_handle($handle);
-
- if (!$recompile && @filemtime($output_file) < @filemtime($source_file))
- {
- $recompile = true;
- }
- }
-
- // Recompile page if the original template is newer, otherwise load the compiled version
- if (!$recompile)
- {
- return new phpbb_template_renderer_include($output_file, $this);
- }
-
- $compile = new phpbb_template_compile($this->config['tpl_allow_php'], $this->style_names, $this->locator, $this->phpbb_root_path, $this->extension_manager, $this->user);
-
- if ($compile->compile_file_to_file($source_file, $output_file) !== false)
- {
- $renderer = new phpbb_template_renderer_include($output_file, $this);
- }
- else if (($code = $compile->compile_file($source_file)) !== false)
- {
- $renderer = new phpbb_template_renderer_eval($code, $this);
- }
- else
- {
- $renderer = null;
- }
-
- return $renderer;
- }
-
- /**
- * Determines compiled file path for handle $handle.
- *
- * @param string $handle Template handle (i.e. "friendly" template name)
- * @return string Compiled file path
- */
- private function _compiled_file_for_handle($handle)
- {
- $source_file = $this->locator->get_filename_for_handle($handle);
- $compiled_file = $this->cachepath . str_replace('/', '.', $source_file) . '.' . $this->php_ext;
- return $compiled_file;
- }
+ public function assign_display($handle, $template_var = '', $return_content = true);
/**
* 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);
- }
- }
+ public function assign_vars(array $vararray);
/**
* Assign a single scalar value to a single key.
@@ -364,11 +96,9 @@ class phpbb_template
*
* @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);
- }
+ public function assign_var($varname, $varval);
/**
* Append text to the string value stored in a key.
@@ -377,24 +107,18 @@ class phpbb_template
*
* @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);
- }
+ public function append_var($varname, $varval);
- // Docstring is copied from phpbb_template_context method with the same name.
/**
* Assign key variable pairs from an array to a specified block
* @param string $blockname Name of block to assign $vararray to
* @param array $vararray A hash of variable name => value pairs
+ * @return phpbb_template $this
*/
- public function assign_block_vars($blockname, array $vararray)
- {
- return $this->context->assign_block_vars($blockname, $vararray);
- }
+ public function assign_block_vars($blockname, array $vararray);
- // Docstring is copied from phpbb_template_context method with the same name.
/**
* Change already assigned key variable pair (one-dimensional - single loop entry)
*
@@ -422,94 +146,12 @@ class phpbb_template
*
* @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);
- }
+ public function alter_block_array($blockname, array $vararray, $key = false, $mode = 'insert');
/**
- * Include a separate template.
+ * Get path to template for handle (required for BBCode parser)
*
- * This function is marked public due to the way the template
- * implementation uses it. It is actually an implementation function
- * and should not be considered part of template class's public API.
- *
- * @param string $filename Template filename to include
- * @param bool $include True to include the file, false to just load it
- * @uses template_compile is used to compile uncached templates
+ * @return string
*/
- public function _tpl_include($filename, $include = true)
- {
- $this->locator->set_filenames(array($filename => $filename));
-
- if (!$this->load_and_render($filename))
- {
- // trigger_error cannot be used here, as the output already started
- echo 'template->_tpl_include(): Failed including ' . htmlspecialchars($handle) . "\n";
- }
- }
-
- /**
- * Include a PHP file.
- *
- * If a relative path is passed in $filename, it is considered to be
- * relative to board root ($phpbb_root_path). Absolute paths are
- * also allowed.
- *
- * This function is marked public due to the way the template
- * implementation uses it. It is actually an implementation function
- * and should not be considered part of template class's public API.
- *
- * @param string $filename Path to PHP file to include
- */
- public function _php_include($filename)
- {
- if (phpbb_is_absolute($filename))
- {
- $file = $filename;
- }
- else
- {
- $file = $this->phpbb_root_path . $filename;
- }
-
- if (!file_exists($file))
- {
- // trigger_error cannot be used here, as the output already started
- echo 'template->_php_include(): File ' . htmlspecialchars($file) . " does not exist\n";
- return;
- }
- include($file);
- }
-
- /**
- * Include JS file
- *
- * @param string $file file name
- * @param bool $locate True if file needs to be located
- * @param bool $relative True if path is relative to phpBB root directory. Ignored if $locate == true
- */
- public function _js_include($file, $locate = false, $relative = false)
- {
- // Locate file
- if ($locate)
- {
- $located = $this->locator->get_first_file_location(array($file), false, true);
- if ($located)
- {
- $file = $located;
- }
- }
- else if ($relative)
- {
- $file = $this->phpbb_root_path . $file;
- }
-
- $file .= (strpos($file, '?') === false) ? '?' : '&';
- $file .= 'assets_version=' . $this->config['assets_version'];
-
- // Add HTML code
- $code = '';
- $this->context->append_var('SCRIPTS', $code);
- }
+ public function get_source_file_for_handle($handle);
}
diff --git a/phpBB/includes/template/twig/definition.php b/phpBB/includes/template/twig/definition.php
new file mode 100644
index 0000000000..6557b209eb
--- /dev/null
+++ b/phpBB/includes/template/twig/definition.php
@@ -0,0 +1,69 @@
+definitions[$name])) ? $this->definitions[$name] : null;
+ }
+
+ /**
+ * DEFINE a variable
+ *
+ * @param string $name
+ * @param mixed $value
+ * @return phpbb_template_twig_definition
+ */
+ public function set($name, $value)
+ {
+ $this->definitions[$name] = $value;
+
+ return $this;
+ }
+
+ /**
+ * Append to a variable
+ *
+ * @param string $name
+ * @param string $value
+ * @return phpbb_template_twig_definition
+ */
+ public function append($name, $value)
+ {
+ if (!isset($this->definitions[$name]))
+ {
+ $this->definitions[$name] = '';
+ }
+
+ $this->definitions[$name] .= $value;
+
+ return $this;
+ }
+}
diff --git a/phpBB/includes/template/twig/environment.php b/phpBB/includes/template/twig/environment.php
new file mode 100644
index 0000000000..b60cd72325
--- /dev/null
+++ b/phpBB/includes/template/twig/environment.php
@@ -0,0 +1,140 @@
+ path)
+ * @param string $phpbb_root_path
+ * @param Twig_LoaderInterface $loader
+ * @param array $options Array of options to pass to Twig
+ */
+ public function __construct($phpbb_config, $phpbb_extensions, $phpbb_root_path, Twig_LoaderInterface $loader = null, $options = array())
+ {
+ $this->phpbb_config = $phpbb_config;
+ $this->phpbb_extensions = $phpbb_extensions;
+ $this->phpbb_root_path = $phpbb_root_path;
+
+ return parent::__construct($loader, $options);
+ }
+
+ /**
+ * Get the list of enabled phpBB extensions
+ *
+ * Used in EVENT node
+ *
+ * @return array
+ */
+ public function get_phpbb_extensions()
+ {
+ return $this->phpbb_extensions;
+ }
+
+ /**
+ * Get phpBB config
+ *
+ * @return phpbb_config
+ */
+ public function get_phpbb_config()
+ {
+ return $this->phpbb_config;
+ }
+
+ /**
+ * Get the phpBB root path
+ *
+ * @return string
+ */
+ public function get_phpbb_root_path()
+ {
+ return $this->phpbb_root_path;
+ }
+
+ /**
+ * Get the namespace look up order
+ *
+ * @return array
+ */
+ public function getNamespaceLookUpOrder()
+ {
+ return $this->namespace_look_up_order;
+ }
+
+ /**
+ * Set the namespace look up order to load templates from
+ *
+ * @param array $namespace
+ * @return Twig_Environment
+ */
+ public function setNamespaceLookUpOrder($namespace)
+ {
+ $this->namespace_look_up_order = $namespace;
+
+ return $this;
+ }
+
+ /**
+ * Loads a template by name.
+ *
+ * @param string $name The template name
+ * @param integer $index The index if it is an embedded template
+ * @return Twig_TemplateInterface A template instance representing the given template name
+ */
+ public function loadTemplate($name, $index = null)
+ {
+ if (strpos($name, '@') === false)
+ {
+ foreach ($this->getNamespaceLookUpOrder() as $namespace)
+ {
+ try
+ {
+ if ($namespace === '__main__')
+ {
+ return parent::loadTemplate($name, $index);
+ }
+
+ return parent::loadTemplate('@' . $namespace . '/' . $name, $index);
+ }
+ catch (Twig_Error_Loader $e)
+ {
+ }
+ }
+
+ // We were unable to load any templates
+ throw $e;
+ }
+ else
+ {
+ return parent::loadTemplate($name, $index);
+ }
+ }
+}
diff --git a/phpBB/includes/template/twig/extension.php b/phpBB/includes/template/twig/extension.php
new file mode 100644
index 0000000000..c279726434
--- /dev/null
+++ b/phpBB/includes/template/twig/extension.php
@@ -0,0 +1,188 @@
+context = $context;
+ $this->user = $user;
+ }
+
+ /**
+ * Get the name of this extension
+ *
+ * @return string
+ */
+ public function getName()
+ {
+ return 'phpbb';
+ }
+
+ /**
+ * Returns the token parser instance to add to the existing list.
+ *
+ * @return array An array of Twig_TokenParser instances
+ */
+ public function getTokenParsers()
+ {
+ return array(
+ new phpbb_template_twig_tokenparser_define,
+ new phpbb_template_twig_tokenparser_include,
+ new phpbb_template_twig_tokenparser_includejs,
+ new phpbb_template_twig_tokenparser_includecss,
+ new phpbb_template_twig_tokenparser_event,
+ new phpbb_template_twig_tokenparser_includephp,
+ new phpbb_template_twig_tokenparser_php,
+ );
+ }
+
+ /**
+ * Returns a list of filters to add to the existing list.
+ *
+ * @return array An array of filters
+ */
+ public function getFilters()
+ {
+ return array(
+ new Twig_SimpleFilter('subset', array($this, 'loop_subset'), array('needs_environment' => true)),
+ new Twig_SimpleFilter('addslashes', 'addslashes'),
+ );
+ }
+
+ /**
+ * Returns a list of global functions to add to the existing list.
+ *
+ * @return array An array of global functions
+ */
+ public function getFunctions()
+ {
+ return array(
+ new Twig_SimpleFunction('lang', array($this, 'lang')),
+ );
+ }
+
+ /**
+ * Returns a list of operators to add to the existing list.
+ *
+ * @return array An array of operators
+ */
+ public function getOperators()
+ {
+ return array(
+ array(
+ '!' => array('precedence' => 50, 'class' => 'Twig_Node_Expression_Unary_Not'),
+ ),
+ array(
+ // precedence settings are copied from similar operators in Twig core extension
+ '||' => array('precedence' => 10, 'class' => 'Twig_Node_Expression_Binary_Or', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT),
+ '&&' => array('precedence' => 15, 'class' => 'Twig_Node_Expression_Binary_And', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT),
+
+ 'eq' => array('precedence' => 20, 'class' => 'Twig_Node_Expression_Binary_Equal', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT),
+
+ 'ne' => array('precedence' => 20, 'class' => 'Twig_Node_Expression_Binary_NotEqual', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT),
+ 'neq' => array('precedence' => 20, 'class' => 'Twig_Node_Expression_Binary_NotEqual', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT),
+ '<>' => array('precedence' => 20, 'class' => 'Twig_Node_Expression_Binary_NotEqual', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT),
+
+ '===' => array('precedence' => 20, 'class' => 'phpbb_template_twig_node_expression_binary_equalequal', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT),
+ '!==' => array('precedence' => 20, 'class' => 'phpbb_template_twig_node_expression_binary_notequalequal', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT),
+
+ 'gt' => array('precedence' => 20, 'class' => 'Twig_Node_Expression_Binary_Greater', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT),
+ 'gte' => array('precedence' => 20, 'class' => 'Twig_Node_Expression_Binary_GreaterEqual', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT),
+ 'ge' => array('precedence' => 20, 'class' => 'Twig_Node_Expression_Binary_GreaterEqual', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT),
+ 'lt' => array('precedence' => 20, 'class' => 'Twig_Node_Expression_Binary_Less', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT),
+ 'lte' => array('precedence' => 20, 'class' => 'Twig_Node_Expression_Binary_LessEqual', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT),
+ 'le' => array('precedence' => 20, 'class' => 'Twig_Node_Expression_Binary_LessEqual', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT),
+
+ 'mod' => array('precedence' => 60, 'class' => 'Twig_Node_Expression_Binary_Mod', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT),
+ ),
+ );
+ }
+
+ /**
+ * Grabs a subset of a loop
+ *
+ * @param Twig_Environment $env A Twig_Environment instance
+ * @param mixed $item A variable
+ * @param integer $start Start of the subset
+ * @param integer $end End of the subset
+ * @param Boolean $preserveKeys Whether to preserve key or not (when the input is an array)
+ *
+ * @return mixed The sliced variable
+ */
+ function loop_subset(Twig_Environment $env, $item, $start, $end = null, $preserveKeys = false)
+ {
+ // We do almost the same thing as Twig's slice (array_slice), except when $end is positive
+ if ($end >= 1)
+ {
+ // When end is > 1, subset will end on the last item in an array with the specified $end
+ // This is different from slice in that it is the number we end on rather than the number
+ // of items to grab (length)
+
+ // Start must always be the actual starting number for this calculation (not negative)
+ $start = ($start < 0) ? sizeof($item) + $start : $start;
+ $end = $end - $start;
+ }
+
+ // We always include the last element (this was the past design)
+ $end = ($end == -1 || $end === null) ? null : $end + 1;
+
+ return twig_slice($env, $item, $start, $end, $preserveKeys);
+ }
+
+ /**
+ * Get output for a language variable (L_FOO, LA_FOO)
+ *
+ * This function checks to see if the language var was outputted to $context
+ * (e.g. in the ACP, L_TITLE)
+ * If not, we return the result of $user->lang()
+ *
+ * @param string $lang name
+ * @return string
+ */
+ function lang()
+ {
+ $args = func_get_args();
+ $key = $args[0];
+
+ $context = $this->context->get_data_ref();
+ $context_vars = $context['.'][0];
+
+ if (isset($context_vars['L_' . $key]))
+ {
+ return $context_vars['L_' . $key];
+ }
+
+ // LA_ is transformed into lang(\'$1\')|addslashes, so we should not
+ // need to check for it
+
+ return call_user_func_array(array($this->user, 'lang'), $args);
+ }
+}
diff --git a/phpBB/includes/template/twig/lexer.php b/phpBB/includes/template/twig/lexer.php
new file mode 100644
index 0000000000..46412ad048
--- /dev/null
+++ b/phpBB/includes/template/twig/lexer.php
@@ -0,0 +1,300 @@
+fix_inline_variable_tokens(array(
+ 'DEFINE.+=',
+ 'INCLUDE',
+ 'INCLUDEPHP',
+ 'INCLUDEJS',
+ 'INCLUDECSS',
+ ), $code);
+
+ // Fix our BEGIN statements
+ $code = $this->fix_begin_tokens($code);
+
+ // Fix our IF tokens
+ $code = $this->fix_if_tokens($code);
+
+ // Fix our DEFINE tokens
+ $code = $this->fix_define_tokens($code);
+
+ // Replace all of our starting tokens, with Twig style, {% TOKEN %}
+ // This also strips outer parenthesis, becomes
+ $code = preg_replace('##', '{% $1 $2 %}', $code);
+
+ // Replace all of our twig masks with Twig code (e.g. with {% block $1 %})
+ $code = $this->replace_twig_tag_masks($code, $twig_tags);
+
+ // Replace all of our language variables, {L_VARNAME}, with Twig style, {{ lang('NAME') }}
+ // Appends any filters after lang()
+ $code = preg_replace('#{L_([a-zA-Z0-9_\.]+)(\|[^}]+?)?}#', '{{ lang(\'$1\')$2 }}', $code);
+
+ // Replace all of our escaped language variables, {LA_VARNAME}, with Twig style, {{ lang('NAME')|addslashes }}
+ // Appends any filters after lang(), but before addslashes
+ $code = preg_replace('#{LA_([a-zA-Z0-9_\.]+)(\|[^}]+?)?}#', '{{ lang(\'$1\')$2|addslashes }}', $code);
+
+ // Replace all of our variables, {VARNAME}, with Twig style, {{ VARNAME }}
+ // Appends any filters
+ $code = preg_replace('#{([a-zA-Z0-9_\.]+)(\|[^}]+?)?}#', '{{ $1$2 }}', $code);
+
+ return parent::tokenize($code, $filename);
+ }
+
+ /**
+ * Fix tokens that may have inline variables
+ *
+ * E.g. ";
+ };
+
+ return preg_replace_callback('##', $callback, $code);
+ }
+
+ /**
+ * Fix begin tokens (convert our BEGIN to Twig for)
+ *
+ * Not meant to be used outside of this context, public because the anonymous function calls this
+ *
+ * @param string $code
+ * @param array $parent_nodes (used in recursion)
+ * @return string
+ */
+ public function fix_begin_tokens($code, $parent_nodes = array())
+ {
+ // PHP 5.3 cannot use $this in an anonymous function, so use this as a work-around
+ $parent_class = $this;
+ $callback = function ($matches) use ($parent_class, $parent_nodes)
+ {
+ $name = $matches[1];
+ $subset = trim(substr($matches[2], 1, -1)); // Remove parenthesis
+ $body = $matches[3];
+
+ // Is the designer wanting to call another loop in a loop?
+ //
+ //
+ //
+ //
+ // 'loop2' is actually on the same nesting level as 'loop' you assign
+ // variables to it with template->assign_block_vars('loop2', array(...))
+ if (strpos($name, '!') === 0)
+ {
+ // Count the number if ! occurrences
+ $count = substr_count($name, '!');
+ for ($i = 0; $i < $count; $i++)
+ {
+ array_pop($parent_nodes);
+ $name = substr($name, 1);
+ }
+ }
+
+ // Remove all parent nodes, e.g. foo, bar from foo.bar.foobar.VAR
+ foreach ($parent_nodes as $node)
+ {
+ $body = preg_replace('#([^a-zA-Z0-9_])' . $node . '\.([a-zA-Z0-9_]+)\.#', '$1$2.', $body);
+ }
+
+ // Add current node to list of parent nodes for child nodes
+ $parent_nodes[] = $name;
+
+ // Recursive...fix any child nodes
+ $body = $parent_class->fix_begin_tokens($body, $parent_nodes);
+
+ // Rename loopname vars (to prevent collisions, loop children are named (loop name)_loop_element)
+ $body = str_replace($name . '.', $name . '_loop_element.', $body);
+
+ // Need the parent variable name
+ array_pop($parent_nodes);
+ $parent = (!empty($parent_nodes)) ? end($parent_nodes) . '_loop_element.' : '';
+
+ if ($subset !== '')
+ {
+ $subset = '|subset(' . $subset . ')';
+ }
+
+ // Turn into a Twig for loop, using (loop name)_loop_element for each child
+ return "{% for {$name}_loop_element in {$parent}{$name}{$subset} %}{$body}{% endfor %}";
+ };
+
+ // Replace correctly, only needs to be done once
+ $code = str_replace('', '{% else %}', $code);
+
+ return preg_replace_callback('#(.+?)#s', $callback, $code);
+ }
+
+ /**
+ * Fix IF statements
+ *
+ * @param string $code
+ * @return string
+ */
+ protected function fix_if_tokens($code)
+ {
+ $callback = function($matches)
+ {
+ // Replace $TEST with definition.TEST
+ $matches[1] = preg_replace('#\s\$([a-zA-Z_0-9]+)#', ' definition.$1', $matches[1]);
+
+ // Replace .test with test|length
+ $matches[1] = preg_replace('#\s\.([a-zA-Z_0-9\.]+)#', ' $1|length', $matches[1]);
+
+ return '';
+ };
+
+ // 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('##', $callback, $code);
+ }
+
+ /**
+ * Fix DEFINE statements and {$VARNAME} variables
+ *
+ * @param string $code
+ * @return string
+ */
+ protected function fix_define_tokens($code)
+ {
+ /**
+ * Changing $VARNAME to definition.varname because set is only local
+ * context (e.g. DEFINE $TEST will only make $TEST available in current
+ * template and any child templates, but not any parent templates).
+ *
+ * DEFINE handles setting it properly to definition in its node, but the
+ * variables reading FROM it need to be altered to definition.VARNAME
+ *
+ * Setting up definition as a class in the array passed to Twig
+ * ($context) makes set definition.TEST available in the global context
+ */
+
+ // Replace #', '{% DEFINE $1 %}', $code);
+
+ // Changing UNDEFINE NAME to DEFINE NAME = null to save from creating an extra token parser/node
+ $code = preg_replace('##', '{% DEFINE $1= null %}', $code);
+
+ // Replace all of our variables, {$VARNAME}, with Twig style, {{ definition.VARNAME }}
+ $code = preg_replace('#{\$([a-zA-Z0-9_\.]+)}#', '{{ definition.$1 }}', $code);
+
+ // Replace all of our variables, ~ $VARNAME ~, with Twig style, ~ definition.VARNAME ~
+ $code = preg_replace('#~ \$([a-zA-Z0-9_\.]+) ~#', '~ definition.$1 ~', $code);
+
+ return $code;
+ }
+
+ /**
+ * Replace Twig tag masks with Twig tag calls
+ *
+ * E.g. with {% block foo %}
+ *
+ * @param string $code
+ * @param array $twig_tags All tags we want to create a mask for
+ * @return string
+ */
+ protected function replace_twig_tag_masks($code, $twig_tags)
+ {
+ $callback = function ($matches)
+ {
+ $matches[1] = strtolower($matches[1]);
+
+ return "{% {$matches[1]}{$matches[2]}%}";
+ };
+
+ foreach ($twig_tags as &$tag)
+ {
+ $tag = strtoupper($tag);
+ }
+
+ // twig_tags is an array of the twig tags, which are all lowercase, but we use all uppercase tags
+ $code = preg_replace_callback('##',$callback, $code);
+
+ return $code;
+ }
+}
diff --git a/phpBB/includes/template/twig/node/define.php b/phpBB/includes/template/twig/node/define.php
new file mode 100644
index 0000000000..fcb19cc773
--- /dev/null
+++ b/phpBB/includes/template/twig/node/define.php
@@ -0,0 +1,58 @@
+ $name, 'value' => $value), array('capture' => $capture, 'safe' => false), $lineno, $tag);
+ }
+
+ /**
+ * Compiles the node to PHP.
+ *
+ * @param Twig_Compiler A Twig_Compiler instance
+ */
+ public function compile(Twig_Compiler $compiler)
+ {
+ $compiler->addDebugInfo($this);
+
+ if ($this->getAttribute('capture')) {
+ $compiler
+ ->write("ob_start();\n")
+ ->subcompile($this->getNode('value'))
+ ;
+
+ $compiler->write("\$value = ('' === \$value = ob_get_clean()) ? '' : new Twig_Markup(\$value, \$this->env->getCharset());\n");
+ }
+ else
+ {
+ $compiler
+ ->write("\$value = ")
+ ->subcompile($this->getNode('value'))
+ ->raw(";\n")
+ ;
+ }
+
+ $compiler
+ ->write("\$context['definition']->set('")
+ ->raw($this->getNode('name')->getAttribute('name'))
+ ->raw("', \$value);\n")
+ ;
+ }
+}
diff --git a/phpBB/includes/template/twig/node/event.php b/phpBB/includes/template/twig/node/event.php
new file mode 100644
index 0000000000..971dea14fa
--- /dev/null
+++ b/phpBB/includes/template/twig/node/event.php
@@ -0,0 +1,79 @@
+environment = $environment;
+
+ parent::__construct(array('expr' => $expr), array(), $lineno, $tag);
+ }
+
+ /**
+ * Compiles the node to PHP.
+ *
+ * @param Twig_Compiler A Twig_Compiler instance
+ */
+ public function compile(Twig_Compiler $compiler)
+ {
+ $compiler->addDebugInfo($this);
+
+ $location = $this->getNode('expr')->getAttribute('name');
+
+ foreach ($this->environment->get_phpbb_extensions() as $ext_namespace => $ext_path)
+ {
+ $ext_namespace = str_replace('/', '_', $ext_namespace);
+
+ if (defined('DEBUG'))
+ {
+ // If debug mode is enabled, lets check for new/removed EVENT
+ // templates on page load rather than at compile. This is
+ // slower, but makes developing extensions easier (no need to
+ // purge the cache when a new event template file is added)
+ $compiler
+ ->write("if (\$this->env->getLoader()->exists('@{$ext_namespace}/{$location}.html')) {\n")
+ ->indent()
+ ;
+ }
+
+ if (defined('DEBUG') || $this->environment->getLoader()->exists('@' . $ext_namespace . '/' . $location . '.html'))
+ {
+ $compiler
+ ->write("\$previous_look_up_order = \$this->env->getNamespaceLookUpOrder();\n")
+
+ // We set the namespace lookup order to be this extension first, then the main path
+ ->write("\$this->env->setNamespaceLookUpOrder(array('{$ext_namespace}', '__main__'));\n")
+ ->write("\$this->env->loadTemplate('@{$ext_namespace}/{$location}.html')->display(\$context);\n")
+ ->write("\$this->env->setNamespaceLookUpOrder(\$previous_look_up_order);\n")
+ ;
+ }
+
+ if (defined('DEBUG'))
+ {
+ $compiler
+ ->outdent()
+ ->write("}\n\n")
+ ;
+ }
+ }
+ }
+}
diff --git a/phpBB/includes/template/twig/node/expression/binary/equalequal.php b/phpBB/includes/template/twig/node/expression/binary/equalequal.php
new file mode 100644
index 0000000000..8ec2069114
--- /dev/null
+++ b/phpBB/includes/template/twig/node/expression/binary/equalequal.php
@@ -0,0 +1,25 @@
+raw('===');
+ }
+}
diff --git a/phpBB/includes/template/twig/node/expression/binary/notequalequal.php b/phpBB/includes/template/twig/node/expression/binary/notequalequal.php
new file mode 100644
index 0000000000..96f32c502e
--- /dev/null
+++ b/phpBB/includes/template/twig/node/expression/binary/notequalequal.php
@@ -0,0 +1,25 @@
+raw('!==');
+ }
+}
diff --git a/phpBB/includes/template/twig/node/include.php b/phpBB/includes/template/twig/node/include.php
new file mode 100644
index 0000000000..5c6ae1bbcf
--- /dev/null
+++ b/phpBB/includes/template/twig/node/include.php
@@ -0,0 +1,56 @@
+addDebugInfo($this);
+
+ $compiler
+ ->write("\$location = ")
+ ->subcompile($this->getNode('expr'))
+ ->raw(";\n")
+ ->write("\$namespace = false;\n")
+ ->write("if (strpos(\$location, '@') === 0) {\n")
+ ->indent()
+ ->write("\$namespace = substr(\$location, 1, strpos(\$location, '/') - 1);\n")
+ ->write("\$previous_look_up_order = \$this->env->getNamespaceLookUpOrder();\n")
+
+ // We set the namespace lookup order to be this namespace first, then the main path
+ ->write("\$this->env->setNamespaceLookUpOrder(array(\$namespace, '__main__'));\n")
+ ->outdent()
+ ->write("}\n")
+ ;
+
+ parent::compile($compiler);
+
+ $compiler
+ ->write("if (\$namespace) {\n")
+ ->indent()
+ ->write("\$this->env->setNamespaceLookUpOrder(\$previous_look_up_order);\n")
+ ->outdent()
+ ->write("}\n")
+ ;
+ }
+}
diff --git a/phpBB/includes/template/twig/node/includeasset.php b/phpBB/includes/template/twig/node/includeasset.php
new file mode 100644
index 0000000000..5abff10e3f
--- /dev/null
+++ b/phpBB/includes/template/twig/node/includeasset.php
@@ -0,0 +1,65 @@
+environment = $environment;
+
+ parent::__construct(array('expr' => $expr), array(), $lineno, $tag);
+ }
+ /**
+ * Compiles the node to PHP.
+ *
+ * @param Twig_Compiler A Twig_Compiler instance
+ */
+ public function compile(Twig_Compiler $compiler)
+ {
+ $compiler->addDebugInfo($this);
+
+ $config = $this->environment->get_phpbb_config();
+
+ $compiler
+ ->write("\$asset_file = ")
+ ->subcompile($this->getNode('expr'))
+ ->raw(";\n")
+ ->write("\$argument_string = \$anchor_string = '';\n")
+ ->write("if ((\$argument_string_start = strpos(\$asset_file, '?')) !== false) {\n")
+ ->indent()
+ ->write("\$argument_string = substr(\$asset_file, \$argument_string_start);\n")
+ ->write("\$asset_file = substr(\$asset_file, 0, \$argument_string_start);\n")
+ ->write("if ((\$anchor_string_start = strpos(\$argument_string, '#')) !== false) {\n")
+ ->indent()
+ ->write("\$anchor_string = substr(\$argument_string, \$anchor_string_start);\n")
+ ->write("\$argument_string = substr(\$argument_string, 0, \$anchor_string_start);\n")
+ ->outdent()
+ ->write("}\n")
+ ->outdent()
+ ->write("}\n")
+ ->write("if (strpos(\$asset_file, '//') !== 0 && strpos(\$asset_file, 'http://') !== 0 && strpos(\$asset_file, 'https://') !== 0 && !file_exists(\$asset_file)) {\n")
+ ->indent()
+ ->write("\$asset_file = \$this->getEnvironment()->getLoader()->getCacheKey(\$asset_file);\n")
+ ->write("\$argument_string .= ((\$argument_string) ? '&' : '?') . 'assets_version={$config['assets_version']}';\n")
+ ->outdent()
+ ->write("}\n")
+ ->write("\$asset_file .= \$argument_string . \$anchor_string;\n")
+ ->write("\$context['definition']->append('{$this->get_definition_name()}', '")
+ ;
+
+ $this->append_asset($compiler);
+
+ $compiler
+ ->raw("\n');\n")
+ ;
+ }
+}
diff --git a/phpBB/includes/template/twig/node/includecss.php b/phpBB/includes/template/twig/node/includecss.php
new file mode 100644
index 0000000000..01fda44aad
--- /dev/null
+++ b/phpBB/includes/template/twig/node/includecss.php
@@ -0,0 +1,30 @@
+raw("raw("\$asset_file . '\"")
+ ->raw(' rel="stylesheet" type="text/css" media="screen, projection" />')
+ ;
+ }
+}
diff --git a/phpBB/includes/template/twig/node/includejs.php b/phpBB/includes/template/twig/node/includejs.php
new file mode 100644
index 0000000000..fdf2bea3ed
--- /dev/null
+++ b/phpBB/includes/template/twig/node/includejs.php
@@ -0,0 +1,32 @@
+environment->get_phpbb_config();
+
+ $compiler
+ ->raw("\n")
+ ;
+ }
+}
diff --git a/phpBB/includes/template/twig/node/includephp.php b/phpBB/includes/template/twig/node/includephp.php
new file mode 100644
index 0000000000..dbe54f0e1a
--- /dev/null
+++ b/phpBB/includes/template/twig/node/includephp.php
@@ -0,0 +1,91 @@
+environment = $environment;
+
+ parent::__construct(array('expr' => $expr), array('ignore_missing' => (Boolean) $ignoreMissing), $lineno, $tag);
+ }
+
+ /**
+ * Compiles the node to PHP.
+ *
+ * @param Twig_Compiler A Twig_Compiler instance
+ */
+ public function compile(Twig_Compiler $compiler)
+ {
+ $compiler->addDebugInfo($this);
+
+ $config = $this->environment->get_phpbb_config();
+
+ if (!$config['tpl_allow_php'])
+ {
+ $compiler
+ ->write("// INCLUDEPHP Disabled\n")
+ ;
+
+ return;
+ }
+
+ if ($this->getAttribute('ignore_missing')) {
+ $compiler
+ ->write("try {\n")
+ ->indent()
+ ;
+ }
+
+ $compiler
+ ->write("\$location = ")
+ ->subcompile($this->getNode('expr'))
+ ->raw(";\n")
+ ->write("if (phpbb_is_absolute(\$location)) {\n")
+ ->indent()
+ // Absolute path specified
+ ->write("require(\$location);\n")
+ ->outdent()
+ ->write("} else if (file_exists(\$this->getEnvironment()->get_phpbb_root_path() . \$location)) {\n")
+ ->indent()
+ // PHP file relative to phpbb_root_path
+ ->write("require(\$this->getEnvironment()->get_phpbb_root_path() . \$location);\n")
+ ->outdent()
+ ->write("} else {\n")
+ ->indent()
+ // Local path (behaves like INCLUDE)
+ ->write("require(\$this->getEnvironment()->getLoader()->getCacheKey(\$location));\n")
+ ->outdent()
+ ->write("}\n")
+ ;
+
+ if ($this->getAttribute('ignore_missing')) {
+ $compiler
+ ->outdent()
+ ->write("} catch (Twig_Error_Loader \$e) {\n")
+ ->indent()
+ ->write("// ignore missing template\n")
+ ->outdent()
+ ->write("}\n\n")
+ ;
+ }
+ }
+}
diff --git a/phpBB/includes/template/twig/node/php.php b/phpBB/includes/template/twig/node/php.php
new file mode 100644
index 0000000000..c11539ea7f
--- /dev/null
+++ b/phpBB/includes/template/twig/node/php.php
@@ -0,0 +1,55 @@
+environment = $environment;
+
+ parent::__construct(array('text' => $text), array(), $lineno, $tag);
+ }
+
+ /**
+ * Compiles the node to PHP.
+ *
+ * @param Twig_Compiler A Twig_Compiler instance
+ */
+ public function compile(Twig_Compiler $compiler)
+ {
+ $compiler->addDebugInfo($this);
+
+ $config = $this->environment->get_phpbb_config();
+
+ if (!$config['tpl_allow_php'])
+ {
+ $compiler
+ ->write("// PHP Disabled\n")
+ ;
+
+ return;
+ }
+
+ $compiler
+ ->raw($this->getNode('text')->getAttribute('data'))
+ ;
+ }
+}
diff --git a/phpBB/includes/template/twig/tokenparser/define.php b/phpBB/includes/template/twig/tokenparser/define.php
new file mode 100644
index 0000000000..4ea15388c4
--- /dev/null
+++ b/phpBB/includes/template/twig/tokenparser/define.php
@@ -0,0 +1,66 @@
+getLine();
+ $stream = $this->parser->getStream();
+ $name = $this->parser->getExpressionParser()->parseExpression();
+
+ $capture = false;
+ if ($stream->test(Twig_Token::OPERATOR_TYPE, '=')) {
+ $stream->next();
+ $value = $this->parser->getExpressionParser()->parseExpression();
+
+ $stream->expect(Twig_Token::BLOCK_END_TYPE);
+ } else {
+ $capture = true;
+
+ $stream->expect(Twig_Token::BLOCK_END_TYPE);
+
+ $value = $this->parser->subparse(array($this, 'decideBlockEnd'), true);
+ $stream->expect(Twig_Token::BLOCK_END_TYPE);
+ }
+
+ return new phpbb_template_twig_node_define($capture, $name, $value, $lineno, $this->getTag());
+ }
+
+ public function decideBlockEnd(Twig_Token $token)
+ {
+ return $token->test('ENDDEFINE');
+ }
+
+ /**
+ * Gets the tag name associated with this token parser.
+ *
+ * @return string The tag name
+ */
+ public function getTag()
+ {
+ return 'DEFINE';
+ }
+}
diff --git a/phpBB/includes/template/twig/tokenparser/event.php b/phpBB/includes/template/twig/tokenparser/event.php
new file mode 100644
index 0000000000..e4dddd6dcc
--- /dev/null
+++ b/phpBB/includes/template/twig/tokenparser/event.php
@@ -0,0 +1,47 @@
+parser->getExpressionParser()->parseExpression();
+
+ $stream = $this->parser->getStream();
+ $stream->expect(Twig_Token::BLOCK_END_TYPE);
+
+ return new phpbb_template_twig_node_event($expr, $this->parser->getEnvironment(), $token->getLine(), $this->getTag());
+ }
+
+ /**
+ * Gets the tag name associated with this token parser.
+ *
+ * @return string The tag name
+ */
+ public function getTag()
+ {
+ return 'EVENT';
+ }
+}
diff --git a/phpBB/includes/template/twig/tokenparser/include.php b/phpBB/includes/template/twig/tokenparser/include.php
new file mode 100644
index 0000000000..520f9fd1a0
--- /dev/null
+++ b/phpBB/includes/template/twig/tokenparser/include.php
@@ -0,0 +1,46 @@
+parser->getExpressionParser()->parseExpression();
+
+ list($variables, $only, $ignoreMissing) = $this->parseArguments();
+
+ return new phpbb_template_twig_node_include($expr, $variables, $only, $ignoreMissing, $token->getLine(), $this->getTag());
+ }
+
+ /**
+ * Gets the tag name associated with this token parser.
+ *
+ * @return string The tag name
+ */
+ public function getTag()
+ {
+ return 'INCLUDE';
+ }
+}
diff --git a/phpBB/includes/template/twig/tokenparser/includecss.php b/phpBB/includes/template/twig/tokenparser/includecss.php
new file mode 100644
index 0000000000..6c24dda647
--- /dev/null
+++ b/phpBB/includes/template/twig/tokenparser/includecss.php
@@ -0,0 +1,38 @@
+parser->getExpressionParser()->parseExpression();
+
+ $stream = $this->parser->getStream();
+ $stream->expect(Twig_Token::BLOCK_END_TYPE);
+
+ return new phpbb_template_twig_node_includecss($expr, $this->parser->getEnvironment(), $token->getLine(), $this->getTag());
+ }
+
+ /**
+ * Gets the tag name associated with this token parser.
+ *
+ * @return string The tag name
+ */
+ public function getTag()
+ {
+ return 'INCLUDECSS';
+ }
+}
diff --git a/phpBB/includes/template/twig/tokenparser/includejs.php b/phpBB/includes/template/twig/tokenparser/includejs.php
new file mode 100644
index 0000000000..b02b2f89ba
--- /dev/null
+++ b/phpBB/includes/template/twig/tokenparser/includejs.php
@@ -0,0 +1,47 @@
+parser->getExpressionParser()->parseExpression();
+
+ $stream = $this->parser->getStream();
+ $stream->expect(Twig_Token::BLOCK_END_TYPE);
+
+ return new phpbb_template_twig_node_includejs($expr, $this->parser->getEnvironment(), $token->getLine(), $this->getTag());
+ }
+
+ /**
+ * Gets the tag name associated with this token parser.
+ *
+ * @return string The tag name
+ */
+ public function getTag()
+ {
+ return 'INCLUDEJS';
+ }
+}
diff --git a/phpBB/includes/template/twig/tokenparser/includephp.php b/phpBB/includes/template/twig/tokenparser/includephp.php
new file mode 100644
index 0000000000..13fe6de8a6
--- /dev/null
+++ b/phpBB/includes/template/twig/tokenparser/includephp.php
@@ -0,0 +1,56 @@
+parser->getExpressionParser()->parseExpression();
+
+ $stream = $this->parser->getStream();
+
+ $ignoreMissing = false;
+ if ($stream->test(Twig_Token::NAME_TYPE, 'ignore')) {
+ $stream->next();
+ $stream->expect(Twig_Token::NAME_TYPE, 'missing');
+
+ $ignoreMissing = true;
+ }
+
+ $stream->expect(Twig_Token::BLOCK_END_TYPE);
+
+ return new phpbb_template_twig_node_includephp($expr, $this->parser->getEnvironment(), $ignoreMissing, $token->getLine(), $this->getTag());
+ }
+
+ /**
+ * Gets the tag name associated with this token parser.
+ *
+ * @return string The tag name
+ */
+ public function getTag()
+ {
+ return 'INCLUDEPHP';
+ }
+}
diff --git a/phpBB/includes/template/twig/tokenparser/php.php b/phpBB/includes/template/twig/tokenparser/php.php
new file mode 100644
index 0000000000..197980a59a
--- /dev/null
+++ b/phpBB/includes/template/twig/tokenparser/php.php
@@ -0,0 +1,55 @@
+parser->getStream();
+
+ $stream->expect(Twig_Token::BLOCK_END_TYPE);
+
+ $body = $this->parser->subparse(array($this, 'decideEnd'), true);
+
+ $stream->expect(Twig_Token::BLOCK_END_TYPE);
+
+ return new phpbb_template_twig_node_php($body, $this->parser->getEnvironment(), $token->getLine(), $this->getTag());
+ }
+
+ public function decideEnd(Twig_Token $token)
+ {
+ return $token->test('ENDPHP');
+ }
+
+ /**
+ * Gets the tag name associated with this token parser.
+ *
+ * @return string The tag name
+ */
+ public function getTag()
+ {
+ return 'PHP';
+ }
+}
diff --git a/phpBB/includes/template/twig/twig.php b/phpBB/includes/template/twig/twig.php
new file mode 100644
index 0000000000..92a37d1634
--- /dev/null
+++ b/phpBB/includes/template/twig/twig.php
@@ -0,0 +1,465 @@
+phpbb_root_path = $phpbb_root_path;
+ $this->adm_relative_path = $adm_relative_path;
+ $this->php_ext = $php_ext;
+ $this->config = $config;
+ $this->user = $user;
+ $this->context = $context;
+ $this->extension_manager = $extension_manager;
+
+ $this->cachepath = $phpbb_root_path . 'cache/twig/';
+
+ // Initiate the loader, __main__ namespace paths will be setup later in set_style_names()
+ $loader = new Twig_Loader_Filesystem('');
+
+ $this->twig = new phpbb_template_twig_environment(
+ $this->config,
+ ($this->extension_manager) ? $this->extension_manager->all_enabled() : array(),
+ $this->phpbb_root_path,
+ $loader,
+ array(
+ 'cache' => (defined('IN_INSTALL')) ? false : $this->cachepath,
+ 'debug' => defined('DEBUG'),
+ 'auto_reload' => (bool) $this->config['load_tplcompile'],
+ 'autoescape' => false,
+ )
+ );
+
+ $this->twig->addExtension(
+ new phpbb_template_twig_extension(
+ $this->context,
+ $this->user
+ )
+ );
+
+ $lexer = new phpbb_template_twig_lexer($this->twig);
+
+ $this->twig->setLexer($lexer);
+ }
+
+ /**
+ * Clear the cache
+ *
+ * @return phpbb_template
+ */
+ public function clear_cache()
+ {
+ if (is_dir($this->cachepath))
+ {
+ $this->twig->clearCacheFiles();
+ }
+
+ return $this;
+ }
+
+ /**
+ * Sets the template filenames for handles.
+ *
+ * @param array $filename_array Should be a hash of handle => filename pairs.
+ * @return phpbb_template $this
+ */
+ public function set_filenames(array $filename_array)
+ {
+ $this->filenames = array_merge($this->filenames, $filename_array);
+
+ return $this;
+ }
+
+ /**
+ * Sets the style names/paths corresponding to style hierarchy being compiled
+ * and/or rendered.
+ *
+ * @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
+ * @return phpbb_template $this
+ */
+ public function set_style_names(array $style_names, array $style_paths, $is_core = false)
+ {
+ $this->style_names = $style_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');
+ }
+
+ // Add all namespaces for all extensions
+ if ($this->extension_manager instanceof phpbb_extension_manager)
+ {
+ $style_names[] = 'all';
+
+ foreach ($this->extension_manager->all_enabled() as $ext_namespace => $ext_path)
+ {
+ // namespaces cannot contain /
+ $namespace = str_replace('/', '_', $ext_namespace);
+ $paths = array();
+
+ foreach ($style_names as $style_name)
+ {
+ $ext_style_path = $ext_path . 'styles/' . $style_name . '/template';
+
+ if (is_dir($ext_style_path))
+ {
+ $paths[] = $ext_style_path;
+ }
+ }
+
+ $this->twig->getLoader()->setPaths($paths, $namespace);
+ }
+ }
+
+ 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.
+ *
+ * The template will be loaded and compiled, if necessary, first.
+ *
+ * This function calls hooks.
+ *
+ * @param string $handle Handle to display
+ * @return phpbb_template $this
+ */
+ public function display($handle)
+ {
+ $result = $this->call_hook($handle, __FUNCTION__);
+ if ($result !== false)
+ {
+ return $result[0];
+ }
+
+ $this->twig->display($this->get_filename_from_handle($handle), $this->get_template_vars());
+
+ 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.
+ *
+ * @param string $handle Handle to operate on
+ * @param string $template_var Template variable to assign compiled handle to
+ * @param bool $return_content If true return compiled handle, otherwise assign to $template_var
+ * @return phpbb_template|string if $return_content is true return string of the compiled handle, otherwise return $this
+ */
+ public function assign_display($handle, $template_var = '', $return_content = true)
+ {
+ if ($return_content)
+ {
+ return $this->twig->render($this->get_filename_from_handle($handle), $this->get_template_vars());
+ }
+
+ $this->assign_var($template_var, $this->twig->render($this->get_filename_from_handle($handle, $this->get_template_vars())));
+
+ 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()
+ {
+ $context_vars = $this->context->get_data_ref();
+
+ $vars = array_merge(
+ $context_vars['.'][0], // To get normal vars
+ $context_vars, // To get loops
+ array(
+ 'definition' => new phpbb_template_twig_definition(),
+ 'user' => $this->user,
+ )
+ );
+
+ // cleanup
+ unset($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)
+ *
+ * @return string
+ */
+ public function get_source_file_for_handle($handle)
+ {
+ return $this->twig->getLoader()->getCacheKey($this->get_filename_from_handle($handle));
+ }
+}
diff --git a/phpBB/includes/ucp/ucp_groups.php b/phpBB/includes/ucp/ucp_groups.php
index aada0525a8..8620e33e47 100644
--- a/phpBB/includes/ucp/ucp_groups.php
+++ b/phpBB/includes/ucp/ucp_groups.php
@@ -565,7 +565,7 @@ class ucp_groups
if ($colour_error = validate_data($submit_ary, array('colour' => array('hex_colour', true))))
{
// Replace "error" string with its real, localised form
- $error = array_merge($error, array_map(array(&$user, 'lang'), $colour_error));
+ $error = array_merge($error, $colour_error);
}
if (!sizeof($error))
@@ -613,6 +613,7 @@ class ucp_groups
if (sizeof($error))
{
+ $error = array_map(array(&$user, 'lang'), $error);
$group_rank = $submit_ary['rank'];
$group_desc_data = array(
diff --git a/phpBB/install/index.php b/phpBB/install/index.php
index f745f51974..84a2a023f8 100644
--- a/phpBB/install/index.php
+++ b/phpBB/install/index.php
@@ -214,7 +214,7 @@ $config = new phpbb_config(array(
$phpbb_style_resource_locator = new phpbb_style_resource_locator();
$phpbb_style_path_provider = new phpbb_style_path_provider();
-$template = new phpbb_template($phpbb_root_path, $phpEx, $config, $user, $phpbb_style_resource_locator, 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/');
$phpbb_style->set_custom_style('admin', $phpbb_admin_path . 'style', array(), '');
diff --git a/phpBB/language/en/acp/common.php b/phpBB/language/en/acp/common.php
index e647485828..d128caca63 100644
--- a/phpBB/language/en/acp/common.php
+++ b/phpBB/language/en/acp/common.php
@@ -606,7 +606,7 @@ $lang = array_merge($lang, array(
'LOG_FORUM_MOVE_UP' => 'Moved forum %1$s above %2$s',
'LOG_FORUM_SYNC' => 'Re-synchronised forum» %s', - 'LOG_GENERAL_ERROR' => 'A general error occured: %1$s
» %2$s', + 'LOG_GENERAL_ERROR' => 'A general error occurred: %1$s
» %2$s', 'LOG_GROUP_CREATED' => 'New usergroup created
» %s', 'LOG_GROUP_DEFAULTS' => 'Group “%1$s” made default for members
» %2$s', diff --git a/phpBB/language/en/acp/posting.php b/phpBB/language/en/acp/posting.php index 89e171744f..ea3eadb0dd 100644 --- a/phpBB/language/en/acp/posting.php +++ b/phpBB/language/en/acp/posting.php @@ -83,7 +83,8 @@ $lang = array_merge($lang, array( 'NUMBER' => 'Any series of digits', 'EMAIL' => 'A valid email address', 'URL' => 'A valid URL using any protocol (http, ftp, etc… cannot be used for javascript exploits). If none is given, “http://” is prefixed to the string.', - 'LOCAL_URL' => 'A local URL. The URL must be relative to the topic page and cannot contain a server name or protocol.', + 'LOCAL_URL' => 'A local URL. The URL must be relative to the topic page and cannot contain a server name or protocol, as links are prefixed with “%s”', + 'RELATIVE_URL' => 'A relative URL. You can use this to match parts of a URL, but be careful: a full URL is a valid relative URL. When you want to use relative URLs of your board, use the LOCAL_URL token.', 'COLOR' => 'A HTML colour, can be either in the numeric form #FF1234 or a CSS colour keyword such as fuchsia or InactiveBorder' ) )); diff --git a/phpBB/language/en/common.php b/phpBB/language/en/common.php index 387ec96126..b188d90f3a 100644 --- a/phpBB/language/en/common.php +++ b/phpBB/language/en/common.php @@ -204,8 +204,8 @@ $lang = array_merge($lang, array( 'ERR_TEMPLATE_EVENT_LOCATION' => 'The specified template event location [%s] is improperly formatted.', 'ERR_TEMPLATE_COMPILATION' => 'The file could not be compiled: %s', 'ERR_UNABLE_TO_LOGIN' => 'The specified username or password is incorrect.', - 'ERR_UNWATCHING' => 'An error occured while trying to unsubscribe.', - 'ERR_WATCHING' => 'An error occured while trying to subscribe.', + 'ERR_UNWATCHING' => 'An error occurred while trying to unsubscribe.', + 'ERR_WATCHING' => 'An error occurred while trying to subscribe.', 'ERR_WRONG_PATH_TO_PHPBB' => 'The phpBB path specified appears to be invalid.', 'ERROR' => 'Error', 'EXPAND_VIEW' => 'Expand view', @@ -338,7 +338,7 @@ $lang = array_merge($lang, array( 'LAST_VISIT' => 'Last visit', 'LDAP_NO_LDAP_EXTENSION' => 'LDAP extension not available.', 'LDAP_NO_SERVER_CONNECTION' => 'Could not connect to LDAP server.', - 'LDAP_SEARCH_FAILED' => 'An error occured while searching the LDAP directory.', + 'LDAP_SEARCH_FAILED' => 'An error occurred while searching the LDAP directory.', 'LEGEND' => 'Legend', 'LOADING' => 'Loading', 'LOCATION' => 'Location', diff --git a/phpBB/language/en/install.php b/phpBB/language/en/install.php index 7607512eab..7b2a1138e9 100644 --- a/phpBB/language/en/install.php +++ b/phpBB/language/en/install.php @@ -364,7 +364,7 @@ $lang = array_merge($lang, array( 'UNAVAILABLE' => 'Unavailable', 'UNWRITABLE' => 'Unwritable', 'UPDATE_TOPICS_POSTED' => 'Generating topics posted information', - 'UPDATE_TOPICS_POSTED_ERR' => 'An error occured while generating topics posted information. You can retry this step in the ACP after the conversion process is completed.', + 'UPDATE_TOPICS_POSTED_ERR' => 'An error occurred while generating topics posted information. You can retry this step in the ACP after the conversion process is completed.', 'VERIFY_OPTIONS' => 'Verifying conversion options', 'VERSION' => 'Version', diff --git a/phpBB/language/en/migrator.php b/phpBB/language/en/migrator.php index f94c27be8c..34dcbf4c52 100644 --- a/phpBB/language/en/migrator.php +++ b/phpBB/language/en/migrator.php @@ -45,7 +45,7 @@ $lang = array_merge($lang, array( 'MIGRATION_NOT_FULFILLABLE' => 'The migration "%1$s" is not fulfillable, missing migration "%2$s".', 'MIGRATION_SCHEMA_DONE' => 'Installed Schema: %s', - 'MODULE_ERROR' => 'An error occured while creating a module: %s', + 'MODULE_ERROR' => 'An error occurred while creating a module: %s', 'MODULE_INFO_FILE_NOT_EXIST' => 'A required module info file is missing: %2$s', 'MODULE_NOT_EXIST' => 'A required module does not exist: %s', diff --git a/phpBB/styles/prosilver/template/memberlist_search.html b/phpBB/styles/prosilver/template/memberlist_search.html index a4468b4af4..4f029627fc 100644 --- a/phpBB/styles/prosilver/template/memberlist_search.html +++ b/phpBB/styles/prosilver/template/memberlist_search.html @@ -38,7 +38,7 @@ function insert_single(user) // ]]> - +