* @author Gerry Weissbach
*/
if(!defined('DOKU_INC')) die();
if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
require_once DOKU_INC . 'inc/parser/xhtml.php';
/**
* The Renderer
*/
class renderer_plugin_siteexport_pdf extends Doku_Renderer_xhtml {
var $acronymsExchanged = null;
var $hasSeenHeader = false;
var $scriptmode = false;
var $currentLevel = 0;
var $startlevel = 0; // level to start with numbered headings (default = 2)
var $levels = array( '======'=>1,
'====='=>2,
'===='=>3,
'==='=>4,
'=='=>5);
var $info = array(
'cache' => true, // may the rendered result cached?
'toc' => true, // render the TOC?
'forceTOC' => false, // shall I force the TOC?
'scriptmode' => false, // In scriptmode, some tags will not be encoded => '<%', '%>'
);
var $headingCount =
array( 1=>0,
2=>0,
3=>0,
4=>0,
5=>0);
/**
* return some info
*/
function getInfo(){
if ( method_exists(parent, 'getInfo')) {
$info = parent::getInfo();
}
return array_merge(is_array($info) ? $info : confToHash(dirname(__FILE__).'/../plugin.info.txt'), array(
));
}
function document_start() {
global $TOC, $ID, $INFO;
parent::document_start();
// Cheating in again
$newMeta = p_get_metadata($ID, 'description tableofcontents', false); // 2010-10-23 This should be save to use
if ( !empty( $newMeta ) && count($newMeta) > 1 ) {
// $TOC = $this->toc = $newMeta; // 2010-08-23 doubled the TOC
$TOC = $newMeta;
}
}
function document_end() {
parent::document_end();
// Prepare the TOC
global $TOC, $ID;
$meta = array();
// NOTOC, and no forceTOC
if ( $this->info['toc'] === false && !($this->info['forceTOC'] || $this->meta['forceTOC']) ) {
$TOC = $this->toc = array();
$meta['internal']['toc'] = false;
$meta['description']['tableofcontents'] = array();
$meta['forceTOC'] = false;
} else if ( $this->info['forceTOC'] || $this->meta['forceTOC'] || (utf8_strlen(strip_tags($this->doc)) >= $this->getConf('documentlengthfortoc') && count($this->toc) > 1 ) ) {
$TOC = $this->toc;
// This is a little bit like cheating ... but this will force the TOC into the metadata
$meta = array();
$meta['internal']['toc'] = true;
$meta['forceTOC'] = $this->info['forceTOC'] || $this->meta['forceTOC'];
$meta['description']['tableofcontents'] = $TOC;
}
// allways write new metadata
p_set_metadata($ID, $meta);
$this->doc = preg_replace('#
\s*
#','',$this->doc);
}
function header($text, $level, $pos) {
global $conf;
global $ID;
global $INFO;
if($text)
{
$hid = $this->_headerToLink($text,true);
//only add items within configured levels
$this->toc_additem($hid, $text, $level);
// adjust $node to reflect hierarchy of levels
$this->node[$level-1]++;
if ($level < $this->lastlevel) {
for ($i = 0; $i < $this->lastlevel-$level; $i++) {
$this->node[$this->lastlevel-$i-1] = 0;
}
}
$this->lastlevel = $level;
/* There should be no class for "sectioneditX" if there is no edit perm */
if ($INFO['perm'] > AUTH_READ &&
$level <= $conf['maxseclevel'] &&
count($this->sectionedits) > 0 &&
$this->sectionedits[count($this->sectionedits) - 1][2] === 'section') {
$this->finishSectionEdit($pos - 1);
}
$headingNumber = '';
$useNumbered = p_get_metadata($ID, 'usenumberedheading', true); // 2011-02-07 This should be save to use
if ( $this->getConf('usenumberedheading') || !empty($useNumbered) || !empty($INFO['meta']['usenumberedheading']) || isset($_REQUEST['usenumberedheading'])) {
// increment the number of the heading
$this->headingCount[$level]++;
// build the actual number
for ($i=1;$i<=5;$i++) {
// reset the number of the subheadings
if ($i>$level) {
$this->headingCount[$i] = 0;
}
// build the number of the heading
$headingNumber .= $this->headingCount[$i] . '.';
}
$headingNumber = preg_replace("/(\.0)+\.?$/", '', $headingNumber) . ' ';
}
// write the header
$this->doc .= DOKU_LF.' AUTH_READ &&
$level <= $conf['maxseclevel']) {
$class[] = $this->startSectionEdit($pos, 'section', $text);
}
if ( !empty($headingNumber) ) {
$class[] = 'level' . trim($headingNumber);
if ( intval($headingNumber) > 1 ) {
$class[] = 'notfirst';
} else {
$class[] = 'first';
}
}
if ( !empty($class) ) {
$this->doc .= ' class="' . implode(' ', $class) . '"';
}
$this->doc .= '>';
$this->doc .= $this->_xmlEntities($headingNumber . $text);
$this->doc .= "".DOKU_LF;
} else if ( $INFO['perm'] > AUTH_READ ) {
if ( $hasSeenHeader ) $this->finishSectionEdit($pos);
// write the header
$name = rand() . $level;
$this->doc .= DOKU_LF.''.DOKU_LF;
}
$hasSeenHeader = true;
}
function section_open($level) {
$this->currentLevel = $level;
parent::section_open($level);
}
function p_open() {
$this->doc .= DOKU_LF.'
'.DOKU_LF;
}
function listu_open() {
$this->doc .= '
'.DOKU_LF;
}
function listo_open() {
$this->doc .= ''.DOKU_LF;
}
public function finishSectionEdit($end = null) {
return '';
}
public function startSectionEdit($start, $type, $title = null) {
return '';
}
/**
* Wrap centered media in a div to center it
*/
function _media ($src, $title=NULL, $align=NULL, $width=NULL,
$height=NULL, $cache=NULL, $render = true) {
$out = '';
if($align == 'center'){
$out .= '
';
}
/**
* API of the imagereference plugin
* https://github.com/i-net-software/dokuwiki-plugin-imagereference
*
* Allows to specify special imagecaption tags that the renderer (mpdf) can use
*/
public function imageCaptionTags(&$imagereferenceplugin)
{
if ( !$imagereferenceplugin->accepts('table') ) {
return array( '', // $captionStart
'', // $captionEnd
'', // $underCaptionStart
'' // $underCaptionEnd
);
}
return null;
}
}
//Setup VIM: ex: et ts=4 enc=utf-8 :