DokuWiki Plugin: multitemplate_styleman

multitemplate_styleman plugin by Pascal Bihler
Solves the problem with style.ini and the MultiTemplate.

Last updated on 2007-06-27. Provides Action.
Compatible with DokuWiki 2008-05-05, 2006-11-06, 2007-05-24, 2007-06-26b.

Tagged with configuration, multitemplate, style.ini, template.

This is an extension for the MultiTemplate template to solve the problem with tempates using style.ini (discussed here).

Download / Installation

Download the plugin here (manually or via Plugin Manager): http://pb.wh4f.de/dokuwiki/multitemplate_styleman.zip

The plugin is compatible with dokuwiki version 2006-11-06 and version 2007-06-26. It requires, that the MultiTemplate template is installed.

For the current version of multitemplate, a small addition in the file /lib/tpl/multitemplate/meat.php is required.

Add the following line to the top of the meat.php file:1)

<?php global $DOKU_TPL,$DOKU_TPLINC; ?>

Usage

With this plugin installed, you are now able to use templates making use of style.ini with MultiTemplate . No additional configuration is required.

Remark: if you want to use the default-template, copy the folder /lib/tpl/default/images/ to /lib/tpl/multitemplate/images/ to assure
that the little icons on the bottom work properly.

Code

The plugin consist of two files:

action.php

<?php
/**
 * Multitemplate Styleman Action Plugin:   Hooks into stylsheet generation to allow
 * templates managed by the mutlitemplate template (http://tatewake.com/wiki/projects:multitemplate_for_dokuwiki)
 * the usage of style.ini
 * 
 * @author     Pascal Bihler <bihler@iai.uni-bonn.de>
 */
 
if(!defined('DOKU_INC')) die();
if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
require_once(DOKU_PLUGIN.'action.php');
 
class action_plugin_multitemplate_styleman extends DokuWiki_Action_Plugin {
 
  /**
   * return some info
   */
  function getInfo(){
    return array(
		 'author' => 'Pascal Bihler',
		 'email'  => 'bihler@iai.uni-bonn.de',
		 'date'   => '2007-06-27',
		 'name'   => 'Multitemplate Stylemananager',
		 'desc'   => 'Allows templates managed by Multitemplate to use style.ini',
		 'url'    => 'http://wiki.splitbrain.org/plugin:multitemplate_styleman',
		 );
  }
 
  /*
   * Register its handlers with the dokuwiki's event controller
   */
  function register(&$controller) {
       if ($this->isMultitemplateTemplateActive())
    	 $controller->register_hook('TPL_METAHEADER_OUTPUT', 'BEFORE',  $this, '_replacecss');
  }
 
  /**
   * Relocates the css-loading to own method
   */
  function _replacecss(&$event, $param) {
	  global $ID,$conf;
        global $DOKU_TPL;
 
        $template = NULL;
 
        // get current template from mutitemplate template:
        // a modification to the current (2007-01-02) version of multitemplate/meat.php is required:
        // Add the following line to the beginning of the file: "global $DOKU_TPL,$DOKU_TPLINC;"
        if (preg_match('/\/([^\/]+)\/$/',$DOKU_TPL,$matches))
          $template = $matches[1];
 
        if (isset($template)) {
 
           // Replace stylsheet requests
           for ($i = 0; $i < count($event->data['link']); $i++) {
               if (isset($event->data['link'][$i]['media'])) {
                   $media = $event->data['link'][$i]['media'];
 
                   // redirect to our css.php-wrapper
                   $href = $event->data['link'][$i]['href'];
                   $pos = strpos($href,'css.php');
                   if ($pos !== false) {
                       $params = substr($href,$pos+7);
                       if (! $params) 
                       	  $href = DOKU_BASE.'lib/plugins/multitemplate_styleman/css.php?tpl=' . $template;
                       else 
                       	  $href = DOKU_BASE.'lib/plugins/multitemplate_styleman/css.php' . $params . '&tpl=' . $template;
                       $event->data['link'][$i]['href'] = $href;
                   }
               }
           }  
        }
  }
 
 
   function isMultitemplateTemplateActive() {
	     global $conf;
       return ($conf['template'] == 'multitemplate');
   }
}

css.php

<?php
/**
 * DokuWiki StyleSheet creator wrapper
 *
 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
 * @author     Pascal Bihler <bihler@iai.uni-bonn.de>
 */
 
 //Load all the basic includes (like css.php tries to do later)
 
if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../../').'/');
if(!defined('NOSESSION')) define('NOSESSION',true); // we do not use a session or authentication here (better caching)
 
$template = NULL;
if (isset($_REQUEST['tpl'])) {
    $tpl = $_REQUEST['tpl'];
    if (preg_match('/^[a-z0-9_-]+$/iD', $tpl)) { //seems to be a valid template name, and not a code injection...
        $template = $tpl;
    }
}
 
// We set the template constants before init.php can do it...
if (isset($template)) {
 
   //Inherit DOKU_BASE from server variables in order to avoid config reading here...
   $script_name = $_SERVER['SCRIPT_NAME'];
   $DOKU_BASE = substr($script_name,0,strlen($script_name)-strlen('lib/plugins/multitemplate_styleman/css.php'));
   define('DOKU_TPL', $DOKU_BASE.'lib/tpl/'  . $template .'/');
   define('DOKU_TPLINC',realpath(dirname(__FILE__).'/../../') . '/tpl/' . $template .'/');
}
 
//Load environment parameters
require_once(DOKU_INC.'inc/init.php');
require_once(DOKU_INC.'inc/pageutils.php');
require_once(DOKU_INC.'inc/io.php');
require_once(DOKU_INC.'inc/confutils.php');
 
// Redirect template: 
if (isset($template))
   $conf['template'] = $template;
 
//Now we let the original css.php do the rest
require_once(realpath(dirname(__FILE__).'/../../').'/exe/css.php');
?>

Discussion

Just a minor note. I think it would be better just to replace the style links in the action.php rather then unsetting > the whole array. This way you loose the alternate/contents/opensearch meta links. — Michael Klier 2007-05-22 15:09

Good point, I adapted the plugin accordingly. — Pascal 2007-06-22 13:38

Great work, thank you so much! —Pekka 2008-03-14 15:33
1) You know this game, if you have already tried to adapt existing templates for the use with MultiTemplate
 
plugin/multitemplate_styleman.txt · Last modified: 2008/05/07 11:00 by pbihler
 
Imprint Recent changes RSS feed Creative Commons License Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki
WikiForumIRCBugsTranslate