* @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 (@$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') ) { ?>