Exemple #1
0
 /**
  * Show difference between two versions.
  *
  * @param  \App\Version
  * @param  \App\Version
  * @return void
  */
 protected function compareVersions(Version $before, Version $after)
 {
     // Parse source
     $beforeArray = explode("\n", $before->source);
     $afterArray = explode("\n", $after->source);
     // Compare versions
     $diff = new \Diff($beforeArray, $afterArray, $options = []);
     // Load view
     return view('version.compare', ['title' => _('Versions'), 'subtitle' => _('Compare'), 'before' => $before, 'after' => $after, 'sideBySideDiff' => $diff->Render(new \Diff_Renderer_Html_SideBySide()), 'inlineDiff' => $diff->render(new \Diff_Renderer_Html_Inline())]);
 }
Exemple #2
0
function diff($path, $action, $title, $content)
{
    $Head = '<meta name="robots" content="noindex, nofollow" />';
    $content['PageNav']->Active("Page History");
    if (is_numeric($action[1])) {
        $pageQuery = mysql_query("SELECT `PageID`,`AccountID`,`EditTime`,`Name`,`Description`,`Title`,`Content` FROM `Wiki_Edits` WHERE `ID`='{$action['1']}' and `Archived` = 0");
        list($PageID, $AccountID, $PageEditTime, $PageName, $PageDescription, $PageTitle, $pageContent) = mysql_fetch_array($pageQuery);
        $previousQuery = mysql_query("Select `ID`, `Content` from `Wiki_Edits` where `ID` < '{$action['1']}' and `PageID`='{$PageID}' and `Archived` = 0 order by `ID` desc limit 1");
        list($previousID, $previousContent) = mysql_fetch_array($previousQuery);
        $nextQuery = mysql_query("Select `ID` from `Wiki_Edits` where `ID` > '{$action['1']}' and `PageID`='{$PageID}' and `Archived` = 0 order by `ID` limit 1");
        list($nextID) = mysql_fetch_array($nextQuery);
        if (!empty($previousID)) {
            $previousPath = FormatPath("/{$path}/?diff/{$previousID}");
            $content['Title'] = "<a href='{$previousPath}' title='Previous Revision'>⟨</a> ";
        }
        $content['Title'] .= FishFormat($PageTitle);
        if (!empty($nextID)) {
            $nextPath = FormatPath("/{$path}/?diff/{$nextID}");
            $content['Title'] .= " <a href='{$nextPath}' title='Next Revision'>⟩</a>";
        }
        $content['Body'] .= <<<JavaScript
        
        <script>
            \$(document).ready(function ()
            {
                \$('body').on('keydown', function(event)
                {
                    event.stopImmediatePropagation()
                    
                    if(event.keyCode == 37) // Previous
                        location.href = '{$previousPath}';
                    else if(event.keyCode == 39) // Next
                        location.href = '{$nextPath}';
                });
            });
        </script>
JavaScript;
        $old = explode("\n", html_entity_decode($previousContent, ENT_QUOTES));
        $new = explode("\n", html_entity_decode($pageContent, ENT_QUOTES));
        // Initialize the diff class
        $diff = new Diff($old, $new);
        require_once dirname(__FILE__) . '/../libraries/Diff/Renderer/Html/SideBySide.php';
        $renderer = new Diff_Renderer_Html_SideBySide();
        $content['Body'] .= $diff->Render($renderer);
        date_default_timezone_set('America/New_York');
        $PageEditTime = formatTime($PageEditTime);
        $content['Footer'] = "This page is an old revision made by <b><a href='/names?id={$AccountID}'>{$PageName}</a></b> on {$PageEditTime}.";
        if ($PageDescription) {
            $content['Footer'] .= "<br />'{$PageDescription}'";
        }
    }
    return array($title, $content);
}
Exemple #3
0
 /**
  * Wrapper function to get differences
  *
  * @return	string	Diff data
  */
 function get_diff($str1, $str2, $type = 'side_by_side')
 {
     $type = isset($this->diff_types[$type]) ? $this->diff_types[$type] : current($this->diff_types);
     #		require_once $this->module_path.'Diff.php';
     // Options for generating the diff
     $options = [];
     //Prepare content
     $str1 = explode("\n", $str1);
     $str2 = explode("\n", $str2);
     // Initialize the diff class
     $diff = new Diff($str1, $str2, $options);
     #		require_once $this->module_path.'Diff/Renderer/Html/'.$type.'.php';
     $diff_type_class = 'Diff_Renderer_Html_' . $type;
     $renderer = new $diff_type_class();
     return $this->custom_style() . $diff->Render($renderer);
 }
Exemple #4
0
 public function process_ajax()
 {
     $a = __Request::get('a');
     $b = __Request::get('b');
     $it = org_glizy_objectFactory::createModelIterator('org.glizycms.core.models.Content');
     $it->where("document_detail_id", $a)->allStatuses();
     $ar_a = $it->first();
     $it = org_glizy_objectFactory::createModelIterator('org.glizycms.core.models.Content');
     $it->where("document_detail_id", $b)->allStatuses();
     $ar_b = $it->first();
     $a = explode("\n", str_replace("<\\/p>", "<\\/p>\n", json_encode(json_decode($ar_a->document_detail_object), JSON_PRETTY_PRINT)));
     $b = explode("\n", str_replace("<\\/p>", "<\\/p>\n", json_encode(json_decode($ar_b->document_detail_object), JSON_PRETTY_PRINT)));
     glz_importLib('Diff/Diff.php');
     glz_importLib('Diff/Diff/Renderer/Html/SideBySide.php');
     // Options for generating the diff
     $options = array();
     $diff = new Diff($a, $b, $options);
     $renderer = new Diff_Renderer_Html_SideBySide();
     $result = $diff->Render($renderer);
     return array('html' => $result);
 }
Exemple #5
0
 public static function wfFunc_diff()
 {
     if (preg_match('/[\'\\"<>\\!\\{\\}\\(\\)\\&\\@\\%\\$\\*\\+\\[\\]\\?]+/', $_GET['file'])) {
         echo "File contains illegal characters.";
         exit;
     }
     $result = self::getWPFileContent($_GET['file'], $_GET['cType'], $_GET['cName'], $_GET['cVersion']);
     if (isset($result['errorMsg']) && $result['errorMsg']) {
         echo wp_kses($result['errorMsg'], array());
         exit(0);
     } else {
         if (!$result['fileContent']) {
             echo "We could not get the contents of the original file to do a comparison.";
             exit(0);
         }
     }
     $localFile = realpath(ABSPATH . '/' . preg_replace('/^[\\.\\/]+/', '', $_GET['file']));
     $localContents = file_get_contents($localFile);
     if ($localContents == $result['fileContent']) {
         $diffResult = '';
     } else {
         $diff = new Diff(preg_split("/(?:\r\n|\n)/", $result['fileContent']), preg_split("/(?:\r\n|\n)/", $localContents), array());
         $renderer = new Diff_Renderer_Html_SideBySide();
         $diffResult = $diff->Render($renderer);
     }
     require 'diffResult.php';
     exit(0);
 }
 /**
  * Shows the latest modification made to a post
  */
 public function historyAction($id = 0)
 {
     $this->view->disable();
     /**
      * Find the post using get
      */
     $post = Posts::findFirstById($id);
     if (!$post) {
         $this->flashSession->error('The discussion does not exist');
         return $this->response->redirect();
     }
     $a = explode("\n", $post->content);
     $first = true;
     $parameters = ['posts_id = ?0', 'bind' => [$post->id], 'order' => 'created_at DESC'];
     /** @var PostsHistory[] $postHistories */
     $postHistories = PostsHistory::find($parameters);
     if (count($postHistories) > 1) {
         foreach ($postHistories as $postHistory) {
             if ($first) {
                 $first = false;
                 continue;
             }
             break;
         }
     } else {
         $postHistory = $postHistories->getFirst();
     }
     if (is_object($postHistory)) {
         $b = explode("\n", $postHistory->content);
         $diff = new \Diff($b, $a, []);
         $renderer = new \Diff_Renderer_Html_SideBySide();
         echo $diff->Render($renderer);
     } else {
         $this->flash->notice('No history available to show');
     }
 }
Exemple #7
0
 /**
  * Show diff using php (optional)
  *
  */
 function PHPDiff($compiled, $css, $force = false)
 {
     if (!$force && isset($_COOKIE['phpdiff']) && $_COOKIE['phpdiff'] == 0) {
         return;
     }
     $compiled = explode("\n", $compiled);
     $css = explode("\n", $css);
     $options = array();
     $diff = new Diff($compiled, $css, $options);
     $renderer = new Diff_Renderer_Html_SideBySide();
     //$renderer = new Diff_Renderer_Html_Inline();
     echo $diff->Render($renderer);
     //show the full contents
     /*
     if( isset($_GET['file']) ){
     	echo '</table>';
     	echo '<table style="width:100%"><tr><td>';
     	echo '<pre>';
     	echo implode("\n",$compiled);
     	echo '</pre>';
     	echo '</td><td>';
     	echo '<pre>';
     	echo implode("\n",$css);
     	echo '</pre>';
     	echo '</td></tr></table>';
     }
     */
 }
Exemple #8
0
 /**
  * Compare versions
  */
 public function compare()
 {
     $strBuffer = '';
     $arrVersions = array();
     $intTo = 0;
     $intFrom = 0;
     $objVersions = $this->Database->prepare("SELECT * FROM tl_version WHERE pid=? AND fromTable=? ORDER BY version DESC")->execute($this->intPid, $this->strTable);
     if ($objVersions->numRows < 2) {
         $strBuffer = '<p>There are no versions of ' . $this->strTable . '.id=' . $this->intPid . '</p>';
     } else {
         $intIndex = 0;
         $from = array();
         // Store the versions and mark the active one
         while ($objVersions->next()) {
             if ($objVersions->active) {
                 $intIndex = $objVersions->version;
             }
             $arrVersions[$objVersions->version] = $objVersions->row();
             $arrVersions[$objVersions->version]['info'] = $GLOBALS['TL_LANG']['MSC']['version'] . ' ' . $objVersions->version . ' (' . \Date::parse(\Config::get('datimFormat'), $objVersions->tstamp) . ') ' . $objVersions->username;
         }
         // To
         if (\Input::post('to') && isset($arrVersions[\Input::post('to')])) {
             $intTo = \Input::post('to');
             $to = deserialize($arrVersions[\Input::post('to')]['data']);
         } elseif (\Input::get('to') && isset($arrVersions[\Input::get('to')])) {
             $intTo = \Input::get('to');
             $to = deserialize($arrVersions[\Input::get('to')]['data']);
         } else {
             $intTo = $intIndex;
             $to = deserialize($arrVersions[$intTo]['data']);
         }
         // From
         if (\Input::post('from') && isset($arrVersions[\Input::post('from')])) {
             $intFrom = \Input::post('from');
             $from = deserialize($arrVersions[\Input::post('from')]['data']);
         } elseif (\Input::get('from') && isset($arrVersions[\Input::get('from')])) {
             $intFrom = \Input::get('from');
             $from = deserialize($arrVersions[\Input::get('from')]['data']);
         } elseif ($intIndex > 1) {
             $intFrom = $intIndex - 1;
             $from = deserialize($arrVersions[$intFrom]['data']);
         }
         // Only continue if both version numbers are set
         if ($intTo > 0 && $intFrom > 0) {
             \System::loadLanguageFile($this->strTable);
             $this->loadDataContainer($this->strTable);
             // Get the order fields
             $objDcaExtractor = \DcaExtractor::getInstance($this->strTable);
             $arrOrder = $objDcaExtractor->getOrderFields();
             // Find the changed fields and highlight the changes
             foreach ($to as $k => $v) {
                 if ($from[$k] != $to[$k]) {
                     if ($GLOBALS['TL_DCA'][$this->strTable]['fields'][$k]['inputType'] == 'password' || $GLOBALS['TL_DCA'][$this->strTable]['fields'][$k]['eval']['doNotShow'] || $GLOBALS['TL_DCA'][$this->strTable]['fields'][$k]['eval']['hideInput']) {
                         continue;
                     }
                     $blnIsBinary = $GLOBALS['TL_DCA'][$this->strTable]['fields'][$k]['inputType'] == 'fileTree' || in_array($k, $arrOrder);
                     // Decrypt the values
                     if ($GLOBALS['TL_DCA'][$this->strTable]['fields'][$k]['eval']['encrypt']) {
                         $to[$k] = \Encryption::decrypt($to[$k]);
                         $from[$k] = \Encryption::decrypt($from[$k]);
                     }
                     // Convert serialized arrays into strings
                     if (is_array($tmp = deserialize($to[$k])) && !is_array($to[$k])) {
                         $to[$k] = $this->implodeRecursive($tmp, $blnIsBinary);
                     }
                     if (is_array($tmp = deserialize($from[$k])) && !is_array($from[$k])) {
                         $from[$k] = $this->implodeRecursive($tmp, $blnIsBinary);
                     }
                     unset($tmp);
                     // Convert binary UUIDs to their hex equivalents (see #6365)
                     if ($blnIsBinary && \Validator::isBinaryUuid($to[$k])) {
                         $to[$k] = \String::binToUuid($to[$k]);
                     }
                     if ($blnIsBinary && \Validator::isBinaryUuid($from[$k])) {
                         $to[$k] = \String::binToUuid($from[$k]);
                     }
                     // Convert date fields
                     if ($GLOBALS['TL_DCA'][$this->strTable]['fields'][$k]['eval']['rgxp'] == 'date') {
                         $to[$k] = \Date::parse(\Config::get('dateFormat'), $to[$k] ?: '');
                         $from[$k] = \Date::parse(\Config::get('dateFormat'), $from[$k] ?: '');
                     } elseif ($GLOBALS['TL_DCA'][$this->strTable]['fields'][$k]['eval']['rgxp'] == 'time') {
                         $to[$k] = \Date::parse(\Config::get('timeFormat'), $to[$k] ?: '');
                         $from[$k] = \Date::parse(\Config::get('timeFormat'), $from[$k] ?: '');
                     } elseif ($GLOBALS['TL_DCA'][$this->strTable]['fields'][$k]['eval']['rgxp'] == 'datim' || $k == 'tstamp') {
                         $to[$k] = \Date::parse(\Config::get('datimFormat'), $to[$k] ?: '');
                         $from[$k] = \Date::parse(\Config::get('datimFormat'), $from[$k] ?: '');
                     }
                     // Convert strings into arrays
                     if (!is_array($to[$k])) {
                         $to[$k] = explode("\n", $to[$k]);
                     }
                     if (!is_array($from[$k])) {
                         $from[$k] = explode("\n", $from[$k]);
                     }
                     $objDiff = new \Diff($from[$k], $to[$k]);
                     $strBuffer .= $objDiff->Render(new DiffRenderer(array('field' => $GLOBALS['TL_DCA'][$this->strTable]['fields'][$k]['label'][0] ?: (isset($GLOBALS['TL_LANG']['MSC'][$k]) ? is_array($GLOBALS['TL_LANG']['MSC'][$k]) ? $GLOBALS['TL_LANG']['MSC'][$k][0] : $GLOBALS['TL_LANG']['MSC'][$k] : $k))));
                 }
             }
         }
     }
     // Identical versions
     if ($strBuffer == '') {
         $strBuffer = '<p>' . $GLOBALS['TL_LANG']['MSC']['identicalVersions'] . '</p>';
     }
     /** @var \BackendTemplate|object $objTemplate */
     $objTemplate = new \BackendTemplate('be_diff');
     // Template variables
     $objTemplate->content = $strBuffer;
     $objTemplate->versions = $arrVersions;
     $objTemplate->to = $intTo;
     $objTemplate->from = $intFrom;
     $objTemplate->showLabel = specialchars($GLOBALS['TL_LANG']['MSC']['showDifferences']);
     $objTemplate->theme = \Backend::getTheme();
     $objTemplate->base = \Environment::get('base');
     $objTemplate->language = $GLOBALS['TL_LANGUAGE'];
     $objTemplate->title = specialchars($GLOBALS['TL_LANG']['MSC']['showDifferences']);
     $objTemplate->charset = \Config::get('characterSet');
     $objTemplate->action = ampersand(\Environment::get('request'));
     \Config::set('debugMode', false);
     $objTemplate->output();
     exit;
 }
Exemple #9
0
 public function diff($fid, $rid)
 {
     //load diff engine
     require_once dirname(APPPATH) . '/iu-application/libraries/diff/Diff.php';
     require_once dirname(APPPATH) . '/iu-application/libraries/diff/Diff/Renderer/Html/SideBySide.php';
     $file = File::factory()->get_by_id((int) $fid);
     $revision = FileRevision::factory()->get_by_id((int) $rid);
     $file_html = explode("\n", $file->contents());
     $revision_html = explode("\n", $revision->contents);
     $options = array('ignoreWhitespace' => true);
     $diff = new Diff($revision_html, $file_html, $options);
     $renderer = new Diff_Renderer_Html_SideBySide();
     $differences = $diff->Render($renderer);
     $this->templatemanager->assign("file", $file);
     $this->templatemanager->assign("revision", $revision);
     $this->templatemanager->assign("differences", $differences);
     $this->templatemanager->set_title("View Differences");
     $this->templatemanager->show_template("templates_diff");
 }
</pre>
<?php 
}
?>


<?php 
if (PerchUtil::count($historical_logs) > 1 && $Action->resourceType() === LOG_REGION_TYPE) {
    echo $HTML->heading1('History');
    $i = 0;
    foreach ($historical_logs as $History) {
        if (isset($historical_logs[$i - 1])) {
            $a = explode("\n", $History->resourceModification());
            $b = explode("\n", $historical_logs[$i - 1]->resourceModification());
            $diff = new Diff($a, $b);
            $renderer = new Diff_Renderer_Html_SideBySide();
            $html = $diff->Render($renderer);
            if ($html) {
                echo '<div class="diff-table">';
                echo '<h2>' . $HTML->encode($Action->relativeTime() . ' by ' . $Action->userProperty('userUsername', 'N/A')) . '</h2>';
                echo $html;
                echo '</div>';
            }
        }
        $i++;
    }
}
?>

<?php 
echo $HTML->main_panel_end();
Exemple #11
0
<?
require_once WIKI_PATH."/lib/Diff/Diff.php";
require_once WIKI_PATH."/lib/Diff/Renderer/Html/SideBySide.php";
$options = array(
	//'ignoreWhitespace' => true,
	//'ignoreCase' => true
);
if(wiki_is_euckr()) {
	$history['content'] = iconv("CP949", "UTF-8", $history['content']);
	$article['wr_content'] = iconv("CP949", "UTF-8", $article['wr_content']);
}
$history_content = explode("\n", $history['content']);
$current_content = explode("\n", $article['wr_content']);
$diff = new Diff($history_content, $current_content, $options);
$renderer = new Diff_Renderer_Html_SideBySide();
$diffData = $diff->Render($renderer);

if(wiki_is_euckr()) {
	$diffData = preg_replace_callback("/(<td(.*?)>)(.*?)(<\/td>)/s", create_function('$matches', 'return $matches[1].iconv("UTF-8", "CP949", $matches[3]).$matches[4];'), $diffData);
}

echo $diffData;
?>

<div class="clear" style="margin-top:10px">
	<div style="float:left">
		<span class="button"><a href="<?php 
echo wiki_url();
?>
">시작페이지</a></span>
		<span class="button"><a href="<?php 
Exemple #12
0
 /**
  * Run the controller
  */
 public function run()
 {
     $strBuffer = '';
     $arrVersions = array();
     $intTo = 0;
     $intFrom = 0;
     if (!Input::get('table') || !Input::get('pid')) {
         $strBuffer = 'Please provide the table name and PID';
     } else {
         $objVersions = $this->Database->prepare("SELECT * FROM tl_version WHERE pid=? AND fromTable=?" . (!$this->User->isAdmin ? " AND userid=?" : "") . " ORDER BY version DESC")->execute(Input::get('pid'), Input::get('table'), $this->User->id);
         if ($objVersions->numRows < 1) {
             $strBuffer = 'There are no versions of ' . Input::get('table') . '.id=' . Input::get('pid');
         } else {
             $intIndex = 0;
             $from = array();
             // Store the versions and mark the active one
             while ($objVersions->next()) {
                 if ($objVersions->active) {
                     $intIndex = $objVersions->version;
                 }
                 $arrVersions[$objVersions->version] = $objVersions->row();
                 $arrVersions[$objVersions->version]['info'] = $GLOBALS['TL_LANG']['MSC']['version'] . ' ' . $objVersions->version . ' (' . $this->parseDate($GLOBALS['TL_CONFIG']['datimFormat'], $objVersions->tstamp) . ') ' . $objVersions->username;
             }
             // To
             if (Input::get('to') && isset($arrVersions[Input::get('to')])) {
                 $intTo = Input::get('to');
                 $to = deserialize($arrVersions[Input::get('to')]['data']);
             } else {
                 $intTo = $intIndex;
                 $to = deserialize($arrVersions[$intTo]['data']);
             }
             // From
             if (Input::get('from') && isset($arrVersions[Input::get('from')])) {
                 $intFrom = Input::get('from');
                 $from = deserialize($arrVersions[Input::get('from')]['data']);
             } elseif ($intIndex > 1) {
                 $intFrom = $intIndex - 1;
                 $from = deserialize($arrVersions[$intFrom]['data']);
             }
             $this->loadLanguageFile(Input::get('table'));
             $this->loadDataContainer(Input::get('table'));
             $arrFields = $GLOBALS['TL_DCA'][Input::get('table')]['fields'];
             // Find the changed fields and highlight the changes
             foreach ($to as $k => $v) {
                 if ($from[$k] != $to[$k]) {
                     if (!isset($arrFields[$k]['inputType']) || $arrFields[$k]['inputType'] == 'password' || $arrFields[$k]['eval']['doNotShow'] || $arrFields[$k]['eval']['hideInput']) {
                         continue;
                     }
                     // Convert serialized arrays into strings
                     if (is_array($tmp = deserialize($to[$k])) && !is_array($to[$k])) {
                         $to[$k] = $this->implode($tmp);
                     }
                     if (is_array($tmp = deserialize($from[$k])) && !is_array($from[$k])) {
                         $from[$k] = $this->implode($tmp);
                     }
                     unset($tmp);
                     // Convert date fields
                     if ($arrFields[$k]['eval']['rgxp'] == 'date') {
                         $to[$k] = $this->parseDate($GLOBALS['TL_CONFIG']['dateFormat'], $to[$k] ?: '');
                         $from[$k] = $this->parseDate($GLOBALS['TL_CONFIG']['dateFormat'], $from[$k] ?: '');
                     } elseif ($arrFields[$k]['eval']['rgxp'] == 'time') {
                         $to[$k] = $this->parseDate($GLOBALS['TL_CONFIG']['timeFormat'], $to[$k] ?: '');
                         $from[$k] = $this->parseDate($GLOBALS['TL_CONFIG']['timeFormat'], $from[$k] ?: '');
                     } elseif ($arrFields[$k]['eval']['rgxp'] == 'datim') {
                         $to[$k] = $this->parseDate($GLOBALS['TL_CONFIG']['datimFormat'], $to[$k] ?: '');
                         $from[$k] = $this->parseDate($GLOBALS['TL_CONFIG']['datimFormat'], $from[$k] ?: '');
                     }
                     // Convert strings into arrays
                     if (!is_array($to[$k])) {
                         $to[$k] = explode("\n", $to[$k]);
                     }
                     if (!is_array($from[$k])) {
                         $from[$k] = explode("\n", $from[$k]);
                     }
                     $objDiff = new Diff($from[$k], $to[$k]);
                     $strBuffer .= $objDiff->Render(new Diff_Renderer_Html_Contao(array('field' => $arrFields[$k]['label'][0] ?: $k)));
                 }
             }
         }
     }
     // Identical versions
     if ($strBuffer == '') {
         $strBuffer = '<p>' . $GLOBALS['TL_LANG']['MSC']['identicalVersions'] . '</p>';
     }
     $this->Template = new BackendTemplate('be_diff');
     // Template variables
     $this->Template->content = $strBuffer;
     $this->Template->versions = $arrVersions;
     $this->Template->to = $intTo;
     $this->Template->from = $intFrom;
     $this->Template->fromLabel = 'Von';
     $this->Template->toLabel = 'Zu';
     $this->Template->showLabel = specialchars($GLOBALS['TL_LANG']['MSC']['showDifferences']);
     $this->Template->table = Input::get('table');
     $this->Template->pid = intval(Input::get('pid'));
     $this->Template->theme = $this->getTheme();
     $this->Template->base = Environment::get('base');
     $this->Template->language = $GLOBALS['TL_LANGUAGE'];
     $this->Template->title = specialchars($GLOBALS['TL_LANG']['MSC']['showDifferences']);
     $this->Template->charset = $GLOBALS['TL_CONFIG']['characterSet'];
     $this->Template->action = ampersand(Environment::get('request'));
     $GLOBALS['TL_CONFIG']['debugMode'] = false;
     $this->Template->output();
 }
Exemple #13
0
 public static function wfFunc_diff()
 {
     $result = self::getWPFileContent($_GET['file'], $_GET['cType'], $_GET['cName'], $_GET['cVersion']);
     if (isset($result['errorMsg']) && $result['errorMsg']) {
         echo htmlentities($result['errorMsg']);
         exit(0);
     } else {
         if (!$result['fileContent']) {
             echo "We could not get the contents of the original file to do a comparison.";
             exit(0);
         }
     }
     $localFile = realpath(ABSPATH . '/' . preg_replace('/^[\\.\\/]+/', '', $_GET['file']));
     $localContents = file_get_contents($localFile);
     if ($localContents == $result['fileContent']) {
         $diffResult = '';
     } else {
         $diff = new Diff(preg_split("/(?:\r\n|\n)/", $result['fileContent']), preg_split("/(?:\r\n|\n)/", $localContents), array());
         $renderer = new Diff_Renderer_Html_SideBySide();
         $diffResult = $diff->Render($renderer);
     }
     require 'diffResult.php';
     exit(0);
 }
Exemple #14
0
#!/usr/bin/php
<?php 
$config = ['git_urls' => ['https://github.com/yfix/php-diff.git' => 'php_diff/'], 'require_once' => ['php_diff/lib/Diff.php', 'php_diff/lib/Diff/Renderer/Html/SideBySide.php'], 'example' => function () {
    $str1 = explode(PHP_EOL, 'aaa' . PHP_EOL . '1');
    $str2 = explode(PHP_EOL, 'aaa' . PHP_EOL . 'av');
    $diff = new Diff($str1, $str2, $options);
    echo $diff->Render(new Diff_Renderer_Html_SideBySide());
    echo PHP_EOL;
}];
if ($return_config) {
    return $config;
}
require_once __DIR__ . '/_yf_autoloader.php';
new yf_autoloader($config);
    require_once PACOWIKI_PLUGIN_PATH . 'library/Diff/Renderer/Html/Inline.php';
    require_once PACOWIKI_PLUGIN_PATH . 'library/Diff/Renderer/Html/SideBySide.php';
    $options = array('ignoreWhitespace' => false, 'ignoreCase' => false);
    // Initialize the diff class for title
    $diff = new Diff(array($new_title), array($old_title), $options);
    $renderer = new Diff_Renderer_Html_SideBySide();
    $diff_output = $diff->Render($renderer);
    if (empty($diff_output)) {
        echo '<p>' . __('No changes were found in wiki Title!', 'pacowiki') . '</p>';
    } else {
        echo '<h2>Title:</h2>';
        echo $diff_output;
    }
    $diff = new Diff($new_content, $old_content, $options);
    $renderer = new Diff_Renderer_Html_Inline();
    $diff_output = $diff->Render($renderer);
    if (empty($diff_output)) {
        echo '<p>' . __('No changes were found in wiki content!', 'pacowiki') . '</p>';
    } else {
        echo '<h2>Content:</h2>';
        echo $diff_output;
    }
} elseif ($view_revision) {
    // View an old revision
    ?>
			<header class="entry-header">
				<h1 class="entry-title"><?php 
    the_title();
    ?>
</h1>
			</header>
Exemple #16
0
 /**
  * Diff revisions
  *
  * @param      object	$file		Models\File
  * @param      array	$params
  *
  * @return     array
  */
 public function diff($params = array())
 {
     $file = isset($params['file']) ? $params['file'] : NULL;
     $rev1 = isset($params['rev1']) ? $params['rev1'] : NULL;
     $rev2 = isset($params['rev2']) ? $params['rev2'] : NULL;
     $full = isset($params['fullDiff']) ? $params['fullDiff'] : NULL;
     $mode = isset($params['mode']) ? $params['mode'] : 'side-by-side';
     if (!$this->isGit()) {
         return false;
     }
     if (!$file instanceof Models\File) {
         return false;
     }
     $rev1Parts = explode('@', $rev1);
     $rev2Parts = explode('@', $rev2);
     // Run some checks
     if (count($rev1Parts) <= 2 || count($rev2Parts) <= 2) {
         $this->setError(Lang::txt('PLG_PROJECTS_FILES_ERROR_DIFF_NO_CONTENT'));
         return false;
     }
     $rev1 = array('rev' => $rev1Parts[0], 'hash' => $rev1Parts[1], 'fpath' => $rev1Parts[2], 'val' => urlencode($rev1));
     $rev2 = array('rev' => $rev2Parts[0], 'hash' => $rev2Parts[1], 'fpath' => $rev2Parts[2], 'val' => urlencode($rev2));
     // Get text blobs
     $rev1['text'] = $this->_git->gitLog($rev1['fpath'], $rev1['hash'], 'blob');
     $rev2['text'] = $this->_git->gitLog($rev2['fpath'], $rev2['hash'], 'blob');
     // Diff class
     include_once PATH_CORE . DS . 'plugins' . DS . 'projects' . DS . 'files' . DS . 'helpers' . DS . 'Diff.php';
     $context = $rev1['text'] == $rev2['text'] || $full ? count($rev1['text']) : 10;
     $options = array('context' => $context);
     // Run diff
     $objDiff = new \Diff($rev1['text'], $rev2['text'], $options);
     if ($mode == 'side-by-side') {
         include_once PATH_CORE . DS . 'plugins' . DS . 'projects' . DS . 'files' . DS . 'php-diff' . DS . 'Diff' . DS . 'Renderer' . DS . 'Html' . DS . 'hubSideBySide.php';
         // Generate a side by side diff
         $renderer = new \Diff_Renderer_Html_SideBySide();
         $diff = $objDiff->Render($renderer);
     } elseif ($mode == 'inline') {
         include_once PATH_CORE . DS . 'plugins' . DS . 'projects' . DS . 'files' . DS . 'php-diff' . DS . 'Diff' . DS . 'Renderer' . DS . 'Html' . DS . 'hubInline.php';
         // Generate inline diff
         $renderer = new \Diff_Renderer_Html_Inline();
         $diff = $objDiff->Render($renderer);
     } else {
         // Print git diff
         $diff = $this->_git->gitDiff($rev1, $rev2);
         if (is_array($diff)) {
             $diff = implode("\n", $diff);
         }
     }
     return $diff;
 }
 /**
  * Compares the current to the original template
  *
  * @param DataContainer $dc
  *
  * @return string
  */
 public function compareTemplate(DataContainer $dc)
 {
     $strCurrentPath = $dc->id;
     $strName = pathinfo($strCurrentPath, PATHINFO_FILENAME);
     $strExtension = pathinfo($strCurrentPath, PATHINFO_EXTENSION);
     $arrTemplates = TemplateLoader::getFiles();
     $blnOverridesAnotherTpl = isset($arrTemplates[$strName]);
     $strPrefix = '';
     if (($pos = strpos($strName, '_')) !== false) {
         $strPrefix = substr($strName, 0, $pos + 1);
     }
     $strBuffer = '';
     $strCompareName = null;
     $strComparePath = null;
     // By default it's the original template to compare against
     if ($blnOverridesAnotherTpl) {
         $strCompareName = $strName;
         $strComparePath = $arrTemplates[$strCompareName] . '/' . $strCompareName . '.' . $strExtension;
         if ($strComparePath !== null) {
             $strBuffer .= '<p class="tl_info" style="margin-bottom:1em">' . sprintf($GLOBALS['TL_LANG']['tl_templates']['overridesAnotherTpl'], $strComparePath) . '</p>';
         }
     }
     // User selected template to compare against
     if (\Input::post('from') && isset($arrTemplates[\Input::post('from')])) {
         $strCompareName = \Input::post('from');
         $strComparePath = $arrTemplates[$strCompareName] . '/' . $strCompareName . '.' . $strExtension;
     }
     if ($strComparePath !== null) {
         $objCurrentFile = new \File($strCurrentPath, true);
         $objCompareFile = new \File($strComparePath, true);
         // Abort if one file is missing
         if (!$objCurrentFile->exists() || !$objCompareFile->exists()) {
             $this->redirect('contao/main.php?act=error');
         }
         $objDiff = new Diff($objCompareFile->getContentAsArray(), $objCurrentFile->getContentAsArray());
         $strDiff = $objDiff->Render(new DiffRenderer(array('field' => $strCurrentPath)));
         // Identical versions
         if ($strDiff == '') {
             $strBuffer .= '<p>' . $GLOBALS['TL_LANG']['MSC']['identicalVersions'] . '</p>';
         } else {
             $strBuffer .= $strDiff;
         }
     } else {
         $strBuffer .= '<p class="tl_info">' . $GLOBALS['TL_LANG']['tl_templates']['pleaseSelect'] . '</p>';
     }
     // Templates to compare against
     $arrComparable = array();
     $intPrefixLength = strlen($strPrefix);
     foreach ($arrTemplates as $k => $v) {
         if (substr($k, 0, $intPrefixLength) === $strPrefix) {
             $arrComparable[$k] = array('version' => $k, 'info' => $k . '.' . $strExtension);
         }
     }
     /** @var \BackendTemplate|object $objTemplate */
     $objTemplate = new \BackendTemplate('be_diff');
     // Template variables
     $objTemplate->staticTo = $strCurrentPath;
     $objTemplate->versions = $arrComparable;
     $objTemplate->from = $strCompareName;
     $objTemplate->showLabel = specialchars($GLOBALS['TL_LANG']['MSC']['showDifferences']);
     $objTemplate->content = $strBuffer;
     $objTemplate->theme = \Backend::getTheme();
     $objTemplate->base = \Environment::get('base');
     $objTemplate->language = $GLOBALS['TL_LANGUAGE'];
     $objTemplate->title = specialchars($GLOBALS['TL_LANG']['MSC']['showDifferences']);
     $objTemplate->charset = \Config::get('characterSet');
     \Config::set('debugMode', false);
     $objTemplate->output();
     exit;
 }
Exemple #18
0
// Include the diff class
require_once __DIR__ . '/../lib/Diff.php';
// Include two sample files for comparison
$a = explode("\n", file_get_contents(__DIR__ . '/a.txt'));
$b = explode("\n", file_get_contents(__DIR__ . '/b.txt'));
// Options for generating the diff
$options = array();
// Initialize the diff class
$diff = new Diff($a, $b, $options);
?>
		<h2>Side by Side Diff</h2>
		<?php 
// Generate a side by side diff
require_once __DIR__ . '/../lib/Diff/Renderer/Html/SideBySide.php';
$renderer = new Diff_Renderer_Html_SideBySide();
echo $diff->Render($renderer);
?>
		<h2>Inline Diff</h2>
		<?php 
// Generate an inline diff
require_once __DIR__ . '/../lib/Diff/Renderer/Html/Inline.php';
$renderer = new Diff_Renderer_Html_Inline();
echo $diff->render($renderer);
?>
		<h2>Unified Diff</h2>
		<pre><?php 
// Generate a unified diff
require_once __DIR__ . '/../lib/Diff/Renderer/Text/Unified.php';
$renderer = new Diff_Renderer_Text_Unified();
echo htmlspecialchars($diff->render($renderer));
?>