Vanilla 1 is no longer supported or maintained. If you need a copy, you can get it here.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.
AutoP
Stash
✭
AutoP
0
This discussion has been closed.
Comments
<?php /* Extension Name: AutoP Extension Url: http://lussumo.com/addons/?PostBackAction=AddOn&AddOnID=235 Description: Automatically formats paragraphs and new lines using valid XHTML. Version: 1.0.4 Author: Luke "[-Stash-]" Scammell Author Url: http://scammell.co.uk */ class AutoPFormatter extends StringFormatter { function Parse($String, $Object, $FormatPurpose) { if ($FormatPurpose == FORMAT_STRING_FOR_DISPLAY) { $String = $this->wpautop($String); $String = $this->AutoPFix($String); } return $String; } function clean_pre($text) { $text = str_replace('<br />', '', $text); $text = str_replace('<p>', "\n", $text); $text = str_replace('</p>', '', $text); return $text; } function wpautop($pee, $br = 1) { $pee = $pee . "\n"; // just to make things a little easier, pad the end $pee = preg_replace('|<br />\s*<br />|', "\n\n", $pee); // Space things out a little $allblocks = '(?:table|thead|tfoot|caption|colgroup|tbody|tr|td|th|div|dl|dd|dt|ul|ol|li|pre|code|select|form|map|area|blockquote|cite|address|math|style|script|object|embed|input|param|p|h[1-6])'; $pee = preg_replace('!(<' . $allblocks . '[^>]*>)!', "\n$1", $pee); $pee = preg_replace('!(</' . $allblocks . '>)!', "$1\n\n", $pee); $pee = str_replace(array("\r\n", "\r"), "\n", $pee); // cross-platform newlines $pee = preg_replace("/\n\n+/", "\n\n", $pee); // take care of duplicates $pee = preg_replace('/\n?(.+?)(?:\n\s*\n|\z)/s', "<p>$1</p>\n", $pee); // make paragraphs, including one at the end $pee = preg_replace('|<p>\s*?</p>|', '', $pee); // under certain strange conditions it could create a P of entirely whitespace $pee = preg_replace('!<p>([^<]+)\s*?(</(?:div|address|form)[^>]*>)!', "<p>$1</p>$2", $pee); $pee = preg_replace( '|<p>|', "$1<p>", $pee ); $pee = preg_replace('!<p>\s*(</?' . $allblocks . '[^>]*>)\s*</p>!', "$1", $pee); // don't pee all over a tag $pee = preg_replace("|<p>(<li.+?)</p>|", "$1", $pee); // problem with nested lists $pee = preg_replace('|<p><blockquote([^>]*)>|i', "<blockquote$1><p>", $pee); $pee = str_replace('</blockquote></p>', '</p></blockquote>', $pee); $pee = preg_replace('!<p>\s*(</?' . $allblocks . '[^>]*>)!', "$1", $pee); $pee = preg_replace('!(</?' . $allblocks . '[^>]*>)\s*</p>!', "$1", $pee); if ($br) { $pee = preg_replace('/<(script|style).*?<\/\\1>/se', 'str_replace("\n", "<WPPreserveNewline />", "\\0")', $pee); $pee = preg_replace('|(?<!<br />)\s*\n|', "<br />\n", $pee); // optionally make line breaks $pee = str_replace('<WPPreserveNewline />', "\n", $pee); } $pee = preg_replace('!(</?' . $allblocks . '[^>]*>)\s*<br />!', "$1", $pee); $pee = preg_replace('!<br />(\s*</?(?:p|li|div|dl|dd|dt|th|pre|code|cite|td|ul|ol)[^>]*>)!', '$1', $pee); if (strpos($pee, '<pre') !== false) $pee = preg_replace('!(<pre.*?>)(.*?)</pre>!ise', " stripslashes('$1') . stripslashes(clean_pre('$2')) . '</pre>' ", $pee); $pee = preg_replace( "|\n</p>$|", '</p>', $pee ); return $pee; } // These fix the few instances in Vanilla that AutoP corrupts. function AutoPFix ($String) { $String = str_replace( array( '<blockquote><p><cite>', '</cite><br />' ), array( '<blockquote><cite>', '<cite>' ), $String); return $String; } } // Instantiate the formatter and add it to the context object's string manipulator $AutoPFormatter = $Context->ObjectFactory->NewObject($Context, "AutoPFormatter"); $Context->StringManipulator->AddGlobalManipulator("AutoPFormatter", $AutoPFormatter); ?>
if (strpos($pee, '<pre') !== false) $pee = preg_replace('!(<pre.*?>)(.*?)</pre>!ise', " stripslashes('$1') . stripslashes(clean_pre('$2')) . '</pre>' ", $pee);
Your quotes are off. Single quotes are evaluated as literal strings, double quotes will insert the variable in the string. This will probably work better:
if (strpos($pee, '<pre')) $pee = preg_replace('!(<pre.*?>)(.*?)</pre>!ise', stripslashes("$1") . stripslashes(clean_pre("$2")) . '</pre>', $pee);
You could probably even do just
$1
instead of"$1"
, but I will leave them in for consistency sake.I have no idea what that means or what this extension does.
Also note that if you have a commented line with a
?>
contained in it... php reads it as an end of the PHP execution. Spent about an hour puzzling over that one.Mark: HTML characters got parsed out. I guess this extension is a more semantic line breaker--at a basic level its
<p></p>
instead of<br />
'sFYI here's a pseudo-fix for using this with PreviewPost:
Add to your vanilla.css:
#CommentBody_Preview br { display: none; } #CommentBody_Preview p br { display: block; }
It basically hides any extraneous breaks that PreviewPost generates.
I just wish I could figure out why PHP thinks the clean_pre function's undefined - bah!
Thanks ever-so-much AlexL
with your cursor (ff2 win xp sp2). This is really strange, is there a way to fix it?
<p>
didn't appear in my las commentwell, that appeared when you tried to select more than one paragraph, you couldn't select the nexr one. I'll try it again this evening an make a video or something