6 * @copyright (c) 2005 phpBB Group
7 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
14 if (!defined('IN_PHPBB'))
19 if (!class_exists('bbcode'))
21 include($phpbb_root_path . 'includes/bbcode.' . $phpEx);
26 * BBCODE first pass class (functions for parsing messages for db storage)
29 class bbcode_firstpass extends bbcode
32 var $warn_msg = array();
33 var $parsed_items = array();
38 function parse_bbcode()
47 $this->bbcode_bitfield = '';
48 $bitfield = new bitfield();
50 foreach ($this->bbcodes as $bbcode_name => $bbcode_data)
52 if (isset($bbcode_data['disabled']) && $bbcode_data['disabled'])
54 foreach ($bbcode_data['regexp'] as $regexp => $replacement)
56 if (preg_match($regexp, $this->message))
58 $this->warn_msg[] = sprintf($user->lang['UNAUTHORISED_BBCODE'] , '[' . $bbcode_name . ']');
65 foreach ($bbcode_data['regexp'] as $regexp => $replacement)
67 // The pattern gets compiled and cached by the PCRE extension,
68 // it should not demand recompilation
69 if (preg_match($regexp, $this->message))
71 $this->message = preg_replace($regexp, $replacement, $this->message);
72 $bitfield->set($bbcode_data['bbcode_id']);
78 $this->bbcode_bitfield = $bitfield->get_base64();
82 * Prepare some bbcodes for better parsing
84 function prepare_bbcodes()
86 // Ok, seems like users instead want the no-parsing of urls, smilies, etc. after and before and within quote tags being tagged as "not a bug".
87 // Fine by me ;) Will ease our live... but do not come back and cry at us, we won't hear you.
89 /* Add newline at the end and in front of each quote block to prevent parsing errors (urls, smilies, etc.)
90 if (strpos($this->message, '[quote') !== false && strpos($this->message, '[/quote]') !== false)
92 $this->message = str_replace("\r\n", "\n", $this->message);
94 // We strip newlines and spaces after and before quotes in quotes (trimming) and then add exactly one newline
95 $this->message = preg_replace('#\[quote(=".*?")?\]\s*(.*?)\s*\[/quote\]#siu', '[quote\1]' . "\n" . '\2' ."\n[/quote]", $this->message);
99 // Add other checks which needs to be placed before actually parsing anything (be it bbcodes, smilies, urls...)
103 * Init bbcode data for later parsing
105 function bbcode_init($allow_custom_bbcode = true)
109 // This array holds all bbcode data. BBCodes will be processed in this
110 // order, so it is important to keep [code] in first position and
111 // [quote] in second position.
112 // To parse multiline URL we enable dotall option setting only for URL text
113 // but not for link itself, thus [url][/url] is not affected.
114 $this->bbcodes = array(
115 'code' => array('bbcode_id' => 8, 'regexp' => array('#\[code(?:=([a-z]+))?\](.+\[/code\])#uise' => "\$this->bbcode_code('\$1', '\$2')")),
116 'quote' => array('bbcode_id' => 0, 'regexp' => array('#\[quote(?:="(.*?)")?\](.+)\[/quote\]#uise' => "\$this->bbcode_quote('\$0')")),
117 'attachment' => array('bbcode_id' => 12, 'regexp' => array('#\[attachment=([0-9]+)\](.*?)\[/attachment\]#uise' => "\$this->bbcode_attachment('\$1', '\$2')")),
118 'b' => array('bbcode_id' => 1, 'regexp' => array('#\[b\](.*?)\[/b\]#uise' => "\$this->bbcode_strong('\$1')")),
119 'i' => array('bbcode_id' => 2, 'regexp' => array('#\[i\](.*?)\[/i\]#uise' => "\$this->bbcode_italic('\$1')")),
120 'url' => array('bbcode_id' => 3, 'regexp' => array('#\[url(=(.*))?\](?(1)((?s).*(?-s))|(.*))\[/url\]#uiUe' => "\$this->validate_url('\$2', ('\$3') ? '\$3' : '\$4')")),
121 'img' => array('bbcode_id' => 4, 'regexp' => array('#\[img\](.*)\[/img\]#uiUe' => "\$this->bbcode_img('\$1')")),
122 'size' => array('bbcode_id' => 5, 'regexp' => array('#\[size=([\-\+]?\d+)\](.*?)\[/size\]#uise' => "\$this->bbcode_size('\$1', '\$2')")),
123 'color' => array('bbcode_id' => 6, 'regexp' => array('!\[color=(#[0-9a-f]{3}|#[0-9a-f]{6}|[a-z\-]+)\](.*?)\[/color\]!uise' => "\$this->bbcode_color('\$1', '\$2')")),
124 'u' => array('bbcode_id' => 7, 'regexp' => array('#\[u\](.*?)\[/u\]#uise' => "\$this->bbcode_underline('\$1')")),
125 'list' => array('bbcode_id' => 9, 'regexp' => array('#\[list(?:=(?:[a-z0-9]|disc|circle|square))?].*\[/list]#uise' => "\$this->bbcode_parse_list('\$0')")),
126 'email' => array('bbcode_id' => 10, 'regexp' => array('#\[email=?(.*?)?\](.*?)\[/email\]#uise' => "\$this->validate_email('\$1', '\$2')")),
127 'flash' => array('bbcode_id' => 11, 'regexp' => array('#\[flash=([0-9]+),([0-9]+)\](.*?)\[/flash\]#uie' => "\$this->bbcode_flash('\$1', '\$2', '\$3')"))
130 // Zero the parsed items array
131 $this->parsed_items = array();
133 foreach ($this->bbcodes as $tag => $bbcode_data)
135 $this->parsed_items[$tag] = 0;
138 if (!$allow_custom_bbcode)
143 if (!is_array($rowset))
149 FROM ' . BBCODES_TABLE;
150 $result = $db->sql_query($sql);
152 while ($row = $db->sql_fetchrow($result))
156 $db->sql_freeresult($result);
159 foreach ($rowset as $row)
161 $this->bbcodes[$row['bbcode_tag']] = array(
162 'bbcode_id' => (int) $row['bbcode_id'],
163 'regexp' => array($row['first_pass_match'] => str_replace('$uid', $this->bbcode_uid, $row['first_pass_replace']))
169 * Making some pre-checks for bbcodes as well as increasing the number of parsed items
171 function check_bbcode($bbcode, &$in)
173 // when using the /e modifier, preg_replace slashes double-quotes but does not
174 // seem to slash anything else
175 $in = str_replace("\r\n", "\n", str_replace('\"', '"', $in));
177 // Trimming here to make sure no empty bbcodes are parsed accidently
183 $this->parsed_items[$bbcode]++;
189 * Transform some characters in valid bbcodes
191 function bbcode_specialchars($text)
193 $str_from = array('<', '>', '[', ']', '.', ':');
194 $str_to = array('<', '>', '[', ']', '.', ':');
196 return str_replace($str_from, $str_to, $text);
202 function bbcode_size($stx, $in)
204 global $user, $config;
206 if (!$this->check_bbcode('size', $in))
211 if ($config['max_' . $this->mode . '_font_size'] && $config['max_' . $this->mode . '_font_size'] < $stx)
213 $this->warn_msg[] = sprintf($user->lang['MAX_FONT_SIZE_EXCEEDED'], $config['max_' . $this->mode . '_font_size']);
215 return '[size=' . $stx . ']' . $in . '[/size]';
218 // Do not allow size=0
221 return '[size=' . $stx . ']' . $in . '[/size]';
224 return '[size=' . $stx . ':' . $this->bbcode_uid . ']' . $in . '[/size:' . $this->bbcode_uid . ']';
230 function bbcode_color($stx, $in)
232 if (!$this->check_bbcode('color', $in))
237 return '[color=' . $stx . ':' . $this->bbcode_uid . ']' . $in . '[/color:' . $this->bbcode_uid . ']';
243 function bbcode_underline($in)
245 if (!$this->check_bbcode('u', $in))
250 return '[u:' . $this->bbcode_uid . ']' . $in . '[/u:' . $this->bbcode_uid . ']';
256 function bbcode_strong($in)
258 if (!$this->check_bbcode('b', $in))
263 return '[b:' . $this->bbcode_uid . ']' . $in . '[/b:' . $this->bbcode_uid . ']';
269 function bbcode_italic($in)
271 if (!$this->check_bbcode('i', $in))
276 return '[i:' . $this->bbcode_uid . ']' . $in . '[/i:' . $this->bbcode_uid . ']';
282 function bbcode_img($in)
284 global $user, $config;
286 if (!$this->check_bbcode('img', $in))
294 $in = str_replace(' ', '%20', $in);
297 if (!preg_match('#^' . get_preg_expression('url') . '$#i', $in) && !preg_match('#^' . get_preg_expression('www_url') . '$#i', $in))
299 return '[img]' . $in . '[/img]';
302 // Try to cope with a common user error... not specifying a protocol but only a subdomain
303 if (!preg_match('#^[a-z0-9]+://#i', $in))
305 $in = 'http://' . $in;
308 if ($config['max_' . $this->mode . '_img_height'] || $config['max_' . $this->mode . '_img_width'])
310 $stats = @getimagesize(htmlspecialchars_decode($in));
312 if ($stats === false)
315 $this->warn_msg[] = $user->lang['UNABLE_GET_IMAGE_SIZE'];
319 if ($config['max_' . $this->mode . '_img_height'] && $config['max_' . $this->mode . '_img_height'] < $stats[1])
322 $this->warn_msg[] = sprintf($user->lang['MAX_IMG_HEIGHT_EXCEEDED'], $config['max_' . $this->mode . '_img_height']);
325 if ($config['max_' . $this->mode . '_img_width'] && $config['max_' . $this->mode . '_img_width'] < $stats[0])
328 $this->warn_msg[] = sprintf($user->lang['MAX_IMG_WIDTH_EXCEEDED'], $config['max_' . $this->mode . '_img_width']);
333 if ($error || $this->path_in_domain($in))
335 return '[img]' . $in . '[/img]';
338 return '[img:' . $this->bbcode_uid . ']' . $this->bbcode_specialchars($in) . '[/img:' . $this->bbcode_uid . ']';
344 function bbcode_flash($width, $height, $in)
346 global $user, $config;
348 if (!$this->check_bbcode('flash', $in))
356 // Do not allow 0-sizes generally being entered
357 if ($width <= 0 || $height <= 0)
359 return '[flash=' . $width . ',' . $height . ']' . $in . '[/flash]';
362 $in = str_replace(' ', '%20', $in);
364 // Make sure $in is a URL.
365 if (!preg_match('#^' . get_preg_expression('url') . '$#i', $in) &&
366 !preg_match('#^' . get_preg_expression('www_url') . '$#i', $in))
368 return '[flash=' . $width . ',' . $height . ']' . $in . '[/flash]';
371 // Apply the same size checks on flash files as on images
372 if ($config['max_' . $this->mode . '_img_height'] || $config['max_' . $this->mode . '_img_width'])
374 if ($config['max_' . $this->mode . '_img_height'] && $config['max_' . $this->mode . '_img_height'] < $height)
377 $this->warn_msg[] = sprintf($user->lang['MAX_FLASH_HEIGHT_EXCEEDED'], $config['max_' . $this->mode . '_img_height']);
380 if ($config['max_' . $this->mode . '_img_width'] && $config['max_' . $this->mode . '_img_width'] < $width)
383 $this->warn_msg[] = sprintf($user->lang['MAX_FLASH_WIDTH_EXCEEDED'], $config['max_' . $this->mode . '_img_width']);
387 if ($error || $this->path_in_domain($in))
389 return '[flash=' . $width . ',' . $height . ']' . $in . '[/flash]';
392 return '[flash=' . $width . ',' . $height . ':' . $this->bbcode_uid . ']' . $this->bbcode_specialchars($in) . '[/flash:' . $this->bbcode_uid . ']';
396 * Parse inline attachments [ia]
398 function bbcode_attachment($stx, $in)
400 if (!$this->check_bbcode('attachment', $in))
405 return '[attachment=' . $stx . ':' . $this->bbcode_uid . ']<!-- ia' . $stx . ' -->' . trim($in) . '<!-- ia' . $stx . ' -->[/attachment:' . $this->bbcode_uid . ']';
409 * Parse code text from code tag
412 function bbcode_parse_code($stx, &$code)
414 switch (strtolower($stx))
418 $remove_tags = false;
420 $str_from = array('<', '>', '[', ']', '.', ':', ':');
421 $str_to = array('<', '>', '[', ']', '.', ':', ':');
422 $code = str_replace($str_from, $str_to, $code);
424 if (!preg_match('/\<\?.*?\?\>/is', $code))
427 $code = "<?php $code ?>";
430 $conf = array('highlight.bg', 'highlight.comment', 'highlight.default', 'highlight.html', 'highlight.keyword', 'highlight.string');
431 foreach ($conf as $ini_var)
433 @ini_set($ini_var, str_replace('highlight.', 'syntax', $ini_var));
436 // Because highlight_string is specialcharing the text (but we already did this before), we have to reverse this in order to get correct results
437 $code = htmlspecialchars_decode($code);
438 $code = highlight_string($code, true);
440 $str_from = array('<span style="color: ', '<font color="syntax', '</font>', '<code>', '</code>','[', ']', '.', ':');
441 $str_to = array('<span class="', '<span class="syntax', '</span>', '', '', '[', ']', '.', ':');
445 $str_from[] = '<span class="syntaxdefault"><?php </span>';
447 $str_from[] = '<span class="syntaxdefault"><?php ';
448 $str_to[] = '<span class="syntaxdefault">';
451 $code = str_replace($str_from, $str_to, $code);
452 $code = preg_replace('#^(<span class="[a-z_]+">)\n?(.*?)\n?(</span>)$#is', '$1$2$3', $code);
456 $code = preg_replace('#(<span class="[a-z]+">)?\?>(</span>)#', '$1 $2', $code);
459 $code = preg_replace('#^<span class="[a-z]+"><span class="([a-z]+)">(.*)</span></span>#s', '<span class="$1">$2</span>', $code);
460 $code = preg_replace('#(?:\s++| )*+</span>$#u', '</span>', $code);
462 // remove newline at the end
463 if (!empty($code) && substr($code, -1) == "\n")
465 $code = substr($code, 0, -1);
468 return "[code=$stx:" . $this->bbcode_uid . ']' . $code . '[/code:' . $this->bbcode_uid . ']';
472 return '[code:' . $this->bbcode_uid . ']' . $this->bbcode_specialchars($code) . '[/code:' . $this->bbcode_uid . ']';
479 * Expects the argument to start right after the opening [code] tag and to end with [/code]
481 function bbcode_code($stx, $in)
483 if (!$this->check_bbcode('code', $in))
488 // We remove the hardcoded elements from the code block here because it is not used in code blocks
489 // Having it here saves us one preg_replace per message containing [code] blocks
490 // Additionally, magic url parsing should go after parsing bbcodes, but for safety those are stripped out too...
491 $htm_match = get_preg_expression('bbcode_htm');
492 unset($htm_match[4], $htm_match[5]);
493 $htm_replace = array('\1', '\1', '\2', '\1');
495 $out = $code_block = '';
500 // Determine position and tag length of next code block
501 preg_match('#(.*?)(\[code(?:=([a-z]+))?\])(.+)#is', $in, $buffer);
502 $pos = (isset($buffer[1])) ? strlen($buffer[1]) : false;
503 $tag_length = (isset($buffer[2])) ? strlen($buffer[2]) : false;
505 // Determine position of ending code tag
506 $pos2 = stripos($in, '[/code]');
508 // Which is the next block, ending code or code block
509 if ($pos !== false && $pos < $pos2)
514 $out .= substr($in, 0, $pos);
515 $in = substr($in, $pos);
516 $stx = (isset($buffer[3])) ? $buffer[3] : '';
521 // Already opened block, just append to the current block
522 $code_block .= substr($in, 0, $pos) . ((isset($buffer[2])) ? $buffer[2] : '');
523 $in = substr($in, $pos);
526 $in = substr($in, $tag_length);
534 $code_block .= substr($in, 0, $pos2);
535 $code_block = preg_replace($htm_match, $htm_replace, $code_block);
537 // Parse this code block
538 $out .= $this->bbcode_parse_code($stx, $code_block);
544 // Close one open tag... add to the current code block
545 $code_block .= substr($in, 0, $pos2 + 7);
550 // end code without opening code... will be always outside code block
551 $out .= substr($in, 0, $pos2 + 7);
554 $in = substr($in, $pos2 + 7);
558 // if now $code_block has contents we need to parse the remaining code while removing the last closing tag to match up.
561 $code_block = substr($code_block, 0, -7);
562 $code_block = preg_replace($htm_match, $htm_replace, $code_block);
564 $out .= $this->bbcode_parse_code($stx, $code_block);
572 * Expects the argument to start with a tag
574 function bbcode_parse_list($in)
576 if (!$this->check_bbcode('list', $in))
581 // $tok holds characters to stop at. Since the string starts with a '[' we'll get everything up to the first ']' which should be the opening [list] tag
585 // First character is [
586 $in = substr($in, 1);
587 $list_end_tags = $item_end_tags = array();
593 for ($i = 0, $tok_len = strlen($tok); $i < $tok_len; ++$i)
595 $tmp_pos = strpos($in, $tok[$i]);
597 if ($tmp_pos !== false && $tmp_pos < $pos)
603 $buffer = substr($in, 0, $pos);
606 $in = substr($in, $pos + 1);
610 // if $tok is ']' the buffer holds a tag
611 if (strtolower($buffer) == '/list' && sizeof($list_end_tags))
613 // valid [/list] tag, check nesting so that we don't hit false positives
614 if (sizeof($item_end_tags) && sizeof($item_end_tags) >= sizeof($list_end_tags))
616 // current li tag has not been closed
617 $out = preg_replace('/\n?\[$/', '[', $out) . array_pop($item_end_tags) . '][';
620 $out .= array_pop($list_end_tags) . ']';
623 else if (preg_match('#^list(=[0-9a-z]+)?$#i', $buffer, $m))
625 // sub-list, add a closing tag
626 if (empty($m[1]) || preg_match('/^=(?:disc|square|circle)$/i', $m[1]))
628 array_push($list_end_tags, '/list:u:' . $this->bbcode_uid);
632 array_push($list_end_tags, '/list:o:' . $this->bbcode_uid);
634 $out .= 'list' . substr($buffer, 4) . ':' . $this->bbcode_uid . ']';
639 if (($buffer == '*' || substr($buffer, -2) == '[*') && sizeof($list_end_tags))
641 // the buffer holds a bullet tag and we have a [list] tag open
642 if (sizeof($item_end_tags) >= sizeof($list_end_tags))
644 if (substr($buffer, -2) == '[*')
646 $out .= substr($buffer, 0, -2) . '[';
648 // current li tag has not been closed
649 if (preg_match('/\n\[$/', $out, $m))
651 $out = preg_replace('/\n\[$/', '[', $out);
652 $buffer = array_pop($item_end_tags) . "]\n[*:" . $this->bbcode_uid;
656 $buffer = array_pop($item_end_tags) . '][*:' . $this->bbcode_uid;
661 $buffer = '*:' . $this->bbcode_uid;
664 $item_end_tags[] = '/*:m:' . $this->bbcode_uid;
666 else if ($buffer == '/*')
668 array_pop($item_end_tags);
669 $buffer = '/*:' . $this->bbcode_uid;
672 $out .= $buffer . $tok;
678 // Not within a tag, just add buffer to the return string
679 $out .= $buffer . $tok;
680 $tok = ($tok == '[') ? ']' : '[]';
685 // do we have some tags open? close them now
686 if (sizeof($item_end_tags))
688 $out .= '[' . implode('][', $item_end_tags) . ']';
690 if (sizeof($list_end_tags))
692 $out .= '[' . implode('][', $list_end_tags) . ']';
700 * Expects the argument to start with a tag
702 function bbcode_quote($in)
704 global $config, $user;
707 * If you change this code, make sure the cases described within the following reports are still working:
708 * #3572 - [quote="[test]test"]test [ test[/quote] - (correct: parsed)
709 * #14667 - [quote]test[/quote] test ] and [ test [quote]test[/quote] (correct: parsed)
710 * #14770 - [quote="["]test[/quote] (correct: parsed)
711 * [quote="[i]test[/i]"]test[/quote] (correct: parsed)
712 * [quote="[quote]test[/quote]"]test[/quote] (correct: parsed - Username displayed as [quote]test[/quote])
713 * #20735 - [quote]test[/[/b]quote] test [/quote][/quote] test - (correct: quoted: "test[/[/b]quote] test" / non-quoted: "[/quote] test" - also failed if layout distorted)
714 * #40565 - [quote="a"]a[/quote][quote="a]a[/quote] (correct: first quote tag parsed, second quote tag unparsed)
717 $in = str_replace("\r\n", "\n", str_replace('\"', '"', trim($in)));
724 // To let the parser not catch tokens within quote_username quotes we encode them before we start this...
725 $in = preg_replace('#quote="(.*?)"\]#ie', "'quote="' . str_replace(array('[', ']', '\\\"'), array('[', ']', '\"'), '\$1') . '"]'", $in);
730 $in = substr($in, 1);
731 $close_tags = $error_ary = array();
737 for ($i = 0, $tok_len = strlen($tok); $i < $tok_len; ++$i)
739 $tmp_pos = strpos($in, $tok[$i]);
740 if ($tmp_pos !== false && $tmp_pos < $pos)
746 $buffer .= substr($in, 0, $pos);
748 $in = substr($in, $pos + 1);
752 if (strtolower($buffer) == '/quote' && sizeof($close_tags) && substr($out, -1, 1) == '[')
754 // we have found a closing tag
755 $out .= array_pop($close_tags) . ']';
759 /* Add space at the end of the closing tag if not happened before to allow following urls/smilies to be parsed correctly
760 * Do not try to think for the user. :/ Do not parse urls/smilies if there is no space - is the same as with other bbcodes too.
761 * Also, we won't have any spaces within $in anyway, only adding up spaces -> #10982
762 if (!$in || $in[0] !== ' ')
767 else if (preg_match('#^quote(?:="(.*?)")?$#is', $buffer, $m) && substr($out, -1, 1) == '[')
769 $this->parsed_items['quote']++;
771 // the buffer holds a valid opening tag
772 if ($config['max_quote_depth'] && sizeof($close_tags) >= $config['max_quote_depth'])
774 // there are too many nested quotes
775 $error_ary['quote_depth'] = sprintf($user->lang['QUOTE_DEPTH_EXCEEDED'], $config['max_quote_depth']);
777 $out .= $buffer . $tok;
784 array_push($close_tags, '/quote:' . $this->bbcode_uid);
786 if (isset($m[1]) && $m[1])
788 $username = str_replace(array('[', ']'), array('[', ']'), $m[1]);
789 $username = preg_replace('#\[(?!b|i|u|color|url|email|/b|/i|/u|/color|/url|/email)#iU', '[$1', $username);
794 preg_match_all('#\[((?:/)?(?:[a-z]+))#i', $username, $tags);
795 foreach ($tags[1] as $tag)
799 $end_tags[] = '/' . $tag;
803 $end_tag = array_pop($end_tags);
804 $error = ($end_tag != $tag) ? true : false;
813 $out .= 'quote="' . $username . '":' . $this->bbcode_uid . ']';
817 $out .= 'quote:' . $this->bbcode_uid . ']';
823 else if (preg_match('#^quote="(.*?)#is', $buffer, $m))
825 // the buffer holds an invalid opening tag
830 $out .= $buffer . $tok;
838 * Old quote code working fine, but having errors listed in bug #3572
840 * $out .= $buffer . $tok;
841 * $tok = ($tok == '[') ? ']' : '[]';
845 $out .= $buffer . $tok;
849 // Search the text for the next tok... if an ending quote comes first, then change tok to []
850 $pos1 = stripos($in, '[/quote');
851 // If the token ] comes first, we change it to ]
852 $pos2 = strpos($in, ']');
853 // If the token [ comes first, we change it to [
854 $pos3 = strpos($in, '[');
856 if ($pos1 !== false && ($pos2 === false || $pos1 < $pos2) && ($pos3 === false || $pos1 < $pos3))
860 else if ($pos3 !== false && ($pos2 === false || $pos3 < $pos2))
880 if (sizeof($close_tags))
882 $out .= '[' . implode('][', $close_tags) . ']';
885 foreach ($error_ary as $error_msg)
887 $this->warn_msg[] = $error_msg;
896 function validate_email($var1, $var2)
898 $var1 = str_replace("\r\n", "\n", str_replace('\"', '"', trim($var1)));
899 $var2 = str_replace("\r\n", "\n", str_replace('\"', '"', trim($var2)));
902 $email = ($var1) ? $var1 : $var2;
906 if (!preg_match('/^' . get_preg_expression('email') . '$/i', $email))
913 return '[email' . (($var1) ? "=$var1" : '') . ']' . $var2 . '[/email]';
916 $this->parsed_items['email']++;
920 $retval = '[email=' . $this->bbcode_specialchars($email) . ':' . $this->bbcode_uid . ']' . $txt . '[/email:' . $this->bbcode_uid . ']';
924 $retval = '[email:' . $this->bbcode_uid . ']' . $this->bbcode_specialchars($email) . '[/email:' . $this->bbcode_uid . ']';
933 * @param string $var1 optional url parameter for url bbcode: [url(=$var1)]$var2[/url]
934 * @param string $var2 url bbcode content: [url(=$var1)]$var2[/url]
936 function validate_url($var1, $var2)
940 $var1 = str_replace("\r\n", "\n", str_replace('\"', '"', trim($var1)));
941 $var2 = str_replace("\r\n", "\n", str_replace('\"', '"', trim($var2)));
943 $url = ($var1) ? $var1 : $var2;
952 return '[url' . (($var1) ? '=' . $var1 : '') . ']' . $var2 . '[/url]';
957 $url = str_replace(' ', '%20', $url);
960 if (preg_match('#^' . get_preg_expression('url') . '$#i', $url) ||
961 preg_match('#^' . get_preg_expression('www_url') . '$#i', $url) ||
962 preg_match('#^' . preg_quote(generate_board_url(), '#') . get_preg_expression('relative_url') . '$#i', $url))
969 $this->parsed_items['url']++;
971 // if there is no scheme, then add http schema
972 if (!preg_match('#^[a-z][a-z\d+\-.]*:/{2}#i', $url))
974 $url = 'http://' . $url;
977 // Is this a link to somewhere inside this board? If so then remove the session id from the url
978 if (strpos($url, generate_board_url()) !== false && strpos($url, 'sid=') !== false)
980 $url = preg_replace('/(&|\?)sid=[0-9a-f]{32}&/', '\1', $url);
981 $url = preg_replace('/(&|\?)sid=[0-9a-f]{32}$/', '', $url);
982 $url = append_sid($url);
985 return ($var1) ? '[url=' . $this->bbcode_specialchars($url) . ':' . $this->bbcode_uid . ']' . $var2 . '[/url:' . $this->bbcode_uid . ']' : '[url:' . $this->bbcode_uid . ']' . $this->bbcode_specialchars($url) . '[/url:' . $this->bbcode_uid . ']';
988 return '[url' . (($var1) ? '=' . $var1 : '') . ']' . $var2 . '[/url]';
992 * Check if url is pointing to this domain/script_path/php-file
994 * @param string $url the url to check
995 * @return true if the url is pointing to this domain/script_path/php-file, false if not
999 function path_in_domain($url)
1001 global $config, $phpEx, $user;
1003 if ($config['force_server_vars'])
1005 $check_path = $config['script_path'];
1009 $check_path = ($user->page['root_script_path'] != '/') ? substr($user->page['root_script_path'], 0, -1) : '/';
1012 // Is the user trying to link to a php file in this domain and script path?
1013 if (strpos($url, ".{$phpEx}") !== false && strpos($url, $check_path) !== false)
1015 $server_name = $user->host;
1017 // Forcing server vars is the only way to specify/override the protocol
1018 if ($config['force_server_vars'] || !$server_name)
1020 $server_name = $config['server_name'];
1023 // Check again in correct order...
1024 $pos_ext = strpos($url, ".{$phpEx}");
1025 $pos_path = strpos($url, $check_path);
1026 $pos_domain = strpos($url, $server_name);
1028 if ($pos_domain !== false && $pos_path >= $pos_domain && $pos_ext >= $pos_path)
1030 // Ok, actually we allow linking to some files (this may be able to be extended in some way later...)
1031 if (strpos($url, '/' . $check_path . '/download/file.' . $phpEx) !== 0)
1045 * Main message parser for posting, pm, etc. takes raw message
1046 * and parses it for attachments, bbcode and smilies
1049 class parse_message extends bbcode_firstpass
1051 var $attachment_data = array();
1052 var $filename_data = array();
1054 // Helps ironing out user error
1055 var $message_status = '';
1057 var $allow_img_bbcode = true;
1058 var $allow_flash_bbcode = true;
1059 var $allow_quote_bbcode = true;
1060 var $allow_url_bbcode = true;
1065 * Init - give message here or manually
1067 function parse_message($message = '')
1070 $this->bbcode_uid = substr(base_convert(unique_id(), 16, 36), 0, BBCODE_UID_LEN);
1071 $this->message = $message;
1077 function parse($allow_bbcode, $allow_magic_url, $allow_smilies, $allow_img_bbcode = true, $allow_flash_bbcode = true, $allow_quote_bbcode = true, $allow_url_bbcode = true, $update_this_message = true, $mode = 'post')
1079 global $config, $db, $user;
1081 $this->mode = $mode;
1083 foreach (array('chars', 'smilies', 'urls', 'font_size', 'img_height', 'img_width') as $key)
1085 if (!isset($config['max_' . $mode . '_' . $key]))
1087 $config['max_' . $mode . '_' . $key] = 0;
1091 $this->allow_img_bbcode = $allow_img_bbcode;
1092 $this->allow_flash_bbcode = $allow_flash_bbcode;
1093 $this->allow_quote_bbcode = $allow_quote_bbcode;
1094 $this->allow_url_bbcode = $allow_url_bbcode;
1096 // If false, then $this->message won't be altered, the text will be returned instead.
1097 if (!$update_this_message)
1099 $tmp_message = $this->message;
1100 $return_message = &$this->message;
1103 if ($this->message_status == 'display')
1105 $this->decode_message();
1108 // Do some general 'cleanup' first before processing message,
1109 // e.g. remove excessive newlines(?), smilies(?)
1110 $match = array('#(script|about|applet|activex|chrome):#i');
1111 $replace = array("\\1:");
1112 $this->message = preg_replace($match, $replace, trim($this->message));
1114 // Store message length...
1115 $message_length = ($mode == 'post') ? utf8_strlen($this->message) : utf8_strlen(preg_replace('#\[\/?[a-z\*\+\-]+(=[\S]+)?\]#ius', ' ', $this->message));
1117 // Maximum message length check. 0 disables this check completely.
1118 if ((int) $config['max_' . $mode . '_chars'] > 0 && $message_length > (int) $config['max_' . $mode . '_chars'])
1120 $this->warn_msg[] = sprintf($user->lang['TOO_MANY_CHARS_' . strtoupper($mode)], $message_length, (int) $config['max_' . $mode . '_chars']);
1121 return (!$update_this_message) ? $return_message : $this->warn_msg;
1124 // Minimum message length check for post only
1125 if ($mode === 'post')
1127 if (!$message_length || $message_length < (int) $config['min_post_chars'])
1129 $this->warn_msg[] = (!$message_length) ? $user->lang['TOO_FEW_CHARS'] : sprintf($user->lang['TOO_FEW_CHARS_LIMIT'], $message_length, (int) $config['min_post_chars']);
1130 return (!$update_this_message) ? $return_message : $this->warn_msg;
1134 // Prepare BBcode (just prepares some tags for better parsing)
1135 if ($allow_bbcode && strpos($this->message, '[') !== false)
1137 $this->bbcode_init();
1138 $disallow = array('img', 'flash', 'quote', 'url');
1139 foreach ($disallow as $bool)
1141 if (!${'allow_' . $bool . '_bbcode'})
1143 $this->bbcodes[$bool]['disabled'] = true;
1147 $this->prepare_bbcodes();
1153 $this->smilies($config['max_' . $mode . '_smilies']);
1159 if ($allow_bbcode && strpos($this->message, '[') !== false)
1161 $this->parse_bbcode();
1162 $num_urls += $this->parsed_items['url'];
1166 if ($allow_magic_url)
1168 $this->magic_url(generate_board_url());
1170 if ($config['max_' . $mode . '_urls'])
1172 $num_urls += preg_match_all('#\<!-- ([lmwe]) --\>.*?\<!-- \1 --\>#', $this->message, $matches);
1176 // Check for "empty" message. We do not check here for maximum length, because bbcode, smilies, etc. can add to the length.
1177 // The maximum length check happened before any parsings.
1178 if ($mode === 'post' && utf8_clean_string($this->message) === '')
1180 $this->warn_msg[] = $user->lang['TOO_FEW_CHARS'];
1181 return (!$update_this_message) ? $return_message : $this->warn_msg;
1184 // Check number of links
1185 if ($config['max_' . $mode . '_urls'] && $num_urls > $config['max_' . $mode . '_urls'])
1187 $this->warn_msg[] = sprintf($user->lang['TOO_MANY_URLS'], $config['max_' . $mode . '_urls']);
1188 return (!$update_this_message) ? $return_message : $this->warn_msg;
1191 if (!$update_this_message)
1193 unset($this->message);
1194 $this->message = $tmp_message;
1195 return $return_message;
1198 $this->message_status = 'parsed';
1203 * Formatting text for display
1205 function format_display($allow_bbcode, $allow_magic_url, $allow_smilies, $update_this_message = true)
1207 // If false, then the parsed message get returned but internal message not processed.
1208 if (!$update_this_message)
1210 $tmp_message = $this->message;
1211 $return_message = &$this->message;
1214 if ($this->message_status == 'plain')
1216 // Force updating message - of course.
1217 $this->parse($allow_bbcode, $allow_magic_url, $allow_smilies, $this->allow_img_bbcode, $this->allow_flash_bbcode, $this->allow_quote_bbcode, $this->allow_url_bbcode, true);
1220 // Replace naughty words such as farty pants
1221 $this->message = censor_text($this->message);
1226 $this->bbcode_cache_init();
1228 // We are giving those parameters to be able to use the bbcode class on its own
1229 $this->bbcode_second_pass($this->message, $this->bbcode_uid);
1232 $this->message = bbcode_nl2br($this->message);
1233 $this->message = smiley_text($this->message, !$allow_smilies);
1235 if (!$update_this_message)
1237 unset($this->message);
1238 $this->message = $tmp_message;
1239 return $return_message;
1242 $this->message_status = 'display';
1247 * Decode message to be placed back into form box
1249 function decode_message($custom_bbcode_uid = '', $update_this_message = true)
1251 // If false, then the parsed message get returned but internal message not processed.
1252 if (!$update_this_message)
1254 $tmp_message = $this->message;
1255 $return_message = &$this->message;
1258 ($custom_bbcode_uid) ? decode_message($this->message, $custom_bbcode_uid) : decode_message($this->message, $this->bbcode_uid);
1260 if (!$update_this_message)
1262 unset($this->message);
1263 $this->message = $tmp_message;
1264 return $return_message;
1267 $this->message_status = 'plain';
1272 * Replace magic urls of form http://xxx.xxx., www.xxx. and xxx@xxx.xxx.
1273 * Cuts down displayed size of link if over 50 chars, turns absolute links
1274 * into relative versions when the server/script path matches the link
1276 function magic_url($server_url)
1278 // We use the global make_clickable function
1279 $this->message = make_clickable($this->message, $server_url);
1285 function smilies($max_smilies = 0)
1291 // See if the static arrays have already been filled on an earlier invocation
1292 if (!is_array($match))
1294 $match = $replace = array();
1296 // NOTE: obtain_* function? chaching the table contents?
1298 // For now setting the ttl to 10 minutes
1299 switch ($db->sql_layer)
1305 FROM ' . SMILIES_TABLE . '
1306 ORDER BY LEN(code) DESC';
1311 FROM ' . SMILIES_TABLE . '
1312 ORDER BY CHAR_LENGTH(code) DESC';
1315 // LENGTH supported by MySQL, IBM DB2, Oracle and Access for sure...
1318 FROM ' . SMILIES_TABLE . '
1319 ORDER BY LENGTH(code) DESC';
1322 $result = $db->sql_query($sql, 600);
1324 while ($row = $db->sql_fetchrow($result))
1326 if (empty($row['code']))
1332 $match[] = preg_quote($row['code'], '#');
1333 $replace[] = '<!-- s' . $row['code'] . ' --><img src="{SMILIES_PATH}/' . $row['smiley_url'] . '" alt="' . $row['code'] . '" title="' . $row['emotion'] . '" /><!-- s' . $row['code'] . ' -->';
1335 $db->sql_freeresult($result);
1342 // 'u' modifier has been added to correctly parse smilies within unicode strings
1343 // For details: http://tracker.phpbb.com/browse/PHPBB3-10117
1344 $num_matches = preg_match_all('#(?<=^|[\n .])(?:' . implode('|', $match) . ')(?![^<>]*>)#u', $this->message, $matches);
1347 if ($num_matches !== false && $num_matches > $max_smilies)
1349 $this->warn_msg[] = sprintf($user->lang['TOO_MANY_SMILIES'], $max_smilies);
1354 // Make sure the delimiter # is added in front and at the end of every element within $match
1355 // 'u' modifier has been added to correctly parse smilies within unicode strings
1356 // For details: http://tracker.phpbb.com/browse/PHPBB3-10117
1358 $this->message = trim(preg_replace(explode(chr(0), '#(?<=^|[\n .])' . implode('(?![^<>]*>)#u' . chr(0) . '#(?<=^|[\n .])', $match) . '(?![^<>]*>)#u'), $replace, $this->message));
1365 function parse_attachments($form_name, $mode, $forum_id, $submit, $preview, $refresh, $is_message = false)
1367 global $config, $auth, $user, $phpbb_root_path, $phpEx, $db;
1371 $num_attachments = sizeof($this->attachment_data);
1372 $this->filename_data['filecomment'] = utf8_normalize_nfc(request_var('filecomment', '', true));
1373 $upload_file = (isset($_FILES[$form_name]) && $_FILES[$form_name]['name'] != 'none' && trim($_FILES[$form_name]['name'])) ? true : false;
1375 $add_file = (isset($_POST['add_file'])) ? true : false;
1376 $delete_file = (isset($_POST['delete_file'])) ? true : false;
1378 // First of all adjust comments if changed
1379 $actual_comment_list = utf8_normalize_nfc(request_var('comment_list', array(''), true));
1381 foreach ($actual_comment_list as $comment_key => $comment)
1383 if (!isset($this->attachment_data[$comment_key]))
1388 if ($this->attachment_data[$comment_key]['attach_comment'] != $actual_comment_list[$comment_key])
1390 $this->attachment_data[$comment_key]['attach_comment'] = $actual_comment_list[$comment_key];
1395 $cfg['max_attachments'] = ($is_message) ? $config['max_attachments_pm'] : $config['max_attachments'];
1396 $forum_id = ($is_message) ? 0 : $forum_id;
1398 if ($submit && in_array($mode, array('post', 'reply', 'quote', 'edit')) && $upload_file)
1400 if ($num_attachments < $cfg['max_attachments'] || $auth->acl_get('a_') || $auth->acl_get('m_', $forum_id))
1402 $filedata = upload_attachment($form_name, $forum_id, false, '', $is_message);
1403 $error = $filedata['error'];
1405 if ($filedata['post_attach'] && !sizeof($error))
1408 'physical_filename' => $filedata['physical_filename'],
1409 'attach_comment' => $this->filename_data['filecomment'],
1410 'real_filename' => $filedata['real_filename'],
1411 'extension' => $filedata['extension'],
1412 'mimetype' => $filedata['mimetype'],
1413 'filesize' => $filedata['filesize'],
1414 'filetime' => $filedata['filetime'],
1415 'thumbnail' => $filedata['thumbnail'],
1417 'in_message' => ($is_message) ? 1 : 0,
1418 'poster_id' => $user->data['user_id'],
1421 $db->sql_query('INSERT INTO ' . ATTACHMENTS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary));
1424 'attach_id' => $db->sql_nextid(),
1426 'real_filename' => $filedata['real_filename'],
1427 'attach_comment'=> $this->filename_data['filecomment'],
1430 $this->attachment_data = array_merge(array(0 => $new_entry), $this->attachment_data);
1431 $this->message = preg_replace('#\[attachment=([0-9]+)\](.*?)\[\/attachment\]#e', "'[attachment='.(\\1 + 1).']\\2[/attachment]'", $this->message);
1433 $this->filename_data['filecomment'] = '';
1435 // This Variable is set to false here, because Attachments are entered into the
1436 // Database in two modes, one if the id_list is 0 and the second one if post_attach is true
1437 // Since post_attach is automatically switched to true if an Attachment got added to the filesystem,
1438 // but we are assigning an id of 0 here, we have to reset the post_attach variable to false.
1440 // This is very relevant, because it could happen that the post got not submitted, but we do not
1441 // know this circumstance here. We could be at the posting page or we could be redirected to the entered
1443 $filedata['post_attach'] = false;
1448 $error[] = sprintf($user->lang['TOO_MANY_ATTACHMENTS'], $cfg['max_attachments']);
1452 if ($preview || $refresh || sizeof($error))
1454 // Perform actions on temporary attachments
1457 include_once($phpbb_root_path . 'includes/functions_admin.' . $phpEx);
1459 $index = array_keys(request_var('delete_file', array(0 => 0)));
1460 $index = (!empty($index)) ? $index[0] : false;
1462 if ($index !== false && !empty($this->attachment_data[$index]))
1464 // delete selected attachment
1465 if ($this->attachment_data[$index]['is_orphan'])
1467 $sql = 'SELECT attach_id, physical_filename, thumbnail
1468 FROM ' . ATTACHMENTS_TABLE . '
1469 WHERE attach_id = ' . (int) $this->attachment_data[$index]['attach_id'] . '
1471 AND poster_id = ' . $user->data['user_id'];
1472 $result = $db->sql_query($sql);
1473 $row = $db->sql_fetchrow($result);
1474 $db->sql_freeresult($result);
1478 phpbb_unlink($row['physical_filename'], 'file');
1480 if ($row['thumbnail'])
1482 phpbb_unlink($row['physical_filename'], 'thumbnail');
1485 $db->sql_query('DELETE FROM ' . ATTACHMENTS_TABLE . ' WHERE attach_id = ' . (int) $this->attachment_data[$index]['attach_id']);
1490 delete_attachments('attach', array(intval($this->attachment_data[$index]['attach_id'])));
1493 unset($this->attachment_data[$index]);
1494 $this->message = preg_replace('#\[attachment=([0-9]+)\](.*?)\[\/attachment\]#e', "(\\1 == \$index) ? '' : ((\\1 > \$index) ? '[attachment=' . (\\1 - 1) . ']\\2[/attachment]' : '\\0')", $this->message);
1497 $this->attachment_data = array_values($this->attachment_data);
1500 else if (($add_file || $preview) && $upload_file)
1502 if ($num_attachments < $cfg['max_attachments'] || $auth->acl_gets('m_', 'a_', $forum_id))
1504 $filedata = upload_attachment($form_name, $forum_id, false, '', $is_message);
1505 $error = array_merge($error, $filedata['error']);
1507 if (!sizeof($error))
1510 'physical_filename' => $filedata['physical_filename'],
1511 'attach_comment' => $this->filename_data['filecomment'],
1512 'real_filename' => $filedata['real_filename'],
1513 'extension' => $filedata['extension'],
1514 'mimetype' => $filedata['mimetype'],
1515 'filesize' => $filedata['filesize'],
1516 'filetime' => $filedata['filetime'],
1517 'thumbnail' => $filedata['thumbnail'],
1519 'in_message' => ($is_message) ? 1 : 0,
1520 'poster_id' => $user->data['user_id'],
1523 $db->sql_query('INSERT INTO ' . ATTACHMENTS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary));
1526 'attach_id' => $db->sql_nextid(),
1528 'real_filename' => $filedata['real_filename'],
1529 'attach_comment'=> $this->filename_data['filecomment'],
1532 $this->attachment_data = array_merge(array(0 => $new_entry), $this->attachment_data);
1533 $this->message = preg_replace('#\[attachment=([0-9]+)\](.*?)\[\/attachment\]#e', "'[attachment='.(\\1 + 1).']\\2[/attachment]'", $this->message);
1534 $this->filename_data['filecomment'] = '';
1539 $error[] = sprintf($user->lang['TOO_MANY_ATTACHMENTS'], $cfg['max_attachments']);
1544 foreach ($error as $error_msg)
1546 $this->warn_msg[] = $error_msg;
1551 * Get Attachment Data
1553 function get_submitted_attachment_data($check_user_id = false)
1555 global $user, $db, $phpbb_root_path, $phpEx, $config;
1557 $this->filename_data['filecomment'] = utf8_normalize_nfc(request_var('filecomment', '', true));
1558 $attachment_data = (isset($_POST['attachment_data'])) ? $_POST['attachment_data'] : array();
1559 $this->attachment_data = array();
1561 $check_user_id = ($check_user_id === false) ? $user->data['user_id'] : $check_user_id;
1563 if (!sizeof($attachment_data))
1568 $not_orphan = $orphan = array();
1570 foreach ($attachment_data as $pos => $var_ary)
1572 if ($var_ary['is_orphan'])
1574 $orphan[(int) $var_ary['attach_id']] = $pos;
1578 $not_orphan[(int) $var_ary['attach_id']] = $pos;
1582 // Regenerate already posted attachments
1583 if (sizeof($not_orphan))
1585 // Get the attachment data, based on the poster id...
1586 $sql = 'SELECT attach_id, is_orphan, real_filename, attach_comment
1587 FROM ' . ATTACHMENTS_TABLE . '
1588 WHERE ' . $db->sql_in_set('attach_id', array_keys($not_orphan)) . '
1589 AND poster_id = ' . $check_user_id;
1590 $result = $db->sql_query($sql);
1592 while ($row = $db->sql_fetchrow($result))
1594 $pos = $not_orphan[$row['attach_id']];
1595 $this->attachment_data[$pos] = $row;
1596 set_var($this->attachment_data[$pos]['attach_comment'], $_POST['attachment_data'][$pos]['attach_comment'], 'string', true);
1598 unset($not_orphan[$row['attach_id']]);
1600 $db->sql_freeresult($result);
1603 if (sizeof($not_orphan))
1605 trigger_error('NO_ACCESS_ATTACHMENT', E_USER_ERROR);
1608 // Regenerate newly uploaded attachments
1609 if (sizeof($orphan))
1611 $sql = 'SELECT attach_id, is_orphan, real_filename, attach_comment
1612 FROM ' . ATTACHMENTS_TABLE . '
1613 WHERE ' . $db->sql_in_set('attach_id', array_keys($orphan)) . '
1614 AND poster_id = ' . $user->data['user_id'] . '
1616 $result = $db->sql_query($sql);
1618 while ($row = $db->sql_fetchrow($result))
1620 $pos = $orphan[$row['attach_id']];
1621 $this->attachment_data[$pos] = $row;
1622 set_var($this->attachment_data[$pos]['attach_comment'], $_POST['attachment_data'][$pos]['attach_comment'], 'string', true);
1624 unset($orphan[$row['attach_id']]);
1626 $db->sql_freeresult($result);
1629 if (sizeof($orphan))
1631 trigger_error('NO_ACCESS_ATTACHMENT', E_USER_ERROR);
1634 ksort($this->attachment_data);
1640 function parse_poll(&$poll)
1642 global $auth, $user, $config;
1644 $poll_max_options = $poll['poll_max_options'];
1646 // Parse Poll Option text ;)
1647 $tmp_message = $this->message;
1648 $this->message = $poll['poll_option_text'];
1649 $bbcode_bitfield = $this->bbcode_bitfield;
1651 $poll['poll_option_text'] = $this->parse($poll['enable_bbcode'], ($config['allow_post_links']) ? $poll['enable_urls'] : false, $poll['enable_smilies'], $poll['img_status'], false, false, $config['allow_post_links'], false, 'poll');
1653 $bbcode_bitfield = base64_encode(base64_decode($bbcode_bitfield) | base64_decode($this->bbcode_bitfield));
1654 $this->message = $tmp_message;
1657 $tmp_message = $this->message;
1658 $this->message = $poll['poll_title'];
1659 $this->bbcode_bitfield = $bbcode_bitfield;
1661 $poll['poll_options'] = explode("\n", trim($poll['poll_option_text']));
1662 $poll['poll_options_size'] = sizeof($poll['poll_options']);
1664 if (!$poll['poll_title'] && $poll['poll_options_size'])
1666 $this->warn_msg[] = $user->lang['NO_POLL_TITLE'];
1670 if (utf8_strlen(preg_replace('#\[\/?[a-z\*\+\-]+(=[\S]+)?\]#ius', ' ', $this->message)) > 100)
1672 $this->warn_msg[] = $user->lang['POLL_TITLE_TOO_LONG'];
1674 $poll['poll_title'] = $this->parse($poll['enable_bbcode'], ($config['allow_post_links']) ? $poll['enable_urls'] : false, $poll['enable_smilies'], $poll['img_status'], false, false, $config['allow_post_links'], false, 'poll');
1675 if (strlen($poll['poll_title']) > 255)
1677 $this->warn_msg[] = $user->lang['POLL_TITLE_COMP_TOO_LONG'];
1681 $this->bbcode_bitfield = base64_encode(base64_decode($bbcode_bitfield) | base64_decode($this->bbcode_bitfield));
1682 $this->message = $tmp_message;
1683 unset($tmp_message);
1685 if (sizeof($poll['poll_options']) == 1)
1687 $this->warn_msg[] = $user->lang['TOO_FEW_POLL_OPTIONS'];
1689 else if ($poll['poll_options_size'] > (int) $config['max_poll_options'])
1691 $this->warn_msg[] = $user->lang['TOO_MANY_POLL_OPTIONS'];
1693 else if ($poll_max_options > $poll['poll_options_size'])
1695 $this->warn_msg[] = $user->lang['TOO_MANY_USER_OPTIONS'];
1698 $poll['poll_max_options'] = ($poll['poll_max_options'] < 1) ? 1 : (($poll['poll_max_options'] > $config['max_poll_options']) ? $config['max_poll_options'] : $poll['poll_max_options']);