TeamSpeak 3 PHP Framework
1.1.12
|
Helper class for data conversion. More...
Static Public Member Functions | |
static | bytes ($bytes) |
Converts bytes to a human readable value. | |
static | seconds ($seconds, $is_ms=FALSE, $format="%dD %02d:%02d:%02d") |
Converts seconds/milliseconds to a human readable value. | |
static | codec ($codec) |
Converts a given codec ID to a human readable name. | |
static | groupType ($type) |
Converts a given group type ID to a human readable name. | |
static | permissionType ($type) |
Converts a given permission type ID to a human readable name. | |
static | permissionCategory ($pcat) |
Converts a given permission category value to a human readable name. | |
static | logLevel ($level) |
Converts a given log level ID to a human readable name and vice versa. | |
static | logEntry ($entry) |
Converts a specified log entry string into an array containing the data. | |
static | password ($plain) |
Converts a given string to a ServerQuery password hash. | |
static | version ($version, $format="Y-m-d h:i:s") |
Returns a client-like formatted version of the TeamSpeak 3 version string. | |
static | imageMimeType ($binary) |
Tries to detect the type of an image by a given string and returns it. |
Helper class for data conversion.
Definition at line 32 of file Convert.php.
static TeamSpeak3_Helper_Convert::bytes | ( | $ | bytes | ) | [static] |
Converts bytes to a human readable value.
integer | $bytes |
Definition at line 40 of file Convert.php.
Referenced by TeamSpeak3_Node_Abstract\getInfo().
{ $kbytes = sprintf("%.02f", $bytes/1024); $mbytes = sprintf("%.02f", $kbytes/1024); $gbytes = sprintf("%.02f", $mbytes/1024); $tbytes = sprintf("%.02f", $gbytes/1024); if($tbytes >= 1) return $tbytes . " TB"; if($gbytes >= 1) return $gbytes . " GB"; if($mbytes >= 1) return $mbytes . " MB"; if($kbytes >= 1) return $kbytes . " KB"; return $bytes . " B"; }
static TeamSpeak3_Helper_Convert::seconds | ( | $ | seconds, |
$ | is_ms = FALSE , |
||
$ | format = "%dD %02d:%02d:%02d" |
||
) | [static] |
Converts seconds/milliseconds to a human readable value.
integer | $seconds | |
boolean | $is_ms | |
string | $format |
Definition at line 67 of file Convert.php.
Referenced by TeamSpeak3_Viewer_Html\getCorpusTitle(), and TeamSpeak3_Node_Abstract\getInfo().
:%02d:%02d") { if($is_ms) $seconds = $seconds/1000; return sprintf($format, $seconds/60/60/24, ($seconds/60/60)%24, ($seconds/60)%60, $seconds%60); }
static TeamSpeak3_Helper_Convert::codec | ( | $ | codec | ) | [static] |
Converts a given codec ID to a human readable name.
integer | $codec |
Definition at line 80 of file Convert.php.
References TeamSpeak3\CODEC_CELT_MONO, TeamSpeak3\CODEC_SPEEX_NARROWBAND, TeamSpeak3\CODEC_SPEEX_ULTRAWIDEBAND, and TeamSpeak3\CODEC_SPEEX_WIDEBAND.
Referenced by TeamSpeak3_Viewer_Html\getCorpusTitle().
{ if($codec == TeamSpeak3::CODEC_SPEEX_NARROWBAND) return "Speex Narrowband (8 kHz)"; if($codec == TeamSpeak3::CODEC_SPEEX_WIDEBAND) return "Speex Wideband (16 kHz)"; if($codec == TeamSpeak3::CODEC_SPEEX_ULTRAWIDEBAND) return "Speex Ultra-Wideband (32 kHz)"; if($codec == TeamSpeak3::CODEC_CELT_MONO) return "CELT Mono (48 kHz)"; return "Unknown"; }
static TeamSpeak3_Helper_Convert::groupType | ( | $ | type | ) | [static] |
Converts a given group type ID to a human readable name.
integer | $type |
Definition at line 100 of file Convert.php.
References TeamSpeak3\GROUP_DBTYPE_REGULAR, TeamSpeak3\GROUP_DBTYPE_SERVERQUERY, and TeamSpeak3\GROUP_DBTYPE_TEMPLATE.
Referenced by TeamSpeak3_Viewer_Html\getCorpusTitle().
{ if($type == TeamSpeak3::GROUP_DBTYPE_TEMPLATE) return "Template"; if($type == TeamSpeak3::GROUP_DBTYPE_REGULAR) return "Regular"; if($type == TeamSpeak3::GROUP_DBTYPE_SERVERQUERY) return "ServerQuery"; return "Unknown"; }
static TeamSpeak3_Helper_Convert::permissionType | ( | $ | type | ) | [static] |
Converts a given permission type ID to a human readable name.
integer | $type |
Definition at line 118 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.
{ if($type == TeamSpeak3::PERM_TYPE_SERVERGROUP) return "Server Group"; if($type == TeamSpeak3::PERM_TYPE_CLIENT) return "Client"; if($type == TeamSpeak3::PERM_TYPE_CHANNEL) return "Channel"; if($type == TeamSpeak3::PERM_TYPE_CHANNELGROUP) return "Channel Group"; if($type == TeamSpeak3::PERM_TYPE_CHANNELCLIENT) return "Channel Client"; return "Unknown"; }
static TeamSpeak3_Helper_Convert::permissionCategory | ( | $ | pcat | ) | [static] |
Converts a given permission category value to a human readable name.
integer | $pcat |
Definition at line 140 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().
{ if($pcat == TeamSpeak3::PERM_CAT_GLOBAL) return "Global"; if($pcat == TeamSpeak3::PERM_CAT_GLOBAL_INFORMATION) return "Global / Information"; if($pcat == TeamSpeak3::PERM_CAT_GLOBAL_SERVER_MGMT) return "Global / Virtual Server Management"; if($pcat == TeamSpeak3::PERM_CAT_GLOBAL_ADM_ACTIONS) return "Global / Administration"; if($pcat == TeamSpeak3::PERM_CAT_GLOBAL_SETTINGS) return "Global / Settings"; if($pcat == TeamSpeak3::PERM_CAT_SERVER) return "Virtual Server"; if($pcat == TeamSpeak3::PERM_CAT_SERVER_INFORMATION) return "Virtual Server / Information"; if($pcat == TeamSpeak3::PERM_CAT_SERVER_ADM_ACTIONS) return "Virtual Server / Administration"; if($pcat == TeamSpeak3::PERM_CAT_SERVER_SETTINGS) return "Virtual Server / Settings"; if($pcat == TeamSpeak3::PERM_CAT_CHANNEL) return "Channel"; if($pcat == TeamSpeak3::PERM_CAT_CHANNEL_INFORMATION) return "Channel / Information"; if($pcat == TeamSpeak3::PERM_CAT_CHANNEL_CREATE) return "Channel / Create"; if($pcat == TeamSpeak3::PERM_CAT_CHANNEL_MODIFY) return "Channel / Modify"; if($pcat == TeamSpeak3::PERM_CAT_CHANNEL_DELETE) return "Channel / Delete"; if($pcat == TeamSpeak3::PERM_CAT_CHANNEL_ACCESS) return "Channel / Access"; if($pcat == TeamSpeak3::PERM_CAT_GROUP) return "Group"; if($pcat == TeamSpeak3::PERM_CAT_GROUP_INFORMATION) return "Group / Information"; if($pcat == TeamSpeak3::PERM_CAT_GROUP_CREATE) return "Group / Create"; if($pcat == TeamSpeak3::PERM_CAT_GROUP_MODIFY) return "Group / Modify"; if($pcat == TeamSpeak3::PERM_CAT_GROUP_DELETE) return "Group / Delete"; if($pcat == TeamSpeak3::PERM_CAT_CLIENT) return "Client"; if($pcat == TeamSpeak3::PERM_CAT_CLIENT_INFORMATION) return "Client / Information"; if($pcat == TeamSpeak3::PERM_CAT_CLIENT_ADM_ACTIONS) return "Client / Admin"; if($pcat == TeamSpeak3::PERM_CAT_CLIENT_BASICS) return "Client / Basics"; if($pcat == TeamSpeak3::PERM_CAT_CLIENT_MODIFY) return "Client / Modify"; if($pcat == TeamSpeak3::PERM_CAT_FILETRANSFER) return "File Transfer"; if($pcat == TeamSpeak3::PERM_CAT_NEEDED_MODIFY_POWER) return "Grant"; return "Unknown"; }
static TeamSpeak3_Helper_Convert::logLevel | ( | $ | level | ) | [static] |
Converts a given log level ID to a human readable name and vice versa.
mixed | $level |
Definition at line 206 of file Convert.php.
References TeamSpeak3\LOGLEVEL_CRITICAL, TeamSpeak3\LOGLEVEL_DEBUG, TeamSpeak3\LOGLEVEL_DEVEL, TeamSpeak3\LOGLEVEL_ERROR, TeamSpeak3\LOGLEVEL_INFO, and TeamSpeak3\LOGLEVEL_WARNING.
Referenced by logEntry().
{ if(is_numeric($level)) { if($level == TeamSpeak3::LOGLEVEL_CRITICAL) return "CRITICAL"; if($level == TeamSpeak3::LOGLEVEL_ERROR) return "ERROR"; if($level == TeamSpeak3::LOGLEVEL_DEBUG) return "DEBUG"; if($level == TeamSpeak3::LOGLEVEL_WARNING) return "WARNING"; if($level == TeamSpeak3::LOGLEVEL_INFO) return "INFO"; return "DEVELOP"; } else { if(strtoupper($level) == "CRITICAL") return TeamSpeak3::LOGLEVEL_CRITICAL; if(strtoupper($level) == "ERROR") return TeamSpeak3::LOGLEVEL_ERROR; if(strtoupper($level) == "DEBUG") return TeamSpeak3::LOGLEVEL_DEBUG; if(strtoupper($level) == "WARNING") return TeamSpeak3::LOGLEVEL_WARNING; if(strtoupper($level) == "INFO") return TeamSpeak3::LOGLEVEL_INFO; return TeamSpeak3::LOGLEVEL_DEVEL; } }
static TeamSpeak3_Helper_Convert::logEntry | ( | $ | entry | ) | [static] |
Converts a specified log entry string into an array containing the data.
string | $entry |
Definition at line 246 of file Convert.php.
References TeamSpeak3_Helper_String\factory(), logLevel(), and TeamSpeak3\LOGLEVEL_ERROR.
{ $parts = explode("|", $entry, 5); $array = array(); if(count($parts) != 5) { $array["timestamp"] = 0; $array["level"] = TeamSpeak3::LOGLEVEL_ERROR; $array["channel"] = "ParamParser"; $array["server_id"] = ""; $array["msg"] = TeamSpeak3_Helper_String::factory("convert error (" . trim($entry) . ")"); $array["msg_plain"] = $entry; $array["malformed"] = TRUE; } else { $array["timestamp"] = strtotime(trim($parts[0])); $array["level"] = self::logLevel(trim($parts[1])); $array["channel"] = trim($parts[2]); $array["server_id"] = trim($parts[3]); $array["msg"] = TeamSpeak3_Helper_String::factory(trim($parts[4])); $array["msg_plain"] = $entry; $array["malformed"] = FALSE; } return $array; }
static TeamSpeak3_Helper_Convert::password | ( | $ | plain | ) | [static] |
Converts a given string to a ServerQuery password hash.
string | $plain |
Definition at line 281 of file Convert.php.
{
return base64_encode(sha1($plain, TRUE));
}
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.
string | $version | |
string | $format |
Definition at line 293 of file Convert.php.
Referenced by TeamSpeak3_Viewer_Html\getCorpusTitle(), and TeamSpeak3_Node_Abstract\getInfo().
:i:s") { if(!$version instanceof TeamSpeak3_Helper_String) { $version = new TeamSpeak3_Helper_String($version); } $buildno = $version->section("[", 1)->filterDigits()->toInt(); return ($buildno <= 15001) ? $version : $version->section("[")->append("(" . date($format, $buildno) . ")"); }
static TeamSpeak3_Helper_Convert::imageMimeType | ( | $ | binary | ) | [static] |
Tries to detect the type of an image by a given string and returns it.
string | $binary |
Definition at line 311 of file Convert.php.
Referenced by TeamSpeak3_Viewer_Html\getSuffixIconChannel(), TeamSpeak3_Viewer_Html\getSuffixIconClient(), and TeamSpeak3_Viewer_Html\getSuffixIconServer().
{ 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)) { return "application/octet-stream"; } $type = array( 1 => "image/jpeg", 2 => "image/gif", 3 => "image/png", 4 => "image/x-windows-bmp", 5 => "image/tiff", 6 => "image/x-ilbm", ); return $type[count($matches)-1]; }