Esempio n. 1
0
 /**
  * @static
  * @param string $text_alt
  * @param string $text_neu
  * @param bool $compact
  * @param int $css_width_hack
  * @param string $pre_str_html
  * @param bool $wrapWithCssClass
  * @param bool $debug
  * @return string
  */
 public static function renderBBCodeDiff2HTML($text_alt, $text_neu, $compact = false, $css_width_hack = 0, $pre_str_html = "", $wrapWithCssClass = true, $debug = false)
 {
     $text_alt = static::bbNormalizeForDiff($text_alt);
     $text_neu = static::bbNormalizeForDiff($text_neu);
     $diff = DiffUtils::getTextDiff($text_alt, $text_neu);
     if ($compact) {
         $renderer = new Horde_Text_Diff_Renderer_Inline_Antrag15();
         $absatz = $renderer->render($diff);
     } else {
         $absatz = DiffUtils::renderAbsatzDiff($diff);
     }
     if ($debug) {
         echo "\n\n============== Nach DIFF ===============\n\n";
         var_dump($absatz);
     }
     $split_lists = function ($matches) use($debug) {
         $lis = explode("[*]", $matches["inhalt"]);
         if (count($lis) == 1) {
             return $matches[0];
         }
         $output = "";
         for ($i = 0; $i < count($lis); $i++) {
             if ($i == 0) {
                 if (trim($lis[$i]) == "") {
                     $output .= $lis[$i];
                 } else {
                     $output .= $matches["anfang"] . $lis[$i] . $matches["ende"];
                 }
             } elseif ($i == count($lis) - 1) {
                 if (trim($lis[$i]) == "") {
                     $output .= "[*]" . $lis[$i];
                 } else {
                     $output .= "[*]" . $matches["anfang"] . $lis[$i] . $matches["ende"];
                 }
             } else {
                 $output .= "[*]" . $matches["anfang"] . $lis[$i] . $matches["ende"];
             }
         }
         if ($debug) {
             echo "-----------------\n";
             var_dump($matches);
             var_dump($lis);
             var_dump($output);
         }
         return $output;
     };
     $absatz = preg_replace_callback("/(?<anfang><del>)(?<inhalt>.*)(?<ende><\\/del>)/siU", $split_lists, $absatz);
     $absatz = preg_replace_callback("/(?<anfang><ins>)(?<inhalt>.*)(?<ende><\\/ins>)/siU", $split_lists, $absatz);
     $diffstr = HtmlBBcodeUtils::bbcode2html($absatz);
     $diffstr = str_ireplace(array("&lt;ins&gt;", "&lt;/ins&gt;", "&lt;del&gt;", "&lt;/del&gt;"), array("<ins>", "</ins>", "<del>", "</del>"), $diffstr);
     if ($debug) {
         echo "\n\n============== In HTML ===============\n\n";
         var_dump($diffstr);
     }
     static::$ins_mode_active = false;
     static::$del_mode_active = false;
     $diffstr = preg_replace_callback("/(<li>)(.*)(<\\/li>)/siuU", function ($matches) {
         $pos_del_open = mb_stripos($matches[2], "<del>");
         $pos_del_close = mb_stripos($matches[2], "</del>");
         $pos_ins_open = mb_stripos($matches[2], "<ins>");
         $pos_ins_close = mb_stripos($matches[2], "</ins>");
         $middle = $matches[2];
         if ($pos_del_close !== false && ($pos_del_open === false || $pos_del_open > $pos_del_close)) {
             $middle = "<del>" . $middle;
             static::$del_mode_active = false;
         }
         if ($pos_del_open !== false && ($pos_del_close === false || $pos_del_open > $pos_del_close)) {
             $middle .= "</del>";
             static::$del_mode_active = true;
         }
         if ($pos_del_close === false && $pos_del_open === false && static::$del_mode_active) {
             $middle = "<del>{$middle}</del>";
         }
         if ($pos_ins_close !== false && ($pos_ins_open === false || $pos_ins_open > $pos_ins_close)) {
             $middle = "<ins>" . $middle;
             static::$ins_mode_active = false;
         }
         if ($pos_ins_open !== false && ($pos_ins_close === false || $pos_ins_open > $pos_ins_close)) {
             $middle .= "</ins>";
             static::$ins_mode_active = true;
         }
         if ($pos_ins_close === false && $pos_ins_open === false && static::$ins_mode_active) {
             $middle = "<ins>{$middle}</ins>";
         }
         return $matches[1] . $middle . $matches[3];
     }, $diffstr);
     if ($diffstr == "") {
         $diffstr = HtmlBBcodeUtils::bbcode2html($text_alt);
     }
     if ($wrapWithCssClass) {
         $diffstr = HtmlBBcodeUtils::wrapWithTextClass($pre_str_html . $diffstr, $css_width_hack);
     }
     return $diffstr;
 }