-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.php
151 lines (139 loc) · 6.44 KB
/
main.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
<?php
/*
Plugin Name: yuki-comment-form
Description: yuki-comment-form
Author: ふぁ
Version: 0.1
*/
class yuki_comment_form
{
function __construct()
{
if (!session_id()) session_start();
$this->time = (string)time();
$this->csrf_token = uniqid('', true);
$_SESSION["csrf_token_" . $this->time] = $this->csrf_token;
add_filter('comment_form_default_fields', array($this, 'comment_form_remove'), 999999, 2);
add_filter('comment_form_defaults', array($this, 'comment_form_change'), 999999, 2);
add_filter('pre_comment_approved', array($this, 'comment_form_notice'), 0, 2);
add_filter('wp_enqueue_scripts', array($this, 'custom_stylesheet'));
add_action('admin_menu', array($this, 'add_pages'));
}
function notify_message($message)
{
wp_nonce_field('shoptions');
$opt = get_option('showtext_options');
$show_text = isset($opt) ? $opt : null;
if (!isset($show_text["token"])) return;
$notifyToken = $show_text["token"];
$data = http_build_query(['message' => $message], '', '&');
$options = [
'http' => [
'method' => 'POST',
'header' => 'Authorization: Bearer ' . $notifyToken . "\r\n"
. "Content-Type: application/x-www-form-urlencoded\r\n"
. 'Content-Length: ' . strlen($data) . "\r\n",
'content' => $data,
]
];
$context = stream_context_create($options);
$resultJson = file_get_contents('https://notify-api.line.me/api/notify', false, $context);
$resultArray = json_decode($resultJson, true);
if ($resultArray['status'] != 200) {
return false;
}
return true;
}
function add_pages()
{
add_menu_page('yuki-comment-form', 'yuki-comment-form', 'level_8', __FILE__, array($this, 'show_text_option_page'), '', 26);
}
function comment_form_remove($arg)
{
if (isset($arg['url'])) $arg['url'] = '';
if (isset($arg['email'])) $arg['email'] = '';
if (isset($arg['author'])) $arg['author'] = '';
if (isset($arg['cookies'])) $arg['cookies'] = '';
return $arg;
}
function comment_form_change($defaults)
{
// $defaults['comment_notes_before'] = '<p class="comment-notes"><span id="email-notes">' . _('URLは使用禁止です。') . '</span></p>';
$defaults['title_reply_to'] = _('返信する');
$defaults['cancel_reply_link'] = _('返信をキャンセル');
$defaults['submit_field'] .= '<input type="hidden" name="csrf_token" value="' . $this->csrf_token . '">';
$defaults['submit_field'] .= '<input type="hidden" name="csrf_time" value="' . $this->time . '">';
$defaults['logged_in_as'] = '<p class="logged-in-as"><a href="" aria-label=" ' . _("プロフィールを編集") . '">' . _("ログイン中</a>のため現在コメント機能は使用できません。") . '<a href="https://fnjpnews.com/wp-login.php?action=logout&redirect_to=https%3A%2F%2Ffnjpnews.com%2FNews%2F7888&_wpnonce=2dca9fc999">' . _("ログアウトしますか?") . '</a></p>';
return $defaults;
}
function comment_form_notice($commentdata, $defaults)
{
$this->notify_message(_("ステータス") . ":" . $commentdata . "\n" . _("記事") . "url:" . home_url('/') . "?p=" . $defaults["comment_post_ID"] . "\nip" . _("アドレス") . ":" . $defaults["comment_author_IP"] . "\n" . _("コメント") . ":" . $defaults["comment_content"]);
if ($commentdata != 1) {
$this->notify_message(_("判定:スパム"));
$this->notify_message(_("他プラグインの判定"));
return "spam";
}
if ($_POST["csrf_token"] != $_SESSION["csrf_token_" . $_POST["csrf_time"]]) {
$this->notify_message(_("判定:スパム"));
$this->notify_message(_("csrfトークンエラー"));
return "spam";
}
if ($defaults["comment_author"] != null) {
$this->notify_message(_("判定:スパム"));
$this->notify_message(_("本来入力されていないはずのフォームが入力されている 該当id:comment_author"));
return "spam";
}
if ($defaults["comment_author_email"] != null) {
$this->notify_message(_("判定:スパム"));
$this->notify_message(_("本来入力されていないはずのフォームが入力されている 該当id:comment_author_email"));
return "spam";
}
if ($defaults["comment_author_url"] != null) {
$this->notify_message(_("判定:スパム"));
$this->notify_message(_("本来入力されていないはずのフォームが入力されている 該当id:comment_author_url"));
return "spam";
}
if ($defaults["user_ID"] != null) {
$this->notify_message(_("判定:スパム"));
$this->notify_message(_("本来入力されていないはずのフォームが入力されている 該当id:user_ID"));
return "spam";
}
$this->notify_message(_("判定:認証"));
}
function custom_stylesheet()
{
wp_enqueue_style(
'yuki_comment_form_custom_stylesheet',
plugins_url('custom-stylesheet.css', __FILE__)
);
}
function show_text_option_page()
{
wp_nonce_field('shoptions');
$opt = get_option('showtext_options');
$show_text = isset($opt) ? $opt : null;
if (isset($_POST['showtext_options'])) {
$opt = $_POST['showtext_options'];
update_option('showtext_options', $opt);
}
$opt = get_option('showtext_options');
$show_text = isset($opt) ? $opt : null;
?>
<h2>LineNotify<?php _e('設定') ?></h2>
<p>LineNotify<?php _e('に通知を送ります。送信する先の') ?>token<?php _e('を入力してください。') ?></p>
<p><?php _e('空白にするとオフにします') ?></p>
<form action="" method="post">
<input name="showtext_options[token]" type="text" id="inputtext" placeholder="token"
value="<?php echo $show_text["token"] ?>" />
<input type="submit" name="Submit" class="button-primary" value="<?php _e('変更を保存') ?>" />
</form>
<?php
if (isset($_POST['showtext_options'])) {
?>
<p><?php _e('保存しました'); ?></p>
<?php
}
}
}
$showtext = new yuki_comment_form;