1<?php 2/** 3 * showlinkpermission - Changes the color of internal link if the user has no read permissions 4 * 5 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) 6 * @author Matthias Schulte <dokuwiki@lupo49.de> 7 */ 8 9// must be run within Dokuwiki 10if(!defined('DOKU_INC')) die(); 11 12// we inherit from the XHTML renderer instead directly of the base renderer 13require_once DOKU_INC.'inc/parser/xhtml.php'; 14 15class renderer_plugin_showlinkpermission extends Doku_Renderer_xhtml { 16 17 function getFormat(){ 18 return 'xhtml'; 19 } 20 21 function canRender($format) { 22 return ($format == 'xhtml'); 23 } 24 25 function internallink($id, $name = NULL, $search=NULL, $returnonly=false, $linktype='content') { 26 global $conf; 27 global $ID; 28 global $INFO; 29 // Disabling the cache to have the XHTML always up-to-date 30 $this->info['cache'] = false; 31 32 $params = ''; 33 $parts = explode('?', $id, 2); 34 if (count($parts) === 2) { 35 $id = $parts[0]; 36 $params = $parts[1]; 37 } 38 39 // For empty $id we need to know the current $ID 40 // We need this check because _simpleTitle needs 41 // correct $id and resolve_pageid() use cleanID($id) 42 // (some things could be lost) 43 if ($id === '') { 44 $id = $ID; 45 } 46 47 // default name is based on $id as given 48 $default = $this->_simpleTitle($id); 49 50 // now first resolve and clean up the $id 51 resolve_pageid(getNS($ID),$id,$exists); 52 53 $name = $this->_getLinkTitle($name, $default, $isImage, $id, $linktype); 54 if ( !$isImage ) { 55 if ( $exists ) { 56 $class='wikilink1'; 57 } else { 58 $class='wikilink2'; 59 $link['rel']='nofollow'; 60 } 61 } else { 62 $class='media'; 63 } 64 65 // Check if the link is accessible by the current user 66 // If not, change color of the link 67 $user = $INFO['userinfo']['name']; 68 $groups = $INFO['userinfo']['grps']; 69 70 if(!$isImage && auth_aclcheck($id, $user, $groups) < AUTH_READ) { 71 // User is not allowed not read the page, change css class 72 $class = 'wikilinknoperm'; 73 } 74 75 //keep hash anchor 76 list($id,$hash) = explode('#',$id,2); 77 if(!empty($hash)) $hash = $this->_headerToLink($hash); 78 79 //prepare for formating 80 $link['target'] = $conf['target']['wiki']; 81 $link['style'] = ''; 82 $link['pre'] = ''; 83 $link['suf'] = ''; 84 // highlight link to current page 85 if ($id == $INFO['id']) { 86 $link['pre'] = '<span class="curid">'; 87 $link['suf'] = '</span>'; 88 } 89 $link['more'] = ''; 90 $link['class'] = $class; 91 $link['url'] = wl($id, $params); 92 $link['name'] = $name; 93 $link['title'] = $id; 94 95 //add search string 96 if($search){ 97 ($conf['userewrite']) ? $link['url'].='?' : $link['url'].='&'; 98 if(is_array($search)){ 99 $search = array_map('rawurlencode',$search); 100 $link['url'] .= 's[]='.join('&s[]=',$search); 101 }else{ 102 $link['url'] .= 's='.rawurlencode($search); 103 } 104 } 105 106 //keep hash 107 if($hash) $link['url'].='#'.$hash; 108 109 //output formatted 110 if($returnonly){ 111 return $this->_formatLink($link); 112 }else{ 113 $this->doc .= $this->_formatLink($link); 114 } 115 } 116} 117