sns 적용중
This commit is contained in:
@ -30,6 +30,11 @@ if(!isset($config['cf_gcaptcha_mp3'])) {
|
||||
ADD `cf_gcaptcha_mp3` VARCHAR(255) NOT NULL DEFAULT '' AFTER `cf_mobile_member_skin` ", true);
|
||||
}
|
||||
|
||||
if(!isset($config['cf_googl_shorturl_apikey'])) {
|
||||
sql_query(" ALTER TABLE `{$g4['config_table']}`
|
||||
ADD `cf_googl_shorturl_apikey` VARCHAR(255) NOT NULL DEFAULT '' AFTER `cf_gcaptcha_mp3` ", true);
|
||||
}
|
||||
|
||||
if(!isset($config['cf_kcpcert_site_cd'])) {
|
||||
sql_query(" ALTER TABLE `{$g4['config_table']}`
|
||||
ADD `cf_kcpcert_site_cd` VARCHAR(255) NOT NULL DEFAULT '' AFTER `cf_memo_send_point` ", true);
|
||||
@ -48,11 +53,13 @@ if(!isset($config['cf_mobile_pages'])) {
|
||||
sql_query(" UPDATE `{$g4['config_table']}` SET cf_mobile_pages = '5' ", true);
|
||||
}
|
||||
|
||||
if(!isset($config['cf_facebook_use'])) {
|
||||
if(!isset($config['cf_sns_use'])) {
|
||||
sql_query(" ALTER TABLE `{$g4['config_table']}`
|
||||
ADD `cf_facebook_use` TINYINT NOT NULL DEFAULT '0' AFTER `cf_kcpcert_use`
|
||||
ADD `cf_sns_use` TINYINT NOT NULL DEFAULT '0' AFTER `cf_kcpcert_use`
|
||||
ADD `cf_facebook_appid` VARCHAR(255) NOT NULL AFTER `cf_facebook_use`,
|
||||
ADD `cf_facebook_secret` VARCHAR(255) NOT NULL AFTER `cf_facebook_secret` ", true);
|
||||
ADD `cf_facebook_secret` VARCHAR(255) NOT NULL AFTER `cf_facebook_secret`,
|
||||
ADD `cf_twitter_key` VARCHAR(255) NOT NULL AFTER `cf_facebook_secret`,
|
||||
ADD `cf_twitter_secret` VARCHAR(255) NOT NULL AFTER `cf_twitter_key` ", true);
|
||||
}
|
||||
|
||||
// uniqid 테이블이 없을 경우 생성
|
||||
@ -723,8 +730,8 @@ $pg_anchor = '<ul class="anchor">
|
||||
</colgroup>
|
||||
<tbody>
|
||||
<tr>
|
||||
<th scope="row"><label for="cf_facebook_use">페이스북 사용</label></th>
|
||||
<td colspan="3"><input type="checkbox" name="cf_facebook_use" value="1" id="cf_facebook_use" <?php echo $config['cf_facebook_use']?'checked':''; ?>> 사용</td>
|
||||
<th scope="row"><label for="cf_facebook_use">SNS 사용</label></th>
|
||||
<td colspan="3"><input type="checkbox" name="cf_sns_use" value="1" id="cf_sns_use" <?php echo $config['cf_sns_use']?'checked':''; ?>> 사용</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row"><label for="cf_facebook_appid">페이스북 앱 ID</label></th>
|
||||
@ -736,10 +743,6 @@ $pg_anchor = '<ul class="anchor">
|
||||
<input type="text" name="cf_facebook_secret" value="<?php echo $config['cf_facebook_secret'] ?>" id="cf_facebook_secret" class="frm_input" size="35">
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row"><label for="cf_twitter_use">트위터 사용</label></th>
|
||||
<td colspan="3"><input type="checkbox" name="cf_twitter_use" value="1" id="cf_twitter_use" <?php echo $config['cf_twitter_use']?'checked':''; ?>> 사용</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row"><label for="cf_twitter_key">트위터 컨슈머 Key</label></th>
|
||||
<td>
|
||||
|
||||
@ -182,35 +182,8 @@ if ($w == 'c') // 댓글 입력
|
||||
|
||||
$wr_subject = get_text(stripslashes($wr['wr_subject']));
|
||||
|
||||
if ($config['cf_facebook_use'] && $_POST['facebook_checked']) {
|
||||
include_once(G4_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 = G4_BBS_URL.'/board.php?bo_table='.$bo_table.'&wr_id='.$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;
|
||||
$access_token = $facebook->getAccessToken();
|
||||
sql_query(" update {$g4['member_table']} set mb_facebook_token = '{$access_token}', mb_facebook_checked = '{$_POST['facebook_checked']}' where mb_id = '{$member['mb_id']}' ", true);
|
||||
} catch(FacebookApiException $e) {
|
||||
;;;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// SNS 등록
|
||||
include_once("./write_comment_update.sns.php");
|
||||
|
||||
// 메일발송 사용
|
||||
if ($config['cf_email_use'] && $board['bo_use_email'])
|
||||
|
||||
50
bbs/write_comment_update.sns.php
Normal file
50
bbs/write_comment_update.sns.php
Normal file
@ -0,0 +1,50 @@
|
||||
<?php
|
||||
if (!defined('_GNUBOARD_')) exit; // 개별 페이지 접근 불가
|
||||
|
||||
if ($config['cf_sns_use']) return;
|
||||
|
||||
// 페이스북
|
||||
if ($_POST['facebook_checked']) {
|
||||
include_once(G4_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 = G4_BBS_URL.'/board.php?bo_table='.$bo_table.'&wr_id='.$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;
|
||||
} catch(FacebookApiException $e) {
|
||||
;;;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 트위터
|
||||
if ($_POST['twitter_checked']) {
|
||||
include_once(G4_SNS_PATH."/twitter/twitteroauth/twitteroauth.php");
|
||||
include_once(G4_SNS_PATH."/twitter/config.php");
|
||||
|
||||
if ( !(empty($_SESSION['access_token']) || empty($_SESSION['access_token']['oauth_token']) || empty($_SESSION['access_token']['oauth_token_secret'])) ) {
|
||||
$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));
|
||||
}
|
||||
}
|
||||
?>
|
||||
@ -2041,4 +2041,37 @@ function board_notice($bo_notice, $wr_id, $insert=false)
|
||||
}
|
||||
return implode(",", $notice_array);
|
||||
}
|
||||
|
||||
|
||||
// goo.gl 짧은주소 만들기
|
||||
function googl_short_url($longUrl)
|
||||
{
|
||||
global $config;
|
||||
|
||||
// Get API key from : http://code.google.com/apis/console/
|
||||
// URL Shortener API ON
|
||||
$apiKey = $config['cf_googl_shorturl_apikey'];
|
||||
|
||||
$postData = array('longUrl' => $longUrl, 'key' => $apiKey);
|
||||
$jsonData = json_encode($postData);
|
||||
|
||||
$curlObj = curl_init();
|
||||
|
||||
curl_setopt($curlObj, CURLOPT_URL, 'https://www.googleapis.com/urlshortener/v1/url');
|
||||
curl_setopt($curlObj, CURLOPT_RETURNTRANSFER, 1);
|
||||
curl_setopt($curlObj, CURLOPT_SSL_VERIFYPEER, 0);
|
||||
curl_setopt($curlObj, CURLOPT_HEADER, 0);
|
||||
curl_setopt($curlObj, CURLOPT_HTTPHEADER, array('Content-type:application/json'));
|
||||
curl_setopt($curlObj, CURLOPT_POST, 1);
|
||||
curl_setopt($curlObj, CURLOPT_POSTFIELDS, $jsonData);
|
||||
|
||||
$response = curl_exec($curlObj);
|
||||
|
||||
//change the response json string to object
|
||||
$json = json_decode($response);
|
||||
|
||||
curl_close($curlObj);
|
||||
|
||||
return $json->id;
|
||||
}
|
||||
?>
|
||||
@ -22,26 +22,18 @@ $g4['title'] = '페이스북 콜백';
|
||||
include_once(G4_PATH.'/head.sub.php');
|
||||
|
||||
if ($user) {
|
||||
|
||||
$access_token = $facebook->getAccessToken();
|
||||
|
||||
$appid = $config['cf_facebook_appid'];
|
||||
|
||||
setcookie('fbs_'.$appid, 1, G4_SERVER_TIME + 86400 * 31, '/', G4_COOKIE_DOMAIN);
|
||||
setcookie('fbs_'.$appid.'_code', $_SESSION['fb_'.$appid.'_code'], G4_SERVER_TIME + 86400 * 31, '/', G4_COOKIE_DOMAIN);
|
||||
setcookie('fbs_'.$appid.'_access_token', $_SESSION['fb_'.$appid.'_access_token'], G4_SERVER_TIME + 86400 * 31, '/', G4_COOKIE_DOMAIN);
|
||||
setcookie('fbs_'.$appid.'_user_id', $_SESSION['fb_'.$appid.'_user_id'], G4_SERVER_TIME + 86400 * 31, '/', G4_COOKIE_DOMAIN);
|
||||
|
||||
sql_query(" update {$g4['member_table']} set mb_facebook_token = '{$access_token}' where mb_id = '{$member['mb_id']}' ", true);
|
||||
|
||||
$sns_name = $user_profile['name'];
|
||||
$g4_sns_url = G4_SNS_URL;
|
||||
|
||||
set_cookie('ck_sns_name', $sns_name);
|
||||
|
||||
echo <<<EOT
|
||||
<script>
|
||||
$(function() {
|
||||
document.write("<strong>페이스북 승인이 되었습니다.</strong>");
|
||||
|
||||
var opener = window.opener;
|
||||
opener.$("#wr_name").val("{$sns_name}");
|
||||
opener.$("#facebook_icon").attr("src", "{$g4_sns_url}/icon/facebook_on.png");
|
||||
opener.$("#facebook_checked").attr("disabled", false);
|
||||
opener.$("#facebook_checked").attr("checked", true);
|
||||
|
||||
@ -48,30 +48,19 @@ include_once(G4_PATH.'/head.sub.php');
|
||||
|
||||
if (200 == $connection->http_code) {
|
||||
|
||||
/*
|
||||
$access_token = $facebook->getAccessToken();
|
||||
|
||||
$appid = $config['cf_facebook_appid'];
|
||||
|
||||
setcookie('fbs_'.$appid, 1, G4_SERVER_TIME + 86400 * 31, '/', G4_COOKIE_DOMAIN);
|
||||
setcookie('fbs_'.$appid.'_code', $_SESSION['fb_'.$appid.'_code'], G4_SERVER_TIME + 86400 * 31, '/', G4_COOKIE_DOMAIN);
|
||||
setcookie('fbs_'.$appid.'_access_token', $_SESSION['fb_'.$appid.'_access_token'], G4_SERVER_TIME + 86400 * 31, '/', G4_COOKIE_DOMAIN);
|
||||
setcookie('fbs_'.$appid.'_user_id', $_SESSION['fb_'.$appid.'_user_id'], G4_SERVER_TIME + 86400 * 31, '/', G4_COOKIE_DOMAIN);
|
||||
|
||||
sql_query(" update {$g4['member_table']} set mb_facebook_token = '{$access_token}' where mb_id = '{$member['mb_id']}' ", true);
|
||||
|
||||
*/
|
||||
|
||||
sql_query(" update {$g4['member_table']} set mb_twitter_token = '{$access_token['oauth_token']}', mb_twitter_token_secret = '{$access_token['oauth_token_secret']}' where mb_id = '{$member['mb_id']}' ", true);
|
||||
|
||||
$content = $connection->get('account/verify_credentials');
|
||||
$sns_name = $content->name;
|
||||
$g4_sns_url = G4_SNS_URL;
|
||||
|
||||
set_cookie('ck_sns_name', $sns_name);
|
||||
|
||||
echo <<<EOT
|
||||
<script>
|
||||
$(function() {
|
||||
document.write("<strong>트위터에 승인이 되었습니다.</strong>");
|
||||
|
||||
var opener = window.opener;
|
||||
opener.$("#wr_name").val("{$sns_name}");
|
||||
opener.$("#twitter_icon").attr("src", "{$g4_sns_url}/icon/twitter_on.png");
|
||||
opener.$("#twitter_checked").attr("disabled", false);
|
||||
opener.$("#twitter_checked").attr("checked", true);
|
||||
|
||||
@ -115,7 +115,7 @@ var char_max = parseInt(<?php echo $comment_max ?>); // 최대
|
||||
<?php } ?>
|
||||
|
||||
<?php
|
||||
include_once($board_skin_path."/sns_comment.skin.php");
|
||||
include_once($board_skin_path."/view_comment.sns.skin.php");
|
||||
?>
|
||||
|
||||
<tr>
|
||||
|
||||
@ -1,49 +1,57 @@
|
||||
<?php
|
||||
if (!defined('_GNUBOARD_')) exit; // 개별 페이지 접근 불가
|
||||
|
||||
if (!$is_member) return;
|
||||
if (!$config['cf_facebook_use'] && !$config['cf_twitter_use']) return;
|
||||
//if (!$is_member) return;
|
||||
if (!$config['cf_sns_use']) return;
|
||||
?>
|
||||
<tr>
|
||||
<th scope="row">SNS 등록</th>
|
||||
<td>
|
||||
<div id="sns_facebook">
|
||||
<?php
|
||||
if ($config['cf_facebook_use']) {
|
||||
//============================================================================
|
||||
// 페이스북
|
||||
//----------------------------------------------------------------------------
|
||||
if ($config['cf_facebook_appid']) {
|
||||
include_once(G4_SNS_PATH."/facebook/src/facebook.php");
|
||||
$facebook = new Facebook(array(
|
||||
'appId' => $config['cf_facebook_appid'],
|
||||
'secret' => $config['cf_facebook_secret']
|
||||
));
|
||||
|
||||
$user = $facebook->getUser();
|
||||
$facebook_user = $facebook->getUser();
|
||||
|
||||
if ($user) {
|
||||
if ($facebook_user) {
|
||||
try {
|
||||
$user_profile = $facebook->api('/me');
|
||||
$facebook_user_profile = $facebook->api('/me');
|
||||
} catch (FacebookApiException $e) {
|
||||
error_log($e);
|
||||
$user = null;
|
||||
$facebook_user = null;
|
||||
}
|
||||
}
|
||||
|
||||
if ($user) {
|
||||
if ($facebook_user) {
|
||||
echo '<input type="checkbox" name="facebook_checked" id="facebook_checked" '.($member['mb_facebook_checked']?'checked':'').' value="1">';
|
||||
echo '<img src="'.G4_SNS_URL.'/icon/facebook_on.png" id="facebook_icon">';
|
||||
} else {
|
||||
$facebook_url = $facebook->getLoginUrl(array("redirect_uri"=>G4_SNS_URL."/facebook/callback.php", "scope"=>"publish_stream,read_stream,offline_access", "display"=>"popup"));
|
||||
|
||||
echo '<input type="checkbox" name="facebook_checked" id="facebook_checked" disabled value="1">';
|
||||
echo '<a href="'.$facebook_url.'" id="facebook_url" onclick="return false;"><img src="'.G4_SNS_URL.'/icon/facebook_'.($user?'on':'off').'.png" id="facebook_icon">';
|
||||
echo '<a href="'.$facebook_url.'" id="facebook_url" onclick="return false;"><img src="'.G4_SNS_URL.'/icon/facebook_'.($facebook_user?'on':'off').'.png" id="facebook_icon"></a>';
|
||||
echo '<script>$(function(){ $("#facebook_url").click(function(){ window.open(this.href, "facebook_url", "width=600,height=250"); }); });</script>';
|
||||
}
|
||||
}
|
||||
//============================================================================
|
||||
|
||||
if ($config['cf_twitter_use']) {
|
||||
|
||||
//============================================================================
|
||||
// 트위터
|
||||
//----------------------------------------------------------------------------
|
||||
if ($config['cf_twitter_key']) {
|
||||
include_once(G4_SNS_PATH."/twitter/twitteroauth/twitteroauth.php");
|
||||
include_once(G4_SNS_PATH."/twitter/config.php");
|
||||
|
||||
$user = false;
|
||||
$twitter_user = false;
|
||||
if (empty($_SESSION['access_token']) || empty($_SESSION['access_token']['oauth_token']) || empty($_SESSION['access_token']['oauth_token_secret'])) {
|
||||
$twitter_url = G4_SNS_URL."/twitter/redirect.php";
|
||||
} else {
|
||||
@ -54,7 +62,7 @@ if (!$config['cf_facebook_use'] && !$config['cf_twitter_use']) return;
|
||||
|
||||
switch ($connection->http_code) {
|
||||
case 200:
|
||||
$user = true;
|
||||
$twitter_user = true;
|
||||
$twitter_url = $connection->getAuthorizeURL($token);
|
||||
break;
|
||||
default :
|
||||
@ -64,22 +72,23 @@ if (!$config['cf_facebook_use'] && !$config['cf_twitter_use']) return;
|
||||
$connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, $member['mb_twitter_token'], $member['mb_twitter_token_secret']);
|
||||
$content = $connection->get('account/verify_credentials');
|
||||
if (200 == $connection->http_code) {
|
||||
$user = true;
|
||||
$twitter_user = true;
|
||||
$twitter_url = $connection->getAuthorizeURL($token);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($user) {
|
||||
if ($twitter_user) {
|
||||
echo '<input type="checkbox" name="twitter_checked" id="twitter_checked" '.($member['mb_twitter_checked']?'checked':'').' value="1">';
|
||||
echo '<img src="'.G4_SNS_URL.'/icon/twitter_on.png" id="twitter_icon">';
|
||||
} else {
|
||||
echo '<input type="checkbox" name="twitter_checked" id="twitter_checked" disabled value="1">';
|
||||
echo '<a href="'.$twitter_url.'" id="twitter_url" onclick="return false;"><img src="'.G4_SNS_URL.'/icon/twitter_'.($user?'on':'off').'.png" id="twitter_icon">';
|
||||
echo '<a href="'.$twitter_url.'" id="twitter_url" onclick="return false;"><img src="'.G4_SNS_URL.'/icon/twitter_'.($twitter_user?'on':'off').'.png" id="twitter_icon"></a>';
|
||||
echo '<script>$(function(){ $("#twitter_url").click(function(){ window.open(this.href, "twitter_url", "width=600,height=250"); }); });</script>';
|
||||
}
|
||||
}
|
||||
//============================================================================
|
||||
?>
|
||||
</div>
|
||||
</td>
|
||||
Reference in New Issue
Block a user