PluginProbe
CryptX / 3.2.3
CryptX v3.2.3
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 +111 -276 1.03.2.3 View file →
@@ -1,318 +1,153 @@
1 1 <?php
2 2 /*
3 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
4 +Plugin URI: http://weber-nrw.de/wordpress/cryptx/
5 +Description: No more SPAM by spiders scanning you site for email adresses. With CryptX you can hide all your email adresses, with and without a mailto-link, by converting them using javascript or UNICODE. Although you can choose to add a mailto-link to all unlinked email adresses with only one klick at the settings. That's great, isn't it?
6 +Version: 3.2.3
7 7 Author: Ralf Weber
8 8 Author URI: http://weber-nrw.de/
9 +Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=4026696
9 10 */
10 -
11 -/////////////////////////////////////////////////////////////////////////////
12 -
13 11 /**
14 -* @internal prevent from direct calls
15 -*/
16 -if (!defined('ABSPATH')) {
17 - return ;
18 - }
19 -
20 -/**
21 -* @internal prevent from second inclusion
22 -*/
23 -if (!class_exists('cryptX')) {
24 -
25 -/////////////////////////////////////////////////////////////////////////////
26 -
27 -load_plugin_textdomain('cryptx', PLUGINDIR . '/' . dirname(plugin_basename (__FILE__)) );
28 -
29 -$cryptX_var = (array) get_option('cryptX');
30 -
31 -/**
32 12 * "CryptX" WordPress Plugin
33 13 *
34 14 * @author Ralf Weber <ralf@weber-nrw.de>
35 15 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
36 16 */
37 -Class cryptX {
38 17
39 - // -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
18 +//avoid direct calls to this file, because now WP core and framework has been used
19 +if ( ! function_exists('add_action') ) {
20 + header('Status: 403 Forbidden');
21 + header('HTTP/1.1 403 Forbidden');
22 + exit();
23 +}
40 24
41 - /**
42 - * Constructor
43 - *
44 - * This constructor attaches the needer plugin hook callbacks
45 - */
46 - function cryptX() {
25 +/**
26 + * some basics
27 + */
28 +global $wp_version;
29 +define( 'CRYPTX_BASENAME', plugin_basename( __FILE__ ) );
30 +define( 'CRYPTX_BASEFOLDER', plugin_basename( dirname( __FILE__ ) ) );
31 +define( 'CRYPTX_FILENAME', str_replace( CRYPTX_BASEFOLDER.'/', '', plugin_basename(__FILE__) ) );
32 +load_plugin_textdomain('cryptx', false, 'cryptx/languages/');
33 +require_once(plugin_dir_path( __FILE__ ) . 'functions.php');
34 +require_once(plugin_dir_path( __FILE__ ) . 'classes.php');
35 +require_once(plugin_dir_path( __FILE__ ) . 'admin.php');
36 +$cryptX_var = rw_loadDefaults();
47 37
48 - global $cryptX_var;
38 +foreach($cryptX_var['filter'] as $filter) {
39 + if (@$cryptX_var[$filter]) {
40 + rw_cryptx_filter($filter);
41 + }
42 +}
49 43
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 - }
44 +add_action( 'activate_' . plugin_basename( __FILE__ ), 'rw_cryptx_install' );
70 45
71 - // attach to admin menu
72 - //
73 - if (is_admin()) {
74 - add_action('admin_menu',
75 - array(&$this, '_menu')
76 - );
77 - }
46 +if (@$cryptX_var['java']) {
47 + if (@$cryptX_var['load_java']) {
48 + add_action( 'wp_footer', 'rw_cryptx_header', 9 );
49 + } else {
50 + add_action( 'wp_head', 'rw_cryptx_header', 9 );
51 + }
52 +}
78 53
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 - );
54 +if (@$cryptX_var['metaBox']) {
55 + add_action('admin_menu', 'rw_cryptx_meta_box');
56 + add_action('wp_insert_post', 'rw_cryptx_insert_post' );
57 + add_action('wp_update_post', 'rw_cryptx_insert_post' );
58 +}
91 59
92 - // attach javascript to Header
93 - //
94 - if (@$cryptX_var[java]) {
95 - add_action(
96 - 'wp_head',
97 - array(&$this, '_header')
98 - );
99 - }
60 +if ( version_compare( $wp_version, '2.8', '>' ) ) {
61 + add_filter( 'plugin_row_meta', 'rw_cryptx_init_row_meta', 10, 2 ); // only 2.8 and higher
62 +} else {
63 + add_filter( 'plugin_action_links', 'rw_cryptx_init_row_meta', 10, 2 );
64 +}
100 65
101 - } // End function
66 +add_filter( 'init', 'rw_cryptx_init_tinyurl');
67 +add_action( 'parse_request', 'rw_cryptx_parse_request');
102 68
103 - // -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
69 +add_shortcode( 'cryptx', 'rw_cryptx_shortcode');
104 70
105 - /**
106 - * Wrap _encrypt
107 - * @param string $content
108 - * @return string
109 - */
110 - function _encrypt($content)
111 - {
112 - global $cryptX_var;
71 +/**
72 + * get CryptX Version
73 + */
74 +function rw_cryptx_version() {
75 + if ( ! function_exists( 'get_plugins' ) )
76 + require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
77 + $plugin_folder = get_plugins( '/' . plugin_basename( dirname( __FILE__ ) ) );
78 + $plugin_file = basename( ( __FILE__ ) );
79 + return $plugin_folder[$plugin_file]['Version'];
80 +}
113 81
114 - preg_match_all('/<a[^>]*href=["|\'](.*)["|\']*>(.*)<\/a>/iUs', $content, $links, PREG_SET_ORDER);
115 82
116 - foreach( $links as $link ) {
83 +/**
84 +* New Template functions...
85 +* $content = string to convert
86 +* $args = string/array with the following parameters
87 +* array('text' => "", 'css_class' => "", 'css_id' => "", 'echo' => 1)
88 +* or
89 +* "text=&css_class=&css_id=&echo=1"
90 +*/
91 +function encryptx( $content, $args="" ) {
92 + global $cryptX_var;
117 93
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 - }
94 + $is_shortcode = true;
133 95
134 - } // foreach
135 - return $content;
136 - }
96 + // Parse incomming $args into an array and merge it with $defaults
97 + $encryptx_vars = rw_loadDefaults( $args );
137 98
138 - // -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
99 + // OPTIONAL: Declare each item in $args as its own variable i.e. $type, $before.
100 + // extract( $args, EXTR_SKIP );
139 101
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;
102 + $tmp = explode("?", $content);
103 + $content = $tmp[0];
104 + $params = (!empty($tmp[1]))? $tmp[1] : '';
105 + if($encryptx_vars['autolink']) {
106 + $content = rw_cryptx_autolink( $content, true );
107 + if (!empty($params)) {
108 + $content = preg_replace( '/(.*\")(.*)(\".*>)(.*)(<\/a>)/i', '$1$2?'.$params.'$3$4$5', $content );
109 + }
167 110 }
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);
111 + $content = rw_cryptx_encryptx( $content, true );
112 + $content = rw_cryptx_linktext( $content, true );
113 + if(!empty($encryptx_vars['text'])) {
114 + $content = preg_replace( '/(.*">)(.*)(<.*)/i', '$1'.$encryptx_vars['text'].'$3', $content );
197 115 }
116 + if(!empty($encryptx_vars['css_id'])) {
117 + $content = preg_replace( '/(.*)(">)/i', '$1" id="'.$encryptx_vars['css_id'].'">', $content );
118 + }
119 + if(!empty($encryptx_vars['css_class'])) {
120 + $content = preg_replace( '/(.*)(">)/i', '$1" class="'.$encryptx_vars['css_class'].'">', $content );
121 + }
198 122
199 - // -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
123 + $is_shortcode = false;
200 124
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 - }
125 + if(!$encryptx_vars['echo'])
126 + return $content;
212 127
213 - /**
214 - * Handles and renders the menu page
215 - */
216 - function _submenu() {
217 - global $cryptX_var;
128 + echo $content;
218 129
219 - // sanitize referrer
220 - //
221 - $_SERVER['HTTP_REFERER'] = preg_replace(
222 - '~&saved=.*$~Uis','', $_SERVER['HTTP_REFERER']
223 - );
130 +}
224 131
225 - // information updated ?
226 - //
227 - if ($_POST['submit']) {
132 +/**
133 + * Template function that encrypt the get_post_meta result
134 + * call it with the default get_post_meta parameters
135 + **/
136 +function get_encryptx_meta( $post_id, $key, $single=false ) {
228 137
229 - // save
230 - //
231 - update_option(
232 - 'cryptX',
233 - $_POST['cryptX_var']
234 - );
138 + $values = get_post_meta( $post_id, $key, $single );
235 139
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
140 + if(is_array($values)) {
141 + $return = array();
142 + foreach( $values as $value) {
143 + $return[] = encryptx($value, array('echo' => 0));
300 144 }
145 + } else {
146 + $return = encryptx($values, array('echo' => 0));
147 + }
301 148
302 - // -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
149 + return $return;
303 150
304 -
305 - //--end-of-class
306 - }
307 -
308 151 }
309 152
310 -/////////////////////////////////////////////////////////////////////////////
311 -
312 -/**
313 -* Initiating the plugin...
314 -* @see cryptX
315 -*/
316 -new cryptX;
317 -
318 -?>
153 +?>