Skip to content

Commit

Permalink
添加管理员 Badge
Browse files Browse the repository at this point in the history
  • Loading branch information
fooleap committed Jul 24, 2017
1 parent 8b74401 commit 4c79f1d
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 10 deletions.
3 changes: 2 additions & 1 deletion api/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* 配置文件
*
* @author fooleap <fooleap@gmail.com>
* @version 2017-07-16 20:45:01
* @version 2017-07-24 12:57:37
* @link https://github.com/fooleap/disqus-php-api
*
*/
Expand All @@ -20,6 +20,7 @@
* DISQUS_SHORTNAME 网站在 Disqus 对应的 Shortname
* DISQUS_APPROVED 评论是否免审核,true 即跳过评论预审核,false 则按后台设置
*
* 留言者的名字为 DISQUS_USERNAME 或邮箱号为 DISQUS_EMAIL 皆视为管理员
* 填写正确的邮箱、密码之后,将以网站管理员的身份去获取评论数据。
* 发送评论请求时,请填写在此设置的用户名、邮箱信息,将以登录身份发表评论。
*
Expand Down
6 changes: 5 additions & 1 deletion api/init.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* 获取权限,简单封装常用函数
*
* @author fooleap <fooleap@gmail.com>
* @version 2017-07-13 14:47:36
* @version 2017-07-24 12:54:39
* @link https://github.com/fooleap/disqus-php-api
*
*/
Expand Down Expand Up @@ -135,6 +135,9 @@ function curl_post($url, $data){
function post_format( $post ){
global $client, $gravatar_cdn, $gravatar_default;

// 是否是管理员
$isMod = $post->author->name == DISQUS_USERNAME || $post->author->email == DISQUS_EMAIL ? true : false;

// 访客指定 Gravatar 头像
$avatar_url = GRAVATAR_CDN.md5($post->author->email).'?d='.GRAVATAR_DEFAULT;
$post->author->avatar->cache = $post->author->isAnonymous ? $avatar_url : $post->author->avatar->cache;
Expand Down Expand Up @@ -165,6 +168,7 @@ function post_format( $post ){

$data = array(
'avatar' => $post -> author -> avatar -> cache,
'isMod' => $isMod,
'createdAt' => $post -> createdAt.'+00:00',
'id'=> $post -> id,
'media' => $imgArr,
Expand Down
2 changes: 1 addition & 1 deletion dist/iDisqus.min.css

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/iDisqus.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "disqus-php-api",
"version": "0.1.7",
"version": "0.1.8",
"description": "disqus-php-api 利用 PHP cURL 转发 Disqus API 请求",
"main": "index.js",
"dependencies": {},
Expand Down
6 changes: 6 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,12 @@ var disq = new iDisqus('comment', {
* {Boolean}
* 默认:`false`;

##### badge

* 管理员徽章文本
* {String}
* 默认:`"管理员"`

### 实例方法

#### init
Expand Down
8 changes: 5 additions & 3 deletions src/iDisqus.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*!
* v 0.1.7
* v 0.1.8
* https://github.com/fooleap/disqus-php-api
*
* Copyright 2017 fooleap
Expand Down Expand Up @@ -225,6 +225,7 @@
_.opts.mode = !!_.opts.mode ? _.opts.mode : 1;
_.opts.timeout = !!_.opts.timeout ? _.opts.timeout : 3000;
_.opts.toggle = !!_.opts.toggle ? d.getElementById(_.opts.toggle) : null;
_.opts.badge = !!_.opts.badge ? _.opts.badge : '管理员';

// emoji 表情
_.opts.emoji_path = !!_.opts.emoji_path ? _.opts.emoji_path : 'https://assets-cdn.github.com/images/icons/emoji/unicode/';
Expand Down Expand Up @@ -661,12 +662,13 @@

var _ = this;

var parentPostDom = _.dom.querySelector('.comment-item[data-id="'+post.parent+'"]');
var parentPost = !post.parent ? {
name: '',
dom: _.dom.querySelector('.comment-list'),
insert: 'afterbegin'
} : {
name: !!_.dom.querySelector('.comment-item[data-id="'+post.parent+'"]') ? '<a class="comment-item-pname" href="#'+_.dom.querySelector('.comment-item[data-id="'+post.parent+'"]').id+'"><svg class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="200" height="200"><path d="M1.664 902.144s97.92-557.888 596.352-557.888V129.728L1024 515.84l-425.984 360.448V628.8c-270.464 0-455.232 23.872-596.352 273.28"></path></svg>' + _.dom.querySelector('.comment-item[data-id="'+post.parent+'"]').dataset.name + '</a>': '',
name: !!parentPostDom ? '<a class="comment-item-pname" href="#'+parentPostDom.id+'"><svg class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="200" height="200"><path d="M1.664 902.144s97.92-557.888 596.352-557.888V129.728L1024 515.84l-425.984 360.448V628.8c-270.464 0-455.232 23.872-596.352 273.28"></path></svg>' + parentPostDom.dataset.name + '</a>': '',
dom: _.dom.querySelector('.comment-item[data-id="'+post.parent+'"] .comment-item-children'),
insert: 'beforeend'
};
Expand All @@ -681,7 +683,7 @@
var html = '<li class="comment-item" data-id="' + post.id + '" data-name="'+ post.name + '" id="comment-' + post.id + '">' +
'<div class="comment-item-avatar"><img src="' + post.avatar + '"></div>'+
'<div class="comment-item-main">'+
'<div class="comment-item-header"><a class="comment-item-name" title="' + post.name + '" rel="nofollow" target="_blank" href="' + ( post.url ? post.url : 'javascript:;' ) + '">' + post.name + '</a>'+parentPost.name+'<span class="comment-item-bullet"> • </span><span class="comment-item-time timeago" datetime="' + post.createdAt + '"></span><span class="comment-item-bullet"> • </span><a class="comment-item-reply" href="javascript:;">回复</a></div>'+
'<div class="comment-item-header"><a class="comment-item-name" title="' + post.name + '" rel="nofollow" target="_blank" href="' + ( post.url ? post.url : 'javascript:;' ) + '">' + post.name + '</a>'+ (post.isMod ?'<span class="comment-item-badge">'+_.opts.badge+'</span>' :'')+parentPost.name+'<span class="comment-item-bullet"> • </span><span class="comment-item-time timeago" datetime="' + post.createdAt + '"></span><span class="comment-item-bullet"> • </span><a class="comment-item-reply" href="javascript:;">回复</a></div>'+
'<div class="comment-item-content">' + post.message + mediaHTML + '</div>'+
'<ul class="comment-item-children"></ul>'+
'</div>'+
Expand Down
13 changes: 12 additions & 1 deletion src/iDisqus.scss
Original file line number Diff line number Diff line change
Expand Up @@ -637,6 +637,17 @@
}
}
}
.comment-item-badge {
color: #fff;
background: #7f919e;
padding: 1px 3px;
margin: 0 2px;
font-size: 10px;
line-height: 1.1;
font-weight: 700;
border-radius: 3px;
display: inline-block;
}
.comment-item-time {
font-size: 12px;
color: #7f919e;
Expand All @@ -646,7 +657,7 @@
.comment-item-name,
.comment-item-cancel{
color: rgb(0, 149, 221);
font-weight: 500;
font-weight: 700;
border-bottom: none;
}
.comment-item-name[href^="javascript"] {
Expand Down

0 comments on commit 4c79f1d

Please sign in to comment.