Ejemplo n.º 1
1
 public function getDiff($old, $new, $granularity = null)
 {
     $granularity = $granularity ? $this->getGranularity($granularity) : $this->defaultGranularity;
     $opcodes = FineDiff::getDiffOpcodes($old, $new, $granularity);
     $html = FineDiff::renderDiffToHTMLFromOpcodes($old, $opcodes);
     return $html;
 }
Ejemplo n.º 2
0
 if (!empty($_POST['from']) || !empty($_POST['to'])) {
     if (!empty($_POST['from'])) {
         $from_text = $_POST['from'];
     }
     if (!empty($_POST['to'])) {
         $to_text = $_POST['to'];
     }
 }
 // limit input
 $from_text = substr($from_text, 0, 1024 * 100);
 $to_text = substr($to_text, 0, 1024 * 100);
 // ensure input is suitable for diff
 $from_text = mb_convert_encoding($from_text, 'HTML-ENTITIES', 'UTF-8');
 $to_text = mb_convert_encoding($to_text, 'HTML-ENTITIES', 'UTF-8');
 $granularityStacks = array(FineDiff::$paragraphGranularity, FineDiff::$sentenceGranularity, FineDiff::$wordGranularity, FineDiff::$characterGranularity);
 $diff_opcodes = FineDiff::getDiffOpcodes($from_text, $to_text, $granularityStacks[$granularity]);
 $diff_opcodes_len = strlen($diff_opcodes);
 $exec_time = gettimeofday(true) - $start_time;
 if ($diff_opcodes_len) {
     $data_key = sha1(serialize(array('granularity' => $granularity, 'from_text' => $from_text, 'diff_opcodes' => $diff_opcodes)));
     $filename = "{$data_key}{$compressed_serialized_filename_extension}";
     if (!file_exists("./cache/{$filename}")) {
         // purge cache if too many files
         if (!(time() % 100)) {
             $files = glob("./cache/*{$compressed_serialized_filename_extension}");
             $num_files = $files ? count($files) : 0;
             if ($num_files > $cache_hi_water_mark) {
                 $sorted_files = array();
                 foreach ($files as $file) {
                     $sorted_files[strval(@filemtime("./cache/{$file}")) . $file] = $file;
                 }