Not Solved emailenc.php
#1
Not Solved
i get this problem
Fatal error: Using $this when not in object context in /home/mmorpgsp/public_html/inc/plugins/emailenc.php on line 80

i cant find it heres the code in emailenc


heres the code
-------------------------------------------------------------------------



<?php

// Disallow direct access to this file for security reasons
if(!defined("IN_MYBB"))
{
	die("Direct initialization of this file is not allowed.<br /><br 

/>Please make sure IN_MYBB is defined.");
}


$plugins->add_hook("newthread_do_newthread_start", "emailenc_new");
$plugins->add_hook("newreply_do_newreply_start", "emailenc_new");
$plugins->add_hook("datahandler_post_update", "emailenc_edit");
$plugins->add_hook("pre_output_page", "emailenc_indexjs");


function emailenc_info()
{
	return array(
		"name"			=> "Email Encryption (In Posts)",
		"description"	=> "This plugin encrypts email addresses 

found in posts using JavaScript so that spambots can't harvest them.",
		"website"		=> "http://www.tweex.net",
		"author"		=> "MrDoom",
		"authorsite"	=> "http://www.tweex.net",
		"version"		=> "1.1",
	);
}


function emailenc_activate()
{
	// Add the custom MyCode [emailenc] tags.
	global $db, $cache;
	$replacement = "<script type=\"text/javascript\">makeEmail(\"$1\", 

\"\");</script><noscript> (Email address protected with JavaScript) 

</noscript>";
	$mycodeadd = array(
				"title" => $db->escape_string("Email 

Encryption - Tag 1"),
				"description" => $db->escape_string("MyCode 

tag 1 for the \"Email Encryption (In Posts)\" Plugin. DO NOT delete this, 

disable the plugin instead"),
				"regex" => $db->escape_string("\[emailenc\]

(.*?)\[/emailenc\]"),
				"replacement" => $db->escape_string

($replacement),
				"active" => $db->escape_string("yes")
				);
	$db->insert_query(TABLE_PREFIX."mycode", $mycodeadd);
	
	$replacement = "<script type=\"text/javascript\">makeEmail(\"$1\", 

\"$2\");</script><noscript> (Email address protected with JavaScript) 

</noscript>";
	$mycodeadd = array(
				"title" => $db->escape_string("Email 

Encryption - Tag 2"),
				"description" => $db->escape_string("MyCode 

tag 2 for the \"Email Encryption (In Posts)\" Plugin. DO NOT delete this, 

disable the plugin instead"),
				"regex" => $db->escape_string("\[emailenc=

(.*?)\](.*?)\[/emailenc\]"),
				"replacement" => $db->escape_string

($replacement),
				"active" => $db->escape_string("yes")
				);
	$db->insert_query(TABLE_PREFIX."mycode", $mycodeadd);
	
	$cache->updatemycode();
	emailenc_addemailenc();
}

function emailenc_deactivate()
{
	// Remove the custom MyCode [emailenc] tag.
	global $db, $cache;
	$db->delete_query(TABLE_PREFIX."mycode", "title='Email Encryption - 

Tag 1'");
	$db->delete_query(TABLE_PREFIX."mycode", "title='Email Encryption - 

Tag 2'");
	
	$cache->updatemycode();
	emailenc_delemailenc();
}


/* ---------------------------------------------------------------------- */
/* Add in [emailenc] tags at the correct place in messages */
/* ---------------------------------------------------------------------- */
function emailenc_new() // Called when making a new thread or post
{
	global $mybb;
	$mybb->input['message'] = emailenc_do($mybb->input['message']);
}

function emailenc_edit($this) // Called after editing a post
{
	$this->post_update_data['message'] = emailenc_do($this-

>post_update_data['message']);
}

function emailenc_do($message) // Called to add the [emailenc] tags before 

the message is put into the database.
{	
	// First replace [email] tags in the message with [emailenc] tags. 

(Easy stuff first :P)
	$str = array('#\[email\](.*?)\[/email\]#ei', '#\[email=(.*?)\](.*?)

\[/email\]#ei');
	$rep = array('emailenc_checkemail("$1", "$1")', 

'emailenc_checkemail("$1", "$2")');
	$message = preg_replace($str, $rep, $message);
	
	
	// Split the message at line breaks.
	$messageArray = explode("\\r\\n", $message);
	$count = count($messageArray);
	
	for($i = 0; $i < $count; $i++)
	{
		// Split the message at spaces to look for email addresses.
		$messageArray2 = explode(" ", $messageArray[$i]);
		$count2 = count($messageArray2);
		
		for($j = 0; $j < $count2; $j++)
		{		
			// Check if we have an email address
			if(preg_match("/^([a-zA-Z0-9-_\+\.]+?)@[a-zA-Z0-9-]

+\.[a-zA-Z0-9\.-]+$/si", $messageArray2[$j]))
			{
				$messageArray2[$j] = 

"[emailenc]".emailenc_ordemail($messageArray2[$j])."[/emailenc]";
			}
		}
		$messageArray[$i] = implode(" ", $messageArray2);
	}
	$message = implode("\\r\\n", $messageArray);
	
	return $message;
}

function emailenc_ordemail($str)
{
	$ordkey = 128; $ord = "";
	for($i=0; $i < strlen($str); $i++)
	{	
		$ord .= ord($str[$i]) + $ordkey;
		if($i < strlen($str) - 1) { $ord .= ","; }
	}
	return $ord;
}

function emailenc_checkemail($part1, $part2)
{
	if(preg_match("/^([a-zA-Z0-9-_\+\.]+?)@[a-zA-Z0-9-]+\.[a-zA-Z0-9\.

-]+$/si", $part1))
	{
		if($part1 == $part2) { return 

'[emailenc]'.emailenc_ordemail($part1).'[/emailenc]'; }
		else { return '[emailenc='.emailenc_ordemail

($part1).']'.$part2.'[/emailenc]'; }
	}
	else { return $part1; }
}


/* ----------------------------------------------------------------------- 

*/
/* Remove [emailenc] tags at the correct place in messages */
/* ----------------------------------------------------------------------- 

*/
function emailenc_undo($message)
{	
	//Replace [emailenc] tags in the message with [email] tags.
	$str = array('#\[emailenc\](.*?)\[/emailenc\]#ei', '#\[emailenc=

(.*?)\](.*?)\[/emailenc\]#ei');
	$rep = array('emailenc_checkemail2("$1", "$1")', 

'emailenc_checkemail2("$1", "$2")');
	$message = preg_replace($str, $rep, $message);
	return $message;
}

function emailenc_checkemail2($part1, $part2)
{
	if($part1 == $part2) { return '[email]'.emailenc_chremail

($part1).'[/email]'; }
	else { return '[email='.emailenc_chremail

($part1).']'.$part2.'[/email]'; }
}

function emailenc_chremail($str)
{
	$chr = ""; $chrArray = explode(",", $str);
	$count = count($chrArray);
	for($i = 0; $i < $count; $i++)
	{ $chr .= chr($chrArray[$i] - 128); }
	return $chr;
}


/* ------------------------------------------------------------*/
/* Put the JavaScript into the <head></head> tags */
/* ----------------------------------------------------------- */
function emailenc_indexjs($page)
{
	$page = str_replace("</head>", "\n<script type=\"text/javascript\"> 

// \"E-mail address protection: Javascript\" function by Adrian Kousz - 

http://adi.kousz.ch/artikel/adr-prot/javascript.en.html\nfunction maildec

(encoded, key, emailenc) { var part1='ma'; var part2='ilto'; 

window.location.href = part1+part2+':'+emailenc; }\nfunction makeEmail

(encoded2, part2) { var encoded3 = \"\";  for(var j=0; j<encoded2.length; 

j++) { if(encoded2.charAt(j) != \" \") { encoded3 = encoded3 + 

encoded2.charAt(j); } } var encoded = encoded3.split(\",\"); var key = 128; 

var emailenc=''; for (var i=0;i<encoded.length;i++) { emailenc=emailenc+

(String.fromCharCode(encoded[i]^key)) } if(part2 == \"\") { document.write

('<a href=\"javascript:maildec(\''+encoded+'\', '+key+', \''+emailenc+'\')

\">'+emailenc+'</a>'); } else { document.write('<a 

href=\"javascript:maildec(\''+encoded+'\', '+key+', \''+emailenc+'\')

\">'+part2+'</a>'); } } \n</script>\n</head>", $page);
	return $page;
}


/* ---------------------------------------------------------------*/
/* Modifying existing posts when turned on and off */
/* -------------------------------------------------------------- */
function emailenc_addemailenc()
{
	// Check the existing posts for email addresses and update as 

necessary.
	global $db;
	$result = $db->query("SELECT pid, message FROM 

".TABLE_PREFIX."posts");
	while($row = $db->fetch_array($result))
	{
		$message = $db->escape_string(emailenc_do($row['message']));
		if($message != $row['message'])
		{
			$db->query("UPDATE ".TABLE_PREFIX."posts SET 

message='$message' WHERE pid='".$row['pid']."'");
		}
	}
}

function emailenc_delemailenc()
{
	// Check the existing posts for email addresses and update as 

necessary.
	global $db;
	$result = $db->query("SELECT pid, message FROM 

".TABLE_PREFIX."posts");
	while($row = $db->fetch_array($result))
	{
		$message = $db->escape_string(emailenc_undo($row


['message']));
		if($message != $row['message'])
		{
			$db->query("UPDATE ".TABLE_PREFIX."posts SET 

message='$message' WHERE pid='".$row['pid']."'");
		}
	}
}

?>
Reply
#2
Not Solved
Just mention the pluginname ... not pasted the whole code. And if you paste code, put it in between proper tags, such as code or php.

Edit:

Was gonna test this plugin; but it seems like screwing up my posts ^^ If i enter a email in a post; it returns this (see code box) and even the post buttons, such as delete, quote ... are vanished; I can't even see my quickreply + footer anymore =D
<script type="text/javascript">makeEmail("244,229,243,244,192,232,239,244,237,225,233,236,174,227,239,237", "");</script>

Conclusion:
-deactivates plugin- ^^
Reply
#3
Not Solved
You know, I never check in this forum. That's why I tell people to use my support thread since I get an email when people post in it.

Are you using PHP5? I know it has some issues with PHP5 and they're pretty major. In short, you really shouldn't be using this since I stopped updating it some while ago and won't be updating it to 1.4.
[Image: sig.php]
The little boat gently drifted across the pond exactly the way a bowling ball wouldn't.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)