* @license http://opensource.org/licenses/gpl-license.php GNU Public License */ Class cryptX { // -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- /** * Constructor * * This constructor attaches the needer plugin hook callbacks */ function cryptX() { global $cryptX_var; // attach the converstion handlers // if (@$cryptX_var[theContent]) { $this->filter('the_content'); } if (@$cryptX_var[theExcerpt]) { $this->filter('the_excerpt'); } if (@$cryptX_var[commentText]) { $this->filter('comment_text'); } if (@$cryptX_var[widgetText]) { $this->filter('widget_text'); } // attach to admin menu // if (is_admin()) { add_action('admin_menu', array(&$this, 'menu') ); } // attach to plugin installation // add_action( 'activate_' . str_replace( DIRECTORY_SEPARATOR, '/', str_replace( realpath(ABSPATH . PLUGINDIR) . DIRECTORY_SEPARATOR, '', __FILE__ ) ), array(&$this, 'install') ); // attach javascript to Header // if (@$cryptX_var[java]) { add_action( 'wp_head', array(&$this, 'header') ); } add_action('admin_menu', array(&$this, 'cryptx_meta_box') ); add_action('wp_insert_post', array(&$this, 'cryptx_insert_post') ); add_action('wp_update_post', array(&$this, 'cryptx_insert_post') ); } // End function // -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- function filter($apply) { global $cryptX_var, $shortcode_tags; if (@$cryptX_var[autolink]) { add_filter($apply, array(&$this, 'autolink'), 5); } if (!empty($shortcode_tags) || is_array($shortcode_tags)) { add_filter($apply, array(&$this, 'autolink'), 11); } add_filter($apply, array($this, 'encryptx'), 12); add_filter($apply, array($this, 'linktext'), 13); } // -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- function linktext($content) { global $post; $cryptxoff = false; $cryptxoffmeta = get_post_meta($post->ID,'cryptxoff',true); if ($cryptxoffmeta == "true") { $cryptxoff = true; } if ($cryptxoff == false) { $content = preg_replace_callback("/([_a-zA-Z0-9-]+(\.[_a-zA-Z0-9-]+)*@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*(\.[a-zA-Z]{2,}))/i", array(get_class($this), '_Linktext'), $content ); } return $content; } function _linktext($Match) { global $cryptX_var; switch ($cryptX_var[opt_linktext]) { case 1: // alternative text for mail link $linktext = $cryptX_var[alt_linktext]; break; case 2: // alternative image for mail link $linktext = "\"""; break; case 3: // uploaded image for mail link $imgurl = "/" . PLUGINDIR . "/" . dirname(plugin_basename (__FILE__)) . "/images/" . $cryptX_var[alt_uploadedimage]; $linktext = "\"""; break; case 4: // text scrambled by antispambot $linktext = antispambot($Match[1]); break; default: $linktext = str_replace( "@", $cryptX_var[at], $Match[1]); $linktext = str_replace( ".", $cryptX_var[dot], $linktext); } return $linktext; } // -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- function _dirImages() { $dir = $_SERVER["DOCUMENT_ROOT"].'/'.PLUGINDIR.'/'.dirname(plugin_basename (__FILE__)).'/images'; $fh = opendir($dir); //Verzeichnis $verzeichnisinhalt = array(); while (true == ($file = readdir($fh))) { if ((substr(strtolower($file), -3)=="jpg") or (substr(strtolower($file), -3)=="gif")) { $verzeichnisinhalt[] = $file; } } return $verzeichnisinhalt; } // -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- function encryptx($content) { global $post; $cryptxoff = false; $cryptxoffmeta = get_post_meta($post->ID,'cryptxoff',true); if ($cryptxoffmeta == "true") { $cryptxoff = true; } if ($cryptxoff == false) { $content = preg_replace_callback('/(.*?)<\/a>/i', array(get_class($this), 'mailtocrypt'), $content ); } return $content; } function mailtocrypt($Match) { global $cryptX_var; $return = $Match[0]; $mailto = "mailto:" . $Match[4]; //* If mailto contains no email adress, like a link from "Sociable" do nothing *// if (substr($Match[4], 0, 9) =="?subject=") return $return; if (@$cryptX_var[java]) { $crypt = ''; $ascii = 0; for ($i = 0; $i < strlen( $Match[4] ); $i++) { $ascii = ord ( substr ( $Match[4], $i ) ); if (8364 <= $char) { $ascii = 128; } $crypt .= chr($ascii + 1); } $javascript="javascript:DeCryptX('" . $crypt . "')"; $return = str_replace( "mailto:".$Match[4], $javascript, $return); } else { $return = str_replace( $mailto, antispambot($mailto), $return); } return $return; } // -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- function autolink($content) { $src[]="/([\s])([_a-zA-Z0-9-]+(\.[_a-zA-Z0-9-]+)*@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*(\.[a-zA-Z]{2,}))/si"; $src[]="/(>)([_a-zA-Z0-9-]+(\.[_a-zA-Z0-9-]+)*@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*(\.[a-zA-Z]{2,}))(<)/si"; $src[]="/(>)([_a-zA-Z0-9-]+(\.[_a-zA-Z0-9-]+)*@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*(\.[a-zA-Z]{2,}))([\s])/si"; $src[]="/([\s])([_a-zA-Z0-9-]+(\.[_a-zA-Z0-9-]+)*@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*(\.[a-zA-Z]{2,}))(<)/si"; $src[]="/^([_a-zA-Z0-9-]+(\.[_a-zA-Z0-9-]+)*@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*(\.[a-zA-Z]{2,}))/si"; $src[]="/(]*>)]*>/"; $src[]="/(<\/A>)<\/A>/i"; $tar[]="\\1\\2"; $tar[]="\\1\\2\\6"; $tar[]="\\1\\2\\6"; $tar[]="\\1\\2\\6"; $tar[]="\\0"; $tar[]="\\1"; $tar[]="\\1"; $content = preg_replace($src,$tar,$content); return $content; } // -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- function install() { add_option( 'cryptX', array( 'at' => ' [at] ', 'dot' => ' [dot] ', 'theContent' => 1, 'theExcerpt' => 0, 'commentText' => 1, 'widgetText' => 0, 'java' => 1, 'opt_linktext' => 0, ) ); } // -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- /** * Attach the menu page to the `Options` tab */ function header() { $cryptX_script.= "\n"; print($cryptX_script); } // -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- function cryptx_meta() { global $post; $cryptxoff = false; $cryptxoffmeta = get_post_meta($post->ID,'cryptxoff',true); if ($cryptxoffmeta == "true") { $cryptxoff = true; } ?> /> Disable CryptX ID,'cryptxoff',true); if ($cryptxoffmeta == "true") { $cryptxoff = true; } if ( current_user_can('edit_posts') ) { ?>

CryptX

/> CryptX disabled?
') ? 'CryptX Icon' : ''). 'CryptX', 9, __FILE__, array( $this, '_submenu' ) ); } /** * Handles and renders the menu page */ function _submenu() { global $cryptX_var; if (isset($_POST) && !empty($_POST)) { if (function_exists('current_user_can') === true && (current_user_can('manage_options') === false || current_user_can('edit_plugins') === false)) { wp_die("You don't have permission to access!"); } check_admin_referer('cryptX'); update_option( 'cryptX', $_POST['cryptX_var']); $cryptX_var = (array) get_option('cryptX'); // reread Options ?>

')) { ?>

CryptX

/>
 
/>
/>
 
/>   
 
/> Try it and look at your site and check the html source!)",'cryptx'); ?>

type="checkbox" />   this can be disabled per Post by an Option)",'cryptx'); ?>
type="checkbox" />  
type="checkbox" />  
type="checkbox" />   works only on all widgets, not on a single widget!)",'cryptx'); ?>
type="radio" value="1" />  
type="radio" value="0" />  
type="checkbox" />  

In your Template you can use the following function to encrypt a email address:

<?php
     $mail="name@example.com";
     $text="Contact";
     $css ="email";
     if (function_exists('cryptx')) {
         cryptx($mail, $text, $css, 1);
     } else {
         echo sprintf('<a href="mailto:%s" class="%s">%s</a>', $mail, $css, ($text != "" ? $text : $mail));
     }
?>

  1. parameter is the email address.
  2. parameter is the linktext. If none given the email address is used.
  3. parameter is a css class added to the link.
  4. parameter is 1 for echo the encrypted email address or 0 to return the redult to a variable.

Ralf Weber | %6$s
', __('Plugin'), 'CryptX', __('Version'), $data['Version'], __('Author'), __('Follow on Twitter', 'cryptx')); ?>
autolink( $content ); $content = $cryptX->encryptx( $content ); if("" != $text) { $content = preg_replace( "/(]*>)(.*)(<\/a>)/i", '$1'.$text.'$3', $content ); } if("" != $css) { $content = preg_replace( "/(]*)(>)/i", '$1 class="'.$css.'"$2', $content ); } if(1 == $echo) echo $content; return $content; } ?>