Example #1
0
/**
 * Display extension documentation using Textile or Markdown.
 */
function pageDocumentation()
{
    global $PIVOTX;
    // Get the filename, extension (markdown or textile) and type (summary or other)
    $filename = $PIVOTX['paths']['extensions_path'] . $_GET['file'];
    $basename = makeAdminPageLink('documentation') . "&file=" . dirname($_GET['file']);
    $extension = strtolower(getExtension($filename));
    list($type, $dummy) = explode(".", basename($filename));
    if (!file_exists($filename) || $extension != "textile" && $extension != "markdown") {
        echo "Not a valid filename";
        die;
    }
    $source = file_get_contents($filename);
    if ($extension == "markdown") {
        $html = pivotxMarkdown($source);
    } else {
        $html = pivotxTextile($source);
    }
    // Find the fist <h1>, to use as title.. But, only for full docs..
    if ($type != "summary") {
        preg_match_all('/<h1>(.*)<\\/h1>/i', $html, $match);
        if (!empty($match[1][0])) {
            $PIVOTX['template']->assign('title', strip_tags($match[1][0]));
        }
    }
    // Find links to other pages in the docs, and rewrite them, so that they're parsed into correct links
    $html = preg_replace('/a href="([a-z0-9_-]*)\\.(markdown|textile)"/', 'a href="' . $basename . '/\\1.\\2"', $html);
    $PIVOTX['template']->assign('html', $html);
    // Check for 'toc.markdown' or 'toc.textile', and insert those, if present..
    $tocfilename = dirname($filename) . "/toc." . $extension;
    if (file_exists($tocfilename)) {
        $toc = file_get_contents($tocfilename);
        if ($extension == "markdown") {
            $tochtml = pivotxMarkdown($toc);
        } else {
            $tochtml = pivotxTextile($toc);
        }
        // Find links to other pages in the docs, and rewrite them, so that they're parsed into correct links
        $tochtml = preg_replace('/a href="([a-z0-9_-]*)\\.(markdown|textile)"/', 'a href="' . $basename . '/\\1.\\2"', $tochtml);
        $PIVOTX['template']->assign('toc', $tochtml);
    }
    renderTemplate('documentation.tpl');
}
Example #2
0
/**
 * Parsing intro or body.
 *
 * if $strip is set, we strip out all tags, except for the most common ones. If
 * $text_processing_only is set, we only apply the text processing (textile,
 * markdown), but not the Smarty parsing. This is useful for converting between
 * one editing mode to the other
 *
 * @param string $text
 * @param boolean $strip
 * @param integer $textmode
 * @param boolean $text_processing_only
 * 
 */
function parse_intro_or_body($text, $strip = false, $textmode = 0, $text_processing_only = false)
{
    global $PIVOTX;
    // Abort immediately if there is no text to parse.
    if (empty($text)) {
        return '';
    }
    $output = $text;
    // Parse [[tags]] in introduction and body..
    // Use $key so a unique name is made, to prevent strange results
    // popping up when we're using caching.
    if (!$text_processing_only) {
        $cachekey = "tpl_" . substr(md5($output), 0, 10);
        $PIVOTX['template']->caching = false;
        $PIVOTX['template']->custom_template[$cachekey] = $output;
        $output = $PIVOTX['template']->fetch("db:" . $cachekey, $cachekey);
        // Re-enable caching, if desired..
        if ($PIVOTX['config']->get('smarty_cache')) {
            $PIVOTX['template']->caching = true;
        }
    }
    if ($strip != false) {
        $output = strip_tags($output, "<a><b><i><u><strong><em>");
    }
    /**
     * text processing: nl2br, Textile or Markdown/SmartyPants
     * We ensure that newlines aren't converted to br elements in script
     * blocks - currently handling PHP and JavaScript.
     * More exclusions will/can be added.
     */
    // Use the ACK (006) ASCII symbol to replace all script elements temporarily
    $output = str_replace("", "", $output);
    $regexp = "#(<script[ >].*?</script>)|(<\\?php\\s.*?\\?>)#is";
    preg_match_all($regexp, $output, $scripts);
    $output = preg_replace($regexp, "", $output);
    if ($textmode == 1) {
        $output = stripTrailingSpace(nl2br($output));
    } else {
        if ($textmode == 2) {
            $output = pivotxTextile($output);
        } else {
            if ($textmode == 3 || $textmode == 4) {
                $output = pivotxMarkdown($output, $textmode);
            }
        }
    }
    // Put captured scripts back into the output
    foreach ($scripts[0] as $script) {
        $output = preg_replace("//", $script, $output, 1);
    }
    // emoticons..
    if ($PIVOTX['weblogs']->get('', 'emoticons') == 1) {
        $output = emoticonize($output);
    }
    // There's a silly quirk in TinyMCE, that prevents transparent Flash. We
    // need to fix this, to make Youtube videos work properly.
    $output = str_replace("<param name=\"wmode\" value=\"\" />", "<param name=\"wmode\" value=\"transparent\" />", $output);
    $output = str_replace(" wmode=\"\" ", " wmode=\"transparent\" ", $output);
    return tidyHtml($output);
}