Skip to content

Commit

Permalink
留言后可一次编辑
Browse files Browse the repository at this point in the history
  • Loading branch information
fooleap committed Aug 1, 2017
1 parent ef35ecb commit 0e6da4a
Show file tree
Hide file tree
Showing 9 changed files with 266 additions and 135 deletions.
4 changes: 2 additions & 2 deletions 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-30 15:09:11
* @version 2017-07-30 15:43:58
* @link https://github.com/fooleap/disqus-php-api
*
*/
Expand Down Expand Up @@ -141,7 +141,7 @@ function curl_post($url, $data){
}

function post_format( $post ){
global $client, $gravatar_cdn, $gravatar_default;
global $client;

// 是否是管理员
$isMod = ($post->author->name == DISQUS_USERNAME || $post->author->email == DISQUS_EMAIL ) && $post->author->isAnonymous == false ? true : false;
Expand Down
3 changes: 2 additions & 1 deletion api/postcomment.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* @param url 访客网址,可为空
*
* @author fooleap <fooleap@gmail.com>
* @version 2017-07-27 20:40:08
* @version 2017-08-01 07:30:43
* @link https://github.com/fooleap/disqus-php-api
*
*/
Expand All @@ -27,6 +27,7 @@
if( $author_email == DISQUS_EMAIL && strpos($session, 'session') !== false ){
$author_email = null;
$author_url = null;
$approved = null;
}
}

Expand Down
9 changes: 5 additions & 4 deletions api/sendemail.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* @param id 该评论 ID
*
* @author fooleap <fooleap@gmail.com>
* @version 2017-07-27 20:32:12
* @version 2017-08-01 07:33:45
* @link https://github.com/fooleap/disqus-php-api
*
*/
Expand All @@ -30,7 +30,8 @@
$curl_url = '/api/3.0/posts/details.json?'.http_build_query($fields_data);
$data = curl_get($curl_url);
$post = post_format($data->response);
$parent_isanon = $data->response->author->isAnonymous; //是否为访客
//$parent_isanon = $data->response->author->isAnonymous; //是否为访客
$parent_isMod = $post['isMod'];
$parent_email = $data->response->author->email; //被回复邮箱
$parent_name = $post['name']; //被回复人名
$parent_message = $post['message']; //被回复留言
Expand All @@ -52,8 +53,8 @@
$content .= $reply_message;
$content .= '<p>查看详情及回复请点击:<a target="_blank" href="'.$website. $_POST['link'] . '#comment-' . $_POST['parent'] . '">' . $_POST['title'] . '</a></p>';

use PHPMailer;
if( $parent_isanon ){
if( !$parent_isMod ){
use PHPMailer;

// 发送邮件
require_once('PHPMailer/class.phpmailer.php');
Expand Down
57 changes: 57 additions & 0 deletions api/updatecomment.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php
/**
* 更新评论
*
* @param id 评论 ID
* @param message 评论内容
*
* @author fooleap <fooleap@gmail.com>
* @version 2017-08-01 06:10:46
* @link https://github.com/fooleap/disqus-php-api
*
*/
namespace Emojione;
date_default_timezone_set('UTC');
require_once('init.php');

$fields_data = array(
'api_key' => DISQUS_PUBKEY,
'post' => $_POST['id']
);
$curl_url = '/api/3.0/posts/details.json?'.http_build_query($fields_data);
$data = curl_get($curl_url);
$duration = time() - strtotime($data->response->createdAt);

$output = array();

if($data->code !== 0){
$output = array(
'code' => 2,
'response' => '请求方式有误或不存在此 post'
);
print_r(json_encode($output));
return;
}

if( $duration < 1800 ){
// 三十分钟内
$post_data = array(
'api_key' => DISQUS_PUBKEY,
'post' => $_POST['id'],
'message' => $_POST['message']
);
$curl_url = '/api/3.0/posts/update.json';
$data = curl_post($curl_url, $post_data);
$output = $data -> code == 0 ? array(
'code' => $data -> code,
'response' => post_format($data -> response)
) : $data;
} else {
// 三十分钟外
$output = array(
'code' => 0,
'response' => '更新失败,留言时间已超过三十分钟'
);
}

print_r(json_encode($output));
2 changes: 1 addition & 1 deletion dist/iDisqus.min.css

Large diffs are not rendered by default.

6 changes: 3 additions & 3 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.12",
"version": "0.1.13",
"description": "disqus-php-api 利用 PHP cURL 转发 Disqus API 请求",
"main": "index.js",
"dependencies": {},
Expand Down
Loading

0 comments on commit 0e6da4a

Please sign in to comment.