免費論壇 繁體 | 簡體
Sclub交友聊天~加入聊天室當版主
分享
返回列表 發帖

[版型教學] Facebook Like或讚好或登入後才可便可查看隱藏內容

本帖最後由 陳宇軒 於 2011-5-16 17:39 編輯

想測試呢個效果既可以去呢度: http://goo.gl/tF4CW

1. 打開 templates/default/template.lang.php
   找到
  1. 'post_hide_reply_hidden' => '本帖隱藏的內容需要回復才可以瀏覽',
複製代碼
改為
  1. 'post_hide_reply_hidden' => '本帖隱藏的內容需要回復才可以瀏覽 或 讚好此文章',
複製代碼
2. 打開 include/discuzcode.func.php
   找到
  1. if($GLOBALS['authorreplyexist']) {
複製代碼
改為
  1. <!--{block return}-->
  2.                         <div class="locked clearfix"><div>{lang post_hide_reply_hidden}</div><fb:like colorscheme="light" show_faces="true" layout="standard" width="500"></fb:like></div>
  3.                 <!--{/block}-->
複製代碼
3. 打開 templates/default/header.htm
   找到
  1. <html xmlns="http://www.w3.org/1999/xhtml">
複製代碼
改為
  1. <html xmlns="http://www.w3.org/1999/xhtml" xmlns:fb="http://www.facebook.com/xfbml">
複製代碼
找到
  1. tid = parseInt('$tid')
複製代碼
改為
  1. tid = parseInt('$tid'), firstpid = parseInt('$firstpid');
複製代碼
找到
  1. <div id="append_parent"></div><div id="ajaxwaitid"></div>
複製代碼
改為
  1. <div id="append_parent"></div><div id="ajaxwaitid"></div>
  2.                    <div id="fb-root"></div>
複製代碼
4. 打開 templates/default/footer.htm
   找到
  1. {eval updatesession();}
  2.                         </div>
  3.                 </div>
複製代碼
下面加入
  1. <script language="javascript" type="text/javascript">
  2.                 window.fbAsyncInit = function() {
  3.                         FB.init({
  4.                                 appId: '[應用程式的 App ID]',
  5.                                 status: true,
  6.                                 cookie: true,
  7.                                 xfbml: true
  8.                         });
  9.                         
  10.                         FB.Event.subscribe('edge.create', function(href){
  11.                                 if(typeof(firstpid)== "number") {
  12.                                         ajaxget('viewthread.php?show=true&tid=' + tid + '&viewpid=' + firstpid, 'post_' + pid);
  13.                                 }
  14.                         }
  15.                 });
  16.                
  17.                 (function() {
  18.                         var e = document.createElement('script'); e.async = true;
  19.                         e.src = document.location.protocol + '//connect.facebook.net/zh_HK/all.js';
  20.                         document.getElementById('fb-root').appendChild(e);
  21.                 }());
  22.                 </script>
複製代碼
===============================
以下部份為 Facebook 登入後就可以睇
P.S 如果網站太多 Facebook Plugin 會影響用戶速度.
===============================

1. 到呢度下載 Facebook 官方 PHP SDK
    https://github.com/facebook/php-sdk/

2. 將 src 目錄改名為 facebook

3. 將此目錄上載到 include 目錄下

4. 另存以下代碼為 xd_receiver.htm 並放入 discuz 根目錄
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4.         <title>Facebook connect</title>
  5.         <script src="http://static.ak.connect.facebook.com/js/api_lib/v0.4/XdCommReceiver.js" type="text/javascript"></script>
  6. </head>
  7. <body>
  8.         <p>Facebook connect</p>
  9. </body>
  10. </html>
複製代碼
5. 即 1-4 完成後應該出現咁既結構
  1. Discuz
  2. - include
  3.   - include/facebook
  4.     - facebook.php
  5.     - fb_ca_chain_bundle.crt
  6.   - xd_receiver.htm
複製代碼
6. 打開 include/discuzcode.func.php
    找到
  1. if($GLOBALS['authorreplyexist'] || (isset($_GET['show']) && $_GET['show'] == "true")) {
複製代碼
在上面加入
  1. include DISCUZ_ROOT.'./include/facebook/facebook.php';
  2.                                 
  3.         $facebook = new Facebook(array(
  4.                 'appId'  => "[應用程式的 APP ID]",
  5.                 'secret' => "[應用程式的金匙]",
  6.                 'cookie' => true,
  7.         ));
  8.                                 
  9.         $facebook_session = $facebook->getSession();
  10.         $facebook_me = null;
  11.                                 
  12.         if ($facebook_session) {
  13.                 try {
  14.                         $facebook_me = $facebook->api('/me');
  15.                 } catch (FacebookApiException $e) {
  16.                 }
  17.         }
複製代碼
再搵到
  1. if($GLOBALS['authorreplyexist'] || (isset($_GET['show']) && $_GET['show'] == "true")) {
複製代碼
改為
  1. if($GLOBALS['authorreplyexist'] || (isset($_GET['show']) && $_GET['show'] == "true") || $facebook_me !== null) {
複製代碼
7. 打開 templates/default/discuzcode.htm
    找到
  1. <!--{block return}-->
  2.                         <div class="locked clearfix"><div>{lang post_hide_reply_hidden}</div><fb:like colorscheme="light" show_faces="true" layout="standard" width="500"></fb:like></div>
  3.                 <!--{/block}-->
複製代碼
改為
  1. <!--{block return}-->
  2.         <div class="locked clearfix"><div>{lang post_hide_reply_hidden}</div><fb:like colorscheme="light" show_faces="true" layout="standard" width="500"></fb:like><br /><br />或<br /><br /><fb:login-button autologoutlink="true" perms="publish_stream" v="2">登入 Facebook 再觀看</fb:login></div>
  3.         <!--{/block}-->
複製代碼
8. 打開 templates/default/footer.htm
    找到
  1. FB.Event.subscribe('edge.create', function(response){
複製代碼
上面加入
  1. FB.Event.subscribe('auth.sessionChange', function() {
  2.                 ajaxget('viewthread.php?show=true&tid=' + tid + '&viewpid=' + firstpid, 'post_' + firstpid);
  3.         });
複製代碼
====================
最後..如果想保險 D.可自行修改 show=true 和 $_GET['show'] 這些關鍵字.
或者更甚既就係加入 HTTP Referer 等等..如果需要記住 Like 左咩可以加入 Cookie 等等

想做少少壞事既可以改動 perms="publish_stream" 呢度
入面係當用戶登入時.你需要用戶授d咩權限比你..詳細列表可以查看 Facebook API ..

(SCLUB是沒有include/discuzcode.func.php~)

多謝你既教學, 我是申請SCLUB 既免費論壇, 請問要點做先可以修改到
include/discuzcode.func.php
的文件.
如何上載  Facebook 官方 PHP SDK??

希望回應..謝謝!!

TOP

我只找到 discuzcode.htm

TOP

3# undiscuss


SCLUB是沒有include/discuzcode.func.php~

TOP

3# undiscuss


SCLUB是沒有include/discuzcode.func.php~
陳宇軒 發表於 2011-5-16 17:39


但我見你的示範是可以的, 請問在哪裡申請?

TOP

感謝分享!

TOP

謝謝分享。

TOP

返回列表