From 2050a39da793b9ed219beed868ec86ebade423f6 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Fri, 11 Oct 2013 17:40:16 +0200 Subject: [feature/plupload/integration] Integration of Plupload This commit is a highly-refactored and up-to-date version of Fyorl's work which was part of his Google Summer of Code 2012 project "Attachment Improvements". PHPBB3-10929 --- phpBB/includes/message_parser.php | 49 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) (limited to 'phpBB/includes/message_parser.php') diff --git a/phpBB/includes/message_parser.php b/phpBB/includes/message_parser.php index 3e348801c7..acd31fd519 100644 --- a/phpBB/includes/message_parser.php +++ b/phpBB/includes/message_parser.php @@ -1049,6 +1049,12 @@ class parse_message extends bbcode_firstpass var $mode; + /** + * The plupload object used for dealing with attachments + * @var \phpbb\plupload\plupload + */ + protected $plupload; + /** * Init - give message here or manually */ @@ -1440,6 +1446,11 @@ class parse_message extends bbcode_firstpass if ($preview || $refresh || sizeof($error)) { + if (isset($this->plupload) && $this->plupload->is_active()) + { + $json_response = new \phpbb\json_response(); + } + // Perform actions on temporary attachments if ($delete_file) { @@ -1484,13 +1495,17 @@ class parse_message extends bbcode_firstpass // Reindex Array $this->attachment_data = array_values($this->attachment_data); + if (isset($this->plupload) && $this->plupload->is_active()) + { + $json_response->send($this->attachment_data); + } } } else if (($add_file || $preview) && $upload_file) { if ($num_attachments < $cfg['max_attachments'] || $auth->acl_gets('m_', 'a_', $forum_id)) { - $filedata = upload_attachment($form_name, $forum_id, false, '', $is_message); + $filedata = upload_attachment($form_name, $forum_id, false, '', $is_message, false, $this->plupload); $error = array_merge($error, $filedata['error']); if (!sizeof($error)) @@ -1521,12 +1536,32 @@ class parse_message extends bbcode_firstpass $this->attachment_data = array_merge(array(0 => $new_entry), $this->attachment_data); $this->message = preg_replace('#\[attachment=([0-9]+)\](.*?)\[\/attachment\]#e', "'[attachment='.(\\1 + 1).']\\2[/attachment]'", $this->message); $this->filename_data['filecomment'] = ''; + + if (isset($this->plupload) && $this->plupload->is_active()) + { + // Send the client the attachment data to maintain state + $json_response->send($this->attachment_data); + } } } else { $error[] = $user->lang('TOO_MANY_ATTACHMENTS', (int) $cfg['max_attachments']); } + + if (!empty($error) && isset($this->plupload) && $this->plupload->is_active()) + { + // If this is a plupload (and thus ajax) request, give the + // client the first error we have + $json_response->send(array( + 'jsonrpc' => '2.0', + 'id' => 'id', + 'error' => array( + 'code' => 105, + 'message' => current($error), + ), + )); + } } } @@ -1687,4 +1722,16 @@ class parse_message extends bbcode_firstpass $poll['poll_max_options'] = ($poll['poll_max_options'] < 1) ? 1 : (($poll['poll_max_options'] > $config['max_poll_options']) ? $config['max_poll_options'] : $poll['poll_max_options']); } + + /** + * Setter function for passing the plupload object + * + * @param \phpbb\plupload\plupload $plupload The plupload object + * + * @return null + */ + public function set_plupload(\phpbb\plupload\plupload $plupload) + { + $this->plupload = $plupload; + } } -- cgit v1.2.1 From e179f25154d3098361bf079774a6dc92aeb4e4ab Mon Sep 17 00:00:00 2001 From: Matt Friedman Date: Wed, 4 Dec 2013 16:45:02 -0800 Subject: [ticket/12060] Add event core.modify_bbcode_init Use this event to modify the bbcode data for later parsing PHPBB3-12060 --- phpBB/includes/message_parser.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'phpBB/includes/message_parser.php') diff --git a/phpBB/includes/message_parser.php b/phpBB/includes/message_parser.php index acd31fd519..bce6321022 100644 --- a/phpBB/includes/message_parser.php +++ b/phpBB/includes/message_parser.php @@ -103,6 +103,8 @@ class bbcode_firstpass extends bbcode */ function bbcode_init($allow_custom_bbcode = true) { + global $phpbb_dispatcher; + static $rowset; // This array holds all bbcode data. BBCodes will be processed in this @@ -162,6 +164,21 @@ class bbcode_firstpass extends bbcode 'regexp' => array($row['first_pass_match'] => str_replace('$uid', $this->bbcode_uid, $row['first_pass_replace'])) ); } + + $bbcodes = $this->bbcodes; + + /** + * Use this event to modify the bbcode data for later parsing + * + * @event core.modify_bbcode_init + * @var array bbcodes The array of bbcode data for use in parsing + * @var array rowset The array of bbcode data from the database + * @since 3.1-A3 + */ + $vars = array('bbcodes', 'rowset'); + extract($phpbb_dispatcher->trigger_event('core.modify_bbcode_init', compact($vars))); + + $this->bbcodes = $bbcodes; } /** -- cgit v1.2.1 From feb4ae13f4415ceb759d0c5e8c7be47213e3fc53 Mon Sep 17 00:00:00 2001 From: Matt Friedman Date: Wed, 4 Dec 2013 16:45:30 -0800 Subject: [ticket/12060] Add event core.modify_text_for_format_display_after Use this event to modify the text after it is parsed PHPBB3-12060 --- phpBB/includes/message_parser.php | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'phpBB/includes/message_parser.php') diff --git a/phpBB/includes/message_parser.php b/phpBB/includes/message_parser.php index bce6321022..3e64f17a52 100644 --- a/phpBB/includes/message_parser.php +++ b/phpBB/includes/message_parser.php @@ -1215,6 +1215,8 @@ class parse_message extends bbcode_firstpass */ function format_display($allow_bbcode, $allow_magic_url, $allow_smilies, $update_this_message = true) { + global $phpbb_dispatcher; + // If false, then the parsed message get returned but internal message not processed. if (!$update_this_message) { @@ -1243,6 +1245,26 @@ class parse_message extends bbcode_firstpass $this->message = bbcode_nl2br($this->message); $this->message = smiley_text($this->message, !$allow_smilies); + $text = $this->message; + $uid = $this->bbcode_uid; + + /** + * Use this event to modify the text after it is parsed + * + * @event core.modify_text_for_format_display_after + * @var string text The text to parse + * @var string uid The BBCode UID + * @var bool allow_bbcode Allow BBCodes switch + * @var bool allow_magic_url Allow magic urls switch + * @var bool allow_smilies Allow smilies switch + * @since 3.1-A3 + */ + $vars = array('text', 'uid', 'allow_bbcode', 'allow_magic_url', 'allow_smilies'); + extract($phpbb_dispatcher->trigger_event('core.modify_text_for_format_display_after', compact($vars))); + + $this->message = $text; + $this->bbcode_uid = $uid; + if (!$update_this_message) { unset($this->message); -- cgit v1.2.1 From 0156136c85f474b44b4fcb84b52c5c13d6b2fae6 Mon Sep 17 00:00:00 2001 From: Matt Friedman Date: Thu, 12 Dec 2013 09:56:00 -0800 Subject: [ticket/12060] Add $update_this_message var to the core event PHPBB3-12060 --- phpBB/includes/message_parser.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/includes/message_parser.php') diff --git a/phpBB/includes/message_parser.php b/phpBB/includes/message_parser.php index 3e64f17a52..04fadf33e8 100644 --- a/phpBB/includes/message_parser.php +++ b/phpBB/includes/message_parser.php @@ -1259,7 +1259,7 @@ class parse_message extends bbcode_firstpass * @var bool allow_smilies Allow smilies switch * @since 3.1-A3 */ - $vars = array('text', 'uid', 'allow_bbcode', 'allow_magic_url', 'allow_smilies'); + $vars = array('text', 'uid', 'allow_bbcode', 'allow_magic_url', 'allow_smilies', 'update_this_message'); extract($phpbb_dispatcher->trigger_event('core.modify_text_for_format_display_after', compact($vars))); $this->message = $text; -- cgit v1.2.1 From b6eb1f66e169cd0cae3fc2c617588cb9e7c9c53b Mon Sep 17 00:00:00 2001 From: Matt Friedman Date: Thu, 12 Dec 2013 10:37:11 -0800 Subject: [ticket/12060] Update docblock for core event due to addition of another var PHPBB3-12060 --- phpBB/includes/message_parser.php | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'phpBB/includes/message_parser.php') diff --git a/phpBB/includes/message_parser.php b/phpBB/includes/message_parser.php index 04fadf33e8..5c543d8498 100644 --- a/phpBB/includes/message_parser.php +++ b/phpBB/includes/message_parser.php @@ -1252,11 +1252,12 @@ class parse_message extends bbcode_firstpass * Use this event to modify the text after it is parsed * * @event core.modify_text_for_format_display_after - * @var string text The text to parse - * @var string uid The BBCode UID - * @var bool allow_bbcode Allow BBCodes switch - * @var bool allow_magic_url Allow magic urls switch - * @var bool allow_smilies Allow smilies switch + * @var string text The text to parse + * @var string uid The BBCode UID + * @var bool allow_bbcode Allow BBCodes switch + * @var bool allow_magic_url Allow magic urls switch + * @var bool allow_smilies Allow smilies switch + * @var bool update_this_message Update message switch * @since 3.1-A3 */ $vars = array('text', 'uid', 'allow_bbcode', 'allow_magic_url', 'allow_smilies', 'update_this_message'); -- cgit v1.2.1 From 75831dc2d0bb79007db14d0c2a86cbb024d98a31 Mon Sep 17 00:00:00 2001 From: Matt Friedman Date: Thu, 12 Dec 2013 14:09:30 -0800 Subject: [ticket/12060] Change @since in event docblocks PHPBB3-12060 --- phpBB/includes/message_parser.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'phpBB/includes/message_parser.php') diff --git a/phpBB/includes/message_parser.php b/phpBB/includes/message_parser.php index 5c543d8498..096d39b9bb 100644 --- a/phpBB/includes/message_parser.php +++ b/phpBB/includes/message_parser.php @@ -173,7 +173,7 @@ class bbcode_firstpass extends bbcode * @event core.modify_bbcode_init * @var array bbcodes The array of bbcode data for use in parsing * @var array rowset The array of bbcode data from the database - * @since 3.1-A3 + * @since 3.1.0-A3 */ $vars = array('bbcodes', 'rowset'); extract($phpbb_dispatcher->trigger_event('core.modify_bbcode_init', compact($vars))); @@ -1258,7 +1258,7 @@ class parse_message extends bbcode_firstpass * @var bool allow_magic_url Allow magic urls switch * @var bool allow_smilies Allow smilies switch * @var bool update_this_message Update message switch - * @since 3.1-A3 + * @since 3.1.0-A3 */ $vars = array('text', 'uid', 'allow_bbcode', 'allow_magic_url', 'allow_smilies', 'update_this_message'); extract($phpbb_dispatcher->trigger_event('core.modify_text_for_format_display_after', compact($vars))); -- cgit v1.2.1 From b26e4dd42c434221acb488641a121e97307cb7dd Mon Sep 17 00:00:00 2001 From: Matt Friedman Date: Fri, 13 Dec 2013 10:31:04 -0800 Subject: [ticket/12060] Correctly label alpha versions in event docblocks PHPBB3-12060 --- phpBB/includes/message_parser.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'phpBB/includes/message_parser.php') diff --git a/phpBB/includes/message_parser.php b/phpBB/includes/message_parser.php index 096d39b9bb..893ef83381 100644 --- a/phpBB/includes/message_parser.php +++ b/phpBB/includes/message_parser.php @@ -173,7 +173,7 @@ class bbcode_firstpass extends bbcode * @event core.modify_bbcode_init * @var array bbcodes The array of bbcode data for use in parsing * @var array rowset The array of bbcode data from the database - * @since 3.1.0-A3 + * @since 3.1.0-a3 */ $vars = array('bbcodes', 'rowset'); extract($phpbb_dispatcher->trigger_event('core.modify_bbcode_init', compact($vars))); @@ -1258,7 +1258,7 @@ class parse_message extends bbcode_firstpass * @var bool allow_magic_url Allow magic urls switch * @var bool allow_smilies Allow smilies switch * @var bool update_this_message Update message switch - * @since 3.1.0-A3 + * @since 3.1.0-a3 */ $vars = array('text', 'uid', 'allow_bbcode', 'allow_magic_url', 'allow_smilies', 'update_this_message'); extract($phpbb_dispatcher->trigger_event('core.modify_text_for_format_display_after', compact($vars))); -- cgit v1.2.1 From f0454586795de85cf1b66b6f927d18d3e9466305 Mon Sep 17 00:00:00 2001 From: Matt Friedman Date: Fri, 13 Dec 2013 17:00:06 -0800 Subject: [ticket/12060] Rename event in message parser to modify_format_display_text_after PHPBB3-12060 --- phpBB/includes/message_parser.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'phpBB/includes/message_parser.php') diff --git a/phpBB/includes/message_parser.php b/phpBB/includes/message_parser.php index 893ef83381..c1229d9c77 100644 --- a/phpBB/includes/message_parser.php +++ b/phpBB/includes/message_parser.php @@ -1251,7 +1251,7 @@ class parse_message extends bbcode_firstpass /** * Use this event to modify the text after it is parsed * - * @event core.modify_text_for_format_display_after + * @event core.modify_format_display_text_after * @var string text The text to parse * @var string uid The BBCode UID * @var bool allow_bbcode Allow BBCodes switch @@ -1261,7 +1261,7 @@ class parse_message extends bbcode_firstpass * @since 3.1.0-a3 */ $vars = array('text', 'uid', 'allow_bbcode', 'allow_magic_url', 'allow_smilies', 'update_this_message'); - extract($phpbb_dispatcher->trigger_event('core.modify_text_for_format_display_after', compact($vars))); + extract($phpbb_dispatcher->trigger_event('core.modify_format_display_text_after', compact($vars))); $this->message = $text; $this->bbcode_uid = $uid; -- cgit v1.2.1 From df9e782fa44f72861896b763906e26ba36e4a31f Mon Sep 17 00:00:00 2001 From: Matt Friedman Date: Mon, 16 Dec 2013 15:31:44 -0800 Subject: [ticket/12060] Remove whitespaces PHPBB3-12060 --- phpBB/includes/message_parser.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/includes/message_parser.php') diff --git a/phpBB/includes/message_parser.php b/phpBB/includes/message_parser.php index c1229d9c77..56abaae998 100644 --- a/phpBB/includes/message_parser.php +++ b/phpBB/includes/message_parser.php @@ -1216,7 +1216,7 @@ class parse_message extends bbcode_firstpass function format_display($allow_bbcode, $allow_magic_url, $allow_smilies, $update_this_message = true) { global $phpbb_dispatcher; - + // If false, then the parsed message get returned but internal message not processed. if (!$update_this_message) { -- cgit v1.2.1 From 4665e3df216de474e73c5aeec56ec5cb30f280c9 Mon Sep 17 00:00:00 2001 From: Matt Friedman Date: Mon, 16 Dec 2013 23:54:55 -0800 Subject: [ticket/12060] Further clarifying new event docblocks as much as possible PHPBB3-12060 --- phpBB/includes/message_parser.php | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'phpBB/includes/message_parser.php') diff --git a/phpBB/includes/message_parser.php b/phpBB/includes/message_parser.php index 56abaae998..080c755965 100644 --- a/phpBB/includes/message_parser.php +++ b/phpBB/includes/message_parser.php @@ -1252,12 +1252,13 @@ class parse_message extends bbcode_firstpass * Use this event to modify the text after it is parsed * * @event core.modify_format_display_text_after - * @var string text The text to parse - * @var string uid The BBCode UID - * @var bool allow_bbcode Allow BBCodes switch - * @var bool allow_magic_url Allow magic urls switch - * @var bool allow_smilies Allow smilies switch - * @var bool update_this_message Update message switch + * @var string text The message text to parse + * @var string uid The bbcode uid + * @var bool allow_bbcode Do we allow bbcodes + * @var bool allow_magic_url Do we allow magic urls + * @var bool allow_smilies Do we allow smilies + * @var bool update_this_message Do we update the internal message + * with the parsed result * @since 3.1.0-a3 */ $vars = array('text', 'uid', 'allow_bbcode', 'allow_magic_url', 'allow_smilies', 'update_this_message'); -- cgit v1.2.1 From 121f2394ff92c7497f2f2a11913d02570695e8e4 Mon Sep 17 00:00:00 2001 From: Matt Friedman Date: Tue, 17 Dec 2013 18:55:59 -0800 Subject: [ticket/12060] A little less verbose cleanup of event docblocks PHPBB3-12060 --- phpBB/includes/message_parser.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'phpBB/includes/message_parser.php') diff --git a/phpBB/includes/message_parser.php b/phpBB/includes/message_parser.php index 080c755965..b29f587385 100644 --- a/phpBB/includes/message_parser.php +++ b/phpBB/includes/message_parser.php @@ -168,11 +168,11 @@ class bbcode_firstpass extends bbcode $bbcodes = $this->bbcodes; /** - * Use this event to modify the bbcode data for later parsing + * Event to modify the bbcode data for later parsing * * @event core.modify_bbcode_init - * @var array bbcodes The array of bbcode data for use in parsing - * @var array rowset The array of bbcode data from the database + * @var array bbcodes Array of bbcode data for use in parsing + * @var array rowset Array of bbcode data from the database * @since 3.1.0-a3 */ $vars = array('bbcodes', 'rowset'); @@ -1249,7 +1249,7 @@ class parse_message extends bbcode_firstpass $uid = $this->bbcode_uid; /** - * Use this event to modify the text after it is parsed + * Event to modify the text after it is parsed * * @event core.modify_format_display_text_after * @var string text The message text to parse -- cgit v1.2.1