include_once 'config.inc'; include_once 'facebook.php'; $user = null; $facebook = new Facebook(array( 'appId' => $app_id, 'secret' => $app_secret, 'cookie' => true, )); $user = $facebook->getUser(); if($user) { $logoutUrl = $facebook->getLogoutUrl(); try { // Proceed knowing you have a logged in user who's authenticated. $me = $facebook->api("/".$user); $fid = $me['id']; $name= $me['name']; toLog('USER: user_data => '.print_r($me,true),'debug',$fid); } catch (FacebookApiException $e) { toLog('Unable to retreive user('.$user.') data ('.$e.')','error'); $user = null; $loginUrl = $facebook->getLoginUrl(array( 'scope' => 'user_likes', 'redirect_uri' => $furl )); } } else { $loginUrl = $facebook->getLoginUrl(array( 'scope' => 'user_likes', 'redirect_uri' => $furl )); } if($user) { if( $tab ) { $is_fan = false; if($signed_request = parsePageSignedRequest()) { $pages_match = (bool)($signed_request->page->id==$page_id); if($signed_request->page->liked and $pages_match) $is_fan = true; toLog("TAB: pages_match => ".(int)$pages_match.", is_fan => ".(int)$is_fan.", signed_request => ".print_r($signed_request,true),'debug', $fid ); } } if( !$tab or !$pages_match ){ // check if user is a fan try { $offset_step = 100; $offset= (int)$is_fan= $next= false; do { // get teh likes from facebooks $likes = $facebook->api("/$user/likes?limit=".$offset_step.(($offset)?"&offset=".$offset:"")); // check if searched page is on list => if yes set $is_fan to true and break; foreach($likes['data'] as $like)if($like['id']==$page_id){ $is_fan=true;break; } // log retrieved likes object and basc info about search conducted on this page toLog("LIKES: page => ".floor($offset/$offset_step).", user_likes => ".print_r($likes,true).", searched_page => ".$page_id.", found => ".(int)$is_fan,'debug',$fid); // increase offset $offset+=$offset_step; // do it until searched page is found (user is a fan) or there's no more pages to go } while(!$is_fan and !empty($likes['paging']['next'])); } catch(Exception $o) { // sometimes $fb->api(); i throwing errors cheerfully, here's the place they got catched toLog('Unable to retreive user('.$user.') likes on page '.floor($offset/$offset_step).' ('.$o.') ','error', $fid); } } // get user pic square $param = array( 'method' => 'users.getinfo', 'uids' => $fid, 'fields' => 'pic_square', 'callback' => '' ); $user_info = $facebook->api($param); toLog('INFO: user_info => '.print_r($user_info,true),'debug',$fid); save_picture($user_info[0]['pic_square'],'avatar',$fid); // remove all app invites: if(!empty($_REQUEST['request_ids'])) { $request_ids = explode(',', $_REQUEST['request_ids']); foreach($request_ids as $request_id) { $full_request_id = $request_id."_".$fid; try { $deleted = $facebook->api("/$full_request_id", 'DELETE'); if($deleted) { $_SESSION['source'] = 'fb'; $_SESSION['medium'] = 'invitation'; toLog("App request removed ($full_request_id)", 'user', ( (isset($fid)) ? $fid : -1)); } else toLog("Failed to remove App request ($full_request_id) [error]", 'error', ( (isset($fid)) ? $fid : -1)); } catch (FacebookApiException $e) { // logged into 'user', because isn't critical nor even important toLog("Attempt to remove already removed App request ($full_request_id)", 'user', ( (isset($fid)) ? $fid : -1)); } } } } include 'header.inc'; if( time() <= strtotime($end) ): if($user): ?> if($is_fan): ?> $sql = "SELECT cid, fid, correct FROM ".$db_prefix."coupons WHERE fid=" . $fid . ";"; $result = mysql_query($sql); $correct = false; if(($rows = mysql_num_rows($result)) > 0) { $row = mysql_fetch_assoc($result); $correct = (bool)$row['correct']; } if($correct) { $coupon_id = $row['cid']; $coupon_url = "cache/coupons/coupon_".$coupon_id."_".$row['fid'].".jpg"; toLog('User ('.$fid.') revisited his coupon ('.$coupon_id.')', 'user', $fid); } else { // retreive coupon data for current user: $user_coupon_url = $url['data']."?promotion_id=".$promotion_id."&fid=".$fid; $coupon_data = file_get_contents($user_coupon_url); if(!$coupon_data) { toLog('Unable to retreive coupon data from '.$user_coupon_url,'error',$fid); // do sth! } else { // process coupon data: $coupon_array = json_decode($coupon_data,true); $coupon_id = (string)$coupon_array['code']; toLog('CDATA: coupons_data => '.print_r($coupon_array,true),'debug',$fid); if($coupon_id <= 0) { // responded returning error $coupon_url = false; // if unable show something instead and work in ajax to download it again toLog('Invalid coupon data retreived ('.$coupon_data.')','error',$fid); } elseif(($coupon_url = save_picture($coupon_array['img'], 'coupon', $fid, $coupon_id))<0) { // failed to cache coupon // if unable to cache coupon show one from remote server $coupon_url = $coupon_array['img']; toLog('Cacheing coupon ('.$coupon_data.') failed', 'error', $fid); } else { if($rows == 0) { $sql = "INSERT INTO ".$db_prefix."coupons (fid,cid,source,medium,new_fan) VALUES (".$fid.", '".$coupon_id."', '".$_SESSION['source']."', '".$_SESSION['medium']."', '".$_SESSION['new_fan']."');"; $result = mysql_query($sql); if(!$result) toLog('Saving coupon('.$coupon_data.') to database failed ('.$sql.')', 'error', $fid); // failed to save to mysql else toLog('User ('.$fid.') created his coupon ('.$coupon_id.')', 'user', $fid); // everything ok } else { $sql = "UPDATE ".$db_prefix."coupons SET cid='".$coupon_id."', correct=1 WHERE fid=".$fid." LIMIT 1;"; $result = mysql_query($sql); if(!$result) toLog('User ('.$fid.') failed to correct his coupon ('.$coupon_id.')', 'user', $fid); // failed to write to db else toLog('User ('.$fid.') corrected his coupon ('.$coupon_id.')', 'user', $fid); // everything ok } // remove stats data that won't be needed any more session_destroy(); } } } ?> else: ?>
, oto kupon rabatowy dla Ciebie:
albo spisz kod kreskowy i podaj sprzedawcy w sklepie.
Numer kodu: XXXXXXXXXXXXXXXX
if($is_fan and $sms_send): ?>albo
Możesz także przesłać kod rabatowy na swój telefon komórkowy. Będzie zawsze pod ręką. Wystarczy, że pokażesz go sprzedawcy przy kasie.
Wyślij kod SMSempodaj numer:
Wpisując numer telefonu oraz klikając „Wyślij”, zgodnie z zapisami ustawy o świadczeniu usług drogą elektroniczną z dnia 18 lipca 2002 r., wyrażam zgodę na świadczenie przez LPP S.A. usług drogą elektroniczną oraz na dostarczanie mi informacji handlowej o produktach i usługach własnych jak i produktach i usługach kontrahentów Reserved za pośrednictwem udostępnionego przeze mnie numeru telefonu komórkowego.
Chcesz jako pierwszy/a otrzymywać informacje o naszych promocjach i nowościach?
Zapisz się do newslettera!
Dziękujemy za udział w akcji i zapraszamy do odwiedzenia naszego profilu na Facebooku