1123bc813SAndreas Gohr<?php 2123bc813SAndreas Gohr/** 3123bc813SAndreas Gohr * DokuWiki Plugin styling (Action Component) 4123bc813SAndreas Gohr * 5123bc813SAndreas Gohr * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html 6123bc813SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 7123bc813SAndreas Gohr */ 8123bc813SAndreas Gohr 9123bc813SAndreas Gohr// must be run within Dokuwiki 10123bc813SAndreas Gohrif(!defined('DOKU_INC')) die(); 11123bc813SAndreas Gohr 12123bc813SAndreas Gohr/** 13123bc813SAndreas Gohr * Class action_plugin_styling 14123bc813SAndreas Gohr * 15123bc813SAndreas Gohr * This handles all the save actions and loading the interface 16123bc813SAndreas Gohr * 17123bc813SAndreas Gohr * All this usually would be done within an admin plugin, but we want to have this available outside 18123bc813SAndreas Gohr * the admin interface using our floating dialog. 19123bc813SAndreas Gohr */ 20123bc813SAndreas Gohrclass action_plugin_styling extends DokuWiki_Action_Plugin { 21123bc813SAndreas Gohr 22123bc813SAndreas Gohr /** 23123bc813SAndreas Gohr * Registers a callback functions 24123bc813SAndreas Gohr * 25123bc813SAndreas Gohr * @param Doku_Event_Handler $controller DokuWiki's event controller object 26123bc813SAndreas Gohr * @return void 27123bc813SAndreas Gohr */ 28123bc813SAndreas Gohr public function register(Doku_Event_Handler $controller) { 29123bc813SAndreas Gohr $controller->register_hook('TPL_METAHEADER_OUTPUT', 'BEFORE', $this, 'handle_header'); 30123bc813SAndreas Gohr } 31123bc813SAndreas Gohr 32123bc813SAndreas Gohr /** 33123bc813SAndreas Gohr * Adds the preview parameter to the stylesheet loading in non-js mode 34123bc813SAndreas Gohr * 35123bc813SAndreas Gohr * @param Doku_Event $event event object by reference 36123bc813SAndreas Gohr * @param mixed $param [the parameters passed as fifth argument to register_hook() when this 37123bc813SAndreas Gohr * handler was registered] 38123bc813SAndreas Gohr * @return void 39123bc813SAndreas Gohr */ 40123bc813SAndreas Gohr public function handle_header(Doku_Event &$event, $param) { 41123bc813SAndreas Gohr global $ACT; 42123bc813SAndreas Gohr global $INPUT; 43123bc813SAndreas Gohr if($ACT != 'admin' || $INPUT->str('page') != 'styling') return; 44*dda9db03SAndreas Gohr /** @var admin_plugin_styling $admin */ 45*dda9db03SAndreas Gohr $admin = plugin_load('admin', 'styling'); 46*dda9db03SAndreas Gohr if(!$admin->isAccessibleByCurrentUser()) return; 47123bc813SAndreas Gohr 48123bc813SAndreas Gohr // set preview 49123bc813SAndreas Gohr $len = count($event->data['link']); 50123bc813SAndreas Gohr for($i = 0; $i < $len; $i++) { 51123bc813SAndreas Gohr if( 52123bc813SAndreas Gohr $event->data['link'][$i]['rel'] == 'stylesheet' && 53123bc813SAndreas Gohr strpos($event->data['link'][$i]['href'], 'lib/exe/css.php') !== false 54123bc813SAndreas Gohr ) { 55123bc813SAndreas Gohr $event->data['link'][$i]['href'] .= '&preview=1&tseed='.time(); 56123bc813SAndreas Gohr } 57123bc813SAndreas Gohr } 58123bc813SAndreas Gohr } 59123bc813SAndreas Gohr 60123bc813SAndreas Gohr} 61123bc813SAndreas Gohr 62123bc813SAndreas Gohr// vim:ts=4:sw=4:et: 63