利用 PHP cURL 转发 Disqus API 请求
Disqus 被墙,故做几个简单的接口,用于墙内环境访问 Disqus。
注:由于 GDPR,Disqus 目前屏蔽了 Email 及 IP 的获取,因此 Gravatar 头像及匿名评论的邮件通知暂无法完美实现。目前暂存匿名评论者邮箱号,以发回复邮件通知显示 Gravatar 头像。
使用 API 实现匿名评论功能,需在 Disqus 后台网站设置,设置相关选项。
config.php
,有简单说明。必须在 Disqus API 申请注册一个 App,取得相关的公钥(API Key)、私钥(API Secret),并填写于后端的配置文件 config.php
中。
App 设置方面,回调链接请填写 login.php
文件的绝对地址,主要的设置如下图,可根据自己情况填写。
简易评论框及 Disqus 评论框皆可实现,规则如下:
DEMO: http://blog.fooleap.org/disqus-php-api.html
项目将 Disqus 原生评论框加载代码打包在内,若使用本评论框,需将网页上所有与 Disqus 相关的元素清除,例如 id 为 disqus_thread
的容器、disqus_config
函数等。
Disqus 评论框的相关配置disqus_config
:
this.page.identifier
: identifier,若无设置则为 urlthis.page.title
: titlethis.page.url
: site + url关于 Disqus 原生评论框配置的说明,可以看此页面:https://help.disqus.com/customer/portal/articles/472098-javascript-configuration-variables
<link rel="stylesheet" href="https://github.com/fooleap/disqus-php-api/blob/master/path/to/iDisqus.min.css" />
<div id="comment"></div>
<script src="https://github.com/fooleap/disqus-php-api/raw/master/path/to/iDisqus.min.js"></script>
var disq = new iDisqus('comment', {
forum: 'ifool',
api: 'http://api.fooleap.org/disqus',
site: 'http://blog.fooleap.org',
mode: 1,
timeout: 3000,
init: true
});
ID
, OPTIONS);"comment"
OPTIONS
);http://api.fooleap.org/disqus
http://blog.fooleap.org
location.origin
location.pathname + location.search
document.title
1
检测能否访问 Disqus,若能则加载 Disqus 原生评论框,超时则加载简易评论框2
仅加载简易评论框3
同时加载两种评论框,先显示简易评论框,Disqus 加载完成则切换至 Disqus 评论框1
3000
<input type="checkbox" id="comment-toggle" disabled />
,此项则设置为 "comment-toggle"
,当 Disqus 加载完时,选择框可用。false
true
false
"https://github.githubassets.com/images/icons/emoji/unicode/"
false
Related
,可选Popular