root / branches / phpBB-3_0_0 / phpBB / includes / message_parser.php
History | View | Annotate | Download (48.8 kB)
| 1 | 3572 | acydburn | <?php
|
|---|---|---|---|
| 2 | 7736 | acydburn | /**
|
| 3 | 5114 | acydburn | * |
| 4 | 5114 | acydburn | * @package phpBB3 |
| 5 | 5114 | acydburn | * @version $Id$ |
| 6 | 7736 | acydburn | * @copyright (c) 2005 phpBB Group |
| 7 | 7736 | acydburn | * @license http://opensource.org/licenses/gpl-license.php GNU Public License |
| 8 | 5114 | acydburn | * |
| 9 | 5114 | acydburn | */ |
| 10 | 3572 | acydburn | |
| 11 | 5114 | acydburn | /**
|
| 12 | 5114 | acydburn | * @ignore |
| 13 | 5114 | acydburn | */ |
| 14 | 4978 | acydburn | if (!defined('IN_PHPBB')) |
| 15 | 4978 | acydburn | {
|
| 16 | 4978 | acydburn | exit;
|
| 17 | 4978 | acydburn | } |
| 18 | 4978 | acydburn | |
| 19 | 4978 | acydburn | if (!class_exists('bbcode')) |
| 20 | 3572 | acydburn | {
|
| 21 | 4978 | acydburn | include($phpbb_root_path . 'includes/bbcode.' . $phpEx); |
| 22 | 4978 | acydburn | } |
| 23 | 4978 | acydburn | |
| 24 | 5114 | acydburn | /**
|
| 25 | 5114 | acydburn | * BBCODE FIRSTPASS |
| 26 | 5114 | acydburn | * BBCODE first pass class (functions for parsing messages for db storage) |
| 27 | 6058 | acydburn | * @package phpBB3 |
| 28 | 5114 | acydburn | */ |
| 29 | 4978 | acydburn | class bbcode_firstpass extends bbcode |
| 30 | 4978 | acydburn | {
|
| 31 | 4045 | ludovic_arnaud | var $message = ''; |
| 32 | 4045 | ludovic_arnaud | var $warn_msg = array(); |
| 33 | 5023 | acydburn | var $parsed_items = array(); |
| 34 | 4045 | ludovic_arnaud | |
| 35 | 6043 | acydburn | /**
|
| 36 | 6043 | acydburn | * Parse BBCode |
| 37 | 6043 | acydburn | */ |
| 38 | 4978 | acydburn | function parse_bbcode() |
| 39 | 3572 | acydburn | {
|
| 40 | 4045 | ludovic_arnaud | if (!$this->bbcodes) |
| 41 | 4045 | ludovic_arnaud | {
|
| 42 | 4045 | ludovic_arnaud | $this->bbcode_init();
|
| 43 | 4045 | ludovic_arnaud | } |
| 44 | 4045 | ludovic_arnaud | |
| 45 | 4045 | ludovic_arnaud | global $user; |
| 46 | 3812 | ludovic_arnaud | |
| 47 | 6209 | davidmj | $this->bbcode_bitfield = ''; |
| 48 | 6209 | davidmj | $bitfield = new bitfield(); |
| 49 | 6209 | davidmj | |
| 50 | 4045 | ludovic_arnaud | foreach ($this->bbcodes as $bbcode_name => $bbcode_data) |
| 51 | 3812 | ludovic_arnaud | {
|
| 52 | 4961 | acydburn | if (isset($bbcode_data['disabled']) && $bbcode_data['disabled']) |
| 53 | 3812 | ludovic_arnaud | {
|
| 54 | 4045 | ludovic_arnaud | foreach ($bbcode_data['regexp'] as $regexp => $replacement) |
| 55 | 4045 | ludovic_arnaud | {
|
| 56 | 4045 | ludovic_arnaud | if (preg_match($regexp, $this->message)) |
| 57 | 4045 | ludovic_arnaud | {
|
| 58 | 6805 | davidmj | $this->warn_msg[] = sprintf($user->lang['UNAUTHORISED_BBCODE'] , '[' . $bbcode_name . ']'); |
| 59 | 4045 | ludovic_arnaud | continue;
|
| 60 | 4045 | ludovic_arnaud | } |
| 61 | 4045 | ludovic_arnaud | } |
| 62 | 3860 | ludovic_arnaud | } |
| 63 | 4045 | ludovic_arnaud | else
|
| 64 | 4045 | ludovic_arnaud | {
|
| 65 | 4045 | ludovic_arnaud | foreach ($bbcode_data['regexp'] as $regexp => $replacement) |
| 66 | 4045 | ludovic_arnaud | {
|
| 67 | 6294 | davidmj | // The pattern gets compiled and cached by the PCRE extension,
|
| 68 | 6294 | davidmj | // it should not demand recompilation
|
| 69 | 6294 | davidmj | if (preg_match($regexp, $this->message)) |
| 70 | 6292 | davidmj | {
|
| 71 | 6294 | davidmj | $this->message = preg_replace($regexp, $replacement, $this->message); |
| 72 | 6294 | davidmj | $bitfield->set($bbcode_data['bbcode_id']); |
| 73 | 6292 | davidmj | } |
| 74 | 4045 | ludovic_arnaud | } |
| 75 | 4045 | ludovic_arnaud | } |
| 76 | 3812 | ludovic_arnaud | } |
| 77 | 6209 | davidmj | |
| 78 | 6263 | davidmj | $this->bbcode_bitfield = $bitfield->get_base64(); |
| 79 | 3572 | acydburn | } |
| 80 | 3572 | acydburn | |
| 81 | 6043 | acydburn | /**
|
| 82 | 6114 | acydburn | * Prepare some bbcodes for better parsing |
| 83 | 6114 | acydburn | */ |
| 84 | 6114 | acydburn | function prepare_bbcodes() |
| 85 | 6114 | acydburn | {
|
| 86 | 7634 | acydburn | // 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 | 7634 | acydburn | // Fine by me ;) Will ease our live... but do not come back and cry at us, we won't hear you.
|
| 88 | 7634 | acydburn | |
| 89 | 7634 | acydburn | /* Add newline at the end and in front of each quote block to prevent parsing errors (urls, smilies, etc.)
|
| 90 | 6804 | davidmj | if (strpos($this->message, '[quote') !== false && strpos($this->message, '[/quote]') !== false) |
| 91 | 6114 | acydburn | {
|
| 92 | 6603 | acydburn | $this->message = str_replace("\r\n", "\n", $this->message);
|
| 93 | 6114 | acydburn | |
| 94 | 6804 | davidmj | // We strip newlines and spaces after and before quotes in quotes (trimming) and then add exactly one newline |
| 95 | 6804 | davidmj | $this->message = preg_replace('#\[quote(=".*?")?\]\s*(.*?)\s*\[/quote\]#siu', '[quote\1]' . "\n" . '\2' ."\n[/quote]", $this->message);
|
| 96 | 6114 | acydburn | } |
| 97 | 7634 | acydburn | */ |
| 98 | 6114 | acydburn | |
| 99 | 6114 | acydburn | // Add other checks which needs to be placed before actually parsing anything (be it bbcodes, smilies, urls...)
|
| 100 | 6114 | acydburn | } |
| 101 | 6114 | acydburn | |
| 102 | 6114 | acydburn | /**
|
| 103 | 6043 | acydburn | * Init bbcode data for later parsing |
| 104 | 6043 | acydburn | */ |
| 105 | 11196 | git-gate | function bbcode_init($allow_custom_bbcode = true) |
| 106 | 3812 | ludovic_arnaud | {
|
| 107 | 3939 | ludovic_arnaud | static $rowset; |
| 108 | 3939 | ludovic_arnaud | |
| 109 | 4532 | ludovic_arnaud | // This array holds all bbcode data. BBCodes will be processed in this
|
| 110 | 4532 | ludovic_arnaud | // order, so it is important to keep [code] in first position and
|
| 111 | 4532 | ludovic_arnaud | // [quote] in second position.
|
| 112 | 11196 | git-gate | // To parse multiline URL we enable dotall option setting only for URL text
|
| 113 | 11196 | git-gate | // but not for link itself, thus [url][/url] is not affected.
|
| 114 | 4045 | ludovic_arnaud | $this->bbcodes = array( |
| 115 | 11103 | git-gate | 'code' => array('bbcode_id' => 8, 'regexp' => array('#\[code(?:=([a-z]+))?\](.+\[/code\])#uise' => "\$this->bbcode_code('\$1', '\$2')")), |
| 116 | 11103 | git-gate | 'quote' => array('bbcode_id' => 0, 'regexp' => array('#\[quote(?:="(.*?)")?\](.+)\[/quote\]#uise' => "\$this->bbcode_quote('\$0')")), |
| 117 | 11103 | git-gate | 'attachment' => array('bbcode_id' => 12, 'regexp' => array('#\[attachment=([0-9]+)\](.*?)\[/attachment\]#uise' => "\$this->bbcode_attachment('\$1', '\$2')")), |
| 118 | 11103 | git-gate | 'b' => array('bbcode_id' => 1, 'regexp' => array('#\[b\](.*?)\[/b\]#uise' => "\$this->bbcode_strong('\$1')")), |
| 119 | 11103 | git-gate | 'i' => array('bbcode_id' => 2, 'regexp' => array('#\[i\](.*?)\[/i\]#uise' => "\$this->bbcode_italic('\$1')")), |
| 120 | 11196 | git-gate | 'url' => array('bbcode_id' => 3, 'regexp' => array('#\[url(=(.*))?\](?(1)((?s).*(?-s))|(.*))\[/url\]#uiUe' => "\$this->validate_url('\$2', ('\$3') ? '\$3' : '\$4')")), |
| 121 | 11103 | git-gate | 'img' => array('bbcode_id' => 4, 'regexp' => array('#\[img\](.*)\[/img\]#uiUe' => "\$this->bbcode_img('\$1')")), |
| 122 | 11103 | git-gate | 'size' => array('bbcode_id' => 5, 'regexp' => array('#\[size=([\-\+]?\d+)\](.*?)\[/size\]#uise' => "\$this->bbcode_size('\$1', '\$2')")), |
| 123 | 11103 | git-gate | '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 | 11103 | git-gate | 'u' => array('bbcode_id' => 7, 'regexp' => array('#\[u\](.*?)\[/u\]#uise' => "\$this->bbcode_underline('\$1')")), |
| 125 | 11103 | git-gate | 'list' => array('bbcode_id' => 9, 'regexp' => array('#\[list(?:=(?:[a-z0-9]|disc|circle|square))?].*\[/list]#uise' => "\$this->bbcode_parse_list('\$0')")), |
| 126 | 11103 | git-gate | 'email' => array('bbcode_id' => 10, 'regexp' => array('#\[email=?(.*?)?\](.*?)\[/email\]#uise' => "\$this->validate_email('\$1', '\$2')")), |
| 127 | 11103 | git-gate | 'flash' => array('bbcode_id' => 11, 'regexp' => array('#\[flash=([0-9]+),([0-9]+)\](.*?)\[/flash\]#uie' => "\$this->bbcode_flash('\$1', '\$2', '\$3')")) |
| 128 | 3812 | ludovic_arnaud | ); |
| 129 | 3812 | ludovic_arnaud | |
| 130 | 5603 | acydburn | // Zero the parsed items array
|
| 131 | 5603 | acydburn | $this->parsed_items = array(); |
| 132 | 5023 | acydburn | |
| 133 | 5603 | acydburn | foreach ($this->bbcodes as $tag => $bbcode_data) |
| 134 | 5603 | acydburn | {
|
| 135 | 5603 | acydburn | $this->parsed_items[$tag] = 0; |
| 136 | 5603 | acydburn | } |
| 137 | 5603 | acydburn | |
| 138 | 11196 | git-gate | if (!$allow_custom_bbcode) |
| 139 | 11196 | git-gate | {
|
| 140 | 11196 | git-gate | return;
|
| 141 | 11196 | git-gate | } |
| 142 | 11196 | git-gate | |
| 143 | 5026 | bartvb | if (!is_array($rowset)) |
| 144 | 3812 | ludovic_arnaud | {
|
| 145 | 3939 | ludovic_arnaud | global $db; |
| 146 | 3939 | ludovic_arnaud | $rowset = array(); |
| 147 | 3939 | ludovic_arnaud | |
| 148 | 6043 | acydburn | $sql = 'SELECT * |
| 149 | 4453 | ludovic_arnaud | FROM ' . BBCODES_TABLE; |
| 150 | 6048 | acydburn | $result = $db->sql_query($sql); |
| 151 | 4453 | ludovic_arnaud | |
| 152 | 3939 | ludovic_arnaud | while ($row = $db->sql_fetchrow($result)) |
| 153 | 3939 | ludovic_arnaud | {
|
| 154 | 3939 | ludovic_arnaud | $rowset[] = $row; |
| 155 | 3939 | ludovic_arnaud | } |
| 156 | 5603 | acydburn | $db->sql_freeresult($result); |
| 157 | 3812 | ludovic_arnaud | } |
| 158 | 5603 | acydburn | |
| 159 | 3939 | ludovic_arnaud | foreach ($rowset as $row) |
| 160 | 3939 | ludovic_arnaud | {
|
| 161 | 4453 | ludovic_arnaud | $this->bbcodes[$row['bbcode_tag']] = array( |
| 162 | 6043 | acydburn | 'bbcode_id' => (int) $row['bbcode_id'], |
| 163 | 5148 | acydburn | 'regexp' => array($row['first_pass_match'] => str_replace('$uid', $this->bbcode_uid, $row['first_pass_replace'])) |
| 164 | 4045 | ludovic_arnaud | ); |
| 165 | 3939 | ludovic_arnaud | } |
| 166 | 3812 | ludovic_arnaud | } |
| 167 | 3812 | ludovic_arnaud | |
| 168 | 6043 | acydburn | /**
|
| 169 | 6043 | acydburn | * Making some pre-checks for bbcodes as well as increasing the number of parsed items |
| 170 | 6043 | acydburn | */ |
| 171 | 5151 | acydburn | function check_bbcode($bbcode, &$in) |
| 172 | 5148 | acydburn | {
|
| 173 | 5902 | acydburn | // when using the /e modifier, preg_replace slashes double-quotes but does not
|
| 174 | 5902 | acydburn | // seem to slash anything else
|
| 175 | 6043 | acydburn | $in = str_replace("\r\n", "\n", str_replace('\"', '"', $in)); |
| 176 | 5148 | acydburn | |
| 177 | 6048 | acydburn | // Trimming here to make sure no empty bbcodes are parsed accidently
|
| 178 | 6161 | acydburn | if (trim($in) == '') |
| 179 | 5148 | acydburn | {
|
| 180 | 5151 | acydburn | return false; |
| 181 | 5148 | acydburn | } |
| 182 | 6043 | acydburn | |
| 183 | 5151 | acydburn | $this->parsed_items[$bbcode]++; |
| 184 | 5148 | acydburn | |
| 185 | 5151 | acydburn | return true; |
| 186 | 5151 | acydburn | } |
| 187 | 5151 | acydburn | |
| 188 | 6043 | acydburn | /**
|
| 189 | 6043 | acydburn | * Transform some characters in valid bbcodes |
| 190 | 6043 | acydburn | */ |
| 191 | 6043 | acydburn | function bbcode_specialchars($text) |
| 192 | 6043 | acydburn | {
|
| 193 | 6043 | acydburn | $str_from = array('<', '>', '[', ']', '.', ':'); |
| 194 | 6043 | acydburn | $str_to = array('<', '>', '[', ']', '.', ':'); |
| 195 | 6043 | acydburn | |
| 196 | 6043 | acydburn | return str_replace($str_from, $str_to, $text); |
| 197 | 6043 | acydburn | } |
| 198 | 6043 | acydburn | |
| 199 | 6043 | acydburn | /**
|
| 200 | 6048 | acydburn | * Parse size tag |
| 201 | 6043 | acydburn | */ |
| 202 | 5151 | acydburn | function bbcode_size($stx, $in) |
| 203 | 5151 | acydburn | {
|
| 204 | 5583 | davidmj | global $user, $config; |
| 205 | 5583 | davidmj | |
| 206 | 5151 | acydburn | if (!$this->check_bbcode('size', $in)) |
| 207 | 5151 | acydburn | {
|
| 208 | 8392 | acydburn | return $in; |
| 209 | 5151 | acydburn | } |
| 210 | 6043 | acydburn | |
| 211 | 5583 | davidmj | if ($config['max_' . $this->mode . '_font_size'] && $config['max_' . $this->mode . '_font_size'] < $stx) |
| 212 | 5583 | davidmj | {
|
| 213 | 5583 | davidmj | $this->warn_msg[] = sprintf($user->lang['MAX_FONT_SIZE_EXCEEDED'], $config['max_' . $this->mode . '_font_size']); |
| 214 | 7330 | acydburn | |
| 215 | 7330 | acydburn | return '[size=' . $stx . ']' . $in . '[/size]'; |
| 216 | 5583 | davidmj | } |
| 217 | 5583 | davidmj | |
| 218 | 8256 | acydburn | // Do not allow size=0
|
| 219 | 8256 | acydburn | if ($stx <= 0) |
| 220 | 8256 | acydburn | {
|
| 221 | 8256 | acydburn | return '[size=' . $stx . ']' . $in . '[/size]'; |
| 222 | 8256 | acydburn | } |
| 223 | 8256 | acydburn | |
| 224 | 5155 | acydburn | return '[size=' . $stx . ':' . $this->bbcode_uid . ']' . $in . '[/size:' . $this->bbcode_uid . ']'; |
| 225 | 5148 | acydburn | } |
| 226 | 5148 | acydburn | |
| 227 | 6043 | acydburn | /**
|
| 228 | 6048 | acydburn | * Parse color tag |
| 229 | 6043 | acydburn | */ |
| 230 | 5148 | acydburn | function bbcode_color($stx, $in) |
| 231 | 5148 | acydburn | {
|
| 232 | 5151 | acydburn | if (!$this->check_bbcode('color', $in)) |
| 233 | 5148 | acydburn | {
|
| 234 | 8392 | acydburn | return $in; |
| 235 | 5148 | acydburn | } |
| 236 | 5148 | acydburn | |
| 237 | 5148 | acydburn | return '[color=' . $stx . ':' . $this->bbcode_uid . ']' . $in . '[/color:' . $this->bbcode_uid . ']'; |
| 238 | 5148 | acydburn | } |
| 239 | 6043 | acydburn | |
| 240 | 6043 | acydburn | /**
|
| 241 | 6048 | acydburn | * Parse u tag |
| 242 | 6043 | acydburn | */ |
| 243 | 5148 | acydburn | function bbcode_underline($in) |
| 244 | 5148 | acydburn | {
|
| 245 | 5151 | acydburn | if (!$this->check_bbcode('u', $in)) |
| 246 | 5148 | acydburn | {
|
| 247 | 8392 | acydburn | return $in; |
| 248 | 5148 | acydburn | } |
| 249 | 5148 | acydburn | |
| 250 | 5148 | acydburn | return '[u:' . $this->bbcode_uid . ']' . $in . '[/u:' . $this->bbcode_uid . ']'; |
| 251 | 5148 | acydburn | } |
| 252 | 5148 | acydburn | |
| 253 | 6043 | acydburn | /**
|
| 254 | 6048 | acydburn | * Parse b tag |
| 255 | 6043 | acydburn | */ |
| 256 | 5148 | acydburn | function bbcode_strong($in) |
| 257 | 5148 | acydburn | {
|
| 258 | 5151 | acydburn | if (!$this->check_bbcode('b', $in)) |
| 259 | 5148 | acydburn | {
|
| 260 | 8392 | acydburn | return $in; |
| 261 | 5148 | acydburn | } |
| 262 | 5148 | acydburn | |
| 263 | 5148 | acydburn | return '[b:' . $this->bbcode_uid . ']' . $in . '[/b:' . $this->bbcode_uid . ']'; |
| 264 | 5148 | acydburn | } |
| 265 | 6043 | acydburn | |
| 266 | 6043 | acydburn | /**
|
| 267 | 6048 | acydburn | * Parse i tag |
| 268 | 6043 | acydburn | */ |
| 269 | 5148 | acydburn | function bbcode_italic($in) |
| 270 | 5148 | acydburn | {
|
| 271 | 5151 | acydburn | if (!$this->check_bbcode('i', $in)) |
| 272 | 5148 | acydburn | {
|
| 273 | 8392 | acydburn | return $in; |
| 274 | 5148 | acydburn | } |
| 275 | 5148 | acydburn | |
| 276 | 5148 | acydburn | return '[i:' . $this->bbcode_uid . ']' . $in . '[/i:' . $this->bbcode_uid . ']'; |
| 277 | 5148 | acydburn | } |
| 278 | 5148 | acydburn | |
| 279 | 6043 | acydburn | /**
|
| 280 | 6048 | acydburn | * Parse img tag |
| 281 | 6043 | acydburn | */ |
| 282 | 5023 | acydburn | function bbcode_img($in) |
| 283 | 5023 | acydburn | {
|
| 284 | 6735 | davidmj | global $user, $config; |
| 285 | 5583 | davidmj | |
| 286 | 5151 | acydburn | if (!$this->check_bbcode('img', $in)) |
| 287 | 5148 | acydburn | {
|
| 288 | 8392 | acydburn | return $in; |
| 289 | 5148 | acydburn | } |
| 290 | 5148 | acydburn | |
| 291 | 6048 | acydburn | $in = trim($in); |
| 292 | 7330 | acydburn | $error = false; |
| 293 | 6048 | acydburn | |
| 294 | 7889 | acydburn | $in = str_replace(' ', '%20', $in); |
| 295 | 7889 | acydburn | |
| 296 | 7889 | acydburn | // Checking urls
|
| 297 | 7889 | acydburn | if (!preg_match('#^' . get_preg_expression('url') . '$#i', $in) && !preg_match('#^' . get_preg_expression('www_url') . '$#i', $in)) |
| 298 | 7889 | acydburn | {
|
| 299 | 7889 | acydburn | return '[img]' . $in . '[/img]'; |
| 300 | 7889 | acydburn | } |
| 301 | 7889 | acydburn | |
| 302 | 7889 | acydburn | // Try to cope with a common user error... not specifying a protocol but only a subdomain
|
| 303 | 7889 | acydburn | if (!preg_match('#^[a-z0-9]+://#i', $in)) |
| 304 | 7889 | acydburn | {
|
| 305 | 7889 | acydburn | $in = 'http://' . $in; |
| 306 | 7889 | acydburn | } |
| 307 | 7889 | acydburn | |
| 308 | 5583 | davidmj | if ($config['max_' . $this->mode . '_img_height'] || $config['max_' . $this->mode . '_img_width']) |
| 309 | 5583 | davidmj | {
|
| 310 | 10600 | git-gate | $stats = @getimagesize(htmlspecialchars_decode($in)); |
| 311 | 6048 | acydburn | |
| 312 | 6073 | acydburn | if ($stats === false) |
| 313 | 5583 | davidmj | {
|
| 314 | 7330 | acydburn | $error = true; |
| 315 | 6073 | acydburn | $this->warn_msg[] = $user->lang['UNABLE_GET_IMAGE_SIZE']; |
| 316 | 5583 | davidmj | } |
| 317 | 6073 | acydburn | else
|
| 318 | 6073 | acydburn | {
|
| 319 | 6073 | acydburn | if ($config['max_' . $this->mode . '_img_height'] && $config['max_' . $this->mode . '_img_height'] < $stats[1]) |
| 320 | 6073 | acydburn | {
|
| 321 | 7330 | acydburn | $error = true; |
| 322 | 6073 | acydburn | $this->warn_msg[] = sprintf($user->lang['MAX_IMG_HEIGHT_EXCEEDED'], $config['max_' . $this->mode . '_img_height']); |
| 323 | 6073 | acydburn | } |
| 324 | 6048 | acydburn | |
| 325 | 6073 | acydburn | if ($config['max_' . $this->mode . '_img_width'] && $config['max_' . $this->mode . '_img_width'] < $stats[0]) |
| 326 | 6073 | acydburn | {
|
| 327 | 7330 | acydburn | $error = true; |
| 328 | 6073 | acydburn | $this->warn_msg[] = sprintf($user->lang['MAX_IMG_WIDTH_EXCEEDED'], $config['max_' . $this->mode . '_img_width']); |
| 329 | 6073 | acydburn | } |
| 330 | 5583 | davidmj | } |
| 331 | 5583 | davidmj | } |
| 332 | 5583 | davidmj | |
| 333 | 7330 | acydburn | if ($error || $this->path_in_domain($in)) |
| 334 | 6048 | acydburn | {
|
| 335 | 6055 | acydburn | return '[img]' . $in . '[/img]'; |
| 336 | 6048 | acydburn | } |
| 337 | 6048 | acydburn | |
| 338 | 6048 | acydburn | return '[img:' . $this->bbcode_uid . ']' . $this->bbcode_specialchars($in) . '[/img:' . $this->bbcode_uid . ']'; |
| 339 | 5023 | acydburn | } |
| 340 | 5023 | acydburn | |
| 341 | 6043 | acydburn | /**
|
| 342 | 6048 | acydburn | * Parse flash tag |
| 343 | 6043 | acydburn | */ |
| 344 | 5023 | acydburn | function bbcode_flash($width, $height, $in) |
| 345 | 5023 | acydburn | {
|
| 346 | 6735 | davidmj | global $user, $config; |
| 347 | 6048 | acydburn | |
| 348 | 5151 | acydburn | if (!$this->check_bbcode('flash', $in)) |
| 349 | 5148 | acydburn | {
|
| 350 | 8392 | acydburn | return $in; |
| 351 | 5148 | acydburn | } |
| 352 | 6015 | acydburn | |
| 353 | 6048 | acydburn | $in = trim($in); |
| 354 | 7330 | acydburn | $error = false; |
| 355 | 6043 | acydburn | |
| 356 | 8613 | acydburn | // Do not allow 0-sizes generally being entered
|
| 357 | 8613 | acydburn | if ($width <= 0 || $height <= 0) |
| 358 | 8613 | acydburn | {
|
| 359 | 8613 | acydburn | return '[flash=' . $width . ',' . $height . ']' . $in . '[/flash]'; |
| 360 | 8613 | acydburn | } |
| 361 | 8613 | acydburn | |
| 362 | 10873 | git-gate | $in = str_replace(' ', '%20', $in); |
| 363 | 10873 | git-gate | |
| 364 | 10873 | git-gate | // Make sure $in is a URL.
|
| 365 | 10873 | git-gate | if (!preg_match('#^' . get_preg_expression('url') . '$#i', $in) && |
| 366 | 10873 | git-gate | !preg_match('#^' . get_preg_expression('www_url') . '$#i', $in)) |
| 367 | 10873 | git-gate | {
|
| 368 | 10873 | git-gate | return '[flash=' . $width . ',' . $height . ']' . $in . '[/flash]'; |
| 369 | 10873 | git-gate | } |
| 370 | 10873 | git-gate | |
| 371 | 6015 | acydburn | // Apply the same size checks on flash files as on images
|
| 372 | 6015 | acydburn | if ($config['max_' . $this->mode . '_img_height'] || $config['max_' . $this->mode . '_img_width']) |
| 373 | 6015 | acydburn | {
|
| 374 | 6015 | acydburn | if ($config['max_' . $this->mode . '_img_height'] && $config['max_' . $this->mode . '_img_height'] < $height) |
| 375 | 6015 | acydburn | {
|
| 376 | 7330 | acydburn | $error = true; |
| 377 | 6015 | acydburn | $this->warn_msg[] = sprintf($user->lang['MAX_FLASH_HEIGHT_EXCEEDED'], $config['max_' . $this->mode . '_img_height']); |
| 378 | 6015 | acydburn | } |
| 379 | 6015 | acydburn | |
| 380 | 6015 | acydburn | if ($config['max_' . $this->mode . '_img_width'] && $config['max_' . $this->mode . '_img_width'] < $width) |
| 381 | 6015 | acydburn | {
|
| 382 | 7330 | acydburn | $error = true; |
| 383 | 6015 | acydburn | $this->warn_msg[] = sprintf($user->lang['MAX_FLASH_WIDTH_EXCEEDED'], $config['max_' . $this->mode . '_img_width']); |
| 384 | 6015 | acydburn | } |
| 385 | 6015 | acydburn | } |
| 386 | 6015 | acydburn | |
| 387 | 7330 | acydburn | if ($error || $this->path_in_domain($in)) |
| 388 | 6048 | acydburn | {
|
| 389 | 6055 | acydburn | return '[flash=' . $width . ',' . $height . ']' . $in . '[/flash]'; |
| 390 | 6048 | acydburn | } |
| 391 | 6048 | acydburn | |
| 392 | 6048 | acydburn | return '[flash=' . $width . ',' . $height . ':' . $this->bbcode_uid . ']' . $this->bbcode_specialchars($in) . '[/flash:' . $this->bbcode_uid . ']'; |
| 393 | 5023 | acydburn | } |
| 394 | 5023 | acydburn | |
| 395 | 6043 | acydburn | /**
|
| 396 | 6043 | acydburn | * Parse inline attachments [ia] |
| 397 | 6043 | acydburn | */ |
| 398 | 4819 | acydburn | function bbcode_attachment($stx, $in) |
| 399 | 4819 | acydburn | {
|
| 400 | 5151 | acydburn | if (!$this->check_bbcode('attachment', $in)) |
| 401 | 5148 | acydburn | {
|
| 402 | 8392 | acydburn | return $in; |
| 403 | 5148 | acydburn | } |
| 404 | 5148 | acydburn | |
| 405 | 6043 | acydburn | return '[attachment=' . $stx . ':' . $this->bbcode_uid . ']<!-- ia' . $stx . ' -->' . trim($in) . '<!-- ia' . $stx . ' -->[/attachment:' . $this->bbcode_uid . ']'; |
| 406 | 4819 | acydburn | } |
| 407 | 4819 | acydburn | |
| 408 | 6043 | acydburn | /**
|
| 409 | 7535 | acydburn | * Parse code text from code tag |
| 410 | 8783 | acydburn | * @access private |
| 411 | 6043 | acydburn | */ |
| 412 | 7749 | acydburn | function bbcode_parse_code($stx, &$code) |
| 413 | 3812 | ludovic_arnaud | {
|
| 414 | 7527 | acydburn | switch (strtolower($stx)) |
| 415 | 3812 | ludovic_arnaud | {
|
| 416 | 7527 | acydburn | case 'php': |
| 417 | 3812 | ludovic_arnaud | |
| 418 | 7527 | acydburn | $remove_tags = false; |
| 419 | 7527 | acydburn | |
| 420 | 8665 | acydburn | $str_from = array('<', '>', '[', ']', '.', ':', ':'); |
| 421 | 8665 | acydburn | $str_to = array('<', '>', '[', ']', '.', ':', ':'); |
| 422 | 8665 | acydburn | $code = str_replace($str_from, $str_to, $code); |
| 423 | 8665 | acydburn | |
| 424 | 7527 | acydburn | if (!preg_match('/\<\?.*?\?\>/is', $code)) |
| 425 | 3812 | ludovic_arnaud | {
|
| 426 | 7527 | acydburn | $remove_tags = true; |
| 427 | 7527 | acydburn | $code = "<?php $code ?>"; |
| 428 | 3812 | ludovic_arnaud | } |
| 429 | 7527 | acydburn | |
| 430 | 7527 | acydburn | $conf = array('highlight.bg', 'highlight.comment', 'highlight.default', 'highlight.html', 'highlight.keyword', 'highlight.string'); |
| 431 | 7527 | acydburn | foreach ($conf as $ini_var) |
| 432 | 3812 | ludovic_arnaud | {
|
| 433 | 7527 | acydburn | @ini_set($ini_var, str_replace('highlight.', 'syntax', $ini_var)); |
| 434 | 3812 | ludovic_arnaud | } |
| 435 | 3812 | ludovic_arnaud | |
| 436 | 7527 | acydburn | // 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 | 7527 | acydburn | $code = htmlspecialchars_decode($code); |
| 438 | 7527 | acydburn | $code = highlight_string($code, true); |
| 439 | 3901 | ludovic_arnaud | |
| 440 | 7527 | acydburn | $str_from = array('<span style="color: ', '<font color="syntax', '</font>', '<code>', '</code>','[', ']', '.', ':'); |
| 441 | 7527 | acydburn | $str_to = array('<span class="', '<span class="syntax', '</span>', '', '', '[', ']', '.', ':'); |
| 442 | 6048 | acydburn | |
| 443 | 7527 | acydburn | if ($remove_tags) |
| 444 | 7527 | acydburn | {
|
| 445 | 7527 | acydburn | $str_from[] = '<span class="syntaxdefault"><?php </span>'; |
| 446 | 7527 | acydburn | $str_to[] = ''; |
| 447 | 7527 | acydburn | $str_from[] = '<span class="syntaxdefault"><?php '; |
| 448 | 7527 | acydburn | $str_to[] = '<span class="syntaxdefault">'; |
| 449 | 7527 | acydburn | } |
| 450 | 4045 | ludovic_arnaud | |
| 451 | 7527 | acydburn | $code = str_replace($str_from, $str_to, $code); |
| 452 | 7527 | acydburn | $code = preg_replace('#^(<span class="[a-z_]+">)\n?(.*?)\n?(</span>)$#is', '$1$2$3', $code); |
| 453 | 3901 | ludovic_arnaud | |
| 454 | 7527 | acydburn | if ($remove_tags) |
| 455 | 7527 | acydburn | {
|
| 456 | 7619 | acydburn | $code = preg_replace('#(<span class="[a-z]+">)?\?>(</span>)#', '$1 $2', $code); |
| 457 | 7527 | acydburn | } |
| 458 | 4045 | ludovic_arnaud | |
| 459 | 7527 | acydburn | $code = preg_replace('#^<span class="[a-z]+"><span class="([a-z]+)">(.*)</span></span>#s', '<span class="$1">$2</span>', $code); |
| 460 | 8039 | davidmj | $code = preg_replace('#(?:\s++| )*+</span>$#u', '</span>', $code); |
| 461 | 3901 | ludovic_arnaud | |
| 462 | 7527 | acydburn | // remove newline at the end
|
| 463 | 8039 | davidmj | if (!empty($code) && substr($code, -1) == "\n") |
| 464 | 7527 | acydburn | {
|
| 465 | 7527 | acydburn | $code = substr($code, 0, -1); |
| 466 | 7527 | acydburn | } |
| 467 | 4045 | ludovic_arnaud | |
| 468 | 7535 | acydburn | return "[code=$stx:" . $this->bbcode_uid . ']' . $code . '[/code:' . $this->bbcode_uid . ']'; |
| 469 | 7527 | acydburn | break;
|
| 470 | 3901 | ludovic_arnaud | |
| 471 | 7527 | acydburn | default:
|
| 472 | 9425 | toonarmy | return '[code:' . $this->bbcode_uid . ']' . $this->bbcode_specialchars($code) . '[/code:' . $this->bbcode_uid . ']'; |
| 473 | 7527 | acydburn | break;
|
| 474 | 3812 | ludovic_arnaud | } |
| 475 | 7535 | acydburn | } |
| 476 | 3812 | ludovic_arnaud | |
| 477 | 7535 | acydburn | /**
|
| 478 | 7535 | acydburn | * Parse code tag |
| 479 | 7535 | acydburn | * Expects the argument to start right after the opening [code] tag and to end with [/code] |
| 480 | 7535 | acydburn | */ |
| 481 | 7535 | acydburn | function bbcode_code($stx, $in) |
| 482 | 7535 | acydburn | {
|
| 483 | 7535 | acydburn | if (!$this->check_bbcode('code', $in)) |
| 484 | 7535 | acydburn | {
|
| 485 | 8392 | acydburn | return $in; |
| 486 | 7535 | acydburn | } |
| 487 | 7535 | acydburn | |
| 488 | 7535 | acydburn | // We remove the hardcoded elements from the code block here because it is not used in code blocks
|
| 489 | 7535 | acydburn | // Having it here saves us one preg_replace per message containing [code] blocks
|
| 490 | 7535 | acydburn | // Additionally, magic url parsing should go after parsing bbcodes, but for safety those are stripped out too...
|
| 491 | 7535 | acydburn | $htm_match = get_preg_expression('bbcode_htm'); |
| 492 | 7535 | acydburn | unset($htm_match[4], $htm_match[5]); |
| 493 | 7535 | acydburn | $htm_replace = array('\1', '\1', '\2', '\1'); |
| 494 | 7535 | acydburn | |
| 495 | 7535 | acydburn | $out = $code_block = ''; |
| 496 | 7535 | acydburn | $open = 1; |
| 497 | 7535 | acydburn | |
| 498 | 7535 | acydburn | while ($in) |
| 499 | 7535 | acydburn | {
|
| 500 | 7535 | acydburn | // Determine position and tag length of next code block
|
| 501 | 7535 | acydburn | preg_match('#(.*?)(\[code(?:=([a-z]+))?\])(.+)#is', $in, $buffer); |
| 502 | 7535 | acydburn | $pos = (isset($buffer[1])) ? strlen($buffer[1]) : false; |
| 503 | 7535 | acydburn | $tag_length = (isset($buffer[2])) ? strlen($buffer[2]) : false; |
| 504 | 7535 | acydburn | |
| 505 | 7535 | acydburn | // Determine position of ending code tag
|
| 506 | 7535 | acydburn | $pos2 = stripos($in, '[/code]'); |
| 507 | 7535 | acydburn | |
| 508 | 7535 | acydburn | // Which is the next block, ending code or code block
|
| 509 | 7535 | acydburn | if ($pos !== false && $pos < $pos2) |
| 510 | 7535 | acydburn | {
|
| 511 | 7535 | acydburn | // Open new block
|
| 512 | 7535 | acydburn | if (!$open) |
| 513 | 7535 | acydburn | {
|
| 514 | 7535 | acydburn | $out .= substr($in, 0, $pos); |
| 515 | 7535 | acydburn | $in = substr($in, $pos); |
| 516 | 7535 | acydburn | $stx = (isset($buffer[3])) ? $buffer[3] : ''; |
| 517 | 7535 | acydburn | $code_block = ''; |
| 518 | 7535 | acydburn | } |
| 519 | 7535 | acydburn | else
|
| 520 | 7535 | acydburn | {
|
| 521 | 7535 | acydburn | // Already opened block, just append to the current block
|
| 522 | 7535 | acydburn | $code_block .= substr($in, 0, $pos) . ((isset($buffer[2])) ? $buffer[2] : ''); |
| 523 | 7535 | acydburn | $in = substr($in, $pos); |
| 524 | 7535 | acydburn | } |
| 525 | 7535 | acydburn | |
| 526 | 7535 | acydburn | $in = substr($in, $tag_length); |
| 527 | 7535 | acydburn | $open++;
|
| 528 | 7535 | acydburn | } |
| 529 | 7535 | acydburn | else
|
| 530 | 7535 | acydburn | {
|
| 531 | 7535 | acydburn | // Close the block
|
| 532 | 7535 | acydburn | if ($open == 1) |
| 533 | 7535 | acydburn | {
|
| 534 | 7535 | acydburn | $code_block .= substr($in, 0, $pos2); |
| 535 | 7712 | acydburn | $code_block = preg_replace($htm_match, $htm_replace, $code_block); |
| 536 | 7535 | acydburn | |
| 537 | 7535 | acydburn | // Parse this code block
|
| 538 | 7535 | acydburn | $out .= $this->bbcode_parse_code($stx, $code_block); |
| 539 | 7535 | acydburn | $code_block = ''; |
| 540 | 7535 | acydburn | $open--;
|
| 541 | 7535 | acydburn | } |
| 542 | 7535 | acydburn | else if ($open) |
| 543 | 7535 | acydburn | {
|
| 544 | 7535 | acydburn | // Close one open tag... add to the current code block
|
| 545 | 7535 | acydburn | $code_block .= substr($in, 0, $pos2 + 7); |
| 546 | 7535 | acydburn | $open--;
|
| 547 | 7535 | acydburn | } |
| 548 | 7535 | acydburn | else
|
| 549 | 7535 | acydburn | {
|
| 550 | 7535 | acydburn | // end code without opening code... will be always outside code block
|
| 551 | 7535 | acydburn | $out .= substr($in, 0, $pos2 + 7); |
| 552 | 7535 | acydburn | } |
| 553 | 7535 | acydburn | |
| 554 | 7535 | acydburn | $in = substr($in, $pos2 + 7); |
| 555 | 7535 | acydburn | } |
| 556 | 7535 | acydburn | } |
| 557 | 7535 | acydburn | |
| 558 | 7535 | acydburn | // if now $code_block has contents we need to parse the remaining code while removing the last closing tag to match up.
|
| 559 | 7535 | acydburn | if ($code_block) |
| 560 | 7535 | acydburn | {
|
| 561 | 7535 | acydburn | $code_block = substr($code_block, 0, -7); |
| 562 | 7712 | acydburn | $code_block = preg_replace($htm_match, $htm_replace, $code_block); |
| 563 | 7712 | acydburn | |
| 564 | 7535 | acydburn | $out .= $this->bbcode_parse_code($stx, $code_block); |
| 565 | 7535 | acydburn | } |
| 566 | 7535 | acydburn | |
| 567 | 3812 | ludovic_arnaud | return $out; |
| 568 | 3812 | ludovic_arnaud | } |
| 569 | 3812 | ludovic_arnaud | |
| 570 | 6043 | acydburn | /**
|
| 571 | 6043 | acydburn | * Parse list bbcode |
| 572 | 6043 | acydburn | * Expects the argument to start with a tag |
| 573 | 6043 | acydburn | */ |
| 574 | 5127 | acydburn | function bbcode_parse_list($in) |
| 575 | 3812 | ludovic_arnaud | {
|
| 576 | 5151 | acydburn | if (!$this->check_bbcode('list', $in)) |
| 577 | 5148 | acydburn | {
|
| 578 | 8392 | acydburn | return $in; |
| 579 | 5148 | acydburn | } |
| 580 | 6043 | acydburn | |
| 581 | 3860 | ludovic_arnaud | // $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
|
| 582 | 3812 | ludovic_arnaud | $tok = ']'; |
| 583 | 3812 | ludovic_arnaud | $out = '['; |
| 584 | 3860 | ludovic_arnaud | |
| 585 | 6457 | acydburn | // First character is [
|
| 586 | 5127 | acydburn | $in = substr($in, 1); |
| 587 | 6777 | davidmj | $list_end_tags = $item_end_tags = array(); |
| 588 | 4453 | ludovic_arnaud | |
| 589 | 3812 | ludovic_arnaud | do
|
| 590 | 3812 | ludovic_arnaud | {
|
| 591 | 3812 | ludovic_arnaud | $pos = strlen($in); |
| 592 | 6457 | acydburn | |
| 593 | 6457 | acydburn | for ($i = 0, $tok_len = strlen($tok); $i < $tok_len; ++$i) |
| 594 | 3812 | ludovic_arnaud | {
|
| 595 | 6777 | davidmj | $tmp_pos = strpos($in, $tok[$i]); |
| 596 | 5127 | acydburn | |
| 597 | 4767 | acydburn | if ($tmp_pos !== false && $tmp_pos < $pos) |
| 598 | 3812 | ludovic_arnaud | {
|
| 599 | 3812 | ludovic_arnaud | $pos = $tmp_pos; |
| 600 | 3812 | ludovic_arnaud | } |
| 601 | 3812 | ludovic_arnaud | } |
| 602 | 3812 | ludovic_arnaud | |
| 603 | 3812 | ludovic_arnaud | $buffer = substr($in, 0, $pos); |
| 604 | 6777 | davidmj | $tok = $in[$pos]; |
| 605 | 3812 | ludovic_arnaud | |
| 606 | 5127 | acydburn | $in = substr($in, $pos + 1); |
| 607 | 6043 | acydburn | |
| 608 | 3812 | ludovic_arnaud | if ($tok == ']') |
| 609 | 3812 | ludovic_arnaud | {
|
| 610 | 3860 | ludovic_arnaud | // if $tok is ']' the buffer holds a tag
|
| 611 | 6371 | davidmj | if (strtolower($buffer) == '/list' && sizeof($list_end_tags)) |
| 612 | 3812 | ludovic_arnaud | {
|
| 613 | 6898 | davidmj | // valid [/list] tag, check nesting so that we don't hit false positives
|
| 614 | 6898 | davidmj | if (sizeof($item_end_tags) && sizeof($item_end_tags) >= sizeof($list_end_tags)) |
| 615 | 6777 | davidmj | {
|
| 616 | 6777 | davidmj | // current li tag has not been closed
|
| 617 | 6777 | davidmj | $out = preg_replace('/\n?\[$/', '[', $out) . array_pop($item_end_tags) . ']['; |
| 618 | 6777 | davidmj | } |
| 619 | 6777 | davidmj | |
| 620 | 4016 | ludovic_arnaud | $out .= array_pop($list_end_tags) . ']'; |
| 621 | 3812 | ludovic_arnaud | $tok = '['; |
| 622 | 3812 | ludovic_arnaud | } |
| 623 | 9007 | toonarmy | else if (preg_match('#^list(=[0-9a-z]+)?$#i', $buffer, $m)) |
| 624 | 3812 | ludovic_arnaud | {
|
| 625 | 3860 | ludovic_arnaud | // sub-list, add a closing tag
|
| 626 | 9034 | toonarmy | if (empty($m[1]) || preg_match('/^=(?:disc|square|circle)$/i', $m[1])) |
| 627 | 4085 | ludovic_arnaud | {
|
| 628 | 4085 | ludovic_arnaud | array_push($list_end_tags, '/list:u:' . $this->bbcode_uid); |
| 629 | 4085 | ludovic_arnaud | } |
| 630 | 4085 | ludovic_arnaud | else
|
| 631 | 4085 | ludovic_arnaud | {
|
| 632 | 4085 | ludovic_arnaud | array_push($list_end_tags, '/list:o:' . $this->bbcode_uid); |
| 633 | 4085 | ludovic_arnaud | } |
| 634 | 7339 | davidmj | $out .= 'list' . substr($buffer, 4) . ':' . $this->bbcode_uid . ']'; |
| 635 | 3812 | ludovic_arnaud | $tok = '['; |
| 636 | 3812 | ludovic_arnaud | } |
| 637 | 3812 | ludovic_arnaud | else
|
| 638 | 3812 | ludovic_arnaud | {
|
| 639 | 6777 | davidmj | if (($buffer == '*' || substr($buffer, -2) == '[*') && sizeof($list_end_tags)) |
| 640 | 6777 | davidmj | {
|
| 641 | 6777 | davidmj | // the buffer holds a bullet tag and we have a [list] tag open
|
| 642 | 6777 | davidmj | if (sizeof($item_end_tags) >= sizeof($list_end_tags)) |
| 643 | 6777 | davidmj | {
|
| 644 | 6777 | davidmj | if (substr($buffer, -2) == '[*') |
| 645 | 6777 | davidmj | {
|
| 646 | 6777 | davidmj | $out .= substr($buffer, 0, -2) . '['; |
| 647 | 6777 | davidmj | } |
| 648 | 6777 | davidmj | // current li tag has not been closed
|
| 649 | 6777 | davidmj | if (preg_match('/\n\[$/', $out, $m)) |
| 650 | 6777 | davidmj | {
|
| 651 | 6777 | davidmj | $out = preg_replace('/\n\[$/', '[', $out); |
| 652 | 6777 | davidmj | $buffer = array_pop($item_end_tags) . "]\n[*:" . $this->bbcode_uid; |
| 653 | 6777 | davidmj | } |
| 654 | 6777 | davidmj | else
|
| 655 | 6777 | davidmj | {
|
| 656 | 6777 | davidmj | $buffer = array_pop($item_end_tags) . '][*:' . $this->bbcode_uid; |
| 657 | 6777 | davidmj | } |
| 658 | 6777 | davidmj | } |
| 659 | 6777 | davidmj | else
|
| 660 | 6777 | davidmj | {
|
| 661 | 6777 | davidmj | $buffer = '*:' . $this->bbcode_uid; |
| 662 | 6777 | davidmj | } |
| 663 | 6777 | davidmj | |
| 664 | 6777 | davidmj | $item_end_tags[] = '/*:m:' . $this->bbcode_uid; |
| 665 | 6777 | davidmj | } |
| 666 | 6777 | davidmj | else if ($buffer == '/*') |
| 667 | 6777 | davidmj | {
|
| 668 | 6898 | davidmj | array_pop($item_end_tags); |
| 669 | 6777 | davidmj | $buffer = '/*:' . $this->bbcode_uid; |
| 670 | 6777 | davidmj | } |
| 671 | 6777 | davidmj | |
| 672 | 3812 | ludovic_arnaud | $out .= $buffer . $tok; |
| 673 | 3812 | ludovic_arnaud | $tok = '[]'; |
| 674 | 3812 | ludovic_arnaud | } |
| 675 | 3812 | ludovic_arnaud | } |
| 676 | 3812 | ludovic_arnaud | else
|
| 677 | 3812 | ludovic_arnaud | {
|
| 678 | 3860 | ludovic_arnaud | // Not within a tag, just add buffer to the return string
|
| 679 | 3812 | ludovic_arnaud | $out .= $buffer . $tok; |
| 680 | 3812 | ludovic_arnaud | $tok = ($tok == '[') ? ']' : '[]'; |
| 681 | 3812 | ludovic_arnaud | } |
| 682 | 3812 | ludovic_arnaud | } |
| 683 | 3812 | ludovic_arnaud | while ($in); |
| 684 | 3812 | ludovic_arnaud | |
| 685 | 6777 | davidmj | // do we have some tags open? close them now
|
| 686 | 6777 | davidmj | if (sizeof($item_end_tags)) |
| 687 | 6777 | davidmj | {
|
| 688 | 6777 | davidmj | $out .= '[' . implode('][', $item_end_tags) . ']'; |
| 689 | 6777 | davidmj | } |
| 690 | 4984 | acydburn | if (sizeof($list_end_tags)) |
| 691 | 4016 | ludovic_arnaud | {
|
| 692 | 4016 | ludovic_arnaud | $out .= '[' . implode('][', $list_end_tags) . ']'; |
| 693 | 4016 | ludovic_arnaud | } |
| 694 | 3812 | ludovic_arnaud | |
| 695 | 3812 | ludovic_arnaud | return $out; |
| 696 | 3812 | ludovic_arnaud | } |
| 697 | 3812 | ludovic_arnaud | |
| 698 | 6043 | acydburn | /**
|
| 699 | 6043 | acydburn | * Parse quote bbcode |
| 700 | 6043 | acydburn | * Expects the argument to start with a tag |
| 701 | 6043 | acydburn | */ |
| 702 | 3939 | ludovic_arnaud | function bbcode_quote($in) |
| 703 | 3939 | ludovic_arnaud | {
|
| 704 | 4045 | ludovic_arnaud | global $config, $user; |
| 705 | 4045 | ludovic_arnaud | |
| 706 | 8155 | acydburn | /**
|
| 707 | 8155 | acydburn | * If you change this code, make sure the cases described within the following reports are still working: |
| 708 | 8204 | acydburn | * #3572 - [quote="[test]test"]test [ test[/quote] - (correct: parsed) |
| 709 | 8204 | acydburn | * #14667 - [quote]test[/quote] test ] and [ test [quote]test[/quote] (correct: parsed) |
| 710 | 8204 | acydburn | * #14770 - [quote="["]test[/quote] (correct: parsed) |
| 711 | 8204 | acydburn | * [quote="[i]test[/i]"]test[/quote] (correct: parsed) |
| 712 | 8393 | acydburn | * [quote="[quote]test[/quote]"]test[/quote] (correct: parsed - Username displayed as [quote]test[/quote]) |
| 713 | 8393 | acydburn | * #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 | 9304 | terrafrost | * #40565 - [quote="a"]a[/quote][quote="a]a[/quote] (correct: first quote tag parsed, second quote tag unparsed) |
| 715 | 8155 | acydburn | */ |
| 716 | 8155 | acydburn | |
| 717 | 5902 | acydburn | $in = str_replace("\r\n", "\n", str_replace('\"', '"', trim($in))); |
| 718 | 5148 | acydburn | |
| 719 | 5148 | acydburn | if (!$in) |
| 720 | 5148 | acydburn | {
|
| 721 | 5148 | acydburn | return ''; |
| 722 | 5148 | acydburn | } |
| 723 | 6043 | acydburn | |
| 724 | 8204 | acydburn | // To let the parser not catch tokens within quote_username quotes we encode them before we start this...
|
| 725 | 9342 | terrafrost | $in = preg_replace('#quote="(.*?)"\]#ie', "'quote="' . str_replace(array('[', ']', '\\\"'), array('[', ']', '\"'), '\$1') . '"]'", $in); |
| 726 | 8204 | acydburn | |
| 727 | 3939 | ludovic_arnaud | $tok = ']'; |
| 728 | 3939 | ludovic_arnaud | $out = '['; |
| 729 | 3939 | ludovic_arnaud | |
| 730 | 5902 | acydburn | $in = substr($in, 1); |
| 731 | 4045 | ludovic_arnaud | $close_tags = $error_ary = array(); |
| 732 | 3997 | ludovic_arnaud | $buffer = ''; |
| 733 | 3939 | ludovic_arnaud | |
| 734 | 3939 | ludovic_arnaud | do
|
| 735 | 3939 | ludovic_arnaud | {
|
| 736 | 3939 | ludovic_arnaud | $pos = strlen($in); |
| 737 | 6452 | acydburn | for ($i = 0, $tok_len = strlen($tok); $i < $tok_len; ++$i) |
| 738 | 3939 | ludovic_arnaud | {
|
| 739 | 6584 | acydburn | $tmp_pos = strpos($in, $tok[$i]); |
| 740 | 4767 | acydburn | if ($tmp_pos !== false && $tmp_pos < $pos) |
| 741 | 3939 | ludovic_arnaud | {
|
| 742 | 3939 | ludovic_arnaud | $pos = $tmp_pos; |
| 743 | 3939 | ludovic_arnaud | } |
| 744 | 3939 | ludovic_arnaud | } |
| 745 | 3939 | ludovic_arnaud | |
| 746 | 3997 | ludovic_arnaud | $buffer .= substr($in, 0, $pos); |
| 747 | 6584 | acydburn | $tok = $in[$pos]; |
| 748 | 3939 | ludovic_arnaud | $in = substr($in, $pos + 1); |
| 749 | 3939 | ludovic_arnaud | |
| 750 | 3939 | ludovic_arnaud | if ($tok == ']') |
| 751 | 3939 | ludovic_arnaud | {
|
| 752 | 8248 | acydburn | if (strtolower($buffer) == '/quote' && sizeof($close_tags) && substr($out, -1, 1) == '[') |
| 753 | 3939 | ludovic_arnaud | {
|
| 754 | 3997 | ludovic_arnaud | // we have found a closing tag
|
| 755 | 6584 | acydburn | $out .= array_pop($close_tags) . ']'; |
| 756 | 3939 | ludovic_arnaud | $tok = '['; |
| 757 | 3997 | ludovic_arnaud | $buffer = ''; |
| 758 | 6584 | acydburn | |
| 759 | 7611 | acydburn | /* Add space at the end of the closing tag if not happened before to allow following urls/smilies to be parsed correctly
|
| 760 | 7611 | acydburn | * 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 | 7611 | acydburn | * Also, we won't have any spaces within $in anyway, only adding up spaces -> #10982 |
| 762 | 6584 | acydburn | if (!$in || $in[0] !== ' ') |
| 763 | 6584 | acydburn | {
|
| 764 | 6584 | acydburn | $out .= ' '; |
| 765 | 7611 | acydburn | }*/ |
| 766 | 3939 | ludovic_arnaud | } |
| 767 | 8393 | acydburn | else if (preg_match('#^quote(?:="(.*?)")?$#is', $buffer, $m) && substr($out, -1, 1) == '[') |
| 768 | 3939 | ludovic_arnaud | {
|
| 769 | 5023 | acydburn | $this->parsed_items['quote']++; |
| 770 | 5023 | acydburn | |
| 771 | 3997 | ludovic_arnaud | // the buffer holds a valid opening tag
|
| 772 | 4984 | acydburn | if ($config['max_quote_depth'] && sizeof($close_tags) >= $config['max_quote_depth']) |
| 773 | 4045 | ludovic_arnaud | {
|
| 774 | 4045 | ludovic_arnaud | // there are too many nested quotes
|
| 775 | 4225 | ludovic_arnaud | $error_ary['quote_depth'] = sprintf($user->lang['QUOTE_DEPTH_EXCEEDED'], $config['max_quote_depth']); |
| 776 | 4045 | ludovic_arnaud | |
| 777 | 4045 | ludovic_arnaud | $out .= $buffer . $tok; |
| 778 | 4045 | ludovic_arnaud | $tok = '[]'; |
| 779 | 4045 | ludovic_arnaud | $buffer = ''; |
| 780 | 4045 | ludovic_arnaud | |
| 781 | 4045 | ludovic_arnaud | continue;
|
| 782 | 4045 | ludovic_arnaud | } |
| 783 | 4045 | ludovic_arnaud | |
| 784 | 3939 | ludovic_arnaud | array_push($close_tags, '/quote:' . $this->bbcode_uid); |
| 785 | 3997 | ludovic_arnaud | |
| 786 | 4978 | acydburn | if (isset($m[1]) && $m[1]) |
| 787 | 3997 | ludovic_arnaud | {
|
| 788 | 8204 | acydburn | $username = str_replace(array('[', ']'), array('[', ']'), $m[1]); |
| 789 | 8204 | acydburn | $username = preg_replace('#\[(?!b|i|u|color|url|email|/b|/i|/u|/color|/url|/email)#iU', '[$1', $username); |
| 790 | 8204 | acydburn | |
| 791 | 4059 | ludovic_arnaud | $end_tags = array(); |
| 792 | 4767 | acydburn | $error = false; |
| 793 | 4059 | ludovic_arnaud | |
| 794 | 4059 | ludovic_arnaud | preg_match_all('#\[((?:/)?(?:[a-z]+))#i', $username, $tags); |
| 795 | 4059 | ludovic_arnaud | foreach ($tags[1] as $tag) |
| 796 | 4059 | ludovic_arnaud | {
|
| 797 | 6459 | acydburn | if ($tag[0] != '/') |
| 798 | 4059 | ludovic_arnaud | {
|
| 799 | 4059 | ludovic_arnaud | $end_tags[] = '/' . $tag; |
| 800 | 4059 | ludovic_arnaud | } |
| 801 | 4059 | ludovic_arnaud | else
|
| 802 | 4059 | ludovic_arnaud | {
|
| 803 | 4085 | ludovic_arnaud | $end_tag = array_pop($end_tags); |
| 804 | 6673 | acydburn | $error = ($end_tag != $tag) ? true : false; |
| 805 | 4059 | ludovic_arnaud | } |
| 806 | 4059 | ludovic_arnaud | } |
| 807 | 6043 | acydburn | |
| 808 | 4059 | ludovic_arnaud | if ($error) |
| 809 | 4059 | ludovic_arnaud | {
|
| 810 | 8204 | acydburn | $username = $m[1]; |
| 811 | 4059 | ludovic_arnaud | } |
| 812 | 4059 | ludovic_arnaud | |
| 813 | 4485 | acydburn | $out .= 'quote="' . $username . '":' . $this->bbcode_uid . ']'; |
| 814 | 3997 | ludovic_arnaud | } |
| 815 | 3997 | ludovic_arnaud | else
|
| 816 | 3997 | ludovic_arnaud | {
|
| 817 | 3997 | ludovic_arnaud | $out .= 'quote:' . $this->bbcode_uid . ']'; |
| 818 | 3997 | ludovic_arnaud | } |
| 819 | 3997 | ludovic_arnaud | |
| 820 | 3939 | ludovic_arnaud | $tok = '['; |
| 821 | 3997 | ludovic_arnaud | $buffer = ''; |
| 822 | 3939 | ludovic_arnaud | } |
| 823 | 5313 | acydburn | else if (preg_match('#^quote="(.*?)#is', $buffer, $m)) |
| 824 | 3997 | ludovic_arnaud | {
|
| 825 | 3997 | ludovic_arnaud | // the buffer holds an invalid opening tag
|
| 826 | 3997 | ludovic_arnaud | $buffer .= ']'; |
| 827 | 3997 | ludovic_arnaud | } |
| 828 | 3939 | ludovic_arnaud | else
|
| 829 | 3939 | ludovic_arnaud | {
|
| 830 | 3939 | ludovic_arnaud | $out .= $buffer . $tok; |
| 831 | 3939 | ludovic_arnaud | $tok = '[]'; |
| 832 | 3997 | ludovic_arnaud | $buffer = ''; |
| 833 | 3939 | ludovic_arnaud | } |
| 834 | 3939 | ludovic_arnaud | } |
| 835 | 3939 | ludovic_arnaud | else
|
| 836 | 3939 | ludovic_arnaud | {
|
| 837 | 6673 | acydburn | /**
|
| 838 | 6673 | acydburn | * Old quote code working fine, but having errors listed in bug #3572 |
| 839 | 6673 | acydburn | * |
| 840 | 6673 | acydburn | * $out .= $buffer . $tok; |
| 841 | 6673 | acydburn | * $tok = ($tok == '[') ? ']' : '[]'; |
| 842 | 6673 | acydburn | * $buffer = ''; |
| 843 | 6673 | acydburn | */ |
| 844 | 6673 | acydburn | |
| 845 | 3939 | ludovic_arnaud | $out .= $buffer . $tok; |
| 846 | 6673 | acydburn | |
| 847 | 6673 | acydburn | if ($tok == '[') |
| 848 | 6673 | acydburn | {
|
| 849 | 6673 | acydburn | // Search the text for the next tok... if an ending quote comes first, then change tok to []
|
| 850 | 8248 | acydburn | $pos1 = stripos($in, '[/quote'); |
| 851 | 8155 | acydburn | // If the token ] comes first, we change it to ]
|
| 852 | 6673 | acydburn | $pos2 = strpos($in, ']'); |
| 853 | 8155 | acydburn | // If the token [ comes first, we change it to [
|
| 854 | 8155 | acydburn | $pos3 = strpos($in, '['); |
| 855 | 6673 | acydburn | |
| 856 | 8155 | acydburn | if ($pos1 !== false && ($pos2 === false || $pos1 < $pos2) && ($pos3 === false || $pos1 < $pos3)) |
| 857 | 6673 | acydburn | {
|
| 858 | 6673 | acydburn | $tok = '[]'; |
| 859 | 6673 | acydburn | } |
| 860 | 8155 | acydburn | else if ($pos3 !== false && ($pos2 === false || $pos3 < $pos2)) |
| 861 | 8155 | acydburn | {
|
| 862 | 8155 | acydburn | $tok = '['; |
| 863 | 8155 | acydburn | } |
| 864 | 6673 | acydburn | else
|
| 865 | 6673 | acydburn | {
|
| 866 | 6673 | acydburn | $tok = ']'; |
| 867 | 6673 | acydburn | } |
| 868 | 6673 | acydburn | } |
| 869 | 6673 | acydburn | else
|
| 870 | 6673 | acydburn | {
|
| 871 | 6673 | acydburn | $tok = '[]'; |
| 872 | 6673 | acydburn | } |
| 873 | 3997 | ludovic_arnaud | $buffer = ''; |
| 874 | 3939 | ludovic_arnaud | } |
| 875 | 3939 | ludovic_arnaud | } |
| 876 | 3939 | ludovic_arnaud | while ($in); |
| 877 | 3939 | ludovic_arnaud | |
| 878 | 9304 | terrafrost | $out .= $buffer; |
| 879 | 9304 | terrafrost | |
| 880 | 4984 | acydburn | if (sizeof($close_tags)) |
| 881 | 3939 | ludovic_arnaud | {
|
| 882 | 3939 | ludovic_arnaud | $out .= '[' . implode('][', $close_tags) . ']'; |
| 883 | 3939 | ludovic_arnaud | } |
| 884 | 3939 | ludovic_arnaud | |
| 885 | 4045 | ludovic_arnaud | foreach ($error_ary as $error_msg) |
| 886 | 4045 | ludovic_arnaud | {
|
| 887 | 4045 | ludovic_arnaud | $this->warn_msg[] = $error_msg; |
| 888 | 4045 | ludovic_arnaud | } |
| 889 | 4045 | ludovic_arnaud | |
| 890 | 3939 | ludovic_arnaud | return $out; |
| 891 | 3939 | ludovic_arnaud | } |
| 892 | 3939 | ludovic_arnaud | |
| 893 | 6043 | acydburn | /**
|
| 894 | 6043 | acydburn | * Validate email |
| 895 | 6043 | acydburn | */ |
| 896 | 3812 | ludovic_arnaud | function validate_email($var1, $var2) |
| 897 | 3812 | ludovic_arnaud | {
|
| 898 | 5902 | acydburn | $var1 = str_replace("\r\n", "\n", str_replace('\"', '"', trim($var1))); |
| 899 | 5902 | acydburn | $var2 = str_replace("\r\n", "\n", str_replace('\"', '"', trim($var2))); |
| 900 | 3860 | ludovic_arnaud | |
| 901 | 5902 | acydburn | $txt = $var2; |
| 902 | 5902 | acydburn | $email = ($var1) ? $var1 : $var2; |
| 903 | 5902 | acydburn | |
| 904 | 4767 | acydburn | $validated = true; |
| 905 | 4453 | ludovic_arnaud | |
| 906 | 6135 | acydburn | if (!preg_match('/^' . get_preg_expression('email') . '$/i', $email)) |
| 907 | 4453 | ludovic_arnaud | {
|
| 908 | 4767 | acydburn | $validated = false; |
| 909 | 4453 | ludovic_arnaud | } |
| 910 | 4453 | ludovic_arnaud | |
| 911 | 4453 | ludovic_arnaud | if (!$validated) |
| 912 | 4453 | ludovic_arnaud | {
|
| 913 | 4453 | ludovic_arnaud | return '[email' . (($var1) ? "=$var1" : '') . ']' . $var2 . '[/email]'; |
| 914 | 4453 | ludovic_arnaud | } |
| 915 | 4453 | ludovic_arnaud | |
| 916 | 5023 | acydburn | $this->parsed_items['email']++; |
| 917 | 6043 | acydburn | |
| 918 | 4453 | ludovic_arnaud | if ($var1) |
| 919 | 4453 | ludovic_arnaud | {
|
| 920 | 6051 | acydburn | $retval = '[email=' . $this->bbcode_specialchars($email) . ':' . $this->bbcode_uid . ']' . $txt . '[/email:' . $this->bbcode_uid . ']'; |
| 921 | 4453 | ludovic_arnaud | } |
| 922 | 4453 | ludovic_arnaud | else
|
| 923 | 4453 | ludovic_arnaud | {
|
| 924 | 6043 | acydburn | $retval = '[email:' . $this->bbcode_uid . ']' . $this->bbcode_specialchars($email) . '[/email:' . $this->bbcode_uid . ']'; |
| 925 | 4453 | ludovic_arnaud | } |
| 926 | 5151 | acydburn | |
| 927 | 3812 | ludovic_arnaud | return $retval; |
| 928 | 3812 | ludovic_arnaud | } |
| 929 | 3812 | ludovic_arnaud | |
| 930 | 6043 | acydburn | /**
|
| 931 | 6043 | acydburn | * Validate url |
| 932 | 6774 | naderman | * |
| 933 | 6774 | naderman | * @param string $var1 optional url parameter for url bbcode: [url(=$var1)]$var2[/url] |
| 934 | 8146 | acydburn | * @param string $var2 url bbcode content: [url(=$var1)]$var2[/url] |
| 935 | 6043 | acydburn | */ |
| 936 | 3812 | ludovic_arnaud | function validate_url($var1, $var2) |
| 937 | 3812 | ludovic_arnaud | {
|
| 938 | 4834 | acydburn | global $config; |
| 939 | 6043 | acydburn | |
| 940 | 5902 | acydburn | $var1 = str_replace("\r\n", "\n", str_replace('\"', '"', trim($var1))); |
| 941 | 5902 | acydburn | $var2 = str_replace("\r\n", "\n", str_replace('\"', '"', trim($var2))); |
| 942 | 5148 | acydburn | |
| 943 | 5902 | acydburn | $url = ($var1) ? $var1 : $var2; |
| 944 | 3812 | ludovic_arnaud | |
| 945 | 8306 | acydburn | if ($var1 && !$var2) |
| 946 | 5148 | acydburn | {
|
| 947 | 8306 | acydburn | $var2 = $var1; |
| 948 | 5148 | acydburn | } |
| 949 | 5148 | acydburn | |
| 950 | 8306 | acydburn | if (!$url) |
| 951 | 8306 | acydburn | {
|
| 952 | 8306 | acydburn | return '[url' . (($var1) ? '=' . $var1 : '') . ']' . $var2 . '[/url]'; |
| 953 | 8306 | acydburn | } |
| 954 | 8306 | acydburn | |
| 955 | 6774 | naderman | $valid = false; |
| 956 | 6774 | naderman | |
| 957 | 6774 | naderman | $url = str_replace(' ', '%20', $url); |
| 958 | 6774 | naderman | |
| 959 | 6774 | naderman | // Checking urls
|
| 960 | 6774 | naderman | if (preg_match('#^' . get_preg_expression('url') . '$#i', $url) || |
| 961 | 6774 | naderman | preg_match('#^' . get_preg_expression('www_url') . '$#i', $url) || |
| 962 | 6774 | naderman | preg_match('#^' . preg_quote(generate_board_url(), '#') . get_preg_expression('relative_url') . '$#i', $url)) |
| 963 | 3572 | acydburn | {
|
| 964 | 6774 | naderman | $valid = true; |
| 965 | 3572 | acydburn | } |
| 966 | 3572 | acydburn | |
| 967 | 4834 | acydburn | if ($valid) |
| 968 | 4451 | acydburn | {
|
| 969 | 5023 | acydburn | $this->parsed_items['url']++; |
| 970 | 6047 | davidmj | |
| 971 | 6774 | naderman | // if there is no scheme, then add http schema
|
| 972 | 6774 | naderman | if (!preg_match('#^[a-z][a-z\d+\-.]*:/{2}#i', $url)) |
| 973 | 3572 | acydburn | {
|
| 974 | 4834 | acydburn | $url = 'http://' . $url; |
| 975 | 3572 | acydburn | } |
| 976 | 3572 | acydburn | |
| 977 | 6774 | naderman | // Is this a link to somewhere inside this board? If so then remove the session id from the url
|
| 978 | 6051 | acydburn | if (strpos($url, generate_board_url()) !== false && strpos($url, 'sid=') !== false) |
| 979 | 6047 | davidmj | {
|
| 980 | 7076 | naderman | $url = preg_replace('/(&|\?)sid=[0-9a-f]{32}&/', '\1', $url); |
| 981 | 7076 | naderman | $url = preg_replace('/(&|\?)sid=[0-9a-f]{32}$/', '', $url); |
| 982 | 7076 | naderman | $url = append_sid($url); |
| 983 | 6047 | davidmj | } |
| 984 | 6047 | davidmj | |
| 985 | 8146 | acydburn | 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 . ']'; |
| 986 | 4834 | acydburn | } |
| 987 | 4451 | acydburn | |
| 988 | 5902 | acydburn | return '[url' . (($var1) ? '=' . $var1 : '') . ']' . $var2 . '[/url]'; |
| 989 | 3572 | acydburn | } |
| 990 | 6055 | acydburn | |
| 991 | 6055 | acydburn | /**
|
| 992 | 6055 | acydburn | * Check if url is pointing to this domain/script_path/php-file |
| 993 | 6055 | acydburn | * |
| 994 | 6055 | acydburn | * @param string $url the url to check |
| 995 | 6055 | acydburn | * @return true if the url is pointing to this domain/script_path/php-file, false if not |
| 996 | 6055 | acydburn | * |
| 997 | 6312 | acydburn | * @access private |
| 998 | 6055 | acydburn | */ |
| 999 | 6055 | acydburn | function path_in_domain($url) |
| 1000 | 6055 | acydburn | {
|
| 1001 | 6055 | acydburn | global $config, $phpEx, $user; |
| 1002 | 6055 | acydburn | |
| 1003 | 6730 | acydburn | if ($config['force_server_vars']) |
| 1004 | 6730 | acydburn | {
|
| 1005 | 6730 | acydburn | $check_path = $config['script_path']; |
| 1006 | 6730 | acydburn | } |
| 1007 | 6730 | acydburn | else
|
| 1008 | 6730 | acydburn | {
|
| 1009 | 6730 | acydburn | $check_path = ($user->page['root_script_path'] != '/') ? substr($user->page['root_script_path'], 0, -1) : '/'; |
| 1010 | 6730 | acydburn | } |
| 1011 | 6149 | acydburn | |
| 1012 | 6055 | acydburn | // Is the user trying to link to a php file in this domain and script path?
|
| 1013 | 6149 | acydburn | if (strpos($url, ".{$phpEx}") !== false && strpos($url, $check_path) !== false) |
| 1014 | 6055 | acydburn | {
|
| 1015 | 8348 | acydburn | $server_name = $user->host; |
| 1016 | 6055 | acydburn | |
| 1017 | 6055 | acydburn | // Forcing server vars is the only way to specify/override the protocol
|
| 1018 | 6055 | acydburn | if ($config['force_server_vars'] || !$server_name) |
| 1019 | 6055 | acydburn | {
|
| 1020 | 6055 | acydburn | $server_name = $config['server_name']; |
| 1021 | 6055 | acydburn | } |
| 1022 | 6055 | acydburn | |
| 1023 | 6055 | acydburn | // Check again in correct order...
|
| 1024 | 6055 | acydburn | $pos_ext = strpos($url, ".{$phpEx}"); |
| 1025 | 6149 | acydburn | $pos_path = strpos($url, $check_path); |
| 1026 | 6055 | acydburn | $pos_domain = strpos($url, $server_name); |
| 1027 | 6055 | acydburn | |
| 1028 | 6055 | acydburn | if ($pos_domain !== false && $pos_path >= $pos_domain && $pos_ext >= $pos_path) |
| 1029 | 6055 | acydburn | {
|
| 1030 | 7643 | acydburn | // Ok, actually we allow linking to some files (this may be able to be extended in some way later...)
|
| 1031 | 8119 | acydburn | if (strpos($url, '/' . $check_path . '/download/file.' . $phpEx) !== 0) |
| 1032 | 7643 | acydburn | {
|
| 1033 | 7643 | acydburn | return false; |
| 1034 | 7643 | acydburn | } |
| 1035 | 7643 | acydburn | |
| 1036 | 6055 | acydburn | return true; |
| 1037 | 6055 | acydburn | } |
| 1038 | 6055 | acydburn | } |
| 1039 | 6055 | acydburn | |
| 1040 | 6055 | acydburn | return false; |
| 1041 | 6055 | acydburn | } |
| 1042 | 4978 | acydburn | } |
| 1043 | 3572 | acydburn | |
| 1044 | 5114 | acydburn | /**
|
| 1045 | 5114 | acydburn | * Main message parser for posting, pm, etc. takes raw message |
| 1046 | 5603 | acydburn | * and parses it for attachments, bbcode and smilies |
| 1047 | 6058 | acydburn | * @package phpBB3 |
| 1048 | 5114 | acydburn | */ |
| 1049 | 4978 | acydburn | class parse_message extends bbcode_firstpass |
| 1050 | 4978 | acydburn | {
|
| 1051 | 4978 | acydburn | var $attachment_data = array(); |
| 1052 | 4978 | acydburn | var $filename_data = array(); |
| 1053 | 4978 | acydburn | |
| 1054 | 4978 | acydburn | // Helps ironing out user error
|
| 1055 | 4978 | acydburn | var $message_status = ''; |
| 1056 | 4978 | acydburn | |
| 1057 | 4978 | acydburn | var $allow_img_bbcode = true; |
| 1058 | 4978 | acydburn | var $allow_flash_bbcode = true; |
| 1059 | 4978 | acydburn | var $allow_quote_bbcode = true; |
| 1060 | 6364 | acydburn | var $allow_url_bbcode = true; |
| 1061 | 4978 | acydburn | |
| 1062 | 5583 | davidmj | var $mode; |
| 1063 | 5583 | davidmj | |
| 1064 | 6043 | acydburn | /**
|
| 1065 | 6043 | acydburn | * Init - give message here or manually |
| 1066 | 6043 | acydburn | */ |
| 1067 | 4978 | acydburn | function parse_message($message = '') |
| 1068 | 4978 | acydburn | {
|
| 1069 | 4978 | acydburn | // Init BBCode UID
|
| 1070 | 8128 | davidmj | $this->bbcode_uid = substr(base_convert(unique_id(), 16, 36), 0, BBCODE_UID_LEN); |
| 1071 | 9453 | acydburn | $this->message = $message; |
| 1072 | 4978 | acydburn | } |
| 1073 | 4978 | acydburn | |
| 1074 | 6043 | acydburn | /**
|
| 1075 | 6048 | acydburn | * Parse Message |
| 1076 | 6043 | acydburn | */ |
| 1077 | 6364 | acydburn | 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') |
| 1078 | 4978 | acydburn | {
|
| 1079 | 4978 | acydburn | global $config, $db, $user; |
| 1080 | 4978 | acydburn | |
| 1081 | 5583 | davidmj | $this->mode = $mode; |
| 1082 | 5583 | davidmj | |
| 1083 | 10249 | acydburn | foreach (array('chars', 'smilies', 'urls', 'font_size', 'img_height', 'img_width') as $key) |
| 1084 | 9892 | nickvergessen | {
|
| 1085 | 10249 | acydburn | if (!isset($config['max_' . $mode . '_' . $key])) |
| 1086 | 10249 | acydburn | {
|
| 1087 | 10249 | acydburn | $config['max_' . $mode . '_' . $key] = 0; |
| 1088 | 10249 | acydburn | } |
| 1089 | 9892 | nickvergessen | } |
| 1090 | 9892 | nickvergessen | |
| 1091 | 4978 | acydburn | $this->allow_img_bbcode = $allow_img_bbcode; |
| 1092 | 4978 | acydburn | $this->allow_flash_bbcode = $allow_flash_bbcode; |
| 1093 | 4978 | acydburn | $this->allow_quote_bbcode = $allow_quote_bbcode; |
| 1094 | 6364 | acydburn | $this->allow_url_bbcode = $allow_url_bbcode; |
| 1095 | 4978 | acydburn | |
| 1096 | 5026 | bartvb | // If false, then $this->message won't be altered, the text will be returned instead.
|
| 1097 | 4978 | acydburn | if (!$update_this_message) |
| 1098 | 4978 | acydburn | {
|
| 1099 | 4978 | acydburn | $tmp_message = $this->message; |
| 1100 | 4978 | acydburn | $return_message = &$this->message; |
| 1101 | 4978 | acydburn | } |
| 1102 | 4978 | acydburn | |
| 1103 | 4978 | acydburn | if ($this->message_status == 'display') |
| 1104 | 4978 | acydburn | {
|
| 1105 | 4978 | acydburn | $this->decode_message();
|
| 1106 | 4978 | acydburn | } |
| 1107 | 4978 | acydburn | |
| 1108 | 4978 | acydburn | // Do some general 'cleanup' first before processing message,
|
| 1109 | 4978 | acydburn | // e.g. remove excessive newlines(?), smilies(?)
|
| 1110 | 7527 | acydburn | $match = array('#(script|about|applet|activex|chrome):#i'); |
| 1111 | 7527 | acydburn | $replace = array("\\1:"); |
| 1112 | 4978 | acydburn | $this->message = preg_replace($match, $replace, trim($this->message)); |
| 1113 | 4978 | acydburn | |
| 1114 | 9656 | acydburn | // Store message length...
|
| 1115 | 9656 | acydburn | $message_length = ($mode == 'post') ? utf8_strlen($this->message) : utf8_strlen(preg_replace('#\[\/?[a-z\*\+\-]+(=[\S]+)?\]#ius', ' ', $this->message)); |
| 1116 | 9656 | acydburn | |
| 1117 | 9656 | acydburn | // Maximum message length check. 0 disables this check completely.
|
| 1118 | 9656 | acydburn | if ((int) $config['max_' . $mode . '_chars'] > 0 && $message_length > (int) $config['max_' . $mode . '_chars']) |
| 1119 | 4978 | acydburn | {
|
| 1120 | 9656 | acydburn | $this->warn_msg[] = sprintf($user->lang['TOO_MANY_CHARS_' . strtoupper($mode)], $message_length, (int) $config['max_' . $mode . '_chars']); |
| 1121 | 9656 | acydburn | return (!$update_this_message) ? $return_message : $this->warn_msg; |
| 1122 | 9656 | acydburn | } |
| 1123 | 8348 | acydburn | |
| 1124 | 9656 | acydburn | // Minimum message length check for post only
|
| 1125 | 9892 | nickvergessen | if ($mode === 'post') |
| 1126 | 9656 | acydburn | {
|
| 1127 | 9656 | acydburn | if (!$message_length || $message_length < (int) $config['min_post_chars']) |
| 1128 | 5076 | bartvb | {
|
| 1129 | 9656 | acydburn | $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 | 8428 | acydburn | return (!$update_this_message) ? $return_message : $this->warn_msg; |
| 1131 | 5076 | bartvb | } |
| 1132 | 4978 | acydburn | } |
| 1133 | 4978 | acydburn | |
| 1134 | 6114 | acydburn | // Prepare BBcode (just prepares some tags for better parsing)
|
| 1135 | 6114 | acydburn | if ($allow_bbcode && strpos($this->message, '[') !== false) |
| 1136 | 6114 | acydburn | {
|
| 1137 | 6114 | acydburn | $this->bbcode_init();
|
| 1138 | 6364 | acydburn | $disallow = array('img', 'flash', 'quote', 'url'); |
| 1139 | 6114 | acydburn | foreach ($disallow as $bool) |
| 1140 | 6114 | acydburn | {
|
| 1141 | 6114 | acydburn | if (!${'allow_' . $bool . '_bbcode'}) |
| 1142 | 6114 | acydburn | {
|
| 1143 | 6114 | acydburn | $this->bbcodes[$bool]['disabled'] = true; |
| 1144 | 6114 | acydburn | } |
| 1145 | 6114 | acydburn | } |
| 1146 | 6114 | acydburn | |
| 1147 | 6114 | acydburn | $this->prepare_bbcodes();
|
| 1148 | 6114 | acydburn | } |
| 1149 | 6114 | acydburn | |
| 1150 | 5109 | acydburn | // Parse smilies
|
| 1151 | 4984 | acydburn | if ($allow_smilies) |
| 1152 | 4984 | acydburn | {
|
| 1153 | 5109 | acydburn | $this->smilies($config['max_' . $mode . '_smilies']); |
| 1154 | 4984 | acydburn | } |
| 1155 | 4984 | acydburn | |
| 1156 | 5023 | acydburn | $num_urls = 0; |
| 1157 | 5023 | acydburn | |
| 1158 | 4978 | acydburn | // Parse BBCode
|
| 1159 | 4978 | acydburn | if ($allow_bbcode && strpos($this->message, '[') !== false) |
| 1160 | 4978 | acydburn | {
|
| 1161 | 4978 | acydburn | $this->parse_bbcode();
|
| 1162 | 5023 | acydburn | $num_urls += $this->parsed_items['url']; |
| 1163 | 4978 | acydburn | } |
| 1164 | 4978 | acydburn | |
| 1165 | 5027 | acydburn | // Parse URL's
|
| 1166 | 5027 | acydburn | if ($allow_magic_url) |
| 1167 | 5027 | acydburn | {
|
| 1168 | 5595 | acydburn | $this->magic_url(generate_board_url());
|
| 1169 | 7476 | acydburn | |
| 1170 | 5027 | acydburn | if ($config['max_' . $mode . '_urls']) |
| 1171 | 5027 | acydburn | {
|
| 1172 | 6735 | davidmj | $num_urls += preg_match_all('#\<!-- ([lmwe]) --\>.*?\<!-- \1 --\>#', $this->message, $matches); |
| 1173 | 5027 | acydburn | } |
| 1174 | 5027 | acydburn | } |
| 1175 | 5027 | acydburn | |
| 1176 | 9370 | acydburn | // Check for "empty" message. We do not check here for maximum length, because bbcode, smilies, etc. can add to the length.
|
| 1177 | 9370 | acydburn | // The maximum length check happened before any parsings.
|
| 1178 | 9892 | nickvergessen | if ($mode === 'post' && utf8_clean_string($this->message) === '') |
| 1179 | 9370 | acydburn | {
|
| 1180 | 9370 | acydburn | $this->warn_msg[] = $user->lang['TOO_FEW_CHARS']; |
| 1181 | 9370 | acydburn | return (!$update_this_message) ? $return_message : $this->warn_msg; |
| 1182 | 9370 | acydburn | } |
| 1183 | 9370 | acydburn | |
| 1184 | 5023 | acydburn | // Check number of links
|
| 1185 | 5023 | acydburn | if ($config['max_' . $mode . '_urls'] && $num_urls > $config['max_' . $mode . '_urls']) |
| 1186 | 5023 | acydburn | {
|
| 1187 | 5023 | acydburn | $this->warn_msg[] = sprintf($user->lang['TOO_MANY_URLS'], $config['max_' . $mode . '_urls']); |
| 1188 | 8428 | acydburn | return (!$update_this_message) ? $return_message : $this->warn_msg; |
| 1189 | 5023 | acydburn | } |
| 1190 | 5023 | acydburn | |
| 1191 | 4978 | acydburn | if (!$update_this_message) |
| 1192 | 4978 | acydburn | {
|
| 1193 | 4978 | acydburn | unset($this->message); |
| 1194 | 4978 | acydburn | $this->message = $tmp_message; |
| 1195 | 4978 | acydburn | return $return_message; |
| 1196 | 4978 | acydburn | } |
| 1197 | 4978 | acydburn | |
| 1198 | 4978 | acydburn | $this->message_status = 'parsed'; |
| 1199 | 5967 | acydburn | return false; |
| 1200 | 4978 | acydburn | } |
| 1201 | 4978 | acydburn | |
| 1202 | 6048 | acydburn | /**
|
| 1203 | 6048 | acydburn | * Formatting text for display |
| 1204 | 6048 | acydburn | */ |
| 1205 | 5603 | acydburn | function format_display($allow_bbcode, $allow_magic_url, $allow_smilies, $update_this_message = true) |
| 1206 | 4978 | acydburn | {
|
| 1207 | 4978 | acydburn | // If false, then the parsed message get returned but internal message not processed.
|
| 1208 | 4978 | acydburn | if (!$update_this_message) |
| 1209 | 4978 | acydburn | {
|
| 1210 | 4978 | acydburn | $tmp_message = $this->message; |
| 1211 | 4978 | acydburn | $return_message = &$this->message; |
| 1212 | 4978 | acydburn | } |
| 1213 | 4978 | acydburn | |
| 1214 | 4978 | acydburn | if ($this->message_status == 'plain') |
| 1215 | 4978 | acydburn | {
|
| 1216 | 4978 | acydburn | // Force updating message - of course.
|
| 1217 | 6364 | acydburn | $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); |
| 1218 | 4978 | acydburn | } |
| 1219 | 4978 | acydburn | |
| 1220 | 8050 | naderman | // Replace naughty words such as farty pants
|
| 1221 | 8050 | naderman | $this->message = censor_text($this->message); |
| 1222 | 8050 | naderman | |
| 1223 | 4978 | acydburn | // Parse BBcode
|
| 1224 | 4978 | acydburn | if ($allow_bbcode) |
| 1225 | 4978 | acydburn | {
|
| 1226 | 4978 | acydburn | $this->bbcode_cache_init();
|
| 1227 | 4978 | acydburn | |
| 1228 | 4978 | acydburn | // We are giving those parameters to be able to use the bbcode class on its own
|
| 1229 | 4978 | acydburn | $this->bbcode_second_pass($this->message, $this->bbcode_uid); |
| 1230 | 4978 | acydburn | } |
| 1231 | 4978 | acydburn | |
| 1232 | 8050 | naderman | $this->message = bbcode_nl2br($this->message); |
| 1233 | 5109 | acydburn | $this->message = smiley_text($this->message, !$allow_smilies); |
| 1234 | 4978 | acydburn | |
| 1235 | 4978 | acydburn | if (!$update_this_message) |
| 1236 | 4978 | acydburn | {
|
| 1237 | 4978 | acydburn | unset($this->message); |
| 1238 | 4978 | acydburn | $this->message = $tmp_message; |
| 1239 | 4978 | acydburn | return $return_message; |
| 1240 | 4978 | acydburn | } |
| 1241 | 4978 | acydburn | |
| 1242 | 4978 | acydburn | $this->message_status = 'display'; |
| 1243 | 5967 | acydburn | return false; |
| 1244 | 6048 | acydburn | } |
| 1245 | 6048 | acydburn | |
| 1246 | 6048 | acydburn | /**
|
| 1247 | 6048 | acydburn | * Decode message to be placed back into form box |
| 1248 | 6048 | acydburn | */ |
| 1249 | 4978 | acydburn | function decode_message($custom_bbcode_uid = '', $update_this_message = true) |
| 1250 | 4978 | acydburn | {
|
| 1251 | 4978 | acydburn | // If false, then the parsed message get returned but internal message not processed.
|
| 1252 | 4978 | acydburn | if (!$update_this_message) |
| 1253 | 4978 | acydburn | {
|
| 1254 | 4978 | acydburn | $tmp_message = $this->message; |
| 1255 | 4978 | acydburn | $return_message = &$this->message; |
| 1256 | 4978 | acydburn | } |
| 1257 | 4978 | acydburn | |
| 1258 | 4978 | acydburn | ($custom_bbcode_uid) ? decode_message($this->message, $custom_bbcode_uid) : decode_message($this->message, $this->bbcode_uid); |
| 1259 | 4978 | acydburn | |
| 1260 | 4978 | acydburn | if (!$update_this_message) |
| 1261 | 4978 | acydburn | {
|
| 1262 | 4978 | acydburn | unset($this->message); |
| 1263 | 4978 | acydburn | $this->message = $tmp_message; |
| 1264 | 4978 | acydburn | return $return_message; |
| 1265 | 4978 | acydburn | } |
| 1266 | 4978 | acydburn | |
| 1267 | 4978 | acydburn | $this->message_status = 'plain'; |
| 1268 | 5967 | acydburn | return false; |
| 1269 | 4978 | acydburn | } |
| 1270 | 6048 | acydburn | |
| 1271 | 6048 | acydburn | /**
|
| 1272 | 6048 | acydburn | * Replace magic urls of form http://xxx.xxx., www.xxx. and xxx@xxx.xxx. |
| 1273 | 6048 | acydburn | * Cuts down displayed size of link if over 50 chars, turns absolute links |
| 1274 | 6048 | acydburn | * into relative versions when the server/script path matches the link |
| 1275 | 6048 | acydburn | */ |
| 1276 | 5595 | acydburn | function magic_url($server_url) |
| 1277 | 4978 | acydburn | {
|
| 1278 | 5712 | acydburn | // We use the global make_clickable function
|
| 1279 | 5712 | acydburn | $this->message = make_clickable($this->message, $server_url); |
| 1280 | 4978 | acydburn | } |
| 1281 | 4978 | acydburn | |
| 1282 | 6048 | acydburn | /**
|
| 1283 | 6048 | acydburn | * Parse Smilies |
| 1284 | 6048 | acydburn | */ |
| 1285 | 5109 | acydburn | function smilies($max_smilies = 0) |
| 1286 | 4978 | acydburn | {
|
| 1287 | 6735 | davidmj | global $db, $user; |
| 1288 | 5026 | bartvb | static $match; |
| 1289 | 5026 | bartvb | static $replace; |
| 1290 | 4978 | acydburn | |
| 1291 | 5026 | bartvb | // See if the static arrays have already been filled on an earlier invocation
|
| 1292 | 5027 | acydburn | if (!is_array($match)) |
| 1293 | 4984 | acydburn | {
|
| 1294 | 6048 | acydburn | $match = $replace = array(); |
| 1295 | 6048 | acydburn | |
| 1296 | 5026 | bartvb | // NOTE: obtain_* function? chaching the table contents?
|
| 1297 | 8348 | acydburn | |
| 1298 | 5026 | bartvb | // For now setting the ttl to 10 minutes
|
| 1299 | 6497 | acydburn | switch ($db->sql_layer) |
| 1300 | 5026 | bartvb | {
|
| 1301 | 5026 | bartvb | case 'mssql': |
| 1302 | 5193 | acydburn | case 'mssql_odbc': |
| 1303 | 10489 | naderman | case 'mssqlnative': |
| 1304 | 8146 | acydburn | $sql = 'SELECT * |
| 1305 | 5026 | bartvb | FROM ' . SMILIES_TABLE . ' |
| 1306 | 5026 | bartvb | ORDER BY LEN(code) DESC';
|
| 1307 | 5907 | davidmj | break;
|
| 1308 | 8348 | acydburn | |
| 1309 | 5907 | davidmj | case 'firebird': |
| 1310 | 8146 | acydburn | $sql = 'SELECT * |
| 1311 | 5907 | davidmj | FROM ' . SMILIES_TABLE . ' |
| 1312 | 6422 | davidmj | ORDER BY CHAR_LENGTH(code) DESC';
|
| 1313 | 5907 | davidmj | break;
|
| 1314 | 5907 | davidmj | |
| 1315 | 5026 | bartvb | // LENGTH supported by MySQL, IBM DB2, Oracle and Access for sure...
|
| 1316 | 5026 | bartvb | default:
|
| 1317 | 8146 | acydburn | $sql = 'SELECT * |
| 1318 | 5026 | bartvb | FROM ' . SMILIES_TABLE . ' |
| 1319 | 5026 | bartvb | ORDER BY LENGTH(code) DESC';
|
| 1320 | 5907 | davidmj | break;
|
| 1321 | 5026 | bartvb | } |
| 1322 | 5026 | bartvb | $result = $db->sql_query($sql, 600); |
| 1323 | 5566 | acydburn | |
| 1324 | 6048 | acydburn | while ($row = $db->sql_fetchrow($result)) |
| 1325 | 5026 | bartvb | {
|
| 1326 | 7875 | acydburn | if (empty($row['code'])) |
| 1327 | 7875 | acydburn | {
|
| 1328 | 7875 | acydburn | continue;
|
| 1329 | 7875 | acydburn | } |
| 1330 | 7875 | acydburn | |
| 1331 | 6048 | acydburn | // (assertion)
|
| 1332 | 9914 | aptx | $match[] = preg_quote($row['code'], '#'); |
| 1333 | 7149 | dhn2 | $replace[] = '<!-- s' . $row['code'] . ' --><img src="{SMILIES_PATH}/' . $row['smiley_url'] . '" alt="' . $row['code'] . '" title="' . $row['emotion'] . '" /><!-- s' . $row['code'] . ' -->'; |
| 1334 | 5026 | bartvb | } |
| 1335 | 5026 | bartvb | $db->sql_freeresult($result); |
| 1336 | 4984 | acydburn | } |
| 1337 | 5566 | acydburn | |
| 1338 | 5027 | acydburn | if (sizeof($match)) |
| 1339 | 4978 | acydburn | {
|
| 1340 | 4978 | acydburn | if ($max_smilies) |
| 1341 | 4978 | acydburn | {
|
| 1342 | 11104 | git-gate | // 'u' modifier has been added to correctly parse smilies within unicode strings
|
| 1343 | 11104 | git-gate | // For details: http://tracker.phpbb.com/browse/PHPBB3-10117
|
| 1344 | 11104 | git-gate | $num_matches = preg_match_all('#(?<=^|[\n .])(?:' . implode('|', $match) . ')(?![^<>]*>)#u', $this->message, $matches); |
| 1345 | 7743 | davidmj | unset($matches); |
| 1346 | 7743 | davidmj | |
| 1347 | 7743 | davidmj | if ($num_matches !== false && $num_matches > $max_smilies) |
| 1348 | 4978 | acydburn | {
|
| 1349 | 7743 | davidmj | $this->warn_msg[] = sprintf($user->lang['TOO_MANY_SMILIES'], $max_smilies); |
| 1350 | 7743 | davidmj | return;
|
| 1351 | 4978 | acydburn | } |
| 1352 | 4978 | acydburn | } |
| 1353 | 7743 | davidmj | |
| 1354 | 7805 | acydburn | // Make sure the delimiter # is added in front and at the end of every element within $match
|
| 1355 | 11104 | git-gate | // 'u' modifier has been added to correctly parse smilies within unicode strings
|
| 1356 | 11104 | git-gate | // For details: http://tracker.phpbb.com/browse/PHPBB3-10117
|
| 1357 | 11104 | git-gate | |
| 1358 | 11104 | git-gate | $this->message = trim(preg_replace(explode(chr(0), '#(?<=^|[\n .])' . implode('(?![^<>]*>)#u' . chr(0) . '#(?<=^|[\n .])', $match) . '(?![^<>]*>)#u'), $replace, $this->message)); |
| 1359 | 4978 | acydburn | } |
| 1360 | 4978 | acydburn | } |
| 1361 | 4978 | acydburn | |
| 1362 | 6048 | acydburn | /**
|
| 1363 | 6048 | acydburn | * Parse Attachments |
| 1364 | 6048 | acydburn | */ |
| 1365 | 10186 | nickvergessen | function parse_attachments($form_name, $mode, $forum_id, $submit, $preview, $refresh, $is_message = false) |
| 1366 | 3572 | acydburn | {
|
| 1367 | 6364 | acydburn | global $config, $auth, $user, $phpbb_root_path, $phpEx, $db; |
| 1368 | 3572 | acydburn | |
| 1369 | 4005 | acydburn | $error = array(); |
| 1370 | 3697 | acydburn | |
| 1371 | 4883 | acydburn | $num_attachments = sizeof($this->attachment_data); |
| 1372 | 6584 | acydburn | $this->filename_data['filecomment'] = utf8_normalize_nfc(request_var('filecomment', '', true)); |
| 1373 | 5109 | acydburn | $upload_file = (isset($_FILES[$form_name]) && $_FILES[$form_name]['name'] != 'none' && trim($_FILES[$form_name]['name'])) ? true : false; |
| 1374 | 5109 | acydburn | |
| 1375 | 5790 | acydburn | $add_file = (isset($_POST['add_file'])) ? true : false; |
| 1376 | 5790 | acydburn | $delete_file = (isset($_POST['delete_file'])) ? true : false; |
| 1377 | 3697 | acydburn | |
| 1378 | 6803 | acydburn | // First of all adjust comments if changed
|
| 1379 | 6803 | acydburn | $actual_comment_list = utf8_normalize_nfc(request_var('comment_list', array(''), true)); |
| 1380 | 6803 | acydburn | |
| 1381 | 6803 | acydburn | foreach ($actual_comment_list as $comment_key => $comment) |
| 1382 | 6803 | acydburn | {
|
| 1383 | 6803 | acydburn | if (!isset($this->attachment_data[$comment_key])) |
| 1384 | 6803 | acydburn | {
|
| 1385 | 6803 | acydburn | continue;
|
| 1386 | 6803 | acydburn | } |
| 1387 | 6803 | acydburn | |
| 1388 | 6803 | acydburn | if ($this->attachment_data[$comment_key]['attach_comment'] != $actual_comment_list[$comment_key]) |
| 1389 | 6803 | acydburn | {
|
| 1390 | 6803 | acydburn | $this->attachment_data[$comment_key]['attach_comment'] = $actual_comment_list[$comment_key]; |
| 1391 | 6803 | acydburn | } |
| 1392 | 6803 | acydburn | } |
| 1393 | 6803 | acydburn | |
| 1394 | 4883 | acydburn | $cfg = array(); |
| 1395 | 4883 | acydburn | $cfg['max_attachments'] = ($is_message) ? $config['max_attachments_pm'] : $config['max_attachments']; |
| 1396 | 4883 | acydburn | $forum_id = ($is_message) ? 0 : $forum_id; |
| 1397 | 4883 | acydburn | |
| 1398 | 5109 | acydburn | if ($submit && in_array($mode, array('post', 'reply', 'quote', 'edit')) && $upload_file) |
| 1399 | 3697 | acydburn | {
|
| 1400 | 6063 | naderman | if ($num_attachments < $cfg['max_attachments'] || $auth->acl_get('a_') || $auth->acl_get('m_', $forum_id)) |
| 1401 | 3697 | acydburn | {
|
| 1402 | 5109 | acydburn | $filedata = upload_attachment($form_name, $forum_id, false, '', $is_message); |
| 1403 | 4005 | acydburn | $error = $filedata['error']; |
| 1404 | 3697 | acydburn | |
| 1405 | 4883 | acydburn | if ($filedata['post_attach'] && !sizeof($error)) |
| 1406 | 3697 | acydburn | {
|
| 1407 | 6364 | acydburn | $sql_ary = array( |
| 1408 | 5109 | acydburn | 'physical_filename' => $filedata['physical_filename'], |
| 1409 | 6177 | acydburn | 'attach_comment' => $this->filename_data['filecomment'], |
| 1410 | 5109 | acydburn | 'real_filename' => $filedata['real_filename'], |
| 1411 | 4160 | acydburn | 'extension' => $filedata['extension'], |
| 1412 | 4160 | acydburn | 'mimetype' => $filedata['mimetype'], |
| 1413 | 4160 | acydburn | 'filesize' => $filedata['filesize'], |
| 1414 | 4160 | acydburn | 'filetime' => $filedata['filetime'], |
| 1415 | 6364 | acydburn | 'thumbnail' => $filedata['thumbnail'], |
| 1416 | 6364 | acydburn | 'is_orphan' => 1, |
| 1417 | 6364 | acydburn | 'in_message' => ($is_message) ? 1 : 0, |
| 1418 | 6364 | acydburn | 'poster_id' => $user->data['user_id'], |
| 1419 | 3960 | acydburn | ); |
| 1420 | 3697 | acydburn | |
| 1421 | 6364 | acydburn | $db->sql_query('INSERT INTO ' . ATTACHMENTS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary)); |
| 1422 | 6364 | acydburn | |
| 1423 | 6364 | acydburn | $new_entry = array( |
| 1424 | 6364 | acydburn | 'attach_id' => $db->sql_nextid(), |
| 1425 | 6364 | acydburn | 'is_orphan' => 1, |
| 1426 | 6364 | acydburn | 'real_filename' => $filedata['real_filename'], |
| 1427 | 6364 | acydburn | 'attach_comment'=> $this->filename_data['filecomment'], |
| 1428 | 6364 | acydburn | ); |
| 1429 | 6364 | acydburn | |
| 1430 | 3960 | acydburn | $this->attachment_data = array_merge(array(0 => $new_entry), $this->attachment_data); |
| 1431 | 4819 | acydburn | $this->message = preg_replace('#\[attachment=([0-9]+)\](.*?)\[\/attachment\]#e', "'[attachment='.(\\1 + 1).']\\2[/attachment]'", $this->message); |
| 1432 | 6048 | acydburn | |
| 1433 | 3960 | acydburn | $this->filename_data['filecomment'] = ''; |
| 1434 | 3697 | acydburn | |
| 1435 | 4767 | acydburn | // This Variable is set to false here, because Attachments are entered into the
|
| 1436 | 4540 | acydburn | // Database in two modes, one if the id_list is 0 and the second one if post_attach is true
|
| 1437 | 3697 | acydburn | // Since post_attach is automatically switched to true if an Attachment got added to the filesystem,
|
| 1438 | 4540 | acydburn | // but we are assigning an id of 0 here, we have to reset the post_attach variable to false.
|
| 1439 | 3697 | acydburn | //
|
| 1440 | 3697 | acydburn | // This is very relevant, because it could happen that the post got not submitted, but we do not
|
| 1441 | 3697 | acydburn | // know this circumstance here. We could be at the posting page or we could be redirected to the entered
|
| 1442 | 3697 | acydburn | // post. :)
|
| 1443 | 4767 | acydburn | $filedata['post_attach'] = false; |
| 1444 | 3697 | acydburn | } |
| 1445 | 3697 | acydburn | } |
| 1446 | 3697 | acydburn | else
|
| 1447 | 3697 | acydburn | {
|
| 1448 | 4883 | acydburn | $error[] = sprintf($user->lang['TOO_MANY_ATTACHMENTS'], $cfg['max_attachments']); |
| 1449 | 3697 | acydburn | } |
| 1450 | 3697 | acydburn | } |
| 1451 | 3697 | acydburn | |
| 1452 | 4984 | acydburn | if ($preview || $refresh || sizeof($error)) |
| 1453 | 3697 | acydburn | {
|
| 1454 | 3697 | acydburn | // Perform actions on temporary attachments
|
| 1455 | 3697 | acydburn | if ($delete_file) |
| 1456 | 3697 | acydburn | {
|
| 1457 | 5595 | acydburn | include_once($phpbb_root_path . 'includes/functions_admin.' . $phpEx); |
| 1458 | 5595 | acydburn | |
| 1459 | 8033 | acydburn | $index = array_keys(request_var('delete_file', array(0 => 0))); |
| 1460 | 8035 | naderman | $index = (!empty($index)) ? $index[0] : false; |
| 1461 | 4510 | acydburn | |
| 1462 | 8033 | acydburn | if ($index !== false && !empty($this->attachment_data[$index])) |
| 1463 | 3697 | acydburn | {
|
| 1464 | 6364 | acydburn | // delete selected attachment
|
| 1465 | 6364 | acydburn | if ($this->attachment_data[$index]['is_orphan']) |
| 1466 | 3960 | acydburn | {
|
| 1467 | 6364 | acydburn | $sql = 'SELECT attach_id, physical_filename, thumbnail |
| 1468 | 6364 | acydburn | FROM ' . ATTACHMENTS_TABLE . ' |
| 1469 | 6364 | acydburn | WHERE attach_id = ' . (int) $this->attachment_data[$index]['attach_id'] . ' |
| 1470 | 6364 | acydburn | AND is_orphan = 1 |
| 1471 | 6364 | acydburn | AND poster_id = ' . $user->data['user_id']; |
| 1472 | 6364 | acydburn | $result = $db->sql_query($sql); |
| 1473 | 6364 | acydburn | $row = $db->sql_fetchrow($result); |
| 1474 | 6364 | acydburn | $db->sql_freeresult($result); |
| 1475 | 6364 | acydburn | |
| 1476 | 6364 | acydburn | if ($row) |
| 1477 | 6364 | acydburn | {
|
| 1478 | 6364 | acydburn | phpbb_unlink($row['physical_filename'], 'file'); |
| 1479 | 6364 | acydburn | |
| 1480 | 6364 | acydburn | if ($row['thumbnail']) |
| 1481 | 6364 | acydburn | {
|
| 1482 | 6364 | acydburn | phpbb_unlink($row['physical_filename'], 'thumbnail'); |
| 1483 | 6364 | acydburn | } |
| 1484 | 6364 | acydburn | |
| 1485 | 6364 | acydburn | $db->sql_query('DELETE FROM ' . ATTACHMENTS_TABLE . ' WHERE attach_id = ' . (int) $this->attachment_data[$index]['attach_id']); |
| 1486 | 6364 | acydburn | } |
| 1487 | 3960 | acydburn | } |
| 1488 | 6364 | acydburn | else
|
| 1489 | 6364 | acydburn | {
|
| 1490 | 6364 | acydburn | delete_attachments('attach', array(intval($this->attachment_data[$index]['attach_id']))); |
| 1491 | 6364 | acydburn | } |
| 1492 | 6048 | acydburn | |
| 1493 | 6364 | acydburn | unset($this->attachment_data[$index]); |
| 1494 | 6364 | acydburn | $this->message = preg_replace('#\[attachment=([0-9]+)\](.*?)\[\/attachment\]#e', "(\\1 == \$index) ? '' : ((\\1 > \$index) ? '[attachment=' . (\\1 - 1) . ']\\2[/attachment]' : '\\0')", $this->message); |
| 1495 | 4819 | acydburn | |
| 1496 | 6364 | acydburn | // Reindex Array
|
| 1497 | 6364 | acydburn | $this->attachment_data = array_values($this->attachment_data); |
| 1498 | 6364 | acydburn | } |
| 1499 | 3697 | acydburn | } |
| 1500 | 6803 | acydburn | else if (($add_file || $preview) && $upload_file) |
| 1501 | 3697 | acydburn | {
|
| 1502 | 6803 | acydburn | if ($num_attachments < $cfg['max_attachments'] || $auth->acl_gets('m_', 'a_', $forum_id)) |
| 1503 | 3697 | acydburn | {
|
| 1504 | 6803 | acydburn | $filedata = upload_attachment($form_name, $forum_id, false, '', $is_message); |
| 1505 | 6803 | acydburn | $error = array_merge($error, $filedata['error']); |
| 1506 | 5790 | acydburn | |
| 1507 | 6803 | acydburn | if (!sizeof($error)) |
| 1508 | 3697 | acydburn | {
|
| 1509 | 6803 | acydburn | $sql_ary = array( |
| 1510 | 6803 | acydburn | 'physical_filename' => $filedata['physical_filename'], |
| 1511 | 6803 | acydburn | 'attach_comment' => $this->filename_data['filecomment'], |
| 1512 | 6803 | acydburn | 'real_filename' => $filedata['real_filename'], |
| 1513 | 6803 | acydburn | 'extension' => $filedata['extension'], |
| 1514 | 6803 | acydburn | 'mimetype' => $filedata['mimetype'], |
| 1515 | 6803 | acydburn | 'filesize' => $filedata['filesize'], |
| 1516 | 6803 | acydburn | 'filetime' => $filedata['filetime'], |
| 1517 | 6803 | acydburn | 'thumbnail' => $filedata['thumbnail'], |
| 1518 | 10186 | nickvergessen | 'is_orphan' => 1, |
| 1519 | 6803 | acydburn | 'in_message' => ($is_message) ? 1 : 0, |
| 1520 | 6803 | acydburn | 'poster_id' => $user->data['user_id'], |
| 1521 | 6803 | acydburn | ); |
| 1522 | 3697 | acydburn | |
| 1523 | 6803 | acydburn | $db->sql_query('INSERT INTO ' . ATTACHMENTS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary)); |
| 1524 | 3697 | acydburn | |
| 1525 | 6803 | acydburn | $new_entry = array( |
| 1526 | 6803 | acydburn | 'attach_id' => $db->sql_nextid(), |
| 1527 | 10186 | nickvergessen | 'is_orphan' => 1, |
| 1528 | 6803 | acydburn | 'real_filename' => $filedata['real_filename'], |
| 1529 | 6803 | acydburn | 'attach_comment'=> $this->filename_data['filecomment'], |
| 1530 | 6803 | acydburn | ); |
| 1531 | 6364 | acydburn | |
| 1532 | 6803 | acydburn | $this->attachment_data = array_merge(array(0 => $new_entry), $this->attachment_data); |
| 1533 | 6803 | acydburn | $this->message = preg_replace('#\[attachment=([0-9]+)\](.*?)\[\/attachment\]#e', "'[attachment='.(\\1 + 1).']\\2[/attachment]'", $this->message); |
| 1534 | 6803 | acydburn | $this->filename_data['filecomment'] = ''; |
| 1535 | 3697 | acydburn | } |
| 1536 | 3697 | acydburn | } |
| 1537 | 6803 | acydburn | else
|
| 1538 | 6803 | acydburn | {
|
| 1539 | 6803 | acydburn | $error[] = sprintf($user->lang['TOO_MANY_ATTACHMENTS'], $cfg['max_attachments']); |
| 1540 | 6803 | acydburn | } |
| 1541 | 3697 | acydburn | } |
| 1542 | 3697 | acydburn | } |
| 1543 | 3697 | acydburn | |
| 1544 | 4045 | ludovic_arnaud | foreach ($error as $error_msg) |
| 1545 | 4045 | ludovic_arnaud | {
|
| 1546 | 4045 | ludovic_arnaud | $this->warn_msg[] = $error_msg; |
| 1547 | 4045 | ludovic_arnaud | } |
| 1548 | 3572 | acydburn | } |
| 1549 | 3572 | acydburn | |
| 1550 | 5790 | acydburn | /**
|
| 1551 | 5790 | acydburn | * Get Attachment Data |
| 1552 | 5790 | acydburn | */ |
| 1553 | 6014 | acydburn | function get_submitted_attachment_data($check_user_id = false) |
| 1554 | 4883 | acydburn | {
|
| 1555 | 5790 | acydburn | global $user, $db, $phpbb_root_path, $phpEx, $config; |
| 1556 | 5790 | acydburn | |
| 1557 | 6584 | acydburn | $this->filename_data['filecomment'] = utf8_normalize_nfc(request_var('filecomment', '', true)); |
| 1558 | 6364 | acydburn | $attachment_data = (isset($_POST['attachment_data'])) ? $_POST['attachment_data'] : array(); |
| 1559 | 6364 | acydburn | $this->attachment_data = array(); |
| 1560 | 4883 | acydburn | |
| 1561 | 6014 | acydburn | $check_user_id = ($check_user_id === false) ? $user->data['user_id'] : $check_user_id; |
| 1562 | 6014 | acydburn | |
| 1563 | 6364 | acydburn | if (!sizeof($attachment_data)) |
| 1564 | 6364 | acydburn | {
|
| 1565 | 6364 | acydburn | return;
|
| 1566 | 6364 | acydburn | } |
| 1567 | 5790 | acydburn | |
| 1568 | 6364 | acydburn | $not_orphan = $orphan = array(); |
| 1569 | 6364 | acydburn | |
| 1570 | 6364 | acydburn | foreach ($attachment_data as $pos => $var_ary) |
| 1571 | 4883 | acydburn | {
|
| 1572 | 6364 | acydburn | if ($var_ary['is_orphan']) |
| 1573 | 4883 | acydburn | {
|
| 1574 | 6364 | acydburn | $orphan[(int) $var_ary['attach_id']] = $pos; |
| 1575 | 5790 | acydburn | } |
| 1576 | 5790 | acydburn | else
|
| 1577 | 5790 | acydburn | {
|
| 1578 | 6364 | acydburn | $not_orphan[(int) $var_ary['attach_id']] = $pos; |
| 1579 | 5790 | acydburn | } |
| 1580 | 5790 | acydburn | } |
| 1581 | 5790 | acydburn | |
| 1582 | 6364 | acydburn | // Regenerate already posted attachments
|
| 1583 | 6364 | acydburn | if (sizeof($not_orphan)) |
| 1584 | 5790 | acydburn | {
|
| 1585 | 6364 | acydburn | // Get the attachment data, based on the poster id...
|
| 1586 | 6364 | acydburn | $sql = 'SELECT attach_id, is_orphan, real_filename, attach_comment |
| 1587 | 5790 | acydburn | FROM ' . ATTACHMENTS_TABLE . ' |
| 1588 | 6364 | acydburn | WHERE ' . $db->sql_in_set('attach_id', array_keys($not_orphan)) . ' |
| 1589 | 6014 | acydburn | AND poster_id = ' . $check_user_id; |
| 1590 | 5790 | acydburn | $result = $db->sql_query($sql); |
| 1591 | 5790 | acydburn | |
| 1592 | 5790 | acydburn | while ($row = $db->sql_fetchrow($result)) |
| 1593 | 5790 | acydburn | {
|
| 1594 | 6364 | acydburn | $pos = $not_orphan[$row['attach_id']]; |
| 1595 | 6364 | acydburn | $this->attachment_data[$pos] = $row; |
| 1596 | 6364 | acydburn | set_var($this->attachment_data[$pos]['attach_comment'], $_POST['attachment_data'][$pos]['attach_comment'], 'string', true); |
| 1597 | 5790 | acydburn | |
| 1598 | 6364 | acydburn | unset($not_orphan[$row['attach_id']]); |
| 1599 | 5790 | acydburn | } |
| 1600 | 5790 | acydburn | $db->sql_freeresult($result); |
| 1601 | 6364 | acydburn | } |
| 1602 | 5790 | acydburn | |
| 1603 | 6364 | acydburn | if (sizeof($not_orphan)) |
| 1604 | 6364 | acydburn | {
|
| 1605 | 7919 | kellanved | trigger_error('NO_ACCESS_ATTACHMENT', E_USER_ERROR); |
| 1606 | 5790 | acydburn | } |
| 1607 | 5790 | acydburn | |
| 1608 | 5790 | acydburn | // Regenerate newly uploaded attachments
|
| 1609 | 6364 | acydburn | if (sizeof($orphan)) |
| 1610 | 5790 | acydburn | {
|
| 1611 | 6364 | acydburn | $sql = 'SELECT attach_id, is_orphan, real_filename, attach_comment |
| 1612 | 6271 | acydburn | FROM ' . ATTACHMENTS_TABLE . ' |
| 1613 | 6364 | acydburn | WHERE ' . $db->sql_in_set('attach_id', array_keys($orphan)) . ' |
| 1614 | 6364 | acydburn | AND poster_id = ' . $user->data['user_id'] . ' |
| 1615 | 6364 | acydburn | AND is_orphan = 1';
|
| 1616 | 6364 | acydburn | $result = $db->sql_query($sql); |
| 1617 | 5790 | acydburn | |
| 1618 | 6364 | acydburn | while ($row = $db->sql_fetchrow($result)) |
| 1619 | 5790 | acydburn | {
|
| 1620 | 6364 | acydburn | $pos = $orphan[$row['attach_id']]; |
| 1621 | 6364 | acydburn | $this->attachment_data[$pos] = $row; |
| 1622 | 6177 | acydburn | set_var($this->attachment_data[$pos]['attach_comment'], $_POST['attachment_data'][$pos]['attach_comment'], 'string', true); |
| 1623 | 5790 | acydburn | |
| 1624 | 6364 | acydburn | unset($orphan[$row['attach_id']]); |
| 1625 | 4883 | acydburn | } |
| 1626 | 6364 | acydburn | $db->sql_freeresult($result); |
| 1627 | 4883 | acydburn | } |
| 1628 | 6364 | acydburn | |
| 1629 | 6364 | acydburn | if (sizeof($orphan)) |
| 1630 | 6364 | acydburn | {
|
| 1631 | 7919 | kellanved | trigger_error('NO_ACCESS_ATTACHMENT', E_USER_ERROR); |
| 1632 | 6364 | acydburn | } |
| 1633 | 6364 | acydburn | |
| 1634 | 6364 | acydburn | ksort($this->attachment_data); |
| 1635 | 4883 | acydburn | } |
| 1636 | 6048 | acydburn | |
| 1637 | 6048 | acydburn | /**
|
| 1638 | 6048 | acydburn | * Parse Poll |
| 1639 | 6048 | acydburn | */ |
| 1640 | 4981 | acydburn | function parse_poll(&$poll) |
| 1641 | 3631 | acydburn | {
|
| 1642 | 4981 | acydburn | global $auth, $user, $config; |
| 1643 | 3631 | acydburn | |
| 1644 | 4981 | acydburn | $poll_max_options = $poll['poll_max_options']; |
| 1645 | 3631 | acydburn | |
| 1646 | 4981 | acydburn | // Parse Poll Option text ;)
|
| 1647 | 4981 | acydburn | $tmp_message = $this->message; |
| 1648 | 4981 | acydburn | $this->message = $poll['poll_option_text']; |
| 1649 | 7747 | davidmj | $bbcode_bitfield = $this->bbcode_bitfield; |
| 1650 | 4503 | acydburn | |
| 1651 | 9892 | nickvergessen | $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'); |
| 1652 | 6048 | acydburn | |
| 1653 | 8039 | davidmj | $bbcode_bitfield = base64_encode(base64_decode($bbcode_bitfield) | base64_decode($this->bbcode_bitfield)); |
| 1654 | 4981 | acydburn | $this->message = $tmp_message; |
| 1655 | 3631 | acydburn | |
| 1656 | 4981 | acydburn | // Parse Poll Title
|
| 1657 | 4981 | acydburn | $tmp_message = $this->message; |
| 1658 | 4981 | acydburn | $this->message = $poll['poll_title']; |
| 1659 | 7747 | davidmj | $this->bbcode_bitfield = $bbcode_bitfield; |
| 1660 | 4184 | acydburn | |
| 1661 | 6735 | davidmj | $poll['poll_options'] = explode("\n", trim($poll['poll_option_text'])); |
| 1662 | 6735 | davidmj | $poll['poll_options_size'] = sizeof($poll['poll_options']); |
| 1663 | 6209 | davidmj | |
| 1664 | 6735 | davidmj | if (!$poll['poll_title'] && $poll['poll_options_size']) |
| 1665 | 6735 | davidmj | {
|
| 1666 | 6735 | davidmj | $this->warn_msg[] = $user->lang['NO_POLL_TITLE']; |
| 1667 | 6735 | davidmj | } |
| 1668 | 6735 | davidmj | else
|
| 1669 | 6735 | davidmj | {
|
| 1670 | 7036 | davidmj | if (utf8_strlen(preg_replace('#\[\/?[a-z\*\+\-]+(=[\S]+)?\]#ius', ' ', $this->message)) > 100) |
| 1671 | 7036 | davidmj | {
|
| 1672 | 7036 | davidmj | $this->warn_msg[] = $user->lang['POLL_TITLE_TOO_LONG']; |
| 1673 | 7036 | davidmj | } |
| 1674 | 9892 | nickvergessen | $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 | 7036 | davidmj | if (strlen($poll['poll_title']) > 255) |
| 1676 | 7036 | davidmj | {
|
| 1677 | 7036 | davidmj | $this->warn_msg[] = $user->lang['POLL_TITLE_COMP_TOO_LONG']; |
| 1678 | 7036 | davidmj | } |
| 1679 | 6735 | davidmj | } |
| 1680 | 4981 | acydburn | |
| 1681 | 7747 | davidmj | $this->bbcode_bitfield = base64_encode(base64_decode($bbcode_bitfield) | base64_decode($this->bbcode_bitfield)); |
| 1682 | 4981 | acydburn | $this->message = $tmp_message; |
| 1683 | 7747 | davidmj | unset($tmp_message); |
| 1684 | 4981 | acydburn | |
| 1685 | 4981 | acydburn | if (sizeof($poll['poll_options']) == 1) |
| 1686 | 4981 | acydburn | {
|
| 1687 | 4981 | acydburn | $this->warn_msg[] = $user->lang['TOO_FEW_POLL_OPTIONS']; |
| 1688 | 3631 | acydburn | } |
| 1689 | 4981 | acydburn | else if ($poll['poll_options_size'] > (int) $config['max_poll_options']) |
| 1690 | 4981 | acydburn | {
|
| 1691 | 4981 | acydburn | $this->warn_msg[] = $user->lang['TOO_MANY_POLL_OPTIONS']; |
| 1692 | 4981 | acydburn | } |
| 1693 | 4981 | acydburn | else if ($poll_max_options > $poll['poll_options_size']) |
| 1694 | 4981 | acydburn | {
|
| 1695 | 4981 | acydburn | $this->warn_msg[] = $user->lang['TOO_MANY_USER_OPTIONS']; |
| 1696 | 4981 | acydburn | } |
| 1697 | 3920 | psotfx | |
| 1698 | 4981 | acydburn | $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']); |
| 1699 | 3631 | acydburn | } |
| 1700 | 3572 | acydburn | } |
| 1701 | 3572 | acydburn | |
| 1702 | 3572 | acydburn | ?> |

