Jump to content

Recommended Posts

Okay, I'm making a plugin for MyBB, and, I'm getting the "unexpected $end" error, but I can't figure out why. I've looked through my code, and, as far as I can tell, everything has been closed off just fine. I've got a feeling that somethings up with my <<<EOF thing I have going. I was using that cause addslashes() wasn't working for me. Anyway, here's my code, see if you can help me:

 

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

$plugins->add_hook('global_start', 'modcp_link');
$plugins->add_hook("admin_index_navigation_end", "modcp_admin_nav");

// ######### Begin the Functions ##########
function modcp_info()
{
return array(
	"name"			=> "Mod CP Plugin",
	"description"	=> "A plugin that gives the Moderators their own Control Panel",
	"website"		=> "http://www.mybboard.com",
	"author"		=> "LegosJed",
	"authorsite"	=> "http://www.mybboard.com",
	"version"		=> "0.1",
);
}

function modcp_activate()
{
global $db, $config;

// Erase previous settings
modcp_deactivate();

// Setup setting group
$setting_group = array(
	'gid' => 'NULL', 
	'name' => 'modcp', 
	'title' => 'Mod CP', 
	'description' => 'Settings that will add a Mod CP, and give it certain privilages.', 
	'disporder' => '99', 
	'isdefault' => 'no'
);
$db->insert_query(TABLE_PREFIX."settinggroups", $insertarray);
$setting_gid = $db->insert_id();

// Setup settings
$setting_1 = array(
	'name' => 'modcp_onoff',
	'title' => 'Mod CP - On/Off Switch',
	'description' => 'Enables or disables the Mod CP',
	'optionscode' => 'onoff',
	'value' => 'on',
	'disporder' => 0,
	'gid' => $setting_gid
);

$setting_2 = array(
	'name' => 'modcp_ban',
	'title' => 'Mod CP - Ban User',
	'description' => 'Can the Mod CP ban users?',
	'optionscode' => 'yesno',
	'value' => 'yes',
	'disporder' => 1,
	'gid' => $setting_gid
);

$setting_3 = array(
	'name' => 'modcp_ban_ip',
	'title' => 'Mod CP - Ban IPs',
	'description' => 'Can the Mod CP ban IP addresses?',
	'optionscode' => 'yesno',
	'value' => 'yesno',
	'disporder' => 2,
	'gid' => $setting_gid
);

$setting_4 = array(
	'name' => 'modcp_ban_email',
	'title' => 'Mod CP - Ban Email',
	'description' => 'Can the Mod CP ban Email addresses?',
	'optionscode' => 'yesno',
	'value' => 'yes',
	'disporder' => 3,
	'gid' => $setting_gid
);

$setting_5 = array(
	'name' => 'modcp_announce',
	'title' => 'Mod CP - Forum Announcements',
	'description' => 'Can the Mod CP add forum announcements?',
	'optionscode' => 'yesno',
	'value' => 'yes',
	'disporder' => 4,
	'gid' => $setting_gid
);

$setting_6 = array(
	'name' => 'modcp_thread_queue',
	'title' => 'Mod CP - Thread Queue',
	'description' => 'Can the Mod CP setup a thread queue?',
	'optionscode' => 'yesno',
	'value' => 'yes',
	'disporder' => 5,
	'gid' => $setting_gid
);

$setting_7 = array(
	'name' => 'modcp_post_queue',
	'title' => 'Mod CP - Post Queue',
	'description' => 'Can the Mod CP setup a post queue?',
	'optionscode' => 'yesno',
	'value' => 'yes',
	'disporder' => 5,
	'gid' => $setting_gid
);

// Insert settings
$db->insert_query(TABLE_PREFIX."settings", $setting_1);
$db->insert_query(TABLE_PREFIX."settings", $setting_2);
$db->insert_query(TABLE_PREFIX."settings", $setting_3);
$db->insert_query(TABLE_PREFIX."settings", $setting_4);
$db->insert_query(TABLE_PREFIX."settings", $setting_5);
$db->insert_query(TABLE_PREFIX."settings", $setting_6);

// Setup tables
$tables_1 = "CREATE TABLE mybb_modoptions (
  		uid int(10) NOT NULL default '0',
  		cpstyle varchar(50) NOT NULL default '',
  		notes text NOT NULL default '',
  		permsset int(1) NOT NULL default '0',
  		caneditann char(3) NOT NULL default '',
  		canmodposts char(3) NOT NULL default '',
  		caneditusers char(3) NOT NULL default '',
  		canban char(3) NOT NULL default '',
  		PRIMARY KEY  (uid)
) TYPE=MyISAM;";

$tables_2 = "CREATE TABLE mybb_modsessions (
	sid varchar(32) NOT NULL default '',
	uid int unsigned NOT NULL default '0',
	loginkey varchar(50) NOT NULL default '',
	ip varchar(40) NOT NULL default '',
	dateline bigint(30) NOT NULL default '0',
	lastactive bigint(30) NOT NULL default '0'
) TYPE=MyISAM;";

// Create Tables
$db->query($tables_1);
$db->query($tables_2);

// Populate new tables
$smods_query = $db->query('SELECT * FROM '.TABLE_PREFIX.'users WHERE usergroup=3');
$mods_query = $db->query('SELECT * FROM '.TABLE_PREFIX.'users WHERE usergroup=6');

if($db->mun_rows($smods_query))
{
	$smods_array = $db->fetch_array($smods_query);
	foreach($smods_array as $smods)
	{
		$query = array(
			'uid' => $smods['uid'],
			'cpstyle' => 'Axiom',
			'notes' => '',
			'permsset' => '1',
			'caneditann' => 'yes',
			'canmodposts' => 'yes',
			'caneditusers' => 'yes',
			'canban' => 'yes',
		);
		$db->insert_query(TABLE_PREFIX.'modoptions', $query);
	}
}
if($db->mun_rows($mods_query))
{
	$mods_array = $db->fetch_array($mods_query);
	foreach($mods_array as $mods)
	{
		$query = array(
			'uid' => $mods['uid'],
			'cpstyle' => 'Axiom',
			'notes' => '',
			'permsset' => '1',
			'caneditann' => 'yes',
			'canmodposts' => 'yes',
			'caneditusers' => 'yes',
			'canban' => 'yes',
		);
		$db->insert_query(TABLE_PREFIX.'modoptions', $query);
	}
}

// Edit existing template
require_once MYBB_ROOT."/inc/adminfunctions_templates.php";
find_replace_templatesets("header_welcomeblock_member", '#welcome_usercp}</strong></a>#', "$0\n{$modcplink}");

// Setup new template
$template = <<<EOF
— <a href="{\$mybb->settings['bburl']}/{\$config['mod_dir']}/index.php">{\$lang->welcome_mod}</a>
EOF;

$template_1 = array(
	array(
	"title" => "header_welcomeblock_member_mod",
	"template" => $template,
	"version" => $mybb->version_code,
	"status" => "",
	"dateline" => time(),
);

// Insert new template
$db->insert_query(TABLE_PREFIX.'templates', $template_1);

// Set Mod CP directory
$config[mod_dir] = 'mod';

echo "<script language=\"JavaScript\">
	  	parent.nav.location.href =  \"./index.php?".SID."&action=navigation\";
	  </script>";
}

function modcp_deactivate()
{
global $db;

$db->delete_query(TABLE_PREFIX."settinggroups", "name='modcp' OR name='Mod CP'");
$db->query("DELETE FROM ".TABLE_PREFIX."settings WHERE name IN(
	'modcp_onoff',
	'modcp_ban',
	'modcp_ban_ip',
	'modcp_ban_email',
	'modcp_announce',
	'modcp_thread_queue',
	'modcp_post_queue'
)");
$db->delete_query(TABLE_PREFIX."templates", "title='header_welcomeblock_member_mod'");

// Attempt to modify header template
require_once MYBB_ROOT."/inc/adminfunctions_templates.php";
find_replace_templatesets("header_welcomeblock_member", '#{$modcplink}#', '', 0);

if(isset($config[mod_dir]))
{
	unset($config[mod_dir]);
}

echo "<script language=\"JavaScript\">
	  	parent.nav.location.href =  \"./index.php?".SID."&action=navigation\";
	  </script>";
}

function modcp_link()
{
if($mybb->usergroup['cancp'] == "yes" || $mybb->usergroup['issupermod'] == "yes" || $mybb->usergroup['gid'] == 6)
{
	eval("\$modcplink = \"".$templates->get("header_welcomeblock_member_mod")."\";");
}
}

function modcp_admin_nav()
{
global $menu, $mybb, $lang;
  
$language = $mybb->settings['bblanguage'];
if(!$lang->language_exists($language."/admin/ban.lang.php"))
{
	$language = 'english';
}
$lang->set_language($language, "admin");
$lang->load("ban");

  	end($menu);
  	$key = key($menu)+10;
$menu[$key] = array(
"title" => $lang->modcp_admin,
"items" => array(
	10 => array("title" => $lang->modcp_options, "url" => "admin_ban.php?".SID."&action=cpopt"),
	20 => array("title" => $lang->mod_options, "url" => "admin_ban.php?".SID."&action=opt"),
	),
);
}
?>

 

Link to comment
https://forums.phpfreaks.com/topic/38079-mybb-plugin-help/
Share on other sites

the ending HEREDOC delimiter  must be on its own on the line with nothing else on it, including spaces.

// Setup new template
$template = <<<EOF
— <a href="{\$mybb->settings['bburl']}/{\$config['mod_dir']}/index.php">{\$lang->welcome_mod}</a>
EOF;

Should be:

// Setup new template
$template = <<<EOF
— <a href="{\$mybb->settings['bburl']}/{\$config['mod_dir']}/index.php">{\$lang->welcome_mod}</a>
EOF;

Link to comment
https://forums.phpfreaks.com/topic/38079-mybb-plugin-help/#findComment-182943
Share on other sites

Sorry for the double post, but there's no 'edit' button.

 

Anyway, now, I'm trying to figure out how to check to see if a table exists. I was doing something like this:

 

<?php
$tables = $db->query("SHOW TABLES");
$mod1 = stristr($tables, 'mybb_modoptions');
$mod2 = stristr($tables, 'mybb_modsessions');

if($mod1)
{
	$db->query("DROP TABLE ".TABLE_PREFIX."modoptions");
}
if($mod2)
{
	$db->query("DROP TABLE ".TABLE_PREFIX."modsessions");
}
?>

 

But that doesn't seem to work.

Link to comment
https://forums.phpfreaks.com/topic/38079-mybb-plugin-help/#findComment-183651
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.