Example #1
0
/**
 * Parse post content into readable data, or return default text
 * @global array
 * @param string $text data to be parsed
 * @param boolean $bbcode show bbcode or not?
 * @return mixed
 */
function parse($text, $bbcode = true)
{
    global $config;
    // Do they allow bbcode or does this post allow bbcode?
    if ($config['bbcode'] && $bbcode) {
        $start = array('/\\[url=("|\'|)(.*?)\\1\\]/i', '/\\[url\\]/i', '/\\[\\/url\\]/i', '/\\[img\\]\\s*(.*?)\\s*\\[\\/img\\]/is', '/\\[colou?r=("|\'|)(.*?)\\1\\](.*?)\\[\\/colou?r\\]/is', '/\\[quote=("|"|\'|)(.*?)\\1\\]\\s */i', '/\\[qoute=("|"|\'|)(.*?)\\1\\]\\s */i', '/\\[quote\\]\\s */i', '/\\[qoute\\]\\s */i', '/\\s*\\[\\/quote\\]\\s */i', '/\\s*\\[\\/qoute\\]/i', '/\\[code\\][\\r\\n]*(.*?)\\[\\/code\\]/is');
        $end = array('[url=$2]', '[url]', '[/url]', '[img]$1[/img]', '[color=$2]$3[/color]', '[quote=$1$2$1]', '[quote=$1$2$1]', '[quote]', '[quote]', '[/quote]' . "\n", '[/quote]' . "\n", '[code]$1[/code]' . "\n");
        // Replace the non needed characters.
        $text = preg_replace($start, $end, $text);
        // Html close tags edited to work for bbcode
        $text = closetags($text);
        // Lets make sure the code doesn't get obscured
        if (strpos($text, '[code]') !== false && strpos($text, '[/code]') !== false) {
            list($inside, $outside) = split_text($text, '[code]', '[/code]');
            $outside = array_map('ltrim', $outside);
            $text = implode('<">', $outside);
        }
        // Quoting
        if (strpos($text, 'quote') !== false) {
            $text = str_replace('[quote]', '<blockquote><div class="quotebox"><div>', $text);
            $text = preg_replace('/\\[quote=(&quot;|"|\'|)(.*)\\1\\]/seU', '"<blockquote><div class=\\"quotebox\\"><h4>".str_replace(array(\'[\', \'\\"\'), array(\'&#91;\', \'"\'), \'$2\')." wrote:</h4><div class=\\"text\\">"', $text);
            $text = preg_replace('/\\[\\/quote\\](\\s *)?/i', '</div></div></blockquote>', $text);
        }
        // Basic BBCodes
        $pattern = array('/\\[b\\](.*?)\\[\\/b\\]/s', '/\\[i\\](.*?)\\[\\/i\\]/s', '/\\[u\\](.*?)\\[\\/u\\]/s');
        $replace = array('<strong>$1</strong>', '<em>$1</em>', '<u>$1</u>');
        // This thing takes a while! :)
        $text = preg_replace($pattern, $replace, $text);
        // Do we allow urls?
        if ($config['bbcode_url']) {
            $pattern = array('/\\[url\\]([^\\[]*?)\\[\\/url\\]/e', '/\\[url=([^\\[]*?)\\](.*?)\\[\\/url\\]/e');
            $replace = array('url_tag(\'$1\')', 'url_tag(\'$1\', \'$2\')');
            $text = preg_replace($pattern, $replace, $text);
        }
        // Color
        $text = preg_replace("/\\[color=([a-zA-Z]*|\\#?[0-9a-fA-F]{6})]/s", '<span style="color: \\1">', $text);
        $text = preg_replace("/\\[\\/color\\]/s", '</span>', $text);
        // Do we allow images?
        if ($config['bbcode_image']) {
            $text = preg_replace('/\\[img\\]((ht|f)tps?:\\/\\/)([^\\s<\\"]*?)\\.(jpg|jpeg|png|gif)\\[\\/img\\]/s', '<img class="p-image" src="\\1\\3.\\4\\" />', $text);
        }
        // If we split up the message before we have to concatenate it together again (code tags)
        if (isset($inside)) {
            $outside = explode('<">', $text);
            $text = '';
            $num_tokens = count($outside);
            for ($i = 0; $i < $num_tokens; ++$i) {
                $text .= $outside[$i];
                if (isset($inside[$i])) {
                    $text .= '<div class="codebox"><h4>Code:</h4><div class="scrollbox"><pre>' . $inside[$i] . '</pre></div></div>';
                }
            }
        }
    }
    // Return base text!
    if (!$bbcode) {
        return $text;
    }
    // Return a fully parsed post / other
    return clickable(stripslashes(nl2br(str_replace(array('\\r\\n', '\\r', '\\n'), "<br />", html_entity_decode($text)))));
}
Example #2
0
function parse_message($text, $hide_smilies)
{
    global $pun_config, $lang_common, $pun_user;
    if ($pun_config['o_censoring'] == '1') {
        $text = censor_words($text);
    }
    // Convert applicable characters to HTML entities
    $text = pun_htmlspecialchars($text);
    // If the message contains a code tag we have to split it up (text within [code][/code] shouldn't be touched)
    if (strpos($text, '[code]') !== false && strpos($text, '[/code]') !== false) {
        list($inside, $outside) = split_text($text, '[code]', '[/code]');
        $outside = array_map('ltrim', $outside);
        $text = implode('<">', $outside);
    }
    if ($pun_config['o_make_links'] == '1') {
        $text = do_clickable($text);
    }
    if ($pun_config['o_smilies'] == '1' && $pun_user['show_smilies'] == '1' && $hide_smilies == '0') {
        $text = do_smilies($text);
    }
    if ($pun_config['p_message_bbcode'] == '1' && strpos($text, '[') !== false && strpos($text, ']') !== false) {
        $text = do_bbcode($text);
        if ($pun_config['p_message_img_tag'] == '1') {
            //			$text = preg_replace('#\[img\]((ht|f)tps?://)([^\s<"]*?)\.(jpg|jpeg|png|gif)\[/img\]#e', 'handle_img_tag(\'$1$3.$4\')', $text);
            $text = preg_replace('#\\[img\\]((ht|f)tps?://)([^\\s<"]*?)\\[/img\\]#e', 'handle_img_tag(\'$1$3\')', $text);
        }
    }
    // Deal with newlines, tabs and multiple spaces
    $pattern = array("\n", "\t", '  ', '  ');
    $replace = array('<br />', '&nbsp; &nbsp; ', '&nbsp; ', ' &nbsp;');
    $text = str_replace($pattern, $replace, $text);
    // If we split up the message before we have to concatenate it together again (code tags)
    if (isset($inside)) {
        $outside = explode('<">', $text);
        $text = '';
        $num_tokens = count($outside);
        for ($i = 0; $i < $num_tokens; ++$i) {
            $text .= $outside[$i];
            if (isset($inside[$i])) {
                $num_lines = (substr_count($inside[$i], "\n") + 3) * 1.5;
                $height_str = $num_lines > 35 ? '35em' : $num_lines . 'em';
                $text .= '</p><div class="codebox"><div class="incqbox"><h4>' . $lang_common['Code'] . ':</h4><div class="scrollbox" style="height: ' . $height_str . '"><pre>' . $inside[$i] . '</pre></div></div></div><p>';
            }
        }
    }
    // Add paragraph tag around post, but make sure there are no empty paragraphs
    $text = str_replace('<p></p>', '', '<p>' . $text . '</p>');
    return $text;
}
Example #3
0
 $action = __('Add comment', 'luna');
 $form = '<form id="post" method="post" action="post.php?action=post&amp;tid=' . $tid . '" onsubmit="window.onbeforeunload=null;this.submit.disabled=true;if(process_form(this)){return true;}else{this.submit.disabled=false;return false;}">';
 // If a quote ID was specified in the url
 if (isset($_GET['qid'])) {
     $qid = intval($_GET['qid']);
     if ($qid < 1) {
         message(__('Bad request. The link you followed is incorrect, outdated or you are simply not allowed to hang around here.', 'luna'), false, '404 Not Found');
     }
     $result = $db->query('SELECT poster, message FROM ' . $db->prefix . 'posts WHERE id=' . $qid . ' AND topic_id=' . $tid) or error('Unable to fetch quote info', __FILE__, __LINE__, $db->error());
     if (!$db->num_rows($result)) {
         message(__('Bad request. The link you followed is incorrect, outdated or you are simply not allowed to hang around here.', 'luna'), false, '404 Not Found');
     }
     list($q_poster, $q_message) = $db->fetch_row($result);
     // If the message contains a code tag we have to split it up (text within [code][/code] shouldn't be touched)
     if (strpos($q_message, '[code]') !== false && strpos($q_message, '[/code]') !== false) {
         list($inside, $outside) = split_text($q_message, '[code]', '[/code]');
         $q_message = implode("", $outside);
     }
     // Remove [img] tags from quoted message
     $q_message = preg_replace('%\\[img(?:=(?:[^\\[]*?))?\\]((ht|f)tps?://)([^\\s<"]*?)\\[/img\\]%U', '\\1\\3', $q_message);
     // If we split up the message before we have to concatenate it together again (code tags)
     if (isset($inside)) {
         $outside = explode("", $q_message);
         $q_message = '';
         $num_tokens = count($outside);
         for ($i = 0; $i < $num_tokens; ++$i) {
             $q_message .= $outside[$i];
             if (isset($inside[$i])) {
                 $q_message .= '[code]' . $inside[$i] . '[/code]';
             }
         }
Example #4
0
function parse_message($text, $html = 'off')
{
    if ($html != 'on') {
        // Convert applicable characters to HTML entities
        $text = pun_htmlspecialchars($text);
    }
    // If the message contains a code tag we have to split it up (text within [code][/code] shouldn't be touched)
    if (strpos($text, '[code]') !== false && strpos($text, '[/code]') !== false) {
        list($inside, $outside) = split_text($text, '[code]', '[/code]');
        $outside = array_map('ltrim', $outside);
        $text = implode('<">', $outside);
    }
    $text = do_clickable($text);
    if (strpos($text, '[') !== false && strpos($text, ']') !== false) {
        $text = do_bbcode($text);
        $text = preg_replace('#\\[img\\]((ht|f)tps?://)([^\\s<"]*?)\\[/img\\]#e', 'handle_img_tag(\'$1$3\')', $text);
    }
    // Deal with newlines, tabs and multiple spaces
    $pattern = array("\n", "\t", '  ', '  ');
    $replace = array('<br />', '&nbsp; &nbsp; ', '&nbsp; ', ' &nbsp;');
    $text = str_replace($pattern, $replace, $text);
    // If we split up the message before we have to concatenate it together again (code tags)
    if (isset($inside)) {
        $outside = explode('<">', $text);
        $text = '';
        $num_tokens = count($outside);
        for ($i = 0; $i < $num_tokens; ++$i) {
            $text .= $outside[$i];
            if (isset($inside[$i])) {
                $num_lines = (substr_count($inside[$i], "\n") + 3) * 1.5;
                $height_str = $num_lines > 35 ? '35em' : $num_lines . 'em';
                $text .= '</p><div class="codebox"><div class="incqbox"><h4>Kod:</h4><div class="scrollbox" style="height: ' . $height_str . '"><pre>' . $inside[$i] . '</pre></div></div></div><p>';
            }
        }
    }
    // Add paragraph tag around post, but make sure there are no empty paragraphs
    $text = str_replace('<p></p>', '', '<p class="IE_wrap">' . $text . '</p>');
    $pattern = '/@([0-9a-zA-Z_\\-åäöÅÄÖ]+)@/';
    $replacement = '<div style="font-weight: bold; font-style: italic;">Svarar till <a href="/traffa/quicksearch.php?username=$1">$1</a></div>';
    $text = preg_replace($pattern, $replacement, $text);
    $pattern = '/@([0-9a-zA-Z_\\-åäöÅÄÖ]+):([0-9]+)@/';
    function fix_postid($matches)
    {
        $query = 'SELECT timestamp FROM forum_posts, login WHERE forum_posts.id = ' . $matches[2] . ' AND login.username LIKE "' . $matches[1] . '" AND login.id = forum_posts.user';
        $result = mysql_query($query);
        $data = mysql_fetch_assoc($result);
        if (mysql_num_rows($result) > 0) {
            $extra_text .= '<strong><i> <a href="javascript: void(0);" onclick="window.open(\'read_post_popup.php?id=' . $matches[2] . '\'';
            $extra_text .= ', \'_blank\', \'width=600, height=450, scrollbars=yes\');">';
            $extra_text .= 'Svarar på inlägg skrivet av ' . $matches[1] . ', ' . date('Y-m-d H:i', $data['timestamp']) . '</a></strong></i>';
        }
        return $extra_text;
    }
    $text = preg_replace_callback($pattern, "fix_postid", $text);
    return $text;
}
Example #5
0
function parse_message($text, $hide_smilies)
{
    global $forum_config, $lang_common, $forum_user;
    $return = ($hook = get_hook('ps_parse_message_start')) ? eval($hook) : null;
    if ($return != null) {
        return $return;
    }
    if ($forum_config['o_censoring'] == '1') {
        $text = censor_words($text);
    }
    $return = ($hook = get_hook('ps_parse_message_post_censor')) ? eval($hook) : null;
    if ($return != null) {
        return $return;
    }
    // Convert applicable characters to HTML entities
    $text = forum_htmlencode($text);
    $return = ($hook = get_hook('ps_parse_message_pre_split')) ? eval($hook) : null;
    if ($return != null) {
        return $return;
    }
    // If the message contains a code tag we have to split it up (text within [code][/code] shouldn't be touched)
    if (strpos($text, '[code]') !== false && strpos($text, '[/code]') !== false) {
        list($inside, $outside) = split_text($text, '[code]', '[/code]', $errors);
        $text = implode("", $outside);
    }
    $return = ($hook = get_hook('ps_parse_message_post_split')) ? eval($hook) : null;
    if ($return != null) {
        return $return;
    }
    if ($forum_config['p_message_bbcode'] == '1' && strpos($text, '[') !== false && strpos($text, ']') !== false) {
        $text = do_bbcode($text);
    }
    if ($forum_config['o_smilies'] == '1' && $forum_user['show_smilies'] == '1' && $hide_smilies == '0') {
        $text = do_smilies($text);
    }
    $return = ($hook = get_hook('ps_parse_message_bbcode')) ? eval($hook) : null;
    if ($return != null) {
        return $return;
    }
    // Deal with newlines, tabs and multiple spaces
    $pattern = array("\n", "\t", '  ', '  ');
    $replace = array('<br />', '&nbsp; &nbsp; ', '&nbsp; ', ' &nbsp;');
    $text = str_replace($pattern, $replace, $text);
    $return = ($hook = get_hook('ps_parse_message_pre_merge')) ? eval($hook) : null;
    if ($return != null) {
        return $return;
    }
    // If we split up the message before we have to concatenate it together again (code tags)
    if (isset($inside)) {
        $outside = explode("", $text);
        $text = '';
        $num_tokens = count($outside);
        for ($i = 0; $i < $num_tokens; ++$i) {
            $text .= $outside[$i];
            if (isset($inside[$i])) {
                $text .= '</p><div class="codebox"><pre><code>' . forum_trim($inside[$i], "\n\r") . '</code></pre></div><p>';
            }
        }
    }
    $return = ($hook = get_hook('ps_parse_message_post_merge')) ? eval($hook) : null;
    if ($return != null) {
        return $return;
    }
    // Add paragraph tag around post, but make sure there are no empty paragraphs
    $text = preg_replace('#<br />\\s*?<br />((\\s*<br />)*)#i', "</p>\$1<p>", $text);
    $text = str_replace('<p><br />', '<p>', $text);
    $text = str_replace('<p></p>', '', '<p>' . $text . '</p>');
    $return = ($hook = get_hook('ps_parse_message_end')) ? eval($hook) : null;
    if ($return != null) {
        return $return;
    }
    return $text;
}
Example #6
0
 public function get_quote_message($qid, $tid)
 {
     global $lang_common;
     $select_get_quote_message = array('poster', 'message');
     $quote = DB::for_table('posts')->select_many($select_get_quote_message)->where('id', $qid)->where('topic_id', $tid)->find_one();
     if (!$quote) {
         message($lang_common['Bad request'], '404');
     }
     // If the message contains a code tag we have to split it up (text within [code][/code] shouldn't be touched)
     if (strpos($quote['message'], '[code]') !== false && strpos($quote['message'], '[/code]') !== false) {
         list($inside, $outside) = split_text($quote['message'], '[code]', '[/code]');
         $quote['message'] = implode("", $outside);
     }
     // Remove [img] tags from quoted message
     $quote['message'] = preg_replace('%\\[img(?:=(?:[^\\[]*?))?\\]((ht|f)tps?://)([^\\s<"]*?)\\[/img\\]%U', '\\1\\3', $quote['message']);
     // If we split up the message before we have to concatenate it together again (code tags)
     if (isset($inside)) {
         $outside = explode("", $quote['message']);
         $quote['message'] = '';
         $num_tokens = count($outside);
         for ($i = 0; $i < $num_tokens; ++$i) {
             $quote['message'] .= $outside[$i];
             if (isset($inside[$i])) {
                 $quote['message'] .= '[code]' . $inside[$i] . '[/code]';
             }
         }
         unset($inside);
     }
     if ($this->config['o_censoring'] == '1') {
         $quote['message'] = censor_words($quote['message']);
     }
     $quote['message'] = feather_escape($quote['message']);
     if ($this->config['p_message_bbcode'] == '1') {
         // Sanitize username for inclusion within QUOTE BBCode attribute.
         //   This is a bit tricky because a username can have any "special"
         //   characters such as backslash \ square brackets [] and quotes '".
         if (preg_match('/[[\\]\'"]/S', $quote['poster'])) {
             // Check if we need to quote it.
             // Post has special chars. Escape escapes and quotes then wrap in quotes.
             if (strpos($quote['poster'], '"') !== false && strpos($quote['poster'], '\'') === false) {
                 // If there are double quotes but no single quotes, use single quotes,
                 $quote['poster'] = feather_escape(str_replace('\\', '\\\\', $quote['poster']));
                 $quote['poster'] = '\'' . $quote['poster'] . '#' . $qid . '\'';
             } else {
                 // otherwise use double quotes.
                 $quote['poster'] = feather_escape(str_replace(array('\\', '"'), array('\\\\', '\\"'), $quote['poster']));
                 $quote['poster'] = '"' . $quote['poster'] . '#' . $qid . '"';
             }
         } else {
             $quote['poster'] = $quote['poster'] . '#' . $qid;
         }
         $quote = '[quote=' . $quote['poster'] . ']' . $quote['message'] . '[/quote]' . "\n";
     } else {
         $quote = '> ' . $quote['poster'] . ' ' . $lang_common['wrote'] . "\n\n" . '> ' . $quote['message'] . "\n";
     }
     return $quote;
 }
Example #7
0
function parse_message($text, $hide_smilies, $post_list = array())
{
    global $pun_config, $pun_user, $lang_common, $lang_topic;
    if ($pun_config['o_censoring'] == '1') {
        $text = censor_words($text);
    }
    // If the message contains a code tag we have to split it up (text within [code][/code] shouldn't be touched)
    if (strpos($text, '[code]') !== false && strpos($text, '[/code]') !== false) {
        list($inside, $outside) = split_text($text, '[code]', '[/code]');
        // Active links between < > or [ ]
        if ($pun_config['o_make_links'] == '1') {
            $outside = array_map('do_clickable', $outside);
        }
        // Convert applicable characters to HTML entities
        $inside = array_map('pun_htmlspecialchars', $inside);
        $outside = array_map('pun_htmlspecialchars', $outside);
        // Implode non code text in one string for next parsing
        $outside = array_map('ltrim', $outside);
        $text = implode('<">', $outside);
    } else {
        // Active links between < > or [ ]
        if ($pun_config['o_make_links'] == '1') {
            $text = do_clickable($text);
        }
        // Convert applicable characters to HTML entities
        $text = pun_htmlspecialchars($text);
    }
    if ($pun_config['o_smilies'] == '1' && $pun_user['show_smilies'] == '1' && $hide_smilies == '0') {
        $text = do_smilies($text);
    }
    if ($pun_config['p_message_bbcode'] == '1' && strpos($text, '[') !== false && strpos($text, ']') !== false) {
        $text = do_bbcode($text, false, $post_list);
        $text = do_video($text);
    }
    // Deal with newlines, tabs and multiple spaces
    $pattern = array("\n", "\t", '    ', '  ', '<p><br />');
    $replace = array('<br />', '&nbsp; &nbsp; ', '&nbsp; ', ' &nbsp;', '<p>');
    $text = str_replace($pattern, $replace, $text);
    // If we split up the message before we have to concatenate it together again (code tags)
    if (isset($inside)) {
        $outside = explode('<">', $text);
        $text = '';
        $num_tokens = count($outside);
        for ($i = 0; $i < $num_tokens; ++$i) {
            $text .= $outside[$i];
            if (isset($inside[$i])) {
                $num_lines = (substr_count($inside[$i], "\n") + 2) * 1.4;
                $height_str = $num_lines > 35 ? '35em' : $num_lines . 'em';
                $text .= '</p><div class="codebox"><div class="incqbox"><h4>' . $lang_common['Code'] . ':</h4><div class="scrollbox" style="height: ' . $height_str . '"><pre>' . $inside[$i] . '</pre></div></div></div><p>';
            }
        }
    }
    // Add paragraph tag around post, but make sure there are no empty paragraphs
    $text = str_replace('<p></p>', '', '<p>' . $text . '</p>');
    // Add new line in the HTML code
    $pattern = array('<br />', '<p>', '</p>', '<pre>', '</pre>', '<ul', '<ol', '<li>', '</ul>', '</ol>');
    $replace = array("<br />\n", "<p>\n", "\n</p>", "<pre>\n", "\n</pre>", "\n<ul", "\n<ol", "\n<li>", "\n</ul>\n", "\n</ol>\n");
    $text = str_replace($pattern, $replace, $text);
    return $text;
}
/**
 * NOT USED IN CORE - Used for update process - Replace bbcode in text by html tag
 * used in update_065_068.php
 *
 * @param $string string: initial string
 *
 * @return formatted string
**/
function rembo($string)
{
    // Adapte de PunBB
    //Copyright (C)  Rickard Andersson (rickard@punbb.org)
    // If the message contains a code tag we have to split it up
    // (text within [code][/code] shouldn't be touched)
    if (strpos($string, '[code]') !== false && strpos($string, '[/code]') !== false) {
        list($inside, $outside) = split_text($string, '[code]', '[/code]');
        $outside = array_map('trim', $outside);
        $string = implode('<">', $outside);
    }
    $pattern = array('#\\[b\\](.*?)\\[/b\\]#s', '#\\[i\\](.*?)\\[/i\\]#s', '#\\[u\\](.*?)\\[/u\\]#s', '#\\[s\\](.*?)\\[/s\\]#s', '#\\[c\\](.*?)\\[/c\\]#s', '#\\[g\\](.*?)\\[/g\\]#s', '#\\[email\\](.*?)\\[/email\\]#', '#\\[email=(.*?)\\](.*?)\\[/email\\]#', '#\\[color=([a-zA-Z]*|\\#?[0-9a-fA-F]{6})](.*?)\\[/color\\]#s');
    $replace = array('<span class="b">$1</span>', '<em>$1</em>', '<span class="souligne">$1</span>', '<span class="barre">$1</span>', '<div class="center">$1</div>', '<big>$1</big>', '<a href="mailto:$1">$1</a>', '<a href="mailto:$1">$2</a>', '<span style="color: $1">$2</span>');
    // This thing takes a while! :)
    $string = preg_replace($pattern, $replace, $string);
    $string = clicurl($string);
    $string = autop($string);
    // If we split up the message before we have to concatenate it together again (code tags)
    if (isset($inside)) {
        $outside = explode('<">', $string);
        $string = '';
        $num_tokens = count($outside);
        for ($i = 0; $i < $num_tokens; ++$i) {
            $string .= $outside[$i];
            if (isset($inside[$i])) {
                $string .= '<br><br><div class="spaced"><table class="code center"><tr>' . '<td class="punquote"><span class="b">Code:</span><br><br><pre>' . trim($inside[$i]) . '</pre></td></tr></table></div>';
            }
        }
    }
    return $string;
}
Example #9
0
function parse_message($text, $hide_smilies)
{
    global $pun_config, $lang_common, $pun_user;
    if ($pun_config['o_censoring'] == '1') {
        $text = censor_words($text);
    }
    // Convert applicable characters to HTML entities
    $text = pun_htmlspecialchars($text);
    // If the message contains a code tag we have to split it up (text within [code][/code] shouldn't be touched)
    if (strpos($text, '[code]') !== false && strpos($text, '[/code]') !== false) {
        list($inside, $outside) = split_text($text, '[code]', '[/code]', $errors);
        $text = implode("", $outside);
    }
    if ($pun_config['p_message_bbcode'] == '1' && strpos($text, '[') !== false && strpos($text, ']') !== false) {
        $text = do_bbcode($text);
    }
    if ($pun_config['o_smilies'] == '1' && $pun_user['show_smilies'] == '1' && $hide_smilies == '0') {
        $text = do_smilies($text);
    }
    // Deal with newlines, tabs and multiple spaces
    $pattern = array("\n", "\t", '  ', '  ');
    $replace = array('<br />', '&#160; &#160; ', '&#160; ', ' &#160;');
    $text = str_replace($pattern, $replace, $text);
    // If we split up the message before we have to concatenate it together again (code tags)
    if (isset($inside)) {
        $outside = explode("", $text);
        $text = '';
        $num_tokens = count($outside);
        for ($i = 0; $i < $num_tokens; ++$i) {
            $text .= $outside[$i];
            if (isset($inside[$i])) {
                $num_lines = substr_count($inside[$i], "\n");
                $text .= '</p><div class="codebox"><pre' . ($num_lines > 28 ? ' class="vscroll"' : '') . '><code>' . pun_trim($inside[$i], "\n\r") . '</code></pre></div><p>';
            }
        }
    }
    // Add paragraph tag around post, but make sure there are no empty paragraphs
    $text = preg_replace('#<br />\\s*?<br />((\\s*<br />)*)#i', "</p>\$1<p>", $text);
    $text = str_replace('<p><br />', '<p>', $text);
    $text = str_replace('<p></p>', '', '<p>' . $text . '</p>');
    return $text;
}
Example #10
0
function parse_message($text, $hide_smilies, $post = 0)
{
    global $pun_config, $lang_common, $pun_user;
    $wap = pathinfo(dirname($_SERVER['PHP_SELF']), PATHINFO_FILENAME) == 'wap';
    if ($pun_config['o_censoring'] == 1) {
        $text = censor_words($text);
    }
    // Convert applicable characters to HTML entities
    $text = pun_htmlspecialchars($text);
    // hide
    if (preg_match_all('#\\[hide(=(&quot;|"|\'|)+(\\d+)){0,1}\\](.*)\\[/hide\\]#sU', $text, $matches)) {
        foreach ($matches[0] as $key => $value) {
            $match = array($value, $matches[1][$key], $matches[2][$key], $matches[3][$key], $matches[4][$key]);
            $text = do_hide($text, $post, $match);
        }
    }
    // If the message contains a code tag we have to split it up (text within [code][/code] shouldn't be touched)
    $inside = array();
    if (strpos($text, '[code]') !== false && strpos($text, '[/code]') !== false) {
        list($inside, $outside) = split_text($text, '[code]', '[/code]');
        $outside = array_map('ltrim', $outside);
        $text = implode('<">', $outside);
    }
    if ($pun_config['o_make_links'] == 1) {
        $text = do_clickable($text);
    }
    if ($pun_config['o_smilies'] == 1 && $pun_user['show_smilies'] == 1 && !$hide_smilies) {
        $text = do_smilies($text);
    }
    if ($pun_config['p_message_bbcode'] == 1 && strpos($text, '[') !== false && strpos($text, ']') !== false) {
        $text = do_bbcode($text);
        if ($pun_config['p_message_img_tag'] == 1) {
            $text = preg_replace_callback('#\\[img\\]((ht|f)tps?://)([^\\s<"]*?)\\[/img\\]#', '_replace_img', $text);
            $text = preg_replace_callback('#\\[imgr\\]((ht|f)tps?://)([^\\s<"]*?)\\[/imgr\\]#', '_replace_img_right', $text);
            $text = preg_replace_callback('#\\[imgl\\]((ht|f)tps?://)([^\\s<"]*?)\\[/imgl\\]#', '_replace_img_left', $text);
        }
    }
    // Deal with newlines, tabs and multiple spaces
    $text = str_replace(array("\n", "\t", '  ', '  ', "\r"), array('<br />', '&#160; &#160; ', '&#160; ', ' &#160;', ''), $text);
    // AJAX POLL MOD BEGIN
    $text = preg_replace_callback('#\\[poll\\]([0-9]*?)\\[/poll\\]#', '_replace_poll', $text);
    // AJAX POLL MOD END
    // If we split up the message before we have to concatenate it together again (code tags)
    $text = do_code($text, $inside);
    // Add paragraph tag around post, but make sure there are no empty paragraphs
    if ($wap) {
        $text = str_replace('<p></p>', '', $text);
    } else {
        $text = str_replace('<p></p>', '', '<p>' . $text . '</p>');
    }
    return $text;
}
 function __construct($underscore)
 {
     if (count($underscore->xpath('leafValues')) != 1) {
         trigger_error("Ill-formed Weak Classifer: no leaf values: " . $underscore->__toString());
     }
     $this->internals = array();
     $this->leaves = array();
     $pieces = split_text((string) $underscore->xpath('leafValues')[0]);
     while (count($pieces) > 0) {
         $this->leaves[] = array_shift($pieces) + 0;
     }
     if (count($underscore->xpath('internalNodes')) != 1) {
         tigger_error("Ill-formed Weak Classifier: no internal nodes: " . $underscore->__toString());
     }
     $pieces = split_text((string) $underscore->xpath('internalNodes')[0]);
     while (count($pieces) > 0) {
         $this->internals[] = new InternalNode($pieces);
     }
 }
Example #12
0
function parse_script_queries($sql)
{
    $sql = preg_replace("/\\\\/", '', $sql);
    $queries = split_text($sql, array(';'), array("'", "`"));
    $queries = array_map("trim", $queries);
    $queries = array_filter($queries);
    $queries = array_merge($queries);
    // condense the indexes
    return $queries;
}
Example #13
0
 function dr_parse($input_text, $is_quote = false)
 {
     global $dr_active_post;
     srand($dr_active_post);
     // If the message contains a code tag we have to split it up (text within [code][/code] shouldn't be touched)
     if (strpos($input_text, '[code]') !== false && strpos($input_text, '[/code]') !== false) {
         list($inside_code, $outside_code) = split_text($input_text, '[code]', '[/code]', $errors);
         $input_text = implode("", $outside_code);
     } else {
         $outside_code = array($input_text);
     }
     foreach ($outside_code as $key => $text) {
         // If the message contains a dice tag we have to split it up (text within [dice][/dice] shouldn't be touched)
         if (strpos($text, '[dice') !== false && strpos($text, '[/dice]') !== false) {
             list($inside, $outside) = split_text($text, '[dice', '[/dice]', $errors);
         }
         if (isset($inside)) {
             $num_tokens = count($inside);
             for ($i = 0; $i < $num_tokens; $i++) {
                 // Reset options
                 $allow_critics = false;
                 $dice_params = array();
                 $block = $inside[$i];
                 if (strpos($block, ']') !== false) {
                     $params = substr($block, 0, strpos($block, ']'));
                     $block = substr($block, strpos($block, ']') + 1);
                     // Search for params
                     if (strpos($params, '=') !== false) {
                         // Clean params
                         $params = preg_replace('/(&quot;|"|\'|=|]| )?/', '', $params);
                         $dice_params = explode(',', $params);
                         // Search for options
                         if (array_search('critic', $dice_params) !== false) {
                             $allow_critics = true;
                         }
                     }
                 }
                 $is_quote = stripos($block, '>') !== false or stripos($block, '<') !== false;
                 if ($is_quote) {
                     // We must convert some simbols, only when when we come for quoting
                     $block = str_replace(array('>', '<'), array('&gt;', '&lt;'), $block);
                 }
                 // Split in expressions
                 $expressions = dr_split_expression($block);
                 $block = '( ' . $block . ' ) : ';
                 if (isset($expressions)) {
                     $to_eval = '';
                     foreach ($expressions as $expression) {
                         $tmp_result = dr_parse_expression($expression, $allow_critics);
                         $block .= $tmp_result;
                         $to_eval .= $tmp_result;
                     }
                     // We must convert some simbols for evalue them
                     $to_eval = str_replace(array("&gt;", "&lt;"), array(">", "<"), $to_eval);
                     // We can only have one operator of any type
                     if (substr_count($to_eval, '<=') > 1 or substr_count($to_eval, '>=') > 1 or substr_count($to_eval, '<') > 1 or substr_count($to_eval, '>') > 1 or substr_count($to_eval, '=') > 1) {
                         $block .= " : " . DR_INVALID_EXPRESSION;
                     } else {
                         // Evaluate the result
                         if (strpos($to_eval, '<') !== false or strpos($to_eval, '>') !== false or strpos($to_eval, '=') !== false) {
                             eval('$block .= " : " . ((' . $to_eval . ') === true ? DR_TRUE_STRING : DR_FALSE_STRING );');
                         } else {
                             eval('$block .= " = " . (' . $to_eval . ');');
                         }
                     }
                 } else {
                     $block .= DR_INVALID_EXPRESSION;
                 }
                 if ($is_quote) {
                     // We must restore some simbols, only when when we come for quoting
                     $block = str_replace(array('&gt;', '&lt;'), array('>', '<'), $block);
                 }
                 if (count($dice_params) > 0) {
                     $dice_params = '="' . implode(',', $dice_params) . '"]';
                 } else {
                     $dice_params = ']';
                 }
                 $inside[$i] = $dice_params . $block;
             }
         }
         // If we split up the message before we have to concatenate it together again (dice tags)
         if (isset($inside)) {
             $text = '';
             $num_tokens = count($outside);
             for ($j = 0; $j < $num_tokens; $j++) {
                 $text .= $outside[$j];
                 if (isset($inside[$j])) {
                     $text .= '[dice' . $inside[$j] . '[/dice]';
                 }
             }
         }
         $outside_code[$key] = $text;
     }
     // If we split up the message before we have to concatenate it together again (code tags)
     if (isset($inside_code)) {
         $outside_code = explode("", $input_text);
         $input_text = '';
         $num_tokens = count($outside_code);
         for ($i = 0; $i < $num_tokens; ++$i) {
             $input_text .= $outside_code[$i];
             if (isset($inside_code[$i])) {
                 $input_text .= '[code]' . $inside_code[$i] . '[/code]';
             }
         }
     } else {
         $input_text = $outside_code[0];
     }
     return $input_text;
 }