Bug 1744 fixed : Incorrect use of timezone with SQLite

Fixed anti-flood system.

Merge from trunk

git-svn-id: http://piwigo.org/svn/branches/2.1@6605 68402e56-0260-453c-a942-63ccdbb3a9ee
This commit is contained in:
nikrou 2010-06-25 19:45:19 +00:00
parent 6394613e9f
commit d7fa727afa
6 changed files with 28 additions and 7 deletions

View file

@ -126,7 +126,7 @@ if ($conf['show_newsletter_subscription']) {
$php_current_timestamp = date("Y-m-d H:i:s"); $php_current_timestamp = date("Y-m-d H:i:s");
$db_version = pwg_get_db_version(); $db_version = pwg_get_db_version();
list($db_current_timestamp) = pwg_db_fetch_row(pwg_query('SELECT CURRENT_TIMESTAMP;')); list($db_current_date) = pwg_db_fetch_row(pwg_query('SELECT now();'));
$query = ' $query = '
SELECT COUNT(*) SELECT COUNT(*)
@ -215,7 +215,7 @@ $template->assign(
'U_CHECK_UPGRADE' => PHPWG_ROOT_PATH.'admin.php?action=check_upgrade', 'U_CHECK_UPGRADE' => PHPWG_ROOT_PATH.'admin.php?action=check_upgrade',
'U_PHPINFO' => PHPWG_ROOT_PATH.'admin.php?action=phpinfo', 'U_PHPINFO' => PHPWG_ROOT_PATH.'admin.php?action=phpinfo',
'PHP_DATATIME' => $php_current_timestamp, 'PHP_DATATIME' => $php_current_timestamp,
'DB_DATATIME' => $db_current_timestamp, 'DB_DATATIME' => $db_current_date,
) )
); );

View file

@ -560,7 +560,6 @@ function boolean_to_string($var)
* *
*/ */
function pwg_db_get_recent_period_expression($period, $date='CURRENT_DATE') function pwg_db_get_recent_period_expression($period, $date='CURRENT_DATE')
{ {
if ($date!='CURRENT_DATE') if ($date!='CURRENT_DATE')
@ -580,6 +579,11 @@ SELECT '.pwg_db_get_recent_period_expression($period);
return $d; return $d;
} }
function pwg_db_get_flood_period_expression($seconds)
{
return 'SUBDATE(now(), INTERVAL '.$seconds.' SECOND)';
}
function pwg_db_get_hour($date) function pwg_db_get_hour($date)
{ {
return 'hour('.$date.')'; return 'hour('.$date.')';

View file

@ -499,6 +499,11 @@ function pwg_db_get_recent_period($period, $date='CURRENT_DATE')
return $d; return $d;
} }
function pwg_db_get_flood_period_expression($seconds)
{
return 'datetime(\'now\', \'localtime\', \''.-$seconds.' seconds\')';
}
function pwg_db_get_hour($date) function pwg_db_get_hour($date)
{ {
return 'strftime(\'%H\', '.$date.')'; return 'strftime(\'%H\', '.$date.')';

View file

@ -546,6 +546,11 @@ function pwg_db_get_recent_period($period, $date='CURRENT_DATE')
return $d; return $d;
} }
function pwg_db_get_flood_period_expression($seconds)
{
return 'now() - \''.$seconds.' SECOND\'::interval';
}
function pwg_db_get_hour($date) function pwg_db_get_hour($date)
{ {
return 'EXTRACT(HOUR FROM '.$date.')'; return 'EXTRACT(HOUR FROM '.$date.')';

View file

@ -511,6 +511,11 @@ function pwg_db_get_recent_period($period, $date='CURRENT_DATE')
return $d; return $d;
} }
function pwg_db_get_flood_period_expression($seconds)
{
return 'datetime(\'now\', \'localtime\', \''.-$seconds.' seconds\')';
}
function pwg_db_get_hour($date) function pwg_db_get_hour($date)
{ {
return 'strftime(\'%H\', '.$date.')'; return 'strftime(\'%H\', '.$date.')';

View file

@ -133,12 +133,14 @@ SELECT COUNT(*) AS user_exists
if ($comment_action!='reject' and $conf['anti-flood_time']>0 ) if ($comment_action!='reject' and $conf['anti-flood_time']>0 )
{ // anti-flood system { // anti-flood system
$reference_date = date('c', time() - $conf['anti-flood_time']); $reference_date = pwg_db_get_flood_period_expression($conf['anti-flood_time']);
$query = ' $query = '
SELECT id FROM '.COMMENTS_TABLE.' SELECT count(1) FROM '.COMMENTS_TABLE.'
WHERE date > \''.$reference_date.'\' WHERE date > '.$reference_date.'
AND author_id = '.$comm['author_id']; AND author_id = '.$comm['author_id'];
if ( pwg_db_num_rows( pwg_query( $query ) ) > 0 ) list($counter) = pwg_db_fetch_row(pwg_query($query));
if ( $counter > 0 )
{ {
array_push( $infos, l10n('Anti-flood system : please wait for a moment before trying to post another comment') ); array_push( $infos, l10n('Anti-flood system : please wait for a moment before trying to post another comment') );
$comment_action='reject'; $comment_action='reject';