PluginProbe
Simple Analytics / 1.67
Simple Analytics v1.67
1.109 1.108 1.107 1.106 1.73 1.74 1.75 1.76 1.77 1.78 1.79 1.8 1.80 1.81 1.82 1.83 1.84 1.85 1.86 1.87 1.88 1.89 1.9 1.90 1.91 All 98 releases
simpleanalytics / src / Settings / Blocks / Fields / IpList.php

IpList.php in Simple Analytics 1.67, at src/Settings/Blocks/Fields/IpList.php

90 lines 2.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace SimpleAnalytics\Settings\Blocks\Fields;
4
5 use SimpleAnalytics\Setting;
6 use SimpleAnalytics\Settings\Concerns\HasDocs;
7 use SimpleAnalytics\Settings\Concerns\HasPlaceholder;
8 use SimpleAnalytics\UI\LabelComponent;
9
10 class IpList extends Field
11 {
12 use HasDocs;
13 use HasPlaceholder;
14
15 public function getValueSanitizer(): callable
16 {
17 return function ($value) {
18 $ips = [];
19
20 if (! is_array($value)) {
21 $ips = explode("\n", $value);
22 }
23
24 $ips = array_map('trim', $ips);
25 $ips = array_filter($ips, function ($ip) {
26 return filter_var($ip, FILTER_VALIDATE_IP) !== false;
27 });
28 $ips = array_unique($ips);
29 return array_values($ips);
30 };
31 }
32
33 public function getValueType(): string
34 {
35 return 'array';
36 }
37
38 public function render(): void
39 {
40 $value = implode("\n", Setting::array($this->getKey()));
41 $currentIp = $_SERVER['REMOTE_ADDR'];
42 ?>
43 <?php
44 (new LabelComponent(
45 $this->getLabel(),
46 $this->docs,
47 esc_attr($this->getKey()))
48 )();
49 ?>
50 <div class="mt-2">
51 <textarea
52 name="<?php
53 echo esc_attr($this->getKey());
54 ?>"
55 id="<?php
56 echo esc_attr($this->getKey());
57 ?>"
58 rows="5"
59 class="block w-full rounded-md border-0 text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 placeholder:text-gray-400 focus:ring-2 focus:ring-inset focus:ring-primary sm:py-1.5 sm:text-sm sm:leading-6"
60 <?php
61 if ($this->placeholder): ?>
62 placeholder="<?php echo esc_attr($this->placeholder); ?>"
63 <?php endif;
64 ?>
65 ><?php
66 echo esc_textarea($value);
67 ?></textarea>
68 </div>
69 <div class="mt-2">
70 <button
71 type="button"
72 onclick="sa_textarea_add_value(this.form.elements['<?php
73 echo esc_js($this->getKey());
74 ?>'], '<?php
75 echo esc_js($currentIp);
76 ?>')"
77 class="rounded bg-white px-2 py-1 text-xs font-semibold text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 hover:bg-gray-50"
78 >
79 Add Current IP (<?php
80 echo esc_html($currentIp);
81 ?>)
82 </button>
83 </div>
84 <p class="mt-2 text-sm text-gray-500">
85 Enter IP addresses to exclude from tracking, one per line.
86 </p>
87 <?php
88 }
89 }
90