static function render($text, $type = null, $id = null, $instructions = null) { global $conf, $baseurl, $db; // Unfortunately dokuwiki also uses $conf $fs_conf = $conf; $conf = array(); // Dokuwiki generates some notices error_reporting(E_ALL ^ E_NOTICE); if (!$instructions) { include_once BASEDIR . '/plugins/dokuwiki/inc/parser/parser.php'; } require_once BASEDIR . '/plugins/dokuwiki/inc/common.php'; require_once BASEDIR . '/plugins/dokuwiki/inc/parser/xhtml.php'; // Create a renderer $Renderer = new Doku_Renderer_XHTML(); if (!is_string($instructions) || strlen($instructions) < 1) { $modes = p_get_parsermodes(); $Parser = new Doku_Parser(); // Add the Handler $Parser->Handler = new Doku_Handler(); // Add modes to parser foreach ($modes as $mode) { $Parser->addMode($mode['mode'], $mode['obj']); } $instructions = $Parser->parse($text); // Cache the parsed text if (!is_null($type) && !is_null($id)) { $fields = array('content' => serialize($instructions), 'type' => $type, 'topic' => $id, 'last_updated' => time()); $keys = array('type', 'topic'); //autoquote is always true on db class $db->Replace('{cache}', $fields, $keys); } } else { $instructions = unserialize($instructions); } $Renderer->smileys = getSmileys(); $Renderer->entities = getEntities(); $Renderer->acronyms = getAcronyms(); $Renderer->interwiki = getInterwiki(); $conf = $fs_conf; $conf['cachedir'] = FS_CACHE_DIR; // for dokuwiki $conf['fperm'] = 0600; $conf['dperm'] = 0700; // Loop through the instructions foreach ($instructions as $instruction) { // Execute the callback against the Renderer call_user_func_array(array(&$Renderer, $instruction[0]), $instruction[1]); } $return = $Renderer->doc; // Display the output if (Get::val('histring')) { $words = explode(' ', Get::val('histring')); foreach ($words as $word) { $return = html_hilight($return, $word); } } return $return; }
function testNonexisting() { $Renderer = new Doku_Renderer(); $Renderer->interwiki = getInterwiki(); $shortcut = 'nonexisting'; $reference = 'foo @+%/'; $url = $Renderer->_resolveInterWiki($shortcut, $reference); $expected = 'https://www.google.com/search?q=foo%20%40%2B%25%2F&btnI=lucky'; $this->assertEquals($expected, $url); }
/** * @param Doku_Event $event event object by reference * @param mixed $param [the parameters passed as fifth argument to register_hook() when this * handler was registered] * @return void */ public function handle_ajax_call_unknown(Doku_Event &$event, $param) { if ($event->data !== 'iwiki_list') { return; } $event->stopPropagation(); $event->preventDefault(); $a = getInterwiki(); ksort($a); echo json_encode($a); }
function p_render($mode, $instructions, &$info) { if (is_null($instructions)) { return ''; } // msg("Memory Usage p_render start: ". memory_get_usage(), -1); // require_once DOKU_INC."inc/parser/$mode.php"; $rclass = "Doku_Renderer_{$mode}"; if (!class_exists($rclass)) { trigger_error("Unable to resolve render class {$rclass}", E_USER_ERROR); } $Renderer =& new $rclass(); #FIXME any way to check for class existance? $Renderer->smileys = getSmileys(); $Renderer->entities = getEntities(); $Renderer->latexentities = $this->_texit_conf['latexentities']; $Renderer->acronyms = getAcronyms(); $Renderer->interwiki = getInterwiki(); $Renderer->info = $info; // Loop through the instructions foreach ($instructions as $instruction) { // Execute the callback against the Renderer call_user_func_array(array(&$Renderer, $instruction[0]), $instruction[1]); } //set info array $info = $Renderer->info; // msg("Memory Usage p_render end: ". memory_get_usage(), -1); // Return the output return $Renderer->doc; }
/** * Prints classes for interwikilinks * * Interwiki links have two classes: 'interwiki' and 'iw_$name>' where * $name is the identifier given in the config. All Interwiki links get * an default style with a default icon. If a special icon is available * for an interwiki URL it is set in it's own class. Both classes can be * overwritten in the template or userstyles. * * @author Andreas Gohr <*****@*****.**> */ function css_interwiki() { // default style echo 'a.interwiki {'; echo ' background: transparent url(' . DOKU_BASE . 'lib/images/interwiki.png) 0px 1px no-repeat;'; echo ' padding: 1px 0px 1px 16px;'; echo '}'; // additional styles when icon available $iwlinks = getInterwiki(); foreach (array_keys($iwlinks) as $iw) { $class = preg_replace('/[^_\\-a-z0-9]+/i', '_', $iw); if (file_exists(DOKU_INC . 'lib/images/interwiki/' . $iw . '.png')) { echo "a.iw_{$class} {"; echo ' background-image: url(' . DOKU_BASE . 'lib/images/interwiki/' . $iw . '.png)'; echo '}'; } elseif (file_exists(DOKU_INC . 'lib/images/interwiki/' . $iw . '.gif')) { echo "a.iw_{$class} {"; echo ' background-image: url(' . DOKU_BASE . 'lib/images/interwiki/' . $iw . '.gif)'; echo '}'; } } }
/** * Renders a list of instruction to the specified output mode * * In the $info array is information from the renderer returned * * @author Harry Fuecks <*****@*****.**> * @author Andreas Gohr <*****@*****.**> */ function p_render($mode, $instructions, &$info) { if (is_null($instructions)) { return ''; } $Renderer =& p_get_renderer($mode); if (is_null($Renderer)) { return null; } $Renderer->reset(); $Renderer->smileys = getSmileys(); $Renderer->entities = getEntities(); $Renderer->acronyms = getAcronyms(); $Renderer->interwiki = getInterwiki(); // Loop through the instructions foreach ($instructions as $instruction) { // Execute the callback against the Renderer call_user_func_array(array(&$Renderer, $instruction[0]), $instruction[1]); } //set info array $info = $Renderer->info; // Post process and return the output $data = array($mode, &$Renderer->doc); trigger_event('RENDERER_CONTENT_POSTPROCESS', $data); return $Renderer->doc; }
/** * Renders a list of instruction to the specified output mode * * In the $info array are informations from the renderer returned * * @author Harry Fuecks <*****@*****.**> * @author Andreas Gohr <*****@*****.**> */ function p_render($mode, $instructions, &$info) { if (is_null($instructions)) { return ''; } if ($mode == 'wiki') { msg("Renderer for {$mode} not valid", -1); return null; } //FIXME!! remove this line when inc/parser/wiki.php works. // Create the renderer if (!@file_exists(DOKU_INC . "inc/parser/{$mode}.php")) { msg("No renderer for {$mode} found", -1); return null; } require_once DOKU_INC . "inc/parser/{$mode}.php"; $rclass = "Doku_Renderer_{$mode}"; if (!class_exists($rclass)) { trigger_error("Unable to resolve render class {$rclass}", E_USER_WARNING); msg("Renderer for {$mode} not valid", -1); return null; } $Renderer = new $rclass(); #FIXME any way to check for class existance? $Renderer->smileys = getSmileys(); $Renderer->entities = getEntities(); $Renderer->acronyms = getAcronyms(); $Renderer->interwiki = getInterwiki(); #$Renderer->badwords = getBadWords(); // Loop through the instructions foreach ($instructions as $instruction) { // Execute the callback against the Renderer call_user_func_array(array(&$Renderer, $instruction[0]), $instruction[1]); } //set info array $info = $Renderer->info; // Post process and return the output $data = array($mode, &$Renderer->doc); trigger_event('RENDERER_CONTENT_POSTPROCESS', $data); return $Renderer->doc; }
/** * Lists all links contained in a wiki page * * @author Michael Klier <*****@*****.**> */ function listLinks($id) { $id = $this->resolvePageId($id); if (auth_quickaclcheck($id) < AUTH_READ) { throw new RemoteAccessDeniedException('You are not allowed to read this page', 111); } $links = array(); // resolve page instructions $ins = p_cached_instructions(wikiFN($id)); // instantiate new Renderer - needed for interwiki links include DOKU_INC . 'inc/parser/xhtml.php'; $Renderer = new Doku_Renderer_xhtml(); $Renderer->interwiki = getInterwiki(); // parse parse instructions foreach ($ins as $in) { $link = array(); switch ($in[0]) { case 'internallink': $link['type'] = 'local'; $link['page'] = $in[1][0]; $link['href'] = wl($in[1][0]); array_push($links, $link); break; case 'externallink': $link['type'] = 'extern'; $link['page'] = $in[1][0]; $link['href'] = $in[1][0]; array_push($links, $link); break; case 'interwikilink': $url = $Renderer->_resolveInterWiki($in[1][2], $in[1][3]); $link['type'] = 'extern'; $link['page'] = $url; $link['href'] = $url; array_push($links, $link); break; } } return $links; }
/** * Returns users realname w/o link * * @param string|null $username or null when currently logged-in user should be used * @param bool $textonly true returns only plain text, true allows returning html * @return string html or plain text(not escaped) of formatted user name * * @triggers COMMON_USER_LINK */ function userlink($username = null, $textonly = false) { global $conf, $INFO; /** @var DokuWiki_Auth_Plugin $auth */ global $auth; /** @var Input $INPUT */ global $INPUT; // prepare initial event data $data = array('username' => $username, 'name' => '', 'link' => array('target' => '', 'pre' => '', 'suf' => '', 'style' => '', 'more' => '', 'url' => '', 'title' => '', 'class' => ''), 'userlink' => '', 'textonly' => $textonly); if ($username === null) { $data['username'] = $username = $INPUT->server->str('REMOTE_USER'); if ($textonly) { $data['name'] = $INFO['userinfo']['name'] . ' (' . $INPUT->server->str('REMOTE_USER') . ')'; } else { $data['name'] = '<bdi>' . hsc($INFO['userinfo']['name']) . '</bdi> (<bdi>' . hsc($INPUT->server->str('REMOTE_USER')) . '</bdi>)'; } } $evt = new Doku_Event('COMMON_USER_LINK', $data); if ($evt->advise_before(true)) { if (empty($data['name'])) { if ($auth) { $info = $auth->getUserData($username); } if ($conf['showuseras'] != 'loginname' && isset($info) && $info) { switch ($conf['showuseras']) { case 'username': case 'username_link': $data['name'] = $textonly ? $info['name'] : hsc($info['name']); break; case 'email': case 'email_link': $data['name'] = obfuscate($info['mail']); break; } } else { $data['name'] = $textonly ? $data['username'] : hsc($data['username']); } } /** @var Doku_Renderer_xhtml $xhtml_renderer */ static $xhtml_renderer = null; if (!$data['textonly'] && empty($data['link']['url'])) { if (in_array($conf['showuseras'], array('email_link', 'username_link'))) { if (!isset($info)) { if ($auth) { $info = $auth->getUserData($username); } } if (isset($info) && $info) { if ($conf['showuseras'] == 'email_link') { $data['link']['url'] = 'mailto:' . obfuscate($info['mail']); } else { if (is_null($xhtml_renderer)) { $xhtml_renderer = p_get_renderer('xhtml'); } if (empty($xhtml_renderer->interwiki)) { $xhtml_renderer->interwiki = getInterwiki(); } $shortcut = 'user'; $exists = null; $data['link']['url'] = $xhtml_renderer->_resolveInterWiki($shortcut, $username, $exists); $data['link']['class'] .= ' interwiki iw_user'; if ($exists !== null) { if ($exists) { $data['link']['class'] .= ' wikilink1'; } else { $data['link']['class'] .= ' wikilink2'; $data['link']['rel'] = 'nofollow'; } } } } else { $data['textonly'] = true; } } else { $data['textonly'] = true; } } if ($data['textonly']) { $data['userlink'] = $data['name']; } else { $data['link']['name'] = $data['name']; if (is_null($xhtml_renderer)) { $xhtml_renderer = p_get_renderer('xhtml'); } $data['userlink'] = $xhtml_renderer->_formatLink($data['link']); } } $evt->advise_after(); unset($evt); return $data['userlink']; }
/** * Return the user home-page link * * @author Giuseppe Di Terlizzi <*****@*****.**> * * @return string */ function _tpl_user_homepage_link() { $interwiki = getInterwiki(); $user_url = str_replace('{NAME}', $_SERVER['REMOTE_USER'], $interwiki['user']); return wl(cleanID($user_url)); }
/** * INITALIZE TEMPLATE * * Load usefull plugins' helpers. */ function _mixture_init() { global $ID, $conf, $JSINFO; // New global variables global $styleIni, $glyphs, $uhp, $trs; // Parse style.ini file (has to be here rather than in _mixture_init() to be abble to use it's data for fonts declarations) $styleIni = array(); // Look for a customized 'style.ini' generated by Styling plugin if (is_file(DOKU_CONF . "tpl/mixture/style.ini")) { $styleIni = parse_ini_file(DOKU_CONF . "tpl/mixture/style.ini", true); } // Or for template's default 'style.ini' if (count($styleIni) == 0) { $styleIni = parse_ini_file("style.ini", true); } // Parse glyphs.conf files $glyphs = array(); // Get template's default glyphs if (is_file(tpl_incdir() . "conf/glyphs.php")) { include tpl_incdir() . "conf/glyphs.php"; } // Get custom glyphs if (is_file(DOKU_CONF . "tpl/mixture/glyphs.php")) { include DOKU_CONF . "tpl/mixture/glyphs.php"; } //dbg($glyphs); // Look for a customized 'style.ini' generated by Styling plugin if (is_file(DOKU_CONF . "tpl/mixture/style.ini")) { $styleIni = parse_ini_file(DOKU_CONF . "tpl/mixture/style.ini", true); } // Store options into $JSINFO for later use $JSINFO['ScrollDelay'] = tpl_getConf('scrollDelay'); // if ((strpos(tpl_getConf('elements'), 'header_landing_changes') !== false) or (strpos(tpl_getConf('elements'), 'header_topbar_date') !== false)) { // $JSINFO['LoadMoment'] = true; // } else { // $JSINFO['LoadMoment'] = false; // } if (strpos(tpl_getConf('elements'), 'header_landing_changes') !== false or strpos(tpl_getConf('elements'), 'header_topbar_lastchanges') !== false) { $JSINFO['LoadNewsTicker'] = true; } else { $JSINFO['LoadNewsTicker'] = false; } // Preparing usefull plugins' helpers $interwiki = getInterwiki(); $mixturePublicId = ltrim(str_replace('{NAME}', $_SERVER['REMOTE_USER'], $interwiki['user']), ':'); if (!plugin_isdisabled('userhomepage')) { $uhpHelper = plugin_load('helper', 'userhomepage'); $uhp = $uhpHelper->getElements(); if (isset($mixturePublicId) and !isset($uhp['public'])) { $uhp['public'] = array(); $uhp['public']['id'] = $mixturePublicId; } } else { // Without Userhomepage plugin, Public Page namespace is set by 'user' value in 'conf/interwiki.conf' $uhp = array(); $uhp['private'] = null; $uhp['public'] = array(); $uhp['public']['id'] = $mixturePublicId; } if (!plugin_isdisabled('translation')) { $trs = array(); $translationHelper = plugin_load('helper', 'translation'); $trs['parts'] = $translationHelper->getTransParts($ID); } else { $trs['parts'] = null; } // Adding test alerts if debug is enabled if ($_GET['debug'] == true) { msg("This is an error alert (-1)", -1); msg("This is an info message (0)", 0); msg("This is a success message (1)", 1); msg("This is a notification (2)", 2); } }
/** * Renders a list of instruction to minimal xhtml *@author Myron Turner <*****@*****.**> */ function _render_xhtml($text) { $mode = 'ckgedit'; global $skip_styling; $skip_styling = $this->getConf('nofont_styling'); if (!$skip_styling && $_POST['styling'] == 'no_styles') { $skip_styling = true; } if (strpos($text, '~~NO_STYLING~~') !== false) { $skip_styling = true; } $text = preg_replace_callback('/(\\[\\[\\w+>)(.*?)([\\]\\|])/ms', create_function('$matches', ' //if(preg_match("/^\\w+$/",$matches[2])) return $matches[0]; return $matches[1] . "oIWIKIo" . $matches[2] ."cIWIKIc" . $matches[3] ;'), $text); global $Smilies; $smiley_as_text = @$this->getConf('smiley_as_text'); if ($smiley_as_text) { $Smilies = array('8-)' => 'aSMILEY_1', '8-O' => 'aSMILEY_2', ':-(' => 'aSMILEY_3', ':-)' => 'aSMILEY_4', '=)' => 'aSMILEY_5', ':-/' => 'aSMILEY_6', ':-\\' => 'aSMILEY_7', ':-?' => 'aSMILEY_8', ':-D' => 'aSMILEY_9', ':-P' => 'bSMILEY_10', ':-O' => 'bSMILEY_11', ':-X' => 'bSMILEY_12', ':-|' => 'bSMILEY_13', ';-)' => 'bSMILEY_14', '^_^' => 'bSMILEY_15', ':?:' => 'bSMILEY_16', ':!:' => 'bSMILEY_17', 'LOL' => 'bSMILEY_18', 'FIXME' => 'bSMILEY_19', 'DELETEME' => 'bSMILEY_20'); $s_values = array_values($Smilies); $s_values_regex = implode('|', $s_values); $s_keys = array_keys($Smilies); $s_keys = array_map(create_function('$k', 'return "(" . preg_quote($k,"/") . ")";'), $s_keys); $s_keys_regex = implode('|', $s_keys); global $haveDokuSmilies; $haveDokuSmilies = false; $text = preg_replace_callback('/(' . $s_keys_regex . ')/ms', create_function('$matches', 'global $Smilies; global $haveDokuSmilies; $haveDokuSmilies = true; return $Smilies[$matches[1]];'), $text); } // try default renderer first: $file = DOKU_INC . "inc/parser/{$mode}.php"; if (@file_exists($file)) { require_once $file; $rclass = "Doku_Renderer_{$mode}"; if (!class_exists($rclass)) { trigger_error("Unable to resolve render class {$rclass}", E_USER_WARNING); msg("Renderer for {$mode} not valid", -1); return null; } $Renderer = new $rclass(); } else { // Maybe a plugin is available? $Renderer = plugin_load('renderer', $mode); if (is_null($Renderer)) { msg("No renderer for {$mode} found", -1); return null; } } // aimed at wrap plugin which allows multiple newlines in a cell $text = preg_replace_callback('#(\\|.*?)\\|.?[\\n\\r]#ms', function ($matches) { $matches[0] = preg_replace("#\\\\\\\\\\s*[\r\n]#ms", " \\\\\\\\ ", $matches[0]); return $matches[0]; }, $text); // prevents utf8 conversions of quotation marks $text = str_replace('"', "_ckgedit_QUOT_", $text); $text = preg_replace_callback('/(<code.*?>)([^<]+)(<\\/code>)/ms', create_function('$matches', '$quot = str_replace("_ckgedit_QUOT_",\'"\',$matches[2]); $quot = str_replace("\\\\ ","_ckgedit_NL",$quot); $quot .= "_ckgedit_NL"; return $matches[1] . $quot . $matches[3];'), $text); $text = preg_replace_callback('/(<file.*?>)([^<]+)(<\\/file>)/ms', create_function('$matches', '$quot = str_replace("_ckgedit_QUOT_",\'"\',$matches[2]); $quot = str_replace("\\\\ ","_ckgedit_NL",$quot); $quot .= "_ckgedit_NL"; return $matches[1] . $quot . $matches[3];'), $text); $text = preg_replace_callback('/(<code>|<file>)([^<]+)(<\\/code>|<\\/file>)/ms', create_function('$matches', '$matches[2] = str_replace("<font","ckgeditFONTOpen",$matches[2]); $matches[2] = str_replace("font>","ckgeditFONTClose",$matches[2]); return $matches[1] .$matches[2] . $matches[3]; '), $text); $instructions = p_get_instructions("=== header ==="); // loads DOKU_PLUGINS array --M.T. Dec 22 2009 $instructions = p_get_instructions($text); if (is_null($instructions)) { return ''; } $Renderer->notoc(); $Renderer->smileys = getSmileys(); $Renderer->entities = getEntities(); $Renderer->acronyms = array(); $Renderer->interwiki = getInterwiki(); // Loop through the instructions /* By-passing plugin processing was sugested and first implemented by Matti Lattu<*****@*****.**> It is a significant contribution to the functionality of ckgEdit */ foreach ($instructions as $instruction) { if ($instruction[0] == 'plugin') { $Renderer->doc .= $instruction[1][3]; } else { // Execute the callback against the Renderer call_user_func_array(array(&$Renderer, $instruction[0]), $instruction[1]); } } //set info array $info = $Renderer->info; // Post process and return the output $data = array($mode, &$Renderer->doc); trigger_event('RENDERER_CONTENT_POSTPROCESS', $data); $xhtml = $Renderer->doc; if (!$skip_styling) { // create font styles from font plugin markup for html display $xhtml = preg_replace_callback('|&lt;font\\s+(.*?)/([\\w ,\\-]+);;([\\(\\)),\\w,\\s\\#]+);;([\\(\\)),\\w,\\s\\#]+)>(.*?)&lt;/font>|ms', function ($matches) { return '<span style = "color:' . $matches[3] . '">' . '<span style = "font-size:' . $matches[1] . '">' . '<span style = "font-family:' . $matches[2] . '">' . '<span style = "background-color:' . $matches[4] . '">' . $matches[5] . '</span></span></span></span>'; }, $xhtml); } if (strpos($xhtml, 'oIWIKIo') !== false) { $xhtml = preg_replace_callback('/(.)oIWIKIo(.*?)cIWIKIc/ms', create_function('$matches', ' if(preg_match("/^\\w+$/",$matches[2]) && $matches[1] == "/") return "/". $matches[2]; return $matches[0];'), $xhtml); $xhtml = preg_replace_callback('/>oIWIKIo(.*?)cIWIKIc(?=<\\/a>)/ms', create_function('$matches', ' return ">". $matches[1] ;'), $xhtml); } $pos = strpos($xhtml, 'MULTI_PLUGIN_OPEN'); if ($pos !== false) { $xhtml = preg_replace_callback('|MULTI_PLUGIN_OPEN.*?MULTI_PLUGIN_CLOSE|ms', create_function('$matches', '$matches[0] = str_replace("//<//", "< ",$matches[0]); $matches[0] = str_replace(array("oIWIKIo","cIWIKIc"),"",$matches[0]); return preg_replace("/\\n/ms","<br />",$matches[0]);'), $xhtml); $xhtml = preg_replace('/~\\s*~\\s*MULTI_PLUGIN_OPEN~\\s*~/', "\n\n~~MULTI_PLUGIN_OPEN~~<span class='multi_p_open'>\n\n</span>\n\n", $xhtml); $xhtml = preg_replace('/~\\s*~\\s*MULTI_PLUGIN_CLOSE~\\s*~/', "<span class='multi_p_close'>\n\n<br /></span>\n\n~~MULTI_PLUGIN_CLOSE~~\n\n", $xhtml); } // remove empty paragraph: see _ckgedit_NPBBR_ comment above $xhtml = preg_replace('/<p>\\s+_ckgedit_NPBBR_\\s+<\\/p>/ms', "\n", $xhtml); $xhtml = str_replace('_ckgedit_NPBBR_', "<span class='np_break'> </span>", $xhtml); $xhtml = str_replace('_ckgedit_QUOT_', '"', $xhtml); $xhtml = str_replace('_ckgedit_NL', "\n", $xhtml); $xhtml = str_replace('</pre>', "\n\n</pre><p> </p>", $xhtml); // inserts p before an initial codeblock to enable text entry above block $xhtml = preg_replace('/^<pre/', "<p> </p><pre", $xhtml); //remove empty markup remaining after removing marked-up acronyms in lists $xhtml = preg_replace('/<(em|b|u|i)>\\s+<\\/(em|b|u|i)>/ms', "", $xhtml); $xhtml = preg_replace("/col\\d+\\s+(\\w+align)/ms", "\$1", $xhtml); //remove col number for cell prpoerties dialog $xhtml = str_replace('ckgeditFONTOpen', '&lt;font', $xhtml); // protect font markup in code blocks $xhtml = str_replace('ckgeditFONTClose', 'font&gt;', $xhtml); if ($smiley_as_text) { if ($haveDokuSmilies) { $s_values = array_values($Smilies); $s_values_regex = implode('|', $s_values); $xhtml = preg_replace_callback('/(' . $s_values_regex . ')/ms', create_function('$matches', 'global $Smilies; return array_search($matches[1],$Smilies); '), $xhtml); } } $ua = strtolower($_SERVER['HTTP_USER_AGENT']); if (strpos($ua, 'chrome') !== false) { $xhtml = preg_replace_callback('/(?<=<a )(href=\\".*?\\")(\\s+\\w+=\\".*?\\")(.*?)(?=>)/sm', create_function('$matches', '$ret_str = " " . trim($matches[3]) . " " . trim($matches[2]) . " " . trim($matches[1]) ; return $ret_str;'), $xhtml); } return $xhtml; }
function create($id, $user_title = false) { ob_start(); $id = ltrim($id, ':'); $id = ":{$id}"; $namespace = getNS($id); epub_save_namespace($namespace); $mode = 'epub'; $Renderer =& plugin_load('renderer', $mode); $Renderer->set_oebps(); $Renderer->set_current_page(epub_clean_name(str_replace(':', '_', $id)) . '.html'); $this->_renderer = $Renderer; if (is_null($Renderer)) { msg("No renderer for {$mode} found", -1); exit; } global $ID; $oldID = $ID; $ID = cleanID($id); $wiki_file = wikiFN($id); if (!file_exists($wiki_file)) { epub_push_spine(array("", "")); echo "{$id} not found\n"; return false; } epub_update_progress("reading {$id}"); $instructions = p_cached_instructions($wiki_file, false, $id); if (is_null($instructions)) { return ''; } $Renderer->notoc(); $Renderer->smileys = getSmileys(); $Renderer->entities = getEntities(); $Renderer->acronyms = array(); $Renderer->interwiki = getInterwiki(); epub_update_progress("rendering {$id}, this could take some time"); // Loop through the instructions foreach ($instructions as $instruction) { // Execute the callback against the Renderer call_user_func_array(array(&$Renderer, $instruction[0]), $instruction[1]); } $result = ""; $result .= '<html xmlns="http://www.w3.org/1999/xhtml">' . "\n"; $result .= "\n<head>\n"; $result .= '<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>' . "\n"; $result .= '<link rel="stylesheet" type="text/css" href="../Styles/style.css"/>'; epub_check_for_mathjax($result); $result .= "\n<title>"; $result .= "</title>\n</head><body>\n"; $result .= "<div class='dokuwiki'>\n"; $info = $Renderer->info; $data = array($mode, &$Renderer->doc); trigger_event('RENDERER_CONTENT_POSTPROCESS', $data); $xhtml = $Renderer->doc; $result .= $xhtml; $result .= "\n</div></body></html>\n"; $result = preg_replace_callback("/&(\\w+);/m", "epbub_entity_replace", $result); $result = preg_replace("/(^[\r\n]*|[\r\n]+)[\\s\t]*[\r\n]+/m", "\n", $result); $result = preg_replace("/^\\s+/m", "", $result); $result = preg_replace_callback('|<p>([\\s\\n]*)(.*?<div.*?/div>.*?)([\\s\\n])*<\\/p>|im', create_function('$matches', '$result = $matches[1] . $matches[2] . $matches[3]; //echo "$result\\n"; return $result;'), $result); ob_end_flush(); if ($user_title) { $id = 'title.html'; } else { $id = epub_clean_name(str_replace(':', '_', $id)) . '.html'; } io_saveFile(epub_get_oebps() . "Text/{$id}", $result); if ($user_title) { epub_write_zip('Text/title.html'); $ID = $oldID; return true; } $item_num = epub_write_item("Text/{$id}", "application/xhtml+xml"); epub_push_spine(array("Text/{$id}", $item_num)); epub_save_namespace(); $ID = $oldID; return true; }
function render($mode, &$renderer, $data) { list($ns, $num, $flags, $refine) = $data; $first = $_REQUEST['first']; if (!is_numeric($first)) { $first = 0; } // get the blog entries for our namespace if ($my =& plugin_load('helper', 'blog')) { $entries = $my->getBlog($ns); } // use tag refinements? if ($refine) { if (plugin_isdisabled('tag') || !($tag =& plugin_load('helper', 'tag'))) { msg($this->getLang('missing_tagplugin'), -1); } else { $entries = $tag->tagRefine($entries, $refine); } } // any create form overrides? $formpos = $this->getConf('formposition'); if (in_array('topform', $flags)) { $formpos = 'top'; } elseif (in_array('bottomform', $flags)) { $formpos = 'bottom'; } elseif (in_array('noform', $flags)) { $formpos = 'none'; } if (!$entries) { if (auth_quickaclcheck($ns . ':*') >= AUTH_CREATE && $mode == 'xhtml') { $renderer->info['cache'] = false; if ($formpos != 'none') { $renderer->doc .= $this->_newEntryForm($ns); } } return true; // nothing to display } // slice the needed chunk of pages $more = count($entries) > $first + $num ? true : false; $entries = array_slice($entries, $first, $num); // load the include helper plugin if (plugin_isdisabled('include') || !($include =& plugin_load('helper', 'include'))) { msg($this->getLang('missing_includeplugin'), -1); return false; } if ($mode == 'xhtml') { // prevent caching to ensure the included pages are always fresh $renderer->info['cache'] = false; // show new entry form $perm_create = auth_quickaclcheck($ns . ':*') >= AUTH_CREATE; if ($perm_create && $formpos == 'top') { $renderer->doc .= $this->_newEntryForm($ns); } // current section level $clevel = 0; preg_match_all('|<div class="level(\\d)">|i', $renderer->doc, $matches, PREG_SET_ORDER); $n = count($matches) - 1; if ($n > -1) { $clevel = $matches[$n][1]; } // close current section if ($clevel) { $renderer->doc .= '</div>' . DOKU_LF; } $renderer->doc .= '<div class="hfeed">' . DOKU_LF; } // we need our own renderer $include_renderer =& p_get_renderer('xhtml'); $include_renderer->smileys = getSmileys(); $include_renderer->entities = getEntities(); $include_renderer->acronyms = getAcronyms(); $include_renderer->interwiki = getInterwiki(); // now include the blog entries foreach ($entries as $entry) { if ($mode == 'xhtml') { if (auth_quickaclcheck($entry['id']) >= AUTH_READ) { $renderer->doc .= $this->render_XHTML($include, $include_renderer, $entry['id'], $clevel, $flags); } } elseif ($mode == 'metadata') { $renderer->meta['relation']['haspart'][$entry['id']] = true; } } if ($mode == 'xhtml') { // resume the section $renderer->doc .= '</div>' . DOKU_LF; if ($clevel) { $renderer->doc .= '<div class="level' . $clevel . '">' . DOKU_LF; } // BEGIN MODIFIED by harukasan if (!in_array('nofollowlink', $flags)) { // show older / newer entries links $renderer->doc .= $this->_browseEntriesLinks($more, $first, $num); } // END MODIFIED // show new entry form if ($perm_create && $formpos == 'bottom') { $renderer->doc .= $this->_newEntryForm($ns); } } return true; }
/** * Renders a list of instruction to minimal xhtml *@author Myron Turner <*****@*****.**> */ function _render_xhtml($text) { $mode = 'fckg'; global $Smilies; $smiley_as_text = @$this->getConf('smiley_as_text'); if ($smiley_as_text) { $Smilies = array('8-)' => 'aSMILEY_1', '8-O' => 'aSMILEY_2', ':-(' => 'aSMILEY_3', ':-)' => 'aSMILEY_4', '=)' => 'aSMILEY_5', ':-/' => 'aSMILEY_6', ':-\\' => 'aSMILEY_7', ':-?' => 'aSMILEY_8', ':-D' => 'aSMILEY_9', ':-P' => 'bSMILEY_10', ':-O' => 'bSMILEY_11', ':-X' => 'bSMILEY_12', ':-|' => 'bSMILEY_13', ';-)' => 'bSMILEY_14', '^_^' => 'bSMILEY_15', ':?:' => 'bSMILEY_16', ':!:' => 'bSMILEY_17', 'LOL' => 'bSMILEY_18', 'FIXME' => 'bSMILEY_19', 'DELETEME' => 'bSMILEY_20'); $s_values = array_values($Smilies); $s_values_regex = implode('|', $s_values); $s_keys = array_keys($Smilies); $s_keys = array_map(create_function('$k', 'return "(" . preg_quote($k,"/") . ")";'), $s_keys); $s_keys_regex = implode('|', $s_keys); global $haveDokuSmilies; $haveDokuSmilies = false; $text = preg_replace_callback('/(' . $s_keys_regex . ')/ms', create_function('$matches', 'global $Smilies; global $haveDokuSmilies; $haveDokuSmilies = true; return $Smilies[$matches[1]];'), $text); } // try default renderer first: $file = DOKU_INC . "inc/parser/{$mode}.php"; if (@file_exists($file)) { require_once $file; $rclass = "Doku_Renderer_{$mode}"; if (!class_exists($rclass)) { trigger_error("Unable to resolve render class {$rclass}", E_USER_WARNING); msg("Renderer for {$mode} not valid", -1); return null; } $Renderer = new $rclass(); } else { // Maybe a plugin is available? $Renderer = plugin_load('renderer', $mode); if (is_null($Renderer)) { msg("No renderer for {$mode} found", -1); return null; } } // prevents utf8 conversions of quotation marks $text = str_replace('"', "_fckg_QUOT_", $text); $text = preg_replace_callback('/(<code|file.*?>)(.*?)(<\\/code>)/ms', create_function('$matches', '$quot = str_replace("_fckg_QUOT_",\'"\',$matches[2]); $quot = str_replace("\\\\ ","_fckg_NL",$quot); return $matches[1] . $quot . $matches[3];'), $text); global $fckgLPluginPatterns; $fckgLPluginPatterns = array(); $instructions = p_get_instructions("=== header ==="); // loads DOKU_PLUGINS array --M.T. Dec 22 2009 $installed_plugins = $this->get_plugins(); $regexes = $installed_plugins['plugins']; $text = preg_replace_callback('/(' . $regexes . ')/', create_function('$matches', 'global $fckgLPluginPatterns; $retv = preg_replace("/([\\{\\}\\@\\:&~\\?\\!<>])/", "$1 ", $matches[0]); $fckgLPluginPatterns[] = array($retv, $matches[0]); return $retv;'), $text); global $fckLImmutables; $fckglImmutables = array(); foreach ($installed_plugins['xcl'] as $xcl) { $text = preg_replace_callback('/' . $xcl . '/', create_function('$matches', 'global $fckLImmutables; if(preg_match("#//<//font#",$matches[0])) { return str_replace("//<//", "<", $matches[0]); } $index = count($fckLImmutables); $fckLImmutables[] = $matches[0]; return "<span id=\'imm_" . "$index\' title=\'imm_" . "$index\' >" . str_replace("//<//", "<", $matches[0]) . "</span>" ;'), $text); } global $multi_block; if (preg_match('/(?=MULTI_PLUGIN_OPEN)(.*?)(?<=MULTI_PLUGIN_CLOSE)/ms', $text, $matches)) { //file_put_contents('multi_text-2.txt',$matches[1]); $multi_block = $matches[1]; } $instructions = p_get_instructions($text); if (is_null($instructions)) { return ''; } $Renderer->notoc(); $Renderer->smileys = getSmileys(); $Renderer->entities = getEntities(); $Renderer->acronyms = array(); $Renderer->interwiki = getInterwiki(); // Loop through the instructions foreach ($instructions as $instruction) { // Execute the callback against the Renderer call_user_func_array(array(&$Renderer, $instruction[0]), $instruction[1]); } //set info array $info = $Renderer->info; // Post process and return the output $data = array($mode, &$Renderer->doc); trigger_event('RENDERER_CONTENT_POSTPROCESS', $data); $xhtml = $Renderer->doc; $pos = strpos($xhtml, 'MULTI_PLUGIN_OPEN'); if ($pos !== false) { $xhtml = preg_replace('/MULTI_PLUGIN_OPEN.*?MULTI_PLUGIN_CLOSE/ms', $multi_block, $xhtml); $xhtml = preg_replace_callback('|MULTI_PLUGIN_OPEN.*?MULTI_PLUGIN_CLOSE|ms', create_function('$matches', '$matches[0] = str_replace("//<//", "< ",$matches[0]); return preg_replace("/\\n/ms","<br />",$matches[0]);'), $xhtml); $xhtml = preg_replace('/~\\s*~\\s*MULTI_PLUGIN_OPEN~\\s*~/', "~ ~ MULTI_PLUGIN_OPEN~ ~\n\n<span class='multi_p_open'>\n\n</span>", $xhtml); $xhtml = preg_replace('/~\\s*~\\s*MULTI_PLUGIN_CLOSE~\\s*~/', "<span class='multi_p_close'>\n\n</span>\n\n~ ~ MULTI_PLUGIN_CLOSE~ ~\n", $xhtml); } // remove empty paragraph: see _fckg_NPBBR_ comment above $xhtml = preg_replace('/<p>\\s+_fckg_NPBBR_\\s+<\\/p>/ms', "\n", $xhtml); $xhtml = str_replace('_fckg_NPBBR_', "<span class='np_break'> </span>", $xhtml); $xhtml = str_replace('_fckg_QUOT_', '"', $xhtml); $xhtml = str_replace('_fckg_NL', "\n", $xhtml); $xhtml = str_replace('</pre>', "\n\n</pre><p> </p>", $xhtml); // inserts p before an initial codeblock to enable text entry above block $xhtml = preg_replace('/^<pre/', "<p> </p><pre", $xhtml); //remove empty markup remaining after removing marked-up acronyms in lists $xhtml = preg_replace('/<(em|b|u|i)>\\s+<\\/(em|b|u|i)>/ms', "", $xhtml); if ($smiley_as_text) { if ($haveDokuSmilies) { $s_values = array_values($Smilies); $s_values_regex = implode('|', $s_values); $xhtml = preg_replace_callback('/(' . $s_values_regex . ')/ms', create_function('$matches', 'global $Smilies; return array_search($matches[1],$Smilies); '), $xhtml); } } $ua = strtolower($_SERVER['HTTP_USER_AGENT']); if (strpos($ua, 'chrome') !== false) { $xhtml = preg_replace_callback('/(?<=<a )(href=\\".*?\\")(\\s+\\w+=\\".*?\\")(.*?)(?=>)/sm', create_function('$matches', '$ret_str = " " . trim($matches[3]) . " " . trim($matches[2]) . " " . trim($matches[1]) ; return $ret_str;'), $xhtml); } return $xhtml; }