Example #1
0
 public function actionIndex()
 {
     $contentType = $this->_input->filterSingle('content_type', XenForo_Input::STRING);
     $contentId = $this->_input->filterSingle('content_id', XenForo_Input::UINT);
     $historyModel = $this->_getHistoryModel();
     $handler = $historyModel->getEditHistoryHandler($contentType);
     if (!$handler) {
         return $this->responseNoPermission();
     }
     $content = $handler->getContent($contentId);
     if (!$content || !$handler->canViewHistoryAndContent($content)) {
         return $this->responseNoPermission();
     }
     if (isset($content['edit_count']) && !$content['edit_count']) {
         return $this->responseError(new XenForo_Phrase('this_content_has_not_been_edited'));
     }
     $list = $historyModel->getEditHistoryListForContent($contentType, $contentId, array('join' => XenForo_Model_EditHistory::FETCH_USER));
     if (!$list) {
         return $this->responseError(new XenForo_Phrase('this_content_edit_history_has_been_removed'));
     }
     $oldId = $this->_input->filterSingle('old', XenForo_Input::UINT);
     $newId = $this->_input->filterSingle('new', XenForo_Input::UINT);
     if ($oldId) {
         // doing a comparison
         $old = $historyModel->getEditHistoryById($oldId);
         $oldText = $old['old_text'];
         if ($newId) {
             $new = $historyModel->getEditHistoryById($newId);
             $newText = $new['old_text'];
         } else {
             $newText = $handler->getText($content);
         }
         $diffHandler = new XenForo_Diff();
         $diffs = $diffHandler->findDifferences($oldText, $newText, XenForo_Diff::DIFF_TYPE_LINE);
     } else {
         $diffs = array();
     }
     $newestHistory = reset($list);
     $this->_routeMatch->setSections($handler->getNavigationTab());
     $viewParams = array('content' => $content, 'contentType' => $contentType, 'contentId' => $contentId, 'title' => $handler->getTitle($content), 'breadCrumbs' => $handler->getBreadcrumbs($content), 'list' => $list, 'diffs' => $diffs, 'oldId' => $oldId ? $oldId : $newestHistory['edit_history_id'], 'newId' => $newId);
     if ($oldId) {
         return $this->responseView('XenForo_ViewPublic_EditHistory_Compare', 'edit_history_compare', $viewParams);
     } else {
         return $this->responseView('XenForo_ViewPublic_EditHistory_Index', 'edit_history_index', $viewParams);
     }
 }
Example #2
0
 public function actionCompare()
 {
     $results = $this->_getTemplateWithParentForCompare();
     $template = $results['template'];
     $style = $results['style'];
     $parentStyle = $results['parentStyle'];
     $parentTemplate = $results['parentTemplate'];
     $diff = new XenForo_Diff();
     $diffs = $diff->findDifferences($parentTemplate['template'], $template['template']);
     $viewParams = array('template' => $template, 'parentTemplate' => $parentTemplate, 'style' => $style, 'parentStyle' => $parentStyle, 'diffs' => $diffs);
     return $this->responseView('XenForo_ViewAdmin_Template_Compare', 'template_compare', $viewParams);
 }
Example #3
0
 public function findDifferences($mine, $original, $yours, $type = XenForo_Diff::DIFF_TYPE_LINE)
 {
     $mineDiff = $this->_comparer->findDifferences($original, $mine, $type);
     $yourDiff = $this->_comparer->findDifferences($original, $yours, $type);
     $output = array();
     $this->_initBlock();
     $m = reset($mineDiff);
     $y = reset($yourDiff);
     while ($m || $y) {
         if ($m && $y) {
             $mType = $m[0];
             $mBlocks =& $m[1];
             $yType = $y[0];
             $yBlocks =& $y[1];
             if ($mType == XenForo_Diff::EQUAL && $yType == XenForo_Diff::EQUAL) {
                 $this->_finishBlock($output);
                 $i = $this->_getMatchLength($mBlocks, $yBlocks);
                 if (!$i) {
                     throw new Exception("Both equal but no leading match?");
                 }
                 $matches = array_splice($mBlocks, 0, $i);
                 $output[] = array(self::EQUAL, $matches);
                 array_splice($yBlocks, 0, $i);
                 if (!$mBlocks) {
                     $m = next($mineDiff);
                 }
                 if (!$yBlocks) {
                     $y = next($yourDiff);
                 }
             } else {
                 if ($mType == XenForo_Diff::INSERT) {
                     $this->_appendMine($mBlocks);
                     $m = next($mineDiff);
                 } else {
                     if ($yType == XenForo_Diff::INSERT) {
                         $this->_appendYours($yBlocks);
                         $y = next($yourDiff);
                     } else {
                         if ($mType == XenForo_Diff::DELETE && $yType == XenForo_Diff::DELETE) {
                             $this->_finishBlock($output);
                             $i = $this->_getMatchLength($mBlocks, $yBlocks);
                             if (!$i) {
                                 throw new Exception("Both deletes but no leading match?");
                             }
                             $this->_appendOrig(array_splice($mBlocks, 0, $i));
                             array_splice($yBlocks, 0, $i);
                             if (!$mBlocks) {
                                 $m = next($mineDiff);
                             }
                             if (!$yBlocks) {
                                 $y = next($yourDiff);
                             }
                         } else {
                             if ($mType == XenForo_Diff::DELETE && $yType == XenForo_Diff::EQUAL) {
                                 $min = min(count($mBlocks), count($yBlocks));
                                 array_splice($mBlocks, 0, $min);
                                 // removed
                                 $block = array_splice($yBlocks, 0, $min);
                                 $this->_appendOrig($block);
                                 $this->_appendYours($block);
                                 if (!$mBlocks) {
                                     $m = next($mineDiff);
                                 }
                                 if (!$yBlocks) {
                                     $y = next($yourDiff);
                                 }
                             } else {
                                 if ($yType == XenForo_Diff::DELETE && $mType == XenForo_Diff::EQUAL) {
                                     $min = min(count($mBlocks), count($yBlocks));
                                     array_splice($yBlocks, 0, $min);
                                     // removed
                                     $block = array_splice($mBlocks, 0, $min);
                                     $this->_appendOrig($block);
                                     $this->_appendMine($block);
                                     if (!$mBlocks) {
                                         $m = next($mineDiff);
                                     }
                                     if (!$yBlocks) {
                                         $y = next($yourDiff);
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         } else {
             if ($m) {
                 if ($m[0] != XenForo_Diff::INSERT) {
                     throw new Exception("Had m only but wasn't insert");
                 }
                 $this->_appendMine($m[1]);
                 $m = next($mineDiff);
             } else {
                 if ($y) {
                     if ($y[0] != XenForo_Diff::INSERT) {
                         throw new Exception("Had y only but wasn't insert");
                     }
                     $this->_appendYours($y[1]);
                     $y = next($yourDiff);
                 }
             }
         }
     }
     $this->_finishBlock($output);
     return $this->_finalize($output);
 }
 public function actionTest()
 {
     $dw = $this->_getUpdatedModificationDwFromInput();
     $dw->preSave();
     if ($dw->getError('template')) {
         return $this->responseError($dw->getError('template'));
     } else {
         if ($dw->getError('find')) {
             return $this->responseError($dw->getError('find'));
         }
     }
     $content = $this->_getTestContent($dw);
     if (!is_string($content)) {
         return $this->responseError(new XenForo_Phrase('requested_template_not_found'));
     }
     $modification = $dw->getMergedData();
     if (empty($modification['modification_id'])) {
         $modification['modification_id'] = 1;
     }
     $contentModified = $this->_getModificationModel()->applyTemplateModifications($content, array($modification));
     $content = $this->_adjustTemplateContentForDisplay($content);
     $contentModified = $this->_adjustTemplateContentForDisplay($contentModified);
     $diff = new XenForo_Diff();
     $diffs = $diff->findDifferences($content, $contentModified);
     $viewParams = array('modification' => $modification, 'content' => $content, 'contentModified' => $contentModified, 'diffs' => $diffs);
     return $this->responseView($this->_viewPrefix . 'Test', $this->_templatePrefix . 'test', $viewParams);
 }