Preg_replace脏代码wordpress插件

时间:2018-08-17 19:10:01

标签: wordpress

我似乎无法确切找到所需的内容以及修改退货内容以显示正确的内容/方式。我的wordpress插件(脏代码)在我的网站上出现错误。

警告:preg_replace_callback():要求参数2“ ' . trunc_c2c_prep_code("$2") . '”是/home/hateyour/public_html/wp-content/plugins/dirty-code/dirtycode.php中的有效回调第110行

这是我的代码:

     <?php
/*
Plugin Name: Dirty Code
Version: 1.1 
Plugin URI: http://blog.netnerds.net/wp-plugins/
Author: Chrissy LeMaire
Author URI: http://netnerds.net
Description: Transforms any code between &lt;dirtycode> and &lt;/dirtycode> into a good looking div which can disappear or reappear with a click.

*/

function pretty_code_quick($text)
{
  extract($GLOBALS);
        global $id;
        $theID=$id;

  // For backwards compatibility
  $text=str_replace("quickcode","dirtycode",$text);
  $text=str_replace("[dirtycode]","<dirtycode>",$text);
  $text=str_replace("[/dirtycode]","</dirtycode>",$text);

  // Start it up :)
  $text=str_replace("</dirtycode>","</code></div>",$text);

 while(!((strpos($text,"<dirtycode") ? strpos($text,"<dirtycode")+1 : 0)==0))
  {

    $i=$i+1;
    $rStr="<a class=\"dirtycode\" title=\"Code\" href=\"javascript:toggleLayer('dirtycode".$theID.$i."');\">Change This Dirty Code Title</a></p>"."\r\n";
    $rStr=$rStr."<div id=\"dirtycode".$theID.$i."\" class=\"dirtycode\"><code>";

    $firstHalf=substr($text,0,(strpos($text,"<dirtycode") ? strpos($text,"<dirtycode")+1 : 0)-1);
    $secondHalf=substr($text,(strpos($text,"<dirtycode") ? strpos($text,"<dirtycode")+1 : 0)-1+strlen("<dirtycode")+1-1,strlen($text));

    $carrotNum=(strpos($secondHalf,">") ? strpos($secondHalf,">")+1 : 0)-1;

    if ($carrotNum<1)
    {

      $codeTitle="Dirty Code";
      $secondHalf=substr($secondHalf,strlen($secondHalf)-(strlen($secondHalf)-1));
      $restofCode=substr($secondHalf,$carrotNum+2-1,strlen($secondHalf));
      $text=$firstHalf.trim(str_replace("Change This Dirty Code Title",$codeTitle,$rStr)).$restofCode;

    }
      else
    {
      $codeTitle=substr($secondHalf,1,$carrotNum-1);
    } 

      if ($codeTitle=="noclick") { $rStr="<div class=\"dirtycodenoclick\"><code>"; }
      if (is_single() && get_option('dirtycodeExpandSingle') == TRUE)
{
      if ($codeTitle!="noclick" && $codeTitle!="Dirty Code")
      { $rStr = "<br><img align=absmiddle src=".get_bloginfo('wpurl')."/wp-content/plugins/dirty-code/dirtycode.gif> ".$codeTitle."<br><div class=\"dirtycodenoclick\"><code>"; }
      else
      { $rStr = "<div class=\"dirtycodenoclick\"><code>"; }
}


      $restofCode=substr($secondHalf,$carrotNum+2-1,strlen($secondHalf));
      $text=$firstHalf.trim(str_replace("Change This Dirty Code Title",$codeTitle,$rStr)).$restofCode;
  } 

  return $text;
} 

function pretty_code_converter_jscss() {
    $wp_url = get_bloginfo('wpurl') . "/";

    echo '
    <!-- Added By Dirty Code Plugin -->
    <link rel="stylesheet" href="'.$wp_url.'wp-content/plugins/dirty-code/dirtycode.css" type="text/css" />
    <script type="text/javascript" src="'.$wp_url.'wp-content/plugins/dirty-code/dirtycode.js"></script>
                ';

}

function dirtycode_add_options_page()
        {
                add_options_page('Dirty Code Options', 'Dirty Code', 9, 'dirty-code/dirtycode-options.php');
        }

// The following code has been derived from: Preserve Code Formatting by Scott Reilly
// http://www.coffee2code.com/wp-plugins/

function trunc_c2c_prep_code( $text ) {
    $text = preg_replace("/(\r\n|\n|\r)/", "\n", $text);
    $text = str_replace(array("&#36&;", "&#39&;"), array("$", "'"), $text);
    $text = htmlspecialchars($text, ENT_QUOTES);
    $text = str_replace('  ', '&nbsp;&nbsp;', $text);

    $text = str_replace('---', '&#45;&#45;-', $text);
    $text = str_replace('--', '&#45;-', $text);
    $text = str_replace('...', '&#46;..', $text);
    $text = str_replace('``', '&#96;`', $text);

    $text = str_replace("\n\n", "\n<br />", $text);
    return $text;
}

function trunc_c2c_preserve_code_formatting( $text ) {
    $text = str_replace(array('$', "'"), array('&#36&;', '&#39&;'), $text);
    $tags = array('code', 'pre');
    foreach ($tags as $tag) {
        $text = preg_replace(
            "^(<$tag>)\n?([\S|\s]*?)\n?(</$tag>)^ie",
            "'<$tag>' . trunc_c2c_prep_code(\"$2\") . '</$tag>'",
            $text
        );
    }
    $text = str_replace(array('&#36&;', '&#39&;'), array('$', "'"), $text);
    return $text;
}


add_filter('the_content', 'trunc_c2c_preserve_code_formatting', 8);
add_filter('the_excerpt', 'trunc_c2c_preserve_code_formatting', 8);

add_filter('the_content', 'pretty_code_quick',0);
add_filter('the_excerpt', 'pretty_code_quick',0);
add_action('wp_head', 'pretty_code_converter_jscss');
add_action('admin_menu', 'dirtycode_add_options_page');
?>

帮助!我不明白我要用这2美元怎么办。

0 个答案:

没有答案