浏览代码

Many improvement & new icon set (Silk & Flag)
ADDED: new icon set (Silk) e national flags (ISO 3166-1 alpha-2)
ADDED: rewrited main class for create a modular code for new icon set

Giuseppe Di Terlizzi 10 年之前
父节点
当前提交
c77ea8774a
共有 7 个文件被更改,包括 162 次插入63 次删除
  1. 18 0
      syntax/fa.php
  2. 25 0
      syntax/flag.php
  3. 25 0
      syntax/fugue.php
  4. 1 0
      syntax/glyphicon.php
  5. 55 63
      syntax/icon.php
  6. 13 0
      syntax/oxygen.php
  7. 25 0
      syntax/silk.php

+ 18 - 0
syntax/fa.php

@@ -0,0 +1,18 @@
+<?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_fa extends syntax_plugin_icons_icon {
+    protected $pattern = '{{fa>.+?}}';
+    const IS_ICON = false;
+}

+ 25 - 0
syntax/flag.php

@@ -0,0 +1,25 @@
+<?php
+/**
+ * Plugin Icons: Flag 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_flag extends syntax_plugin_icons_icon {
+
+    protected $pattern = '{{flag>.+?}}';
+
+    const IS_ICON = true;
+
+    public static function makePath($icon, $size, $base_url) {
+      return "$base_url/$icon-icon.png";
+    }
+
+}

+ 25 - 0
syntax/fugue.php

@@ -13,5 +13,30 @@ if(!defined('DOKU_INC')) die();
 require_once(dirname(__FILE__).'/icon.php');
 
 class syntax_plugin_icons_fugue extends syntax_plugin_icons_icon {
+
     protected $pattern = '{{fugue>.+?}}';
+
+    const IS_ICON = true;
+
+    public static function makePath($icon, $size, $base_url) {
+
+        $sizes = array(16, 24, 32);
+        $size  = (($size > max($sizes)) ? max($sizes) : $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 "$base_url/$size/$icon.png";
+
+    }
+
 }

+ 1 - 0
syntax/glyphicon.php

@@ -14,4 +14,5 @@ require_once(dirname(__FILE__).'/icon.php');
 
 class syntax_plugin_icons_glyphicon extends syntax_plugin_icons_icon {
     protected $pattern = '{{glyphicon>.+?}}';
+    const IS_ICON = false;
 }

+ 55 - 63
syntax/icon.php

@@ -77,24 +77,31 @@ class syntax_plugin_icons_icon extends DokuWiki_Syntax_Plugin {
             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;
+            $class_icon = 'syntax_plugin_icons_'.$this->getFlag('pack');
+
+            if (constant("$class_icon::IS_ICON")) {
+
+              unset($this->styles['font-size']);
+              $size      = $this->getFlag('size');
+              $base_path = rtrim($this->getConf("{$pack}URL"), '/');
+              $path      = call_user_func_array(array($class_icon, 'makePath'), array($icon, $size, $base_path));
+
+              $renderer->doc .= sprintf('<img src="%s" title="%s" class="%s" style="%s" />',
+                                        $path, $title,
+                                        $this->toClassString($this->getClasses()),
+                                        $this->toInlineStyle($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()), ';'),
+                                      $this->toClassString($this->getClasses()),
+                                      $this->toInlineStyle($this->getStyles()),
                                       $title);
+
             return true;
 
         }
@@ -103,6 +110,24 @@ class syntax_plugin_icons_icon extends DokuWiki_Syntax_Plugin {
 
     }
 
+    protected function toClassString($things) {
+      return trim(implode(' ', $things), ' ');
+    }
+
+    protected function toInlineStyle($things) {
+
+      $result = '';
+      
+      foreach ($things as $property => $value) {
+        $result .= "$property:$value;";
+      }
+
+      $result = trim($result, ';');
+
+      return $result;
+
+    }
+
     protected function getFlag($name) {
       return (isset($this->flags[$name]) ? $this->flags[$name] : null);
     }
@@ -151,28 +176,30 @@ class syntax_plugin_icons_icon extends DokuWiki_Syntax_Plugin {
             break;
 
           case 'size':
-            $this->flags['size'] = (int) $value;
-            $this->styles[] = "font-size:{$value}px";
+            $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%';
+            $this->flags['circle']                 = true;
+            $this->styles['border-radius']         = '50%';
+            $this->styles['-moz-border-radius']    = '50%';
+            $this->styles['-webkit-border-radius'] = '50%';
             break;
 
           case 'padding':
-            $this->flags['padding'] = $value;
-            $this->styles[] = "padding:$value";
+            $this->flags['padding']  = $value;
+            $this->styles['padding'] = $value;
             break;
 
           case 'background':
-            $this->flags['background'] = $value;
-            $this->styles[] = "background-color:$value";
+            $this->flags['background']        = $value;
+            $this->styles['background-color'] = $value;
             break;
 
           case 'color':
-            $this->flags['color'] = $value;
-            $this->styles[] = "color: $value";
+            $this->flags['color']  = $value;
+            $this->styles['color'] = $value;
             break;
 
           case 'class':
@@ -186,9 +213,12 @@ class syntax_plugin_icons_icon extends DokuWiki_Syntax_Plugin {
 
             if ($value !== 'center') {
               $margin = ($value == 'left') ? 'right' : 'left';
-              $this->styles[] = "float:$value; margin-$margin: .2em";
+              $this->styles['float'] = $value;
+              $this->styles["margin-$margin"] = '.2em';
             } else {
-              $this->styles[] = "display:block; text-align:center; margin:0 auto";
+              $this->styles['display']    = 'block';
+              $this->styles['text-align'] = 'center';
+              $this->styles['margin']     = '0 auto';
             }
 
             break;
@@ -199,7 +229,8 @@ class syntax_plugin_icons_icon extends DokuWiki_Syntax_Plugin {
       }
 
       if (! isset($this->flags['size'])) {
-        $this->styles[] = "font-size:" . $this->getConf('defaultSize') . "px";
+        $this->flags['size'] = $this->getConf('defaultSize');
+        $this->styles['font-size'] = $this->getConf('defaultSize') . "px";
       }
 
       if ($this->flags['pack'] == 'icon') {
@@ -216,43 +247,4 @@ class syntax_plugin_icons_icon extends DokuWiki_Syntax_Plugin {
       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  = rtrim($this->getConf('fugueURL'), '/');
-        $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 = rtrim($this->getConf('oxygenURL'), '/');
-      $size = $this->getFlag('size').'x'.$this->getFlag('size');
-      return "$repo/$size/$icon.png";
-
-    }
-
 }

+ 13 - 0
syntax/oxygen.php

@@ -13,5 +13,18 @@ if(!defined('DOKU_INC')) die();
 require_once(dirname(__FILE__).'/icon.php');
 
 class syntax_plugin_icons_oxygen extends syntax_plugin_icons_icon {
+
     protected $pattern = '{{oxygen>.+?}}';
+
+    const IS_ICON = true;
+
+    public static function makePath($icon, $size, $base_url) {
+
+        $sizes = array(8, 16, 22, 32, 48, 64, 128, 256, 512);
+        $size  = (($size > max($sizes)) ? max($sizes) : $size);
+
+        return "$base_url/{$size}x{$size}/$icon.png";
+
+    }
+
 }

+ 25 - 0
syntax/silk.php

@@ -0,0 +1,25 @@
+<?php
+/**
+ * Plugin Icons: Silk 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_silk extends syntax_plugin_icons_icon {
+
+    protected $pattern = '{{silk>.+?}}';
+
+    const IS_ICON = true;
+
+    public static function makePath($icon, $size, $base_url) {
+      return "$base_url/$icon-icon.png";
+    }
+
+}