<?php $filename = "songs.json"; include('lib/config.php'); include('lib/sqlquery.php'); // get contents of a file into a string $handle = fopen($filename, "r"); $contents = fread($handle, filesize($filename)); fclose($handle); if ($contents) { $songs = json_decode($contents, true); if (array_key_exists('songs', $songs) and is_array($songs['songs'])) { $DB = new SQLQuery(); $DB->chooseTable(DB_SONGS_TABLE); foreach($songs['songs'] as $song) { $dataInsert = array(); $dataInsert['id'] = $song['id']; $dataInsert['title'] = $song['title']; $dataInsert['artist'] = $song['artist']; $dataInsert['album'] = $song['album']; $dataInsert['length'] = $song['length']; $dataInsert['filename'] = $song['filename']; $DB->addItemsArray($dataInsert); echo "Added " . $song['title'] . " by " . $song['artist'] . " to the database.<br />"; } } } ?>
} $connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, $_SESSION['oauth_token'], $_SESSION['oauth_token_secret']); $access_token = $connection->getAccessToken($_REQUEST['oauth_verifier']); $_SESSION['access_token'] = $access_token; unset($_SESSION['oauth_token']); unset($_SESSION['oauth_token_secret']); $authedconn = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, $access_token['oauth_token'], $access_token['oauth_token_secret']); $content = $authedconn->get('account/verify_credentials'); if (200 == $connection->http_code && !empty($content->id)) { //TODO(njoubert): Here we should pass it off to an "insert into local database and set up our own session" thingy //if the user exists, update. if not, create. $DB = new SQLQuery(); $DB->chooseTable(DB_USERS_TABLE); $dataInsert = array(); $fullname = explode(" ", $content->name); $fname = "Britney"; $lname = "Spears"; if (count($fullname) > 0) { $fname = $fullname[0]; } if (count($fullname) > 1) { $lname = $fullname[1]; } $dataInsert['tw_id'] = $content->id; $dataInsert['fname'] = $fname; $dataInsert['lname'] = $lname; $dataInsert['tw_name'] = $content->screen_name; $dataInsert['avatar'] = $content->profile_image_url; $dataInsert['tw_oauth_token'] = $access_token['oauth_token']; $dataInsert['tw_oauth_token_secret'] = $access_token['oauth_token_secret'];
function record_vote($user_id, $song_id) { $DB = new SQLQuery(); $DB->chooseTable(DB_VOTES_TABLE); }