Current time: 07-29-2014, 04:54 PM Hello There, Guest! (LoginRegister)


Post Reply 
[HELP] Inserting a status icon !
09-15-2010, 05:26 PM
Post: #1
[HELP] Inserting a status icon !
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 !
Find all posts by this user
Quote this message in a reply
09-15-2010, 07:38 PM (This post was last modified: 09-15-2010 07:44 PM by Cayo.)
Post: #2
RE: [HELP] Inserting a status icon !
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
Find all posts by this user
Quote this message in a reply
09-15-2010, 11:14 PM
Post: #3
RE: [HELP] Inserting a status icon !
(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 !
Find all posts by this user
Quote this message in a reply
Post Reply 


Forum Jump:


User(s) browsing this thread: 1 Guest(s)

Contact Us | MyBB | Return to Top | Return to Content | Lite (Archive) Mode | RSS Syndication