1<?php
2/**
3 * Plugin animation: combine a sequence of images to create an animation"
4 *
5 * Syntax:
6 <ani id url type max interval autoplay | opts>
7 *
8 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
9 * @author     Yihui Xie <xie@yihui.name>
10 */
11if(!defined('DOKU_INC')) die();
12if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
13require_once(DOKU_PLUGIN.'action.php');
14
15class action_plugin_animation extends DokuWiki_Action_Plugin {
16
17    /*
18    * return some info
19    */
20    function getInfo(){
21        return array(
22            'author' => 'Yihui Xie',
23            'email'  => 'xie@yihui.name',
24            'date'   => '2012-02-22',
25            'name'   => 'Animation Plugin',
26            'desc'   => 'Generate an animation from a sequence of images, e.g. 1.png, 2.png, ...',
27            'url'    => 'https://github.com/yihui/dokuwiki',
28                     );
29    }
30
31    /*
32    * plugin should use this method to register its handlers with the dokuwiki's event controller
33    */
34    function register(&$controller) {
35        $controller->register_hook('TPL_METAHEADER_OUTPUT',
36                                   'BEFORE',
37                                   $this,
38                                   '_hooksh'
39                                   );
40
41        $controller->register_hook('TPL_ACT_RENDER',
42                                   'AFTER',
43                                   $this,
44                                   '_hookjsprocessing'
45                                   );
46    }
47
48    /*
49    *  Inject the SyntaxHightlighter files
50    *
51    *  @author David Shin <dshin@pimpsmart.com>
52    *  @param $event object target event
53    *  @param $param mixed event parameters passed from register_hook
54    *
55    *  To add other brushes, add file name(s) to the $brushes array.
56    */
57    function _hooksh (&$event, $param) {
58
59        // Add stylesheets
60        $anistyles = array('shCore', 'shThemeDefault', 'scianimator');
61        foreach ($anistyles as $anistyle) {
62            $event->data['link'][] = array( 'rel'   => 'stylesheet',
63                                            'type'  => 'text/css',
64                                            'href'  => DOKU_BASE.'lib/plugins/animation/styles/' . $anistyle . '.css',
65                                            );
66        }
67
68        // Add JS
69        $brushes = array("shCore.js","shAutoloader.js","shBrushR.js", "jquery.scianimator.min.js");
70
71        // Register all brushes.
72        foreach ($brushes as $brush) {
73            $event->data["script"][] = array ("type"   => "text/javascript",
74                                               "src"   => DOKU_BASE."lib/plugins/animation/scripts/".$brush,
75                                               "_data" => ""
76                                               );
77        }
78
79        $morecode = array();
80        $addjs = '';
81        trigger_event('JQUERY_READY', $morecode, NULL, false);
82        foreach ($morecode as $id=>$mc) {
83            $addjs .= '// BEGIN --- ' . $id . PHP_EOL;
84            $addjs .= $mc . PHP_EOL;
85            $addjs .= '// END --- ' . $id . PHP_EOL;
86        }
87
88        $fulljs = 'jQuery.noConflict();' . PHP_EOL;
89        if (!empty($addjs)) {
90            $fulljs .= 'jQuery(document).ready(function() {' . PHP_EOL;
91            $fulljs .= $addjs . PHP_EOL;
92            $fulljs .= '});' . PHP_EOL;
93        }
94        $event->data['script'][] = array(
95            'type' => 'text/javascript',
96            'charset' => 'utf-8',
97            '_data' => $fulljs,
98        );
99
100    }
101
102    /*
103    *  Inject the SyntaxHightlighter javascript processing
104    *
105    *  @author Dominik
106    *  @param $event object target event
107    *  @param $param mixed event parameters passed from register_hook
108    *
109    */
110    function _hookjsprocessing (&$event, $param) {
111        global $ID;
112        global $INFO;
113
114        //this ensures that code will be written only on base page
115        //not on other inlined wiki pages (e.g. when using monobook template)
116        if ($ID != $INFO["id"]) return;
117
118        ptln("");
119        ptln("<script type=\"text/javascript\">");
120        ptln("  SyntaxHighlighter.defaults[\"toolbar\"] = false;");
121        ptln("  SyntaxHighlighter.all();");
122        ptln("</script>");
123
124    }
125}
126