<commit_before><?php
session_start();
require_once ('config.php');
require_once ("mysql.php");
require_once ("functions.php");

require_once ('codebird.php');
\Codebird\Codebird::setConsumerKey(OAUTH_CONSUMER_KEY, OAUTH_CONSUMER_SECRET);

$cb = \Codebird\Codebird::getInstance();

if (! isset($_SESSION['oauth_token'])) {
  // get the request token
  $reply = $cb->oauth_requestToken([
    'oauth_callback' => 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']
  ]);

  // store the token
  $cb->setToken($reply->oauth_token, $reply->oauth_token_secret);
  $_SESSION['oauth_token'] = $reply->oauth_token;
  $_SESSION['oauth_token_secret'] = $reply->oauth_token_secret;
  $_SESSION['oauth_verify'] = true;

  // redirect to auth website
  $auth_url = $cb->oauth_authorize();
  header('Location: ' . $auth_url);
  die();

} elseif (isset($_GET['oauth_verifier']) && isset($_SESSION['oauth_verify'])) {
  // verify the token
  $cb->setToken($_SESSION['oauth_token'], $_SESSION['oauth_token_secret']);
  unset($_SESSION['oauth_verify']);

  // get the access token
  $reply = $cb->oauth_accessToken([
    'oauth_verifier' => $_GET['oauth_verifier']
  ]);

  // store the token (which is different from the request token!)
  $_SESSION['oauth_token'] = $reply->oauth_token;
  $_SESSION['oauth_token_secret'] = $reply->oauth_token_secret;

  // send to same URL, without oauth GET parameters
  header('Location: ' . basename(__FILE__));
  die();
}

// assign access token on each page load
$cb->setToken($_SESSION['oauth_token'], $_SESSION['oauth_token_secret']);

$reply = (array) $cb->account_verifyCredentials();

$id_str = $reply["id_str"];
$screen_name = $reply["screen_name"];

$userID = insert_user("twitter", $id_str, $screen_name);

include("header.php");
?><?php
if ($_FILES['userfile']['tmp_name'])
{
	$inscription = $_POST['inscription'];
	$filename = $_FILES['userfile']['tmp_name'];
	$sha1 = sha1_file ($filename );

	$location = get_image_location($filename);

	if (false != $location)
	{
		$directory = substr($sha1,0,1);
		$subdirectory = substr($sha1,1,1);
		$photo_path = "photos/".$directory."/".$subdirectory."/";
		$photo_full_path = $photo_path.$sha1.".jpg";

		if(file_exists($photo_full_path)){
			echo "<h2>That photo already exists in the database</h2>";
		}	else {
			if (!is_dir($photo_path)) {
				mkdir($photo_path, 0777, true);
			}

			$benchID = insert_bench($location["lat"],$location["lng"], $inscription, $userID);
			$mediaID = insert_media($benchID, $userID, $sha1);

			move_uploaded_file($_FILES['userfile']['tmp_name'], $photo_path.$sha1.".jpg");

			echo "Added! {$benchID} at ". $location["lat"] . "," . $location["lng"] .
				  " and media {$mediaID} with sha1 {$sha1} from twitter/{$id_str}";

			echo "<br><img width='480' src=\"" . $photo_path.$sha1.".jpg" . "\" />";
		}


	} else {
		echo "<h2>No location metadata found in image</h2>";
	}
}<commit_msg>Fix login issue<commit_after><?php
session_start();
require_once ('config.php');
require_once ("mysql.php");
require_once ("functions.php");

require_once ('codebird.php');
\Codebird\Codebird::setConsumerKey(OAUTH_CONSUMER_KEY, OAUTH_CONSUMER_SECRET);

$cb = \Codebird\Codebird::getInstance();

if (! isset($_SESSION['oauth_token'])) {
	// get the request token
	$reply = $cb->oauth_requestToken([
		'oauth_callback' => 'https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']
	]);

	// store the token
	$cb->setToken($reply->oauth_token, $reply->oauth_token_secret);
	$_SESSION['oauth_token'] = $reply->oauth_token;
	$_SESSION['oauth_token_secret'] = $reply->oauth_token_secret;
	$_SESSION['oauth_verify'] = true;

	// redirect to auth website
	$auth_url = $cb->oauth_authorize();
	header('Location: ' . $auth_url);
	die();

} elseif (isset($_GET['oauth_verifier']) && isset($_SESSION['oauth_verify'])) {
	// verify the token
	$cb->setToken($_SESSION['oauth_token'], $_SESSION['oauth_token_secret']);
	unset($_SESSION['oauth_verify']);

	// get the access token
	$reply = $cb->oauth_accessToken([
		'oauth_verifier' => $_GET['oauth_verifier']
	]);

	// store the token (which is different from the request token!)
	$_SESSION['oauth_token'] = $reply->oauth_token;
	$_SESSION['oauth_token_secret'] = $reply->oauth_token_secret;

	// send to same URL, without oauth GET parameters
	header('Location: ' . basename(__FILE__));
	die();
}

// assign access token on each page load
$cb->setToken($_SESSION['oauth_token'], $_SESSION['oauth_token_secret']);

$reply = (array) $cb->account_verifyCredentials();

//	If the authorization hasn't worked, clear the session variables and start again
if($reply["errors"]) {
	$_SESSION['oauth_token'] = null;
	$_SESSION['oauth_token'] = null;
	$_SESSION['oauth_token_secret'] = null;
	$_SESSION['oauth_verify'] = null;
	// send to same URL, without oauth GET parameters
	header('Location: ' . basename(__FILE__));
	die();
}

//	Get the user's ID & name
$id_str = $reply["id_str"];
$screen_name = $reply["screen_name"];

//	Add the user to the database
$userID = insert_user("twitter", $id_str, $screen_name);

//	Start the normal page
include("header.php");
//	Has a photo been posted?
if ($_FILES['userfile']['tmp_name'])
{
	$inscription = $_POST['inscription'];
	$filename = $_FILES['userfile']['tmp_name'];
	$sha1 = sha1_file ($filename );

	$location = get_image_location($filename);

	if (false != $location)
	{
		$directory = substr($sha1,0,1);
		$subdirectory = substr($sha1,1,1);
		$photo_path = "photos/".$directory."/".$subdirectory."/";
		$photo_full_path = $photo_path.$sha1.".jpg";

		if(file_exists($photo_full_path)){
			echo "<h2>That photo already exists in the database</h2>";
		}	else {
			if (!is_dir($photo_path)) {
				mkdir($photo_path, 0777, true);
			}

			$benchID = insert_bench($location["lat"],$location["lng"], $inscription, $userID);

			if (null != $benchID){
				$mediaID = insert_media($benchID, $userID, $sha1);
			}
			if (null != $mediaID){
				move_uploaded_file($_FILES['userfile']['tmp_name'], $photo_path.$sha1.".jpg");
				echo "Added! {$benchID} at ". $location["lat"] . "," . $location["lng"] .
						" and media {$mediaID} with sha1 {$sha1} from twitter/{$id_str}";
				echo "<br><img width='480' src=\"" . $photo_path.$sha1.".jpg" . "\" />";
			}
		}


	} else {
		echo "<h2>No location metadata found in image</h2>";
	}
}
{'fraction_non_alphanumeric': 0.19635499207606974, 'fraction_numerical': 0.00792393026941363, 'mean_word_length': 5.248514851485148, 'pattern_counts': {'":': 0, '<': 18, '<?xml version=': 0, '>': 46, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7406808', 'n_tokens_mistral': 2330, 'n_tokens_neox': 2208, 'n_words': 427}