admin 發表於 2020-3-7 19:49:35

[X2.0] Facebook Connect 教學

⊙ 插件名稱:Discuz X2 Facebook Connect
⊙ 主要功能:同時登入FB與DZ、自動以FB帳號註冊DZ新會員(新會員可自訂帳號與密碼)、自動以FB帳戶整合DZ舊會員(DZ使用的E-mail與FB註冊的E-mail相同就會自動綁定)
⊙ 插件版本:2.3
⊙ 插件語言:繁體中文、簡體中文
⊙ 適用版本:Discuz X2 (20110629) - BIG5、GBK、UTF8繁中、UTF8簡中
⊙ 插件開發:derek
⊙ 執行環境:建議使用 PHP 5.X (主機須開啟CURL以及allow_url_fopen支援)
⊙ 鄙視收費插件:抵制收費插件、本插件完全免費,各位就別再花錢了,用買的插件不一定好!
⊙ 安裝前請注意:覆蓋檔案前,應先備份原來的檔案,安裝完畢請至後台更新緩存。( 需被覆蓋的檔案若有自行修改過,請勿直接使用本站提供的檔案覆蓋,應自行比對修改。)


⊙ 最後更新時間:2011/7/27 13:20
⊙ 本次更新說明:修正BIG5版本無法使用問題,若非使BIG5版本者,可不需更新
⊙ 本次升級注意:請參閱壓縮檔內的安裝說明,上傳全部檔案覆蓋後,務必先卸載插件再重新安裝,設定完插件後再更新緩存。關於在 Facebook 建立應用程式之相關教學於本帖底部。

forum.php

'heats', 'historyposts', 'onlinerecord', 'userstats', 'diytemplatenameforum'),替換成
'heats', 'historyposts', 'onlinerecord', 'userstats', 'diytemplatenameforum', 'plugin'),找
'onlinelist', 'forumstick', 'threadtable_info', 'threadtableids', 'stamps', 'diytemplatenameforum'),替換成
'onlinelist', 'forumstick', 'threadtable_info', 'threadtableids', 'stamps', 'diytemplatenameforum', 'plugin'),找
'threadtableids', 'threadtable_info', 'posttable_info', 'diytemplatenameforum'),
      'redirect'      => array('threadtableids', 'threadtable_info', 'posttable_info'),替換成
'threadtableids', 'threadtable_info', 'posttable_info', 'diytemplatenameforum', 'plugin'),
      'redirect'      => array('threadtableids', 'threadtable_info', 'posttable_info', 'plugin'),找
'domainwhitelist'),
      'space'                => array('fields_required', 'fields_optional', 'custominfo'),
      'group'                => array('grouptype', 'diytemplatenamegroup'),替換成
'domainwhitelist', 'plugin'),
      'space'                => array('fields_required', 'fields_optional', 'custominfo', 'plugin'),
      'group'                => array('grouptype', 'diytemplatenamegroup', 'plugin'),
group.php

$cachelist = array('grouptype', 'groupindex', 'diytemplatenamegroup');替換成
$cachelist = array('grouptype', 'groupindex', 'diytemplatenamegroup', 'plugin');home.php

$cachelist = array('magic','userapp','usergroups', 'diytemplatenamehome');替換成
$cachelist = array('magic','userapp','usergroups', 'diytemplatenamehome', 'plugin');misc.php

'ranklist' => array('forums', 'diytemplatename'),替換成
'ranklist' => array('forums', 'diytemplatename', 'plugin'),portal.php

$cachelist = array('userapp', 'portalcategory', 'diytemplatenameportal');替換成
$cachelist = array('userapp', 'portalcategory', 'diytemplatenameportal', 'plugin');./source/class 下的文件
class_core.php

$_G['PHP_SELF'] = htmlspecialchars($this->_get_script_url());替換成
$_G['PHP_SELF'] = htmlspecialchars($_SERVER['SCRIPT_NAME'] ? $_SERVER['SCRIPT_NAME'] : $_SERVER['PHP_SELF']);找
$this->var['config']['cookie']['cookiepre'] = $this->var['config']['cookie']['cookiepre'].substr(md5($this->var['config']['cookie']['cookiepath'].'|'.$this->var['config']['cookie']['cookiedomain']), 0, 4).'_';下面加上
$this->var['authkey'] = md5($_config['security']['authkey'].$_SERVER['HTTP_USER_AGENT']);找
} elseif((!defined('ALLOWGUEST') || !ALLOWGUEST) && !in_array(CURSCRIPT, array('member', 'api')) && !$this->var['inajax']) {替換成
} elseif((!defined('ALLOWGUEST') || !ALLOWGUEST) && !in_array(CURSCRIPT, array('member', 'api')) && !$this->var['inajax'] && !$_GET['act']) {class_member.php

function logging_ctl() {下面加上
loadcache(array('plugin'));找
loadcache(array('modreasons', 'stamptypeid', 'fields_required', 'fields_optional', 'fields_register', 'ipctrl'));
替換成
loadcache(array('modreasons', 'stamptypeid', 'fields_required', 'fields_optional', 'fields_register', 'ipctrl', 'plugin'));./source/function/ 下的文件
function_delete.php

DB::query("DELETE FROM ".DB::table('common_mailcron').", ".DB::table('common_mailqueue')." USING ".DB::table('common_mailcron').", ".DB::table('common_mailqueue')." WHERE ".DB::table('common_mailcron').".touid IN ($uids) AND ".DB::table('common_mailcron').".cid=".DB::table('common_mailqueue').".cid", 'UNBUFFERED');
下面加上
DB::query("DELETE FROM ".DB::table('facebook_connect')." WHERE uid IN ($uids)", 'UNBUFFERED');function_space.php

global $_G, $space;替換成
global $_G, $space, $sfb, $isfriend;找

$html .= "<li class='ul_pm'><a href=\"home.php?mod=spacecp&ac=pm&op=showmsg&handlekey=showmsg_$space&touid=$space&pmid=0&daterange=2\" id=\"a_sendpm_$space\" onclick=\"showWindow('showMsgBox', this.href, 'get', 0)\">".lang('space', 'block_profile_sendmessage')."</a></li>";下面加上
if(($sfb && $_G['adminid'] > 0) || ($sfb && $sfb == 0) || ($sfb && $sfb == 1 && $isfriend)) {
                                        $html .= "<li><a href=\"http://www.facebook.com/profile.php?id=$sfb\" target=\"_blank\" style=\"background-image:url(static/image/facebook_icon.png);\">".lang('space', 'facebook_profile')."</a></li>";
                                        $html .= "<li><a href=\"http://www.facebook.com/addfriend.php?id=$sfb\" target=\"_blank\" style=\"background-image:url(static/image/facebook_icon.png);\">".lang('space', 'add_facebook_friend')."</a></li>";
                              }
./source/language/ 下面文件
lang_message.php

'post_hide_nopermission' => '抱歉,您沒有權限使用 代碼',下面加上
'post_like_nopermission' => '對不起,你沒有權限使用 代碼,請返回修改。',
'post_like_dontinreply' => '對不起,回帖不可使用 代碼,請返回修改。',
'facebook_not_yet_like' => '您還未點讚,請返回。',
'facebook_not_yet_comm' => '您還未於本帖的Facebook留言版上留言 (請使用FB帳戶進行留言),請返回。',lang_space.php

'facebook_profile' => '看FB檔案',
      'add_facebook_friend' => '加FB好友',
./source/language/forum/ 下的文件
lang_template.php

'post_hide_reply_hidden' => ',如果您要查看本帖隱藏內容請<a href="forum.php?mod=post&action=reply&fid=$_G&tid=$_G" onclick="showWindow(\'reply\', this.href)">回復</a>',換成
'post_hide_reply_hidden' => ',如果您要查看本帖隱藏內容請<a href="forum.php?mod=post&action=reply&fid=$_G&tid=$_G" onclick="showWindow(\'reply\', this.href)">回覆</a>',
'post_hide_reply_like_hidden' => ',如果你要查看本帖隱藏內容請 <a href="forum.php?mod=post&action=reply&fid=$_G&tid=$_G" onclick="showWindow(\'reply\', this.href)">回覆</a> 或 <b>點讚</b>:',
'post_hide_like_hidden' => ',如果你要查看本帖隱藏內容請<b>點讚</b>:',
'first_login' => '請先登入會員:',
'facebook_profile' => '查看FB檔案',
'add_facebook_friend' => '加入FB好友',
'facebook_send' => '傳送',
'facebook_invite_friend_add' => '邀請朋友加入',
'facebook_invite_friend_addmsg' => '我在 [ {$_G} ] 加入會員了!誠摯邀請您一同加入!',
'facebook_already_like' => '[ 若您已點過讚,請點此重新檢查 ]',
'facebook_already_comm' => '[ 已在FB版留言?請點此重新檢查 ]',
'facebook_already_like_t' => '因為您目前並無登入本論壇,所以必須手動檢查您是否已點過讚。',
'facebook_already_comm_t' => '因為您目前並無登入本論壇,所以必須手動檢查您是否已在本帖的Facebook留言版上留言 (請使用FB帳戶進行留言)。',找
'facebook_profile' => '看FB檔案',
'add_facebook_friend' => '加FB好友',./source/module/forum/ 下的文件
forum_viewthread.php

LEFT JOIN ".DB::table('facebook_connect')." fc USING(uid)找

require_once libfile('function/friend');找
$postlist[$pid] = viewthread_procpost($post, $_G['member']['lastvisit'], $ordertype);下面加上
if($postlist[$pid]['first'] == 1) {
                        $getmsgi = $postlist[$pid]['message'];
                }
      }
      preg_match_all('/<img.+file=[\'"]([^\'"]+)[\'"].*>/i', $getmsgi, $iattrsA);
      preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $getmsgi, $iattrsB);
      if($iattrsA) {
                $iattrs = $_G.$iattrsA;
      } elseif($iattrsB) {
                if(stristr($iattrsB, "http://")) {
                        $iattrs = $iattrsB;
                } else {
                        $iattrs = $_G.$iattrsB;
                }
      } else {
                $iattrs = $_G['cache']['plugin']['facebook_connect']['dfimg'];./source/module/home/ 下的文件
home_space.php

<meta http-equiv="MSThemeCompatible" content="Yes" />下面加上

<!--{if $_G}-->
      <meta property="og:type" content="discuz:thread"/>
      <meta property="og:site_name" content="$_G['setting']['bbname']"/>
      <!--{if in_array('forum_viewthread', $_G['setting']['rewritestatus'])}-->
      <meta property="og:url" content="$_Gthread-{$_G}-1-1.html"/>
      <!--{else}-->
      <meta property="og:url" content="$_Gforum.php?mod=viewthread&tid=$_G"/>
      <!--{/if}-->
      <meta property="og:title" content="$_G - $_G['setting']['bbname']"/>
      <meta property="og:description" content="{if !empty($metadescription)}{echo htmlspecialchars($metadescription)}{/if}"/>
      <!--{if $iattrs}-->
      <meta property="og:image" content="$iattrs"/>
      <!--{/if}-->
      <meta property="fb:app_id" content="$_G['cache']['plugin']['facebook_connect']['appid']"/>
      <!--{/if}-->./template/default/common/ 下的文件
footer.htm

<!--{eval userappprompt();}-->
<!--{if $_G['basescript'] != 'userapp'}-->
<span id="scrolltop" onclick="window.scrollTo('0','0')">{lang scrolltop}</span>
<script type="text/javascript">_attachEvent(window, 'scroll', function(){showTopLink();});</script>
<!--{/if}-->下面加上
<div id="fb-root"></div>
<script type="text/javascript">
window.fbAsyncInit = function() {
      FB.init({appId:'$_G['cache']['plugin']['facebook_connect']['appid']', status:true, cookie:true, xfbml:true, channelUrl:'{$_G}channel.html'});
<!--{if $_G}-->
      <!--{if $_G['like'] == 'no'}-->
      FB.Event.subscribe('edge.create', function() {
                location.replace('forum.php?mod=viewthread&tid={$_G}&page={$_G}&todo=like');
      });
      <!--{if $_G['fbc'] && $_G['cache']['plugin']['facebook_ltv']['fctv']}-->
      FB.Event.subscribe('comment.create', function() {
                location.replace('forum.php?mod=viewthread&tid={$_G}&page={$_G}&todo=fcomm');
      });
      <!--{/if}-->
      <!--{/if}-->
      FB.Event.subscribe('edge.remove', function() {
                fbshare();
      });
      <!--{if $_G['like'] && $_G['fbc'] && $_G['cache']['plugin']['facebook_ltv']['fctv']}-->
      FB.Event.subscribe('comment.remove', function() {
                location.replace('forum.php?mod=viewthread&tid={$_G}&page={$_G}&todo=unfcomm');
      });
      <!--{/if}-->
<!--{/if}-->
};
(function() {
      var e = document.createElement('script');
      e.src = document.location.protocol + '//connect.facebook.net/zh_TW/all.js';
      e.async = true;
      document.getElementById('fb-root').appendChild(e);
}());
<!--{if $_G}-->
function fbshare() {
      FB.ui({
                method: 'feed',
                name: '$_G',
                <!--{if in_array('forum_viewthread', $_G['setting']['rewritestatus'])}-->
                link: '$_Gthread-{$_G}-1-1.html',
                <!--{else}-->
                link: '$_Gforum.php?mod=viewthread&tid=$_G',
                <!--{/if}-->
                <!--{if $iattrs}-->
                picture: '$iattrs',
                <!--{/if}-->
                caption: '$_G['setting']['bbname']',
                description: '{if !empty($metadescription)}{echo htmlspecialchars($metadescription)}{/if}',
                message: ''
      }, function(response) {
                <!--{if $_G['like']}-->
                if (response && response.post_id) {
                        location.replace('forum.php?mod=viewthread&tid={$_G}&page={$_G}&todo=unlike');
                } else {
                        location.replace('forum.php?mod=viewthread&tid={$_G}&page={$_G}&todo=unlike');
                }
                <!--{/if}-->
      });
}
function fbsend() {
      FB.ui({
                method: 'send',
                app_id: '$_G['cache']['plugin']['facebook_connect']['appid']',
                name: '$_G',
                <!--{if in_array('forum_viewthread', $_G['setting']['rewritestatus'])}-->
                link: '$_Gthread-{$_G}-1-1.html',
                <!--{else}-->
                link: '$_Gforum.php?mod=viewthread&tid=$_G',
                <!--{/if}-->
                <!--{if $iattrs}-->
                picture: '$iattrs',
                <!--{/if}-->
                description: '{if !empty($metadescription)}{echo htmlspecialchars($metadescription)}{/if}'
      });
}
function fbinvite() {
      FB.ui({
                method: 'apprequests',
                message: '{lang facebook_invite_friend_addmsg}',
                filters: "['app_non_users']",
                title: '{lang facebook_invite_friend_add} {$_G['setting']['bbname']}'
      });
}
<!--{/if}-->
function fblogin() {
      FB.login(function(response) {
                if (response.session) {
                        if (response.perms) {
                              location.replace('fblogin.php?act=logging&rf='+urlencode(location.href));
                        } else {
                              location.replace('index.php');
                        }
                } else {
                        location.replace('index.php');
                }
      }, {perms:'email,user_likes,publish_stream'});
}
function urlencode(str) {
      var output = '', x = 0, regex = /(^*)/;
      str = str.toString();
      while (x < str.length) {
                var match = regex.exec(str.substr(x));
                if (match != null && match.length > 1 && match != '') {
                        output += match;
                        x += match.length;
                } else {
                        if (str == ' ') {
                              output += '+';
                        } else {
                              var charCode = str.charCodeAt(x), hexVal = charCode.toString(16);
                              output += '%' + ( hexVal.length < 2 ? '0' : '' ) + hexVal.toUpperCase();
                        }
                        x++;
                }
      }
      return output;
}
</script>
header_common.htm

<html xmlns="http://www.w3.org/1999/xhtml">替換成
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:og="http://ogp.me/ns#" xmlns:fb="https://www.facebook.com/2008/fbml" xmlns:discuz="http://www.discuz.net/ns#">找
<meta http-equiv="MSThemeCompatible" content="Yes" />下面加上
<!--{if $_G}-->
      <meta property="og:type" content="discuz:thread"/>
      <meta property="og:site_name" content="$_G['setting']['bbname']"/>
      <!--{if in_array('forum_viewthread', $_G['setting']['rewritestatus'])}-->
      <meta property="og:url" content="$_Gthread-{$_G}-1-1.html"/>
      <!--{else}-->
      <meta property="og:url" content="$_Gforum.php?mod=viewthread&tid=$_G"/>
      <!--{/if}-->
      <meta property="og:title" content="$_G - $_G['setting']['bbname']"/>
      <meta property="og:description" content="{if !empty($metadescription)}{echo htmlspecialchars($metadescription)}{/if}"/>
      <!--{if $iattrs}-->
      <meta property="og:image" content="$iattrs"/>
      <!--{/if}-->
      <meta property="fb:app_id" content="$_G['cache']['plugin']['facebook_connect']['appid']"/>
      <!--{/if}-->./template/default/forum/ 下的文件
forumdisplay_fastpost.htm

<div class="pt hm">{lang login_to_post} <a href="member.php?mod=logging&action=login" onclick="showWindow('login', this.href)" class="xi2">{lang login}</a> | <a href="member.php?mod={$_G}" class="xi2">$_G['setting']['reglinkname']</a> <!--{hook/global_login_text}--></div>換成

<div class="pt hm">{lang login_to_post} <a href="member.php?mod=logging&action=login" onclick="showWindow('login', this.href)" class="xi2">{lang login}</a> | <a href="member.php?mod={$_G}" class="xi2">$_G['setting']['reglinkname']</a> | <a href="javascript:;" onclick="fblogin();"><img src="static/image/facebook_icon3.png" style="margin-bottom:-5px;"></a> <!--{hook/global_login_text}--></div>viewthread.htm

<div id="post_$post">
                              <!--{subtemplate forum/viewthread_node}-->
                        </div>下面加入
<!--{if $post['first'] && $_G['fbc']}-->
                              <!--{if in_array('forum_viewthread', $_G['setting']['rewritestatus'])}-->
                                        <div id="fbcomm_$post" style="text-align:right;"><fb:comments href="{$_G}thread-{$_G}-1-1.html" num_posts="10" width="960"></fb:comments>
                                        <div style="line-height:5px;background:{$_G};"> </div></div>
                              <!--{else}-->
                                        <div id="fbcomm_$post" style="text-align:right;"><fb:comments href="{$_G}forum.php?mod=viewthread&tid={$_G}" num_posts="10" width="960"></fb:comments>
                                        <div style="line-height:5px;background:{$_G};"> </div></div>
                              <!--{/if}-->
                        <!--{/if}-->viewthread_fastpost.htm

<div class="pt hm">{lang login_to_reply} <a href="member.php?mod=logging&action=login" onclick="showWindow('login', this.href)" class="xi2">{lang login}</a> | <a href="member.php?mod={$_G}" class="xi2">$_G['setting']['reglinkname']</a> <!--{hook/global_login_text}--></div>換成

<div class="pt hm">{lang login_to_reply} <a href="member.php?mod=logging&action=login" onclick="showWindow('login', this.href)" class="xi2">{lang login}</a> | <a href="member.php?mod={$_G}" class="xi2">$_G['setting']['reglinkname']</a> | <a href="javascript:;" onclick="fblogin();"><img src="static/image/facebook_icon3.png" style="margin-bottom:-5px;"></a> <!--{hook/global_login_text}--></div>viewthread_node.htm

<li class="pm2"><a href="home.php?mod=spacecp&ac=pm&op=showmsg&handlekey=showmsg_$post&touid=$post&pmid=0&daterange=2&pid=$post&tid=$post" onclick="showWindow('sendpm', this.href);" title="{lang viewthread_left_sendpm}" class="xi2">{lang viewthread_left_sendpm}</a></li>下面加上
<!--{if ($post && $_G['forum']['ismoderator']) || ($post && $post == 0) || ($post && $post == 1 && $isfriend[$post])}-->
                                                <li style="background-image:url(static/image/facebook_icon.png);"><a href="http://www.facebook.com/profile.php?id=$post" target="_blank">{lang facebook_profile}</a></li>
                                                <li style="background-image:url(static/image/facebook_icon.png);"><a href="http://www.facebook.com/addfriend.php?id=$post" target="_blank">{lang add_facebook_friend}</a></li>
                                        <!--{/if}-->找
<tr><td class="plc plm">下面加上

<!--{if $post['first']}--><div style="line-height:40px;"><!--{if in_array('forum_viewthread', $_G['setting']['rewritestatus'])}--><fb:like href="$_Gthread-{$_G}-1-1.html" show_faces="false" send="true" width="450"></fb:like><!--{else}--><fb:like href="$_Gforum.php?mod=viewthread&tid=$_G" show_faces="false" send="true" width="450"></fb:like><!--{/if}--></div><!--{/if}-->找
<!--{if $post['first'] && $_G && $_G == $post}-->
                              <a href="misc.php?mod=invite&action=thread&id=$_G" onclick="showWindow('invite', this.href, 'get', 0);"><i><img src="{IMGDIR}/activitysmall.gif" alt="{lang invite}" />{lang invite}</i></a>
                        <!--{/if}-->下面加上
<a href="javascript:;" onclick="fbshare();"><i><img src="static/image/facebook_icon2.png" style="margin-right:5px;">{lang thread_share}</i></a>
                        <a href="javascript:;" onclick="fbsend();"><i><img src="static/image/facebook_icon2.png" style="margin-right:5px;">{lang facebook_send}</i></a>
                        <a href="javascript:;" onclick="fbinvite();"><i><img src="static/image/facebook_icon2.png" style="margin-right:5px;">{lang invite}</i></a>viewthread_node_body.htm

<div class="{if !$_G}t_fsz{else}pcbs{/if}">
                <!--{if $post['first']}-->下面加上
<div style="line-height:40px;"><!--{if in_array('forum_viewthread', $_G['setting']['rewritestatus'])}--><fb:like href="$_Gthread-{$_G}-1-1.html" show_faces="false" send="true" width="450"></fb:like><!--{else}--><fb:like href="$_Gforum.php?mod=viewthread&tid=$_G" show_faces="false" send="true" width="450"></fb:like><!--{/if}--></div>./template/default/home/ 下的文件
space_userabout.htm

<li class="ul_pm"><a href="home.php?mod=spacecp&ac=pm&op=showmsg&handlekey=showmsg_$space&touid=$space&pmid=0&daterange=2" id="a_sendpm_$space" onclick="showWindow('showMsgBox', this.href, 'get', 0)">{lang send_pm}</a></li>下面加入

<!--{if ($sfb && $_G['adminid'] > 0) || ($sfb && $sfb == 0) || ($sfb && $sfb == 1 && $isfriend)}-->
                                        <li><a href="http://www.facebook.com/profile.php?id=$sfb" target="_blank" style="background-image:url(static/image/facebook_icon.png);">{lang facebook_profile}</a></li>
                                        <li><a href="http://www.facebook.com/addfriend.php?id=$sfb" target="_blank" style="background-image:url(static/image/facebook_icon.png);">{lang add_facebook_friend}</a></li>
                              <!--{/if}-->./template/default/member/ 下的檔案
login.htm

<td>
                                                                <button class="pn pnc" type="submit" name="loginsubmit" value="true" tabindex="1"><strong>{lang login}</strong></button>
                                                      </td>下面加上
<td><b>Facebook</b> <a href="javascript:;" onclick="fblogin();"><img src="static/image/facebook_icon3.png" style="margin-bottom:-5px;"></a></td>login_simple.htm

<td class="fastlg_l"><label for="ls_cookietime"><input type="checkbox" name="cookietime" id="ls_cookietime" class="pc" value="2592000" tabindex="903" />{lang login_permanent}</label></td>下面加上
<td class="fastlg_l" rowspan="2"><a href="javascript:;" onclick="fblogin();"><img src="static/image/facebook_iconb.png"></a></td>register.htm

<td><!--{if $this->setting['sitemessage']}--><a href="javascript:;" id="custominfo_register" class="y"><img src="{IMGDIR}/info_small.gif" alt="{lang faq}" /></a><!--{/if}--></td>下面加入
<td><b>Facebook</b> <a href="javascript:;" onclick="fblogin();"><img src="static/image/facebook_icon3.png" style="margin-bottom:-5px;"></a></td>最後把附件上傳,大功告成!







































































頁: [1]
查看完整版本: [X2.0] Facebook Connect 教學