Location: PHPKode > scripts > Skype Status > skype-status/skype.status.class.php
<?php 
// version 1.0.0, created in 12/2008 by hide@address.com 

/* 
* This class reads current account status for any skype account.
* 
* This class is actually a workaround for HTTPS problem when client/browser needs to check skype status via HTTPS secure connection.
* Since skype does not support normally HTTPS requests, it is impossible to determine skype status via client (javascript) implementation.
* Therefore this class attempts to read accoutn status via HTTP (CURL) connection and returns to client status regardless what kind of connection uses.
* All acquired statuses will be cached into local files into directory [skype_accounts]. Cached statuses will be refreshed by default every 120 seconds.
* 

DIRECTORY STRUCTURE:
|skype
|skype/skype_accounts/
|skype/skype_images/skype_online.png
|skype/skype_images/skype_do_not_disturb.png
|skype/skype_images/skype_me.png
|skype/skype_images/skype_not_available.png
|skype/skype_images/skype_away.png
|skype/skype_images/skype_offline.png
|skype/skype.status.class.php

INSTALLATION:

1/ create folder [skype_accounts] with writable permissions
2/ create folder [skype_images] and copy there skype status images. you can replace/create your own images.
3/ set/check correct paths in class and image names
4/ initiate the class - see examples #1 - #3 bellow:

example #1:
$skype = new Skype_Status();
$skype_data = $skype->get_skype_status('myskypename', 120);
echo $skype_data['html'];

example #2:
$skype = new Skype_Status();
$skype->show_picture('myskypename', 120);

example #3:
$skype->show_html('myskypename', 120);
 
* 
* Possible acquired SKYPE status codes:
* 1 = offline/invisible, 
* 2 = Online, 
* 3 = Away, 
* 4 = Not available, 
* 5 = Do not disturb, 
* 6 = invisible (not returned as regular status, returned 1 instead)
* 7 = Skype me
* --------------------
*/
class Skype_Status{

	// directory where skype status images are stored, keep trailing slash
	var $dir_skype_images = './skype_images/';

	// must be writable! - directory where skype account statuseses shall be stored, keep trailing slash
	var $dir_skype_accounts = './skype_accounts/';

	// set your HTTPS proxy server here, or leave empty, sample: $https_proxy_server = '1.20.203.196:6588';
	var $https_proxy_server = ''; 

	// list of skype images for possible statuses
	var $skype_image = array(
		1 => 'skype_offline.png',
		2 => 'skype_online.png',
		3 => 'skype_away.png',
		4 => 'skype_not_available.png',
		5 => 'skype_do_not_disturb.png',
		6 => 'skype_invisible.png', // however returned by SKYPE as status 1
		7 => 'skype_me.png',
	);
	
	// characters that should not appear in filenames
	var $dirty_characters = array(
		'"' => '_',
		"'" => '_',
		'\\' => '_',
		"/" => '_',
		"?" => '',
		// add more characters, if needed...
	);
	
	// set what action should happen if user clicks on skype image [chat|call|add]
	var $default_skype_action = 'chat';
	
	// constructor
	function Skype_Status(){
		if(substr($this->dir_skype_images, -1) != '/'){
			$this->dir_skype_images .= '/';
		}
		if(substr($this->dir_skype_accounts, -1) != '/'){
			$this->dir_skype_accounts .= '/';
		}
		if(!is_dir($this->dir_skype_images)){
			// does not make sense to create directory without skype images, right?
			exit('ERROR (1) - cannot find directory with skype images in ['.$this->dir_skype_images.']. Please create directory with all skype images inside.');
		}
		if(!is_dir($this->dir_skype_accounts) || !is_writable($this->dir_skype_accounts)){
			mkdir($this->dir_skype_accounts, 744);
			// try to create directory with writing permissions for owner
			if(!is_dir($this->dir_skype_accounts)){
				exit('ERROR (2) - cannot find directory for user accounts in ['.$this->dir_skype_accounts.']. Please create directory with writing permissions.');
			}
		}
		if(!extension_loaded('curl')){
			if(!@dl('curl')){ // caution - not supported on multi-threaded apache or in safe mode!
				exit('ERROR (3) - MISSING EXTENSION: [CURL]. Please enable extension CURL in php.ini and try again. Skype status class wont work without CURL library.');
			}
		}
	}

	/**
	* Checks skype status and returns array with
	* 
	* @param mixed $myskypename - the name of the skype account being checked
	* @param mixed $check_frequency - seconds how often should read status from skype server
	* @return array():
	* - status code
	* - status image
	* - status XHTML
	*/
	function get_skype_status($myskypename = 'MYSKYPENAME', $check_frequency = 120){
		if($check_frequency < 30){ // minimum every 30 secs
			$check_frequency = 30;
		}elseif($check_frequency > 7200){ // maximum every 2 hours (120 minutes x 60 secs)
			$check_frequency = 7200;
		}
		$clean_skypename = 	str_replace(
							array_keys($this->dirty_characters), 
							array_values($this->dirty_characters), 
							$myskypename
		);
		// full path to file where status will be stored (cached)
		$path = $this->dir_skype_accounts.'skype_status.'.$clean_skypename.'.txt';
		$now = time();

		if(file_exists($path)){ // any previously cached status for this account?
			$status_code = intval(file_get_contents($path)); // read previous status
			$last_check = filemtime($path); // read last status timestamp
		}else{
			$status_code = 1; // offline, if no file found
			$last_check = $now-$check_frequency-1; // force auto-check
		}

		// shall I read fresh status?
		if($now - $last_check > $check_frequency || !in_array($status_code, array(1,2,3,4,5,7)) || isset($_REQUEST['skype_refresh'])){ // 2x60 secs

			// read skype status directly from SKYPE server via CURL session
			$skype_url = 'http://mystatus.skype.com/'.$myskypename.'.num'; // note - it is calling HTTP link, not HTTPS!
			$cUrl = curl_init();
			curl_setopt($cUrl, CURLOPT_URL, $skype_url);
			curl_setopt($cUrl, CURLOPT_RETURNTRANSFER, 1);
			curl_setopt($cUrl, CURLOPT_TIMEOUT, 5);
			if (trim($this->https_proxy_server) != '') {
				curl_setopt($cUrl, CURLOPT_PROXY, $this->https_proxy_server);
			}
			// read current SKYPE status for your user account 
			// CAUTION - may have longer response time (150-300 ms)
			$status_code = trim(curl_exec($cUrl));
			curl_close($cUrl);

			$status_code = intval($status_code); // convert status to integer
			$f = fopen($path, 'wb'); // write status into locally stored file
			if($f){
				fwrite($f, $status_code); // write new status into file
				fclose($f);
			}
		}
		
		// create locally stored images of your skype status
		$status_img_path = $this->dir_skype_images.$this->skype_image[$status_code];
		if(file_exists($status_img_path)){
			$status_html = '<a href="skype:'.$myskypename.'?'.$this->default_skype_action.'">'
			.'<img src="'.$status_img_path.'" style="border: none;" width="114" height="20" title="Skype status" alt="Skype status" />'
			.'</a>';
		}else{
			$status_html = '';
			$status_img_path = '';
		}

		return array(
			'code' => $status_code, // 1-5 or 7
			'img' => $status_img_path, // relative URL to status image
			'html' => $status_html, // HTML to be just embedded into web page
		);
	}
	
	// shows status image as link with attached skype action (chat, call,...)
	function show_html($myskypename = 'MYSKYPENAME', $check_frequency = 120){
		$data = $this->get_skype_status($myskypename, $check_frequency);
		echo $data['html'];
	}

	// shows only skype image without action
	function show_picture($myskypename = 'MYSKYPENAME', $check_frequency = 120){
		$data = $this->get_skype_status($myskypename, $check_frequency);
		$html = '<img src="'.$data['img'].'" style="border: none;" title="Skype status" alt="Skype status" />';
		echo $html;
	}

	// returns link to status image
	function get_picture_link($myskypename = 'MYSKYPENAME', $check_frequency = 120){
		$data = $this->get_skype_status($myskypename, $check_frequency);
		return $data['img'];
	}

	// returns status code
	function get_code($myskypename = 'MYSKYPENAME', $check_frequency = 120){
		$data = $this->get_skype_status($myskypename, $check_frequency);
		return $data['code'];
	}

}

?>
Return current item: Skype Status