Index: branches/5.0.x/core/units/general/helpers/spam_helper.php =================================================================== diff -u -r12117 -r12299 --- branches/5.0.x/core/units/general/helpers/spam_helper.php (.../spam_helper.php) (revision 12117) +++ branches/5.0.x/core/units/general/helpers/spam_helper.php (.../spam_helper.php) (revision 12299) @@ -1,6 +1,6 @@ TableName = TABLE_PREFIX.'SpamControl'; } - + /** * Initializes helper for concrete item * @@ -59,62 +61,62 @@ { $this->ResourceId = $resource_id; $this->DataType = $data_type; - + if (preg_match('/(.*):(.*)/', $expiration, $regs)) { $delay_value = $this->Application->ConfigValue($regs[1]); $delay_interval = $this->Application->ConfigValue($regs[2]); $expiration = $delay_value * $delay_interval; } - + $this->Expiration = adodb_mktime() + $expiration; } - + /** * Returns WHERE clause that identified each spam control record * * @param bool $as_array return result as array, not string - * + * * @return string */ function GetKeyClause($as_array = false) { $user_id = $this->Application->RecallVar('user_id'); - + if ($user_id == 0) { $user_id = -2; } - + $keys = Array ( 'ItemResourceId' => $this->ResourceId, 'IPaddress' => $_SERVER['REMOTE_ADDR'], 'PortalUserId' => $user_id, 'DataType' => $this->DataType, ); - + if ($as_array) { return $keys; } - + $ret = ''; foreach ($keys as $field_name => $field_value) { $ret .= '('.$field_name.' = '.$this->Conn->qstr($field_value).') AND '; } - + return preg_replace('/(.*) AND $/', '\\1', $ret); } - + /** * Allows to add current item in spam control * */ function AddToSpamControl() { $fields_hash = $this->GetKeyClause(true); - + $fields_hash['Expire'] = $this->Expiration; $this->Conn->doInsert($fields_hash, $this->TableName); } - + /** * Allows to check if current item is in spam control * @@ -123,23 +125,20 @@ function InSpamControl() { $key_clause = $this->GetKeyClause(); - + $sql = 'SELECT Expire FROM '.$this->TableName.' WHERE '.$key_clause; $expires = $this->Conn->GetOne($sql); - + if ($expires && $expires < adodb_mktime()) { // spam control record is expired $sql = 'DELETE FROM '.$this->TableName.' WHERE '.$key_clause; $this->Conn->Query($sql); return false; } - + return $expires ? true : false; } - - } - -?> \ No newline at end of file + } \ No newline at end of file