Example #1
0
 /**
  * Parses a string/message with the MyBB Parser Class
  * Refers to: /inc/class_parser.php
  *
  * @param string $message The String which shall be parsed
  * @param array $options Options the parser can accept: filter_badwords, allow_html, allow_mycode, me_username, allow_smilies, nl2br, 
  * @return string Parsed string
  */
 function parseString($message, $options = array())
 {
     // Set base URL for parsing smilies
     $base_url = $this->mybb->settings['bburl'];
     if ($base_url != "") {
         if (my_substr($base_url, my_strlen($base_url) - 1) != "/") {
             $base_url = $base_url . "/";
         }
     }
     $message = $this->plugins->run_hooks("parse_message_start", $message);
     // Get rid of cartridge returns for they are the workings of the devil
     $message = str_replace("\r", "", $message);
     // Filter bad words if requested.
     if ($options['filter_badwords']) {
         $message = $this->parser->parse_badwords($message);
     }
     if ($options['allow_html'] != 1) {
         $message = $this->parser->parse_html($message);
     } else {
         while (preg_match("#<script(.*)>(.*)</script(.*)>#is", $message)) {
             $message = preg_replace("#<script(.*)>(.*)</script(.*)>#is", "&lt;script\$1&gt;\$2&lt;/script\$3&gt;", $message);
         }
         // Remove these completely
         $message = preg_replace("#\\s*<base[^>]*>\\s*#is", "", $message);
         $message = preg_replace("#\\s*<meta[^>]*>\\s*#is", "", $message);
         $message = str_replace(array('<?php', '<!--', '-->', '?>', "<br />\n", "<br>\n"), array('&lt;?php', '&lt;!--', '--&gt;', '?&gt;', "\n", "\n"), $message);
     }
     // If MyCode needs to be replaced, first filter out [code] and [php] tags.
     if ($options['allow_mycode']) {
         // First we split up the contents of code and php tags to ensure they're not parsed.
         preg_match_all("#\\[(code|php)\\](.*?)\\[/\\1\\](\r\n?|\n?)#si", $message, $code_matches, PREG_SET_ORDER);
         $message = preg_replace("#\\[(code|php)\\](.*?)\\[/\\1\\](\r\n?|\n?)#si", "<mybb-code>\n", $message);
     }
     // Always fix bad Javascript in the message.
     $message = $this->parser->fix_javascript($message);
     // Replace "me" code and slaps if we have a username
     if ($options['me_username']) {
         $message = preg_replace('#(>|^|\\r|\\n)/me ([^\\r\\n<]*)#i', "\\1<span style=\"color: red;\">* {$options['me_username']} \\2</span>", $message);
         $message = preg_replace('#(>|^|\\r|\\n)/slap ([^\\r\\n<]*)#i', "\\1<span style=\"color: red;\">* {$options['me_username']} {$this->lang->slaps} \\2 {$this->lang->with_trout}</span>", $message);
     }
     // If we can, parse smilies
     if ($options['allow_smilies']) {
         $message = $this->parser->parse_smilies($message, $options['allow_html']);
     }
     // Replace MyCode if requested.
     if ($options['allow_mycode']) {
         $message = $this->parser->parse_mycode($message, $options);
     }
     // Run plugin hooks
     $message = $this->plugins->run_hooks("parse_message", $message);
     if ($options['allow_mycode']) {
         // Now that we're done, if we split up any code tags, parse them and glue it all back together
         if (count($code_matches) > 0) {
             foreach ($code_matches as $text) {
                 // Fix up HTML inside the code tags so it is clean
                 if ($options['allow_html'] != 0) {
                     $text[2] = $this->parser->parse_html($text[2]);
                 }
                 if (my_strtolower($text[1]) == "code") {
                     $code = $this->parser->mycode_parse_code($text[2]);
                 } elseif (my_strtolower($text[1]) == "php") {
                     $code = $this->parser->mycode_parse_php($text[2]);
                 }
                 $message = preg_replace("#\\<mybb-code>\n?#", $code, $message, 1);
             }
         }
     }
     if ($options['nl2br'] !== 0) {
         $message = nl2br($message);
         // Fix up new lines and block level elements
         $message = preg_replace("#(</?(?:html|head|body|div|p|form|table|thead|tbody|tfoot|tr|td|th|ul|ol|li|div|p|blockquote|cite|hr)[^>]*>)\\s*<br />#i", "\$1", $message);
         $message = preg_replace("#(&nbsp;)+(</?(?:html|head|body|div|p|form|table|thead|tbody|tfoot|tr|td|th|ul|ol|li|div|p|blockquote|cite|hr)[^>]*>)#i", "\$2", $message);
     }
     $message = my_wordwrap($message);
     $message = $this->plugins->run_hooks("parse_message_end", $message);
     return $message;
 }
Example #2
0
 /**
  * Parses a message with the specified options.
  *
  * @param string The message to be parsed.
  * @param array Array of yes/no options - allow_html,filter_badwords,allow_mycode,allow_smilies,nl2br,me_username,filter_cdata.
  * @return string The parsed message.
  */
 function parse_message($message, $options = array())
 {
     global $plugins, $mybb;
     // Set base URL for parsing smilies
     $this->base_url = $mybb->settings['bburl'];
     if ($this->base_url != "") {
         if (my_substr($this->base_url, my_strlen($this->base_url) - 1) != "/") {
             $this->base_url = $this->base_url . "/";
         }
     }
     // Set the options
     $this->options = $options;
     $message = $plugins->run_hooks("parse_message_start", $message);
     // Get rid of cartridge returns for they are the workings of the devil
     $message = str_replace("\r", "", $message);
     // Filter bad words if requested.
     if ($this->options['filter_badwords']) {
         $message = $this->parse_badwords($message);
     }
     // Filter CDATA tags if requested (syndication.php).
     if (!empty($this->options['filter_cdata'])) {
         $message = $this->parse_cdata($message);
     }
     if ($this->options['allow_html'] != 1) {
         $message = $this->parse_html($message);
     } else {
         while (preg_match("#<s(cript|tyle)(.*)>(.*)</s(cript|tyle)(.*)>#is", $message)) {
             $message = preg_replace("#<s(cript|tyle)(.*)>(.*)</s(cript|tyle)(.*)>#is", "&lt;s\$1\$2&gt;\$3&lt;/s\$4\$5&gt;", $message);
         }
         $find = array('<?php', '<!--', '-->', '?>', "<br />\n", "<br>\n");
         $replace = array('&lt;?php', '&lt;!--', '--&gt;', '?&gt;', "\n", "\n");
         $message = str_replace($find, $replace, $message);
     }
     // If MyCode needs to be replaced, first filter out [code] and [php] tags.
     if ($this->options['allow_mycode']) {
         preg_match_all("#\\[(code|php)\\](.*?)\\[/\\1\\](\r\n?|\n?)#si", $message, $code_matches, PREG_SET_ORDER);
         $message = preg_replace("#\\[(code|php)\\](.*?)\\[/\\1\\](\r\n?|\n?)#si", "<mybb-code>\n", $message);
     }
     // Always fix bad Javascript in the message.
     $message = $this->fix_javascript($message);
     // Replace "me" code and slaps if we have a username
     if ($this->options['me_username']) {
         global $lang;
         $message = preg_replace('#(>|^|\\r|\\n)/me ([^\\r\\n<]*)#i', "\\1<span style=\"color: red;\">* {$this->options['me_username']} \\2</span>", $message);
         $message = preg_replace('#(>|^|\\r|\\n)/slap ([^\\r\\n<]*)#i', "\\1<span style=\"color: red;\">* {$this->options['me_username']} {$lang->slaps} \\2 {$lang->with_trout}</span>", $message);
     }
     // If we can, parse smilies
     if ($this->options['allow_smilies']) {
         $message = $this->parse_smilies($message, $this->options['allow_html']);
     }
     // Replace MyCode if requested.
     if ($this->options['allow_mycode']) {
         $message = $this->parse_mycode($message, $this->options);
     }
     // Parse Highlights
     if (!empty($this->options['highlight'])) {
         $message = $this->highlight_message($message, $this->options['highlight']);
     }
     // Run plugin hooks
     $message = $plugins->run_hooks("parse_message", $message);
     if ($this->options['allow_mycode']) {
         // Now that we're done, if we split up any code tags, parse them and glue it all back together
         if (count($code_matches) > 0) {
             foreach ($code_matches as $text) {
                 // Fix up HTML inside the code tags so it is clean
                 if ($options['allow_html'] != 0) {
                     $text[2] = $this->parse_html($text[2]);
                 }
                 if (my_strtolower($text[1]) == "code") {
                     $code = $this->mycode_parse_code($text[2]);
                 } elseif (my_strtolower($text[1]) == "php") {
                     $code = $this->mycode_parse_php($text[2]);
                 }
                 $message = preg_replace("#\\<mybb-code>\n?#", $code, $message, 1);
             }
         }
     }
     // Replace meta and base tags in our post - these are > dangerous <
     if ($this->options['allow_html']) {
         $message = preg_replace_callback("#<((m[^a])|(b[^diloru>])|(s[^aemptu>]))(\\s*[^>]*)>#si", create_function('$matches', 'return htmlspecialchars_uni($matches[0]);'), $message);
     }
     if (!isset($options['nl2br']) || $options['nl2br'] != 0) {
         $message = nl2br($message);
         // Fix up new lines and block level elements
         $message = preg_replace("#(</?(?:html|head|body|div|p|form|table|thead|tbody|tfoot|tr|td|th|ul|ol|li|div|p|blockquote|cite|hr)[^>]*>)\\s*<br />#i", "\$1", $message);
         $message = preg_replace("#(&nbsp;)+(</?(?:html|head|body|div|p|form|table|thead|tbody|tfoot|tr|td|th|ul|ol|li|div|p|blockquote|cite|hr)[^>]*>)#i", "\$2", $message);
     }
     $message = my_wordwrap($message);
     $message = $plugins->run_hooks("parse_message_end", $message);
     return $message;
 }
 /**
  * Parses a message with the specified options.
  *
  * @param string The message to be parsed.
  * @param array Array of yes/no options - allow_html,filter_badwords,allow_mycode,allow_smilies,nl2br,me_username.
  * @return string The parsed message.
  */
 function parse_message($message, $options = array())
 {
     global $plugins, $mybb, $lang;
     // Set base URL for parsing smilies
     $this->base_url = $mybb->settings['bburl'];
     if ($this->base_url != "") {
         if (my_substr($this->base_url, my_strlen($this->base_url) - 1) != "/") {
             $this->base_url = $this->base_url . "/";
         }
     }
     // Set the options
     $this->options = $options;
     // Get rid of cartridge returns for they are the workings of the devil
     $message = str_replace("\r", "", $message);
     // Filter bad words if requested.
     if ($options['filter_badwords'] != "no") {
         $message = $this->parse_badwords($message);
     }
     if ($options['allow_mycode'] != "no") {
         $message = str_replace("", '', $message);
         preg_match_all("#\\[(c|cpp|vb|sql|bat|java|js|html|xml|php|ini|code)(=[0-9]+?|)\\](.*?)\\[/\\1\\](\r\n?|\n?)#si", $message, $coolcode_matches, PREG_SET_ORDER);
         $message = preg_replace("#\\[(c|cpp|vb|sql|bat|java|js|html|xml|php|ini|code)(=[0-9]+?|)\\](.*?)\\[/\\1\\](\r\n?|\n?)#si", "", $message);
     }
     if ($options['allow_html'] != "yes") {
         $message = $this->parse_html($message);
     } else {
         // Strip out any script tags if HTML is enabled
         if ($options['allow_html'] == "yes") {
             while (preg_match("#<script(.*)>(.*)</script(.*)>#is", $message)) {
                 $message = preg_replace("#<script(.*)>(.*)</script(.*)>#is", "&lt;script\$1&gt;\$2&lt;/script\$3&gt;", $message);
             }
             // Remove these completely
             $message = preg_replace("#\\s*<base[^>]*>\\s*#is", "", $message);
             $message = preg_replace("#\\s*<meta[^>]*>\\s*#is", "", $message);
             $message = str_replace(array('<?php', '<!--', '-->', '?>', "<br />\n", "<br>\n"), array('&lt;?php', '&lt;!--', '--&gt;', '?&gt;', "\n", "\n"), $message);
         }
     }
     // Always fix bad Javascript in the message.
     $message = $this->fix_javascript($message);
     // Replace "me" code and slaps if we have a username
     if ($options['me_username']) {
         $message = preg_replace('#(>|^|\\r|\\n)/me ([^\\r\\n<]*)#i', "\\1<span style=\"color: red;\">* {$options['me_username']} \\2</span>", $message);
         $message = preg_replace('#(>|^|\\r|\\n)/slap ([^\\r\\n<]*)#i', "\\1<span style=\"color: red;\">* {$options['me_username']} {$lang->slaps} \\2 {$lang->with_trout}</span>", $message);
     }
     // If we can, parse smilies
     if ($options['allow_smilies'] != "no") {
         $message = $this->parse_smilies($message, $options['allow_html']);
     }
     // Replace MyCode if requested.
     if ($options['allow_mycode'] != "no") {
         $message = $this->parse_mycode($message, $options);
     }
     // Run plugin hooks
     $message = $plugins->run_hooks("parse_message", $message);
     if ($options['nl2br'] != "no") {
         $message = nl2br($message);
         // Fix up new lines and block level elements
         $message = preg_replace("#(</?(?:html|head|body|form|div|p|table|thead|tbody|tfoot|tr|td|th|ul|ol|li|div|p)[^>]*>)\\s*<br />#i", "\$1", $message);
         $message = preg_replace("#(&nbsp;)+(</?(?:html|head|body|form|div|p|table|thead|tbody|tfoot|tr|td|th|ul|ol|li|div|p)[^>]*>)#i", "\$2", $message);
     }
     $message = my_wordwrap($message);
     coolcode_run($message, $coolcode_matches, $options['allow_mycode']);
     $message = $plugins->run_hooks("parse_message_end", $message);
     return $message;
 }
Example #4
0
function check_value($value)
{
    if ($value == '') {
        return '<i>no value</i>';
    }
    if (@is_bool($value)) {
        return $value ? 'TRUE' : 'FALSE';
    }
    if ($value === null) {
        return 'NULL';
    }
    if (@is_object($value)) {
        $value = (array) $value;
    }
    if (@is_array($value)) {
        @ob_start();
        print_r($value);
        $value = @ob_get_contents();
        @ob_end_clean();
    }
    return my_wordwrap((string) $value);
}