Witaj,
Niestety, nie tędy droga, wartość zwrócona -> NULL. Sprawdzanie czy restrykcja istnieje jest dużo wcześniej, ale skoro tak mówisz, to może błędem było nie nie udostępnienie całej funkcji. Oto i ona i iteracja musi się odbyć. Myślę nad magicznym słowem continue :-)
<?php
function sort_restrictions()
{
$my_groups = array( $this->ipsclass->member['mgroup'] );
if( $this->ipsclass->member['mgroup_others'] )
{
$other_mgroups = explode( ",", $this->ipsclass->clean_perm_string( $this->ipsclass->member['mgroup_others'] ) );
$my_groups = array_merge( $my_groups, $other_mgroups ); }
$can_download = 1;
// First, loop through groups and determine what restrictions are placed on member (better overrides worse)
// Then, loop through the restrictions and see if they're blocked
// If blocked, set can_download to 0, break loop, and show error
$my_restrictions = array();
$less_is_more = array( 'min_posts', 'min_fg', 'posts_per_dl' ); // Tu dodaję min_fg też
foreach( $my_groups as $gid )
{
$group = $this->ipsclass->cache['group_cache'][ $gid ];
$this_restrictions = array(); $this_restrictions = unserialize( $group['idm_restrictions'] );
if( is_array( $this_restrictions ) AND
count( $this_restrictions ) ) {
if( $this_restrictions['enabled'] == 1 )
{
foreach( $this_restrictions as $k => $v )
{
if( isset($my_restrictions[$k]) AND
$my_restrictions[$k] == 0 ) {
// Zero is always best - it means no restriction
continue;
}
else if( in_array( $k, $less_is_more ) ) {
// Lower the better for post-based restrictions
if( isset( $my_restrictions[$k] ) ) {
if( $v < $my_restrictions[$k] )
{
$my_restrictions[$k] = $v; // Widzisz jak wygląda pętla foreach? :-)
}
}
else
{
$my_restrictions[$k] = $v;
}
}
else
{
// Higher the better for bw/dl restrictions
if( $v > intval($my_restrictions[$k]) ) {
$my_restrictions[$k] = $v;
}
}
}
}
}
}
// Now we should have this member's restrictions in place.
// Let's check...if all are 0, go ahead and return now
{
// No restrictions
return;
}
else
{
$at_least_one = 0;
foreach( $my_restrictions as $k => $v )
{
if( $v > 0 )
{
$at_least_one = 1;
break;
}
}
if( $at_least_one == 0 )
{
// All restrictions disabled
return;
}
}
// Still here? Ok, check restrictions
// Before we loop, let's get the counts we'll need (easier to do this in three queries)
// If this is a guest, check IP too
$ip_check = '';
if( !$this->ipsclass->member['id'] )
{
$ip_check = " AND dip='{$this->ipsclass->ip_address}'";
}
$one_day = time() - 86400; $daily = $this->ipsclass->DB->build_and_exec_query( array( 'select' => 'COUNT(*) as dl, SUM(dsize) as bw', 'from' => 'downloads_downloads', 'where' => 'dmid='.$this->ipsclass->member['id'].' AND dtime > '.$one_day . $ip_check ) );
$one_week = time() - 604800; $weekly = $this->ipsclass->DB->build_and_exec_query( array( 'select' => 'COUNT(*) as dl, SUM(dsize) as bw', 'from' => 'downloads_downloads', 'where' => 'dmid='.$this->ipsclass->member['id'].' AND dtime > '.$one_week . $ip_check ) );
$one_month = time() - 2592000; $monthly = $this->ipsclass->DB->build_and_exec_query( array( 'select' => 'COUNT(*) as dl, SUM(dsize) as bw', 'from' => 'downloads_downloads', 'where' => 'dmid='.$this->ipsclass->member['id'].' AND dtime > '.$one_month . $ip_check ) );
foreach( $my_restrictions as $k => $v )
{
if( $v > 0 ) // Perwsza iteracja zwraca 1, prawidłowo
{
if( array_key_exists( 'min_posts', $my_restrictions ) AND
array_key_exists( 'min_fg', $my_restrictions ) ) // Jak tutaj dać, aby w tej iteracji dał następny element czyli wartość ( $v ) min_fg? Próbować z continue? {
if( $this->ipsclass->member['posts'] < $my_restrictions['min_posts'] OR $this->ipsclass->member['fg'] < $my_restrictions['min_fg'] )
{
$this->produce_error( 'dl_restrict_min_posts' );
$this->restricted = 1;
return;
}
}
if( $k == 'posts_per_dl' )
{
// Get last download stamp
$download = $this->ipsclass->DB->build_and_exec_query( array( 'select' => 'MAX(dtime) as dtime', 'from' => 'downloads_downloads', 'where' => 'dmid='.$this->ipsclass->member['id'] . $ip_check ) );
if( $download['dtime'] )
{
$posts = $this->ipsclass->DB->build_and_exec_query( array( 'select' => 'COUNT(*) as num', 'from' => 'posts', 'where' => 'author_id='.$this->ipsclass->member['id'].' AND post_date>'.$download['dtime'] ) );
if( $posts['num'] < $v )
{
$this->produce_error( 'dl_restrict_posts_p_dl' );
$this->restricted = 1;
return;
}
}
}
if( $k == 'daily_bw' AND $daily['bw'] )
{
if( $daily['bw'] > ($v*1024) )
{
$this->produce_error( 'dl_restrict_daily_bw' );
$this->restricted = 1;
return;
}
}
if( $k == 'weekly_bw' AND $weekly['bw'] )
{
if( $weekly['bw'] > ($v*1024) )
{
$this->produce_error( 'dl_restrict_weekly_bw' );
$this->restricted = 1;
return;
}
}
if( $k == 'monthly_bw' AND $monthly['bw'] )
{
if( $monthly['bw'] > ($v*1024) )
{
$this->produce_error( 'dl_restrict_monthly_bw' );
$this->restricted = 1;
return;
}
}
if( $k == 'daily_dl' AND $daily['dl'] )
{
if( $daily['dl'] > $v )
{
$this->produce_error( 'dl_restrict_daily_dl' );
$this->restricted = 1;
return;
}
}
if( $k == 'weekly_dl' AND $weekly['dl'] )
{
if( $weekly['dl'] > $v )
{
$this->produce_error( 'dl_restrict_weekly_dl' );
$this->restricted = 1;
return;
}
}
if( $k == 'monthly_dl' AND $monthly['dl'] )
{
if( $monthly['dl'] > $v )
{
$this->produce_error( 'dl_restrict_monthly_dl' );
$this->restricted = 1;
return;
}
}
if( $k == 'limit_sim' )
{
$ip_extra = !$this->ipsclass->member['id'] ? " AND dsess_ip='{$this->ipsclass->ip_address}'" : '';
$this->ipsclass->DB->build_query( array( 'select' => '*', 'from' => 'downloads_sessions', 'where' => "dsess_mid={$this->ipsclass->member['id']}{$ip_extra}" ) ); $this->ipsclass->DB->exec_query();
while( $r = $this->ipsclass->DB->fetch_row() )
{
$this->dl_sessions[] = $r;
}
$sess_count = 0;
if( count($this->dl_sessions) ) {
foreach( $this->dl_sessions as $session )
{
// If this is a request for the same file and the HTTP_RANGE header is sent don't count
// It's probably a download manager. If HTTP_RANGE isn't set, member is trying to download two copies simultaneously
if( intval($this->ipsclass->input['id']) == $session['dsess_file'] AND
$this->ipsclass->my_getenv('HTTP_RANGE') ) {
continue;
}
$sess_count++;
}
}
if( $sess_count >= $v )
{
$this->produce_error( 'dl_restrict_sim' );
$this->restricted = 1;
return;
}
}
}
}
}
?>
Opisałem kod co i jak. Liczę dalj na porady, a ja próbuję z continue i zamknąć min_fg w funkcji.
Pozdrawiam,
Largo