-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplugin.php
311 lines (261 loc) · 12.5 KB
/
plugin.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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
<?php
class newIineButton extends Plugin {
public function init()
{
$this->dbFields = array(
'iineURL' => '',
'useUniqueButtonName' => true,
'countLimitNumber' => '10',
'buttonShape' => 'default',
'showIcon' => true,
'showCounts' => true,
'popupDirection' => 'up',
'thanksMessage' => 'ありがとうございます!',
'thanksMessage2' => '',
'thanksMessage3' => '',
'ThanksImageURL' => '',
'ThanksImageURL2' => '',
'ThanksImageURL3' => '',
'iconFontSource' => 'google',
'jQuerySource' => 'bludit'
);
}
public function form()
{
global $L;
$html .= '<h4 class="mt-3">基本設定</h3>';
$html .= '<div>';
$html .= '<label>いいねボタン・改のディレクトリ</label>';
$html .= '<input name="iineURL" class="form-control" type="url" pattern="http.*://.*" dir="auto" value="' . $this->getValue('iineURL') . '" placeholder="http://yourdomain/newiine_app">';
$html .= '<span class="tip">いいねボタン改をインストールしたディレクトリのURLを入力してください。CSSおよびJavaScriptのパスは自動で補完されます。</span>';
$html .= '</div>';
$html .= '<div>';
$html .= '<label>ページごとに個別のボタン名を使用する</label>';
$html .= '<select name="useUniqueButtonName">';
$html .= '<option value="true" ' . ($this->getValue('useUniqueButtonName') === true ? 'selected' : '') . '>有効</option>';
$html .= '<option value="false" ' . ($this->getValue('useUniqueButtonName') === false ? 'selected' : '') . '>無効</option>';
$html .= '</select>';
$html .= '<span class="tip">有効にすると、ページごとにボタン名としてページのスラッグを使用します。いいね数もページごとに集計されます。無効にすると、サイト内すべてのボタン名が「Bludit」になり、サイト全体で合計のいいね数が集計されます。</span>';
$html .= '</div>';
$html .= '<div>';
$html .= '<label>1日あたりのいいね上限回数</label>';
$html .= '<input name="countLimitNumber" class="form-control" type=number min="1" dir="auto" value="' . $this->getValue('countLimitNumber') . '">';
$html .= '<span class="tip">いいねボタン改の管理画面で設定した回数よりもこちらに入力した回数が優先して適用されます。</span>';
$html .= '</div>';
$html .= '<hr>';
$html .= '<h4 class="mt-3">ボタンの見た目</h3>';
$html .= '<div>';
$html .= '<label>ボタンの形状</label>';
$html .= '<select name="buttonShape">';
$html .= '<option value="default" ' . ($this->getValue('buttonShape') === 'default' ? 'selected' : '') . '>デフォルト</option>';
$html .= '<option value="rounded" ' . ($this->getValue('buttonShape') === 'rounded' ? 'selected' : '') . '>丸形</option>';
$html .= '</select>';
$html .= '</div>';
$html .= '<div>';
$html .= '<label>アイコンを表示</label>';
$html .= '<select name="showIcon">';
$html .= '<option value="true" ' . ($this->getValue('showIcon') === true ? 'selected' : '') . '>有効</option>';
$html .= '<option value="false" ' . ($this->getValue('showIcon') === false ? 'selected' : '') . '>無効</option>';
$html .= '</select>';
$html .= '</div>';
$html .= '<div>';
$html .= '<label>いいね数を表示</label>';
$html .= '<select name="showCounts">';
$html .= '<option value="true" ' . ($this->getValue('showCounts') === true ? 'selected' : '') . '>有効</option>';
$html .= '<option value="false" ' . ($this->getValue('showCounts') === false ? 'selected' : '') . '>無効</option>';
$html .= '</select>';
$html .= '</div>';
$html .= '<div>';
$html .= '<label>ポップアップの表示方向</label>';
$html .= '<select name="popupDirection">';
$html .= '<option value="up" ' . ($this->getValue('popupDirection') === 'up' ? 'selected' : '') . '>上</option>';
$html .= '<option value="down" ' . ($this->getValue('popupDirection') === 'down' ? 'selected' : '') . '>下</option>';
$html .= '</select>';
$html .= '</div>';
$html .= '<hr>';
$html .= '<h4 class="mt-3">お礼のメッセージ</h4>';
$html .= '<h5 class="mt-3">お礼のメッセージ1</h5>';
$html .= '<div>';
$html .= '<label>メッセージの内容</label>';
$html .= '<input name="thanksMessage" class="form-control" type="text" dir="auto" value="' . $this->getValue('thanksMessage') . '">';
$html .= '</div>';
$html .= '<div>';
$html .= '<label>メッセージの画像</label>';
$html .= '<input name="ThanksImageURL" class="form-control" type="url" pattern="http.*://.*" dir="auto" value="' . $this->getValue('ThanksImageURL') . '">';
$html .= '<span class="tip">お礼のメッセージに使用する画像のURLを入力します。空欄の場合、デフォルトの画像を使用します。</span>';
$html .= '</div>';
$html .= '<h5 class="mt-3">お礼のメッセージ2</h5>';
$html .= '<div>';
$html .= '<label>メッセージの内容</label>';
$html .= '<input name="thanksMessage2" class="form-control" type="text" dir="auto" value="' . $this->getValue('thanksMessage2') . '">';
$html .= '</div>';
$html .= '<span class="tip">メッセージの内容を複数設定すると、ランダムで選んだ内容が表示されます。</span>';
$html .= '<div>';
$html .= '<label>メッセージの画像</label>';
$html .= '<input name="ThanksImageURL2" class="form-control" type="url" pattern="http.*://.*" dir="auto" value="' . $this->getValue('ThanksImageURL2') . '">';
$html .= '<span class="tip">設定しない場合は「お礼のメッセージ1」で設定したURLを使用します。</span>';
$html .= '</div>';
$html .= '<h5 class="mt-3">お礼のメッセージ3</h5>';
$html .= '<div>';
$html .= '<label>メッセージの内容</label>';
$html .= '<input name="thanksMessage3" class="form-control" type="text" dir="auto" value="' . $this->getValue('thanksMessage3') . '">';
$html .= '</div>';
$html .= '<div>';
$html .= '<label>メッセージの画像</label>';
$html .= '<input name="ThanksImageURL3" class="form-control" type="url" pattern="http.*://.*" dir="auto" value="' . $this->getValue('ThanksImageURL3') . '">';
$html .= '<span class="tip">設定しない場合は「お礼のメッセージ1」で設定したURLを使用します。</span>';
$html .= '</div>';
$html .= '<hr>';
$html .= '<h4 class="mt-3">高度な設定</h4>';
$html .= '<div>';
$html .= '<label>Material Iconsアイコンフォントの取得元</label>';
$html .= '<select name="iconFontSource">';
$html .= '<option value="google" ' . ($this->getValue('iconFontSource') === 'google' ? 'selected' : '') . '>Google Fonts</option>';
$html .= '<option value="jsdelivr" ' . ($this->getValue('iconFontSource') === 'jsdelivr' ? 'selected' : '') . '>jsDelivr</option>';
'>Google Fonts</option>';
$html .= '<option value="none" ' . ($this->getValue('iconFontSource') === 'none' ? 'selected' : '') . '>読み込まない(テーマで読み込み済み)</option>';
$html .= '</select>';
$html .= '</div>';
$html .= '<div>';
$html .= '<label>jQueryの取得元</label>';
$html .= '<select name="jQuerySource">';
$html .= '<option value="googleapis" ' . ($this->getValue('jQuerySource') === 'googleapis' ? 'selected' : '') . '>Google</option>';
$html .= '<option value="jquerycom" ' . ($this->getValue('jQuerySource') === 'jquerycom' ? 'selected' : '') . '>jQuery.com</option>';
$html .= '<option value="bludit" ' . ($this->getValue('jQuerySource') === 'bludit' ? 'selected' : '') . '>Bludit内蔵</option>';
'>Google Fonts</option>';
$html .= '<option value="none" ' . ($this->getValue('jQuerySource') === 'none' ? 'selected' : '') . '>読み込まない(テーマで読み込み済み)</option>';
$html .= '</select>';
$html .= '</div>';
return $html;
}
public function siteHead()
{
global $page;
if ($this->getValue('showIcon') && $this->getValue('iconFontSource') == 'google') {
$iconFontSource = '<link href="https://fonts.googleapis.com/icon?family=Material+Icons|Material+Icons+Round" rel="stylesheet">'.PHP_EOL;
} elseif ($this->getValue('showIcon') && $this->getValue('iconFontSource') == 'jsdelivr') {
$iconFontSource = '<link href="https://cdn.jsdelivr.net/npm/material-icons@1.13.12/iconfont/material-icons.min.css" rel="stylesheet">'.PHP_EOL;
}
// フォントとボタン用のCSSを読み込み
return $iconFontSource .
'<link rel="stylesheet" href="' .($this->getValue('iineURL')). '/newiine.css">'.PHP_EOL;
}
public function pageEnd()
{
global $url;
global $WHERE_AM_I;
// page not foundのときにボタンを表示しない
if ($url->notFound()) {
return false;
}
// ページのときだけボタンを表示
if ($WHERE_AM_I === 'page' OR 'home') {
global $page;
return $this->buttonContent();
}
return false;
}
private function buttonContent()
{
global $page;
// ボタン名の設定
$buttonName = '';
if ($this->getValue('useUniqueButtonName')) {
$buttonName = $page->slug();
} else {
$buttonName = 'Bludit';
}
// いいねの回数制限
$countLimitNumber = $this->getValue('countLimitNumber');
// 「丸型のボタンを使用する(buttonShape)」が有効のとき、クラス「(スペース)newiine_type02」を追加
if ($this->getValue('buttonShape') == 'rounded') {
$isRounded = ' newiine_type02';
}
// 「アイコンを表示(showIcon)」が有効のとき、アイコンの表示を追加
if ($this->getValue('showIcon')) {
$showIcon = '<span class="material-icons-round">favorite</span>';
}
// 「いいね数を表示(showCounts)」が有効のとき、カウントの表示を追加
if ($this->getValue('showCounts')) {
$showCounts = '<span class="newiine_count"></span>';
}
// ポップアップの方向
if ($this->getValue('popupDirection') == 'up') {
$popupDirection = 'newiine_thanks_up';
} elseif ($this->getValue('popupDirection') == 'down') {
$popupDirection = 'newiine_thanks_down';
}
// お礼メッセージの内容
$thanksMessage = $this->getValue('thanksMessage');
// お礼メッセージの画像の取得元
if ($this->getValue('ThanksImageURL')) {
$thanksImageURL = $this->getValue('ThanksImageURL');
} else {
$thanksImageURL = $this->getValue('iineURL') . "/example.jpg";
}
if ($this->getValue('ThanksImageURL2')) {
$thanksImageURL2 = $this->getValue('ThanksImageURL2');
} else {
$thanksImageURL2 = $thanksImageURL;
}
if ($this->getValue('ThanksImageURL3')) {
$thanksImageURL3 = $this->getValue('ThanksImageURL3');
} else {
$thanksImageURL3 = $thanksImageURL;
}
if ($this->getValue('thanksMessage2')) {
$thanksMessage2 =
'<div class="newiine_box">
<img src="' . $thanksImageURL2 . '" alt="THANK YOU!">
<p>' .$this->getValue('thanksMessage2'). '</p>
</div>';
}
if ($this->getValue('thanksMessage3')) {
$thanksMessage3 =
'<div class="newiine_box">
<img src="' . $thanksImageURL . '" alt="THANK YOU!">
<p>' .$this->getValue('thanksMessage3'). '</p>
</div>';
}
// ページに出力するボタンのコード
$code = <<<EOF
<!-- いいねボタン改ここから -->
<button type="submit" class="newiine_btn$isRounded" data-iinename="$buttonName" data-iinecountlimit="$countLimitNumber">
$showIcon
$showCounts
<span>いいね</span>
<!-- お礼メッセージここから -->
<div class="newiine_thanks $popupDirection" style="display:none;">
<div class="newiine_box">
<img src="$thanksImageURL" alt="THANK YOU!">
<p>$thanksMessage</p>
</div>
$thanksMessage2
$thanksMessage3
</div>
<!-- お礼メッセージここまで -->
</button>
<!-- いいねボタン改ここまで -->
EOF;
return $code;
}
public function siteBodyEnd()
{
global $page;
if ($this->getValue('jQuerySource') == 'googleapis') {
$jQuerySource = '<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>'.PHP_EOL;
} elseif ($this->getValue('jQuerySource') == 'jquerycom') {
$jQuerySource = '<script src="https://code.jquery.com/jquery-3.6.0.min.js" integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4=" crossorigin="anonymous"></script>'.PHP_EOL;
} elseif ($this->getValue('jQuerySource') == 'bludit') {
$jQuerySource = Theme::jquery();
}
//いいねボタン・改のディレクトリを指定
$iineURL = $this->getValue('iineURL');
// jQueryとスクリプトを読み込み
$script = <<<EOF
$jQuerySource
<script src="$iineURL/newiine.js"></script>
EOF;
return $script;
}
}