[HELP] Inserting a status icon !
#1
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 Code:
<?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$error3))
        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 !
Reply
#2
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 Code:
<?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$error3))
    {
        
$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
Reply
#3
(09-15-2010, 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 Code:
<?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$error3))
    {
        
$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 !
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)