You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

57 lines
1.7 KiB

  1. <?php
  2. use dokuwiki\Extension\ActionPlugin;
  3. use dokuwiki\Extension\EventHandler;
  4. use dokuwiki\Extension\Event;
  5. /**
  6. * DokuWiki Plugin styling (Action Component)
  7. *
  8. * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
  9. * @author Andreas Gohr <andi@splitbrain.org>
  10. */
  11. class action_plugin_styling extends ActionPlugin
  12. {
  13. /**
  14. * Registers a callback functions
  15. *
  16. * @param EventHandler $controller DokuWiki's event controller object
  17. * @return void
  18. */
  19. public function register(EventHandler $controller)
  20. {
  21. $controller->register_hook('TPL_METAHEADER_OUTPUT', 'BEFORE', $this, 'handleHeader');
  22. }
  23. /**
  24. * Adds the preview parameter to the stylesheet loading in non-js mode
  25. *
  26. * @param Event $event event object by reference
  27. * @param mixed $param [the parameters passed as fifth argument to register_hook() when this
  28. * handler was registered]
  29. * @return void
  30. */
  31. public function handleHeader(Event &$event, $param)
  32. {
  33. global $ACT;
  34. global $INPUT;
  35. if ($ACT != 'admin' || $INPUT->str('page') != 'styling') return;
  36. /** @var admin_plugin_styling $admin */
  37. $admin = plugin_load('admin', 'styling');
  38. if (!$admin->isAccessibleByCurrentUser()) return;
  39. // set preview
  40. $len = count($event->data['link']);
  41. for ($i = 0; $i < $len; $i++) {
  42. if (
  43. $event->data['link'][$i]['rel'] == 'stylesheet' &&
  44. strpos($event->data['link'][$i]['href'], 'lib/exe/css.php') !== false
  45. ) {
  46. $event->data['link'][$i]['href'] .= '&preview=1&tseed=' . time();
  47. }
  48. }
  49. }
  50. }
  51. // vim:ts=4:sw=4:et: