MyBB Community Forums

Full Version: Code Help
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
hello everyone
i need some help with this code
first
find_replace_templatesets("header",  '#{\$bbclosedwarning}#', "{\$bbclosedwarning}\r\n{\$display}");
this is working fine
2nd
function display($page){
global $db, $theme, $mybb, $templates;
if ($mybb->settings['enabled_yourplugin'] == 1){
$page = str_replace("<div id=\"content\">", "<div id=\"content\"> hellllllllooooooooo".$mybb->settings['banner']." ", $page);
}
return $page;
} 
2nd working fine on Hook but its displaying nothing in header
please help me

here is entire codes of my plugin
<?php
/**
 * Simplebanner 1.0
 */
$plugins->add_hook("pre_output_page", "display");
require MYBB_ROOT."/inc/adminfunctions_templates.php";
if(!defined("IN_MYBB"))
{
    die("You Cannot Access This File Directly");
}

function simplebanner_info()
{
return array(
        "name"  => "Simplebanner",
        "description"=> "This is a Example Plugin",
        "website"        => "http://www.ismybb.info",
        "author"        => "Dhfola",
        "authorsite"    => "http://www.ismybb.info",
        "version"        => "1.0",
        "guid"             => "",
        "compatibility" => "*"
    );
}
function Simplebanner_activate()
  {
    global $db;
       $Simplebanner_group = array(
        'gid'    => 'NULL',
        'name'  => 'Simplebanner',
        'title'      => 'Simplebanner',
        'description'    => 'Settings For Simplebanner',
        'disporder'    => "1",
        'isdefault'  => 'no',
    );
  find_replace_templatesets("header",  '#{\$bbclosedwarning}#', "{\$bbclosedwarning}\r\n{\$display}");


 $db->insert_query('settinggroups', $Simplebanner_group);
 $gid = $db->insert_id();

 $Simplebanner_setting_1 = array(
'name' => 'banner',
'title' =>'Custom text or banner',
'description' =>'You can enter text or arbitrary code for displayed in below Index Ads.',
'optionscode' => 'textarea',
'value' => '',
'disporder' => 3,
'gid' => intval($gid),
);
   $Simplebanner_setting_2 = array(
        'sid'            => 'NULL',
        'name'        => 'enabled_Simplebanner',
        'title'            => 'Do you want Simplebanner Enabled',
        'description'    => 'If Yes People Can Use Simplebanner, If No People Cannot Use Simplebanner.',
        'optionscode'    => 'yesno',
        'value'        => '1',
        'disporder'        => 1,
        'gid'            => intval($gid),
    );
     $db->insert_query('settings', $Simplebanner_setting_1);
     $db->insert_query('settings', $Simplebanner_setting_2);
     rebuild_settings();
  }
function Simplebanner_deactivate()
  {
  global $db;
   $db->query("DELETE FROM ".TABLE_PREFIX."settings WHERE name IN ('enabled_Simplebanner')");
    $db->query("DELETE FROM ".TABLE_PREFIX."settinggroups WHERE name='Simplebanner'");
rebuild_settings();
 } 




function display($page){
global $db, $theme, $mybb, $templates,$banner;
if ($mybb->settings['enabled_Simplebanner'] == 1){
$page = str_replace("<div id=\"content\">", "<div id=\"content\"> hellllllllooooooooo".$mybb->settings['banner']." ", $page);
}
return $page;
} 

?>



It works fine, although I would suggest adding the require in the activate and deactivate functions instead of requiring it every time whether it's needed or not.
its working fine in Hook but not in header
find_replace_templatesets("header", '#{\$bbclosedwarning}#', "{\$bbclosedwarning}\r\n{\$display}");
its putting $display fine in head template but how to show this by code?
(2011-03-28, 05:51 AM)faran Wrote: [ -> ]its working fine in Hook but not in header
find_replace_templatesets("header", '#{\$bbclosedwarning}#', "{\$bbclosedwarning}\r\n{\$display}");
its putting $display fine in head template but how to show this by code?

If you want to use your code in header template, then you've to change your hook from;
$plugins->add_hook("pre_output_page", "display");
to;
$plugins->add_hook("global_start", "display");
If you want to use your code in header template, then you've to change your hook from;
no i dont
i want to display template in header
function simplebanne(){
    global $db, $mybb, $templates, $simplebanner;
    if ($mybb->settings['simplebanner'] == "1" )
{
    eval("\$simplebanner = \"".$templates->get("simplebanner")."\";");
	
}
   
}  
but its not working
Then add $simplebanner in header template using the global_start hook.
thanks Yaldaram