Преглед на файлове

Added full support for icon-links.

Now it's possbile to use the DokuWiki syntax (eg. [[:wiki:welcome|{{fa>home?24|Welcome to DokuWiki}}]].

Note: The previous syntax is deprecated (see PR #4)
Giuseppe Di Terlizzi преди 9 години
родител
ревизия
4d83d96ed5
променени са 2 файла, в които са добавени 67 реда и са изтрити 33 реда
  1. 1 1
      plugin.info.txt
  2. 66 32
      syntax/icon.php

+ 1 - 1
plugin.info.txt

@@ -1,7 +1,7 @@
 base icons
 author Giuseppe Di Terlizzi
 email giuseppe.diterlizzi@gmail.com
-date 2015-05-18
+date 2015-08-28
 name Icons Plugin
 desc Embed icons in Dokuwiki
 url http://www.dokuwiki.org/plugin:icons

+ 66 - 32
syntax/icon.php

@@ -6,10 +6,10 @@
  * @author     Giuseppe Di Terlizzi <giuseppe.diterlizzi@gmail.com>
  * @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>.+?}}';
@@ -31,15 +31,16 @@ class syntax_plugin_icons_icon extends DokuWiki_Syntax_Plugin {
      *
      * @return int
      */
-    public function getSort() { return 32; }
- 
+    public function getSort() { return 299; }
+
     /**
      * @param  string  $mode
      */
     public function connectTo($mode) {
         $this->Lexer->addSpecialPattern($this->pattern, $mode, 'plugin_icons_'.$this->getPluginComponent());
+        $this->Lexer->addSpecialPattern('\[\[[^\}]+\|'.$this->pattern.'\]\]', $mode, 'plugin_icons_'.$this->getPluginComponent());
     }
- 
+
     /**
      * Handler to prepare matched data for the rendering process
      *
@@ -51,12 +52,27 @@ class syntax_plugin_icons_icon extends DokuWiki_Syntax_Plugin {
      */ 
     public function handle($match, $state, $pos, Doku_Handler $handler) {
 
-        $match                = substr($match, 2, -2); // strip markup
-        list($match, $title, $url) = explode('|', $match);
+        $match = substr($match, 2, -2); // strip markup
+        list($match, $title, $title2) = explode('|', $match);
+
+        if (isset($title2)) $title .= '}}';
+
+        if (isset($title) && preg_match('/'.$this->pattern.'/', $title)) {
+
+          $url   = $match;
+          $match = $title;
+
+          $match = substr($match, 2, -2); // strip markup
+          list($match, $title) = explode('|', $match);
+
+          if (isset($title2)) $title = rtrim($title2, '}');
+
+        }
+
         list($match, $flags)  = explode('?', $match, 2);
         list($pack, $icon)    = explode('>', $match, 2);
 
-        return array($pack, $icon, explode('&', $flags), $title, $url, $align, $match, $state, $pos);
+        return array($pack, $icon, explode('&', $flags), $title, $url, $match, $state, $pos);
 
     }
 
@@ -86,32 +102,50 @@ class syntax_plugin_icons_icon extends DokuWiki_Syntax_Plugin {
               $base_path = rtrim($this->getConf("{$pack}URL"), '/');
               $path      = call_user_func_array(array($class_icon, 'makePath'), array($icon, $size, $base_path));
 
-              if (isset($url)) {
-                  $renderer->doc .= sprintf('<a href="%s" rel="nofollow">', $url);
-              }
-              $renderer->doc .= sprintf('<img src="%s" title="%s" class="%s" style="%s" />',
-                                        $path, $title,
-                                        $this->toClassString($this->getClasses()),
-                                        $this->toInlineStyle($this->getStyles()));
-              if (isset($url)) {
-                  $renderer->doc .= sprintf('</a>');
-              }
-              return true;
+              $icon_markup = sprintf('<img src="%s" title="%s" class="%s" style="%s" />',
+                                     $path, $title,
+                                     $this->toClassString($this->getClasses()),
+                                     $this->toInlineStyle($this->getStyles()));
 
-            }
+            } else {
 
-            $this->classes[] = $this->getFlag('pack');
-            $this->classes[] = $this->getFlag('pack') . '-' . $icon;
+              $this->classes[] = $this->getFlag('pack');
+              $this->classes[] = $this->getFlag('pack') . '-' . $icon;
+  
+              $icon_markup = sprintf('<i class="%s" style="%s" title="%s"></i>',
+                                     $this->toClassString($this->getClasses()),
+                                     $this->toInlineStyle($this->getStyles()),
+                                     $title);
 
-            if (isset($url)) {
-                  $renderer->doc .= sprintf('<a href="%s" rel="nofollow">', $url);
             }
-            $renderer->doc .= sprintf('<i class="%s" style="%s" title="%s"></i>',
-                                      $this->toClassString($this->getClasses()),
-                                      $this->toInlineStyle($this->getStyles()),
-                                      $title);
+
             if (isset($url)) {
-                  $renderer->doc .= sprintf('</a>');
+
+              global $conf;
+              global $ID;
+
+              resolve_pageid(getNS($ID), $url, $exists, $this->date_at, true);
+
+              $link['target'] = $conf['target']['wiki'];
+              $link['style']  = '';
+              $link['pre']    = '';
+              $link['suf']    = '';
+              $link['more']   = '';
+              $link['class']  = '';
+              $link['url']    = wl($url);
+              $link['name']   = $icon_markup;
+
+              if ($exists) {
+                $link['class'] = 'wikilink1';
+              } else {
+                $link['class'] = 'wikilink2';
+                $link['rel']   = 'nofollow';
+              }
+
+              $renderer->doc .= $renderer->_formatLink($link);
+
+            } else {
+              $renderer->doc .= $icon_markup;
             }
 
             return true;
@@ -129,7 +163,7 @@ class syntax_plugin_icons_icon extends DokuWiki_Syntax_Plugin {
     protected function toInlineStyle($things) {
 
       $result = '';
-      
+
       foreach ($things as $property => $value) {
         $result .= "$property:$value;";
       }
@@ -244,9 +278,9 @@ class syntax_plugin_icons_icon extends DokuWiki_Syntax_Plugin {
                 $this->styles['padding-'.(($value == 'left') ? 'right' : 'left')] = '.2em';
                 $this->styles['float'] = $value;
               }
-              
+
             }
-            
+
             break;
 
           default: