1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12:
13: class Wicked_Page_SyncDiff extends Wicked_Page_SyncPages {
14:
15: 16: 17:
18: public $supportedModes = array(
19: Wicked::MODE_CONTENT => true,
20: Wicked::MODE_DISPLAY => true);
21:
22: 23: 24:
25: protected $_sync;
26:
27: 28: 29:
30: protected $_pageName;
31:
32: public function __construct()
33: {
34: parent::__construct();
35: $this->_pageName = Horde_Util::getGet('sync_page');
36: }
37:
38: 39: 40: 41: 42:
43: public function content()
44: {
45: if (!$this->_loadSyncDriver()) {
46: throw new Wicked_Exception(_("Synchronization is disabled"));
47: }
48:
49: $remote = $this->_sync->getPageSource($this->_pageName);
50: $page = Wicked_Page::getPage($this->_pageName);
51: $local = $page->getText();
52:
53: $inverse = Horde_Util::getGet('inverse', 1);
54:
55: if ($inverse) {
56: $diff = new Horde_Text_Diff('auto',
57: array(explode("\n", $local),
58: explode("\n", $remote)));
59: $name1 = _("Local");
60: $name2 = _("Remote");
61: } else {
62: $diff = new Horde_Text_Diff('auto',
63: array(explode("\n", $remote),
64: explode("\n", $local)));
65: $name1 = _("Remote");
66: $name2 = _("Local");
67: }
68:
69: $renderer = new Horde_Text_Diff_Renderer_Inline();
70:
71: Horde::addScriptFile('tables.js', 'horde', true);
72:
73: ob_start();
74: require WICKED_TEMPLATES . '/sync/diff.inc';
75: return ob_get_clean();
76: }
77:
78: 79: 80: 81:
82: public function displayContents($isBlock)
83: {
84: return $this->content();
85: }
86:
87: 88: 89:
90: public function pageName()
91: {
92: return 'SyncDiff';
93: }
94:
95: 96: 97:
98: public function pageTitle()
99: {
100: return _("Sync Diff");
101: }
102:
103: 104: 105: 106: 107: 108:
109: protected function _getSameVersion()
110: {
111: $local = $GLOBALS['wicked']->getHistory($this->_pageName);
112: $info = $this->getLocalPageInfo($this->_pageName);
113: $local[] = $info;
114: $remote = $this->_sync->getPageHistory($this->_pageName);
115: $info = $this->getRemotePageInfo($this->_pageName);
116: $remote[] = $info;
117:
118: $checksums = array();
119: foreach (array_keys($local) as $i) {
120: if (!isset($local[$i]['page_checksum'])) {
121: $local[$i]['page_checksum'] = md5($local[$i]['page_text']);
122: unset($local[$i]['page_text']);
123: }
124: $checksums[$i] = $local[$i]['page_checksum'];
125: }
126:
127: $result = false;
128: foreach ($remote as $history) {
129: $version = array_search($history['page_checksum'], $checksums);
130: if ($version !== false) {
131: $result = array('remote' => $history, 'local' => $local[$version]);
132: break;
133: }
134: }
135:
136: return $result;
137: }
138:
139: }
140: