aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/includes
diff options
context:
space:
mode:
authorBart van Bragt <bartvb@users.sourceforge.net>2004-11-10 14:15:16 +0000
committerBart van Bragt <bartvb@users.sourceforge.net>2004-11-10 14:15:16 +0000
commitd62c5a6fcd06605087b5084beb897798fbf11ec9 (patch)
tree4c3039ef8812b807ea5b758202d8d82b755a14f1 /phpBB/includes
parente9eda1bd3ee909fc8106ed7de156acb001f888c2 (diff)
downloadforums-d62c5a6fcd06605087b5084beb897798fbf11ec9.tar
forums-d62c5a6fcd06605087b5084beb897798fbf11ec9.tar.gz
forums-d62c5a6fcd06605087b5084beb897798fbf11ec9.tar.bz2
forums-d62c5a6fcd06605087b5084beb897798fbf11ec9.tar.xz
forums-d62c5a6fcd06605087b5084beb897798fbf11ec9.zip
Some small touchups
git-svn-id: file:///svn/phpbb/trunk@5026 89ea8834-ac86-4346-8a33-228a782c2dd0
Diffstat (limited to 'phpBB/includes')
-rw-r--r--phpBB/includes/functions_admin.php57
-rw-r--r--phpBB/includes/message_parser.php123
2 files changed, 120 insertions, 60 deletions
diff --git a/phpBB/includes/functions_admin.php b/phpBB/includes/functions_admin.php
index 7e9de1147f..3022266f7e 100644
--- a/phpBB/includes/functions_admin.php
+++ b/phpBB/includes/functions_admin.php
@@ -732,11 +732,47 @@ function sync($mode, $where_type = '', $where_ids = '', $resync_parents = FALSE,
{
if (!$where_type)
{
- $where_sql = '';
- $where_sql_and = 'WHERE';
+ // Sync all topics/forums.
+ 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')
{
+ // Only check a range of topics/forums. For instance: 'topic_id BETWEEN 1 AND 60'
$where_sql = 'WHERE (' . $mode{0} . ".$where_ids)";
$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))
{
+ // Empty array with IDs. This means that we don't have any work to do. Just 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_and = $where_sql . "\n\tAND";
}
@@ -756,6 +795,7 @@ function sync($mode, $where_type = '', $where_ids = '', $resync_parents = FALSE,
{
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_and = $where_sql . "\n\tAND";
}
@@ -1014,7 +1054,7 @@ function sync($mode, $where_type = '', $where_ids = '', $resync_parents = FALSE,
break;
case 'forum':
- // 1° Get the list of all forums
+ // 1: Get the list of all forums
$sql = 'SELECT f.*
FROM ' . FORUMS_TABLE . " f
$where_sql";
@@ -1041,7 +1081,7 @@ function sync($mode, $where_type = '', $where_ids = '', $resync_parents = FALSE,
$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
FROM ' . TOPICS_TABLE . '
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
FROM ' . POSTS_TABLE . '
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'];
}
- // 4° Retrieve last_post infos
+ // 4: Retrieve last_post infos
if (count($post_ids))
{
$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);
}
- // 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');
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);
// 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
FROM ' . POSTS_TABLE . " t
$where_sql
@@ -1283,7 +1324,7 @@ function sync($mode, $where_type = '', $where_ids = '', $resync_parents = FALSE,
}
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');
if ($sync_extra)
diff --git a/phpBB/includes/message_parser.php b/phpBB/includes/message_parser.php
index f738f31967..bcbdd47234 100644
--- a/phpBB/includes/message_parser.php
+++ b/phpBB/includes/message_parser.php
@@ -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);
- if (!isset($rowset))
+ if (!is_array($rowset))
{
global $db;
$rowset = array();
@@ -643,7 +643,7 @@ class parse_message extends bbcode_firstpass
$this->allow_flash_bbcode = $allow_flash_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)
{
$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
function magic_url($server_protocol, $server_name, $server_port, $script_path)
{
+ static $match;
+ static $replace;
+
$server_port = ($server_port <> 80 ) ? ':' . trim($server_port) . '/' : '/';
$match = $replace = array();
- // Be sure to not let the matches cross over. ;)
-
- // 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';
- $replace[] = '$1<!-- l --><a href="$2/$3" target="_blank">$3</a><!-- l -->';
-
- // matches a xxxx://aaaaa.bbb.cccc. ...
- $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 "www.xxxx.yyyy[/zzzz]" kinda lazy URL thing
- $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 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 -->'";
-
+ if(!is_array($match))
+ {
+ // Be sure to not let the matches cross over. ;)
+
+ // 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';
+ $replace[] = '$1<!-- l --><a href="$2/$3" target="_blank">$3</a><!-- l -->';
+
+ // matches a xxxx://aaaaa.bbb.cccc. ...
+ $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 "www.xxxx.yyyy[/zzzz]" kinda lazy URL thing
+ $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 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:
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
@@ -850,40 +855,55 @@ class parse_message extends bbcode_firstpass
function emoticons($max_smilies = 0)
{
global $db, $user, $phpbb_root_path;
+ static $match;
+ static $replace;
- // NOTE: obtain_* function? chaching the table contents?
-
- // For now setting the ttl to 10 minutes
- switch (SQL_LAYER)
- {
- case 'mssql':
- case 'mssql-odbc':
- $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;
- }
- $result = $db->sql_query($sql, 600);
-
- if ($row = $db->sql_fetchrow($result))
+ // NOTE: There is a memory leak in this block somewhere :\
+ // See if the static arrays have already been filled on an earlier invocation
+ if(!is_array($match))
{
- $match = $replace = array();
-
- do
+ // NOTE: obtain_* function? chaching the table contents?
+
+ // For now setting the ttl to 10 minutes
+ switch (SQL_LAYER)
{
- // (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'] . ' -->';
+ case 'mssql':
+ case 'mssql-odbc':
+ $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)
{
$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));
}
- $db->sql_freeresult($result);
}
// Parse Attachments
@@ -1145,7 +1164,7 @@ class fulltext_search
return;
}
- if (!$drop_char_match)
+ if (!is_array($drop_char_match))
{
$drop_char_match = array('-', '^', '$', ';', '#', '&', '(', ')', '<', '>', '`', '\'', '"', '|', ',', '@', '_', '?', '%', '~', '.', '[', ']', '{', '}', ':', '\\', '/', '=', '\'', '!', '*');
$drop_char_replace = array(' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '', '', ' ', ' ', ' ', ' ', '', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '' , ' ', ' ', ' ', ' ', ' ');