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 private $lastheadlevel = 0; 19 20 /** 21 * Make available as XHTML replacement renderer 22 */ 23 public function canRender($format){ 24 if($format == 'xhtml') return true; 25 return false; 26 } 27 28 /** 29 * Simplified header printing with PDF bookmarks 30 */ 31 function header($text, $level, $pos) { 32 if(!$text) return; //skip empty headlines 33 34 // add PDF bookmark 35 $bmlevel = $this->getConf('maxbookmarks'); 36 if($bmlevel && $bmlevel >= $level){ 37 // PDF readers choke on invalid nested levels 38 $step = $level - $this->lastheadlevel; 39 if($step > 1) $level = $this->lastheadlevel; 40 $this->lastheadlevel = $level; 41 42 $this->doc .= '<bookmark content="'.$this->_xmlEntities($text).'" level="'.($level-1).'" />'; 43 } 44 45 // print header 46 $this->doc .= DOKU_LF."<h$level>"; 47 $this->doc .= $this->_xmlEntities($text); 48 $this->doc .= "</h$level>".DOKU_LF; 49 } 50 51 /** 52 * Wrap centered media in a div to center it 53 */ 54 function _media ($src, $title=NULL, $align=NULL, $width=NULL, 55 $height=NULL, $cache=NULL, $render = true) { 56 57 $out = ''; 58 if($align == 'center'){ 59 $out .= '<div align="center" style="text-align: center">'; 60 } 61 62 $out .= parent::_media ($src, $title, $align, $width, $height, $cache, $render); 63 64 if($align == 'center'){ 65 $out .= '</div>'; 66 } 67 68 return $out; 69 } 70 71 /** 72 * hover info makes no sense in PDFs, so drop acronyms 73 */ 74 function acronym($acronym) { 75 $this->doc .= $this->_xmlEntities($acronym); 76 } 77 78 79 /** 80 * reformat links if needed 81 */ 82 function _formatLink($link){ 83 // prefix interwiki links with interwiki icon 84 if($link['name'][0] != '<' && preg_match('/\binterwiki iw_(.\w+)\b/',$link['class'],$m)){ 85 if(file_exists(DOKU_INC.'lib/images/interwiki/'.$m[1].'.png')){ 86 $img = DOKU_BASE.'lib/images/interwiki/'.$m[1].'.png'; 87 }elseif(file_exists(DOKU_INC.'lib/images/interwiki/'.$m[1].'.gif')){ 88 $img = DOKU_BASE.'lib/images/interwiki/'.$m[1].'.gif'; 89 }else{ 90 $img = DOKU_BASE.'lib/images/interwiki.png'; 91 } 92 93 $link['name'] = '<img src="'.$img.'" width="16" height="16" style="vertical-align: center" />'.$link['name']; 94 } 95 return parent::_formatLink($link); 96 } 97 98 /** 99 * no obfuscation for email addresses 100 */ 101 function emaillink($address, $name = NULL) { 102 global $conf; 103 $old = $conf['mailguard']; 104 $conf['mailguard'] = 'none'; 105 parent::emaillink($address, $name); 106 $conf['mailguard'] = $old; 107 } 108 109} 110 111