====== Plugin Loadskin ====== ---- plugin ---- description: Change the skin/template/theme (admins can select templates per page/namespace or users can select a template for the whole wiki) author : Anika Henke (previous author: Michael Klier) email : anika@selfthinker.org type : action admin helper lastupdate : 2011-02-07 compatible : Angua, 2011-05-25 "Rincewind", 2010-11-07 "Anteater", 2009-12-25 "Lemming", 2009-02-14, 2008-05-05 depends : conflicts : similar : tags : template, skin, theme downloadurl: http://github.com/selfthinker/dokuwiki-plugin-loadskin/tarball/master bugtracker : http://github.com/selfthinker/dokuwiki-plugin-loadskin/issues sourcerepo : http://github.com/selfthinker/dokuwiki-plugin-loadskin/ ---- ===== Download and Installation ===== Download and install the plugin using the [[plugin:plugin|Plugin Manager]] using the URL given above. Refer to [[:Plugins]] on how to install plugins manually. The plugin is also available via git. % cd /lib/plugins % git clone git://github.com/selfthinker/dokuwiki-plugin-loadskin.git loadskin **:!: IMPORTANT :!:** The plugin won't work without the following small changes to DokuWiki's source code! They are necessary in order to allow the plugin to interfere with the template constants used by DokuWiki. Remove (or comment) the following lines in ''/inc/init.php'' around line 123: // define Template baseURL if(!defined('DOKU_TPL')) define('DOKU_TPL', DOKU_BASE.'lib/tpl/'.$conf['template'].'/'); // define real Template directory if(!defined('DOKU_TPLINC')) define('DOKU_TPLINC', DOKU_INC.'lib/tpl/'.$conf['template'].'/'); ===== Usage ===== This plugin can be used in two ways: Admins can specify different templates for different wiki pages or namespaces or users can use a select box for the whole wiki. ==== Admin way: Specify templates per namespace/page ==== The plugin comes with an admin component you'll find in the admin menu. Use it to specify the templates to be used for different wiki pages or namespaces. ==== User way: Select template for whole wiki ==== Alternatively the plugin can let the user choose the template for the whole wiki through a template switcher. Your users will need to **allow cookies** for that (otherwise the template won't switch permanently). ===== Configuration ===== ^''automaticOutput''| Automatically output the template switcher on every page (turn this off if you don't want to show the template switcher or want to put it somewhere else) | ^''excludeTemplates''| Exclude templates from template switcher (comma-separated list) | The template switcher is automatically put before the wiki content. If you like to put it somewhere else (e.g. near the login button or into the sidebar), you need to switch ''automaticOutput'' and put the following code into your template to wherever you like to display it: loadHelper('loadskin', true); echo $loadskinHelper->showTemplateSwitcher(); ?> ===== Changelog ===== A complete changelog is available [[http://github.com/selfthinker/dokuwiki-plugin-loadskin/commits/|here]]. {{rss>http://github.com/feeds/selfthinker/commits/dokuwiki-plugin-loadskin/master 10 1d date}} ===== Discussion ===== ==== Multitemplate template ==== Does this plugin do the same thing as [[:template:multitemplate|the multitemplate template]]? --- //[[tjgrant@tatewake.com|Terence J. Grant]] 2008/08/09 05:38// > Yes, but it doesn't require to modify the templates (instead it requires a change in the DokuWiki source which isn't optimal either, however with the ''inc/preload.php'' in the current devel version this shouldn't be no problem). Hope you don't mind the competition. --- //[[chi@chimeric.de|Michael Klier]] 2008/08/09 10:14// >> I'd rather phase out multitemplate in favor of this actually... --- //[[tjgrant@tatewake.com|Terence J. Grant]] 2008/08/10 00:34// ==== Templates per user ==== This worked just as advertised. Very nice. =) Now, how hard would it be to make a plug-in that allows individual users to choose a template that suits their visual limitations (low lux, large fonts, etc.)? --- //Joyful 2008/09/18 06:32// > I just implemented a template switcher that can be used by every user to switch to any installed template. --- [[user>ach]] //2010/11/29 01:46// >> The latest version even stores the template per user if you're logged in. --- [[user>ach]] //2011/02/07 02:34// ==== Appreciation ==== Super Plugin!!! Vielen Dank! tokuehn@web.de 05.06.2009 ==== Manager sets template for whole wiki ==== :!: This doesn't work as advertised with my Anteater DW. I want different templates for different namespaces. I see, how the template manager can handle it, but each time I set a new 'property' (namespace -> template), the tpl gets applied to the **whole wiki** :-( Any ideas? //Lnz 2011/01/19 00:04// > This is a bug which only affects the admin who has used the template manager. Everyone else (including the admin who opens the wiki in a different browser) is not affected by that bug and it will work as expected for them. The only way to make it go away for the admin currently is to clear the DokuWiki cookie. I will fix it and release a new version (with some more changes) this coming weekend. --- [[user>ach]] //2011/01/19 02:32// >> You're right! It only affects the admin... It works as advertised now. Thank you for your quick response -//Lnz 2011/01/20// >>> A bit later than planned, but I updated the plugin now, which will fix that problem. The old bug will still be in affect because the old values are stored in the cookie. So, you'd either have to delete your DokuWiki cookie or use the follow "trick": Add ''?tpl=*&act=select'' to the end of the URL of your wiki, and that should take care of things and revert to your usual settings. --- [[user>ach]] //2011/02/07 02:34// ==== Templates per user patch ==== Here's a patch for per user templates Richard Westwell 09.12.2010 > The bad thing about this patch is, that it's not just a patch for the plugin but also changes the DokuWiki core. Template choices per user are supported by the plugin since version 2011-02-07 anyway. --- [[user>ach|Anika Henke]] //2011/05/29 13:31// diff -Naur D:\Sites\dokuwiki.orig/inc/auth.php D:\Sites\dokuwiki.new/inc/auth.php --- D:\Sites\dokuwiki.orig/inc/auth.php 2010-11-07 16:43:03.000000000 +0000 +++ D:\Sites\dokuwiki.new/inc/auth.php 2010-12-09 14:25:33.677367100 +0000 @@ -789,9 +789,20 @@ return false; } + //Get the Selected / stored Template + $selectedtemplate = $_POST['perusertpl']; + $themeconfig = DOKU_INC.'conf/loadskin_user.conf'; + if(@file_exists($themeconfig)) { + $themedata = unserialize(io_readFile($themeconfig, false)); + if(!empty($themedata)) { + $storedtemplate = $themedata[$INFO[client]]; + } + } + if ($_POST['fullname'] != $INFO['userinfo']['name'] && $auth->canDo('modName')) $changes['name'] = $_POST['fullname']; if ($_POST['email'] != $INFO['userinfo']['mail'] && $auth->canDo('modMail')) $changes['mail'] = $_POST['email']; if (!empty($_POST['newpass']) && $auth->canDo('modPass')) $changes['pass'] = $_POST['newpass']; + if ($selectedtemplate != $storedtemplate) $changes['perusertpl'] = $selectedtemplate; if (!count($changes)) { msg($lang['profnochange'], -1); @@ -811,6 +822,16 @@ list($user,$sticky,$pass) = explode('|',$cookie,3); if ($changes['pass']) $pass = PMA_blowfish_encrypt($changes['pass'],auth_cookiesalt()); + //Save selected template + if(@file_exists($themeconfig)) { + $themedata = unserialize(io_readFile($themeconfig, false)); + $themedata[$INFO[client]] = $selectedtemplate; + io_saveFile($themeconfig, serialize($themedata)); + } else { + $themedata[$INFO[client]] = $selectedtemplate; + io_saveFile($themeconfig, serialize( $themedata)); + } + auth_setCookie($_SERVER['REMOTE_USER'],$pass,(bool)$sticky); return true; } diff -Naur D:\Sites\dokuwiki.orig/inc/html.php D:\Sites\dokuwiki.new/inc/html.php --- D:\Sites\dokuwiki.orig/inc/html.php 2010-11-07 16:43:04.000000000 +0000 +++ D:\Sites\dokuwiki.new/inc/html.php 2010-12-09 14:19:20.867253100 +0000 @@ -1115,6 +1115,27 @@ $form->addElement(form_makeTag('br')); $form->addElement(form_makePasswordField('oldpass', $lang['oldpass'], '', 'block', array('size'=>'50'))); } + + // Show the Drop Down for the Selected Template + $selectedtemplate = 'default'; + $themeconfig = DOKU_INC.'conf/loadskin_user.conf'; + + if(@file_exists($themeconfig)) { + $themedata = unserialize(io_readFile($themeconfig, false)); + if(!empty($themedata)) { + $selectedtemplate = $themedata[$INFO[client]]; + } + } + + $form->addElement(form_makeListboxField('perusertpl',getTemplates(),$selectedtemplate,'Template')); + $form->addElement(form_makeTag('br')); + $form->addElement(form_makeTag('br')); + $form->addElement(form_makeButton('submit', '', $lang['btn_save'])); $form->addElement(form_makeButton('reset', '', $lang['btn_reset'])); $form->endFieldset(); @@ -1122,6 +1143,28 @@ print ''.NL; } + /** + * Returns an array of available templates to choose from + * + * @author Michael Klier + */ + function getTemplates() { + $tpl_dir = DOKU_INC.'lib/tpl/'; + if ($dh = @opendir($tpl_dir)) { + while (false !== ($entry = readdir($dh))) { + if ($entry == '.' || $entry == '..') continue; + if (!preg_match('/^[\w-]+$/', $entry)) continue; + + $file = (is_link(_dir.$entry)) ? readlink($tpl_dir.$entry) : $entry; + if (is_dir($tpl_dir.$file)) $list[] = $entry; + } + closedir($dh); + sort($list); + $list[] = 'use selector'; + } + return $list; + } + + /** * Preprocess edit form data * diff -Naur D:\Sites\dokuwiki.orig/lib/plugins/loadskin/action.php D:\Sites\dokuwiki.new/lib/plugins/loadskin/action.php --- D:\Sites\dokuwiki.orig/lib/plugins/loadskin/action.php 2010-11-29 00:50:58.000000000 +0000 +++ D:\Sites\dokuwiki.new/lib/plugins/loadskin/action.php 2010-12-09 14:48:04.090599400 +0000 @@ -99,6 +99,22 @@ * @author Anika Henke */ function getTpl() { + + // get template from per user setup + $themeconfig = DOKU_INC.'conf/loadskin_user.conf'; + + global $INFO; + io_saveFile('conf/test.conf',serialize($INFO)); + + if(@file_exists($themeconfig)) { + $themedata = unserialize(io_readFile($themeconfig, false)); + if(!empty($themedata)) { + if ($themedata[$INFO[client]] != 'use selector') { + return $themedata[$INFO[client]]; + } + } + } + + + // get template from session if ($_REQUEST['tpl']) $_SESSION[DOKU_COOKIE]['loadskinTpl'] = $_REQUEST['tpl']; ==== Template script.js does not work without DOKU_TPLINC ==== :!: I noticed small trouble with javascript loading. All ''lib/tpl//script.js'' should be loaded at the start. But because I commented out part of ''init.php'' definig DOKU_TPLINC as suggested, ''script.js'' in template directory does not get loaded. It's because DOKU_TPLINC constant is needed when list of scripts to include is generated. It is in ''lib/exe/js.php'' in function ''js_out()''. The plugin is great anyway, but it took me some time to localize reason, why my new template does not uses the script.js, so be warned. --- //Jan Kreps 2011/03/16 12:38// > Thanks for reporting this issue. I [[https://github.com/selfthinker/dokuwiki-plugin-loadskin/issues/3|added it the bug tracker]] to better be able to keep track of it. I don't know when I will fix it, as I don't have much time at the moment. --- [[user>ach|Anika Henke]] //2011/05/29 13:31// ==== Template per HTTP_USER_AGENT ==== It could be a great step for Multi-Device-DokuWiki Usinge, to admin a relation list between THEME <-> HTTP_USER_AGENT.\\