Explorar el Código

Initial commit

Giuseppe Di Terlizzi hace 10 años
padre
commit
d1a6c606ed
Se han modificado 10 ficheros con 388 adiciones y 0 borrados
  1. 46 0
      action.php
  2. 11 0
      conf/default.php
  3. 12 0
      conf/metadata.php
  4. 13 0
      lang/en/settings.php
  5. 7 0
      plugin.info.txt
  6. 17 0
      syntax/fontawesome.php
  7. 17 0
      syntax/fugue.php
  8. 17 0
      syntax/glyphicon.php
  9. 231 0
      syntax/icon.php
  10. 17 0
      syntax/oxygen.php

+ 46 - 0
action.php

@@ -0,0 +1,46 @@
+<?php
+/**
+ * Icons Action Plugin
+ * 
+ * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
+ * @author     Giuseppe Di Terlizzi <giuseppe.diterlizzi>
+ * @copyright  (C) 2015, Giuseppe Di Terlizzi
+ */
+
+// must be run within Dokuwiki
+if(!defined('DOKU_INC')) die();
+
+/**
+ * Class Icons Action Plugin
+ *
+ * Add external CSS file to DokuWiki
+ */
+class action_plugin_icons extends DokuWiki_Action_Plugin {
+ 
+    /**
+     * Register events
+     *
+     * @param  Doku_Event_Handler  $controller
+     */
+    public function register(Doku_Event_Handler $controller) {
+        $controller->register_hook('TPL_METAHEADER_OUTPUT', 'BEFORE', $this,
+                                   '_hookcss');
+    }
+ 
+    /**
+     * Event handler
+     *
+     * @param  Doku_Event  &$event
+     */
+    public function _hookcss(Doku_Event &$event, $param) {
+
+        if ($this->getConf('loadFontAwesome')) {
+            $event->data['link'][] = array(
+              'type'    => 'text/css',
+              'rel'     => 'stylesheet',
+              'href'    => $this->getConf('fontAwesomeURL'));
+        }
+
+    }
+
+}

+ 11 - 0
conf/default.php

@@ -0,0 +1,11 @@
+<?php
+/**
+ * Default settings for the icons plugin
+ *
+ * @author Giuseppe Di Terlizzi <giuseppe.diterlizzi@gmail.com>
+ */
+
+$conf['defaultSize']     = '16';
+$conf['defaultPack']     = 'fa';
+$conf['fontAwesomeURL']  = '//maxcdn.bootstrapcdn.com/font-awesome/latest/css/font-awesome.min.css';
+$conf['loadFontAwesome'] = 1;

+ 12 - 0
conf/metadata.php

@@ -0,0 +1,12 @@
+<?php
+/**
+ * Options for the icons plugin
+ *
+ * @author Giuseppe Di Terlizzi <giuseppe.diterlizzi@gmail.com>
+ */
+
+
+$meta['defaultSize']     = array('string');
+$meta['defaultPack']     = array('multichoice','_choices' => array('fa', 'glyphicon', 'fugue', 'oxygen'));
+$meta['loadFontAwesome'] = array('onoff');
+$meta['fontAwesomeURL']  = array('string');

+ 13 - 0
lang/en/settings.php

@@ -0,0 +1,13 @@
+<?php
+/**
+ * English language file
+ *
+ * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
+ * @author     Giuseppe Di Terlizzi <giuseppe.diterlizzi@gmail.com>
+ */
+ 
+// for the configuration manager
+$lang['defaultSize']     = 'Default size for icon';
+$lang['defaultPack']     = 'Default icon package';
+$lang['fontAwesomeURL']  = 'Font Awesome CSS URL (example CDN or local)';
+$lang['loadFontAwesome'] = 'Do you want load the CSS file of Font Awesome ?';

+ 7 - 0
plugin.info.txt

@@ -0,0 +1,7 @@
+base icons
+author Giuseppe Di Terlizzi
+email giuseppe.diterlizzi@gmail.com
+date 2015-03-17
+name Icons Plugin
+desc Add icons to Dokuwiki
+url http://www.dokuwiki.org/devel:syntax_plugins

+ 17 - 0
syntax/fontawesome.php

@@ -0,0 +1,17 @@
+<?php
+/**
+ * Plugin Icons: Font Awesome helper
+ * 
+ * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
+ * @author     Giuseppe Di Terlizzi <giuseppe.diterlizzi>
+ * @copyright  (C) 2015, Giuseppe Di Terlizzi
+ */
+ 
+// must be run within Dokuwiki
+if(!defined('DOKU_INC')) die();
+
+require_once(dirname(__FILE__).'/icon.php');
+
+class syntax_plugin_icons_fontawesome extends syntax_plugin_icons_icon {
+    protected $pattern = '{{fa>.+?}}';
+}

+ 17 - 0
syntax/fugue.php

@@ -0,0 +1,17 @@
+<?php
+/**
+ * Plugin Icons: Fugue helper
+ * 
+ * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
+ * @author     Giuseppe Di Terlizzi <giuseppe.diterlizzi>
+ * @copyright  (C) 2015, Giuseppe Di Terlizzi
+ */
+ 
+// must be run within Dokuwiki
+if(!defined('DOKU_INC')) die();
+
+require_once(dirname(__FILE__).'/icon.php');
+
+class syntax_plugin_icons_fugue extends syntax_plugin_icons_icon {
+    protected $pattern = '{{fugue>.+?}}';
+}

+ 17 - 0
syntax/glyphicon.php

@@ -0,0 +1,17 @@
+<?php
+/**
+ * Plugin Icons: Glyphicons helper
+ * 
+ * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
+ * @author     Giuseppe Di Terlizzi <giuseppe.diterlizzi>
+ * @copyright  (C) 2015, Giuseppe Di Terlizzi
+ */
+ 
+// must be run within Dokuwiki
+if(!defined('DOKU_INC')) die();
+
+require_once(dirname(__FILE__).'/icon.php');
+
+class syntax_plugin_icons_glyphicon extends syntax_plugin_icons_icon {
+    protected $pattern = '{{glyphicon>.+?}}';
+}

+ 231 - 0
syntax/icon.php

@@ -0,0 +1,231 @@
+<?php
+/**
+ * Plugin Icons for DokuWiki
+ * 
+ * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
+ * @author     Giuseppe Di Terlizzi <giuseppe.diterlizzi>
+ * @copyright  (C) 2015, Giuseppe Di Terlizzi
+ */
+ 
+// must be run within Dokuwiki
+if(!defined('DOKU_INC')) die();
+ 
+class syntax_plugin_icons_icon extends DokuWiki_Syntax_Plugin {
+
+    protected $pattern = '{{icon>.+?}}';
+    protected $flags   = array();
+    protected $classes = array();
+    protected $styles  = array();
+
+    /**
+     * Syntax Type
+     *
+     * Needs to return one of the mode types defined in $PARSER_MODES in parser.php
+     *
+     * @return string
+     */
+    public function getType() { return 'substition'; }
+
+    /**
+     * Sort for applying this mode
+     *
+     * @return int
+     */
+    public function getSort() { return 32; }
+ 
+    /**
+     * @param  string  $mode
+     */
+    public function connectTo($mode) {
+        $this->Lexer->addSpecialPattern($this->pattern, $mode, 'plugin_icons_'.$this->getPluginComponent());
+    }
+ 
+    /**
+     * Handler to prepare matched data for the rendering process
+     *
+     * @param   string        $match    The text matched by the patterns
+     * @param   int           $state    The lexer state for the match
+     * @param   int           $pos      The character position of the matched text
+     * @param   Doku_Handler  $handler  The Doku_Handler object
+     * @return  bool|array              Return an array with all data you want to use in render, false don't add an instruction
+     */ 
+    public function handle($match, $state, $pos, Doku_Handler $handler) {
+
+        $match                = substr($match, 2, -2); // strip markup
+        list($match, $flags)  = explode('?', $match, 2);
+        list($pack, $icon)    = preg_split('/>/u', $match, 2);
+        list($flags, $title)  = explode('|', $flags);
+
+        return array($pack, $icon, explode('&', $flags), $title, $align, $match, $state, $pos);
+
+    }
+
+    /**
+     * Handles the actual output creation.
+     *
+     * @param   string         $mode      output format being rendered
+     * @param   Doku_Renderer  $renderer  the current renderer object
+     * @param   array          $data      data created by handler()
+     * @return  boolean                   rendered correctly? (however, returned value is not used at the moment)
+     */
+    public function render($mode, Doku_Renderer $renderer, $data) {
+
+        if ($mode == 'xhtml') {
+
+            /** @var Doku_Renderer_xhtml $renderer */
+
+            list($pack, $icon, $flags, $title) = $data;
+            $this->parseFlags($pack, $icon, $flags);
+
+            switch ($this->getFlag('pack')) {
+                case 'fugue':
+                case 'oxygen':
+                    $path = $this->makeIconPath($icon);    
+                    $renderer->doc .= sprintf('<img src="%s" title="%s" class="%s" style="%s" />',
+                                              $path, $title,
+                                              trim(implode(' ', $this->getClasses()), ' '),
+                                              trim(implode(';', $this->getStyles()), ';'));
+                    return true;
+            }
+
+            $this->classes[] = $this->getFlag('pack');
+            $this->classes[] = $this->getFlag('pack') . '-' . $icon;
+
+            $renderer->doc .= sprintf('<i class="%s" style="%s" title="%s"></i>',
+                                      trim(implode(' ', $this->getClasses()), ' '),
+                                      trim(implode(';', $this->getStyles()), ';'),
+                                      $title);
+            return true;
+
+        }
+
+        return false;
+
+    }
+
+    protected function getFlag($name) {
+      return (isset($this->flags[$name]) ? $this->flags[$name] : null);
+    }
+
+    protected function getFlags() {
+      return $this->flags;
+    }
+
+    protected function parseFlags($pack, $icon, $flags) {
+
+      $this->flags   = array();
+      $this->classes = array();
+      $this->styles  = array();
+
+      if ((int) $flags[0] > 0) {
+        $flags[] = "size=" . $flags[0];
+        unset($flags[0]);
+      }
+
+      $this->flags['pack'] = $pack;
+      $this->flags['icon'] = $icon;
+
+      foreach ($flags as $flag) {
+        list($flag, $value) = explode('=', $flag);
+        switch ($flag) {
+          case 'pack':
+            $this->flags['pack'] = $value;
+            break;
+          case 'size':
+            $this->flags['size'] = (int) $value;
+            $this->styles[] = "font-size:{$value}px";
+            break;
+          case 'circle':
+            $this->flags['circle'] = true;
+            $this->styles[] = 'border-radius:50%; -moz-border-radius:50%; -webkit-border-radius:50%';
+            break;
+          case 'padding':
+            $this->flags['padding'] = $value;
+            $this->styles[] = "padding:$value";
+            break;
+          case 'background':
+            $this->flags['background'] = $value;
+            $this->styles[] = "background-color:$value";
+            break;
+          case 'color':
+            $this->flags['color'] = $value;
+            $this->styles[] = "color: $value";
+            break;
+          case 'class':
+            $this->flags['class'] = $value;
+            $this->classes[] = $value;
+            break;
+          case 'align':
+
+            $this->flags['align'] = $value;
+
+            if ($value !== 'center') {
+              $margin = ($value == 'left') ? 'right' : 'left';
+              $this->styles[] = "float:$value; margin-$margin: .1em";
+            } else {
+              $this->styles[] = "display:block; text-align:center; margin:0 auto";
+            }
+
+            break;
+          default:
+            $this->classes[] = $flag;
+        }
+      }
+
+      if (! isset($this->flags['size'])) {
+        $this->styles[] = "font-size:" . $this->getConf('defaultSize') . "px";
+      }
+      if ($this->flags['pack'] == 'icon') {
+        $this->flags['pack'] = $this->getConf('defaultPack');
+      }
+
+    }
+
+    protected function getStyles() {
+      return $this->styles;
+    }
+
+    protected function getClasses() {
+      return $this->classes;
+    }
+
+    protected function makeIconPath($icon) {
+
+      switch ($this->getFlag('pack')) {
+          case 'fugue'  : return $this->makeFuguePath($icon);
+          case 'oxygen' : return $this->makeOxygenPath($icon);
+      }
+
+    }
+
+    protected function makeFuguePath($icon) {
+
+        $repo  = 'https://raw.githubusercontent.com/yusukekamiyamane/fugue-icons/master';
+        $sizes = array(16, 24, 32);
+        $size  = (($this->getFlag('size') > max($sizes)) ? max($sizes) : $this->getFlag($size));
+
+        switch ($size) {
+            case 0:
+            case 16:
+               $size = 'icons'; break;
+            case 24:
+              $size = 'bonus/icons-24'; break;
+            case 32:
+              $size = 'bonus/icons-32'; break;
+            default:
+              $size = 'icons';
+        }
+
+        return "$repo/$size/$icon.png";
+
+    }
+
+    protected function makeOxygenPath($icon) {
+
+      $repo = 'https://raw.githubusercontent.com/pasnox/oxygen-icons-png/master/oxygen';
+      $size = $this->getFlag('size').'x'.$this->getFlag('size');
+      return "$repo/$size/$icon.png";
+
+    }
+
+}

+ 17 - 0
syntax/oxygen.php

@@ -0,0 +1,17 @@
+<?php
+/**
+ * Plugin Icons: KDE Oxygen helper
+ * 
+ * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
+ * @author     Giuseppe Di Terlizzi <giuseppe.diterlizzi>
+ * @copyright  (C) 2015, Giuseppe Di Terlizzi
+ */
+ 
+// must be run within Dokuwiki
+if(!defined('DOKU_INC')) die();
+
+require_once(dirname(__FILE__).'/icon.php');
+
+class syntax_plugin_icons_oxygen extends syntax_plugin_icons_icon {
+    protected $pattern = '{{oxygen>.+?}}';
+}