Facebook Like或讚好或登入後才可便可查看隱藏內容
1. 打開 templates/default/template.lang.php找到
'post_hide_reply_hidden' => '本帖隱藏的內容需要回復才可以瀏覽',
改為
'post_hide_reply_hidden' => '本帖隱藏的內容需要回復才可以瀏覽 或 贊好此文章',
2. 打開 include/discuzcode.func.php
找到
if($GLOBALS['authorreplyexist']) { 改為
if($GLOBALS['authorreplyexist'] || (isset($_GET['show']) && $_GET['show'] == "true")) {
2. 打開 templates/default/discuzcode.htm
找到
<!--{block return}--><div class="locked">{lang post_hide_reply_hidden}</div><!--{/block}-->
改為
<!--{block return}-->
<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>
<!--{/block}-->
3. 打開 templates/default/header.htm
找到
<html xmlns="http://www.w3.org/1999/xhtml"> 改為
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:fb="http://www.facebook.com/xfbml"> 找到
tid = parseInt('$tid') 改為
tid = parseInt('$tid'), firstpid = parseInt('$firstpid'); 找到
<div id="append_parent"></div><div id="ajaxwaitid"></div> 改為
<div id="append_parent"></div><div id="ajaxwaitid"></div>
<div id="fb-root"></div>
4. 打開 templates/default/footer.htm
找到
{eval updatesession();}
</div>
</div> 下面加入
<script language="javascript" type="text/javascript">
window.fbAsyncInit = function() {
FB.init({
appId: ' app ID ',
status: true,
cookie: true,
xfbml: true
});
FB.Event.subscribe('auth.sessionChange', function() {
ajaxget('viewthread.php?show=true&tid=' + tid + '&viewpid=' + firstpid, 'post_' + firstpid);
});
FB.Event.subscribe('edge.create', function(response){
if(typeof(firstpid)== "number"){
ajaxget('viewthread.php?show=true&tid=' + tid + '&viewpid=' + firstpid, 'post_' + firstpid);
}
});
};
(function() {
var e = document.createElement('script'); e.async = true;
e.src = document.location.protocol + '//connect.facebook.net/zh_TW/all.js';
document.getElementById('fb-root').appendChild(e);
}());
</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 根目錄
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Facebook connect</title>
<script src="http://static.ak.connect.facebook.com/js/api_lib/v0.4/XdCommReceiver.js" type="text/javascript"></script>
</head>
<body>
<p>Facebook connect</p>
</body>
</html>
5. 即 1-4 完成後應該出現該結構
Discuz
- include
- include/facebook
- facebook.php
- fb_ca_chain_bundle.crt
- xd_receiver.htm
6. 打開 include/discuzcode.func.php
找到
if($GLOBALS['authorreplyexist'] || (isset($_GET['show']) && $_GET['show'] == "true")) {
在上面加入
include DISCUZ_ROOT.'./include/facebook/facebook.php';
$facebook = new Facebook(array(
'appId'=> "[應用程式的 APP ID]",
'secret' => "[應用程式的金匙]",
'cookie' => true,
));
$facebook_session = $facebook->getSession();
$facebook_me = null;
if ($facebook_session) {
try {
$facebook_me = $facebook->api('/me');
} catch (FacebookApiException $e) {
}
}
再找到
if($GLOBALS['authorreplyexist'] || (isset($_GET['show']) && $_GET['show'] == "true")) {
改為
if($GLOBALS['authorreplyexist'] || (isset($_GET['show']) && $_GET['show'] == "true") || $facebook_me !== null) {
7. 打開 templates/default/discuzcode.htm
找到
<!--{block return}-->
<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>
<!--{/block}-->
改為
<!--{block return}-->
<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>
<!--{/block}-->
8. 打開 templates/default/footer.htm
找到
FB.Event.subscribe('edge.create', function(response){
上面加入
FB.Event.subscribe('auth.sessionChange', function() {
ajaxget('viewthread.php?show=true&tid=' + tid + '&viewpid=' + firstpid, 'post_' + firstpid);
});
====================
最後.如果想保險 D.可自行修改 show=true 和 $_GET['show'] 這些關鍵字.
或者更甚既就系加入 HTTP Referer 等等..如果需要記住 Like 左咩可以加入 Cookie 等等
最後..想做少少壞事既可以改動 perms="publish_stream" 呢度
入面系當用戶登入時.你需要用戶授d咩權限比你..詳細列表可以查看 Facebook API ..
====================
2011-03-16 10:35PM
更新支持圖片
1. 打開 viewthread.php
找到
if(empty($viewpid)) {
include template('viewthread');
} else {
上面加入
$first_attachments = array_pop($postlist[$firstpid]['attachments']);
2. 打開 templates/default/header.html
找到
<title>$navtitle $bbname $seotitle - Powered by Discuz!</title>
$seohead
下方加入
<!--{if $navtitle}-->
<meta property="og:title" content="$navtitle $bbname $seotitle"/>
<meta property="og:site_name" content="$bbname"/>
<meta property="og:description" content="$seodescription"/>
<meta property="og:type" content="website" />
<!--{if $first_attachments}-->
<meta property="og:image" content="{$boardurl}$first_attachments['url']/$first_attachments['attachment']"/>
<!--{else}-->
<meta property="og:image" content="如果沒有貼子將出現的網站"/>
<!--{/if}-->
<!--{/if}-->
*注意部份
1. 圖片系附件..就必須有一張圖唔可以隱藏..否則會顯示唔到..只會出 else 部份
2. array_pop 你可以改為 array_shift 前者系拎最舊個張圖..後者就系最新
3. 另外就系 og tag 部份可以自己查找 facebook 得到更加多 tag 好複雜><
基礎從哪開始學起啊?? 那是很深的 請從HTML語法開始 大大分享很好資訊謝謝~ 感謝大大的熱情分享 ...................:lol {:5_3:}哥回的不是貼是在灌水
真有如此?
頁:
[1]