1<?php
2/**
3 * DokuWiki Action Plugin MetaHeaders
4 *
5 * @license     GPL 2 (http://www.gnu.org/licenses/gpl.html)
6 * @author      Stephen Flitman <sflitman@xenoscience.com>
7 */
8// must be run within Dokuwiki
9if(!defined('DOKU_INC')) die();
10
11if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
12require_once(DOKU_PLUGIN.'action.php');
13
14/**
15 * All DokuWiki plugins to extend the admin function
16 * need to inherit from this class
17 */
18class action_plugin_scriptheader extends DokuWiki_Action_Plugin {
19
20    public function getInfo() {
21        return array(
22                'author' => 'Stephen Flitman',
23                'email' => 'sflitman@xenoscience.com',
24                'date'   => @file_get_contents(DOKU_PLUGIN.'scriptheader/VERSION'),
25                'name' => 'scriptheader',
26                'desc' => 'Lets you add <script> headers to your wiki pages.',
27                'url' => 'http://dokuwiki.org/plugin:scriptheader'
28            );
29    }
30
31    public function register(Doku_Event_Handler $controller) {
32        $controller->register_hook('TPL_METAHEADER_OUTPUT', 'BEFORE', $this, 'scriptheader');
33    }
34
35    /**
36     * Modifies the script headers before their send to the browser.
37     *
38     * Stephen Flitman <sflitman@xenoscience.com>
39     */
40    public function scriptheader(&$event, $param) {
41       global $ID;
42       global $INFO;
43       global $ACT;
44
45       if ($ACT != 'show' || !page_exists($ID)) return;
46
47       $headerconf = DOKU_CONF . 'scriptheader.conf';
48       if (@file_exists($headerconf)) {
49          $scripts=confToHash($headerconf);
50          $except=$scripts['except'];
51          if ($except) {
52             if (preg_match($except,$ID)) return;
53             unset($scripts['except']);
54          }
55          foreach ($scripts as $i => $script) {
56             $event->data["script"][] = array (
57                     "type" => "text/javascript",
58                     "src" => $script,
59                     "_data" => "",
60             );
61          }
62       }
63       return true;
64   }
65}
66
67