Topic: Custom variable or hook in admin head for plugin

Actually we could not add JS or additionnal CSS for our plugins.

A simple conventionned variable could be added to make it possible to add customized code in <head></head> like JS or CSS.

Then in admin_loader.php we load the plugin file before header.php so if (isset($custom_head)) etc.

... not sure my explanation really clear hmm

Re: Custom variable or hook in admin head for plugin

You can add Javascript and stylesheets within <body> hmm

Of course, this will most likely be possible with the extension system in 1.3

Re: Custom variable or hook in admin head for plugin

yes it is that the problem

but if we use the extension mecanism, will must create an extension for a plugin ; so for the purpose we will have to add an extension just for display a JS or CSS code, I think it is not really appropriate
therefor it is really simple to add in header.php a simple test if variable exist we add content to head

Re: Custom variable or hook in admin head for plugin

i've try my idea :

in admin_loader.php, replace

$page_title = pun_htmlspecialchars($pun_config['o_board_title']).' / Admin / '.$plugin;
require PUN_ROOT.'header.php';

// Attempt to load the plugin. We don't use @ here to supress error messages,
// because if we did and a parse error occurred in the plugin, we would only
// get the "blank page of death".
include PUN_ROOT.'plugins/'.$plugin;
if (!defined('PUN_PLUGIN_LOADED'))
    message('Loading of the plugin \''.$plugin.'\' failed.');

by this :

// Attempt to load the plugin. We don't use @ here to supress error messages,
// because if we did and a parse error occurred in the plugin, we would only
// get the "blank page of death".
ob_start();
include PUN_ROOT.'plugins/'.$plugin;
$plugin_content = trim(ob_get_contents());
ob_end_clean();

if (!defined('PUN_PLUGIN_LOADED'))
    message('Loading of the plugin \''.$plugin.'\' failed.');

$page_title = pun_htmlspecialchars($pun_config['o_board_title']).' / Admin / '.$plugin;
require PUN_ROOT.'header.php';

echo $plugin_content;

in header.hp search for :

$user_agent = isset($_SERVER['HTTP_USER_AGENT']) ? strtolower($_SERVER['HTTP_USER_AGENT']) : '';

just before, add :

if (isset($custom_head)) echo $custom_head;

then in plugin file, I could simply add for exemple :

$custom_head =
'<script type="text/javascript">
//<![CDATA[
...
//]]>
</script>';

Re: Custom variable or hook in admin head for plugin

another thing but for same purpose, how to add to <body onload=""> ? no way for the moment, we have to edit .tpl files

I've found in DotClear2 this code :

//
// ChainHandler, py Peter van der Beken
//
function chainHandler(obj, handlerName, handler) {
    obj[handlerName] = (function(existingFunction) {
        return function() {
            handler.apply(this, arguments);
            if (existingFunction)
                existingFunction.apply(this, arguments); 
        };
    })(handlerName in obj ? obj[handlerName] : null);
};

//
// On load
//
chainHandler(window,'onload',function() {
    
});

really simple to add window.onload event...

all of this to allow plugins authors to do more things

Re: Custom variable or hook in admin head for plugin

vin100 wrote:

yes it is that the problem

but if we use the extension mecanism, will must create an extension for a plugin ; so for the purpose we will have to add an extension just for display a JS or CSS code, I think it is not really appropriate

Why? The point of an extension is to allow you to easily add code where there's hooks.
And I don't see why you need it though, there should be no need to edit onload attributes and the rest can all be put within the body

7

Re: Custom variable or hook in admin head for plugin

In 1.3 all of PunBB's javascript (what there is of it) is going to an external file and an onload handler will be used to make it easier to add more javacript so that part of your request is already taken care of.

8 (edited by vin100 2006-09-09 16:14)

Re: Custom variable or hook in admin head for plugin

cool Paul smile

Smarty, perhaps I'm wrong but I think if a plugin will add is proper extension just to fetch some CSS or JS is not efficient, I'm talking in the plugin context ; ok for a "comlpete" mod, extension probably have to add some additionnal code in head and then the use of hook is appropriate, but for a plugin I don't thinks so

then a hook... well, in the absence of another thing it is already better than nothing smile