1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-08-18 22:41:28 +02:00

- some cross-db related changes

- putting active bots array into cache


git-svn-id: file:///svn/phpbb/trunk@5140 89ea8834-ac86-4346-8a33-228a782c2dd0
This commit is contained in:
Meik Sievertsen
2005-05-05 16:55:05 +00:00
parent 16e50db4ba
commit b576d6af0a
11 changed files with 206 additions and 120 deletions

View File

@@ -1116,6 +1116,36 @@ function obtain_attach_extensions(&$extensions, $forum_id = false)
return;
}
/**
* Obtain active bots
*/
function obtain_bots(&$bots)
{
global $db, $cache;
if ($cache->exists('bots'))
{
$bots = $cache->get('bots');
}
else
{
$sql = 'SELECT user_id, bot_agent, bot_ip
FROM ' . BOTS_TABLE . '
WHERE bot_active = 1';
$result = $db->sql_query($sql);
while ($row = $db->sql_fetchrow($result))
{
$bots[] = $row;
}
$db->sql_freeresult($result);
$cache->put('bots', $bots);
}
return;
}
/**
* Generate board url
*/

View File

@@ -1492,9 +1492,9 @@ function remove_comments(&$output)
$linecount = sizeof($lines);
$in_comment = false;
for($i = 0; $i < $linecount; $i++)
for ($i = 0; $i < $linecount; $i++)
{
if (preg_match('#^\/\*#', preg_quote($lines[$i])))
if (trim($lines[$i]) == '/*')
{
$in_comment = true;
}
@@ -1504,7 +1504,7 @@ function remove_comments(&$output)
$output .= $lines[$i] . "\n";
}
if (preg_match('#\*\/$#', preg_quote($lines[$i])))
if (trim($lines[$i]) == '*/')
{
$in_comment = false;
}

View File

@@ -148,10 +148,18 @@ function upload_attachment($form_name, $forum_id, $local = false, $local_storage
include_once($phpbb_root_path . 'includes/functions_upload.php');
$upload = new fileupload();
$filedata['post_attach'] = ($upload->is_valid($form_name)) ? true : false;
if (!$local)
{
$filedata['post_attach'] = ($upload->is_valid($form_name)) ? true : false;
}
else
{
$filedata['post_attach'] = true;
}
if (!$filedata['post_attach'])
{
$filedata['error'][] = 'No filedata found';
return $filedata;
}

View File

@@ -56,6 +56,12 @@ class filespec
// Opera adds the name to the mime type
$this->mimetype = (strpos($this->mimetype, '; name') !== false) ? str_replace(strstr($this->mimetype, '; name'), '', $this->mimetype) : $this->mimetype;
if (!$this->mimetype)
{
$this->mimetype = 'application/octetstream';
}
$this->extension = array_pop(explode('.', strtolower($this->realname)));
// Try to get real filesize from temporary folder (not always working) ;)
@@ -122,7 +128,12 @@ class filespec
function is_uploaded()
{
return (file_exists($this->filename) && is_uploaded_file($this->filename)) ? true : false;
if (!$this->local && !is_uploaded_file($this->filename))
{
return false;
}
return (file_exists($this->filename)) ? true : false;
}
function remove()
@@ -394,8 +405,64 @@ class fileupload
}
// Move file from another location to phpBB
function local_upload($source_file)
function local_upload($source_file, $filedata = false)
{
global $user;
$form_name = 'local';
$_FILES[$form_name]['local_mode'] = true;
$_FILES[$form_name]['tmp_name'] = $source_file;
if ($filedata === false)
{
$_FILES[$form_name]['name'] = basename($source_file);
$_FILES[$form_name]['size'] = 0;
$_FILES[$form_name]['type'] = '';
}
else
{
$_FILES[$form_name]['name'] = $filedata['realname'];
$_FILES[$form_name]['size'] = $filedata['size'];
$_FILES[$form_name]['type'] = $filedata['type'];
}
$file = new filespec($_FILES[$form_name], $this);
if ($file->init_error)
{
$file->error[] = '';
return $file;
}
if (isset($_FILES[$form_name]['error']))
{
$error = $this->assign_internal_error($_FILES[$form_name]['error']);
if ($error !== false)
{
$file->error[] = $error;
return $file;
}
}
// PHP Upload filesize exceeded
if ($file->get('filename') == 'none')
{
$file->error[] = (@ini_get('upload_max_filesize') == '') ? $user->lang[$this->error_prefix . 'PHP_SIZE_NA'] : sprintf($user->lang[$this->error_prefix . 'PHP_SIZE_OVERRUN'], @ini_get('upload_max_filesize'));
return $file;
}
// Not correctly uploaded
if (!$file->is_uploaded())
{
$file->error[] = $user->lang[$this->error_prefix . 'NOT_UPLOADED'];
return $file;
}
$this->common_checks($file);
return $file;
}
/**

View File

@@ -138,12 +138,10 @@ class session
$bot = false;
// Pull bot information from DB and loop through it
$sql = 'SELECT user_id, bot_agent, bot_ip
FROM ' . BOTS_TABLE . '
WHERE bot_active = 1';
$result = $db->sql_query($sql);
$active_bots = array();
obtain_bots($active_bots);
while ($row = $db->sql_fetchrow($result))
foreach ($active_bots as $row)
{
if ($row['bot_agent'] && preg_match('#' . preg_quote($row['bot_agent'], '#') . '#i', $this->browser))
{
@@ -168,7 +166,6 @@ class session
break;
}
}
$db->sql_freeresult($result);
// Garbage collection ... remove old sessions updating user information
// if necessary. It means (potentially) 11 queries but only infrequently
@@ -586,7 +583,7 @@ class user extends session
$style = ($style) ? $style : ((!$config['override_user_style'] && $this->data['user_id'] != ANONYMOUS) ? $this->data['user_style'] : $config['default_style']);
}
// TODO: DISTINCT making problems with DBMS not able to distinct TEXT fields
// TODO: DISTINCT making problems with DBMS not able to distinct TEXT fields, test grouping
switch (SQL_LAYER)
{
case 'mssql':
@@ -596,16 +593,18 @@ class user extends session
WHERE s.style_id IN ($style, " . $config['default_style'] . ')
AND t.template_id = s.template_id
AND c.theme_id = s.theme_id
AND i.imageset_id = s.imageset_id';
AND i.imageset_id = s.imageset_id
GROUP BY s.style_id';
break;
default:
$sql = 'SELECT DISTINCT s.style_id, t.*, c.*, i.*
$sql = 'SELECT s.style_id, t.*, c.*, i.*
FROM ' . STYLES_TABLE . ' s, ' . STYLES_TPL_TABLE . ' t, ' . STYLES_CSS_TABLE . ' c, ' . STYLES_IMAGE_TABLE . " i
WHERE s.style_id IN ($style, " . $config['default_style'] . ')
AND t.template_id = s.template_id
AND c.theme_id = s.theme_id
AND i.imageset_id = s.imageset_id';
AND i.imageset_id = s.imageset_id
GROUP BY s.style_id';
break;
}
$result = $db->sql_query($sql, 3600);