Remove nested quotes in full and quick reply boxes

Discussion forum for MOD Writers regarding MOD Development.
Yosiah
Registered User
Posts: 38
Joined: Sat Oct 01, 2011 4:27 pm

Remove nested quotes in full and quick reply boxes

Post by Yosiah »

This may be a bit complicated, but I'm hoping that someone can help me out or point me in the right direction.

I'm currently in the process of setting up a new board for a community that has for more than a decade used a custom coded board and become very accustomed to its features.

One notable aspect of that board was that it did not have nested quotes. It also featured a quickquote button that sent the quoted post to the quick reply box without jumping to it so that users could quote posts as they read a thread, and then reply to each quote once they reached the bottom of the page. Nested quotes did not show up either on the full reply page when a single post was quoted or in the quick reply box when multiple posts had been quoted.

I have modified the Full Quick Reply Editor MOD to accomplish this quickquote feature while preserving the standard quote button. My edits to that MOD are included below just in case they're needed here. What I need help with now is removing nested quotes from the quick reply box and full reply page.

Firstly, I know that phpBB has a max setting for nested quotes that requires a user to manually edit them out if they go over the limit (or have any nested quotes at all in my case), but this isn't very user friendly.

In an attempt get around that error message, I've installed the Quote Remover MOD, and it seems to do everything that I need perfectly... except that it only removes nested quotes from a reply once the reply has been posted.

If the purpose of a quote remover mod is to remove the clutter that nested quotes can cause, then it only makes sense to also remove that clutter for your users when they're replying and the text is even more cluttered by BBCode. In my case, where I've made a multi-quote feature available via the quick reply box, it can be especially cluttered when a user tries to reply.

So, is there a MOD available to strip nested quotes from a post before they reach the quick or full reply boxes? And, if not, would anyone be willing to create something to accomplish this that works with the following quickquote mod?

Any help is greatly appreciated.

--------

The following are my changes to Full Quick Reply Editor. Apply these edits after installing that MOD.

Upload this (hastily made) image

Image

Rename as 'icon_post_quickquote.gif' and upload to:

prosilver/imageset/en/

--------

includes/acp/acp_styles.php

FIND:

Code: Select all

 'button_topic_reply',
IN-LINE FIND:

Code: Select all

 'button_topic_reply',
IN-LINE ADD AFTER:

Code: Select all

 'icon_post_quickquote',
--------

language/en/acp/styles.php

FIND:

Code: Select all

	'IMG_ICON_POST_QUOTE'			=> 'Quote post',
ADD AFTER:

Code: Select all

	'IMG_ICON_POST_QUICKQUOTE'		=> 'Quickquote post',
--------

language/en/common.php

FIND:

Code: Select all

	'REPLY_WITH_QUOTE'			=> 'Reply with quote',
ADD AFTER:

Code: Select all

	'REPLY_WITH_QUICKQUOTE'			=> 'Reply with quickquote',
--------

viewtopic.php

FIND:

Code: Select all

	'QUOTE_IMG' 		=> $user->img('icon_post_quote', 'REPLY_WITH_QUOTE'),
ADD AFTER:

Code: Select all

	'QUICKQUOTE_IMG'		=> $user->img('icon_post_quickquote', 'REPLY_WITH_QUICKQUOTE'),
--------

styles/prosilver/imageset/en/imageset.cfg

FIND:

Code: Select all

img_icon_post_quote = icon_post_quote.gif*20*54
ADD AFTER:

Code: Select all

img_icon_post_quickquote = icon_post_quickquote.gif*20*87
--------

styles/prosilver/theme/buttons.css

FIND:

Code: Select all

.quote-icon, .quote-icon a		{ background: none top left no-repeat; }
ADD AFTER:

Code: Select all

.qq-icon, .qq-icon a				{ background: none top left no-repeat; }
FIND:

Code: Select all

ul.profile-icons li.quote-icon	{ width: {IMG_ICON_POST_QUOTE_WIDTH}px; height: {IMG_ICON_POST_QUOTE_HEIGHT}px; }
ADD AFTER:

Code: Select all

ul.profile-icons li.qq-icon		{ width: {IMG_ICON_POST_QUICKQUOTE_WIDTH}px; height: {IMG_ICON_POST_QUICKQUOTE_HEIGHT}px; }
FIND:

Code: Select all

ul.profile-icons li.quote-icon	{ margin: 0 0 0 10px; }
REPLACE:

Code: Select all

ul.profile-icons li.quote-icon	{ margin: 0 0 0 3px; }
ADD AFTER:

Code: Select all

ul.profile-icons li.qq-icon	{ margin: 0 0 0 3px; }
--------

styles/prosilver/theme/colours.css

FIND:

Code: Select all

.quote-icon, .quote-icon a		{ background-image: url("{IMG_ICON_POST_QUOTE_SRC}"); }
ADD AFER:

Code: Select all

.qq-icon, .qq-icon a			{ background-image: url("{IMG_ICON_POST_QUICKQUOTE_SRC}"); }
--------

styles/prosilver/template/viewtopic_body.html

FIND:

Code: Select all

					<!-- IF postrow.U_QUOTE --><li class="quote-icon"><a href="{postrow.U_QUOTE}" title="{L_REPLY_WITH_QUOTE}"><span>{L_REPLY_WITH_QUOTE}</span></a></li><!-- ENDIF -->

REPLACE:

Code: Select all

					<!-- IF postrow.DECODED_MESSAGE and S_QUICK_REPLY --><li class="qq-icon"><a href="#quickquote" onclick="addquote({postrow.POST_ID}, '{postrow.POSTER_QUOTE}', '{LA_WROTE}');" title="{L_REPLY_WITH_QUICKQUOTE}"><span>{L_REPLY_WITH_QUICKQUOTE}</span></a></li><!-- ENDIF -->
ADD AFTER:

Code: Select all

					<!-- IF postrow.U_QUOTE --><li class="quote-icon"><a href="{postrow.U_QUOTE}" title="{L_REPLY_WITH_QUOTE}"><span>{L_REPLY_WITH_QUOTE}</span></a></li><!-- ENDIF -->
--------

To add line breaks after quote in quick reply to better visually separate multi-quotes:

/styles/prosilver/template/editor.js

FIND:

Code: Select all

			insert_text('[quote="' + username + '"]' + theSelection + '[/quote]');
REPLACE:

Code: Select all

			insert_text('[quote="' + username + '"]' + theSelection + '[/quote]' + '\n' + '\n');
--------

Optionally, remove "Display quick reply" option from user control panel (in board preferences) so that you can be certain that quick reply is always available. If your board is active and may have users who have already disabled the quick reply box, you may want to leave this option available.

styles/prosilver/template/ucp_prefs_view.html

FIND AND REMOVE:

Code: Select all

		<!-- IF S_QUICK_REPLY_GLOBAL -->
			<dl>
				<dt><label for="quickreply1">{L_VIEW_QUICK_REPLY}:</label></dt>
				<dd>
					<label for="quickreply1"><input type="radio" name="quickreply" id="quickreply1" value="1"<!-- IF S_QUICK_REPLY --> checked="checked"<!-- ENDIF --> /> {L_YES}</label> 
					<label for="quickreply0"><input type="radio" name="quickreply" id="quickreply0" value="0"<!-- IF not S_QUICK_REPLY --> checked="checked"<!-- ENDIF --> /> {L_NO}</label>
				</dd>
			</dl>
		<!-- ENDIF -->
--------

And that's it. Thanks for any help.
Last edited by Yosiah on Tue Oct 30, 2012 3:35 pm, edited 1 time in total.
User avatar
4_seven
I've Been Banned!
Posts: 5155
Joined: Wed Apr 30, 2008 1:41 am

Re: Remove nested quotes in full and quick reply boxes

Post by 4_seven »

make these edits the same functionality as here?
http://www.phpbb.com/community/viewtopi ... &t=2122446

not shure, but good job.

the trick with the remove of nested quotes are very tricky, bcs. the quote bbcode is the most complex bbcode, so reduce the count of nestings via acp seems the beste way without a code overkill.
Current Mods | Mod Base | php(BB) programming | No help via PM
Yosiah
Registered User
Posts: 38
Joined: Sat Oct 01, 2011 4:27 pm

Re: Remove nested quotes in full and quick reply boxes

Post by Yosiah »

4_seven wrote:make these edits the same functionality as here?
http://www.phpbb.com/community/viewtopi ... &t=2122446

not shure, but good job.
My edits are essentially the same, but they allow multiple quotes to be sent to quick reply without reloading the page or jumping to the quick reply box.
4_seven wrote:the trick with the remove of nested quotes are very tricky, bcs. the quote bbcode is the most complex bbcode, so reduce the count of nestings via acp seems the beste way without a code overkill.
Ah, I wasn't sure how difficult it would be. The only issue with reducing the nesting count via ACP is that it doesn't prevent nested quotes from showing up in the reply box. I can remove them with quote remover once the post is submitted, but since I'm using a multi-quote mod for the quick reply box, it can easily become very confusing to navigate when nested quotes are present.

If it's really difficult though, then I guess I'm out of luck? Or is anyone here willing to give it a shot? Any help would be very appreciated.
Yosiah
Registered User
Posts: 38
Joined: Sat Oct 01, 2011 4:27 pm

Re: Remove nested quotes in full and quick reply boxes

Post by Yosiah »

Anyone?

Even just a tip to point me in the right direction would be really helpful. At the moment, I'm not sure where to even begin in trying implement something like this.
Yosiah
Registered User
Posts: 38
Joined: Sat Oct 01, 2011 4:27 pm

Re: Remove nested quotes in full and quick reply boxes

Post by Yosiah »

I assume that I need to add something like this:

Code: Select all

var text=$('#edit-privatemsgbody').val();
var tmp=[];
var level=0;

for (var i=0,l=text.length;i<l;i++){
 if(text[i]=='['&&text[i+1]=='q') level++; 
 if(text[i-6]=='q'&&text[i-7]=='/'&&text[i-8]=='[') level--;
 if(level<3) tmp.push(text[i]);
}
alert(tmp.join(''));
... which I found here to the addquote function in editor.js?

I just can't really work out where it should be added or how to integrate it with the existing code. Nothing that I've tried has worked so far.

I really have no idea what I'm doing here. Any help is immensely appreciated.
Yosiah
Registered User
Posts: 38
Joined: Sat Oct 01, 2011 4:27 pm

Re: Remove nested quotes in full and quick reply boxes

Post by Yosiah »

Okay...

So in editor.js, I've made two modifications.

FIND:

Code: Select all

	var message_name = 'message_' + post_id;
	var theSelection = '';
	var divarea = false;
ADD AFTER:

Code: Select all

	var tmp = [];
	var level = 0;
FIND:

Code: Select all

	if (theSelection)
	{
		if (bbcodeEnabled)
		{
			insert_text('[quote="' + username + '"]' + theSelection + '[/quote]' + '\n' + '\n');
		}
		else
		{
			insert_text(username + ' ' + l_wrote + ':' + '\n');
			var lines = split_lines(theSelection);
			for (i = 0; i < lines.length; i++)
			{
				insert_text('> ' + lines[i] + '\n');
			}
		}
	}
ADD BEFORE:

Code: Select all

	if (theSelection)
	{
		for (var i = 0, l = theSelection.length; i < l; i++)
		{
			if (theSelection[i] == '[' && theSelection[i+1] == 'q') level++; 
			if (theSelection[i-6] == 'q' && theSelection[i-7] == '/' && theSelection[i-8] == '[') level--;
			if (level<1) tmp.push(theSelection[i]);
		}
		theSelection = tmp.join('');
	}
After those edits, embedded quotes are being removed from the quick reply box. But there is still one issue.

It only works for the quick reply box.

Where would I apply these changes to the full reply page as well?

Also, this topic is more development than request now, so it may be in the wrong place?
Last edited by Yosiah on Mon Oct 17, 2011 7:26 am, edited 1 time in total.
User avatar
Oyabun1
Former Team Member
Posts: 23162
Joined: Sun May 17, 2009 1:05 pm
Location: Australia
Name: Bill

Re: Remove nested quotes in full and quick reply boxes

Post by Oyabun1 »

Yosiah wrote:Also, this topic is more development than request now, so it may be in the wrong place?
This type of thing would be better in [3.0.x] MOD Writers Discussion, you can request moderator to move it for you.
                      Support Request Template
3.0.x: Knowledge Base Styles Support MOD Requests
3.1.x: Knowledge BaseStyles SupportExtension Requests
Yosiah
Registered User
Posts: 38
Joined: Sat Oct 01, 2011 4:27 pm

Re: Remove nested quotes in full and quick reply boxes

Post by Yosiah »

Oyabun1 wrote:
Yosiah wrote:Also, this topic is more development than request now, so it may be in the wrong place?
This type of thing would be better in [3.0.x] MOD Writers Discussion, you can request moderator to move it for you.
That works. Could a mod please move this topic?

--------

Removing nested quotes left behind excessive line breaks, so I've updated the javascript to handle that. Note that this reflects my own personal taste for quote formatting. The new edits (made after applying all of the changes in this thread) are:

styles/prosilver/template/editor.js

FIND:

Code: Select all

		if (bbcodeEnabled)
ADD BEFORE:

Code: Select all

		theSelection = theSelection.replace(/\n{3,}/g, "\n\n").replace(/^\s+|\s+$/g,"");
FIND:

Code: Select all

         insert_text('[quote="' + username + '"]' + theSelection + '[/quote]' + '\n' + '\n');
REPLACE:

Code: Select all

			insert_text('[quote="' + username + '"]' + '\n' + '\n' + theSelection + '[/quote]' + '\n' + '\n');
This should assure that all text sent to the quick reply box is formatted as:

Code: Select all

[quote="Username"]

Quote text.

More quote text.

Even more quote text.[/quote]
... regardless of whether the quoted post contained no nested quotes at all, multiple nested quotes, or a nested quote at the beginning of the post. It also adds two line breaks after each quote to better space out multiple quotes and make them easier for users to navigate.

The only issue left is that this only works for quick reply. In order for these changes to also be applied to quotes sent to the full reply page, I think these changes will need to be ported to PHP. Since I know almost nothing about PHP though, I'm having difficulty even locating where these changes will need to be made. My best guess is this bit of code from posting.php:

Code: Select all

// Decode text for message display
$post_data['bbcode_uid'] = ($mode == 'quote' && !$preview && !$refresh && !sizeof($error)) ? $post_data['bbcode_uid'] : $message_parser->bbcode_uid;
$message_parser->decode_message($post_data['bbcode_uid']);

if ($mode == 'quote' && !$submit && !$preview && !$refresh)
{
	if ($config['allow_bbcode'])
	{
		$message_parser->message = '[quote="' . $post_data['quote_username'] . '"]' . censor_text(trim($message_parser->message)) . "[/quote]\n";
	}
	else
	{
		$offset = 0;
		$quote_string = "> ";
		$message = censor_text(trim($message_parser->message));
		// see if we are nesting. It's easily tricked but should work for one level of nesting
		if (strpos($message, ">") !== false)
		{
			$offset = 10;
		}
		$message = utf8_wordwrap($message, 75 + $offset, "\n");

		$message = $quote_string . $message;
		$message = str_replace("\n", "\n" . $quote_string, $message);
		$message_parser->message =  $post_data['quote_username'] . " " . $user->lang['WROTE'] . ":\n" . $message . "\n";
	}
}

if (($mode == 'reply' || $mode == 'quote') && !$submit && !$preview && !$refresh)
{
	$post_data['post_subject'] = ((strpos($post_data['post_subject'], 'Re: ') !== 0) ? 'Re: ' : '') . censor_text($post_data['post_subject']);
}

$attachment_data = $message_parser->attachment_data;
$filename_data = $message_parser->filename_data;
$post_data['post_text'] = $message_parser->message;

if (sizeof($post_data['poll_options']) || !empty($post_data['poll_title']))
{
	$message_parser->message = $post_data['poll_title'];
	$message_parser->bbcode_uid = $post_data['bbcode_uid'];

	$message_parser->decode_message();
	$post_data['poll_title'] = $message_parser->message;

	$message_parser->message = implode("\n", $post_data['poll_options']);
	$message_parser->decode_message();
	$post_data['poll_options'] = explode("\n", $message_parser->message);
}
But I'm not 100% certain that this is where the changes will need to be made. Can anyone confirm?

Also, would anyone be willing to port the javascript that I'm currently using for the quickquote MOD to PHP so that it can be integrated into the full reply box?

Thanks for any help.
Yosiah
Registered User
Posts: 38
Joined: Sat Oct 01, 2011 4:27 pm

Re: Remove nested quotes in full and quick reply boxes

Post by Yosiah »

This is mostly solved now. The changes need to be extended to cover PMs, but I don't expect to run into any problems there. If anyone else is interested in doing this, I'll post the last few bits of the puzzle once I'm sure everything is working properly.

Complete list of changes made:

- Adds a full reply box (based on Full Quick Reply Editor)
- Adds the ability to quote multiple posts to the quick reply box via a new "quickquote" button.
- Completely removes nested quotes from your board. Quotes are removed from posts that are quoted using the quickquote feature, the full reply box or in PMs.
- All quotes are formatted the same after quotes are removed from (or if no quotes were present within) a post.
- Uses Quote Remover to strip nested quotes (above the threshold set in ACP) added manually to a post by a user without throwing an error message.

Anyone interested in something like this? If so, I'll try to put together one simple, coherent post with all of the edits needed. It might be a few days before I'd be able to get around to it though.
dani1a
Registered User
Posts: 23
Joined: Mon Mar 16, 2009 7:57 pm

Re: Remove nested quotes in full and quick reply boxes

Post by dani1a »

Yosiah wrote:This is mostly solved now. The changes need to be extended to cover PMs, but I don't expect to run into any problems there. If anyone else is interested in doing this, I'll post the last few bits of the puzzle once I'm sure everything is working properly.

Complete list of changes made:

- Adds a full reply box (based on Full Quick Reply Editor)
- Adds the ability to quote multiple posts to the quick reply box via a new "quickquote" button.
- Completely removes nested quotes from your board. Quotes are removed from posts that are quoted using the quickquote feature, the full reply box or in PMs.
- All quotes are formatted the same after quotes are removed from (or if no quotes were present within) a post.
- Uses Quote Remover to strip nested quotes (above the threshold set in ACP) added manually to a post by a user without throwing an error message.

Anyone interested in something like this? If so, I'll try to put together one simple, coherent post with all of the edits needed. It might be a few days before I'd be able to get around to it though.
Yes, very interested. Can you post link to your forum where this is working?
browser123
Registered User
Posts: 162
Joined: Thu Nov 24, 2011 12:28 pm

Re: Remove nested quotes in full and quick reply boxes

Post by browser123 »

Yosaih thats perfect, how do i get it too work though without jumping to the quick reply box everytime you hit the button?
browser123
Registered User
Posts: 162
Joined: Thu Nov 24, 2011 12:28 pm

Re: Remove nested quotes in full and quick reply boxes

Post by browser123 »

bump
User avatar
4_seven
I've Been Banned!
Posts: 5155
Joined: Wed Apr 30, 2008 1:41 am

Re: Remove nested quotes in full and quick reply boxes

Post by 4_seven »

Just follow the un-jumpy instruction from Yosiah
http://www.phpbb.com/community/viewtopi ... #p13064022
Yosiah wrote:
4_seven wrote:make these edits the same functionality as here?
http://www.phpbb.com/community/viewtopi ... &t=2122446

not shure, but good job.
My edits are essentially the same, but they allow multiple quotes to be sent to quick reply without reloading the page or jumping to the quick reply box.
Current Mods | Mod Base | php(BB) programming | No help via PM
browser123
Registered User
Posts: 162
Joined: Thu Nov 24, 2011 12:28 pm

Re: Remove nested quotes in full and quick reply boxes

Post by browser123 »

i followed all these instructions, but it still seemed to jump :s
Yosiah
Registered User
Posts: 38
Joined: Sat Oct 01, 2011 4:27 pm

Re: Remove nested quotes in full and quick reply boxes

Post by Yosiah »

At the point where I left off in this thread, I think the only instances where I ran into jumping issues were on touchscreen devices. I eventually ended up replacing the #quickquote anchor tag with javascript:void(0) to remedy that problem. Outside of that, the only thing that I know of that would cause it to jump would be if you've used "quickquote" as a class or id or something somewhere on your page.

I'm having computer issues at the moment, so I can't really play around with the code for now. I'm hoping to have that sorted soon though, and I'm planning to try to put together a finalized version of this as soon as I can. That may end up being a few weeks or something, but I'll try to look into any remaining issues (like jumping) once I've had a chance to get around to releasing the completed MOD. Sorry for the delay.
Locked

Return to “[3.0.x] MOD Writers Discussion”