public function actionTmp() { $model = Question::find()->one(); $model->attributes = ['title' => 123]; $diff = new \cogpowered\FineDiff\Diff(); if (!isset($model->dirtyAttributes)) { $old = []; $new = $model->attributes; } else { $old = array_intersect_key($model->oldAttributes, $model->dirtyAttributes); $new = array_intersect_key($model->attributes, $model->dirtyAttributes); } echo $diff->render(json_encode($old), json_encode($new)); }
public static function attributeDifference(Event $event) { /** @var ActiveRecord $model */ $model = $event->sender; $diff = new \cogpowered\FineDiff\Diff(); if (!isset($model->dirtyAttributes)) { $old = []; $new = $model->attributes; } else { $old = array_intersect_key($model->oldAttributes, $model->dirtyAttributes); $new = array_intersect_key($model->attributes, $model->dirtyAttributes); } unset($old['password'], $new['password']); return $diff->render(preg_replace(['#[\\s\\n]*\\)#', '#Array[\\s\\n]*\\(#'], ['', ''], print_r($old, true)), preg_replace(['#[\\s\\n]*\\)#', '#Array[\\s\\n]*\\(#'], ['', ''], print_r($new, true))); }
private function compareResult($pathinput, $pathoutput) { $finediff = new cogpowered\FineDiff\Diff(); $input = fopen($pathinput, "r"); $output = fopen($pathoutput, "r"); while (!feof($input)) { $lineinp = fgets($input, 4096); $lineout = fgets($output, 4096); $opcodes = $finediff->getOpcodes($lineinp, $lineout); for ($i = 0; $i < strlen($opcodes); $i++) { if ($opcodes[$i] == 'i') { $i++; while ($opcodes[$i] != ':') { $i++; } $i++; if ($opcodes[$i] != ' ' || $opcodes[$i] != '\\t' || $opcodes[$i] != '\\n') { throw new IncorrectOutputError(); #return -8; } else { throw new OutputFormatError(); #return -9; } } else { if ($opcodes[$i] == 'd') { throw new OutputFormatError(); # return -9; } } } } return 0; }
return implode(' ', $tag_lists); }); HTML::macro('show_users', function ($users) { $user_lists = []; foreach ($users as $user) { $image = HTML::gravator($user["email"], 20); $username = $user['username']; $user_page_url = route('user.profile', compact('username')); $user_lists[] = $image . ' <a href="' . $user_page_url . '">' . e($username) . '</a>'; } return implode(' ', $user_lists); }); HTML::macro('markdown', function ($str) { $parser = new Owl\Libraries\CustomMarkdown(); $parser->enableNewlines = true; return $parser->parse($str); }); HTML::macro('diff', function ($from, $to) { $from = mb_convert_encoding($from, 'HTML-ENTITIES', 'UTF-8'); $to = mb_convert_encoding($to, 'HTML-ENTITIES', 'UTF-8'); $granularity = new cogpowered\FineDiff\Granularity\Word(); $diff = new cogpowered\FineDiff\Diff($granularity); $result = htmlspecialchars_decode($diff->render($from, $to)); return nl2br($result); }); HTML::macro('date_replace', function ($str) { $str = str_replace("%{Year}", date('Y'), $str); $str = str_replace("%{month}", date('m'), $str); $str = str_replace("%{day}", date('d'), $str); return $str; });
<?php echo ucfirst($fieldChanged) . ': '; ?> <span style="text-decoration: line-through; background-color: #F78181;"><?php echo $this->fieldChanges[$index][1]; ?> </span> <span style="background-color: #BCF5A9;"><?php echo $this->fieldChanges[$index][2]; ?> </span> <?php } else { ?> <?php $granularity = new cogpowered\FineDiff\Granularity\Word(); $diff = new cogpowered\FineDiff\Diff($granularity); $fromText = $this->fieldChanges[$index][1]; $toText = $this->fieldChanges[$index][2]; $opCodes = $diff->getOpcodes($fromText, $toText); $render = new cogpowered\FineDiff\Render\Html(); $diffHTML = $render->process($fromText, $opCodes); $diffHTML = str_replace('<ins>', '<ins style="color: green; background: #dfd; text-decoration: none;">', $diffHTML); $diffHTML = str_replace('<del>', '<del style="color: red;background: #fdd; text-decoration: none;">', $diffHTML); ?> <span><?php echo ucfirst($fieldChanged) . ': ' . str_replace("\n", '<br />', htmlspecialchars_decode($diffHTML)); ?> </span> <?php } ?>
/** * save diff report HTML */ public function save_diff_report_html($repo) { $path_diffHtml = $this->conf['output'] . '/report/diff/' . $repo['path'] . '.diff.html'; $path_base = $this->fs->get_relatedpath($this->conf['output'] . '/report/', dirname($path_diffHtml)); $diff = new \cogpowered\FineDiff\Diff(); ob_start(); ?> <!DOCTYPE html> <html> <head> <meta charset="UTF-8" /> <title>diff: <?php echo htmlspecialchars($repo['path']); ?> </title> <link rel="stylesheet" href="<?php echo htmlspecialchars($path_base); ?> resources/fess-1.2.2.css" /> <script src="<?php echo htmlspecialchars($path_base); ?> resources/jquery-1.10.1.min.js"></script> <link rel="stylesheet" href="<?php echo htmlspecialchars($path_base); ?> resources/bootstrap/css/bootstrap.css" /> <link rel="stylesheet" href="<?php echo htmlspecialchars($path_base); ?> resources/bootstrap/css/bootstrap-theme.css" /> <script src="<?php echo htmlspecialchars($path_base); ?> resources/bootstrap/js/bootstrap.js"></script> <link rel="stylesheet" href="<?php echo htmlspecialchars($path_base); ?> resources/common.css" /> <script src="<?php echo htmlspecialchars($path_base); ?> resources/common.js"></script> </head> <body> <div class="theme_outline"> <h1><?php echo htmlspecialchars($repo['path']); ?> </h1> <p> <?php if ($repo['before_info']['type'] == $repo['after_info']['type']) { echo htmlspecialchars($repo['after_info']['type']); } elseif (!strlen($repo['before_info']['type'])) { echo htmlspecialchars($repo['after_info']['type']); } elseif (!strlen($repo['after_info']['type'])) { echo htmlspecialchars($repo['before_info']['type']); } else { echo htmlspecialchars($repo['before_info']['type']); ?> to <?php echo htmlspecialchars($repo['after_info']['type']); } ?> </p> <div class="contents"> <div class="unit"> <?php if ($repo['before_info']['type'] == 'file' || $repo['after_info']['type'] == 'file') { $bin_before = @$this->fs->read_file($this->before . $repo['path']); $bin_after = @$this->fs->read_file($this->after . $repo['path']); $ext = @$this->fs->get_extension($repo['path']); switch (strtolower($ext)) { // ウェブドキュメント類 case 'html': case 'htm': case 'xhtml': case 'xhtm': case 'shtml': case 'shtm': case 'js': case 'css': case 'rss': case 'rdf': case 'inc': // テキスト類 // テキスト類 case 'text': case 'txt': case 'md': // プログラム言語類 // プログラム言語類 case 'php': case 'cgi': case 'pl': case 'rb': case 'py': case 'c': case 'cpp': case 'cs': case 'd': case 'go': case 'h': case 'hx': case 'java': case 'lisp': case 'lua': case 'sql': case 'scala': case 'sh': case 'bat': case 'vbs': case 'hs': case 'lhs': case 'as': // データファイル類 // データファイル類 case 'csv': case 'json': case 'ini': case 'conf': case 'yml': case 'mm': case 'xml': case 'svg': // 糖衣言語類 // 糖衣言語類 case 'scss': case 'coffee': case 'styl': case 'jade': ?> <div class="code"><pre><code><?php echo $diff->render(@mb_convert_encoding($bin_before, 'UTF-8', 'SJIS-win,Shift-JIS,eucJP-win,EUC-JP,UTF-8,' . mb_detect_order()), @mb_convert_encoding($bin_after, 'UTF-8', 'SJIS-win,Shift-JIS,eucJP-win,EUC-JP,UTF-8,' . mb_detect_order())); ?> </code></pre></div><?php break; case 'jpg': case 'jpeg': case 'jpe': case 'gif': case 'png': print '<div class="image-preview">'; print '<div class="btn-group" role="group">'; print ' <button type="button" class="btn btn-default" onclick="compareImagesInTwoColumns();">並べて比較</button>'; print ' <button type="button" class="btn btn-default" onclick="compareImagesInPilingUp();">重ねて比較</button>'; print '</div>'; print '<div class="image-preview--twocolumns">'; if (@strlen($bin_before)) { print '<div class="image-preview--before">'; print '<p>変更前</p>'; print '<img src="data:image/png;base64,' . htmlspecialchars(base64_encode($bin_before)) . '" alt="変更前の画像プレビュー" />'; print '</div>'; } if (@strlen($bin_after)) { print '<div class="image-preview--after">'; print '<p>変更後</p>'; print '<img src="data:image/png;base64,' . htmlspecialchars(base64_encode($bin_after)) . '" alt="変更後の画像プレビュー" />'; print '</div>'; } print '</div>'; print '<div class="image-preview--pilingup">'; print '</div>'; print '</div>'; break; default: print '<p>比較できない拡張子です。</p>'; break; } } else { ?> <p>This item is a directory.</p> <?php } ?> </div> <div> <table class="def" style="width:100%;"> <thead> <tr> <th style="width:20%;"> </th> <th style="width:40%;">before</th> <th style="width:40%;">after</th> </tr> </thead> <tr> <th>path</th> <td colspan="2"><?php echo htmlspecialchars($repo['path']); ?> </td> </tr> <tr> <th>status</th> <td colspan="2"><?php echo htmlspecialchars($repo['status']); ?> </td> </tr> <?php foreach ($repo['before_info'] as $key => $val) { ?> <tr> <th><?php echo htmlspecialchars($key); ?> </th> <?php if ($key == 'timestamp') { ?> <td><?php echo htmlspecialchars(strlen($repo['before_info'][$key]) ? @date('Y-m-d H:i:s', $repo['before_info'][$key]) : '---'); ?> </td> <td><?php echo htmlspecialchars(strlen($repo['after_info'][$key]) ? @date('Y-m-d H:i:s', $repo['after_info'][$key]) : '---'); ?> </td> <?php } else { ?> <td><?php echo htmlspecialchars(strlen($repo['before_info'][$key]) ? $repo['before_info'][$key] : '---'); ?> </td> <td><?php echo htmlspecialchars(strlen($repo['after_info'][$key]) ? $repo['after_info'][$key] : '---'); ?> </td> <?php } ?> </tr> <?php } ?> </table> </div> </div> </div> </body> </html> <?php $src_html_diff = ob_get_clean(); $this->fs->mkdir_r(dirname($path_diffHtml)); $this->fs->save_file($path_diffHtml, $src_html_diff); return true; }