/[drupal]/contributions/modules/skypesupport/skypesupport.inc
ViewVC logotype

Contents of /contributions/modules/skypesupport/skypesupport.inc

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.2 - (show annotations) (download) (as text)
Sun May 21 20:06:56 2006 UTC (3 years, 6 months ago) by stevemckenzie
Branch: MAIN
CVS Tags: DRUPAL-4-7--1-0, DRUPAL-4-7--1-1, DRUPAL-4-7--1-2, DRUPAL-4-7--1-3, DRUPAL-5--1-0, HEAD
Branch point for: DRUPAL-5, DRUPAL-4-7
Changes since 1.1: +92 -69 lines
File MIME type: text/x-php
cleaned up formatting & added history comment to phpSkype class
1 <?php
2 /**
3 * The class class.phpSkypeStatus.php
4 *
5 * The class.phpSkypeStatus.php class is for viewing the online status of a skype user
6 * please read: http://skype.com/share/buttons/status.html
7 *
8 * @package phpSkypeStatus
9 * @author Bastian Gorke <b.gorke@ipunkt.biz>
10 * @version 2006-03-01
11 *
12 * History:
13 * 2006-05-21: added curl hook for certain servers that no longer support file_get_contents and ImageCreateFromPNG
14 * special thanks to Steve McKenzie & Robin Monks for these additions (Drupal Community Members - www.drupal.org)
15 * 2006-03-01: bug fix
16 * x error with getting xml/image is not longer shown
17 * 2006-02-13: initial version
18 */
19 class phpSkypeStatus
20 {
21 var $skypeid;
22
23 var $statusuri = "http://mystatus.skype.com/%s.xml";
24 var $statusimguri = "http://mystatus.skype.com/%s/%s";
25
26 var $str_status_xml = '';
27
28 function phpSkypeStatus($id = ""){
29 if ($id != "") {
30 $this->setSkypeID($id);
31 }
32 }
33
34 /**
35 * set the skypeid for a user to check
36 */
37 function setSkypeID($id){
38 $this->skypeid = $id;
39 }
40
41 /**
42 * get status from skype mystatus server
43 */
44 function _retrieveStatus(){
45 if (function_exists('curl_init')) {
46 $this->str_status_xml = $this->curlDownload(sprintf($this->statusuri,$this->skypeid));
47 } else {
48 $this->str_status_xml = @file_get_contents(sprintf($this->statusuri,$this->skypeid));
49 }
50 }
51
52 /**
53 * returns the unprocessed xml/rdf data
54 */
55 function getXML(){
56 $this->_retrieveStatus();
57 return $this->str_status_xml;
58 }
59
60 /**
61 * returns status text in specified language. defaults to english
62 *
63 * English en
64 * Deutsch de
65 * Francais fr
66 * italian it
67 * polish pl
68 * Japanese ja
69 * Spanish es
70 * Pt pt
71 * Pt/br pt-br
72 * Swedish se
73 * zh zh-cn
74 * Cn zh-cn
75 * Zh/cn zh-cn
76 * hk zh-tw
77 * tw zh-tw
78 * Zh/tw zh-tw
79 */
80 function getText($lang = "en"){
81 $match = array();
82 $this->_retrieveStatus();
83 $pattern = "~xml:lang=\"".strtolower($lang)."\">(.*)</~";
84 preg_match($pattern,$this->str_status_xml, $match);
85 return $match[1];
86 }
87
88 /**
89 * get the status number
90 *
91 * 0 UNKNOWN Not opted in or no data available.
92 * 1 OFFLINE The user is Offline
93 * 2 ONLINE The user is Online
94 * 3 AWAY The user is Away
95 * 4 NOT AVAILABLE The user is Not Available
96 * 5 DO NOT DISTURB The user is Do Not Disturb (DND)
97 * 6 INVISIBLE The user is Invisible or appears Offline
98 * 7 SKYPE ME The user is in Skype Me mode
99 */
100 function getNum(){
101 $match = array();
102 $this->_retrieveStatus();
103 $pattern = "~xml:lang=\"NUM\">(\d)</~";
104 preg_match($pattern,$this->str_status_xml, $match);
105 return $match[1];
106 }
107
108 /**
109 * returns a php image ressource defined by type
110 * {@see #getImagePNG($type)}
111 *
112 * TODO at this moment, only supports english language images
113 *
114 * type-modes:
115 * balloon - Balloon style
116 * bigclassic - Big Classic Style
117 * smallclassic - Small Classic Style
118 * smallicon - Small Icon (transparent background)
119 * mediumicon - Medium Icon
120 * dropdown-white - Dropdown White Background
121 * dropdown-trans - Dropdown Transparent Background
122 *
123 * defaults to smallicon
124 */
125 function getImageRessource($type = "smallicon"){
126 if (function_exists('curl_init')) {
127 $im = $this->curlDownload(sprintf($this->statusimguri,$type,$this->skypeid));
128 } else {
129 $im = @ImageCreateFromPNG(sprintf($this->statusimguri,$type,$this->skypeid));
130 }
131 if (!$im) return null;
132 return $im;
133 }
134
135 /**
136 * outputs the statusimage as png to browser
137 * {@see #getImageRessource($type)}
138 *
139 * TODO at this moment, only supports english language images
140 *
141 * type-modes:
142 * balloon - Balloon style
143 * bigclassic - Big Classic Style
144 * smallclassic - Small Classic Style
145 * smallicon - Small Icon (transparent background)
146 * mediumicon - Medium Icon
147 * dropdown-white - Dropdown White Background
148 * dropdown-trans - Dropdown Transparent Background
149 *
150 * defaults to smallicon
151 */
152 function getImagePNG($type = "smallicon"){
153 $png = $this->getImageRessource($type);
154 @imagepng($png);
155 }
156
157 /**
158 * outputs the path of the image
159 * {@see #getImageRessource($type)}
160 *
161 * TODO at this moment, only supports english language images
162 *
163 * type-modes:
164 * balloon - Balloon style
165 * bigclassic - Big Classic Style
166 * smallclassic - Small Classic Style
167 * smallicon - Small Icon (transparent background)
168 * mediumicon - Medium Icon
169 * dropdown-white - Dropdown White Background
170 * dropdown-trans - Dropdown Transparent Background
171 *
172 * defaults to smallicon
173 */
174 function getImagePath($type = "smallicon") {
175 return sprintf($this->statusimguri,$type,$this->skypeid);
176 }
177
178 /**
179 * implementation of a curl hook
180 */
181 function curlDownload($url) {
182 $ch = curl_init();
183 curl_setopt ($ch, CURLOPT_URL, $url);
184 curl_setopt ($ch, CURLOPT_HEADER, 0);
185 curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
186 $result = curl_exec ($ch);
187 curl_close ($ch);
188 return $result;
189 }
190
191 }
192 ?>

  ViewVC Help
Powered by ViewVC 1.1.2