| 1 |
<?php |
| 2 |
/* |
| 3 |
Plugin Name: CryptX |
| 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 |
| 7 |
Author: Ralf Weber |
| 8 |
Author URI: http://weber-nrw.de/ |
| 9 |
Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=4026696 |
| 10 |
*/ |
| 11 |
/** |
| 12 |
* "CryptX" WordPress Plugin |
| 13 |
* |
| 14 |
* @author Ralf Weber <ralf@weber-nrw.de> |
| 15 |
* @license http://opensource.org/licenses/gpl-license.php GNU Public License |
| 16 |
*/ |
| 17 |
|
| 18 |
/** |
| 19 |
* Don't load this file direct! |
| 20 |
*/ |
| 21 |
if (!defined('ABSPATH')) { |
| 22 |
return ; |
| 23 |
} |
| 24 |
|
| 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(); |
| 37 |
|
| 38 |
foreach($cryptX_var['filter'] as $filter) { |
| 39 |
if (@$cryptX_var[$filter]) { |
| 40 |
rw_cryptx_filter($filter); |
| 41 |
} |
| 42 |
} |
| 43 |
|
| 44 |
add_action( 'activate_' . plugin_basename( __FILE__ ), 'rw_cryptx_install' ); |
| 45 |
|
| 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 |
} |
| 53 |
|
| 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 |
} |
| 59 |
|
| 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 |
} |
| 65 |
|
| 66 |
add_filter( 'init', 'rw_cryptx_init_tinyurl'); |
| 67 |
add_action( 'parse_request', 'rw_cryptx_parse_request'); |
| 68 |
|
| 69 |
add_shortcode( 'cryptx', 'rw_cryptx_shortcode'); |
| 70 |
|
| 71 |
|
| 72 |
/** |
| 73 |
* New Template functions... |
| 74 |
* $content = string to convert |
| 75 |
* $args = string/array with the following parameters |
| 76 |
* array('text' => "", 'css_class' => "", 'css_id' => "", 'echo' => 1) |
| 77 |
* or |
| 78 |
* "text=&css_class=&css_id=&echo=1" |
| 79 |
*/ |
| 80 |
function encryptx( $content, $args="" ) { |
| 81 |
global $cryptX_var; |
| 82 |
|
| 83 |
$is_shortcode = true; |
| 84 |
|
| 85 |
// Parse incomming $args into an array and merge it with $defaults |
| 86 |
$encryptx_vars = rw_loadDefaults( $args ); |
| 87 |
|
| 88 |
// OPTIONAL: Declare each item in $args as its own variable i.e. $type, $before. |
| 89 |
// extract( $args, EXTR_SKIP ); |
| 90 |
|
| 91 |
$tmp = explode("?", $content); |
| 92 |
$content = $tmp[0]; |
| 93 |
$params = (!empty($tmp[1]))? $tmp[1] : ''; |
| 94 |
if($encryptx_vars['autolink']) { |
| 95 |
$content = rw_cryptx_autolink( $content, true ); |
| 96 |
if (!empty($params)) { |
| 97 |
$content = preg_replace( '/(.*\")(.*)(\".*>)(.*)(<\/a>)/i', '$1$2?'.$params.'$3$4$5', $content ); |
| 98 |
} |
| 99 |
} |
| 100 |
$content = rw_cryptx_encryptx( $content, true ); |
| 101 |
$content = rw_cryptx_linktext( $content, true ); |
| 102 |
if(!empty($encryptx_vars['text'])) { |
| 103 |
$content = preg_replace( '/(.*">)(.*)(<.*)/i', '$1'.$encryptx_vars['text'].'$3', $content ); |
| 104 |
} |
| 105 |
if(!empty($encryptx_vars['css_id'])) { |
| 106 |
$content = preg_replace( '/(.*)(">)/i', '$1" id="'.$encryptx_vars['css_id'].'">', $content ); |
| 107 |
} |
| 108 |
if(!empty($encryptx_vars['css_class'])) { |
| 109 |
$content = preg_replace( '/(.*)(">)/i', '$1" class="'.$encryptx_vars['css_class'].'">', $content ); |
| 110 |
} |
| 111 |
|
| 112 |
$is_shortcode = false; |
| 113 |
|
| 114 |
if(!$encryptx_vars['echo']) |
| 115 |
return $content; |
| 116 |
|
| 117 |
echo $content; |
| 118 |
|
| 119 |
} |
| 120 |
|
| 121 |
/** |
| 122 |
* Template function that encrypt the get_post_meta result |
| 123 |
* call it with the default get_post_meta parameters |
| 124 |
**/ |
| 125 |
function get_encryptx_meta( $post_id, $key, $single=false ) { |
| 126 |
|
| 127 |
$values = get_post_meta( $post_id, $key, $single ); |
| 128 |
|
| 129 |
if(is_array($values)) { |
| 130 |
$return = array(); |
| 131 |
foreach( $values as $value) { |
| 132 |
$return[] = encryptx($value, array('echo' => 0)); |
| 133 |
} |
| 134 |
} else { |
| 135 |
$return = encryptx($values, array('echo' => 0)); |
| 136 |
} |
| 137 |
|
| 138 |
return $return; |
| 139 |
|
| 140 |
} |
| 141 |
|
| 142 |
/** |
| 143 |
* Create Template functions... |
| 144 |
* $content = string to convert |
| 145 |
* $text = string to replace linktext |
| 146 |
* $css_class = assign a css class to the link |
| 147 |
* $echo = 0: keep result in a variable, 1: show result |
| 148 |
* $css_id = assign a css id to the link |
| 149 |
*/ |
| 150 |
function cryptx( $content, $text="", $css_class="", $echo=1, $css_id="" ) { |
| 151 |
global $cryptX_var; |
| 152 |
$tmp = explode("?", $content); |
| 153 |
$content = $tmp[0]; |
| 154 |
$params = (count($tmp) > 1)? $tmp[1] : ''; |
| 155 |
$content = rw_cryptx_autolink( $content, true ); |
| 156 |
if (!empty($params)) { |
| 157 |
$content = preg_replace( '/(.*\")(.*)(\".*>)(.*)(<\/a>)/i', '$1$2?'.$params.'$3$4$5', $content ); |
| 158 |
} |
| 159 |
$content = rw_cryptx_encryptx( $content, true ); |
| 160 |
$content = rw_cryptx_linktext( $content, true ); |
| 161 |
if("" != $text) { |
| 162 |
$content = preg_replace( '/(.*">)(.*)(<.*)/i', '$1'.$text.'$3', $content ); |
| 163 |
} |
| 164 |
if("" != $css_id) { |
| 165 |
$content = preg_replace( '/(.*)(">)/i', '$1" id="'.$css_id.'">', $content ); |
| 166 |
} |
| 167 |
if("" != $css_class) { |
| 168 |
$content = preg_replace( '/(.*)(">)/i', '$1" class="'.$css_class.'">', $content ); |
| 169 |
} |
| 170 |
if(1 == $echo) echo $content; |
| 171 |
return $content; |
| 172 |
} |
| 173 |
?> |