====== DokuWiki Plugin: multitemplate_styleman ======
---- plugin ----
description: Solves the problem with style.ini and the MultiTemplate.
author : Pascal Bihler
email : bihler@iai.uni-bonn.de
type : action
lastupdate : 2007-06-27
compatible : 2008-05-05, 2006-11-06, 2007-05-24, 2007-06-26b
depends :
conflicts :
similar :
tags : style.ini, multitemplate, configuration, template
----
This is an extension for the [[http://tatewake.com/wiki/projects:multitemplate_for_dokuwiki|MultiTemplate]] template to solve the problem with tempates using ''style.ini'' (discussed [[http://tatewake.com/wiki/doku.php?id=projects:multitemplate_for_dokuwiki&rev=1177656191#style.ini|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 [[http://tatewake.com/wiki/projects:multitemplate_for_dokuwiki|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:((You know this game, if you have already tried to adapt existing templates for the use with [[http://tatewake.com/wiki/projects:multitemplate_for_dokuwiki|MultiTemplate]]))
===== Usage =====
With this plugin installed, you are now able to use templates making use of ''style.ini'' with [[http://tatewake.com/wiki/projects:multitemplate_for_dokuwiki|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 ====
*/
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://www.dokuwiki.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 ====
*/
//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. --- //[[chi@chimeric.de|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@notomorrow.de|sf]] 2008-10-11 12:05//