Page Menu
Home
In-Portal Phabricator
Search
Configure Global Search
Log In
Files
F1047595
spam_helper.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Mon, Jun 30, 3:49 AM
Size
3 KB
Mime Type
text/x-php
Expires
Wed, Jul 2, 3:49 AM (11 h, 12 m)
Engine
blob
Format
Raw Data
Handle
677399
Attached To
rINP In-Portal
spam_helper.php
View Options
<?php
/**
* @version $Id: spam_helper.php 12306 2009-08-17 02:35:55Z dmitrya $
* @package In-Portal
* @copyright Copyright (C) 1997 - 2009 Intechnic. All rights reserved.
* @license GNU/GPL
* In-Portal is Open Source software.
* This means that this software may have been modified pursuant
* the GNU General Public License, and as distributed it includes
* or is derivative of works licensed under the GNU General Public License
* or other free or open source software licenses.
* See http://www.in-portal.net/license/ for copyright notices and details.
*/
defined
(
'FULL_PATH'
)
or
die
(
'restricted access!'
);
class
SpamHelper
extends
kHelper
{
/**
* Table name where spam control information is keeped
*
* @var string
*/
var
$TableName
;
/**
* RecourceId field of current item
*
* @var int
*/
var
$ResourceId
=
0
;
/**
* Type of information to put into spam control
*
* @var string
*/
var
$DataType
=
''
;
/**
* Default spam control record expiration
*
* @var int
*/
var
$Expiration
=
0
;
function
SpamHelper
()
{
parent
::
kHelper
();
$this
->
TableName
=
TABLE_PREFIX
.
'SpamControl'
;
}
/**
* Initializes helper for concrete item
*
* @param int $resource_id
* @param string $data_type
* @param int $expiration
*/
function
InitHelper
(
$resource_id
,
$data_type
,
$expiration
)
{
$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
*
* @return bool
*/
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
;
}
}
Event Timeline
Log In to Comment