/** * Process * * @access private * @return string Json */ private function _process() { //----------------------------------------- // INIT //----------------------------------------- $pergo = intval($this->request['perGo']) ? intval($this->request['perGo']) : 10; $diffSessionID = intval($this->request['sessionID']); $completed = 0; //----------------------------------------- // Fetch current session //----------------------------------------- $session = $this->skinFunctions->fetchSession($diffSessionID); if ($session === FALSE) { $this->returnJsonError('Could not locate a valid differences session'); exit; } //----------------------------------------- // Get Diff library //----------------------------------------- require_once IPS_KERNEL_PATH . 'classDifference.php'; $classDifference = new classDifference(); $classDifference->method = 'PHP'; //----------------------------------------- // Get template bits to check //----------------------------------------- $this->DB->build(array('select' => '*', 'from' => 'skin_templates', 'where' => 'template_set_id=0', 'order' => 'template_id ASC', 'limit' => array(intval($session['diff_session_done']), intval($pergo)))); $outer = $this->DB->execute(); if (!$this->DB->getTotalRows($outer)) { $completed = 1; } else { while ($row = $this->DB->fetch($outer)) { //----------------------------------------- // Get corresponding row from diff table //----------------------------------------- $diff_row = $this->DB->buildAndFetch(array('select' => '*', 'from' => 'templates_diff_import', 'where' => "diff_func_group='{$row['template_group']}' AND diff_func_name='{$row['template_name']}' AND diff_session_id=" . $diffSessionID)); //----------------------------------------- // Got anything? //----------------------------------------- if ($diff_row['diff_key']) { //----------------------------------------- // Get difference //----------------------------------------- $difference = $classDifference->getDifferences($diff_row['diff_func_content'], $row['template_content']); //----------------------------------------- // Got any differences? //----------------------------------------- if ($classDifference->diff_found) { //----------------------------------------- // Get corresponding row from diff table //----------------------------------------- $diff_check = $this->DB->buildAndFetch(array('select' => 'diff_change_key', 'from' => 'template_diff_changes', 'where' => "diff_change_key='" . $diffSessionID . ':' . $row['template_group'] . ':' . $row['template_name'] . "'")); if ($diff_check['diff_change_key']) { $this->DB->update('template_diff_changes', array('diff_change_func_group' => $row['template_group'], 'diff_change_func_name' => $row['template_name'], 'diff_change_content' => $difference, 'diff_change_type' => 1, 'diff_session_id' => $diffSessionID), "diff_change_key='" . $diffSessionID . ':' . $row['template_group'] . ':' . $row['template_name'] . "'"); } else { $this->DB->insert('template_diff_changes', array('diff_change_key' => $diffSessionID . ':' . $row['template_group'] . ':' . $row['template_name'], 'diff_change_func_group' => $row['template_group'], 'diff_change_func_name' => $row['template_name'], 'diff_change_content' => $difference, 'diff_change_type' => 1, 'diff_session_id' => $diffSessionID)); } } } else { if (!$session['diff_session_ignore_missing']) { $this->DB->insert('template_diff_changes', array('diff_change_key' => $diffSessionID . ':' . $row['template_group'] . ':' . $row['template_name'], 'diff_change_func_group' => $row['template_group'], 'diff_change_func_name' => $row['template_name'], 'diff_change_content' => htmlspecialchars($row['template_content']), 'diff_change_type' => 0, 'diff_session_id' => $diffSessionID)); } } //----------------------------------------- // Increment //----------------------------------------- $session['diff_session_done']++; } } //----------------------------------------- // Update current session //----------------------------------------- $this->DB->update('template_diff_session', array('diff_session_done' => intval($session['diff_session_done'])), 'diff_session_id=' . $diffSessionID); //----------------------------------------- // Done or more? //----------------------------------------- $this->returnJsonArray(array('processed' => $session['diff_session_done'], 'completed' => $completed, 'message' => $session['diff_session_done'] . ' template bits processed...')); }
/** * Get differences of a template * * @return @e void */ protected function _getDifferences() { //----------------------------------------- // Init //----------------------------------------- $setID = intval($this->request['setID']); $templateID = intval($this->request['template_id']); //----------------------------------------- // Get requested //----------------------------------------- $current = $this->DB->buildAndFetch(array('select' => '*', 'from' => 'skin_templates', 'where' => 'template_id=' . $templateID)); if ($current['template_set_id']) { //----------------------------------------- // Get the original //----------------------------------------- $set = $this->DB->buildAndFetch(array('select' => 'set_master_key', 'from' => 'skin_collections', 'where' => 'set_id=' . $current['template_set_id'])); $set['set_master_key'] = $set['set_master_key'] ? $set['set_master_key'] : 'root'; $original = $this->DB->buildAndFetch(array('select' => '*', 'from' => 'skin_templates', 'where' => "template_set_id=0 AND template_master_key='{$set['set_master_key']}' AND template_group='{$current['template_group']}' AND template_name='{$current['template_name']}'")); } else { $original['template_content'] = $current['template_content']; } //----------------------------------------- // Get Diff library //----------------------------------------- require_once IPS_KERNEL_PATH . 'classDifference.php'; /*noLibHook*/ $classDifference = new classDifference(); $classDifference->method = 'PHP'; $difference = $classDifference->getDifferences($original['template_content'], $current['template_content'], 'unified'); if (1 == 1) { $difference = str_replace(array("\r\n", "\r"), "\n", $difference); $difference = preg_replace('#(^|\\n)(\\-|\\+)([^\\n]+?)\\n#', "\n\\1\\2\\3\n\n", $difference); $difference = htmlspecialchars($difference); $difference = preg_replace('#^@@([^@]+?)@@#m', '', $difference); $difference = preg_replace('#(^|\\n)\\-([^\\n]+?)\\n#', "\\1<del>\\2</del>\n", $difference); $difference = preg_replace('#(^|\\n)\\+([^\\n]+?)\\n#', "\\1<ins>\\2</ins>\n", $difference); $difference = str_replace("</ins>\n\n", "</ins>\n", $difference); $difference = str_replace("</del>\n", '</del>', $difference); $difference = str_replace("\n\n<ins>", "\n<ins>", $difference); $difference = str_replace("\n\n<del>", "\n<del>", $difference); $difference = '<pre>' . $difference . '</pre>'; } else { if ($classDifference->diff_found) { $difference = str_replace("\n", "<br>", $difference); $difference = str_replace("><", ">\n<", $difference); $difference = preg_replace("#(?<!(\\<del|\\<ins)) {1}(?!:style)#i", " ", $difference); $difference = str_replace("\t", " ", $difference); } else { $difference = htmlspecialchars($current['template_content']); $difference = str_replace(' ', ' ', $difference); $difference = str_replace("\r", '<br />', $difference); $difference = str_replace("\n", '<br />', $difference); $difference = str_replace("><", ">\n<", $difference); $difference = str_replace("\t", " ", $difference); } } $this->returnHtml($this->html->differenceResult($difference)); }
/** * Get differences of a template * * @access private * @return void */ private function _getDifferences() { //----------------------------------------- // Init //----------------------------------------- $setID = intval($this->request['setID']); $templateID = intval($this->request['template_id']); //----------------------------------------- // Get requested //----------------------------------------- $current = $this->DB->buildAndFetch(array('select' => '*', 'from' => 'skin_templates', 'where' => 'template_id=' . $templateID)); if ($current['template_set_id']) { //----------------------------------------- // Get the original //----------------------------------------- $original = $this->DB->buildAndFetch(array('select' => '*', 'from' => 'skin_templates', 'where' => "template_set_id=0 AND template_group='{$current['template_group']}' AND template_name='{$current['template_name']}'")); } else { $original['template_content'] = $current['template_content']; } //----------------------------------------- // Get Diff library //----------------------------------------- require_once IPS_KERNEL_PATH . 'classDifference.php'; $classDifference = new classDifference(); $classDifference->method = 'PHP'; $difference = $classDifference->getDifferences($original['template_content'], $current['template_content']); if ($classDifference->diff_found) { $difference = str_replace("\n", "<br>", $difference); $difference = str_replace("><", ">\n<", $difference); $difference = preg_replace("#(?<!(\\<del|\\<ins)) {1}(?!:style)#i", " ", $difference); $difference = str_replace("\t", " ", $difference); } else { $difference = htmlspecialchars($current['template_content']); $difference = str_replace(' ', ' ', $difference); $difference = str_replace("\r", '<br />', $difference); $difference = str_replace("\n", '<br />', $difference); $difference = str_replace("><", ">\n<", $difference); $difference = str_replace("\t", " ", $difference); } $this->returnHtml($this->html->differenceResult($difference)); }