function viewRevisions($page, $l, $sectionMap = false) { global $DB, $Controller; if (is_numeric($page)) { $page = $Controller->{(string) $page}(EDIT); } $lang = google::languages($l); $revisions = array(); $_REQUEST->setType('rev1', 'numeric', true); $_REQUEST->setType('rev2', 'numeric', true); //FIXME: Move to CSS Head::add('ins {background: lightgreen;} del {background: pink;} .revlegend {text-align: right;display:inline;margin: 0 0 0 45px;} .revlegend ins,.revlegend del {margin: 0 5px;}', 'css-raw'); $r1 = false; $r2 = false; $r = $DB->content->get(array('id' => $this->that->ID, 'language' => $l), false, false, 'revision DESC'); while ($rev = Database::fetchAssoc($r)) { $revisions[$rev['section']][$rev['revision']] = strftime('%c', $rev['revision']); if ($_REQUEST['rev1'][$rev['section']] === $rev['revision']) { $r1[$rev['section']] = $rev; } if ($_REQUEST['rev2'][$rev['section']] === $rev['revision']) { $r2[$rev['section']] = $rev; } } $revArray = array(); if ($revisions) { foreach ($revisions as $sectionName => $sectContent) { $revArray[] = new Tab($sectionMap && isset($sectionMap[$sectionName]) ? $sectionMap[$sectionName] : $sectionName, new Li(new Select('View revision', 'rev1[' . $sectionName . ']', $sectContent, $_REQUEST['rev1'][$sectionName], false, __('None')), new Submit('Revert to this', 'revert1[' . $sectionName . ']')), new Li(new Select('Compare to', 'rev2[' . $sectionName . ']', $sectContent, $_REQUEST['rev2'][$sectionName], false, __('None')), new Submit('Revert to this', 'revert2[' . $sectionName . ']')), isset($r1[$sectionName]) ? '<div class="revlegend"><ins>' . strftime('%c', $r1[$sectionName]['revision']) . '</ins>' . (isset($r2[$sectionName]) ? '<del>' . strftime('%c', $r2[$sectionName]['revision']) . '</del></div>' . '<div id="revdiff">' . diff($r2[$sectionName]['content'], $r1[$sectionName]['content']) . '</div>' : '<div id="revdiff">' . strip_tags($r1[$sectionName]['content'], '<p><div>') . '</div>') : null); } $rForm = new Form('revisionsForm', url(null, array('id', 'edit', 'view', 'lang'), false)); return '<div class="nav">' . Short::backn() . '</div>' . $rForm->collection(new Hidden('lang', $l), new Tabber('r' . $l, $revArray)); } else { return '<div class="nav">' . Short::backn() . '</div>' . __('There are no saved revisions for this page and language'); } }