Skip to content

Instantly share code, notes, and snippets.

@masonticehurst
Last active September 30, 2018 03:37
Show Gist options
  • Save masonticehurst/6c317464a62955469704e30db89b3819 to your computer and use it in GitHub Desktop.
Save masonticehurst/6c317464a62955469704e30db89b3819 to your computer and use it in GitHub Desktop.
TinderRates Updated Initialization and Index Page
<?php
// Debug
// ini_set('display_errors', 1);
// ini_set('display_startup_errors', 1);
// error_reporting(E_ALL);
// Define the account we're using (Email)
// global $user;
// PHP Functions
function SQLInit( ){
$CONN_INFO = array(
"host" => "127.0.0.1",
"username" => "no",
"password" => "no",
"database" => "no"
);
if( !isset( $DB ) || !$DB ){
$DB = mysqli_connect( $CONN_INFO["host"], $CONN_INFO["username"], $CONN_INFO["password"], $CONN_INFO["database"] );
if( !$DB ){
print( "Error: Unable to connect to MySQL." );
exit;
}
}
return $DB;
}
function getActiveAPIKey( ){
global $user;
$DB = SQLInit( );
$q = $DB->prepare("SELECT `tinder_api` FROM `fb_accounts` WHERE `fb_user`=?");
$q->bind_param("s", $user);
$q->execute();
$q->bind_result($sKey);
$q->fetch();
$q->close();
return $sKey;
}
function getFacebookData( ){
global $user;
$DB = SQLInit( );
$q = $DB->prepare("SELECT `fb_id`, `fb_token` FROM `fb_accounts` WHERE `fb_user`=?");
$q->bind_param("s", $user);
$q->execute();
$result = $q->get_result();
$row = $result->fetch_assoc();
$q->close();
return $row;
}
function createCurl( $sURL, $pData, $aHeaderArray ){
global $user;
$c = curl_init();
curl_setopt($c, CURLOPT_URL, $sURL);
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($c, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($c, CURLOPT_POST, 0);
curl_setopt($c, CURLOPT_CUSTOMREQUEST, 'GET');
if( isset( $pData ) ){
curl_setopt($c, CURLOPT_POSTFIELDS, $pData);
curl_setopt($c, CURLOPT_POST, 1);
curl_setopt($c, CURLOPT_CUSTOMREQUEST, '');
}
curl_setopt($c, CURLOPT_USERAGENT, 'Tinder/7.5.3 (iPhone; iOS 10.3.2; Scale/2.00)');
curl_setopt($c, CURLOPT_HTTPHEADER, $aHeaderArray);
$exec = curl_exec($c);
$data = json_decode($exec, true);
curl_close($c);
return $data;
}
function getNewAPIKey( ){
global $user;
$fb_data = getFacebookData( $user );
$pData = array(
"facebook_token" => $fb_data["fb_token"],
"facebook_id" => $fb_data["fb_id"],
);
$aHeaderArray = array(
'Content-Type: application/json',
);
$data = createCurl( "https://api.gotinder.com/auth", $pData, $aHeaderArray );
// Update in database
$DB = SQLInit( );
$q = $DB->prepare("UPDATE `fb_accounts` SET `tinder_api`='?' WHERE `fb_user`='?'");
$q->bind_param("ss", $data["token"], $user);
$q->execute();
$q->close();
return $data["token"];
}
function pingAPIKey( ){
global $user;
$sKey = getActiveAPIKey( $user );
$XAuth = 'X-Auth-Token: ' . $sKey;
$CType = 'Content-Type: application/json';
$aHeaderArray = array(
$XAuth,
$CType,
);
$data = createCurl( "https://api.gotinder.com/user/recs", null, $aHeaderArray );
if( $data['status'] != 200 ){
$newKey = getNewAPIKey();
// echo("API KEY UPDATED SUCCESSFULLY!");
}
}
function attemptCall( ){
global $user;
$sKey = getActiveAPIKey( $user );
$XAuth = 'X-Auth-Token: ' . $sKey;
$CType = 'Content-Type: application/json';
$aHeaderArray = array(
$XAuth,
$CType,
);
$data = createCurl( "https://api.gotinder.com/user/recs", null, $aHeaderArray );
return $data;
}
function getResults( &$acc_array, $age_limit ){
global $user;
$data = attemptCall( $user );
if( $data['status'] == 401 ){
pingAPIKey( $user );
$data = attemptCall( $user );
}
for($i = 0; $i < sizeof( $data['results'] ); $i++ ){
$result = $data['results'][$i];
if( !isset( $result ) ){
// Broken profile?
continue;
}
if( in_array( $result['_id'], $acc_array ) ){
// Duplicate, skip
continue;
}
$birthDate = explode("-", $result['birth_date']);
$age = (2018 - (int)($birthDate[0]));
if( $age > $age_limit ){
continue;
}
$occupation = "None";
$jobData = $result['jobs'];
if( isset( $jobData[0] ) && isset( $jobData[0]['title'] ) ){
$occupation = $jobData[0]['title']['name'];
}
$x = ( $i - 1 ) % 3;
$divTypes = array("left: 0px;", "left: 0px; right: 0px; margin: auto;", "right: 0px;");
$currentStyle = $divTypes[ ( $i ) % 3];
$currentID = ( $i % 4 ) + 1;
if( $i >= 12 ){
return;
}
$name_bday = $result['name'] . ", " . (2018 - (int)($birthDate[0]));
echo '<div class="col s6 center-align" id="extra-pic-container" style="min-width: 614.5px;min-height: 591px;">';
echo '<figure>';
echo '<a href="https://profile.tinderrates.com/index.php?id=' . $result['_id'] . '" target="_blank">';
echo '<center>';
echo '<img alt="' . $name_bday . '" id="profile-pic" width=100% src="' . $result['photos'][0]['url'] . '">';
echo '</center>';
echo '<font face="Source Sans Pro">';
echo '<figcaption>' . $name_bday . '</a></figcaption>';
echo '<figcaption>Occupation: ' . $occupation . '</figcaption>';
echo "</figure></font>";
echo "</div>";
$acc_array[] = $result['_id'];
}
}
?>
<?php
// Debug
// ini_set('display_errors', 1);
// ini_set('display_startup_errors', 1);
// error_reporting(E_ALL);
$user = "kpjVideo@yahoo.se";
include( "mysql/_tinder_init.php" );
?>
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0-beta/css/materialize.min.css">
<link rel="stylesheet" type="text/css" href="css/profile.css">
<link rel="stylesheet" type="text/css" href="css/universal.css">
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,600,700,300italic,400italic,600italic">
<meta name="description" content="Tinder Rates is a free, fast, open-source website dedicated to searching profiles on the popular dating application, Tinder. ">
<meta name="og:description" content="Tinder Rates is a free, fast, open-source website dedicated to searching profiles on the popular dating application, Tinder. ">
<meta name="twitter:card" content="summary" />
<!-- Unused meta data
<meta property="og:title" content="Buenos Aires - Argentina" />
<meta property="title" content="Buenos Aires - Argentina" />
<meta property="twitter:title" content="Buenos Aires - Argentina" />
-->
<script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0-beta/js/materialize.min.js"></script>
<title>Tinder Rates</title>
</head>
<body>
<?php
include_once( "fb_login.php" );
?>
<div id="topbar">
<div id="topbar-logo-text">
Tinder Rates
</div>
<a href="https://tinderrates.com/login.php">
<div id="topbar-button-signin">
<div id="topbar-button-signin-text">
Sign-In
</div>
</div>
</a>
</div>
<br>
<div id="main-content-container">
<div class="container" style="width: 88%;height: 100%;max-width: 100%;margin: auto;">
<div class="row" style="width: 100%;height: 100%;">
<div style="display: flex;flex-wrap: wrap;justify-content: center;align-items: center;">
<?php
$yeet = array();
while( count( $yeet ) < 12 ){
getResults( $yeet, 25 );
if( count( $yeet ) <= 0 ){
return;
}
}
?>
</div>
</div>
</div>
</div>
<br>
<div id="main-content-container">
<div class="container" style="width: 88%;height: 100%;max-width: 100%;margin: auto;">
<div class="row" style="width: 100%;height: 100%;">
<div style="display: flex;flex-wrap: wrap;justify-content: center;align-items: center;">
<div style="background-color:white;"></div>
</div>
</div>
</div>
</div>
<br>
<div id="showmore">
<!-- Maybe this will be implemented one day -->
</div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment