MyBB Community Forums

Full Version: My plugin is "Imploading"?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
I get this error when going into the settings for my mod.
Warning [2] implode() [function.implode]: Invalid arguments passed - Line: 1157 - File: admin/modules/config/settings.php PHP 5.2.16 (Linux)
File    Line    Function
    errorHandler->error
/admin/modules/config/settings.php    1157    implode
/admin/index.php    483    require

and this on the index.

The following warnings occurred:
Warning [2] call_user_func_array() [function.call-user-func-array]: First argument is expected to be a valid callback, 'adsense_code_insert_header' was given - Line: 101 - File: inc/class_plugins.php PHP 5.2.16 (Linux)
File    Line    Function
[PHP]         errorHandler->error
/inc/class_plugins.php    101    call_user_func_array
/global.php    95    pluginSystem->run_hooks
/index.php    18    require_once
Warning [2] call_user_func_array() [function.call-user-func-array]: First argument is expected to be a valid callback, 'adsense_code_insert_footer' was given - Line: 101 - File: inc/class_plugins.php PHP 5.2.16 (Linux)
File    Line    Function
[PHP]         errorHandler->error
/inc/class_plugins.php    101    call_user_func_array
/index.php    25    pluginSystem->run_hooks

Here is my code.
<?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.");
}
$plugins->add_hook('global_start','adsense_code_insert_header');
$plugins->add_hook('index_start','adsense_code_insert_footer');

function adsense_info()
{
global $db;

    return array(
        'name'            => 'AdSense Code',
        'description'    => 'Add your adsense code (or any ad!) to your index.',
        'website'        => 'http://mods.mybb.com/',
        'author'        => 'Blake',
        'authorsite'    => 'http://mcmines.com',
        'version'        => '1.2',
        'compatibility'    => '16*',
        'guid'           => 'dc9443796a5dfaeb9d75fd5d0bf08be2'
    );
}

function adsense_activate()
{

global $db;
require MYBB_ROOT."/inc/adminfunctions_templates.php";
      $confirm_group = array(
        'gid'            => 'NULL',
        'name'            => 'google_adsense',
        'title'            => 'Adsense Code',
        'description'    => 'Edit your Ad details in here.',
        'disporder'        => "1",
        'isdefault'        => '0',
    );
    $db->insert_query('settinggroups', $confirm_group);
    $gid = $db->insert_id();
    
$adsense_setting_1 = array(
    "sid"            => "NULL",
    "name"            => "adsense_on_off_header",
    "title"            => "Is the plugin active for the header?",
    "description"    => "No means off",
    "optionscode"    => "yesno",
    "value"            => "no",
    "disporder"        => "1",
    "gid"            => intval($gid),
    );
    
    $adsense_setting_2 = array(
    "sid"            => "NULL",
    "name"            => "adsense_code_header",
    "title"            => "Adsense Header Code",
    "description"    => "Post your Ad Code in here",
    "optionscode"    => "textarea",
    "value"            => '',
    "disporder"        => "2",
    "gid"            => intval($gid),
    );
    
    $adsense_setting_3 = array(
    "sid"            => "NULL",
    "name"            => "adsense_on_off_footer",
    "title"            => "Is the plugin active for the footer?",
    "description"    => "No means off",
    "optionscode"    => "yesno",
    "value"            => "no",
    "disporder"        => "3",
    "gid"            => intval($gid),
    );
    
    $adsense_setting_4 = array(
    "sid"            => "NULL",
    "name"            => "adsense_code_footer",
    "title"            => "Adsense Footer Code",
    "description"    => "Post your Ad Code in here",
    "optionscode"    => "textarea",
    "value"            => '',
    "disporder"        => "4",
    "gid"            => intval($gid),
    );
    
    $adsense_setting_5 = array(
    "sid"            => "NULL",
    "name"            => "adsense_name",
    "title"            => "Adsense Title",
    "description"    => "Give your logo's a title. Note! If you are using this mod for Google adsense codes keep the default!",
    "optionscode"    => "textarea",
    "value"            => '',
    "disporder"        => "5",
    "gid"            => intval($gid),
    );
    
    $db->insert_query('settings', $adsense_setting_1);
    $db->insert_query('settings', $adsense_setting_2);
    $db->insert_query('settings', $adsense_setting_3);
    $db->insert_query('settings', $adsense_setting_4);
    $db->insert_query('settings', $adsense_setting_5);
    
     require_once MYBB_ROOT."/inc/adminfunctions_templates.php";
    find_replace_templatesets("header", "#".preg_quote("<navigation>")."#i", "{\$adsense_code_header}");
     require_once MYBB_ROOT."/inc/adminfunctions_templates.php";
    find_replace_templatesets("index", "#".preg_quote("</dl>")."#i", "{\$adsense_code_footer}");
}

function adsense_deactivate()
{
global $db;
    require MYBB_ROOT."/inc/adminfunctions_templates.php";
    $db->delete_query("settings", "name='adsense_on_off'");
    $db->delete_query("settings", "name='adsense_on_off_footer'");
    $db->delete_query("settings", "name='adsense_code_footer'");
    $db->delete_query("settings", "name='adsense_code_header'");
    $db->delete_query("settings", "name='adsense_name'");
    $db->delete_query("settinggroups", "name='google_adsense'");
    rebuild_settings();
    
    require_once MYBB_ROOT."/inc/adminfunctions_templates.php";
    find_replace_templatesets("index", "#".preg_quote("{\$adsense_code_footer}")."#i", "", 0);
    
    require_once MYBB_ROOT."/inc/adminfunctions_templates.php";
    find_replace_templatesets("header", "#".preg_quote("{\$adsense_code_header}")."#i", "", 0);
}

//Header Insert
function myplugin_header()
{
    global $mybb, $adsense_code;
    
    if($mybb->settings['adsense_on_off_header'] == "1")
    {
        $adsense_code_header = "<div style=\"padding: 6px 0px 0px 0px\">
<table class=\"tborder\" cellpadding=\"6\" cellspacing=\"1\" border=\"0\" width=\"100%\" align=\"center\"> 
  
<tr>
<td class=\"thead\">
{$mybb->settings['adsense_name']}
</td>
</tr>
<tr>
<td class=\"alt1\" align=\"center\">
{$mybb->settings['adsense_code_header']}
</td> 
</tr>
</table> 
<br>
</div>";
    }
}
    
//Footer Insert
function myplugin_index()
{
    global $mybb, $adsense_code;
    
    if($mybb->settings['adsense_on_off_footer'] == "1")
    {
        $adsense_code_footer = "<div style=\"padding: 6px 0px 0px 0px\">
<table class=\"tborder\" cellpadding=\"6\" cellspacing=\"1\" border=\"0\" width=\"100%\" align=\"center\"> 
  
<tr>
<td class=\"thead\">
{$mybb->settings['adsense_name']}
</td>
</tr>
<tr>
<td class=\"alt1\" align=\"center\">
{$mybb->settings['adsense_code_footer']}
</td> 
</tr>
</table> 
<br>
</div>";
    }
}
?>
your functions are called myplugin_xxxxx but your add_hooks are asking for adsense_code_xxxx

you need to rename your functions to match your plugin filename

myplugin_header -> adsense_code_insert_header

(2011-06-29, 12:46 AM)pavemen Wrote: [ -> ]your functions are called myplugin_xxxxx but your add_hooks are asking for adsense_code_xxxx

you need to rename your functions to match your plugin filename

myplugin_header -> adsense_code_insert_header
Oh! I see. One other small issue. I am trying to add a 5th setting but it wont appear in the settings area of the acp.... I have NO idea why, here is the code.
 $adsense_setting_5 = array(
    "sid"            => "NULL",
    "name"            => "adsense_logo_name",
    "title"            => "Adsense Title",
    "description"    => "Give your logo's a title. Note! If you are using this mod for Google adsense codes keep the default!",
    "optionscode"    => "textarea",
    "value"            => 'Sponsored Links',
    "disporder"        => "5",
    "gid"            => intval($gid),
    );
    
    $db->insert_query('settings', $adsense_setting_1);
    $db->insert_query('settings', $adsense_setting_2);
    $db->insert_query('settings', $adsense_setting_3);
    $db->insert_query('settings', $adsense_setting_4);
    $db->insert_query('settings', $adsense_setting_5);
    
     require_once MYBB_ROOT."/inc/adminfunctions_templates.php";
    find_replace_templatesets("header", "#".preg_quote("<navigation>")."#i", "{\$adsense_code_header}");
     require_once MYBB_ROOT."/inc/adminfunctions_templates.php";
    find_replace_templatesets("index", "#".preg_quote("</dl>")."#i", "{\$adsense_code_footer}");
}

function adsense_deactivate()
{
global $db;
    require MYBB_ROOT."/inc/adminfunctions_templates.php";
    $db->delete_query("settings", "name='adsense_on_off'");
    $db->delete_query("settings", "name='adsense_on_off_footer'");
    $db->delete_query("settings", "name='adsense_code_footer'");
    $db->delete_query("settings", "name='adsense_code_header'");
    $db->delete_query("settings", "name='adsense_logo_name'");
    $db->delete_query("settinggroups", "name='google_adsense'");
    rebuild_settings();

I think that you need to escape the apostrophe in the description

"description"    => "Give your logo\'s a title. Note! If you are using this mod for Google adsense codes keep the default!",
You also need to rebuild_settings(); after inserting settings query.
Thanks that fixed it but this is happening.

The following warnings occurred:
Warning [2] call_user_func_array() [function.call-user-func-array]: First argument is expected to be a valid callback, 'adsense_code_insert_header' was given - Line: 101 - File: inc/class_plugins.php PHP 5.2.16 (Linux)
File	Line	Function
[PHP]	 	errorHandler->error
/inc/class_plugins.php	101	call_user_func_array
/global.php	95	pluginSystem->run_hooks
/index.php	18	require_once
Warning [2] call_user_func_array() [function.call-user-func-array]: First argument is expected to be a valid callback, 'adsense_code_insert_footer' was given - Line: 101 - File: inc/class_plugins.php PHP 5.2.16 (Linux)
File	Line	Function
[PHP]	 	errorHandler->error
/inc/class_plugins.php	101	call_user_func_array
/index.php	25	pluginSystem->run_hooks

<?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.");
}
$plugins->add_hook('global_start','adsense_code_insert_header');
$plugins->add_hook('index_start','adsense_code_insert_footer');

function adsense_info()
{
global $db;

    return array(
        'name'            => 'AdSense Code',
        'description'    => 'Add your adsense code (or any ad!) to your index.',
        'website'        => 'http://mods.mybb.com/',
        'author'        => 'Blake',
        'authorsite'    => 'http://mcmines.com',
        'version'        => '1.2',
        'compatibility'    => '16*',
        'guid'           => 'dc9443796a5dfaeb9d75fd5d0bf08be2'
    );
}

function adsense_activate()
{

global $db;
require MYBB_ROOT."/inc/adminfunctions_templates.php";
      $confirm_group = array(
        'gid'            => 'NULL',
        'name'            => 'google_adsense',
        'title'            => 'Adsense Code',
        'description'    => 'Edit your Ad details in here.',
        'disporder'        => "1",
        'isdefault'        => '0',
    );
    $db->insert_query('settinggroups', $confirm_group);
    $gid = $db->insert_id();
    
$adsense_setting_1 = array(
    "sid"            => "NULL",
    "name"            => "adsense_on_off_header",
    "title"            => "Is the plugin active for the header?",
    "description"    => "No means off",
    "optionscode"    => "yesno",
    "value"            => "no",
    "disporder"        => "1",
    "gid"            => intval($gid),
    );
    
    $adsense_setting_2 = array(
    "sid"            => "NULL",
    "name"            => "adsense_code_header",
    "title"            => "Adsense Header Code",
    "description"    => "Post your Ad Code in here",
    "optionscode"    => "textarea",
    "value"            => '',
    "disporder"        => "2",
    "gid"            => intval($gid),
    );
    
    $adsense_setting_3 = array(
    "sid"            => "NULL",
    "name"            => "adsense_on_off_footer",
    "title"            => "Is the plugin active for the footer?",
    "description"    => "No means off",
    "optionscode"    => "yesno",
    "value"            => "no",
    "disporder"        => "3",
    "gid"            => intval($gid),
    );
    
    $adsense_setting_4 = array(
    "sid"            => "NULL",
    "name"            => "adsense_code_footer",
    "title"            => "Adsense Footer Code",
    "description"    => "Post your Ad Code in here",
    "optionscode"    => "textarea",
    "value"            => '',
    "disporder"        => "4",
    "gid"            => intval($gid),
    );
    
    $adsense_setting_5 = array(
    "sid"            => "NULL",
    "name"            => "adsense_logo_name",
    "title"            => "Adsense Title",
    "description"    => "Give your logo\'s a title. Note! If you are using this mod for Google adsense codes keep the default!",
    "optionscode"    => "textarea",
    "value"            => 'Sponsored Links',
    "disporder"        => "5",
    "gid"            => intval($gid),
    );
    
    $db->insert_query('settings', $adsense_setting_1);
    $db->insert_query('settings', $adsense_setting_2);
    $db->insert_query('settings', $adsense_setting_3);
    $db->insert_query('settings', $adsense_setting_4);
    $db->insert_query('settings', $adsense_setting_5);
    rebuild_settings();
    
     require_once MYBB_ROOT."/inc/adminfunctions_templates.php";
    find_replace_templatesets("header", "#".preg_quote("<navigation>")."#i", "{\$adsense_code_header}");
     require_once MYBB_ROOT."/inc/adminfunctions_templates.php";
    find_replace_templatesets("index", "#".preg_quote("</dl>")."#i", "{\$adsense_code_footer}");
}

function adsense_deactivate()
{
global $db;
    require MYBB_ROOT."/inc/adminfunctions_templates.php";
    $db->delete_query("settings", "name='adsense_on_off'");
    $db->delete_query("settings", "name='adsense_on_off_footer'");
    $db->delete_query("settings", "name='adsense_code_footer'");
    $db->delete_query("settings", "name='adsense_code_header'");
    $db->delete_query("settings", "name='adsense_logo_name'");
    $db->delete_query("settinggroups", "name='google_adsense'");
    rebuild_settings();
    
    require_once MYBB_ROOT."/inc/adminfunctions_templates.php";
    find_replace_templatesets("index", "#".preg_quote("{\$adsense_code_footer}")."#i", "", 0);
    
    require_once MYBB_ROOT."/inc/adminfunctions_templates.php";
    find_replace_templatesets("header", "#".preg_quote("{\$adsense_code_header}")."#i", "", 0);
}

//Header Insert
function myplugin_header()
{
    global $mybb, $adsense_code;
    
    if($mybb->settings['adsense_on_off_header'] == "1")
    {
        $adsense_code_header = "<div style=\"padding: 6px 0px 0px 0px\">
<table class=\"tborder\" cellpadding=\"6\" cellspacing=\"1\" border=\"0\" width=\"100%\" align=\"center\"> 
  
<tr>
<td class=\"thead\">
{$mybb->settings['adsense_logo_name']}
</td>
</tr>
<tr>
<td class=\"alt1\" align=\"center\">
{$mybb->settings['adsense_code_header']}
</td> 
</tr>
</table> 
<br>
</div>";
    }
}
    
//Footer Insert
function myplugin_index()
{
    global $mybb, $adsense_code;
    
    if($mybb->settings['adsense_on_off_footer'] == "1")
    {
        $adsense_code_footer = "<div style=\"padding: 6px 0px 0px 0px\">
<table class=\"tborder\" cellpadding=\"6\" cellspacing=\"1\" border=\"0\" width=\"100%\" align=\"center\"> 
  
<tr>
<td class=\"thead\">
{$mybb->settings['adsense_logo_name']}
</td>
</tr>
<tr>
<td class=\"alt1\" align=\"center\">
{$mybb->settings['adsense_code_footer']}
</td> 
</tr>
</table> 
<br>
</div>";
    }
}
?>
you are back to not having the correct function names. what you put in the add_hook, needs to be present in the plugin
So like this?
//Header Insert
function myplugin_header()
{
    global $mybb, $adsense_code;
    
    if($mybb->settings['adsense_on_off_header'] == "1")
    {
        $adsense_code_header = "<div style=\"padding: 6px 0px 0px 0px\">
<table class=\"tborder\" cellpadding=\"6\" cellspacing=\"1\" border=\"0\" width=\"100%\" align=\"center\"> 
  
<tr>
<td class=\"thead\">
{$mybb->settings['adsense_logo_name']}
</td>
</tr>
<tr>
<td class=\"alt1\" align=\"center\">
{$mybb->settings['adsense_code_header']}
</td> 
</tr>
</table> 
<br>
</div>";
    }
}
    
//Footer Insert
function myplugin_footer()
{
    global $mybb, $adsense_code;
    
    if($mybb->settings['adsense_on_off_footer'] == "1")
    {
        $adsense_code_footer = "<div style=\"padding: 6px 0px 0px 0px\">
<table class=\"tborder\" cellpadding=\"6\" cellspacing=\"1\" border=\"0\" width=\"100%\" align=\"center\"> 
  
<tr>
<td class=\"thead\">
{$mybb->settings['adsense_logo_name']}
</td>
</tr>
<tr>
<td class=\"alt1\" align=\"center\">
{$mybb->settings['adsense_code_footer']}
</td> 
</tr>
</table> 
<br>
</div>";
    }
}
?>
pavemen meant to use the same function name as you've used in hook, like this;

//Header Insert
function adsense_code_insert_header()
{
    global $mybb, $adsense_code;
    
    if($mybb->settings['adsense_on_off_header'] == "1")
    {
        $adsense_code_header = "<div style=\"padding: 6px 0px 0px 0px\">
<table class=\"tborder\" cellpadding=\"6\" cellspacing=\"1\" border=\"0\" width=\"100%\" align=\"center\"> 
  
<tr>
<td class=\"thead\">
{$mybb->settings['adsense_logo_name']}
</td>
</tr>
<tr>
<td class=\"alt1\" align=\"center\">
{$mybb->settings['adsense_code_header']}
</td> 
</tr>
</table> 
<br>
</div>";
    }
}
    
//Footer Insert
function adsense_code_insert_footer()
{
    global $mybb, $adsense_code;
    
    if($mybb->settings['adsense_on_off_footer'] == "1")
    {
        $adsense_code_footer = "<div style=\"padding: 6px 0px 0px 0px\">
<table class=\"tborder\" cellpadding=\"6\" cellspacing=\"1\" border=\"0\" width=\"100%\" align=\"center\"> 
  
<tr>
<td class=\"thead\">
{$mybb->settings['adsense_logo_name']}
</td>
</tr>
<tr>
<td class=\"alt1\" align=\"center\">
{$mybb->settings['adsense_code_footer']}
</td> 
</tr>
</table> 
<br>
</div>";
    }
}
just so you are clear

$plugins->add_hook('global_start','adsense_code_insert_header');

the first paramter "global_start' is the hook name in which 'adsense_code_insert_header' function will run. You do not have an 'adsense_code_insert_header' function.

Pages: 1 2