public function view_log() { $log_value = unserialize($this->pdh->get('logs', 'value', array($this->url_id))); $blnCompare = false; if (is_array($log_value)) { foreach ($log_value as $k => $v) { if ($k != 'header') { //Enable Compare view if (is_array($v)) { $blnCompare = true; if ($v['flag'] == 1) { require_once $this->root_path . 'libraries/diff/diff.php'; require_once $this->root_path . 'libraries/diff/engine.php'; require_once $this->root_path . 'libraries/diff/renderer.php'; $diff = new diff(xhtml_entity_decode($this->logs->lang_replace($v['old'])), xhtml_entity_decode($this->logs->lang_replace($v['new'])), true); $renderer = new diff_renderer_inline(); $new = $content = $renderer->get_diff_content($diff); } else { $new = nl2br($this->logs->lang_replace($v['new'])); } $this->tpl->assign_block_vars('log_compare_row', array('KEY' => $this->logs->lang_replace(stripslashes($k)) . ':', 'OLD' => nl2br($this->logs->lang_replace($v['old'])), 'NEW' => $new, 'FLAG' => $v['flag'])); } else { $this->tpl->assign_block_vars('log_row', array('KEY' => $this->logs->lang_replace(stripslashes($k)) . ':', 'VALUE' => $this->logs->lang_replace(stripslashes($v)))); } } } } $plugin = $this->pdh->get('logs', 'plugin', array($this->url_id)); $this->tpl->assign_vars(array('LOG_PLUGIN' => $plugin != 'core' ? $this->user->lang($plugin) ? $this->user->lang($plugin) : ucfirst($plugin) : '', 'LOG_DATE' => $this->pdh->geth('logs', 'date', array($this->url_id, true)), 'LOG_USERNAME' => $this->pdh->geth('logs', 'user', array($this->url_id)), 'LOG_IP_ADDRESS' => $this->pdh->geth('logs', 'ipaddress', array($this->url_id)), 'LOG_SESSION_ID' => $this->pdh->geth('logs', 'sid', array($this->url_id)), 'LOG_ACTION' => $this->pdh->geth('logs', 'tag', array($this->url_id)), 'LOG_RECORD' => $this->pdh->geth('logs', 'record', array($this->url_id)), 'LOG_RECORD_ID' => $this->pdh->geth('logs', 'recordid', array($this->url_id)), 'S_COMPARE_VIEW' => $blnCompare, 'S_MORE_INFOS' => count($log_value))); $this->tpl->add_js(' $("#back2view").click(function(){ window.location="manage_logs.php' . $this->SID . '"; });', 'docready'); $this->tpl->css_file($this->root_path . 'libraries/diff/diff.css'); $this->core->set_vars(array('page_title' => $this->user->lang('viewlogs_title'), 'template_file' => 'admin/manage_logs_view.html', 'display' => true)); }
function _changed($orig, $final) { // If we've already split on words, don't try to do so again - just display. if ($this->_split_level == 'words') { $prefix = ''; while ($orig[0] !== false && $final[0] !== false && substr($orig[0], 0, 1) == ' ' && substr($final[0], 0, 1) == ' ') { $prefix .= substr($orig[0], 0, 1); $orig[0] = substr($orig[0], 1); $final[0] = substr($final[0], 1); } return $prefix . $this->_deleted($orig) . $this->_added($final); } $text1 = implode("\n", $orig); $text2 = implode("\n", $final); // Non-printing newline marker. $nl = ""; // We want to split on word boundaries, but we need to preserve whitespace as well. // Therefore we split on words, but include all blocks of whitespace in the wordlist. $splitted_text_1 = $this->_split_on_words($text1, $nl); $splitted_text_2 = $this->_split_on_words($text2, $nl); $diff = new diff($splitted_text_1, $splitted_text_2); unset($splitted_text_1, $splitted_text_2); // Get the diff in inline format. $renderer = new diff_renderer_inline(array_merge($this->get_params(), array('split_level' => 'words'))); // Run the diff and get the output. return str_replace($nl, "\n", $renderer->render($diff)) . "\n"; }
function diff() { $page = Wiki::getPageById(get_id(), active_project()); if (!instance_of($page, 'WikiPage')) { flash_error('wiki page dnx'); $this->redirectTo('wiki'); } // if if (!$page->canView(logged_user())) { flash_error('no access permissions'); $this->redirectTo('wiki'); } // if $rev1 = $page->getRevision(array_var($_GET, 'rev1', -1)); $rev2 = $page->getRevision(array_var($_GET, 'rev2', -1)); if (!instance_of($rev1, 'Revision') || !instance_of($rev2, 'Revision')) { flash_error(lang('wiki page revision dnx')); $this->redirectTo('wiki'); } // if $this->addHelper('textile'); //Load text diff library Env::useLibrary('diff', 'wiki'); $diff = new diff($rev1->getContent(), $rev2->getContent()); $output = new diff_renderer_inline(); tpl_assign('diff', $output->render($diff)); tpl_assign('page', $page); tpl_assign('revision', $page->getLatestRevision()); tpl_assign('rev1', $rev1); tpl_assign('rev2', $rev2); }
public function compare_versions($article, $from, $to) { if ($from == 0 || $to == 0) { trigger_error('NO_VERSIONS_SELECTED'); } require $this->phpbb_root_path . 'includes/diff/diff.' . $this->php_ext; require $this->phpbb_root_path . 'includes/diff/engine.' . $this->php_ext; require $this->phpbb_root_path . 'includes/diff/renderer.' . $this->php_ext; $sql = 'SELECT article_text, bbcode_uid, bbcode_bitfield, article_sources, article_description FROM ' . $this->article_table . ' WHERE article_id = ' . (int) $from; $result = $this->db->sql_query($sql); $from_row = $this->db->sql_fetchrow($result); $sql = 'SELECT article_text, bbcode_uid, bbcode_bitfield, article_sources, article_description FROM ' . $this->article_table . ' WHERE article_id = ' . (int) $to; $result = $this->db->sql_query($sql); $to_row = $this->db->sql_fetchrow($result); $from_article = generate_text_for_edit($from_row['article_text'], $from_row['bbcode_uid'], $from_row['bbcode_bitfield'], 3, true); $to_article = generate_text_for_edit($to_row['article_text'], $to_row['bbcode_uid'], $to_row['bbcode_bitfield'], 3, true); $u_from = $this->helper->route('tas2580_wiki_index', array('id' => $from)); $u_to = $this->helper->route('tas2580_wiki_index', array('id' => $to)); $article_diff = new \diff($from_article['text'], $to_article['text']); $article_diff_empty = $article_diff->is_empty(); $sources_diff = new \diff($from_row['article_sources'], $to_row['article_sources']); $sources_diff_empty = $sources_diff->is_empty(); $description_diff = new \diff($from_row['article_description'], $to_row['article_description']); $descriptiondiff_empty = $sources_diff->is_empty(); $renderer = new \diff_renderer_inline(); $this->template->assign_vars(array('HEADLINE' => sprintf($this->user->lang['VERSION_COMPARE_HEADLINE'], $from, $to, $u_from, $u_to), 'DIFF' => $article_diff_empty ? '' : $renderer->get_diff_content($article_diff), 'DIFF_SOURCE' => $sources_diff_empty ? '' : $renderer->get_diff_content($sources_diff), 'DIFF_DESCRIPTION' => $descriptiondiff_empty ? '' : $renderer->get_diff_content($description_diff))); return $this->helper->render('article_compare.html', $this->user->lang['VERSIONS_OF_ARTICLE']); }
public function get_html_value($id) { $strValue = $this->objPagination->get($id, 'log_value'); $log_value = unserialize($strValue); $arrTable = array(); $arrCompare = array(); $objLogs = register('logs'); if (is_array($log_value)) { foreach ($log_value as $k => $v) { if ($k != 'header') { //Enable Compare view if (is_array($v)) { if ($v['flag'] == 1) { require_once $this->root_path . 'libraries/diff/diff.php'; require_once $this->root_path . 'libraries/diff/engine.php'; require_once $this->root_path . 'libraries/diff/renderer.php'; $diff = new diff(xhtml_entity_decode($objLogs->lang_replace($v['old'])), xhtml_entity_decode($objLogs->lang_replace($v['new'])), true); $renderer = new diff_renderer_inline(); $new = $content = $renderer->get_diff_content($diff); } else { $new = nl2br($objLogs->lang_replace($v['new'])); } $arrCompare[] = array($objLogs->lang_replace(stripslashes($k)), nl2br($objLogs->lang_replace($v['old'])), $new, $v['flag']); } else { $arrTable[] = array($objLogs->lang_replace(stripslashes($k)), $objLogs->lang_replace(stripslashes($v))); } } } } $out = ""; if (count($arrTable)) { $out .= '<table class="table fullwidth">'; foreach ($arrTable as $val) { if (is_serialized($val[1])) { $val[1] = print_r(unserialize($val[1]), true); } $out .= '<tr><td style="font-weight: bold;">' . $val[0] . ':</td><td>' . $val[1] . '</td></tr>'; } $out .= '</table><br />'; } if (count($arrCompare)) { $out .= '<table class="table fullwidth colorswitch"> <tr> <th>' . $this->user->lang('value') . '</th><th>' . $this->user->lang('old_value') . '</th><th>' . $this->user->lang('new_value') . '</th> </tr>'; foreach ($arrCompare as $val) { $out .= '<tr> <td style="font-weight: bold;">' . $val[0] . '</td><td style="white-space: pre-wrap; word-break: break-word;">' . $val[1] . '</td><td class="log-comp-pre">' . $val[2] . '</td> </tr>'; } $out .= '</table>'; } return $out; }
/** * Create inline diff for two versions of a report description. * * @return string Returns diff or original description if the description if there aren't two versions to compare. */ public function get_description_diff() { // Get rid of <br /> tags as they seem to interfere with the diff engine // \n is sufficient to represent line breaks $temp = str_replace('<br />', '', $this->attention_description); $split_pos = strpos($temp, '>>>>>>>>>>'); if ($split_pos !== false) { if (!class_exists('diff_engine')) { include $this->phpbb_root_path . 'includes/diff/engine.' . $this->php_ext; include $this->phpbb_root_path . 'includes/diff/diff.' . $this->php_ext; include $this->phpbb_root_path . 'includes/diff/renderer.' . $this->php_ext; } $old = substr($temp, 0, $split_pos); $new = substr($temp, $split_pos + 10); $diff = new diff($old, $new); $renderer = new diff_renderer_inline(); // <pre> is used to display the diff, so get rid of \n to get remove double line spacing $desc_diff = str_replace("\n", '', html_entity_decode($renderer->get_diff_content($diff))); return $desc_diff; } return $this->attention_description; }