MyBB Community Forums

Full Version: Task to remove user sigs with urls in
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi all,

I used to develop a few plugins for mybb back in the 1.2 days but havn't done any for a while.

What i want to do is this:
Remove signaures from users who have a url in their signature and have less than 10 posts

This is the code i have so far:

<?php


function task_removesigs($task)
{
	global $db, $mybb, $lang;
	
	$query = $db->query("SELECT uid, username FROM ".TABLE_PREFIX."users WHERE postnum < 10 AND signature LIKE '%[url%'");
	
	while($row = $db->fetch_array($query)){
	
		$db->query("UPDATE ".TABLE_PREFIX."users SET signature='' WHERE uid='" . $row['uid'] . "'");
	
		require_once MYBB_ROOT."inc/datahandlers/pm.php";
		$pmhandler = new PMDataHandler();

		$pm = array(
			"subject" => "Signature Removed",
			"message" => "Hi, Your signature has been automatically removed because it contains a url.   
Once you have 10 posts you can then add a url to your signature and it will not be removed automatically",
			"icon" => "-1",
			"toid" => $row['uid'],
			"fromid" => 34,
			"do" => '',
			"pmid" => ''
		);
		$pm['options'] = array(
			"signature" => "0",
			"disablesmilies" => "0",
			"savecopy" => "0",
			"readreceipt" => "0"
		);
	
		$pmhandler->set_data($pm);
				
		if(!$pmhandler->validate_pm())
		{
			add_task_log($task, "Could not send PM to uid " . $row['uid']);
		}
		else
		{
			$pminfo = $pmhandler->insert_pm();
		}
		
		add_task_log($task, "Signature removed from user: " . $row['username'] . " ID: " . $row['uid']);
	}
	
	add_task_log($task, "Task completed successfully");

}
?>

The removing of signatures works great however the PM part where i send a message to the user telling them there signature has been removed does not

In the task logs i get this:

Quote:Warning - [2] 'Invalid argument supplied for foreach()' - Line: 548 - File: inc/datahandlers/pm.php

any help please?

Thankyou for all your times Smile

Update:
forgot to mention, focusing on this section of code:

		if(!$pmhandler->validate_pm())
		{
			add_task_log($task, "Could not send PM to uid " . $row['uid']);
		}
		else
		{
			$pminfo = $pmhandler->insert_pm();
		}

that log never gets added so i guess that its being validated okay?
UPDATE FIXED:
Okay got it working, had to have the toid as an array even if it is only to one user.

Below i've included the working code and added a config section at the top so you can customise it for your own use

Feel free to use it Smile

You'll need to upload it to

/inc/tasks/removesigs.php

Then create a new task in task manager in mybb for it to run as often as you want it to (as often as possible for best results)

Probably should have made this is a plugin instead and had the config options in the config panel but i wanted to have a look how the tasks worked

If anyone wants it as a plugin then let me know Smile

<?php


function task_removesigs($task)
{

	//Configuration Section...
	$fromid = 1; // Set the ID of the user the message should be sent from
	$PMsubject = "Signature Removed"; //Subject of the PM
	$PMmessage = "Hi, Your signature has been automatically removed because it contains a url.
					Once you have 10 posts you can then add a url to your signature and it will 
					not be removed automatically";
					//Set to the message you want to be sent in the pm
					
	$requiredPosts = 10; //Set to how many posts are required before a user can have urls in their sigs

	global $db, $mybb, $lang;
	
	$query = $db->query("SELECT uid, username FROM ".TABLE_PREFIX."users WHERE postnum < " . $requiredPosts . " AND signature LIKE '%[url%'");
	
	while($row = $db->fetch_array($query)){
	
		$db->query("UPDATE ".TABLE_PREFIX."users SET signature='' WHERE uid='" . $row['uid'] . "'");
	
		require_once MYBB_ROOT."inc/datahandlers/pm.php";
		$pmhandler = new PMDataHandler();

		$pm = array(
			"subject" => $PMsubject,
			"message" => $PMmessage,
			"icon" => "-1",
			"toid" => Array($row['uid']),
			"fromid" => $fromid,
			"do" => '',
			"pmid" => ''
		);
		$pm['options'] = array(
			"signature" => "0",
			"disablesmilies" => "0",
			"savecopy" => "0",
			"readreceipt" => "0"
		);
	
		$pmhandler->set_data($pm);
				
		if(!$pmhandler->validate_pm())
		{
			add_task_log($task, "Could not send PM to uid " . $row['uid']);
		}
		else
		{
			$pminfo = $pmhandler->insert_pm();
		}
		
		unset($pm);
		unset($pmhandler);
		unset($pminfo);
		
		add_task_log($task, "Signature removed from user: " . $row['username'] . " ID: " . $row['uid']);
	}
	
	add_task_log($task, "Task completed successfully");

}
?>


Plugin Update

Turned it into a plugin anyway, submitted it to mods.mybboard.net and will post it in releases once it's done
I'm going to download it once it is approved. Smile
http://mods.mybboard.net/view/automatic-...re-removal

someone's given it a 2/5 star already which I think is pretty poor so maybe there are some bugs.

Let me know if you find any and I will be happy to fix them/add new features![/align]
Good plugin, very useful idea Smile
thanks for that no problem

Let me know of any problems and i'll fix them up
This is exactly what I was looking for. How can I get this to work on 1.6.1? Right now I get the error message on the plugins page:

This plugin is incompatible with MyBB 1.6.1

Thanks!
(2010-12-30, 11:53 PM)zen Wrote: [ -> ]This is exactly what I was looking for. How can I get this to work on 1.6.1? Right now I get the error message on the plugins page:

This plugin is incompatible with MyBB 1.6.1

Thanks!

http://community.mybb.com/thread-75646.html
That is some very intensive code. Instead of running a query inside a loop, put all uid's in an array and once the loop has ended, run a query to update all those members. That way you run 2 queries instead of plenty of them.
(2010-12-31, 01:12 AM)Jammerx2 Wrote: [ -> ]
(2010-12-30, 11:53 PM)zen Wrote: [ -> ]This is exactly what I was looking for. How can I get this to work on 1.6.1? Right now I get the error message on the plugins page:

This plugin is incompatible with MyBB 1.6.1

Thanks!

http://community.mybb.com/thread-75646.html

Cool thanks that works. Smile