Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

[Ticket/10845] Reported post text was not parsing BBCode #786

Merged
merged 5 commits into from over 1 year ago

7 participants

brunoais Don't Add Me To Your Organization a.k.a The Travis Bot David King Jakub Senko Joas Schilling Oleg Pudeyev Callum Macrae
brunoais

This fixes the BBCode not being parsed by saving the post's bitfield and uid in the database to be retrieved while reading the saved post.
While viewing the report, the preview post is now parsed by the BBCode system and shows exactly like a user would see except still the text is not censored.

added some commits April 26, 2012
brunoais [ticket/10845] Changed the report system. Now it saves posts with the…
… bbcode

Now the bitfield and uid of the bbcode is saved in the reports table.
This will allow parsing the BBCode while loading the post to show

PHPBB3-10845
f3e5acf
brunoais [ticket/10845] Now it shows the preview post parsed
With this addition, the preview post in the report details now shows with the
BBCode parsed.

Note: Tested with all BBCodes I have including one personalised to write the <s>
BBCode.

PHPBB3-10845
06f4ef8
phpBB/includes/mcp/mcp_reports.php
@@ -227,7 +227,7 @@ function main($id, $mode)
227 227
 					'REPORTER_NAME'				=> get_username_string('username', $report['user_id'], $report['username'], $report['user_colour']),
228 228
 					'U_VIEW_REPORTER_PROFILE'	=> get_username_string('profile', $report['user_id'], $report['username'], $report['user_colour']),
229 229
 
230  
-					'POST_PREVIEW'			=> bbcode_nl2br($report['reported_post_text']),
  230
+					'POST_PREVIEW'			=> bbcode_nl2br(generate_text_for_display($report['reported_post_text'], $report['reported_post_uid'], $report['reported_post_bitfield'], OPTION_FLAG_BBCODE + OPTION_FLAG_SMILIES + OPTION_FLAG_LINKS)),
2
Joas Schilling Collaborator

doesnt generate_text_for_display() do the bbcode_nl2br() ?

brunoais
brunoais added a note May 02, 2012

Please use a complete sentence I didn't understand (explained that generate_text_for_display() already applies bbcode_nl2br in IRC).

Fixed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
brunoais [ticket/10845] Remove censor from text
In order to remove the censor, I added a new parameter to
generate_text_for_display(), that new parameter is used to tell if the text
should be censored or not. Defaults to true.

PHPBB3-10845
593ef78
brunoais

Ups. There's one thing missing here.
I forgot to register the changes to the DB in the DB update files. Will do in some minutes

brunoais [ticket/10845] Two of the three colouns were missing in the DB update…
… file

Added the two colouns that were missing in the DB update file

PHPBB3-10845
6069d9a
Don't Add Me To Your Organization a.k.a The Travis Bot

This pull request fails (merged 6069d9a into beda22c).

Callum Macrae callumacrae commented on the diff May 16, 2012
phpBB/develop/create_schema_files.php
((9 lines not shown))
1527  
-			'user_notify'			=> array('BOOL', 0),
1528  
-			'report_closed'			=> array('BOOL', 0),
1529  
-			'report_time'			=> array('TIMESTAMP', 0),
1530  
-			'report_text'			=> array('MTEXT_UNI', ''),
1531  
-			'reported_post_text'	=> array('MTEXT_UNI', ''),
  1522
+			'report_id'					=> array('UINT', NULL, 'auto_increment'),
  1523
+			'reason_id'					=> array('USINT', 0),
  1524
+			'post_id'					=> array('UINT', 0),
  1525
+			'pm_id'						=> array('UINT', 0),
  1526
+			'user_id'					=> array('UINT', 0),
  1527
+			'user_notify'				=> array('BOOL', 0),
  1528
+			'report_closed'				=> array('BOOL', 0),
  1529
+			'report_time'				=> array('TIMESTAMP', 0),
  1530
+			'report_text'				=> array('MTEXT_UNI', ''),
  1531
+			'reported_post_text'		=> array('MTEXT_UNI', ''),
  1532
+			'reported_post_uid'			=> array('VCHAR:8', ''),
2
Callum Macrae
callumacrae added a note May 16, 2012

Not sure what's happening here, but there should only be three additions.

brunoais
brunoais added a note May 16, 2012

Count the number of whitespace characters.
In order to have the => aligned, all of them require a new tab.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
David King imkingdavid commented on the diff June 01, 2012
phpBB/includes/mcp/mcp_reports.php
@@ -227,7 +227,7 @@ function main($id, $mode)
227 227
 					'REPORTER_NAME'				=> get_username_string('username', $report['user_id'], $report['username'], $report['user_colour']),
228 228
 					'U_VIEW_REPORTER_PROFILE'	=> get_username_string('profile', $report['user_id'], $report['username'], $report['user_colour']),
229 229
 
230  
-					'POST_PREVIEW'			=> bbcode_nl2br($report['reported_post_text']),
  230
+					'POST_PREVIEW'			=> generate_text_for_display($report['reported_post_text'], $report['reported_post_uid'], $report['reported_post_bitfield'], OPTION_FLAG_BBCODE | OPTION_FLAG_SMILIES, false),
7
David King Collaborator
imkingdavid added a note June 01, 2012

Why are only BBCode and Smilies allowed, shouldn't it also parse magic urls?

brunoais
brunoais added a note June 02, 2012

I don't know. I'm ok with both (the current and with magic urls).

David King Collaborator
imkingdavid added a note June 02, 2012

IMO, all three should be parsed. Also, aren't you supposed to add the flags together when passing them to generate_text_for_display, rather than using bitwise OR? (i.e. OPTION_FLAG_BBCODE + OPTION_FLAG_SMILIES)

brunoais
brunoais added a note June 03, 2012

That: OPTION_FLAG_BBCODE + OPTION_FLAG_SMILIES
Is only equivalent to:
OPTION_FLAG_BBCODE | OPTION_FLAG_SMILIES
because there don't have not shared bits.
I.e.
OPTION_FLAG_BBCODE = 001
OPTION_FLAG_SMILIES = 010
OPTION_FLAG_LINKS = 100

The bitwise OR is the standard(?) (at least the most logical to me and what's teached). I don't know about the specifics and which one is faster but the bitwise OR is what makes more sense to me. If there's something in the coding guidelines that I missed, I'll fix it.

David King Collaborator
imkingdavid added a note June 03, 2012
brunoais
brunoais added a note June 03, 2012
Joas Schilling Collaborator

In posts table we have 3 columns for this (enable_bbcodes, *_smilies, *_urls) which should be copied and used here aswell, otherwise the post is still not the same as it is in the viewtopic view.

However I guess you can combine them to one "reported_post_text_options" field

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
phpBB/report.php
@@ -150,16 +154,19 @@
150 154
 		trigger_error('EMPTY_REPORT');
151 155
 	}
152 156
 
  157
+
2
David King Collaborator
imkingdavid added a note June 14, 2012

There should not be a new line added here.

brunoais
brunoais added a note June 14, 2012

Hum... You're right... I wonder why that got there...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
David King
Collaborator

Other than the comment on the newline, I would like someone else to provide input on the question I had about whether or not to parse magic url (IMO it should be parsed), and then this should be ready for merge.

brunoais [ticket/10845] Removed one empty line that wasn't supposed to be there
I onder when it got there... Maybe a wrong rebase... Don't really know.

PHPBB3-10845
27775e8
Don't Add Me To Your Organization a.k.a The Travis Bot

This pull request passes (merged 27775e8 into beda22c).

brunoais

I'm still waiting for feedback here...
Feedback please!

Jakub Senko

Yes, please, include magic urls!

Another idea comes to my mind: if DB is being updated, 2 new columns are added to REPORTS_TABLE, but they will stay empty for all already existing reports, do not they? Do not we need to fill them while updating database?

Joas Schilling
Collaborator

I think updating all of them is not needed. That might be a rather huge task for little purpose

Joas Schilling
Collaborator

Regarding magic urls, they should be parsed, if they are parsed in the actual post.

Oleg Pudeyev
p commented November 06, 2012

http://tracker.phpbb.com/browse/PHPBB3-11170, I only now realized this is a bug.

Oleg Pudeyev p referenced this pull request from a commit in p/phpbb3 November 06, 2012
Oleg Pudeyev Merge PR #786 branch 'brunoais/ticket/10845' into develop
* brunoais/ticket/10845:
  [ticket/10845] Removed one empty line that wasn't supposed to be there
  [ticket/10845] Two of the three colouns were missing in the DB update file
  [ticket/10845] Remove censor from text
  [ticket/10845] Now it shows the preview post parsed
  [ticket/10845] Changed the report system. Now it saves posts with the bbcode

Conflicts:
	phpBB/includes/functions_content.php
196ed8e
Oleg Pudeyev p merged commit 27775e8 into from November 06, 2012
Oleg Pudeyev p closed this November 06, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 5 unique commits by 1 author.

May 01, 2012
brunoais [ticket/10845] Changed the report system. Now it saves posts with the…
… bbcode

Now the bitfield and uid of the bbcode is saved in the reports table.
This will allow parsing the BBCode while loading the post to show

PHPBB3-10845
f3e5acf
brunoais [ticket/10845] Now it shows the preview post parsed
With this addition, the preview post in the report details now shows with the
BBCode parsed.

Note: Tested with all BBCodes I have including one personalised to write the <s>
BBCode.

PHPBB3-10845
06f4ef8
May 02, 2012
brunoais [ticket/10845] Remove censor from text
In order to remove the censor, I added a new parameter to
generate_text_for_display(), that new parameter is used to tell if the text
should be censored or not. Defaults to true.

PHPBB3-10845
593ef78
May 06, 2012
brunoais [ticket/10845] Two of the three colouns were missing in the DB update…
… file

Added the two colouns that were missing in the DB update file

PHPBB3-10845
6069d9a
Jun 14, 2012
brunoais [ticket/10845] Removed one empty line that wasn't supposed to be there
I onder when it got there... Maybe a wrong rebase... Don't really know.

PHPBB3-10845
27775e8
This page is out of date. Refresh to see the latest.
22  phpBB/develop/create_schema_files.php
@@ -1519,16 +1519,18 @@ function get_schema_struct()
1519 1519
 
1520 1520
 	$schema_data['phpbb_reports'] = array(
1521 1521
 		'COLUMNS'		=> array(
1522  
-			'report_id'				=> array('UINT', NULL, 'auto_increment'),
1523  
-			'reason_id'				=> array('USINT', 0),
1524  
-			'post_id'				=> array('UINT', 0),
1525  
-			'pm_id'					=> array('UINT', 0),
1526  
-			'user_id'				=> array('UINT', 0),
1527  
-			'user_notify'			=> array('BOOL', 0),
1528  
-			'report_closed'			=> array('BOOL', 0),
1529  
-			'report_time'			=> array('TIMESTAMP', 0),
1530  
-			'report_text'			=> array('MTEXT_UNI', ''),
1531  
-			'reported_post_text'	=> array('MTEXT_UNI', ''),
  1522
+			'report_id'					=> array('UINT', NULL, 'auto_increment'),
  1523
+			'reason_id'					=> array('USINT', 0),
  1524
+			'post_id'					=> array('UINT', 0),
  1525
+			'pm_id'						=> array('UINT', 0),
  1526
+			'user_id'					=> array('UINT', 0),
  1527
+			'user_notify'				=> array('BOOL', 0),
  1528
+			'report_closed'				=> array('BOOL', 0),
  1529
+			'report_time'				=> array('TIMESTAMP', 0),
  1530
+			'report_text'				=> array('MTEXT_UNI', ''),
  1531
+			'reported_post_text'		=> array('MTEXT_UNI', ''),
  1532
+			'reported_post_uid'			=> array('VCHAR:8', ''),
  1533
+			'reported_post_bitfield'	=> array('VCHAR:255', ''),
1532 1534
 		),
1533 1535
 		'PRIMARY_KEY'	=> 'report_id',
1534 1536
 		'KEYS'			=> array(
7  phpBB/includes/functions_content.php
@@ -408,7 +408,7 @@ function strip_bbcode(&$text, $uid = '')
408 408
 * For display of custom parsed text on user-facing pages
409 409
 * Expects $text to be the value directly from the database (stored value)
410 410
 */
411  
-function generate_text_for_display($text, $uid, $bitfield, $flags)
  411
+function generate_text_for_display($text, $uid, $bitfield, $flags, $censor_text = true)
412 412
 {
413 413
 	static $bbcode;
414 414
 
@@ -417,7 +417,10 @@ function generate_text_for_display($text, $uid, $bitfield, $flags)
417 417
 		return '';
418 418
 	}
419 419
 
420  
-	$text = censor_text($text);
  420
+	if ($censor_text)
  421
+	{
  422
+		$text = censor_text($text);
  423
+	}
421 424
 
422 425
 	// Parse bbcode if bbcode uid stored and bbcode enabled
423 426
 	if ($uid && ($flags & OPTION_FLAG_BBCODE))
4  phpBB/includes/mcp/mcp_reports.php
@@ -71,7 +71,7 @@ function main($id, $mode)
71 71
 				// closed reports are accessed by report id
72 72
 				$report_id = request_var('r', 0);
73 73
 
74  
-				$sql = 'SELECT r.post_id, r.user_id, r.report_id, r.report_closed, report_time, r.report_text, r.reported_post_text, rr.reason_title, rr.reason_description, u.username, u.username_clean, u.user_colour
  74
+				$sql = 'SELECT r.post_id, r.user_id, r.report_id, r.report_closed, report_time, r.report_text, r.reported_post_text, r.reported_post_uid, r.reported_post_bitfield, rr.reason_title, rr.reason_description, u.username, u.username_clean, u.user_colour
75 75
 					FROM ' . REPORTS_TABLE . ' r, ' . REPORTS_REASONS_TABLE . ' rr, ' . USERS_TABLE . ' u
76 76
 					WHERE ' . (($report_id) ? 'r.report_id = ' . $report_id : "r.post_id = $post_id") . '
77 77
 						AND rr.reason_id = r.reason_id
@@ -227,7 +227,7 @@ function main($id, $mode)
227 227
 					'REPORTER_NAME'				=> get_username_string('username', $report['user_id'], $report['username'], $report['user_colour']),
228 228
 					'U_VIEW_REPORTER_PROFILE'	=> get_username_string('profile', $report['user_id'], $report['username'], $report['user_colour']),
229 229
 
230  
-					'POST_PREVIEW'			=> bbcode_nl2br($report['reported_post_text']),
  230
+					'POST_PREVIEW'			=> generate_text_for_display($report['reported_post_text'], $report['reported_post_uid'], $report['reported_post_bitfield'], OPTION_FLAG_BBCODE | OPTION_FLAG_SMILIES, false),
231 231
 					'POST_SUBJECT'			=> ($post_info['post_subject']) ? $post_info['post_subject'] : $user->lang['NO_SUBJECT'],
232 232
 					'POST_DATE'				=> $user->format_date($post_info['post_time']),
233 233
 					'POST_IP'				=> $post_info['poster_ip'],
4  phpBB/install/database_update.php
@@ -1102,7 +1102,9 @@ function database_update_info()
1102 1102
 					'style_parent_tree'		=> array('TEXT', ''),
1103 1103
 				),
1104 1104
 				REPORTS_TABLE		=> array(
1105  
-					'reported_post_text'	=> array('MTEXT_UNI', ''),
  1105
+					'reported_post_text'		=> array('MTEXT_UNI', ''),
  1106
+					'reported_post_uid'			=> array('VCHAR:8', ''),
  1107
+					'reported_post_bitfield'	=> array('VCHAR:255', ''),
1106 1108
 				),
1107 1109
 			),
1108 1110
 			'change_columns'	=> array(
4  phpBB/install/schemas/firebird_schema.sql
@@ -910,7 +910,9 @@ CREATE TABLE phpbb_reports (
910 910
 	report_closed INTEGER DEFAULT 0 NOT NULL,
911 911
 	report_time INTEGER DEFAULT 0 NOT NULL,
912 912
 	report_text BLOB SUB_TYPE TEXT CHARACTER SET UTF8 DEFAULT '' NOT NULL,
913  
-	reported_post_text BLOB SUB_TYPE TEXT CHARACTER SET UTF8 DEFAULT '' NOT NULL
  913
+	reported_post_text BLOB SUB_TYPE TEXT CHARACTER SET UTF8 DEFAULT '' NOT NULL,
  914
+	reported_post_bitfield VARCHAR(255) CHARACTER SET NONE DEFAULT '' NOT NULL,
  915
+	reported_post_uid VARCHAR(8) CHARACTER SET NONE DEFAULT '' NOT NULL
914 916
 );;
915 917
 
916 918
 ALTER TABLE phpbb_reports ADD PRIMARY KEY (report_id);;
4  phpBB/install/schemas/mssql_schema.sql
@@ -1109,7 +1109,9 @@ CREATE TABLE [phpbb_reports] (
1109 1109
 	[report_closed] [int] DEFAULT (0) NOT NULL ,
1110 1110
 	[report_time] [int] DEFAULT (0) NOT NULL ,
1111 1111
 	[report_text] [text] DEFAULT ('') NOT NULL ,
1112  
-	[reported_post_text] [text] DEFAULT ('') NOT NULL
  1112
+	[reported_post_text] [text] DEFAULT ('') NOT NULL ,
  1113
+	[reported_post_bitfield] [varchar] (255) DEFAULT ('') NOT NULL ,
  1114
+	[reported_post_uid] [varchar] (8) DEFAULT ('') NOT NULL 
1113 1115
 ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
1114 1116
 GO
1115 1117
 
2  phpBB/install/schemas/mysql_40_schema.sql
@@ -648,6 +648,8 @@ CREATE TABLE phpbb_reports (
648 648
 	report_time int(11) UNSIGNED DEFAULT '0' NOT NULL,
649 649
 	report_text mediumblob NOT NULL,
650 650
 	reported_post_text mediumblob NOT NULL,
  651
+	reported_post_bitfield varbinary(255) DEFAULT '' NOT NULL,
  652
+	reported_post_uid varbinary(8) DEFAULT '' NOT NULL,
651 653
 	PRIMARY KEY (report_id),
652 654
 	KEY post_id (post_id),
653 655
 	KEY pm_id (pm_id)
2  phpBB/install/schemas/mysql_41_schema.sql
@@ -648,6 +648,8 @@ CREATE TABLE phpbb_reports (
648 648
 	report_time int(11) UNSIGNED DEFAULT '0' NOT NULL,
649 649
 	report_text mediumtext NOT NULL,
650 650
 	reported_post_text mediumtext NOT NULL,
  651
+	reported_post_bitfield varchar(255) DEFAULT '' NOT NULL,
  652
+	reported_post_uid varchar(8) DEFAULT '' NOT NULL,
651 653
 	PRIMARY KEY (report_id),
652 654
 	KEY post_id (post_id),
653 655
 	KEY pm_id (pm_id)
2  phpBB/install/schemas/oracle_schema.sql
@@ -1215,6 +1215,8 @@ CREATE TABLE phpbb_reports (
1215 1215
 	report_time number(11) DEFAULT '0' NOT NULL,
1216 1216
 	report_text clob DEFAULT '' ,
1217 1217
 	reported_post_text clob DEFAULT '' ,
  1218
+	reported_post_bitfield varchar2(255) DEFAULT '' ,
  1219
+	reported_post_uid varchar2(8) DEFAULT '' ,
1218 1220
 	CONSTRAINT pk_phpbb_reports PRIMARY KEY (report_id)
1219 1221
 )
1220 1222
 /
2  phpBB/install/schemas/postgres_schema.sql
@@ -854,6 +854,8 @@ CREATE TABLE phpbb_reports (
854 854
 	report_time INT4 DEFAULT '0' NOT NULL CHECK (report_time >= 0),
855 855
 	report_text TEXT DEFAULT '' NOT NULL,
856 856
 	reported_post_text TEXT DEFAULT '' NOT NULL,
  857
+	reported_post_bitfield varchar(255) DEFAULT '' NOT NULL,
  858
+	reported_post_uid varchar(8) DEFAULT '' NOT NULL,
857 859
 	PRIMARY KEY (report_id)
858 860
 );
859 861
 
4  phpBB/install/schemas/sqlite_schema.sql
@@ -628,7 +628,9 @@ CREATE TABLE phpbb_reports (
628 628
 	report_closed INTEGER UNSIGNED NOT NULL DEFAULT '0',
629 629
 	report_time INTEGER UNSIGNED NOT NULL DEFAULT '0',
630 630
 	report_text mediumtext(16777215) NOT NULL DEFAULT '',
631  
-	reported_post_text mediumtext(16777215) NOT NULL DEFAULT ''
  631
+	reported_post_text mediumtext(16777215) NOT NULL DEFAULT '',
  632
+	reported_post_bitfield varchar(255) NOT NULL DEFAULT '',
  633
+	reported_post_uid varchar(8) NOT NULL DEFAULT ''
632 634
 );
633 635
 
634 636
 CREATE INDEX phpbb_reports_post_id ON phpbb_reports (post_id);
30  phpBB/report.php
@@ -71,9 +71,11 @@
71 71
 		trigger_error('POST_NOT_EXIST');
72 72
 	}
73 73
 
74  
-	$forum_id 			= (int) $report_data['forum_id'];
75  
-	$topic_id 			= (int) $report_data['topic_id'];
76  
-	$reported_post_text	= $report_data['post_text'];
  74
+	$forum_id 				= (int) $report_data['forum_id'];
  75
+	$topic_id 				= (int) $report_data['topic_id'];
  76
+	$reported_post_text		= $report_data['post_text'];
  77
+	$reported_post_bitfield	= $report_data['bbcode_bitfield'];
  78
+	$reported_post_uid		= $report_data['bbcode_uid'];
77 79
 
78 80
 	$sql = 'SELECT *
79 81
 		FROM ' . FORUMS_TABLE . '
@@ -132,7 +134,9 @@
132 134
 		trigger_error($message);
133 135
 	}
134 136
 	
135  
-	$reported_post_text = $report_data['message_text'];
  137
+	$reported_post_text 	= $report_data['message_text'];
  138
+	$reported_post_bitfield	= $report_data['bbcode_bitfield'];
  139
+	$reported_post_uid		= $report_data['bbcode_uid'];
136 140
 }
137 141
 
138 142
 // Submit report?
@@ -151,15 +155,17 @@
151 155
 	}
152 156
 
153 157
 	$sql_ary = array(
154  
-		'reason_id'		=> (int) $reason_id,
155  
-		'post_id'		=> $post_id,
156  
-		'pm_id'			=> $pm_id,
157  
-		'user_id'		=> (int) $user->data['user_id'],
158  
-		'user_notify'	=> (int) $user_notify,
159  
-		'report_closed'	=> 0,
160  
-		'report_time'	=> (int) time(),
161  
-		'report_text'	=> (string) $report_text,
  158
+		'reason_id'				=> (int) $reason_id,
  159
+		'post_id'				=> $post_id,
  160
+		'pm_id'					=> $pm_id,
  161
+		'user_id'				=> (int) $user->data['user_id'],
  162
+		'user_notify'			=> (int) $user_notify,
  163
+		'report_closed'			=> 0,
  164
+		'report_time'			=> (int) time(),
  165
+		'report_text'			=> (string) $report_text,
162 166
 		'reported_post_text'	=> $reported_post_text,
  167
+		'reported_post_uid'		=> $reported_post_uid,
  168
+		'reported_post_bitfield'=> $reported_post_bitfield,
163 169
 	);
164 170
 
165 171
 	$sql = 'INSERT INTO ' . REPORTS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary);
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.