<?php

  IF (!defined('_GNUBOARD_')) exit; // 접근 불가

  IF (!$board_cate_list_a[$board_cate_n]['bca_use_sns']) return;

set_cookie('ck_facebook_checked', false, 86400*31);
set_cookie('ck_twitter_checked' , false, 86400*31);

//----------------------------------------------------------------------------
$wr_facebook_user = "";

  IF (! empty($_POST['facebook_checked'])) {
    include_once(G5_SNS_PATH."/facebook/src/facebook.php");

    $facebook = new Facebook(array(
        'appId'  => $config['cf_facebook_appid'],
        'secret' => $config['cf_facebook_secret']
    ));

    $user = $facebook->getUser();

    IF ( $user) {
        try {
            $link = go_piree_cafe_board('', $piree_cafe_n, $board_cate_n, $wr['wr_parent']) .'#c_'. $comment_id;
            $attachment = array(
                'message'       => stripslashes($wr_content),
                'name'          => $wr_subject,
                'link'          => $link,
                'description'   => stripslashes(strip_tags($wr['wr_content']))
            );

            $facebook->api('/me/feed/', 'post', $attachment);
//$errors = error_get_last(); print_r2($errros); exit;

            set_cookie('ck_facebook_checked', true, 86400*31);
        } catch(FacebookApiException $e) {
            ;;;
        }
    }

    $wr_facebook_user = get_session("ss_facebook_user");
}

//----------------------------------------------------------------------------
$wr_twitter_user = "";

  IF (! empty($_POST['twitter_checked'])) {
    include_once(G5_SNS_PATH."/twitter/twitteroauth/twitteroauth.php");
    include_once(G5_SNS_PATH."/twitter/twitterconfig.php");

    IF ( !(empty($_SESSION['access_token']) || empty($_SESSION['access_token']['oauth_token']) || empty($_SESSION['access_token']['oauth_token_secret'])) ) {
        $comment_url = go_piree_cafe_board('', $piree_cafe_n, $board_cate_n, $wr['wr_parent']) .'#c_'. $comment_id;

        $post = googl_short_url($comment_url).' '. $wr_content;
        $post = utf8_strcut($post, 140);

        $access_token = $_SESSION['access_token'];
        $connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, $access_token['oauth_token'], $access_token['oauth_token_secret']);

        $connection->post('statuses/update', array('status' => $post));

        set_cookie('ck_twitter_checked', true, 86400*31);
    }

    $wr_twitter_user = get_session("ss_twitter_user");
}
//;