PluginProbe
CryptX / 4.0.1
CryptX v4.0.1
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
← All changes | cryptx.php +163 -297 1.04.0.1 View file →
@@ -1,318 +1,184 @@
1 1 <?php
2 -/*
3 -Plugin Name: CryptX
4 -Plugin URI: http://weber-nrw.de/
5 -Description: En-/Decrypt mailto-Links to prevent Spam Bots scanning Sorcecode for Emails.
6 -Version: 1.0
7 -Author: Ralf Weber
8 -Author URI: http://weber-nrw.de/
9 -*/
2 +/**
3 + * Plugin Name: CryptX
4 + * Plugin URI: https://wordpress.org/plugins/cryptx/
5 + * Description: CryptX encrypts email addresses in your posts, pages, comments, and text widgets to protect them from spam bots while keeping them readable for your visitors.
6 + * Version: 4.0.1
7 + * Requires at least: 6.7
8 + * Tested up to: 6.8
9 + * Requires PHP: 8.1
10 + * Author: Ralf Weber
11 + * Author URI: https://weber-nrw.de/
12 + * License: GPL v2 or later
13 + * License URI: https://www.gnu.org/licenses/gpl-2.0.html
14 + * Text Domain: cryptx
15 + * Domain Path: /languages
16 + * Network: false
17 + * Update URI: https://wordpress.org/plugins/cryptx/
18 + *
19 + * CryptX is free software: you can redistribute it and/or modify
20 + * it under the terms of the GNU General Public License as published by
21 + * the Free Software Foundation, either version 2 of the License, or
22 + * any later version.
23 + *
24 + * CryptX is distributed in the hope that it will be useful,
25 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
26 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27 + * GNU General Public License for more details.
28 + *
29 + * You should have received a copy of the GNU General Public License
30 + * along with CryptX. If not, see https://www.gnu.org/licenses/gpl-2.0.html.
31 + *
32 + * @package CryptX
33 + * @since 1.0.0
34 + */
10 35
11 -/////////////////////////////////////////////////////////////////////////////
12 -
13 -/**
14 -* @internal prevent from direct calls
15 -*/
36 +// Prevent direct access
16 37 if (!defined('ABSPATH')) {
17 - return ;
18 - }
38 + exit;
39 +}
19 40
20 -/**
21 -* @internal prevent from second inclusion
22 -*/
23 -if (!class_exists('cryptX')) {
41 +// Plugin constants
42 +define('CRYPTX_VERSION', '4.0.1');
43 +define('CRYPTX_PLUGIN_FILE', __FILE__);
44 +define('CRYPTX_PLUGIN_BASENAME', plugin_basename(__FILE__));
45 +define('CRYPTX_BASENAME', plugin_basename(__FILE__)); // Add this missing constant
46 +define('CRYPTX_DIR_PATH', plugin_dir_path(__FILE__));
47 +define('CRYPTX_DIR_URL', plugin_dir_url(__FILE__));
48 +define('CRYPTX_BASEFOLDER', dirname(CRYPTX_PLUGIN_BASENAME));
24 49
25 -/////////////////////////////////////////////////////////////////////////////
50 +// Minimum requirements check
51 +if (version_compare(PHP_VERSION, '8.1.0', '<')) {
52 + add_action('admin_notices', function() {
53 + echo '<div class="notice notice-error"><p>';
54 + printf(
55 + /* translators: %1$s: Required PHP version, %2$s: Current PHP version */
56 + __('CryptX requires PHP version %1$s or higher. You are running version %2$s. Please update PHP.', 'cryptx'),
57 + '8.1.0',
58 + PHP_VERSION
59 + );
60 + echo '</p></div>';
61 + });
62 + return;
63 +}
26 64
27 -load_plugin_textdomain('cryptx', PLUGINDIR . '/' . dirname(plugin_basename (__FILE__)) );
65 +// WordPress version check
66 +global $wp_version;
67 +if (version_compare($wp_version, '6.7', '<')) {
68 + add_action('admin_notices', function() {
69 + echo '<div class="notice notice-error"><p>';
70 + printf(
71 + /* translators: %1$s: Required WordPress version, %2$s: Current WordPress version */
72 + __('CryptX requires WordPress version %1$s or higher. You are running version %2$s. Please update WordPress.', 'cryptx'),
73 + '5.0',
74 + $GLOBALS['wp_version']
75 + );
76 + echo '</p></div>';
77 + });
78 + return;
79 +}
28 80
29 -$cryptX_var = (array) get_option('cryptX');
81 +// Autoloader for plugin classes
82 +spl_autoload_register(function ($class) {
83 + // Check if the class belongs to our namespace
84 + if (strpos($class, 'CryptX\\') !== 0) {
85 + return;
86 + }
30 87
31 -/**
32 -* "CryptX" WordPress Plugin
33 -*
34 -* @author Ralf Weber <ralf@weber-nrw.de>
35 -* @license http://opensource.org/licenses/gpl-license.php GNU Public License
36 -*/
37 -Class cryptX {
88 + // Remove namespace prefix
89 + $class = substr($class, 7);
38 90
39 - // -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
91 + // Convert namespace separators to directory separators
92 + $class = str_replace('\\', DIRECTORY_SEPARATOR, $class);
40 93
41 - /**
42 - * Constructor
43 - *
44 - * This constructor attaches the needer plugin hook callbacks
45 - */
46 - function cryptX() {
94 + // Build the full path
95 + $file = CRYPTX_DIR_PATH . 'classes' . DIRECTORY_SEPARATOR . $class . '.php';
47 96
48 - global $cryptX_var;
97 + // Include the file if it exists
98 + if (file_exists($file)) {
99 + require_once $file;
100 + }
101 +});
49 102
50 - // attach the converstion handlers
51 - //
52 - if (@$cryptX_var[theContent]) {
53 - if (@$cryptX_var[java]) {
54 - add_filter('the_content',
55 - array(&$this, '_encrypt'));
56 - } else {
57 - add_filter('the_content',
58 - array(&$this, '_unicode'));
59 - }
60 - }
61 - if (@$cryptX_var[theExcerpt]) {
62 - if (@$cryptX_var[java]) {
63 - add_filter('the_content',
64 - array(&$this, '_encrypt'));
65 - } else {
66 - add_filter('the_content',
67 - array(&$this, '_unicode'));
68 - }
69 - }
103 +// Initialize the plugin
104 +add_action('plugins_loaded', function() {
105 + // Check if all required classes can be loaded
106 + $requiredClasses = [
107 + 'CryptX\\CryptX',
108 + 'CryptX\\Config',
109 + 'CryptX\\CryptXSettingsTabs',
110 + 'CryptX\\SecureEncryption',
111 + 'CryptX\\Admin\\ChangelogSettingsTab',
112 + 'CryptX\\Admin\\GeneralSettingsTab',
113 + 'CryptX\\Admin\\PresentationSettingsTab',
114 + 'CryptX\\Util\\DataSanitizer',
115 + ];
70 116
71 - // attach to admin menu
72 - //
73 - if (is_admin()) {
74 - add_action('admin_menu',
75 - array(&$this, '_menu')
76 - );
77 - }
117 + $missingClasses = [];
118 + foreach ($requiredClasses as $class) {
119 + if (!class_exists($class)) {
120 + $missingClasses[] = $class;
121 + }
122 + }
78 123
79 - // attach to plugin installation
80 - //
81 - add_action(
82 - 'activate_' . str_replace(
83 - DIRECTORY_SEPARATOR, '/',
84 - str_replace(
85 - realpath(ABSPATH . PLUGINDIR) . DIRECTORY_SEPARATOR,
86 - '', __FILE__
87 - )
88 - ),
89 - array(&$this, '_install')
90 - );
124 + if (!empty($missingClasses)) {
125 + add_action('admin_notices', function() use ($missingClasses) {
126 + echo '<div class="notice notice-error"><p>';
127 + echo esc_html__('CryptX: Missing required classes: ', 'cryptx') . implode(', ', $missingClasses);
128 + echo '</p></div>';
129 + });
130 + return;
131 + }
91 132
92 - // attach javascript to Header
93 - //
94 - if (@$cryptX_var[java]) {
95 - add_action(
96 - 'wp_head',
97 - array(&$this, '_header')
98 - );
99 - }
133 + // Initialize the main plugin class
134 + try {
135 + $cryptx_instance = CryptX\CryptX::get_instance();
136 + $cryptx_instance->startCryptX();
137 + } catch (Exception $e) {
138 + add_action('admin_notices', function() use ($e) {
139 + echo '<div class="notice notice-error"><p>';
140 + echo esc_html__('CryptX initialization failed: ', 'cryptx') . esc_html($e->getMessage());
141 + echo '</p></div>';
142 + });
143 + }
144 +});
100 145
101 - } // End function
146 +// Remove the strict activation requirements - let the plugin handle fallbacks
147 +register_activation_hook(__FILE__, function() {
148 + // Just flush rewrite rules
149 + flush_rewrite_rules();
150 +});
102 151
103 - // -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
152 +// Plugin deactivation hook
153 +register_deactivation_hook(__FILE__, function() {
154 + // Clean up any transients or cached data
155 + global $wpdb;
156 + $wpdb->query("DELETE FROM {$wpdb->options} WHERE option_name LIKE '_transient_cryptx_%'");
157 + $wpdb->query("DELETE FROM {$wpdb->options} WHERE option_name LIKE '_transient_timeout_cryptx_%'");
158 +});
104 159
105 - /**
106 - * Wrap _encrypt
107 - * @param string $content
108 - * @return string
109 - */
110 - function _encrypt($content)
111 - {
112 - global $cryptX_var;
160 +// Add plugin action links - updated to match the settings page slug
161 +add_filter('plugin_action_links_' . plugin_basename(__FILE__), function($links) {
162 + $settings_link = '<a href="' . admin_url('options-general.php?page=cryptx') . '">' .
163 + esc_html__('Settings', 'cryptx') . '</a>';
164 + array_unshift($links, $settings_link);
165 + return $links;
166 +});
113 167
114 - preg_match_all('/<a[^>]*href=["|\'](.*)["|\']*>(.*)<\/a>/iUs', $content, $links, PREG_SET_ORDER);
115 -
116 - foreach( $links as $link ) {
117 -
118 - if(preg_match('/mailto:(.*)/', $link[1], $mail)) {
119 - $crypt = '';
120 - $ascii = 0;
121 - for ($i = 0; $i < strlen( $mail[1] ); $i++) {
122 - $ascii = ord ( substr ( $mail[1], $i ) );
123 - if (8364 <= $char) {
124 - $ascii = 128;
125 - }
126 - $crypt .= chr($ascii + 1);
127 - }
128 - $content = str_replace( $link[1], "javascript:DeCryptX('" . $crypt . "')", $content);
129 - $new_mail = str_replace( "@", $cryptX_var[at], $link[2]);
130 - $new_mail = str_replace( ".", $cryptX_var[dot], $new_mail);
131 - $content = str_replace( $link[2], $new_mail, $content);
132 - }
133 -
134 - } // foreach
135 - return $content;
136 - }
137 -
138 - // -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
139 -
140 - /**
141 - * Wrap _unicode
142 - * @param string $content
143 - * @return string
144 - */
145 - function _unicode($content)
146 - {
147 - global $cryptX_var;
148 -
149 - preg_match_all('/<a[^>]*href=["|\'](.*)["|\']*>(.*)<\/a>/iUs', $content, $links, PREG_SET_ORDER);
150 -
151 - foreach( $links as $link ) {
152 -
153 - if(preg_match('/mailto:(.*)/', $link[1], $mail)) {
154 - $mailto = "mailto:" . $mail[1];
155 - $crypt = '';
156 - for ($i = 0; $i < strlen( $mailto ); $i++) {
157 - $crypt .= "&#".ord ( substr ( $mailto, $i ) );
158 - }
159 - $content = str_replace( $mailto, $crypt, $content);
160 - $new_mail = str_replace( "@", $cryptX_var[at], $link[2]);
161 - $new_mail = str_replace( ".", $cryptX_var[dot], $new_mail);
162 - $content = str_replace( $link[2], $new_mail, $content);
163 - }
164 -
165 - } // foreach
166 - return $content;
167 - }
168 -
169 - // -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
170 -
171 - /**
172 - * Performs the routines required at plugin installation:
173 - * in general introducing the settings array
174 - */
175 - function _install() {
176 - add_option(
177 - 'cryptX',
178 - array(
179 - 'at' => ' [at] ',
180 - 'dot' => ' [dot] ',
181 - 'theContent' => 1,
182 - 'theExcerpt' => 0,
183 - 'java' => 1,
184 - )
185 - );
186 - }
187 -
188 - // -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
189 -
190 - /**
191 - * Attach the menu page to the `Options` tab
192 - */
193 - function _header()
194 - {
195 - $cryptX_script.= "<script type=\"text/javascript\" src=\"" . get_option('siteurl') . '/' . PLUGINDIR . '/' . dirname(plugin_basename (__FILE__)) . "/js/cryptx.js\"></script>\n";
196 - print($cryptX_script);
197 - }
198 -
199 - // -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
200 -
201 - /**
202 - * Attach the menu page to the `Options` tab
203 - */
204 - function _menu() {
205 - add_submenu_page('options-general.php',
206 - 'CryptX',
207 - 'CryptX', 9,
208 - __FILE__,
209 - array($this, '_submenu')
210 - );
211 - }
212 -
213 - /**
214 - * Handles and renders the menu page
215 - */
216 - function _submenu() {
217 - global $cryptX_var;
218 -
219 - // sanitize referrer
220 - //
221 - $_SERVER['HTTP_REFERER'] = preg_replace(
222 - '~&saved=.*$~Uis','', $_SERVER['HTTP_REFERER']
223 - );
224 -
225 - // information updated ?
226 - //
227 - if ($_POST['submit']) {
228 -
229 - // save
230 - //
231 - update_option(
232 - 'cryptX',
233 - $_POST['cryptX_var']
234 - );
235 -
236 - die("<script>document.location.href = '{$_SERVER['HTTP_REFERER']}&saved=settings:" . time() . "';</script>");
237 - }
238 -
239 - // operation report detected
240 - //
241 - if (@$_GET['saved']) {
242 -
243 - list($saved, $ts) = explode(':', $_GET['saved']);
244 - if (time() - $ts < 10) {
245 - echo '<div id="message" class="updated fade"><p><strong>';
246 -
247 - switch ($saved) {
248 - case 'settings' :
249 - echo 'Settings saved.';
250 - break;
251 - }
252 -
253 - echo '</strong></p></div>';
254 - }
255 - }
256 -
257 - // read the settings
258 - //
259 - //$cryptX = (array) get_option('cryptX');
260 -
261 -?>
262 -<!-- Start Optionen im Adminbereich (xhtml, au�erhalb PHP) -->
263 -<div class="wrap">
264 - <h2><?php _e("CryptX Options...",'cryptx'); ?></h2>
265 - <form method="post">
266 - <blockquote>
267 - <table>
268 - <tr>
269 - <td valign="top"><?php _e("Replacement for '@'",'cryptx'); ?>
270 - <input name="cryptX_var[at]" value="<?php echo $cryptX_var[at]; ?>" type="text" /></td>
271 - </tr>
272 - <tr>
273 - <td valign="top"><?php _e("Replacement for '.'",'cryptx'); ?>
274 - <input name="cryptX_var[dot]" value="<?php echo $cryptX_var[dot]; ?>" type="text" /></td>
275 - </tr>
276 - <tr>
277 - <td valign="top"><input name="cryptX_var[theContent]" <?php echo ($cryptX_var[theContent]) ? 'checked="checked"' : ''; ?> type="checkbox" />
278 - <?php _e("Apply CryptX to the Content",'cryptx'); ?></td>
279 - </tr>
280 - <tr>
281 - <td valign="top"><input name="cryptX_var[theExcerpt]" <?php echo ($cryptX_var[theExcerpt]) ? 'checked="checked"' : ''; ?> type="checkbox" />
282 - <?php _e("Apply CryptX to the Excerpt",'cryptx'); ?></td>
283 - </tr>
284 - <tr>
285 - <td valign="top">
286 - <input name="cryptX_var[java]" <?php echo ($cryptX_var[java]) ? 'checked="checked"' : ''; ?> type="radio" value="1" />
287 - <?php _e("Use javascript to hide the Email-Link.",'cryptx'); ?><br />
288 - <input name="cryptX_var[java]" <?php echo (!$cryptX_var[java]) ? 'checked="checked"' : ''; ?> type="radio" value="0" />
289 - <?php _e("Use Unicode to hide the Email-Link.",'cryptx'); ?>
290 - </td>
291 - </tr>
292 - <tr>
293 - <td><input type="submit" name="submit" value="Update &raquo;" /></td>
294 - </tr>
295 - </table>
296 - </blockquote>
297 - </form>
298 -</div>
299 -<?php
300 - }
301 -
302 - // -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
303 -
304 -
305 - //--end-of-class
306 - }
307 -
308 -}
309 -
310 -/////////////////////////////////////////////////////////////////////////////
311 -
312 168 /**
313 -* Initiating the plugin...
314 -* @see cryptX
315 -*/
316 -new cryptX;
169 + * Encrypts the given content using the CryptX library and wraps it with a shortcode.
170 + *
171 + * @param string $content The content to be encrypted.
172 + * @param array|null $args Optional arguments to customize the encryption process.
173 + *
174 + * @return string The encrypted content wrapped in the appropriate shortcode.
175 + */
176 +if (!function_exists('encryptx')) {
177 + function encryptx(string $content, ?array $args = []): string {
178 + $cryptXInstance = Cryptx\CryptX::get_instance();
179 + $attributesString = $cryptXInstance->convertArrayToArgumentString($args);
180 + $shortcode = '[cryptx' . $attributesString . ']' . $content . '[/cryptx]';
317 181
318 -?>
182 + return do_shortcode($shortcode);
183 + }
184 +}