2010-05-27, 11:40 AM
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:
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:
any help please?
Thankyou for all your times
Update:
forgot to mention, focusing on this section of code:
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
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
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 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
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
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
<?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