<commit_before><?php

require_once APPPATH.'third_party/facebook/vendor/autoload.php';

class Facebook extends CI_Controller{

	
	public function __construct(){
			parent::__construct();
		
			if (session_status() == PHP_SESSION_NONE) {
				session_start();  //defining here as a fix to avoid session clearing during redirection
			}
    }


	



	public function ajaxTest($value='')
	{
		$str = [

				"name"=>"superman",
				"city"=>"metropolis",
				"age"=>200
			];

		$data["json"] = json_encode($str);
		echo json_encode($data);
	}


	public function testfb($value='')
	{
		$client = new Facebook\Facebook([
			'app_id' => '558049591013252',
			'app_secret' => '<KEY>',
			'default_graph_version' => 'v2.2',
			]);

		

		if($value == "callback"){
			$helper = $client->getRedirectLoginHelper();
			try {
			  $accessToken = $helper->getAccessToken();
			} catch(Facebook\Exceptions\FacebookResponseException $e) {
			  // When Graph returns an error
			  echo 'Graph returned an error: ' . $e->getMessage();
			  exit;
			} catch(Facebook\Exceptions\FacebookSDKException $e) {
			  // When validation fails or other local issues
			  echo 'Facebook SDK returned an error: ' . $e->getMessage();
			  exit;
			}
			if (isset($accessToken)) {
				  // Logged in!
				  $_SESSION['facebook_access_token'] = (string) $accessToken;

				  // Now you can redirect to another page and use the
				  // access token from $_SESSION['facebook_access_token']
				  // OAuth 2.0 client handler
					$oAuth2Client = $client->getOAuth2Client();

					// Exchanges a short-lived access token for a long-lived one
					$longLivedAccessToken = $oAuth2Client->getLongLivedAccessToken($accessToken);
					$client->setDefaultAccessToken($longLivedAccessToken);
					$_SESSION['client'] = $client;

				  echo "token found";

				  $this->testapi();
				}

		}
		else{ //not logged in yet
			$helper = $client->getRedirectLoginHelper();
			$permissions = ['email', 'user_likes']; // optional
			$loginUrl = $helper->getLoginUrl( base_url() . 'index.php/facebook/testfb/callback', $permissions);
			echo '<a href="' . $loginUrl . '">Log in with Facebook!</a>';
		}

	}

	private function testapi($value='')
	{
		$client = $_SESSION['client'];
		try {
		  $response = $client->get('/me');
		  $userNode = $response->getGraphUser();
		} catch(Facebook\Exceptions\FacebookResponseException $e) {
		  // When Graph returns an error
		  echo 'Graph returned an error: ' . $e->getMessage();
		  exit;
		} catch(Facebook\Exceptions\FacebookSDKException $e) {
		  // When validation fails or other local issues
		  echo 'Facebook SDK returned an error: ' . $e->getMessage();
		  exit;
		}

		echo 'Logged in as ' . $userNode->getName();
	}

}


?><commit_msg>small changes to test fb code<commit_after><?php

require_once APPPATH.'third_party/facebook/vendor/autoload.php';

class Facebook extends CI_Controller{

	
	public function __construct(){
			parent::__construct();
		
			if (session_status() == PHP_SESSION_NONE) {
				session_start();  //defining here as a fix to avoid session clearing during redirection
			}
    }


	



	public function ajaxTest($value='')
	{
		$str = [

				"name"=>"superman",
				"city"=>"metropolis",
				"age"=>200
			];

		$data["json"] = json_encode($str);
		echo json_encode($data);
	}


	public function testfb($value='')
	{
		$client = new Facebook\Facebook([
			'app_id' => '558049591013252',
			'app_secret' => '<KEY>',
			'default_graph_version' => 'v2.2',
			]);

		

		if($value == "callback"){
			$helper = $client->getRedirectLoginHelper();
			try {
			  $accessToken = $helper->getAccessToken();
			} catch(Facebook\Exceptions\FacebookResponseException $e) {
			  // When Graph returns an error
			  echo 'Graph returned an error: ' . $e->getMessage();
			  exit;
			} catch(Facebook\Exceptions\FacebookSDKException $e) {
			  // When validation fails or other local issues
			  echo 'Facebook SDK returned an error: ' . $e->getMessage();
			  exit;
			}
			if (isset($accessToken)) {
				  // Logged in!
				  $_SESSION['facebook_access_token'] = (string) $accessToken;

				  // Now you can redirect to another page and use the
				  // access token from $_SESSION['facebook_access_token']
				  // OAuth 2.0 client handler
					$oAuth2Client = $client->getOAuth2Client();

					// Exchanges a short-lived access token for a long-lived one
					$longLivedAccessToken = $oAuth2Client->getLongLivedAccessToken($accessToken);
					$client->setDefaultAccessToken($longLivedAccessToken);
					$_SESSION['client'] = $client;

				  echo "token found";

				  $this->testapi();
				}

		}
		else{ //not logged in yet
			$helper = $client->getRedirectLoginHelper();
			$permissions = ['email', 'user_likes']; // optional
			$loginUrl = $helper->getLoginUrl( base_url() . 'index.php/facebook/testfb/callback', $permissions);
			echo '<a href="' . $loginUrl . '">Log in with Facebook!</a>';
		}

	}

	private function testapi($value='')
	{
		$client = $_SESSION['client'];
		try {
		  $response = $client->get('/me');
		  $userNode = $response->getGraphUser();
		} catch(Facebook\Exceptions\FacebookResponseException $e) {
		  // When Graph returns an error
		  echo 'Graph returned an error: ' . $e->getMessage();
		  exit;
		} catch(Facebook\Exceptions\FacebookSDKException $e) {
		  // When validation fails or other local issues
		  echo 'Facebook SDK returned an error: ' . $e->getMessage();
		  exit;
		}

		echo 'Logged in as ' . $userNode->getId();
		print_r( $response->getDecodedBody());
	}

}


?>
{'fraction_non_alphanumeric': 0.15131221719457014, 'fraction_numerical': 0.00904977375565611, 'mean_word_length': 3.3409269442262373, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 54, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 28, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4023828', 'n_tokens_mistral': 2116, 'n_tokens_neox': 1708, 'n_words': 411}