* @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');
}
// 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
// -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
function _filter($apply)
{
global $cryptX_var;
if (@$cryptX_var[autolink]) {
add_filter($apply,
array(&$this, '_autolink'),
9);
}
add_filter( $apply,
array(&$this, '_findMatches'),
11);
}
// -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
function _linktext($txt)
{
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($txt);
break;
default:
$linktext = str_replace( "@", $cryptX_var[at], $txt);
$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")) //Abfrage nach gültigen Datenformat
{
$verzeichnisinhalt[] = $file;
}
}
return $verzeichnisinhalt;
}
// -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
function _findMatches($content)
{
global $cryptX_var;
$pattern = '/(.*?)<\/a>/i'; // Thx to Michael Woehrer (http://sw-guide.de) for this pattern out of his plugin 'Link Indication'
$result = preg_replace_callback($pattern,array(get_class($this), '_encrypt'),$content);
return $result;
}
function _encrypt($matches)
{
global $cryptX_var;
if(preg_match('/mailto:(.*)/', $matches[4], $mail)) {
if (@$cryptX_var[java]) {
$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);
}
$matches[4] = "javascript:DeCryptX('" . $crypt . "')";
} else {
$matches[4] = antispambot($matches[4]);
}
}
$matches[7] = $this->_linktext($matches[7]);
$others = $matches[1] . ' ' . $matches[6];
$others = eregi_replace('[[:space:]]+', ' ', $others);
$others = trim($others);
return '' . $matches[7] . '';
}
// -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
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;
}
// -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
function _install() {
add_option(
'cryptX',
array(
'at' => ' [at] ',
'dot' => ' [dot] ',
'theContent' => 1,
'theExcerpt' => 0,
'commentText' => 1,
'java' => 1,
'opt_linktext' => 0,
)
);
}
// -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
/**
* 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_options_page(
'CryptX',
(version_compare($GLOBALS['wp_version'], '2.6.999', '>') ? '
' : ''). '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
?>