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
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
|
<?php /** * Plugin Name: Antispam Bee * Description: Antispam plugin with a sophisticated toolset for effective day to day comment and trackback spam-fighting. Built with data protection and privacy in mind. * Author: pluginkollektiv * Author URI: https://pluginkollektiv.org * Plugin URI: https://antispambee.pluginkollektiv.org/ * Text Domain: antispam-bee * Domain Path: /lang * License: GPLv2 or later * License URI: http://www.gnu.org/licenses/gpl-2.0.html * Version: 2.9.3 * * [](http://coderisk.com/wp/plugin/antispam-bee/RIPS-lAHLcgvqY8) * * @package Antispam Bee **/
/* * Copyright (C) 2009-2015 Sergej Müller * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */
// Make sure this file is only run from within the WordPress context. defined( 'ABSPATH' ) || exit;
/** * Antispam_Bee * * @since 0.1 * @change 2.4 */ class Antispam_Bee {
/** * The option defaults. * * @var array */ public static $defaults;
/** * Which internal datastructure version we are running on. * * @var int */ private static $db_version = 1.01;
/** * The base. * * @var string */ private static $_base;
/** * The salt. * * @var string */ private static $_salt;
/** * The spam reason. * * @var string */ private static $_reason;
/** * The current Post ID. * * @var int */ private static $_current_post_id;
/** * "Constructor" of the class * * @since 0.1 * @change 2.6.4 */ public static function init() { add_action( 'unspam_comment', array( __CLASS__, 'delete_spam_reason_by_comment', ) );
add_action( 'comment_unapproved_to_spam', array( __CLASS__, 'update_antispam_bee_reason', ) );
add_action( 'comment_approved_to_spam', array( __CLASS__, 'update_antispam_bee_reason', ) );
if ( ( defined( 'DOING_AJAX' ) && DOING_AJAX ) || ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) ) { return; }
self::_init_internal_vars();
if ( defined( 'DOING_CRON' ) ) { add_action( 'antispam_bee_daily_cronjob', array( __CLASS__, 'start_daily_cronjob', ) );
} elseif ( is_admin() ) { add_action( 'admin_menu', array( __CLASS__, 'add_sidebar_menu', ) );
if ( self::_current_page( 'dashboard' ) ) { add_action( 'init', array( __CLASS__, 'load_plugin_lang', ) ); add_filter( 'dashboard_glance_items', array( __CLASS__, 'add_dashboard_count', ) ); add_action( 'wp_dashboard_setup', array( __CLASS__, 'add_dashboard_chart', ) );
} elseif ( self::_current_page( 'plugins' ) ) { add_action( 'init', array( __CLASS__, 'load_plugin_lang', ) ); add_filter( 'plugin_row_meta', array( __CLASS__, 'init_row_meta', ), 10, 2 ); add_filter( 'plugin_action_links_' . self::$_base, array( __CLASS__, 'init_action_links', ) );
} elseif ( self::_current_page( 'options' ) ) { add_action( 'admin_init', array( __CLASS__, 'load_plugin_lang', ) ); add_action( 'admin_init', array( __CLASS__, 'init_plugin_sources', ) ); add_action( 'admin_init', array( __CLASS__, 'update_database', ) );
} elseif ( self::_current_page( 'admin-post' ) ) { require_once dirname( __FILE__ ) . '/inc/gui.class.php';
add_action( 'admin_post_ab_save_changes', array( 'Antispam_Bee_GUI', 'save_changes', ) );
} elseif ( self::_current_page( 'edit-comments' ) ) { // phpcs:disable WordPress.CSRF.NonceVerification.NoNonceVerification if ( ! empty( $_GET['comment_status'] ) && 'spam' === $_GET['comment_status'] && ! self::get_option( 'no_notice' ) ) { // phpcs:enable WordPress.CSRF.NonceVerification.NoNonceVerification require_once dirname( __FILE__ ) . '/inc/columns.class.php';
self::load_plugin_lang();
add_filter( 'manage_edit-comments_columns', array( 'Antispam_Bee_Columns', 'register_plugin_columns', ) ); add_filter( 'manage_comments_custom_column', array( 'Antispam_Bee_Columns', 'print_plugin_column', ), 10, 2 ); add_filter( 'admin_print_styles-edit-comments.php', array( 'Antispam_Bee_Columns', 'print_column_styles', ) );
add_filter( 'manage_edit-comments_sortable_columns', array( 'Antispam_Bee_Columns', 'register_sortable_columns', ) ); add_action( 'pre_get_comments', array( 'Antispam_Bee_Columns', 'set_orderby_query', ) ); add_action( 'restrict_manage_comments', array( 'Antispam_Bee_Columns', 'filter_columns', ) ); add_action( 'pre_get_comments', array( 'Antispam_Bee_Columns', 'filter_by_spam_reason', ) ); } } } else { add_action( 'wp', array( __CLASS__, 'populate_post_id', ) );
add_action( 'template_redirect', array( __CLASS__, 'prepare_comment_field', ) ); add_action( 'init', array( __CLASS__, 'precheck_incoming_request', ) ); add_action( 'preprocess_comment', array( __CLASS__, 'handle_incoming_request', ), 1 ); add_action( 'antispam_bee_count', array( __CLASS__, 'the_spam_count', ) ); } }
/* * ############################ * ######## INSTALL ######### * ############################ */
/** * Action during the activation of the Plugins * * @since 0.1 * @change 2.4 */ public static function activate() { add_option( 'antispam_bee', array(), '', 'no' );
if ( self::get_option( 'cronjob_enable' ) ) { self::init_scheduled_hook(); } }
/** * Action to deactivate the plugin * * @since 0.1 * @change 2.4 */ public static function deactivate() { self::clear_scheduled_hook(); }
/** * Action deleting the plugin * * @since 2.4 * @change 2.4 */ public static function uninstall() { if ( ! self::get_option( 'delete_data_on_uninstall' ) ) { return; } global $wpdb;
delete_option( 'antispam_bee' ); $wpdb->query( 'OPTIMIZE TABLE `' . $wpdb->options . '`' );
//phpcs:disable WordPress.WP.PreparedSQL.NotPrepared $sql = 'delete from `' . $wpdb->commentmeta . '` where `meta_key` IN ("antispam_bee_iphash", "antispam_bee_reason")'; $wpdb->query( $sql ); //phpcs:enable WordPress.WP.PreparedSQL.NotPrepared }
/* * ############################ * ######## INTERNAL ######## * ############################ */
/** * Initialization of the internal variables * * @since 2.4 * @change 2.7.0 */ private static function _init_internal_vars() { self::$_base = plugin_basename( __FILE__ );
$salt = defined( 'NONCE_SALT' ) ? NONCE_SALT : ABSPATH; self::$_salt = substr( sha1( $salt ), 0, 10 );
self::$defaults = array( 'options' => array( 'regexp_check' => 1, 'spam_ip' => 1, 'already_commented' => 1, 'gravatar_check' => 0, 'time_check' => 0, 'ignore_pings' => 0, 'always_allowed' => 0,
'dashboard_chart' => 0, 'dashboard_count' => 0,
'country_code' => 0, 'country_black' => '', 'country_white' => '',
'translate_api' => 0, 'translate_lang' => array(),
'bbcode_check' => 1,
'flag_spam' => 1, 'email_notify' => 0, 'no_notice' => 0, 'cronjob_enable' => 0, 'cronjob_interval' => 0,
'ignore_filter' => 0, 'ignore_type' => 0,
'reasons_enable' => 0, 'ignore_reasons' => array(),
'delete_data_on_uninstall' => 1, ), 'reasons' => array( 'css' => esc_attr__( 'Honeypot', 'antispam-bee' ), 'time' => esc_attr__( 'Comment time', 'antispam-bee' ), 'empty' => esc_attr__( 'Empty Data', 'antispam-bee' ), 'localdb' => esc_attr__( 'Local DB Spam', 'antispam-bee' ), 'server' => esc_attr__( 'Fake IP', 'antispam-bee' ), 'country' => esc_attr__( 'Country Check', 'antispam-bee' ), 'bbcode' => esc_attr__( 'BBCode', 'antispam-bee' ), 'lang' => esc_attr__( 'Comment Language', 'antispam-bee' ), 'regexp' => esc_attr__( 'Regular Expression', 'antispam-bee' ), 'title_is_name' => esc_attr__( 'Identical Post title and blog title', 'antispam-bee' ), 'manually' => esc_attr__( 'Manually', 'antispam-bee' ), ), ); }
/** * Check and return an array key * * @since 2.4.2 * @change 2.4.2 * * @param array $array Array with values. * @param string $key Name of the key. * @return mixed Value of the requested key. */ public static function get_key( $array, $key ) { if ( empty( $array ) || empty( $key ) || empty( $array[ $key ] ) ) { return null; }
return $array[ $key ]; }
/** * Localization of the admin pages * * @since 0.1 * @change 2.4 * * @param string $page Mark the page. * @return boolean True on success. */ private static function _current_page( $page ) { // phpcs:disable WordPress.CSRF.NonceVerification.NoNonceVerification switch ( $page ) { case 'dashboard': return ( empty( $GLOBALS['pagenow'] ) || ( ! empty( $GLOBALS['pagenow'] ) && 'index.php' === $GLOBALS['pagenow'] ) );
case 'options': return ( ! empty( $_GET['page'] ) && 'antispam_bee' === $_GET['page'] );
case 'plugins': return ( ! empty( $GLOBALS['pagenow'] ) && 'plugins.php' === $GLOBALS['pagenow'] );
case 'admin-post': return ( ! empty( $GLOBALS['pagenow'] ) && 'admin-post.php' === $GLOBALS['pagenow'] );
case 'edit-comments': return ( ! empty( $GLOBALS['pagenow'] ) && 'edit-comments.php' === $GLOBALS['pagenow'] );
default: return false; } // phpcs:enable WordPress.CSRF.NonceVerification.NoNonceVerification }
/** * Integration of the localization file * * @since 0.1 * @change 2.4 */ public static function load_plugin_lang() { load_plugin_textdomain( 'antispam-bee' ); }
/** * Add the link to the settings * * @since 1.1 * @change 1.1 * * @param array $data The action link array. * @return array $data The action link array. */ public static function init_action_links( $data ) { if ( ! current_user_can( 'manage_options' ) ) { return $data; }
return array_merge( $data, array( sprintf( '<a href="%s">%s</a>', add_query_arg( array( 'page' => 'antispam_bee', ), admin_url( 'options-general.php' ) ), esc_attr__( 'Settings', 'antispam-bee' ) ), ) ); }
/** * Meta links of the plugin * * @since 0.1 * @change 2.6.2 * * @param array $input Existing links. * @param string $file Current page. * @return array $data Modified links. */ public static function init_row_meta( $input, $file ) { if ( $file !== self::$_base ) { return $input; }
return array_merge( $input, array( '<a href="https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=TD4AMD2D8EMZW" target="_blank" rel="noopener noreferrer">' . esc_html__( 'Donate', 'antispam-bee' ) . '</a>', '<a href="https://wordpress.org/support/plugin/antispam-bee" target="_blank" rel="noopener noreferrer">' . esc_html__( 'Support', 'antispam-bee' ) . '</a>', ) ); }
/* * ############################ * ####### RESOURCES ######## * ############################ */
/** * Registration of resources (CSS & JS) * * @since 1.6 * @change 2.4.5 */ public static function init_plugin_sources() { $plugin = get_plugin_data( __FILE__ );
wp_register_script( 'ab_script', plugins_url( 'js/scripts.min.js', __FILE__ ), array( 'jquery' ), $plugin['Version'] );
wp_register_style( 'ab_style', plugins_url( 'css/styles.min.css', __FILE__ ), array( 'dashicons' ), $plugin['Version'] ); }
/** * Initialization of the option page * * @since 0.1 * @change 2.4.3 */ public static function add_sidebar_menu() { $page = add_options_page( 'Antispam Bee', 'Antispam Bee', 'manage_options', 'antispam_bee', array( 'Antispam_Bee_GUI', 'options_page', ) );
add_action( 'admin_print_scripts-' . $page, array( __CLASS__, 'add_options_script', ) );
add_action( 'admin_print_styles-' . $page, array( __CLASS__, 'add_options_style', ) );
add_action( 'load-' . $page, array( __CLASS__, 'init_options_page', ) ); }
/** * Initialization of JavaScript * * @since 1.6 * @change 2.4 */ public static function add_options_script() { wp_enqueue_script( 'ab_script' ); }
/** * Initialization of Stylesheets * * @since 1.6 * @change 2.4 */ public static function add_options_style() { wp_enqueue_style( 'ab_style' ); }
/** * Integration of the GUI * * @since 2.4 * @change 2.4 */ public static function init_options_page() { require_once dirname( __FILE__ ) . '/inc/gui.class.php'; }
/* * ############################ * ####### DASHBOARD ######## * ############################ */
/** * Display the spam counter on the dashboard * * @since 0.1 * @change 2.6.5 * * @param array $items Initial array with dashboard items. * @return array $items Merged array with dashboard items. */ public static function add_dashboard_count( $items = array() ) { if ( ! current_user_can( 'manage_options' ) || ! self::get_option( 'dashboard_count' ) ) { return $items; }
echo '<style>#dashboard_right_now .ab-count:before {content: "\f117"}</style>';
$items[] = '<span class="ab-count">' . esc_html( sprintf( // translators: The number of spam comments Antispam Bee blocked so far. __( '%s Blocked', 'antispam-bee' ), self::_get_spam_count() ) ) . '</span>';
return $items; }
/** * Initialize the dashboard chart * * @since 1.9 * @change 2.5.6 */ public static function add_dashboard_chart() { if ( ! current_user_can( 'publish_posts' ) || ! self::get_option( 'dashboard_chart' ) ) { return; }
wp_add_dashboard_widget( 'ab_widget', 'Antispam Bee', array( __CLASS__, 'show_spam_chart', ) );
add_action( 'admin_head', array( __CLASS__, 'add_dashboard_style', ) ); }
/** * Print dashboard styles * * @since 1.9.0 * @change 2.5.8 */ public static function add_dashboard_style() { $plugin = get_plugin_data( __FILE__ );
wp_register_style( 'ab_chart', plugins_url( 'css/dashboard.min.css', __FILE__ ), array(), $plugin['Version'] );
wp_print_styles( 'ab_chart' ); }
/** * Print dashboard scripts * * @since 1.9.0 * @change 2.5.8 */ public static function add_dashboard_script() { if ( ! self::get_option( 'daily_stats' ) ) { return; }
$plugin = get_plugin_data( __FILE__ );
wp_enqueue_script( 'raphael', plugins_url( 'js/raphael.min.js', __FILE__ ), array(), '2.1.0', true );
wp_enqueue_script( 'ab-raphael', plugins_url( 'js/raphael.helper.min.js', __FILE__ ), array( 'raphael' ), $plugin['Version'], true );
wp_enqueue_script( 'ab_chart_js', plugins_url( 'js/dashboard.min.js', __FILE__ ), array( 'jquery', 'ab-raphael' ), $plugin['Version'], true ); }
/** * Print dashboard html * * @since 1.9.0 * @change 2.5.8 */ public static function show_spam_chart() { $items = (array) self::get_option( 'daily_stats' );
if ( empty( $items ) ) { echo sprintf( '<div id="ab_chart"><p>%s</p></div>', esc_html__( 'No data available.', 'antispam-bee' ) );
return; }
self::add_dashboard_script();
ksort( $items, SORT_NUMERIC );
$html = "<table id=ab_chart_data>\n";
$html .= "<tfoot><tr>\n"; foreach ( $items as $date => $count ) { $html .= '<th>' . date_i18n( 'j. F Y', $date ) . "</th>\n"; } $html .= "</tr></tfoot>\n";
$html .= "<tbody><tr>\n"; foreach ( $items as $date => $count ) { $html .= '<td>' . (int) $count . "</td>\n"; } $html .= "</tr></tbody>\n";
$html .= "</table>\n";
echo wp_kses_post( '<div id="ab_chart">' . $html . '</div>' ); }
/* * ############################ * ######## OPTIONS ######### * ############################ */
/** * Get all plugin options * * @since 2.4 * @change 2.6.1 * * @return array $options Array with option fields. */ public static function get_options() { $options = wp_cache_get( 'antispam_bee' ); if ( ! $options ) { wp_cache_set( 'antispam_bee', $options = get_option( 'antispam_bee' ) ); }
if ( null === self::$defaults ) { self::_init_internal_vars(); }
return wp_parse_args( $options, self::$defaults['options'] ); }
/** * Get single option field * * @since 0.1 * @change 2.4.2 * * @param string $field Field name. * @return mixed Field value. */ public static function get_option( $field ) { $options = self::get_options();
return self::get_key( $options, $field ); }
/** * Update single option field * * @since 0.1 * @change 2.4 * * @param string $field Field name. * @param mixed $value The Field value. */ private static function _update_option( $field, $value ) { self::update_options( array( $field => $value, ) ); }
/** * Update multiple option fields * * @since 0.1 * @change 2.6.1 * * @param array $data Array with plugin option fields. */ public static function update_options( $data ) { $options = get_option( 'antispam_bee' );
if ( is_array( $options ) ) { $options = array_merge( $options, $data ); } else { $options = $data; }
update_option( 'antispam_bee', $options );
wp_cache_set( 'antispam_bee', $options ); }
/* * ############################ * ######## CRONJOBS ######## * ############################ */
/** * Execution of the daily cronjobs * * @since 0.1 * @change 2.4 */ public static function start_daily_cronjob() { if ( ! self::get_option( 'cronjob_enable' ) ) { return; }
self::_update_option( 'cronjob_timestamp', time() );
self::_delete_old_spam(); }
/** * Delete old spam comments * * @since 0.1 * @change 2.4 */ private static function _delete_old_spam() { $days = (int) self::get_option( 'cronjob_interval' );
if ( empty( $days ) ) { return false; }
global $wpdb;
$wpdb->query( $wpdb->prepare( "DELETE c, cm FROM `$wpdb->comments` AS c LEFT JOIN `$wpdb->commentmeta` AS cm ON (c.comment_ID = cm.comment_id) WHERE c.comment_approved = 'spam' AND SUBDATE(NOW(), %d) > c.comment_date_gmt", $days ) );
$wpdb->query( "OPTIMIZE TABLE `$wpdb->comments`" ); }
/** * Initialization of the cronjobs * * @since 0.1 * @change 2.4 */ public static function init_scheduled_hook() { if ( ! wp_next_scheduled( 'antispam_bee_daily_cronjob' ) ) { wp_schedule_event( time(), 'daily', 'antispam_bee_daily_cronjob' ); } }
/** * Deletion of the cronjobs * * @since 0.1 * @change 2.4 */ public static function clear_scheduled_hook() { if ( wp_next_scheduled( 'antispam_bee_daily_cronjob' ) ) { wp_clear_scheduled_hook( 'antispam_bee_daily_cronjob' ); } }
/* * ############################ * ###### SPAM CHECK ######## * ############################ */
/** * Check POST values * * @since 0.1 * @change 2.6.3 */ public static function precheck_incoming_request() { // phpcs:disable WordPress.CSRF.NonceVerification.NoNonceVerification if ( is_feed() || is_trackback() || empty( $_POST ) || self::_is_mobile() ) { return; }
$request_uri = self::get_key( $_SERVER, 'REQUEST_URI' ); $request_path = self::parse_url( $request_uri, 'path' );
if ( strpos( $request_path, 'wp-comments-post.php' ) === false ) { return; }
$post_id = (int) self::get_key( $_POST, 'comment_post_ID' ); $hidden_field = self::get_key( $_POST, 'comment' ); $plugin_field = self::get_key( $_POST, self::get_secret_name_for_post( $post_id ) );
if ( empty( $hidden_field ) && ! empty( $plugin_field ) ) { $_POST['comment'] = $plugin_field; unset( $_POST[ self::get_secret_name_for_post( $post_id ) ] ); } else { $_POST['ab_spam__hidden_field'] = 1; } // phpcs:enable WordPress.CSRF.NonceVerification.NoNonceVerification }
/** * Check incoming requests for spam * * @since 0.1 * @change 2.6.3 * * @param array $comment Untreated comment. * @return array $comment Treated comment. */ public static function handle_incoming_request( $comment ) { $comment['comment_author_IP'] = self::get_client_ip();
$request_uri = self::get_key( $_SERVER, 'REQUEST_URI' ); $request_path = self::parse_url( $request_uri, 'path' );
if ( empty( $request_path ) ) { return self::_handle_spam_request( $comment, 'empty' ); }
$ping = array( 'types' => array( 'pingback', 'trackback', 'pings' ), 'allowed' => ! self::get_option( 'ignore_pings' ), );
// phpcs:disable WordPress.CSRF.NonceVerification.NoNonceVerification // Everybody can post. if ( strpos( $request_path, 'wp-comments-post.php' ) !== false && ! empty( $_POST ) ) { // phpcs:enable WordPress.CSRF.NonceVerification.NoNonceVerification $status = self::_verify_comment_request( $comment );
if ( ! empty( $status['reason'] ) ) { return self::_handle_spam_request( $comment, $status['reason'] ); } } elseif ( in_array( self::get_key( $comment, 'comment_type' ), $ping['types'], true ) && $ping['allowed'] ) { $status = self::_verify_trackback_request( $comment );
if ( ! empty( $status['reason'] ) ) { return self::_handle_spam_request( $comment, $status['reason'], true ); } }
return $comment; }
/** * Prepares the replacement of the comment field * * @since 0.1 * @change 2.4 */ public static function prepare_comment_field() { if ( is_feed() || is_trackback() || is_robots() || self::_is_mobile() ) { return; }
if ( ! is_singular() && ! self::get_option( 'always_allowed' ) ) { return; }
ob_start( array( 'Antispam_Bee', 'replace_comment_field', ) ); }
/** * Replaces the comment field * * @since 2.4 * @change 2.6.4 * * @param string $data HTML code of the website. * @return string Treated HTML code. */ public static function replace_comment_field( $data ) { if ( empty( $data ) ) { return; }
if ( ! preg_match( '#<textarea.+?name=["\']comment["\']#s', $data ) ) { return $data; }
return preg_replace_callback( '/(?P<all> (?# match the whole textarea tag ) <textarea (?# the opening of the textarea and some optional attributes ) ( (?# match a id attribute followed by some optional ones and the name attribute ) (?P<before1>[^>]*) (?P<id1>id=["\'](?P<id_value1>[^>"\']*)["\']) (?P<between1>[^>]*) name=["\']comment["\'] | (?# match same as before, but with the name attribute before the id attribute ) (?P<before2>[^>]*) name=["\']comment["\'] (?P<between2>[^>]*) (?P<id2>id=["\'](?P<id_value2>[^>"\']*)["\']) | (?# match same as before, but with no id attribute ) (?P<before3>[^>]*) name=["\']comment["\'] (?P<between3>[^>]*) ) (?P<after>[^>]*) (?# match any additional optional attributes ) > (?# the closing of the textarea opening tag ) (?s)(?P<content>.*?) (?# any textarea content ) <\/textarea> (?# the closing textarea tag ) )/x', array( 'Antispam_Bee', 'replace_comment_field_callback' ), $data, -1 ); }
/** * The callback function for the preg_match_callback to modify the textarea tags. * * @since 2.6.10 * * @param array $matches The regex matches. * * @return string The modified content string. */ public static function replace_comment_field_callback( $matches ) { if ( self::get_option( 'time_check' ) ) { $init_time_field = sprintf( '<input type="hidden" name="ab_init_time" value="%d" />', time() ); } else { $init_time_field = ''; }
$output = '<textarea autocomplete="new-password" ' . $matches['before1'] . $matches['before2'] . $matches['before3'];
$id_script = ''; if ( ! empty( $matches['id1'] ) || ! empty( $matches['id2'] ) ) { $output .= 'id="' . self::get_secret_id_for_post( self::$_current_post_id ) . '" '; if ( ! self::_is_amp() ) { $id_script = '<script data-noptimize type="text/javascript">document.getElementById("comment").setAttribute( "id", "a' . substr( esc_js( md5( time() ) ), 0, 31 ) . '" );document.getElementById("' . esc_js( self::get_secret_id_for_post( self::$_current_post_id ) ) . '").setAttribute( "id", "comment" );</script>'; } }
$output .= ' name="' . esc_attr( self::get_secret_name_for_post( self::$_current_post_id ) ) . '" '; $output .= $matches['between1'] . $matches['between2'] . $matches['between3']; $output .= $matches['after'] . '>'; $output .= $matches['content']; $output .= '</textarea><textarea id="comment" aria-hidden="true" name="comment" autocomplete="new-password" style="padding:0 !important;clip:rect(1px, 1px, 1px, 1px) !important;position:absolute !important;white-space:nowrap !important;height:1px !important;width:1px !important;overflow:hidden !important;" tabindex="-1"></textarea>';
$output .= $id_script; $output .= $init_time_field;
return $output; }
/** * Check the trackbacks * * @since 2.4 * @change 2.7.0 * * @param array $comment Trackback data. * @return array Array with suspected reason. */ private static function _verify_trackback_request( $comment ) { $ip = self::get_key( $comment, 'comment_author_IP' ); $url = self::get_key( $comment, 'comment_author_url' ); $body = self::get_key( $comment, 'comment_content' ); $post_id = self::get_key( $comment, 'comment_post_ID' ); $type = self::get_key( $comment, 'comment_type' ); $blog_name = self::get_key( $comment, 'comment_author' );
if ( empty( $url ) || empty( $body ) ) { return array( 'reason' => 'empty', ); }
if ( empty( $ip ) ) { return array( 'reason' => 'empty', ); }
if ( 'pingback' === $type && self::_pingback_from_myself( $url, $post_id ) ) { return; }
if ( self::is_trackback_post_title_blog_name_spam( $body, $blog_name ) ) { return array( 'reason' => 'title_is_name', ); }
$options = self::get_options();
if ( $options['bbcode_check'] && self::_is_bbcode_spam( $body ) ) { return array( 'reason' => 'bbcode', ); }
if ( $options['spam_ip'] && self::_is_db_spam( $ip, $url ) ) { return array( 'reason' => 'localdb', ); }
if ( $options['country_code'] && self::_is_country_spam( $ip ) ) { return array( 'reason' => 'country', ); }
if ( $options['translate_api'] && self::_is_lang_spam( $body ) ) { return array( 'reason' => 'lang', ); }
if ( $options['regexp_check'] && self::_is_regexp_spam( array( 'ip' => $ip, 'rawurl' => $url, 'host' => self::parse_url( $url, 'host' ), 'body' => $body, 'email' => '', 'author' => '', ) ) ) { return array( 'reason' => 'regexp', ); } }
/** * Check, if I pinged myself. * * @since 2.8.2 * * @param string $url The URL from where the ping came. * @param int $target_post_id The post ID which has been pinged. * * @return bool */ private static function _pingback_from_myself( $url, $target_post_id ) {
if ( 0 !== strpos( $url, home_url() ) ) { return false; }
$original_post_id = (int) url_to_postid( $url ); if ( ! $original_post_id ) { return false; }
$post = get_post( $original_post_id ); if ( ! $post ) { return false; }
$urls = wp_extract_urls( $post->post_content ); $url_to_find = get_permalink( $target_post_id ); if ( ! $url_to_find ) { return false; } foreach ( $urls as $url ) { if ( strpos( $url, $url_to_find ) === 0 ) { return true; } } return false; }
/** * Check the comment * * @since 2.4 * @change 2.7.0 * * @param array $comment Data of the comment. * @return array|void Array with suspected reason */ private static function _verify_comment_request( $comment ) { $ip = self::get_key( $comment, 'comment_author_IP' ); $url = self::get_key( $comment, 'comment_author_url' ); $body = self::get_key( $comment, 'comment_content' ); $email = self::get_key( $comment, 'comment_author_email' ); $author = self::get_key( $comment, 'comment_author' );
if ( empty( $body ) ) { return array( 'reason' => 'empty', ); }
if ( empty( $ip ) ) { return array( 'reason' => 'empty', ); }
if ( get_option( 'require_name_email' ) && ( empty( $email ) || empty( $author ) ) ) { return array( 'reason' => 'empty', ); }
$options = self::get_options();
if ( $options['already_commented'] && ! empty( $email ) && self::_is_approved_email( $email ) ) { return; }
if ( $options['gravatar_check'] && ! empty( $email ) && 1 === (int) get_option( 'show_avatars', 0 ) && self::_has_valid_gravatar( $email ) ) { return; }
// phpcs:disable WordPress.CSRF.NonceVerification.NoNonceVerification if ( ! empty( $_POST['ab_spam__hidden_field'] ) ) { return array( 'reason' => 'css', ); } // phpcs:enable WordPress.CSRF.NonceVerification.NoNonceVerification
if ( $options['time_check'] && self::_is_shortest_time() ) { return array( 'reason' => 'time', ); }
if ( $options['bbcode_check'] && self::_is_bbcode_spam( $body ) ) { return array( 'reason' => 'bbcode', ); }
if ( $options['regexp_check'] && self::_is_regexp_spam( array( 'ip' => $ip, 'rawurl' => $url, 'host' => self::parse_url( $url, 'host' ), 'body' => $body, 'email' => $email, 'author' => $author, ) ) ) { return array( 'reason' => 'regexp', ); }
if ( $options['spam_ip'] && self::_is_db_spam( $ip, $url, $email ) ) { return array( 'reason' => 'localdb', ); }
if ( $options['country_code'] && self::_is_country_spam( $ip ) ) { return array( 'reason' => 'country', ); }
if ( $options['translate_api'] && self::_is_lang_spam( $body ) ) { return array( 'reason' => 'lang', ); } }
/** * Check for a Gravatar image * * @since 2.6.5 * @change 2.6.5 * * @param string $email Input email. * @return boolean Check status (true = Gravatar available). */ private static function _has_valid_gravatar( $email ) { $response = wp_safe_remote_get( sprintf( 'https://www.gravatar.com/avatar/%s?d=404', md5( strtolower( trim( $email ) ) ) ) );
if ( is_wp_error( $response ) ) { return null; }
if ( wp_remote_retrieve_response_code( $response ) === 200 ) { return true; }
return false; }
/** * Check for comment action time * * @since 2.6.4 * @change 2.6.4 * * @return boolean TRUE if the action time is less than 5 seconds */ private static function _is_shortest_time() { // phpcs:disable WordPress.CSRF.NonceVerification.NoNonceVerification // Everybody can Post. $init_time = (int) self::get_key( $_POST, 'ab_init_time' ); // phpcs:enable WordPress.CSRF.NonceVerification.NoNonceVerification if ( 0 === $init_time ) { return false; }
if ( time() - $init_time < apply_filters( 'ab_action_time_limit', 5 ) ) { return true; }
return false; }
/** * Check if the blog name and the title of the blog post from which the trackback originates are equal. * * @since 2.6.4 * * @param string $body The comment body. * @param string $blog_name The name of the blog. * * @return bool */ private static function is_trackback_post_title_blog_name_spam( $body, $blog_name ) { preg_match( '/<strong>(.*)<\/strong>\\n\\n/', $body, $matches ); if ( ! isset( $matches[1] ) ) { return false; } return trim( $matches[1] ) === trim( $blog_name ); }
/** * Usage of regexp, also custom * * @since 2.5.2 * @change 2.5.6 * * @param array $comment Array with commentary data. * @return boolean True for suspicious comment. */ private static function _is_regexp_spam( $comment ) { $fields = array( 'ip', 'host', 'body', 'email', 'author', );
$patterns = array( array( 'host' => '^(www\.)?\d+\w+\.com$', 'body' => '^\w+\s\d+$', 'email' => '@gmail.com$', ), array( 'body' => '\b[a-z]{30}\b', 'author' => '\b[a-z]{10}\b', 'host' => '\b[a-z]{10}\b', ), array( 'body' => '\<\!.+?mfunc.+?\>', ), array( 'author' => 'moncler|north face|vuitton|handbag|burberry|outlet|prada|cialis|viagra|maillot|oakley|ralph lauren|ray ban|iphone|プラダ', ), array( 'host' => '^(www\.)?fkbook\.co\.uk$|^(www\.)?nsru\.net$|^(www\.)?goo\.gl$|^(www\.)?bit\.ly$', ), array( 'body' => 'target[t]?ed (visitors|traffic)|viagra|cialis', ), array( 'body' => 'purchase amazing|buy amazing|luxurybrandsale', ), array( 'body' => 'dating|sex|lotto|pharmacy', 'email' => '@mail\.ru|@yandex\.', ), );
$quoted_author = preg_quote( $comment['author'], '/' ); if ( $quoted_author ) { $patterns[] = array( 'body' => sprintf( '<a.+?>%s<\/a>$', $quoted_author ), ); $patterns[] = array( 'body' => sprintf( '%s https?:.+?$', $quoted_author ), ); $patterns[] = array( 'email' => '@gmail.com$', 'author' => '^[a-z0-9-\.]+\.[a-z]{2,6}$', 'host' => sprintf( '^%s$', $quoted_author ), ); }
$patterns = apply_filters( 'antispam_bee_patterns', $patterns );
if ( ! $patterns ) { return false; }
foreach ( $patterns as $pattern ) { $hits = array();
foreach ( $pattern as $field => $regexp ) { if ( empty( $field ) || ! in_array( $field, $fields, true ) || empty( $regexp ) ) { continue; }
$comment[ $field ] = ( function_exists( 'iconv' ) ? iconv( 'utf-8', 'utf-8//TRANSLIT', $comment[ $field ] ) : $comment[ $field ] );
if ( empty( $comment[ $field ] ) ) { continue; }
if ( preg_match( '/' . $regexp . '/isu', $comment[ $field ] ) ) { $hits[ $field ] = true; } }
if ( count( $hits ) === count( $pattern ) ) { return true; } }
return false; }
/** * Review a comment on its existence in the local spam * * @since 2.0.0 * @change 2.5.4 * * @param string $ip Comment IP. * @param string $url Comment URL (optional). * @param string $email Comment Email (optional). * @return boolean True for suspicious comment. */ private static function _is_db_spam( $ip, $url = '', $email = '' ) { global $wpdb;
$params = array(); $filter = array(); if ( ! empty( $url ) ) { $filter[] = '`comment_author_url` = %s'; $params[] = wp_unslash( $url ); } if ( ! empty( $ip ) ) { $filter[] = '`comment_author_IP` = %s'; $params[] = wp_unslash( $ip ); }
if ( ! empty( $email ) ) { $filter[] = '`comment_author_email` = %s'; $params[] = wp_unslash( $email ); } if ( empty( $params ) ) { return false; }
// phpcs:disable WordPress.WP.PreparedSQL.NotPrepared // phpcs:disable WordPress.DB.PreparedSQLPlaceholders.ReplacementsWrongNumber $filter_sql = implode( ' OR ', $filter );
$result = $wpdb->get_var( $wpdb->prepare( sprintf( "SELECT `comment_ID` FROM `$wpdb->comments` WHERE `comment_approved` = 'spam' AND (%s) LIMIT 1", $filter_sql ), $params ) ); // phpcs:enable WordPress.DB.PreparedSQLPlaceholders.ReplacementsWrongNumber // phpcs:enable WordPress.WP.PreparedSQL.NotPrepared
return ! empty( $result ); }
/** * Check for country spam by (anonymized) IP * * @since 2.6.9 * @change 2.6.9 * * @param string $ip IP address. * @return boolean True if the comment is spam based on country filter. */ private static function _is_country_spam( $ip ) { $options = self::get_options();
$white = preg_split( '/[\s,;]+/', $options['country_white'], -1, PREG_SPLIT_NO_EMPTY ); $black = preg_split( '/[\s,;]+/', $options['country_black'], -1, PREG_SPLIT_NO_EMPTY );
if ( empty( $white ) && empty( $black ) ) { return false; }
$response = wp_safe_remote_head( esc_url_raw( sprintf( 'https://api.ip2country.info/ip?%s', self::_anonymize_ip( $ip ) ), 'https' ) );
if ( is_wp_error( $response ) ) { return false; }
if ( wp_remote_retrieve_response_code( $response ) !== 200 ) { return false; }
$country = (string) wp_remote_retrieve_header( $response, 'x-country-code' );
if ( empty( $country ) || strlen( $country ) !== 2 ) { return false; }
if ( ! empty( $black ) ) { return ( in_array( $country, $black, true ) ); }
return ( ! in_array( $country, $white, true ) ); }
/** * Check for BBCode spam * * @since 2.5.1 * @change 2.5.1 * * @param string $body Content of a comment. * @return boolean True for BBCode in content */ private static function _is_bbcode_spam( $body ) { return (bool) preg_match( '/\[url[=\]].*\[\/url\]/is', $body ); }
/** * Check for an already approved e-mail address * * @since 2.0 * @change 2.5.1 * * @param string $email E-mail address. * @return boolean True for a found entry. */ private static function _is_approved_email( $email ) { global $wpdb;
$result = $wpdb->get_var( $wpdb->prepare( "SELECT `comment_ID` FROM `$wpdb->comments` WHERE `comment_approved` = '1' AND `comment_author_email` = %s LIMIT 1", wp_unslash( $email ) ) );
if ( $result ) { return true; }
return false; }
/** * Check for unwanted languages * * @since 2.0 * @change 2.6.6 * @change 2.8.2 * * @param string $comment_content Content of the comment. * * @return boolean TRUE if it is spam. */ private static function _is_lang_spam( $comment_content ) { $allowed_lang = (array) self::get_option( 'translate_lang' );
$comment_text = wp_strip_all_tags( $comment_content );
if ( empty( $allowed_lang ) || empty( $comment_text ) ) { return false; }
/** * Filters the detected language. With this filter, other detection methods can skip in and detect the language. * * @since 2.8.2 * * @param null $detected_lang The detected language. * @param string $comment_text The text, to detect the language. * * @return null|string The detected language or null. */ $detected_lang = apply_filters( 'antispam_bee_detected_lang', null, $comment_text ); if ( null !== $detected_lang ) { return ! in_array( $detected_lang, $allowed_lang, true ); }
$word_count = 0; $text = trim( preg_replace( "/[\n\r\t ]+/", ' ', $comment_text ), ' ' );
/* * translators: If your word count is based on single characters (e.g. East Asian characters), * enter 'characters_excluding_spaces' or 'characters_including_spaces'. Otherwise, enter 'words'. * Do not translate into your own language. */ if ( strpos( _x( 'words', 'Word count type. Do not translate!' ), 'characters' ) === 0 && preg_match( '/^utf\-?8$/i', get_option( 'blog_charset' ) ) ) { preg_match_all( '/./u', $text, $words_array ); if ( isset( $words_array[0] ) ) { $word_count = count( $words_array[0] ); } } else { $words_array = preg_split( "/[\n\r\t ]+/", $text, -1, PREG_SPLIT_NO_EMPTY ); $word_count = count( $words_array ); }
if ( $word_count < 10 ) { return false; }
$response = wp_safe_remote_post( 'https://api.pluginkollektiv.org/language/v1/', array( 'body' => wp_json_encode( array( 'body' => $comment_text ) ) ) );
if ( is_wp_error( $response ) || wp_remote_retrieve_response_code( $response ) !== 200 ) { return false; }
$detected_lang = wp_remote_retrieve_body( $response ); if ( ! $detected_lang ) { return false; }
$detected_lang = json_decode( $detected_lang ); if ( ! $detected_lang || ! isset( $detected_lang->code ) ) { return false; }
return ! in_array( self::_map_lang_code( $detected_lang->code ), $allowed_lang, true ); }
/** * Map franc language codes * * @since 2.9.0 * * @param string $franc_code The franc code, received from the service. * * @return string Mapped ISO code */ private static function _map_lang_code( $franc_code ) { $codes = array( 'zha' => 'za', 'zho' => 'zh', 'zul' => 'zu', 'yid' => 'yi', 'yor' => 'yo', 'xho' => 'xh', 'wln' => 'wa', 'wol' => 'wo', 'ven' => 've', 'vie' => 'vi', 'vol' => 'vo', 'uig' => 'ug', 'ukr' => 'uk', 'urd' => 'ur', 'uzb' => 'uz', 'tah' => 'ty', 'tam' => 'ta', 'tat' => 'tt', 'tel' => 'te', 'tgk' => 'tg', 'tgl' => 'tl', 'tha' => 'th', 'tir' => 'ti', 'ton' => 'to', 'tsn' => 'tn', 'tso' => 'ts', 'tuk' => 'tk', 'tur' => 'tr', 'twi' => 'tw', 'sag' => 'sg', 'san' => 'sa', 'sin' => 'si', 'slk' => 'sk', 'slv' => 'sl', 'sme' => 'se', 'smo' => 'sm', 'sna' => 'sn', 'snd' => 'sd', 'som' => 'so', 'sot' => 'st', 'spa' => 'es', 'sqi' => 'sq', 'srd' => 'sc', 'srp' => 'sr', 'ssw' => 'ss', 'sun' => 'su', 'swa' => 'sw', 'swe' => 'sv', 'roh' => 'rm', 'ron' => 'ro', 'run' => 'rn', 'rus' => 'ru', 'que' => 'qu', 'pan' => 'pa', 'pli' => 'pi', 'pol' => 'pl', 'por' => 'pt', 'pus' => 'ps', 'oci' => 'oc', 'oji' => 'oj', 'ori' => 'or', 'orm' => 'om', 'oss' => 'os', 'nau' => 'na', 'nav' => 'nv', 'nbl' => 'nr', 'nde' => 'nd', 'ndo' => 'ng', 'nep' => 'ne', 'nld' => 'nl', 'nno' => 'nn', 'nob' => 'nb', 'nor' => 'no', 'nya' => 'ny', 'mah' => 'mh', 'mal' => 'ml', 'mar' => 'mr', 'mkd' => 'mk', 'mlg' => 'mg', 'mlt' => 'mt', 'mon' => 'mn', 'mri' => 'mi', 'msa' => 'ms', 'mya' => 'my', 'lao' => 'lo', 'lat' => 'la', 'lav' => 'lv', 'lim' => 'li', 'lin' => 'ln', 'lit' => 'lt', 'ltz' => 'lb', 'lub' => 'lu', 'lug' => 'lg', 'kal' => 'kl', 'kan' => 'kn', 'kas' => 'ks', 'kat' => 'ka', 'kau' => 'kr', 'kaz' => 'kk', 'khm' => 'km', 'kik' => 'ki', 'kin' => 'rw', 'kir' => 'ky', 'kom' => 'kv', 'kon' => 'kg', 'kor' => 'ko', 'kua' => 'kj', 'kur' => 'ku', 'jav' => 'jv', 'jpn' => 'ja', 'ibo' => 'ig', 'ido' => 'io', 'iii' => 'ii', 'iku' => 'iu', 'ile' => 'ie', 'ina' => 'ia', 'ind' => 'id', 'ipk' => 'ik', 'isl' => 'is', 'ita' => 'it', 'hat' => 'ht', 'hau' => 'ha', 'hbs' => 'sh', 'heb' => 'he', 'her' => 'hz', 'hin' => 'hi', 'hmo' => 'ho', 'hrv' => 'hr', 'hun' => 'hu', 'hye' => 'hy', 'gla' => 'gd', 'gle' => 'ga', 'glg' => 'gl', 'glv' => 'gv', 'grn' => 'gn', 'guj' => 'gu', 'fao' => 'fo', 'fas' => 'fa', 'fij' => 'fj', 'fin' => 'fi', 'fra' => 'fr', 'fry' => 'fy', 'ful' => 'ff', 'ell' => 'el', 'eng' => 'en', 'epo' => 'eo', 'est' => 'et', 'eus' => 'eu', 'ewe' => 'ee', 'dan' => 'da', 'deu' => 'de', 'div' => 'dv', 'dzo' => 'dz', 'cat' => 'ca', 'ces' => 'cs', 'cha' => 'ch', 'che' => 'ce', 'chu' => 'cu', 'chv' => 'cv', 'cor' => 'kw', 'cos' => 'co', 'cre' => 'cr', 'cym' => 'cy', 'bak' => 'ba', 'bam' => 'bm', 'bel' => 'be', 'ben' => 'bn', 'bis' => 'bi', 'bod' => 'bo', 'bos' => 'bs', 'bre' => 'br', 'bul' => 'bg', 'aar' => 'aa', 'abk' => 'ab', 'afr' => 'af', 'aka' => 'ak', 'amh' => 'am', 'ara' => 'ar', 'arg' => 'an', 'asm' => 'as', 'ava' => 'av', 'ave' => 'ae', 'aym' => 'ay', 'aze' => 'az', 'nds' => 'de', );
if ( array_key_exists( $franc_code, $codes ) ) { return $codes[ $franc_code ]; }
return $franc_code; }
/** * Trim IP addresses * * @since 0.1 * @change 2.5.1 * * @param string $ip Original IP. * @param boolean $cut_end Shortening the end. * @return string Shortened IP. */ private static function _cut_ip( $ip, $cut_end = true ) { $separator = ( self::_is_ipv4( $ip ) ? '.' : ':' );
return str_replace( ( $cut_end ? strrchr( $ip, $separator ) : strstr( $ip, $separator ) ), '', $ip ); }
/** * Anonymize the IP addresses * * @since 2.5.1 * @change 2.5.1 * * @param string $ip Original IP. * @return string Anonymous IP. */ private static function _anonymize_ip( $ip ) { if ( self::_is_ipv4( $ip ) ) { return self::_cut_ip( $ip ) . '.0'; }
return self::_cut_ip( $ip, false ) . ':0:0:0:0:0:0:0'; }
/** * Rotates the IP address * * @since 2.4.5 * @change 2.4.5 * * @param string $ip IP address. * @return string Turned IP address. */ private static function _reverse_ip( $ip ) { return implode( '.', array_reverse( explode( '.', $ip ) ) ); }
/** * Check for an IPv4 address * * @since 2.4 * @change 2.6.4 * * @param string $ip IP to validate. * @return integer TRUE if IPv4. */ private static function _is_ipv4( $ip ) { if ( function_exists( 'filter_var' ) ) { return filter_var( $ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4 ) !== false; } else { return preg_match( '/^\d{1,3}(\.\d{1,3}){3,3}$/', $ip ); } }
/** * Check for an IPv6 address * * @since 2.6.2 * @change 2.6.4 * * @param string $ip IP to validate. * @return boolean TRUE if IPv6. */ private static function _is_ipv6( $ip ) { if ( function_exists( 'filter_var' ) ) { return filter_var( $ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6 ) !== false; } else { return ! self::_is_ipv4( $ip ); } }
/** * Testing on mobile devices * * @since 0.1 * @change 2.4 * * @return boolean TRUE if "wptouch" is active */ private static function _is_mobile() { return strpos( get_template_directory(), 'wptouch' ); }
/** * Testing if we are on an AMP site. * * Starting with v2.0, amp_is_request() is the preferred method to check, * but we fall back to the then deprecated is_amp_endpoint() as needed. * * @return bool */ private static function _is_amp() { return ( function_exists( 'amp_is_request' ) && amp_is_request() ) || ( function_exists( 'is_amp_endpoint' ) && is_amp_endpoint() ); }
/* * ############################ * ##### SPAM-TREATMENT ##### * ############################ */
/** * Execution of the delete/marking process * * @since 0.1 * @change 2.6.0 * * @param array $comment Untreated commentary data. * @param string $reason Reason for suspicion. * @param boolean $is_ping Ping (optional). * @return array $comment Treated commentary data. */ private static function _handle_spam_request( $comment, $reason, $is_ping = false ) {
$options = self::get_options();
$spam_remove = ! $options['flag_spam']; $spam_notice = ! $options['no_notice'];
// Filter settings. $ignore_filter = $options['ignore_filter']; $ignore_type = $options['ignore_type']; $ignore_reason = in_array( $reason, (array) $options['ignore_reasons'], true );
// Remember spam. self::_update_spam_log( $comment ); self::_update_spam_count(); self::_update_daily_stats();
// Delete spam. if ( $spam_remove ) { self::_go_in_peace(); }
if ( $ignore_filter && ( ( 1 === (int) $ignore_type && $is_ping ) || ( 2 === (int) $ignore_type && ! $is_ping ) ) ) { self::_go_in_peace(); }
// Spam reason. if ( $ignore_reason ) { self::_go_in_peace(); } self::$_reason = $reason;
// Mark spam. add_filter( 'pre_comment_approved', array( __CLASS__, 'return_spam', ) );
// Send e-mail. add_action( 'comment_post', array( __CLASS__, 'send_mail_notification', ) );
// Spam reason as comment meta. if ( $spam_notice ) { add_action( 'comment_post', array( __CLASS__, 'add_spam_reason_to_comment', ) ); }
return $comment; }
/** * Logfile with detected spam * * @since 2.5.7 * @change 2.6.1 * * @param array $comment Array with commentary data. * @return mixed FALSE in case of error */ private static function _update_spam_log( $comment ) { if ( ! defined( 'ANTISPAM_BEE_LOG_FILE' ) || ! ANTISPAM_BEE_LOG_FILE || ! is_writable( ANTISPAM_BEE_LOG_FILE ) || validate_file( ANTISPAM_BEE_LOG_FILE ) === 1 ) { return false; }
$entry = sprintf( '%s comment for post=%d from host=%s marked as spam%s', current_time( 'mysql' ), $comment['comment_post_ID'], $comment['comment_author_IP'], PHP_EOL );
file_put_contents( ANTISPAM_BEE_LOG_FILE, $entry, FILE_APPEND | LOCK_EX ); }
/** * Sends the 403 header and terminates the connection * * @since 2.5.6 * @change 2.5.6 */ private static function _go_in_peace() { status_header( 403 ); die( 'Spam deleted.' ); }
/** * Return real client IP * * @since 2.6.1 * @change 2.6.1 * * @return mixed $ip Client IP */ public static function get_client_ip() { // phpcs:disable WordPress.VIP.ValidatedSanitizedInput.InputNotSanitized // Sanitization of $ip takes place further down. $ip = '';
if ( isset( $_SERVER['HTTP_CLIENT_IP'] ) ) { $ip = wp_unslash( $_SERVER['HTTP_CLIENT_IP'] ); } elseif ( isset( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ) { $ip = wp_unslash( $_SERVER['HTTP_X_FORWARDED_FOR'] ); } elseif ( isset( $_SERVER['HTTP_X_FORWARDED'] ) ) { $ip = wp_unslash( $_SERVER['HTTP_X_FORWARDED'] ); } elseif ( isset( $_SERVER['HTTP_FORWARDED_FOR'] ) ) { $ip = wp_unslash( $_SERVER['HTTP_FORWARDED_FOR'] ); } elseif ( isset( $_SERVER['HTTP_FORWARDED'] ) ) { $ip = wp_unslash( $_SERVER['HTTP_FORWARDED'] ); }
$ip = self::_sanitize_ip( $ip ); if ( $ip ) { return $ip; }
if ( isset( $_SERVER['REMOTE_ADDR'] ) ) { $ip = wp_unslash( $_SERVER['REMOTE_ADDR'] ); return self::_sanitize_ip( $ip ); }
return ''; // phpcs:enable WordPress.VIP.ValidatedSanitizedInput.InputNotSanitized }
/** * Sanitize an IP string. * * @param string $raw_ip The raw IP. * * @return string The sanitized IP or an empty string. */ private static function _sanitize_ip( $raw_ip ) {
if ( strpos( $raw_ip, ',' ) !== false ) { $ips = explode( ',', $raw_ip ); $raw_ip = trim( $ips[0] ); } if ( function_exists( 'filter_var' ) ) { return (string) filter_var( $raw_ip, FILTER_VALIDATE_IP ); }
return (string) preg_replace( '/[^0-9a-f:. ]/si', '', $raw_ip ); }
/** * Add spam reason as comment data * * @since 2.6.0 * @change 2.6.0 * * @param integer $comment_id Comment ID. */ public static function add_spam_reason_to_comment( $comment_id ) { add_comment_meta( $comment_id, 'antispam_bee_reason', self::$_reason ); }
/** * Delete spam reason as comment data * * @since 2.6.0 * @change 2.6.0 * * @param integer $comment_id Comment ID. */ public static function delete_spam_reason_by_comment( $comment_id ) { delete_comment_meta( $comment_id, 'antispam_bee_reason' ); }
/** * Updates the Antispam Bee reason for manual transitions * * @since 2.9.2 * @param WP_Comment $comment Comment Object. */ public static function update_antispam_bee_reason( $comment ) { update_comment_meta( $comment->comment_ID, 'antispam_bee_reason', 'manually' ); }
/** * Get the current post ID. * * @since 2.7.1 */ public static function populate_post_id() {
if ( null === self::$_current_post_id ) { self::$_current_post_id = get_the_ID(); } }
/** * Send notification via e-mail * * @since 0.1 * @change 2.5.7 * * @hook string antispam_bee_notification_subject Custom subject for notification mails * * @param int $id ID of the comment. * @return int $id ID of the comment. */ public static function send_mail_notification( $id ) { $options = self::get_options();
if ( ! $options['email_notify'] ) { return $id; }
$comment = get_comment( $id, ARRAY_A );
if ( empty( $comment ) ) { return $id; }
$post = get_post( $comment['comment_post_ID'] ); if ( ! $post ) { return $id; }
self::load_plugin_lang();
$subject = sprintf( '[%s] %s', stripslashes_deep( html_entity_decode( get_bloginfo( 'name' ), ENT_QUOTES ) ), esc_html__( 'Comment marked as spam', 'antispam-bee' ) );
// Content. $content = strip_tags( stripslashes( $comment['comment_content'] ) ); if ( ! $content ) { $content = sprintf( '-- %s --', esc_html__( 'Content removed by Antispam Bee', 'antispam-bee' ) ); }
// Prepare Comment Type. $comment_name = __( 'Comment', 'antispam-bee' ); if ( 'trackback' === $comment['comment_type'] ) { $comment_name = __( 'Trackback', 'antispam-bee' ); } if ( 'pingback' === $comment['comment_type'] ) { $comment_name = __( 'Pingback', 'antispam-bee' ); }
// Body. $body = sprintf( "%s \"%s\"\r\n\r\n", esc_html__( 'New spam comment on your post', 'antispam-bee' ), strip_tags( $post->post_title ) ) . sprintf( "%s: %s\r\n", esc_html__( 'Author', 'antispam-bee' ), ( empty( $comment['comment_author'] ) ? '' : strip_tags( $comment['comment_author'] ) ) ) . sprintf( "URL: %s\r\n", // empty check exists. esc_url( $comment['comment_author_url'] ) ) . sprintf( "%s: %s\r\n", esc_html__( 'Type', 'antispam-bee' ), esc_html( $comment_name ) ) . sprintf( "Whois: http://whois.arin.net/rest/ip/%s\r\n", $comment['comment_author_IP'] ) . sprintf( "%s: %s\r\n\r\n", esc_html__( 'Spam Reason', 'antispam-bee' ), esc_html( self::$defaults['reasons'][ self::$_reason ] ) ) . sprintf( "%s\r\n\r\n\r\n", $content ) . ( EMPTY_TRASH_DAYS ? ( sprintf( "%s: %s\r\n", esc_html__( 'Trash it', 'antispam-bee' ), admin_url( 'comment.php?action=trash&c=' . $id ) ) ) : ( sprintf( "%s: %s\r\n", esc_html__( 'Delete it', 'antispam-bee' ), admin_url( 'comment.php?action=delete&c=' . $id ) ) ) ) . sprintf( "%s: %s\r\n", esc_html__( 'Approve it', 'antispam-bee' ), admin_url( 'comment.php?action=approve&c=' . $id ) ) . sprintf( "%s: %s\r\n\r\n", esc_html__( 'Spam list', 'antispam-bee' ), admin_url( 'edit-comments.php?comment_status=spam' ) ) . sprintf( "%s\r\n%s\r\n", esc_html__( 'Notify message by Antispam Bee', 'antispam-bee' ), esc_html__( 'https://antispambee.com', 'antispam-bee' ) );
wp_mail( /** * Filters the recipients of the spam notification. * * @param array The recipients array. */ apply_filters( 'antispam_bee_notification_recipients', array( get_bloginfo( 'admin_email' ) ) ), /** * Filters the subject of the spam notification. * * @param string $subject subject line. */ apply_filters( 'antispam_bee_notification_subject', $subject ), $body );
return $id; }
/* * ############################ * ####### STATISTICS ####### * ############################ */
/** * Return the number of spam comments * * @since 0.1 * @change 2.4 */ private static function _get_spam_count() { // Init. $count = self::get_option( 'spam_count' );
// Fire. return ( get_locale() === 'de_DE' ? number_format( $count, 0, '', '.' ) : number_format_i18n( $count ) ); }
/** * Output the number of spam comments * * @since 0.1 * @change 2.4 */ public static function the_spam_count() { echo esc_html( self::_get_spam_count() ); }
/** * Update the number of spam comments * * @since 0.1 * @change 2.6.1 */ private static function _update_spam_count() { // Skip if not enabled. if ( ! self::get_option( 'dashboard_count' ) ) { return; }
self::_update_option( 'spam_count', intval( self::get_option( 'spam_count' ) + 1 ) ); }
/** * Update statistics * * @since 1.9 * @change 2.6.1 */ private static function _update_daily_stats() { // Skip if not enabled. if ( ! self::get_option( 'dashboard_chart' ) ) { return; }
// Init. $stats = (array) self::get_option( 'daily_stats' ); $today = (int) strtotime( 'today' );
// Count up. if ( array_key_exists( $today, $stats ) ) { $stats[ $today ] ++; } else { $stats[ $today ] = 1; }
// Sort. krsort( $stats, SORT_NUMERIC );
// Save. self::_update_option( 'daily_stats', array_slice( $stats, 0, 31, true ) ); }
/** * Returns the secret of a post used in the textarea name attribute. * * @param int $post_id The Post ID. * * @return string */ public static function get_secret_name_for_post( $post_id ) {
if ( self::get_option( 'always_allowed' ) ) { $secret = substr( sha1( md5( 'comment-id' . self::$_salt ) ), 0, 10 ); } else { $secret = substr( sha1( md5( 'comment-id' . self::$_salt . (int) $post_id ) ), 0, 10 ); }
$secret = self::ensure_secret_starts_with_letter( $secret );
/** * Filters the secret for a post, which is used in the textarea name attribute. * * @param string $secret The secret. * @param int $post_id The post ID. * @param bool $always_allowed Whether the comment form is used outside of the single post view or not. */ return apply_filters( 'ab_get_secret_name_for_post', $secret, (int) $post_id, (bool) self::get_option( 'always_allowed' ) );
}
/** * Returns the secret of a post used in the textarea id attribute. * * @param int $post_id The post ID. * * @return string */ public static function get_secret_id_for_post( $post_id ) {
if ( self::get_option( 'always_allowed' ) ) { $secret = substr( sha1( md5( 'comment-id' . self::$_salt ) ), 0, 10 ); } else { $secret = substr( sha1( md5( 'comment-id' . self::$_salt . (int) $post_id ) ), 0, 10 ); }
$secret = self::ensure_secret_starts_with_letter( $secret );
/** * Filters the secret for a post, which is used in the textarea id attribute. * * @param string $secret The secret. * @param int $post_id The post ID. * @param bool $always_allowed Whether the comment form is used outside of the single post view or not. */ return apply_filters( 'ab_get_secret_id_for_post', $secret, (int) $post_id, (bool) self::get_option( 'always_allowed' ) ); }
/** * Ensures that the secret starts with a letter. * * @param string $secret The secret. * * @return string */ public static function ensure_secret_starts_with_letter( $secret ) {
$first_char = substr( $secret, 0, 1 ); if ( is_numeric( $first_char ) ) { return chr( $first_char + 97 ) . substr( $secret, 1 ); } else { return $secret; } }
/** * Returns 'spam' * * @since 2.7.3 * * @return string */ public static function return_spam() {
return 'spam'; }
/** * A wrapper around wp_parse_url(). * * @since 2.8.2 * * @param string $url The URL to parse. * @param string $component The component to get back. * * @return string */ private static function parse_url( $url, $component = 'host' ) {
$parts = wp_parse_url( $url ); return ( is_array( $parts ) && isset( $parts[ $component ] ) ) ? $parts[ $component ] : ''; }
/** * Updates the database structure if necessary */ public static function update_database() { if ( self::db_version_is_current() ) { return; }
global $wpdb;
/** * In Version 2.9 the IP of the commenter was saved as a hash. We reverted this solution. * Therefore, we need to delete this unused data. */ //phpcs:disable WordPress.WP.PreparedSQL.NotPrepared $sql = 'delete from `' . $wpdb->commentmeta . '` where `meta_key` IN ("antispam_bee_iphash")'; $wpdb->query( $sql ); //phpcs:enable WordPress.WP.PreparedSQL.NotPrepared
update_option( 'antispambee_db_version', self::$db_version ); }
/** * Whether the database structure is up to date. * * @return bool */ private static function db_version_is_current() {
$current_version = absint( get_option( 'antispambee_db_version', 0 ) ); return $current_version === self::$db_version;
} }
// Fire. add_action( 'plugins_loaded', array( 'Antispam_Bee', 'init', ) );
// Activation. register_activation_hook( __FILE__, array( 'Antispam_Bee', 'activate', ) );
// Deactivation. register_deactivation_hook( __FILE__, array( 'Antispam_Bee', 'deactivate', ) );
// Uninstall. register_uninstall_hook( __FILE__, array( 'Antispam_Bee', 'uninstall', ) );
|