Table of Contents
DokuWiki Plugin: multitemplate_styleman
Compatible with DokuWiki
2008-05-05, 2006-11-06, 2007-05-24, 2007-06-26b
This extension has not been updated in over 2 years. It may no longer be maintained or supported and may have compatibility issues.
Extension name contains underscore, will not generate popularity points.
Similar to templateconfhelper
This is an extension for the MultiTemplate template to solve the problem with templates 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 stylesheet generation to allow * templates managed by the mutlitemplate template (http://dokuwiki.org/template:multitemplate) * 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' => '2009-02-02', 'name' => 'Multitemplate Stylemananager', 'desc' => 'Allows templates managed by Multitemplate to use style.ini', 'url' => 'http://www.dokuwiki.org/plugin:multitemplate_styleman', ); } /* * Register its handlers with the DokuWiki's event controller */ function register(Doku_Event_Handler $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); $params = str_replace( 't=multitemplate', '', $params ); 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
Hello, for me this did not work as long as t was set in the css call as lib/exe/css.php does not use DOKU_TPL.
$params = str_replace( 't=multitemplate', '', $params );fixed this. — sf 2008-10-11 12:05
The same for me, and I could not have done it without SF's help who gave me this essential precision:
in/lib/plugins/multitemplate_styleman/action.phpafter
$params = substr($href,$pos+7);add
$params = str_replace( 't=multitemplate', '', $params );I suggest that this should be implemented in the next plugin release… — NewMorning 2008/12/21 16:49
done — Pascal 2009-02-02 14:01