[geeklog-cvs] Geeklog-1.x/public_html lib-common.php,1.672,1.673
Dirk Haun
dhaun at qs1489.pair.com
Sun Jan 20 04:36:01 EST 2008
Update of /cvsroot/geeklog/Geeklog-1.x/public_html
In directory qs1489.pair.com:/tmp/cvs-serv66205/public_html
Modified Files:
lib-common.php
Log Message:
Allow speedlimit to be used with other identifiable properties (other than the IP address)
Index: lib-common.php
===================================================================
RCS file: /cvsroot/geeklog/Geeklog-1.x/public_html/lib-common.php,v
retrieving revision 1.672
retrieving revision 1.673
diff -C2 -d -r1.672 -r1.673
*** lib-common.php 5 Jan 2008 18:50:41 -0000 1.672
--- lib-common.php 20 Jan 2008 09:35:59 -0000 1.673
***************
*** 5005,5015 ****
/**
! * Check if speed limit applies for current IP address.
*
! * @param type string type of speed limit to check, e.g. 'submit', 'comment'
! * @param max int max number of allowed tries within speed limit
! * @return int 0 = does not apply, else: seconds since last post
*/
! function COM_checkSpeedlimit( $type = 'submit', $max = 1 )
{
global $_TABLES;
--- 5005,5016 ----
/**
! * Check if speed limit applies
*
! * @param string $type type of speed limit, e.g. 'submit', 'comment'
! * @param int $max max number of allowed tries within speed limit
! * @param string $property IP address or other identifiable property
! * @return int 0: does not apply, else: seconds since last post
*/
! function COM_checkSpeedlimit($type = 'submit', $max = 1, $property = '')
{
global $_TABLES;
***************
*** 5017,5036 ****
$last = 0;
! $res = DB_query( "SELECT date FROM {$_TABLES['speedlimit']} WHERE (type = '$type') AND (ipaddress = '{$_SERVER['REMOTE_ADDR']}') ORDER BY date ASC" );
// If the number of allowed tries has not been reached,
// return 0 (didn't hit limit)
! if( DB_numRows( $res ) < $max )
! {
return $last;
}
! list( $date ) = DB_fetchArray( $res );
! if( !empty( $date ))
! {
$last = time() - $date;
! if( $last == 0 )
! {
// just in case someone manages to submit something in < 1 sec.
$last = 1;
--- 5018,5039 ----
$last = 0;
! if (empty($property)) {
! $property = $_SERVER['REMOTE_ADDR'];
! }
! $property = addslashes($property);
!
! $res = DB_query("SELECT date FROM {$_TABLES['speedlimit']} WHERE (type = '$type') AND (ipaddress = '$property') ORDER BY date ASC");
// If the number of allowed tries has not been reached,
// return 0 (didn't hit limit)
! if (DB_numRows($res) < $max) {
return $last;
}
! list($date) = DB_fetchArray($res);
! if (!empty($date)) {
$last = time() - $date;
! if ($last == 0) {
// just in case someone manages to submit something in < 1 sec.
$last = 1;
***************
*** 5042,5056 ****
/**
! * Store post info for current IP address.
*
! * @param type string type of speed limit, e.g. 'submit', 'comment'
*
*/
! function COM_updateSpeedlimit( $type = 'submit' )
{
global $_TABLES;
! DB_save( $_TABLES['speedlimit'], 'ipaddress,date,type',
! "'{$_SERVER['REMOTE_ADDR']}',unix_timestamp(),'$type'" );
}
--- 5045,5065 ----
/**
! * Store post info for speed limit
*
! * @param string $type type of speed limit, e.g. 'submit', 'comment'
! * @param string $property IP address or other identifiable property
*
*/
! function COM_updateSpeedlimit($type = 'submit', $property = '')
{
global $_TABLES;
! if (empty($property)) {
! $property = $_SERVER['REMOTE_ADDR'];
! }
! $property = addslashes($property);
!
! DB_save($_TABLES['speedlimit'], 'ipaddress,date,type',
! "'$property',UNIX_TIMESTAMP(),'$type'");
}
***************
*** 5062,5095 ****
*
*/
! function COM_clearSpeedlimit( $speedlimit = 60, $type = '' )
{
global $_TABLES;
$sql = "DELETE FROM {$_TABLES['speedlimit']} WHERE ";
! if( !empty( $type ))
! {
$sql .= "(type = '$type') AND ";
}
! $sql .= "(date < unix_timestamp() - $speedlimit)";
! DB_query( $sql );
}
/**
! * Reset the speedlimit for an IP address
*
! * @param string $type type of speed limit to reset, e.g. 'submit'
! * @param string $ip IP address (use current IP address if empty)
*
*/
! function COM_resetSpeedlimit($type = 'submit', $ip = '')
{
global $_TABLES;
! if (empty($ip)) {
! $ip = $_SERVER['REMOTE_ADDR'];
}
! $ip = addslashes($ip);
! DB_query("DELETE FROM {$_TABLES['speedlimit']} WHERE (type = '$type') AND (ipaddress = '$ip')");
}
--- 5071,5103 ----
*
*/
! function COM_clearSpeedlimit($speedlimit = 60, $type = '')
{
global $_TABLES;
$sql = "DELETE FROM {$_TABLES['speedlimit']} WHERE ";
! if (!empty($type)) {
$sql .= "(type = '$type') AND ";
}
! $sql .= "(date < UNIX_TIMESTAMP() - $speedlimit)";
! DB_query($sql);
}
/**
! * Reset the speedlimit
*
! * @param string $type type of speed limit to reset, e.g. 'submit'
! * @param string $property IP address or other identifiable property
*
*/
! function COM_resetSpeedlimit($type = 'submit', $property = '')
{
global $_TABLES;
! if (empty($property)) {
! $property = $_SERVER['REMOTE_ADDR'];
}
! $property = addslashes($property);
! DB_query("DELETE FROM {$_TABLES['speedlimit']} WHERE (type = '$type') AND (ipaddress = '$property')");
}
***************
*** 5100,5105 ****
* This function returns a crawler friendly URL (if possible)
*
! * @param string $url URL to try to build crawler friendly URL for
! * @return string Rewritten URL
*/
--- 5108,5113 ----
* This function returns a crawler friendly URL (if possible)
*
! * @param string $url URL to try to build crawler friendly URL for
! * @return string Rewritten URL
*/
More information about the geeklog-cvs
mailing list