diff options
author | David M <davidmj@users.sourceforge.net> | 2006-08-11 21:52:46 +0000 |
---|---|---|
committer | David M <davidmj@users.sourceforge.net> | 2006-08-11 21:52:46 +0000 |
commit | 86f3d738a0efbf5c50bdf112841aba2c8b859e85 (patch) | |
tree | 6c7c34285132704577420d8f6b56545523018c71 /phpBB/includes | |
parent | 9086adad3c5fb9454a6df9149fb3f4ab7987b8ef (diff) | |
download | forums-86f3d738a0efbf5c50bdf112841aba2c8b859e85.tar forums-86f3d738a0efbf5c50bdf112841aba2c8b859e85.tar.gz forums-86f3d738a0efbf5c50bdf112841aba2c8b859e85.tar.bz2 forums-86f3d738a0efbf5c50bdf112841aba2c8b859e85.tar.xz forums-86f3d738a0efbf5c50bdf112841aba2c8b859e85.zip |
so.... what does this thing do?
well, the super fast, ultra efficient, massively huge BBCode handling system was implemented differently on each DBMS. Although this provided the best performance, the solution was a bit hacky.
So what does this new thing do? We use base64 encoding to make everything nice and shiny, it turns into nice, safe characters that we can just jam into varchars on essentially any database. This has two implications: we must decode every bitfield we get AND we have slightly fewer IDs to work with. It goes down from 2040 BBCodes to 1512. We lose like a quarter of them :P
P.S. I hope nothing broke :P
git-svn-id: file:///svn/phpbb/trunk@6263 89ea8834-ac86-4346-8a33-228a782c2dd0
Diffstat (limited to 'phpBB/includes')
-rw-r--r-- | phpBB/includes/bbcode.php | 3 | ||||
-rw-r--r-- | phpBB/includes/db/dbal.php | 9 | ||||
-rw-r--r-- | phpBB/includes/db/mssql.php | 10 | ||||
-rw-r--r-- | phpBB/includes/db/mssql_odbc.php | 8 | ||||
-rw-r--r-- | phpBB/includes/db/mysql.php | 10 | ||||
-rw-r--r-- | phpBB/includes/db/mysql4.php | 10 | ||||
-rw-r--r-- | phpBB/includes/db/mysqli.php | 10 | ||||
-rw-r--r-- | phpBB/includes/db/postgres.php | 8 | ||||
-rw-r--r-- | phpBB/includes/db/sqlite.php | 41 | ||||
-rw-r--r-- | phpBB/includes/functions.php | 7 | ||||
-rw-r--r-- | phpBB/includes/functions_posting.php | 2 | ||||
-rw-r--r-- | phpBB/includes/mcp/mcp_main.php | 2 | ||||
-rw-r--r-- | phpBB/includes/mcp/mcp_topic.php | 2 | ||||
-rwxr-xr-x | phpBB/includes/mcp/mcp_warn.php | 2 | ||||
-rw-r--r-- | phpBB/includes/message_parser.php | 2 | ||||
-rw-r--r-- | phpBB/includes/ucp/ucp_pm_viewmessage.php | 2 |
16 files changed, 15 insertions, 113 deletions
diff --git a/phpBB/includes/bbcode.php b/phpBB/includes/bbcode.php index 96efad10f8..f8fbbc2d3e 100644 --- a/phpBB/includes/bbcode.php +++ b/phpBB/includes/bbcode.php @@ -28,7 +28,7 @@ class bbcode * Constructor * Init bbcode cache entries if bitfield is specified */ - function bbcode($bitfield = 0) + function bbcode($bitfield = '') { if ($bitfield) { @@ -126,7 +126,6 @@ class bbcode $sql = ''; $bbcode_ids = $rowset = array(); - $bitlen = strlen(decbin($this->bbcode_bitfield)); $bitfield = new bitfield($this->bbcode_bitfield); $bbcodes_set = $bitfield->get_all_set(); diff --git a/phpBB/includes/db/dbal.php b/phpBB/includes/db/dbal.php index 0dd04c1a7b..b12ff81e0f 100644 --- a/phpBB/includes/db/dbal.php +++ b/phpBB/includes/db/dbal.php @@ -199,14 +199,7 @@ class dbal } else if (is_string($var)) { - if (strpos($key, 'bitfield') === false) - { - $values[] = "'" . $this->sql_escape($var) . "'"; - } - else - { - $values[] = $this->sql_escape_binary($var); - } + $values[] = "'" . $this->sql_escape($var) . "'"; } else if (is_array($var) && is_string($var[0])) { diff --git a/phpBB/includes/db/mssql.php b/phpBB/includes/db/mssql.php index 0e8cc318f1..fe6cf75b12 100644 --- a/phpBB/includes/db/mssql.php +++ b/phpBB/includes/db/mssql.php @@ -256,7 +256,7 @@ class dbal_mssql extends dbal { foreach ($row as $key => $value) { - $row[$key] = ($value === ' ' && strpos($key, 'bitfield') === false) ? '' : $value; + $row[$key] = ($value === ' ') ? '' : $value; } } @@ -370,14 +370,6 @@ class dbal_mssql extends dbal } /** - * Escape string used in sql query - */ - function sql_escape_binary($msg) - { - return "CAST('" . $msg . "' AS varbinary)"; - } - - /** * return sql error array * @access: private */ diff --git a/phpBB/includes/db/mssql_odbc.php b/phpBB/includes/db/mssql_odbc.php index 38ed91cd55..e1b2675a23 100644 --- a/phpBB/includes/db/mssql_odbc.php +++ b/phpBB/includes/db/mssql_odbc.php @@ -380,14 +380,6 @@ class dbal_mssql_odbc extends dbal } /** - * Escape string used in sql query - */ - function sql_escape_binary($msg) - { - return "CAST('" . $msg . "' AS varbinary)"; - } - - /** * Build db-specific query data * @access: private */ diff --git a/phpBB/includes/db/mysql.php b/phpBB/includes/db/mysql.php index ee7918473d..7e363721a9 100644 --- a/phpBB/includes/db/mysql.php +++ b/phpBB/includes/db/mysql.php @@ -328,16 +328,6 @@ class dbal_mysql extends dbal return @mysql_real_escape_string($msg, $this->db_connect_id); } - function sql_escape_binary($msg) - { - // If the last char is - if (substr($msg, -1) == ' ') - { - $msg .= "\0"; - } - return "'" . $this->sql_escape($msg) . "'"; - } - /** * Build db-specific query data * @access: private diff --git a/phpBB/includes/db/mysql4.php b/phpBB/includes/db/mysql4.php index c63d5fb064..071f4c4b55 100644 --- a/phpBB/includes/db/mysql4.php +++ b/phpBB/includes/db/mysql4.php @@ -331,16 +331,6 @@ class dbal_mysql4 extends dbal return @mysql_real_escape_string($msg, $this->db_connect_id); } - function sql_escape_binary($msg) - { - // If the last char is - if (substr($msg, -1) == ' ') - { - $msg .= "\0"; - } - return "'" . $this->sql_escape($msg) . "'"; - } - /** * Build db-specific query data * @access: private diff --git a/phpBB/includes/db/mysqli.php b/phpBB/includes/db/mysqli.php index 46ddd55569..fa4d3ffdc7 100644 --- a/phpBB/includes/db/mysqli.php +++ b/phpBB/includes/db/mysqli.php @@ -311,16 +311,6 @@ class dbal_mysqli extends dbal return @mysqli_real_escape_string($this->db_connect_id, $msg); } - function sql_escape_binary($msg) - { - // If the last char is - if (substr($msg, -1) == ' ') - { - $msg .= "\0"; - } - return "'" . $this->sql_escape($msg) . "'"; - } - /** * Build db-specific query data * @access: private diff --git a/phpBB/includes/db/postgres.php b/phpBB/includes/db/postgres.php index 68dc396232..1836952346 100644 --- a/phpBB/includes/db/postgres.php +++ b/phpBB/includes/db/postgres.php @@ -397,14 +397,6 @@ class dbal_postgres extends dbal } /** - * Escape string used in sql query - */ - function sql_escape_binary($msg) - { - return "'" . @pg_escape_bytea($msg) . "'"; - } - - /** * return sql error array * @access: private */ diff --git a/phpBB/includes/db/sqlite.php b/phpBB/includes/db/sqlite.php index c203af9f67..cd6d40e3c7 100644 --- a/phpBB/includes/db/sqlite.php +++ b/phpBB/includes/db/sqlite.php @@ -49,7 +49,6 @@ class dbal_sqlite extends dbal @sqlite_query('PRAGMA short_column_names = 1', $this->db_connect_id); } - sqlite_create_function($this->db_connect_id, 'binary_insert', array('dbal_sqlite', '_sql_insert'), 1); return ($this->db_connect_id) ? true : array('message' => $error); } @@ -217,13 +216,6 @@ class dbal_sqlite extends dbal } $row = @sqlite_fetch_array($query_id, SQLITE_ASSOC); - if ($row) - { - foreach ($row as $key => $value) - { - $row[$key] = (strpos($key, 'bitfield') === false) ? $value : sqlite_udf_decode_binary($value); - } - } return $row; } @@ -317,14 +309,6 @@ class dbal_sqlite extends dbal } /** - * Escape string used in sql query - */ - function sql_escape_binary($msg) - { - return "'" . @sqlite_udf_encode_binary($msg) . "'"; - } - - /** * return sql error array * @access: private */ @@ -384,31 +368,6 @@ class dbal_sqlite extends dbal } } - /** - * Build the proper binary string used for the default - * @access: private - */ - function _sql_insert($mode) - { - if ($mode == 1) - { - $bitfield = new bitfield(); - $bitfield->set(0); - $bitfield->set(3); - $bitfield->set(8); - $bitfield->set(9); - $bitfield->set(11); - $bitfield->set(12); - return sqlite_udf_encode_binary($bitfield->data); - } - /* - else - { - return sqlite_udf_encode_binary("\0"); - } - */ - } - } } // if ... define diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 48336727f0..a676a717ff 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -3012,7 +3012,7 @@ class bitfield function bitfield($bitfield = '') { - $this->data = $bitfield; + $this->data = base64_decode($bitfield); } /** @@ -3072,6 +3072,11 @@ class bitfield return $this->data; } + function get_base64() + { + return base64_encode($this->data); + } + function get_bin() { $bin = ''; diff --git a/phpBB/includes/functions_posting.php b/phpBB/includes/functions_posting.php index 3fe1fbab9f..1e3fd877b3 100644 --- a/phpBB/includes/functions_posting.php +++ b/phpBB/includes/functions_posting.php @@ -842,7 +842,7 @@ function topic_review($topic_id, $forum_id, $mode = 'topic_review', $cur_post_id do { $rowset[] = $row; - $bbcode_bitfield = $bbcode_bitfield | $row['bbcode_bitfield']; + $bbcode_bitfield = $bbcode_bitfield | base64_decode($row['bbcode_bitfield']); } while ($row = $db->sql_fetchrow($result)); $db->sql_freeresult($result); diff --git a/phpBB/includes/mcp/mcp_main.php b/phpBB/includes/mcp/mcp_main.php index 9125ae55b1..ce0c47941d 100644 --- a/phpBB/includes/mcp/mcp_main.php +++ b/phpBB/includes/mcp/mcp_main.php @@ -886,7 +886,7 @@ function mcp_fork_topic($topic_ids) 'post_checksum' => (string) $row['post_checksum'], 'post_encoding' => (string) $row['post_encoding'], 'post_attachment' => (int) $row['post_attachment'], - 'bbcode_bitfield' => (int) $row['bbcode_bitfield'], + 'bbcode_bitfield' => $row['bbcode_bitfield'], 'bbcode_uid' => (string) $row['bbcode_uid'], 'post_edit_time' => (int) $row['post_edit_time'], 'post_edit_count' => (int) $row['post_edit_count'], diff --git a/phpBB/includes/mcp/mcp_topic.php b/phpBB/includes/mcp/mcp_topic.php index b2c3e21170..75dd9ea2e2 100644 --- a/phpBB/includes/mcp/mcp_topic.php +++ b/phpBB/includes/mcp/mcp_topic.php @@ -92,7 +92,7 @@ function mcp_topic_view($id, $mode, $action) while ($row = $db->sql_fetchrow($result)) { $rowset[] = $row; - $bbcode_bitfield = $bbcode_bitfield | $row['bbcode_bitfield']; + $bbcode_bitfield = $bbcode_bitfield | base64_decode($row['bbcode_bitfield']); } $db->sql_freeresult($result); diff --git a/phpBB/includes/mcp/mcp_warn.php b/phpBB/includes/mcp/mcp_warn.php index 87ed6e93c8..bc428570ab 100755 --- a/phpBB/includes/mcp/mcp_warn.php +++ b/phpBB/includes/mcp/mcp_warn.php @@ -416,7 +416,7 @@ function add_warning($userrow, $warning, $send_pm = true, $post_id = 0) 'enable_smilies' => true, 'enable_urls' => false, 'icon_id' => 0, - 'bbcode_bitfield' => (int) $message_parser->bbcode_bitfield, + 'bbcode_bitfield' => $message_parser->bbcode_bitfield, 'bbcode_uid' => $message_parser->bbcode_uid, 'message' => $message_parser->message, 'address_list' => array('u' => array($userrow['user_id'] => 'to')), diff --git a/phpBB/includes/message_parser.php b/phpBB/includes/message_parser.php index 8d51a195c6..94e4d94d04 100644 --- a/phpBB/includes/message_parser.php +++ b/phpBB/includes/message_parser.php @@ -79,7 +79,7 @@ class bbcode_firstpass extends bbcode } } - $this->bbcode_bitfield = $bitfield->get_blob(); + $this->bbcode_bitfield = $bitfield->get_base64(); } /** diff --git a/phpBB/includes/ucp/ucp_pm_viewmessage.php b/phpBB/includes/ucp/ucp_pm_viewmessage.php index a4db5bd3e0..620bc9701f 100644 --- a/phpBB/includes/ucp/ucp_pm_viewmessage.php +++ b/phpBB/includes/ucp/ucp_pm_viewmessage.php @@ -281,7 +281,7 @@ function message_history($msg_id, $user_id, $message_row, $folder) else { $rowset[$row['msg_id']] = $row; - $bbcode_bitfield = $bbcode_bitfield | $row['bbcode_bitfield']; + $bbcode_bitfield = $bbcode_bitfield | base64_decode($row['bbcode_bitfield']); } } while ($row = $db->sql_fetchrow($result)); |