*/ // must be run within Dokuwiki if(!defined('DOKU_INC')) die(); if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/'); if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); require_once(DOKU_PLUGIN.'syntax.php'); // class syntax_plugin_embed extends DokuWiki_Syntax_Plugin { function syntax_plugin_embed() { global $embedded_pages_by_plugin_embed; if (! $embedded_pages_by_plugin_embed) { $embedded_pages_by_plugin_embed = array(); // To avoid recursion; } } function getInfo(){ return array( 'author' => 'Pascal Bihler', 'email' => 'bihler@iai.uni-bonn.de', 'date' => '2007-05-14', 'name' => 'Embed', 'desc' => 'Allows to embed wikipages in other ones, while offering the possibility to replace parts of the original page marked with labels.', 'url' => 'http://wiki.splitbrain.org/plugin:embed', ); } function getType(){ return 'substition'; } function getSort(){ return 500; } function connectTo($mode) { $this->Lexer->addSpecialPattern(']+\s*>.*?',$mode,'plugin_embed'); $this->Lexer->addSpecialPattern('',$mode,'plugin_embed'); } /** * Handle the match */ function handle($match, $state, $pos, &$handler){ switch ($state) { case DOKU_LEXER_SPECIAL : if (preg_match('/]+)\s*>(.*?)<\/embed>/ms',$match,$matches)) return array($matches[1],$matches[2]); else if (preg_match('/]+)\s*\/>/',$match,$matches)) return array($matches[1],''); break; } return array(); } /** * Create output */ function render($mode, &$renderer, $data) { global $ID; global $embedded_pages_by_plugin_embed; if($mode == 'xhtml'){ list($id,$replacement) = $data; $renderer->info['cache'] = false; // prevent caching (to ensure ACL conformity) (TODO sometimes: make more intelligent) resolve_pageid(getNS($ID), $id, $exists); // resolve shortcuts //resolve_pageid(getNS($ID), $id, $exists); // resolve shortcuts // avoid circular references if (! (array_search($id,$embedded_pages_by_plugin_embed) === false)) return false; array_push($embedded_pages_by_plugin_embed,$id); $ins = $this->_embed_file($id,$replacement); $renderer->doc .= p_render('xhtml', $ins, $info); // ptype = 'normal' array_pop($embedded_pages_by_plugin_embed); return true; } return false; } function _embed_file($id,$replacement) { // check permission $perm = auth_quickaclcheck($id); if ($perm < AUTH_READ) return false; //Read embeded page $page = io_readfile(wikiFN($id)); // convert relative links $page = $this->_convertInstructions($page,$id); // do replacements (on text-base to preserve List indentation and ordering etc.): $page = $this->_do_replacements($page,$replacement); $ins = p_get_instructions($page); return $ins; } function _do_replacements($page,$r_str) { //Build up list of replacements (this needs to be done manually to allow several replacements with nesting if before