1<?php 2/** 3 * DokuWiki Plugin dw2pdf (Renderer Component) 4 * 5 * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html 6 * @author Andreas Gohr <gohr@cosmocode.de> 7 */ 8 9// must be run within Dokuwiki 10if (!defined('DOKU_INC')) die(); 11 12if (!defined('DOKU_LF')) define('DOKU_LF', "\n"); 13if (!defined('DOKU_TAB')) define('DOKU_TAB', "\t"); 14require_once DOKU_INC.'inc/parser/xhtml.php'; 15 16class renderer_plugin_dw2pdf extends Doku_Renderer_xhtml { 17 18 /** 19 * Make available as XHTML replacement renderer 20 */ 21 public function canRender($format){ 22 if($format == 'xhtml') return true; 23 return false; 24 } 25 26 /** 27 * Simplified header printing with PDF bookmarks 28 */ 29 function header($text, $level, $pos) { 30 if(!$text) return; //skip empty headlines 31 32 // add PDF bookmark 33 $bmlevel = $this->getConf('maxbookmarks'); 34 if($bmlevel && $bmlevel >= $level){ 35 $this->doc .= '<bookmark content="'.$this->_xmlEntities($text).'" level="'.($level-1).'" />'; 36 } 37 38 // print header 39 $this->doc .= DOKU_LF."<h$level>"; 40 $this->doc .= $this->_xmlEntities($text); 41 $this->doc .= "</h$level>".DOKU_LF; 42 } 43 44 /** 45 * Wrap centered media in a div to center it 46 */ 47 function _media ($src, $title=NULL, $align=NULL, $width=NULL, 48 $height=NULL, $cache=NULL, $render = true) { 49 50 $out = ''; 51 if($align == 'center'){ 52 $out .= '<div align="center" style="text-align: center">'; 53 } 54 55 $out .= parent::_media ($src, $title, $align, $width, $height, $cache, $render); 56 57 if($align == 'center'){ 58 $out .= '</div>'; 59 } 60 61 return $out; 62 } 63 64 /** 65 * hover info makes no sense in PDFs, so drop acronyms 66 */ 67 function acronym($acronym) { 68 $this->doc .= $this->_xmlEntities($acronym); 69 } 70 71 72 /** 73 * reformat links if needed 74 */ 75 function _formatLink($link){ 76 // prefix interwiki links with interwiki icon 77 if($link['name'][0] != '<' && preg_match('/\binterwiki iw_(.\w+)\b/',$link['class'],$m)){ 78 if(file_exists(DOKU_INC.'lib/images/interwiki/'.$m[1].'.png')){ 79 $img = DOKU_BASE.'lib/images/interwiki/'.$m[1].'.png'; 80 }elseif(file_exists(DOKU_INC.'lib/images/interwiki/'.$m[1].'.gif')){ 81 $img = DOKU_BASE.'lib/images/interwiki/'.$m[1].'.gif'; 82 }else{ 83 $img = DOKU_BASE.'lib/images/interwiki.png'; 84 } 85 86 $link['name'] = '<img src="'.$img.'" width="16" height="16" style="vertical-align: center" />'.$link['name']; 87 } 88 return parent::_formatLink($link); 89 } 90 91 /** 92 * no obfuscation for email addresses 93 */ 94 function emaillink($address, $name = NULL) { 95 global $conf; 96 $old = $conf['mailguard']; 97 $conf['mailguard'] = 'none'; 98 parent::emaillink($address, $name); 99 $conf['mailguard'] = $old; 100 } 101 102} 103 104