質問編集履歴
1
進展があったので報告します。できたら自己解決したいです。
test
CHANGED
File without changes
|
test
CHANGED
@@ -8,551 +8,7 @@
|
|
8
8
|
|
9
9
|
|
10
10
|
|
11
|
-
### プラグインの中身
|
12
11
|
|
13
|
-
|
14
|
-
|
15
|
-
```PHP
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
if (is_file(dirname(dirname(__FILE__)) . '/comment-image-extras.php')) {
|
20
|
-
|
21
|
-
@include(dirname(dirname(__FILE__)) . '/comment-image-extras.php');
|
22
|
-
|
23
|
-
}
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
add_action('admin_head', 'commentimage_admin_head');
|
28
|
-
|
29
|
-
function commentimage_admin_head()
|
30
|
-
|
31
|
-
{
|
32
|
-
|
33
|
-
if (strpos($_GET['page'], 'comment-image/') === 0) {
|
34
|
-
|
35
|
-
echo '<link type="text/css" rel="stylesheet" href="' .
|
36
|
-
|
37
|
-
get_option('siteurl') . '/wp-content/plugins/comment-image/admin.css"/>';
|
38
|
-
|
39
|
-
}
|
40
|
-
|
41
|
-
}
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
add_filter('comment_text', 'commentimage_comment_text');
|
46
|
-
|
47
|
-
function commentimage_comment_text($comment = '')
|
48
|
-
|
49
|
-
{
|
50
|
-
|
51
|
-
$options = get_option('commentimage');
|
52
|
-
|
53
|
-
$id = get_comment_ID();
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
$images = $options['images'];
|
58
|
-
|
59
|
-
if (!isset($images) || !is_numeric($images)) $images = 1;
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
$url = get_option('siteurl');
|
64
|
-
|
65
|
-
for ($i=0; $i<$images; $i++)
|
66
|
-
|
67
|
-
{
|
68
|
-
|
69
|
-
if (file_exists(ABSPATH . 'wp-content/comment-image/' . $id . ($i==0?'':('-'.$i)) . '-tn.jpg'))
|
70
|
-
|
71
|
-
{
|
72
|
-
|
73
|
-
$comment .= '<p><a href="' . $url . '/wp-content/comment-image/' . commentimage_find_original($id, $i) . '"><img src="' . $url . '/wp-content/comment-image/' . $id . ($i==0?'':('-'.$i)) . '-tn.jpg"/></a></p>';
|
74
|
-
|
75
|
-
}
|
76
|
-
|
77
|
-
}
|
78
|
-
|
79
|
-
return $comment;
|
80
|
-
|
81
|
-
}
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
add_action('comment_post', 'commentimage_comment_post');
|
88
|
-
|
89
|
-
function commentimage_comment_post($id)
|
90
|
-
|
91
|
-
{
|
92
|
-
|
93
|
-
$options = get_option('commentimage');
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
$images = $options['images'];
|
98
|
-
|
99
|
-
if (!isset($images) || !is_numeric($images)) $images = 1;
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
for ($i=0; $i<$images; $i++)
|
104
|
-
|
105
|
-
{
|
106
|
-
|
107
|
-
$field = 'image' . ($i==0?'':$i);
|
108
|
-
|
109
|
-
if ($_FILES[$field]['name'] != '')
|
110
|
-
|
111
|
-
{
|
112
|
-
|
113
|
-
$name = $id . ($i==0?'':('-'.$i));
|
114
|
-
|
115
|
-
$dest = ABSPATH . 'wp-content/comment-image/' . $name;
|
116
|
-
|
117
|
-
switch($_FILES[$field]['type'])
|
118
|
-
|
119
|
-
{
|
120
|
-
|
121
|
-
case 'image/jpeg':
|
122
|
-
|
123
|
-
case 'image/pjpeg':
|
124
|
-
|
125
|
-
$dest .= '.jpg';
|
126
|
-
|
127
|
-
break;
|
128
|
-
|
129
|
-
case 'image/png':
|
130
|
-
|
131
|
-
$dest .= '.png';
|
132
|
-
|
133
|
-
break;
|
134
|
-
|
135
|
-
case 'image/gif':
|
136
|
-
|
137
|
-
$dest .= '.gif';
|
138
|
-
|
139
|
-
break;
|
140
|
-
|
141
|
-
default:
|
142
|
-
|
143
|
-
// try with jpg if mime type doen's match
|
144
|
-
|
145
|
-
$dest .= '.jpg';
|
146
|
-
|
147
|
-
}
|
148
|
-
|
149
|
-
$thumb = ABSPATH . 'wp-content/comment-image/' . $name . '-tn.jpg';
|
150
|
-
|
151
|
-
move_uploaded_file($_FILES[$field]['tmp_name'], $dest);
|
152
|
-
|
153
|
-
$res = commentimage_thumb($dest, $thumb, (int)$options['width'], (int)$options['width'], $_FILES[$field]['type']);
|
154
|
-
|
155
|
-
if (!$res) @unlink($dest);
|
156
|
-
|
157
|
-
}
|
158
|
-
|
159
|
-
}
|
160
|
-
|
161
|
-
}
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
add_action('comment_form', 'commentimage_comment_form', 99);
|
168
|
-
|
169
|
-
function commentimage_comment_form()
|
170
|
-
|
171
|
-
{
|
172
|
-
|
173
|
-
//if (!is_single() && !is_page()) return;
|
174
|
-
|
175
|
-
if (!is_singular()) {
|
176
|
-
|
177
|
-
return;
|
178
|
-
|
179
|
-
}
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
$options = get_option('commentimage');
|
184
|
-
|
185
|
-
if ($options['field'] == 0)
|
186
|
-
|
187
|
-
{
|
188
|
-
|
189
|
-
$images = $options['images'];
|
190
|
-
|
191
|
-
if (!isset($images) || !is_numeric($images)) $images = 1;
|
192
|
-
|
193
|
-
for ($i=0; $i<$images; $i++)
|
194
|
-
|
195
|
-
{
|
196
|
-
|
197
|
-
echo '<p style="clear: both"><input style="width: auto" type="file" name="image' . ($i==0?'':$i) .
|
198
|
-
|
199
|
-
'"/> ' . htmlspecialchars($options['label']) . '</p>';
|
200
|
-
|
201
|
-
}
|
202
|
-
|
203
|
-
}
|
204
|
-
|
205
|
-
}
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
add_action('admin_menu', 'commentimage_admin_menu');
|
212
|
-
|
213
|
-
function commentimage_admin_menu()
|
214
|
-
|
215
|
-
{
|
216
|
-
|
217
|
-
add_options_page('Comment Image', 'Comment Image', 'manage_options', 'comment-image/options.php');
|
218
|
-
|
219
|
-
}
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
add_filter('delete_comment', 'commentimage_delete_comment');
|
224
|
-
|
225
|
-
function commentimage_delete_comment($id)
|
226
|
-
|
227
|
-
{
|
228
|
-
|
229
|
-
$options = get_option('commentimage');
|
230
|
-
|
231
|
-
$images = $options['images'];
|
232
|
-
|
233
|
-
if (!isset($images) || !is_numeric($images)) $images = 1;
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
for ($i=0; $i<20; $i++)
|
238
|
-
|
239
|
-
{
|
240
|
-
|
241
|
-
// If the thumbnail exists (it's always jpg)...
|
242
|
-
|
243
|
-
if (file_exists(ABSPATH . 'wp-content/comment-image/' . $id . ($i==0?'':('-'.$i)) . '-tn.jpg'))
|
244
|
-
|
245
|
-
{
|
246
|
-
|
247
|
-
@unlink(ABSPATH . 'wp-content/comment-image/' . $id . ($i==0?'':('-'.$i)) . '-tn.jpg');
|
248
|
-
|
249
|
-
@unlink(ABSPATH . 'wp-content/comment-image/' . commentimage_find_original($id, $i));
|
250
|
-
|
251
|
-
}
|
252
|
-
|
253
|
-
}
|
254
|
-
|
255
|
-
}
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
add_filter('comment_notification_text', 'commentimage_comment_notification_text', 10, 2);
|
260
|
-
|
261
|
-
add_filter('comment_moderation_text', 'commentimage_comment_notification_text', 10, 2);
|
262
|
-
|
263
|
-
function commentimage_comment_notification_text($message, $id)
|
264
|
-
|
265
|
-
{
|
266
|
-
|
267
|
-
$options = get_option('commentimage');
|
268
|
-
|
269
|
-
$url = get_option('siteurl');
|
270
|
-
|
271
|
-
$buffer = '';
|
272
|
-
|
273
|
-
for ($i=0; $i<20; $i++)
|
274
|
-
|
275
|
-
{
|
276
|
-
|
277
|
-
if (file_exists(ABSPATH . 'wp-content/comment-image/' . $id . ($i==0?'':('-'.$i)) . '-tn.jpg'))
|
278
|
-
|
279
|
-
{
|
280
|
-
|
281
|
-
$buffer .= "*** This comment has an image: " . $url . "/wp-content/comment-image/" . commentimage_find_original($id, $i) . "\r\n";
|
282
|
-
|
283
|
-
}
|
284
|
-
|
285
|
-
}
|
286
|
-
|
287
|
-
return $buffer . "\r\n" . $message;
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
}
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
add_action('wp_footer', 'commentimage_wp_footer');
|
296
|
-
|
297
|
-
function commentimage_wp_footer()
|
298
|
-
|
299
|
-
{
|
300
|
-
|
301
|
-
if (!is_single() && !is_page()) return;
|
302
|
-
|
303
|
-
$options = get_option('commentimage');
|
304
|
-
|
305
|
-
$images = $options['images'];
|
306
|
-
|
307
|
-
if (!isset($images) || !is_numeric($images)) $images = 1;
|
308
|
-
|
309
|
-
echo
|
310
|
-
|
311
|
-
'
|
312
|
-
|
313
|
-
<script type="text/javascript">
|
314
|
-
|
315
|
-
for (i=0; i<document.forms.length; i++) {
|
316
|
-
|
317
|
-
var f = document.forms[i];
|
318
|
-
|
319
|
-
if (f.comment_post_ID) {
|
320
|
-
|
321
|
-
f.encoding = "multipart/form-data";
|
322
|
-
|
323
|
-
';
|
324
|
-
|
325
|
-
if ($options['field'] == 1)
|
326
|
-
|
327
|
-
{
|
328
|
-
|
329
|
-
echo
|
330
|
-
|
331
|
-
'
|
332
|
-
|
333
|
-
var l = f.getElementsByTagName("textarea");
|
334
|
-
|
335
|
-
l = l[0].parentNode;
|
336
|
-
|
337
|
-
';
|
338
|
-
|
339
|
-
for ($i=$images-1; $i>=0; $i--)
|
340
|
-
|
341
|
-
{
|
342
|
-
|
343
|
-
echo '
|
344
|
-
|
345
|
-
var p = document.createElement("p");
|
346
|
-
|
347
|
-
var t = document.createElement("input");
|
348
|
-
|
349
|
-
t.setAttribute("name", "image' . ($i==0?'':$i) . '");
|
350
|
-
|
351
|
-
t.setAttribute("type", "file");
|
352
|
-
|
353
|
-
t.setAttribute("style", "width: auto");
|
354
|
-
|
355
|
-
p.appendChild(t);
|
356
|
-
|
357
|
-
p.appendChild(document.createTextNode("' . addslashes($options['label']) . '"));
|
358
|
-
|
359
|
-
l.parentNode.insertBefore(p, l.nextSibling);
|
360
|
-
|
361
|
-
';
|
362
|
-
|
363
|
-
}
|
364
|
-
|
365
|
-
}
|
366
|
-
|
367
|
-
echo
|
368
|
-
|
369
|
-
'
|
370
|
-
|
371
|
-
break;
|
372
|
-
|
373
|
-
}
|
374
|
-
|
375
|
-
}
|
376
|
-
|
377
|
-
</script>
|
378
|
-
|
379
|
-
';
|
380
|
-
|
381
|
-
}
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
function commentimage_thumb($file, $thumb, $new_w, $new_h, $type='image/jpeg')
|
386
|
-
|
387
|
-
{
|
388
|
-
|
389
|
-
switch ($type)
|
390
|
-
|
391
|
-
{
|
392
|
-
|
393
|
-
case 'image/jpeg':
|
394
|
-
|
395
|
-
case 'image/pjpeg':
|
396
|
-
|
397
|
-
$src_img = imagecreatefromjpeg($file);
|
398
|
-
|
399
|
-
break;
|
400
|
-
|
401
|
-
case 'image/gif':
|
402
|
-
|
403
|
-
$src_img = imagecreatefromgif($file);
|
404
|
-
|
405
|
-
break;
|
406
|
-
|
407
|
-
case 'image/png':
|
408
|
-
|
409
|
-
$src_img = imagecreatefrompng($file);
|
410
|
-
|
411
|
-
break;
|
412
|
-
|
413
|
-
// try with jpg for strange mime types
|
414
|
-
|
415
|
-
default:
|
416
|
-
|
417
|
-
$src_img = imagecreatefromjpeg($file);
|
418
|
-
|
419
|
-
}
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
//$src_img = imagecreatefromjpeg($file);
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
if ($src_img === false) return false;
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
$old_x = imagesx($src_img);
|
432
|
-
|
433
|
-
$old_y = imagesy($src_img);
|
434
|
-
|
435
|
-
if ($new_w == null)
|
436
|
-
|
437
|
-
{
|
438
|
-
|
439
|
-
$thumb_h = $new_h;
|
440
|
-
|
441
|
-
$thumb_w=$old_x*($new_h/$old_y);
|
442
|
-
|
443
|
-
}
|
444
|
-
|
445
|
-
else
|
446
|
-
|
447
|
-
{
|
448
|
-
|
449
|
-
if ($old_x > $old_y)
|
450
|
-
|
451
|
-
{
|
452
|
-
|
453
|
-
$thumb_w=$new_w;
|
454
|
-
|
455
|
-
$thumb_h=$old_y*($new_h/$old_x);
|
456
|
-
|
457
|
-
}
|
458
|
-
|
459
|
-
if ($old_x < $old_y)
|
460
|
-
|
461
|
-
{
|
462
|
-
|
463
|
-
$thumb_w=$old_x*($new_w/$old_y);
|
464
|
-
|
465
|
-
$thumb_h=$new_h;
|
466
|
-
|
467
|
-
}
|
468
|
-
|
469
|
-
if ($old_x == $old_y)
|
470
|
-
|
471
|
-
{
|
472
|
-
|
473
|
-
$thumb_w=$new_w;
|
474
|
-
|
475
|
-
$thumb_h=$new_h;
|
476
|
-
|
477
|
-
}
|
478
|
-
|
479
|
-
}
|
480
|
-
|
481
|
-
$dst_img = ImageCreateTrueColor($thumb_w,$thumb_h);
|
482
|
-
|
483
|
-
imagecopyresampled($dst_img,$src_img,0,0,0,0,$thumb_w,$thumb_h,$old_x,$old_y);
|
484
|
-
|
485
|
-
|
486
|
-
|
487
|
-
imagejpeg($dst_img, $thumb, 80);
|
488
|
-
|
489
|
-
imagedestroy($dst_img);
|
490
|
-
|
491
|
-
imagedestroy($src_img);
|
492
|
-
|
493
|
-
return true;
|
494
|
-
|
495
|
-
}
|
496
|
-
|
497
|
-
|
498
|
-
|
499
|
-
register_activation_hook(__FILE__, 'commentimage_activate');
|
500
|
-
|
501
|
-
function commentimage_activate()
|
502
|
-
|
503
|
-
{
|
504
|
-
|
505
|
-
@mkdir(ABSPATH . 'wp-content/comment-image');
|
506
|
-
|
507
|
-
|
508
|
-
|
509
|
-
@include(dirname(__FILE__) . '/languages/en_US_options.php');
|
510
|
-
|
511
|
-
if (WPLANG != '') @include(dirname(__FILE__) . '/languages/' . WPLANG . '_options.php');
|
512
|
-
|
513
|
-
|
514
|
-
|
515
|
-
$options = get_option('commentimage');
|
516
|
-
|
517
|
-
if (is_array($options))
|
518
|
-
|
519
|
-
{
|
520
|
-
|
521
|
-
$options = array_merge($default_options, $options);
|
522
|
-
|
523
|
-
update_option('commentimage', $options);
|
524
|
-
|
525
|
-
}
|
526
|
-
|
527
|
-
else
|
528
|
-
|
529
|
-
{
|
530
|
-
|
531
|
-
update_option('commentimage', $default_options);
|
532
|
-
|
533
|
-
}
|
534
|
-
|
535
|
-
}
|
536
|
-
|
537
|
-
|
538
|
-
|
539
|
-
function commentimage_find_original($id, $i)
|
540
|
-
|
541
|
-
{
|
542
|
-
|
543
|
-
$name = $id . ($i==0?'':('-'.$i));
|
544
|
-
|
545
|
-
if (is_file(ABSPATH . 'wp-content/comment-image/' . $name . '.jpg')) return $name . '.jpg';
|
546
|
-
|
547
|
-
if (is_file(ABSPATH . 'wp-content/comment-image/' . $name . '.gif')) return $name . '.gif';
|
548
|
-
|
549
|
-
if (is_file(ABSPATH . 'wp-content/comment-image/' . $name . '.png')) return $name . '.png';
|
550
|
-
|
551
|
-
}
|
552
|
-
|
553
|
-
?>
|
554
|
-
|
555
|
-
```
|
556
12
|
|
557
13
|
|
558
14
|
|
@@ -564,49 +20,7 @@
|
|
564
20
|
|
565
21
|
|
566
22
|
|
567
|
-
|
568
|
-
|
569
|
-
add_filter('comment_text', 'commentimage_comment_text');
|
570
|
-
|
571
|
-
function commentimage_comment_text($comment = '')
|
572
|
-
|
573
|
-
{
|
574
|
-
|
575
|
-
$options = get_option('commentimage');
|
576
|
-
|
577
|
-
$id = get_comment_ID();
|
578
|
-
|
579
|
-
|
580
|
-
|
581
|
-
$images = $options['images'];
|
582
|
-
|
583
|
-
if (!isset($images) || !is_numeric($images)) $images = 1;
|
584
|
-
|
585
|
-
|
586
|
-
|
587
|
-
$url = get_option('siteurl');
|
588
|
-
|
589
|
-
for ($i=0; $i<$images; $i++)
|
590
|
-
|
591
|
-
{
|
592
|
-
|
593
|
-
if (file_exists(ABSPATH . 'wp-content/comment-image/' . $id . ($i==0?'':('-'.$i)) . '-tn.jpg'))
|
594
|
-
|
595
|
-
{
|
596
|
-
|
597
|
-
$comment .= '<p><a href="' . $url . '/wp-content/comment-image/' . commentimage_find_original($id, $i) . '"><img src="' . $url . '/wp-content/comment-image/' . $id . ($i==0?'':('-'.$i)) . '-tn.jpg"/></a></p>';
|
598
|
-
|
599
|
-
}
|
600
|
-
|
601
|
-
}
|
602
|
-
|
603
|
-
return $comment;
|
604
|
-
|
605
|
-
}
|
606
|
-
|
607
|
-
```
|
608
|
-
|
609
|
-
この部分にadd_comment_metaで画像があるコメントにだけコメントメタを追加できれば一番よさそうなんですが、これはプラグインの中身ですので、functions.phpに書き込む方法で対処できないかな、と思っています。
|
23
|
+
add_comment_metaで画像があるコメントにだけコメントメタを追加できれば一番よさそうなんですが、これはプラグインの中身ですので、functions.phpに書き込む方法で対処できないかな、と思っています。
|
610
24
|
|
611
25
|
|
612
26
|
|
@@ -621,3 +35,57 @@
|
|
621
35
|
|
622
36
|
|
623
37
|
どうか、よろしくお願いいたします。
|
38
|
+
|
39
|
+
|
40
|
+
|
41
|
+
|
42
|
+
|
43
|
+
### 進展
|
44
|
+
|
45
|
+
|
46
|
+
|
47
|
+
https://accelboon.com/tn/wordpress%E3%81%AE%E3%82%B3%E3%83%A1%E3%83%B3%E3%83%88%E6%AC%84%E3%81%AB%E7%94%BB%E5%83%8F%E3%82%92%E5%85%A5%E3%82%8C%E3%81%A6%E3%82%82%E3%82%89%E3%81%88%E3%82%8B%E3%82%88%E3%81%86%E3%81%AB%E3%81%99/
|
48
|
+
|
49
|
+
|
50
|
+
|
51
|
+
これの
|
52
|
+
|
53
|
+
```PHP
|
54
|
+
|
55
|
+
<?php
|
56
|
+
|
57
|
+
$comments = get_comments(array('status' => 'approve' ,'number' => 5));
|
58
|
+
|
59
|
+
foreach($comments as $comment):
|
60
|
+
|
61
|
+
$post = get_post($comment->comment_post_ID);
|
62
|
+
|
63
|
+
$posturl = get_permalink( $comment->comment_post_ID );
|
64
|
+
|
65
|
+
|
66
|
+
|
67
|
+
$image_url = "";
|
68
|
+
|
69
|
+
if (file_exists(ABSPATH . 'wp-content/comment-image/' . $comment->comment_ID . '-tn.jpg')) {
|
70
|
+
|
71
|
+
$image_url = home_url() . '/wp-content/comment-image/' . $comment->comment_ID . '-tn.jpg';
|
72
|
+
|
73
|
+
}else{
|
74
|
+
|
75
|
+
$image_url = get_bloginfo('template_url') . '/images/noimage.png';
|
76
|
+
|
77
|
+
}
|
78
|
+
|
79
|
+
echo '<img scr="' . $image_url . '" alt="' . $post . '">';
|
80
|
+
|
81
|
+
endforeach;
|
82
|
+
|
83
|
+
?>
|
84
|
+
|
85
|
+
```
|
86
|
+
|
87
|
+
|
88
|
+
|
89
|
+
これをadd_comment_metaできればいけるかもしれないので、アクションフックと組み合わせてやってみます。
|
90
|
+
|
91
|
+
できたら自己解決したいです。
|