2011-04-21, 02:58 PM
Hi there, i need a few pointers as this is my first plugin. Currently, i am having trouble with a function
What i want this function to do is check after a post(reply) has been made and if all conditions are not met, it updates by copying the unix timestamp from 'lastpost' in mybb_users and pasting it in the new column i have created for this. The column i have created is called 'hlforumlastpost' in mybb_users.
The conditions are if it is enabled AND if user is in particular usergroup AND if user is not the thread maker AND the post( a reply) is in the affected forum. (It returns nothing). (4 conditions)
If the conditions above are not met it updates the unix timestamp in the column 'hlforumlastpost' in the table 'mybb_users'
The plugin hooks i used, not sure which hook is correct.
The sql column i have created is working since i tested it step by step.
The settings are correct:
I then insert the query
I know my function might be syntacically wrong since i am not familiar with mybb structure and mysql.
To summarize what i want this function to do is if the conditions are not met then it copies the timestamp from the table 'mybb_user' column 'lastpost' and pastes it in the new column i have created called 'hlforumlastpost'. Can someone help me revise my function? I'm not too sure what is wrong.
What i want this function to do is check after a post(reply) has been made and if all conditions are not met, it updates by copying the unix timestamp from 'lastpost' in mybb_users and pasting it in the new column i have created for this. The column i have created is called 'hlforumlastpost' in mybb_users.
The conditions are if it is enabled AND if user is in particular usergroup AND if user is not the thread maker AND the post( a reply) is in the affected forum. (It returns nothing). (4 conditions)
If the conditions above are not met it updates the unix timestamp in the column 'hlforumlastpost' in the table 'mybb_users'
The plugin hooks i used, not sure which hook is correct.
$plugins->add_hook("newreply_end", "hidelinks_checkforums");
$plugins->add_hook("newthread_start", "hidelinks_checkforums");
The sql column i have created is working since i tested it step by step.
$query="ALTER TABLE ".TABLE_PREFIX."users ADD hlforumlastpost bigint( 30 ) NOT NULL default '0' AFTER lastpost;";
$db->query($query);
The settings are correct:
$hidelinks_setting_3 = array(
"sid" => "NULL",
"name" => "hidelinks_groups",
"title" => "Usergroups",
"description" => "Please enter the IDs of the usergroups that should be affected. (0 = all groups). (1,2,4 = guests, members, admins)",
"optionscode" => "text",
"value" => "0",
"disporder" => "3",
"gid" => intval($gid),
);
$hidelinks_setting_4 = array(
"sid" => "NULL",
"name" => "hidelinks_forums",
"title" => "Forums",
"description" => "Please enter the fIDs of the forums for replies to not be counted. 0 = disable (seperate with a comma: 1,2,3,4)",
"optionscode" => "text",
"value" => "0",
"disporder" => "4",
"gid" => intval($gid),
);
I then insert the query
$db->insert_query("settings", $hidelinks_setting_3);
$db->insert_query("settings", $hidelinks_setting_4);
I know my function might be syntacically wrong since i am not familiar with mybb structure and mysql.
//Check posts for qualification
function hidelinks_checkforums()
{
global $db, $mybb, $fid, $settings;
$affectedforum = explode(",", $mybb->settings['hidelinks_forums']);
if($mybb->settings['hidelinks_enabled'] == "1" && in_array($fid,$affectedforum) && $mybb->posts['username'] != $mybb->threads['username']){
return;
}
else{
$lastpost = $mybb->user['lastpost'];
$query="INSERT INTO ".TABLE_PREFIX."users (hlforumlastpost)
VALUES (".$lastpost.")";
$db->query($query);
}
}
To summarize what i want this function to do is if the conditions are not met then it copies the timestamp from the table 'mybb_user' column 'lastpost' and pastes it in the new column i have created called 'hlforumlastpost'. Can someone help me revise my function? I'm not too sure what is wrong.