public function actionDiff($id, $mode)
 {
     if (!isset(Yii::app()->session['code'])) {
         $this->redirect(array('index'));
     }
     $class = Class_Prog::model()->findByPk($id);
     if ($class == null) {
         throw new CHttpException(404, 'Unable to find the requested class.');
     }
     $original = $this->renderPartial('/generator/cpp_class_decl', array('raw' => 1, 'class' => $class), true);
     $new = Yii::app()->session['code'];
     $diff = TextDiff::compare($original, $new, $mode);
     $this->render('diff', array('class' => $class, 'diff' => $diff, 'new' => $new, 'mode' => $mode));
 }
 /**
  * The code diff action.
  * This action shows up the difference between the newly generated code and the corresponding existing code.
  */
 public function actionDiff()
 {
     Yii::import('gii.components.TextDiff');
     $model = $this->prepare();
     if (isset($_GET['id']) && isset($model->files[$_GET['id']])) {
         $file = $model->files[$_GET['id']];
         if (!in_array($file->type, array('php', 'txt', 'js', 'css'))) {
             $diff = false;
         } else {
             if ($file->operation === CCodeFile::OP_OVERWRITE) {
                 $diff = TextDiff::compare(file_get_contents($file->path), $file->content);
             } else {
                 $diff = '';
             }
         }
         $this->renderPartial('/common/diff', array('file' => $file, 'diff' => $diff));
     } else {
         throw new CHttpException(404, 'Unable to find the code you requested.');
     }
 }
Example #3
0
 /**
  * Displays difference between two page revisions
  *
  * @param string $uid unique wiki id
  * @param string $rev1 page revision
  * @param string $rev2 page revision
  */
 public function actionDiff($uid, $rev1, $rev2)
 {
     $r1 = WikiPageRevision::model()->findByPk($rev1);
     if (!$r1) {
         throw new CHttpException(404);
     }
     $r2 = WikiPageRevision::model()->findByPk($rev2);
     if (!$r2) {
         throw new CHttpException(404);
     }
     $this->render('diff', array('diff' => TextDiff::compare($r1->content, $r2->content), 'r1' => $r1, 'r2' => $r2, 'uid' => $uid));
 }
Example #4
0
 private function setWordReg()
 {
     if (null === self::$word_reg) {
         $regs = array('々〇〻\\x{3220}-\\x{3244}\\x{3280}-\\x{32B0}\\x{3400}-\\x{9FFF}\\x{F900}-\\x{FAFF}\\x{20000}-\\x{2FFFF}', 'ぁ-ん~ー', 'ァ-ヴ~ー', 'ヲ-゚', '\\!-\\~');
         $reg = '[' . implode(']+|[', $regs) . ']+';
         $reg .= '|[^' . implode('', $regs) . ']+';
         self::$word_reg = $reg;
     }
 }
Example #5
0
<?php

if (array_key_exists('source', $_POST) && array_key_exists('change', $_POST)) {
    include dirname(__FILE__) . '/TextDiff.php';
    $diff = new TextDiff($_POST['source'], $_POST['change']);
    $html = $diff->getHtml();
    $html['data'] = var_export($diff->getData(), true);
    echo json_encode($html);
    exit;
}
?>
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<title>TextDiff demo</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" integrity="sha512-dTfge/zgoMYpP7QbHy4gWMEGsbsdZeCXz7irItjcC3sPUFtf0kuFbDz/ixG7ArTxmDjLXDmezHubeNikyKGVyQ==" crossorigin="anonymous">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/octicons/3.1.0/octicons.min.css">
<style media="screen">
.differ {
    width:100%;
    margin:0;
    background:#f9f9f9;
    border:1px solid #ddd;
    font-size:inherit;
    border-collapse:separate;
    border-spacing:0;
    border:1px solid #ddd;
}

.differ td {
Example #6
0
 /**
  * Compare two texts and show the differences report
  * @param string $a
  * @param string $b
  * @return string
  */
 public static function diffTexts($a, $b)
 {
     Yii::import('ext.TextDiff.*');
     Yii::import('ext.TextDiff.Text.*');
     $diffObj = new TextDiff();
     // For some reason without the space this does not work.
     // Have no clue why but at least the space thing solves it
     $diffObj->getDiff(' ' . $a . ' ', ' ' . $b . ' ');
     return $diffObj->myOutput ? $diffObj->myOutput : Yii::t('global', 'Error trying to show the differences.');
 }