From 2f7a5efd5a98cf50fc525d7321c3568e51fb8319 Mon Sep 17 00:00:00 2001
From: Andreas Gohr <andi@splitbrain.org>
Date: Fri, 19 May 2017 19:57:04 +0200
Subject: [PATCH] use menu for site tools

this adds an option to print the menu without icons (as we do in the
dokuwiki template) but icons were added nontheless
---
 inc/Menu/AbstractMenu.php                 |  5 +++--
 inc/Menu/Item/AbstractItem.php            | 11 ++++++++---
 inc/Menu/Item/Index.php                   |  2 ++
 inc/Menu/Item/Media.php                   |  2 ++
 inc/Menu/Item/Recent.php                  |  1 +
 lib/images/menu/calendar-clock.svg        |  1 +
 lib/images/menu/file-tree.svg             |  1 +
 lib/images/menu/folder-multiple-image.svg |  1 +
 lib/tpl/dokuwiki/tpl_header.php           |  8 +++-----
 9 files changed, 22 insertions(+), 10 deletions(-)
 create mode 100644 lib/images/menu/calendar-clock.svg
 create mode 100644 lib/images/menu/file-tree.svg
 create mode 100644 lib/images/menu/folder-multiple-image.svg

diff --git a/inc/Menu/AbstractMenu.php b/inc/Menu/AbstractMenu.php
index 7680d2bac..8c01abe08 100644
--- a/inc/Menu/AbstractMenu.php
+++ b/inc/Menu/AbstractMenu.php
@@ -66,9 +66,10 @@ abstract class AbstractMenu {
      * output, use getItems() and build the HTML yourself
      *
      * @param string|false $classprefix create a class from type with this prefix, false for no class
+     * @param bool $svg add the SVG link
      * @return string
      */
-    public function getListItems($classprefix = '') {
+    public function getListItems($classprefix = '', $svg = true) {
         $html = '';
         foreach($this->getItems() as $item) {
             if($classprefix !== false) {
@@ -78,7 +79,7 @@ abstract class AbstractMenu {
             }
 
             $html .= "<li$class>";
-            $html .= $item->asHtmlLink(false);
+            $html .= $item->asHtmlLink(false, $svg);
             $html .= '</li>';
         }
         return $html;
diff --git a/inc/Menu/Item/AbstractItem.php b/inc/Menu/Item/AbstractItem.php
index 001dcf8ec..9af475448 100644
--- a/inc/Menu/Item/AbstractItem.php
+++ b/inc/Menu/Item/AbstractItem.php
@@ -114,13 +114,18 @@ abstract class AbstractItem {
      * Wraps around the label and SVG image
      *
      * @param string|false $classprefix create a class from type with this prefix, false for no class
+     * @param bool $svg add SVG icon to the link
      * @return string
      */
-    public function asHtmlLink($classprefix = 'menuitem ') {
+    public function asHtmlLink($classprefix = 'menuitem ', $svg = true) {
         $attr = buildAttributes($this->getLinkAttributes($classprefix));
         $html = "<a $attr>";
-        $html .= '<span>' . hsc($this->getLabel()) . '</span>';
-        $html .= inlineSVG($this->getSvg());
+        if($svg) {
+            $html .= '<span>' . hsc($this->getLabel()) . '</span>';
+            $html .= inlineSVG($this->getSvg());
+        } else {
+            $html .= hsc($this->getLabel());
+        }
         $html .= "</a>";
 
         return $html;
diff --git a/inc/Menu/Item/Index.php b/inc/Menu/Item/Index.php
index 33908f073..55244984c 100644
--- a/inc/Menu/Item/Index.php
+++ b/inc/Menu/Item/Index.php
@@ -4,6 +4,8 @@ namespace dokuwiki\Menu\Item;
 
 class Index extends AbstractItem {
 
+    protected $svg = DOKU_INC . 'lib/images/menu/file-tree.svg';
+
     /** @inheritdoc */
     public function __construct() {
         parent::__construct();
diff --git a/inc/Menu/Item/Media.php b/inc/Menu/Item/Media.php
index f5b89d908..e0cd04d25 100644
--- a/inc/Menu/Item/Media.php
+++ b/inc/Menu/Item/Media.php
@@ -4,6 +4,8 @@ namespace dokuwiki\Menu\Item;
 
 class Media extends AbstractItem {
 
+    protected $svg = DOKU_INC . 'lib/images/menu/folder-multiple-image.svg';
+
     /** @inheritdoc */
     public function __construct() {
         global $ID;
diff --git a/inc/Menu/Item/Recent.php b/inc/Menu/Item/Recent.php
index fd38404ef..8d924d1ef 100644
--- a/inc/Menu/Item/Recent.php
+++ b/inc/Menu/Item/Recent.php
@@ -10,6 +10,7 @@ class Recent extends AbstractItem {
 
         $this->category = 'site';
         $this->accesskey = 'r';
+        $this->svg = DOKU_INC . 'lib/images/menu/calendar-clock.svg';
     }
 
 }
diff --git a/lib/images/menu/calendar-clock.svg b/lib/images/menu/calendar-clock.svg
new file mode 100644
index 000000000..b19735dbb
--- /dev/null
+++ b/lib/images/menu/calendar-clock.svg
@@ -0,0 +1 @@
+<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><path d="M15 13h1.5v2.82l2.44 1.41-.75 1.3L15 16.69V13m4-5H5v11h4.67c-.43-.91-.67-1.93-.67-3a7 7 0 0 1 7-7c1.07 0 2.09.24 3 .67V8M5 21a2 2 0 0 1-2-2V5c0-1.11.89-2 2-2h1V1h2v2h8V1h2v2h1a2 2 0 0 1 2 2v6.1c1.24 1.26 2 2.99 2 4.9a7 7 0 0 1-7 7c-1.91 0-3.64-.76-4.9-2H5m11-9.85A4.85 4.85 0 0 0 11.15 16c0 2.68 2.17 4.85 4.85 4.85A4.85 4.85 0 0 0 20.85 16c0-2.68-2.17-4.85-4.85-4.85z"/></svg>
\ No newline at end of file
diff --git a/lib/images/menu/file-tree.svg b/lib/images/menu/file-tree.svg
new file mode 100644
index 000000000..0f261882f
--- /dev/null
+++ b/lib/images/menu/file-tree.svg
@@ -0,0 +1 @@
+<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><path d="M3 3h6v4H3V3m12 7h6v4h-6v-4m0 7h6v4h-6v-4m-2-4H7v5h6v2H5V9h2v2h6v2z"/></svg>
\ No newline at end of file
diff --git a/lib/images/menu/folder-multiple-image.svg b/lib/images/menu/folder-multiple-image.svg
new file mode 100644
index 000000000..f66aaaddb
--- /dev/null
+++ b/lib/images/menu/folder-multiple-image.svg
@@ -0,0 +1 @@
+<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><path d="M7 15l4.5-6 3.5 4.5 2.5-3L21 15m1-11h-8l-2-2H6a2 2 0 0 0-2 2v12a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2V6a2 2 0 0 0-2-2M2 6H0v14a2 2 0 0 0 2 2h18v-2H2V6z"/></svg>
\ No newline at end of file
diff --git a/lib/tpl/dokuwiki/tpl_header.php b/lib/tpl/dokuwiki/tpl_header.php
index 780c413a2..5de60df82 100644
--- a/lib/tpl/dokuwiki/tpl_header.php
+++ b/lib/tpl/dokuwiki/tpl_header.php
@@ -63,11 +63,9 @@ if (!defined('DOKU_INC')) die();
             </div>
             <ul>
                 <?php
-                    tpl_toolsevent('sitetools', array(
-                        tpl_action('recent', true, 'li', true),
-                        tpl_action('media', true, 'li', true),
-                        tpl_action('index', true, 'li', true)
-                    ));
+                    $menu = new \dokuwiki\Menu\SiteMenu();
+                    echo $menu->getListItems('action ', false);
+                    unset($menu);
                 ?>
             </ul>
         </div>
-- 
GitLab