This class renders the diff in classic diff format. It is intended that this class be customized via inheritance, to obtain fancier outputs. Copyright 2004-2016 Horde LLC (http://www.horde.org/) See the enclosed file COPYING for license information (LGPL). If you did not receive this file, see http://www.horde.org/licenses/lgpl21.
コード例 #1
0
ファイル: Character.php プロジェクト: Jony01/LLD
 public function __construct($context_lines = 0)
 {
     parent::__construct();
     $this->_leading_context_lines = $context_lines;
     $this->_trailing_context_lines = $context_lines;
     $this->orig = "";
     $this->final = "";
 }
コード例 #2
0
ファイル: Jfscan.php プロジェクト: knigherrant/decopatio
 /**
  * Adds a log entry to the #__admintools_scanalerts table, marking a modified, added or suspicious file.
  *
  * @param   \stdClass       $newFileRecord  The record of the current version of the file
  * @param   \stdClass|null  $oldFileRecord  The record of the old version of the file (or null if it's an added file)
  *
  * @return  void
  */
 private function _logFileChange(&$newFileRecord, &$oldFileRecord = null)
 {
     // Initialise the new alert record
     $alertRecord = array('path' => $newFileRecord->path, 'scan_id' => \Akeeba\Engine\Factory::getStatistics()->getId(), 'diff' => '', 'threat_score' => 0, 'acknowledged' => 0);
     // Produce the diff if there is an old file
     if (!is_null($oldFileRecord)) {
         if ($this->generateDiff) {
             // Modified file, generate diff
             $newText = gzinflate($newFileRecord->data);
             $newText = str_replace("\r\n", "\n", $newText);
             $newText = str_replace("\r", "\n", $newText);
             $newLines = explode("\n", $newText);
             unset($newText);
             $oldText = gzinflate($oldFileRecord->data);
             $oldText = str_replace("\r\n", "\n", $oldText);
             $oldText = str_replace("\r", "\n", $oldText);
             $oldLines = explode("\n", $oldText);
             unset($oldText);
             $diffObject = new \Horde_Text_Diff('native', array($newLines, $oldLines));
             $renderer = new \Horde_Text_Diff_Renderer();
             $alertRecord['diff'] = $renderer->render($diffObject);
             unset($renderer);
             unset($diffObject);
             unset($newLines);
             unset($oldLines);
             $alertRecord['threat_score'] = $this->_getThreatScore($alertRecord['diff']);
         } else {
             // Modified file, do not generate diff
             $alertRecord['diff'] = "###MODIFIED FILE###\n";
             $newText = @file_get_contents($newFileRecord->sourcePath);
             $alertRecord['threat_score'] = $this->_getThreatScore($newText);
             unset($newText);
         }
     } else {
         // New file
         $newText = @file_get_contents($newFileRecord->sourcePath);
         $alertRecord['threat_score'] = $this->_getThreatScore($newText);
         unset($newText);
     }
     // Do not create a record for non-threat files
     if ($this->ignoreNonThreats && !$alertRecord['threat_score']) {
         return;
     }
     $alertRecord = (object) $alertRecord;
     $db = \JFactory::getDbo();
     $db->insertObject('#__admintools_scanalerts', $alertRecord);
     unset($alertRecord);
 }
コード例 #3
0
ファイル: pearweb.php プロジェクト: stof/pearweb
 protected function _context($lines)
 {
     array_walk($lines, create_function('&$a,$b', '$a=htmlspecialchars($a);'));
     return "\n" . parent::_context($lines);
 }
コード例 #4
0
ファイル: RendererTest.php プロジェクト: jubinpatel/horde
    public function testPearBug7839()
    {
        $oldtext = <<<EOT
This is line 1.
This is line 2.
This is line 3.
This is line 4.
This is line 5.
This is line 6.
This is line 7.
This is line 8.
This is line 9.
EOT;
        $newtext = <<<EOT
This is line 1.
This was line 2.
This is line 3.
This is line 5.
This was line 6.
This was line 7.
This was line 8.
This is line 9.
This is line 10.
EOT;
        $patch = <<<END_OF_PATCH
2c2
< This is line 2.
---
> This was line 2.
4d3
< This is line 4.
6,8c5,7
< This is line 6.
< This is line 7.
< This is line 8.
---
> This was line 6.
> This was line 7.
> This was line 8.
9a9
> This is line 10.

END_OF_PATCH;
        $test = array(explode("\n", $oldtext), explode("\n", $newtext));
        $diff = new Horde_Text_Diff('Native', $test);
        $renderer = new Horde_Text_Diff_Renderer();
        $this->assertEquals($patch, $renderer->render($diff));
    }