Esempio n. 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);
}
Esempio n. 2
0
/**
 * Updates a post.
 *
 * @param string $uid
 * @param string $postid
 * @param string $title
 * @param string $content
 * @param array $categories
 * @return void
 */
function pivotx_update_post($uid, $postid, $title, $content, $categories = '')
{
    global $PIVOTX, $conversion_method, $body_separator;
    $oldentry = $PIVOTX['db']->read_entry($postid);
    $entry['code'] = $postid;
    $entry['date'] = $oldentry['date'];
    list($pivotintro, $pivotbody) = explode($body_separator, stripTrailingSpace(stripslashes($content)));
    $entry['introduction'] = $pivotintro;
    $entry['body'] = $pivotbody;
    $entry['introduction'] = tidyHtml($entry['introduction'], TRUE);
    $entry['body'] = tidyHtml($entry['body'], TRUE);
    if (empty($categories)) {
        $entry['category'] = $oldentry['category'];
    } else {
        $entry['category'] = $categories;
    }
    $entry['publish_date'] = $oldentry['publish_date'];
    $entry['edit_date'] = date("Y-m-d-H-i", getCurrentDate());
    $entry['title'] = stripTrailingSpace(stripslashes($title));
    $entry['subtitle'] = $oldentry['subtitle'];
    $entry['user'] = $uid;
    $entry['convert_lb'] = $conversion_method;
    $entry['status'] = "publish";
    $entry['allow_comments'] = 1;
    $entry['keywords'] = $oldentry['keywords'];
    $entry['vialink'] = $oldentry['vialink'];
    $entry['viatitle'] = $oldentry['viatitle'];
    $PIVOTX['db']->set_entry($entry);
    $PIVOTX['db']->save_entry(TRUE);
}
Esempio n. 3
0
function tidyEscaper($twig, $str, $charset)
{
    return tidyHtml($str);
}