示例#1
1
function diff($from, $to)
{
    $from = mb_convert_encoding($from, 'HTML-ENTITIES', 'UTF-8');
    $to = mb_convert_encoding($to, 'HTML-ENTITIES', 'UTF-8');
    require_once AppFile::lib('finediff');
    $diff = new FineDiff($from, $to, FineDiff::$paragraphGranularity);
    $html = $diff->renderDiffToHTML();
    $html = mb_convert_encoding($html, 'UTF-8', 'HTML-ENTITIES');
    $html = html_entity_decode($html);
    $html = nl2br($html);
    return $html;
}
示例#2
0
// don't want to override guid cause if it's new page
if (sizeof($input) > 0) {
    foreach ($input as $name => $value) {
        $markdown_wiki->{$name} = $value;
    }
}
if ($markdown_wiki->save()) {
    elgg_clear_sticky_form('markdown_wiki');
    elgg_load_library('markdown_wiki:fineDiff');
    // set diff
    $compare = new FineDiff($old_description, $markdown_wiki->description, array(FineDiff::wordDelimiters));
    $compared['word'] = calc_diff_markdown_wiki($compare->renderDiffToHTML());
    $compare = new FineDiff($old_description, $markdown_wiki->description, array(FineDiff::sentenceDelimiters));
    $compared['sentence'] = calc_diff_markdown_wiki($compare->renderDiffToHTML());
    $compare = new FineDiff($old_description, $markdown_wiki->description, array(FineDiff::paragraphDelimiters));
    $compared['paragraph'] = calc_diff_markdown_wiki($compare->renderDiffToHTML());
    $array_change = array('text' => $markdown_wiki->description, 'diff' => $compared, 'summary' => get_input('summary'));
    // Now save description as an annotation
    $annotation_id = create_annotation($markdown_wiki->guid, 'markdown_wiki', serialize($array_change), '', 0, $markdown_wiki->access_id);
    system_message(elgg_echo('markdown_wiki:saved'));
    if ($new_markdown_wiki) {
        add_to_river('river/object/markdown_wiki/create', 'create', $user_guid, $markdown_wiki->guid);
    } else {
        if (!get_input('minorchange', false)) {
            add_to_river('river/object/markdown_wiki/update', 'update', $user_guid, $markdown_wiki->guid, '', 0, $annotation_id);
        }
    }
    forward($markdown_wiki->getURL());
} else {
    register_error(elgg_echo('markdown_wiki:error:no_save'));
    forward(REFERER);
示例#3
0
function formatEventDetails($event)
{
    $details = '';
    switch ($event->getEventTypeID()) {
        case 'edit_update_uploads':
        case 'edit_task_uploads':
            $addedIDs = explode(',', $event->getData2());
            $added = '';
            foreach ($addedIDs as $a) {
                if ($a == '') {
                    continue;
                }
                // skip blanks
                $upload = Upload::load($a);
                $added .= $upload->getOriginalName() . ' (' . formatFileSize($upload->getSize()) . ')<br /><br />';
            }
            if (!empty($added)) {
                $details .= '<ins>' . $added . '</ins>';
            }
            $deletedIDs = explode(',', $event->getData1());
            $deleted = '';
            foreach ($deletedIDs as $d) {
                if ($d == '') {
                    continue;
                }
                // skip blanks
                $upload = Upload::load($d);
                $deleted .= $upload->getOriginalName() . ' (' . formatFileSize($upload->getSize()) . ')<br /><br />';
            }
            if (!empty($deleted)) {
                $details .= '<del>' . $deleted . '</del>';
            }
            break;
        case 'edit_pitch':
        case 'edit_specs':
        case 'edit_rules':
        case 'edit_task_description':
        case 'edit_update_message':
            $from = $event->getData1();
            $to = $event->getData2();
            $from = str_replace('&#10;', '<br />', $from);
            $to = str_replace('&#10;', '<br />', $to);
            $diff = new FineDiff($from, $to);
            $htmlDiff = $diff->renderDiffToHTML();
            $htmlDiff = html_entity_decode($htmlDiff, ENT_QUOTES, 'UTF-8');
            $htmlDiff = html_entity_decode($htmlDiff, ENT_QUOTES, 'UTF-8');
            $details .= $htmlDiff;
            break;
        case 'edit_task_title':
        case 'edit_update_title':
            $from = $event->getData1();
            $to = $event->getData2();
            $diff = new FineDiff($from, $to);
            $htmlDiff = $diff->renderDiffToHTML();
            $htmlDiff = html_entity_decode($htmlDiff, ENT_QUOTES, 'UTF-8');
            $htmlDiff = html_entity_decode($htmlDiff, ENT_QUOTES, 'UTF-8');
            $details .= $htmlDiff;
            break;
        case 'edit_task_leader':
            $details .= 'Old Leader: <del>' . formatUserLink($event->getUser1ID(), $event->getProjectID()) . '</del><br /><br />';
            $details .= 'New Leader: <ins>' . formatUserLink($event->getUser2ID(), $event->getProjectID()) . '</ins>';
            break;
        case 'edit_task_num_needed':
            $old = $event->getData1() != null ? $event->getData1() : '&#8734;';
            $new = $event->getData2() != null ? $event->getData2() : '&#8734;';
            $details .= 'Old: <del>' . $old . '</del> people needed<br /><br />';
            $details .= 'New: <ins>' . $new . '</ins> people needed';
            break;
        case 'edit_task_deadline':
        case 'edit_project_deadline':
            $old = $event->getData1() != null ? formatTimeTag($event->getData1()) : '(none)';
            $new = $event->getData2() != null ? formatTimeTag($event->getData2()) : '(none)';
            $details .= 'Old Deadline: <del>' . $old . '</del><br /><br />';
            $details .= 'New Deadline: <ins>' . $new . '</ins>';
            break;
        case 'edit_project_status':
            $old = formatProjectStatus($event->getData1());
            $new = formatProjectStatus($event->getData2());
            $details .= 'Old Project Status: <del>' . $old . '</del><br /><br />';
            $details .= 'New Project Status: <ins>' . $new . '</ins>';
            break;
        case 'edit_accepted_status':
            $old = formatAcceptedStatus($event->getData1());
            $new = formatAcceptedStatus($event->getData2());
            $details .= 'Old Status: <del>' . $old . '</del><br /><br />';
            $details .= 'New Status: <ins>' . $new . '</ins>';
            break;
        case 'create_task_comment':
        case 'create_task_comment_reply':
        case 'create_update_comment':
        case 'create_update_comment_reply':
            $details .= formatComment($event->getData1());
            break;
        case 'create_discussion':
            $details .= '<strong>' . $event->getData1() . '</strong><br /><br />';
            $details .= formatDiscussionReply($event->getData2());
            break;
        case 'create_discussion_reply':
            $details .= formatDiscussionReply($event->getData1());
            break;
        case 'create_update':
            if ($event->getData1() != '') {
                $details .= '<strong>' . $event->getData1() . '</strong><br /><br />';
            }
            if ($event->getData2() != '') {
                $details .= formatUpdate($event->getData2());
            }
            break;
        case 'create_task':
            if ($event->getData1() != '') {
                $details .= '<strong>' . $event->getData1() . '</strong><br /><br />';
            }
            if ($event->getData2() != '') {
                $details .= formatTaskDescription($event->getData2());
            }
            break;
    }
    return $details;
}
示例#4
0
    if (!empty($_REQUEST['from'])) {
        $from_text = $_REQUEST['from'];
    }
    if (!empty($_REQUEST['to'])) {
        $to_text = $_REQUEST['to'];
    }
}
$diff = '';
$granularityStacks = array(FineDiff::$paragraphGranularity, FineDiff::$sentenceGranularity, FineDiff::$wordGranularity, FineDiff::$characterGranularity);
$from_len = strlen($from_text);
$to_len = strlen($to_text);
$start_time = gettimeofday(true);
$diff = new FineDiff($from_text, $to_text, $granularityStacks[$granularity]);
$edits = $diff->getOps();
$exec_time = gettimeofday(true) - $start_time;
$rendered_diff = $diff->renderDiffToHTML();
$rendering_time = gettimeofday(true) - $start_time;
$diff_len = strlen($diff->getOpcodes());
?>
<form action="viewdiff.php" method="post">
<div class="panecontainer" style="display:inline-block;width:49.5%"><p>From</p><div><textarea name="from" class="pane"><?php 
echo htmlentities($from_text);
?>
</textarea></div></div>
<div class="panecontainer" style="display:inline-block;width:49.5%"><p>To</p><div><textarea name="to" class="pane"><?php 
echo htmlentities($to_text);
?>
</textarea></div></div>
<p id="params">Granularity:<input name="granularity" type="radio" value="0"<?php 
if ($granularity === 0) {
    echo ' checked="checked"';
示例#5
0
文件: String.php 项目: nabble/ajde
 public static function textDiff($from, $to, $truncate = false)
 {
     require_once 'lib/finediff.php';
     $diff = new FineDiff($from, $to, FineDiff::$wordGranularity);
     if (!$truncate) {
         return $diff->renderDiffToHTML();
     } else {
         $html = $diff->renderDiffToHTML();
         // find first change
         $firstDel = strpos($html, '<del>');
         $firstIns = strpos($html, '<ins>');
         if ($firstDel === false) {
             $firstDel = $firstIns;
         }
         if ($firstIns === false) {
             $firstIns = $firstDel;
         }
         $first = min($firstDel, $firstIns);
         $first = max(0, $first - $truncate);
         // find last change
         $lastDel = strrpos($html, '</del>');
         $lastIns = strrpos($html, '</ins>');
         if ($lastDel === false) {
             $lastDel = $lastIns;
         }
         if ($lastIns === false) {
             $lastIns = $lastDel;
         }
         $last = max($lastDel, $lastIns);
         $last = min(strlen($html), $last + $truncate);
         // create truncated string
         return ($first > 0 ? '<span>....</span> ' : '') . substr($html, $first, $last - $first) . ($last < strlen($html) ? ' <span>....</span>' : '');
     }
 }
示例#6
0
        }
        $array_diff = $values[$key]['diff'][$granularity];
        $diff_text = '';
        if ($array_diff[0] != 0) {
            $diff_text .= '<ins class="elgg-subtext">&nbsp;+' . $array_diff[0] . '&nbsp;</ins>';
        }
        if ($array_diff[1] != 0) {
            $diff_text .= '<del class="elgg-subtext">&nbsp;-' . $array_diff[1] . '&nbsp;</del>';
        }
        $annotationSummary[$key] = <<<HTML
<div id='owner-{$key}' class='owner'>
\t{$summary}<br/>
\t<span class="elgg-subtext">
\t\t{$diff_text} {$owner_link} {$time}
\t</span>
</div>
HTML;
    }
    $diff = new FineDiff(htmlspecialchars($values[0]['text'], ENT_QUOTES, 'UTF-8', false), htmlspecialchars($values[1]['text'], ENT_QUOTES, 'UTF-8', false), $granularity_fine);
    $diffOutput = str_replace(' ', '&nbsp;', $diff->renderDiffToHTML());
    $diffOutput = str_replace(CHR(13), '<br/>', $diffOutput);
    $diffHTML = "<div id='diff-from' class='diff'>" . $diffOutput . '</div>';
    $content = "<div class='diff-output'>" . $diffHTML . '</div>';
    $title = elgg_echo('markdown_wiki:compare:result', array($markdown_wiki->title));
    $sidebar .= elgg_view('markdown_wiki/sidebar/compare_sidebar', array('from' => $annotationSummary[0], 'to' => $annotationSummary[1]));
} else {
    $content = elgg_view_form('markdown_wiki/compare', array('disable_security' => true, 'action' => "wiki/compare/{$markdown_wiki_guid}/{$markdown_wiki->title}"), array('markdown_wiki' => $markdown_wiki, 'annoff' => $annoff));
    $title = elgg_echo('markdown_wiki:compare', array($markdown_wiki->title));
}
$body = elgg_view_layout('content', array('filter' => '', 'content' => $content, 'title' => $title, 'sidebar' => $sidebar));
echo elgg_view_page($title, $body);
示例#7
0
elgg_register_menu_item('page', array('name' => 'discussion', 'href' => "wiki/discussion/{$markdown_wiki_guid}/{$markdown_wiki->title}", 'text' => elgg_echo('markdown_wiki:page:discussion')));
elgg_register_menu_item('page', array('name' => 'compare', 'href' => "wiki/compare/{$markdown_wiki_guid}/{$markdown_wiki->title}", 'text' => elgg_echo('markdown_wiki:page:compare')));
if ($markdown_wiki->canEdit()) {
    elgg_register_menu_item('page', array('name' => 'edit-page', 'href' => "wiki/edit/{$markdown_wiki_guid}/{$markdown_wiki->title}", 'text' => elgg_echo('markdown_wiki:page:edit')));
}
$annotations = elgg_get_annotations(array('types' => 'object', 'subtypes' => 'markdown_wiki', 'annotation_names' => 'markdown_wiki', 'guids' => $markdown_wiki_guid, 'order_by' => 'time_created desc', 'limit' => 50));
$count = elgg_get_annotations(array('types' => 'object', 'subtypes' => 'markdown_wiki', 'annotation_names' => 'markdown_wiki', 'guids' => $markdown_wiki_guid, 'order_by' => 'time_created desc', 'count' => true));
$annotations = array_reverse($annotations);
foreach ($annotations as $key => $annotation) {
    $values[] = unserialize($annotation->value);
}
$diffHTML = $diffOwner = '';
for ($i = count($annotations) - 1; $i >= 0; $i--) {
    if ($i != 0) {
        $diff = new FineDiff(htmlspecialchars($values[$i - 1]['text'], ENT_QUOTES, 'UTF-8', false), htmlspecialchars($values[$i]['text'], ENT_QUOTES, 'UTF-8', false), $granularity_fine);
        $diffOutput = $diff->renderDiffToHTML();
    } else {
        $diffOutput = htmlspecialchars($values[0]['text'], ENT_QUOTES, 'UTF-8', false);
    }
    $diffOutput = str_replace(' ', '&nbsp;', $diffOutput);
    $diffOutput = preg_replace('#\\r\\n</del>#sU', '</del>', $diffOutput);
    $diffOutput = str_replace(CHR(13), '<br/>', $diffOutput);
    $diffHTML .= "<div id='diff-{$i}' class='diff hidden'>" . $diffOutput . '</div>';
    $owner = get_entity($annotations[$i]->owner_guid);
    $owner_link = elgg_echo('markdown_wiki:history:date', array("<a href=\"{$owner->getURL()}\">{$owner->name}</a>"));
    $time = htmlspecialchars(strftime(elgg_echo('markdown_wiki:history:date_format'), $annotations[$i]->time_created));
    $summary = $values[$i]['summary'];
    $array_diff = $values[$i]['diff'][$granularity];
    $diff_text = '';
    if ($array_diff[0] != 0) {
        $diff_text .= '<ins class="elgg-subtext">&nbsp;+' . $array_diff[0] . '&nbsp;</ins>';
示例#8
0
文件: diff.php 项目: alerque/bibledit
 /**
  * This filter returns the diff of two input strngs.
  * $oldstring: The old string for input.
  * $newstring: The new string for input.
  * The function returns the differences marked.
  */
 public static function diff($oldstring, $newstring)
 {
     include_once "finediff.php";
     // FineDiff::$paragraphGranularity
     // FineDiff::$sentenceGranularity
     // FineDiff::$wordGranularity
     // FineDiff::$characterGranularity
     $diff = new FineDiff($oldstring, $newstring, FineDiff::$wordGranularity);
     $rendering = $diff->renderDiffToHTML();
     $search = array("<ins>", "</ins>", "<del>", "</del>");
     $replace = array("<span style=\"font-weight: bold;\">", "</span>", "<span style=\"text-decoration: line-through;\">", "</span>");
     $html = str_replace($search, $replace, $rendering);
     return $html;
 }
示例#9
0
        $doc->encoding = 'utf-8';
        $content1 = trim($doc->saveXML());
    } else {
        if (is_file($origFile)) {
            $content1 = strtr(trim(file_get_contents($origFile)), array("\r\n" => "\n"));
        } else {
            $content1 = "";
        }
    }
    if (is_file($convFile)) {
        $content2 = strtr(trim(file_get_contents($convFile)), array("\r\n" => "\n"));
    } else {
        $content2 = "";
    }
    $diff = new FineDiff($content1, $content2, FineDiff::$paragraphGranularity);
    $diffHtml = $diff->renderDiffToHTML();
} catch (Exception $ex) {
    $error = $ex->getMessage();
}
?>

<? $mainClass = "diff-page" ?>
<? include "templates/header.php" ?>


<h2>diff: <?php 
echo htmlspecialchars($file);
?>
</h2>

<? if ($error === null): ?>