. * * @sytnax : * --> Where LABEL refers to a label name defined with . * --> Where NAME matches the regular expression [a-zA-Z0-9_]+ * --> Where ... refers to the code to reproduce. * --> Where [PAGEID] (optional) refers to a source page ID * that matches the regular expression [a-zA-Z0-9_:-]*. * If PAGEID is omitted, the current page will be used. * * @license : GPL 2 http://www.gnu.org/licenses/gpl-2.0.html * @author : Patrice Bonneau * @lastupdate : 2012-07-18 * @compatible : 2012-01-25 "Angua" */ // 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/'); require_once DOKU_PLUGIN.'syntax.php'; class syntax_plugin_reproduce extends DokuWiki_Syntax_Plugin { var $LABEL_PATTERN = "[a-zA-Z0-9_]+"; var $PAGE_ID_PATTERN = "[a-zA-Z0-9_:-]*"; public function getType() { return 'substition'; } public function getPType() { return 'normal'; } public function getSort() { return 100; } public function getInfo() { return array( 'author' => 'Patrice Bonneau', 'email' => 'patrice.bonneau@live.ca', 'date' => '2012-05-18', 'name' => 'Reproduce Plugin', 'desc' => 'Allows to reproduce a code marked with a label located within the same source page, or in an other source page specified by its ID.', 'url' => 'http://www.dokuwiki.org/plugin:reproduce', ); } public function connectTo($mode) { $this->Lexer->addSpecialPattern('LABEL_PATTERN . '\s*' . $this->PAGE_ID_PATTERN . '\s*/>', $mode, 'plugin_reproduce'); } public function handle($match, $state, $pos, &$handler){ switch ($state) { case DOKU_LEXER_SPECIAL : // Find the label name and the optional source page ID in the tag if (preg_match('/LABEL_PATTERN . ')\s*(' . $this->PAGE_ID_PATTERN . ')\s*\/>/', $match, $matches)) { $labelName = $matches[1]; $sourcePageID = $matches[2]; if (!empty($sourcePageID)) { $sourcePageContent = io_readfile(wikiFN($sourcePageID)); } else { // Load the source code of the current DokuWiki page global $ID; // This is the current page ID $sourcePageContent = io_readfile(wikiFN($ID)); } // To be compatible with the plugin « autonumbering ». // This will make sure to keep the original numbering and not restart // numbering at 1, by doing the numbering before to reproduce the code. $pluginList = plugin_list(); if (in_array('autonumbering', $pluginList)) { $autonumbering = new syntax_plugin_autonumbering(); $sourcePageContent = $autonumbering->doNumbering($sourcePageContent); } // Find the corresponding