Example #1
0
function inline_diff($text1, $text2, $nl)
{
    // create the hacked lines for each file
    $htext1 = chunk_split($text1, 1, "\n");
    $htext2 = chunk_split($text2, 1, "\n");
    // convert the hacked texts to arrays
    // if you have PHP5, you can use str_split:
    /*
    $hlines1 = str_split(htext1, 2);
    $hlines2 = str_split(htext2, 2);
    */
    // otherwise, use this code
    $len1 = strlen($text1);
    $len2 = strlen($text2);
    for ($i = 0; $i < $len1; $i++) {
        $hlines1[$i] = substr($htext1, $i * 2, 2);
    }
    for ($i = 0; $i < $len2; $i++) {
        $hlines2[$i] = substr($htext2, $i * 2, 2);
    }
    /*
    	$text1 = str_replace("\n",$nl,$text1);
    	$text2 = str_replace("\n",$nl,$text2);
    */
    $text1 = str_replace("\n", " \n", $text1);
    $text2 = str_replace("\n", " \n", $text2);
    $hlines1 = explode(" ", $text1);
    $hlines2 = explode(" ", $text2);
    // create the diff object
    $diff = new Text_Diff($hlines1, $hlines2);
    // get the diff in unified format
    // you can add 4 other parameters, which will be the ins/del prefix/suffix tags
    $renderer = new Text_Diff_Renderer_inline(50000);
    return $renderer->render($diff);
}
function dodiff($cur, $prev)
{
    $cur = str_replace("\r", '', $cur);
    $prev = str_replace("\r", '', $prev);
    $diff = new Text_Diff('native', array(explode("\n", $prev), explode("\n", $cur)));
    $renderer = new Text_Diff_Renderer_inline();
    $stuff = nl2br($renderer->render($diff));
    return '<div style="font-family:\'Consolas\',\'Courier New\',monospace; border:1px dashed #ccc; padding: 1em;">' . $stuff . '</div>';
}
 function execute($request)
 {
     parent::execute($request);
     $cat_data = $this->currentCategoryObj->getData();
     $breadcrumbsObj =& AltsysBreadcrumbs::getInstance();
     // get $history_profile from the id
     $older_profile = pico_get_content_history_profile($this->mydirname, $request['older_history_id']);
     if (empty($request['newer_history_id'])) {
         $newer_profile = pico_get_content_history_profile($this->mydirname, 0, intval($older_profile[1]));
     } else {
         $newer_profile = pico_get_content_history_profile($this->mydirname, $request['newer_history_id']);
     }
     // check each content_ids
     if ($older_profile[1] != $newer_profile[1]) {
         die('Differenct content_ids each other');
     }
     $this->contentObj = new PicoContent($this->mydirname, $request['content_id'], $this->currentCategoryObj);
     // add breadcrumbs if the content exists
     if (!$this->contentObj->isError()) {
         $content_data = $this->contentObj->getData();
         $this->assign['content'] = $this->contentObj->getData4html();
         $breadcrumbsObj->appendPath(XOOPS_URL . '/modules/' . $this->mydirname . '/' . $this->assign['content']['link'], $this->assign['content']['subject']);
         $breadcrumbsObj->appendPath(XOOPS_URL . '/modules/' . $this->mydirname . '/index.php?page=contentmanager&amp;content_id=' . $content_data['id'], _MD_PICO_CONTENTMANAGER);
     }
     // permission check by 'can_edit'
     if (empty($cat_data['can_edit'])) {
         redirect_header(XOOPS_URL . '/', 2, _MD_PICO_ERR_EDITCONTENT);
         exit;
     }
     // get diff
     $diff_from_file4disp = '';
     $original_error_level = error_reporting();
     error_reporting($original_error_level & ~E_NOTICE & ~E_WARNING);
     $diff = new Text_Diff(explode("\n", $older_profile[2]), explode("\n", $newer_profile[2]));
     //$renderer = new Text_Diff_Renderer_unified();
     //$diff_str = htmlspecialchars( $renderer->render( $diff ) , ENT_QUOTES ) ;
     $renderer = new Text_Diff_Renderer_inline();
     $this->assign['diff_str'] = $renderer->render($diff);
     error_reporting($original_error_level);
     // breadcrumbs
     $breadcrumbsObj->appendPath('', 'DIFF');
     $this->assign['xoops_breadcrumbs'] = $breadcrumbsObj->getXoopsbreadcrumbs();
     $this->assign['xoops_pagetitle'] = _MD_PICO_HISTORY;
     // view
     $this->view = $request['view'];
     switch ($this->view) {
         case 'diffhistories':
             $this->template_name = $this->mydirname . '_main_diffhistories.html';
             $this->is_need_header_footer = true;
             break;
         default:
             $this->is_need_header_footer = false;
             break;
     }
 }
Example #4
0
/**
 * Render diffence between strings
 *
 * @param string $string_1
 * @param string $string_2
 * @return string
 */
function render_diff($string_1, $string_2)
{
    require_once DIFF_LIB_PATH . '/Diff.php';
    require_once DIFF_LIB_PATH . '/Diff/Renderer.php';
    require_once DIFF_LIB_PATH . '/Diff/Renderer/inline.php';
    $lines_1 = strpos($string_1, "\n") ? explode("\n", $string_1) : array($string_1);
    $lines_2 = strpos($string_2, "\n") ? explode("\n", $string_2) : array($string_2);
    $diff = new Text_Diff('auto', array($lines_1, $lines_2));
    $renderer = new Text_Diff_Renderer_inline();
    return $renderer->render($diff);
}
Example #5
0
 public static function compare($lines1, $lines2)
 {
     if (is_string($lines1)) {
         $lines1 = explode("\n", $lines1);
     }
     if (is_string($lines2)) {
         $lines2 = explode("\n", $lines2);
     }
     $diff = new Text_Diff('auto', array($lines1, $lines2));
     $renderer = new Text_Diff_Renderer_inline();
     return $renderer->render($diff);
 }
Example #6
0
 function render_diff_text($new, $old)
 {
     require_once 'Text/Diff.php';
     require_once 'Text/Diff/Renderer/inline.php';
     $diff = new Text_Diff('auto', array(split("\n", $old), split("\n", $new)));
     $diff_renderer = new Text_Diff_Renderer_inline();
     $diff_value = $diff_renderer->render($diff);
     $form_renderer = AMP_get_renderer();
     if (!$diff_value) {
         $diff_value = htmlentities($new);
     }
     if (!$diff_value) {
         return false;
     }
     return $form_renderer->div($form_renderer->tag('pre', $diff_value), array('class' => 'diff'));
 }
 private function createDiff(&$old_article, &$new_article, &$result)
 {
     $old = "";
     $new = "";
     foreach ($old_article as $key => $value) {
         if (isset($new_article[$key])) {
             $v1 = preg_split("[\n\r]", $value);
             $v2 = preg_split("[\n\r]", $new_article[$key]);
             /* Create the Diff object. */
             $diff = new Text_Diff($v1, $v2);
             /* Output the diff in unified format.*/
             $renderer = new Text_Diff_Renderer_inline();
             $result[] = $renderer->render($diff);
         }
     }
 }
Example #8
0
 public function textDiff($lines1, $lines2)
 {
     require_once APP_PATH . 'core' . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . 'Text' . DIRECTORY_SEPARATOR . 'Diff.php';
     // require_once(APP_PATH.'core'.DIRECTORY_SEPARATOR.'vendor'.DIRECTORY_SEPARATOR.'Text'.DIRECTORY_SEPARATOR.'Diff'.DIRECTORY_SEPARATOR.'Renderer.php');
     require_once APP_PATH . 'core' . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . 'Text' . DIRECTORY_SEPARATOR . 'Diff' . DIRECTORY_SEPARATOR . 'Renderer' . DIRECTORY_SEPARATOR . 'unified.php';
     require_once APP_PATH . 'core' . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . 'Text' . DIRECTORY_SEPARATOR . 'Diff' . DIRECTORY_SEPARATOR . 'Renderer' . DIRECTORY_SEPARATOR . 'context.php';
     require_once APP_PATH . 'core' . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . 'Text' . DIRECTORY_SEPARATOR . 'Diff' . DIRECTORY_SEPARATOR . 'Renderer' . DIRECTORY_SEPARATOR . 'inline.php';
     if (is_string($lines1)) {
         $lines1 = explode("\n", $lines1);
     }
     if (is_string($lines2)) {
         $lines2 = explode("\n", $lines2);
     }
     $diff = new \Text_Diff('auto', array($lines1, $lines2));
     $renderer = new \Text_Diff_Renderer_inline();
     return $renderer->render($diff);
 }
Example #9
0
 function diff($f1, $f2)
 {
     require_once 'InlineDiff/diff.php';
     require_once 'InlineDiff/renderer.php';
     require_once 'InlineDiff/inline.php';
     // Load the lines of each file.
     $c1 = @file_get_contents($f1);
     $c2 = @file_get_contents($f2);
     $lines1 = empty($c1) ? array() : explode("\n", $c1);
     $lines2 = empty($c2) ? array() : explode("\n", $c2);
     $lines1 = $this->mapNewline($lines1);
     $lines2 = $this->mapNewline($lines2);
     // Create the Diff object.
     $diff = new Text_Diff($lines1, $lines2);
     $renderer = new Text_Diff_Renderer_inline();
     global $plugin_ret_diff;
     $plugin_ret_diff = "<pre id=\"diff\">" . $renderer->render($diff) . "</pre>";
     return true;
 }
Example #10
0
function getTextDiff($method, $diff1, $diff2)
{
    switch ($method) {
        case 'unified':
            require_once '/data/project/xtools/textdiff/textdiff/Diff/Renderer/unified.php';
            $diff = new Text_Diff('auto', array(explode("\n", $diff1), explode("\n", $diff2)));
            $renderer = new Text_Diff_Renderer_unified();
            $diff = $renderer->render($diff);
            break;
        case 'inline':
            require_once '/data/project/xtools/textdiff/textdiff/Diff/Renderer/inline.php';
            $diff = new Text_Diff('auto', array(explode("\n", $diff1), explode("\n", $diff2)));
            $renderer = new Text_Diff_Renderer_inline();
            $diff = $renderer->render($diff);
            break;
    }
    unset($renderer);
    return $diff;
}
Example #11
0
 public function getDiffObject($original)
 {
     require_once 'Text/Diff.php';
     require_once 'Text/Diff/Renderer/inline.php';
     $diffObject = new SxCms_Page_Revision();
     $renderer = new Text_Diff_Renderer_inline();
     $titleDiff = new Text_Diff('auto', array(array($original->getTitle()), array($this->getTitle())));
     $titleDiff = $renderer->render($titleDiff) ? $renderer->render($titleDiff) : array_pop($titleDiff->getOriginal());
     $summaryDiff = new Text_Diff('auto', array(array($original->getSummary()), array($this->getSummary())));
     $summaryDiff = $renderer->render($summaryDiff) ? $renderer->render($summaryDiff) : array_pop($summaryDiff->getOriginal());
     $summaryDiff = html_entity_decode($summaryDiff);
     $contentDiff = new Text_Diff('auto', array(array($original->getContent()), array($this->getContent())));
     $contentDiff = $renderer->render($contentDiff) ? $renderer->render($contentDiff) : array_pop($contentDiff->getOriginal());
     $contentDiff = html_entity_decode($contentDiff);
     $sourceDiff = new Text_Diff('auto', array(array($original->getSource()), array($this->getSource())));
     $sourceDiff = $renderer->render($sourceDiff) ? $renderer->render($sourceDiff) : array_pop($sourceDiff->getOriginal());
     $linkDiff = new Text_Diff('auto', array(array($original->getLink()), array($this->getLink())));
     $linkDiff = $renderer->render($linkDiff) ? $renderer->render($linkDiff) : array_pop($linkDiff->getOriginal());
     $diffObject->setLanguage($this->getLanguage())->setTitle($titleDiff)->setSummary($summaryDiff)->setContent($contentDiff)->setSource($sourceDiff)->setLink($linkDiff)->setApproved($this->isApproved());
     return $diffObject;
 }
 public function show_only_difference()
 {
     $renderer = new Text_Diff_Renderer_inline();
     $result = $renderer->render($this->text_diff);
     $lignes = explode("\n", $result);
     $del_continue = false;
     $ins_continue = false;
     $first_trois_points = true;
     $next_points = "";
     $buffer = array();
     foreach ($lignes as $l) {
         $l_inti = $l;
         $return = "";
         if ($del_continue) {
             $return .= "<span class='diff_del'>";
         }
         if ($ins_continue) {
             $return .= "<span class='diff_ins'>";
         }
         if (substr_count($l, '<del>') - substr_count($l, '</del>') > 0) {
             $del_continue = true;
         }
         if (substr_count($l, '<del>') - substr_count($l, '</del>') < 0) {
             $del_continue = false;
         }
         if (substr_count($l, '<ins>') - substr_count($l, '</ins>') > 0) {
             $ins_continue = true;
         }
         if (substr_count($l, '<ins>') - substr_count($l, '</ins>') < 0) {
             $ins_continue = false;
         }
         $l = str_replace("<del>", "<span class='diff_del'>", $l);
         $l = str_replace("<ins>", "<span class='diff_ins'>", $l);
         $l = str_replace("</ins>", "</span>", $l);
         $l = str_replace("</del>", "</span>", $l);
         $return .= $l;
         if ($del_continue) {
             $return .= "</span>";
         }
         if ($ins_continue) {
             $return .= "</span>";
         }
         if ($l_inti != $return) {
             $buffer[] = array(true, $return);
         } else {
             $buffer[] = array(false, $return);
         }
     }
     $return = "<div class='diff_result'><ol class='numbering'>\n";
     $troispoint = false;
     for ($i = 0; $i < count($buffer); $i++) {
         // If there is a modified line 3 before or 3 after this lines we print it ... other wise we print one sigle "..."
         $n1 = max(0, $i - 1);
         $n2 = max(0, $i - 2);
         $n3 = max(0, $i - 3);
         $n4 = $i;
         $n5 = min(count($buffer) - 1, $i + 1);
         $n6 = min(count($buffer) - 1, $i + 2);
         $n7 = min(count($buffer) - 1, $i + 3);
         if ($buffer[$n1][0] || $buffer[$n2][0] || $buffer[$n3][0] || $buffer[$n4][0] || $buffer[$n5][0] || $buffer[$n6][0] || $buffer[$n7][0]) {
             $return .= $next_points;
             $next_points = "";
             $return .= "<li class='numbering_li' value='" . ($i + 1) . "'><pre> " . $buffer[$i][1] . "</pre></li>\n";
             $troispoint = false;
         } else {
             if (!$troispoint) {
                 if ($first_trois_points) {
                     $return .= "</ol><pre> ...</pre>\n";
                     $next_points .= "<ol class='numbering'>\n";
                     $troispoint = true;
                     $first_trois_points = false;
                 } else {
                     $return .= "</ol><pre> ...</pre>\n";
                     $next_points .= "<hr class='diff_hr'/>\n";
                     $next_points .= "<pre> ...</pre>";
                     $next_points .= "<ol class='numbering'>\n";
                     $troispoint = true;
                 }
             }
         }
     }
     if ($next_points == "") {
         $return .= "</ol></div>\n";
     } else {
         $return .= "</div>\n";
     }
     return $return;
 }
Example #13
0
    $from_lines = explode("\n", $from_page["data"][0]["data"]);
    if (isset($_REQUEST["diff_to"]) && $_REQUEST["diff_to"] != $gContent->mInfo["version"]) {
        $to_version = $_REQUEST["diff_to"];
        $to_page = $gContent->getHistory($to_version);
        $to_lines = explode("\n", $to_page["data"][0]["data"]);
    } else {
        $to_version = $gContent->mInfo["version"];
        $to_lines = explode("\n", $gContent->mInfo["data"]);
    }
    /**
     * run 'pear install Text_Diff' to install the library,
     */
    if ($gBitSystem->isFeatureActive('liberty_inline_diff') && @(include_once 'Text/Diff.php')) {
        include_once 'Text/Diff/Renderer/inline.php';
        $diff = new Text_Diff($from_lines, $to_lines);
        $renderer = new Text_Diff_Renderer_inline();
        $html = $renderer->render($diff);
    } else {
        include_once UTIL_PKG_PATH . 'diff.php';
        $diffx = new WikiDiff($from_lines, $to_lines);
        $fmt = new WikiUnifiedDiffFormatter();
        $html = $fmt->format($diffx, $from_lines);
    }
    $gBitSmarty->assign('diffdata', $html);
    $gBitSmarty->assign('diff2', 'y');
    $gBitSmarty->assign('version_from', $from_version);
    $gBitSmarty->assign('version_to', $to_version);
} elseif (@BitBase::verifyId($_REQUEST["compare"])) {
    $from_version = $_REQUEST["compare"];
    $from_page = $gContent->getHistory($from_version);
    $from_page['data'][0]['no_cache'] = TRUE;
Example #14
0
 public static function process($url, $history_call = false, $refresh = false)
 {
     if (MODULE_TIMES) {
         $time = microtime(true);
     }
     $url = str_replace('&amp;', '&', $url);
     //do we need this if we set arg_separator.output to &?
     if ($url) {
         $_POST = array();
         parse_str($url, $_POST);
         if (get_magic_quotes_gpc()) {
             $_POST = undoMagicQuotes($_POST);
         }
         $_GET = $_REQUEST =& $_POST;
     }
     ModuleManager::load_modules();
     self::check_firstrun();
     if ($history_call === '0') {
         History::clear();
     } elseif ($history_call) {
         History::set_id($history_call);
     }
     //on init call methods...
     $ret = on_init(null, null, null, true);
     foreach ($ret as $k) {
         call_user_func_array($k['func'], $k['args']);
     }
     $root =& ModuleManager::create_root();
     self::go($root);
     //go somewhere else?
     $loc = location(null, true);
     //on exit call methods...
     $ret = on_exit(null, null, null, true, $loc === false);
     foreach ($ret as $k) {
         call_user_func_array($k['func'], $k['args']);
     }
     if ($loc !== false) {
         if (isset($_REQUEST['__action_module__'])) {
             $loc['__action_module__'] = $_REQUEST['__action_module__'];
         }
         //clean up
         foreach (self::$content as $k => $v) {
             unset(self::$content[$k]);
         }
         foreach (self::$jses as $k => $v) {
             if ($v[1]) {
                 unset(self::$jses[$k]);
             }
         }
         //go
         $loc['__location'] = microtime(true);
         return self::process(http_build_query($loc), false, true);
     }
     $debug = '';
     if (DEBUG && ($debug_diff = @(include_once 'tools/Diff.php'))) {
         require_once 'tools/Text/Diff/Renderer/inline.php';
         $diff_renderer = new Text_Diff_Renderer_inline();
     }
     //clean up old modules
     if (isset($_SESSION['client']['__module_content__'])) {
         $to_cleanup = array_keys($_SESSION['client']['__module_content__']);
         foreach ($to_cleanup as $k) {
             $mod = ModuleManager::get_instance($k);
             if ($mod === null) {
                 $xx = explode('/', $k);
                 $yy = explode('|', $xx[count($xx) - 1]);
                 $mod = $yy[0];
                 if (is_callable(array($mod . 'Common', 'destroy'))) {
                     call_user_func(array($mod . 'Common', 'destroy'), $k, isset($_SESSION['client']['__module_vars__'][$k]) ? $_SESSION['client']['__module_vars__'][$k] : null);
                 }
                 if (DEBUG) {
                     $debug .= 'Clearing mod vars & module content ' . $k . '<br>';
                 }
                 unset($_SESSION['client']['__module_vars__'][$k]);
                 unset($_SESSION['client']['__module_content__'][$k]);
             }
         }
     }
     $reloaded = array();
     foreach (self::$content as $k => $v) {
         $reload = $v['module']->get_reload();
         $parent = $v['module']->get_parent_path();
         if (DEBUG && REDUCING_TRANSFER) {
             $debug .= '<hr style="height: 3px; background-color:black">';
             $debug .= '<b> Checking ' . $k . ', &nbsp;&nbsp;&nbsp; parent=' . $v['module']->get_parent_path() . '</b><ul>' . '<li>Force - ' . (isset($reload) ? print_r($reload, true) : 'not set') . '</li>' . '<li>First display - ' . (isset($_SESSION['client']['__module_content__'][$k]) ? 'no</li>' . '<li>Content changed - ' . ($_SESSION['client']['__module_content__'][$k]['value'] !== $v['value'] ? 'yes' : 'no') . '</li>' . '<li>JS changed - ' . ($_SESSION['client']['__module_content__'][$k]['js'] !== $v['js'] ? 'yes' : 'no') : 'yes') . '</li>' . '<li>Parent reloaded - ' . (isset($reloaded[$parent]) ? 'yes' : 'no') . '</li>' . '<li>History call - ' . ($history_call ? 'yes' : 'no') . '</li>' . '</ul>';
         }
         if (!REDUCING_TRANSFER || (!isset($reload) && (!isset($_SESSION['client']['__module_content__'][$k]) || $_SESSION['client']['__module_content__'][$k]['value'] !== $v['value'] || $_SESSION['client']['__module_content__'][$k]['js'] !== $v['js']) || $history_call || $reload == true || isset($reloaded[$parent]))) {
             //force reload or parent reloaded
             if (DEBUG && isset($_SESSION['client']['__module_content__'])) {
                 $debug .= '<b>Reloading: ' . (isset($v['span']) ? ';&nbsp;&nbsp;&nbsp;&nbsp;span=' . $v['span'] . ',' : '') . '&nbsp;&nbsp;&nbsp;&nbsp;triggered=' . ($reload == true ? 'force' : 'auto') . ',&nbsp;&nbsp;</b><hr><b>New value:</b><br><pre>' . htmlspecialchars($v['value']) . '</pre>' . (isset($_SESSION['client']['__module_content__'][$k]['value']) ? '<hr><b>Old value:</b><br><pre>' . htmlspecialchars($_SESSION['client']['__module_content__'][$k]['value']) . '</pre>' : '');
                 if ($debug_diff && isset($_SESSION['client']['__module_content__'][$k]['value'])) {
                     $xxx = new Text_Diff(explode("\n", $_SESSION['client']['__module_content__'][$k]['value']), explode("\n", $v['value']));
                     $debug .= '<hr><b>Diff:</b><br><pre>' . $diff_renderer->render($xxx) . '</pre>';
                 }
                 $debug .= '<hr style="height: 5px; background-color:black">';
             }
             if (isset($v['span'])) {
                 self::text($v['value'], $v['span']);
             }
             if ($v['js']) {
                 self::js(join(";", $v['js']));
             }
             if (REDUCING_TRANSFER) {
                 $_SESSION['client']['__module_content__'][$k]['value'] = $v['value'];
                 $_SESSION['client']['__module_content__'][$k]['js'] = $v['js'];
             }
             $_SESSION['client']['__module_content__'][$k]['parent'] = $parent;
             $reloaded[$k] = true;
             if (method_exists($v['module'], 'reloaded')) {
                 $v['module']->reloaded();
             }
         }
     }
     foreach ($_SESSION['client']['__module_content__'] as $k => $v) {
         if (!array_key_exists($k, self::$content) && isset($reloaded[$v['parent']])) {
             if (DEBUG) {
                 $debug .= 'Reloading missing ' . $k . '<hr>';
             }
             if (isset($v['span'])) {
                 self::text($v['value'], $v['span']);
             }
             if (isset($v['js']) && $v['js']) {
                 self::js(join(";", $v['js']));
             }
             $reloaded[$k] = true;
         }
     }
     if (DEBUG) {
         $debug .= 'vars ' . CID . ': ' . print_r($_SESSION['client']['__module_vars__'], true) . '<br>';
         $debug .= 'user='******'<br>';
         if (isset($_REQUEST['__action_module__'])) {
             $debug .= 'action module=' . $_REQUEST['__action_module__'] . '<br>';
         }
     }
     $debug .= self::debug();
     if (MODULE_TIMES) {
         foreach (self::$content as $k => $v) {
             $style = 'color:red;font-weight:bold';
             if ($v['time'] < 0.5) {
                 $style = 'color:orange;font-weight:bold';
             }
             if ($v['time'] < 0.05) {
                 $style = 'color:green;font-weight:bold';
             }
             $debug .= 'Time of loading module <b>' . $k . '</b>: <i>' . '<span style="' . $style . ';">' . number_format($v['time'], 4) . '</span>' . '</i><br>';
         }
         $debug .= 'Page renderered in ' . (microtime(true) - $time) . 's<hr>';
     }
     if (SQL_TIMES) {
         $debug .= '<font size="+1">QUERIES</font><br>';
         $queries = DB::GetQueries();
         $sum = 0;
         $qty = 0;
         foreach ($queries as $kk => $q) {
             $style = 'color:red;font-weight:bold';
             if ($q['time'] < 0.5) {
                 $style = 'color:orange;font-weight:bold';
             }
             if ($q['time'] < 0.05) {
                 $style = 'color:green';
             }
             for ($kkk = 0; $kkk < $kk; $kkk++) {
                 if ($queries[$kkk]['args'] == $q['args']) {
                     $style .= ';text-decoration:underline';
                 }
             }
             $debug .= '<span style="' . $style . ';">' . '<b>' . $q['func'] . '</b> ' . htmlspecialchars(var_export($q['args'], true)) . ' <i><b>' . number_format($q['time'], 4) . '</b></i>' . (isset($q['caller']) ? ', ' . $q['caller'] : '') . '<br>' . '</span>';
             $sum += $q['time'];
             $qty++;
         }
         $debug .= '<b>Number of queries:</b> ' . $qty . '<br>';
         $debug .= '<b>Queries times:</b> ' . $sum . '<br>';
     }
     if (!isset($_SESSION['client']['custom_debug']) || $debug != $_SESSION['client']['custom_debug']) {
         self::text($debug, 'debug');
         if ($debug) {
             Epesi::js("\$('debug_content').style.display='block';");
         }
         $_SESSION['client']['custom_debug'] = $debug;
     }
     if (!$history_call && !History::soft_call()) {
         History::set();
     }
     if (!$history_call) {
         self::js('Epesi.history_add(' . History::get_id() . ')');
     }
     self::send_output();
 }
Example #15
0
function log_diff($fromvalue,$tovalue)	
	{
	# Forumlate descriptive text to describe the change made to a metadata field.

	# Remove any database escaping
	$fromvalue=str_replace("\\","",$fromvalue);
	$tovalue=str_replace("\\","",$tovalue);
	
	if (substr($fromvalue,0,1)==",")
		{
		# Work a different way for checkbox lists.
		$fromvalue=explode(",",i18n_get_translated($fromvalue));
		$tovalue=explode(",",i18n_get_translated($tovalue));
		
		# Get diffs
		$inserts=array_diff($tovalue,$fromvalue);
		$deletes=array_diff($fromvalue,$tovalue);

		# Process array diffs into meaningful strings.
		$return="";
		if (count($deletes)>0)
			{
			$return.="- " . join("\n- " , $deletes);
			}
		if (count($inserts)>0)
			{
			if ($return!="") {$return.="\n";}
			$return.="+ " . join("\n+ ", $inserts);
			}
		
		#debug($return);
		return $return;
		}

	# For standard strings, use Text_Diff
		
	require_once dirname(__FILE__).'/../lib/Text_Diff/Diff.php';
	require_once dirname(__FILE__).'/../lib/Text_Diff/Diff/Renderer/inline.php';

	$lines1 = explode("\n",$fromvalue);
	$lines2 = explode("\n",$tovalue);

	$diff     = new Text_Diff('native', array($lines1, $lines2));
	$renderer = new Text_Diff_Renderer_inline();
	$diff=$renderer->render($diff);
	
	$return="";

	# The inline diff syntax places inserts within <ins></ins> tags and deletes within <del></del> tags.

	# Handle deletes
	if (strpos($diff,"<del>")!==false)
		{
		$s=explode("<del>",$diff);
		for ($n=1;$n<count($s);$n++)
			{
			$t=explode("</del>",$s[$n]);
			if ($return!="") {$return.="\n";}
			$return.="- " . trim(i18n_get_translated($t[0]));
			}
		}
	# Handle inserts
	if (strpos($diff,"<ins>")!==false)
		{
		$s=explode("<ins>",$diff);
		for ($n=1;$n<count($s);$n++)
			{
			$t=explode("</ins>",$s[$n]);
			if ($return!="") {$return.="\n";}
			$return.="+ " . trim(i18n_get_translated($t[0]));
			}
		}


	#debug ($return);
	return $return;
	}
Example #16
0
function fn_text_diff($source, $dest, $side_by_side = false)
{
    $diff = new Text_Diff('auto', array(explode("\n", $source), explode("\n", $dest)));
    $renderer = new Text_Diff_Renderer_inline();
    if ($side_by_side == false) {
        $renderer->_split_level = 'words';
    }
    $res = $renderer->render($diff);
    if ($side_by_side == true) {
        $res = $renderer->sideBySide($res);
    }
    return $res;
}
Example #17
0
 /**
  * Gets an HTML diff output between the records at $id1 and $id2 
  * respectively, where $id1 and $id2 are history ids from the history__id
  * column of the history table.
  * @param string $tablename The name of the base table.
  * @param integer $id1 The id number of the first record (from the history__id column)
  * @param integer $id2 The id of the second record (from the history__id column)
  * @param string $fieldname Optional name of a field to return.
  * @returns mixed Either the value of the specified field name if $fieldname is specified,
  *			or a Dataface_Record object whose field values are formatted diffs.
  */
 function getDiffs($tablename, $id1, $id2 = null, $fieldname = null)
 {
     import('Text/Diff.php');
     import('Text/Diff/Renderer/inline.php');
     $htablename = $tablename . '__history';
     if (!Dataface_Table::tableExists($htablename)) {
         return PEAR::raiseError(df_translate('scripts.Dataface.HistoryTool.getDiffs.ERROR_HISTORY_TABLE_DOES_NOT_EXIST', "History table for '{$tablename}' does not exist, so we cannot obtain changes for records of that table.", array('tablename' => $tablename)), DATAFACE_E_ERROR);
     }
     $rec1 = df_get_record($htablename, array('history__id' => $id1));
     if (!isset($id2)) {
         // The 2nd id wasn't provided so we assume we want to know the diffs
         // against the current state of the record.
         $table =& Dataface_Table::loadTable($tablename);
         $query = $rec1->strvals(array_keys($table->keys()));
         $io = new Dataface_IO($tablename);
         $io->lang = $rec1->val('history__language');
         $rec2 = new Dataface_Record($tablename, array());
         $io->read($query, $rec2);
     } else {
         $rec2 = df_get_record($htablename, array('history__id' => $id2));
     }
     $vals1 = $rec1->strvals();
     $vals2 = $rec2->strvals();
     $vals_diff = array();
     $renderer = new Text_Diff_Renderer_inline();
     foreach ($vals2 as $key => $val) {
         $diff = new Text_Diff(explode("\n", @$vals1[$key]), explode("\n", $val));
         $vals_diff[$key] = $renderer->render($diff);
     }
     $diff_rec = new Dataface_Record($htablename, $vals_diff);
     if (isset($fieldname)) {
         return $diff_rec->val($fieldname);
     }
     return $diff_rec;
 }
Example #18
0
 public function compare()
 {
     require_once APP_PATH . '/../Text/Diff.php';
     require_once APP_PATH . '/../Text/Diff/Renderer.php';
     require_once APP_PATH . '/../Text/Diff/Renderer/inline.php';
     $page_id = I("page_id");
     $history_id = I("page_history_id");
     $diff_type = I("diff_type");
     $page = D("Page")->where(" page_id = '{$page_id}' ")->find();
     $history = D("PageHistory")->where(" page_history_id = '{$history_id}' ")->find();
     $lines1 = htmlspecialchars_decode($page['page_content']);
     $lines2 = htmlspecialchars_decode($history['page_content']);
     is_string($lines1) && ($lines1 = explode("\n", $lines1));
     is_string($lines2) && ($lines2 = explode("\n", $lines2));
     $diff = new \Text_Diff('auto', array($lines2, $lines1));
     $renderer = new \Text_Diff_Renderer_inline();
     $diffResutl = $renderer->render($diff);
     $this->assign("diffResutl", $diffResutl);
     $this->assign("page_id", $page_id);
     $this->assign("page_history_id", $history_id);
     $this->assign("item_id", $page['item_id']);
     $this->display();
 }
 public function executeDiff()
 {
     $this->setPage();
     // $this->revision is revision2
     $this->forward403Unless($this->canView);
     $this->forward404If($this->page->isNew());
     $this->forward404If($this->revision->isNew());
     // Source revision
     $c = new Criteria();
     $c->add(nahoWikiRevisionPeer::PAGE_ID, $this->page->getId());
     $c->add(nahoWikiRevisionPeer::REVISION, $this->getRequestParameter('oldRevision'));
     $this->revision1 = nahoWikiRevisionPeer::doSelectOne($c);
     $this->forward404Unless($this->revision1);
     // Dest revision
     $this->revision2 = $this->revision;
     // Make diff
     $lines1 = explode("\n", $this->revision1->getContent());
     $lines2 = explode("\n", $this->revision2->getContent());
     $diff = new Text_Diff('auto', array($lines1, $lines2));
     switch ($this->getRequestParameter('mode', 'inline')) {
         case 'unified':
             $renderer = new Text_Diff_Renderer_unified();
             break;
         case 'context':
             $renderer = new Text_Diff_Renderer_context();
             break;
         case 'inline':
         default:
             $renderer = new Text_Diff_Renderer_inline();
             break;
     }
     $this->diff = $renderer->render($diff);
     // Direct download
     if ($this->getRequestParameter('raw')) {
         $this->getResponse()->setContentType('text/plain');
         $this->renderText($this->diff);
         return sfView::NONE;
     }
     return sfView::SUCCESS;
 }
Example #20
0
 /**
  * Get history
  */
 public function getHistory()
 {
     $tbl_wiki = $this->tbl_wiki;
     $condition_session = $this->condition_session;
     $groupfilter = $this->groupfilter;
     $page = $this->page;
     $course_id = $this->course_id;
     $session_id = $this->session_id;
     $userId = api_get_user_id();
     if (!$_GET['title']) {
         self::setMessage(Display::display_error_message(get_lang("MustSelectPage"), false, true));
         return;
     }
     /* First, see the property visibility that is at the last register and
        therefore we should select descending order.
        But to give ownership to each record,
        this is no longer necessary except for the title. TODO: check this*/
     $sql = 'SELECT * FROM ' . $tbl_wiki . '
             WHERE
                 c_id = ' . $course_id . ' AND
                 reflink="' . Database::escape_string($page) . '" AND
                 ' . $groupfilter . $condition_session . '
             ORDER BY id DESC';
     $result = Database::query($sql);
     $KeyVisibility = null;
     $KeyAssignment = null;
     $KeyTitle = null;
     $KeyUserId = null;
     while ($row = Database::fetch_array($result)) {
         $KeyVisibility = $row['visibility'];
         $KeyAssignment = $row['assignment'];
         $KeyTitle = $row['title'];
         $KeyUserId = $row['user_id'];
     }
     $icon_assignment = null;
     if ($KeyAssignment == 1) {
         $icon_assignment = Display::return_icon('wiki_assignment.png', get_lang('AssignmentDescExtra'), '', ICON_SIZE_SMALL);
     } elseif ($KeyAssignment == 2) {
         $icon_assignment = Display::return_icon('wiki_work.png', get_lang('AssignmentWorkExtra'), '', ICON_SIZE_SMALL);
     }
     // Second, show
     //if the page is hidden and is a job only sees its author and professor
     if ($KeyVisibility == 1 || api_is_allowed_to_edit(false, true) || api_is_platform_admin() || $KeyAssignment == 2 && $KeyVisibility == 0 && $userId == $KeyUserId) {
         // We show the complete history
         if (!isset($_POST['HistoryDifferences']) && !isset($_POST['HistoryDifferences2'])) {
             $sql = 'SELECT * FROM ' . $tbl_wiki . '
                     WHERE
                         c_id = ' . $course_id . ' AND
                         reflink="' . Database::escape_string($page) . '" AND
                         ' . $groupfilter . $condition_session . '
                     ORDER BY id DESC';
             $result = Database::query($sql);
             $title = $_GET['title'];
             $group_id = api_get_group_id();
             echo '<div id="wikititle">';
             echo $icon_assignment . '&nbsp;&nbsp;&nbsp;' . api_htmlentities($KeyTitle);
             echo '</div>';
             echo '<form id="differences" method="POST" action="index.php?' . api_get_cidreq() . '&action=history&title=' . api_htmlentities(urlencode($title)) . '&session_id=' . api_htmlentities($session_id) . '&group_id=' . api_htmlentities($group_id) . '">';
             echo '<ul style="list-style-type: none;">';
             echo '<br/>';
             echo '<button class="search" type="submit" name="HistoryDifferences" value="HistoryDifferences">' . get_lang('ShowDifferences') . ' ' . get_lang('LinesDiff') . '</button>';
             echo '<button class="search" type="submit" name="HistoryDifferences2" value="HistoryDifferences2">' . get_lang('ShowDifferences') . ' ' . get_lang('WordsDiff') . '</button>';
             echo '<br/><br/>';
             $counter = 0;
             $total_versions = Database::num_rows($result);
             while ($row = Database::fetch_array($result)) {
                 $userinfo = api_get_user_info($row['user_id']);
                 $username = api_htmlentities(sprintf(get_lang('LoginX'), $userinfo['username']), ENT_QUOTES);
                 echo '<li style="margin-bottom: 5px;">';
                 $counter == 0 ? $oldstyle = 'style="visibility: hidden;"' : ($oldstyle = '');
                 $counter == 0 ? $newchecked = ' checked' : ($newchecked = '');
                 $counter == $total_versions - 1 ? $newstyle = 'style="visibility: hidden;"' : ($newstyle = '');
                 $counter == 1 ? $oldchecked = ' checked' : ($oldchecked = '');
                 echo '<input name="old" value="' . $row['id'] . '" type="radio" ' . $oldstyle . ' ' . $oldchecked . '/> ';
                 echo '<input name="new" value="' . $row['id'] . '" type="radio" ' . $newstyle . ' ' . $newchecked . '/> ';
                 echo '<a href="' . api_get_self() . '?action=showpage&title=' . api_htmlentities(urlencode($page)) . '&view=' . $row['id'] . '">';
                 echo '<a href="' . api_get_self() . '?' . api_get_cidreq() . '&action=showpage&title=' . api_htmlentities(urlencode($page)) . '&view=' . $row['id'] . '">';
                 echo api_get_local_time($row['dtime'], null, date_default_timezone_get());
                 echo '</a>';
                 echo ' (' . get_lang('Version') . ' ' . $row['version'] . ')';
                 echo ' ' . get_lang('By') . ' ';
                 if ($row['user_id'] != 0) {
                     echo UserManager::getUserProfileLink($userinfo);
                 } else {
                     echo get_lang('Anonymous') . ' (' . api_htmlentities($row['user_ip']) . ')';
                 }
                 echo ' ( ' . get_lang('Progress') . ': ' . api_htmlentities($row['progress']) . '%, ';
                 $comment = $row['comment'];
                 if (!empty($comment)) {
                     echo get_lang('Comments') . ': ' . api_htmlentities(api_substr($row['comment'], 0, 100));
                     if (api_strlen($row['comment']) > 100) {
                         echo '... ';
                     }
                 } else {
                     echo get_lang('Comments') . ':  ---';
                 }
                 echo ' ) </li>';
                 $counter++;
             }
             //end while
             echo '<br/>';
             echo '<button class="search" type="submit" name="HistoryDifferences" value="HistoryDifferences">' . get_lang('ShowDifferences') . ' ' . get_lang('LinesDiff') . '</button>';
             echo '<button class="search" type="submit" name="HistoryDifferences2" value="HistoryDifferences2">' . get_lang('ShowDifferences') . ' ' . get_lang('WordsDiff') . '</button>';
             echo '</ul></form>';
         } else {
             // We show the differences between two versions
             $version_old = array();
             if (isset($_POST['old'])) {
                 $sql_old = "SELECT * FROM {$tbl_wiki}\n                                WHERE c_id = {$course_id} AND id='" . Database::escape_string($_POST['old']) . "'";
                 $result_old = Database::query($sql_old);
                 $version_old = Database::fetch_array($result_old);
             }
             $sql_new = "SELECT * FROM {$tbl_wiki}\n                            WHERE c_id = {$course_id} AND id='" . Database::escape_string($_POST['new']) . "'";
             $result_new = Database::query($sql_new);
             $version_new = Database::fetch_array($result_new);
             $oldTime = isset($version_old['dtime']) ? $version_old['dtime'] : null;
             $oldContent = isset($version_old['content']) ? $version_old['content'] : null;
             if (isset($_POST['HistoryDifferences'])) {
                 include 'diff.inc.php';
                 //title
                 echo '<div id="wikititle">' . api_htmlentities($version_new['title']) . '
                         <font size="-2"><i>(' . get_lang('DifferencesNew') . '</i>
                         <font style="background-color:#aaaaaa">' . $version_new['dtime'] . '</font>
                         <i>' . get_lang('DifferencesOld') . '</i>
                         <font style="background-color:#aaaaaa">' . $oldTime . '</font>
             ) ' . get_lang('Legend') . ':  <span class="diffAdded" >' . get_lang('WikiDiffAddedLine') . '</span>
             <span class="diffDeleted" >' . get_lang('WikiDiffDeletedLine') . '</span> <span class="diffMoved">' . get_lang('WikiDiffMovedLine') . '</span></font>
             </div>';
             }
             if (isset($_POST['HistoryDifferences2'])) {
                 //title
                 echo '<div id="wikititle">' . api_htmlentities($version_new['title']) . '
                     <font size="-2"><i>(' . get_lang('DifferencesNew') . '</i> <font style="background-color:#aaaaaa">' . $version_new['dtime'] . '</font>
                     <i>' . get_lang('DifferencesOld') . '</i> <font style="background-color:#aaaaaa">' . $oldTime . '</font>)
                     ' . get_lang('Legend') . ':  <span class="diffAddedTex" >' . get_lang('WikiDiffAddedTex') . '</span>
                     <span class="diffDeletedTex" >' . get_lang('WikiDiffDeletedTex') . '</span></font></div>';
             }
             if (isset($_POST['HistoryDifferences'])) {
                 echo '<table>' . diff($oldContent, $version_new['content'], true, 'format_table_line') . '</table>';
                 // format_line mode is better for words
                 echo '<br />';
                 echo '<strong>' . get_lang('Legend') . '</strong><div class="diff">' . "\n";
                 echo '<table><tr>';
                 echo '<td>';
                 echo '</td><td>';
                 echo '<span class="diffEqual" >' . get_lang('WikiDiffUnchangedLine') . '</span><br />';
                 echo '<span class="diffAdded" >' . get_lang('WikiDiffAddedLine') . '</span><br />';
                 echo '<span class="diffDeleted" >' . get_lang('WikiDiffDeletedLine') . '</span><br />';
                 echo '<span class="diffMoved" >' . get_lang('WikiDiffMovedLine') . '</span><br />';
                 echo '</td>';
                 echo '</tr></table>';
             }
             if (isset($_POST['HistoryDifferences2'])) {
                 $lines1 = array(strip_tags($oldContent));
                 //without <> tags
                 $lines2 = array(strip_tags($version_new['content']));
                 //without <> tags
                 $diff = new Text_Diff($lines1, $lines2);
                 $renderer = new Text_Diff_Renderer_inline();
                 echo '<style>del{background:#fcc}ins{background:#cfc}</style>' . $renderer->render($diff);
                 // Code inline
                 echo '<br />';
                 echo '<strong>' . get_lang('Legend') . '</strong><div class="diff">' . "\n";
                 echo '<table><tr>';
                 echo '<td>';
                 echo '</td><td>';
                 echo '<span class="diffAddedTex" >' . get_lang('WikiDiffAddedTex') . '</span><br />';
                 echo '<span class="diffDeletedTex" >' . get_lang('WikiDiffDeletedTex') . '</span><br />';
                 echo '</td>';
                 echo '</tr></table>';
             }
         }
     }
 }
Example #21
0
--TEST--
Text_Diff: Inline renderer
--FILE--
<?php 
include_once 'Text/Diff.php';
include_once 'Text/Diff/Renderer/inline.php';
$lines1 = file(dirname(__FILE__) . '/1.txt');
$lines2 = file(dirname(__FILE__) . '/2.txt');
$diff = new Text_Diff('native', array($lines1, $lines2));
$renderer = new Text_Diff_Renderer_inline();
echo $renderer->render($diff);
?>
--EXPECT--
This line is the same.
This line is different in <del>1.txt</del><ins>2.txt</ins>
This line is the same.
Example #22
0
 /**
  * Get a html diff between two versions.
  *
  * @param string latest_revision id of the latest revision
  * @param string oldest_revision id of the oldest revision
  * @return array array with the original value, the new value and a diff -u
  */
 public function get_diff($oldest_revision, $latest_revision, $renderer_style = 'inline')
 {
     if (!class_exists('Text_Diff')) {
         @(include_once 'Text/Diff.php');
         @(include_once 'Text/Diff/Renderer.php');
         @(include_once 'Text/Diff/Renderer/unified.php');
         @(include_once 'Text/Diff/Renderer/inline.php');
         if (!class_exists('Text_Diff')) {
             throw new midcom_error("Failed to load Text_Diff library.");
         }
     }
     $oldest = $this->get_revision($oldest_revision);
     $newest = $this->get_revision($latest_revision);
     $return = array();
     foreach ($oldest as $attribute => $oldest_value) {
         if (!array_key_exists($attribute, $newest)) {
             continue;
             // This isn't in the newer version, skip
         }
         if (is_array($oldest_value)) {
             continue;
             // Skip
         }
         $return[$attribute] = array('old' => $oldest_value, 'new' => $newest[$attribute]);
         if ($oldest_value != $newest[$attribute]) {
             $lines1 = explode("\n", $oldest_value);
             $lines2 = explode("\n", $newest[$attribute]);
             $diff = new Text_Diff($lines1, $lines2);
             if ($renderer_style == 'unified') {
                 $renderer = new Text_Diff_Renderer_unified();
             } else {
                 $renderer = new Text_Diff_Renderer_inline();
             }
             if (!$diff->isEmpty()) {
                 // Run the diff
                 $return[$attribute]['diff'] = $renderer->render($diff);
                 if ($renderer_style == 'inline') {
                     // Modify the output for nicer rendering
                     $return[$attribute]['diff'] = str_replace('<del>', "<span class=\"deleted\" title=\"removed in {$latest_revision}\">", $return[$attribute]['diff']);
                     $return[$attribute]['diff'] = str_replace('</del>', '</span>', $return[$attribute]['diff']);
                     $return[$attribute]['diff'] = str_replace('<ins>', "<span class=\"inserted\" title=\"added in {$latest_revision}\">", $return[$attribute]['diff']);
                     $return[$attribute]['diff'] = str_replace('</ins>', '</span>', $return[$attribute]['diff']);
                 }
             }
         }
     }
     return $return;
 }
Example #23
0
if (session_admin()) {
    $level++;
}
$current = db_single('select * from sitewiki_page where id = ?', $cgi->page);
if (!$current) {
    echo rpc_response(false);
    exit;
}
$revision = db_single('select * from sitewiki_page_sv where id = ? and sv_autoid = ?', $cgi->page, $cgi->rev);
if (!$revision) {
    echo rpc_response(false);
    exit;
}
if ($current->view_level > $level && $current->owner != session_username()) {
    echo rpc_response(false);
    exit;
}
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
    $join = ';';
} else {
    $join = ':';
}
ini_set('include_path', 'inc/app/sitewiki/lib/Ext' . $join . ini_get('include_path'));
loader_import('sitewiki.Ext.Text.Diff');
loader_import('sitewiki.Ext.Text.Diff.Renderer');
loader_import('sitewiki.Ext.Text.Diff.Renderer.inline');
$diff = new Text_Diff(explode("\n", $revision->body), explode("\n", $current->body));
$renderer = new Text_Diff_Renderer_inline();
$out = $renderer->render($diff);
echo rpc_response($out);
exit;
Example #24
0
/**
 * Uses the pear Text_Diff library to generate a diff between two files.
 * The only HTML-tags allowed are <p> and <div>, all other will be stripped.
 * @param string $text1 The first text
 * @param string $text2 The text to compare
 * @return string
 */
function diff($text1, $text2)
{
    __autoload('TextDiff');
    include_once 'Text/Diff.php';
    include_once 'Text/Diff/Renderer.php';
    include_once 'Text/Diff/Renderer/unified.php';
    $vtext1 = chunk_split(strip_tags($text1, '<p><div>'), 1, "\n");
    $vtext2 = chunk_split(strip_tags($text2, '<p><div>'), 1, "\n");
    $vlines1 = str_split($vtext1, 2);
    $vlines2 = str_split($vtext2, 2);
    $text1 = str_replace("\n", " \n", $text1);
    $text2 = str_replace("\n", " \n", $text2);
    $vlines1 = explode(" ", $text1);
    $vlines2 = explode(" ", $text2);
    $diff = new Text_Diff($vlines1, $vlines2);
    $renderer = new Text_Diff_Renderer_inline();
    $html = html_entity_decode($renderer->render($diff));
    return preg_replace(array('#(<ins>|<del>)(<[^\\>]+>)#i', '#(</[^\\>]+>)(</ins>|</del>)#i'), '$2$1', $html);
}
Example #25
0
 $query = $db->simple_select("templates", "*", "title='" . $db->escape_string($mybb->input['title']) . "' AND sid='" . intval($mybb->input['sid2']) . "'");
 $template2 = $db->fetch_array($query);
 if ($mybb->input['sid2'] == -2) {
     $sub_tabs['full_edit'] = array('title' => $lang->full_edit, 'link' => "index.php?module=style/templates&action=edit_template&title=" . urlencode($template1['title']) . "&sid=" . intval($mybb->input['sid1']) . "&amp;from=diff_report");
 }
 if ($template1['template'] == $template2['template']) {
     flash_message($lang->templates_the_same, 'error');
     admin_redirect("index.php?module=style/templates&sid=" . intval($mybb->input['sid2']) . $expand_str);
 }
 $template1['template'] = explode("\n", $template1['template']);
 $template2['template'] = explode("\n", $template2['template']);
 $plugins->run_hooks("admin_style_templates_diff_report_run");
 require_once MYBB_ROOT . "inc/3rdparty/diff/Diff.php";
 require_once MYBB_ROOT . "inc/3rdparty/diff/Diff/Renderer/inline.php";
 $diff = new Text_Diff('auto', array($template1['template'], $template2['template']));
 $renderer = new Text_Diff_Renderer_inline();
 if ($sid) {
     $page->add_breadcrumb_item($template_sets[$sid], "index.php?module=style/templates&amp;sid={$sid}{$expand_str}");
 }
 if ($mybb->input['sid2'] == -2) {
     $page->add_breadcrumb_item($lang->find_updated, "index.php?module=style/templates&amp;action=find_updated");
 }
 $page->add_breadcrumb_item($lang->diff_report . ": " . $template1['title'], "index.php?module=style/templates&amp;action=diff_report&amp;title=" . $db->escape_string($mybb->input['title']) . "&amp;sid1=" . intval($mybb->input['sid1']) . "&amp;sid2=" . intval($mybb->input['sid2']));
 $page->output_header($lang->template_sets);
 $page->output_nav_tabs($sub_tabs, 'diff_report');
 $table = new Table();
 $table->construct_header("<ins>" . $lang->master_updated_ins . "</ins><br /><del>" . $lang->master_updated_del . "</del>");
 $table->construct_cell("<pre class=\"differential\">" . $renderer->render($diff) . "</pre>");
 $table->construct_row();
 $table->output($lang->template_diff_analysis . ": " . $template1['title']);
 $page->output_footer();
     }
     $old_array = explode("\n", $second);
     $new_array = explode("\n", $first);
     // diff-methode festlegen
     if ($environment["parameter"][7] != "") {
         $diff_type = $environment["parameter"][7];
     } else {
         $diff_type = $cfg["contented"]["diff_engine"];
     }
     if ($diff_type == "phpdiff3") {
         $diff = phpdiff3($second, $first);
     } elseif (strstr($diff_type, "phpdiff")) {
         $diff = arr_diff($old_array, $new_array);
     } else {
         $diff = new Text_Diff('auto', array($old_array, $new_array));
         $renderer = new Text_Diff_Renderer_inline();
         $diff = str_replace("\n", "<br>", $renderer->render($diff));
     }
     $ausgaben["diff"] = $diff;
 }
 // form options holen
 $form_options = form_options(eCRC($environment["ebene"]) . "." . $environment["kategorie"]);
 // form elememte bauen
 $element = form_elements($cfg["contented"]["db"]["leer"]["entries"], $form_values);
 // form elemente erweitern
 $element["extension1"] = "<input name=\"extension1\" type=\"text\" maxlength=\"5\" size=\"5\">";
 $element["extension2"] = "<input name=\"extension2\" type=\"text\" maxlength=\"5\" size=\"5\">";
 // +++
 // page basics
 // funktions bereich fuer erweiterungen
 // ***
Example #27
0
 function _changed($orig, $final)
 {
     /* If we've already split on words, don't try to do so again - just
      * display. */
     if ($this->_split_level == 'words') {
         $prefix = '';
         while ($orig[0] !== false && $final[0] !== false && substr($orig[0], 0, 1) == ' ' && substr($final[0], 0, 1) == ' ') {
             $prefix .= substr($orig[0], 0, 1);
             $orig[0] = substr($orig[0], 1);
             $final[0] = substr($final[0], 1);
         }
         return $prefix . $this->_deleted($orig) . $this->_added($final);
     }
     $text1 = implode("\n", $orig);
     $text2 = implode("\n", $final);
     /* Non-printing newline marker. */
     $nl = "";
     /* We want to split on word boundaries, but we need to
      * preserve whitespace as well. Therefore we split on words,
      * but include all blocks of whitespace in the wordlist. */
     $diff = new Text_Diff($this->_splitOnWords($text1, $nl), $this->_splitOnWords($text2, $nl));
     /* Get the diff in inline format. */
     $renderer = new Text_Diff_Renderer_inline(array_merge($this->getParams(), array('split_level' => 'words')));
     /* Run the diff and get the output. */
     return str_replace($nl, "\n", $renderer->render($diff)) . "\n";
 }
Example #28
0
 public function get_Text_Diff_Renderer_inline()
 {
     $renderer = new Text_Diff_Renderer_inline();
     return $renderer->render($this);
 }
Example #29
0
 /**
  * Makes diff betweed 2 strings
  * @param  sring   $source       original data
  * @param  string  $dest         new data
  * @param  boolean $side_by_side side-by-side diff if set to true
  * @return string  diff
  */
 private static function textDiff($source, $dest, $side_by_side = false)
 {
     $diff = new \Text_Diff('auto', array(explode("\n", $source), explode("\n", $dest)));
     $renderer = new \Text_Diff_Renderer_inline();
     $renderer->_leading_context_lines = 3;
     $renderer->_trailing_context_lines = 3;
     if ($side_by_side == false) {
         $renderer->_split_level = 'words';
     }
     $res = $renderer->render($diff);
     if ($side_by_side == true) {
         $res = $renderer->sideBySide($res);
     }
     return $res;
 }
 /**
  * Produce differences using PHP
  *
  * @access	private
  * @param	string		comapre string 1
  * @param	string		comapre string 2
  * @return	string
  */
 private function _getPhpDiff($str1, $str2)
 {
     $str1 = explode("\n", str_replace("\r\n", "\n", $str1));
     $str2 = explode("\n", str_replace("\r\n", "\n", $str2));
     /* Set include path.. */
     @set_include_path(IPS_KERNEL_PATH . 'PEAR/');
     /* OMG.. too many PHP 5 errors under strict standards */
     $oldReportLevel = error_reporting(0);
     error_reporting($oldReportLevel ^ E_STRICT);
     require_once 'Text/Diff.php';
     require_once 'Text/Diff/Renderer.php';
     require_once 'Text/Diff/Renderer/inline.php';
     $diff = new Text_Diff('auto', array($str1, $str2));
     $renderer = new Text_Diff_Renderer_inline();
     $result = $renderer->render($diff);
     /* Go back to old reporting level */
     error_reporting($oldReportLevel | E_STRICT);
     $result = str_replace("<ins>", '<ins style="-ips-match:1">', $result);
     $result = str_replace("<del>", '<del style="-ips-match:1">', $result);
     # Got a match?
     if (strstr($result, 'style="-ips-match:1"')) {
         $this->diff_found = 1;
     }
     # No post processing please
     $this->post_process = 0;
     # Convert lines to a space, and two spaces to a single line
     $result = str_replace('  ', chr(10), str_replace("\n", " ", $result));
     $result = $this->_diffTagSpace($result, 1);
     return $result;
 }