1<?php
2
3if(!defined('DOKU_INC')) die();
4if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
5require_once(DOKU_PLUGIN.'action.php');
6
7class action_plugin_freesync extends DokuWiki_Action_Plugin {
8	var $fshlp;
9
10	function action_plugin_freesync () {
11		$this->fshlp =& plugin_load('helper', 'freesync');
12	}
13
14	/**
15	 * return some info
16	 */
17	function getInfo(){
18		return array(
19	 'author' => 'Mikhail I. Izmestev',
20	 'email'  => 'izmmishao5@gmail.com',
21	 'date'   => '2009-03-11',
22	 'name'   => 'freesync ajax handler',
23	 'desc'   => '',
24	 'url'    => '',
25		);
26	}
27
28	/**
29	 * Register its handlers with the DokuWiki's event controller
30	 */
31	function register(&$controller) {
32		$controller->register_hook('AJAX_CALL_UNKNOWN', 'BEFORE',  $this, '_ajax_handler');
33	}
34
35	function _ajax_handler(&$event, $param) {
36		if($event->data != '_freesync_page_l2r'
37		&& $event->data != '_freesync_page_r2l'
38		&& $event->data != '_freesync_file_l2r'
39		&& $event->data != '_freesync_file_r2l'
40		&& $event->data != '_freesync_diff') return;
41
42		$this->fshlp->loadProfile($_REQUEST['profile']);
43
44		header('Content-Type: text/html; charset=utf-8');
45		switch($event->data) {
46			case "_freesync_page_l2r": print $this->fshlp->page_l2r($_REQUEST['id'], $_REQUEST['sum']); break;
47			case "_freesync_page_r2l": print $this->fshlp->page_r2l($_REQUEST['id'], $_REQUEST['sum']); break;
48			case "_freesync_file_l2r": print $this->fshlp->file_l2r($_REQUEST['id'], $_REQUEST['sum']); break;
49			case "_freesync_file_r2l": print $this->fshlp->file_r2l($_REQUEST['id'], $_REQUEST['sum']); break;
50			case "_freesync_diff": print $this->fshlp->getDiff($_REQUEST['id']); break;
51		}
52		$event->preventDefault();
53		return;
54	}
55}
56