sections in the content and escape certain characters, depending on the markup and lang attributes. (For backwards compatibility, "allow" works as a synonym of "markup".) Also remove newlines after and before . This prevents spurious linebreaks. */ global $wp_version; // TODO wrap multiline code tags in a pre element if not already wrapped // $content = preg_replace('%(?]*>[^>]*)(]*>.*?)%ims', '
\n$1\n
', $content); if ($wp_version < '2.3') { // escape backslashes so WordPress doesn't remove them (this problem was fixed in WP 2.3) $content = preg_replace_callback('!]*)>(.*?)!ims', 'tguy_cmu_escape_backslash_callback', $content); } // encode XML inside code blocks (removing newlines after and before ) $content = preg_replace_callback('!]*)>(?:\r\n|\n|\r|)(.*?)(?:\r\n|\n|\r|)!ims', 'tguy_cmu_encode_xml_callback', $content); return $content; } function tguy_cmu_tidy_code($content) { /* Fix two potential WordPress problems: when a post is displayed, - Double quotes inside a
 are prepended with a backslash.
	- Contents inside a  block after the first tag are texturized.
*/
	// unescape double quotes inside 
 blocks
	$content = preg_replace_callback('!]*)>(.*?)
!ims', 'tguy_cmu_unescape_qq_callback', $content); // untexturize the contents of blocks $content = preg_replace_callback('!]*)>(.*?)!ims', 'tguy_cmu_untexturize_code_callback', $content); return $content; } // ===== Callback functions ================================================== function tguy_cmu_encode_xml_callback($matches) { /* Encode XML in a tag. */ $attributes = $matches[1]; $escapedContent = $matches[2]; $attrMatches = array(); // $markup tells us what HTML special chars are allowed to remain unescaped. // This can be set to a space-separated list of tags. Can also be set to the // special values all, none or default. If missing, same as default. // Also remove the attribute once we've used it. $markup = 'default'; if (0 < preg_match('!^(.*?)\s+(?:markup|allow)="([^"]*)"(.*)$!i', $attributes, $attrMatches)) { $markup = strtolower($attrMatches[2]); $attributes = $attrMatches[1] . $attrMatches[3]; } // Depending on language, default handling may change if ($markup == 'default') { // See if lang is specified; also remove the attribute once we've used it. if (0 < preg_match('!^(.*)lang="([^"]*)"(.*)$!i', $attributes, $attrMatches)) { $lang = strtolower($attrMatches[2]); $attributes = $attrMatches[1] . $attrMatches[3]; if ($lang == 'html' || $lang == 'xhtml') { $markup = 'none'; } } } if ($markup == 'all') { // Nothing to do -- allow anything through. } else { // Could be default, none, or (possibly blank) space-separated list. if ($markup == 'none' || $markup == '') { $allowedTags = ''; } else if ($markup == 'default' || $markup == 'tags') { // 'tags' allowed for backward compatibility $allowedTags = 'em|strong|b|i|ins|del|a|span|comment'; } else { $allowedTags = preg_replace('!\s+!', '|', trim($markup)); } // Escape html special chars $escapedContent = htmlspecialchars($escapedContent, ENT_NOQUOTES); if ($allowedTags != '') { // Certain HTML tags are allowed: translate them back. $escapedContent = preg_replace_callback('!</?('.$allowedTags.')( .*?)?>!is', 'tguy_cmu_unescape_tag', $escapedContent); if (false !== strpos($allowedTags, 'comment')) { $escapedContent = preg_replace_callback('|<!--.*?-->|is', 'tguy_cmu_unescape_tag', $escapedContent); } } } return "$escapedContent"; } function tguy_cmu_unescape_tag($matches) { return str_replace( array(">", "<", """, "&"), array(">", "<", "\"", "&"), $matches[0]); } function tguy_cmu_escape_backslash_callback($matches) { /* Escape backslashes in a
 tag.
*/
	return "".str_replace('\\', '\\\\', $matches[2])."
"; } function tguy_cmu_unescape_qq_callback($matches) { /* Unescape double quotes in a
 tag.
*/
	return "".str_replace('\"', '"', $matches[2])."
"; } function tguy_cmu_untexturize_code_callback($matches) { /* Undo the effect of wptexturize() within a element. wptexturize() is meant to handle this but is buggy... BUGS: Turns --- into -- and `` into " */ $fancy = array('×', '‘', '’', '′', '“', '”', '″', '—', '–', '…', '“'); $plain = array('x' ,'\'' , '\'' , '\'' , '"' , '"' , '"' , '--' , '--' , '...' , '``' ); return "".str_replace($fancy, $plain, $matches[2]).""; } // TinyMCE part function my_change_mce_settings( $init_array ) { $init_array['theme_advanced_blockformats'] = 'p,pre,h3,h4,h5,h6'; return $init_array; } add_filter( 'tiny_mce_before_init', 'my_change_mce_settings' ); function my_plugin_css($css) { return $css . "," . get_bloginfo('template_url') . "/stylesheets/post.css"; } add_filter("mce_css", "my_plugin_css"); /** * void wpi_comment_paging_noindex_meta() * Add meta noindex rules on Singular comment page section * * @author Avice D * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License * @link http://blog.kaizeku.com/wordpress/prevent-wordpress-27-duplicate-content/ * * @todo Check for duplicate meta-robots tag generated by * meta-tag type plugins (SEO plugins) * * @uses $wp_query Wp_query object * @return string Output HTML meta noindex */ function wpi_comment_paging_noindex_meta() { global $wp_query; if (version_compare( (float) get_bloginfo('version'), 2.7, '>=') ){ if ($wp_query->is_singular && get_option('page_comments')){ // comments paging enabled if (isset($wp_query->query['cpage']) && absint($wp_query->query['cpage']) >= 1 ){ echo ''.PHP_EOL; } } } } add_action('wp_head','wpi_comment_paging_noindex_meta'); // Widgets part function widget_mytheme_search() { echo ''; } if ( function_exists('register_sidebar_widget') ) register_sidebar_widget(__('Search'), 'widget_mytheme_search'); if ( function_exists('register_sidebar') ) register_sidebar(array( 'before_widget' => '
  • ', 'after_widget' => '
  • ', 'before_title' => '

    ', 'after_title' => '

    ', ) ); ?>