1<?php
2/**
3 * Table Plot Action Plugin
4 *
5 *  Plots a table using JQPlot libraries
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';
15require_once (DOKU_INC.'inc/parserutils.php');
16
17class action_plugin_tableplot extends DokuWiki_Action_Plugin {
18
19    function getInfo() {
20        return array(
21            'author' => 'Tom Cafferty',
22            'email'  => 'tcafferty@glocalfocal.com',
23            'date'   => '2011-12-29',
24            'name'   => 'tableplot',
25            'desc'   => 'Integrate jquery jqPlot plugin with dokuwiki',
26            'url'    => 'http://www.dokuwiki.org/plugin:tableplot',
27        );
28    }
29
30    /**
31     * Register its handlers with the DokuWiki's event controller
32     */
33    function register(&$controller) {
34        $controller->register_hook('TPL_METAHEADER_OUTPUT', 'BEFORE', $this, 'tableplot_hookjs');
35    }
36
37    /**
38     * Hook js script into page headers.
39     *
40     * @author Tom Cafferty <tcafferty@glocalfocal.com>
41     */
42    function tableplot_hookjs(&$event, $param) {
43        global $INFO;
44        global $ID;
45        $basePath = DOKU_BASE;
46        $basePath = str_replace("dokuwiki/", "", $basePath);
47
48        $key = 'keywords';
49        $metadata = p_get_metadata($ID, $key, false);
50
51        // metadata check to include javascript files if needed
52        if (p_get_metadata($ID, 'plugin tableplot') || (strpos($metadata, 'table2plot') !== false) ) {
53                $event->data['link'][] = array(
54                            'rel' => 'stylesheet',
55                            'type'    => 'text/css',
56                            '_data'   => '',
57                            'href'     => $basePath ."lib/scripts/jqplot/jquery.jqplot.min.css");
58            $event->data['script'][] = array(
59                            'type'    => 'text/javascript',
60                            'charset' => 'utf-8',
61                            '_data'   => '',
62                            'src'     => $basePath ."lib/scripts/jquery/jquery.min.js");
63            $event->data['script'][] = array(
64                            'type'    => 'text/javascript',
65                            'charset' => 'utf-8',
66                            '_data'   => '',
67                            'src'     => $basePath ."lib/scripts/jqplot/jquery.jqplot.min.js");
68            $event->data['script'][] = array(
69                            'type'    => 'text/javascript',
70                            'charset' => 'utf-8',
71                            '_data'   => '',
72                            'src'     => $basePath ."lib/scripts/jqplot/plugins/jqplot.barRenderer.min.js");
73            $event->data['script'][] = array(
74                            'type'    => 'text/javascript',
75                            'charset' => 'utf-8',
76                            '_data'   => '',
77                            'src'     => $basePath ."lib/scripts/jqplot/plugins/jqplot.categoryAxisRenderer.min.js");
78            $event->data['script'][] = array(
79                            'type'    => 'text/javascript',
80                            'charset' => 'utf-8',
81                            '_data'   => '',
82                            'src'     => $basePath ."lib/scripts/jqplot/plugins/jqplot.dateAxisRenderer.min.js");
83            $event->data['script'][] = array(
84                            'type'    => 'text/javascript',
85                            'charset' => 'utf-8',
86                            '_data'   => '',
87                            'src'     => $basePath ."lib/scripts/jqplot/plugins/jqplot.canvasTextRenderer.min.js");
88            $event->data['script'][] = array(
89                            'type'    => 'text/javascript',
90                            'charset' => 'utf-8',
91                            '_data'   => '',
92                            'src'     => $basePath ."lib/scripts/jqplot/plugins/jqplot.canvasAxisTickRenderer.min.js");
93            $event->data['script'][] = array(
94                            'type'    => 'text/javascript',
95                            'charset' => 'utf-8',
96                            '_data'   => '',
97                            'src'     => $basePath ."lib/scripts/jqplot/plugins/jqplot.highlighter.js");
98            $event->data['script'][] = array(
99                            'type'    => 'text/javascript',
100                            'charset' => 'utf-8',
101                            '_data'   => '',
102                            'src'     => $basePath ."lib/scripts/jqplot/plugins/jqplot.pointLabels.min.js");
103            $event->data['script'][] = array(
104                            'type'    => 'text/javascript',
105                            'charset' => 'utf-8',
106                            '_data'   => '',
107                            'src'     => $basePath ."lib/scripts/jqplot/plugins/jqplot.enhancedLegendRenderer.min.js");
108            $event->data['script'][] = array(
109                            'type'    => 'text/javascript',
110                            'charset' => 'utf-8',
111                            '_data'   => '',
112                            'src'     => $basePath ."lib/scripts/jqplot/plugins/jqplot.pieRenderer.min.js");
113            $event->data['script'][] = array(
114                            'type'    => 'text/javascript',
115                            'charset' => 'utf-8',
116                            '_data'   => '',
117                            'src'     => DOKU_BASE."lib/plugins/tableplot/table2Plot.js");
118       }
119    }
120}