« Projects list

Quick links

Jabbim-Status

I developped this class for showing my IM status on my Website and why not on other Websites I use to visit.

The only one constraint is that this script works only with Jabber and only with Jabbim. Do you use Windows Live Messenger? I do too.
The idea is to use an IM client which could manage several different IM protocols in the same time. Personally, as Mac OS X user, I chose Adium which suits my needs. Connect both accounts (Windows Live Messenger and Jabbim) and now, you are ready to spread out to the world when you are connected or not.

This script provides 4 versions of your status :

Top

Download

Jabbim-Status v.1.20
2009-09-16 — ZIP package (96 Ko)

Changelog

Version 1.20 — 2009-09-16

Version 1.11 — 2009-01-26

Version 1.10 — 2009-01-20

Version 1.00 — 2009-01-19

Top

How to setup?

What you need:

<?php
    
// Here, it's a method from my Smak extended class
    
public function getJabberStatus($type 'html')
    {
        
// Switches outputting mod
        
switch ($type) {
            case 
'img':
                
$filen 'jabber-full.png';
                break;
            case 
'ico':
                
$filen 'jabber.png';
                break;
            case 
'text':
                
$filen 'jabber.txt';
                break;
            default:
                
$filen 'jabber.html';
        }
        
        
// Creates a connexion
        
$con curl_init('http://www.eexit.net/' $filen);
        
        
// Provides parameters to the connexion
        
curl_setopt_array($con, array(
            
CURLOPT_HEADER          => false,
            
CURLOPT_RETURNTRANSFER  => true
        
));
        
        
// Launches the query
        
$result curl_exec($con);
        
        
// Closes the connexion
        
curl_close($con);
        
        
// Returns the result
        
return $result;
    }
    
    
// Calls the method
    
echo $this->getJabberStatus();
?>

Top

Source code

<?php
/*
*   ###########
*   #__________#
*   __________#
*   ________#
*   _____###_____²xiT development
*   _________#
*   ___________#
*   #__________#
*   _#________#
*   __#______#
*   ____####
*
*   @version    1.20
*   @author     Joris Berthelot <admin@eexit.net>
*   @copyright  Copyright (c) 2009, Joris Berthelot
*   @license    http://www.opensource.org/licenses/mit-license.php MIT Licence
*/

class JabbimStatus
{    
    
// Jabber ID
    
const JID '@jabbim.com';
    
    
// Status provider URL (%uid% will be replaced by JID constant)
    
const SURL 'http://netlab.cz/status/?jid=%uid%&ib=bulb&type=text';
     
    
// Your Website URL
    
const URL 'http://(www.)foobar.tld/';
    
    
// Paragraphe DOM ID (don't forget spaces around)
    
const DOMID ' id="jabber" ';
    
    
// Images config
    
const IMG_PATH      'img/';
    const 
IMG_EXT       '.png';
    const 
IMG_WIDTH     120;
    const 
IMG_HEIGHT    20;
    const 
IMG_FONT      './Trebuchet_MS.ttf';
    
    
// Default AWAY array key
    // Needed for all custom AWAY statuses
    // Also depending of your Jabber client language
    
const AWAY_KEY 'parti(e)';
    
    
// Statuses will go here
    
private $_curl_info;
    private 
$_result;
    private 
$_status;
    private 
$_extraStatus;
    
    
// Sets image names
    
public $statusIcons = array(
        
'online'    => 'status_online',
        
'chatty'    => 'status_online',
        
'dnd'       => 'status_busy',
        
'away'      => 'status_away',
        
'xa'        => 'status_away',
        
'offline'   => 'status_offline',
        
'timeout'   => 'status_offline'
    
);
    
    
// Sets translations from French to English + manages custom status
    
public $statusTexts = array(
        
'online'    => array(null => 'Online'),
        
'chatty'    => array(null => 'Free to chat'),
        
'away'      => array(
            
null                            => 'Invisible',
            
'parti(e)'                      => 'Away',
            
'au t&eacute;l&eacute;phone'    => 'On the phone',
            
'parti(e) manger'               => 'Out to lunch',
            
'de retour de suite'            => 'Be right back',
            
'inactif'                       => 'Inactive'
        
),
        
'xa'        => array(null => 'Away for a while'),
        
'dnd'       => array(
            
null    => 'Do not disturb',
            
'code'  => 'Coding...'
        
),
        
'offline'   => array(null => 'Offline'),
        
'timeout'   => array(null => '(timeout)')
    ); 
    
    public function 
__construct()
    {
        
$this->_getStatus();
    }
    
    public function 
render() {
        
header("Cache-Control: no-cache, must-revalidate");
        
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT");
        
        switch (
array_shift(@array_keys($_GET))) {
            case 
'img' :
                
header('Content-Type: image/png');
                echo 
$this->showIconStatus();
                break;
            case 
'full' :
                
header('Content-Type: image/png');
                
$this->showFullImgStatus();
                break;
            case 
'text' :
                
header('Content-Type: text/plain');
                echo 
$this->showTextStatus();
                break;
            case 
'debug' :
                
header('Content-Type: text/plain');
                
$this->showDebugStatus();
                break;
            default :
                
header('Content-Type: text/html');
                echo 
$this->showFullHtml();
        }
    }
    
    
// Returns information about request + request result
    
public function showDebugStatus()
    {
        echo 
'Request connexion information:' "\n";
        
var_dump($this->_curl_info);
        echo 
"\n" 'Request original result:' "\n";
        
var_dump($this->_result);
    }
    
    
// Returns the status icon source code
    
public function showIconStatus()
    {
        return @
file_get_contents($this->_getIconPath());
    }
    
    
// Outputs the status text
    
public function showTextStatus()
    {
        return 
$this->_getTextStatus();
    }
    
    
// Generates and outputs status + text as an image
    
public function showFullImgStatus()
    {
        
$img imagecreate(self::IMG_WIDTHself::IMG_HEIGHT) or exit;
        
$status $this->_getTextStatus(false);
        
$icon imagecreatefrompng($this->_getIconPath());
        
        
// Enables transparency
        
imagealphablending($iconfalse);
        
imagesavealpha($icontrue);
        
imagecolortransparent($imgimagecolorallocate($img255255255));
        
        
// Pastes status icon on the final image
        
imagecopy($img$icon22001616);
        
        
// Writes the status text
        
imagefttext($img1002016,
            
imagecolorallocate($img000),
            
self::IMG_FONT,
            
$status
        
);
        
        
// Generates the final image
        
imagepng($img);
        
imagedestroy($img);
    }
    
    public function 
showFullHtml()
    {
        return 
'<p'
                
self::DOMID
                
'><img src="'
                
self::URL
                
'jabber.png" '
                
'alt="status" width="16" height="16" title="'
                
$this->_getTextStatus()
                . 
'" />&nbsp;'
                
$this->_getTextStatus()
                . 
'</p>';
    }
    
    private function 
_getStatus()
    {
        
// Opens a connection to get official status
        
$con curl_init();
        
        
// Sets some connection parameters
        
curl_setopt_array($con, array(
                
CURLOPT_HEADER          => false,
                
CURLOPT_RETURNTRANSFER  => true,
                
CURLOPT_TIMEOUT         => 3,
                
CURLOPT_URL             => str_replace(
                    
'%uid%'self::JIDself::SURL)
        ));
        
        
// Unable to connect
        
if (!$this->_result curl_exec($con)) {
            
$this->_errorMod();
            return;
        }
        
        
// Saves connexion information for debug output
        
$this->_curl_info curl_getinfo($con);
        
        
// Closes the connection
        
curl_close($con);
        
        
// Gets the status
        
$state = @explode(
            
'title="',
            
$this->_result
        
);
        
        
// Unexcepted result
        
if (count($state) < 2) {
            
$this->_errorMod();
            return;
        }
        
        
// Gets official status and extra status
        
$finalState = @explode(':'substr(
            
$state[1],
            
0,
            
stripos($state[1], '"')
        ));
        
        
// Sets status values
        
$this->status strtolower(trim($finalState[0]));
        
$this->extraStatus htmlentities(trim(strtr($finalState[1],
            
'?',
            
' '
        
)), ENT_COMPAT'UTF-8');
    }
    
    
// Sets the status to timeout for the rest of the script
    
private function _errorMod()
    {
        
$this->_status 'timeout';
    }
    
    private function 
_getIconPath()
    {
        
// Fixes a tips because server doesn't make the
        // difference between offine and invisible
        // For the server, invisible = away
        
if ($this->status == 'away' && !$this->extraStatus) {
            
$this->status 'offline';
        }
        
        return 
self::IMG_PATH
            
$this->statusIcons[$this->status]
            . 
self::IMG_EXT;
    }
    
    
// Gets the status as text
    
private function _getTextStatus($extra true)
    {
        
// The extra status exists
        
if (array_key_exists(
                
strtolower($this->extraStatus),
                
$this->statusTexts[$this->status]
            )) {
            return 
$this->statusTexts[$this->status]
                    [
strtolower($this->extraStatus)];
        }
        
        
// The extra status doesn't exist
        
if ($extra) {
            
            
// If the status is a custom one, it's assigned to AWAY by default
            
if ($this->status == 'away') {
                
                
// Returns the status with the AWAY text instead of null value 
                // which is actually INVISIBLE
                
return 
                    
ucfirst($this->statusTexts[$this->status][self::AWAY_KEY])
                    . 
' ('
                    
$this->extraStatus
                    
')';
            }
            
            
// The status is not AWAY then it returns the value to the current 
            // value
            
return ucfirst($this->statusTexts[$this->status][null])
                . 
' ('
                
$this->extraStatus
                
')';
        }
        
        
// These lines are used for the full img format (only status title)
        // Returns the status with the AWAY text instead of null value which 
        // is actually INVISIBLE
        
if ($this->status == 'away') {
            return 
$this->statusTexts[$this->status][self::AWAY_KEY];
        }
        
        
// The status is not AWAY then it returns the value to the current value
        
return $this->statusTexts[$this->status][null];
    }
}

$s = new JabbimStatus();
$s->render();
?>

Top

Open Source Licence

Open source

Jabbim-Status uses the MIT Licence.

Copyright © 2009-2018, Joris Berthelot.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Top