[ Index ]

PHP Cross Reference of DokuWiki

title

Body

[close]

/lib/plugins/styling/ -> action.php (source)

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