action.php 1.6 KB

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