MyBB Community Forums

Full Version: Function syntax error
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
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.
$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.

$mybb->posts['username'] and $mybb->threads['username'] do not exist.
I'm not really sure what you want to do with these.
i want to test from the database if the post(reply) is not the same as the thread maker.
The problem is, the checkforums function is executed in two places: when creating a post and when creating a new thread.

Why would you check if the user making the thread, is the one making the post?
I wasn't sure which hook to use because i was testing to see if the function works and it seems it didn't update my database with the timestamp so i was testing new threads and new replies.

I'm checking the user if it's his thread, if it is then he can continue to post updates on his threads and continuously have his timestamp updated in my new column.
If $mybb->posts['username'] and $mybb->threads['username'] does not exist what do i need to have in order to call out those 2 records from mybb_posts and mybb_threads table username field.
Well you have to query those tables for an entry.
oh, thanks for the heads up but when the conditions aren't met, my query to update the record doesn't work.
else{
        $lastpost = $mybb->user['lastpost'];
        $query="INSERT INTO ".TABLE_PREFIX."users (hlforumlastpost)
        VALUES (".$lastpost.")";
        $db->query($query);
    }
Use MyBB's DB::update_query method for that.

e.g.
$db->update_query("users", array('hlforumlastpost', => $lastpost), 'uid='.$mybb->user['uid']);

I think you want to update, not insert.
hmmm, i got this error when i placed it in my else statement
Parse error: syntax error, unexpected T_DOUBLE_ARROW, expecting ')'

	else{
		$lastpost = $mybb->user['lastpost'];
		$db->update_query("users", array('hlforumlastpost', => $lastpost), 'uid='.$mybb->user['uid']); 
	}

the new column i created in mybb_users has the same attributes as the lastpost column.
There is a comma after 'hlforumlastpost' which shouldn't be there.
Pages: 1 2