diff --git a/phpBB/develop/check_flash_bbcodes.php b/phpBB/develop/check_flash_bbcodes.php new file mode 100644 index 0000000000..b0fa399209 --- /dev/null +++ b/phpBB/develop/check_flash_bbcodes.php @@ -0,0 +1,163 @@ + ''"; + + $result = $db->sql_query($sql); + while ($row = $db->sql_fetchrow($result)) + { + $uid = $row[$uid_field]; + + // thanks support toolkit + $content = html_entity_decode_utf8($row[$content_field]); + set_var($content, $content, 'string', true); + $content = utf8_normalize_nfc($content); + + $bitfield_data = $row[$bitfield_field]; + + if (!is_valid_flash_bbcode($content, $uid) && has_flash_enabled($bitfield_data)) + { + $ids[] = (int) $row[$id_field]; + } + } + $db->sql_freeresult($result); + + return $ids; +} + +function get_flash_regex($uid) +{ + return "#\[flash=([0-9]+),([0-9]+):$uid\](.*?)\[/flash:$uid\]#"; +} + +// extract all valid flash bbcodes +// check if the bbcode content is a valid URL for each match +function is_valid_flash_bbcode($cleaned_content, $uid) +{ + $regex = get_flash_regex($uid); + + $url_regex = get_preg_expression('url'); + $www_url_regex = get_preg_expression('www_url'); + + if (preg_match_all($regex, $cleaned_content, $matches)) + { + foreach ($matches[3] as $flash_url) + { + if (!preg_match("#^($url_regex|$www_url_regex)$#i", $flash_url)) + { + return false; + } + } + } + + return true; +} + +// check if a bitfield includes flash +// 11 = flash bit +function has_flash_enabled($bitfield_data) +{ + $bitfield = new bitfield($bitfield_data); + return $bitfield->get(11); +} + +// taken from support toolkit +function html_entity_decode_utf8($string) +{ + static $trans_tbl; + + // replace numeric entities + $string = preg_replace('~&#x([0-9a-f]+);~ei', 'code2utf8(hexdec("\\1"))', $string); + $string = preg_replace('~&#([0-9]+);~e', 'code2utf8(\\1)', $string); + + // replace literal entities + if (!isset($trans_tbl)) + { + $trans_tbl = array(); + + foreach (get_html_translation_table(HTML_ENTITIES) as $val=>$key) + $trans_tbl[$key] = utf8_encode($val); + } + return strtr($string, $trans_tbl); +} + +// taken from support toolkit +// Returns the utf string corresponding to the unicode value (from php.net, courtesy - romans@void.lv) +function code2utf8($num) +{ + if ($num < 128) return chr($num); + if ($num < 2048) return chr(($num >> 6) + 192) . chr(($num & 63) + 128); + if ($num < 65536) return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); + if ($num < 2097152) return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); + return ''; +}