This class can be used to retrieve the online status of a Skype user.
It can connect to the Skype Web site and retrieve the status information XML record. Then the class can parse the returned information to extract the status code.
The class may also return the user online status as a text or an icon in one of many supported idioms.
advanced_example.php
class.phpSkypeStatus.php
description.html
example.php
It can connect to the Skype Web site and retrieve the status information XML record. Then the class can parse the returned information to extract the status code.
The class may also return the user online status as a text or an icon in one of many supported idioms.
advanced_example.php
Code:
<?php require_once ("class.phpSkypeStatus.php"); if (!isset ($_GET['skype'])) { echo "<form action=\"$PHPSELF\" method=\"GET\">"; echo " SkypeUser: <input type=\"text\" name=\"skype\"/>"; echo "</form>"; die(); } $skypeid = $_GET['skype']; // new status $status = new phpSkypeStatus($skypeid); // if param image = 1 return just the image if ($_GET['image'] == "1") { $status->getImagePNG("smallicon"); } $statusText = $status->getText(); echo<<<EOF <html> <head> <title>$skypeid status is $statusText</title> <style> a { color: #776644; font-weight: bold; text-decoration: none; } </style> </head> <body> <script type="text/javascript" src="/js/skypeCheck.js"></script> <h1>Status of $skypeid is $statusText</h1> <p>This is an advanced example for the phpSkypeStatus class.<br/> It shows a command in dependence on the status of the user:<br/> <a href="skype:$skypeid?userinfo" onclick="return skypeCheck();"><img name="skypestatus" src="$PHPSELF?image=1&skype=$skypeid" width="16" height="16" border="0" align="absmiddle" style="padding-bottom: 4px;" /></a> Skype:<br/> EOF; $fields = array (); switch ($status->getNum()) { case 0 : echo "Sorry, status could not detected. See <a href=\"http://www.skype.com/share/buttons/status.html\">Information about SkypeWebStatus</a>"; break; case 2 : // ONLINE case 7 : // SKYPE ME $fields[] = array ("call", "Call"); $fields[] = array ("sendfile", "Send a file"); case 3 : // AWAY case 4 : // NOT AVAILABLE $fields[] = array ("chat", "Send a textmessage"); case 5 : // DO NOT DISTURB case 1 : // OFFLINE case 6 : // INVISIBLE $fields[] = array ("add", "Add to contact list"); $fields[] = array ("userinfo", "Show Skype profile"); break; default : $fields = array (); break; } drawSelectBox($fields); echo "</p>"; echo "</body></html>"; /* * function to draw with special fields */ function drawSelectBox($fields = array ()) { if (empty ($fields)) return; foreach ($fields as $field) { echo "<a href=\"skype:{$GLOBALS['skypeid']}?{$field[0]}\" onclick=\"return skypeCheck();\">{$field[1]}</a><br/>\n"; } } ?>
Code:
<?php /** * The class class.phpSkypeStatus.php * * The class.phpSkypeStatus.php class is for viewing the online status of a skype user * please read: http://skype.com/share/buttons/status.html * * @package phpSkypeStatus * @author Bastian Gorke <b.gorke@ipunkt.biz> * @version 2006-03-01 * * History: * 2006-03-01: bug fix * x error with getting xml/image is not longer shown * 2006-02-13: initial version */ class phpSkypeStatus { var $skypeid; var $statusuri = "http://mystatus.skype.com/%s.xml"; var $statusimguri = "http://mystatus.skype.com/%s/%s"; var $str_status_xml = ''; function phpSkypeStatus($id = ""){ if ($id != "") { $this->setSkypeID($id); } } /** * set the skypeid for a user to check */ function setSkypeID($id){ $this->skypeid = $id; } /** * get status from skype mystatus server */ function _retrieveStatus(){ $this->str_status_xml = @file_get_contents(sprintf($this->statusuri,$this->skypeid)); } /** * returns the unprocessed xml/rdf data */ function getXML(){ $this->_retrieveStatus(); return $this->str_status_xml; } /** * returns status text in specified language. defaults to english * * English en * Deutsch de * Francais fr * italian it * polish pl * Japanese ja * Spanish es * Pt pt * Pt/br pt-br * Swedish se * zh zh-cn * Cn zh-cn * Zh/cn zh-cn * hk zh-tw * tw zh-tw * Zh/tw zh-tw */ function getText($lang = "en"){ $match = array(); $this->_retrieveStatus(); $pattern = "~xml:lang=\"".strtolower($lang)."\">(.*)</~"; preg_match($pattern,$this->str_status_xml, $match); return $match[1]; } /** * get the status number * * 0 UNKNOWN Not opted in or no data available. * 1 OFFLINE The user is Offline * 2 ONLINE The user is Online * 3 AWAY The user is Away * 4 NOT AVAILABLE The user is Not Available * 5 DO NOT DISTURB The user is Do Not Disturb (DND) * 6 INVISIBLE The user is Invisible or appears Offline * 7 SKYPE ME The user is in Skype Me mode */ function getNum(){ $match = array(); $this->_retrieveStatus(); $pattern = "~xml:lang=\"NUM\">(\d)</~"; preg_match($pattern,$this->str_status_xml, $match); return $match[1]; } /** * returns a php image ressource defined by type * {@see #getImagePNG($type)} * * TODO at this moment, only supports english language images * * type-modes: * balloon - Balloon style * bigclassic - Big Classic Style * smallclassic - Small Classic Style * smallicon - Small Icon (transparent background) * mediumicon - Medium Icon * dropdown-white - Dropdown White Background * dropdown-trans - Dropdown Transparent Background * * defaults to smallicon */ function getImageRessource($type = "smallicon"){ $im = @ImageCreateFromPNG(sprintf($this->statusimguri,$type,$this->skypeid)); if (!$im) return null; return $im; } /** * outputs the statusimage as png to browser * {@see #getImageRessource($type)} * * TODO at this moment, only supports english language images * * type-modes: * balloon - Balloon style * bigclassic - Big Classic Style * smallclassic - Small Classic Style * smallicon - Small Icon (transparent background) * mediumicon - Medium Icon * dropdown-white - Dropdown White Background * dropdown-trans - Dropdown Transparent Background * * defaults to smallicon */ function getImagePNG($type = "smallicon"){ $png = $this->getImageRessource($type); @imagepng($png); } } ?>
Code:
<html><head><title>Description for phpSkypeStatus</title></head> <body> <h1>Description for phpSkypeStatus</h1> <p>This class offers This class offers you all features of the SkypeWeb. You can get the status text in different languages, the status code and all status images.</p> <p>for more information look at <a href="http://skype.com/share/buttons/status.html">http://skype.com/share/buttons/status.html</a>. The code is fully commented with phpDocumentor tags.</p> <p>An example and API description is provided.</p> <h2>functions</h2> <p><b>setSkypeID($id)</b><br/> - set the skypeid for a user to check </p> <p><b>string getXML()</b><br/> - returns the unprocessed xml/rdf data </p> <p><b>string getText($lang)</b><br/> - returns status text (in UTF-8 encoding) in specified language. defaults to english<br/> supported languages: <table> <tr><th>Language</th><th>lang-code</th></tr> <tr><td>English</td><td>en</td></tr> <tr><td>Deutsch</td><td>de</td></tr> <tr><td>Francais</td><td>fr</td></tr> <tr><td>italian</td><td>it</td></tr> <tr><td>polish</td><td>pl</td></tr> <tr><td>Japanese</td><td>ja</td></tr> <tr><td>Spanish</td><td>es</td></tr> <tr><td>Pt</td><td>pt</td></tr> <tr><td>Swedish</td><td>se</td></tr> <tr><td>Pt/br</td><td>pt-br</td></tr> <tr><td>zh, China, Zh/cn</td><td>zh-cn</td></tr> <tr><td>Honkong, Taiwan, Zh/tw</td><td>zh-tw</td></tr> </table> </p> <p><b>int getNum()</b><br/> - get the status id<br/> following status codes may be returned <table> <tr><th>ID</th><th>Status</th><th>this means</th></tr> <tr><td>0</td><td>UNKNOWN</td><td>Not opted in or no data available.</td></tr> <tr><td>1</td><td>OFFLINE</td><td>The user is Offline</td></tr> <tr><td>2</td><td>ONLINE</td><td>The user is Online</td></tr> <tr><td>3</td><td>AWAY</td><td>The user is Away</td></tr> <tr><td>4</td><td>NOT AVAILABLE</td><td>The user is Not Available</td></tr> <tr><td>5</td><td>DO NOT DISTURB</td><td>The user is Do Not Disturb (DND)</td></tr> <tr><td>6</td><td>INVISIBLE</td><td>The user is Invisible or appears Offline</td></tr> <tr><td>7</td><td>SKYPE ME</td><td>The user is in Skype Me mode</td></tr> </table> </p> <p><b>ressource getImageRessource($type)</b><br/> - returns a php image ressource defined by type (defaults to smallicon)<br/> - see getImagePNG($type)<br/> - TODO at this moment, only supports english language images <table> <tr><th>type</th><th>image style</th></tr> <tr><td>balloon</td><td>Balloon style</td></tr> <tr><td>bigclassic</td><td>Big Classic Style</td></tr> <tr><td>smallclassic</td><td>Small Classic Style</td></tr> <tr><td>smallicon</td><td>Small Icon (transparent background)</td></tr> <tr><td>mediumicon</td><td>Medium Icon</td></tr> <tr><td>dropdown-white</td><td>Dropdown White Background</td></tr> <tr><td>dropdown-trans</td><td>Dropdown Transparent Background</td></tr> </table> </p> <p><b>void getImagePNG($type)</b><br/> - outputs the statusimage as png to browser (defaults to smallicon)<br/> - see getImageRessource($type) for options </p> </body></html>
Code:
<?php require_once("class.phpSkypeStatus.php"); $skypeid="bastian.gorke"; // new status $status = new phpSkypeStatus($skypeid); // if param image = 1 return just the image if ($_GET['image'] == "1"){ $status->getImagePNG("smallclassic"); } echo "<html><head><title>".$skypeid." status is ".$status->getText()."</title></head><body>"; echo "<h1>".$skypeid." status is ".$status->getText()."</h1>"; echo "<p>This is a simple example for the phpSkypeStatus class. As you can see my status is: <img src=\"".$PHPSELF."?image=1\" /></p>"; echo "<p>In my language german this status is named ".$status->getText("de")."</p>"; echo "</body></html>"; ?>
Comment