1<?php
2/**
3 * Icons Action Plugin
4 *
5 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
6 * @author     Giuseppe Di Terlizzi <giuseppe.diterlizzi@gmail.com>
7 * @copyright  (C) 2015-2018, Giuseppe Di Terlizzi
8 */
9
10// must be run within Dokuwiki
11if(!defined('DOKU_INC')) die();
12
13/**
14 * Class Icons Action Plugin
15 *
16 * Add external CSS file to DokuWiki
17 */
18class action_plugin_icons extends DokuWiki_Action_Plugin {
19
20  /**
21   * Register events
22   *
23   * @param  Doku_Event_Handler  $controller
24   */
25  public function register(Doku_Event_Handler $controller) {
26    $controller->register_hook('TPL_METAHEADER_OUTPUT', 'BEFORE', $this, '_loadcss');
27    $controller->register_hook('TOOLBAR_DEFINE', 'AFTER', $this, '_toolbarButton', array ());
28    $controller->register_hook('PLUGIN_POPULARITY_DATA_SETUP', 'AFTER', $this, '_popularity');
29  }
30
31
32  /**
33   * Event handler
34   *
35   * @param  Doku_Event  &$event
36   */
37  public function _toolbarButton(Doku_Event $event, $param) {
38
39    $event->data[] = array(
40      'type'   => 'mediapopup',
41      'title'  => 'Icons',
42      'icon'   => '../../tpl/dokuwiki/images/logo.png',
43      'url'    => 'lib/plugins/icons/exe/popup.php?ns=',
44      'name'   => 'icons',
45      'options'=> 'width=800,height=600,left=20,top=20,toolbar=no,menubar=no,scrollbars=yes,resizable=yes',
46      'block'  => false
47    );
48
49  }
50
51
52  /**
53   * Event handler
54   *
55   * @param  Doku_Event  &$event
56   */
57  public function _popularity(Doku_Event $event, $param) {
58    $plugin_info = $this->getInfo();
59    $event->data['icon']['version'] = $plugin_info['date'];
60  }
61
62
63  /**
64   * Event handler
65   *
66   * @param  Doku_Event  &$event
67   */
68  public function _loadcss(Doku_Event &$event, $param) {
69
70    global $conf;
71
72    $base_url   = DOKU_BASE . 'lib/plugins/icons/assets';
73    $font_icons = array();
74
75    # Load Font-Awesome (skipped for Bootstrap3 template)
76    if ($this->getConf('loadFontAwesome')) {
77      $font_icons[] = "$base_url/font-awesome/css/font-awesome.min.css";
78    }
79
80    # Load Typicons
81    if ($this->getConf('loadTypicons')) {
82      $font_icons[] = "$base_url/typicons/typicons.min.css";
83    }
84
85    # Load RPG-Awesome
86    if ($this->getConf('loadRpgAwesome')) {
87      $font_icons[] = "$base_url/rpg-awesome/css/rpg-awesome.min.css";
88    }
89
90    # Load Font Linux
91    if ($this->getConf('loadFontlinux')) {
92      $font_icons[] = "$base_url/font-linux/font-linux.css";
93    }
94
95    # Load Material Icons
96    if ($this->getConf('loadMaterialDesignIcons')) {
97      $font_icons[] = "$base_url/material-design-icons/css/materialdesignicons.min.css";
98    }
99
100
101    foreach ($font_icons as $font_icon) {
102      $event->data['link'][] = array(
103        'type'    => 'text/css',
104        'rel'     => 'stylesheet',
105        'href'    => $font_icon);
106    }
107
108  }
109
110}
111