1<?php 2/** 3 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) 4 * @author Randolf Rotta <rrotta@informatik.tu-cottbus.de> 5 */ 6 7// must be run within Dokuwiki 8if (!defined('DOKU_INC')) die(); 9 10if (!defined('DOKU_LF')) define('DOKU_LF', "\n"); 11if (!defined('DOKU_TAB')) define('DOKU_TAB', "\t"); 12if (!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); 13 14require_once(DOKU_PLUGIN.'action.php'); 15 16class action_plugin_usercss extends DokuWiki_Action_Plugin{ 17 var $pagename = ':usercss'; 18 19 function getInfo(){ 20 return array( 21 'author' => 'Randolf Rotta', 22 'email' => 'rrotta@informatik.tu-cottbus.de', 23 'date' => '2009-04-05', 24 'name' => 'user-editable CSS', 25 'desc' => 'Uses CSS definitions from a wiki page', 26 'url' => 'http://www.dokuwiki.org/plugin:usercss', 27 ); 28 } 29 30 function register(&$contr){ 31 $contr->register_hook( 32 'TPL_CSS_OUTPUT', 33 'BEFORE', 34 $this, 35 'add_css', 36 array() 37 ); 38 $contr->register_hook( 39 'TPL_CSS_CACHEOK', 40 'BEFORE', 41 $this, 42 'add_cached_files', 43 array() 44 ); 45 } 46 47 function add_css(&$event, $param) { 48 // get content from wiki page 49 $txt = io_readWikiPage(wikiFN($this->pagename), $this->pagename); 50 51 // filter for CSS definitions in <code css> blocks 52 preg_match_all('/<code css>(.*?)<\/code>/sm', $txt, $matches); 53 $usercss = implode("\n", $matches[1]); 54 55 // fix url() locations 56 $usercss = preg_replace_callback( 57 '#(url\([ \'"]*)([^\'"]*)#', 58 create_function('$matches', 59 'global $ID; $m = $matches[2]; 60 resolve_mediaid(getNS($ID), $m, $exists); 61 return $matches[1].ml($m);'), 62 $usercss); 63 64 // append all 65 $event->data .= $usercss; 66 } 67 68 function add_cached_files(&$event, $param) { 69 $event->data[] = wikiFN($this->pagename); 70 } 71 72} 73 74//Setup VIM: ex: et ts=4 enc=utf-8 :