/** * Transform text using Wiki library * * @author Greg Meiste <*****@*****.**> */ function transform($wikitext) { require_once 'Text/Wiki.php'; if (!defined('WIKI_PARSER')) { define('WIKI_PARSER', 'Default'); } $wiki =& Text_Wiki::factory(WIKI_PARSER); if (PEAR::isError($wiki)) { return sprintf(dgettext('wiki', 'Error! %s parser not found.'), WIKI_PARSER); } $wikitext = str_replace("'", "'", $wikitext); $db = new PHPWS_DB('wiki_pages'); $db->addColumn('title'); $pages = $db->select('col'); if (PEAR::isError($pages)) { PHPWS_Error::log($pages); $pages = NULL; } // Add custom parser rules $wiki->addPath('parse', PHPWS_SOURCE_DIR . 'mod/wiki/class/parse/'); $wiki->insertRule('Template', ''); $wiki->setRenderConf('xhtml', 'wikilink', 'pages', $pages); $wiki->setRenderConf('xhtml', 'wikilink', 'view_url', MOD_REWRITE_ENABLED ? 'wiki/%s' : './index.php?module=wiki&page=%s'); $wiki->setRenderConf('xhtml', 'wikilink', 'new_url', MOD_REWRITE_ENABLED ? 'wiki/%s' : './index.php?module=wiki&page=%s'); $wiki->setRenderConf('xhtml', 'toc', 'title', '<strong>' . dgettext('wiki', 'Table of Contents') . '</strong>'); $wiki->setRenderConf('xhtml', 'image', 'base', 'images/wiki/'); $wiki->setRenderConf('xhtml', 'url', 'target', PHPWS_Settings::get('wiki', 'ext_page_target')); $wiki->setRenderConf('xhtml', 'interwiki', 'target', PHPWS_Settings::get('wiki', 'ext_page_target')); $sites = array(); $db = new PHPWS_DB('wiki_interwiki'); $result = $db->select(); foreach ($result as $row) { $sites[$row['label']] = $row['url']; } $wiki->setRenderConf('xhtml', 'interwiki', 'sites', $sites); if (PHPWS_Settings::get('wiki', 'ext_chars_support')) { $wiki->setParseConf('Wikilink', 'ext_chars', true); $wiki->setFormatConf('Xhtml', 'translate', HTML_SPECIALCHARS); } // Setting CSS styles for tags $wiki->setRenderConf('xhtml', 'blockquote', 'css', 'wiki'); $wiki->setRenderConf('xhtml', 'code', 'css', 'wiki'); $wiki->setRenderConf('xhtml', 'code', 'css_code', 'wiki'); $wiki->setRenderConf('xhtml', 'code', 'css_php', 'wiki'); $wiki->setRenderConf('xhtml', 'code', 'css_html', 'wiki'); $wiki->setRenderConf('xhtml', 'deflist', 'css_dl', 'wiki'); $wiki->setRenderConf('xhtml', 'deflist', 'css_dt', 'wiki'); $wiki->setRenderConf('xhtml', 'deflist', 'css_dd', 'wiki'); $wiki->setRenderConf('xhtml', 'emphasis', 'css', 'wiki'); $wiki->setRenderConf('xhtml', 'heading', 'css_h1', 'wiki'); $wiki->setRenderConf('xhtml', 'heading', 'css_h2', 'wiki'); $wiki->setRenderConf('xhtml', 'heading', 'css_h3', 'wiki'); $wiki->setRenderConf('xhtml', 'heading', 'css_h4', 'wiki'); $wiki->setRenderConf('xhtml', 'heading', 'css_h5', 'wiki'); $wiki->setRenderConf('xhtml', 'heading', 'css_h6', 'wiki'); $wiki->setRenderConf('xhtml', 'horiz', 'css', 'wiki'); $wiki->setRenderConf('xhtml', 'image', 'css', 'wiki'); $wiki->setRenderConf('xhtml', 'interwiki', 'css', 'wiki'); $wiki->setRenderConf('xhtml', 'list', 'css_ol', 'wiki'); $wiki->setRenderConf('xhtml', 'list', 'css_ol_li', 'wiki'); $wiki->setRenderConf('xhtml', 'list', 'css_ul', 'wiki'); $wiki->setRenderConf('xhtml', 'list', 'css_ul_li', 'wiki'); $wiki->setRenderConf('xhtml', 'paragraph', 'css', 'wiki'); $wiki->setRenderConf('xhtml', 'table', 'css_table', 'wiki'); $wiki->setRenderConf('xhtml', 'table', 'css_tr', 'wiki'); $wiki->setRenderConf('xhtml', 'table', 'css_th', 'wiki'); $wiki->setRenderConf('xhtml', 'table', 'css_td', 'wiki'); $wiki->setRenderConf('xhtml', 'tt', 'css', 'wiki'); $wiki->setRenderConf('xhtml', 'url', 'css_inline', 'wiki'); $wiki->setRenderConf('xhtml', 'url', 'css_footnote', 'wiki'); $wiki->setRenderConf('xhtml', 'url', 'css_descr', 'wiki'); $wiki->setRenderConf('xhtml', 'url', 'css_img', 'wiki'); $wiki->setRenderConf('xhtml', 'wikilink', 'css', 'wiki'); $wiki->setRenderConf('xhtml', 'wikilink', 'css_new', 'wiki'); if (ALLOW_PROFANITY) { $wikitext = $wiki->transform($wikitext); } else { $wikitext = $wiki->transform(PHPWS_Text::profanityFilter($wikitext)); } if (PHPWS_Settings::get('wiki', 'allow_bbcode')) { $wikitext = PHPWS_Text::bb2html($wikitext, 'wiki'); } $wikitext = PHPWS_Text::fixAnchors($wikitext); $wikitext = str_replace('%23', '#', $wikitext); return PHPWS_Text::parseTag($wikitext); }