An error occurred while loading the file. Please try again.
-
Christoph Zysik authoredce5e4ff0
Forked from
Eric Laufer / VMS-SUEE_2.0
89 commits behind, 34 commits ahead of the upstream repository.
zReloads.php 4.35 KiB
<?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 ';
$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);
}
}