1*123bc813SAndreas Gohr<?php 2*123bc813SAndreas Gohr/** 3*123bc813SAndreas Gohr * DokuWiki Plugin styling (Action Component) 4*123bc813SAndreas Gohr * 5*123bc813SAndreas Gohr * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html 6*123bc813SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 7*123bc813SAndreas Gohr */ 8*123bc813SAndreas Gohr 9*123bc813SAndreas Gohr// must be run within Dokuwiki 10*123bc813SAndreas Gohrif(!defined('DOKU_INC')) die(); 11*123bc813SAndreas Gohr 12*123bc813SAndreas Gohr/** 13*123bc813SAndreas Gohr * Class action_plugin_styling 14*123bc813SAndreas Gohr * 15*123bc813SAndreas Gohr * This handles all the save actions and loading the interface 16*123bc813SAndreas Gohr * 17*123bc813SAndreas Gohr * All this usually would be done within an admin plugin, but we want to have this available outside 18*123bc813SAndreas Gohr * the admin interface using our floating dialog. 19*123bc813SAndreas Gohr */ 20*123bc813SAndreas Gohrclass action_plugin_styling extends DokuWiki_Action_Plugin { 21*123bc813SAndreas Gohr 22*123bc813SAndreas Gohr /** 23*123bc813SAndreas Gohr * Registers a callback functions 24*123bc813SAndreas Gohr * 25*123bc813SAndreas Gohr * @param Doku_Event_Handler $controller DokuWiki's event controller object 26*123bc813SAndreas Gohr * @return void 27*123bc813SAndreas Gohr */ 28*123bc813SAndreas Gohr public function register(Doku_Event_Handler $controller) { 29*123bc813SAndreas Gohr $controller->register_hook('AJAX_CALL_UNKNOWN', 'BEFORE', $this, 'handle_ajax'); 30*123bc813SAndreas Gohr $controller->register_hook('ACTION_ACT_PREPROCESS', 'BEFORE', $this, 'handle_action'); 31*123bc813SAndreas Gohr $controller->register_hook('TPL_METAHEADER_OUTPUT', 'BEFORE', $this, 'handle_header'); 32*123bc813SAndreas Gohr } 33*123bc813SAndreas Gohr 34*123bc813SAndreas Gohr /** 35*123bc813SAndreas Gohr * Adds the preview parameter to the stylesheet loading in non-js mode 36*123bc813SAndreas Gohr * 37*123bc813SAndreas Gohr * @param Doku_Event $event event object by reference 38*123bc813SAndreas Gohr * @param mixed $param [the parameters passed as fifth argument to register_hook() when this 39*123bc813SAndreas Gohr * handler was registered] 40*123bc813SAndreas Gohr * @return void 41*123bc813SAndreas Gohr */ 42*123bc813SAndreas Gohr public function handle_header(Doku_Event &$event, $param) { 43*123bc813SAndreas Gohr global $ACT; 44*123bc813SAndreas Gohr global $INPUT; 45*123bc813SAndreas Gohr if($ACT != 'admin' || $INPUT->str('page') != 'styling') return; 46*123bc813SAndreas Gohr if(!auth_isadmin()) return; 47*123bc813SAndreas Gohr 48*123bc813SAndreas Gohr // set preview 49*123bc813SAndreas Gohr $len = count($event->data['link']); 50*123bc813SAndreas Gohr for($i = 0; $i < $len; $i++) { 51*123bc813SAndreas Gohr if( 52*123bc813SAndreas Gohr $event->data['link'][$i]['rel'] == 'stylesheet' && 53*123bc813SAndreas Gohr strpos($event->data['link'][$i]['href'], 'lib/exe/css.php') !== false 54*123bc813SAndreas Gohr ) { 55*123bc813SAndreas Gohr $event->data['link'][$i]['href'] .= '&preview=1&tseed='.time(); 56*123bc813SAndreas Gohr } 57*123bc813SAndreas Gohr } 58*123bc813SAndreas Gohr } 59*123bc813SAndreas Gohr 60*123bc813SAndreas Gohr /** 61*123bc813SAndreas Gohr * Updates the style.ini settings by passing it on to handle() of the admin component 62*123bc813SAndreas Gohr * 63*123bc813SAndreas Gohr * @param Doku_Event $event event object by reference 64*123bc813SAndreas Gohr * @param mixed $param [the parameters passed as fifth argument to register_hook() when this 65*123bc813SAndreas Gohr * handler was registered] 66*123bc813SAndreas Gohr * @return void 67*123bc813SAndreas Gohr */ 68*123bc813SAndreas Gohr public function handle_action(Doku_Event &$event, $param) { 69*123bc813SAndreas Gohr if($event->data != 'styling_plugin') return; 70*123bc813SAndreas Gohr if(!auth_isadmin()) return; 71*123bc813SAndreas Gohr $event->data = 'show'; 72*123bc813SAndreas Gohr 73*123bc813SAndreas Gohr /** @var admin_plugin_styling $hlp */ 74*123bc813SAndreas Gohr $hlp = plugin_load('admin', 'styling'); 75*123bc813SAndreas Gohr $hlp->handle(); 76*123bc813SAndreas Gohr } 77*123bc813SAndreas Gohr 78*123bc813SAndreas Gohr /** 79*123bc813SAndreas Gohr * Create the style form in the floating Dialog 80*123bc813SAndreas Gohr * 81*123bc813SAndreas Gohr * @param Doku_Event $event event object by reference 82*123bc813SAndreas Gohr * @param mixed $param [the parameters passed as fifth argument to register_hook() when this 83*123bc813SAndreas Gohr * handler was registered] 84*123bc813SAndreas Gohr * @return void 85*123bc813SAndreas Gohr */ 86*123bc813SAndreas Gohr 87*123bc813SAndreas Gohr public function handle_ajax(Doku_Event &$event, $param) { 88*123bc813SAndreas Gohr if($event->data != 'plugin_styling') return; 89*123bc813SAndreas Gohr if(!auth_isadmin()) return; 90*123bc813SAndreas Gohr $event->preventDefault(); 91*123bc813SAndreas Gohr $event->stopPropagation(); 92*123bc813SAndreas Gohr 93*123bc813SAndreas Gohr global $ID; 94*123bc813SAndreas Gohr global $INPUT; 95*123bc813SAndreas Gohr $ID = getID(); 96*123bc813SAndreas Gohr 97*123bc813SAndreas Gohr /** @var admin_plugin_styling $hlp */ 98*123bc813SAndreas Gohr $hlp = plugin_load('admin', 'styling'); 99*123bc813SAndreas Gohr if($INPUT->str('run') == 'preview') { 100*123bc813SAndreas Gohr $hlp->run_preview(); 101*123bc813SAndreas Gohr } else { 102*123bc813SAndreas Gohr $hlp->form(true); 103*123bc813SAndreas Gohr } 104*123bc813SAndreas Gohr } 105*123bc813SAndreas Gohr 106*123bc813SAndreas Gohr} 107*123bc813SAndreas Gohr 108*123bc813SAndreas Gohr// vim:ts=4:sw=4:et: 109