MyBB Community Forums

Full Version: Online status color / header modification question
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
Q1) I can't find the place to alter the online / offline status text, right below a user's avatar, at the left of a comment, which says "status: online".

It's always bright green. How do I alter that?

The same for "Warning Level", (warning plugin) -> 0%

Q2) I want to change the header, preferably by creating a header-plugin. Goal is to be able to fill in a left logo graphics path, a right logo graphics path, and a small gradient bitmap path , which creates a horizontal area behind the left and right logo (repeat-x). That means i have 3 or 4 variables, that I want to pass on to the template to be used (header).

This shouldn't be too hard, however: i don't have a clue what hook to use: is there documentation available which hook does what, exactly, and when a hook is called? I can only find some minor documentation... Also: how can I find the available vars to use in the templates? (like $mybb_user etc.)? I've tried all kinds of hooks, but wich one should I use to pass a value which I can use in the header template?
spritje Wrote:Q1) I can't find the place to alter the online / offline status text, right below a user's avatar, at the left of a comment, which says "status: online".

It's always bright green. How do I alter that?


Try Templates -> Post Bit Templates (expand this) ->postbit_author_user
The code should be there in
postbit_author_user
spritje Wrote:Q2) I want to change the header, preferably by creating a header-plugin. Goal is to be able to fill in a left logo graphics path, a right logo graphics path, and a small gradient bitmap path , which creates a horizontal area behind the left and right logo (repeat-x). That means i have 3 or 4 variables, that I want to pass on to the template to be used (header).

This shouldn't be too hard, however: i don't have a clue what hook to use: is there documentation available which hook does what, exactly, and when a hook is called? I can only find some minor documentation... Also: how can I find the available vars to use in the templates? (like $mybb_user etc.)? I've tried all kinds of hooks, but wich one should I use to pass a value which I can use in the header template?

Create a function in your plugin wich load your variables. In this function your have to call the header templat. You can call your header template with.
eval("\$header = \"".$tempaltes->get("header")."\";");
The calling of the template have to be on the end of your function.
You can inplend your plugin with the hook "global_end". Have fun. Smile

Garlant
Thanks for the reply...

The plugin variables are already available in the plugin code. In the board settings I have defined a setting fhdr_leftlogo, and I filled in a value for it. This value is now available in the plugin code. It shows above the header when I echo it from the plugin hook:

//HOOK declaration
$plugins->add_hook("pre_output_page", "fancyheader_output_page");

//HOOK implementation
function fancyheader_global_end()
{
	global $mybb;
	echo $mybb->settings['fhdr_leftlogo'];
}

But how do I pass fhdr_leftlogo from the plugin to the header template? That's the only thing I can't get to work. In the header template I want to load and format the logo. I have tried filling a Post variable, a static variable, global variable, nothing seems to work. Sad
Nobody knows how to do this? Or is it just plain stupid to ask such a thing. I imagine it's quite simple, but yet I was not able to make it work.
Du you have inpelnded a activate and a deactivate function in this plugin?
You can use the template replace function in your activation function.

In your activate function should be this:
	global $db;
	require MYBB_ROOT."/inc/adminfunctions_templates.php";
	find_replace_templatesets("templatename",  '#the_part_which should_replaced#', "the_new_part");

In your function which will used from the hook should be code like this:
function fancyheader_global_end()
{
    global $mybb,$templates;
	
    $img_left = $mybb->settings['fhdr_leftlogo'];
	$img_right = $mybb->settings['fhdr_rightlogo'];
	...
	// We call the header template.
	eval("\$header = \"".$templates->get("header")."\";");
	return $header;
}  
Its only a samll (and bad, too) example to show how to work in an plugin. I really hope this will help you. ^^'
How exactly would this make make the fhdr_leftlogo variable available in the template??? I never see you setting the fhdr_leftlogo var in the first place.

find_replace_templatesets? Part that should be replaced? I haven't got a clue...

After all of this i would have the $img_left and $img_right vars available in the template?
It's your Plugin right? Only you know how your plugin should work and or look. So I only can help in small code examples. You have to use your program knowledge. ...

The easiest way to see how the template replace funktion is working is to open a plugin to see the source. (Ok, now I'll give you another example)
Create a aile with this name "test_plugin.php" in your /inc/plugin folder.

This is the content:
// secure
if(!defined("IN_MYBB"))
{
	die("Direct initialization of this file is not allowed.<br /><br />Please make sure IN_MYBB is defined.");
}
// Your author infos
function test_plugin_info()
{
	return array(
		"name"			=> "Plugin Name",
		"description"		=> "I'll descripe my plugin",
		"website"		=> "http://www",
		"author"		=> "Author",
		"authorsite"		=> "http://www",
		"version"		=> "x.x.x",
	);
}

An activate function give you one chance to insert new fields, tables, templates, change templates, ... and so on.
function test_plugin_activate()
{
	// we load the replace function
	require MYBB_ROOT."/inc/adminfunctions_templates.php";
	#Example:
	//find_replace_templatesets("templatename",  '#the_part_which should_replaced#', "the_new_part"); 
	find_replace_templatesets("header",  '#{\$bbclosedwarning}#', "{\$bbclosedwarning}\r\n{\$hello_world}");
}
You can deaktivate your plugin so you need an deactivate function to. You revert all changes.
function test_plugin_activate()
{

	// This will remove §hello_world from your header template
	find_replace_templatesets("header",  '#{\$hello_world}\r\n#', "", 0);
}
We're useing a hook. ....
$plugins->add_hook("global_end", "test_plugin_hello_world");
function test_plugin_hello_world()
{

	$hello_world = "<ul><li>Hello World</li></ul>";
	eval("\$header .= \"".$tempaltes->get("header")."\";"); 
return $hello_world;
}
I hope this example will help you to understand how the replace funktion is working. This example plugin is not tested but should work. After activation you can see a Hello World message under your welcome planel.

Garlant
Thanks a lot Garlant! Your help is greatly appreciated. I'll look into your reply this evening. Thanks for your time and help. Since I'm totally new to MyBBS and the plugin system this sure helps a lot.
Call me stupid if you like. I have spent several hours. It works, great, but only for already existing variables in the template, like bbclosedwarning.

If I try replacing a random piece of html in the template it just won't work. Even variables, like $test, which I place inside the header, nope. Just won't work.

Even when I take bbclosedwarning in the header, add a bbclosedwarning1 right below it, it's not going to change or add anything. I am puzzled by "find_replace_templatesets". It does work for bbclosedwarning, but not for a newly added variable.

What am I missing here? I feel like a total idiot right now, having 15+ years of software development experience (desktop only), I can't seem to figure this out. I know what regular expressions are. I also know that find_replace_templatesets uses regex for the find argument, but still... Any help on this last matter is greatly appreciated, I am so close, this is just stupid.
Pages: 1 2