1<?php
2/**
3 * Timeline Action Plugin
4 *
5 *  Provides a wiki timeline
6 *
7 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
8 * @author     Tom Cafferty <tcafferty@glocalfocal.com>
9 */
10
11// must be run within Dokuwiki
12if(!defined('DOKU_INC')) die();
13if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
14require_once DOKU_PLUGIN.'action.php';
15
16class action_plugin_eventline extends DokuWiki_Action_Plugin {
17
18    function getInfo() {
19        return array(
20            'author' => 'Tom Cafferty',
21            'email'  => 'tcafferty@glocalfocal.com',
22            'date'   => '2011-09-30',
23            'name'   => 'eventline',
24            'desc'   => 'Integrate simile timeline with dokuwiki',
25            'url'    => 'http://www.dokuwiki.org/plugin:eventline'
26        );
27    }
28
29    /**
30     * Register its handlers with the DokuWiki's event controller
31     */
32    function register(&$controller) {
33        $controller->register_hook('TPL_METAHEADER_OUTPUT', 'BEFORE', $this, 'eventline_hookjs');
34        $controller->register_hook('ACTION_ACT_PREPROCESS', 'BEFORE', $this, 'convert',array());
35    }
36
37    /**
38     * Hook js script into page headers.
39     *
40     * @author Tom Cafferty <tcafferty@glocalfocal.com>
41     */
42    function eventline_hookjs(&$event, $param) {
43        global $INFO;
44        global $ID;
45
46        // metadata check to include javascript files if needed
47        if (p_get_metadata($ID, 'plugin eventline')) {
48            $event->data['script'][] = array(
49                            'type'    => 'text/javascript',
50                            'charset' => 'utf-8',
51                            '_data'   => 'Timeline_urlPrefix="'.DOKU_BASE.'lib/plugins/eventline/timeline_js/";');
52            $event->data['script'][] = array(
53                            'type'    => 'text/javascript',
54                            'charset' => 'utf-8',
55                            '_data'   => "Timeline_parameters='bundle=true';");
56            $event->data['script'][] = array(
57                            'type'    => 'text/javascript',
58                            'charset' => 'utf-8',
59                            '_data'   => '',
60                            'src'     => DOKU_BASE."lib/plugins/eventline/timeline_ajax/simile-ajax-api.js");
61            $event->data['script'][] = array(
62                            'type'    => 'text/javascript',
63                            'charset' => 'utf-8',
64                            '_data'   => '',
65                            'src'     => DOKU_BASE."lib/plugins/eventline/timeline_js/timeline-api.js");
66            $event->data['script'][] = array(
67                            'type'    => 'text/javascript',
68                            'charset' => 'utf-8',
69                            '_data'   => '',
70                            'src'     => DOKU_BASE."lib/plugins/eventline/timeline.js");
71            $event->data['script'][] = array(
72                            'type'    => 'text/javascript',
73                            'charset' => 'utf-8',
74                            '_data'   => "SimileAjax.History.enabled=false;");
75       }
76    }
77
78    /**
79     * convert script for xml plain text file output.
80     *
81     * @author Tom Cafferty <tcafferty@glocalfocal.com>
82     */
83    function convert(&$event, $param) {
84        global $ACT;
85        global $ID;
86        global $conf;
87        $key = 'keywords';
88
89        // our event?
90        if ($ACT != 'export_timeline' ) return false;
91
92        // check user's rights
93        if ( auth_quickaclcheck($ID) < AUTH_READ ) return false;
94
95        // it's ours, no one else's
96        require_once ('getXmlData.php');
97        $event->preventDefault();
98
99       $wikihtml = '';
100       $metadata = p_get_metadata($ID, $key, false);
101       if (strpos($metadata, 'eventline_html') !== false) {
102         $wikihtml = 1; }
103       elseif (strpos($metadata, 'eventline_nohtml') !== false) {
104         $wikihtml = 0; }
105       else {
106        $wikihtml = $this->getConf('wikihtml'); }
107
108        // get page data
109        if (strpos($metadata, 'eventline_fr') !== false) {
110            setlocale(LC_CTYPE, 'fr_FR');
111            $html = iconv('UTF-8', 'ASCII//TRANSLIT', pullInXmlData($ID, $wikihtml));
112            $html = str_ireplace("'", "&#039;", $html);
113        } else {
114            $html = pullInXmlData($ID, $wikihtml);
115        }
116
117        // write to xml file
118        $fp = fopen(DOKU_INC . 'data/pages/'. str_replace(":", "/", $ID) . '.xml', 'w');
119        fwrite($fp, $html);
120        fclose($fp);
121
122        // remain on current page
123        header("HTTP/1.1 204 No Content");
124        exit();
125    }
126}
127