コード例 #1
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);
}
コード例 #2
0
/**
 * Parsing intro or body
 */
function parse_intro_or_body($text, $strip = "")
{
    global $db, $Weblogs, $Current_weblog;
    $output = $text;
    if ($strip == "strip") {
        $output = strip_tags($output, "<a><b><i><u><embed><strong><ol><li><ul>");
    }
    $output = parse_step4($output);
    /* 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 ($db->entry['convert_lb'] == 1) {
        $output = strip_trailing_space(nl2br($output));
    } else {
        if ($db->entry['convert_lb'] == 2) {
            $output = pivot_textile($output);
        } else {
            if ($db->entry['convert_lb'] == 3 || $db->entry['convert_lb'] == 4) {
                $output = pivot_markdown($output, $db->entry['convert_lb']);
            }
        }
    }
    // Put captured scripts back into the output
    foreach ($scripts[0] as $script) {
        $output = preg_replace("//", $script, $output, 1);
    }
    // targetblank
    if ($Weblogs[$Current_weblog]['target_blank'] > 0) {
        $output = targetblank($output);
    }
    // emoticons..
    if ($Weblogs[$Current_weblog]['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 tidy_html($output);
}
コード例 #3
0
ファイル: pvlib.php プロジェクト: wborbajr/TecnodataApp
/**
 * Formats trackbacks according the settings for the current weblog.
 *
 * We strip _all_ tags except <b> and <i> and after that
 * we convert everything that looks like a url or mail-address
 * to the equivalent link (if enabled).
 *
 * @param string $text
 * @return string
 */
function trackback_format($text)
{
    global $Cfg, $Weblogs, $Current_weblog, $Paths;
    $text = trim(strip_tags($text, '<b>,<i>,<em>,<strong>'));
    // did user request '_blank' target rerouting?
    if (1 == $Weblogs[$Current_weblog]['target_blank']) {
        $target = ' target="_blank"';
    } else {
        $target = '';
    }
    if (1 == $Weblogs[$Current_weblog]['comment_texttolinks']) {
        $text = eregi_replace("([ \t]|^)www\\.", " http://www.", $text);
        $text = eregi_replace("([ \t]|^)ftp\\.", " ftp://ftp.", $text);
        $text = eregi_replace("(http://[^ )\r\n]+)", "<a  href=\"\\1\"{$target}>[[\\1]]</a>", $text);
        $text = eregi_replace("(https://[^ )\r\n]+)", "<a  href=\"\\1\"{$target}>[[\\1]]</a>", $text);
        $text = eregi_replace("(ftp://[^ )\r\n]+)", "<a  href=\"\\1\"{$target}>[[\\1]]</a>", $text);
        // 2004/11/30 =*=*= JM - clear up messed ftp links with '@' in
        preg_match_all("|\\[\\[(.*)\\]\\]|U", $text, $match, PREG_PATTERN_ORDER);
        // do we need to do changes?
        if (is_array($match) && count($match) > 0) {
            foreach ($match[1] as $url) {
                $url2 = str_replace('@', '%40', $url);
                $text = str_replace($url, $url2, $text);
            }
        }
        $text = eregi_replace("([-a-z0-9_]+(\\.[_a-z0-9-]+)*@([a-z0-9-]+(\\.[a-z0 -9-]+)+))", "<a href=\"mailto:\\1\">\\1</a>", $text);
        // now change the '@' back...
        $text = str_replace('%40', '@', $text);
        // then make long urls into short urls, with correct link..
        preg_match_all("|\\[\\[(.*)\\]\\]|U", $text, $match, PREG_PATTERN_ORDER);
        foreach ($match[1] as $url) {
            if (strlen($url) > 40) {
                $s_url = substr($url, 0, 40) . '..';
            } else {
                $s_url = $url;
            }
            $text = str_replace('[[' . $url . ']]', $s_url, $text);
        }
        // perhaps redirect the link..
        if (isset($Weblogs[$Current_weblog]['lastcomm_redirect']) && 1 == $Weblogs[$Current_weblog]['lastcomm_redirect']) {
            //$text = str_replace(  'href="http://','href="'.$Paths['pivot_url'].'includes/re.php?http://',$text );
            $text = preg_replace("#<a href=(\"|')([^>\n]+)\\1([^<>]*)>(.*)</a>#iUs", "<a href=\"\\2\" \\3 rel='nofollow'>\\4</a>", $text);
        }
    }
    $text = nl2br(trim($text));
    if ($Weblogs[$Current_weblog]['emoticons'] == 1) {
        $text = emoticonize($text);
    }
    return stripslashes($text);
}