Skip to content

Commit

Permalink
完善配置说明
Browse files Browse the repository at this point in the history
  • Loading branch information
fooleap committed Jun 23, 2017
1 parent a7611aa commit af253d3
Show file tree
Hide file tree
Showing 19 changed files with 270 additions and 253 deletions.
42 changes: 21 additions & 21 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
MIT License

Copyright (c) 2017 Fooleap Chen

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
MIT License
Copyright (c) 2017 Fooleap Chen
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
File renamed without changes.
File renamed without changes.
82 changes: 62 additions & 20 deletions api/config.php
Original file line number Diff line number Diff line change
@@ -1,27 +1,69 @@
<?php
namespace Emojione;

$public_key = 'E8Uh5l5fHZ6gD8U3KycjAIAk46f68Zw7C6eW8WSjZvCLXebZ7p0r1yrYDrLilk2F';
$origin = '网站域名';
$forum = 'Disqus forum';
$username = 'Disqus 用户名';
$email = 'Disqus 邮箱';
$password = 'Disqus 密码';
/*
* Disqus 设置
*
* DISQUS_PUBKEY Disqus 公钥,无需修改
* DISQUS_NAME Disqus 用户名
* DISQUS_EMAIL Disqus 注册邮箱
* DISQUS_PASSWORD Disqus 密码
* DISQUS_WEBSITE 网站域名,如:'http://blog.fooleap.org'
* DISQUS_SHORTNAME 网站在 Disqus 对应的 Short name
*
* 填写正确的邮箱、密码之后,将以网站管理员的身份去获取评论数据。
* 发送评论请求时,请填写在此设置的用户名、邮箱信息,将以登录身份发表评论。
*
*/

$gfw_inside = 0;
$disqus_ip = '151.101.0.134';
$disqus_media_ip = '151.101.40.64';
define('DISQUS_PUBKEY', 'E8Uh5l5fHZ6gD8U3KycjAIAk46f68Zw7C6eW8WSjZvCLXebZ7p0r1yrYDrLilk2F');
define('DISQUS_NAME', '');
define('DISQUS_EMAIL', '');
define('DISQUS_PASSWORD', '');
define('DISQUS_WEBSITE', '');
define('DISQUS_SHORTNAME', '');

$gravatar_cdn = '//cn.gravatar.com/avatar/';
$gravatar_default = 'https://a.disquscdn.com/images/noavatar92.png';
$emoji_path = 'https://assets-cdn.github.com/images/icons/emoji/unicode/';
/*
* 网络设置
*
* GFW_INSIDE 服务器是否在墙内,在墙内则为 true,将指定 IP
* DISQUS_IP disqus.com IP 地址,可选:151.101.0.134, 151.101.64.134, 151.101.128.134, 151.101.192.134
* DISQUS_MEDIAIP uploads.services.disqus.com IP 地址,可选:151.101.24.64, 151.101.40.64, 151.101.52.64
*
*/

// PHP Mailer 设置
$site_name = '网站名';
$smtp_secure = 'ssl';
$smtp_host = 'smtp.exmail.qq.com';
$smtp_port = 465;
$smtp_username = '邮箱';
$smtp_password = '密码';
define('GFW_INSIDE', false);
define('DISQUS_IP', '151.101.0.134');
define('DISQUS_MEDIAIP', '151.101.24.64');

$max_posts = 50;
/*
* 图片设置
*
* GRAVATAR_CDN Gravatar 头像 CDN
* GRAVATAR_DEFAULT 默认头像 URL
* EMOJI_PATH Emoji 表情 PNG 资源路径
*
*/

define('GRAVATAR_CDN', '//cn.gravatar.com/avatar/');
define('GRAVATAR_DEFAULT', 'https://a.disquscdn.com/images/noavatar92.png');
define('EMOJI_PATH', 'https://assets-cdn.github.com/images/icons/emoji/unicode/');

/*
* PHP Mailer 设置
*
* SITE_NAME 网站名
* SMTP_SECURE 安全协议
* SMTP_HOST 邮箱服务器
* SMTP_PORT 端口号
* SMTP_USERNAME SMTP 登录的账号,即邮箱号
* SMTP_PASSWORD SMTP 登录的账号,即邮箱密码
*
*/

define('SITE_NAME', '');
define('SMTP_SECURE', 'ssl');
define('SMTP_HOST', '');
define('SMTP_PORT', 465);
define('SMTP_USERNAME', '');
define('SMTP_PASSWORD', '');
6 changes: 3 additions & 3 deletions api/count.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
namespace Emojione;
require_once('init.php');

$links = '&thread=link:'.$origin.preg_replace('/,/i','&thread=link:'.$origin, $_GET['link']);
$links = '&thread=link:'.DISQUS_WEBSITE.preg_replace('/,/i','&thread=link:'.DISQUS_WEBSITE, $_GET['link']);

$fields_data = array(
'api_key' => $public_key,
'forum' => $forum
'api_key' => DISQUS_PUBKEY,
'forum' => DISQUS_SHORTNAME
);

$curl_url = '/api/3.0/threads/list.json?'.http_build_query($fields_data).$links;
Expand Down
4 changes: 2 additions & 2 deletions api/createthread.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
require_once('init.php');
$curl_url = '/api/3.0/threads/create.json';
$post_data = array(
'api_key' => $public_key,
'forum' => $forum,
'api_key' => DISQUS_PUBKEY,
'forum' => DISQUS_SHORTNAME,
'message' => $_POST['message'],
'slug' => $_POST['slug'],
'title' => $_POST['title'],
Expand Down
16 changes: 8 additions & 8 deletions api/getcomments.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,20 @@
require_once('init.php');

$fields_data = array(
'api_key' => $public_key,
'api_key' => DISQUS_PUBKEY,
'cursor' => $_GET['cursor'],
'limit' => isset($max_posts) ? $max_posts : 50,
'forum' => $forum,
'limit' => 50,
'forum' => DISQUS_SHORTNAME,
'order' => 'desc',
'thread' => 'link:'.$origin.$_GET['link']
'thread' => 'link:'.DISQUS_WEBSITE.$_GET['link']
);
$curl_url = '/api/3.0/posts/list.json?'.http_build_query($fields_data);
$data = curl_get($curl_url);

$fields_data = array(
'api_key' => $public_key,
'forum' => $forum,
'thread' => 'link:'.$origin.$_GET['link'],
'api_key' => DISQUS_PUBKEY,
'forum' => DISQUS_SHORTNAME,
'thread' => 'link:'.DISQUS_WEBSITE.$_GET['link'],
);
$curl_url = '/api/3.0/threads/details.json?'.http_build_query($fields_data);
$detail = curl_get($curl_url);
Expand All @@ -28,7 +28,7 @@
$listposts = array(
'code' => $detail -> code,
'cursor' => $data -> cursor,
'link' => 'https://disqus.com/home/discussion/'.$forum.'/'.$detail -> response -> slug.'/?l=zh',
'link' => 'https://disqus.com/home/discussion/'.DISQUS_SHORTNAME.'/'.$detail -> response -> slug.'/?l=zh',
'posts' => $detail -> response -> posts,
'response' => array_reverse($posts),
'thread' => $detail -> response -> id
Expand Down
3 changes: 1 addition & 2 deletions api/getgravatar.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?php
require_once('init.php');
$avatar_url = $gravatar_cdn.md5($_GET['email']).'?d='.$gravatar_default;
$output = checkdnsrr(array_pop(explode("@",$_GET['email'])),"MX") ? $avatar_url : 'false';
$output = checkdnsrr(array_pop(explode("@",$_GET['email'])),"MX") ? GRAVATAR_CDN.md5($_GET['email']).'?d='.GRAVATAR_DEFAULT : 'false';
print_r($output);
30 changes: 12 additions & 18 deletions api/init.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
header('Content-type:text/json');
header('Access-Control-Allow-Origin: *');
require_once('config.php');
require_once( dirname(__FILE__) . '/emojione/autoload.php');
require_once('emojione/autoload.php');
$client = new Client(new Ruleset());
$client->imageType = 'png';
$client->imagePathPNG = $emoji_path;
$client->imagePathPNG = EMOJI_PATH;

$disqus_host = $gfw_inside ? $disqus_ip : 'disqus.com';
$disqus_host = GFW_INSIDE == 1 ? DISQUS_IP : 'disqus.com';
$media_host = GFW_INSIDE == 1 ? DISQUS_MEDIAIP : 'uploads.services.disqus.com';

//读取文件
$session_data = json_decode(file_get_contents(sys_get_temp_dir().'/session.json'));
Expand Down Expand Up @@ -36,18 +37,13 @@
$response = curl_exec($ch);

preg_match_all('/^Set-Cookie:\s*([^;]*)/mi', $response, $matches);
$cookies = array();
foreach($matches[1] as $item) {
parse_str($item, $cookie_temp);
$cookies = array_merge($cookies, $cookie_temp);
}
$token = str_replace("Set-Cookie: csrftoken=", "", $matches[0][0]);

// 登录并取得 session
$params = array(
'csrfmiddlewaretoken' => $token,
'username' => $email,
'password' => $password
'username' => DISQUS_EMAIL,
'password' => DISQUS_PASSWORD
);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_REFERER, 'https://disqus.com/profile/login/');
Expand All @@ -63,10 +59,8 @@

if( strpos($session, 'session') !== false ){
//写入文件
$output_date = date('Ymd');
$output_data = array('day' => $output_date, 'session' => $session);
$output_string = json_encode($output_data);
file_put_contents(sys_get_temp_dir().'/session.json', $output_string);
$output_data = array('day' => date('Ymd'), 'session' => $session);
file_put_contents(sys_get_temp_dir().'/session.json', json_encode($output_data));
}
}

Expand All @@ -91,10 +85,10 @@ function curl_get($url){
}

function curl_post($url, $data){
global $session, $disqus_host;
global $session, $disqus_host, $media_host;

$curl_url = strpos($url, 'https') !== false ? $url : 'https://'.$disqus_host.$url;
$curl_host = strpos($url, 'https') !== false ? 'uploads.services.disqus.com' : 'disqus.com';
$curl_url = strpos($url, 'media') !== false ? 'https://'.$media_host.$url : 'https://'.$disqus_host.$url;
$curl_host = strpos($url, 'media') !== false ? 'uploads.services.disqus.com' : 'disqus.com';

$options = array(
CURLOPT_URL => $curl_url,
Expand All @@ -119,7 +113,7 @@ function post_format( $post ){
global $client, $gravatar_cdn, $gravatar_default;

// 访客指定 Gravatar 头像
$avatar_url = $gravatar_cdn.md5($post->author->email).'?d='.$gravatar_default;
$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
48 changes: 24 additions & 24 deletions api/popular.php
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
<?php
namespace Emojione;
require_once('init.php');

$fields_data = array(
'api_key' => $public_key,
'limit' => 5,
'forum' => $forum,
'interval' => '30d'
);
$curl_url = '/api/3.0/threads/listPopular.json?'.http_build_query($fields_data);
$data = curl_get($curl_url);

foreach ( $data -> response as $key => $post ) {
$posts[$key] = array(
'link'=> $post->link,
'title'=> $post -> clean_title
);
}
$listposts = array(
'code' => $data -> code,
'response' => $posts
);
print_r(json_encode($listposts));
<?php
namespace Emojione;
require_once('init.php');

$fields_data = array(
'api_key' => DISQUS_PUBKEY,
'limit' => 5,
'forum' => DISQUS_SHORTNAME,
'interval' => '30d'
);
$curl_url = '/api/3.0/threads/listPopular.json?'.http_build_query($fields_data);
$data = curl_get($curl_url);

foreach ( $data -> response as $key => $post ) {
$posts[$key] = array(
'link'=> $post->link,
'title'=> $post -> clean_title
);
}
$listposts = array(
'code' => $data -> code,
'response' => $posts
);
print_r(json_encode($listposts));
4 changes: 2 additions & 2 deletions api/postcomment.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
$author_email = $_POST['email'];
$author_url = $_POST['url'] == '' || $_POST['url'] == 'null' ? null : $_POST['url'];

if( $author_name == $username && $author_email == $email && strpos($session, 'session') !== false ){
if( $author_name == DISQUS_NAME && $author_email == DISQUS_EMAIL && strpos($session, 'session') !== false ){
$author_name = null;
$author_email = null;
$author_url = null;
Expand All @@ -16,7 +16,7 @@
$post_message = $client->shortnameToUnicode($_POST['message']);

$post_data = array(
'api_key' => $public_key,
'api_key' => DISQUS_PUBKEY,
'thread' => $_POST['thread'],
'parent' => $_POST['parent'],
'message' => $post_message,
Expand Down
Loading

0 comments on commit af253d3

Please sign in to comment.