Creating an addon and a weird thing happens! Help!

Matthew Hawley

Well-known member
Okay lets see what I'm doing.

So this the Listener.php

Code:
<?php

class MumbleViewer_Listener
{
    public static function templateHook($hookName, &$contents, array $hookParams, XenForo_Template_Abstract $template)
    {
        if ($hookName == 'ad_sidebar_bottom')
        {
            $contents .= $template->create('mumble_viewer_sidebar', $template->getParams());
        }
    }
}

This is the template mumble_viewer_sidebar:

Code:
<div class="section">
    <div class="secondaryContent">
        <h3>{xen:phrase mumble_viewer_sidebar_title}</h3>
                      <iframe src="http://cache.www.gametracker.com/components/html0/?host=193.218.154.228:64738&bgColor=1F2642&fontColor=8790AE&titleBgColor=11172D&titleColor=FFFFFF&borderColor=333333&linkColor=FF9900&borderLinkColor=999999&showMap=0&currentPlayersHeight=160&showCurrPlayers=1&showTopPlayers=0&showBlogs=0&width=240" frameborder="0" scrolling="no" width="240" height="348"></iframe>
    </div>
</div>

And this is what I put into the form for creating a Code Event Listener

addonhelp.webp

Now when I save everything shows up like its supposed to, except this happens. (You may have to look closely, theres a gray space above the moderator bar.

addonproblem.webp

When I put "templateHook" into the Event Hint the problem in the image above goes way, but the template that goes in "ad_sidebar_bottom goes away aswell. I suspect there might be a new way of doing this in 1.2 or something. Anyone know the problem?

Thanks in advance!
 
the event hint for the templatehook is the hookname (did your read the description text? :D )

In your case => ad_sidebar_bottom
 
I also get server errors from the addon im making.

Server Error Log
Error Info
ErrorException: Cannot modify header information - headers already sent by (output started at /home/mcwh/public_html/letspwn.com/store/library/MumbleViewer/Listener.php:1) - library/XenForo/CssOutput.php:558
Generated By: Unknown Account, Today at 2:32 PM
Stack Trace
#0 [internal function]: XenForo_Application::handlePhpError(2, 'Cannot modify h...', '/home/mcwh/publ...', 558, Array)
#1 /home/mcwh/public_html/letspwn.com/store/library/XenForo/CssOutput.php(558): header('Content-type: t...')
#2 /home/mcwh/public_html/letspwn.com/store/library/XenForo/CssOutput.php(590): XenForo_CssOutput->displayCss('@CHARSET "UTF-8...')
#3 /home/mcwh/public_html/letspwn.com/store/css.php(12): XenForo_CssOutput::run()
#4 {main}
Request State
array(3) {
["url"] => string(86) "http://letspwn.com/store/css.php?css=xenforo,form,public&style=15&dir=LTR&d=1371731639"
["_GET"] => array(4) {
["css"] => string(19) "xenforo,form,public"
["style"] => string(2) "15"
["dir"] => string(3) "LTR"
["d"] => string(10) "1371731639"
}
["_POST"] => array(0) {
}
}
 
Normally that error means you are echoing/printing something from PHP file Listener.php, or you have some additional white space after the ?> at the end of the file, but I would suspect xF takes care of that(?)

Do you need the ?> at the end of the listener?
 
I don't think so.

This is the Listener.php

Code:
<?php

class MumbleViewer_Listener
{
    public static function templateHook($hookName, &$contents, array $hookParams, XenForo_Template_Abstract $template)
    {
        if ($hookName == 'ad_sidebar_bottom')
        {
            $contents .= $template->create('mumble_viewer_sidebar', $template->getParams());
        }
    }
}
 
Yeah, you don't need the ?> at the end. Do you have display_errors on in your config? Maybe there's a a notice or something being displayed?
 
I don't know if it will help, but you can try adding this to your config.php temporarily to see if there is a notice or something, but it appears to me something it being sent as output before the headers can be set.

Code:
ini_set('display_errors', true);
 
I don't know if it will help, but you can try adding this to your config.php temporarily to see if there is a notice or something, but it appears to me something it being sent as output before the headers can be set.

Code:
ini_set('display_errors', true);

Added it. Where do the errors show up?
 
I tried it on my 1.1.4 test installation. It completely screwed up the default xf style, but I got the game tracker IFRAME to show up.

matthews_mumble.webp
 
Top Bottom