1<?php
2/**
3 * Multitemplate Styleman Action Plugin:   Hooks into stylsheet generation to allow
4 * templates managed by the mutlitemplate template (http://tatewake.com/wiki/projects:multitemplate_for_dokuwiki)
5 * the usage of style.ini
6 *
7 * @author     Pascal Bihler <bihler@iai.uni-bonn.de>
8 */
9
10if(!defined('DOKU_INC')) die();
11if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
12require_once(DOKU_PLUGIN.'action.php');
13
14class action_plugin_multitemplate_styleman extends DokuWiki_Action_Plugin {
15
16  /**
17   * return some info
18   */
19  function getInfo(){
20    return array(
21		 'author' => 'Pascal Bihler',
22		 'email'  => 'bihler@iai.uni-bonn.de',
23		 'date'   => '2009-02-02',
24		 'name'   => 'Multitemplate Stylemananager',
25		 'desc'   => 'Allows templates managed by Multitemplate to use style.ini',
26		 'url'    => 'http://wiki.splitbrain.org/plugin:multitemplate_styleman',
27		 );
28  }
29
30  /*
31   * Register its handlers with the dokuwiki's event controller
32   */
33  function register(&$controller) {
34       if ($this->isMultitemplateTemplateActive())
35    	 $controller->register_hook('TPL_METAHEADER_OUTPUT', 'BEFORE',  $this, '_replacecss');
36  }
37
38  /**
39   * Relocates the css-loading to own method
40   */
41  function _replacecss(&$event, $param) {
42	  global $ID,$conf;
43        global $DOKU_TPL;
44
45        $template = NULL;
46
47        // get current template from mutitemplate template:
48        // a modification to the current (2007-01-02) version of multitemplate/meat.php is required:
49        // Add the following line to the beginning of the file: "global $DOKU_TPL,$DOKU_TPLINC;"
50        if (preg_match('/\/([^\/]+)\/$/',$DOKU_TPL,$matches))
51          $template = $matches[1];
52
53        if (isset($template)) {
54
55           // Replace stylsheet requests
56           for ($i = 0; $i < count($event->data['link']); $i++) {
57               if (isset($event->data['link'][$i]['media'])) {
58                   $media = $event->data['link'][$i]['media'];
59
60                   // redirect to our css.php-wrapper
61                   $href = $event->data['link'][$i]['href'];
62                   $pos = strpos($href,'css.php');
63                   if ($pos !== false) {
64                       $params = substr($href,$pos+7);
65                       $params = str_replace( 't=multitemplate', '', $params );
66                       if (! $params)
67                       	  $href = DOKU_BASE.'lib/plugins/multitemplate_styleman/css.php?tpl=' . $template;
68                       else
69                       	  $href = DOKU_BASE.'lib/plugins/multitemplate_styleman/css.php' . $params . '&tpl=' . $template;
70                       $event->data['link'][$i]['href'] = $href;
71                   }
72               }
73           }
74        }
75  }
76
77
78   function isMultitemplateTemplateActive() {
79	     global $conf;
80       return ($conf['template'] == 'multitemplate');
81   }
82}