MyBB Community Forums

Full Version: Plugin's Error
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi,

I hope that you'll help me...


The system said : unexpected ',' in these lines , how to solve ?

if($mybb->user['usergroup'], explode(',', $ugroup))) {
    eval("\$thread_restriction_user = \"".$templates->get("thread_restriction_user")."\";");
}

if(!in_array($mybb->user['usergroup'], explode(',', $ugroup))) {

require_once MYBB_ROOT."/inc/adminfunctions_templates.php";

  find_replace_templatesets("newthread", "#" . preg_quote('{$thread_restriction_user}') . "#i", '{$youdonthavepermission}');

  eval("\$youdonthavepermission = \"".$templates->get("youdonthavepermission")."\";");
} 
Well, the first line in the code posted above doesn't make any sense. I guess you meant to use in_array()?
if(in_array($mybb->user['usergroup'], explode(',', $ugroup))) {
I explain to you my problem:
In practice before it was so:

if(in_array($mybb->user['usergroup'], explode(',', $ugroup))) {
    eval("\$thread_restriction_user = \"".$templates->get("thread_restriction_user")."\";");
}

if(!in_array($mybb->user['usergroup'], explode(',', $ugroup))) {

require_once MYBB_ROOT."/inc/adminfunctions_templates.php";

  find_replace_templatesets("newthread", "#" . preg_quote('{$thread_restriction_user}') . "#i", '{$youdonthavepermission}');

  eval("\$youdonthavepermission = \"".$templates->get("youdonthavepermission")."\";");
} 

Then, since it did not work , or even when I put the gid of the groups in the settings , however, showed the message " youdonthavepermission " I changed .

Currently it is so :

function thread_restriction_newthread_start()

{   
    global $db, $lang, $mybb, $templates, $post_errors, $thread, $tid, $forums, $fid, $uid, $threadrestriction, $youdonthavepermission, $thread_restriction_user,  $submit_thread_restriction;

    $lang->load("thread_restriction_user");

    require_once MYBB_ROOT."/newthread.php";

    $usgroup = $mybb->user['usergroup'];
    $ugroup = $mybb->settings['threadrestriction_usergroup'];
    $youdonthavepermission = $lang->thread_restriction_error_permission;
    $submit_thread_restriction = $lang->submit_thread_restriction;

if($usgroup, explode(',', $ugroup))

 {
    eval("\$thread_restriction_user = \"".$templates->get("thread_restriction_user")."\";");
}

if(!$usgroup, explode(',', $ugroup)) {

require_once MYBB_ROOT."/inc/adminfunctions_templates.php";

  find_replace_templatesets("newthread", "#" . preg_quote('{$thread_restriction_user}') . "#i", '{$youdonthavepermission}');

  eval("\$youdonthavepermission = \"".$templates->get("youdonthavepermission")."\";");
} 

It gives me this error : unexpected ' , ' at line 348 which is this :

if($usgroup, explode(',', $ugroup)) 

The purpose of function newthread_start is this:

If there are gid of user groups in setting related to MyBB created with the plugin ( threadrestriction_usergroup ) then shows thread_restriction_user and value and template , everything associated with it , otherwise if there are not , replace ( replace find template set ) $ thread_restriction_user with $ youdonthavepermission which is the same as the language file thread_restriction_error_permission and a value to that , with eval fact .


Another problem :

By opening a new thread the language file and template associated with youdonthavepermission repeat 4 times one below the other .
If we put a gid ( id of user groups ) in setting threadrestriction_usergroup then only appears the phrase associated with youdonthavepermission above all on page all attacked that repeats 5 times .

I came to the conclusion that the function threadrestriction_newthread_start is all to do again , but how?

All plugin:

<?php

/**
 * Thread Restriction plugin
 * Copyright = © 2014 The_Dark
 * Author = The_Dark
 * Codding = The_Dark & murder
 * Version = 3.5
 * Special thanks to murder & MyBB-Ir
 * Website: http://yugiohspirits.altervista.org/
 * License: http://www.mybb.com/about/license
 */




//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

if(!defined("IN_MYBB"))
{
	die("Direct initialization of this file is not allowed.<br /><br />Please make sure IN_MYBB is defined.");
}



if(my_strpos($_SERVER['PHP_SELF'], 'newthread.php'))
{
    global $templatelist;
    if(isset($templatelist))
    {
        $templatelist .= ',';
    }
    $templatelist .= 'thread_restriction_user';
} 

// add infinty hooks xD
$plugins->add_hook("showthread_start", "thread_restriction_showthread_start");
$plugins->add_hook("newthread_start", "thread_restriction_newthread_start");
$plugins->add_hook('datahandler_post_validate_thread', 'thread_restriction_newthread_validate');
$plugins->add_hook("datahandler_post_insert_thread", 'thread_restriction_action_newthread');
$plugins->add_hook("editpost_action_start", "thread_restriction_editpost_action_start");
$plugins->add_hook("editpost_do_editpost_start", "thread_restriction_editpost_action_send");






//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////







function thread_restriction_info()
{
	
     global $mybb, $db, $lang;

	$lang->load("thread_restriction_user", true);

	return array(
		"name"			=> $lang->threadrestriction_info_name,
		"description"	=> $lang->threadrestriction_info_desc,
		"website"		=> "http://yugiohspirits.altervista.org/",
		"author"		=> "The_Dark",
		"authorsite"	=> "http://yugiohspirits.altervista.org/",
		"version"		=> "3.5",
		"guid" 			=> "",
		"compatibility" => "18*" 
		);
}






//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////







function thread_restriction_install()

{
	//add templates

	global $db, $mybb, $templates, $lang;

     $lang->load("thread_restriction_user");

$db->query("ALTER TABLE ".TABLE_PREFIX."threads ADD submit_thread_restriction INT(1) NOT NULL");
$db->query("ALTER TABLE ".TABLE_PREFIX."threads ADD thread_restriction_user TEXT NOT NULL");

	$template1 = array(
		'title'		=> 'thread_restriction_user',
		'template'	=> $db->escape_string('<tr>
<td class="trow2"><strong>{$lang->thread_restriction_user}</strong></td>
<td class="trow2"><input type="text" class="textbox" name="thread_restriction_user" size="40" maxlength="240" value="{$thread_restriction_user}" tabindex="2" /></td>
</tr><tr>
<td class="trow2">
<input id="submit_thread_restriction" type="submit" class="button" name="submit_thread_restriction" value="{$submit_thread_restriction}" tabindex="3">
<span id="spinner_span"></span>
</td>
</tr>'),
		'sid'		=> '-1',
		'version'	=> '',
		'dateline'	=> TIME_NOW
	);

	$db->insert_query("templates", $template1);


	$template2 = array(
		'title'		=> 'youdonthavepermission',
		'template'	=> $db->escape_string('<tr>
<td class="trow2"><strong>{$lang->thread_restriction_error_permission}</strong></td>
<td class="trow2"><input type="text" class="textbox" name="youdonthavepermission" size="40" maxlength="240" value="{$youdonthavepermission}" tabindex="2" /></td>
</tr>'),
		'sid'		=> '-1',
		'version'	=> '',
		'dateline'	=> TIME_NOW
	);

	$db->insert_query("templates", $template2);

		$template3 = array(
		'title'		=> 'youdonthavepermissionforedit',
		'template'	=> $db->escape_string('<tr>
<td class="trow2"><strong>{$lang->thread_restriction_you_do_not_edit_restriction_in_this_thread}</strong></td>
<td class="trow2"><input type="text" class="textbox" name="youdonthavepermissionforedit" size="40" maxlength="240" value="{$youdonthavepermissionforedit}" tabindex="2" /></td>
</tr>'),
		'sid'		=> '-1',
		'version'	=> '',
		'dateline'	=> TIME_NOW
	);

	$db->insert_query("templates", $template3);

	require_once MYBB_ROOT."/inc/adminfunctions_templates.php";

	find_replace_templatesets("newthread", "#" . preg_quote('{$posticons}') . "#i", '{$thread_restriction_user}{$posticons}');

    
}





//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////







function thread_restriction_is_installed()

 {

global $db, $mybb, $templates, $thread, $tid, $forums, $fid, $uid, $thread_restriction_user, $submit_thread_restriction;
	
	if($db->field_exists("submit_thread_restriction", "threads") && $db->field_exists("thread_restriction_user", "threads"))
	{
		return true;
	}
	
	return false;
}





//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////







function thread_restriction_uninstall()

{

global $db, $mybb, $templates;

$db->query("ALTER TABLE ".TABLE_PREFIX."threads DROP `submit_thread_restriction`");	
$db->query("ALTER TABLE ".TABLE_PREFIX."threads DROP `thread_restriction_user`");	
$db->delete_query("templates", "title IN('thread_restriction_user','youdonthavepermission','youdonthavepermissionforedit')");

}






//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////






function thread_restriction_activate()

{

   global $db, $mybb, $templates, $lang;

     $lang->load("thread_restriction_user");

	
	// create settings
	$insertarray = array(
		'name' => 'threadrestriction', 
		'title' => $lang->threadrestriction_settinggroups_title, 
		'description' => $lang->threadrestriction_settinggroups_desc, 
		'disporder' => "5",
	);

	$gid = $db->insert_query("settinggroups", $insertarray);
	// add settings

	$setting0 = array(
		"name"			=> "threadrestriction_threads",
		"title"			=> $lang->threadrestriction_settings_threads,
		"description"	=> $lang->threadrestriction_settings_threads_desc,
		"optionscode"	=> "text",
		"value"			=> "",
		"disporder"		=> "1",
		"gid"			=> intval($gid),
	);

	
	$db->insert_query("settings", $setting0);
	
	$setting1 = array(
		"name"			=> "threadrestriction_banuser",
		"title"			=> $lang->threadrestriction_settings_banuser,
		"description"	=> $lang->threadrestriction_settings_banuser_desc,
		"optionscode"	=> "text",
		"value"			=> "",
		"disporder"		=> "2",
		"gid"			=> intval($gid),
	);

	$db->insert_query("settings", $setting1);
	
	$setting2 = array(
		"name"			=> "threadrestriction_bangroups",
		"title"			=> $lang->threadrestriction_settings_bangroups,
		"description"	=> $lang->threadrestriction_settings_bangroups_desc,
		"optionscode"	=> "text",
		"value"			=> "",
		"disporder"		=> "3",
		"gid"			=> intval($gid),
	);

	$db->insert_query("settings", $setting2);

	$setting3= array(
		"name"			=> "threadrestriction_usergroup",
		"title"			=> $lang->threadrestriction_settings_usergroup,
		"description"	=> $lang->threadrestriction_settings_usergroup_desc,
		"optionscode"	=> "text",
		"value"			=> "",
		"disporder"		=> "4",
		"gid"			=> intval($gid),

		);

		$db->insert_query("settings", $setting3);

	
	
	rebuild_settings();   
	
}






//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////






function thread_restriction_deactivate()

{    

	global $db, $mybb, $templates, $lang;

    $db->delete_query("settinggroups", "name = 'threadrestriction'");
   $db->delete_query('settings', 'name IN ( \'threadrestriction_threads\',\'threadrestriction_banuser\',\'threadrestriction_bangroups\',\'threadrestriction_usergroup\')');
                                          
    rebuild_settings();
}








/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////








function thread_restriction_newthread_start()

{   
    global $db, $lang, $mybb, $templates, $post_errors, $thread, $tid, $forums, $fid, $uid, $threadrestriction, $youdonthavepermission, $thread_restriction_user,  $submit_thread_restriction;

    $lang->load("thread_restriction_user");

    require_once MYBB_ROOT."/newthread.php";

    $usgroup = $mybb->user['usergroup'];
    $ugroup = $mybb->settings['threadrestriction_usergroup'];
    $youdonthavepermission = $lang->thread_restriction_error_permission;
    $submit_thread_restriction = $lang->submit_thread_restriction;

if($usgroup, explode(',', $ugroup))

 {
    eval("\$thread_restriction_user = \"".$templates->get("thread_restriction_user")."\";");
}

if(!$usgroup, explode(',', $ugroup)) {

require_once MYBB_ROOT."/inc/adminfunctions_templates.php";

  find_replace_templatesets("newthread", "#" . preg_quote('{$thread_restriction_user}') . "#i", '{$youdonthavepermission}');

  eval("\$youdonthavepermission = \"".$templates->get("youdonthavepermission")."\";");
}


}






//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////








function thread_restriction_newthread_validate(&$dh)
{
    global $mybb;

    if($mybb->input['submit_thread_restriction'])
    {
    	$dh->data['submit_thread_restriction'] = $mybb->input['submit_thread_restriction_user'];
        $dh->data['thread_restriction_user'] = $mybb->input['thread_restriction_user'];
		
    }
} 







//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////








function thread_restriction_action_newthread(&$dh)
{
    global $mybb, $lang, $db, $templates, $thread_restriction_user, $submit_thread_restriction;

    if($mybb->input['submit_thread_restriction'] == 1)

	{

      $thread_restriction_user = $mybb->input['thread_restriction_user'];
	
	$lang->load("thread_restriction_user");

	$submit_thread_restriction = $lang->submit_thread_restriction;

	if($thread_restriction_user = $mybb->user['uid'])

	 {
	 success($lang->thread_restriction_valide_send);
	 }

	
	if($thread_restriction_user != $mybb->user['uid'])

	 {
	 error($lang->thread_restriction_invalide_uids);
	 }

	 if($thread_restriction_user = "")

	 {
	 error($lang->thread_restriction_invalide);
	 }

	 if($thread_restriction_user = $mybb->usergroup['cancp'])

	 {
	 error($lang->thread_restriction_permission_admin);
	 }
	 
	 else{$db->query("UPDATE ".TABLE_PREFIX."threads SET submit_thread_restriction=1 AND thread_restriction_user='".$db->escape_string(intval($mybb->input['thread_restriction_user']))."' WHERE tid='".$posthandler->tid."'");}
	 
	 
	 
if($dh->action == 'thread' && $dh->method == 'insert')
    {

    	$dh->thread_insert_data['submit_thread_restriction'] = $db->escape_string($dh->data['submit_thread_restriction']);
        $dh->thread_insert_data['thread_restriction_user'] = $db->escape_string($dh->data['thread_restriction_user']);
        
    }	 
			
}

	}








	//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////








	function thread_restriction_showthread_start()
{
    global $db, $lang, $mybb, $templates, $submit_thread_restriction, $post_errors, $thread, $tid, $forums, $fid, $uid, $threadrestriction, $thread_restriction_user, $submit_thread_restriction;

    $lang->load("thread_restriction_user");

    $ugroup = $mybb->settings['threadrestriction_usergroup'];
    $tids = $mybb->settings['threadrestriction_threads'];
    $uids = $mybb->settings['threadrestriction_banuser'];
    $uidss = $mybb->input['thread_restriction_user'];
    $ugroups = $mybb->settings['threadrestriction_bangroups'];
    $submit_thread_restriction = $mybb->input['submit_thread_restriction'];

    if(in_array($tid, explode(',', $tids)) && in_array($mybb->user['uid'], explode(',', $uids))) {
        error_no_permission();
    }

    if(in_array($tid, explode(',', $tids)) && in_array($mybb->user['usergroup'], explode(',', $ugroups))) {
    	
        error_no_permission();
    }

 if(in_array($mybb->user['usergroup'], explode(',', $ugroup)) && in_array($submit_thread_restriction, explode(',', $uidss)))

 {
         error_no_permission();
 }
   
          eval("\$thread_restriction_user = \"".$templates->get("thread_restriction_user")."\";");

} 







//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////








// Admin can edit the choice of the users about thread restriction, users and other groups not:



function thread_restriction_editpost_action_start()

{

	global $db, $lang, $mybb, $templates, $post, $editpost, $youdonthavepermissionforedit, $thread, $uid, $pid, 
$submit_thread_restriction, $thread_restriction_user;


    require_once MYBB_ROOT."/editpost.php";

$lang->load("thread_restriction_user");

$submit_thread_restriction = $lang->submit_thread_restriction;

$youdonthavepermissionforedit = $lang->thread_restriction_you_do_not_edit_restriction_in_this_thread;

   
   if($mybb->usergroup['cancp'] == 1) 

	{
          eval("\$thread_restriction_user = \"".$templates->get("thread_restriction_user")."\";");
	}


if($mybb->usergroup['cancp'] != 1)

{
	require_once MYBB_ROOT."/inc/adminfunctions_templates.php";

  find_replace_templatesets("newthread", "#" . preg_quote('{$thread_restriction_user}') . "#i", '{$youdonthavepermissionforedit}');

  eval("\$youdonthavepermissionforedit = \"".$templates->get("youdonthavepermissionforedit")."\";");
	
}

   

}




/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////



function thread_restriction_editpost_action_send()


{
    global $mybb, $lang, $thread, $db, $post, $thread_restriction_user, $submit_thread_restriction, $templates;
	

	$emptyfield = $mybb->input['thread_restriction_user'];

	$tid = $thread['tid'];
	
	if($mybb->input['submit_thread_restriction'] == 1)

	{

	$lang->load("thread_restriction_user");

	   if($mybb->usergroup['cancp'] == 1) 

	{
          eval("\$thread_restriction_user = \"".$templates->get("thread_restriction_user")."\";");
	}


if($mybb->usergroup['cancp'] != 1)

{
	require_once MYBB_ROOT."/inc/adminfunctions_templates.php";

  find_replace_templatesets("newthread", "#" . preg_quote('{$thread_restriction_user}') . "#i", '{$youdonthavepermissionforedit}');

  eval("\$youdonthavepermissionforedit = \"".$templates->get("youdonthavepermissionforedit")."\";");
	
}
	
	 if($emptyfield != $mybb->user['uid'])

	 {
	 error($lang->thread_restriction_invalide_uids);
	 }

	 if($emptyfield = "")

	 {
	 error($lang->thread_restriction_invalide);
	 }

	 if($emptyfield = $mybb->usergroup['cancp'])

	 {
	 error($lang->thread_restriction_permission_admin);
	 }
	 

	 
     $db->query("UPDATE ".TABLE_PREFIX."threads SET submit_thread_restriction=1, thread_restriction_user='".$db->escape_string($emptyfield)."' WHERE tid='".$post['tid']."'");	 
	
	 
	} 
	
	if($mybb->input['submit_thread_restriction'] == 0)
	{
	
	$db->query("UPDATE ".TABLE_PREFIX."threads SET submit_thread_restriction=0, thread_restriction_user='".$db->escape_string($emptyfield)."' WHERE tid='".$post['tid']."'");
	}

}


?>
I don't know why you wrote this block of text, I told you what's the issue and its solution..

(2014-12-06, 05:20 AM)Destroy666 Wrote: [ -> ]Well, the first line in the code posted above doesn't make any sense. I guess you meant to use in_array()?


if(in_array($mybb->user['usergroup'], explode(',', $ugroup))) {

There is nothing else you can do, your syntax is invalid and the error won't disappear without changing it.

And if the result is not good (everyone not having access or whatever you meant), you should change the conditional to proper (negated perhaps?). I don't know what it should check since your code is confusing - for example you're trying to do unexpected things like using find_replace_templatesets() function in newthread hook or non-existent success() function.