* @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'); } // 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') ); } } // End function // -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- /** * Wrap _filter * @param string $content * @return string */ function _filter($apply) { global $cryptX_var; if (@$cryptX_var[autolink]) { add_filter($apply, array(&$this, '_autolink')); } if (@$cryptX_var[java]) { add_filter($apply, array(&$this, '_encrypt')); } else { add_filter($apply, array(&$this, '_unicode')); } } // -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- /** * Wrap _encrypt * @param string $content * @return string */ function _encrypt($content) { global $cryptX_var; preg_match_all('/]*href=["|\'](.*)["|\'].*>(.*)<\/a>/iUs', $content, $links, PREG_SET_ORDER); foreach( $links as $link ) { if(preg_match('/mailto:(.*)/', $link[1], $mail)) { $crypt = ''; $ascii = 0; for ($i = 0; $i < strlen( $mail[1] ); $i++) { $ascii = ord ( substr ( $mail[1], $i ) ); if (8364 <= $char) { $ascii = 128; } $crypt .= chr($ascii + 1); } $temp = str_replace( $link[1], "javascript:DeCryptX('" . $crypt . "')", $link[0]); $new_mail = str_replace( "@", $cryptX_var[at], $link[2]); $new_mail = str_replace( ".", $cryptX_var[dot], $new_mail); $temp = str_replace( $link[2], $new_mail, $temp); $content = str_replace( $link[0], $temp, $content); } } // foreach return $content; } // -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- /** * Wrap _unicode * @param string $content * @return string */ function _unicode($content) { global $cryptX_var; preg_match_all('/]*href=["|\'](.*)["|\'].*>(.*)<\/a>/iUs', $content, $links, PREG_SET_ORDER); foreach( $links as $link ) { if(preg_match('/mailto:(.*)/', $link[1], $mail)) { $mailto = "mailto:" . $mail[1]; $crypt = ''; for ($i = 0; $i < strlen( $mailto ); $i++) { $crypt .= "" . ord ( substr ( $mailto, $i ) ) . ";"; } $content = str_replace( $mailto, $crypt, $content); $new_mail = str_replace( "@", $cryptX_var[at], $link[2]); $new_mail = str_replace( ".", $cryptX_var[dot], $new_mail); $content = str_replace( $link[2], $new_mail, $content); } } // foreach return $content; } // -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 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,}))/si"; $src[]="/(]*>)]*>/"; $src[]="/(<\/A>)<\/A>/i"; $tar[]="\\1\\2"; $tar[]="\\1\\2\\6"; $tar[]="\\0"; $tar[]="\\1"; $tar[]="\\1"; $content = preg_replace($src,$tar,$content); return $content; } // -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- /** * Performs the routines required at plugin installation: * in general introducing the settings array */ function _install() { add_option( 'cryptX', array( 'at' => ' [at] ', 'dot' => ' [dot] ', 'theContent' => 1, 'theExcerpt' => 0, 'java' => 1, ) ); } // -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- /** * Attach the menu page to the `Options` tab */ function _header() { $cryptX_script.= "\n"; print($cryptX_script); } // -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- /** * Attach the menu page to the `Options` tab */ function _menu() { add_submenu_page('options-general.php', 'CryptX', 'CryptX', 9, __FILE__, array($this, '_submenu') ); } /** * Handles and renders the menu page */ function _submenu() { global $cryptX_var; // sanitize referrer // $_SERVER['HTTP_REFERER'] = preg_replace( '~&saved=.*$~Uis','', $_SERVER['HTTP_REFERER'] ); // information updated ? // if ($_POST['submit']) { // save // update_option( 'cryptX', $_POST['cryptX_var'] ); die(""); } // operation report detected // if (@$_GET['saved']) { list($saved, $ts) = explode(':', $_GET['saved']); if (time() - $ts < 10) { echo '
'; switch ($saved) { case 'settings' : echo 'Settings saved.'; break; } echo '