MyBB Community Forums

Full Version: [HELP] Inserting a status icon !
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi, I've been trying to insert this php code in my header, that simply displays an icon when a website is online or offline.
Here's what I have so far, but honestly, I don't know what I am doing :
<?php
if(!defined("IN_MYBB"))
{
	die("Direct initialization of this file is not allowed.<br /><br />Please make sure IN_MYBB is defined.");
}

$plugins->add_hook("index_start", "stat_index_start");

function stat_info()
{
	return array
	(
		"name"=>"Status",
		"description"=>" ",
		"website"=>" ",
		"author"=>" ",
		"version"=>"1.0",
		"compatibility"=>"*"
	);
}

function stat_index_start()
{
$ip = "194.71.10.15";
$ipstatic = "194.71.10.18";
$port = "80";
	if (! $sock = @fsockopen($ip, $port, $num, $error, 3))
		echo "Site is <img src='http://img696.imageshack.us/img696/7649/offlinef.png' alt='Offline'/>";
	else{
		echo "Site is <img src='http://img215.imageshack.us/img215/1135/onlineb.png' alt='Online'/>";
		fclose($sock);
		} 
}
?>

The code is displayed correctly but appears at the top left corner of the index page. I'd like to display it somewhere cute under the header, but I have no idea how to insert it in the forum layout.

Cheers !
Hi,

I would use the "pre_output_page" hook, so you can change the page contents.

In my example, the status will be placed directly under the header (like PM notification).
Of course you can display it, where ever you want (just change the "div" part, line 39).

<?php
if(!defined("IN_MYBB"))
{
	die("Direct initialization of this file is not allowed.<br /><br />Please make sure IN_MYBB is defined.");
}

$plugins->add_hook("pre_output_page", "stat_run");

function stat_info()
{
	return array
	(
		"name"=>"Status",
		"description"=>" ",
		"website"=>" ",
		"author"=>" ",
		"version"=>"1.0",
		"compatibility"=>"*"
	);
}

function stat_run($page)
{
	$ip = "194.71.10.15";
	$ipstatic = "194.71.10.18";
	$port = "80";
	
	if (! $sock = @fsockopen($ip, $port, $num, $error, 3))
	{
		$status = "Site is <img src='http://img696.imageshack.us/img696/7649/offlinef.png' alt='Offline'/>";
	}
	else
	{
		$status = "Site is <img src='http://img215.imageshack.us/img215/1135/onlineb.png' alt='Online'/>";
		fclose($sock);
	}

	$page = str_replace("<div id=\"content\">", "<div id=\"content\">$status", $page);

	return $page;
}
?>

Code tested (without fsock parts) and works for me - I hope it helps you Wink
(2010-09-15, 07:38 PM)Cayo Wrote: [ -> ]Hi,

I would use the "pre_output_page" hook, so you can change the page contents.

In my example, the status will be placed directly under the header (like PM notification).
Of course you can display it, where ever you want (just change the "div" part, line 39).

<?php
if(!defined("IN_MYBB"))
{
	die("Direct initialization of this file is not allowed.<br /><br />Please make sure IN_MYBB is defined.");
}

$plugins->add_hook("pre_output_page", "stat_run");

function stat_info()
{
	return array
	(
		"name"=>"Status",
		"description"=>" ",
		"website"=>" ",
		"author"=>" ",
		"version"=>"1.0",
		"compatibility"=>"*"
	);
}

function stat_run($page)
{
	$ip = "194.71.10.15";
	$ipstatic = "194.71.10.18";
	$port = "80";
	
	if (! $sock = @fsockopen($ip, $port, $num, $error, 3))
	{
		$status = "Site is <img src='http://img696.imageshack.us/img696/7649/offlinef.png' alt='Offline'/>";
	}
	else
	{
		$status = "Site is <img src='http://img215.imageshack.us/img215/1135/onlineb.png' alt='Online'/>";
		fclose($sock);
	}

	$page = str_replace("<div id=\"content\">", "<div id=\"content\">$status", $page);

	return $page;
}
?>

Code tested (without fsock parts) and works for me - I hope it helps you Wink
Hmm nice Smile.
I'll try your version asap.

Thank you !