Skip to content

Commit

Permalink
Bug 1744 fixed : Incorrect use of timezone with SQLite
Browse files Browse the repository at this point in the history
Fixed anti-flood system.

Need refactoring between each interval functions

git-svn-id: http://piwigo.org/svn/trunk@6604 68402e56-0260-453c-a942-63ccdbb3a9ee
  • Loading branch information
nikrou committed Jun 25, 2010
1 parent fb1d1c4 commit 1ba0969
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 7 deletions.
4 changes: 2 additions & 2 deletions admin/intro.php
Expand Up @@ -126,7 +126,7 @@

$php_current_timestamp = date("Y-m-d H:i:s");
$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 = '
SELECT COUNT(*)
Expand Down Expand Up @@ -215,7 +215,7 @@
'U_CHECK_UPGRADE' => PHPWG_ROOT_PATH.'admin.php?action=check_upgrade',
'U_PHPINFO' => PHPWG_ROOT_PATH.'admin.php?action=phpinfo',
'PHP_DATATIME' => $php_current_timestamp,
'DB_DATATIME' => $db_current_timestamp,
'DB_DATATIME' => $db_current_date,
)
);

Expand Down
6 changes: 5 additions & 1 deletion include/dblayer/functions_mysql.inc.php
Expand Up @@ -560,7 +560,6 @@ function boolean_to_string($var)
*
*/


function pwg_db_get_recent_period_expression($period, $date='CURRENT_DATE')
{
if ($date!='CURRENT_DATE')
Expand All @@ -580,6 +579,11 @@ function pwg_db_get_recent_period($period, $date='CURRENT_DATE')
return $d;
}

function pwg_db_get_flood_period_expression($seconds)
{
return 'SUBDATE(now(), INTERVAL '.$seconds.' SECOND)';
}

function pwg_db_get_hour($date)
{
return 'hour('.$date.')';
Expand Down
5 changes: 5 additions & 0 deletions include/dblayer/functions_pdo-sqlite.inc.php
Expand Up @@ -499,6 +499,11 @@ function pwg_db_get_recent_period($period, $date='CURRENT_DATE')
return $d;
}

function pwg_db_get_flood_period_expression($seconds)
{
return 'datetime(\'now\', \'localtime\', \''.-$seconds.' seconds\')';
}

function pwg_db_get_hour($date)
{
return 'strftime(\'%H\', '.$date.')';
Expand Down
5 changes: 5 additions & 0 deletions include/dblayer/functions_pgsql.inc.php
Expand Up @@ -546,6 +546,11 @@ function pwg_db_get_recent_period($period, $date='CURRENT_DATE')
return $d;
}

function pwg_db_get_flood_period_expression($seconds)
{
return 'now() - \''.$seconds.' SECOND\'::interval';
}

function pwg_db_get_hour($date)
{
return 'EXTRACT(HOUR FROM '.$date.')';
Expand Down
5 changes: 5 additions & 0 deletions include/dblayer/functions_sqlite.inc.php
Expand Up @@ -511,6 +511,11 @@ function pwg_db_get_recent_period($period, $date='CURRENT_DATE')
return $d;
}

function pwg_db_get_flood_period_expression($seconds)
{
return 'datetime(\'now\', \'localtime\', \''.-$seconds.' seconds\')';
}

function pwg_db_get_hour($date)
{
return 'strftime(\'%H\', '.$date.')';
Expand Down
10 changes: 6 additions & 4 deletions include/functions_comment.inc.php
Expand Up @@ -133,12 +133,14 @@ function insert_user_comment( &$comm, $key, &$infos )

if ($comment_action!='reject' and $conf['anti-flood_time']>0 )
{ // 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 = '
SELECT id FROM '.COMMENTS_TABLE.'
WHERE date > \''.$reference_date.'\'
SELECT count(1) FROM '.COMMENTS_TABLE.'
WHERE date > '.$reference_date.'
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') );
$comment_action='reject';
Expand Down

0 comments on commit 1ba0969

Please sign in to comment.