1<?php 2 3class IckeNavigationElement {} 4 5class IckeNavigationSeparator extends IckeNavigationElement {} 6 7class IckeNavigationItem extends IckeNavigationElement { 8 9 public $id; 10 public $link; 11 public $exists; 12 public $isNamespace; 13 public $class; 14 15 function __construct($id, $link, $isNamespace) { 16 $this->id = $id; 17 $this->link = $link; 18 $this->isNamespace = $isNamespace; 19 $this->class = $this->buildClass($id); 20 $this->exists = page_exists($this->link); 21 } 22 23 private function buildClass($id) { 24 $id = ltrim($id, ':'); 25 $pos = strpos($id, ':'); 26 if ($pos === false) return $id; 27 return substr($id, 0, $pos); 28 } 29 30 public function getNamespace() { 31 if (!$this->isNamespace) return $this->id; 32 return getNS($this->id); 33 } 34} 35 36class IckeNavigation { 37 38 public $navigation; 39 40 public function __construct() { 41 $navigationConfig = tpl_getConf('namespaces'); 42 $this->loadNavigation($navigationConfig); 43 } 44 45 public function loadNavigation($navigationConfig) { 46 global $conf; 47 48 $navigation = explode(',',$navigationConfig); 49 $navigation = array_map('trim', $navigation); 50 51 $this->navigation = array(); 52 foreach ($navigation as $id) { 53 if ($id === '') { 54 // add separator 55 $this->navigation[] = new IckeNavigationSeparator(); 56 continue; 57 } 58 59 $link = $this->replaceUserPlaceholder($id); 60 if ($link === false) continue; 61 62 resolve_pageid('',$link,$exists); // create full links 63 if (auth_quickaclcheck($link) < AUTH_READ) continue; 64 65 $isNamespace = false; 66 if (substr($link, -1) === ':') { 67 $isNamespace = true; 68 $link = $link . $conf['start']; 69 } 70 71 $link = $this->translateId($link); 72 $link = cleanID($link); 73 74 $this->navigation[] = new IckeNavigationItem($id, $link, $isNamespace); 75 } 76 return $this->navigation; 77 } 78 79 private function replaceUserPlaceholder($id) { 80 if(strstr($id,'%USER%') === false) { 81 return $id; 82 } 83 84 if(empty($_SERVER['REMOTE_USER'])) { 85 return false; 86 } 87 88 $id = str_replace('%USER%',$_SERVER['REMOTE_USER'],$id); 89 return $id; 90 } 91 92 private function translateId($id) { 93 $translation = $this->getCurrentTranslation(); 94 95 $translatedId = $translation . ":$id"; 96 if (page_exists($translatedId)) { 97 return $translatedId; 98 } 99 return $id; 100 } 101 102 private function getCurrentTranslation() { 103 if (!isset($_SESSION[DOKU_COOKIE]['translationlc']) || empty($_SESSION[DOKU_COOKIE]['translationlc'])) { 104 return ''; 105 } 106 return $_SESSION[DOKU_COOKIE]['translationlc']; 107 } 108 109 public function drawSidebar() { 110 global $ID; 111 112 $firstItem = true; 113 $separator = false; 114 foreach($this->navigation as $item){ 115 if ($item instanceof IckeNavigationSeparator) { 116 $separator = !$firstItem; 117 $firstItem = false; 118 continue; 119 } 120 $firstItem = false; 121 if ($item instanceof IckeNavigationItem) { 122 123 $namespace = $this->replaceUserPlaceholder(getNS($item->id)); 124 125 $popup = p_wiki_xhtml($this->getLocalizedPopup($namespace.':quick'),'',false); 126 $translationNs = preg_quote($this->getCurrentTranslation().':', '/'); 127 $active = (bool) preg_match('/^('.$translationNs.')?'.preg_quote($namespace,'/').':/',$ID); 128 $class = 'qnav_'.explode(':',$item->class)[0]; // first ns part 129 icke_navi($item->link, '', $class, $popup, $active, $separator); 130 131 $separator = false; 132 } 133 } 134 135 // Add toolbox 136 icke_navi('','Settings','qnav_einstellungen',icke_toolbox(),false,false); 137 } 138 139 private function getLocalizedPopup($id) { 140 $lang = $this->getCurrentTranslation(); 141 if ($lang === '') return $id; 142 143 $local = "$lang:$id"; 144 if (page_exists($local)) { 145 return $local; 146 } 147 return $id; 148 } 149 150 public function buildPageCss() { 151 echo "<style type=\"text/css\">\n"; 152 153 // $navi[] = "einstellungen"; 154 155 foreach($this->navigation as $navigationItem){ 156 157 if (!($navigationItem instanceof IckeNavigationItem)) { 158 continue; 159 } 160 161 /*$processed = icke_processFancySearchItem($id); 162 if (!$processed) continue; 163 $class = $processed['class']; 164 $ns = $processed['ns']; 165 $imgClass = $processed['imgClass'];*/ 166 167 168 169 $bigInactive = $this->getImage($navigationItem, 60, 'icon_off.png', '_inaktiv.png'); 170 $bigActive = $this->getImage($navigationItem, 60, 'icon_on.png', '_aktiv.png'); 171 $iconActive = $this->getImage($navigationItem, 30, 'icon_on.png', '_aktiv.png'); 172 173 echo $this->cssEntry($navigationItem->class, $bigInactive, $bigActive, $iconActive); 174 } 175 176 echo $this->cssEntry('einstellungen', DOKU_TPL . '/images/icons/60x60/einstellungen_inaktiv.png', DOKU_TPL . '/images/icons/60x60/einstellungen_aktiv.png', ''); 177 echo "#fancysearch__ns_custom li.fancysearch_ns_icke {"; 178 echo 'text-indent: -10000px; width:30px; height:30px;'; 179 echo 'background-image: url('.DOKU_TPL.'/images/icons/30x30/icke.png)'; 180 echo "}\n"; 181 182 echo "</style>\n"; 183 } 184 185 private function getImage(IckeNavigationItem $navigationItem, $size, $nsPostFix, $pathPostFix) { 186 if (file_exists(mediaFN($navigationItem->getNamespace() . $nsPostFix))) { 187 return ml($navigationItem->getNamespace() . $nsPostFix, array('w'=>$size,'h'=>$size), true, '&'); 188 } 189 190 $path = "/images/icons/{$size}x$size/".$navigationItem->class.$pathPostFix; 191 if (file_exists(DOKU_TPLINC . $path)) { 192 return DOKU_TPL . $path; 193 } 194 return DOKU_TPL . "/images/icons/{$size}x$size/fail.png"; 195 } 196 197 private function cssEntry($name, $bigInactive, $bigActive, $iconActive) { 198 $css = ' 199 #icke__quicknav a.qnav_%1$s { 200 background-image: url(%2$s) 201 } 202 #icke__quicknav li.active a.qnav_%1$s, 203 #icke__quicknav li:hover a.qnav_%1$s { 204 background-image: url(%3$s) 205 } 206 #fancysearch__ns_custom li.fancysearch_ns_%1$s { 207 text-indent: -10000px; 208 width:30px; 209 height:30px; 210 background-image: url(%4$s) 211 }'; 212 return sprintf($css, $name, $bigInactive, $bigActive, $iconActive); 213 } 214 215} 216 217function icke_getNavigation() { 218 static $navigation = null; 219 if ($navigation === null) { 220 $navigation = new IckeNavigation(); 221 } 222 return $navigation; 223}