TeamSpeak 3 PHP Framework
Modern use-at-will framework that provides individual components to manage TeamSpeak 3 Server instances
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 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 iconId ($unsigned)
 Converts a specified 32-bit unsigned integer value to a signed 32-bit integer value. More...
 
static imageMimeType ($binary)
 Tries to detect the type of an image by a given string and returns it. More...
 
static logEntry ($entry)
 Converts a specified log entry string into an array containing the data. More...
 
static logLevel ($level)
 Converts a given log level ID to a human readable name and vice versa. More...
 
static password ($plain)
 Converts a given string to a ServerQuery password hash. More...
 
static permissionCategory ($pcat)
 Converts a given permission category value to a human readable name. More...
 
static permissionType ($type)
 Converts a given permission type ID to a human readable name. More...
 
static seconds ($seconds, $is_ms=FALSE, $format="%dD %02d:%02d:%02d")
 Converts seconds/milliseconds to a human readable value. 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...
 

Detailed Description

Helper class for data conversion.

Member Function Documentation

◆ bytes()

static bytes (   $bytes)
static

Converts bytes to a human readable value.

Parameters
integer$bytes
Returns
string
38  {
39  $kbytes = sprintf("%.02f", $bytes/1024);
40  $mbytes = sprintf("%.02f", $kbytes/1024);
41  $gbytes = sprintf("%.02f", $mbytes/1024);
42  $tbytes = sprintf("%.02f", $gbytes/1024);
43 
44  if($tbytes >= 1)
45  return $tbytes . " TB";
46  if($gbytes >= 1)
47  return $gbytes . " GB";
48  if($mbytes >= 1)
49  return $mbytes . " MB";
50  if($kbytes >= 1)
51  return $kbytes . " KB";
52 
53  return $bytes . " B";
54  }

◆ codec()

static codec (   $codec)
static

Converts a given codec ID to a human readable name.

Parameters
integer$codec
Returns
string
78  {
80  return "Speex Narrowband";
82  return "Speex Wideband";
84  return "Speex Ultra-Wideband";
85  if($codec == TeamSpeak3::CODEC_CELT_MONO)
86  return "CELT Mono";
87  if($codec == TeamSpeak3::CODEC_OPUS_VOICE)
88  return "Opus Voice";
89  if($codec == TeamSpeak3::CODEC_OPUS_MUSIC)
90  return "Opus Music";
91 
92  return "Unknown";
93  }
const CODEC_OPUS_VOICE
3: opus voice (interactive)
Definition: TeamSpeak3.php:102
const CODEC_CELT_MONO
3: celt mono (mono, 16bit, 48kHz)
Definition: TeamSpeak3.php:101
const CODEC_SPEEX_ULTRAWIDEBAND
2: speex ultra-wideband (mono, 16bit, 32kHz)
Definition: TeamSpeak3.php:100
const CODEC_SPEEX_WIDEBAND
1: speex wideband (mono, 16bit, 16kHz)
Definition: TeamSpeak3.php:99
const CODEC_SPEEX_NARROWBAND
0: speex narrowband (mono, 16bit, 8kHz)
Definition: TeamSpeak3.php:98
const CODEC_OPUS_MUSIC
3: opus music (interactive)
Definition: TeamSpeak3.php:103

◆ groupType()

static groupType (   $type)
static

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

Parameters
integer$type
Returns
string
102  {
104  return "Template";
106  return "Regular";
108  return "ServerQuery";
109 
110  return "Unknown";
111  }
const GROUP_DBTYPE_SERVERQUERY
2: global query group (used for ServerQuery clients)
Definition: TeamSpeak3.php:159
const GROUP_DBTYPE_TEMPLATE
0: template group (used for new virtual servers)
Definition: TeamSpeak3.php:157
const GROUP_DBTYPE_REGULAR
1: regular group (used for regular clients)
Definition: TeamSpeak3.php:158

◆ iconId()

static iconId (   $unsigned)
static

Converts a specified 32-bit unsigned integer value to a signed 32-bit integer value.

Parameters
integer$unsigned
Returns
integer
283  {
284  $signed = (int) $unsigned;
285 
286  if(PHP_INT_SIZE > 4) // 64-bit
287  {
288  if($signed & 0x80000000) return $signed - 0x100000000;
289  }
290 
291  return $signed;
292  }

◆ imageMimeType()

static imageMimeType (   $binary)
static

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

Parameters
string$binary
Returns
string
347  {
348  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))
349  {
350  return "image/svg+xml";
351  }
352 
353  $type = array(
354  1 => "image/jpeg",
355  2 => "image/gif",
356  3 => "image/png",
357  4 => "image/x-windows-bmp",
358  5 => "image/tiff",
359  6 => "image/x-ilbm",
360  );
361 
362  return $type[count($matches)-1];
363  }

◆ logEntry()

static logEntry (   $entry)
static

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

Parameters
string$entry
Returns
array
248  {
249  $parts = explode("|", $entry, 5);
250  $array = array();
251 
252  if(count($parts) != 5)
253  {
254  $array["timestamp"] = 0;
255  $array["level"] = TeamSpeak3::LOGLEVEL_ERROR;
256  $array["channel"] = "ParamParser";
257  $array["server_id"] = "";
258  $array["msg"] = TeamSpeak3_Helper_String::factory("convert error (" . trim($entry) . ")");
259  $array["msg_plain"] = $entry;
260  $array["malformed"] = TRUE;
261  }
262  else
263  {
264  $array["timestamp"] = strtotime(trim($parts[0]));
265  $array["level"] = self::logLevel(trim($parts[1]));
266  $array["channel"] = trim($parts[2]);
267  $array["server_id"] = trim($parts[3]);
268  $array["msg"] = TeamSpeak3_Helper_String::factory(trim($parts[4]));
269  $array["msg_plain"] = $entry;
270  $array["malformed"] = FALSE;
271  }
272 
273  return $array;
274  }
const LOGLEVEL_ERROR
1: everything that is really bad
Definition: TeamSpeak3.php:83
static factory($string)
Returns a TeamSpeak3_Helper_String object for thegiven string.
Definition: String.php:60

◆ logLevel()

static logLevel (   $level)
static

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

Parameters
mixed$level
Returns
string
208  {
209  if(is_numeric($level))
210  {
211  if($level == TeamSpeak3::LOGLEVEL_CRITICAL)
212  return "CRITICAL";
213  if($level == TeamSpeak3::LOGLEVEL_ERROR)
214  return "ERROR";
215  if($level == TeamSpeak3::LOGLEVEL_DEBUG)
216  return "DEBUG";
217  if($level == TeamSpeak3::LOGLEVEL_WARNING)
218  return "WARNING";
219  if($level == TeamSpeak3::LOGLEVEL_INFO)
220  return "INFO";
221 
222  return "DEVELOP";
223  }
224  else
225  {
226  if(strtoupper($level) == "CRITICAL")
228  if(strtoupper($level) == "ERROR")
230  if(strtoupper($level) == "DEBUG")
232  if(strtoupper($level) == "WARNING")
234  if(strtoupper($level) == "INFO")
236 
238  }
239  }
const LOGLEVEL_ERROR
1: everything that is really bad
Definition: TeamSpeak3.php:83
const LOGLEVEL_DEVEL
5: development output
Definition: TeamSpeak3.php:87
const LOGLEVEL_WARNING
2: everything that might be bad
Definition: TeamSpeak3.php:84
const LOGLEVEL_CRITICAL
0: these messages stop the program
Definition: TeamSpeak3.php:82
const LOGLEVEL_DEBUG
3: output that might help find a problem
Definition: TeamSpeak3.php:85
const LOGLEVEL_INFO
4: informational output
Definition: TeamSpeak3.php:86

◆ password()

static password (   $plain)
static

Converts a given string to a ServerQuery password hash.

Parameters
string$plain
Returns
string
301  {
302  return base64_encode(sha1($plain, TRUE));
303  }

◆ permissionCategory()

static permissionCategory (   $pcat)
static

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

Parameters
integer$pcat
Returns
string
142  {
143  if($pcat == TeamSpeak3::PERM_CAT_GLOBAL)
144  return "Global";
146  return "Global / Information";
148  return "Global / Virtual Server Management";
150  return "Global / Administration";
152  return "Global / Settings";
153  if($pcat == TeamSpeak3::PERM_CAT_SERVER)
154  return "Virtual Server";
156  return "Virtual Server / Information";
158  return "Virtual Server / Administration";
160  return "Virtual Server / Settings";
161  if($pcat == TeamSpeak3::PERM_CAT_CHANNEL)
162  return "Channel";
164  return "Channel / Information";
166  return "Channel / Create";
168  return "Channel / Modify";
170  return "Channel / Delete";
172  return "Channel / Access";
173  if($pcat == TeamSpeak3::PERM_CAT_GROUP)
174  return "Group";
176  return "Group / Information";
178  return "Group / Create";
180  return "Group / Modify";
182  return "Group / Delete";
183  if($pcat == TeamSpeak3::PERM_CAT_CLIENT)
184  return "Client";
186  return "Client / Information";
188  return "Client / Admin";
190  return "Client / Basics";
192  return "Client / Modify";
194  return "File Transfer";
196  return "Grant";
197 
198  return "Unknown";
199  }
const PERM_CAT_CLIENT_MODIFY
01010100: client permissions -> edit clients
Definition: TeamSpeak3.php:210
const PERM_CAT_SERVER_INFORMATION
00100001: virtual server permissions -> virtual server information
Definition: TeamSpeak3.php:192
const PERM_CAT_GLOBAL
00010000: global permissions
Definition: TeamSpeak3.php:186
const PERM_CAT_CLIENT_BASICS
01010011: client permissions -> client basic communication
Definition: TeamSpeak3.php:209
const PERM_CAT_FILETRANSFER
01100000: file transfer permissions
Definition: TeamSpeak3.php:211
const PERM_CAT_GLOBAL_SETTINGS
00010100: global permissions -> global settings
Definition: TeamSpeak3.php:190
const PERM_CAT_GROUP
01000000: group permissions
Definition: TeamSpeak3.php:201
const PERM_CAT_CHANNEL_INFORMATION
00110001: channel permissions -> channel information
Definition: TeamSpeak3.php:196
const PERM_CAT_GROUP_CREATE
01000010: group permissions -> create groups
Definition: TeamSpeak3.php:203
const PERM_CAT_GLOBAL_ADM_ACTIONS
00010011: global permissions -> global administrative actions
Definition: TeamSpeak3.php:189
const PERM_CAT_NEEDED_MODIFY_POWER
11111111: needed permission modify power (grant) permissions
Definition: TeamSpeak3.php:212
const PERM_CAT_GROUP_INFORMATION
01000001: group permissions -> group information
Definition: TeamSpeak3.php:202
const PERM_CAT_CHANNEL
00110000: channel permissions
Definition: TeamSpeak3.php:195
const PERM_CAT_GLOBAL_INFORMATION
00010001: global permissions -> global information
Definition: TeamSpeak3.php:187
const PERM_CAT_CLIENT_ADM_ACTIONS
01010010: client permissions -> client administrative actions
Definition: TeamSpeak3.php:208
const PERM_CAT_GROUP_MODIFY
01000011: group permissions -> edit groups
Definition: TeamSpeak3.php:204
const PERM_CAT_SERVER_SETTINGS
00100011: virtual server permissions -> virtual server settings
Definition: TeamSpeak3.php:194
const PERM_CAT_CLIENT
01010000: client permissions
Definition: TeamSpeak3.php:206
const PERM_CAT_SERVER_ADM_ACTIONS
00100010: virtual server permissions -> virtual server administrative actions
Definition: TeamSpeak3.php:193
const PERM_CAT_SERVER
00100000: virtual server permissions
Definition: TeamSpeak3.php:191
const PERM_CAT_GROUP_DELETE
01000100: group permissions -> delete groups
Definition: TeamSpeak3.php:205
const PERM_CAT_CLIENT_INFORMATION
01010001: client permissions -> client information
Definition: TeamSpeak3.php:207
const PERM_CAT_CHANNEL_MODIFY
00110011: channel permissions -> edit channels
Definition: TeamSpeak3.php:198
const PERM_CAT_CHANNEL_ACCESS
00110101: channel permissions -> access channels
Definition: TeamSpeak3.php:200
const PERM_CAT_CHANNEL_CREATE
00110010: channel permissions -> create channels
Definition: TeamSpeak3.php:197
const PERM_CAT_GLOBAL_SERVER_MGMT
00010010: global permissions -> virtual server management
Definition: TeamSpeak3.php:188
const PERM_CAT_CHANNEL_DELETE
00110100: channel permissions -> delete channels
Definition: TeamSpeak3.php:199

◆ permissionType()

static permissionType (   $type)
static

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

Parameters
integer$type
Returns
string
120  {
122  return "Server Group";
123  if($type == TeamSpeak3::PERM_TYPE_CLIENT)
124  return "Client";
125  if($type == TeamSpeak3::PERM_TYPE_CHANNEL)
126  return "Channel";
128  return "Channel Group";
130  return "Channel Client";
131 
132  return "Unknown";
133  }
const PERM_TYPE_CHANNELCLIENT
4: channel-client specific permission
Definition: TeamSpeak3.php:181
const PERM_TYPE_CHANNEL
2: channel specific permission
Definition: TeamSpeak3.php:179
const PERM_TYPE_SERVERGROUP
0: server group permission
Definition: TeamSpeak3.php:177
const PERM_TYPE_CHANNELGROUP
3: channel group permission
Definition: TeamSpeak3.php:180
const PERM_TYPE_CLIENT
1: client specific permission
Definition: TeamSpeak3.php:178

◆ seconds()

static 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
64  :%02d:%02d")
65  {
66  if($is_ms) $seconds = $seconds/1000;
67 
68  return sprintf($format, $seconds/60/60/24, ($seconds/60/60)%24, ($seconds/60)%60, $seconds%60);
69  }

◆ version()

static 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
312  :i:s")
313  {
314  if(!$version instanceof TeamSpeak3_Helper_String)
315  {
316  $version = new TeamSpeak3_Helper_String($version);
317  }
318 
319  $buildno = $version->section("[", 1)->filterDigits()->toInt();
320 
321  return ($buildno <= 15001) ? $version : $version->section("[")->append("(" . date($format, $buildno) . ")");
322  }

◆ versionShort()

static versionShort (   $version)
static

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

Parameters
string$version
Returns
string
331  {
332  if(!$version instanceof TeamSpeak3_Helper_String)
333  {
334  $version = new TeamSpeak3_Helper_String($version);
335  }
336 
337  return $version->section(" ", 0);
338  }
Helper class for string handling.
Definition: String.php:29

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