/** * Default previewer for plugins with no custom preview. * * @param GedcomRecord $record * * @return string */ public function getActionPreview(GedcomRecord $record) { $old_lines = preg_split('/[\\n]+/', $record->getGedcom()); $new_lines = preg_split('/[\\n]+/', $this->updateRecord($record->getXref(), $record->getGedcom())); // Find matching lines using longest-common-subsequence algorithm. $lcs = self::longestCommonSubsequence($old_lines, $new_lines, 0, count($old_lines) - 1, 0, count($new_lines) - 1); $diff_lines = array(); $last_old = -1; $last_new = -1; while ($lcs) { list($old, $new) = array_shift($lcs); while ($last_old < $old - 1) { $diff_lines[] = self::decorateDeletedText($old_lines[++$last_old]); } while ($last_new < $new - 1) { $diff_lines[] = self::decorateInsertedText($new_lines[++$last_new]); } $diff_lines[] = $new_lines[$new]; $last_old = $old; $last_new = $new; } while ($last_old < count($old_lines) - 1) { $diff_lines[] = self::decorateDeletedText($old_lines[++$last_old]); } while ($last_new < count($new_lines) - 1) { $diff_lines[] = self::decorateInsertedText($new_lines[++$last_new]); } return '<pre class="gedcom-data">' . self::createEditLinks(implode("\n", $diff_lines)) . '</pre>'; }
/** * Inserts a clipping into the clipping cart * * @param GedcomRecord $record */ public function addClipping(GedcomRecord $record) { if ($record->canShowName()) { $this->cart[$record->getTree()->getTreeId()][$record->getXref()] = true; // Add directly linked records preg_match_all('/\\n\\d (?:OBJE|NOTE|SOUR|REPO) @(' . WT_REGEX_XREF . ')@/', $record->getGedcom(), $matches); foreach ($matches[1] as $match) { $this->cart[$record->getTree()->getTreeId()][$match] = true; } } }
/** * Default previewer for plugins with no custom preview. * * @param GedcomRecord $record * * @return string */ public function getActionPreview(GedcomRecord $record) { $old_lines = preg_split('/[\\n]+/', $record->getGedcom()); $new_lines = preg_split('/[\\n]+/', $this->updateRecord($record->getXref(), $record->getGedcom())); $algorithm = new MyersDiff(); $differences = $algorithm->calculate($old_lines, $new_lines); $diff_lines = array(); foreach ($differences as $difference) { switch ($difference[1]) { case MyersDiff::DELETE: $diff_lines[] = self::decorateDeletedText($difference[0]); break; case MyersDiff::INSERT: $diff_lines[] = self::decorateInsertedText($difference[0]); break; default: $diff_lines[] = $difference[0]; } } return '<pre class="gedcom-data">' . self::createEditLinks(implode("\n", $diff_lines)) . '</pre>'; }