Support Forum

Just One Reply Blockquote per Reply

SI sintmacro
sintmacro
Member

Hi,

One my old forum (version 4.45) I had changed (with help) the reply with just one blockquote added. See the example how it was on the old forum:

blockquote-old.png

 

And below a sample on the new version now: 

blockquote-new.png

 

Change of code was done at the file sf-forum.js. See the code how we changed it. 

Code OLD forum:
 
function sfjquotePost(postid, intro, editor, forumid, quoteUrl)
{
quoteUrl+=’&post=’+postid+’&editor=’+editor+’&forumid=’+forumid;
 
jQuery(‘#sfpostform’).show(function() {
jQuery(‘#postitem’).load(quoteUrl, function(content, b) {
 
 
//——————–
// Added 2010-08-13 by Arno Brinkman
//
// First remove/replace some horizontal breaks and whitspace
content=content.replace(/(</blockquote>)(s*)(((<p>s*</p>)s*(<hrs*/>))|((<hrs*/>)s*(<p>s*</p>)))/ig, ‘</blockquote>’);
 
 
/* all browsers */
document.getElementById(‘sfpostform’).scrollIntoView();
 
if(editor == 2 || editor == 4)
{
//——————–
// Added 2010-08-15 by Arno Brinkman
//
// Remove quote blocks
content=content.replace(/(<div>((.|n|r)*)</code>)((.|n|r)*)(<blockquote>((.|n|r)*)</blockquote>)/ig, ”);
//
//——————–
 
document.addpost.postitem.value = ‘<div><strong>’+intro+'</strong></div>rr’+'<blockquote>’+content+'</blockquote><hr />rr’;
document.addpost.postitem.focus();
}
if(editor == 3)
{
document.addpost.postitem.value = ‘‘+intro+’rr

‘+content+’

rr’;

document.addpost.postitem.focus();
}
if(editor == 1)
{
 
//——————–
// Added 2010-08-15 by Arno Brinkman
//
// Remove quote blocks
//content=content.replace(/(<p><strong>((.|n|r)*)</strong></p>)((.|n|r)*)(<blockquote>((.|n|r)*)</blockquote>)/ig, ”);
content=content.replace(/(<div>((.|n|r)*)</div>)((.|n|r)*)(<blockquote>((.|n|r)*)</blockquote>)/ig, ”);
//
//——————–
 
if(jQuery.browser.mozilla || jQuery.browser.opera)
{
tinyMCE.activeEditor.selection.setContent(‘<div><strong>’+intro+'</strong></div><blockquote>’+content+'</blockquote><p><hr /><br /></p>’);
tinyMCE.activeEditor.focus();
}
if(jQuery.browser.safari || jQuery.browser.webkit)
{
tinyMCE.activeEditor.execCommand(“InsertHTML”, false, ‘<div><strong>’+intro+'</strong></div><blockquote>’+content+'</blockquote><p><hr /><br /></p>’);
}
 
if(jQuery.browser.msie)
{
tinyMCE.activeEditor.execCommand(“mceInsertRawHTML”, false, ‘<div><strong>’+intro+'</strong></div><blockquote>’+content+'</blockquote><p><hr /></p>’);
tinyMCE.activeEditor.focus();
}
}
});
});
}
 
 
Now the code is like below. 
 
New forum code:
 
function spjQuotePost(postid, intro, forumid, quoteUrl) {
quoteUrl+=’&post=’+postid+’&forumid=’+forumid;
 
jQuery(‘#spPostForm’).show(‘normal’, function() {
        spjOpenEditor(‘spPostForm’, ‘post’);
jQuery(‘#postitem’).load(quoteUrl, function(content, b) {
spjEdInsertContent(intro, content);
});
});
}

 

I tried to change it but it doesn’t work. Hopefully you can help me with this.

 

11 Answers

New Answer

MP Mr Papa
Mr Papa
Member

first, what are you trying to do?  I dont understand the relationship of the first image to the second image???

are you just wanting a single blockquote in the post content?  just filter the post content and remove… probably using the same regex you used before…

something link:

add_filter('sph_save_post_content_filter', 'my_content_filter');
function my_content_filter($content) {
# do your blockquote regex or other code to change multi blockquote
}

stick that in the spFunctions.php file of your theme…

in 5.0, you wont need to be editing core code to customize…  extensive theme work and api of hooks, filters and actions…

SI sintmacro
sintmacro
Member

Hi, both images are form different forums. The first one is how it is now at the old version (4.45) en de second one how it is at my testsite. What happens is if someone add a reply and another one quote this, then it will get one blockquote with the text of the quoted post. But if someone else quote on this message you’ll get 2 blockquotes with all the text. That’s how it standard works. On my old forum it was changed by the code and add just the latest reply on the post in the blockquote. Hopes this makes it a bit more clear.

Thanks.

MP Mr Papa
Mr Papa
Member

my answer still stands…  just filter the post content with the hook I showed you…

SI sintmacro
sintmacro
Member

OKe thanks. But the thing is that I don’t know what part of the code I need to add. The code was created by some one else and unfortunatelly I don’t have the knowledge to change it. Hopefully you’ll assist me with this?

Thanks in advance.

MP Mr Papa
Mr Papa
Member

afraid I dont know what they did either… would have to spend bunch of time studying it…

you will want a regex to replace all occurrences of blockquote with a div except for the first (negative lookahead?)…  If I get some time, I will think on it…

SI sintmacro
sintmacro
Member

OKe thanks anyway. I’ll have some tries by myself eather. If it works I’ll let you know. Maybe it’s something for a  future version.

MP Mr Papa
Mr Papa
Member

here is one that strips all blockquote

$out = preg_replace(“~<blockquote(.*?)>(.*)</blockquote>~si”,””,’ ‘.$out.’ ‘);

would need to add a negative lookahead to skip the first one…

SI sintmacro
sintmacro
Member

Mr Papa said
here is one that strips all blockquote

$out = preg_replace(“~<blockquote(.*?)>(.*)</blockquote>~si”,””,’ ‘.$out.’ ‘);

would need to add a negative lookahead to skip the first one…

 

Thanks. I would prefer to keep the blockquote only from the first quoted post. Quote button would be unnecessary.

MP Mr Papa
Mr Papa
Member

Yes, I know… why I said that quick piece of code wouldnt do it…

SI sintmacro
sintmacro
Member

Mr Papa said
Yes, I know… why I said that quick piece of code wouldnt do it…

Thanks anyway, you helped a lot with giving the assists.

 

I’ve got some help form the person who wrote the first code. It was for him much easier to implement a code via your filter tip. Below the code. Maybe it’s interesting for you also for a new plugin or something. 

The code removes the extra blockquote when you “Submit Reply”. Then just one blockquote will be published, the last one of course.

add_filter(‘sph_save_post_content_filter’, ‘spbeursklets_context_filter’);

# beursklets content filter
function spbeursklets_context_filter($content) {

# If exists more than 1 <blockquote> tag, remove “inner-blockquotes”
$bqcount = substr_count($content, ‘<blockquote>’);
if ($bqcount >= 2) {
# Find second <blockquote> tag and prefix with own tag
$count = 0;
$pos = 0;
while ($count < 2) {
$pos = strpos($content, ‘<blockquote>’, $pos);
if ($pos === false) {
$count = 100;
} else {
$pos++;
$count++;
if ($count > 1) {
$content = substr_replace($content, ‘<[REMOVE_MARKER]>’, $pos – 1, 0);
}
}
}

# Find (last – 1) </blockquote> tag, if exists more than 1 and suffix with own tag
$count = 0;
$pos = 0;
while ($count < ($bqcount – 1)) {
$pos = strpos($content, ‘</blockquote>’, $pos);
if ($pos === false) {
$count = $bqcount + 100;
} else {
$pos++;
$count++;
if ($count == ($bqcount – 1)) {
$content = substr_replace($content, ‘</[REMOVE_MARKER]>’, $pos + strlen(‘</blockquote>’) – 1, 0);
}
}
}

$content = preg_replace(‘/<[REMOVE_MARKER]>((.|n|r)*)</[REMOVE_MARKER]>/i’, ”, $content);
}

return $content;
}

?>

MP Mr Papa
Mr Papa
Member

ah, the old fashioned brute force method… ;)   thanks for the update – saves me figuring out the negative look ahead regexp! cool