TeamSpeak 3 PHP Framework  1.1.23
Copyright © Planet TeamSpeak. All rights reserved.
 All Classes Namespaces Files Functions Variables Pages
TeamSpeak3_Helper_Convert Class Reference

Helper class for data conversion. More...

Static Public Member Functions

static bytes ($bytes)
 Converts bytes to a human readable value. More...
 
static seconds ($seconds, $is_ms=FALSE, $format="%dD %02d:%02d:%02d")
 Converts seconds/milliseconds to a human readable value. More...
 
static codec ($codec)
 Converts a given codec ID to a human readable name. More...
 
static groupType ($type)
 Converts a given group type ID to a human readable name. More...
 
static permissionType ($type)
 Converts a given permission type ID to a human readable name. More...
 
static permissionCategory ($pcat)
 Converts a given permission category value to a human readable name. More...
 
static logLevel ($level)
 Converts a given log level ID to a human readable name and vice versa. More...
 
static logEntry ($entry)
 Converts a specified log entry string into an array containing the data. More...
 
static password ($plain)
 Converts a given string to a ServerQuery password hash. More...
 
static version ($version, $format="Y-m-d h:i:s")
 Returns a client-like formatted version of the TeamSpeak 3 version string. More...
 
static versionShort ($version)
 Returns a client-like short-formatted version of the TeamSpeak 3 version string. More...
 
static imageMimeType ($binary)
 Tries to detect the type of an image by a given string and returns it. More...
 

Detailed Description

Helper class for data conversion.

Definition at line 32 of file Convert.php.

Member Function Documentation

static TeamSpeak3_Helper_Convert::bytes (   $bytes)
static

Converts bytes to a human readable value.

Parameters
integer$bytes
Returns
string

Definition at line 40 of file Convert.php.

Referenced by TeamSpeak3_Node_Abstract\getInfo().

41  {
42  $kbytes = sprintf("%.02f", $bytes/1024);
43  $mbytes = sprintf("%.02f", $kbytes/1024);
44  $gbytes = sprintf("%.02f", $mbytes/1024);
45  $tbytes = sprintf("%.02f", $gbytes/1024);
46 
47  if($tbytes >= 1)
48  return $tbytes . " TB";
49  if($gbytes >= 1)
50  return $gbytes . " GB";
51  if($mbytes >= 1)
52  return $mbytes . " MB";
53  if($kbytes >= 1)
54  return $kbytes . " KB";
55 
56  return $bytes . " B";
57  }
static TeamSpeak3_Helper_Convert::seconds (   $seconds,
  $is_ms = FALSE,
  $format = "%dD %02d:%02d:%02d" 
)
static

Converts seconds/milliseconds to a human readable value.

Parameters
integer$seconds
boolean$is_ms
string$format
Returns
string

Definition at line 67 of file Convert.php.

Referenced by TeamSpeak3_Viewer_Html\getCorpusTitle(), and TeamSpeak3_Node_Abstract\getInfo().

67  :%02d:%02d")
68  {
69  if($is_ms) $seconds = $seconds/1000;
70 
71  return sprintf($format, $seconds/60/60/24, ($seconds/60/60)%24, ($seconds/60)%60, $seconds%60);
72  }
static TeamSpeak3_Helper_Convert::codec (   $codec)
static

Converts a given codec ID to a human readable name.

Parameters
integer$codec
Returns
string

Definition at line 80 of file Convert.php.

References TeamSpeak3\CODEC_CELT_MONO, TeamSpeak3\CODEC_OPUS_MUSIC, TeamSpeak3\CODEC_OPUS_VOICE, TeamSpeak3\CODEC_SPEEX_NARROWBAND, TeamSpeak3\CODEC_SPEEX_ULTRAWIDEBAND, and TeamSpeak3\CODEC_SPEEX_WIDEBAND.

Referenced by TeamSpeak3_Viewer_Html\getCorpusTitle().

81  {
83  return "Speex Narrowband";
85  return "Speex Wideband";
87  return "Speex Ultra-Wideband";
88  if($codec == TeamSpeak3::CODEC_CELT_MONO)
89  return "CELT Mono";
90  if($codec == TeamSpeak3::CODEC_OPUS_VOICE)
91  return "Opus Voice";
92  if($codec == TeamSpeak3::CODEC_OPUS_MUSIC)
93  return "Opus Music";
94 
95  return "Unknown";
96  }
static TeamSpeak3_Helper_Convert::groupType (   $type)
static

Converts a given group type ID to a human readable name.

Parameters
integer$type
Returns
string

Definition at line 104 of file Convert.php.

References TeamSpeak3\GROUP_DBTYPE_REGULAR, TeamSpeak3\GROUP_DBTYPE_SERVERQUERY, and TeamSpeak3\GROUP_DBTYPE_TEMPLATE.

Referenced by TeamSpeak3_Viewer_Html\getCorpusTitle().

105  {
107  return "Template";
109  return "Regular";
111  return "ServerQuery";
112 
113  return "Unknown";
114  }
static TeamSpeak3_Helper_Convert::permissionType (   $type)
static

Converts a given permission type ID to a human readable name.

Parameters
integer$type
Returns
string

Definition at line 122 of file Convert.php.

References TeamSpeak3\PERM_TYPE_CHANNEL, TeamSpeak3\PERM_TYPE_CHANNELCLIENT, TeamSpeak3\PERM_TYPE_CHANNELGROUP, TeamSpeak3\PERM_TYPE_CLIENT, and TeamSpeak3\PERM_TYPE_SERVERGROUP.

123  {
125  return "Server Group";
126  if($type == TeamSpeak3::PERM_TYPE_CLIENT)
127  return "Client";
128  if($type == TeamSpeak3::PERM_TYPE_CHANNEL)
129  return "Channel";
131  return "Channel Group";
133  return "Channel Client";
134 
135  return "Unknown";
136  }
static TeamSpeak3_Helper_Convert::permissionCategory (   $pcat)
static

Converts a given permission category value to a human readable name.

Parameters
integer$pcat
Returns
string

Definition at line 144 of file Convert.php.

References TeamSpeak3\PERM_CAT_CHANNEL, TeamSpeak3\PERM_CAT_CHANNEL_ACCESS, TeamSpeak3\PERM_CAT_CHANNEL_CREATE, TeamSpeak3\PERM_CAT_CHANNEL_DELETE, TeamSpeak3\PERM_CAT_CHANNEL_INFORMATION, TeamSpeak3\PERM_CAT_CHANNEL_MODIFY, TeamSpeak3\PERM_CAT_CLIENT, TeamSpeak3\PERM_CAT_CLIENT_ADM_ACTIONS, TeamSpeak3\PERM_CAT_CLIENT_BASICS, TeamSpeak3\PERM_CAT_CLIENT_INFORMATION, TeamSpeak3\PERM_CAT_CLIENT_MODIFY, TeamSpeak3\PERM_CAT_FILETRANSFER, TeamSpeak3\PERM_CAT_GLOBAL, TeamSpeak3\PERM_CAT_GLOBAL_ADM_ACTIONS, TeamSpeak3\PERM_CAT_GLOBAL_INFORMATION, TeamSpeak3\PERM_CAT_GLOBAL_SERVER_MGMT, TeamSpeak3\PERM_CAT_GLOBAL_SETTINGS, TeamSpeak3\PERM_CAT_GROUP, TeamSpeak3\PERM_CAT_GROUP_CREATE, TeamSpeak3\PERM_CAT_GROUP_DELETE, TeamSpeak3\PERM_CAT_GROUP_INFORMATION, TeamSpeak3\PERM_CAT_GROUP_MODIFY, TeamSpeak3\PERM_CAT_NEEDED_MODIFY_POWER, TeamSpeak3\PERM_CAT_SERVER, TeamSpeak3\PERM_CAT_SERVER_ADM_ACTIONS, TeamSpeak3\PERM_CAT_SERVER_INFORMATION, and TeamSpeak3\PERM_CAT_SERVER_SETTINGS.

Referenced by TeamSpeak3_Node_Host\permissionTree().

145  {
146  if($pcat == TeamSpeak3::PERM_CAT_GLOBAL)
147  return "Global";
149  return "Global / Information";
151  return "Global / Virtual Server Management";
153  return "Global / Administration";
155  return "Global / Settings";
156  if($pcat == TeamSpeak3::PERM_CAT_SERVER)
157  return "Virtual Server";
159  return "Virtual Server / Information";
161  return "Virtual Server / Administration";
163  return "Virtual Server / Settings";
164  if($pcat == TeamSpeak3::PERM_CAT_CHANNEL)
165  return "Channel";
167  return "Channel / Information";
169  return "Channel / Create";
171  return "Channel / Modify";
173  return "Channel / Delete";
175  return "Channel / Access";
176  if($pcat == TeamSpeak3::PERM_CAT_GROUP)
177  return "Group";
179  return "Group / Information";
181  return "Group / Create";
183  return "Group / Modify";
185  return "Group / Delete";
186  if($pcat == TeamSpeak3::PERM_CAT_CLIENT)
187  return "Client";
189  return "Client / Information";
191  return "Client / Admin";
193  return "Client / Basics";
195  return "Client / Modify";
197  return "File Transfer";
199  return "Grant";
200 
201  return "Unknown";
202  }
static TeamSpeak3_Helper_Convert::logLevel (   $level)
static

Converts a given log level ID to a human readable name and vice versa.

Parameters
mixed$level
Returns
string

Definition at line 210 of file Convert.php.

References TeamSpeak3\LOGLEVEL_CRITICAL, TeamSpeak3\LOGLEVEL_DEBUG, TeamSpeak3\LOGLEVEL_DEVEL, TeamSpeak3\LOGLEVEL_ERROR, TeamSpeak3\LOGLEVEL_INFO, and TeamSpeak3\LOGLEVEL_WARNING.

211  {
212  if(is_numeric($level))
213  {
214  if($level == TeamSpeak3::LOGLEVEL_CRITICAL)
215  return "CRITICAL";
216  if($level == TeamSpeak3::LOGLEVEL_ERROR)
217  return "ERROR";
218  if($level == TeamSpeak3::LOGLEVEL_DEBUG)
219  return "DEBUG";
220  if($level == TeamSpeak3::LOGLEVEL_WARNING)
221  return "WARNING";
222  if($level == TeamSpeak3::LOGLEVEL_INFO)
223  return "INFO";
224 
225  return "DEVELOP";
226  }
227  else
228  {
229  if(strtoupper($level) == "CRITICAL")
231  if(strtoupper($level) == "ERROR")
233  if(strtoupper($level) == "DEBUG")
235  if(strtoupper($level) == "WARNING")
237  if(strtoupper($level) == "INFO")
239 
241  }
242  }
static TeamSpeak3_Helper_Convert::logEntry (   $entry)
static

Converts a specified log entry string into an array containing the data.

Parameters
string$entry
Returns
array

Definition at line 250 of file Convert.php.

References TeamSpeak3_Helper_String\factory(), and TeamSpeak3\LOGLEVEL_ERROR.

251  {
252  $parts = explode("|", $entry, 5);
253  $array = array();
254 
255  if(count($parts) != 5)
256  {
257  $array["timestamp"] = 0;
258  $array["level"] = TeamSpeak3::LOGLEVEL_ERROR;
259  $array["channel"] = "ParamParser";
260  $array["server_id"] = "";
261  $array["msg"] = TeamSpeak3_Helper_String::factory("convert error (" . trim($entry) . ")");
262  $array["msg_plain"] = $entry;
263  $array["malformed"] = TRUE;
264  }
265  else
266  {
267  $array["timestamp"] = strtotime(trim($parts[0]));
268  $array["level"] = self::logLevel(trim($parts[1]));
269  $array["channel"] = trim($parts[2]);
270  $array["server_id"] = trim($parts[3]);
271  $array["msg"] = TeamSpeak3_Helper_String::factory(trim($parts[4]));
272  $array["msg_plain"] = $entry;
273  $array["malformed"] = FALSE;
274  }
275 
276  return $array;
277  }
static TeamSpeak3_Helper_Convert::password (   $plain)
static

Converts a given string to a ServerQuery password hash.

Parameters
string$plain
Returns
string

Definition at line 285 of file Convert.php.

286  {
287  return base64_encode(sha1($plain, TRUE));
288  }
static TeamSpeak3_Helper_Convert::version (   $version,
  $format = "Y-m-d h:i:s" 
)
static

Returns a client-like formatted version of the TeamSpeak 3 version string.

Parameters
string$version
string$format
Returns
string

Definition at line 297 of file Convert.php.

Referenced by TeamSpeak3_Node_Abstract\getInfo().

297  :i:s")
298  {
299  if(!$version instanceof TeamSpeak3_Helper_String)
300  {
301  $version = new TeamSpeak3_Helper_String($version);
302  }
303 
304  $buildno = $version->section("[", 1)->filterDigits()->toInt();
305 
306  return ($buildno <= 15001) ? $version : $version->section("[")->append("(" . date($format, $buildno) . ")");
307  }
static TeamSpeak3_Helper_Convert::versionShort (   $version)
static

Returns a client-like short-formatted version of the TeamSpeak 3 version string.

Parameters
string$version
Returns
string

Definition at line 315 of file Convert.php.

Referenced by TeamSpeak3_Viewer_Html\getCorpusTitle().

316  {
317  if(!$version instanceof TeamSpeak3_Helper_String)
318  {
319  $version = new TeamSpeak3_Helper_String($version);
320  }
321 
322  return $version->section(" ", 0);
323  }
static TeamSpeak3_Helper_Convert::imageMimeType (   $binary)
static

Tries to detect the type of an image by a given string and returns it.

Parameters
string$binary
Returns
string

Definition at line 331 of file Convert.php.

Referenced by TeamSpeak3_Viewer_Html\getSuffixIconChannel(), TeamSpeak3_Viewer_Html\getSuffixIconClient(), and TeamSpeak3_Viewer_Html\getSuffixIconServer().

332  {
333  if(!preg_match('/\A(?:(\xff\xd8\xff)|(GIF8[79]a)|(\x89PNG\x0d\x0a)|(BM)|(\x49\x49(\x2a\x00|\x00\x4a))|(FORM.{4}ILBM))/', $binary, $matches))
334  {
335  return "application/octet-stream";
336  }
337 
338  $type = array(
339  1 => "image/jpeg",
340  2 => "image/gif",
341  3 => "image/png",
342  4 => "image/x-windows-bmp",
343  5 => "image/tiff",
344  6 => "image/x-ilbm",
345  );
346 
347  return $type[count($matches)-1];
348  }

The documentation for this class was generated from the following file: