Some small touchups

git-svn-id: file:///svn/phpbb/trunk@5026 89ea8834-ac86-4346-8a33-228a782c2dd0
This commit is contained in:
Bart van Bragt 2004-11-10 14:15:16 +00:00
parent e9eda1bd3e
commit d62c5a6fcd
3 changed files with 121 additions and 61 deletions

View file

@ -31,7 +31,7 @@ require('pagestart.' . $phpEx);
include($phpbb_root_path.'includes/functions_user.'.$phpEx); include($phpbb_root_path.'includes/functions_user.'.$phpEx);
include($phpbb_root_path.'includes/functions_profile_fields.'.$phpEx); include($phpbb_root_path.'includes/functions_profile_fields.'.$phpEx);
$user->add_lang(array('posting', 'ucp', 'gcp')); $user->add_lang(array('posting', 'ucp'));
// //
// Get and set basic vars // Get and set basic vars

View file

@ -732,11 +732,47 @@ function sync($mode, $where_type = '', $where_ids = '', $resync_parents = FALSE,
{ {
if (!$where_type) if (!$where_type)
{ {
$where_sql = ''; // Sync all topics/forums.
$where_sql_and = 'WHERE'; if($mode == 'topic')
{
//This can bomb out on a large forum so we're going to split this up.
$batch_size = 500;
//TODO: Fit this into the layout.
print "Syncing topics, going to do this in batches (batch size = $batch_size):<br />";
$sql = "SELECT
MIN(topic_id) AS topic_min,
MAX(topic_id) AS topic_max
FROM " . TOPICS_TABLE;
$result = $db->sql_query($sql);
$row = $db->sql_fetchrow($result);
$topic_min = $row['topic_min'];
$topic_max = $row['topic_max'];
// Run the batches
$batch_start = $topic_min;
while($batch_start <= $topic_max)
{
if (defined('DEBUG_EXTRA'))
{
print "Syncing topic_id $batch_start to ". ($batch_start+$batch_size) . ". ";
print ceil(memory_get_usage()/1024) . " KB<br />\n";
flush();
}
sync('topic', 'range', "topic_id BETWEEN $batch_start AND " . ($batch_start+$batch_size-1));
$batch_start += $batch_size;
}
}
else
{
$where_sql = '';
$where_sql_and = 'WHERE';
}
} }
elseif ($where_type == 'range') elseif ($where_type == 'range')
{ {
// Only check a range of topics/forums. For instance: 'topic_id BETWEEN 1 AND 60'
$where_sql = 'WHERE (' . $mode{0} . ".$where_ids)"; $where_sql = 'WHERE (' . $mode{0} . ".$where_ids)";
$where_sql_and = $where_sql . "\n\tAND"; $where_sql_and = $where_sql . "\n\tAND";
} }
@ -744,8 +780,11 @@ function sync($mode, $where_type = '', $where_ids = '', $resync_parents = FALSE,
{ {
if (!sizeof($where_ids)) if (!sizeof($where_ids))
{ {
// Empty array with IDs. This means that we don't have any work to do. Just return.
return; return;
} }
// Limit the topics/forums we are syncing, use specific topic/forum IDs.
// $where_type contains the field for the where clause (forum_id, topic_id)
$where_sql = 'WHERE ' . $mode{0} . ".$where_type IN (" . implode(', ', $where_ids) . ')'; $where_sql = 'WHERE ' . $mode{0} . ".$where_type IN (" . implode(', ', $where_ids) . ')';
$where_sql_and = $where_sql . "\n\tAND"; $where_sql_and = $where_sql . "\n\tAND";
} }
@ -756,6 +795,7 @@ function sync($mode, $where_type = '', $where_ids = '', $resync_parents = FALSE,
{ {
return; return;
} }
// $where_type contains the field for the where clause (forum_id, topic_id)
$where_sql = 'WHERE ' . $mode{0} . ".$where_type IN (" . implode(', ', $where_ids) . ')'; $where_sql = 'WHERE ' . $mode{0} . ".$where_type IN (" . implode(', ', $where_ids) . ')';
$where_sql_and = $where_sql . "\n\tAND"; $where_sql_and = $where_sql . "\n\tAND";
} }
@ -1014,7 +1054,7 @@ function sync($mode, $where_type = '', $where_ids = '', $resync_parents = FALSE,
break; break;
case 'forum': case 'forum':
// 1° Get the list of all forums // 1: Get the list of all forums
$sql = 'SELECT f.* $sql = 'SELECT f.*
FROM ' . FORUMS_TABLE . " f FROM ' . FORUMS_TABLE . " f
$where_sql"; $where_sql";
@ -1041,7 +1081,7 @@ function sync($mode, $where_type = '', $where_ids = '', $resync_parents = FALSE,
$forum_data[$forum_id]['last_poster_name'] = ''; $forum_data[$forum_id]['last_poster_name'] = '';
} }
// 2° Get topic counts for each forum // 2: Get topic counts for each forum
$sql = 'SELECT forum_id, topic_approved, COUNT(topic_id) AS forum_topics $sql = 'SELECT forum_id, topic_approved, COUNT(topic_id) AS forum_topics
FROM ' . TOPICS_TABLE . ' FROM ' . TOPICS_TABLE . '
WHERE forum_id IN (' . implode(', ', $forum_ids) . ') WHERE forum_id IN (' . implode(', ', $forum_ids) . ')
@ -1058,7 +1098,7 @@ function sync($mode, $where_type = '', $where_ids = '', $resync_parents = FALSE,
} }
} }
// 3° Get post count and last_post_id for each forum // 3: Get post count and last_post_id for each forum
$sql = 'SELECT forum_id, COUNT(post_id) AS forum_posts, MAX(post_id) AS last_post_id $sql = 'SELECT forum_id, COUNT(post_id) AS forum_posts, MAX(post_id) AS last_post_id
FROM ' . POSTS_TABLE . ' FROM ' . POSTS_TABLE . '
WHERE forum_id IN (' . implode(', ', $forum_ids) . ') WHERE forum_id IN (' . implode(', ', $forum_ids) . ')
@ -1075,7 +1115,7 @@ function sync($mode, $where_type = '', $where_ids = '', $resync_parents = FALSE,
$post_ids[] = $row['last_post_id']; $post_ids[] = $row['last_post_id'];
} }
// 4° Retrieve last_post infos // 4: Retrieve last_post infos
if (count($post_ids)) if (count($post_ids))
{ {
$sql = 'SELECT p.post_id, p.poster_id, p.post_time, p.post_username, u.username $sql = 'SELECT p.post_id, p.poster_id, p.post_time, p.post_username, u.username
@ -1112,7 +1152,7 @@ function sync($mode, $where_type = '', $where_ids = '', $resync_parents = FALSE,
unset($post_info); unset($post_info);
} }
// 5° Now do that thing // 5: Now do that thing
$fieldnames = array('posts', 'topics', 'topics_real', 'last_post_id', 'last_post_time', 'last_poster_id', 'last_poster_name'); $fieldnames = array('posts', 'topics', 'topics_real', 'last_post_id', 'last_post_time', 'last_poster_id', 'last_poster_name');
foreach ($forum_data as $forum_id => $row) foreach ($forum_data as $forum_id => $row)
@ -1173,6 +1213,7 @@ function sync($mode, $where_type = '', $where_ids = '', $resync_parents = FALSE,
$db->sql_freeresult($result); $db->sql_freeresult($result);
// Use "t" as table alias because of the $where_sql clause // Use "t" as table alias because of the $where_sql clause
// NOTE: 't.post_approved' in the GROUP BY is causing a major slowdown.
$sql = 'SELECT t.topic_id, t.post_approved, COUNT(t.post_id) AS total_posts, MIN(t.post_id) AS first_post_id, MAX(t.post_id) AS last_post_id $sql = 'SELECT t.topic_id, t.post_approved, COUNT(t.post_id) AS total_posts, MIN(t.post_id) AS first_post_id, MAX(t.post_id) AS last_post_id
FROM ' . POSTS_TABLE . " t FROM ' . POSTS_TABLE . " t
$where_sql $where_sql
@ -1283,7 +1324,7 @@ function sync($mode, $where_type = '', $where_ids = '', $resync_parents = FALSE,
} }
unset($approved_unapproved_ids); unset($approved_unapproved_ids);
// These are field that will be synchronised // These are fields that will be synchronised
$fieldnames = array('time', 'replies', 'replies_real', 'poster', 'first_post_id', 'first_poster_name', 'last_post_id', 'last_post_time', 'last_poster_id', 'last_poster_name'); $fieldnames = array('time', 'replies', 'replies_real', 'poster', 'first_post_id', 'first_poster_name', 'last_post_id', 'last_post_time', 'last_poster_id', 'last_poster_name');
if ($sync_extra) if ($sync_extra)

View file

@ -121,7 +121,7 @@ class bbcode_firstpass extends bbcode
$this->parsed_items = array('code' => 0, 'quote' => 0, 'attachment' => 0, 'url' => 0, 'email' => 0, 'img' => 0, 'flash' => 0); $this->parsed_items = array('code' => 0, 'quote' => 0, 'attachment' => 0, 'url' => 0, 'email' => 0, 'img' => 0, 'flash' => 0);
if (!isset($rowset)) if (!is_array($rowset))
{ {
global $db; global $db;
$rowset = array(); $rowset = array();
@ -643,7 +643,7 @@ class parse_message extends bbcode_firstpass
$this->allow_flash_bbcode = $allow_flash_bbcode; $this->allow_flash_bbcode = $allow_flash_bbcode;
$this->allow_quote_bbcode = $allow_quote_bbcode; $this->allow_quote_bbcode = $allow_quote_bbcode;
// If false, then the parsed message get returned but internal message not processed. // If false, then $this->message won't be altered, the text will be returned instead.
if (!$update_this_message) if (!$update_this_message)
{ {
$tmp_message = $this->message; $tmp_message = $this->message;
@ -812,28 +812,33 @@ class parse_message extends bbcode_firstpass
// into relative versions when the server/script path matches the link // into relative versions when the server/script path matches the link
function magic_url($server_protocol, $server_name, $server_port, $script_path) function magic_url($server_protocol, $server_name, $server_port, $script_path)
{ {
static $match;
static $replace;
$server_port = ($server_port <> 80 ) ? ':' . trim($server_port) . '/' : '/'; $server_port = ($server_port <> 80 ) ? ':' . trim($server_port) . '/' : '/';
$match = $replace = array(); $match = $replace = array();
// Be sure to not let the matches cross over. ;) if(!is_array($match))
{
// relative urls for this board // Be sure to not let the matches cross over. ;)
$match[] = '#(^|[\n ]|\()(' . preg_quote($server_protocol . trim($server_name) . $server_port . preg_replace('/^\/?(.*?)(\/)?$/', '$1', trim($script_path)), '#') . ')/(.*?([^ \t\n\r<"\'\)]*)?)#i';
$replace[] = '$1<!-- l --><a href="$2/$3" target="_blank">$3</a><!-- l -->'; // relative urls for this board
$match[] = '#(^|[\n ]|\()(' . preg_quote($server_protocol . trim($server_name) . $server_port . preg_replace('/^\/?(.*?)(\/)?$/', '$1', trim($script_path)), '#') . ')/(.*?([^ \t\n\r<"\'\)]*)?)#i';
// matches a xxxx://aaaaa.bbb.cccc. ... $replace[] = '$1<!-- l --><a href="$2/$3" target="_blank">$3</a><!-- l -->';
$match[] = '#(^|[\n ]|\()([\w]+?://.*?([^ \t\n\r<"\'\)]*)?)#ie';
$replace[] = "'\$1<!-- m --><a href=\"\$2\" target=\"_blank\">' . ((strlen('\$2') > 55) ? substr('\$2', 0, 39) . ' ... ' . substr('\$2', -10) : '\$2') . '</a><!-- m -->'"; // matches a xxxx://aaaaa.bbb.cccc. ...
$match[] = '#(^|[\n ]|\()([\w]+?://.*?([^ \t\n\r<"\'\)]*)?)#ie';
// matches a "www.xxxx.yyyy[/zzzz]" kinda lazy URL thing $replace[] = "'\$1<!-- m --><a href=\"\$2\" target=\"_blank\">' . ((strlen('\$2') > 55) ? substr('\$2', 0, 39) . ' ... ' . substr('\$2', -10) : '\$2') . '</a><!-- m -->'";
$match[] = '#(^|[\n ]|\()(www\.[\w\-]+\.[\w\-.\~]+(?:/[^ \t\n\r<"\'\)]*)?)#ie';
$replace[] = "'\$1<!-- w --><a href=\"http://\$2\" target=\"_blank\">' . ((strlen('\$2') > 55) ? substr(str_replace(' ', '%20', '\$2'), 0, 39) . ' ... ' . substr('\$2', -10) : '\$2') . '</a><!-- w -->'"; // matches a "www.xxxx.yyyy[/zzzz]" kinda lazy URL thing
$match[] = '#(^|[\n ]|\()(www\.[\w\-]+\.[\w\-.\~]+(?:/[^ \t\n\r<"\'\)]*)?)#ie';
// matches an email@domain type address at the start of a line, or after a space. $replace[] = "'\$1<!-- w --><a href=\"http://\$2\" target=\"_blank\">' . ((strlen('\$2') > 55) ? substr(str_replace(' ', '%20', '\$2'), 0, 39) . ' ... ' . substr('\$2', -10) : '\$2') . '</a><!-- w -->'";
$match[] = '#(^|[\n ]|\()([a-z0-9&\-_.]+?@[\w\-]+\.([\w\-\.]+\.)?[\w]+)#ie';
$replace[] = "'\$1<!-- e --><a href=\"mailto:\$2\">' . ((strlen('\$2') > 55) ? substr('\$2', 0, 39) . ' ... ' . substr('\$2', -10) : '\$2') . '</a><!-- e -->'"; // matches an email@domain type address at the start of a line, or after a space.
$match[] = '#(^|[\n ]|\()([a-z0-9&\-_.]+?@[\w\-]+\.([\w\-\.]+\.)?[\w]+)#ie';
$replace[] = "'\$1<!-- e --><a href=\"mailto:\$2\">' . ((strlen('\$2') > 55) ? substr('\$2', 0, 39) . ' ... ' . substr('\$2', -10) : '\$2') . '</a><!-- e -->'";
}
/* IMPORTANT NOTE (Developer inability to do advanced regular expressions) - Acyd Burn: /* IMPORTANT NOTE (Developer inability to do advanced regular expressions) - Acyd Burn:
Transforming &lt; (<) to <&amp;lt; in order to bypass the inability of preg_replace Transforming &lt; (<) to <&amp;lt; in order to bypass the inability of preg_replace
supporting multi-character sequences (POSIX - [..]). Since all message text is specialchared by supporting multi-character sequences (POSIX - [..]). Since all message text is specialchared by
@ -850,40 +855,55 @@ class parse_message extends bbcode_firstpass
function emoticons($max_smilies = 0) function emoticons($max_smilies = 0)
{ {
global $db, $user, $phpbb_root_path; global $db, $user, $phpbb_root_path;
static $match;
static $replace;
// NOTE: obtain_* function? chaching the table contents? // NOTE: There is a memory leak in this block somewhere :\
// See if the static arrays have already been filled on an earlier invocation
// For now setting the ttl to 10 minutes if(!is_array($match))
switch (SQL_LAYER)
{ {
case 'mssql': // NOTE: obtain_* function? chaching the table contents?
case 'mssql-odbc':
$sql = 'SELECT * // For now setting the ttl to 10 minutes
FROM ' . SMILIES_TABLE . ' switch (SQL_LAYER)
ORDER BY LEN(code) DESC';
break;
// LENGTH supported by MySQL, IBM DB2, Oracle and Access for sure...
default:
$sql = 'SELECT *
FROM ' . SMILIES_TABLE . '
ORDER BY LENGTH(code) DESC';
break;
}
$result = $db->sql_query($sql, 600);
if ($row = $db->sql_fetchrow($result))
{
$match = $replace = array();
do
{ {
// (assertion) case 'mssql':
$match[] = '#(?<=^|[\n ]|\.)' . preg_quote($row['code'], '#') . '#'; case 'mssql-odbc':
$replace[] = '<!-- s' . $row['code'] . ' --><img src="{SMILE_PATH}/' . $row['smile_url'] . '" border="0" alt="' . $row['emoticon'] . '" title="' . $row['emoticon'] . '" /><!-- s' . $row['code'] . ' -->'; $sql = 'SELECT *
FROM ' . SMILIES_TABLE . '
ORDER BY LEN(code) DESC';
break;
// LENGTH supported by MySQL, IBM DB2, Oracle and Access for sure...
default:
$sql = 'SELECT *
FROM ' . SMILIES_TABLE . '
ORDER BY LENGTH(code) DESC';
break;
} }
while ($row = $db->sql_fetchrow($result)); $result = $db->sql_query($sql, 600);
if ($row = $db->sql_fetchrow($result))
{
$match = $replace = array();
do
{
// (assertion)
$match[] = '#(?<=^|[\n ]|\.)' . preg_quote($row['code'], '#') . '#';
$replace[] = '<!-- s' . $row['code'] . ' --><img src="{SMILE_PATH}/' . $row['smile_url'] . '" border="0" alt="' . $row['emoticon'] . '" title="' . $row['emoticon'] . '" /><!-- s' . $row['code'] . ' -->';
}
while ($row = $db->sql_fetchrow($result));
}
else
{
$match = $replace = array();
}
$db->sql_freeresult($result);
}
if(count($match))
{
if ($max_smilies) if ($max_smilies)
{ {
$num_matches = preg_match_all('#' . str_replace('#', '', implode('|', $match)) . '#', $this->message, $matches); $num_matches = preg_match_all('#' . str_replace('#', '', implode('|', $match)) . '#', $this->message, $matches);
@ -898,7 +918,6 @@ class parse_message extends bbcode_firstpass
$this->message = trim(preg_replace($match, $replace, $this->message)); $this->message = trim(preg_replace($match, $replace, $this->message));
} }
$db->sql_freeresult($result);
} }
// Parse Attachments // Parse Attachments
@ -1145,7 +1164,7 @@ class fulltext_search
return; return;
} }
if (!$drop_char_match) if (!is_array($drop_char_match))
{ {
$drop_char_match = array('-', '^', '$', ';', '#', '&', '(', ')', '<', '>', '`', '\'', '"', '|', ',', '@', '_', '?', '%', '~', '.', '[', ']', '{', '}', ':', '\\', '/', '=', '\'', '!', '*'); $drop_char_match = array('-', '^', '$', ';', '#', '&', '(', ')', '<', '>', '`', '\'', '"', '|', ',', '@', '_', '?', '%', '~', '.', '[', ']', '{', '}', ':', '\\', '/', '=', '\'', '!', '*');
$drop_char_replace = array(' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '', '', ' ', ' ', ' ', ' ', '', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '' , ' ', ' ', ' ', ' ', ' '); $drop_char_replace = array(' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '', '', ' ', ' ', ' ', ' ', '', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '' , ' ', ' ', ' ', ' ', ' ');