/** * Get the Text_Wiki renderer * * Singleton to get the Text_Wiki instance properly configured for the * TIP system. You can specify an array of rules to use in the $rules * array, or leave it undefined to use all the available rules. * * @param array|null $rules The array of rules to enable * @param string|null $toc_title TOC title or null to use a default value * @param string|null $wiki_base Base URI for wiki links * @return Text_Wiki The renderer */ public static function &getWiki($rules = null, $toc_title = null, $wiki_base = '') { static $renderer = null; static $all_rules = array('Prefilter', 'Delimiter', 'Code', 'Function', 'Html', 'Raw', 'Include', 'Embed', 'Anchor', 'Heading', 'Toc', 'Horiz', 'Break', 'Blockquote', 'List', 'Deflist', 'Table', 'Image', 'Phplookup', 'Center', 'Paragraph', 'Url', 'Freelink', 'Interwiki', 'Wikilink', 'Colortext', 'Strong', 'Bold', 'Emphasis', 'Italic', 'Underline', 'Tt', 'Superscript', 'Subscript', 'Revise', 'Tighten'); static $base_rules = array('Prefilter', 'Break', 'Paragraph', 'Tighten'); if (is_null($renderer)) { require_once 'Text/Wiki.php'; isset($toc_title) || ($toc_title = TIP::getLocale('index', 'wiki')); $renderer =& Text_Wiki::singleton('Default'); $renderer->disable = array(); $renderer->setFormatConf('Xhtml', 'charset', 'UTF-8'); /* According to the following comment: * http://php.net/manual/function.htmlentities.php#78509 * "There's no sane reason to use htmlentities() instead of htmlspecialchars()" */ $renderer->setFormatConf('Xhtml', 'translate', HTML_SPECIALCHARS); $renderer->setRenderConf('Xhtml', 'url', array('target' => '', 'regexes' => array('|http://picasaweb\\.google\\.com/.*/photo/.*|' => array('TIP_Renderer', 'picasa2PhotoCallback'), '|http://picasaweb\\.google\\.com/.*/albumid/.*|' => array('TIP_Renderer', 'picasa2AlbumCallback')))); $renderer->setRenderConf('Xhtml', 'code', array('css' => 'programlisting')); $renderer->setRenderConf('Xhtml', 'toc', array('title' => '<p><strong>' . $toc_title . '</strong></p>', 'div_id' => 'idToc', 'use_ul' => true, 'collapse' => false)); $renderer->setRenderConf('Xhtml', 'freelink', array('pages' => null, 'view_url' => $wiki_base, 'new_text_pos' => null)); } if (is_array($rules)) { // Capitalize the $rules values $rules = array_map('ucfirst', array_map('strtolower', $rules)); // Join the forced rules $rules = array_merge($rules, $base_rules); // Get the real rules to apply $rules = array_intersect($all_rules, $rules); } else { $rules = $base_rules; } $renderer->rules = $rules; return $renderer; }
public function __construct(Sensei_Doc_Toc $toc, array $options = array()) { $defaultOptions = array( 'title' => 'Title', 'author' => 'Author', 'version' => '', 'subject' => 'Subject', 'keywords' => 'key, word', 'template' => '' ); $this->_options = array_merge($defaultOptions, $this->_options); $this->setOptions($options); $this->_toc = $toc; $this->_wiki = Text_Wiki::singleton('Doc'); $this->_wiki->setParseConf('Doclink', 'toc', $this->_toc); }
function pearwiki_general_parse_data($parser_fmt, &$pParseHash, &$pCommonObject) { global $gBitSystem; if (!defined('PAGE_SEP')) { define('PAGE_SEP', 'PAGE MARKER HERE*&^%$#^$%*PAGEMARKERHERE'); } $parser = Text_Wiki::singleton($parser_fmt); if (PEAR::isError($parser)) { $gBitSystem->fatalError("There was an unknown error while constructing the PEAR parser."); } global $gBitSystem; if ($gBitSystem->isPackageActive('wiki')) { $parser->setRenderConf('xhtml', 'wikilink', 'exists_callback', array(&$pCommonObject, 'pageExists')); $parser->setRenderConf('xhtml', 'wikilink', 'view_url', WIKI_PKG_URL . 'index.php?page='); $parser->setRenderConf('xhtml', 'wikilink', 'new_url', WIKI_PKG_URL . 'edit.php?page='); } $parser->setRenderConf('xhtml', 'table', 'css_table', 'wikitable'); $xhtml = $parser->transform($pParseHash['data'], 'Xhtml'); return $xhtml; }
function beforeCache(&$input) { global $conf; // code highlighting require_once 'geshi/geshi.php'; require_once 'Text/Wiki.php'; // transform it a little to save it from evil wiki parser ^^ $input = preg_replace_callback('#<code (\\w+)>(.*?)</code>#Uuism', array($this, 'code_cut_tag'), $input) . ' '; // create a Wiki object with the loaded options $wiki =& Text_Wiki::singleton('Doku'); $wiki->setRenderConf('xhtml', 'wikilink', 'new_text', ''); if (isset($conf['general']['doku_url']) && $conf['general']['doku_url']) { $wiki->setRenderConf('xhtml', 'wikilink', 'new_url', $conf['general']['doku_url']); } $wiki->setFormatConf('Xhtml', 'translate', HTML_SPECIALCHARS); $wiki->setFormatConf('Xhtml', 'charset', 'utf-8'); if (@$type == 'Doku') { $input = str_replace('\\\\', '', $input); } $input = @$wiki->transform($input, 'Xhtml'); // restoring code tags with highlighting $input = preg_replace_callback('#:code__(\\d+)_:#Uuism', array($this, 'code_callback'), $input); }
} $_REQUEST['translate'] = true; } foreach (array('parser' => $plist[0], 'render' => $rlist[0], 'exchoice' => $elist ? $elist[0] : '', 'source' => '') as $fld => $def) { if (!isset($_REQUEST[$fld])) { $_REQUEST[$fld] = $def; } ${$fld} = $_REQUEST[$fld]; } if (!isset($_REQUEST['translate'])) { echo bldHtml('', $plist, $rlist, $elist); die; } } // instantiate a Text_Wiki object from the given class $wiki =& Text_Wiki::singleton($parser); // If you want to include rules, use //$wiki = & Text_Wiki::singleton($parser, $rules); // If you want to get a new copy of the class use factory //$wiki =& Text_Wiki::factory($parser); //print "<pre>\n"; //print_r($wiki); //print "</pre>\n"; // when rendering XHTML, make sure wiki links point to a // specific base URL //$wiki->setRenderConf('xhtml', 'wikilink', 'view_url', // 'http://example.com/view.php?page='); // set an array of pages that exist in the wiki // and tell the XHTML renderer about them //$pages = array('HomePage', 'AnotherPage', 'SomeOtherPage'); $wiki->setRenderConf('xhtml', 'code', 'css_filename', 'codefilename');
/** * Return the frozen value of field using the specified Text_Wiki renderer * @return string * @since 1.0 * @access public */ function getFrozenHtml() { if (isset($this->_wiki)) { // Use the user provided Text_Wiki instance $wiki =& $this->_wiki; } else { // Use the 'Default' Text_Wiki instance require_once 'Text/Wiki.php'; $wiki =& Text_Wiki::singleton('Default'); } $value = $this->getValue(); $html = $wiki->transform($value, $this->_renderer); return $html . $this->_getPersistantData(); }
function parse_code($codedpage) { // Pre-parsing: $pageclean = $this->preParsingCleanup($codedpage); // Strange bugfix; WIKI databases are URF-8, but apparently the TEXT-WIKI code requires LATIN1 input if (IS_ON_KTH_SERVER) { $pageclean = mb_convert_encoding($pageclean, "ISO-8859-1"); } // Create wiki object using given parser: $parser = "Mediawiki"; $render = "Xhtml"; $wiki =& Text_Wiki::singleton($parser); $wiki->setRenderConf('xhtml', 'code', 'css_filename', 'codefilename'); // Transform the wiki text into given rendering $decodedpage = $wiki->transform($pageclean, $render); $decodedpage = html_entity_decode(html_entity_decode($decodedpage)); //TODO: bugfix... if (!in_array(SUBSITE, array("nordita2011"))) { $decodedpage = str_replace("'nordita2011/", "'", $decodedpage); } // Post-parsing adjustments: if (isset($this->wikipage_images)) { if (preg_match_all("/src=\"\\/(.*)\"/U", $decodedpage, $ims)) { foreach ($ims[1] as $im) { if (isset($this->wikipage_images[$im]["src"])) { // need to match more than just "/".$im (here: also initial quotation mark), // in case a wiki image is displayed more than once: $decodedpage = preg_replace("~([\"'])/" . $im . "~U", "\\1" . $this->wikipage_images[$im]["src"], $decodedpage); } } } } $decodedpage = trim($this->postParsingCleanup($decodedpage)); if (!empty($decodedpage)) { $decodedpage .= "\r\n"; } return $decodedpage; }