MyBB Community Forums

Full Version: Plugin error
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2 3 4 5 6
You need to either escape the dollar sign or the single quotes depending on what you use:
"\$post['onlinestatus']"
'$post[\'onlinestatus\']'
An unescaped dollar sign will try to put the value of the given variable in the string:
$var = "hello";
print "$var world"; // hello world
print "\$var world"; // $var world
This only applies to double quotes. Single quotes will have the literal string.
(2011-05-04, 07:38 AM)Tomm M Wrote: [ -> ]
(2011-05-04, 03:23 AM)Dylan M. Wrote: [ -> ]
$post['onlinestatus'] .= "<br /><strong>{$post[$fid1212]}</strong>";

In 1.6.4, a variable as an array key won't be liked very much due to the new security in the templates.

So the solution above would even be better then, since it isn't in the template, yes? Wink
I also got another error (Not surprised, this IS my frist plugin) It said this.
syntax error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting ')' in /home/gfxcafen/public_html/test/inc/plugins/status.php on line 35
Line 35
"lenth" => '0'

Here is all the code to see if you guys can see how many other errors I know I made. Toungue

<?php

// Disallow direct access to this file for security reasons
if(!defined("IN_MYBB"))
{
	die("Direct initialization of this file is not allowed.<br /><br />Please make sure IN_MYBB is defined.");
}

function status_info()
{
global $db;

	return array(
		'name'			=> 'Allow user to make their own status',
		'description'	=> 'Users edit there profile, enter a status and it will appear in the postbit',
		'website'		=> 'http://mods.mybb.com/',
		'author'		=> 'Blake',
		'authorsite'	=> 'mcmines.com',
		'version'		=> '1.0',
		'compatibility'	=> '16*',
	);
}

function status_activate()
{

find_replace_templatesets("postbit", "#".preg_quote("{$post['onlinestatus']}")."#i", "{$post['onlinestatus']} <br /><strong>{$post['fid1212']}</strong>");  

//Adds a Custome Profile Field
    $profilefield = array(
		"name" => "Custom Status",
		"description" => "Add's a status for your users",
		"disporder" => '1212',
		"type" => "textarea" 
		"lenth" => '0'
		"maxlength" => '300',
		"required" => "no",
		"editable" => "yes",
		"hidden" => "no",
		);
		$db->insert_query(TABLE_PREFIX."profilefields", $profilefield);
		$fid = $db->insert_id();
		$fieldname = "fid$fid";
		$db->query("ALTER TABLE ".TABLE_PREFIX."userfields ADD $fieldname TEXT;");
		$db->query("OPTIMIZE TABLE ".TABLE_PREFIX."userfields");

}

function status_deactivate()
{
 find_replace_templatesets("postbit", "#".preg_quote('<br /><strong>{$post['$fid1212']}</strong>')."#i", '', 0); 

//Remove Status Field
   global $db;
	
	$db->query("DELETE FROM ".TABLE_PREFIX."profilefields WHERE name='Custom Status'");
}

?>
You forgot a comma here:
  "type" => "textarea" 
So I fixed the other errors I got and when i activated the plugin this came up.

Fatal error: Call to undefined function find_replace_templatesets() in /home/gfxcafen/public_html/test/inc/plugins/status.php on line 27

Back to the Find_replace_templatesets again.
find_replace_templatesets("postbit", "#".preg_quote("{$post['onlinestatus']}")."#i", "{$post['onlinestatus']} <br /><strong>{$post['fid1212']}</strong>");
You need to include the function file before using the function
include MYBB_ROOT."/inc/adminfunctions_templates.php";
What a schock another error. -,-
A SQL error.
Quote:MyBB has experienced an internal SQL error and cannot continue.

SQL Error:
1153 - Got a packet bigger than 'max_allowed_packet' bytes
Query:
UPDATE mybb_templates SET template='

<
b
r

/
>
<
s
t
r
o
n
g
>
<
/
s
t
r
o
n
g
>
{
and it repeats over and over and over!
Like a said in a post above, you need to escape dollar signs in double quotes if you want to use it literally. Otherwise PHP will put the value of the variable (or what he thinks is a variable due to the dollar sign) in the string instead of the variable name.

Try this instead:
find_replace_templatesets("postbit", "#".preg_quote("{\$post['onlinestatus']}")."#i", "{\$post['onlinestatus']} <br /><strong>{\$post['fid1212']}</strong>");
-.-
Fatal error: Call to a member function insert_query() on a non-object in /home/gfxcafen/public_html/test/inc/plugins/status.php on line 43
The line.
$db->insert_query(TABLE_PREFIX."profilefields", $profilefield);

The rest of that code.
$db->insert_query(TABLE_PREFIX."profilefields", $profilefield);
		$fid = $db->insert_id();
		$fieldname = "fid$fid";
		$db->query("ALTER TABLE ".TABLE_PREFIX."userfields ADD $fieldname TEXT;");
		$db->query("OPTIMIZE TABLE ".TABLE_PREFIX."userfields");
In your status_activate() function you still need to get the $db variable from the global scope:
function status_activate()
{
     global $db;

//...............
Pages: 1 2 3 4 5 6