Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<?php
class zReloads
{
public $parent;
public function __construct( $zVms )
{
$this->parent = $zVms;
}
public function cleanCampaign( )
{
$zeit = time();
$sql = ' DELETE FROM `'.DB_PREIX.'_campaign_reloads` WHERE `until` <= :until ';
$sql_params = array( 'until' => $zeit );
return $this->parent->database->rawDelete( $sql, $sql_params );
}
public function cleanContent( )
{
$zeit = time();
$sql = ' DELETE FROM `'.DB_PREIX.'_content_reloads` WHERE `until` <= :until ';
$sql_params = array( 'until' => $zeit );
return $this->parent->database->rawDelete( $sql, $sql_params );
}
public function cleanAll( )
{
$this->cleanCampaign( );
$this->cleanContent( );
return true;
}
public function deleteCampaignByUserId( $uid )
{
$sql = ' DELETE FROM `'.DB_PREIX.'_campaign_reloads` WHERE `uid` = :uid ';
$sql_params = array( 'uid' => $uid );
return $this->parent->database->rawDelete( $sql, $sql_params );
}
public function deleteContentByUserId( $uid )
{
$sql = ' DELETE FROM `'.DB_PREIX.'_content_reloads` WHERE `uid` = :uid ';
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
$sql_params = array( 'uid' => $uid );
return $this->parent->database->rawDelete( $sql, $sql_params );
}
public function deleteByUserId( $uid )
{
$this->deleteCampaignByUserId( $uid );
$this->deleteContentByUserId( $uid );
}
public function addCampaign( $cid, $uid, $ip, $until )
{
$sql = 'INSERT INTO `'.DB_PREFIX.'_campaign_reloads`
(`ip`, `uid`, `cid`, `until`) VALUES
(:aip, :auid, :acid, :auntil) ON DUPLICATE KEY UPDATE
`until` = :buntil ';
$sql_params = array(
':aip' => inet_pton($ip),
':auid' => $uid,
':acid' => $cid,
':auntil'=> $until,
':buntil'=> $until,
);
return $this->parent->database->rawInsert( $sql, $sql_params );
}
public function addContent( $cid, $uid, $ip, $until )
{
$sql = 'INSERT INTO `'.DB_PREFIX.'_content_reloads`
(`ip`, `uid`, `cid`, `until`) VALUES
(:aip, :auid, :acid, :auntil) ON DUPLICATE KEY UPDATE
`until` = :buntil ';
$sql_params = array(
':aip' => inet_pton($ip),
':auid' => $uid,
':acid' => $cid,
':auntil'=> $until,
':buntil'=> $until,
);
return $this->parent->database->rawInsert( $sql, $sql_params );
}
public function hasCampaign( $cid, $uid, $ip, $time )
{
$sql = ' COUNT(`until`) AS `c`, `until` FROM `'.DB_PREFIX.'_campaign_reloads` WHERE `until` >= :until AND ( (`uid` = :uid OR `ip` = :ip) AND `cid` = :cid ) LIMIT 1';
$sql_params = array(
':until' => $time,
':uid' => $uid,
':ip' => inet_pton($ip),
':cid' => $cid,
);
$db_result = $this->parent->database->select( $sql, $sql_params );
$in_reload = ( isset($db_result[0]) && 0 == $db_result[0]->c ) ? false : true;
$until = ( $in_reload ) ? $db_result[0]->until : 0;
return array('in_reload' => $in_reload, 'until' => $until);
}
public function hasContent( $cid, $uid, $ip, $time)
{
$sql = ' COUNT(`until`) AS `c`, `until` FROM `'.DB_PREFIX.'_content_reloads` WHERE `until` >= :until AND ( (`uid` = :uid OR `ip` = :ip) AND `cid` = :cid ) LIMIT 1';
$sql_params = array(
':until' => $time,
':uid' => $uid,
':ip' => inet_pton($ip),
':cid' => $cid,
);
$db_result = $this->parent->database->select( $sql, $sql_params );
$in_reload = ( isset($db_result[0]) && 0 == $db_result[0]->c ) ? false : true;
$until = ( $in_reload ) ? $db_result[0]->until : 0;
return array('in_reload' => $in_reload, 'until' => $until);
}
}