>...<> HTML block are not
* converted into paragraphs or line-breaks.
*
* @since WP 1.2.0
*
* @param array|string $matches The array or string
* @return string The pre block without paragraph/line-break conversion.
*/
function clean_pre($matches) {
if ( is_array($matches) )
$text = $matches[1] . $matches[2] . "";
else
$text = $matches;
$text = str_replace('
', '', $text);
$text = str_replace('
', "\n", $text);
$text = str_replace('
', '', $text);
return $text;
}
endif;
if ( !function_exists( 'js_escape' ) ) : // Current at [WP9840]
/**
* Escape single quotes, specialchar double quotes, and fix line endings.
*
* The filter 'js_escape' is also applied here.
*
* @since WP 2.0.4
*
* @param string $text The text to be escaped.
* @return string Escaped text.
*/
function js_escape($text) {
$safe_text = wp_specialchars($text, 'double');
$safe_text = preg_replace('/(x)?0*(?(1)27|39);?/i', "'", stripslashes($safe_text));
$safe_text = preg_replace("/\r?\n/", "\\n", addslashes($safe_text));
return apply_filters('js_escape', $safe_text, $text);
}
endif;
if ( !function_exists( 'attribute_escape' ) ) : // Current at [WP9840]
/**
* Escaping for HTML attributes.
*
* @since WP 2.0.6
*
* @param string $text
* @return string
*/
function attribute_escape($text) {
$safe_text = wp_specialchars($text, true);
return apply_filters('attribute_escape', $safe_text, $text);
}
endif;
if ( !function_exists( 'force_balance_tags' ) ) : // Current at [WP9840]
/**
* Balances tags of string using a modified stack.
*
* @since WP 2.0.4
*
* @author Leonard Lin
* @license GPL v2.0
* @copyright November 4, 2001
* @version 1.1
* @todo Make better - change loop condition to $text in 1.2
* @internal Modified by Scott Reilly (coffee2code) 02 Aug 2004
* 1.1 Fixed handling of append/stack pop order of end text
* Added Cleaning Hooks
* 1.0 First Version
*
* @param string $text Text to be balanced.
* @return string Balanced text.
*/
function force_balance_tags( $text ) {
$tagstack = array(); $stacksize = 0; $tagqueue = ''; $newtext = '';
$single_tags = array('br', 'hr', 'img', 'input'); //Known single-entity/self-closing tags
$nestable_tags = array('blockquote', 'div', 'span'); //Tags that can be immediately nested within themselves
# WP bug fix for comments - in case you REALLY meant to type '< !--'
$text = str_replace('< !--', '< !--', $text);
# WP bug fix for LOVE <3 (and other situations with '<' before a number)
$text = preg_replace('#<([0-9]{1})#', '<$1', $text);
while (preg_match("/<(\/?\w*)\s*([^>]*)>/",$text,$regex)) {
$newtext .= $tagqueue;
$i = strpos($text,$regex[0]);
$l = strlen($regex[0]);
// clear the shifter
$tagqueue = '';
// Pop or Push
if ($regex[1][0] == "/") { // End Tag
$tag = strtolower(substr($regex[1],1));
// if too many closing tags
if($stacksize <= 0) {
$tag = '';
//or close to be safe $tag = '/' . $tag;
}
// if stacktop value = tag close value then pop
else if ($tagstack[$stacksize - 1] == $tag) { // found closing tag
$tag = '' . $tag . '>'; // Close Tag
// Pop
array_pop ($tagstack);
$stacksize--;
} else { // closing tag not at top, search for it
for ($j=$stacksize-1;$j>=0;$j--) {
if ($tagstack[$j] == $tag) {
// add tag to tagqueue
for ($k=$stacksize-1;$k>=$j;$k--){
$tagqueue .= '' . array_pop ($tagstack) . '>';
$stacksize--;
}
break;
}
}
$tag = '';
}
} else { // Begin Tag
$tag = strtolower($regex[1]);
// Tag Cleaning
// If self-closing or '', don't do anything.
if((substr($regex[2],-1) == '/') || ($tag == '')) {
}
// ElseIf it's a known single-entity tag but it doesn't close itself, do so
elseif ( in_array($tag, $single_tags) ) {
$regex[2] .= '/';
} else { // Push the tag onto the stack
// If the top of the stack is the same as the tag we want to push, close previous tag
if (($stacksize > 0) && !in_array($tag, $nestable_tags) && ($tagstack[$stacksize - 1] == $tag)) {
$tagqueue = '' . array_pop ($tagstack) . '>';
$stacksize--;
}
$stacksize = array_push ($tagstack, $tag);
}
// Attributes
$attributes = $regex[2];
if($attributes) {
$attributes = ' '.$attributes;
}
$tag = '<'.$tag.$attributes.'>';
//If already queuing a close tag, then put this tag on, too
if ($tagqueue) {
$tagqueue .= $tag;
$tag = '';
}
}
$newtext .= substr($text,0,$i) . $tag;
$text = substr($text,$i+$l);
}
// Clear Tag Queue
$newtext .= $tagqueue;
// Add Remaining text
$newtext .= $text;
// Empty Stack
while($x = array_pop($tagstack)) {
$newtext .= '' . $x . '>'; // Add remaining tags to close
}
// WP fix for the bug with HTML comments
$newtext = str_replace("< !--","