get_loggedin_user(); if ($fb_user) { $about = $fb->api_client->users_getStandardInfo($fb_user, 'username, sex, current_location'); $city = $state = $country = $sex = ''; if (in_array(strtolower($about[0]['current_location']['country']), array('canada', 'united states', ''))) { $zip = preg_replace("/[^a-z0-9]+/i", "", $about[0]['current_location']['zip']); if (!is_numeric($zip)) $zip = strtoupper(preg_replace("@[^a-z0-9]+@i", '', $zip)); $country = $about[0]['current_location']['country']; $state = array_shift(query("SELECT code FROM states WHERE country='{$country}' AND name='".preg_replace("/[^a-z\ ]+/i", '', $about[0]['current_location']['state'])."' LIMIT 1")->fetch_array(MYSQLI_NUM)); $city = preg_replace("/'/", "\'", $about[0]['current_location']['city']); if ($about[0]['sex']) $sex = substr($about[0]['sex'], 0, 1); $sim = $fb->api_client->users_getInfo($fb_user, 'meeting_sex, pic_big, status, about_me, birthday_date'); $result = query("SELECT lat, lon, city, state, country FROM coordinates WHERE zip='".((strlen($zip) == 6)?(substr($zip, 0, 3).' '.substr($zip, -3)):$zip)."' LIMIT 1"); while ($row = $result->fetch_array(MYSQLI_NUM)) { $city = $row[2]?$row[2]:$city; $state = $row[3]?$row[3]:$state; $country = $row[4]?$row[4]:$country; $lat = $row[0]; $lon = $row[1]; } $result = query("SELECT id, name, zip FROM users WHERE email='{$fb_user}' AND status!='0' LIMIT 1"); if ($result->num_rows == 0) { $un = trim(preg_replace("/'/", "\'", $about[0]['username'])); if (!$un) $un = 'Facebook User '.substr($fb_user, -3); query("INSERT INTO users VALUES (NULL, '{$un}', 'Facebook User', '{$fb_user}', '{$zip}', NULL, '1')"); $_uid = $mysqli->insert_id; do { $hash = md5(uniqid(microtime())); $res = query("SELECT id FROM profiles WHERE hash='$hash' LIMIT 1"); } while ($res->num_rows > 0); query("INSERT INTO profiles (id, name, hash, city, state, country, sex, online, created, updated, seen, showcity, hidden) VALUES ('$_uid', '{$un}', '$hash', '{$city}', '{$state}', '{$country}', '{$sex}', 1, NOW(), NOW(), NOW(), '1', '0')"); if ($lat && $lon) query("UPDATE profiles SET lat='$lat', lon='$lon' WHERE id='$_uid' LIMIT 1"); $sex = $_sex;$_name = $un;$_zip = $zip; $zodiac[356] = "Capricorn"; $zodiac[326] = "Sagittarius"; $zodiac[296] = "Scorpio"; $zodiac[266] = "Libra"; $zodiac[235] = "Virgo"; $zodiac[203] = "Leo"; $zodiac[172] = "Cancer"; $zodiac[140] = "Gemini"; $zodiac[111] = "Taurus"; $zodiac[78] = "Aries"; $zodiac[51] = "Pisces"; $zodiac[20] = "Aquarius"; $zodiac[0] = "Capricorn"; $date = strtotime($sim[0]['birthday_date']."/1970"); $dayOfTheYear = date("z",$date); $isLeapYear = date("L",$date); if ($isLeapYear && ($dayOfTheYear > 59)) $dayOfTheYear = $dayOfTheYear - 1; foreach($zodiac as $day => $sign) if ($dayOfTheYear > $day) break; query("INSERT INTO extendeds SET id='$_uid', star='$sign', headline='".preg_replace("/'/", "\'", $sim[0]['status']['message'])."', textline='".preg_replace("/'/", "\'", $sim[0]['about_me'])."'"); } else { list($_uid, $_name, $_zip) = $result->fetch_array(MYSQLI_NUM); $result = query("SELECT sex, seeking FROM profiles WHERE id='$_uid' LIMIT 1"); $row = $result->fetch_array(MYSQLI_NUM); $_sex = $row[0]; $_seeking = $row[1]; if ($sim[0]['about_me']) query("UPDATE extendeds SET textline='".preg_replace("/'/", "\'", $sim[0]['about_me'])."' WHERE id='$_uid' LIMIT 1"); if ($sim[0]['status']['message']) query("UPDATE extendeds SET headline='".preg_replace("/'/", "\'", $sim[0]['status']['message'])."' WHERE id='$_uid' LIMIT 1"); query("DELETE FROM sessions WHERE uid='$_uid' AND sid!='$_sid'"); } if ($sim[0]['pic_big']) { $fname = "./photos/master/".$_uid.substr(md5(uniqid(microtime())), 0, 8); file_put_contents($fname, file_get_contents($sim[0]['pic_big'])); $info = getimagesize($fname); $extension = image_type_to_extension($info[2]); rename($fname, $fname.'.'.$extension); $fname = $fname.'.'.$extension; $mw = 77; $mh = 79; $w = $mw; $h = $mh; $d = max($w / $info[0], $h / $info[1]); $w = max(1, floor($d * $info[0])); $h = max(1, floor($d * $info[1])); $im = imagecreatetruecolor($mw, $mh); if ($info[2] == 1 ) $src = @imagecreatefromgif($fname); else if ($info[2] == 2 ) $src = @imagecreatefromjpeg($fname); else if ($info[2] == 3 ) $src = @imagecreatefrompng($fname); imagecopyresampled($im, $src, 0, 0, ($w - $mw)/2, ($h - $mh)/2, $w, $h, $info[0], $info[1]); $fbi = @imagecreatefrompng("./images/connect_light_small_short.png"); imagecopy($im, $fbi, $w-18, $h-18, 0, 0, 16, 16); imagejpeg($im, './photos/thumb/'.$_uid.'.jpg', 70); imagedestroy($im); $mw = 200; $mh = 1000; $w = $mw; $h = $mh; $d = min($w / $info[0], $h / $info[1]); $w = max(1, floor($d * $info[0])); $h = max(1, floor($d * $info[1])); $im = imagecreatetruecolor($w, $h); imagecopyresampled($im, $src, 0, 0, 0, 0, $w, $h, $info[0], $info[1]); imagecopy($im, $fbi, $w-18, $h-18, 0, 0, 16, 16); imagejpeg($im, './photos/profile/'.$_uid.'.jpg', 75); imagedestroy($im); imagedestroy($fbi); imagedestroy($src); query("INSERT INTO photos VALUES('$_uid', NOW()) ON DUPLICATE KEY UPDATE `date`=NOW()"); query("UPDATE profiles SET photo='1', updated=NOW() WHERE id='$_uid' LIMIT 1"); } $_name = preg_replace("/'/", "\'", $_name); query("UPDATE sessions SET uid='$_uid', name='{$_name}', zip='$_zip', sex='$_sex', seeking=".($_seeking?"'$_seeking'":'NULL').", status='1' WHERE sid='$_sid' LIMIT 1"); } } header("HTTP/1.1 303 See Other"); header("Location: ./".($fb_user?"?profile":'')); header("Connection: close"); die; ?>