<commit_before><?php

session_start();


require_once('settings.php');


define('FACEBOOK_SDK_V4_SRC_DIR', '/include/facebook-php-sdk-v4/src/Facebook/');
require_once('/include/facebook-php-sdk-v4/autoload.php');

use Facebook\FacebookSession;
use Facebook\FacebookRequest;
use Facebook\FacebookRequestException;


FacebookSession::setDefaultApplication(get_setting(KEY_APP_ID),
     get_setting(KEY_APP_SECRET));

define('STAGE_LOGIN', 'login');
define('STAGE_COUNTER', 'counters');

define('AUTH_DENIED', '0');
define('AUTH_ALLOWED', '1');
define('AUTH_ERROR', '-1');


function handle_ping(){
    return 'Pong';
}


function check_permissions($session) {

    $request = new FacebookRequest(
        $session,
        'GET',
        '/me/permissions'
    );

    try {
        $response = $request->execute();
        // TODO: verify permission
        $graphObject = $response->getGraphObject();
    } catch (FacebookRequestException $ex) {
        Flight::error($ex);
    } catch (\Exception $ex) {
        Flight::error($ex);
    }
}

// In the FB callback, we show a form to the user<commit_msg>Actually verify publish permissions<commit_after><?php

session_start();


require_once('settings.php');


define('FACEBOOK_SDK_V4_SRC_DIR', '/include/facebook-php-sdk-v4/src/Facebook/');
require_once('/include/facebook-php-sdk-v4/autoload.php');

use Facebook\FacebookSession;
use Facebook\FacebookRequest;
use Facebook\FacebookRequestException;


FacebookSession::setDefaultApplication(get_setting(KEY_APP_ID),
     get_setting(KEY_APP_SECRET));

define('STAGE_LOGIN', 'login');
define('STAGE_COUNTER', 'counters');

define('AUTH_DENIED', '0');
define('AUTH_ALLOWED', '1');
define('AUTH_ERROR', '-1');


function handle_ping(){
    return 'Pong';
}


function check_permissions($session) {

    $request = new FacebookRequest(
        $session,
        'GET',
        '/me/permissions'
    );

    try {
        $response = $request->execute();
        // TODO: verify permission
        $graphObject = $response->getGraphObject();
        // http://stackoverflow.com/q/23527919
        foreach ($graphObject as $permission) {
            if ($permission['permission'] == 'publish_actions') {
                return $permission['status'] == 'granted';
            }
        }
    } catch (FacebookRequestException $ex) {
        Flight::error($ex);
    } catch (\Exception $ex) {
        Flight::error($ex);
    }
    return false;
}

// In the FB callback, we show a form to the user
{'fraction_non_alphanumeric': 0.1535369774919614, 'fraction_numerical': 0.008038585209003215, 'mean_word_length': 3.6178107606679037, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 20, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3770419', 'n_tokens_mistral': 804, 'n_tokens_neox': 768, 'n_words': 141}