1123bc813SAndreas Gohr<?php 28553d24dSAndreas Gohruse dokuwiki\Extension\ActionPlugin; 38553d24dSAndreas Gohruse dokuwiki\Extension\EventHandler; 48553d24dSAndreas Gohruse dokuwiki\Extension\Event; 5123bc813SAndreas Gohr/** 6123bc813SAndreas Gohr * DokuWiki Plugin styling (Action Component) 7123bc813SAndreas Gohr * 8123bc813SAndreas Gohr * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html 9123bc813SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 10123bc813SAndreas Gohr */ 118553d24dSAndreas Gohrclass action_plugin_styling extends ActionPlugin 1271a75f04SAndreas Gohr{ 13123bc813SAndreas Gohr 14123bc813SAndreas Gohr /** 15123bc813SAndreas Gohr * Registers a callback functions 16123bc813SAndreas Gohr * 17123bc813SAndreas Gohr * @param Doku_Event_Handler $controller DokuWiki's event controller object 18123bc813SAndreas Gohr * @return void 19123bc813SAndreas Gohr */ 208553d24dSAndreas Gohr public function register(EventHandler $controller) 2171a75f04SAndreas Gohr { 2271a75f04SAndreas Gohr $controller->register_hook('TPL_METAHEADER_OUTPUT', 'BEFORE', $this, 'handleHeader'); 23123bc813SAndreas Gohr } 24123bc813SAndreas Gohr 25123bc813SAndreas Gohr /** 26123bc813SAndreas Gohr * Adds the preview parameter to the stylesheet loading in non-js mode 27123bc813SAndreas Gohr * 28123bc813SAndreas Gohr * @param Doku_Event $event event object by reference 29123bc813SAndreas Gohr * @param mixed $param [the parameters passed as fifth argument to register_hook() when this 30123bc813SAndreas Gohr * handler was registered] 31123bc813SAndreas Gohr * @return void 32123bc813SAndreas Gohr */ 338553d24dSAndreas Gohr public function handleHeader(Event &$event, $param) 3471a75f04SAndreas Gohr { 35123bc813SAndreas Gohr global $ACT; 36123bc813SAndreas Gohr global $INPUT; 37123bc813SAndreas Gohr if ($ACT != 'admin' || $INPUT->str('page') != 'styling') return; 38dda9db03SAndreas Gohr /** @var admin_plugin_styling $admin */ 39dda9db03SAndreas Gohr $admin = plugin_load('admin', 'styling'); 40dda9db03SAndreas Gohr if (!$admin->isAccessibleByCurrentUser()) return; 41123bc813SAndreas Gohr 42123bc813SAndreas Gohr // set preview 43123bc813SAndreas Gohr $len = count($event->data['link']); 44123bc813SAndreas Gohr for ($i = 0; $i < $len; $i++) { 45*7d34963bSAndreas Gohr if ( 46*7d34963bSAndreas Gohr $event->data['link'][$i]['rel'] == 'stylesheet' && 47123bc813SAndreas Gohr strpos($event->data['link'][$i]['href'], 'lib/exe/css.php') !== false 48123bc813SAndreas Gohr ) { 49123bc813SAndreas Gohr $event->data['link'][$i]['href'] .= '&preview=1&tseed='.time(); 50123bc813SAndreas Gohr } 51123bc813SAndreas Gohr } 52123bc813SAndreas Gohr } 53123bc813SAndreas Gohr} 54123bc813SAndreas Gohr 55123bc813SAndreas Gohr// vim:ts=4:sw=4:et: 56