{'System/BaseURL'} ) { # this is homepage $homepage = 'YES'; # $match = " and ((do_where='1') or (do_where='3')) "; } # read our background_array from background_country_list $QBA = "SELECT * FROM background_country_list limit 1"; $RBA = $DatabaseObj->fetchAll($QBA); $BA = $RBA[0]; # setup our array $backgrounds_array = array(); if ($BA->backgrounds_array != '') { #$backgrounds_array = unserialize($BA->backgrounds_array); $backgrounds_array = dec($BA->backgrounds_array); } #echo '
!!! full!!!'; #print_r($backgrounds_array); # handle empty? # at least make them arrays # the countries if (!is_array($backgrounds_array[0])) $backgrounds_array[0] = array(); # the backgrounds --- full pool if (!is_array($backgrounds_array[1])) $backgrounds_array[1] = array(); # setup the ANY pool if (!is_array($backgrounds_array[2])) $backgrounds_array[2] = array(); #print_r($backgrounds_array[2]); # setup the PRIORITY pool if (!is_array($backgrounds_array[3])) $backgrounds_array[3] = array(); # setup the ACTIVE pool (for homepage) if (!is_array($backgrounds_array[4])) $backgrounds_array[4] = array(); # setup the ACTIVE pool (for non-homepage) if (!is_array($backgrounds_array[5])) $backgrounds_array[5] = array(); ################# ################# # the first thing we want to do is see if we have a country for this caller require_once "Net/GeoIP.php"; $geoip = Net_GeoIP::getInstance("/var/www/html/recipebridge.com/html/geo/GeoIP.dat"); if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) { $rip = $_SERVER['HTTP_X_FORWARDED_FOR']; } else { $rip = $_SERVER['REMOTE_ADDR']; } try { #echo $geoip->lookupCountryCode('71.0.170.218'); $cc = $geoip->lookupCountryCode($rip); } catch (Exception $e) { // Handle exception } ################## ################## function filter_homepage($var) { # do_where = 1 or 3 = homepage # do_where = 1 or 2 = not homepage if ($var->do_where == '1') return(1); if ($var->do_where == '3') return(1); return(0); } function filter_not_homepage($var) { # do_where = 1 or 3 = homepage # do_where = 1 or 2 = not homepage if ($var->do_where == '1') return(1); if ($var->do_where == '2') return(1); return(0); } # for testing no country #$cc = ''; #$cc = 'AU'; #$cc = 'CA'; # do we have some defined country? ###################### ###################### # defined country if ($cc != '') { # we have some defined country # echo '

Country:'.$cc; # simple test case for NOT ACTIVE -- if so treat this as no defined country # check our country array $pool = $backgrounds_array[0]; # find the matching country foreach ($pool as $country) { if ($country->kv == $cc) { # this is our COUNTRY # is it active? if ($country->status != '1') { # no? # clear our country code $cc = ''; break; } # this break leaves country set break; } } # end foreach } # end some defined country ###################### ###################### # defined country if ($cc != '') { echo '

MS Found Country:'.$cc; # print_r($country); # we are still active after the simple test $cid = $country->id; # is priority enforced for this country? $ep = $country->enforce_priority; $hpr = $country->have_priority_records; # 0 = no 1 = yes $allow_any = $country->allow_any; # now we must fill our pool #$pool = array(); ################ ################ # do we BOTH enforce priority and have priority records? if ($ep == '1') { # we DO enforce priority if ($hpr == 'Y') { # we have priority records # we MUST pick from this pool ONLY # do not add in the ANY records $allow_any = 0; $tpool = $backgrounds_array[3][$cid]; # echo '

have priority records and do enforce priorty'; # print_r($pool); } else { # we do enforce priority but we have no priority records # we can choose from the active country records AND any (if allowed) # bring in the COUNTRY records # filter the pool for the homepage if ($homepage == 'YES') { #echo '
pool before:'; #print_r($pool); $pool = $backgrounds_array[4][$cid]; $cpool = array_filter($pool,filter_homepage); #echo '

pool after homepage:'; #print_r($tpool); } else { $pool = $backgrounds_array[5][$cid]; $cpool = array_filter($pool,filter_not_homepage); #echo '

pool after not homepage:'; #print_r($tpool); } $tpool = $cpool; } # end ep } else { # we DONT enforce priority # bring in the active country records # filter the pool for the homepage if ($homepage == 'YES') { #echo '
pool before:'; #print_r($pool); $pool = $backgrounds_array[4][$cid]; if ($pool == '') $pool = array(); $cpool = array_filter($pool,filter_homepage); #echo '

pool after homepage:'; #print_r($tpool); } else { $pool = $backgrounds_array[5][$cid]; if ($pool == '') $pool = array(); $cpool = array_filter($pool,filter_not_homepage); #echo '

pool after not homepage:'; #print_r($tpool); } $tpool = $cpool; } # end else ep # tpool holds what we've gathered so far.... # do we allow any? if ($allow_any == '1') { # yes -- merge that in # bring in the ANY pool $pool = $backgrounds_array[2]; #print_r($pool); # filter the ANY pool for the homepage if ($homepage == 'YES') { #echo '
pool before:'; #print_r($pool); $apool = array_filter($pool,filter_homepage); #echo '

pool after homepage:'; #print_r($tpool); } else { $apool = array_filter($pool,filter_not_homepage); #echo '

pool after not homepage:'; #print_r($tpool); } # and merge any pool -- filtered) $tpool = $tpool + $apool; } # end if allow any #echo 'after'; # tpool contains our pool -- handle sessions $Result = ''; # do we have any left? $pc = count($tpool); #echo '

tpc:'.$pc; #print_r($pool); if ($pc > 0) { # we have some pool entries # pick one.... $done = 'NO'; while ($done == 'NO') { # we might have looped and emptied the pool $pc = count($tpool); if ($pc == '0') { # clear any result $Result = ''; $done == 'YES'; #echo '

...empty pool'; break; } # pick a random entry from pool $rand_key = array_rand($tpool); $Result = $tpool[$rand_key]; # we have a result $done = 'YES'; # echo '

Initial result:'; # print_r($Result); $limit = $Result->do_sessions; #echo '

limit:'.$limit; if ($limit != '0') { # this result must check sessions.... # we have some id $bid = $Result->id; if(isset($_SESSION['background_session_check'][$bid])) { # this background has been seen before! $seen = $_SESSION['background_session_check'][$bid]; #echo '

seen:'.$seen; # are we greater than our limit? if ($seen > $limit ) { # we ARE greater than our BID -- we CANNOT use this background # drop it from our pool # and try again #echo '

out of pool'; unset($tpool[$bid]); $Result = ''; $done = 'NO'; } } # increment our seen count for this result $_SESSION['background_session_check'][$bid] = $seen+1; } } # end while not done } else { # no entries left in pool -- no background ...done! } } # end handle country ###################### ###################### # NO defined country (or country found but not active! if ($cc == '') { # we have NO defined country -- use any active record from the ANY pool # we will NOT enforce priority (any pool) but we might enforce sessions $pool = $backgrounds_array[2]; # filter the ANY pool for the homepage if ($homepage == 'YES') { #echo '
pool before:'; #print_r($pool); $tpool = array_filter($pool,filter_homepage); #echo '

pool after homepage:'; #print_r($tpool); } else { $tpool = array_filter($pool,filter_not_homepage); #echo '

pool after not homepage:'; #print_r($tpool); } # print_r($tpool); #unset($tpool[3]); #echo '

unset:'; # print_r($tpool); #exit; # do we have any left? $pc = count($tpool); #echo 'tpc:'.$pc; if ($pc > 0) { # we have some pool entries # pick one.... $done = 'NO'; while ($done == 'NO') { # we might have looped and emptied the pool $pc = count($tpool); if ($pc == '0') { # clear any result $Result = ''; $done == 'YES'; break; } # pick a random entry from pool $rand_key = array_rand($tpool); $Result = $tpool[$rand_key]; # we have a result $done = 'YES'; # echo '

Initial result:'; # print_r($Result); $limit = $Result->do_sessions; #echo '

limit:'.$limit; if ($limit != '0') { # this result must check sessions.... # we have some id $bid = $Result->id; if(isset($_SESSION['background_session_check'][$bid])) { # this background has been seen before! $seen = $_SESSION['background_session_check'][$bid]; #echo '

seen:'.$seen; # are we greater than our limit? if ($seen > $limit ) { # we ARE greater than our BID -- we CANNOT use this background # drop it from our pool # and try again #echo '

out of pool'; unset($tpool[$bid]); $Result = ''; $done = 'NO'; } } # increment our seen count for this result $_SESSION['background_session_check'][$bid] = $seen+1; } } # end while not done } else { # no entries left in pool -- no background ...done! } # end if no country defined } # end some country processing # we have picked an entry to show # echo '

Final result:'; # print_r($Result); if ((isset($Result)) and ($Result != '')) { # we have a result to show ################# # we need to deal with the new background options # if they are set we will apply them # !!! note that CENTERING overides some other options if ($Result->do_background_color != '-1') { # we have some background color $the_color = $Result->do_background_color; # background color -- this is a css modification ?> do_position; $top = $Result->do_top; # we have to modify the top based on the home page or other page # what is our page? #echo "

".$this->{'System/BaseURL'}."

"; #print_r($_SERVER); # adjust positon if FIXED to offset header (and zero top) $cval = 'http://'.$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI']; if ($position == 'absolute') if ( $cval == $this->{'System/BaseURL'} ) { $top = 44; } else { $top = 111; } ?> do_centering; if ($centering == '1'){ # do not apply left } else { # apply left $left = $Result->do_left; ?> do_width; if ($width != '0') { # we have some set width ?> new_window == '0') { $nw = ''; } else { $nw = ' target="_blank" '; } $t_file = '/var/www/html/recipebridge.com/html/backgrounds/'.$Result->file_name; $t_url = $this->{'System/BaseURL'}.'backgrounds/'.$Result->file_name; if ($Result->show_html != '1') if (file_exists($t_file)) { # yes show it # we are showing the image directly...and activating the click logic #echo ' '; # if CENTERING is active style differently if ($centering == '1'){ # centering IS active $size = getimagesize($t_file); $width = $size[0]; # default if not provided if (!is_numeric($width)) $width=1200; echo '
'; echo 'image description'; echo '
'; } else { # no centering echo 'image description'; } # end else centering ############ # script to activate click ?> show_html != '1') echo 'image description'; } if ($Result->show_html == '1') { # add extra click to my_body if present ?> html; $html = str_replace("\'","'", $html); $html = str_replace('\"','"', $html); $html = str_replace('\r\n',"\n", $html); echo $html; } } # end Result (should be only 1) ?>