TShopping

 找回密碼
 註冊
搜索
查看: 5756|回復: 6

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

    [複製鏈接]
發表於 2011-4-3 23:49:09 | 顯示全部樓層 |閱讀模式
 
Push to Facebook
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. if($GLOBALS['authorreplyexist'] || (isset($_GET['show']) && $_GET['show'] == "true")) {
複製代碼

2. 打開 templates/default/discuzcode.htm
   找到
               

  1. <!--{block return}--><div class="locked">{lang post_hide_reply_hidden}</div><!--{/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></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. FB.Event.subscribe('auth.sessionChange', function() {
  10.   ajaxget('viewthread.php?show=true&tid=' + tid + '&viewpid=' + firstpid, 'post_' + firstpid);
  11. });

  12. FB.Event.subscribe('edge.create', function(response){
  13.   if(typeof(firstpid)== "number"){
  14.    ajaxget('viewthread.php?show=true&tid=' + tid + '&viewpid=' + firstpid, 'post_' + firstpid);
  15.   }
  16. });
  17. };
  18. (function() {
  19. var e = document.createElement('script'); e.async = true;
  20. e.src = document.location.protocol + '//connect.facebook.net/zh_TW/all.js';
  21. document.getElementById('fb-root').appendChild(e);
  22. }());
  23. </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 ..


====================
2011-03-16 10:35PM
更新支持圖片

1. 打開 viewthread.php
    找到
      
  1. if(empty($viewpid)) {
  2.                 include template('viewthread');
  3.         } else {
複製代碼



    上面加入
        
  1. $first_attachments = array_pop($postlist[$firstpid]['attachments']);
複製代碼




2. 打開 templates/default/header.html
    找到
      
  1. <title>$navtitle $bbname $seotitle - Powered by Discuz!</title>
  2.         $seohead
複製代碼



    下方加入
      
  1. <!--{if $navtitle}-->
  2.                 <meta property="og:title" content="$navtitle $bbname $seotitle"/>
  3.                 <meta property="og:site_name" content="$bbname"/>
  4.                 <meta property="og:description" content="$seodescription"/>
  5.                 <meta property="og:type" content="website" />
  6.                 <!--{if $first_attachments}-->
  7.                         <meta property="og:image" content="{$boardurl}$first_attachments['url']/$first_attachments['attachment']"/>
  8.                 <!--{else}-->
  9.                         <meta property="og:image" content="如果沒有貼子將出現的網站"/>
  10.                 <!--{/if}-->
  11.         <!--{/if}-->
複製代碼




*注意部份
1. 圖片系附件..就必須有一張圖唔可以隱藏..否則會顯示唔到..只會出 else 部份
2. array_pop 你可以改為 array_shift 前者系拎最舊個張圖..後者就系最新
3. 另外就系 og tag 部份可以自己查找 facebook 得到更加多 tag

 

臉書網友討論
發表於 2011-5-3 21:09:46 | 顯示全部樓層
好複雜><
基礎從哪開始學起啊??

版主招募中

 樓主| 發表於 2011-5-3 22:55:35 | 顯示全部樓層
那是很深的 請從HTML語法開始


發表於 2011-5-18 21:26:37 | 顯示全部樓層
大大分享很好資訊謝謝~


發表於 2011-6-9 14:17:40 | 顯示全部樓層
感謝大大的熱情分享 ...................:lol


發表於 2012-1-22 23:53:26 | 顯示全部樓層
哥回的不是貼是在灌水


發表於 2014-7-28 16:42:16 | 顯示全部樓層


  真有如此?


*滑块验证:
您需要登錄後才可以回帖 登錄 | 註冊 |

本版積分規則



Archiver|手機版|小黑屋|免責聲明|TShopping

GMT+8, 2024-3-19 15:59 , Processed in 0.053179 second(s), 19 queries .

本論壇言論純屬發表者個人意見,與 TShopping綜合論壇 立場無關 如有意見侵犯了您的權益 請寫信聯絡我們。

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回復 返回頂部 返回列表