MyBB Community Forums

Full Version: [Problem] Plugin
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi guys, i created a plugin, i upload it in inc/plugins, I go to pca and active but does not give me no errors. I go into the index (which I had set as a hook), but you can't see what I did ... What is wrong? I post the code I did:

<?php

if(!defined("IN_MYBB"))
    die("This file cannot be accessed directly.");

$plugins->add_hook('index_start', 'avvisospiti', './index.php');
$plugins->add_hook('portal_start', 'avvisospiti', './portal.php');

function avvisospiti_info() {
    return array(
      'name'         => 'Avviso Ospiti / Guest warn',
      'description'  => 'Crea un avviso elegante a tutti gli ospiti del vostro forum. Make a elegant warn for all guest of your forum.',
      'website'      => 'http://www.cionfs.it/',
      'author'       => 'Clear',
      'authorsite'   => 'http://www.downloadsafe.altervista.org',
      'version'      => '1',
  );
}

function avvisospiti_lang()
{
    global $lang;
    $lang->load('avvisospiti',false,true);
    $l['avvisospiti_messaggio']='Ciao Ospite, se leggi questo messaggio significa che non sei registrato. <a href="member.php?action=register">Clicca qui</a> per effettuare la registrazione in pochi semplici passaggi e potrai usufruire di tutte le funzioni del nostro Forum . Ti ricordiamo che sono vietati nick volgari o privi di senso (no numeri o lettere a caso) e di presentarti nella sezione apposita per farti conoscere alla nostra community!';
    foreach($l as $key=>$val)
    {
        if(!$lang->$key)
        {
            $lang->$key=$val;
        }
    }
}


function avvisospiti()
{
    global $mybb;
    if($mybb->user['usergroup']==1)
    {
        global $theme,$lang,$avvisospiti;
        avvisospiti_lang();
        $avvisospiti='<head><style>#avviso { background: #000; color: #fff; font-size: 10px; border: 0px solid #94c2e8; padding: 8px; -moz-border-radius: 8px; -webkit-border-radius: 8px;  filter:alpha(opacity=88); -moz-opacity:.88; opacity:.88; -moz-box-shadow:5px 5px 5px #191919; -webkit-box-shadow:5px 5px 5px #191919; box-shadow:5px 5px 5px #191919; } #avviso a:link { color: #fff; text-decoration: none; } #avviso a:visited { color: #fff; text-decoration: none; } #avviso a:hover, #avviiso a:active { color: #fff; text-decoration: underline; } .avviso_fixed { height: auto;  position: fixed;  top: 50%;  right: 0%; width: 280px; } </style></head> <div class="avviso_fixed"><div id="avviso">'.$lang->avvisospiti_messaggio.'</div></div>';
    }
}

?>

As you see I added two hooks, the index.php (start) and portal.php (start) and as a function I put "avvisospiti"

$plugins->add_hook('index_start', 'avvisospiti', './index.php');
$plugins->add_hook('portal_start', 'avvisospiti', './portal.php');

and then I wrote the function "avvisospiti"

function avvisospiti()
{
    global $mybb;
    if($mybb->user['usergroup']==1)
    {
        global $theme,$lang,$avvisospiti;
        avvisospiti_lang();
        $avvisospiti='<head><style>#avviso { background: #000; color: #fff; font-size: 10px; border: 0px solid #94c2e8; padding: 8px; -moz-border-radius: 8px; -webkit-border-radius: 8px;  filter:alpha(opacity=88); -moz-opacity:.88; opacity:.88; -moz-box-shadow:5px 5px 5px #191919; -webkit-box-shadow:5px 5px 5px #191919; box-shadow:5px 5px 5px #191919; } #avviso a:link { color: #fff; text-decoration: none; } #avviso a:visited { color: #fff; text-decoration: none; } #avviso a:hover, #avviiso a:active { color: #fff; text-decoration: underline; } .avviso_fixed { height: auto;  position: fixed;  top: 50%;  right: 0%; width: 280px; } </style></head> <div class="avviso_fixed"><div id="avviso">'.$lang->avvisospiti_messaggio.'</div></div>';
    }
}

where in the code invokes a language:

function avvisospiti_lang()
{
    global $lang;
    $lang->load('avvisospiti',false,true);
    $l['avvisospiti_messaggio']='Ciao Ospite, se leggi questo messaggio significa che non sei registrato. <a href="member.php?action=register">Clicca qui</a> per effettuare la registrazione in pochi semplici passaggi e potrai usufruire di tutte le funzioni del nostro Forum . Ti ricordiamo che sono vietati nick volgari o privi di senso (no numeri o lettere a caso) e di presentarti nella sezione apposita per farti conoscere alla nostra community!';
    foreach($l as $key=>$val)
    {
        if(!$lang->$key)
        {
            $lang->$key=$val;
        }
    }
}

As you can see it should be all right, but I do not understand why they can not see anything in index.php and portal.php Confused

P.S. I also tried to add priority to the hock (index Priority 1 and Priority 2 portal), but nothing ...

Can you help me??? Sad
You don't put index.php and portal.php in the hook like that, it knows where the hooks are, that parameter is to include another file for the plugin.

Also your method of using language strings is completely defeating the point of using them. Language strings are supposed to go in a language file in the ./inc/languages/english/ folder; you've loaded a language file, then put the language string in the file, and run code to set it, but that's what $lang->load does, loads the language file specified and sets the values.

The reason it doesn't show is because you don't seem to be running any code to actually put $avvisospiti into any templates for it to show up. Plus you can't put a <head> tag in there as there's already going to be a <head> tag.
i know but if i put tag <head> works the same xD

So ... if I take off my working language of the sentence and put directly into the code in the function "avvisospiti" what else can I do to see my plugin?
Well, as I said, you're not putting $avvisospiti into any templates, so it's not going to be able to show. You're setting the value of it in your plugin but if it's not in any templates, how will it be shown??
nono, i try to put:

{$avvisospiti}

in the header templates but nothing Sad
I removed the function of language .. the code is correct so apart from the tag <head>?

<?php

if(!defined("IN_MYBB"))
    die("This file cannot be accessed directly.");

$plugins->add_hook('index_start', 'avvisospiti', 1, './index.php');
$plugins->add_hook('portal_start', 'avvisospiti', 2, './portal.php');

function avvisospiti_info() {
    return array(
      'name'         => 'Avviso Ospiti / Guest warn',
      'description'  => 'Crea un avviso elegante a tutti gli ospiti del vostro forum. Make a elegant warn for all guest of your forum.',
      'website'      => 'http://www.cionfs.it/',
      'author'       => 'Clear',
      'authorsite'   => 'http://www.downloadsafe.altervista.org',
      'version'      => '1',
  );
}


function avvisospiti()
{
	global $mybb;
	if($mybb->user['usergroup']==1)
	{
		global $theme,$avvisospiti;
		$avvisospiti='<head><style>#avviso { background: #000; color: #fff; font-size: 10px; border: 0px solid #94c2e8; padding: 8px; -moz-border-radius: 8px; -webkit-border-radius: 8px;  filter:alpha(opacity=88); -moz-opacity:.88; opacity:.88; -moz-box-shadow:5px 5px 5px #191919; -webkit-box-shadow:5px 5px 5px #191919; box-shadow:5px 5px 5px #191919; } #avviso a:link { color: #fff; text-decoration: none; } #avviso a:visited { color: #fff; text-decoration: none; } #avviso a:hover, #avviiso a:active { color: #fff; text-decoration: underline; } .avviso_fixed { height: auto;  position: fixed;  top: 50%;  right: 0%; width: 280px; } </style></head> <div class="avviso_fixed"><div id="avviso">Ciao Ospite, se leggi questo messaggio significa che non sei registrato. <a href="member.php?action=register">Clicca qui</a> per effettuare la registrazione in pochi semplici passaggi e potrai usufruire di tutte le funzioni del nostro Forum . Ti ricordiamo che sono vietati nick volgari o privi di senso (no numeri o lettere a caso) e di presentarti nella sezione apposita per farti conoscere alla nostra community!</div></div>';
	}
}

?>
It's not going to work in the header template, because the header template is loaded before the index_start and portal_start hooks are run.

And again, you don't need to put index.php and portal.php in the plugin hooks, remove that.
i tried to remove:

plugins $->add_hook('index_start', 'avvisospiti', 1, 'index.php. /';)
plugins $->add_hook('portal_start', 'avvisospiti', 2, 'portal.php. /';)

But nothing >.<
exist a hook for header?
I don't think you're understanding what I'm saying. Change this:

$plugins->add_hook('index_start', 'avvisospiti', 1, './index.php');
$plugins->add_hook('portal_start', 'avvisospiti', 2, './portal.php');

to this:

$plugins->add_hook('index_start', 'avvisospiti');
$plugins->add_hook('portal_start', 'avvisospiti');

You don't need to put index.php and portal.php in there; it shouldn't be stoping it working, but it's unnecessary.

If you want this to show in the header you'll need to use global_start:

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

Then you'll need to add a check for index.php and portal.php to your funtion:

function avvisospiti()
{
    global $mybb;
    if($mybb->user['usergroup']==1)
    {
        if(THIS_SCRIPT == "index.php" || THIS_SCRIPT == "portal.php")
        {
            global $theme,$avvisospiti;
            $avvisospiti='<head><style>#avviso { background: #000; color: #fff; font-size: 10px; border: 0px solid #94c2e8; padding: 8px; -moz-border-radius: 8px; -webkit-border-radius: 8px;  filter:alpha(opacity=88); -moz-opacity:.88; opacity:.88; -moz-box-shadow:5px 5px 5px #191919; -webkit-box-shadow:5px 5px 5px #191919; box-shadow:5px 5px 5px #191919; } #avviso a:link { color: #fff; text-decoration: none; } #avviso a:visited { color: #fff; text-decoration: none; } #avviso a:hover, #avviiso a:active { color: #fff; text-decoration: underline; } .avviso_fixed { height: auto;  position: fixed;  top: 50%;  right: 0%; width: 280px; } </style></head> <div class="avviso_fixed"><div id="avviso">Ciao Ospite, se leggi questo messaggio significa che non sei registrato. <a href="member.php?action=register">Clicca qui</a> per effettuare la registrazione in pochi semplici passaggi e potrai usufruire di tutte le funzioni del nostro Forum . Ti ricordiamo che sono vietati nick volgari o privi di senso (no numeri o lettere a caso) e di presentarti nella sezione apposita per farti conoscere alla nostra community!</div></div>';
        }
    }
}
wooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooorks Big Grin xDDDDDD

Can i add you nickname in the credits fo my plugin??? Big Grin