getUser(); $NEED_APP = array("question", "answer"); $TYPES = array("text", "video", "photo"); //if($_SERVER["REMOTE_ADDR"] == "92.244.127.145"){ if($_SERVER["REMOTE_ADDR"] == "213.238.9.4"){ #print "
"; print_r($_SESSION["PAGE_DATA"]); print "
"; #exit; }else{ } // IMPORTANT!!! if($_SESSION["PAGE_DATA"]["oauth_token"]) $facebook->setAccessToken($_SESSION["PAGE_DATA"]["oauth_token"]); if($FBID > 0 && 1==2){ if(!$_SESSION["FBP"]){ try { $FB_PROFILE = $facebook->api('/me?fields=id,name,link,email'); } catch (FacebookApiException $e) { # error_log($e); if($_SERVER["REMOTE_ADDR"] == "213.238.9.4"){ #print "
"; print_r($e); print "
"; #exit; } } $_SESSION["FBP"] = $FB_PROFILE; } if($_SERVER["REMOTE_ADDR"] == "213.238.9.4"){ #print "
"; print_r($_SESSION); print "
"; #exit; } $db->query("SELECT * FROM `danonestory_users` WHERE `fb_id`= " . $FBID, "user"); $USER_PROFILE = $db->fetch_assoc("user"); if($USER_PROFILE["userId"]){ // Получаем список того, за, что пользователь уже проголосовал $db->query("SELECT workId FROM `danonestory_votes` WHERE userId = " . $USER_PROFILE["userId"], "votesfor"); while($_r = $db->fetch_row("votesfor")){ $USER_VOTES[] = $_r[0]; } }else{ $db->query("INSERT INTO `danonestory_users` VALUES('', '".$FBID."', '".$FB_PROFILE["name"]."', '".$FB_PROFILE["link"]."', '', CURRENT_TIMESTAMP())", "newuser"); } $FB_DATA = array( 'me' => $FB_PROFILE, 'uid' => $FBID, 'loginUrl' => $facebook->getLoginUrl( array( 'scope' => 'email,publish_stream,user_videos,user_photos', // app permissions 'redirect_uri' => './' // URL where you want to redirect your users after a successful login ) ), 'logoutUrl' => $facebook->getLogoutUrl(), ); }else{ //print ''; //exit; } if(in_array( $PAGE, $NEED_APP )){ if(!$FBID){ //header("Location: " . $facebook->getLoginUrl() ); print ''; exit; } } if($PAGE == "add" && !count($_SESSION["PAGE_DATA"]["user"])){ $PAGE = "new"; } switch($PAGE){ case "end": include("ui/the_end.php"); break; case "new": include("ui/new.php"); break; case "add": if($_SERVER["REMOTE_ADDR"] == "92.244.127.145"){ #print "dsfsdf"; #print "
"; print_r($_SESSION["PAGE_DATA"]); print "
"; #exit; } #print "
"; print_r($FB_DATA); print "
"; /* $video_title = "Title"; $video_desc = "Description"; print "1. " . $facebook->getAccessToken() . "
"; print "2. " . $facebook->getUserAccessToken(); $post_url = "https://graph-video.facebook.com/me/videos?" . "title=" . $video_title. "&description=" . $video_desc . "&". $token_url; */ include("ui/add.php"); exit; break; case "addnew": if( in_array( $_POST["type"], $TYPES ) ){ if($_POST["description"] == ""){ print "no-desc"; exit; } if($_POST["phone"] == ""){ print "no-phone"; exit; } if($_POST["type"] == "photo"){ if(count($_FILES)){ $SCRIPT_ROOT = dirname(__FILE__); checkUploadDir($SCRIPT_ROOT . "/img/story/" . $USER_PROFILE["fb_id"] ); checkUploadDir($SCRIPT_ROOT . "/img/story/" . $USER_PROFILE["fb_id"] . "/small" ); #$_small = uplOneFile($_FILES, $SCRIPT_ROOT . "/img/story/" . $USER_PROFILE["fb_id"] . "/small/"); checkUploadDir($SCRIPT_ROOT . "/img/story/" . $USER_PROFILE["fb_id"] . "/big" ); $_big = uplOneFile($_FILES, $SCRIPT_ROOT . "/img/story/" . $USER_PROFILE["fb_id"] . "/big/"); resizeImage($SCRIPT_ROOT . "/img/story/" . $USER_PROFILE["fb_id"] . "/big/" . $_big["name"], '500'); cropImage("100", "75", $SCRIPT_ROOT . "/img/story/" . $USER_PROFILE["fb_id"] . "/big/" . $_big["name"], $SCRIPT_ROOT . "/img/story/" . $USER_PROFILE["fb_id"] . "/small/" . $_big["name"]); $_fileUrl = $_big["name"] ? $_big["name"] : ""; }else{ print "no-photo"; exit; } } if($_POST["type"] == "video"){ if(count($_FILES)){ $vid = realpath($_FILES['file']['tmp_name']); $new_name = $vid . $_FILES['file']['name']; rename($vid, $new_name); #$new_name = "./tmp/" . $_FILES['file']['name']; #move_uploaded_file($_FILES['file']['tmp_name'], $new_name); $facebook->setFileUploadSupport(TRUE); // upload video $file = $new_name; $video_title = "Історія моєї подорожі"; $video_desc = "Я приймаю участь у конкурсі від Activia"; try { $video = $facebook->api('/me/videos', 'POST', array('access_token' => $facebook->getAccessToken(), 'source' => '@' . realpath($file), 'title' => $video_title, 'description' => $video_desc, )); }catch (FacebookApiException $e) { if($_SERVER["REMOTE_ADDR"] == "213.238.8.13"){ print "
"; print_r($e); print "
"; } #error_log($e); exit; } // get video info $video_id = $video["id"];//'500764699939591';//$video["id"]; try { $fql = 'SELECT vid, owner, title, description, thumbnail_link, embed_html, updated_time, created_time FROM video WHERE vid= ' . $video_id; $video_info = $facebook->api(array( 'method' => 'fql.query', 'query' => $fql, )); }catch (FacebookApiException $e) { #print "
"; print_r($e); print "
"; #error_log($e); } $video_data["id"] = $video["id"]; $video_data["info"] = $video_info[0]; #print "
"; print_r($video_data); print "
"; $_fileUrl = serialize($video_data); }else{ print "no-video"; exit; } } $_desc = addslashes($_POST["description"]); $db->query("INSERT INTO `danonestory_works` VALUES ('', '".$USER_PROFILE["userId"]."', '".$_POST["type"]."', '".$_fileUrl."', '".$_desc."', '0', '0', '1', CURRENT_TIMESTAMP())"); $db->query("UPDATE `danonestory_users` SET `phone` = " . addslashes($_POST["phone"]) . " WHERE userId = " . $USER_PROFILE["userId"] . " LIMIT 1"); #header("Location: ./app.php?p=list&type=".$_POST["type"]); print "good"; exit; } exit; break; case "list": $BG = "bg_inner"; #$db->query("SELECT w.*, u.`name`, u.`fb_id` FROM `danonestory_works` AS w LEFT JOIN `danonestory_users` AS u ON w.`userId` = u.`userId` WHERE w.`is_public` = 1 ORDER BY w.`created_at` DESC", "list"); $db->query("SELECT w.*, u.`name`, u.`fb_id` FROM `danonestory_works` AS w LEFT JOIN `danonestory_users` AS u ON w.`userId` = u.`userId` WHERE w.`is_public` = 1 AND w.`userId` > 0 ORDER BY w.`created_at` DESC", "list"); $i = 0; while($_r = $db->fetch_assoc("list")){ if($_r["type"] == "video"){ $_r["file"] = unserialize($_r["file"]); $video_info = array(); if($_r["file"]["info"] == ""){ $video_id = $_r["file"]["id"]; $fql = 'SELECT vid, owner, title, description, thumbnail_link, embed_html, updated_time, created_time FROM video WHERE vid= ' . $video_id; try{ $video_info = $facebook->api(array( 'method' => 'fql.query', 'query' => $fql, )); }catch (FacebookApiException $e) { error_log($e); } } if(count($video_info)){ $_r["file"]["info"] = $video_info[0]; $db->query("UPDATE `danonestory_works` SET `file` = '". serialize($_r["file"]) ."' WHERE workId = " . $_r["workId"] . " LIMIT 1" , 'add'); } #print "
"; print_r($_r); print "
"; } $WORKS[$_r["type"]][] = $_r; } include("ui/list.php"); break; case "show": $wid = intval($_GET["word_id"]); $db->query("SELECT w.*, u.`name`, u.`fb_id` FROM `danonestory_works` as w LEFT JOIN `danonestory_users` AS u ON w.`userId` = u.`userId` WHERE w.`workId` = $wid LIMIT 1"); $WORK = $db->fetch_assoc(); $WORK["can_vote"] = in_array( $WORK["workId"], $USER_VOTES) ? 0 : 1; if($WORK["type"] == "video"){ $WORK["file"] = unserialize($WORK["file"]); } $db->query("UPDATE `danonestory_works` SET `views` = views + 1 WHERE `workId` = $wid LIMIT 1", "upd"); include("ui/one_work.php"); break; case "vote": if(date("z") > 273){ exit; } if($_SERVER["REMOTE_ADDR"] == "92.244.127.145"){ #print $facebook->getAccessToken(); #print "
"; print_r($USER_PROFILE); print "
"; #print "
"; print_r($_SESSION["PAGE_DATA"]); print "
"; #exit; } if( !$USER_PROFILE["userId"] ){ // Если пользователя нет, добавляем его. $FB_PROFILE = $facebook->api('/me?fields=id,name,link,email'); $db->query("INSERT INTO `danonestory_users` VALUES('', '".$FBID."', '".$FB_PROFILE["name"]."', '".$FB_PROFILE["link"]."', '', CURRENT_TIMESTAMP())", "newuser"); $db->query("SELECT * FROM `danonestory_users` WHERE `fb_id`= " . $FBID, "user"); $USER_PROFILE = $db->fetch_assoc("user"); } $_wid = $_POST["wid"]; $_author = addslashes($_POST["author"]); $_post = array( 'name' => 'Вигравай пригоду своєї мрії', 'link' => FB_PAGE_URL . '?app_data=' . $_wid, 'message' => 'Я проголосував за пригоду мрії «'.$_author.'»', 'picture' => 'https://uacdn.org/activia_stories/ui/img/activia_contest_thumbnail.jpg'); if($_SERVER["REMOTE_ADDR"] == "95.135.8.45"){ #print "
"; print_r($_post); print "
"; #print "
"; print_r($_SESSION["FB_DATA"]); print "
"; } try { $ret_obj = $facebook->api('/me/feed', 'POST', $_post); } catch(FacebookApiException $e) { #print "error-post"; #if($_SERVER["REMOTE_ADDR"] == "92.244.127.145"){ # print "
"; print_r($e); print "
"; #exit; #} #exit; } $_uid = $USER_PROFILE["userId"]; $_wid = intval($_POST["wid"]); $db->query("SELECT * FROM `danonestory_votes` WHERE userId = $_uid AND workId = $_wid LIMIT 1", "ck"); $_res = $db->fetch_assoc("ck"); if(!$_res["userId"]){ // Сохраняем $db->query("INSERT INTO `danonestory_votes` VALUES('$_uid', '$_wid', CURRENT_TIMESTAMP() )"); $db->query("UPDATE `danonestory_works` SET `votes` = votes + 1 WHERE workId = $_wid LIMIT 1"); print "good"; }else{ print "error"; } break; case "user": $id = intval($_GET["user_id"]); $db->query("SELECT * FROM `danonestory_users` WHERE userId = $id"); $USER = $db->fetch_assoc(); if($USER){ $db->query("SELECT * FROM `danonestory_works` AS w WHERE `userId` = $id AND `is_public` = 1 ORDER BY `created_at` DESC", "list"); $i = 0; while($_r = $db->fetch_assoc("list")){ if($_r["type"] == "video"){ $_r["file"] = unserialize($_r["file"]); } $WORKS[$_r["type"]][] = $_r; } #print "
"; print_r($WORKS); print "
"; include("ui/user.php"); } break; case "notfan": include("ui/not_fan.php"); break; default: //$BG = "bg_home"; //include("ui/main.php"); include("ui/the_end.php"); break; } ?>