aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoas Schilling <nickvergessen@gmx.de>2014-04-20 14:15:54 +0200
committerJoas Schilling <nickvergessen@gmx.de>2014-04-20 14:15:54 +0200
commit8ddc9ff185527128d74b618107edde2f57637dde (patch)
treee252fa5d9659901c07a5feb2c6d8e780a10f8cba
parent1a913d6e0f9f1e0f5df2acbfdc5a5f43a0c83be0 (diff)
downloadforums-8ddc9ff185527128d74b618107edde2f57637dde.tar
forums-8ddc9ff185527128d74b618107edde2f57637dde.tar.gz
forums-8ddc9ff185527128d74b618107edde2f57637dde.tar.bz2
forums-8ddc9ff185527128d74b618107edde2f57637dde.tar.xz
forums-8ddc9ff185527128d74b618107edde2f57637dde.zip
[ticket/12273] Allow multiple $vars lines
PHPBB3-12273
-rw-r--r--phpBB/phpbb/event/php_exporter.php36
-rw-r--r--tests/event/fixtures/duplicate_event.test9
-rw-r--r--tests/event/fixtures/trigger.test5
-rw-r--r--tests/event/fixtures/trigger_many_vars.test45
-rw-r--r--tests/event/php_exporter_test.php37
5 files changed, 106 insertions, 26 deletions
diff --git a/phpBB/phpbb/event/php_exporter.php b/phpBB/phpbb/event/php_exporter.php
index eb9e8f72b3..9044168980 100644
--- a/phpBB/phpbb/event/php_exporter.php
+++ b/phpBB/phpbb/event/php_exporter.php
@@ -302,25 +302,43 @@ class php_exporter
*/
public function get_vars_from_array()
{
- $vars_line = ltrim($this->file_lines[$this->current_event_line - 1], "\t");
- if (strpos($vars_line, "\$vars = array('") !== 0 || substr($vars_line, -3) !== '\');')
+ $vars_array_line = 1;
+ $found_vars_array = false;
+ $vars_array = array();
+ while (ltrim($this->file_lines[$this->current_event_line - $vars_array_line], "\t") !== '*/')
{
- throw new \LogicException('Can not find "$vars = array();"-line for event "' . $this->current_event . '" in file "' . $this->current_file . '"', 1);
+ $line = ltrim($this->file_lines[$this->current_event_line - $vars_array_line], "\t");
+ $match = array();
+ preg_match('#^\$vars (?:\+)?= array\(\'([a-zA-Z0-9_\' ,]+)\'\);$#', $line, $match);
+
+ if (isset($match[1]))
+ {
+ $found_vars_array = true;
+ if (strlen($match[1]) > 90)
+ {
+ throw new \LogicException('Should use multiple lines for $vars definition'
+ . ' for event "' . $this->current_event . '" in file "' . $this->current_file . '"', 1);
+ }
+ $vars_array = array_merge($vars_array, explode("', '", $match[1]));
+ }
+
+ $vars_array_line++;
+ if ($this->current_event_line - $vars_array_line === 0)
+ {
+ throw new \LogicException('Can not find "$vars = array();"-line for event "' . $this->current_event . '" in file "' . $this->current_file . '"', 2);
+ }
}
- $vars_array = substr($vars_line, strlen("\$vars = array('"), 0 - strlen('\');'));
- if ($vars_array === '')
+ if (!$found_vars_array)
{
- throw new \LogicException('Found empty $vars array for event "' . $this->current_event . '" in file "' . $this->current_file . '"', 2);
+ throw new \LogicException('Can not find "$vars = array();"-line for event "' . $this->current_event . '" in file "' . $this->current_file . '"', 3);
}
- $vars_array = explode("', '", $vars_array);
-
foreach ($vars_array as $var)
{
if (!preg_match('#^([a-zA-Z_][a-zA-Z0-9_]*)$#', $var))
{
- throw new \LogicException('Found invalid var "' . $var . '" in array for event "' . $this->current_event . '" in file "' . $this->current_file . '"', 3);
+ throw new \LogicException('Found invalid var "' . $var . '" in array for event "' . $this->current_event . '" in file "' . $this->current_file . '"', 4);
}
}
diff --git a/tests/event/fixtures/duplicate_event.test b/tests/event/fixtures/duplicate_event.test
index f5fa580c2b..b042ca0377 100644
--- a/tests/event/fixtures/duplicate_event.test
+++ b/tests/event/fixtures/duplicate_event.test
@@ -5,16 +5,9 @@
*
* @event duplicate.trigger
* @var int start Start item of this page
- * @var int current_row_number Number of the post on this page
- * @var int end Number of posts on this page
- * @var array row Array with original post and user data
- * @var array cp_row Custom profile field data of the poster
- * @var array attachments List of attachments
- * @var array user_poster_data Poster's data from user cache
- * @var array post_row Template block array of the post
* @since 3.1.0-a3
*/
- $vars = array('start', 'current_row_number', 'end', 'row', 'cp_row', 'attachments', 'user_poster_data', 'post_row');
+ $vars = array('start');
extract($phpbb_dispatcher->trigger_event('duplicate.trigger', compact($vars)));
/**
diff --git a/tests/event/fixtures/trigger.test b/tests/event/fixtures/trigger.test
index 9df6e5b386..7cd6a7b956 100644
--- a/tests/event/fixtures/trigger.test
+++ b/tests/event/fixtures/trigger.test
@@ -9,10 +9,7 @@
* @var int end Number of posts on this page
* @var array row Array with original post and user data
* @var array cp_row Custom profile field data of the poster
- * @var array attachments List of attachments
- * @var array user_poster_data Poster's data from user cache
- * @var array post_row Template block array of the post
* @since 3.1.0-a3
*/
- $vars = array('start', 'current_row_number', 'end', 'row', 'cp_row', 'attachments', 'user_poster_data', 'post_row');
+ $vars = array('start', 'current_row_number', 'end', 'row', 'cp_row');
extract($phpbb_dispatcher->trigger_event('core.trigger', compact($vars)));
diff --git a/tests/event/fixtures/trigger_many_vars.test b/tests/event/fixtures/trigger_many_vars.test
new file mode 100644
index 0000000000..79f121cd7b
--- /dev/null
+++ b/tests/event/fixtures/trigger_many_vars.test
@@ -0,0 +1,45 @@
+<?php
+
+ /**
+ * This event allows you to modify template variables for the posting screen
+ *
+ * @event core.posting_modify_template_vars
+ * @var array post_data Array with post data
+ * @var array moderators Array with forum moderators
+ * @var string mode What action to take if the form is submitted
+ * post|reply|quote|edit|delete|bump|smilies|popup
+ * @var string page_title Title of the mode page
+ * @var bool s_topic_icons Whether or not to show the topic icons
+ * @var string form_enctype If attachments are allowed for this form
+ * "multipart/form-data" or empty string
+ * @var string s_action The URL to submit the POST data to
+ * @var string s_hidden_fields Concatenated hidden input tags of posting form
+ * @var int post_id ID of the post
+ * @var int topic_id ID of the topic
+ * @var int forum_id ID of the forum
+ * @var bool submit Whether or not the form has been submitted
+ * @var bool preview Whether or not the post is being previewed
+ * @var bool save Whether or not a draft is being saved
+ * @var bool load Whether or not a draft is being loaded
+ * @var bool delete Whether or not the post is being deleted
+ * @var bool cancel Whether or not to cancel the form (returns to
+ * viewtopic or viewforum depending on if the user
+ * is posting a new topic or editing a post)
+ * @var array error Any error strings; a non-empty array aborts
+ * form submission.
+ * NOTE: Should be actual language strings, NOT
+ * language keys.
+ * @var bool refresh Whether or not to retain previously submitted data
+ * @var array page_data Posting page data that should be passed to the
+ * posting page via $template->assign_vars()
+ * @var object message_parser The message parser object
+ * @since 3.1-A1
+ * @change 3.1.0-b3 Added vars post_data, moderators, mode, page_title,
+ * s_topic_icons, form_enctype, s_action, s_hidden_fields,
+ * post_id, topic_id, forum_id, submit, preview, save, load,
+ * delete, cancel, refresh, error, page_data, message_parser
+ */
+ $vars = array('post_data', 'moderators', 'mode', 'page_title', 's_topic_icons', 'form_enctype');
+ $vars += array('s_action', 's_hidden_fields', 'post_id', 'topic_id', 'forum_id', 'submit', 'preview');
+ $vars += array('save', 'load', 'delete', 'cancel', 'refresh', 'error', 'page_data', 'message_parser');
+ extract($phpbb_dispatcher->trigger_event('core.posting_modify_template_vars', compact($vars)));
diff --git a/tests/event/php_exporter_test.php b/tests/event/php_exporter_test.php
index 2a23d1a6c1..fca7698c71 100644
--- a/tests/event/php_exporter_test.php
+++ b/tests/event/php_exporter_test.php
@@ -51,13 +51,31 @@ class phpbb_event_php_exporter_test extends phpbb_test_case
'core.trigger' => array(
'event' => 'core.trigger',
'file' => 'trigger.test',
- 'arguments' => array('attachments', 'cp_row', 'current_row_number', 'end', 'post_row', 'row', 'start', 'user_poster_data'),
+ 'arguments' => array('cp_row', 'current_row_number', 'end', 'row', 'start'),
'since' => '3.1.0-a3',
'description' => 'Event after the post data has been assigned to the template',
),
),
),
array(
+ 'trigger_many_vars.test',
+ array(
+ 'core.posting_modify_template_vars' => array(
+ 'event' => 'core.posting_modify_template_vars',
+ 'file' => 'trigger_many_vars.test',
+ 'arguments' => array(
+ 'cancel', 'delete', 'error', 'form_enctype', 'forum_id',
+ 'load', 'message_parser', 'mode', 'moderators', 'page_data',
+ 'page_title', 'post_data', 'post_id', 'preview', 'refresh',
+ 's_action', 's_hidden_fields', 's_topic_icons', 'save',
+ 'submit', 'topic_id',
+ ),
+ 'since' => '3.1.0-a1',
+ 'description' => 'This event allows you to modify template variables for the posting screen',
+ ),
+ ),
+ ),
+ array(
'none.test',
array(),
),
@@ -321,11 +339,20 @@ class phpbb_event_php_exporter_test extends phpbb_test_case
array(
'/**',
'*/',
+ '$phpbb_dispatcher->dispatch(\'test\');',
+ ),
+ 2,
+ 3,
+ ),
+ array(
+ array(
+ '/**',
+ '*/',
'$vars = $bertie;',
'$phpbb_dispatcher->dispatch(\'test\');',
),
3,
- 1,
+ 3,
),
array(
array(
@@ -335,17 +362,17 @@ class phpbb_event_php_exporter_test extends phpbb_test_case
'$phpbb_dispatcher->dispatch(\'test\');',
),
3,
- 1,
+ 3,
),
array(
array(
'/**',
'*/',
- '$vars = array(\'\');',
+ '$vars = array(\'test2\', \'\');',
'$phpbb_dispatcher->dispatch(\'test\');',
),
3,
- 2,
+ 4,
),
array(
array(