Overview

Packages

  • None
  • Wicked

Classes

  • Text_Wiki_Parse_Heading2
  • Text_Wiki_Parse_Toc2
  • Text_Wiki_Render_Latex_Heading2
  • Text_Wiki_Render_Latex_Toc2
  • Text_Wiki_Render_Plain_Heading2
  • Text_Wiki_Render_Plain_Toc2
  • Text_Wiki_Render_Rst
  • Text_Wiki_Render_Rst_Blockquote
  • Text_Wiki_Render_Rst_Bold
  • Text_Wiki_Render_Rst_Code
  • Text_Wiki_Render_Rst_Deflist
  • Text_Wiki_Render_Rst_Emphasis
  • Text_Wiki_Render_Rst_Freelink
  • Text_Wiki_Render_Rst_Heading2
  • Text_Wiki_Render_Rst_Links
  • Text_Wiki_Render_Rst_List
  • Text_Wiki_Render_Rst_Newline
  • Text_Wiki_Render_Rst_Paragraph
  • Text_Wiki_Render_Rst_Raw
  • Text_Wiki_Render_Rst_Toc2
  • Text_Wiki_Render_Rst_Tt
  • Text_Wiki_Render_Rst_Url
  • Text_Wiki_Render_Xhtml_Attribute
  • Text_Wiki_Render_Xhtml_Code2
  • Text_Wiki_Render_Xhtml_Freelink2
  • Text_Wiki_Render_Xhtml_Heading2
  • Text_Wiki_Render_Xhtml_Image2
  • Text_Wiki_Render_Xhtml_Interwiki
  • Text_Wiki_Render_Xhtml_Registrylink
  • Text_Wiki_Render_Xhtml_Toc2
  • Text_Wiki_Render_Xhtml_Url
  • Text_Wiki_Render_Xhtml_Wickedblock
  • Text_Wiki_Render_Xhtml_Wikilink2
  • Wicked
  • Wicked_Api
  • Wicked_Driver
  • Wicked_Driver_Sql
  • Wicked_Exception
  • Wicked_Factory_Driver
  • Wicked_Page
  • Wicked_Page_AddPage
  • Wicked_Page_AllPages
  • Wicked_Page_AttachedFiles
  • Wicked_Page_BackLinks
  • Wicked_Page_DeletePage
  • Wicked_Page_EditPage
  • Wicked_Page_LeastPopular
  • Wicked_Page_LikePages
  • Wicked_Page_MergeOrRename
  • Wicked_Page_MostPopular
  • Wicked_Page_NewPage
  • Wicked_Page_RecentChanges
  • Wicked_Page_RevertPage
  • Wicked_Page_Search
  • Wicked_Page_StandardHistoryPage
  • Wicked_Page_StandardPage
  • Wicked_Page_SyncDiff
  • Wicked_Page_SyncPages
  • Wicked_Sync
  • Wicked_Sync_Wicked
  • Wicked_Test
  • Overview
  • Package
  • Class
  • Tree
  1: <?php
  2: /**
  3:  * Wicked SyncDiff class.
  4:  *
  5:  * Copyright 2008-2012 Horde LLC (http://www.horde.org/)
  6:  *
  7:  * See the enclosed file COPYING for license information (GPL). If you
  8:  * did not receive this file, see http://www.horde.org/licenses/gpl.
  9:  *
 10:  * @author  Duck <duck@obala.net>
 11:  * @package Wicked
 12:  */
 13: class Wicked_Page_SyncDiff extends Wicked_Page_SyncPages {
 14: 
 15:     /**
 16:      * Display modes supported by this page.
 17:      */
 18:     public $supportedModes = array(
 19:         Wicked::MODE_CONTENT => true,
 20:         Wicked::MODE_DISPLAY => true);
 21: 
 22:     /**
 23:      * Sync driver
 24:      */
 25:     protected $_sync;
 26: 
 27:     /**
 28:      * Working page
 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:      * Renders this page in content mode.
 40:      *
 41:      * @throws Wicked_Exception
 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:      * @return string  The page contents.
 80:      * @throws Wicked_Exception
 81:      */
 82:     public function displayContents($isBlock)
 83:     {
 84:         return $this->content();
 85:     }
 86: 
 87:     /**
 88:      * Page name
 89:      */
 90:     public function pageName()
 91:     {
 92:         return 'SyncDiff';
 93:     }
 94: 
 95:     /**
 96:      * Page title
 97:      */
 98:     public function pageTitle()
 99:     {
100:         return _("Sync Diff");
101:     }
102: 
103:     /**
104:      * Tries to find out if any version's content is the same on the local and
105:      * remote servers.
106:      *
107:      * @throws Wicked_Exception
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: 
API documentation generated by ApiGen