* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*/
if (!defined('ABSPATH')) {
return ;
}
define( 'CRYPTX_BASENAME', plugin_basename( __FILE__ ) );
define( 'CRYPTX_BASEFOLDER', plugin_basename( dirname( __FILE__ ) ) );
define( 'CRYPTX_FILENAME', str_replace( CRYPTX_BASEFOLDER.'/', '', plugin_basename(__FILE__) ) );
load_plugin_textdomain('cryptx', false, 'cryptx/languages/');
$cryptX_var = (array) get_option('cryptX');
global $cryptX_var, $wp_version;
if (@$cryptX_var['theContent']) {
rw_cryptx_filter('the_content');
}
if (@$cryptX_var['the_meta_key']) {
rw_cryptx_filter('the_meta_key');
}
if (@$cryptX_var['theExcerpt']) {
rw_cryptx_filter('the_excerpt');
}
if (@$cryptX_var['commentText']) {
rw_cryptx_filter('comment_text');
}
if (@$cryptX_var['widgetText']) {
rw_cryptx_filter('widget_text');
}
if (is_admin()) {
add_action('admin_menu', 'rw_cryptx_menu');
}
add_action( 'activate_' . str_replace( DIRECTORY_SEPARATOR, '/', str_replace( realpath(ABSPATH . PLUGINDIR) . DIRECTORY_SEPARATOR, '', __FILE__ ) ), 'rw_cryptx_install' );
if (@$cryptX_var['java']) {
if (@$cryptX_var['load_java']) {
add_action( 'wp_footer', 'rw_cryptx_header', 9 );
} else {
add_action( 'wp_head', 'rw_cryptx_header', 9 );
}
}
if (@$cryptX_var[metaBox]) {
add_action('admin_menu', 'rw_cryptx_meta_box');
add_action('wp_insert_post', 'rw_cryptx_insert_post' );
add_action('wp_update_post', 'rw_cryptx_insert_post' );
}
if ( version_compare( $wp_version, '2.8', '>' ) ) {
add_filter( 'plugin_row_meta', 'rw_cryptx_init_row_meta', 10, 2 ); // only 2.8 and higher
} else {
add_filter( 'plugin_action_links', 'rw_cryptx_init_row_meta', 10, 2 );
}
add_filter( 'init', 'rw_cryptx_init_tinyurl');
add_action( 'parse_request', 'rw_cryptx_parse_request');
add_shortcode( 'cryptx', 'rw_cryptx_shortcode');
function rw_cryptx_shortcode( $atts, $content=null) {
global $cryptX_var;
if (@$cryptX_var[autolink]) $content = rw_cryptx_autolink($content, true);
$content = rw_cryptx_encryptx($content, true);
$content = rw_cryptx_linktext($content, true);
return $content;
}
function rw_cryptx_parse_request( $wp ) {
if ( isset($_GET['cryptx']) ) {
switch( $_GET['cryptx'] ) {
case 'news':
include( 'ajax/news.php' );
break;
}
exit;
}
}
function rw_cryptx_init_tinyurl() {
global $cryptX_var;
$url = $_SERVER['REQUEST_URI'];
$params = explode( '/', $url );
if ( count( $params ) > 1 ) {
$tiny_url = $params[count( $params ) -2];
if ( $tiny_url == md5( get_bloginfo('url') ) ) {
$font = $cryptX_var['c2i_font'];
$msg = $params[count( $params ) -1];
$size = $cryptX_var['c2i_fontSize'];
$pad = 1;
$transparent = 1;
$red = hexdec(substr($cryptX_var['c2i_fontRGB'],0,2));
$grn = hexdec(substr($cryptX_var['c2i_fontRGB'],2,2));
$blu = hexdec(substr($cryptX_var['c2i_fontRGB'],4,2));
$bg_red = 255 - $red;
$bg_grn = 255 - $grn;
$bg_blu = 255 - $blu;
$width = 0;
$height = 0;
$offset_x = 0;
$offset_y = 0;
$bounds = array();
$image = "";
$bounds = ImageTTFBBox($size, 0, $font, "W");
$font_height = abs($bounds[7]-$bounds[1]);
$bounds = ImageTTFBBox($size, 0, $font, $msg);
$width = abs($bounds[4]-$bounds[6]);
$height = abs($bounds[7]-$bounds[1]);
$offset_y = $font_height+abs(($height - $font_height)/2)-1;
$offset_x = 0;
$image = imagecreatetruecolor($width+($pad*2),$height+($pad*2));
imagesavealpha($image, true);
$foreground = ImageColorAllocate($image, $red, $grn, $blu);
$background = imagecolorallocatealpha($image, 0, 0, 0, 127);
imagefill($image, 0, 0, $background);
ImageTTFText($image, $size, 0, $offset_x+$pad, $offset_y+$pad, $foreground, $font, $msg);
Header("Content-type: image/png");
imagePNG($image);
die;
}
}
}
function rw_cryptx_init_row_meta($links, $file) {
if (CRYPTX_BASENAME == $file) {
return array_merge(
$links,
array(
sprintf(
'%s',
CRYPTX_BASENAME,
__('Settings')
)
),
array(
sprintf(
'%s',
__('Donate', 'cryptx')
)
)
);
}
return $links;
}
function rw_cryptx_filter($apply) {
global $cryptX_var, $post, $shortcode_tags;
if (@$cryptX_var['autolink']) {
add_filter($apply, 'rw_cryptx_autolink', 5);
if (!empty($shortcode_tags) || is_array($shortcode_tags)) {
add_filter($apply, 'rw_cryptx_autolink', 11);
}
}
add_filter($apply, 'rw_cryptx_encryptx', 12);
add_filter($apply, 'rw_cryptx_linktext', 13);
}
function rw_cryptx_excluded($ID) {
global $cryptX_var;
$return = false;
$exIDs = explode(",", $cryptX_var['excludedIDs']);
if(in_array($ID, $exIDs) > 0 ) $return = true;
return $return;
}
function rw_cryptx_linktext($content, $shortcode=false) {
global $post;
if (!rw_cryptx_excluded($post->ID) OR $shortcode!=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", 'rw_cryptx_do_Linktext', $content );
}
return $content;
}
function rw_cryptx_do_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 = $cryptX_var['alt_uploadedimage'];
$linktext = "
";
break;
case 4: // text scrambled by antispambot
$linktext = antispambot($Match[1]);
break;
case 5: // convert to image
$linktext = "
";
break;
default:
$linktext = str_replace( "@", $cryptX_var['at'], $Match[1]);
$linktext = str_replace( ".", $cryptX_var['dot'], $linktext);
}
return $linktext;
}
function rw_cryptx_dirImages() {
$dir = plugin_dir_path( __FILE__ ).'images';
$fh = opendir($dir);
$verzeichnisinhalt = array();
while (true == ($file = readdir($fh)))
{
if ((substr(strtolower($file), -3)=="jpg") or (substr(strtolower($file), -3)=="gif"))
{
$verzeichnisinhalt[] = $file;
}
}
return $verzeichnisinhalt;
}
function rw_cryptx_dirFonts() {
$dir = plugin_dir_path( __FILE__ ).'fonts';
$fh = opendir($dir);
$verzeichnisinhalt = array();
while (true == ($file = readdir($fh)))
{
if ((substr(strtolower($file), -3)=="ttf") or (substr(strtolower($file), -3)=="ttf"))
{
$verzeichnisinhalt[] = $file;
}
}
return $verzeichnisinhalt;
}
function rw_cryptx_encryptx($content, $shortcode=false) {
global $post;
if (!rw_cryptx_excluded($post->ID) OR $shortcode!=false) {
$content = preg_replace_callback('/(.*?)<\/a>/i', 'rw_cryptx_mailtocrypt', $content );
}
return $content;
}
function rw_cryptx_mailtocrypt($Match) {
global $cryptX_var;
$return = $Match[0];
$mailto = "mailto:" . $Match[4];
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 <= $ascii) {
$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 rw_cryptx_autolink($content, $shortcode=false) {
global $post;
if (rw_cryptx_excluded($post->ID) AND $shortcode==false) return $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[]="/(>)([_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[]="\\1\\2\\6";
$tar[]="\\0";
$tar[]="\\1";
$tar[]="\\1";
$content = preg_replace($src,$tar,$content);
return $content;
}
function rw_cryptx_install() {
global $cryptX_var, $wpdb;
$firstImage = rw_cryptx_dirImages();
$firstFont = rw_cryptx_dirFonts();
$cryptX_var = (array) get_option('cryptX'); // reread Options
$defaults = array(
'at' => ' [at] ',
'dot' => ' [dot] ',
'theContent' => 1,
'the_meta_key' => 1,
'theExcerpt' => 0,
'commentText' => 1,
'widgetText' => 0,
'java' => 1,
'load_java' => 0,
'opt_linktext' => 0,
'autolink' => 1,
'alt_linktext' => '',
'alt_linkimage' => '',
'http_linkimage_title' => '',
'alt_linkimage_title' => '',
'excludedIDs' => '',
'metaBox' => 1,
'alt_uploadedimage' => plugins_url('cryptx/images/').$firstImage[0],
'c2i_font' => plugin_dir_path( __FILE__ ).'fonts/'.$firstFont[0],
'c2i_fontSize' => 10,
'c2i_fontRGB' => '000000'
);
$cryptX_var = $cryptX_var + $defaults;
if ($cryptX_var['excludedIDs'] == "") {
$tmp = array();
$excludes = $wpdb->get_results("SELECT post_id FROM $wpdb->postmeta WHERE meta_key = 'cryptxoff' AND meta_value = 'true'");
if(count($excludes) > 0) {
foreach ($excludes as $exclude) {
$tmp[] = $exclude->post_id;
}
sort($tmp);
$cryptX_var['excludedIDs'] = implode(",", $tmp);
update_option( 'cryptX', $cryptX_var);
$cryptX_var = (array) get_option('cryptX'); // reread Options
$wpdb->query("DELETE FROM $wpdb->postmeta WHERE meta_key = 'cryptxoff'");
}
}
if (empty($cryptX_var['c2i_font'])) {
$cryptX_var['c2i_font'] = plugin_dir_path( __FILE__ ).'fonts/'.$firstFont[0];
}
if (empty($cryptX_var['c2i_fontSize'])) {
$cryptX_var['c2i_fontSize'] = 10;
}
if (empty($cryptX_var['c2i_fontRGB'])) {
$cryptX_var['c2i_fontRGB'] = '000000';
}
update_option( 'cryptX', $cryptX_var);
$cryptX_var = (array) get_option('cryptX'); // reread Options
}
function rw_cryptx_header() {
$cryptX_script = "\n";
print($cryptX_script);
}
function rw_cryptx_meta() {
global $post;
?>
ID)) { echo 'checked="checked"'; } ?>/> Disable CryptX for this post/page