mirror of
https://github.com/phpbb/phpbb.git
synced 2025-10-29 06:26:22 +01:00
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
This commit is contained in:
@@ -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();
|
||||
|
||||
@@ -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]))
|
||||
{
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -369,14 +369,6 @@ class dbal_mssql extends dbal
|
||||
return str_replace("'", "''", $msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Escape string used in sql query
|
||||
*/
|
||||
function sql_escape_binary($msg)
|
||||
{
|
||||
return "CAST('" . $msg . "' AS varbinary)";
|
||||
}
|
||||
|
||||
/**
|
||||
* return sql error array
|
||||
* @access: private
|
||||
|
||||
@@ -379,14 +379,6 @@ class dbal_mssql_odbc extends dbal
|
||||
return str_replace("'", "''", $msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Escape string used in sql query
|
||||
*/
|
||||
function sql_escape_binary($msg)
|
||||
{
|
||||
return "CAST('" . $msg . "' AS varbinary)";
|
||||
}
|
||||
|
||||
/**
|
||||
* Build db-specific query data
|
||||
* @access: private
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -396,14 +396,6 @@ class dbal_postgres extends dbal
|
||||
return @pg_escape_string($msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Escape string used in sql query
|
||||
*/
|
||||
function sql_escape_binary($msg)
|
||||
{
|
||||
return "'" . @pg_escape_bytea($msg) . "'";
|
||||
}
|
||||
|
||||
/**
|
||||
* return sql error array
|
||||
* @access: private
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
@@ -316,14 +308,6 @@ class dbal_sqlite extends dbal
|
||||
return @sqlite_escape_string($msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
|
||||
@@ -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 = '';
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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'],
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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')),
|
||||
|
||||
@@ -79,7 +79,7 @@ class bbcode_firstpass extends bbcode
|
||||
}
|
||||
}
|
||||
|
||||
$this->bbcode_bitfield = $bitfield->get_blob();
|
||||
$this->bbcode_bitfield = $bitfield->get_base64();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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));
|
||||
|
||||
Reference in New Issue
Block a user