PluginProbe
CryptX / 4.0.6
CryptX v4.0.6
4.2.1 4.2.0 4.1.1 trunk 1.0 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.9 2.0 2.1 2.2 2.3 2.3.1 2.3.2 2.3.3 2.4.0 2.4.1 2.4.2 2.4.3 2.4.4 All 93 releases
cryptx / classes / Admin / GeneralSettingsTab.php

GeneralSettingsTab.php in CryptX 4.0.6, at classes/Admin/GeneralSettingsTab.php

165 lines 6.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace CryptX\Admin;
4
5 use CryptX\Config;
6
7 class GeneralSettingsTab {
8 private Config $config;
9 private const TEMPLATE_PATH = CRYPTX_DIR_PATH . 'templates/admin/tabs/general.php';
10 private const DEFAULTS = [
11 'the_content' => 0,
12 'the_meta_key' => 0,
13 'the_excerpt' => 0,
14 'comment_text' => 0,
15 'widget_text' => 0,
16 'autolink' => 0,
17 'metaBox' => 0,
18 'disable_rss' => 0,
19 'java' => 1,
20 'load_java' => 1,
21 'use_secure_encryption' => 0,
22 'encryption_mode' => 'legacy',
23 'iteration' => '10000'
24 ];
25
26 public function __construct(Config $config) {
27 $this->config = $config;
28 }
29
30 public function render(): void {
31 if ('general' !== $this->getActiveTab()) {
32 return;
33 }
34
35 $options = $this->config->getAll();
36 // Extract variables for the template
37 $settings = [
38 'options' => $options, // Pass all options
39 'securitySettings' => [
40 'use_secure_encryption' => [
41 'label' => esc_html__('Use Secure Encryption', 'cryptx'),
42 'description' => esc_html__('Enable AES-256-GCM encryption for enhanced security (recommended for new installations)', 'cryptx'),
43 'value' => $options['use_secure_encryption'] ?? 0
44 ],
45 'encryption_mode' => [
46 'label' => esc_html__('Encryption Mode', 'cryptx'),
47 'description' => esc_html__('Choose encryption method. Legacy mode maintains backward compatibility with existing encrypted emails.', 'cryptx'),
48 'value' => $options['encryption_mode'] ?? 'legacy',
49 'options' => [
50 'legacy' => esc_html__('Legacy (Compatible)', 'cryptx'),
51 'secure' => esc_html__('Secure (AES-256-GCM)', 'cryptx')
52 ]
53 ],
54 'iterations' => [
55 'label' => esc_html__('PBKDF2 iterations', 'cryptx'),
56 'description' => esc_html__('Choose iterations mode. It\'s a trade-off between security and speed. The more email addresses there are on a page, the greater the impact will be.', 'cryptx'),
57 'value' => $options['iterations'] ?? '10000',
58 'options' => [
59 '100000' => esc_html__('Secure', 'cryptx'),
60 '10000' => esc_html__('Balanced', 'cryptx'),
61 '1000' => esc_html__('Performance', 'cryptx')
62 ]
63 ]
64 ],
65 'applyTo' => [
66 'the_content' => [
67 'label' => esc_html__('Content', 'cryptx'),
68 'description' => esc_html__('(this can be disabled per Post by an Option)', 'cryptx')
69 ],
70 'the_meta_key' => [
71 'label' => esc_html__('Custom fields', 'cryptx'),
72 'description' => esc_html__('(works only with the_meta()!)', 'cryptx')
73 ],
74 'the_excerpt' => [
75 'label' => esc_html__('Excerpt', 'cryptx'),
76 ],
77 'comment_text' => [
78 'label' => esc_html__('Comments', 'cryptx'),
79 ],
80 'widget_text' => [
81 'label' => esc_html__('Widgets', 'cryptx'),
82 'description' => esc_html__('(applies to all text and HTML widgets)', 'cryptx')
83 ]
84 ],
85 'decryptionType' => [
86 'javascript' => [
87 'value' => 1,
88 'label' => esc_html__('Use javascript to hide the Email-Link.', 'cryptx')
89 ],
90 'unicode' => [
91 'value' => 0,
92 'label' => esc_html__('Use Unicode to hide the Email-Link.', 'cryptx')
93 ]
94 ],
95 'javascriptLocation' => [
96 'header' => [
97 'value' => 0,
98 'label' => esc_html__('Load the javascript in the <b>header</b> of the page.', 'cryptx')
99 ],
100 'footer' => [
101 'value' => 1,
102 'label' => esc_html__('Load the javascript in the <b>footer</b> of the page.', 'cryptx')
103 ]
104 ],
105 'excludedIds' => $options['excludedIDs'],
106 'metaBox' => $options['metaBox'],
107 'autolink' => $options['autolink'],
108 'whiteList' => $options['whiteList']
109 ];
110
111 $this->renderTemplate(self::TEMPLATE_PATH, $settings);
112 }
113
114 private function renderTemplate(string $path, array $data): void {
115 if (!file_exists($path)) {
116 throw new \RuntimeException(sprintf('Template file not found: %s', esc_html($path, 'cryptx')));
117 }
118
119 extract($data);
120 include $path;
121 }
122
123 private function getActiveTab(): string {
124 return sanitize_text_field(wp_unslash($_GET['tab']) ?? 'general');
125 }
126
127 public function saveSettings(array $data): void
128 {
129 if (!current_user_can('manage_options')) {
130 wp_die(esc_html__('You do not have sufficient permissions to access this page.', 'cryptx'));
131 }
132
133 check_admin_referer('cryptX');
134
135 // Merge POST data with defaults to handle unchecked checkboxes
136 $sanitized = array_merge(
137 self::DEFAULTS,
138 array_map(function($value) {
139 if ($value === '1') return 1; // Convert string '1' to integer 1 for checkboxes
140 return sanitize_text_field($value);
141 }, $data)
142 );
143
144 if (!empty($_POST['cryptX_var_reset'])) {
145 $this->config->reset();
146 return;
147 }
148
149 $this->config->update($sanitized);
150
151 add_settings_error(
152 'cryptx_messages',
153 'settings_updated',
154 esc_html__('Settings saved.', 'cryptx'),
155 'updated'
156 );
157 }
158
159 private function sanitizeSettings(array $data): array {
160 return array_merge(
161 self::DEFAULTS,
162 array_map('sanitize_text_field', $data)
163 );
164 }
165 }