*/
// must be run within Dokuwiki
if (!defined('DOKU_INC')) die();
if (!defined('DOKU_LF')) define('DOKU_LF', "\n");
if (!defined('DOKU_TAB')) define('DOKU_TAB', "\t");
if (!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN', DOKU_INC.'lib/plugins/');
class helper_plugin_include extends DokuWiki_Plugin { // DokuWiki_Helper_Plugin
var $pages = array(); // filechain of included pages
var $page = array(); // associative array with data about the page to include
var $ins = array(); // instructions array
var $doc = ''; // the final output XHTML string
var $mode = 'section'; // inclusion mode: 'page' or 'section'
var $clevel = 0; // current section level
var $firstsec = 0; // show first section only
var $header = array(); // included page / section header
var $renderer = NULL; // DokuWiki renderer object
function getInfo(){
return array(
'author' => 'Esther Brunner',
'email' => 'wikidesign@gmail.com',
'date' => '2006-12-18',
'name' => 'Include Plugin (helper class)',
'desc' => 'Functions to include another page in a wiki page',
'url' => 'http://www.wikidesign/en/plugin/include/start',
);
}
function getMethods(){
$result = array();
$result[] = array(
'name' => 'setPage',
'desc' => 'sets the page to include',
'params' => array("page attributes, 'id' required, 'section' for filtering" => 'array'),
'return' => array('success' => 'boolean'),
);
$result[] = array(
'name' => 'setMode',
'desc' => 'sets inclusion mode: should indention be merged?',
'params' => array("'page' (original) or 'section' (merged indention)" => 'string'),
);
$result[] = array(
'name' => 'setLevel',
'desc' => 'sets the indention for the current section level',
'params' => array('level: 0 to 5' => 'integer'),
'return' => array('success' => 'boolean'),
);
$result[] = array(
'name' => 'renderXHTML',
'desc' => 'renders the XHTML output of the included page',
'params' => array('DokuWiki renderer' => 'object'),
'return' => array('XHTML' => 'string'),
);
return $result;
}
/**
* Sets the page to include if it is not already included (prevent recursion)
*/
function setPage($page){
global $ID;
$id = $page['id'];
$fullid = $id.'#'.$page['section'];
if (!$id) return false; // no page id given
if ($id == $ID) return false; // page can't include itself
// prevent include recursion
if ((isset($this->pages[$id.'#'])) || (isset($this->pages[$fullid]))) return false;
// add the page to the filechain
$this->pages[$fullid] = $page;
$this->page =& $this->pages[$fullid];
return true;
}
/**
* Sets the inclusion mode
*/
function setMode($mode){
$this->mode = $mode;
}
/**
* Sets the right indention for a given section level
*/
function setLevel($level){
if ((is_numeric($level)) && ($level >= 0) && ($level <= 5)){
$this->clevel = $level;
return true;
}
return false;
}
/**
* Builds the XHTML to embed the page to include
*/
function renderXHTML(&$renderer){
if (!$this->page['id']) return ''; // page must be set first
$this->doc = '';
$this->firstsec = $this->getConf('firstseconly');
$this->renderer =& $renderer;
// get instructions and render them on the fly
$this->page['file'] = wikiFN($this->page['id']);
$this->ins = p_cached_instructions($this->page['file']);
// show only a given section?
if ($this->page['section']) $this->_getSection();
// convert relative links
$this->_convertInstructions();
// insert a read more link if only first section is shown
if ($this->firstsec) $this->_readMore();
// render the included page
if ($this->header) $content = '