Skip to content

Instantly share code, notes, and snippets.

@derrobin154
Created March 30, 2018 20:21
Show Gist options
  • Save derrobin154/fbc4986c3f4b5c61a2169e3616ce784e to your computer and use it in GitHub Desktop.
Save derrobin154/fbc4986c3f4b5c61a2169e3616ce784e to your computer and use it in GitHub Desktop.
# Auto detect text files and perform LF normalization
* text=auto
# Custom for Visual Studio
*.cs diff=csharp
# Standard to msysgit
*.doc diff=astextplain
*.DOC diff=astextplain
*.docx diff=astextplain
*.DOCX diff=astextplain
*.dot diff=astextplain
*.DOT diff=astextplain
*.pdf diff=astextplain
*.PDF diff=astextplain
*.rtf diff=astextplain
*.RTF diff=astextplain
config/config.php
prototypes/
admin/
.idea/
cache/
!/cache/.htaccess
# Heroku specific entries
vendor/
.env
# Created by https://www.gitignore.io/api/osx,linux,windows,phpstorm,sublimetext
### Linux ###
*~
# temporary files which can be created if a process still has a handle open of a deleted file
.fuse_hidden*
# KDE directory preferences
.directory
# Linux trash folder which might appear on any partition or disk
.Trash-*
# .nfs files are created when an open file is removed but is still being accessed
.nfs*
### OSX ###
*.DS_Store
.AppleDouble
.LSOverride
# Icon must end with two \r
Icon
# Thumbnails
._*
# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent
# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk
### PhpStorm ###
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
# User-specific stuff:
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/dictionaries
# Sensitive or high-churn files:
.idea/**/dataSources/
.idea/**/dataSources.ids
.idea/**/dataSources.xml
.idea/**/dataSources.local.xml
.idea/**/sqlDataSources.xml
.idea/**/dynamic.xml
.idea/**/uiDesigner.xml
# Gradle:
.idea/**/gradle.xml
.idea/**/libraries
# CMake
cmake-build-debug/
# Mongo Explorer plugin:
.idea/**/mongoSettings.xml
## File-based project format:
*.iws
## Plugin-specific files:
# IntelliJ
/out/
# mpeltonen/sbt-idea plugin
.idea_modules/
# JIRA plugin
atlassian-ide-plugin.xml
# Cursive Clojure plugin
.idea/replstate.xml
# Ruby plugin and RubyMine
/.rakeTasks
# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties
### PhpStorm Patch ###
# Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721
# *.iml
# modules.xml
# .idea/misc.xml
# *.ipr
# Sonarlint plugin
.idea/sonarlint
### SublimeText ###
# cache files for sublime text
*.tmlanguage.cache
*.tmPreferences.cache
*.stTheme.cache
# workspace files are user-specific
*.sublime-workspace
# project files should be checked into the repository, unless a significant
# proportion of contributors will probably not be using SublimeText
# *.sublime-project
# sftp configuration file
sftp-config.json
# Package control specific files
Package Control.last-run
Package Control.ca-list
Package Control.ca-bundle
Package Control.system-ca-bundle
Package Control.cache/
Package Control.ca-certs/
Package Control.merged-ca-bundle
Package Control.user-ca-bundle
oscrypto-ca-bundle.crt
bh_unicode_properties.cache
# Sublime-github package stores a github token in this file
# https://packagecontrol.io/packages/sublime-github
GitHub.sublime-settings
### Windows ###
# Windows thumbnail cache files
Thumbs.db
ehthumbs.db
ehthumbs_vista.db
# Folder config file
Desktop.ini
# Recycle Bin used on file shares
$RECYCLE.BIN/
# Windows Installer files
*.cab
*.msi
*.msm
*.msp
# Windows shortcuts
*.lnk
# End of https://www.gitignore.io/api/osx,linux,windows,phpstorm,sublimetext
# (c) 2015 - 2018 Wruczek <wruczekk@gmail.com> and contributors
AddDefaultCharset UTF-8
# DISABLE DIRECTORY LISTING
Options -Indexes
SetEnv HTACCESS on
ErrorDocument 403 "<!DOCTYPE html><html lang=\"en\"><head> <meta charset=\"utf-8\"> <meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\"> <meta name=\"viewport\" content=\"width=device-width, initial-scale=1\"> <meta name=\"author\" content=\"Wruczek\"> <title>403 - Forbidden</title> <link rel=\"shortcut icon\" href=\"img/icon/icon-64.png\" style=\"-webkit-box-sizing: border-box;-moz-box-sizing: border-box;box-sizing: border-box;\"></head><body style=\"-webkit-box-sizing: border-box;-moz-box-sizing: border-box;box-sizing: border-box;margin: 0;font-family: &quot;Lato&quot;,&quot;Helvetica Neue&quot;,Helvetica,Arial,sans-serif;font-size: 15px;line-height: 1.42857143;color: #ebebeb;background-color: #2b3e50;\"> <div class=\"container\" style=\"-webkit-box-sizing: border-box;-moz-box-sizing: border-box;box-sizing: border-box;margin-right: auto;margin-left: auto;padding-left: 15px;padding-right: 15px;display: table;position: absolute;height: 100%;width: 100%;\"> <div class=\"text-center\" style=\"-webkit-box-sizing: border-box;-moz-box-sizing: border-box;box-sizing: border-box;text-align: center;display: table-cell;vertical-align: middle;\"> <h1 style=\"-webkit-box-sizing: border-box;-moz-box-sizing: border-box;box-sizing: border-box;font-size: 39px;margin: 0.67em 0;font-family: inherit;font-weight: 400;line-height: 1.1;color: inherit;margin-top: 21px;margin-bottom: 10.5px;\">403 <span style=\"font-size: 32px;color: #9E9E9E;-webkit-box-sizing: border-box;-moz-box-sizing: border-box;box-sizing: border-box;\">Forbidden</span></h1> <h3 style=\"-webkit-box-sizing: border-box;-moz-box-sizing: border-box;box-sizing: border-box;orphans: 3;widows: 3;page-break-after: avoid;font-family: inherit;font-weight: 400;line-height: 1.1;color: inherit;margin-top: 21px;margin-bottom: 10.5px;font-size: 26px;\">Access to this page is forbidden.</h3> <br style=\"-webkit-box-sizing: border-box;-moz-box-sizing: border-box;box-sizing: border-box;\"> <a href=\".\" class=\"btn btn-primary btn-lg\" style=\"-webkit-box-sizing: border-box;-moz-box-sizing: border-box;box-sizing: border-box;background-color: #df691a;color: #ffffff;text-decoration: none;display: inline-block;margin-bottom: 0;font-weight: normal;text-align: center;vertical-align: middle;-ms-touch-action: manipulation;touch-action: manipulation;cursor: pointer;background-image: none;border: 1px solid transparent;white-space: nowrap;padding: 12px 24px;font-size: 19px;line-height: 1.3333333;border-radius: 0;-webkit-user-select: none;-moz-user-select: none;-ms-user-select: none;user-select: none;border-color: transparent;\">&larr;&nbsp;&nbsp;&nbsp;Go back</a> </div></div></body></html>"
ErrorDocument 404 "<!DOCTYPE html><html lang=\"en\"><head> <meta charset=\"utf-8\"> <meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\"> <meta name=\"viewport\" content=\"width=device-width, initial-scale=1\"> <meta name=\"author\" content=\"Wruczek\"> <title>404 - Not found</title> <link rel=\"shortcut icon\" href=\"img/icon/icon-64.png\"></head><body style=\"-webkit-box-sizing: border-box;-moz-box-sizing: border-box;box-sizing: border-box;margin: 0;font-family: &quot;Lato&quot;,&quot;Helvetica Neue&quot;,Helvetica,Arial,sans-serif;font-size: 15px;line-height: 1.42857143;color: #ebebeb;background-color: #2b3e50;\"> <div class=\"container\" style=\"-webkit-box-sizing: border-box;-moz-box-sizing: border-box;box-sizing: border-box;margin-right: auto;margin-left: auto;padding-left: 15px;padding-right: 15px;display: table;position: absolute;height: 100%;width: 100%;\"> <div class=\"text-center\" style=\"-webkit-box-sizing: border-box;-moz-box-sizing: border-box;box-sizing: border-box;text-align: center;display: table-cell;vertical-align: middle;\"> <h1 style=\"-webkit-box-sizing: border-box;-moz-box-sizing: border-box;box-sizing: border-box;font-size: 39px;margin: 0.67em 0;font-family: inherit;font-weight: 400;line-height: 1.1;color: inherit;margin-top: 21px;margin-bottom: 10.5px;\">404 <span style=\"font-size: 32px;color: #9E9E9E;-webkit-box-sizing: border-box;-moz-box-sizing: border-box;box-sizing: border-box;\">page not found</span></h1> <h3 style=\"-webkit-box-sizing: border-box;-moz-box-sizing: border-box;box-sizing: border-box;orphans: 3;widows: 3;page-break-after: avoid;font-family: inherit;font-weight: 400;line-height: 1.1;color: inherit;margin-top: 21px;margin-bottom: 10.5px;font-size: 26px;\">We couldn't find what you were looking for.</h3> <br style=\"-webkit-box-sizing: border-box;-moz-box-sizing: border-box;box-sizing: border-box;\"> <a href=\".\" class=\"btn btn-primary btn-lg\" style=\"-webkit-box-sizing: border-box;-moz-box-sizing: border-box;box-sizing: border-box;background-color: #df691a;color: #ffffff;text-decoration: none;display: inline-block;margin-bottom: 0;font-weight: normal;text-align: center;vertical-align: middle;-ms-touch-action: manipulation;touch-action: manipulation;cursor: pointer;background-image: none;border: 1px solid transparent;white-space: nowrap;padding: 12px 24px;font-size: 19px;line-height: 1.3333333;border-radius: 0;-webkit-user-select: none;-moz-user-select: none;-ms-user-select: none;user-select: none;border-color: transparent;\">&larr;&nbsp;&nbsp;&nbsp;Go back</a> </div></div></body></html>"
ErrorDocument 500 "<!DOCTYPE html><html lang=\"en\"><head> <meta charset=\"utf-8\"> <meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\"> <meta name=\"viewport\" content=\"width=device-width, initial-scale=1\"> <meta name=\"author\" content=\"Wruczek\"> <title>500 - server error</title> <link rel=\"shortcut icon\" href=\"img/icon/icon-64.png\"></head><body style=\"-webkit-box-sizing: border-box;-moz-box-sizing: border-box;box-sizing: border-box;margin: 0;font-family: &quot;Lato&quot;,&quot;Helvetica Neue&quot;,Helvetica,Arial,sans-serif;font-size: 15px;line-height: 1.42857143;color: #ebebeb;background-color: #2b3e50;\"> <div class=\"container\" style=\"-webkit-box-sizing: border-box;-moz-box-sizing: border-box;box-sizing: border-box;margin-right: auto;margin-left: auto;padding-left: 15px;padding-right: 15px;display: table;position: absolute;height: 100%;width: 100%;\"> <div class=\"text-center\" style=\"-webkit-box-sizing: border-box;-moz-box-sizing: border-box;box-sizing: border-box;text-align: center;display: table-cell;vertical-align: middle;\"> <h1 style=\"-webkit-box-sizing: border-box;-moz-box-sizing: border-box;box-sizing: border-box;font-size: 39px;margin: 0.67em 0;font-family: inherit;font-weight: 400;line-height: 1.1;color: inherit;margin-top: 21px;margin-bottom: 10.5px;\">500 <span style=\"font-size: 32px;color: #9E9E9E;-webkit-box-sizing: border-box;-moz-box-sizing: border-box;box-sizing: border-box;\">server error</span></h1> <h3 style=\"-webkit-box-sizing: border-box;-moz-box-sizing: border-box;box-sizing: border-box;orphans: 3;widows: 3;page-break-after: avoid;font-family: inherit;font-weight: 400;line-height: 1.1;color: inherit;margin-top: 21px;margin-bottom: 10.5px;font-size: 26px;\">Something went wrong. Try again later.</h3> <br style=\"-webkit-box-sizing: border-box;-moz-box-sizing: border-box;box-sizing: border-box;\"> <a href=\".\" class=\"btn btn-primary btn-lg\" style=\"-webkit-box-sizing: border-box;-moz-box-sizing: border-box;box-sizing: border-box;background-color: #df691a;color: #ffffff;text-decoration: none;display: inline-block;margin-bottom: 0;font-weight: normal;text-align: center;vertical-align: middle;-ms-touch-action: manipulation;touch-action: manipulation;cursor: pointer;background-image: none;border: 1px solid transparent;white-space: nowrap;padding: 12px 24px;font-size: 19px;line-height: 1.3333333;border-radius: 0;-webkit-user-select: none;-moz-user-select: none;-ms-user-select: none;user-select: none;border-color: transparent;\">&larr;&nbsp;&nbsp;&nbsp;Go back</a> </div></div></body></html>"
<IfModule mod_rewrite.c>
#RewriteEngine On
# PAGES WITHOUT .PHP AT THE END
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
# PAGES WITHOUT .HTML AT THE END
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ $1.html
</IfModule>
# Enable GZIP
<ifmodule mod_deflate.c>
AddOutputFilterByType DEFLATE text/text text/html text/plain text/xml text/css application/x-javascript application/javascript
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
</ifmodule>
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/ts-website.iml" filepath="$PROJECT_DIR$/.idea/ts-website.iml" />
</modules>
</component>
</project>
<?xml version="1.0" encoding="UTF-8"?>
<module type="WEB_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
<?php
header('Content-Type:application/javascript');
require_once __DIR__ . "/../include/language.php";
?>
var textShowMore = "<?php json_encode(tl($lang["index"]["showmore"])); ?>", textShowLess = "<?php json_encode(tl($lang["index"]["showless"])); ?>", statusOnline = "<?php json_encode(tl($lang["serverstatus"]["online"])); ?>", statusOffline = "<?php json_encode(tl($lang["serverstatus"]["offline"])); ?>", statusUptime = "<?php json_encode(tl($lang["serverstatus"]["uptime"])); ?>", statusVersion = "<?php json_encode(tl($lang["serverstatus"]["version"])); ?>", statusAvgping = "<?php json_encode(tl($lang["serverstatus"]["avgping"])); ?>", statusAvgpl = "<?php json_encode(tl($lang["serverstatus"]["avgpl"])); ?>";
<?php
// error_reporting(0);
header('Content-Type: application/json');
set_error_handler("exception_error_handler", E_ALL);
require_once __DIR__ . "/../include/tsutils.php";
require_once __DIR__ . "/../include/cacheutils.class.php";
date_default_timezone_set($config["general"]["timezone"]);
$cacheutils = new CacheUtils('serverstatus');
if($cacheutils->isExpired()) {
$cacheutils->setValue(getResult(), 60);
}
die ($cacheutils->getValue());
// *********
// METHODS
// *********
function getResult() {
try {
$start = microtime(true);
$tsstatus = getTeamspeakServerStatus();
$stop = microtime(true);
return json_encode(array(
"tsstatus" => $tsstatus,
"generated" => date('d-m-Y H:i:s')
));
} catch (Exception $e) {
scriptFail($e);
}
}
function scriptFail($error) {
die(json_encode(array(
"success" => false,
"id" => "script_error",
"message" => "There has been an error while retrieving the server status",
"error" => $error
)));
}
function exception_error_handler($errno, $errstr, $errfile, $errline) {
scriptFail("[$errfile @ $errline] " . $errstr);
}
function getTeamspeakServerStatus() {
$response = pingTeamspeakServerFromConfig();
if ($response) {
return array(
"success" => $response["virtualserver_status"]->toString() == "online",
"name" => $response["virtualserver_name"]->toString(),
"clientsonline" => $response["virtualserver_clientsonline"] - $response["virtualserver_queryclientsonline"],
"maxclients" => $response["virtualserver_maxclients"],
"version" => TeamSpeak3_Helper_Convert::versionShort($response["virtualserver_version"]->toString())->toString(),
"platform" => $response["virtualserver_platform"]->toString(),
"uptime" => TeamSpeak3_Helper_Convert::seconds($response["virtualserver_uptime"], false, "%dd %02dh %02dm"),
"averagePacketloss" => $response["virtualserver_total_packetloss_total"]->toString(),
"averagePing" => $response["virtualserver_total_ping"]->toString()
);
} else {
return array(
"success" => false,
"id" => "not_responding",
"message" => "Server is not responding"
);
}
}
<?php
$bansPage = true;
require_once __DIR__ . "/include/header.php";
require_once __DIR__ . "/include/tsutils.php";
require_once __DIR__ . "/include/cacheutils.class.php";
$cacheutils = new CacheUtils('banlist');
if($cacheutils->isExpired()) {
$cacheutils->setValue([getBanlist(), date('d.m.Y H:i:s')], 300);
}
$banlist = $cacheutils->getValue();
?>
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title"><i class="fa fa-ban" aria-hidden="true"></i> <?php tl($lang["banlist"]["title"]); ?></h3>
</div>
<div class="panel-body">
<?php if(empty($banlist[0])) { ?>
<div class="alert alert-success">
<p class="text-center"><?php tl($lang["banlist"]["emptylist"]); ?></p>
</div>
<?php } else { ?>
<div class="table-responsive">
<table id="banlist" class="table table-striped table-bordered" cellspacing="0" width="100%">
<thead>
<tr>
<th><?php tl($lang["banlist"]["table"]["nickname"]); ?></th>
<th><?php tl($lang["banlist"]["table"]["reason"]); ?></th>
<th><?php tl($lang["banlist"]["table"]["bannedby"]); ?></th>
<th><?php tl($lang["banlist"]["table"]["bandate"]); ?></th>
<th><?php tl($lang["banlist"]["table"]["expires"]); ?></th>
</tr>
</thead>
<tbody>
<?php echo $banlist[0]; ?>
</tbody>
</table>
</div>
<?php } ?>
</div>
<div class="panel-footer">
<?php tl($lang["banlist"]["lastupdate"], [$banlist[1]]); ?><!-- <span style="float: right">Data is refreshed every X seconds</span> -->
</div>
</div>
<?php
function getBanlist() {
global $lang;
try {
$tsAdmin = getTeamspeakConnection("#no_query_clients");
$bans = $tsAdmin->banList();
$output = "";
foreach ($bans as $ban) {
$user = null;
if (!empty($ban['ip']))
$user = censorIP((string)$ban['ip']);
if (!empty($ban['lastnickname']))
$user = htmlspecialchars((string)$ban['lastnickname']);
if (empty($user))
$user = "<i>Unknown</i>";
$reason = htmlspecialchars((string)$ban['reason']);
$invokername = htmlspecialchars((string)$ban['invokername']);
$duration = $ban['duration'];
$createdepoch = $ban['created'];
$expiresepoch = $ban['created'] + $duration;
$created = date('d-m-Y H:i:s', $createdepoch);
if (empty($reason))
$reason = "<b>" . translate($lang["banlist"]["table"]["emptyreason"]) . "</b>";
if ($duration == 0)
$expires = translate($lang["banlist"]["table"]["permaban"]);
else
$expires = date('d.m.Y H:i:s', $expiresepoch);
$output .= "<tr><td>$user</td><td>$reason</td><td>$invokername</td><td data-order=\"$createdepoch\">$created</td><td data-order=\"$expiresepoch\">$expires</td></tr>";
}
return $output;
} catch (TeamSpeak3_Exception $e) {
if ($e->getCode() == 1281) {
return '';
} else {
return '<div class="alert alert-danger"><p class="text-center">' . translate($lang["general"]["scripterror"], [$e->getCode(), $e->getMessage()]) . '</p></div>';
}
}
}
function censorIP($ip) {
return preg_replace("/(\d+\.\d+\.)\d+\.\d+/", "$1***.***", $ip);
}
require_once __DIR__ . "/include/footer.php";
?>
order deny,allow
deny from all
allow from 127.0.0.1
order deny, allow
deny from all
allow from 127.0.0.1
a:3:{s:1:"d";a:2:{i:0;s:323:"<p class="groupname"><img src="lib/ts3phpframework/images/viewer/group_icon_300.png" alt="Group icon" /> TS Admin</p><p><img src="lib/ts3phpframework/images/viewer/client_away.png" alt="User status"><span class="label label-primary">Robin | derrobin154</span><span class="label label-warning pull-right">Abwesend</span></p>";i:1;s:19:"30.03.2018 22:20:03";}s:1:"t";O:8:"DateTime":3:{s:4:"date";s:26:"2018-03-30 22:22:03.000000";s:13:"timezone_type";i:3;s:8:"timezone";s:13:"Europe/Warsaw";}s:1:"g";a:0:{}}
a:3:{s:1:"d";s:240:"{"tsstatus":{"success":true,"name":"Robin's Teamspeak","clientsonline":1,"maxclients":32,"version":"3.0.13.8","platform":"Linux","uptime":"56d 00h 17m","averagePacketloss":"0.0020","averagePing":"34.0000"},"generated":"30-03-2018 22:20:05"}";s:1:"t";O:8:"DateTime":3:{s:4:"date";s:26:"2018-03-30 22:21:05.000000";s:13:"timezone_type";i:3;s:8:"timezone";s:13:"Europe/Warsaw";}s:1:"g";a:0:{}}
{
"require" : {
"php" : "^5.5",
"ext-mbstring": "*"
}
}
<?php
/*
Author: Wruczek
Donate: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=9PL5J7ULZQYJQ
I am happy to take any programming-related requests, add additional features or modify the code to suit your needs for a small donation :)
I am experienced at Java, PHP, HTML, CSS, Javascript, SQL, server configurations ect.
For business enquiries only: wruczekk at gmail.com, for anything else please join Telegram chat.
Need help? Join our telegram group for news, announcements, help and general chat about ts-website: https://t.me/tswebsite
*/
/************* General configuration *************/
$config["general"]["title"] = "BestTS.NET"; // Website title - displayed in the menu
$config["general"]["icon"] = "img/icon/icon-32.png"; // Website icon
$config["general"]["subtitle"] = " - Best TeamSpeak server!"; // Website subtitle
$config["general"]["desc"] = "Polski serwer TeamSpeak! Zapraszamy :)"; // Website description - displayed in Google search engine
$config["general"]["newsDir"] = "config/news"; // News folder (relative to project folder)
$config["general"]["timezone"] = "Europe/Warsaw"; // Your timezone - http://php.net/manual/en/timezones.php
$config["general"]["christmasmode"] = true; // Set to false to permanently disable christmas mode activated in December
$config["general"]["enablehta"] = false; // Enable / Disable additional website features (recommended, but
// you need to have up-to-date version of Apache and install mod_rewrite)
// After setting to true, go into .htaccess file and uncomment 19 line
/********* TeamSpeak configuration *********/
$config['teamspeak']['host'] = 'h1.robin154.de'; // TeamSpeak host address
$config['teamspeak']['login'] = 'serveradmin'; // Login
$config['teamspeak']['password'] = 'EvMcO1Ro'; // Password
$config['teamspeak']['server_port'] = 9987; // TeamSpeak server port
$config['teamspeak']['query_port'] = 10011; // Query port
$config['teamspeak']['displayip'] = 'ts.server.net'; // IP shown to users and used for connections
/************* Additional navigation links - you can link to your stuff *************/
// TEMPLATE: (ICON is an icon name from: http://fontawesome.io/icons/)
// $config["navlinks"][] = ["icon", "displayed text", "link"];
$config["navlinks"][] = ["fa-facebook-official", "Facebook", "https://facebook.com/Facebook"];
$config["navlinks"][] = ["fa-twitter-square", "Twitter", "https://twitter.com/Twitter"];
$config["navlinks"][] = ["fa-comments", "Forum", "forum"];
/************* Adminlist configuration *************/
// ID of servergroups displayed as admins in Adminlist. Put it in the same way you want it to be displayed.
$config["adminlist"] = [32];
/************* Contact panel configuration *************/
$config['contact']['title'] = 'Contact the staff';
/*
TIP: You can remove all items below to hide contact panel
CONTACT PANEL SYNTAX:
$config['contact']['items'][] = ["name", "link description", "link"];
FOR EXAMPLE:
$config['contact']['items'][] = ["Telegram", "@Wruczek", "https://t.me/Wruczek"];
*/
$config['contact']['items'][] = ["TeamSpeak", "Support channel", "ts3server://teamspeakip?cid=30"];
$config['contact']['items'][] = ["Email", "contact@email.com", "mailto:contact@email.com"];
$config['contact']['items'][] = ["Telegram", "@Telegram", "https://t.me/Telegram"];
$config['contact']['items'][] = ["Twitter", "@Twitter", "https://twitter.com/Twitter"];
<?php
/*
Author: Wruczek
Donate: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=9PL5J7ULZQYJQ
I am happy to take any programming-related requests, add additional features or modify the code to suit your needs for a small donation :)
I am experienced at Java, PHP, HTML, CSS, Javascript, SQL, server configurations ect.
For business enquiries only: wruczekk at gmail.com, for anything else please join Telegram chat.
Need help? Join our telegram group for news, announcements, help and general chat about ts-website: https://t.me/tswebsite
*/
/************* General configuration *************/
$config["general"]["title"] = "BestTS.NET"; // Website title - displayed in the menu
$config["general"]["icon"] = "img/icon/icon-32.png"; // Website icon
$config["general"]["subtitle"] = " - Best TeamSpeak server!"; // Website subtitle
$config["general"]["desc"] = "Polski serwer TeamSpeak! Zapraszamy :)"; // Website description - displayed in Google search engine
$config["general"]["newsDir"] = "config/news"; // News folder (relative to project folder)
$config["general"]["timezone"] = "Europe/Warsaw"; // Your timezone - http://php.net/manual/en/timezones.php
$config["general"]["christmasmode"] = true; // Set to false to permanently disable christmas mode activated in December
$config["general"]["enablehta"] = false; // Enable / Disable additional website features (recommended, but
// you need to have up-to-date version of Apache and install mod_rewrite)
// After setting to true, go into .htaccess file and uncomment 19 line
/********* TeamSpeak configuration *********/
$config['teamspeak']['host'] = '127.0.0.1'; // TeamSpeak host address
$config['teamspeak']['login'] = 'serveradmin'; // Login
$config['teamspeak']['password'] = 'pa$$word'; // Password
$config['teamspeak']['server_port'] = 9987; // TeamSpeak server port
$config['teamspeak']['query_port'] = 10011; // Query port
$config['teamspeak']['displayip'] = 'ts.server.net'; // IP shown to users and used for connections
/************* Additional navigation links - you can link to your stuff *************/
// TEMPLATE: (ICON is an icon name from: http://fontawesome.io/icons/)
// $config["navlinks"][] = ["icon", "displayed text", "link"];
$config["navlinks"][] = ["fa-facebook-official", "Facebook", "https://facebook.com/Facebook"];
$config["navlinks"][] = ["fa-twitter-square", "Twitter", "https://twitter.com/Twitter"];
$config["navlinks"][] = ["fa-comments", "Forum", "forum"];
/************* Adminlist configuration *************/
// ID of servergroups displayed as admins in Adminlist. Put it in the same way you want it to be displayed.
$config["adminlist"] = [6, 17, 19];
/************* Contact panel configuration *************/
$config['contact']['title'] = 'Contact the staff';
/*
TIP: You can remove all items below to hide contact panel
CONTACT PANEL SYNTAX:
$config['contact']['items'][] = ["name", "link description", "link"];
FOR EXAMPLE:
$config['contact']['items'][] = ["Telegram", "@Wruczek", "https://t.me/Wruczek"];
*/
$config['contact']['items'][] = ["TeamSpeak", "Support channel", "ts3server://teamspeakip?cid=30"];
$config['contact']['items'][] = ["Email", "contact@email.com", "mailto:contact@email.com"];
$config['contact']['items'][] = ["Telegram", "@Telegram", "https://t.me/Telegram"];
$config['contact']['items'][] = ["Twitter", "@Twitter", "https://twitter.com/Twitter"];
<?php
/*
* Bulgarian language for ts-website
* @copy toster234 <contact@ts-24.pro>
*/
$lang = array();
/************* General *************/
$lang["general"]["langcode"] = "bg_BG";
$lang["general"]["scripterror"] = "Възникна грешка! {0}: {1}";
/************* Navbar *************/
$lang["navbar"]["navigation"] = "навигация";
$lang["navbar"]["viewer"] = "Преглед на сървъра";
$lang["navbar"]["bans"] = "банове";
$lang["navbar"]["rules"] = "правилник";
$lang["navbar"]["connect"] = "Се свърже със сървъра";
$lang["navbar"]["connecttooltip"] = "Кликнете, за да се свържете със сървъра {0}";
/************* Footer *************/
$lang["footer"]["website"] = "страница";
$lang["footer"]["css"] = "CSS учтивост";
$lang["footer"]["background"] = "фон";
/************* Server status *************/
$lang["serverstatus"]["title"] = "сървъра Status";
$lang["serverstatus"]["address"] = "адрес";
$lang["serverstatus"]["loading"] = "товарене...";
$lang["serverstatus"]["online"] = "онлайн";
$lang["serverstatus"]["offline"] = "на линия";
$lang["serverstatus"]["uptime"] = "Uptime";
$lang["serverstatus"]["version"] = "версия";
$lang["serverstatus"]["avgping"] = "Средната пинг";
$lang["serverstatus"]["avgpl"] = "Средната загуба на пакет";
/************* Admin list *************/
$lang["adminlist"]["title"] = "Статус администрация";
$lang["adminlist"]["emptygroup"] = "Тази група е празна";
$lang["adminlist"]["status"]["online"] = "онлайн";
$lang["adminlist"]["status"]["away"] = "далеч";
$lang["adminlist"]["status"]["offline"] = "на линия";
$lang["adminlist"]["lastupdate"] = "към {0}";
/************* Server viewer promo box (under adminlist and contact) *************/
$lang["svpb"]["title"] = "Преглед на сървъра";
$lang["svpb"]["takealook"] = "изглед &raquo;";
/************************************/
/************* SUBPAGES *************/
/************************************/
/************* News - index.php *************/
$lang["index"]["title"] = "Публикации";
$lang["index"]["showmore"] = "Покажи още";
$lang["index"]["showless"] = "Покажи по-малко";
$lang["index"]["errortitle"] = "Грешка: папката на новини не е намерен.";
$lang["index"]["errorsubtitle"] = "Уверете се, местоположението, зададено във файла <code>config/config.php</code> Това е правилно.";
/************* Server viewer - viewer.php *************/
$lang["viewer"]["title"] = "Преглед на сървъра";
$lang["viewer"]["lastupdate"] = "към {0}";
/************* Ban List - bans.php *************/
$lang["banlist"]["title"] = "банове";
$lang["banlist"]["datatablesurl"] = "//cdn.datatables.net/plug-ins/1.10.12/i18n/Bulgarian.json";
$lang["banlist"]["emptylist"] = "NO забранени потребители";
$lang["banlist"]["lastupdate"] = "към {0}";
$lang["banlist"]["table"]["emptyreason"] = "(Няма причина)";
$lang["banlist"]["table"]["permaban"] = "някога";
$lang["banlist"]["table"]["nickname"] = "Nick";
$lang["banlist"]["table"]["reason"] = "причина";
$lang["banlist"]["table"]["bannedby"] = "забранена от";
$lang["banlist"]["table"]["bandate"] = "Дата на забрана";
$lang["banlist"]["table"]["expires"] = "изтича";
/************* Rules - rules.php *************/
$lang["rules"]["title"] = "правила за сървъри";
$lang["rules"]["filenotfound"] = "Грешка: файл <code>config/rules.md</code> Той не е намерен!";
$lang["rules"]["readerror"] = "Грешка: не може да чете файл <code>config/rules.md</code>!";
<?php
/*
* Tradução para PT-BR para tsweb.
* @copy Michel Lago <michel_physalis@hotmail.com>
*/
$lang = array();
/************* General *************/
$lang["general"]["langcode"] = "br_GB";
$lang["general"]["scripterror"] = "Erro Ocorrido! {0}: {1}";
/************* Menu *************/
$lang["navbar"]["navigation"] = "Navegação";
$lang["navbar"]["viewer"] = "Ver Servidor";
$lang["navbar"]["bans"] = "Lista de Ban";
$lang["navbar"]["rules"] = "Regras do Servidor";
$lang["navbar"]["menu"] = "Menu";
$lang["navbar"]["connect"] = "Conectar ao Servidor";
$lang["navbar"]["connecttooltip"] = "Click para se conectar {0}";
/************* Rodapé *************/
$lang["footer"]["css"] = "CSS por";
$lang["footer"]["background"] = "background";
/************* Status do Servidor *************/
$lang["serverstatus"]["title"] = "Status do Servidor";
$lang["serverstatus"]["address"] = "Endereço";
$lang["serverstatus"]["loading"] = "Carregando...";
$lang["serverstatus"]["online"] = "Online";
$lang["serverstatus"]["offline"] = "Offline";
$lang["serverstatus"]["uptime"] = "Uptime";
$lang["serverstatus"]["version"] = "Versão";
$lang["serverstatus"]["avgping"] = "Ping";
$lang["serverstatus"]["avgpl"] = "Perda de pacotes";
/************* Lista de Admins *************/
$lang["adminlist"]["title"] = "Lista de Admin's";
$lang["adminlist"]["emptygroup"] = "Este grupo esta vazio";
$lang["adminlist"]["status"]["online"] = "Online";
$lang["adminlist"]["status"]["away"] = "Away";
$lang["adminlist"]["status"]["offline"] = "Offline";
$lang["adminlist"]["lastupdate"] = "Ultima atualização: {0}";
/************* Server viewer ( embaixo da lista de adm e ebaixo da aba contato) *************/
$lang["svpb"]["title"] = "Servidor Online";
$lang["svpb"]["takealook"] = "Dê uma olhada &raquo;";
/************************************/
/************* SUB-PAGINAS **********/
/************************************/
/************* Noticias - index.php *************/
$lang["index"]["title"] = "Noticias";
$lang["index"]["showmore"] = "Ler Mais";
$lang["index"]["showless"] = "Mostrar Menos";
$lang["index"]["errortitle"] = "Error: Diretório de Noticias não encontrado!";
$lang["index"]["errorsubtitle"] = "Porfavor tenha a certeza que o arquivo no diretório <b><code>config/config.php</code></b> está valido.";
/************* Server viewer - viewer.php *************/
$lang["viewer"]["title"] = "Servidor Online";
$lang["viewer"]["lastupdate"] = "Ultima Atualização: {0}";
/************* Lista de Bans - bans.php *************/
$lang["banlist"]["title"] = "Lista de Ban";
$lang["banlist"]["datatablesurl"] = "//cdn.datatables.net/plug-ins/1.10.12/i18n/Portuguese.json";
$lang["banlist"]["emptylist"] = "Lista de Ban está vazia";
$lang["banlist"]["lastupdate"] = "Ultima Atualização: {0}";
$lang["banlist"]["table"]["emptyreason"] = "(sem reação)";
$lang["banlist"]["table"]["permaban"] = "Nunca";
$lang["banlist"]["table"]["nickname"] = "Nick";
$lang["banlist"]["table"]["reason"] = "Reação";
$lang["banlist"]["table"]["bannedby"] = "Banido por";
$lang["banlist"]["table"]["bandate"] = "Data do Ban";
$lang["banlist"]["table"]["expires"] = "Expira";
/************* Regras do Servidor - rules.php *************/
$lang["rules"]["title"] = "Regras do servidor";
$lang["rules"]["filenotfound"] = "Error: Arquivo <code>config/rules.md</code> não foi encontrado!";
$lang["rules"]["readerror"] = "Error: Não foi possível acessar o arquivo <code>config/rules.md</code>!";
<?php
/*
* Belarussian language for ts-website
* @copy kidi <@goodgame.by>
*/
$lang = array();
/************* General *************/
$lang["general"]["langcode"] = "be_BY";
$lang["general"]["scripterror"] = "Адбылася памылка! {0}: {1}";
/************* Navbar *************/
$lang["navbar"]["navigation"] = "Навігацыя";
$lang["navbar"]["viewer"] = "Агляд сервера";
$lang["navbar"]["bans"] = "Спіс забаненых";
$lang["navbar"]["rules"] = "Правілы сервера";
$lang["navbar"]["connect"] = "Падклучыцца";
$lang["navbar"]["connecttooltip"] = "Націсніце, што б падключыцца да {0}";
/************* Footer *************/
$lang["footer"]["website"] = "Вэб-сайт";
$lang["footer"]["css"] = "CSS дзякуючы ласкі";
$lang["footer"]["background"] = "фон";
/************* Server status *************/
$lang["serverstatus"]["title"] = "Статус сервера";
$lang["serverstatus"]["address"] = "Адрас";
$lang["serverstatus"]["loading"] = "Загрузка...";
$lang["serverstatus"]["online"] = "Працуе";
$lang["serverstatus"]["offline"] = "Не працуе";
$lang["serverstatus"]["uptime"] = "Аптайм";
$lang["serverstatus"]["version"] = "Версія";
$lang["serverstatus"]["avgping"] = "Сярэдні пінг";
$lang["serverstatus"]["avgpl"] = "Сяр. страта пакетаў";
/************* Admin list *************/
$lang["adminlist"]["title"] = "Статус адміністрацыі";
$lang["adminlist"]["emptygroup"] = "Эта группа пуста";
$lang["adminlist"]["status"]["online"] = "У анлайне";
$lang["adminlist"]["status"]["away"] = "Няма на месцы";
$lang["adminlist"]["status"]["offline"] = "У афлайне";
$lang["adminlist"]["lastupdate"] = "Апошнее абнаўленне: {0}";
/************* Server viewer promo box (under adminlist and contact) *************/
$lang["svpb"]["title"] = "Агляд сервера";
$lang["svpb"]["takealook"] = "Зірнуць на &raquo;";
/************************************/
/************* SUBPAGES *************/
/************************************/
/************* News - index.php *************/
$lang["index"]["title"] = "Навіны";
$lang["index"]["showmore"] = "Чытаць далей";
$lang["index"]["showless"] = "Паказаць менш";
$lang["index"]["errortitle"] = "Памылка: каталог навін не знойдзены!";
$lang["index"]["errorsubtitle"] = "Калі ласка, ўпэўніцеся, што месцазнаходжанне тэчкі у <b><code>config/config.php</code></b> ўстаноўлена карэктна.";
/************* Server viewer - viewer.php *************/
$lang["viewer"]["title"] = "Агляд сервера";
$lang["viewer"]["lastupdate"] = "Апошнее абнаўленне: {0}";
/************* Ban List - bans.php *************/
$lang["banlist"]["title"] = "Спіс забаненых";
$lang["banlist"]["datatablesurl"] = "//cdn.datatables.net/plug-ins/1.10.12/i18n/Belarusian.json";
$lang["banlist"]["emptylist"] = "Спіс забаненых пусты";
$lang["banlist"]["lastupdate"] = "Апошнее абнаўленне: {0}";
$lang["banlist"]["table"]["emptyreason"] = "(прычына адсутнічае)";
$lang["banlist"]["table"]["permaban"] = "Ніколі";
$lang["banlist"]["table"]["nickname"] = "Нік";
$lang["banlist"]["table"]["reason"] = "Прычына";
$lang["banlist"]["table"]["bannedby"] = "Забанены";
$lang["banlist"]["table"]["bandate"] = "Дата бана";
$lang["banlist"]["table"]["expires"] = "Заканчваецца";
/************* Rules - rules.php *************/
$lang["rules"]["title"] = "Правілы сервера";
$lang["rules"]["filenotfound"] = "Памылка: файл <code>config/rules.md</code> не знойдзены!";
$lang["rules"]["readerror"] = "Памылка: няма доступу да файла <code>config/rules.md</code>!";
<?php
/*
* Czech language for ts-website
* @copy Najsr <https://github.com/Najsr>
*/
$lang = array();
/************* General *************/
$lang["general"]["langcode"] = "cs_CZ";
$lang["general"]["scripterror"] = "Nastala chyba! {0}: {1}";
/************* Navbar *************/
$lang["navbar"]["navigation"] = "Navigace";
$lang["navbar"]["viewer"] = "Prohlížeč serveru";
$lang["navbar"]["bans"] = "Banlist";
$lang["navbar"]["rules"] = "Pravidla";
$lang["navbar"]["connect"] = "Připojit";
$lang["navbar"]["connecttooltip"] = "Klikněte pro připojení na {0}";
/************* Footer *************/
$lang["footer"]["css"] = "CSS od";
$lang["footer"]["background"] = "pozadí";
/************* Server status *************/
$lang["serverstatus"]["title"] = "Status";
$lang["serverstatus"]["address"] = "Adresa";
$lang["serverstatus"]["loading"] = "Načítání...";
$lang["serverstatus"]["online"] = "Online";
$lang["serverstatus"]["offline"] = "Offline";
$lang["serverstatus"]["uptime"] = "Doba zapnutí";
$lang["serverstatus"]["version"] = "Verze";
$lang["serverstatus"]["avgping"] = "Průměrný ping";
$lang["serverstatus"]["avgpl"] = "Průměrná ztrátovost paketů";
/************* Admin list *************/
$lang["adminlist"]["title"] = "Seznam adminů";
$lang["adminlist"]["emptygroup"] = "Tato skupina je prázdná";
$lang["adminlist"]["status"]["online"] = "Online";
$lang["adminlist"]["status"]["away"] = "Pryč";
$lang["adminlist"]["status"]["offline"] = "Offline";
$lang["adminlist"]["lastupdate"] = "Poslední aktualizace: {0}";
/************* Server viewer promo box (under adminlist and contact) *************/
$lang["svpb"]["title"] = "Prohlížeč serveru";
$lang["svpb"]["takealook"] = "Otevřít &raquo;";
/************************************/
/************* SUBPAGES *************/
/************************************/
/************* News - index.php *************/
$lang["index"]["title"] = "Novinky";
$lang["index"]["showmore"] = "Zobrazit více";
$lang["index"]["showless"] = "Zobrazit méně";
$lang["index"]["errortitle"] = "Error: stránka s novinkami nenalezena!";
$lang["index"]["errorsubtitle"] = "Ujistěte se, že cesta zadaná v <b><code>config/config.php</code></b> je správná.";
/************* Server viewer - viewer.php *************/
$lang["viewer"]["title"] = "Prohlížeč serveru";
$lang["viewer"]["lastupdate"] = "Poslední aktualizace: {0}";
/************* Ban List - bans.php *************/
$lang["banlist"]["title"] = "Banlist";
$lang["banlist"]["datatablesurl"] = "//cdn.datatables.net/plug-ins/1.10.12/i18n/Czech.json";
$lang["banlist"]["emptylist"] = "Banlist je prázdný";
$lang["banlist"]["lastupdate"] = "Poslední aktualizace: {0}";
$lang["banlist"]["table"]["emptyreason"] = "(bez důvodu)";
$lang["banlist"]["table"]["permaban"] = "Až naprší a uschne";
$lang["banlist"]["table"]["nickname"] = "Nick";
$lang["banlist"]["table"]["reason"] = "Důvod";
$lang["banlist"]["table"]["bannedby"] = "Zabanován od";
$lang["banlist"]["table"]["bandate"] = "Datum";
$lang["banlist"]["table"]["expires"] = "Vyprší";
/************* Rules - rules.php *************/
$lang["rules"]["title"] = "Pravidla serveru";
$lang["rules"]["filenotfound"] = "Error: soubor <code>config/rules.md</code> nebyl nalezen!";
$lang["rules"]["readerror"] = "Error: nemám přístup k <code>config/rules.md</code>!";
<?php
/*
* Danish language for ts-website
* @copy Cadmium
*/
$lang = array();
/************* General *************/
$lang["general"]["langcode"] = "da_DK";
$lang["general"]["scripterror"] = "En fejl opstod! {0}: {1}";
/************* Navbar *************/
$lang["navbar"]["navigation"] = "Navigation";
$lang["navbar"]["viewer"] = "Server Fremvisning";
$lang["navbar"]["bans"] = "Ban Liste";
$lang["navbar"]["rules"] = "Server Regler";
$lang["navbar"]["connect"] = "Forbind til server";
$lang["navbar"]["connecttooltip"] = "Klik for at fobinde til {0}";
/************* Footer *************/
$lang["footer"]["css"] = "CSS af";
$lang["footer"]["background"] = "baggrund";
/************* Server status *************/
$lang["serverstatus"]["title"] = "Server status";
$lang["serverstatus"]["address"] = "Adresse";
$lang["serverstatus"]["loading"] = "Indlæser...";
$lang["serverstatus"]["online"] = "Online";
$lang["serverstatus"]["offline"] = "Offline";
$lang["serverstatus"]["uptime"] = "Oppetid";
$lang["serverstatus"]["version"] = "Version";
$lang["serverstatus"]["avgping"] = "Gennemsnitlig ping";
$lang["serverstatus"]["avgpl"] = "Gennemsnitlig pakketab";
/************* Admin list *************/
$lang["adminlist"]["title"] = "Admin Liste";
$lang["adminlist"]["emptygroup"] = "Denne gruppe er tom";
$lang["adminlist"]["status"]["online"] = "Online";
$lang["adminlist"]["status"]["away"] = "Borte";
$lang["adminlist"]["status"]["offline"] = "Offline";
$lang["adminlist"]["lastupdate"] = "Sidste opdatering: {0}";
/************* Server viewer promo box (under adminlist and contact) *************/
$lang["svpb"]["title"] = "Server Fremvisning";
$lang["svpb"]["takealook"] = "Tag et kig &raquo;";
/************************************/
/************* SUBPAGES *************/
/************************************/
/************* News - index.php *************/
$lang["index"]["title"] = "Nyheder";
$lang["index"]["showmore"] = "Læs mere";
$lang["index"]["showless"] = "Vis mindre";
$lang["index"]["errortitle"] = "Fejl: nyheden kunne ikke findes!";
$lang["index"]["errorsubtitle"] = "Tjek venligst, at den angivne lokation i filen <b><code>config/config.php</code></b> findes.";
/************* Server viewer - viewer.php *************/
$lang["viewer"]["title"] = "Server Fremvisning";
$lang["viewer"]["lastupdate"] = "Sidst opdateret: {0}";
/************* Ban List - bans.php *************/
$lang["banlist"]["title"] = "Ban Liste";
$lang["banlist"]["datatablesurl"] = "//cdn.datatables.net/plug-ins/1.10.12/i18n/Danish.json";
$lang["banlist"]["emptylist"] = "BAN LISTEN ER TOM";
$lang["banlist"]["lastupdate"] = "Sidst opdateret: {0}";
$lang["banlist"]["table"]["emptyreason"] = "(ingen grund givet)";
$lang["banlist"]["table"]["permaban"] = "Aldrig";
$lang["banlist"]["table"]["nickname"] = "Navn";
$lang["banlist"]["table"]["reason"] = "Grund";
$lang["banlist"]["table"]["bannedby"] = "Banlyst af";
$lang["banlist"]["table"]["bandate"] = "Dato for ban";
$lang["banlist"]["table"]["expires"] = "Udløber";
/************* Rules - rules.php *************/
$lang["rules"]["title"] = "Server Regler";
$lang["rules"]["filenotfound"] = "Fejl: filen <code>config/rules.md</code> kunne ikke findes!";
$lang["rules"]["readerror"] = "Fejl: adgang til filen <code>config/rules.md</code> nægtet!";
<?php
/*
* German language for ts-website
* @copy NothingTV <contact@tactical-gaming.com>
*/
$lang = array();
/************* General *************/
$lang["general"]["langcode"] = "de_DE";
$lang["general"]["scripterror"] = "Es ist ein Fehler aufgetreten! {0}: {1}";
/************* Navbar *************/
$lang["navbar"]["navigation"] = "Navigation";
$lang["navbar"]["viewer"] = "Server Viewer";
$lang["navbar"]["bans"] = "Bann Liste";
$lang["navbar"]["rules"] = "Server Regeln";
$lang["navbar"]["connect"] = "Mit Server verbinden";
$lang["navbar"]["connecttooltip"] = "Klicken um mit {0} zu verbinden";
/************* Footer *************/
$lang["footer"]["website"] = "Webseite";
$lang["footer"]["css"] = "CSS bereitgestellt von";
$lang["footer"]["background"] = "Hintergrund";
/************* Server status *************/
$lang["serverstatus"]["title"] = "Server Status";
$lang["serverstatus"]["address"] = "Adresse";
$lang["serverstatus"]["loading"] = "Laden...";
$lang["serverstatus"]["online"] = "Online";
$lang["serverstatus"]["offline"] = "Offline";
$lang["serverstatus"]["uptime"] = "Uptime";
$lang["serverstatus"]["version"] = "Server Version";
$lang["serverstatus"]["avgping"] = "Ø Ping";
$lang["serverstatus"]["avgpl"] = "Ø Paketverlust";
/************* Admin list *************/
$lang["adminlist"]["title"] = "Admin Liste";
$lang["adminlist"]["emptygroup"] = "Diese Gruppe ist leer";
$lang["adminlist"]["status"]["online"] = "Online";
$lang["adminlist"]["status"]["away"] = "Abwesend";
$lang["adminlist"]["status"]["offline"] = "Offline";
$lang["adminlist"]["lastupdate"] = "Letzte Aktualisierung: {0}";
/************* Server viewer promo box (under adminlist and contact) *************/
$lang["svpb"]["title"] = "Server Viewer";
$lang["svpb"]["takealook"] = "Riskier 'n Blick &raquo;";
/************************************/
/************* SUBPAGES *************/
/************************************/
/************* News - index.php *************/
$lang["index"]["title"] = "Neuigkeiten";
$lang["index"]["showmore"] = "Mehr anzeigen";
$lang["index"]["showless"] = "Weniger anzeigen";
$lang["index"]["errortitle"] = "Fehler: Neuigkeiten Ordner konnte nicht gefunden werden!";
$lang["index"]["errorsubtitle"] = "Bitte stelle sicher, dass der Ordner Pfad in <code>config/config.php</code> richtig angegeben wurde.";
/************* Server viewer - viewer.php *************/
$lang["viewer"]["title"] = "Server Viewer";
$lang["viewer"]["lastupdate"] = "Letzte Aktualisierung: {0}";
/************* Ban List - bans.php *************/
$lang["banlist"]["title"] = "Bann Liste";
$lang["banlist"]["datatablesurl"] = "//cdn.datatables.net/plug-ins/1.10.12/i18n/German.json";
$lang["banlist"]["emptylist"] = "Es gibt derzeit keine Gebannten User";
$lang["banlist"]["lastupdate"] = "Letzte Aktualisierung: {0}";
$lang["banlist"]["table"]["emptyreason"] = "(kein Grund angegeben)";
$lang["banlist"]["table"]["permaban"] = "Niemals";
$lang["banlist"]["table"]["nickname"] = "Benutzername";
$lang["banlist"]["table"]["reason"] = "Grund";
$lang["banlist"]["table"]["bannedby"] = "Gebannt von";
$lang["banlist"]["table"]["bandate"] = "Bann Zeitpunkt";
$lang["banlist"]["table"]["expires"] = "Läuft ab am";
/************* Rules - rules.php *************/
$lang["rules"]["title"] = "Server Regeln";
$lang["rules"]["filenotfound"] = "Fehler: Die Datei <code>config/rules.md</code> wurde nicht gefunden!";
$lang["rules"]["readerror"] = "Fehler: Nicht genügend Rechte um auf <code>config/rules.md</code> zuzugreifen!";
<?php
/*
* English language for ts-website
* @copy Wruczek <wruczekk@gmail.com>
*/
$lang = array();
/************* General *************/
$lang["general"]["langcode"] = "en_GB";
$lang["general"]["scripterror"] = "An error occured! {0}: {1}";
/************* Navbar *************/
$lang["navbar"]["navigation"] = "Navigation";
$lang["navbar"]["viewer"] = "Server Viewer";
$lang["navbar"]["bans"] = "Ban List";
$lang["navbar"]["rules"] = "Server Rules";
$lang["navbar"]["connect"] = "Connect to server";
$lang["navbar"]["connecttooltip"] = "Click to connect to {0}";
/************* Footer *************/
$lang["footer"]["css"] = "CSS by";
$lang["footer"]["background"] = "background";
/************* Server status *************/
$lang["serverstatus"]["title"] = "Server status";
$lang["serverstatus"]["address"] = "Address";
$lang["serverstatus"]["loading"] = "Loading...";
$lang["serverstatus"]["online"] = "Online";
$lang["serverstatus"]["offline"] = "Offline";
$lang["serverstatus"]["uptime"] = "Uptime";
$lang["serverstatus"]["version"] = "Version";
$lang["serverstatus"]["avgping"] = "Average ping";
$lang["serverstatus"]["avgpl"] = "Average packet loss";
/************* Admin list *************/
$lang["adminlist"]["title"] = "Adminlist";
$lang["adminlist"]["emptygroup"] = "This group is empty";
$lang["adminlist"]["status"]["online"] = "Online";
$lang["adminlist"]["status"]["away"] = "Away";
$lang["adminlist"]["status"]["offline"] = "Offline";
$lang["adminlist"]["lastupdate"] = "Last update: {0}";
/************* Server viewer promo box (under adminlist and contact) *************/
$lang["svpb"]["title"] = "Server Viewer";
$lang["svpb"]["takealook"] = "Take a look &raquo;";
/************************************/
/************* SUBPAGES *************/
/************************************/
/************* News - index.php *************/
$lang["index"]["title"] = "News";
$lang["index"]["showmore"] = "Read more";
$lang["index"]["showless"] = "Show less";
$lang["index"]["errortitle"] = "Error: news directory has not been found!";
$lang["index"]["errorsubtitle"] = "Please make sure that directory location set in <b><code>config/config.php</code></b> is valid.";
/************* Server viewer - viewer.php *************/
$lang["viewer"]["title"] = "Server Viewer";
$lang["viewer"]["lastupdate"] = "Last update: {0}";
/************* Ban List - bans.php *************/
$lang["banlist"]["title"] = "Ban List";
$lang["banlist"]["datatablesurl"] = "//cdn.datatables.net/plug-ins/1.10.12/i18n/English.json";
$lang["banlist"]["emptylist"] = "BAN LIST IS EMPTY";
$lang["banlist"]["lastupdate"] = "Last update: {0}";
$lang["banlist"]["table"]["emptyreason"] = "(no reason set)";
$lang["banlist"]["table"]["permaban"] = "Never";
$lang["banlist"]["table"]["nickname"] = "Nick";
$lang["banlist"]["table"]["reason"] = "Reason";
$lang["banlist"]["table"]["bannedby"] = "Banned by";
$lang["banlist"]["table"]["bandate"] = "Ban date";
$lang["banlist"]["table"]["expires"] = "Expires";
/************* Rules - rules.php *************/
$lang["rules"]["title"] = "Server Rules";
$lang["rules"]["filenotfound"] = "Error: file <code>config/rules.md</code> has not been found!";
$lang["rules"]["readerror"] = "Error: cannot access the file <code>config/rules.md</code>!";
<?php
/*
* Spanish language for ts-website
* @copy Vinanrra <staff@teamworkers.es>
*/
$lang = array();
/************* General *************/
$lang["general"]["langcode"] = "es-ES";
$lang["general"]["scripterror"] = "Ha ocurrido un error {0}: {1}";
/************* Navbar *************/
$lang["navbar"]["navigation"] = "Navegación";
$lang["navbar"]["viewer"] = "Server Viewer";
$lang["navbar"]["bans"] = "Lista de baneados";
$lang["navbar"]["rules"] = "Reglas del servidor";
$lang["navbar"]["connect"] = "Conectar al ts3";
$lang["navbar"]["connecttooltip"] = "Click para conectar a {0}";
/************* Footer *************/
$lang["footer"]["css"] = "CSS por";
$lang["footer"]["background"] = "fondo";
/************* Server status *************/
$lang["serverstatus"]["title"] = "Estado del servidor";
$lang["serverstatus"]["address"] = "Direción";
$lang["serverstatus"]["loading"] = "Cargando...";
$lang["serverstatus"]["online"] = "En linea";
$lang["serverstatus"]["offline"] = "Desconectado";
$lang["serverstatus"]["uptime"] = "Tiempo activo";
$lang["serverstatus"]["version"] = "Versión";
$lang["serverstatus"]["avgping"] = "Ping promedio";
$lang["serverstatus"]["avgpl"] = "Pérdida de paquetes";
/************* Admin list *************/
$lang["adminlist"]["title"] = "Lista de ADM/MOD";
$lang["adminlist"]["emptygroup"] = "Grupo vacio";
$lang["adminlist"]["status"]["online"] = "En linea";
$lang["adminlist"]["status"]["away"] = "AFK";
$lang["adminlist"]["status"]["offline"] = "Desconectado";
$lang["adminlist"]["lastupdate"] = "Última actualización: {0}";
/************* Server viewer promo box (under adminlist and contact) *************/
$lang["svpb"]["title"] = "Ver servidor";
$lang["svpb"]["takealook"] = "Echar un vistazo &raquo;";
/************************************/
/************* SUBPAGES *************/
/************************************/
/************* News - index.php *************/
$lang["index"]["title"] = "Noticias";
$lang["index"]["showmore"] = "Leer más";
$lang["index"]["showless"] = "Mostar menos";
$lang["index"]["errortitle"] = "Error: El directorio de noticias no fue encontrado";
$lang["index"]["errorsubtitle"] = "Por favor asegurate que el directorio que está en <b><code>config/config.php</code></b> es válido.";
/************* Server viewer - viewer.php *************/
$lang["viewer"]["title"] = "Ver servidor";
$lang["viewer"]["lastupdate"] = "Última actualización: {0}";
/************* Ban List - bans.php *************/
$lang["banlist"]["title"] = "Lista de baneados";
$lang["banlist"]["datatablesurl"] = "//cdn.datatables.net/plug-ins/1.10.12/i18n/Spanish.json";
$lang["banlist"]["emptylist"] = "La lista de baneados está vacia";
$lang["banlist"]["lastupdate"] = "Última actualización: {0}";
$lang["banlist"]["table"]["emptyreason"] = "(sin razón)";
$lang["banlist"]["table"]["permaban"] = "Nunca";
$lang["banlist"]["table"]["nickname"] = "Usuario";
$lang["banlist"]["table"]["reason"] = "Razón";
$lang["banlist"]["table"]["bannedby"] = "Baneado por";
$lang["banlist"]["table"]["bandate"] = "Fecha de baneo";
$lang["banlist"]["table"]["expires"] = "Expiración";
/************* Rules - rules.php *************/
$lang["rules"]["title"] = "Reglas del servidor";
$lang["rules"]["filenotfound"] = "Error: archivo <code>config/rules.md</code> no ha sido encontrado";
$lang["rules"]["readerror"] = "Error: no se puede acceder al archivo <code>config/rules.md</code>";
<?php
/*
* French language for ts-website
* @copy FleuryK <contact@fleuryk.tk>
*/
$lang = array();
/************* General *************/
$lang["general"]["langcode"] = "fr_FR";
$lang["general"]["scripterror"] = "Une erreur s'est produite ! {0} : {1}";
/************* Navbar *************/
$lang["navbar"]["navigation"] = "Navigation";
$lang["navbar"]["viewer"] = "Affichage du Serveur";
$lang["navbar"]["bans"] = "Liste des Bans";
$lang["navbar"]["rules"] = "Règles du Serveur";
$lang["navbar"]["connect"] = "Se connecter au Serveur";
$lang["navbar"]["connecttooltip"] = "Cliquez pour vous connecter à {0}";
/************* Footer *************/
$lang["footer"]["css"] = "CSS par";
$lang["footer"]["background"] = "arrière-plan";
/************* Server status *************/
$lang["serverstatus"]["title"] = "Statut du Serveur";
$lang["serverstatus"]["address"] = "Adresse";
$lang["serverstatus"]["loading"] = "Chargement ...";
$lang["serverstatus"]["online"] = "En ligne";
$lang["serverstatus"]["offline"] = "Hors ligne";
$lang["serverstatus"]["uptime"] = "Tps de fonction.";
$lang["serverstatus"]["version"] = "Version";
$lang["serverstatus"]["avgping"] = "Moyenne du Ping";
$lang["serverstatus"]["avgpl"] = "Perte moyenne de paquets";
/************* Admin list *************/
$lang["adminlist"]["title"] = "Liste d'Admin";
$lang["adminlist"]["emptygroup"] = "Ce groupe est vide";
$lang["adminlist"]["status"]["online"] = "En ligne";
$lang["adminlist"]["status"]["away"] = "Away";
$lang["adminlist"]["status"]["offline"] = "Hors ligne";
$lang["adminlist"]["lastupdate"] = "Dernière mise à jour : {0}";
/************* Server viewer promo box (under adminlist and contact) *************/
$lang["svpb"]["title"] = "Affichage du Serveur";
$lang["svpb"]["takealook"] = "Regarder &raquo;";
/************************************/
/************* SUBPAGES *************/
/************************************/
/************* News - index.php *************/
$lang["index"]["title"] = "News";
$lang["index"]["showmore"] = "Lire la suite";
$lang["index"]["showless"] = "Moins montrer";
$lang["index"]["errortitle"] = "Erreur : le dossier des news n'a pas été trouvé !";
$lang["index"]["errorsubtitle"] = "Assurez-vous que l'emplacement du répertoire défini dans <b><code>config/config.php</code></b> est valide.";
/************* Server viewer - viewer.php *************/
$lang["viewer"]["title"] = "Affichage du Serveur";
$lang["viewer"]["lastupdate"] = "Dernière mise à jour : {0}";
/************* Ban List - bans.php *************/
$lang["banlist"]["title"] = "Liste des Bans";
$lang["banlist"]["datatablesurl"] = "//cdn.datatables.net/plug-ins/1.10.12/i18n/French.json";
$lang["banlist"]["emptylist"] = "LA LISTE DES BANS EST VIDE";
$lang["banlist"]["lastupdate"] = "Dernière mise à jour : {0}";
$lang["banlist"]["table"]["emptyreason"] = "(pas de raison)";
$lang["banlist"]["table"]["permaban"] = "Jamais";
$lang["banlist"]["table"]["nickname"] = "Surnom";
$lang["banlist"]["table"]["reason"] = "Raison";
$lang["banlist"]["table"]["bannedby"] = "Banni par";
$lang["banlist"]["table"]["bandate"] = "Date du Ban";
$lang["banlist"]["table"]["expires"] = "Expire";
/************* Rules - rules.php *************/
$lang["rules"]["title"] = "Règles du Serveur";
$lang["rules"]["filenotfound"] = "Erreur : Le fichier <code>config/rules.md</code> n'a pas été trouvé !";
$lang["rules"]["readerror"] = "Erreur : Impossible d'accéder au fichier <code>config/rules.md</code> !";
<?php
/*
* Greek language for ts-website
* @copy Alligatoras
*/
$lang = array();
/************* General *************/
$lang["general"]["langcode"] = "el_GR";
$lang["general"]["scripterror"] = "Προέκυψε Σφάλμα! {0}: {1}";
/************* Navbar *************/
$lang["navbar"]["navigation"] = "Περιήγηση";
$lang["navbar"]["viewer"] = "Προβολή TS3";
$lang["navbar"]["bans"] = "Λίστα Αποκλεισμών";
$lang["navbar"]["rules"] = "Κανόνες";
$lang["navbar"]["connect"] = "Σύνδεση";
$lang["navbar"]["connecttooltip"] = "Κάντε κλικ για να συνδεθείτε στην IP: {0}";
/************* Footer *************/
$lang["footer"]["css"] = "CSS by";
$lang["footer"]["background"] = "background";
/************* Server status *************/
$lang["serverstatus"]["title"] = "Κατάσταση Server";
$lang["serverstatus"]["address"] = "Διεύθυνση";
$lang["serverstatus"]["loading"] = "Φορτώνει...";
$lang["serverstatus"]["online"] = "Σε Σύνδεση";
$lang["serverstatus"]["offline"] = "Εκτός Σύνδεσης";
$lang["serverstatus"]["uptime"] = "Συνδεσιμότητα";
$lang["serverstatus"]["version"] = "Έκδοση";
$lang["serverstatus"]["avgping"] = "Μέσος Όρος Ping";
$lang["serverstatus"]["avgpl"] = "Μέση Απώλεια Πακ.";
/************* Admin list *************/
$lang["adminlist"]["title"] = "Λίστα Διαχειριστών";
$lang["adminlist"]["emptygroup"] = "Αυτό το γκρουπ είναι άδειο.";
$lang["adminlist"]["status"]["online"] = "Online";
$lang["adminlist"]["status"]["away"] = "Away";
$lang["adminlist"]["status"]["offline"] = "Offline";
$lang["adminlist"]["lastupdate"] = "Τελευταία Ενημέρωση: {0}";
/************* Server viewer promo box (under adminlist and contact) *************/
$lang["svpb"]["title"] = "Προβολή TS3";
$lang["svpb"]["takealook"] = "Ρίξτε μια ματιά &raquo;";
/************************************/
/************* SUBPAGES *************/
/************************************/
/************* News - index.php *************/
$lang["index"]["title"] = "Νέα & Ειδοποιήσεις";
$lang["index"]["showmore"] = "Δείτε Περισσότερα";
$lang["index"]["showless"] = "Δείτε Λιγότερα";
$lang["index"]["errortitle"] = "Σημαντικό Σφάλμα: Ο κατάλογος για τα Νέα και τις Ειδοποιήσεις δεν βρέθηκε!";
$lang["index"]["errorsubtitle"] = "Παρακαλώ βεβαιωθείτε ότι θέση του καταλόγου στο <b><code>config/config.php</code></b> είναι σωστή.";
/************* Server viewer - viewer.php *************/
$lang["viewer"]["title"] = "Προβολή TS3";
$lang["viewer"]["lastupdate"] = "Τελευταία Ενημέρωση: {0}";
/************* Ban List - bans.php *************/
$lang["banlist"]["title"] = "Λίστα Αποκλεισμών";
$lang["banlist"]["datatablesurl"] = "//cdn.datatables.net/plug-ins/1.10.12/i18n/Greek.json";
$lang["banlist"]["emptylist"] = "Η λίστα αοκλεισμών είναι άδεια!";
$lang["banlist"]["lastupdate"] = "Τελευταία Ενημέρωση: {0}";
$lang["banlist"]["table"]["emptyreason"] = "(Χωρίς Λόγο)";
$lang["banlist"]["table"]["permaban"] = "Ποτέ";
$lang["banlist"]["table"]["nickname"] = "Όνομα";
$lang["banlist"]["table"]["reason"] = "Αιτία";
$lang["banlist"]["table"]["bannedby"] = "Αποκλείστηκε από";
$lang["banlist"]["table"]["bandate"] = "Ημερομηνία Αποκλεισμού";
$lang["banlist"]["table"]["expires"] = "Λήγει";
/************* Rules - rules.php *************/
$lang["rules"]["title"] = "Κανόνες";
$lang["rules"]["filenotfound"] = "Σημαντικό Σφάλμα: Το αρχείο <code>config/rules.md</code> δεν βρέθηκε!";
$lang["rules"]["readerror"] = "Σημαντικό Σφάλμα: Δεν υπάρχει πρόσβαση στο αρχείο <code>config/rules.md</code>!";
<?php
/*
* Hungarian language for ts-website
* @copy SmaCk <steamcommunity.com/id/smackiii>
*/
$lang = array();
/************* Általános *************/
$lang["general"]["langcode"] = "hu_HU";
$lang["general"]["scripterror"] = "Hiba történt! {0}: {1}";
/************* Navbár *************/
$lang["navbar"]["navigation"] = "Navigáció";
$lang["navbar"]["viewer"] = "Szerver Státusz";
$lang["navbar"]["bans"] = "Banlista";
$lang["navbar"]["rules"] = "Szabályzat";
$lang["navbar"]["connect"] = "CSATLAKOZÁS";
$lang["navbar"]["connecttooltip"] = "Csatlakozáshoz katt.. {0}";
/************* Lábrész *************/
$lang["footer"]["css"] = "CSS by ";
/************* Server Státusz *************/
$lang["serverstatus"]["title"] = "Státusz";
$lang["serverstatus"]["address"] = "IP Cím";
$lang["serverstatus"]["loading"] = "Betöltés...";
$lang["serverstatus"]["online"] = "Online";
$lang["serverstatus"]["offline"] = "Offline";
$lang["serverstatus"]["uptime"] = "Üzemidő";
$lang["serverstatus"]["version"] = "Verzió";
$lang["serverstatus"]["avgping"] = "Átlagos ping";
$lang["serverstatus"]["avgpl"] = "Csomagveszteség";
/************* Admin lista *************/
$lang["adminlist"]["title"] = "Staff";
$lang["adminlist"]["emptygroup"] = "A csoport üres.";
$lang["adminlist"]["status"]["online"] = "Online";
$lang["adminlist"]["status"]["away"] = "Távol";
$lang["adminlist"]["status"]["offline"] = "Offline";
$lang["adminlist"]["lastupdate"] = "Utoljára frissítve: {0}";
/************* Adminlista és Kapcsolat alatt megjelenő szövegek *************/
$lang["svpb"]["title"] = "Státusz";
$lang["svpb"]["takealook"] = "Megnéz";
/************************************/
/************* ALOLDALAK *************/
/************************************/
/************* Hírek - index.php *************/
$lang["index"]["title"] = "Hírek";
$lang["index"]["showmore"] = "olvass tovább";
$lang["index"]["showless"] = "kevesebb";
$lang["index"]["errortitle"] = "Hiba: hírek mappa nem található!";
$lang["index"]["errorsubtitle"] = "Kérlek állítsd be a fájlt megfelelően <b><code>config/config.php</code></b>.";
/************* Szerver Státusz - viewer.php *************/
$lang["viewer"]["title"] = "Szerver Státusz";
$lang["viewer"]["lastupdate"] = "Utoljára frissítve: {0}";
/************* BanLista - bans.php *************/
$lang["banlist"]["title"] = "Banlista";
$lang["banlist"]["datatablesurl"] = "//cdn.datatables.net/plug-ins/1.10.12/i18n/Hungarian.json";
$lang["banlist"]["emptylist"] = "A banlista üres.";
$lang["banlist"]["lastupdate"] = "Utoljára frissítve: {0}";
$lang["banlist"]["table"]["emptyreason"] = "(nincs indok)";
$lang["banlist"]["table"]["permaban"] = "Soha";
$lang["banlist"]["table"]["nickname"] = "Név";
$lang["banlist"]["table"]["reason"] = "Indok";
$lang["banlist"]["table"]["bannedby"] = "Admin";
$lang["banlist"]["table"]["bandate"] = "Dátum";
$lang["banlist"]["table"]["expires"] = "Lejár";
/************* Szabályok - rules.php *************/
$lang["rules"]["title"] = "Szabályzat";
$lang["rules"]["filenotfound"] = "Hiba: fájl <code>config/rules.md</code> nem található!";
$lang["rules"]["readerror"] = "Hiba: nincs megfelelő joga <code>config/rules.md</code>!";
<?php
/*
* Italian language for ts-website
* @copy JohnnyKing94 <https://github.com/JohnnyKing94>
*/
$lang = array();
/************* General *************/
$lang["general"]["langcode"] = "it";
$lang["general"]["scripterror"] = "Un errore si è verificato! {0}: {1}";
/************* Navbar *************/
$lang["navbar"]["navigation"] = "Navigazione";
$lang["navbar"]["viewer"] = "Visualizza Server";
$lang["navbar"]["bans"] = "Lista Ban";
$lang["navbar"]["rules"] = "Regolamento";
$lang["navbar"]["connect"] = "Unisciti a noi!";
$lang["navbar"]["connecttooltip"] = "Clicca per connetterti a {0}";
/************* Footer *************/
$lang["footer"]["css"] = "CSS di";
$lang["footer"]["background"] = "sfondo";
/************* Server status *************/
$lang["serverstatus"]["title"] = "Stato Server";
$lang["serverstatus"]["address"] = "Indirizzo";
$lang["serverstatus"]["loading"] = "In caricamento...";
$lang["serverstatus"]["online"] = "Online";
$lang["serverstatus"]["offline"] = "Offline";
$lang["serverstatus"]["uptime"] = "Uptime";
$lang["serverstatus"]["version"] = "Versione";
$lang["serverstatus"]["avgping"] = "Ping medio";
$lang["serverstatus"]["avgpl"] = "Perdita media dei pacchetti";
/************* Admin list *************/
$lang["adminlist"]["title"] = "Lista admin";
$lang["adminlist"]["emptygroup"] = "Questo gruppo è vuoto";
$lang["adminlist"]["status"]["online"] = "Online";
$lang["adminlist"]["status"]["away"] = "Assente";
$lang["adminlist"]["status"]["offline"] = "Offline";
$lang["adminlist"]["lastupdate"] = "Ultimo aggiornamento: {0}";
/************* Server viewer promo box (under adminlist and contact) *************/
$lang["svpb"]["title"] = "Visualizza server";
$lang["svpb"]["takealook"] = "Guarda &raquo;";
/************************************/
/************* SUBPAGES *************/
/************************************/
/************* News - index.php *************/
$lang["index"]["title"] = "News";
$lang["index"]["showmore"] = "Leggi di più";
$lang["index"]["showless"] = "VIsualizza meno";
$lang["index"]["errortitle"] = "Errore: la directory news non è stata trovata!";
$lang["index"]["errorsubtitle"] = "Si prega di assicurarsi che la posizione della cartella impostata in <b><code>config/config.php</code></b> sia valida.";
/************* Server viewer - viewer.php *************/
$lang["viewer"]["title"] = "Visualizza Server";
$lang["viewer"]["lastupdate"] = "Ultimo aggiornamento: {0}";
/************* Ban List - bans.php *************/
$lang["banlist"]["title"] = "Lista Ban";
$lang["banlist"]["datatablesurl"] = "//cdn.datatables.net/plug-ins/1.10.12/i18n/Italian.json";
$lang["banlist"]["emptylist"] = "LA LISTA BAN E' VUOTA";
$lang["banlist"]["lastupdate"] = "Ultimo aggiornamento: {0}";
$lang["banlist"]["table"]["emptyreason"] = "(nessun motivo)";
$lang["banlist"]["table"]["permaban"] = "Permanente";
$lang["banlist"]["table"]["nickname"] = "Nick";
$lang["banlist"]["table"]["reason"] = "Motivo";
$lang["banlist"]["table"]["bannedby"] = "Bananto da";
$lang["banlist"]["table"]["bandate"] = "Data del Ban";
$lang["banlist"]["table"]["expires"] = "Scade";
/************* Rules - rules.php *************/
$lang["rules"]["title"] = "Regolamento";
$lang["rules"]["filenotfound"] = "Errore: il file <code>config/rules.md</code> non è stato trovato!";
$lang["rules"]["readerror"] = "Errore: impossibile accede al file <code>config/rules.md</code>!";
<?php
/*
* Dutch language for ts-website
* @copy MojoW <mojow@solidsn4ke.com>
*/
$lang = array();
/************* General *************/
$lang["general"]["langcode"] = "nl_NL";
$lang["general"]["scripterror"] = "Er is een fout opgetreden! {0}: {1}";
/************* Navbar *************/
$lang["navbar"]["navigation"] = "Navigatie";
$lang["navbar"]["viewer"] = "Server Bekijken";
$lang["navbar"]["bans"] = "Ban Lijst";
$lang["navbar"]["rules"] = "Server Regels";
$lang["navbar"]["connect"] = "Verbinden met server";
$lang["navbar"]["connecttooltip"] = "Klik om verbinding te maken met {0}";
/************* Footer *************/
$lang["footer"]["website"] = "Website";
$lang["footer"]["css"] = "CSS mogelijk gemaakt door";
$lang["footer"]["background"] = "achtergrond";
/************* Server status *************/
$lang["serverstatus"]["title"] = "Server status";
$lang["serverstatus"]["address"] = "Adres";
$lang["serverstatus"]["loading"] = "Laden...";
$lang["serverstatus"]["online"] = "Online";
$lang["serverstatus"]["offline"] = "Offline";
$lang["serverstatus"]["uptime"] = "Uptijd";
$lang["serverstatus"]["version"] = "Versie";
$lang["serverstatus"]["avgping"] = "Gemiddelde ping";
$lang["serverstatus"]["avgpl"] = "Gemiddelde pakketverlies";
/************* Admin list *************/
$lang["adminlist"]["title"] = "Adminlijst";
$lang["adminlist"]["emptygroup"] = "Deze groep is leeg";
$lang["adminlist"]["status"]["online"] = "Online";
$lang["adminlist"]["status"]["away"] = "Afwezig";
$lang["adminlist"]["status"]["offline"] = "Offline";
$lang["adminlist"]["lastupdate"] = "Laaste update: {0}";
/************* Server viewer promo box (under adminlist and contact) *************/
$lang["svpb"]["title"] = "Server Bekijken";
$lang["svpb"]["takealook"] = "Neem een kijkje &raquo;";
/************************************/
/************* SUBPAGES *************/
/************************************/
/************* News - index.php *************/
$lang["index"]["title"] = "Niews";
$lang["index"]["showmore"] = "Lees meer";
$lang["index"]["showless"] = "Minimaliseer";
$lang["index"]["errortitle"] = "Fout: niews map is niet gevonden!";
$lang["index"]["errorsubtitle"] = "Controleer A.U.B of de map locatie in <code>config/config.php</code> correct is.";
/************* Server viewer - viewer.php *************/
$lang["viewer"]["title"] = "Server Bekijken";
$lang["viewer"]["lastupdate"] = "Laaste update: {0}";
/************* Ban List - bans.php *************/
$lang["banlist"]["title"] = "Ban Lijst";
$lang["banlist"]["datatablesurl"] = "//cdn.datatables.net/plug-ins/1.10.12/i18n/Dutch.json";
$lang["banlist"]["emptylist"] = "BAN LIJST IS LEEG";
$lang["banlist"]["lastupdate"] = "Laaste update: {0}";
$lang["banlist"]["table"]["emptyreason"] = "(Geen reden)";
$lang["banlist"]["table"]["permaban"] = "Nooit";
$lang["banlist"]["table"]["nickname"] = "Bijnaam";
$lang["banlist"]["table"]["reason"] = "Reden";
$lang["banlist"]["table"]["bannedby"] = "Gebanned door";
$lang["banlist"]["table"]["bandate"] = "Ban datum";
$lang["banlist"]["table"]["expires"] = "Verloopt op";
/************* Rules - rules.php *************/
$lang["rules"]["title"] = "Server Regels";
$lang["rules"]["filenotfound"] = "Fout: kan het bestand <code>config/rules.md</code> niet vinden!";
$lang["rules"]["readerror"] = "Fout: Geen toegang tot het bestand <code>config/rules.md</code>!";
<?php
/*
* Polish language for ts-website
* @copy Wruczek <wruczekk@gmail.com>
*/
$lang = array();
/************* General *************/
$lang["general"]["langcode"] = "pl_PL";
$lang["general"]["scripterror"] = "Wystąpił błąd! {0}: {1}";
/************* Navbar *************/
$lang["navbar"]["navigation"] = "Nawigacja";
$lang["navbar"]["viewer"] = "Podgląd serwera";
$lang["navbar"]["bans"] = "Lista banów";
$lang["navbar"]["rules"] = "Regulamin";
$lang["navbar"]["connect"] = "Połącz z serwerem";
$lang["navbar"]["connecttooltip"] = "Kliknij, by połączyć się z serwerem {0}";
/************* Footer *************/
$lang["footer"]["website"] = "Strona";
$lang["footer"]["css"] = "CSS dzięki uprzejmości";
$lang["footer"]["background"] = "tło";
/************* Server status *************/
$lang["serverstatus"]["title"] = "Status serwera";
$lang["serverstatus"]["address"] = "Adres";
$lang["serverstatus"]["loading"] = "Ładowanie...";
$lang["serverstatus"]["online"] = "Online";
$lang["serverstatus"]["offline"] = "Offline";
$lang["serverstatus"]["uptime"] = "Uptime";
$lang["serverstatus"]["version"] = "Wersja";
$lang["serverstatus"]["avgping"] = "Średni ping";
$lang["serverstatus"]["avgpl"] = "Średni packet loss";
/************* Admin list *************/
$lang["adminlist"]["title"] = "Status administracji";
$lang["adminlist"]["emptygroup"] = "Ta grupa jest pusta";
$lang["adminlist"]["status"]["online"] = "Online";
$lang["adminlist"]["status"]["away"] = "Away";
$lang["adminlist"]["status"]["offline"] = "Offline";
$lang["adminlist"]["lastupdate"] = "Stan na {0}";
/************* Server viewer promo box (under adminlist and contact) *************/
$lang["svpb"]["title"] = "Podgląd serwera";
$lang["svpb"]["takealook"] = "Zobacz &raquo;";
/************************************/
/************* SUBPAGES *************/
/************************************/
/************* News - index.php *************/
$lang["index"]["title"] = "Wiadomości";
$lang["index"]["showmore"] = "Pokaż wiecej";
$lang["index"]["showless"] = "Pokaż mniej";
$lang["index"]["errortitle"] = "Wystąpił błąd: folder z newsami nie został odnaleziony.";
$lang["index"]["errorsubtitle"] = "Sprawdź, czy lokalizacja ustawiona w pliku <code>config/config.php</code> jest poprawna.";
/************* Server viewer - viewer.php *************/
$lang["viewer"]["title"] = "Podgląd serwera";
$lang["viewer"]["lastupdate"] = "Stan na {0}";
/************* Ban List - bans.php *************/
$lang["banlist"]["title"] = "Lista banów";
$lang["banlist"]["datatablesurl"] = "//cdn.datatables.net/plug-ins/1.10.12/i18n/Polish.json";
$lang["banlist"]["emptylist"] = "BRAK ZBANOWANYCH UŻYTKOWNIKÓW";
$lang["banlist"]["lastupdate"] = "Stan na {0}";
$lang["banlist"]["table"]["emptyreason"] = "(brak powodu)";
$lang["banlist"]["table"]["permaban"] = "Nigdy";
$lang["banlist"]["table"]["nickname"] = "Nick";
$lang["banlist"]["table"]["reason"] = "Powód";
$lang["banlist"]["table"]["bannedby"] = "Zbanowany przez";
$lang["banlist"]["table"]["bandate"] = "Data zbanowania";
$lang["banlist"]["table"]["expires"] = "Wygasa";
/************* Rules - rules.php *************/
$lang["rules"]["title"] = "Regulamin serwera";
$lang["rules"]["filenotfound"] = "Wystąpił błąd: plik <code>config/rules.md</code> nie został odnaleziony!";
$lang["rules"]["readerror"] = "Wystąpił błąd: nie można odczytać pliku <code>config/rules.md</code>!";
<?php
/*
* Russian language for ts-website
* @copy TRID <admin@awp.by>
*/
$lang = array();
/************* General *************/
$lang["general"]["langcode"] = "ru_RU";
$lang["general"]["scripterror"] = "Произошла ошибка! {0}: {1}";
/************* Navbar *************/
$lang["navbar"]["navigation"] = "Навигация";
$lang["navbar"]["viewer"] = "Обзор сервера";
$lang["navbar"]["bans"] = "Список забаненных";
$lang["navbar"]["rules"] = "Правила сервера";
$lang["navbar"]["connect"] = "Подключиться";
$lang["navbar"]["connecttooltip"] = "Нажмите, чтобы подключиться к {0}";
/************* Footer *************/
$lang["footer"]["website"] = "Веб-сайт";
$lang["footer"]["css"] = "CSS благодаря любезности";
$lang["footer"]["background"] = "фон";
/************* Server status *************/
$lang["serverstatus"]["title"] = "Статус сервера";
$lang["serverstatus"]["address"] = "Адрес";
$lang["serverstatus"]["loading"] = "Загрузка...";
$lang["serverstatus"]["online"] = "В сети";
$lang["serverstatus"]["offline"] = "Не в сети";
$lang["serverstatus"]["uptime"] = "Аптайм";
$lang["serverstatus"]["version"] = "Версия";
$lang["serverstatus"]["avgping"] = "Средний пинг";
$lang["serverstatus"]["avgpl"] = "Ср. потеря пакетов";
/************* Admin list *************/
$lang["adminlist"]["title"] = "Статус администрации";
$lang["adminlist"]["emptygroup"] = "Эта группа пуста";
$lang["adminlist"]["status"]["online"] = "В сети";
$lang["adminlist"]["status"]["away"] = "Нет на месте";
$lang["adminlist"]["status"]["offline"] = "Не в сети";
$lang["adminlist"]["lastupdate"] = "Последнее обновление: {0}";
/************* Server viewer promo box (under adminlist and contact) *************/
$lang["svpb"]["title"] = "Обзор сервера";
$lang["svpb"]["takealook"] = "Взглянуть &raquo;";
/************************************/
/************* SUBPAGES *************/
/************************************/
/************* News - index.php *************/
$lang["index"]["title"] = "Новости";
$lang["index"]["showmore"] = "Читать дальше";
$lang["index"]["showless"] = "Показать меньше";
$lang["index"]["errortitle"] = "Ошибка: каталог новостей не найден!";
$lang["index"]["errorsubtitle"] = "Пожалуйста, убедитесь, что местоположение папки в <b><code>config/config.php</code></b> установлено корректно.";
/************* Server viewer - viewer.php *************/
$lang["viewer"]["title"] = "Обзор сервера";
$lang["viewer"]["lastupdate"] = "Последнее обновление: {0}";
/************* Ban List - bans.php *************/
$lang["banlist"]["title"] = "Список забаненных";
$lang["banlist"]["datatablesurl"] = "//cdn.datatables.net/plug-ins/1.10.12/i18n/Russian.json";
$lang["banlist"]["emptylist"] = "Список забаненных пуст";
$lang["banlist"]["lastupdate"] = "Последнее обновление: {0}";
$lang["banlist"]["table"]["emptyreason"] = "(причина не указана)";
$lang["banlist"]["table"]["permaban"] = "Никогда";
$lang["banlist"]["table"]["nickname"] = "Ник";
$lang["banlist"]["table"]["reason"] = "Причина";
$lang["banlist"]["table"]["bannedby"] = "Забанен";
$lang["banlist"]["table"]["bandate"] = "Дата бана";
$lang["banlist"]["table"]["expires"] = "Истекает";
/************* Rules - rules.php *************/
$lang["rules"]["title"] = "Правила сервера";
$lang["rules"]["filenotfound"] = "Ошибка: файл <code>config/rules.md</code> не найден!";
$lang["rules"]["readerror"] = "Ошибка: нет доступа к файлу <code>config/rules.md</code>!";
<?php
/*
* Swedish language for ts-website
* @copy Mattias G. <mattiasghodsian@gmail.com>
*/
$lang = array();
/************* General *************/
$lang["general"]["langcode"] = "se_SV";
$lang["general"]["scripterror"] = "Ett fel inträffade! {0}: {1}";
/************* Navbar *************/
$lang["navbar"]["navigation"] = "Navigering";
$lang["navbar"]["viewer"] = "Server överblick";
$lang["navbar"]["bans"] = "Ban Lista";
$lang["navbar"]["rules"] = "Server Regler";
$lang["navbar"]["connect"] = "Anslut till servern";
$lang["navbar"]["connecttooltip"] = "Klicka för att ansluta till {0}";
/************* Footer *************/
$lang["footer"]["css"] = "CSS av";
$lang["footer"]["background"] = "bakgrund";
/************* Server status *************/
$lang["serverstatus"]["title"] = "Serverstatus";
$lang["serverstatus"]["address"] = "Adress";
$lang["serverstatus"]["loading"] = "Laddar...";
$lang["serverstatus"]["online"] = "Uppkopplad";
$lang["serverstatus"]["offline"] = "Nerkopplad";
$lang["serverstatus"]["uptime"] = "Upp tid";
$lang["serverstatus"]["version"] = "Version";
$lang["serverstatus"]["avgping"] = "Genomsnittlig ping";
$lang["serverstatus"]["avgpl"] = "Genomsnittlig paketförlust";
/************* Admin list *************/
$lang["adminlist"]["title"] = "Admin lista";
$lang["adminlist"]["emptygroup"] = "Den här gruppen är tom";
$lang["adminlist"]["status"]["online"] = "Uppkopplad";
$lang["adminlist"]["status"]["away"] = "Bort";
$lang["adminlist"]["status"]["offline"] = "Nerkopplad";
$lang["adminlist"]["lastupdate"] = "Senaste uppdateringen: {0}";
/************* Server viewer promo box (under adminlist and contact) *************/
$lang["svpb"]["title"] = "Server överblick";
$lang["svpb"]["takealook"] = "Ta en titt &raquo;";
/************************************/
/************* SUBPAGES *************/
/************************************/
/************* News - index.php *************/
$lang["index"]["title"] = "Nyheter";
$lang["index"]["showmore"] = "Läs mer";
$lang["index"]["showless"] = "Visa mindre";
$lang["index"]["errortitle"] = "Fel: Nyhetskatalog har inte hittats!";
$lang["index"]["errorsubtitle"] = "Se till att katalogplatsen som anges i <b><code>config/config.php</code></b> är giltig. ";
/************* Server viewer - viewer.php *************/
$lang["viewer"]["title"] = "Server överblick";
$lang["viewer"]["lastupdate"] = "Senaste uppdateringen: {0}";
/************* Ban List - bans.php *************/
$lang["banlist"]["title"] = "Ban ListA";
$lang["banlist"]["datatablesurl"] = "/cdn.datatables.net/plug-ins/1.10.12/i18n/Swedish.json";
$lang["banlist"]["emptylist"] = "BANLISTAN ÄR TOM";
$lang["banlist"]["lastupdate"] = "Senaste uppdateringen: {0}";
$lang["banlist"]["table"]["emptyreason"] = "(Ingen anledning inställd)";
$lang["banlist"]["table"]["permaban"] = "Aldrig";
$lang["banlist"]["table"]["nickname"] = "Nick";
$lang["banlist"]["table"]["reason"] = "Anledning";
$lang["banlist"]["table"]["bannedby"] = "Banned av";
$lang["banlist"]["table"]["bandate"] = "Ban tid";
$lang["banlist"]["table"]["expires"] = "Löper ut";
/************* Rules - rules.php *************/
$lang["rules"]["title"] = "Server Regler";
$lang["rules"]["filenotfound"] = "Fel: filen <code>config/rules.md</code> har inte hittats!";
$lang["rules"]["readerror"] = "Fel: kan inte komma åt filen <code>config/rules.md</code>!";
<?php
/*
* Turkish language for ts-website
* @copy Eikichi <kontakt@eiki.moe>
*/
$lang = array();
/************* General *************/
$lang["general"]["langcode"] = "tr_TR";
$lang["general"]["scripterror"] = "Bir hata olmustur! {0}: {1}";
/************* Navbar *************/
$lang["navbar"]["navigation"] = "Navigasyon";
$lang["navbar"]["viewer"] = "Sunucu Görüntüleyici";
$lang["navbar"]["bans"] = "Ban listesi";
$lang["navbar"]["rules"] = "Sunucu kurallari";
$lang["navbar"]["connect"] = "Sunucuya Baglan";
$lang["navbar"]["connecttooltip"] = "Baglanmak için {0} tiklayin";
/************* Footer *************/
$lang["footer"]["website"] = "Websitesi";
$lang["footer"]["css"] = "CSS tarafindan saglanan";
$lang["footer"]["background"] = "Arka plân";
/************* Server status *************/
$lang["serverstatus"]["title"] = "Sunucu durumu";
$lang["serverstatus"]["address"] = "Adres";
$lang["serverstatus"]["loading"] = "Yükleme...";
$lang["serverstatus"]["online"] = "Online";
$lang["serverstatus"]["offline"] = "Offline";
$lang["serverstatus"]["uptime"] = "Çalisma süresi";
$lang["serverstatus"]["version"] = "Sunucu sürümü";
$lang["serverstatus"]["avgping"] = "Ø Ping";
$lang["serverstatus"]["avgpl"] = "Ø Paket kaybi";
/************* Admin list *************/
$lang["adminlist"]["title"] = "Yönetici listesi";
$lang["adminlist"]["emptygroup"] = "Bu grup bos";
$lang["adminlist"]["status"]["online"] = "Online";
$lang["adminlist"]["status"]["away"] = "Yok";
$lang["adminlist"]["status"]["offline"] = "Offline";
$lang["adminlist"]["lastupdate"] = "Son güncelleme: {0}";
/************* Server viewer promo box (under adminlist and contact) *************/
$lang["svpb"]["title"] = "Sunucu Görüntüleyici";
$lang["svpb"]["takealook"] = "Görüntüle &raquo;";
/************************************/
/************* SUBPAGES *************/
/************************************/
/************* News - index.php *************/
$lang["index"]["title"] = "Haber";
$lang["index"]["showmore"] = "Daha görüntüle";
$lang["index"]["showless"] = "Daha az";
$lang["index"]["errortitle"] = "Hata: Haber klasörü bulunamadi!";
$lang["index"]["errorsubtitle"] = "Klasör yolu <code>config / config.php</code> dogru belirtilen emin olun.";
/************* Server viewer - viewer.php *************/
$lang["viewer"]["title"] = "Sunucu Görüntüleyici";
$lang["viewer"]["lastupdate"] = "Son güncelleme: {0}";
/************* Ban List - bans.php *************/
$lang["banlist"]["title"] = "Ban listesi";
$lang["banlist"]["datatablesurl"] = "//cdn.datatables.net/plug-ins/1.10.12/i18n/Turkish.json";
$lang["banlist"]["emptylist"] = "Hiçbir lanetli Kullanici su anda yok";
$lang["banlist"]["lastupdate"] = "Son güncelleme: {0}";
$lang["banlist"]["table"]["emptyreason"] = "(Verilen hiçbir neden)";
$lang["banlist"]["table"]["permaban"] = "Asla";
$lang["banlist"]["table"]["nickname"] = "Kullanici adi";
$lang["banlist"]["table"]["reason"] = "Neden";
$lang["banlist"]["table"]["bannedby"] = "Banlayan kisi";
$lang["banlist"]["table"]["bandate"] = "Ban zaman";
$lang["banlist"]["table"]["expires"] = "Sona eriyor";
/************* Rules - rules.php *************/
$lang["rules"]["title"] = "Sunucu kurallari";
$lang["rules"]["filenotfound"] = "Hata: Dosya <code>config / rules.md</code> bulunamadi!";
$lang["rules"]["readerror"] = "Hata: erisim için yeterli haklar <code>config / rules.md</code>!";
<?php
/*
* Ukrainian language for ts-website
* @copy TRID <admin@live.ovh>
*/
$lang = array();
/************* General *************/
$lang["general"]["langcode"] = "uk_UA";
$lang["general"]["scripterror"] = "Виникла помилка! {0}: {1}";
/************* Navbar *************/
$lang["navbar"]["navigation"] = "Навігація";
$lang["navbar"]["viewer"] = "Огляд сервера";
$lang["navbar"]["bans"] = "Перелік заблокованих";
$lang["navbar"]["rules"] = "Правила сервера";
$lang["navbar"]["connect"] = "Підключитися";
$lang["navbar"]["connecttooltip"] = "Натисніть, щоб підключитися до {0}";
/************* Footer *************/
$lang["footer"]["website"] = "Веб-сайт";
$lang["footer"]["css"] = "CSS завдяки люб'язності";
$lang["footer"]["background"] = "фон";
/************* Server status *************/
$lang["serverstatus"]["title"] = "Статус сервера";
$lang["serverstatus"]["address"] = "Адрес";
$lang["serverstatus"]["loading"] = "Завантаження...";
$lang["serverstatus"]["online"] = "В мережі";
$lang["serverstatus"]["offline"] = "Не в мережі";
$lang["serverstatus"]["uptime"] = "Аптайм";
$lang["serverstatus"]["version"] = "Версія";
$lang["serverstatus"]["avgping"] = "Сер. пінг";
$lang["serverstatus"]["avgpl"] = "Сер. втрата пакетів";
/************* Admin list *************/
$lang["adminlist"]["title"] = "Статус адміністрації";
$lang["adminlist"]["emptygroup"] = "Ця група порожня";
$lang["adminlist"]["status"]["online"] = "В мережі";
$lang["adminlist"]["status"]["away"] = "Немає на місці";
$lang["adminlist"]["status"]["offline"] = "Не в мережі";
$lang["adminlist"]["lastupdate"] = "Останнє оновлення: {0}";
/************* Server viewer promo box (under adminlist and contact) *************/
$lang["svpb"]["title"] = "Огляд сервера";
$lang["svpb"]["takealook"] = "Поглянути &raquo;";
/************************************/
/************* SUBPAGES *************/
/************************************/
/************* News - index.php *************/
$lang["index"]["title"] = "Новини";
$lang["index"]["showmore"] = "Читати далі";
$lang["index"]["showless"] = "Показати менше";
$lang["index"]["errortitle"] = "Помилка: каталога новин не знайдено!";
$lang["index"]["errorsubtitle"] = "Будь ласка, переконайтеся, що місце розташування папки в <b><code>config/config.php</code></b> встановлено коректно.";
/************* Server viewer - viewer.php *************/
$lang["viewer"]["title"] = "Огляд сервера";
$lang["viewer"]["lastupdate"] = "Останнє оновлення: {0}";
/************* Ban List - bans.php *************/
$lang["banlist"]["title"] = "Перелік заблокованих";
$lang["banlist"]["datatablesurl"] = "//cdn.datatables.net/plug-ins/1.10.12/i18n/Russian.json";
$lang["banlist"]["emptylist"] = "Перелік заблокованих порожній";
$lang["banlist"]["lastupdate"] = "Останнє оновлення: {0}";
$lang["banlist"]["table"]["emptyreason"] = "(не вказано причини)";
$lang["banlist"]["table"]["permaban"] = "Ніколи";
$lang["banlist"]["table"]["nickname"] = "Нік";
$lang["banlist"]["table"]["reason"] = "Причина";
$lang["banlist"]["table"]["bannedby"] = "Забанен";
$lang["banlist"]["table"]["bandate"] = "Дата бана";
$lang["banlist"]["table"]["expires"] = "Завершується";
/************* Rules - rules.php *************/
$lang["rules"]["title"] = "Правила сервера";
$lang["rules"]["filenotfound"] = "Помилка: файл <code>config/rules.md</code> не знайден!";
$lang["rules"]["readerror"] = "Помилка: немає доступу до файлу <code>config/rules.md</code>!";

About the news system Wruczek, 2016-10-26, 21:00

You can add, change and remove news as a separate Markdown files located in config/news folder with extension .md.

I recommend following John Gruber's excellent markdown guide, found right under this text . It's really worth reading. To view the code that makes up the guide, go to config/news/news2.md.

I can also recommend GitHub's "Mastering Markdown" guide.

PS: You can mix Markdown with HTML to add cool stuff like icons , or even a full YouTube player with video!

Informations:

  • News are read from the config/news folder, alphabetically sorted by file name. (news A.md will be at top of the page while Z.md at the bottom)
  • Every news file need to have .md (Markdown) extension
  • News file syntax:
    • First line: News title
    • Second line: author and date
    • Third line: empty (seperator)
    • The rest of the file is Markdown code and HTML

Example news file:

News system test
Wruczek, 26-10-2016

Hello **world**!

I am the *news file*, you can save me in **config/news** folder with an **.md** extension to see me on the page!

Good luck and Happy writing! -Wruczek

Markdown Syntax - example Markdown test file John Gruber, daringfireball.net

Markdown: Syntax


Overview

Philosophy

Markdown is intended to be as easy-to-read and easy-to-write as is feasible.

Readability, however, is emphasized above all else. A Markdown-formatted document should be publishable as-is, as plain text, without looking like it's been marked up with tags or formatting instructions. While Markdown's syntax has been influenced by several existing text-to-HTML filters -- including [Setext] 1, [atx] 2, [Textile] 3, [reStructuredText] 4, [Grutatext] 5, and [EtText] 6 -- the single biggest source of inspiration for Markdown's syntax is the format of plain text email.

To this end, Markdown's syntax is comprised entirely of punctuation characters, which punctuation characters have been carefully chosen so as to look like what they mean. E.g., asterisks around a word actually look like *emphasis*. Markdown lists look like, well, lists. Even blockquotes look like quoted passages of text, assuming you've ever used email.

Inline HTML

Markdown's syntax is intended for one purpose: to be used as a format for writing for the web.

Markdown is not a replacement for HTML, or even close to it. Its syntax is very small, corresponding only to a very small subset of HTML tags. The idea is not to create a syntax that makes it easier to insert HTML tags. In my opinion, HTML tags are already easy to insert. The idea for Markdown is to make it easy to read, write, and edit prose. HTML is a publishing format; Markdown is a writing format. Thus, Markdown's formatting syntax only addresses issues that can be conveyed in plain text.

For any markup that is not covered by Markdown's syntax, you simply use HTML itself. There's no need to preface it or delimit it to indicate that you're switching from Markdown to HTML; you just use the tags.

The only restrictions are that block-level HTML elements -- e.g. <div>, <table>, <pre>, <p>, etc. -- must be separated from surrounding content by blank lines, and the start and end tags of the block should not be indented with tabs or spaces. Markdown is smart enough not to add extra (unwanted) <p> tags around HTML block-level tags.

For example, to add an HTML table to a Markdown article:

This is a regular paragraph.

<table>
    <tr>
        <td>Foo</td>
    </tr>
</table>

This is another regular paragraph.

Note that Markdown formatting syntax is not processed within block-level HTML tags. E.g., you can't use Markdown-style *emphasis* inside an HTML block.

Span-level HTML tags -- e.g. <span>, <cite>, or <del> -- can be used anywhere in a Markdown paragraph, list item, or header. If you want, you can even use HTML tags instead of Markdown formatting; e.g. if you'd prefer to use HTML <a> or <img> tags instead of Markdown's link or image syntax, go right ahead.

Unlike block-level HTML tags, Markdown syntax is processed within span-level tags.

Automatic Escaping for Special Characters

In HTML, there are two characters that demand special treatment: < and &. Left angle brackets are used to start tags; ampersands are used to denote HTML entities. If you want to use them as literal characters, you must escape them as entities, e.g. &lt;, and &amp;.

Ampersands in particular are bedeviling for web writers. If you want to write about 'AT&T', you need to write 'AT&amp;T'. You even need to escape ampersands within URLs. Thus, if you want to link to:

http://images.google.com/images?num=30&q=larry+bird

you need to encode the URL as:

http://images.google.com/images?num=30&amp;q=larry+bird

in your anchor tag href attribute. Needless to say, this is easy to forget, and is probably the single most common source of HTML validation errors in otherwise well-marked-up web sites.

Markdown allows you to use these characters naturally, taking care of all the necessary escaping for you. If you use an ampersand as part of an HTML entity, it remains unchanged; otherwise it will be translated into &amp;.

So, if you want to include a copyright symbol in your article, you can write:

&copy;

and Markdown will leave it alone. But if you write:

AT&T

Markdown will translate it to:

AT&amp;T

Similarly, because Markdown supports inline HTML, if you use angle brackets as delimiters for HTML tags, Markdown will treat them as such. But if you write:

4 < 5

Markdown will translate it to:

4 &lt; 5

However, inside Markdown code spans and blocks, angle brackets and ampersands are always encoded automatically. This makes it easy to use Markdown to write about HTML code. (As opposed to raw HTML, which is a terrible format for writing about HTML syntax, because every single < and & in your example code needs to be escaped.)


Block Elements

Paragraphs and Line Breaks

A paragraph is simply one or more consecutive lines of text, separated by one or more blank lines. (A blank line is any line that looks like a blank line -- a line containing nothing but spaces or tabs is considered blank.) Normal paragraphs should not be indented with spaces or tabs.

The implication of the "one or more consecutive lines of text" rule is that Markdown supports "hard-wrapped" text paragraphs. This differs significantly from most other text-to-HTML formatters (including Movable Type's "Convert Line Breaks" option) which translate every line break character in a paragraph into a <br /> tag.

When you do want to insert a <br /> break tag using Markdown, you end a line with two or more spaces, then type return.

Yes, this takes a tad more effort to create a <br />, but a simplistic "every line break is a <br />" rule wouldn't work for Markdown. Markdown's email-style blockquoting and multi-paragraph list items work best -- and look better -- when you format them with hard breaks.

Headers

Markdown supports two styles of headers, [Setext] 1 and [atx] 2.

Setext-style headers are "underlined" using equal signs (for first-level headers) and dashes (for second-level headers). For example:

This is an H1
=============

This is an H2
-------------

Any number of underlining ='s or -'s will work.

Atx-style headers use 1-6 hash characters at the start of the line, corresponding to header levels 1-6. For example:

# This is an H1

## This is an H2

###### This is an H6

Optionally, you may "close" atx-style headers. This is purely cosmetic -- you can use this if you think it looks better. The closing hashes don't even need to match the number of hashes used to open the header. (The number of opening hashes determines the header level.) :

# This is an H1 #

## This is an H2 ##

### This is an H3 ######

Blockquotes

Markdown uses email-style > characters for blockquoting. If you're familiar with quoting passages of text in an email message, then you know how to create a blockquote in Markdown. It looks best if you hard wrap the text and put a > before every line:

> This is a blockquote with two paragraphs. Lorem ipsum dolor sit amet,
> consectetuer adipiscing elit. Aliquam hendrerit mi posuere lectus.
> Vestibulum enim wisi, viverra nec, fringilla in, laoreet vitae, risus.
> 
> Donec sit amet nisl. Aliquam semper ipsum sit amet velit. Suspendisse
> id sem consectetuer libero luctus adipiscing.

Markdown allows you to be lazy and only put the > before the first line of a hard-wrapped paragraph:

> This is a blockquote with two paragraphs. Lorem ipsum dolor sit amet,
consectetuer adipiscing elit. Aliquam hendrerit mi posuere lectus.
Vestibulum enim wisi, viverra nec, fringilla in, laoreet vitae, risus.

> Donec sit amet nisl. Aliquam semper ipsum sit amet velit. Suspendisse
id sem consectetuer libero luctus adipiscing.

Blockquotes can be nested (i.e. a blockquote-in-a-blockquote) by adding additional levels of >:

> This is the first level of quoting.
>
> > This is nested blockquote.
>
> Back to the first level.

Blockquotes can contain other Markdown elements, including headers, lists, and code blocks:

> ## This is a header.
> 
> 1.   This is the first list item.
> 2.   This is the second list item.
> 
> Here's some example code:
> 
>     return shell_exec("echo $input | $markdown_script");

Any decent text editor should make email-style quoting easy. For example, with BBEdit, you can make a selection and choose Increase Quote Level from the Text menu.

Lists

Markdown supports ordered (numbered) and unordered (bulleted) lists.

Unordered lists use asterisks, pluses, and hyphens -- interchangably -- as list markers:

*   Red
*   Green
*   Blue

is equivalent to:

+   Red
+   Green
+   Blue

and:

-   Red
-   Green
-   Blue

Ordered lists use numbers followed by periods:

1.  Bird
2.  McHale
3.  Parish

It's important to note that the actual numbers you use to mark the list have no effect on the HTML output Markdown produces. The HTML Markdown produces from the above list is:

<ol>
<li>Bird</li>
<li>McHale</li>
<li>Parish</li>
</ol>

If you instead wrote the list in Markdown like this:

1.  Bird
1.  McHale
1.  Parish

or even:

3. Bird
1. McHale
8. Parish

you'd get the exact same HTML output. The point is, if you want to, you can use ordinal numbers in your ordered Markdown lists, so that the numbers in your source match the numbers in your published HTML. But if you want to be lazy, you don't have to.

If you do use lazy list numbering, however, you should still start the list with the number 1. At some point in the future, Markdown may support starting ordered lists at an arbitrary number.

List markers typically start at the left margin, but may be indented by up to three spaces. List markers must be followed by one or more spaces or a tab.

To make lists look nice, you can wrap items with hanging indents:

*   Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
    Aliquam hendrerit mi posuere lectus. Vestibulum enim wisi,
    viverra nec, fringilla in, laoreet vitae, risus.
*   Donec sit amet nisl. Aliquam semper ipsum sit amet velit.
    Suspendisse id sem consectetuer libero luctus adipiscing.

But if you want to be lazy, you don't have to:

*   Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
Aliquam hendrerit mi posuere lectus. Vestibulum enim wisi,
viverra nec, fringilla in, laoreet vitae, risus.
*   Donec sit amet nisl. Aliquam semper ipsum sit amet velit.
Suspendisse id sem consectetuer libero luctus adipiscing.

If list items are separated by blank lines, Markdown will wrap the items in <p> tags in the HTML output. For example, this input:

*   Bird
*   Magic

will turn into:

<ul>
<li>Bird</li>
<li>Magic</li>
</ul>

But this:

*   Bird

*   Magic

will turn into:

<ul>
<li><p>Bird</p></li>
<li><p>Magic</p></li>
</ul>

List items may consist of multiple paragraphs. Each subsequent paragraph in a list item must be indented by either 4 spaces or one tab:

1.  This is a list item with two paragraphs. Lorem ipsum dolor
    sit amet, consectetuer adipiscing elit. Aliquam hendrerit
    mi posuere lectus.

    Vestibulum enim wisi, viverra nec, fringilla in, laoreet
    vitae, risus. Donec sit amet nisl. Aliquam semper ipsum
    sit amet velit.

2.  Suspendisse id sem consectetuer libero luctus adipiscing.

It looks nice if you indent every line of the subsequent paragraphs, but here again, Markdown will allow you to be lazy:

*   This is a list item with two paragraphs.

    This is the second paragraph in the list item. You're
only required to indent the first line. Lorem ipsum dolor
sit amet, consectetuer adipiscing elit.

*   Another item in the same list.

To put a blockquote within a list item, the blockquote's > delimiters need to be indented:

*   A list item with a blockquote:

    > This is a blockquote
    > inside a list item.

To put a code block within a list item, the code block needs to be indented twice -- 8 spaces or two tabs:

*   A list item with a code block:

        <code goes here>

It's worth noting that it's possible to trigger an ordered list by accident, by writing something like this:

1986. What a great season.

In other words, a number-period-space sequence at the beginning of a line. To avoid this, you can backslash-escape the period:

1986\. What a great season.

Code Blocks

Pre-formatted code blocks are used for writing about programming or markup source code. Rather than forming normal paragraphs, the lines of a code block are interpreted literally. Markdown wraps a code block in both <pre> and <code> tags.

To produce a code block in Markdown, simply indent every line of the block by at least 4 spaces or 1 tab. For example, given this input:

This is a normal paragraph:

    This is a code block.

Markdown will generate:

<p>This is a normal paragraph:</p>

<pre><code>This is a code block.
</code></pre>

One level of indentation -- 4 spaces or 1 tab -- is removed from each line of the code block. For example, this:

Here is an example of AppleScript:

    tell application "Foo"
        beep
    end tell

will turn into:

<p>Here is an example of AppleScript:</p>

<pre><code>tell application "Foo"
    beep
end tell
</code></pre>

A code block continues until it reaches a line that is not indented (or the end of the article).

Within a code block, ampersands (&) and angle brackets (< and >) are automatically converted into HTML entities. This makes it very easy to include example HTML source code using Markdown -- just paste it and indent it, and Markdown will handle the hassle of encoding the ampersands and angle brackets. For example, this:

    <div class="footer">
        &copy; 2004 Foo Corporation
    </div>

will turn into:

<pre><code>&lt;div class="footer"&gt;
    &amp;copy; 2004 Foo Corporation
&lt;/div&gt;
</code></pre>

Regular Markdown syntax is not processed within code blocks. E.g., asterisks are just literal asterisks within a code block. This means it's also easy to use Markdown to write about Markdown's own syntax.

Horizontal Rules

You can produce a horizontal rule tag (<hr />) by placing three or more hyphens, asterisks, or underscores on a line by themselves. If you wish, you may use spaces between the hyphens or asterisks. Each of the following lines will produce a horizontal rule:

* * *

***

*****

- - -

---------------------------------------

Span Elements

Markdown supports two style of links: inline and reference.

In both styles, the link text is delimited by [square brackets].

To create an inline link, use a set of regular parentheses immediately after the link text's closing square bracket. Inside the parentheses, put the URL where you want the link to point, along with an optional title for the link, surrounded in quotes. For example:

This is [an example](http://example.com/ "Title") inline link.

[This link](http://example.net/) has no title attribute.

Will produce:

<p>This is <a href="http://example.com/" title="Title">
an example</a> inline link.</p>

<p><a href="http://example.net/">This link</a> has no
title attribute.</p>

If you're referring to a local resource on the same server, you can use relative paths:

See my [About](/about/) page for details.   

Reference-style links use a second set of square brackets, inside which you place a label of your choosing to identify the link:

This is [an example][id] reference-style link.

You can optionally use a space to separate the sets of brackets:

This is [an example] [id] reference-style link.

Then, anywhere in the document, you define your link label like this, on a line by itself:

[id]: http://example.com/  "Optional Title Here"

That is:

  • Square brackets containing the link identifier (optionally indented from the left margin using up to three spaces);
  • followed by a colon;
  • followed by one or more spaces (or tabs);
  • followed by the URL for the link;
  • optionally followed by a title attribute for the link, enclosed in double or single quotes, or enclosed in parentheses.

The following three link definitions are equivalent:

[foo]: http://example.com/  "Optional Title Here"
[foo]: http://example.com/  'Optional Title Here'
[foo]: http://example.com/  (Optional Title Here)

Note: There is a known bug in Markdown.pl 1.0.1 which prevents single quotes from being used to delimit link titles.

The link URL may, optionally, be surrounded by angle brackets:

[id]: <http://example.com/>  "Optional Title Here"

You can put the title attribute on the next line and use extra spaces or tabs for padding, which tends to look better with longer URLs:

[id]: http://example.com/longish/path/to/resource/here
    "Optional Title Here"

Link definitions are only used for creating links during Markdown processing, and are stripped from your document in the HTML output.

Link definition names may consist of letters, numbers, spaces, and punctuation -- but they are not case sensitive. E.g. these two links:

[link text][a]
[link text][A]

are equivalent.

The implicit link name shortcut allows you to omit the name of the link, in which case the link text itself is used as the name. Just use an empty set of square brackets -- e.g., to link the word "Google" to the google.com web site, you could simply write:

[Google][]

And then define the link:

[Google]: http://google.com/

Because link names may contain spaces, this shortcut even works for multiple words in the link text:

Visit [Daring Fireball][] for more information.

And then define the link:

[Daring Fireball]: http://daringfireball.net/

Link definitions can be placed anywhere in your Markdown document. I tend to put them immediately after each paragraph in which they're used, but if you want, you can put them all at the end of your document, sort of like footnotes.

Here's an example of reference links in action:

I get 10 times more traffic from [Google] [1] than from
[Yahoo] [2] or [MSN] [3].

  [1]: http://google.com/        "Google"
  [2]: http://search.yahoo.com/  "Yahoo Search"
  [3]: http://search.msn.com/    "MSN Search"

Using the implicit link name shortcut, you could instead write:

I get 10 times more traffic from [Google][] than from
[Yahoo][] or [MSN][].

  [google]: http://google.com/        "Google"
  [yahoo]:  http://search.yahoo.com/  "Yahoo Search"
  [msn]:    http://search.msn.com/    "MSN Search"

Both of the above examples will produce the following HTML output:

<p>I get 10 times more traffic from <a href="http://google.com/"
title="Google">Google</a> than from
<a href="http://search.yahoo.com/" title="Yahoo Search">Yahoo</a>
or <a href="http://search.msn.com/" title="MSN Search">MSN</a>.</p>

For comparison, here is the same paragraph written using Markdown's inline link style:

I get 10 times more traffic from [Google](http://google.com/ "Google")
than from [Yahoo](http://search.yahoo.com/ "Yahoo Search") or
[MSN](http://search.msn.com/ "MSN Search").

The point of reference-style links is not that they're easier to write. The point is that with reference-style links, your document source is vastly more readable. Compare the above examples: using reference-style links, the paragraph itself is only 81 characters long; with inline-style links, it's 176 characters; and as raw HTML, it's 234 characters. In the raw HTML, there's more markup than there is text.

With Markdown's reference-style links, a source document much more closely resembles the final output, as rendered in a browser. By allowing you to move the markup-related metadata out of the paragraph, you can add links without interrupting the narrative flow of your prose.

Emphasis

Markdown treats asterisks (*) and underscores (_) as indicators of emphasis. Text wrapped with one * or _ will be wrapped with an HTML <em> tag; double *'s or _'s will be wrapped with an HTML <strong> tag. E.g., this input:

*single asterisks*

_single underscores_

**double asterisks**

__double underscores__

will produce:

<em>single asterisks</em>

<em>single underscores</em>

<strong>double asterisks</strong>

<strong>double underscores</strong>

You can use whichever style you prefer; the lone restriction is that the same character must be used to open and close an emphasis span.

Emphasis can be used in the middle of a word:

un*frigging*believable

But if you surround an * or _ with spaces, it'll be treated as a literal asterisk or underscore.

To produce a literal asterisk or underscore at a position where it would otherwise be used as an emphasis delimiter, you can backslash escape it:

\*this text is surrounded by literal asterisks\*

Code

To indicate a span of code, wrap it with backtick quotes (`). Unlike a pre-formatted code block, a code span indicates code within a normal paragraph. For example:

Use the `printf()` function.

will produce:

<p>Use the <code>printf()</code> function.</p>

To include a literal backtick character within a code span, you can use multiple backticks as the opening and closing delimiters:

``There is a literal backtick (`) here.``

which will produce this:

<p><code>There is a literal backtick (`) here.</code></p>

The backtick delimiters surrounding a code span may include spaces -- one after the opening, one before the closing. This allows you to place literal backtick characters at the beginning or end of a code span:

A single backtick in a code span: `` ` ``

A backtick-delimited string in a code span: `` `foo` ``

will produce:

<p>A single backtick in a code span: <code>`</code></p>

<p>A backtick-delimited string in a code span: <code>`foo`</code></p>

With a code span, ampersands and angle brackets are encoded as HTML entities automatically, which makes it easy to include example HTML tags. Markdown will turn this:

Please don't use any `<blink>` tags.

into:

<p>Please don't use any <code>&lt;blink&gt;</code> tags.</p>

You can write this:

`&#8212;` is the decimal-encoded equivalent of `&mdash;`.

to produce:

<p><code>&amp;#8212;</code> is the decimal-encoded
equivalent of <code>&amp;mdash;</code>.</p>

Images

Admittedly, it's fairly difficult to devise a "natural" syntax for placing images into a plain text document format.

Markdown uses an image syntax that is intended to resemble the syntax for links, allowing for two styles: inline and reference.

Inline image syntax looks like this:

![Alt text](/path/to/img.jpg)

![Alt text](/path/to/img.jpg "Optional title")

That is:

  • An exclamation mark: !;
  • followed by a set of square brackets, containing the alt attribute text for the image;
  • followed by a set of parentheses, containing the URL or path to the image, and an optional title attribute enclosed in double or single quotes.

Reference-style image syntax looks like this:

![Alt text][id]

Where "id" is the name of a defined image reference. Image references are defined using syntax identical to link references:

[id]: url/to/image  "Optional title attribute"

As of this writing, Markdown has no syntax for specifying the dimensions of an image; if this is important to you, you can simply use regular HTML <img> tags.


Miscellaneous

Markdown supports a shortcut style for creating "automatic" links for URLs and email addresses: simply surround the URL or email address with angle brackets. What this means is that if you want to show the actual text of a URL or email address, and also have it be a clickable link, you can do this:

<http://example.com/>

Markdown will turn this into:

<a href="http://example.com/">http://example.com/</a>

Automatic links for email addresses work similarly, except that Markdown will also perform a bit of randomized decimal and hex entity-encoding to help obscure your address from address-harvesting spambots. For example, Markdown will turn this:

<address@example.com>

into something like this:

<a href="&#x6D;&#x61;i&#x6C;&#x74;&#x6F;:&#x61;&#x64;&#x64;&#x72;&#x65;
&#115;&#115;&#64;&#101;&#120;&#x61;&#109;&#x70;&#x6C;e&#x2E;&#99;&#111;
&#109;">&#x61;&#x64;&#x64;&#x72;&#x65;&#115;&#115;&#64;&#101;&#120;&#x61;
&#109;&#x70;&#x6C;e&#x2E;&#99;&#111;&#109;</a>

which will render in a browser as a clickable link to "address@example.com".

(This sort of entity-encoding trick will indeed fool many, if not most, address-harvesting bots, but it definitely won't fool all of them. It's better than nothing, but an address published in this way will probably eventually start receiving spam.)

Backslash Escapes

Markdown allows you to use backslash escapes to generate literal characters which would otherwise have special meaning in Markdown's formatting syntax. For example, if you wanted to surround a word with literal asterisks (instead of an HTML <em> tag), you can use backslashes before the asterisks, like this:

\*literal asterisks\*

Markdown provides backslash escapes for the following characters:

\   backslash
`   backtick
*   asterisk
_   underscore
{}  curly braces
[]  square brackets
()  parentheses
#   hash mark
+	plus sign
-	minus sign (hyphen)
.   dot
!   exclamation mark
Visit your freshly installed ts-website to see instructions about news system

Server Rules

In dieser Datei werden die Server Regeln eingetragen welche dann auf der Seite "rules.php" angezeigt werden. Zum Ändern muss einfach die Datei rules.md im Verzeichnis config verändert werden.


This is a dedicated file to keep your server rules. Its loaded and displayed on "rules.php" page. To change it, go to the config directory and edit file rules.md


Oto dedykowany plik na regulamin twojego Teamspeaka wyświetlany na podstronie "regulamin". Plik z regulaminem znajdziesz w folderze config pod nazwą rules.md. Edytuje się go podobnie jak newsy.


1. Definicje

  1. Teamspeak - oprogramowanie służące do komunikacji...
  2. ...

2. Postanowienia ogólne

  1. Serwer Teamspeak pod adresem "127.0.0.1" jest...
  2. ...

3. Tytuł

  1. Lista
  • Sublista
  • Sublista
  • Sublista
  1. Lista
  2. Lista

4. Tytuł

  • Lista
  • Lista
  • Lista

5. Tabela kar

Przewinienie Kara
Wulgarny nick Kick z serwera
Wulgarna nazwa kanału Usunięcie z kanału
Wyzywanie użytkowników Ban do 7 dni
Zniewaga administracji Ban permanentny
/*!
* Christmas theme for ts-website
* https://github.com/Wruczek/ts-website
* (c) Wruczek 2016 - 2018
* The MIT License
*/
body {
background-image: url(../img/christmas-bg.jpg);
}
.panel {
background-color: #410b13;
}
.table-hover > tbody > tr:hover {
background-color: #b41320
}
.table > thead > tr > td.active,
.table > tbody > tr > td.active,
.table > tfoot > tr > td.active,
.table > thead > tr > th.active,
.table > tbody > tr > th.active,
.table > tfoot > tr > th.active,
.table > thead > tr.active > td,
.table > tbody > tr.active > td,
.table > tfoot > tr.active > td,
.table > thead > tr.active > th,
.table > tbody > tr.active > th,
.table > tfoot > tr.active > th {
background-color: #a51321
}
.dropdown-menu > li > a:hover,
.dropdown-menu > li > a:focus {
background-color: #a51321
}
.navbar-default .navbar-nav > .active > a,
.navbar-default .navbar-nav > .active > a:hover,
.navbar-default .navbar-nav > .active > a:focus {
background-color: #a51321
}
@media (max-width: 767px) {
.navbar-default .navbar-nav .open .dropdown-menu > li > a:hover,
.navbar-default .navbar-nav .open .dropdown-menu > li > a:focus {
background-color: #a51321
}
.navbar-default .navbar-nav .open .dropdown-menu > .active > a,
.navbar-default .navbar-nav .open .dropdown-menu > .active > a:hover,
.navbar-default .navbar-nav .open .dropdown-menu > .active > a:focus {
background-color: #a51321
}
}
.pagination > li > a:hover,
.pagination > li > span:hover,
.pagination > li > a:focus,
.pagination > li > span:focus {
background-color: #a51321;
}
.pager li > a:hover,
.pager li > a:focus {
background-color: #a51321
}
a.list-group-item:hover,
button.list-group-item:hover,
a.list-group-item:focus,
button.list-group-item:focus {
background-color: #a51321
}
.panel-footer {
background-color: #a51321;
}
.popover-title {
background-color: #a51321;
}
.btn-default:hover {
background-color: #a51321
}
.panel-default > .panel-heading {
background-color: #a51321;
}
.modal-header,
.modal-footer {
background-color: #a51321
}
.table-bordered {
border-color: #871522;
}
.table > thead > tr > th {
background-color: #871522;
border-color: #871522;
}
.table-striped > tbody > tr:nth-of-type(odd) {
background-color: #871522;
}
.navbar-default {
background-color: #b91524 !important;
}
.navbar-default .navbar-nav > li > a:hover,
.navbar-default .navbar-nav > li > a:focus {
background-color: #9b131f
}
.navbar-default .navbar-nav > .active > a,
.navbar-default .navbar-nav > .active > a:hover,
.navbar-default .navbar-nav > .active > a:focus {
background-color: #9b131f
}
.dropdown-menu {
background-color: #410b13;
}
.navbar-default .navbar-nav > .open > a,
.navbar-default .navbar-nav > .open > a:hover,
.navbar-default .navbar-nav > .open > a:focus {
background-color: #9b131f;
}
@media (max-width: 767px) {
.navbar-default .navbar-nav .open .dropdown-menu > li > a:hover,
.navbar-default .navbar-nav .open .dropdown-menu > li > a:focus {
background-color: #9b131f
}
.navbar-default .navbar-nav .open .dropdown-menu > .active > a,
.navbar-default .navbar-nav .open .dropdown-menu > .active > a:hover,
.navbar-default .navbar-nav .open .dropdown-menu > .active > a:focus {
background-color: #9b131f
}
}
.famfamfam-flags{background:url(famfamfam-flags.png) no-repeat;display: inline-block;background-size:224px 199px}.famfamfam-flags.me{width:16px;height:12px;background-position:0 0}.famfamfam-flags.ky{width:16px;height:11px;background-position:-16px 0}.famfamfam-flags.af{width:16px;height:11px;background-position:0 -12px}.famfamfam-flags.ag{width:16px;height:11px;background-position:-16px -12px}.famfamfam-flags.ai{width:16px;height:11px;background-position:-32px 0}.famfamfam-flags.al{width:16px;height:11px;background-position:-32px -11px}.famfamfam-flags.am{width:16px;height:11px;background-position:0 -23px}.famfamfam-flags.an{width:16px;height:11px;background-position:-16px -23px}.famfamfam-flags.ao{width:16px;height:11px;background-position:-32px -23px}.famfamfam-flags.ar{width:16px;height:11px;background-position:0 -34px}.famfamfam-flags.as{width:16px;height:11px;background-position:-16px -34px}.famfamfam-flags.at{width:16px;height:11px;background-position:-32px -34px}.famfamfam-flags.au{width:16px;height:11px;background-position:-48px 0}.famfamfam-flags.aw{width:16px;height:11px;background-position:-48px -11px}.famfamfam-flags.ax{width:16px;height:11px;background-position:-48px -22px}.famfamfam-flags.az{width:16px;height:11px;background-position:-48px -33px}.famfamfam-flags.ba{width:16px;height:11px;background-position:0 -45px}.famfamfam-flags.bb{width:16px;height:11px;background-position:-16px -45px}.famfamfam-flags.bd{width:16px;height:11px;background-position:-32px -45px}.famfamfam-flags.be{width:16px;height:11px;background-position:-48px -45px}.famfamfam-flags.bf{width:16px;height:11px;background-position:-64px 0}.famfamfam-flags.bg{width:16px;height:11px;background-position:-64px -11px}.famfamfam-flags.bh{width:16px;height:11px;background-position:-64px -22px}.famfamfam-flags.bi{width:16px;height:11px;background-position:-64px -33px}.famfamfam-flags.bj{width:16px;height:11px;background-position:-64px -44px}.famfamfam-flags.bm{width:16px;height:11px;background-position:0 -56px}.famfamfam-flags.bn{width:16px;height:11px;background-position:-16px -56px}.famfamfam-flags.bo{width:16px;height:11px;background-position:-32px -56px}.famfamfam-flags.br{width:16px;height:11px;background-position:-48px -56px}.famfamfam-flags.bs{width:16px;height:11px;background-position:-64px -56px}.famfamfam-flags.bt{width:16px;height:11px;background-position:0 -67px}.famfamfam-flags.bv{width:16px;height:11px;background-position:-16px -67px}.famfamfam-flags.bw{width:16px;height:11px;background-position:-32px -67px}.famfamfam-flags.by{width:16px;height:11px;background-position:-48px -67px}.famfamfam-flags.bz{width:16px;height:11px;background-position:-64px -67px}.famfamfam-flags.ca{width:16px;height:11px;background-position:-80px 0}.famfamfam-flags.catalonia{width:16px;height:11px;background-position:-80px -11px}.famfamfam-flags.cc{width:16px;height:11px;background-position:-80px -22px}.famfamfam-flags.cd{width:16px;height:11px;background-position:-80px -33px}.famfamfam-flags.cf{width:16px;height:11px;background-position:-80px -44px}.famfamfam-flags.cg{width:16px;height:11px;background-position:-80px -55px}.famfamfam-flags.zm{width:16px;height:11px;background-position:-80px -66px}.famfamfam-flags.ci{width:16px;height:11px;background-position:0 -78px}.famfamfam-flags.ck{width:16px;height:11px;background-position:-16px -78px}.famfamfam-flags.cl{width:16px;height:11px;background-position:-32px -78px}.famfamfam-flags.cm{width:16px;height:11px;background-position:-48px -78px}.famfamfam-flags.cn{width:16px;height:11px;background-position:-64px -78px}.famfamfam-flags.co{width:16px;height:11px;background-position:-80px -78px}.famfamfam-flags.cr{width:16px;height:11px;background-position:-96px 0}.famfamfam-flags.cs{width:16px;height:11px;background-position:-96px -11px}.famfamfam-flags.cu{width:16px;height:11px;background-position:-96px -22px}.famfamfam-flags.cv{width:16px;height:11px;background-position:-96px -33px}.famfamfam-flags.cx{width:16px;height:11px;background-position:-96px -44px}.famfamfam-flags.cy{width:16px;height:11px;background-position:-96px -55px}.famfamfam-flags.cz{width:16px;height:11px;background-position:-96px -66px}.famfamfam-flags.de{width:16px;height:11px;background-position:-96px -77px}.famfamfam-flags.dj{width:16px;height:11px;background-position:0 -89px}.famfamfam-flags.dk{width:16px;height:11px;background-position:-16px -89px}.famfamfam-flags.dm{width:16px;height:11px;background-position:-32px -89px}.famfamfam-flags.do{width:16px;height:11px;background-position:-48px -89px}.famfamfam-flags.dz{width:16px;height:11px;background-position:-64px -89px}.famfamfam-flags.ec{width:16px;height:11px;background-position:-80px -89px}.famfamfam-flags.ee{width:16px;height:11px;background-position:-96px -89px}.famfamfam-flags.eg{width:16px;height:11px;background-position:0 -100px}.famfamfam-flags.eh{width:16px;height:11px;background-position:-16px -100px}.famfamfam-flags.england{width:16px;height:11px;background-position:-32px -100px}.famfamfam-flags.er{width:16px;height:11px;background-position:-48px -100px}.famfamfam-flags.es{width:16px;height:11px;background-position:-64px -100px}.famfamfam-flags.et{width:16px;height:11px;background-position:-80px -100px}.famfamfam-flags.europeanunion{width:16px;height:11px;background-position:-96px -100px}.famfamfam-flags.fam{width:16px;height:11px;background-position:-112px 0}.famfamfam-flags.fi{width:16px;height:11px;background-position:-112px -11px}.famfamfam-flags.fj{width:16px;height:11px;background-position:-112px -22px}.famfamfam-flags.fk{width:16px;height:11px;background-position:-112px -33px}.famfamfam-flags.fm{width:16px;height:11px;background-position:-112px -44px}.famfamfam-flags.fo{width:16px;height:11px;background-position:-112px -55px}.famfamfam-flags.fr,.famfamfam-flags.gp,.famfamfam-flags.mf,.famfamfam-flags.re,.famfamfam-flags.yt{width:16px;height:11px;background-position:-112px -66px}.famfamfam-flags.ga{width:16px;height:11px;background-position:-112px -77px}.famfamfam-flags.gb{width:16px;height:11px;background-position:-112px -88px}.famfamfam-flags.gd{width:16px;height:11px;background-position:-112px -99px}.famfamfam-flags.ge{width:16px;height:11px;background-position:0 -111px}.famfamfam-flags.gf{width:16px;height:11px;background-position:-16px -111px}.famfamfam-flags.gg{width:16px;height:11px;background-position:-32px -111px}.famfamfam-flags.gh{width:16px;height:11px;background-position:-48px -111px}.famfamfam-flags.gi{width:16px;height:11px;background-position:-64px -111px}.famfamfam-flags.gl{width:16px;height:11px;background-position:-80px -111px}.famfamfam-flags.gm{width:16px;height:11px;background-position:-96px -111px}.famfamfam-flags.gn{width:16px;height:11px;background-position:-112px -111px}.famfamfam-flags.gp{width:16px;height:11px;background-position:-128px 0}.famfamfam-flags.gq{width:16px;height:11px;background-position:-128px -11px}.famfamfam-flags.gr{width:16px;height:11px;background-position:-128px -22px}.famfamfam-flags.gs{width:16px;height:11px;background-position:-128px -33px}.famfamfam-flags.gt{width:16px;height:11px;background-position:-128px -44px}.famfamfam-flags.gu{width:16px;height:11px;background-position:-128px -55px}.famfamfam-flags.gw{width:16px;height:11px;background-position:-128px -66px}.famfamfam-flags.gy{width:16px;height:11px;background-position:-128px -77px}.famfamfam-flags.hk{width:16px;height:11px;background-position:-128px -88px}.famfamfam-flags.hm{width:16px;height:11px;background-position:-128px -99px}.famfamfam-flags.hn{width:16px;height:11px;background-position:-128px -110px}.famfamfam-flags.hr{width:16px;height:11px;background-position:0 -122px}.famfamfam-flags.ht{width:16px;height:11px;background-position:-16px -122px}.famfamfam-flags.hu{width:16px;height:11px;background-position:-32px -122px}.famfamfam-flags.id{width:16px;height:11px;background-position:-48px -122px}.famfamfam-flags.ie{width:16px;height:11px;background-position:-64px -122px}.famfamfam-flags.il{width:16px;height:11px;background-position:-80px -122px}.famfamfam-flags.in{width:16px;height:11px;background-position:-96px -122px}.famfamfam-flags.io{width:16px;height:11px;background-position:-112px -122px}.famfamfam-flags.iq{width:16px;height:11px;background-position:-128px -122px}.famfamfam-flags.ir{width:16px;height:11px;background-position:0 -133px}.famfamfam-flags.is{width:16px;height:11px;background-position:-16px -133px}.famfamfam-flags.it{width:16px;height:11px;background-position:-32px -133px}.famfamfam-flags.je{width:16px;height:11px;background-position:-48px -133px}.famfamfam-flags.jm{width:16px;height:11px;background-position:-64px -133px}.famfamfam-flags.jo{width:16px;height:11px;background-position:-80px -133px}.famfamfam-flags.jp{width:16px;height:11px;background-position:-96px -133px}.famfamfam-flags.ke{width:16px;height:11px;background-position:-112px -133px}.famfamfam-flags.kg{width:16px;height:11px;background-position:-128px -133px}.famfamfam-flags.kh{width:16px;height:11px;background-position:-144px 0}.famfamfam-flags.ki{width:16px;height:11px;background-position:-144px -11px}.famfamfam-flags.km{width:16px;height:11px;background-position:-144px -22px}.famfamfam-flags.kn{width:16px;height:11px;background-position:-144px -33px}.famfamfam-flags.kp{width:16px;height:11px;background-position:-144px -44px}.famfamfam-flags.kr{width:16px;height:11px;background-position:-144px -55px}.famfamfam-flags.kw{width:16px;height:11px;background-position:-144px -66px}.famfamfam-flags.ae{width:16px;height:11px;background-position:-144px -77px}.famfamfam-flags.kz{width:16px;height:11px;background-position:-144px -88px}.famfamfam-flags.la{width:16px;height:11px;background-position:-144px -99px}.famfamfam-flags.lb{width:16px;height:11px;background-position:-144px -110px}.famfamfam-flags.lc{width:16px;height:11px;background-position:-144px -121px}.famfamfam-flags.li{width:16px;height:11px;background-position:-144px -132px}.famfamfam-flags.lk{width:16px;height:11px;background-position:0 -144px}.famfamfam-flags.lr{width:16px;height:11px;background-position:-16px -144px}.famfamfam-flags.ls{width:16px;height:11px;background-position:-32px -144px}.famfamfam-flags.lt{width:16px;height:11px;background-position:-48px -144px}.famfamfam-flags.lu{width:16px;height:11px;background-position:-64px -144px}.famfamfam-flags.lv{width:16px;height:11px;background-position:-80px -144px}.famfamfam-flags.ly{width:16px;height:11px;background-position:-96px -144px}.famfamfam-flags.ma{width:16px;height:11px;background-position:-112px -144px}.famfamfam-flags.mc{width:16px;height:11px;background-position:-128px -144px}.famfamfam-flags.md{width:16px;height:11px;background-position:-144px -144px}.famfamfam-flags.ad{width:16px;height:11px;background-position:-160px 0}.famfamfam-flags.mg{width:16px;height:11px;background-position:-160px -11px}.famfamfam-flags.mh{width:16px;height:11px;background-position:-160px -22px}.famfamfam-flags.mk{width:16px;height:11px;background-position:-160px -33px}.famfamfam-flags.ml{width:16px;height:11px;background-position:-160px -44px}.famfamfam-flags.mm{width:16px;height:11px;background-position:-160px -55px}.famfamfam-flags.mn{width:16px;height:11px;background-position:-160px -66px}.famfamfam-flags.mo{width:16px;height:11px;background-position:-160px -77px}.famfamfam-flags.mp{width:16px;height:11px;background-position:-160px -88px}.famfamfam-flags.mq{width:16px;height:11px;background-position:-160px -99px}.famfamfam-flags.mr{width:16px;height:11px;background-position:-160px -110px}.famfamfam-flags.ms{width:16px;height:11px;background-position:-160px -121px}.famfamfam-flags.mt{width:16px;height:11px;background-position:-160px -132px}.famfamfam-flags.mu{width:16px;height:11px;background-position:-160px -143px}.famfamfam-flags.mv{width:16px;height:11px;background-position:0 -155px}.famfamfam-flags.mw{width:16px;height:11px;background-position:-16px -155px}.famfamfam-flags.mx{width:16px;height:11px;background-position:-32px -155px}.famfamfam-flags.my{width:16px;height:11px;background-position:-48px -155px}.famfamfam-flags.mz{width:16px;height:11px;background-position:-64px -155px}.famfamfam-flags.na{width:16px;height:11px;background-position:-80px -155px}.famfamfam-flags.nc{width:16px;height:11px;background-position:-96px -155px}.famfamfam-flags.ne{width:16px;height:11px;background-position:-112px -155px}.famfamfam-flags.nf{width:16px;height:11px;background-position:-128px -155px}.famfamfam-flags.ng{width:16px;height:11px;background-position:-144px -155px}.famfamfam-flags.ni{width:16px;height:11px;background-position:-160px -155px}.famfamfam-flags.bq,.famfamfam-flags.nl{width:16px;height:11px;background-position:-176px 0}.famfamfam-flags.no{width:16px;height:11px;background-position:-176px -11px}.famfamfam-flags.za{width:16px;height:11px;background-position:-176px -22px}.famfamfam-flags.nr{width:16px;height:11px;background-position:-176px -33px}.famfamfam-flags.nu{width:16px;height:11px;background-position:-176px -44px}.famfamfam-flags.nz{width:16px;height:11px;background-position:-176px -55px}.famfamfam-flags.om{width:16px;height:11px;background-position:-176px -66px}.famfamfam-flags.pa{width:16px;height:11px;background-position:-176px -77px}.famfamfam-flags.pe{width:16px;height:11px;background-position:-176px -88px}.famfamfam-flags.pf{width:16px;height:11px;background-position:-176px -99px}.famfamfam-flags.pg{width:16px;height:11px;background-position:-176px -110px}.famfamfam-flags.ph{width:16px;height:11px;background-position:-176px -121px}.famfamfam-flags.pk{width:16px;height:11px;background-position:-176px -132px}.famfamfam-flags.pl{width:16px;height:11px;background-position:-176px -143px}.famfamfam-flags.pm{width:16px;height:11px;background-position:-176px -154px}.famfamfam-flags.pn{width:16px;height:11px;background-position:0 -166px}.famfamfam-flags.pr{width:16px;height:11px;background-position:-16px -166px}.famfamfam-flags.ps{width:16px;height:11px;background-position:-32px -166px}.famfamfam-flags.pt{width:16px;height:11px;background-position:-48px -166px}.famfamfam-flags.pw{width:16px;height:11px;background-position:-64px -166px}.famfamfam-flags.py{width:16px;height:11px;background-position:-80px -166px}.famfamfam-flags.qa{width:16px;height:11px;background-position:-96px -166px}.famfamfam-flags.re{width:16px;height:11px;background-position:-112px -166px}.famfamfam-flags.ro{width:16px;height:11px;background-position:-128px -166px}.famfamfam-flags.rs{width:16px;height:11px;background-position:-144px -166px}.famfamfam-flags.ru{width:16px;height:11px;background-position:-160px -166px}.famfamfam-flags.rw{width:16px;height:11px;background-position:-176px -166px}.famfamfam-flags.sa{width:16px;height:11px;background-position:0 -177px}.famfamfam-flags.sb{width:16px;height:11px;background-position:-16px -177px}.famfamfam-flags.sc{width:16px;height:11px;background-position:-32px -177px}.famfamfam-flags.scotland{width:16px;height:11px;background-position:-48px -177px}.famfamfam-flags.sd{width:16px;height:11px;background-position:-64px -177px}.famfamfam-flags.se{width:16px;height:11px;background-position:-80px -177px}.famfamfam-flags.sg{width:16px;height:11px;background-position:-96px -177px}.famfamfam-flags.sh{width:16px;height:11px;background-position:-112px -177px}.famfamfam-flags.si{width:16px;height:11px;background-position:-128px -177px}.famfamfam-flags.sj{width:16px;height:11px;background-position:-144px -177px}.famfamfam-flags.sk{width:16px;height:11px;background-position:-160px -177px}.famfamfam-flags.sl{width:16px;height:11px;background-position:-176px -177px}.famfamfam-flags.sm{width:16px;height:11px;background-position:-192px 0}.famfamfam-flags.sn{width:16px;height:11px;background-position:-192px -11px}.famfamfam-flags.so{width:16px;height:11px;background-position:-192px -22px}.famfamfam-flags.sr{width:16px;height:11px;background-position:-192px -33px}.famfamfam-flags.st{width:16px;height:11px;background-position:-192px -44px}.famfamfam-flags.sv{width:16px;height:11px;background-position:-192px -55px}.famfamfam-flags.sy{width:16px;height:11px;background-position:-192px -66px}.famfamfam-flags.sz{width:16px;height:11px;background-position:-192px -77px}.famfamfam-flags.tc{width:16px;height:11px;background-position:-192px -88px}.famfamfam-flags.td{width:16px;height:11px;background-position:-192px -99px}.famfamfam-flags.tf{width:16px;height:11px;background-position:-192px -110px}.famfamfam-flags.tg{width:16px;height:11px;background-position:-192px -121px}.famfamfam-flags.th{width:16px;height:11px;background-position:-192px -132px}.famfamfam-flags.tj{width:16px;height:11px;background-position:-192px -143px}.famfamfam-flags.tk{width:16px;height:11px;background-position:-192px -154px}.famfamfam-flags.tl{width:16px;height:11px;background-position:-192px -165px}.famfamfam-flags.tm{width:16px;height:11px;background-position:-192px -176px}.famfamfam-flags.tn{width:16px;height:11px;background-position:0 -188px}.famfamfam-flags.to{width:16px;height:11px;background-position:-16px -188px}.famfamfam-flags.tr{width:16px;height:11px;background-position:-32px -188px}.famfamfam-flags.tt{width:16px;height:11px;background-position:-48px -188px}.famfamfam-flags.tv{width:16px;height:11px;background-position:-64px -188px}.famfamfam-flags.tw{width:16px;height:11px;background-position:-80px -188px}.famfamfam-flags.tz{width:16px;height:11px;background-position:-96px -188px}.famfamfam-flags.ua{width:16px;height:11px;background-position:-112px -188px}.famfamfam-flags.ug{width:16px;height:11px;background-position:-128px -188px}.famfamfam-flags.um{width:16px;height:11px;background-position:-144px -188px}.famfamfam-flags.us{width:16px;height:11px;background-position:-160px -188px}.famfamfam-flags.uy{width:16px;height:11px;background-position:-176px -188px}.famfamfam-flags.uz{width:16px;height:11px;background-position:-192px -188px}.famfamfam-flags.va{width:16px;height:11px;background-position:-208px 0}.famfamfam-flags.vc{width:16px;height:11px;background-position:-208px -11px}.famfamfam-flags.ve{width:16px;height:11px;background-position:-208px -22px}.famfamfam-flags.vg{width:16px;height:11px;background-position:-208px -33px}.famfamfam-flags.vi{width:16px;height:11px;background-position:-208px -44px}.famfamfam-flags.vn{width:16px;height:11px;background-position:-208px -55px}.famfamfam-flags.vu{width:16px;height:11px;background-position:-208px -66px}.famfamfam-flags.wales{width:16px;height:11px;background-position:-208px -77px}.famfamfam-flags.wf{width:16px;height:11px;background-position:-208px -88px}.famfamfam-flags.ws{width:16px;height:11px;background-position:-208px -99px}.famfamfam-flags.ye{width:16px;height:11px;background-position:-208px -110px}.famfamfam-flags.yt{width:16px;height:11px;background-position:-208px -121px}.famfamfam-flags.zw{width:16px;height:11px;background-position:-208px -132px}.famfamfam-flags.ch{width:11px;height:11px;background-position:-208px -143px}.famfamfam-flags.np{width:9px;height:11px;background-position:-208px -154px}
/*!
* bootswatch v3.3.6
* Homepage: http://bootswatch.com
* Copyright 2012-2016 Thomas Park
* Licensed under MIT
* Based on Bootstrap
*/
/*!
* Bootstrap v3.3.6 (http://getbootstrap.com)
* Copyright 2011-2015 Twitter, Inc.
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
*/
.navbar {
min-height: 50px
}
.navbar-brand {
padding: 14.5px 15px;
height: 50px
}
.navbar-toggle {
margin-top: 8px;
margin-bottom: 8px
}
.navbar-nav {
margin: 0px -15px 0px 0px
}
@media (min-width: 768px) {
.navbar-nav > li > a {
padding-top: 14.5px;
padding-bottom: 14.5px;
}
}
.navbar-form {
margin-top: 3.5px;
margin-bottom: 3.5px;
}
.navbar-btn {
margin-top: 3.5px;
margin-bottom: 3.5px;
}
.navbar-btn.btn-sm {
margin-top: 9.5px;
margin-bottom: 9.5px;
}
.navbar-btn.btn-xs {
margin-top: 14px;
margin-bottom: 14px;
}
.navbar-text {
margin-top: 14.5px;
margin-bottom: 14.5px;
}
.navbar .dropdown-menu > li > a {
font-size: 14px;
}
.fa {
margin-right: 5px
}
.icon-smaller {
font-size: 0.7em
}
a {
transition: color 500ms ease-out
}
.news-header {
font-size: 1.4em;
text-align: center
}
.news-author {
font-size: 0.7em;
text-align: right
}
.pull-right .fa {
margin-right: 0
}
p, a {
overflow-wrap: break-word;
word-wrap: break-word
}
/* Force 16px icon size after TeamSpeak update 3.1.5 */
.ts3_viewer img, .adminlist img {
max-height: 16px;
max-width: 16px
}
/* ****** */
/* STATUS */
/* ****** */
.serverstatus p, .serverstatus .label .fa {
margin: 0
}
.serverstatus a, .serverstatus span {
float: right
}
/* ********* */
/* ADMINLIST */
/* ********* */
.adminlist > .groupname ~ .groupname {
margin-top: 15px
}
.adminlist .groupname {
text-align: center;
font-size: 1.2em;
border-bottom: 1px solid #677481;
margin-bottom: 5px
}
.adminlist .label-primary {
background-color: #375a7f
}
.adminlist p {
margin: 0
}
.adminlist img {
margin-right: 3px
}
.adminlist .iconspacer {
margin-left: 19px
}
/* ****** */
/* NAVBAR */
/* ****** */
body {
padding-top: 80px
}
.navbar {
font-size: 14px
}
.nav > li > a {
padding-left: 10px;
padding-right: 10px
}
.navbar-brand {
padding: 0 10px 0 0;
display: flex;
align-items: center
}
.navbar-brand > img {
height: 100%;
padding: 5px 5px 5px 15px
}
/* ****** */
/* FOOTER */
/* ****** */
body {
position: relative;
margin: 0;
padding-bottom: 120px;
min-height: 100vh
}
@media (max-width: 380px) {
body {
padding-bottom: 150px
}
}
.footer {
position: absolute;
right: 0;
bottom: 0;
left: 0;
padding: 10px
}
.footer .pull-right p {
margin: 0 0 0 0;
font-size: 0.8em;
text-align: right
}
/*!
* Stylesheet kindly donated by NothingTV from https://flamespersecond.de/
* Edited by Wruczek
* The MIT License
*/
body {
background: url(../img/bg.png) no-repeat fixed center;
background-size: cover;
}
.navbar-default {
background-color: #055157 !important;
}
.btn-dark {
background-color: #4e5d6c;
}
.text-muted {
color: #00343f
}
abbr[data-original-title] {
border-bottom: 1px dotted #00343f
}
blockquote {
border-left: 5px solid #00343f
}
blockquote.pull-right {
border-right: 5px solid #00343f;
}
caption {
color: #00343f;
}
.table > tfoot > tr > td {
border-top: 1px solid #00343f
}
.table > thead > tr > th {
border-bottom: 2px solid #00343f
}
.table > tbody + tbody {
border-top: 2px solid #00343f
}
.table-bordered {
border: 1px solid #00343f
}
.table-bordered > tfoot > tr > td {
border: 1px solid #00343f
}
.table-striped > tbody > tr:nth-of-type(odd) {
background-color: #00343f
}
.table-hover > tbody > tr:hover {
background-color: #004449
}
.table > thead > tr > td.active,
.table > tbody > tr > td.active,
.table > tfoot > tr > td.active,
.table > thead > tr > th.active,
.table > tbody > tr > th.active,
.table > tfoot > tr > th.active,
.table > thead > tr.active > td,
.table > tbody > tr.active > td,
.table > tfoot > tr.active > td,
.table > thead > tr.active > th,
.table > tbody > tr.active > th,
.table > tfoot > tr.active > th {
background-color: #004449
}
@media screen and (max-width: 767px) {
.table-responsive {
border: 1px solid #00343f
}
}
legend {
border-bottom: 1px solid #00343f
}
.btn-default {
background-color: #00343f;
}
.btn-default.disabled:hover,
.btn-default[disabled]:hover,
fieldset[disabled] .btn-default:hover,
.btn-default.disabled:focus,
.btn-default[disabled]:focus,
fieldset[disabled] .btn-default:focus,
.btn-default.disabled.focus,
.btn-default[disabled].focus,
fieldset[disabled] .btn-default.focus {
background-color: #00343f;
}
.btn-default .badge {
color: #00343f;
}
fieldset[disabled] .btn-link:focus {
color: #00343f;
}
.dropdown-menu {
background-color: #00343f;
}
.dropdown-menu > li > a:hover,
.dropdown-menu > li > a:focus {
background-color: #004449
}
.input-group-addon {
background-color: #00343f;
}
.nav > li > a:focus {
background-color: #00343f
}
.nav > li.disabled > a {
color: #00343f
}
.nav > li.disabled > a:hover,
.nav > li.disabled > a:focus {
color: #00343f;
}
.nav .open > a,
.nav .open > a:hover,
.nav .open > a:focus {
background-color: #00343f;
}
.nav-tabs > li > a:hover {
border-color: #00343f #00343f transparent
}
.nav-tabs > li.active > a:focus {
border: 1px solid #00343f;
}
.nav-tabs > li.active > a,
.nav-tabs > li.active > a:hover,
.nav-tabs > li.active > a:focus {
border: 1px solid #00343f;
}
@media (min-width: 768px) {
.nav-tabs.nav-justified > li > a {
border-bottom: 1px solid #00343f;
}
.nav-tabs.nav-justified > .active > a,
.nav-tabs.nav-justified > .active > a:hover,
.nav-tabs.nav-justified > .active > a:focus {
border-bottom-color: #00343f
}
}
.nav-tabs-justified > .active > a,
.nav-tabs-justified > .active > a:hover,
.nav-tabs-justified > .active > a:focus {
border: 1px solid #00343f
}
@media (min-width: 768px) {
.nav-tabs-justified > li > a {
border-bottom: 1px solid #00343f;
}
.nav-tabs-justified > .active > a,
.nav-tabs-justified > .active > a:hover,
.nav-tabs-justified > .active > a:focus {
border-bottom-color: #00343f
}
}
.navbar-default {
background-color: #00343f;
}
.navbar-default .navbar-nav > li > a:hover,
.navbar-default .navbar-nav > li > a:focus {
background-color: #083d48
}
.navbar-default .navbar-nav > .active > a,
.navbar-default .navbar-nav > .active > a:hover,
.navbar-default .navbar-nav > .active > a:focus {
background-color: #004449
}
@media (max-width: 767px) {
.navbar-default .navbar-nav .open .dropdown-menu > li > a:hover,
.navbar-default .navbar-nav .open .dropdown-menu > li > a:focus {
background-color: #004449
}
.navbar-default .navbar-nav .open .dropdown-menu > .active > a,
.navbar-default .navbar-nav .open .dropdown-menu > .active > a:hover,
.navbar-default .navbar-nav .open .dropdown-menu > .active > a:focus {
background-color: #004449
}
}
.breadcrumb {
background-color: #00343f;
}
.pagination > li > a,
.pagination > li > span {
background-color: #00343f;
}
.pagination > li > a:hover,
.pagination > li > span:hover,
.pagination > li > a:focus,
.pagination > li > span:focus {
background-color: #004449;
}
.pagination > .disabled > a:focus {
background-color: #00343f;
}
.pager li > a,
.pager li > span {
background-color: #00343f;
}
.pager li > a:hover,
.pager li > a:focus {
background-color: #004449
}
.pager .disabled > a,
.pager .disabled > a:hover,
.pager .disabled > a:focus,
.pager .disabled > span {
background-color: #00343f;
}
.label-default {
background-color: #00343f
}
.badge {
background-color: #00343f;
}
.jumbotron {
background-color: #00343f
}
.progress {
background-color: #00343f;
}
.list-group-item {
background-color: #00343f;
}
a.list-group-item:hover,
button.list-group-item:hover,
a.list-group-item:focus,
button.list-group-item:focus {
background-color: #004449
}
.list-group-item.disabled,
.list-group-item.disabled:hover,
.list-group-item.disabled:focus {
color: #00343f;
}
.list-group-item.disabled .list-group-item-text,
.list-group-item.disabled:hover .list-group-item-text,
.list-group-item.disabled:focus .list-group-item-text {
color: #00343f
}
.panel {
background-color: #00343f;
}
.panel-footer {
background-color: #004449;
}
.panel > .panel-body + .table,
.panel > .panel-body + .table-responsive,
.panel > .table + .panel-body,
.panel > .table-responsive + .panel-body {
border-top: 1px solid #00343f
}
.panel-success > .panel-heading {
color: #13ddcd;
}
.panel-info > .panel-heading {
color: #13ddcd;
}
.panel-warning > .panel-heading {
color: #13ddcd;
}
.well {
background-color: #00343f;
}
.modal-content {
background-color: #00343f;
}
.popover {
background-color: #00343f;
}
.popover-title {
background-color: #004449;
}
.popover.top > .arrow:after {
border-top-color: #00343f
}
.popover.right > .arrow:after {
border-right-color: #00343f
}
.popover.bottom > .arrow:after {
border-bottom-color: #00343f
}
.popover.left > .arrow:after {
border-left-color: #00343f;
}
.navbar-default .badge {
color: #00343f
}
.btn-default:hover {
background-color: #004449
}
.page-header {
border-bottom-color: #00343f
}
table .text-muted,
.table .text-muted {
color: #00343f
}
.panel-default > .panel-heading {
background-color: #004449;
}
.thumbnail {
background-color: #00343f
}
.modal-header,
.modal-footer {
background-color: #004449
}
<!DOCTYPE html>
<html lang="pl">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="author" content="Wruczek">
<title>403 - Forbidden</title>
<!-- Icon -->
<link rel="shortcut icon" href="../img/icon/icon-64.png">
<!-- Bootswatch -->
<link href="https://cdnjs.cloudflare.com/ajax/libs/bootswatch/3.3.7/superhero/bootstrap.min.css" rel="stylesheet">
<style>
.container {
display: table;
position: absolute;
height: 100%;
width: 100%;
}
.text-center {
display: table-cell;
vertical-align: middle;
}
</style>
</head>
<body>
<div class="container">
<div class="text-center">
<h1>403 <span style="font-size: 32px;color: #9E9E9E">forbidden</span></h1>
<h3>Access to this page is forbidden.</h3>
<br>
<a href="." class="btn btn-primary btn-lg">&larr;&nbsp;&nbsp;&nbsp;Go back</a>
</div>
</div>
</body>
</html>
<!DOCTYPE html>
<html lang="pl">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="author" content="Wruczek">
<title>404 - Not found</title>
<!-- Icon -->
<link rel="shortcut icon" href="../img/icon/icon-64.png">
<!-- Bootswatch -->
<link href="https://cdnjs.cloudflare.com/ajax/libs/bootswatch/3.3.7/superhero/bootstrap.min.css" rel="stylesheet">
<style>
.container {
display: table;
position: absolute;
height: 100%;
width: 100%;
}
.text-center {
display: table-cell;
vertical-align: middle;
}
</style>
</head>
<body>
<div class="container">
<div class="text-center">
<h1>404 <span style="font-size: 32px;color: #9E9E9E">page not found</span></h1>
<h3>We couldn't find what you were looking for.</h3>
<br>
<a href="." class="btn btn-primary btn-lg">&larr;&nbsp;&nbsp;&nbsp;Go back</a>
</div>
</div>
</body>
</html>
<!DOCTYPE html>
<html lang="pl">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="author" content="Wruczek">
<title>500 - Server Error</title>
<!-- Icon -->
<link rel="shortcut icon" href="../img/icon/icon-64.png">
<!-- Bootswatch -->
<link href="https://cdnjs.cloudflare.com/ajax/libs/bootswatch/3.3.7/superhero/bootstrap.min.css" rel="stylesheet">
<style>
.container {
display: table;
position: absolute;
height: 100%;
width: 100%;
}
.text-center {
display: table-cell;
vertical-align: middle;
}
</style>
</head>
<body>
<div class="container">
<div class="text-center">
<h1>500 <span style="font-size: 32px;color: #9E9E9E">server error</span></h1>
<h3>Something went wrong. Try again later.</h3>
<br>
<a href="." class="btn btn-primary btn-lg">&larr;&nbsp;&nbsp;&nbsp;Go back</a>
</div>
</div>
</body>
</html>
<?php
require_once __DIR__ . "/tsutils.php";
require_once __DIR__ . "/cacheutils.class.php";
$cacheutils = new CacheUtils('adminlist');
if($cacheutils->isExpired()) {
$cacheutils->setValue([getAdminList(), date('d.m.Y H:i:s')], 120);
}
$adminlist = $cacheutils->getValue();
// FUNCTIONS
function getAdminList() {
global $config;
global $lang;
$admingroups = $config["adminlist"];
$localIcons = array(100, 200, 300, 400, 500, 600);
try {
$tsAdmin = getTeamspeakConnection();
$output = "";
foreach ($admingroups as $group) {
if (!array_key_exists((string)$group, $tsAdmin->serverGroupList()))
continue;
$group = $tsAdmin->serverGroupGetById($group);
$icon = '';
if ($group["iconid"]) {
if (!$group->iconIsLocal("iconid")) {
$groupicon = getGroupIcon($tsAdmin, $group);
if ($groupicon) {
$icon = '<img src="data:' . TeamSpeak3_Helper_Convert::imageMimeType($groupicon) . ';base64,' . base64_encode($groupicon) . '" alt="Group icon" /> ';
}
} elseif (in_array($group["iconid"], $localIcons)) {
$icon = '<img src="lib/ts3phpframework/images/viewer/group_icon_' . $group["iconid"] . '.png" alt="Group icon" /> ';
}
}
$output .= "<p class=\"groupname\">$icon$group</p>";
$clients = $group->clientList();
if (empty($clients)) {
$output .= '<p class="text-center"><i>' . translate($lang["adminlist"]["emptygroup"]) . '</i></p>';
continue;
}
$onlineClients = [];
$offlineClients = [];
foreach ($clients as $userInfo) {
$user = getClientByDbid($tsAdmin, $userInfo['cldbid']);
if($user["client_type"]) continue;
if (!$user) {
$offlineClients[] = '<p><span class="label label-primary iconspacer">' . htmlspecialchars($userInfo['client_nickname']) . '</span><span class="label label-danger pull-right">' . translate($lang["adminlist"]["status"]["offline"]) . '</span></p>';
continue;
}
$onlineClients[] = '<p><img src="lib/ts3phpframework/images/viewer/' . $user->getIcon() . '.png" alt="User status">' . '<span class="label label-primary">' . htmlspecialchars($user) . '</span>' . ($user['client_away'] ? '<span class="label label-warning pull-right">' . translate($lang["adminlist"]["status"]["away"]) . '</span>' : '<span class="label label-success pull-right">' . translate($lang["adminlist"]["status"]["online"]) . '</span>') . '</p>';
}
foreach (array_merge($onlineClients, $offlineClients) as $str)
$output .= $str;
}
return $output;
} catch (TeamSpeak3_Exception $e) {
return '<div class="alert alert-danger"><p class="text-center">' . translate($lang["general"]["scripterror"], [$e->getCode(), $e->getMessage()]) . '</p></div>';
}
}
function getClientByDbid($tsAdmin, $cldbid) {
try {
return $tsAdmin->clientGetByDbid($cldbid);
} catch (TeamSpeak3_Exception $e) {
return false;
}
}
function getGroupIcon($tsAdmin, $group) {
try {
return $group->iconDownload();
} catch (TeamSpeak3_Exception $e) {
return false;
}
}
// echo getAdminList();
<?php
require_once __DIR__ . "/../lib/phpfastcache/src/autoload.php";
require_once __DIR__ . "/../config/config.php";
use phpFastCache\CacheManager;
use phpFastCache\Util\Languages;
class CacheUtils {
private $devMode;
private $cacheInstance;
private $cacheItem;
private $key;
public function __construct($key) {
// If devMode is set, the cache will be invalidated immediately
$this->devMode = defined("DEV_MODE") || getenv("DEV_MODE") || file_exists(__DIR__ . "/dev_mode");
if(!is_string($key))
throw new InvalidArgumentException("Key must be a string");
global $config;
if(isset($config["general"]["timezone"])) {
date_default_timezone_set($config["general"]["timezone"]);
}
$this->cacheInstance = CacheManager::getInstance('Files', ["path" => __DIR__ . '/../cache']);
Languages::setEncoding();
$this->cacheItem = $this->cacheInstance->getItem($key);
$this->key = $key;
}
public function getCacheInstance() {
return $this->cacheInstance;
}
public function getCacheItem() {
return $this->cacheItem;
}
public function getValue() {
return $this->cacheItem->get();
}
public function setValue($value, $expireTime) {
if($this->devMode)
$expireTime = 1;
$this->cacheItem = $this->cacheItem->set($value)->expiresAfter($expireTime);
$this->cacheInstance->save($this->cacheItem);
}
public function isExpired() {
return $this->devMode || !$this->cacheItem->isHit();
}
public function remove() {
$this->cacheInstance->deleteItem($this->key);
}
}
<?php
$start = microtime(true);
require_once __DIR__ . "/../include/modulecheck.php";
require_once __DIR__ . "/../config/config.php";
require_once __DIR__ . "/../include/language.php";
require_once __DIR__ . "/../include/adminlist.php";
$htalink = $config["general"]["enablehta"] ? "" : ".php";
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="<?php echo $config["general"]["desc"]; ?>">
<meta name="author" content="Wruczek and contributors">
<title><?php echo $config["general"]["title"] . $config["general"]["subtitle"]; ?></title>
<!-- Icon -->
<link rel="shortcut icon" href="img/icon/icon-64.png">
<!-- Bootswatch -->
<link href="https://cdnjs.cloudflare.com/ajax/libs/bootswatch/3.3.7/superhero/bootstrap.min.css" rel="stylesheet">
<link href="css/theme.css" rel="stylesheet">
<!-- Font Awesome -->
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet">
<?php if(isset($bansPage)) { ?>
<!-- DataTables for Bootstrap -->
<link href="https://cdnjs.cloudflare.com/ajax/libs/datatables/1.10.12/css/dataTables.bootstrap.min.css" rel="stylesheet">
<?php } ?>
<link href="css/flags/famfamfam-flags.min.css" rel="stylesheet">
<!-- Custom CSS -->
<link href="css/navbar.css" rel="stylesheet">
<link href="css/style.css" rel="stylesheet">
<?php if(!empty($config["general"]["christmasmode"])) { ?>
<script src="js/christmas.js"></script>
<?php } ?>
<script src="api/i18n.php"></script>
<!--[if IE]>
<script src="https://cdnjs.cloudflare.com/ajax/libs/html5shiv/3.7.3/html5shiv.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body>
<nav class="navbar navbar-default navbar-fixed-top">
<div class="container">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
<span class="sr-only"><?php tl($lang["navbar"]["navigation"]); ?></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="."><img style="width: 64px;" src="img/icon/icon-64.png" alt="Site logo"><?php echo $config["general"]["title"]; ?></a>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav">
<li><a href="viewer<?php echo $htalink ?>"><i class="fa fa-eye" aria-hidden="true"></i> <?php tl($lang["navbar"]["viewer"]); ?></a></li>
<li><a href="bans<?php echo $htalink ?>"><i class="fa fa-ban" aria-hidden="true"></i> <?php tl($lang["navbar"]["bans"]); ?></a></li>
<li><a href="rules<?php echo $htalink ?>"><i class="fa fa-book" aria-hidden="true"></i> <?php tl($lang["navbar"]["rules"]); ?></a></li>
<!-- I don't have time for this.
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false"><i class="fa fa-television" aria-hidden="true"></i></i>Ranking <span class="caret"></span></a>
<ul class="dropdown-menu">
<li><a href="#"><i class="fa fa-clock-o" aria-hidden="true"></i>Ranking Aktywności</a></li>
<li><a href="#"><i class="fa fa-sign-in" aria-hidden="true"></i>Ranking Połaczeń</a></li>
<li><a href="#"><i class="fa fa-sign-out" aria-hidden="true"></i>Ranking Połączenia</a></li>
</ul>
</li>
-->
</ul>
<ul class="nav navbar-nav navbar-right">
<?php foreach ($config["navlinks"] as $navlink) {
$icon = $navlink[0];
$text = $navlink[1];
$link = $navlink[2]; ?>
<li><a href="<?php echo $link; ?>"><i class="fa <?php echo $icon; ?>" aria-hidden="true"></i> <?php echo $text; ?></a></li>
<?php } ?>
<li data-toggle="tooltip" data-placement="bottom" title="<?php tl($lang["navbar"]["connecttooltip"], [$config['teamspeak']['displayip']]); ?>"><a href="ts3server://<?php echo $config['teamspeak']['displayip']; ?>"><i class="fa fa-sign-in" aria-hidden="true"></i><?php tl($lang["navbar"]["connect"]); ?></a></li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false"><i class="famfamfam-flags <?php echo $langcode == "en" ? "gb" : $langcode; ?>" aria-hidden="true"></i> Language <span class="caret"></span></a>
<ul class="dropdown-menu">
<!-- Languages are sorted by number of total users in millions in all countries, based on ethnologue.com and Wikipedia -->
<li><a href="?lang=en"><i class="famfamfam-flags gb" aria-hidden="true"></i> English</a></li> <!-- English : 1010 -->
<li><a href="?lang=es"><i class="famfamfam-flags es" aria-hidden="true"></i> Español</a></li> <!-- Spanish : 528 -->
<li><a href="?lang=ru"><i class="famfamfam-flags ru" aria-hidden="true"></i> Русский</a></li> <!-- Russian : 268 -->
<li><a href="?lang=br"><i class="famfamfam-flags br" aria-hidden="true"></i> Português</a></li> <!-- Portuguese : 229,945 -->
<li><a href="?lang=fr"><i class="famfamfam-flags fr" aria-hidden="true"></i> Français</a></li> <!-- French : 229,582 -->
<li><a href="?lang=de"><i class="famfamfam-flags de" aria-hidden="true"></i> Deutsch</a></li> <!-- German : 130 -->
<li><a href="?lang=tr"><i class="famfamfam-flags tr" aria-hidden="true"></i> Türkçe</a></li> <!-- Turkish : 71 -->
<li><a href="?lang=it"><i class="famfamfam-flags it" aria-hidden="true"></i> Italiano</a></li> <!-- Italian : 66 -->
<li><a href="?lang=pl"><i class="famfamfam-flags pl" aria-hidden="true"></i> Polski</a></li> <!-- Polish : 41 -->
<li><a href="?lang=ua"><i class="famfamfam-flags ua" aria-hidden="true"></i> Українська</a></li> <!-- Ukrainian : 35 -->
<li><a href="?lang=nl"><i class="famfamfam-flags nl" aria-hidden="true"></i> Nederlands</a></li> <!-- Dutch : 22 -->
<li><a href="?lang=cz"><i class="famfamfam-flags cz" aria-hidden="true"></i> Česky</a></li> <!-- Czech : 13,217 -->
<li><a href="?lang=gr"><i class="famfamfam-flags gr" aria-hidden="true"></i> Ελληνικά</a></li> <!-- Greek : 13,134 -->
<li><a href="?lang=hu"><i class="famfamfam-flags hu" aria-hidden="true"></i> Magyar</a></li> <!-- Hungarian : 13 -->
<li><a href="?lang=se"><i class="famfamfam-flags se" aria-hidden="true"></i> Svenska</a></li> <!-- Swedish : 12 -->
<li><a href="?lang=bg"><i class="famfamfam-flags bg" aria-hidden="true"></i> български</a></li> <!-- Bulgarian : 8 -->
<li><a href="?lang=da"><i class="famfamfam-flags dk" aria-hidden="true"></i> Dansk</a></li> <!-- Danish : 6 -->
<li><a href="?lang=by"><i class="famfamfam-flags by" aria-hidden="true"></i> Беларуская мова</a></li> <!-- Belarusian : 3 -->
</ul>
</li>
</ul>
</div>
<!-- /.navbar-collapse -->
</div>
<!-- /.container-fluid -->
</nav>
<div class="container">
<div class="row">
<div class="col-md-3 col-md-push-9">
<div class="panel panel-default">
<div class="panel-heading"><i class="fa fa-bar-chart" aria-hidden="true"></i> <?php tl($lang["serverstatus"]["title"]); ?></div>
<div class="panel-body">
<div class="serverstatus">
<p><i class="fa fa-globe fa-fw" aria-hidden="true"></i> <?php tl($lang["serverstatus"]["address"]); ?>: <a href="ts3server://<?php echo $config['teamspeak']['displayip']; ?>"><?php echo $config['teamspeak']['displayip']; ?></a></p>
<div id="serverstatus">
<div class="text-center">
<i class="fa fa-refresh fa-spin fa-3x fa-fw"></i>
<span class="sr-only"><?php tl($lang["serverstatus"]["loading"]); ?></span>
</div>
</div>
</div>
</div>
</div>
<div class="panel panel-default">
<div class="panel-heading"><i class="fa fa-shield" aria-hidden="true"></i> <?php tl($lang["adminlist"]["title"]); ?> <span class="pull-right"><i class="fa fa-question-circle" aria-hidden="true" data-toggle="tooltip" data-placement="bottom" title="<?php tl($lang["adminlist"]["lastupdate"], [$adminlist[1]]); ?>"></i></span></div>
<div class="panel-body adminlist">
<?php echo $adminlist[0]; ?>
</div>
</div>
<?php if(!empty($config['contact']['items'])) { ?>
<div class="panel panel-default">
<div class="panel-heading"><i class="fa fa-envelope" aria-hidden="true"></i> <?php echo $config['contact']['title']; ?></div>
<div class="panel-body">
<ul class="list-unstyled">
<?php foreach ($config['contact']['items'] as $item) {
$name = $item[0];
$linkdesc = $item[1];
$link = $item[2];
echo '<li>' . $name . ' <span class="pull-right"><a href="' . $link . '">' . $linkdesc . '</a></span></li>';
} ?>
</ul>
</div>
</div>
<?php } ?>
<div class="panel panel-default">
<div class="panel-heading"><i class="fa fa-eye" aria-hidden="true"></i> <?php tl($lang["svpb"]["title"]); ?></div>
<div class="panel-body">
<a href="viewer<?php echo $htalink ?>" class="btn btn-primary btn-lg btn-block"><i class="fa fa-eye" aria-hidden="true"></i> <?php tl($lang["svpb"]["takealook"]); ?></a>
</div>
</div>
</div>
<div class="col-md-9 col-md-pull-3">
<?php
session_start();
header('Cache-control: private');
if (isset($_GET['lang'])) {
$langcode = $_GET['lang'];
$_SESSION['lang'] = $langcode;
setcookie('lang', $langcode, time() + (3600 * 24 * 60));
header("Location: {$_SERVER['PHP_SELF']}");
} else if (isset($_SESSION['lang'])) {
$langcode = $_SESSION['lang'];
} else if (isset($_COOKIE['lang'])) {
$langcode = $_COOKIE['lang'];
} else if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
$langcode = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2);
} else {
$langcode = "en";
}
if (!file_exists(getLanguagePath($langcode)))
$langcode = "en";
require_once getLanguagePath($langcode);
function getLanguagePath($langcode) {
return __DIR__ . '/../config/languages/lang.' . $langcode . '.php';
}
function tl($pattern, $args = null) {
echo translate($pattern, $args);
}
function translate($pattern, $args = null) {
if (!$args) {
return $pattern;
}
$size = count($args);
for ($i = 0; $i < $size; $i++) {
$pattern = str_ireplace('{' . $i . '}', $args[$i], $pattern);
}
return $pattern;
}
<?php
if (!defined("PHP_VERSION_ID") || PHP_VERSION_ID < 50500) {
$title = 'Unsupported PHP version';
$text =
'<p>You are using old, unsupported PHP version.</p>' .
'<p>Your PHP version: <b>' . PHP_VERSION . '</b>, required PHP version: <b>5.5.0</b>.</p>' .
'<p>Please update your PHP installation and try again.</p>';
showError($title, $text);
exit;
}
if (!function_exists("utf8_encode")) {
showExtensionMissingError("xml");
exit;
}
if (!extension_loaded("json")) {
showExtensionMissingError("json");
exit;
}
if (!extension_loaded("mbstring")) {
showExtensionMissingError("mbstring");
exit;
}
if((fileperms(__DIR__ . '/../cache') & 0777) !== 0777) {
$title = 'Cache directory is not writable';
$text =
'<p>Please make sure that the <code>cache</code> directory is fully readable, writable and executable.</p>' .
'<p>Running: <code>sudo chmod 777 -R ' . realpath(__DIR__ . '/../cache') . '</code> should fix the problem.</p>';
showError($title, $text);
exit;
}
if (!file_exists(__DIR__ . "/../config/config.php")) {
$title = 'config.php does not exists';
$text =
'<p>Please go into the directory <code>config</code> and rename <code>config.template.php</code> to <code>config.php</code>.</p>' .
'<p>Edit the new file and tweak it to suite your needs.</p>';
showError($title, $text);
exit;
}
// FUNCTION
function showExtensionMissingError($extension_name) {
$title = 'Required extension "' . $extension_name . '" is missing';
$text =
'<p>Required PHP extension <code>' . $extension_name . '</code> is missing or is not loaded.</p>' .
'<p>Install it and restart your server. Usually running <code>sudo apt-get install php-' . $extension_name . '</code> should be enough.</p>' .
'<p>If you still get this error, try restarting your web server and <code>php-fpm</code> service or just reboot your machine</p>' .
'<p>If you are using Web Hosting service, please contact their support for instructions on enabling <code>' . $extension_name . '</code> extension</p>';
showError($title, $text);
}
function showError($title, $text) { ?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="author" content="Wruczek">
<title><?php echo $title ?></title>
<!-- Icon -->
<link rel="shortcut icon" href="https://assets-cdn.github.com/images/icons/emoji/unicode/26a0.png">
<!-- Twitter Bootstrap -->
<link href="https://cdnjs.cloudflare.com/ajax/libs/bootswatch/3.3.7/superhero/bootstrap.min.css" rel="stylesheet">
<!--[if IE]>
<script src="https://cdnjs.cloudflare.com/ajax/libs/html5shiv/3.7.3/html5shiv.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->
<style>
body { margin-top: 70px }
</style>
</head>
<body>
<div class="container">
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title"><img src="https://assets-cdn.github.com/images/icons/emoji/unicode/26a0.png" width="20px" alt="Error"> <?php echo $title ?></h3>
</div>
<div class="panel-body">
<?php echo $text ?>
</div>
<div class="panel-footer">
&copy; <a href="https://wruczek.tech">Wruczek</a> 2016 - 2018 | <a href="https://github.com/Wruczek/ts-website">ts-website</a> v 1.4.5 | MIT License
</div>
</div>
</div>
<!-- /container -->
</body>
</html>
<?php }
<?php
require_once __DIR__ . '/../config/config.php';
require_once __DIR__ . "/../lib/ts3phpframework/libraries/TeamSpeak3/TeamSpeak3.php";
function pingTeamspeakServerFromConfig() {
return pingTeamspeakServer(getTeamspeakConnection("?use_offline_as_virtual=1&no_query_clients=1"));
}
function pingTeamspeakServer() {
try {
$tsAdmin = getTeamspeakConnection();
if ($tsAdmin->isOffline())
throw new Exception("Server is offline");
return $tsAdmin->getInfo();
} catch (TeamSpeak3_Exception $e) {
return false;
}
}
function getTeamspeakConnection($arguments = '') {
try {
global $config;
$host = $config['teamspeak']['host'];
$login = $config['teamspeak']['login'];
$passwd = $config['teamspeak']['password'];
$sport = $config['teamspeak']['server_port'];
$qport = $config['teamspeak']['query_port'];
$tsNodeHost = TeamSpeak3::factory("serverquery://$host:$qport/$arguments");
$tsNodeHost->login($login, $passwd);
return $tsNodeHost->serverGetByPort($sport);
} catch (Exception $e) {
throw $e;
}
}
<?php
require_once dirname(__FILE__) . "/include/modulecheck.php";
require_once __DIR__ . "/include/header.php";
require_once __DIR__ . "/lib/parsedown/parsedown.php";
?>
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title news-header"><i class="fa fa-newspaper-o" aria-hidden="true"></i> <?php tl($lang["index"]["title"]); ?></h3>
</div>
</div>
<!-- NEWSY -->
<?php
$parsedown = new Parsedown();
$path = __DIR__ . "/" . $config["general"]["newsDir"];
if (file_exists($path))
showNews($path);
else
echo '<div class="alert alert-danger"><p class="text-center">' . translate($lang["index"]["errortitle"]) . '</p><p class="text-center">' . translate($lang["index"]["errorsubtitle"]) . '</p></div>';
// *******
// METHODS
// *******
function showNews($path) {
global $parsedown;
$files = array_diff(scandir($path), array('..', '.'));
foreach ($files as $newsFile) {
if (!endsWith($newsFile, ".md"))
continue;
$file = readFileContent($path . "/" . $newsFile);
$lines = explode("\n", $file);
$title = $lines[0];
$author = $lines[1];
$text = implode("\n", array_slice($lines, 3));
generateNewsBox($title, $author, $parsedown->text($text));
}
}
function generateNewsBox($title, $author, $text) { ?>
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title"><div class="row"><div class="col-md-8"><i class="fa fa-info-circle" aria-hidden="true"></i> <?php echo $title; ?></div><div class="col-md-4 news-author"><i class="fa fa-user" aria-hidden="true"></i> <?php echo $author; ?></div></div></h3>
</div>
<div class="panel-body news-body">
<?php echo $text; ?>
</div>
</div>
<?php }
function readFileContent($file) {
$fopen = @fopen($file, "r");
if (!$fopen) return false;
$text = fread($fopen, filesize($file));
fclose($fopen);
return $text;
}
function endsWith($haystack, $needle) {
return $needle === "" || (($temp = strlen($haystack) - strlen($needle)) >= 0 && strpos($haystack, $needle, $temp) !== false);
}
require_once __DIR__ . "/include/footer.php";
?>
$(document).ready(function () {
$('#banlist').dataTable({
"order": [[3, "desc"]],
"language": {
"url": datatablesUrl
}
});
});
// Remember: This file is loaded before jQuery!
// Check if the current month on user device is December...
if (new Date().getMonth() === 11) {
// Enable the christmas functions! Happy holidays from Wruczek! :D
// Load and enable the christmas theme
var stylesheet = document.createElement('link');
stylesheet.href = 'css/christmas-theme.css';
stylesheet.rel = 'stylesheet';
document.head.appendChild(stylesheet);
// Load and enable the snow
var script = document.createElement('script');
script.src = 'https://cdnjs.cloudflare.com/ajax/libs/JQuery-Snowfall/1.7.4/snowfall.min.js';
document.head.appendChild(script);
window.addEventListener('load', function () {
// Change background artist in the footer
document.getElementById('background-artist').innerHTML = '<a href="http://www.publicdomainpictures.net/view-image.php?image=28562&picture=christmas-bulbs-red-background">Debi Geroux - Public Domain</a>';
if(getCookie('snoweffect') === 'false') {
document.getElementById('website-copyright').innerHTML += ' &mdash; <a class="disableSnowLink" href="#" onclick="enableSnowEffect()">Enable snow effect</a>';
return;
}
// Add a link to disable the effect
document.getElementById('website-copyright').innerHTML += ' &mdash; <a class="disableSnowLink" href="#" onclick="disableSnowEffect()">Disable snow effect</a>';
// Add the snow effect
snowFall.snow(document.body, {
flakeCount: (document.body.clientWidth > 992 ? 500 : 100),
flakeIndex: -1,
minSize: 4,
maxSize: 5,
minSpeed: 1,
maxSpeed: 2,
round: true,
shadow: true
});
});
}
function disableSnowEffect() {
setCookie('snoweffect', 'false', 30);
location.reload();
}
function enableSnowEffect() {
setCookie('snoweffect', 'true', 30);
location.reload();
}
function setCookie(cname,cvalue,exdays) {
var d = new Date();
d.setTime(d.getTime() + (exdays*24*60*60*1000));
var expires = "expires=" + d.toGMTString();
document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/";
}
function getCookie(cname) {
var name = cname + "=";
var ca = document.cookie.split(';');
for(var i = 0; i < ca.length; i++) {
var c = ca[i];
while (c.charAt(0) == ' ') {
c = c.substring(1);
}
if (c.indexOf(name) == 0) {
return c.substring(name.length, c.length);
}
}
return "";
}
$(document).ready(function () {
"use strict";
// Bootstrap tooltips initialization
$('[data-toggle="tooltip"]').tooltip({
"html": true
});
// Add "Show more" button to news panels
$('.news-body').readmore({
speed: 500,
collapsedHeight: 300,
moreLink: '<button type="button" class="btn btn-dark"><i class="fa fa-plus-circle" aria-hidden="true"></i> ' + textShowMore + '</button>',
lessLink: '<button type="button" class="btn btn-dark"><i class="fa fa-minus-circle" aria-hidden="true"></i> ' + textShowLess + '</button>'
});
});
$(document).ready(function () {
checkStatus();
var intervalid = setInterval(function () {
checkStatus();
}, 10 * 1000);
});
function checkStatus() {
$.ajax({
url: apiurl,
success: function (json) {
json = json.tsstatus;
var result = "";
if (json.success) {
var clientsonline = json.clientsonline;
var maxclients = json.maxclients;
var clientsprecent = Math.round(json.clientsonline * 100 / json.maxclients);
var version = json.version;
var platform = json.platform;
var uptime = json.uptime;
var averagePacketloss = Math.round(json.averagePacketloss * 100) / 100;
var averagePing = Math.round(json.averagePing * 100) / 100;
var platformIcon = '<i class="fa %s fa-fw" title="' + platform + '" aria-hidden="true"></i>';
switch (platform.toLowerCase()) {
case "windows":
platformIcon = platformIcon.replace(/%s/, 'fa-windows');
break;
case "linux":
platformIcon = platformIcon.replace(/%s/, 'fa-linux');
break;
case "os x":
case "macos":
platformIcon = platformIcon.replace(/%s/, 'fa-apple');
break;
default:
platformIcon = platform;
}
result =
'<p><i class="fa fa-power-off fa-fw" aria-hidden="true"></i> ' + statusOnline + ': <span class="label label-success">' + clientsonline + ' / ' + maxclients + ' (' + clientsprecent + '%)</span></p>' +
'<p><i class="fa fa-clock-o fa-fw" aria-hidden="true"></i> ' + statusUptime + ': <span class="label label-success">' + uptime + '</span></p>' +
'<p><i class="fa fa-info-circle fa-fw" aria-hidden="true"></i> ' + statusVersion + ': <span class="label label-success">' + version + ' on ' + platformIcon + '</span></p>' +
'<p><i class="fa fa-signal fa-fw" aria-hidden="true"></i> ' + statusAvgping + ': <span class="label label-success">' + averagePing + ' ms</span></p>' +
'<p><i class="fa fa-bolt fa-fw" aria-hidden="true"></i> ' + statusAvgpl + ': <span class="label label-success">' + averagePacketloss + '%</span></p>';
} else {
result = '<p><i class="fa fa-power-off fa-fw" aria-hidden="true"></i> Online: <span class="label label-danger">' + statusOffline + '</span></p>';
}
$("#serverstatus").html(result);
},
error: function (result) {
$("#serverstatus").html('<p><i class="fa fa-power-off fa-fw" aria-hidden="true"></i> ' + statusOnline + ': <span class="label label-danger">ERROR</span></p>');
}
})
}
<?php
#
#
# Parsedown
# http://parsedown.org
#
# (c) Emanuil Rusev
# http://erusev.com
#
# For the full license information, view the LICENSE file that was distributed
# with this source code.
#
#
class Parsedown
{
# ~
const version = '1.6.0';
# ~
function text($text)
{
# make sure no definitions are set
$this->DefinitionData = array();
# standardize line breaks
$text = str_replace(array("\r\n", "\r"), "\n", $text);
# remove surrounding line breaks
$text = trim($text, "\n");
# split text into lines
$lines = explode("\n", $text);
# iterate through lines to identify blocks
$markup = $this->lines($lines);
# trim line breaks
$markup = trim($markup, "\n");
return $markup;
}
#
# Setters
#
function setBreaksEnabled($breaksEnabled)
{
$this->breaksEnabled = $breaksEnabled;
return $this;
}
protected $breaksEnabled;
function setMarkupEscaped($markupEscaped)
{
$this->markupEscaped = $markupEscaped;
return $this;
}
protected $markupEscaped;
function setUrlsLinked($urlsLinked)
{
$this->urlsLinked = $urlsLinked;
return $this;
}
protected $urlsLinked = true;
#
# Lines
#
protected $BlockTypes = array(
'#' => array('Header'),
'*' => array('Rule', 'List'),
'+' => array('List'),
'-' => array('SetextHeader', 'Table', 'Rule', 'List'),
'0' => array('List'),
'1' => array('List'),
'2' => array('List'),
'3' => array('List'),
'4' => array('List'),
'5' => array('List'),
'6' => array('List'),
'7' => array('List'),
'8' => array('List'),
'9' => array('List'),
':' => array('Table'),
'<' => array('Comment', 'Markup'),
'=' => array('SetextHeader'),
'>' => array('Quote'),
'[' => array('Reference'),
'_' => array('Rule'),
'`' => array('FencedCode'),
'|' => array('Table'),
'~' => array('FencedCode'),
);
# ~
protected $unmarkedBlockTypes = array(
'Code',
);
#
# Blocks
#
protected function lines(array $lines)
{
$CurrentBlock = null;
foreach ($lines as $line)
{
if (chop($line) === '')
{
if (isset($CurrentBlock))
{
$CurrentBlock['interrupted'] = true;
}
continue;
}
if (strpos($line, "\t") !== false)
{
$parts = explode("\t", $line);
$line = $parts[0];
unset($parts[0]);
foreach ($parts as $part)
{
$shortage = 4 - mb_strlen($line, 'utf-8') % 4;
$line .= str_repeat(' ', $shortage);
$line .= $part;
}
}
$indent = 0;
while (isset($line[$indent]) and $line[$indent] === ' ')
{
$indent ++;
}
$text = $indent > 0 ? substr($line, $indent) : $line;
# ~
$Line = array('body' => $line, 'indent' => $indent, 'text' => $text);
# ~
if (isset($CurrentBlock['continuable']))
{
$Block = $this->{'block'.$CurrentBlock['type'].'Continue'}($Line, $CurrentBlock);
if (isset($Block))
{
$CurrentBlock = $Block;
continue;
}
else
{
if ($this->isBlockCompletable($CurrentBlock['type']))
{
$CurrentBlock = $this->{'block'.$CurrentBlock['type'].'Complete'}($CurrentBlock);
}
}
}
# ~
$marker = $text[0];
# ~
$blockTypes = $this->unmarkedBlockTypes;
if (isset($this->BlockTypes[$marker]))
{
foreach ($this->BlockTypes[$marker] as $blockType)
{
$blockTypes []= $blockType;
}
}
#
# ~
foreach ($blockTypes as $blockType)
{
$Block = $this->{'block'.$blockType}($Line, $CurrentBlock);
if (isset($Block))
{
$Block['type'] = $blockType;
if ( ! isset($Block['identified']))
{
$Blocks []= $CurrentBlock;
$Block['identified'] = true;
}
if ($this->isBlockContinuable($blockType))
{
$Block['continuable'] = true;
}
$CurrentBlock = $Block;
continue 2;
}
}
# ~
if (isset($CurrentBlock) and ! isset($CurrentBlock['type']) and ! isset($CurrentBlock['interrupted']))
{
$CurrentBlock['element']['text'] .= "\n".$text;
}
else
{
$Blocks []= $CurrentBlock;
$CurrentBlock = $this->paragraph($Line);
$CurrentBlock['identified'] = true;
}
}
# ~
if (isset($CurrentBlock['continuable']) and $this->isBlockCompletable($CurrentBlock['type']))
{
$CurrentBlock = $this->{'block'.$CurrentBlock['type'].'Complete'}($CurrentBlock);
}
# ~
$Blocks []= $CurrentBlock;
unset($Blocks[0]);
# ~
$markup = '';
foreach ($Blocks as $Block)
{
if (isset($Block['hidden']))
{
continue;
}
$markup .= "\n";
$markup .= isset($Block['markup']) ? $Block['markup'] : $this->element($Block['element']);
}
$markup .= "\n";
# ~
return $markup;
}
protected function isBlockContinuable($Type)
{
return method_exists($this, 'block'.$Type.'Continue');
}
protected function isBlockCompletable($Type)
{
return method_exists($this, 'block'.$Type.'Complete');
}
#
# Code
protected function blockCode($Line, $Block = null)
{
if (isset($Block) and ! isset($Block['type']) and ! isset($Block['interrupted']))
{
return;
}
if ($Line['indent'] >= 4)
{
$text = substr($Line['body'], 4);
$Block = array(
'element' => array(
'name' => 'pre',
'handler' => 'element',
'text' => array(
'name' => 'code',
'text' => $text,
),
),
);
return $Block;
}
}
protected function blockCodeContinue($Line, $Block)
{
if ($Line['indent'] >= 4)
{
if (isset($Block['interrupted']))
{
$Block['element']['text']['text'] .= "\n";
unset($Block['interrupted']);
}
$Block['element']['text']['text'] .= "\n";
$text = substr($Line['body'], 4);
$Block['element']['text']['text'] .= $text;
return $Block;
}
}
protected function blockCodeComplete($Block)
{
$text = $Block['element']['text']['text'];
$text = htmlspecialchars($text, ENT_NOQUOTES, 'UTF-8');
$Block['element']['text']['text'] = $text;
return $Block;
}
#
# Comment
protected function blockComment($Line)
{
if ($this->markupEscaped)
{
return;
}
if (isset($Line['text'][3]) and $Line['text'][3] === '-' and $Line['text'][2] === '-' and $Line['text'][1] === '!')
{
$Block = array(
'markup' => $Line['body'],
);
if (preg_match('/-->$/', $Line['text']))
{
$Block['closed'] = true;
}
return $Block;
}
}
protected function blockCommentContinue($Line, array $Block)
{
if (isset($Block['closed']))
{
return;
}
$Block['markup'] .= "\n" . $Line['body'];
if (preg_match('/-->$/', $Line['text']))
{
$Block['closed'] = true;
}
return $Block;
}
#
# Fenced Code
protected function blockFencedCode($Line)
{
if (preg_match('/^['.$Line['text'][0].']{3,}[ ]*([\w-]+)?[ ]*$/', $Line['text'], $matches))
{
$Element = array(
'name' => 'code',
'text' => '',
);
if (isset($matches[1]))
{
$class = 'language-'.$matches[1];
$Element['attributes'] = array(
'class' => $class,
);
}
$Block = array(
'char' => $Line['text'][0],
'element' => array(
'name' => 'pre',
'handler' => 'element',
'text' => $Element,
),
);
return $Block;
}
}
protected function blockFencedCodeContinue($Line, $Block)
{
if (isset($Block['complete']))
{
return;
}
if (isset($Block['interrupted']))
{
$Block['element']['text']['text'] .= "\n";
unset($Block['interrupted']);
}
if (preg_match('/^'.$Block['char'].'{3,}[ ]*$/', $Line['text']))
{
$Block['element']['text']['text'] = substr($Block['element']['text']['text'], 1);
$Block['complete'] = true;
return $Block;
}
$Block['element']['text']['text'] .= "\n".$Line['body'];;
return $Block;
}
protected function blockFencedCodeComplete($Block)
{
$text = $Block['element']['text']['text'];
$text = htmlspecialchars($text, ENT_NOQUOTES, 'UTF-8');
$Block['element']['text']['text'] = $text;
return $Block;
}
#
# Header
protected function blockHeader($Line)
{
if (isset($Line['text'][1]))
{
$level = 1;
while (isset($Line['text'][$level]) and $Line['text'][$level] === '#')
{
$level ++;
}
if ($level > 6)
{
return;
}
$text = trim($Line['text'], '# ');
$Block = array(
'element' => array(
'name' => 'h' . min(6, $level),
'text' => $text,
'handler' => 'line',
),
);
return $Block;
}
}
#
# List
protected function blockList($Line)
{
list($name, $pattern) = $Line['text'][0] <= '-' ? array('ul', '[*+-]') : array('ol', '[0-9]+[.]');
if (preg_match('/^('.$pattern.'[ ]+)(.*)/', $Line['text'], $matches))
{
$Block = array(
'indent' => $Line['indent'],
'pattern' => $pattern,
'element' => array(
'name' => $name,
'handler' => 'elements',
),
);
if($name === 'ol')
{
$listStart = stristr($matches[0], '.', true);
if($listStart !== '1')
{
$Block['element']['attributes'] = array('start' => $listStart);
}
}
$Block['li'] = array(
'name' => 'li',
'handler' => 'li',
'text' => array(
$matches[2],
),
);
$Block['element']['text'] []= & $Block['li'];
return $Block;
}
}
protected function blockListContinue($Line, array $Block)
{
if ($Block['indent'] === $Line['indent'] and preg_match('/^'.$Block['pattern'].'(?:[ ]+(.*)|$)/', $Line['text'], $matches))
{
if (isset($Block['interrupted']))
{
$Block['li']['text'] []= '';
unset($Block['interrupted']);
}
unset($Block['li']);
$text = isset($matches[1]) ? $matches[1] : '';
$Block['li'] = array(
'name' => 'li',
'handler' => 'li',
'text' => array(
$text,
),
);
$Block['element']['text'] []= & $Block['li'];
return $Block;
}
if ($Line['text'][0] === '[' and $this->blockReference($Line))
{
return $Block;
}
if ( ! isset($Block['interrupted']))
{
$text = preg_replace('/^[ ]{0,4}/', '', $Line['body']);
$Block['li']['text'] []= $text;
return $Block;
}
if ($Line['indent'] > 0)
{
$Block['li']['text'] []= '';
$text = preg_replace('/^[ ]{0,4}/', '', $Line['body']);
$Block['li']['text'] []= $text;
unset($Block['interrupted']);
return $Block;
}
}
#
# Quote
protected function blockQuote($Line)
{
if (preg_match('/^>[ ]?(.*)/', $Line['text'], $matches))
{
$Block = array(
'element' => array(
'name' => 'blockquote',
'handler' => 'lines',
'text' => (array) $matches[1],
),
);
return $Block;
}
}
protected function blockQuoteContinue($Line, array $Block)
{
if ($Line['text'][0] === '>' and preg_match('/^>[ ]?(.*)/', $Line['text'], $matches))
{
if (isset($Block['interrupted']))
{
$Block['element']['text'] []= '';
unset($Block['interrupted']);
}
$Block['element']['text'] []= $matches[1];
return $Block;
}
if ( ! isset($Block['interrupted']))
{
$Block['element']['text'] []= $Line['text'];
return $Block;
}
}
#
# Rule
protected function blockRule($Line)
{
if (preg_match('/^(['.$Line['text'][0].'])([ ]*\1){2,}[ ]*$/', $Line['text']))
{
$Block = array(
'element' => array(
'name' => 'hr'
),
);
return $Block;
}
}
#
# Setext
protected function blockSetextHeader($Line, array $Block = null)
{
if ( ! isset($Block) or isset($Block['type']) or isset($Block['interrupted']))
{
return;
}
if (chop($Line['text'], $Line['text'][0]) === '')
{
$Block['element']['name'] = $Line['text'][0] === '=' ? 'h1' : 'h2';
return $Block;
}
}
#
# Markup
protected function blockMarkup($Line)
{
if ($this->markupEscaped)
{
return;
}
if (preg_match('/^<(\w*)(?:[ ]*'.$this->regexHtmlAttribute.')*[ ]*(\/)?>/', $Line['text'], $matches))
{
$element = strtolower($matches[1]);
if (in_array($element, $this->textLevelElements))
{
return;
}
$Block = array(
'name' => $matches[1],
'depth' => 0,
'markup' => $Line['text'],
);
$length = strlen($matches[0]);
$remainder = substr($Line['text'], $length);
if (trim($remainder) === '')
{
if (isset($matches[2]) or in_array($matches[1], $this->voidElements))
{
$Block['closed'] = true;
$Block['void'] = true;
}
}
else
{
if (isset($matches[2]) or in_array($matches[1], $this->voidElements))
{
return;
}
if (preg_match('/<\/'.$matches[1].'>[ ]*$/i', $remainder))
{
$Block['closed'] = true;
}
}
return $Block;
}
}
protected function blockMarkupContinue($Line, array $Block)
{
if (isset($Block['closed']))
{
return;
}
if (preg_match('/^<'.$Block['name'].'(?:[ ]*'.$this->regexHtmlAttribute.')*[ ]*>/i', $Line['text'])) # open
{
$Block['depth'] ++;
}
if (preg_match('/(.*?)<\/'.$Block['name'].'>[ ]*$/i', $Line['text'], $matches)) # close
{
if ($Block['depth'] > 0)
{
$Block['depth'] --;
}
else
{
$Block['closed'] = true;
}
}
if (isset($Block['interrupted']))
{
$Block['markup'] .= "\n";
unset($Block['interrupted']);
}
$Block['markup'] .= "\n".$Line['body'];
return $Block;
}
#
# Reference
protected function blockReference($Line)
{
if (preg_match('/^\[(.+?)\]:[ ]*<?(\S+?)>?(?:[ ]+["\'(](.+)["\')])?[ ]*$/', $Line['text'], $matches))
{
$id = strtolower($matches[1]);
$Data = array(
'url' => $matches[2],
'title' => null,
);
if (isset($matches[3]))
{
$Data['title'] = $matches[3];
}
$this->DefinitionData['Reference'][$id] = $Data;
$Block = array(
'hidden' => true,
);
return $Block;
}
}
#
# Table
protected function blockTable($Line, array $Block = null)
{
if ( ! isset($Block) or isset($Block['type']) or isset($Block['interrupted']))
{
return;
}
if (strpos($Block['element']['text'], '|') !== false and chop($Line['text'], ' -:|') === '')
{
$alignments = array();
$divider = $Line['text'];
$divider = trim($divider);
$divider = trim($divider, '|');
$dividerCells = explode('|', $divider);
foreach ($dividerCells as $dividerCell)
{
$dividerCell = trim($dividerCell);
if ($dividerCell === '')
{
continue;
}
$alignment = null;
if ($dividerCell[0] === ':')
{
$alignment = 'left';
}
if (substr($dividerCell, - 1) === ':')
{
$alignment = $alignment === 'left' ? 'center' : 'right';
}
$alignments []= $alignment;
}
# ~
$HeaderElements = array();
$header = $Block['element']['text'];
$header = trim($header);
$header = trim($header, '|');
$headerCells = explode('|', $header);
foreach ($headerCells as $index => $headerCell)
{
$headerCell = trim($headerCell);
$HeaderElement = array(
'name' => 'th',
'text' => $headerCell,
'handler' => 'line',
);
if (isset($alignments[$index]))
{
$alignment = $alignments[$index];
$HeaderElement['attributes'] = array(
'style' => 'text-align: '.$alignment.';',
);
}
$HeaderElements []= $HeaderElement;
}
# ~
$Block = array(
'alignments' => $alignments,
'identified' => true,
'element' => array(
'name' => 'table',
'handler' => 'elements',
'attributes' => array(
'class' => 'table table-bordered table-hover table-responsive'
),
),
);
$Block['element']['text'] []= array(
'name' => 'thead',
'handler' => 'elements',
);
$Block['element']['text'] []= array(
'name' => 'tbody',
'handler' => 'elements',
'text' => array(),
);
$Block['element']['text'][0]['text'] []= array(
'name' => 'tr',
'handler' => 'elements',
'text' => $HeaderElements,
);
return $Block;
}
}
protected function blockTableContinue($Line, array $Block)
{
if (isset($Block['interrupted']))
{
return;
}
if ($Line['text'][0] === '|' or strpos($Line['text'], '|'))
{
$Elements = array();
$row = $Line['text'];
$row = trim($row);
$row = trim($row, '|');
preg_match_all('/(?:(\\\\[|])|[^|`]|`[^`]+`|`)+/', $row, $matches);
foreach ($matches[0] as $index => $cell)
{
$cell = trim($cell);
$Element = array(
'name' => 'td',
'handler' => 'line',
'text' => $cell,
);
if (isset($Block['alignments'][$index]))
{
$Element['attributes'] = array(
'style' => 'text-align: '.$Block['alignments'][$index].';',
);
}
$Elements []= $Element;
}
$Element = array(
'name' => 'tr',
'handler' => 'elements',
'text' => $Elements,
);
$Block['element']['text'][1]['text'] []= $Element;
return $Block;
}
}
#
# ~
#
protected function paragraph($Line)
{
$Block = array(
'element' => array(
'name' => 'p',
'text' => $Line['text'],
'handler' => 'line',
),
);
return $Block;
}
#
# Inline Elements
#
protected $InlineTypes = array(
'"' => array('SpecialCharacter'),
'!' => array('Image'),
'&' => array('SpecialCharacter'),
'*' => array('Emphasis'),
':' => array('Url'),
'<' => array('UrlTag', 'EmailTag', 'Markup', 'SpecialCharacter'),
'>' => array('SpecialCharacter'),
'[' => array('Link'),
'_' => array('Emphasis'),
'`' => array('Code'),
'~' => array('Strikethrough'),
'\\' => array('EscapeSequence'),
);
# ~
protected $inlineMarkerList = '!"*_&[:<>`~\\';
#
# ~
#
public function line($text)
{
$markup = '';
# $excerpt is based on the first occurrence of a marker
while ($excerpt = strpbrk($text, $this->inlineMarkerList))
{
$marker = $excerpt[0];
$markerPosition = strpos($text, $marker);
$Excerpt = array('text' => $excerpt, 'context' => $text);
foreach ($this->InlineTypes[$marker] as $inlineType)
{
$Inline = $this->{'inline'.$inlineType}($Excerpt);
if ( ! isset($Inline))
{
continue;
}
# makes sure that the inline belongs to "our" marker
if (isset($Inline['position']) and $Inline['position'] > $markerPosition)
{
continue;
}
# sets a default inline position
if ( ! isset($Inline['position']))
{
$Inline['position'] = $markerPosition;
}
# the text that comes before the inline
$unmarkedText = substr($text, 0, $Inline['position']);
# compile the unmarked text
$markup .= $this->unmarkedText($unmarkedText);
# compile the inline
$markup .= isset($Inline['markup']) ? $Inline['markup'] : $this->element($Inline['element']);
# remove the examined text
$text = substr($text, $Inline['position'] + $Inline['extent']);
continue 2;
}
# the marker does not belong to an inline
$unmarkedText = substr($text, 0, $markerPosition + 1);
$markup .= $this->unmarkedText($unmarkedText);
$text = substr($text, $markerPosition + 1);
}
$markup .= $this->unmarkedText($text);
return $markup;
}
#
# ~
#
protected function inlineCode($Excerpt)
{
$marker = $Excerpt['text'][0];
if (preg_match('/^('.$marker.'+)[ ]*(.+?)[ ]*(?<!'.$marker.')\1(?!'.$marker.')/s', $Excerpt['text'], $matches))
{
$text = $matches[2];
$text = htmlspecialchars($text, ENT_NOQUOTES, 'UTF-8');
$text = preg_replace("/[ ]*\n/", ' ', $text);
return array(
'extent' => strlen($matches[0]),
'element' => array(
'name' => 'code',
'text' => $text,
),
);
}
}
protected function inlineEmailTag($Excerpt)
{
if (strpos($Excerpt['text'], '>') !== false and preg_match('/^<((mailto:)?\S+?@\S+?)>/i', $Excerpt['text'], $matches))
{
$url = $matches[1];
if ( ! isset($matches[2]))
{
$url = 'mailto:' . $url;
}
return array(
'extent' => strlen($matches[0]),
'element' => array(
'name' => 'a',
'text' => $matches[1],
'attributes' => array(
'href' => $url,
),
),
);
}
}
protected function inlineEmphasis($Excerpt)
{
if ( ! isset($Excerpt['text'][1]))
{
return;
}
$marker = $Excerpt['text'][0];
if ($Excerpt['text'][1] === $marker and preg_match($this->StrongRegex[$marker], $Excerpt['text'], $matches))
{
$emphasis = 'strong';
}
elseif (preg_match($this->EmRegex[$marker], $Excerpt['text'], $matches))
{
$emphasis = 'em';
}
else
{
return;
}
return array(
'extent' => strlen($matches[0]),
'element' => array(
'name' => $emphasis,
'handler' => 'line',
'text' => $matches[1],
),
);
}
protected function inlineEscapeSequence($Excerpt)
{
if (isset($Excerpt['text'][1]) and in_array($Excerpt['text'][1], $this->specialCharacters))
{
return array(
'markup' => $Excerpt['text'][1],
'extent' => 2,
);
}
}
protected function inlineImage($Excerpt)
{
if ( ! isset($Excerpt['text'][1]) or $Excerpt['text'][1] !== '[')
{
return;
}
$Excerpt['text']= substr($Excerpt['text'], 1);
$Link = $this->inlineLink($Excerpt);
if ($Link === null)
{
return;
}
$Inline = array(
'extent' => $Link['extent'] + 1,
'element' => array(
'name' => 'img',
'attributes' => array(
'src' => $Link['element']['attributes']['href'],
'alt' => $Link['element']['text'],
'class' => 'img-responsive'
),
),
);
$Inline['element']['attributes'] += $Link['element']['attributes'];
unset($Inline['element']['attributes']['href']);
return $Inline;
}
protected function inlineLink($Excerpt)
{
$Element = array(
'name' => 'a',
'handler' => 'line',
'text' => null,
'attributes' => array(
'href' => null,
'title' => null,
),
);
$extent = 0;
$remainder = $Excerpt['text'];
if (preg_match('/\[((?:[^][]++|(?R))*+)\]/', $remainder, $matches))
{
$Element['text'] = $matches[1];
$extent += strlen($matches[0]);
$remainder = substr($remainder, $extent);
}
else
{
return;
}
if (preg_match('/^[(]\s*+((?:[^ ()]++|[(][^ )]+[)])++)(?:[ ]+("[^"]*"|\'[^\']*\'))?\s*[)]/', $remainder, $matches))
{
$Element['attributes']['href'] = $matches[1];
if (isset($matches[2]))
{
$Element['attributes']['title'] = substr($matches[2], 1, - 1);
}
$extent += strlen($matches[0]);
}
else
{
if (preg_match('/^\s*\[(.*?)\]/', $remainder, $matches))
{
$definition = strlen($matches[1]) ? $matches[1] : $Element['text'];
$definition = strtolower($definition);
$extent += strlen($matches[0]);
}
else
{
$definition = strtolower($Element['text']);
}
if ( ! isset($this->DefinitionData['Reference'][$definition]))
{
return;
}
$Definition = $this->DefinitionData['Reference'][$definition];
$Element['attributes']['href'] = $Definition['url'];
$Element['attributes']['title'] = $Definition['title'];
}
$Element['attributes']['href'] = str_replace(array('&', '<'), array('&amp;', '&lt;'), $Element['attributes']['href']);
return array(
'extent' => $extent,
'element' => $Element,
);
}
protected function inlineMarkup($Excerpt)
{
if ($this->markupEscaped or strpos($Excerpt['text'], '>') === false)
{
return;
}
if ($Excerpt['text'][1] === '/' and preg_match('/^<\/\w*[ ]*>/s', $Excerpt['text'], $matches))
{
return array(
'markup' => $matches[0],
'extent' => strlen($matches[0]),
);
}
if ($Excerpt['text'][1] === '!' and preg_match('/^<!---?[^>-](?:-?[^-])*-->/s', $Excerpt['text'], $matches))
{
return array(
'markup' => $matches[0],
'extent' => strlen($matches[0]),
);
}
if ($Excerpt['text'][1] !== ' ' and preg_match('/^<\w*(?:[ ]*'.$this->regexHtmlAttribute.')*[ ]*\/?>/s', $Excerpt['text'], $matches))
{
return array(
'markup' => $matches[0],
'extent' => strlen($matches[0]),
);
}
}
protected function inlineSpecialCharacter($Excerpt)
{
if ($Excerpt['text'][0] === '&' and ! preg_match('/^&#?\w+;/', $Excerpt['text']))
{
return array(
'markup' => '&amp;',
'extent' => 1,
);
}
$SpecialCharacter = array('>' => 'gt', '<' => 'lt', '"' => 'quot');
if (isset($SpecialCharacter[$Excerpt['text'][0]]))
{
return array(
'markup' => '&'.$SpecialCharacter[$Excerpt['text'][0]].';',
'extent' => 1,
);
}
}
protected function inlineStrikethrough($Excerpt)
{
if ( ! isset($Excerpt['text'][1]))
{
return;
}
if ($Excerpt['text'][1] === '~' and preg_match('/^~~(?=\S)(.+?)(?<=\S)~~/', $Excerpt['text'], $matches))
{
return array(
'extent' => strlen($matches[0]),
'element' => array(
'name' => 'del',
'text' => $matches[1],
'handler' => 'line',
),
);
}
}
protected function inlineUrl($Excerpt)
{
if ($this->urlsLinked !== true or ! isset($Excerpt['text'][2]) or $Excerpt['text'][2] !== '/')
{
return;
}
if (preg_match('/\bhttps?:[\/]{2}[^\s<]+\b\/*/ui', $Excerpt['context'], $matches, PREG_OFFSET_CAPTURE))
{
$Inline = array(
'extent' => strlen($matches[0][0]),
'position' => $matches[0][1],
'element' => array(
'name' => 'a',
'text' => $matches[0][0],
'attributes' => array(
'href' => $matches[0][0],
),
),
);
return $Inline;
}
}
protected function inlineUrlTag($Excerpt)
{
if (strpos($Excerpt['text'], '>') !== false and preg_match('/^<(\w+:\/{2}[^ >]+)>/i', $Excerpt['text'], $matches))
{
$url = str_replace(array('&', '<'), array('&amp;', '&lt;'), $matches[1]);
return array(
'extent' => strlen($matches[0]),
'element' => array(
'name' => 'a',
'text' => $url,
'attributes' => array(
'href' => $url,
),
),
);
}
}
# ~
protected function unmarkedText($text)
{
if ($this->breaksEnabled)
{
$text = preg_replace('/[ ]*\n/', "<br />\n", $text);
}
else
{
$text = preg_replace('/(?:[ ][ ]+|[ ]*\\\\)\n/', "<br />\n", $text);
$text = str_replace(" \n", "\n", $text);
}
return $text;
}
#
# Handlers
#
protected function element(array $Element)
{
$markup = '<'.$Element['name'];
if (isset($Element['attributes']))
{
foreach ($Element['attributes'] as $name => $value)
{
if ($value === null)
{
continue;
}
$markup .= ' '.$name.'="'.$value.'"';
}
}
if (isset($Element['text']))
{
$markup .= '>';
if (isset($Element['handler']))
{
$markup .= $this->{$Element['handler']}($Element['text']);
}
else
{
$markup .= $Element['text'];
}
$markup .= '</'.$Element['name'].'>';
}
else
{
$markup .= ' />';
}
return $markup;
}
protected function elements(array $Elements)
{
$markup = '';
foreach ($Elements as $Element)
{
$markup .= "\n" . $this->element($Element);
}
$markup .= "\n";
return $markup;
}
# ~
protected function li($lines)
{
$markup = $this->lines($lines);
$trimmedMarkup = trim($markup);
if ( ! in_array('', $lines) and substr($trimmedMarkup, 0, 3) === '<p>')
{
$markup = $trimmedMarkup;
$markup = substr($markup, 3);
$position = strpos($markup, "</p>");
$markup = substr_replace($markup, '', $position, 4);
}
return $markup;
}
#
# Deprecated Methods
#
function parse($text)
{
$markup = $this->text($text);
return $markup;
}
#
# Static Methods
#
static function instance($name = 'default')
{
if (isset(self::$instances[$name]))
{
return self::$instances[$name];
}
$instance = new static();
self::$instances[$name] = $instance;
return $instance;
}
private static $instances = array();
#
# Fields
#
protected $DefinitionData;
#
# Read-Only
protected $specialCharacters = array(
'\\', '`', '*', '_', '{', '}', '[', ']', '(', ')', '>', '#', '+', '-', '.', '!', '|',
);
protected $StrongRegex = array(
'*' => '/^[*]{2}((?:\\\\\*|[^*]|[*][^*]*[*])+?)[*]{2}(?![*])/s',
'_' => '/^__((?:\\\\_|[^_]|_[^_]*_)+?)__(?!_)/us',
);
protected $EmRegex = array(
'*' => '/^[*]((?:\\\\\*|[^*]|[*][*][^*]+?[*][*])+?)[*](?![*])/s',
'_' => '/^_((?:\\\\_|[^_]|__[^_]*__)+?)_(?!_)\b/us',
);
protected $regexHtmlAttribute = '[a-zA-Z_:][\w:.-]*(?:\s*=\s*(?:[^"\'=<>`\s]+|"[^"]*"|\'[^\']*\'))?';
protected $voidElements = array(
'area', 'base', 'br', 'col', 'command', 'embed', 'hr', 'img', 'input', 'link', 'meta', 'param', 'source',
);
protected $textLevelElements = array(
'a', 'br', 'bdo', 'abbr', 'blink', 'nextid', 'acronym', 'basefont',
'b', 'em', 'big', 'cite', 'small', 'spacer', 'listing',
'i', 'rp', 'del', 'code', 'strike', 'marquee',
'q', 'rt', 'ins', 'font', 'strong',
's', 'tt', 'sub', 'mark',
'u', 'xm', 'sup', 'nobr',
'var', 'ruby',
'wbr', 'span',
'time',
);
}
{
"name": "psr/cache",
"description": "Common interface for caching libraries",
"keywords": ["psr", "psr-6", "cache"],
"license": "MIT",
"authors": [
{
"name": "PHP-FIG",
"homepage": "http://www.php-fig.org/"
}
],
"require": {
"php": ">=5.3.0"
},
"autoload": {
"psr-4": {
"Psr\\Cache\\": "src/"
}
},
"extra": {
"branch-alias": {
"dev-master": "1.0.x-dev"
}
}
}
Copyright (c) 2015 PHP Framework Interoperability Group
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

PSR Cache

This repository holds all interfaces defined by PSR-6.

Note that this is not a Cache implementation of its own. It is merely an interface that describes a Cache implementation. See the specification for more details.

<?php
namespace Psr\Cache;
/**
* Exception interface for all exceptions thrown by an Implementing Library.
*/
interface CacheException
{
}
<?php
namespace Psr\Cache;
/**
* CacheItemInterface defines an interface for interacting with objects inside a cache.
*
* Each Item object MUST be associated with a specific key, which can be set
* according to the implementing system and is typically passed by the
* Cache\CacheItemPoolInterface object.
*
* The Cache\CacheItemInterface object encapsulates the storage and retrieval of
* cache items. Each Cache\CacheItemInterface is generated by a
* Cache\CacheItemPoolInterface object, which is responsible for any required
* setup as well as associating the object with a unique Key.
* Cache\CacheItemInterface objects MUST be able to store and retrieve any type
* of PHP value defined in the Data section of the specification.
*
* Calling Libraries MUST NOT instantiate Item objects themselves. They may only
* be requested from a Pool object via the getItem() method. Calling Libraries
* SHOULD NOT assume that an Item created by one Implementing Library is
* compatible with a Pool from another Implementing Library.
*
*/
interface CacheItemInterface
{
/**
* Returns the key for the current cache item.
*
* The key is loaded by the Implementing Library, but should be available to
* the higher level callers when needed.
*
* @return string
* The key string for this cache item.
*/
public function getKey();
/**
* Retrieves the value of the item from the cache associated with this object's key.
*
* The value returned must be identical to the value originally stored by set().
*
* If isHit() returns false, this method MUST return null. Note that null
* is a legitimate cached value, so the isHit() method SHOULD be used to
* differentiate between "null value was found" and "no value was found."
*
* @return mixed
* The value corresponding to this cache item's key, or null if not found.
*/
public function get();
/**
* Confirms if the cache item lookup resulted in a cache hit.
*
* Note: This method MUST NOT have a race condition between calling isHit()
* and calling get().
*
* @return bool
* True if the request resulted in a cache hit. False otherwise.
*/
public function isHit();
/**
* Sets the value represented by this cache item.
*
* The $value argument may be any item that can be serialized by PHP,
* although the method of serialization is left up to the Implementing
* Library.
*
* @param mixed $value
* The serializable value to be stored.
*
* @return static
* The invoked object.
*/
public function set($value);
/**
* Sets the expiration time for this cache item.
*
* @param \DateTimeInterface $expiration
* The point in time after which the item MUST be considered expired.
* If null is passed explicitly, a default value MAY be used. If none is set,
* the value should be stored permanently or for as long as the
* implementation allows.
*
* @return static
* The called object.
*/
public function expiresAt($expiration);
/**
* Sets the expiration time for this cache item.
*
* @param int|\DateInterval $time
* The period of time from the present after which the item MUST be considered
* expired. An integer parameter is understood to be the time in seconds until
* expiration. If null is passed explicitly, a default value MAY be used.
* If none is set, the value should be stored permanently or for as long as the
* implementation allows.
*
* @return static
* The called object.
*/
public function expiresAfter($time);
}
<?php
namespace Psr\Cache;
/**
* CacheItemPoolInterface generates CacheItemInterface objects.
*
* The primary purpose of Cache\CacheItemPoolInterface is to accept a key from
* the Calling Library and return the associated Cache\CacheItemInterface object.
* It is also the primary point of interaction with the entire cache collection.
* All configuration and initialization of the Pool is left up to an
* Implementing Library.
*
*/
interface CacheItemPoolInterface
{
/**
* Returns a Cache Item representing the specified key.
*
* This method must always return a CacheItemInterface object, even in case of
* a cache miss. It MUST NOT return null.
*
* @param string $key
* The key for which to return the corresponding Cache Item.
*
* @throws InvalidArgumentException
* If the $key string is not a legal value a \Psr\Cache\InvalidArgumentException
* MUST be thrown.
*
* @return CacheItemInterface
* The corresponding Cache Item.
*/
public function getItem($key);
/**
* Returns a traversable set of cache items.
*
* @param array $keys
* An indexed array of keys of items to retrieve.
*
* @throws InvalidArgumentException
* If any of the keys in $keys are not a legal value a \Psr\Cache\InvalidArgumentException
* MUST be thrown.
*
* @return array|\Traversable
* A traversable collection of Cache Items keyed by the cache keys of
* each item. A Cache item will be returned for each key, even if that
* key is not found. However, if no keys are specified then an empty
* traversable MUST be returned instead.
*/
public function getItems(array $keys = array());
/**
* Confirms if the cache contains specified cache item.
*
* Note: This method MAY avoid retrieving the cached value for performance reasons.
* This could result in a race condition with CacheItemInterface::get(). To avoid
* such situation use CacheItemInterface::isHit() instead.
*
* @param string $key
* The key for which to check existence.
*
* @throws InvalidArgumentException
* If the $key string is not a legal value a \Psr\Cache\InvalidArgumentException
* MUST be thrown.
*
* @return bool
* True if item exists in the cache, false otherwise.
*/
public function hasItem($key);
/**
* Deletes all items in the pool.
*
* @return bool
* True if the pool was successfully cleared. False if there was an error.
*/
public function clear();
/**
* Removes the item from the pool.
*
* @param string $key
* The key for which to delete
*
* @throws InvalidArgumentException
* If the $key string is not a legal value a \Psr\Cache\InvalidArgumentException
* MUST be thrown.
*
* @return bool
* True if the item was successfully removed. False if there was an error.
*/
public function deleteItem($key);
/**
* Removes multiple items from the pool.
*
* @param array $keys
* An array of keys that should be removed from the pool.
* @throws InvalidArgumentException
* If any of the keys in $keys are not a legal value a \Psr\Cache\InvalidArgumentException
* MUST be thrown.
*
* @return bool
* True if the items were successfully removed. False if there was an error.
*/
public function deleteItems(array $keys);
/**
* Persists a cache item immediately.
*
* @param CacheItemInterface $item
* The cache item to save.
*
* @return bool
* True if the item was successfully persisted. False if there was an error.
*/
public function save(CacheItemInterface $item);
/**
* Sets a cache item to be persisted later.
*
* @param CacheItemInterface $item
* The cache item to save.
*
* @return bool
* False if the item could not be queued or if a commit was attempted and failed. True otherwise.
*/
public function saveDeferred(CacheItemInterface $item);
/**
* Persists any deferred cache items.
*
* @return bool
* True if all not-yet-saved items were successfully saved or there were none. False otherwise.
*/
public function commit();
}
<?php
namespace Psr\Cache;
/**
* Exception interface for invalid cache arguments.
*
* Any time an invalid argument is passed into a method it must throw an
* exception class which implements Psr\Cache\InvalidArgumentException.
*/
interface InvalidArgumentException extends CacheException
{
}
Copyright (c) 2016 phpFastCache
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
Software), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
<?php
/**
*
* This file is part of phpFastCache.
*
* @license MIT License (MIT)
*
* For full copyright and license information, please see the docs/CREDITS.txt file.
*
* @author Khoa Bui (khoaofgod) <khoaofgod@gmail.com> http://www.phpfastcache.com
* @author Georges.L (Geolim4) <contact@geolim4.com>
*
*/
define('PFC_PHP_EXT', 'php');
define('PFC_BIN_DIR', __DIR__ . '/../bin/');
/**
* Register Autoload
*/
spl_autoload_register(function ($entity) {
$module = explode('\\', $entity, 2);
if (!in_array($module[ 0 ], ['phpFastCache', 'Psr'])) {
/**
* Not a part of phpFastCache file
* then we return here.
*/
return;
} else if (strpos($entity, 'Psr\Cache') === 0) {
$path = PFC_BIN_DIR . 'legacy/Psr/Cache/src/' . substr(strrchr($entity, '\\'), 1) . '.' . PFC_PHP_EXT;
if (is_readable($path)) {
require_once $path;
}else{
trigger_error('Cannot locate the Psr/Cache files', E_USER_ERROR);
}
return;
}
$entity = str_replace('\\', '/', $entity);
$path = __DIR__ . '/' . $entity . '.' . PFC_PHP_EXT;
if (is_readable($path)) {
require_once $path;
}
});
if ((!defined('PFC_IGNORE_COMPOSER_WARNING') || !PFC_IGNORE_COMPOSER_WARNING) && class_exists('Composer\Autoload\ClassLoader')) {
trigger_error('Your project already makes use of Composer. You SHOULD use the composer dependency "phpfastcache/phpfastcache" instead of hard-autoloading.',
E_USER_WARNING);
}
order deny,allow
deny from all
allow from 127.0.0.1
<?php
/**
*
* This file is part of phpFastCache.
*
* @license MIT License (MIT)
*
* For full copyright and license information, please see the docs/CREDITS.txt file.
*
* @author Khoa Bui (khoaofgod) <khoaofgod@gmail.com> http://www.phpfastcache.com
* @author Georges.L (Geolim4) <contact@geolim4.com>
*
*/
namespace phpFastCache;
/**
* Class Api
* @package phpFastCache
*/
class Api
{
protected static $version = '1.1.3';
/**
* This method will returns the current
* API version, the API version will be
* updated by following the semantic versioning
* based on changes of:
* - ExtendedCacheItemPoolInterface
* - ExtendedCacheItemInterface
*
* @see http://semver.org/
* @return string
*/
public static function getVersion()
{
return self::$version;
}
/**
* Return the API changelog, as a string.
* @return string
*/
public static function getChangelog()
{
return <<<CHANGELOG
- 1.1.3
-- Added an additional CacheItemInterface method:
ExtendedCacheItemInterface::getEncodedKey()
- 1.1.2
-- Implemented [de|a]ttaching methods to improve memory management
ExtendedCacheItemPoolInterface::detachItem()
ExtendedCacheItemPoolInterface::detachAllItems()
ExtendedCacheItemPoolInterface::attachItem()
ExtendedCacheItemPoolInterface::isAttached()
- 1.1.1
-- Implemented JsonSerializable interface to ExtendedCacheItemInterface
- 1.1.0
-- Implemented JSON methods such as:
ExtendedCacheItemPoolInterface::getItemsAsJsonString()
ExtendedCacheItemPoolInterface::getItemsByTagsAsJsonString()
ExtendedCacheItemInterface::getDataAsJsonString()
- 1.0.0
-- First initial version
CHANGELOG;
}
}
<?php
/**
*
* This file is part of phpFastCache.
*
* @license MIT License (MIT)
*
* For full copyright and license information, please see the docs/CREDITS.txt file.
*
* @author Khoa Bui (khoaofgod) <khoaofgod@gmail.com> http://www.phpfastcache.com
* @author Georges.L (Geolim4) <contact@geolim4.com>
*
*/
namespace phpFastCache\Cache;
use phpFastCache\Core\ExtendedCacheItemPoolTrait;
use phpFastCache\Exceptions\phpFastCacheDriverException;
/**
* Class DriverBaseTrait
* @package phpFastCache\Cache
*/
trait DriverBaseTrait
{
use ExtendedCacheItemPoolTrait;
/**
* @var array default options, this will be merge to Driver's Options
*/
protected $config = [];
/**
* @var bool
*/
protected $fallback = false;
/**
* @var mixed Instance of driver service
*/
protected $instance;
/**
* @param $config_name
* @param string $value
*/
public function setup($config_name, $value = '')
{
/**
* Config for class
*/
if (is_array($config_name)) {
$this->config = array_merge($this->config, $config_name);
} else {
$this->config[ $config_name ] = $value;
}
}
/**
* @return array
*/
public function getConfig()
{
return $this->config;
}
/**
* @param $file
* @return string
* @throws \Exception
*/
protected function readfile($file)
{
if (function_exists('file_get_contents')) {
return file_get_contents($file);
} else {
$string = '';
$file_handle = @fopen($file, 'r');
if (!$file_handle) {
throw new phpFastCacheDriverException("Can't Read File", 96);
}
while (!feof($file_handle)) {
$line = fgets($file_handle);
$string .= $line;
}
fclose($file_handle);
return $string;
}
}
/**
* Encode data types such as object/array
* for driver that does not support
* non-scalar value
* @param $data
* @return string
*/
protected function encode($data)
{
return serialize($data);
}
/**
* Decode data types such as object/array
* for driver that does not support
* non-scalar value
* @param $value
* @return mixed
*/
protected function decode($value)
{
return @unserialize($value);
}
/**
* Check phpModules or CGI
* @return bool
*/
protected function isPHPModule()
{
if (PHP_SAPI === 'apache2handler') {
return true;
} else {
if (strpos(PHP_SAPI, 'handler') !== false) {
return true;
}
}
return false;
}
/**
* @param $class
* @return bool
*/
protected function isExistingDriver($class)
{
return class_exists("\\phpFastCache\\Drivers\\{$class}");
}
/**
* @param $tag
* @return string
*/
protected function _getTagName($tag)
{
return "__tag__" . $tag;
}
/**
* @param \phpFastCache\Cache\ExtendedCacheItemInterface $item
* @return array
*/
public function driverPreWrap(ExtendedCacheItemInterface $item)
{
return [
self::DRIVER_DATA_WRAPPER_INDEX => $item->get(),
self::DRIVER_TIME_WRAPPER_INDEX => $item->getExpirationDate(),
self::DRIVER_TAGS_WRAPPER_INDEX => $item->getTags(),
];
}
/**
* @param array $wrapper
* @return mixed
*/
public function driverUnwrapData(array $wrapper)
{
return $wrapper[ self::DRIVER_DATA_WRAPPER_INDEX ];
}
/**
* @param array $wrapper
* @return mixed
*/
public function driverUnwrapTags(array $wrapper)
{
return $wrapper[ self::DRIVER_TAGS_WRAPPER_INDEX ];
}
/**
* @param array $wrapper
* @return \DateTime
*/
public function driverUnwrapTime(array $wrapper)
{
return $wrapper[ self::DRIVER_TIME_WRAPPER_INDEX ];
}
/**
* @return string
*/
public function getDriverName()
{
static $driverName;
return ($driverName ?: $driverName = ucfirst(substr(strrchr((new \ReflectionObject($this))->getNamespaceName(), '\\'), 1)));
}
/**
* @param \phpFastCache\Cache\ExtendedCacheItemInterface $item
* @return bool
* @throws \LogicException
*/
public function driverWriteTags(ExtendedCacheItemInterface $item)
{
/**
* Do not attempt to write tags
* on tags item, it can leads
* to an infinite recursive calls
*/
if(strpos($item->getKey(), self::DRIVER_TAGS_KEY_PREFIX ) === 0){
throw new \LogicException('Trying to set tag(s) to an Tag item index: ' . $item->getKey());
}
/**
* @var $tagsItems ExtendedCacheItemInterface[]
*/
$tagsItems = $this->getItems($this->getTagKeys($item->getTags()));
foreach ($tagsItems as $tagsItem) {
$data = $tagsItem->get();
$expTimestamp = $item->getExpirationDate()->getTimestamp();
/**
* Using the key will
* avoid to use array_unique
* that has slow performances
*/
$tagsItem->set(array_merge((array) $data, [$item->getKey() => $expTimestamp]));
/**
* Set the expiration date
* of the $tagsItem based
* on the older $item
* expiration date
*/
if ($expTimestamp > $tagsItem->getExpirationDate()->getTimestamp()) {
$tagsItem->expiresAt($item->getExpirationDate());
}
$this->driverWrite($tagsItem);
$tagsItem->setHit(true);
}
/**
* Also update removed tags to
* keep the index up to date
*/
$tagsItems = $this->getItems($this->getTagKeys($item->getRemovedTags()));
foreach ($tagsItems as $tagsItem) {
$data = (array) $tagsItem->get();
unset($data[ $item->getKey() ]);
$tagsItem->set($data);
/**
* Recalculate the expiration date
*
* If the $tagsItem does not have
* any cache item references left
* then remove it from tagsItems index
*/
if (count($data)) {
$tagsItem->expiresAt(max($data));
$this->driverWrite($tagsItem);
$tagsItem->setHit(true);
} else {
$this->deleteItem($tagsItem->getKey());
}
}
return true;
}
/**
* @param $key
* @return string
*/
public function getTagKey($key)
{
return self::DRIVER_TAGS_KEY_PREFIX . $key;
}
/**
* @param $key
* @return string
*/
public function getTagKeys(array $keys)
{
foreach ($keys as &$key) {
$key = $this->getTagKey($key);
}
return $keys;
}
/**
* @param string $optionName
* @param mixed $optionValue
* @return bool
* @throws \InvalidArgumentException
*/
public static function isValidOption($optionName, $optionValue)
{
if (!is_string($optionName)) {
throw new \InvalidArgumentException('$optionName must be a string');
}
return true;
}
/**
* @return array
*/
public static function getRequiredOptions()
{
return [];
}
/**
* @return array
*/
public static function getValidOptions()
{
return [];
}
}
<?php
/**
*
* This file is part of phpFastCache.
*
* @license MIT License (MIT)
*
* For full copyright and license information, please see the docs/CREDITS.txt file.
*
* @author Khoa Bui (khoaofgod) <khoaofgod@gmail.com> http://www.phpfastcache.com
* @author Georges.L (Geolim4) <contact@geolim4.com>
*
*/
namespace phpFastCache\Cache;
use Psr\Cache\CacheItemInterface;
/**
* Interface ExtendedCacheItemInterface
* @package phpFastCache\Cache
*/
interface ExtendedCacheItemInterface extends CacheItemInterface, \JsonSerializable
{
/**
* Returns the encoded key for the current cache item.
* Usually as a MD5 hash
*
* @return string
* The encoded key string for this cache item.
*/
public function getEncodedKey();
/**
* @return mixed
*/
public function getUncommittedData();
/**
* @return \DateTimeInterface
*/
public function getExpirationDate();
/**
* @return int
*/
public function getTtl();
/**
* @return bool
*/
public function isExpired();
/**
* @param \phpFastCache\Cache\ExtendedCacheItemPoolInterface $driver
* @return mixed
*/
public function setDriver(ExtendedCacheItemPoolInterface $driver);
/**
* @param bool $isHit
* @return $this
* @throws \InvalidArgumentException
*/
public function setHit($isHit);
/**
* @param int $step
* @return $this
* @throws \InvalidArgumentException
*/
public function increment($step = 1);
/**
* @param int $step
* @return $this
* @throws \InvalidArgumentException
*/
public function decrement($step = 1);
/**
* @param array|string $data
* @return $this
* @throws \InvalidArgumentException
*/
public function append($data);
/**
* @param array|string $data
* @return $this
* @throws \InvalidArgumentException
*/
public function prepend($data);
/**
* Sets the expiration time for this cache item.
*
* @param int|\DateInterval $time
* The period of time from the present after which the item MUST be considered
* expired. An integer parameter is understood to be the time in seconds until
* expiration. If null is passed explicitly, a default value MAY be used.
* If none is set, the value should be stored permanently or for as long as the
* implementation allows.
*
* @return static
* The called object.
*
* @deprecated Use CacheItemInterface::expiresAfter() instead
*/
public function touch($time);
/**
* @param string $tagName
* @return $this
* @throws \InvalidArgumentException
*/
public function addTag($tagName);
/**
* @param array $tagNames
* @return $this
*/
public function addTags(array $tagNames);
/**
* @param array $tags
* @return $this
* @throws \InvalidArgumentException
*/
public function setTags(array $tags);
/**
* @return array
*/
public function getTags();
/**
* @param string $separator
* @return mixed
*/
public function getTagsAsString($separator = ', ');
/**
* @param array $tagName
* @return $this
*/
public function removeTag($tagName);
/**
* @param array $tagNames
* @return $this
*/
public function removeTags(array $tagNames);
/**
* @return array
*/
public function getRemovedTags();
/**
* Return the data as a well-formatted string.
* Any scalar value will be casted to an array
* @param int $option json_encode() options
* @param int $depth json_encode() depth
* @return string
*/
public function getDataAsJsonString($option = 0, $depth = 512);
}
<?php
/**
*
* This file is part of phpFastCache.
*
* @license MIT License (MIT)
*
* For full copyright and license information, please see the docs/CREDITS.txt file.
*
* @author Khoa Bui (khoaofgod) <khoaofgod@gmail.com> http://www.phpfastcache.com
* @author Georges.L (Geolim4) <contact@geolim4.com>
*
*/
namespace phpFastCache\Cache;
use InvalidArgumentException;
use phpFastCache\Entities\driverStatistic;
use Psr\Cache\CacheItemInterface;
use Psr\Cache\CacheItemPoolInterface;
/**
* Interface ExtendedCacheItemPoolInterface
* @package phpFastCache\Cache
*/
interface ExtendedCacheItemPoolInterface extends CacheItemPoolInterface
{
/**
* @return array
*/
public function getConfig();
/**
* @return string
*/
public function getDriverName();
/**
* [phpFastCache phpDoc Override]
* Returns a Cache Item representing the specified key.
*
* This method must always return a CacheItemInterface object, even in case of
* a cache miss. It MUST NOT return null.
*
* @param string $key
* The key for which to return the corresponding Cache Item.
*
* @throws InvalidArgumentException
* If the $key string is not a legal value a \Psr\Cache\InvalidArgumentException
* MUST be thrown.
*
* @return ExtendedCacheItemInterface
* The corresponding Cache Item.
*/
public function getItem($key);
/**
* [phpFastCache phpDoc Override]
* Returns a traversable set of cache items.
*
* @param array $keys
* An indexed array of keys of items to retrieve.
*
* @throws InvalidArgumentException
* If any of the keys in $keys are not a legal value a \Psr\Cache\InvalidArgumentException
* MUST be thrown.
*
* @return ExtendedCacheItemInterface[]
* A traversable collection of Cache Items keyed by the cache keys of
* each item. A Cache item will be returned for each key, even if that
* key is not found. However, if no keys are specified then an empty
* traversable MUST be returned instead.
*/
public function getItems(array $keys = []);
/**
* Returns A json string that represents an array of items.
*
* @param array $keys
* An indexed array of keys of items to retrieve.
* @param int $option json_encode() options
* @param int $depth json_encode() depth
*
* @throws InvalidArgumentException
* If any of the keys in $keys are not a legal value a \Psr\Cache\InvalidArgumentException
* MUST be thrown.
*
* @return string
*/
public function getItemsAsJsonString(array $keys = [], $option = 0, $depth = 512);
/**
* @param \Psr\Cache\CacheItemInterface $item
* @return mixed
*/
public function setItem(CacheItemInterface $item);
/**
* Deletes all items in the pool.
* @deprecated Use clear() instead
* Will be removed in 5.1
*
* @return bool
* True if the pool was successfully cleared. False if there was an error.
*/
public function clean();
/**
* @return driverStatistic
*/
public function getStats();
/**
* Returns a traversable set of cache items by a tag name.
*
* @param string $tagName
* An indexed array of keys of items to retrieve.
*
* @throws InvalidArgumentException
* If any of the keys in $keys are not a legal value a \Psr\Cache\InvalidArgumentException
* MUST be thrown.
*
* @return ExtendedCacheItemInterface[]
* A traversable collection of Cache Items keyed by the cache keys of
* each item. A Cache item will be returned for each key, even if that
* key is not found. However, if no keys are specified then an empty
* traversable MUST be returned instead.
*/
public function getItemsByTag($tagName);
/**
* Returns a traversable set of cache items by a tag name.
*
* @param array $tagNames
* An indexed array of keys of items to retrieve.
*
* @throws InvalidArgumentException
* If any of the keys in $keys are not a legal value a \Psr\Cache\InvalidArgumentException
* MUST be thrown.
*
* @return ExtendedCacheItemInterface[]
* A traversable collection of Cache Items keyed by the cache keys of
* each item. A Cache item will be returned for each key, even if that
* key is not found. However, if no keys are specified then an empty
* traversable MUST be returned instead.
*/
public function getItemsByTags(array $tagNames);
/**
* Returns A json string that represents an array of items by tags-based.
*
* @param array $tagNames
* An indexed array of keys of items to retrieve.
* @param int $option json_encode() options
* @param int $depth json_encode() depth
*
* @throws InvalidArgumentException
* If any of the keys in $keys are not a legal value a \Psr\Cache\InvalidArgumentException
* MUST be thrown.
*
* @return string
*/
public function getItemsByTagsAsJsonString(array $tagNames, $option = 0, $depth = 512);
/**
* Removes the item from the pool by tag.
*
* @param string $tagName
* The tag for which to delete
*
* @throws InvalidArgumentException
* If the $key string is not a legal value a \Psr\Cache\InvalidArgumentException
* MUST be thrown.
*
* @return bool
* True if the item was successfully removed. False if there was an error.
*/
public function deleteItemsByTag($tagName);
/**
* Removes the item from the pool by tag.
*
* @param array $tagNames
* The tag for which to delete
*
* @throws InvalidArgumentException
* If the $key string is not a legal value a \Psr\Cache\InvalidArgumentException
* MUST be thrown.
*
* @return bool
* True if the item was successfully removed. False if there was an error.
*/
public function deleteItemsByTags(array $tagNames);
/**
* Increment the items from the pool by tag.
*
* @param string $tagName
* The tag for which to increment
* @param int $step
*
* @throws InvalidArgumentException
* If the $key string is not a legal value a \Psr\Cache\InvalidArgumentException
* MUST be thrown.
*
* @return bool
* True if the item was successfully incremented. False if there was an error.
*/
public function incrementItemsByTag($tagName, $step = 1);
/**
* Increment the items from the pool by tag.
*
* @param array $tagNames
* The tag for which to increment
* @param int $step
*
* @throws InvalidArgumentException
* If the $key string is not a legal value a \Psr\Cache\InvalidArgumentException
* MUST be thrown.
*
* @return bool
* True if the item was successfully incremented. False if there was an error.
*/
public function incrementItemsByTags(array $tagNames, $step = 1);
/**
* Decrement the items from the pool by tag.
*
* @param string $tagName
* The tag for which to decrement
* @param int $step
*
* @throws InvalidArgumentException
* If the $key string is not a legal value a \Psr\Cache\InvalidArgumentException
* MUST be thrown.
*
* @return bool
* True if the item was successfully decremented. False if there was an error.
*/
public function decrementItemsByTag($tagName, $step = 1);
/**
* Decrement the items from the pool by tag.
*
* @param array $tagNames
* The tag for which to decrement
* @param int $step
*
* @throws InvalidArgumentException
* If the $key string is not a legal value a \Psr\Cache\InvalidArgumentException
* MUST be thrown.
*
* @return bool
* True if the item was successfully decremented. False if there was an error.
*/
public function decrementItemsByTags(array $tagNames, $step = 1);
/**
* Decrement the items from the pool by tag.
*
* @param string $tagName
* The tag for which to append
*
* @param array|string $data
*
* @throws InvalidArgumentException
* If the $key string is not a legal value a \Psr\Cache\InvalidArgumentException
* MUST be thrown.
*
* @return bool
* True if the item was successfully appended. False if there was an error.
*/
public function appendItemsByTag($tagName, $data);
/**
* Decrement the items from the pool by tag.
*
* @param array $tagNames
* The tag for which to append
*
* @param array|string $data
*
* @throws InvalidArgumentException
* If the $key string is not a legal value a \Psr\Cache\InvalidArgumentException
* MUST be thrown.
*
* @return bool
* True if the item was successfully appended. False if there was an error.
*/
public function appendItemsByTags(array $tagNames, $data);
/**
* Prepend the items from the pool by tag.
*
* @param string $tagName
* The tag for which to prepend
*
* @param array|string $data
*
* @throws InvalidArgumentException
* If the $key string is not a legal value a \Psr\Cache\InvalidArgumentException
* MUST be thrown.
*
* @return bool
* True if the item was successfully prepended. False if there was an error.
*/
public function prependItemsByTag($tagName, $data);
/**
* Prepend the items from the pool by tag.
*
* @param array $tagNames
* The tag for which to prepend
*
* @param array|string $data
*
* @throws InvalidArgumentException
* If the $key string is not a legal value a \Psr\Cache\InvalidArgumentException
* MUST be thrown.
*
* @return bool
* True if the item was successfully prepended. False if there was an error.
*/
public function prependItemsByTags(array $tagNames, $data);
/**
* @param \Psr\Cache\CacheItemInterface $item
* @return void
*/
public function detachItem(CacheItemInterface $item);
/**
* @return void
*/
public function detachAllItems();
/**
* @param \Psr\Cache\CacheItemInterface $item
* @return void
* @throws \LogicException
*/
public function attachItem(CacheItemInterface $item);
/**
* Returns true if the item exists, is attached and the Spl Hash matches
* Returns false if the item exists, is attached and the Spl Hash mismatches
* Returns null if the item does not exists
*
* @param \Psr\Cache\CacheItemInterface $item
* @return bool|null
* @throws \LogicException
*/
public function isAttached(CacheItemInterface $item);
}
<?php
/**
*
* This file is part of phpFastCache.
*
* @license MIT License (MIT)
*
* For full copyright and license information, please see the docs/CREDITS.txt file.
*
* @author Khoa Bui (khoaofgod) <khoaofgod@gmail.com> http://www.phpfastcache.com
* @author Georges.L (Geolim4) <contact@geolim4.com>
*
*/
namespace phpFastCache\Cache;
use phpFastCache\Core\DriverAbstract;
trait ItemBaseTrait
{
/**
* @var bool
*/
protected $fetched = false;
/**
* @var DriverAbstract
*/
protected $driver;
/**
* @var string
*/
protected $key;
/**
* @var mixed
*/
protected $data;
/**
* @var \DateTime
*/
protected $expirationDate;
/**
* @var array
*/
protected $tags = [];
/**
* @var array
*/
protected $removedTags = [];
/**
* @var bool
*/
protected $isHit = false;
/********************
*
* PSR-6 Methods
*
*******************/
/**
* @return string
*/
public function getKey()
{
return $this->key;
}
/**
* @return mixed
*/
public function get()
{
return $this->data;
}
/**
* @param mixed $value
* @return $this
*/
public function set($value)
{
/**
* The user set a value,
* therefore there is no need to
* fetch from source anymore
*/
$this->fetched = true;
$this->data = $value;
return $this;
}
/**
* @return bool
* @throws \InvalidArgumentException
*/
public function isHit()
{
return $this->isHit;
}
/**
* @param bool $isHit
* @return $this
* @throws \InvalidArgumentException
*/
public function setHit($isHit)
{
if (is_bool($isHit)) {
$this->isHit = $isHit;
return $this;
} else {
throw new \InvalidArgumentException('$isHit must be a boolean');
}
}
/**
* @param \DateTimeInterface $expiration
* @return $this
*/
public function expiresAt($expiration)
{
if ($expiration instanceof \DateTimeInterface) {
$this->expirationDate = $expiration;
} else {
throw new \InvalidArgumentException('$expiration must be an object implementing the DateTimeInterface');
}
return $this;
}
/**
* Sets the expiration time for this cache item.
*
* @param int|\DateInterval $time
* The period of time from the present after which the item MUST be considered
* expired. An integer parameter is understood to be the time in seconds until
* expiration. If null is passed explicitly, a default value MAY be used.
* If none is set, the value should be stored permanently or for as long as the
* implementation allows.
*
* @return static
* The called object.
*
* @deprecated Use CacheItemInterface::expiresAfter() instead
*/
public function touch($time)
{
trigger_error('touch() is deprecated and will be removed in the next major release, use CacheItemInterface::expiresAfter() instead');
return $this->expiresAfter($time);
}
/**
* @param \DateInterval|int $time
* @return $this
* @throws \InvalidArgumentException
*/
public function expiresAfter($time)
{
if (is_numeric($time)) {
if ($time <= 0) {
/**
* 5 years, however memcached or memory cached will gone when u restart it
* just recommended for sqlite. files
*/
$time = 30 * 24 * 3600 * 5;
}
$this->expirationDate = (new \DateTime())->add(new \DateInterval(sprintf('PT%dS', $time)));
} else if ($time instanceof \DateInterval) {
$this->expirationDate = (new \DateTime())->add($time);
} else {
throw new \InvalidArgumentException('Invalid date format');
}
return $this;
}
/********************
*
* PSR-6 Extended Methods
*
*******************/
/**
* @return string
*/
public function getEncodedKey()
{
return md5($this->getKey());
}
/**
* @return mixed
*/
public function getUncommittedData()
{
return $this->data;
}
/**
* @return \DateTimeInterface
*/
public function getExpirationDate()
{
return $this->expirationDate;
}
/**
* @return int
*/
public function getTtl()
{
$ttl = $this->expirationDate->getTimestamp() - time();
if ($ttl > 2592000) {
$ttl = time() + $ttl;
}
return $ttl;
}
/**
* @return bool
*/
public function isExpired()
{
return $this->expirationDate->getTimestamp() < (new \DateTime())->getTimestamp();
}
/**
* @param int $step
* @return $this
* @throws \InvalidArgumentException
*/
public function increment($step = 1)
{
if (is_int($step)) {
$this->fetched = true;
$this->data += $step;
} else {
throw new \InvalidArgumentException('$step must be numeric.');
}
return $this;
}
/**
* @param int $step
* @return $this
* @throws \InvalidArgumentException
*/
public function decrement($step = 1)
{
if (is_int($step)) {
$this->fetched = true;
$this->data -= $step;
} else {
throw new \InvalidArgumentException('$step must be numeric.');
}
return $this;
}
/**
* @param array|string $data
* @return $this
* @throws \InvalidArgumentException
*/
public function append($data)
{
if (is_array($this->data)) {
array_push($this->data, $data);
} else if (is_string($data)) {
$this->data .= (string) $data;
} else {
throw new \InvalidArgumentException('$data must be either array nor string.');
}
return $this;
}
/**
* @param array|string $data
* @return $this
* @throws \InvalidArgumentException
*/
public function prepend($data)
{
if (is_array($this->data)) {
array_unshift($this->data, $data);
} else if (is_string($data)) {
$this->data = (string) $data . $this->data;
} else {
throw new \InvalidArgumentException('$data must be either array nor string.');
}
return $this;
}
/**
* @param $tagName
* @return $this
* @throws \InvalidArgumentException
*/
public function addTag($tagName)
{
if (is_string($tagName)) {
$this->tags = array_unique(array_merge($this->tags, [$tagName]));
return $this;
} else {
throw new \InvalidArgumentException('$tagName must be a string');
}
}
/**
* @param array $tagNames
* @return $this
*/
public function addTags(array $tagNames)
{
foreach ($tagNames as $tagName) {
$this->addTag($tagName);
}
return $this;
}
/**
* @param array $tags
* @return $this
* @throws \InvalidArgumentException
*/
public function setTags(array $tags)
{
if (count($tags)) {
if (array_filter($tags, 'is_string')) {
$this->tags = $tags;
} else {
throw new \InvalidArgumentException('$tagName must be an array of string');
}
}
return $this;
}
/**
* @return array
*/
public function getTags()
{
return $this->tags;
}
/**
* @return string
*/
public function getTagsAsString($separator = ', ')
{
return implode($separator, $this->tags);
}
/**
* @param $tagName
* @return $this
*/
public function removeTag($tagName)
{
if (($key = array_search($tagName, $this->tags)) !== false) {
unset($this->tags[ $key ]);
$this->removedTags[] = $tagName;
}
return $this;
}
/**
* @param array $tagNames
* @return $this
*/
public function removeTags(array $tagNames)
{
foreach ($tagNames as $tagName) {
$this->removeTag($tagName);
}
return $this;
}
/**
* @return array
*/
public function getRemovedTags()
{
return array_diff($this->removedTags, $this->tags);
}
/**
* Return the data as a well-formatted string.
* Any scalar value will be casted to an array
* @param int $option json_encode() options
* @param int $depth json_encode() depth
* @return string
*/
public function getDataAsJsonString($option = 0, $depth = 512)
{
$data = $this->get();
if (is_object($data) || is_array($data)) {
$data = json_encode($data, $option, $depth);
} else {
$data = json_encode([$data], $option, $depth);
}
return json_encode($data, $option, $depth);
}
/**
* Implements \JsonSerializable interface
* @return mixed
*/
public function jsonSerialize()
{
return $this->get();
}
/**
* Prevent recursions for Debug (php 5.6+)
* @return array
*/
final public function __debugInfo()
{
$info = get_object_vars($this);
$info[ 'driver' ] = 'object(' . get_class($info[ 'driver' ]) . ')';
return (array) $info;
}
}
<?php
/**
*
* This file is part of phpFastCache.
*
* @license MIT License (MIT)
*
* For full copyright and license information, please see the docs/CREDITS.txt file.
*
* @author Khoa Bui (khoaofgod) <khoaofgod@gmail.com> http://www.phpfastcache.com
* @author Georges.L (Geolim4) <contact@geolim4.com>
*
*/
namespace phpFastCache;
use phpFastCache\Cache\ExtendedCacheItemPoolInterface;
use phpFastCache\Core\DriverAbstract;
use phpFastCache\Exceptions\phpFastCacheDriverCheckException;
/**
* Class CacheManager
* @package phpFastCache
*
* @method static ExtendedCacheItemPoolInterface Apc() Apc($config = []) Return a driver "apc" instance
* @method static ExtendedCacheItemPoolInterface Apcu() Apcu($config = []) Return a driver "apcu" instance
* @method static ExtendedCacheItemPoolInterface Cookie() Cookie($config = []) Return a driver "cookie" instance
* @method static ExtendedCacheItemPoolInterface Couchbase() Couchbase($config = []) Return a driver "couchbase" instance
* @method static ExtendedCacheItemPoolInterface Files() Files($config = []) Return a driver "files" instance
* @method static ExtendedCacheItemPoolInterface Leveldb() Leveldb($config = []) Return a driver "leveldb" instance
* @method static ExtendedCacheItemPoolInterface Memcache() Memcache($config = []) Return a driver "memcache" instance
* @method static ExtendedCacheItemPoolInterface Memcached() Memcached($config = []) Return a driver "memcached" instance
* @method static ExtendedCacheItemPoolInterface Mongodb() Mongodb($config = []) Return a driver "mongodb" instance
* @method static ExtendedCacheItemPoolInterface Predis() Predis($config = []) Return a driver "predis" instance
* @method static ExtendedCacheItemPoolInterface Redis() Redis($config = []) Return a driver "redis" instance
* @method static ExtendedCacheItemPoolInterface Sqlite() Sqlite($config = []) Return a driver "sqlite" instance
* @method static ExtendedCacheItemPoolInterface Ssdb() Ssdb($config = []) Return a driver "ssdb" instance
* @method static ExtendedCacheItemPoolInterface Wincache() Wincache($config = []) Return a driver "wincache" instance
* @method static ExtendedCacheItemPoolInterface Xcache() Xcache($config = []) Return a driver "xcache" instance
* @method static ExtendedCacheItemPoolInterface Zenddisk() Zenddisk($config = []) Return a driver "zend disk cache" instance
* @method static ExtendedCacheItemPoolInterface Zendshm() Zendshm($config = []) Return a driver "zend memory cache" instance
*
*/
class CacheManager
{
/**
* @var int
*/
public static $ReadHits = 0;
/**
* @var int
*/
public static $WriteHits = 0;
/**
* @var array
*/
protected static $config = [
'securityKey' => 'auto', // The securityKey that will be used to create the sub-directory
'ignoreSymfonyNotice' => false, // Ignore Symfony notices for Symfony projects that do not makes use of PhpFastCache's Symfony Bundle
'defaultTtl' => 900, // Default time-to-live in seconds
'htaccess' => true, // Auto-generate .htaccess if it is missing
'default_chmod' => 0777, // 0777 is recommended
'path' => '', // If not set will be the value of sys_get_temp_dir()
'fallback' => false, // Fall back when old driver is not supported
'limited_memory_each_object' => 4096, // Maximum size (bytes) of object store in memory
'compress_data' => false, // Compress stored data if the backend supports it
];
/**
* @var string
*/
protected static $namespacePath;
/**
* @var array
*/
protected static $instances = [];
/**
* @param string $driver
* @param array $config
* @return ExtendedCacheItemPoolInterface
*/
public static function getInstance($driver = 'auto', $config = [])
{
static $badPracticeOmeter = [];
/**
* @todo: Standardize a method for driver name
*/
$driver = self::standardizeDriverName($driver);
$config = array_merge(self::$config, $config);
if (!$driver || $driver === 'Auto') {
$driver = self::getAutoClass($config);
}
$instance = crc32($driver . serialize($config));
if (!isset(self::$instances[ $instance ])) {
$badPracticeOmeter[$driver] = 1;
if(!$config['ignoreSymfonyNotice'] && interface_exists('Symfony\Component\HttpKernel\KernelInterface') && !class_exists('phpFastCache\Bundle\phpFastCacheBundle')){
trigger_error('A Symfony Bundle to make the PhpFastCache integration more easier is now available here: https://github.com/PHPSocialNetwork/phpfastcache-bundle', E_USER_NOTICE);
}
$class = self::getNamespacePath() . $driver . '\Driver';
try{
self::$instances[ $instance ] = new $class($config);
}catch(phpFastCacheDriverCheckException $e){
$fallback = self::standardizeDriverName($config['fallback']);
if($fallback && $fallback !== $driver){
$class = self::getNamespacePath() . $fallback . '\Driver';
self::$instances[ $instance ] = new $class($config);
trigger_error(sprintf('The "%s" driver is unavailable at the moment, the fallback driver "%s" has been used instead.', $driver, $fallback), E_USER_WARNING);
}else{
throw new phpFastCacheDriverCheckException($e->getMessage(), $e->getCode(), $e);
}
}
} else if(++$badPracticeOmeter[$driver] >= 5){
trigger_error('[' . $driver . '] Calling many times CacheManager::getInstance() for already instanced drivers is a bad practice and have a significant impact on performances.
See https://github.com/PHPSocialNetwork/phpfastcache/wiki/[V5]-Why-calling-getInstance%28%29-each-time-is-a-bad-practice-%3F');
}
return self::$instances[ $instance ];
}
/**
* @param $config
* @return string
* @throws phpFastCacheDriverCheckException
*/
public static function getAutoClass($config = [])
{
static $autoDriver;
if ($autoDriver === null) {
foreach (self::getStaticSystemDrivers() as $driver) {
try {
self::getInstance($driver, $config);
$autoDriver = $driver;
} catch (phpFastCacheDriverCheckException $e) {
continue;
}
}
}
return $autoDriver;
}
/**
* @param string $name
* @param array $arguments
* @return \Psr\Cache\CacheItemPoolInterface
*/
public static function __callStatic($name, $arguments)
{
$options = (array_key_exists(0, $arguments) && is_array($arguments) ? $arguments[ 0 ] : []);
return self::getInstance($name, $options);
}
/**
* @return bool
*/
public static function clearInstances()
{
self::$instances = [];
gc_collect_cycles();
return !count(self::$instances);
}
/**
* @return string
*/
public static function getNamespacePath()
{
return self::$namespacePath ?: __NAMESPACE__ . '\Drivers\\';
}
/**
* @param string $path
*/
public static function setNamespacePath($path)
{
self::$namespacePath = $path;
}
/**
* @param $name
* @param string $value
* @deprecated Method "setup" is deprecated and will be removed in V6. Use method "setDefaultConfig" instead.
* @throws \InvalidArgumentException
*/
public static function setup($name, $value = '')
{
trigger_error('Method "setup" is deprecated and will be removed in V6 Use method "setDefaultConfig" instead.', E_USER_DEPRECATED);
self::setDefaultConfig($name, $value);
}
/**
* @param $name string|array
* @param mixed $value
* @throws \InvalidArgumentException
*/
public static function setDefaultConfig($name, $value = null)
{
if (is_array($name)) {
self::$config = array_merge(self::$config, $name);
} else if (is_string($name)){
self::$config[ $name ] = $value;
}else{
throw new \InvalidArgumentException('Invalid variable type: $name');
}
}
/**
* @return array
*/
public static function getDefaultConfig()
{
return self::$config;
}
/**
* @return array
*/
public static function getStaticSystemDrivers()
{
return [
'Sqlite',
'Files',
'Apc',
'Apcu',
'Memcache',
'Memcached',
'Couchbase',
'Mongodb',
'Predis',
'Redis',
'Ssdb',
'Leveldb',
'Wincache',
'Xcache',
'Zenddisk',
'Zendshm',
'Devnull',
];
}
/**
* @return array
*/
public static function getStaticAllDrivers()
{
return array_merge(self::getStaticSystemDrivers(), [
'Devtrue',
'Devfalse',
'Cookie',
]);
}
/**
* @param string $driverName
* @return string
*/
public static function standardizeDriverName($driverName)
{
return ucfirst(strtolower(trim($driverName)));
}
}
<?php
/**
*
* This file is part of phpFastCache.
*
* @license MIT License (MIT)
*
* For full copyright and license information, please see the docs/CREDITS.txt file.
*
* @author Khoa Bui (khoaofgod) <khoaofgod@gmail.com> http://www.phpfastcache.com
* @author Georges.L (Geolim4) <contact@geolim4.com>
*
*/
namespace phpFastCache\Core;
/**
* Trait ClassNamespaceResolverTrait
* @package phpFastCache\Core
*/
trait ClassNamespaceResolverTrait
{
/**
* @return string
*/
protected function getClassNamespace()
{
static $namespace;
if (!$namespace) {
$namespace = (new \ReflectionObject($this))->getNamespaceName();
}
return $namespace;
}
}
<?php
/**
*
* This file is part of phpFastCache.
*
* @license MIT License (MIT)
*
* For full copyright and license information, please see the docs/CREDITS.txt file.
*
* @author Khoa Bui (khoaofgod) <khoaofgod@gmail.com> http://www.phpfastcache.com
* @author Georges.L (Geolim4) <contact@geolim4.com>
*
*/
namespace phpFastCache\Core;
use phpFastCache\Cache\DriverBaseTrait;
use phpFastCache\Cache\ExtendedCacheItemPoolInterface;
use Psr\Cache\CacheItemInterface;
/**
* Class DriverAbstract
* @package phpFastCache\Core
*/
abstract class DriverAbstract implements ExtendedCacheItemPoolInterface
{
use DriverBaseTrait;
const DRIVER_CHECK_FAILURE = '%s is not installed or is misconfigured, cannot continue.';
const DRIVER_TAGS_KEY_PREFIX = '_TAG_';
const DRIVER_DATA_WRAPPER_INDEX = 'd';
const DRIVER_TIME_WRAPPER_INDEX = 't';
const DRIVER_TAGS_WRAPPER_INDEX = 'g';
/**
* @param \Psr\Cache\CacheItemInterface $item
* @return array [
* 'd' => 'THE ITEM DATA'
* 't' => 'THE ITEM DATE EXPIRATION'
* 'g' => 'THE ITEM TAGS'
* ]
*
*/
abstract protected function driverRead(CacheItemInterface $item);
/**
* @param \Psr\Cache\CacheItemInterface $item
* @return mixed
*/
abstract protected function driverWrite(CacheItemInterface $item);
/**
* @return bool
*/
abstract protected function driverClear();
/**
* @return bool
*/
abstract protected function driverConnect();
/**
* @param \Psr\Cache\CacheItemInterface $item
* @return bool
*/
abstract protected function driverDelete(CacheItemInterface $item);
}
<?php
/**
*
* This file is part of phpFastCache.
*
* @license MIT License (MIT)
*
* For full copyright and license information, please see the docs/CREDITS.txt file.
*
* @author Khoa Bui (khoaofgod) <khoaofgod@gmail.com> http://www.phpfastcache.com
* @author Georges.L (Geolim4) <contact@geolim4.com>
*
*/
namespace phpFastCache\Core;
use InvalidArgumentException;
use phpFastCache\Cache\ExtendedCacheItemInterface;
use Psr\Cache\CacheItemInterface;
trait ExtendedCacheItemPoolTrait
{
use StandardPsr6StructureTrait;
/**
* Deletes all items in the pool.
* @deprecated Use clear() instead
* Will be removed in 5.1
*
* @return bool
* True if the pool was successfully cleared. False if there was an error.
*/
public function clean()
{
trigger_error('Cache clean() method is deprecated, use clear() method instead', E_USER_DEPRECATED);
return $this->clear();
}
/**
* @param array $keys
* An indexed array of keys of items to retrieve.
* @param int $option json_encode() options
* @param int $depth json_encode() depth
* @return string
* @throws \InvalidArgumentException
*/
public function getItemsAsJsonString(array $keys = [], $option = 0, $depth = 512)
{
$callback = function(CacheItemInterface $item){
return $item->get();
};
return json_encode(array_map($callback, array_values($this->getItems($keys))), $option, $depth);
}
/**
* @param string $tagName
* @return \phpFastCache\Cache\ExtendedCacheItemInterface[]
* @throws InvalidArgumentException
*/
public function getItemsByTag($tagName)
{
if (is_string($tagName)) {
$driverResponse = $this->getItem($this->getTagKey($tagName));
if ($driverResponse->isHit()) {
$items = (array) $driverResponse->get();
/**
* getItems() may provides expired item(s)
* themselves provided by a cache of item
* keys based stored the tag item.
* Therefore we pass a filter callback
* to remove the expired Item(s) provided by
* the item keys passed through getItems()
*
* #headache
*/
return array_filter($this->getItems(array_unique(array_keys($items))), function(ExtendedCacheItemInterface $item){
return $item->isHit();
});
} else {
return [];
}
} else {
throw new InvalidArgumentException('$tagName must be a string');
}
}
/**
* @param array $tagNames
* @return \phpFastCache\Cache\ExtendedCacheItemInterface[]
* @throws InvalidArgumentException
*/
public function getItemsByTags(array $tagNames)
{
$items = [];
foreach (array_unique($tagNames) as $tagName) {
$items = array_merge($items, $this->getItemsByTag($tagName));
}
return $items;
}
/**
* Returns A json string that represents an array of items by tags-based.
*
* @param array $tagNames
* An indexed array of keys of items to retrieve.
* @param int $option json_encode() options
* @param int $depth json_encode() depth
*
* @throws InvalidArgumentException
* If any of the keys in $keys are not a legal value a \Psr\Cache\InvalidArgumentException
* MUST be thrown.
*
* @return string
*/
public function getItemsByTagsAsJsonString(array $tagNames, $option = 0, $depth = 512)
{
$callback = function(CacheItemInterface $item){
return $item->get();
};
return json_encode(array_map($callback, array_values($this->getItemsByTags($tagNames))), $option, $depth);
}
/**
* @param string $tagName
* @return bool|null
* @throws InvalidArgumentException
*/
public function deleteItemsByTag($tagName)
{
if (is_string($tagName)) {
$return = null;
foreach ($this->getItemsByTag($tagName) as $item) {
$result = $this->deleteItem($item->getKey());
if ($return !== false) {
$return = $result;
}
}
return $return;
} else {
throw new InvalidArgumentException('$tagName must be a string');
}
}
/**
* @param array $tagNames
* @return bool|null
* @throws InvalidArgumentException
*/
public function deleteItemsByTags(array $tagNames)
{
$return = null;
foreach ($tagNames as $tagName) {
$result = $this->deleteItemsByTag($tagName);
if ($return !== false) {
$return = $result;
}
}
return $return;
}
/**
* @inheritdoc
*/
public function incrementItemsByTag($tagName, $step = 1)
{
if (is_string($tagName) && is_int($step)) {
foreach ($this->getItemsByTag($tagName) as $item) {
$item->increment($step);
$this->saveDeferred($item);
}
return $this->commit();
} else {
throw new InvalidArgumentException('$tagName must be a string and $step an integer');
}
}
/**
* @inheritdoc
*/
public function incrementItemsByTags(array $tagNames, $step = 1)
{
$return = null;
foreach ($tagNames as $tagName) {
$result = $this->incrementItemsByTag($tagName, $step);
if ($return !== false) {
$return = $result;
}
}
return $return;
}
/**
* @inheritdoc
*/
public function decrementItemsByTag($tagName, $step = 1)
{
if (is_string($tagName) && is_int($step)) {
foreach ($this->getItemsByTag($tagName) as $item) {
$item->decrement($step);
$this->saveDeferred($item);
}
return $this->commit();
} else {
throw new InvalidArgumentException('$tagName must be a string and $step an integer');
}
}
/**
* @inheritdoc
*/
public function decrementItemsByTags(array $tagNames, $step = 1)
{
$return = null;
foreach ($tagNames as $tagName) {
$result = $this->decrementItemsByTag($tagName, $step);
if ($return !== false) {
$return = $result;
}
}
return $return;
}
/**
* @inheritdoc
*/
public function appendItemsByTag($tagName, $data)
{
if (is_string($tagName)) {
foreach ($this->getItemsByTag($tagName) as $item) {
$item->append($data);
$this->saveDeferred($item);
}
return $this->commit();
} else {
throw new InvalidArgumentException('$tagName must be a string');
}
}
/**
* @inheritdoc
*/
public function appendItemsByTags(array $tagNames, $data)
{
$return = null;
foreach ($tagNames as $tagName) {
$result = $this->appendItemsByTag($tagName, $data);
if ($return !== false) {
$return = $result;
}
}
return $return;
}
/**
* @inheritdoc
*/
public function prependItemsByTag($tagName, $data)
{
if (is_string($tagName)) {
foreach ($this->getItemsByTag($tagName) as $item) {
$item->prepend($data);
$this->saveDeferred($item);
}
return $this->commit();
} else {
throw new InvalidArgumentException('$tagName must be a string');
}
}
/**
* @inheritdoc
*/
public function prependItemsByTags(array $tagNames, $data)
{
$return = null;
foreach ($tagNames as $tagName) {
$result = $this->prependItemsByTag($tagName, $data);
if ($return !== false) {
$return = $result;
}
}
return $return;
}
/**
* @param \Psr\Cache\CacheItemInterface $item
* @return void
*/
public function detachItem(CacheItemInterface $item)
{
if(isset($this->itemInstances[$item->getKey()])){
$this->deregisterItem($item);
}
}
/**
* @return void
*/
public function detachAllItems()
{
foreach ($this->itemInstances as $item) {
$this->detachItem($item);
}
}
/**
* @param \Psr\Cache\CacheItemInterface $item
* @return void
* @throws \LogicException
*/
public function attachItem(CacheItemInterface $item)
{
if(isset($this->itemInstances[$item->getKey()]) && spl_object_hash($item) !== spl_object_hash($this->itemInstances[ $item->getKey() ])){
throw new \LogicException('The item already exists and cannot be overwritten because the Spl object hash mismatches ! You probably tried to re-attach a detached item which has been already retrieved from cache.');
}else{
$this->itemInstances[$item->getKey()] = $item;
}
}
/**
* @internal This method de-register an item from $this->itemInstances
* @param CacheItemInterface|string $item
* @throws \InvalidArgumentException
*/
protected function deregisterItem($item)
{
if($item instanceof CacheItemInterface){
unset($this->itemInstances[ $item->getKey() ]);
}else if(is_string($item)){
unset($this->itemInstances[ $item ]);
}else{
throw new \InvalidArgumentException('Invalid type for $item variable');
}
if(gc_enabled()){
gc_collect_cycles();
}
}
/**
* Returns true if the item exists, is attached and the Spl Hash matches
* Returns false if the item exists, is attached and the Spl Hash mismatches
* Returns null if the item does not exists
*
* @param \Psr\Cache\CacheItemInterface $item
* @return bool|null
* @throws \LogicException
*/
public function isAttached(CacheItemInterface $item)
{
if(isset($this->itemInstances[$item->getKey()])){
return spl_object_hash($item) === spl_object_hash($this->itemInstances[ $item->getKey() ]);
}
return null;
}
}
<?php
namespace phpFastCache\Core;
/**
* Trait MemcacheDriverCollisionDetectorTrait
* @package phpFastCache\Core
*/
trait MemcacheDriverCollisionDetectorTrait
{
/**
* @var string
*/
protected static $driverUsed;
/**
* @param $driverName
* @return bool
*/
public static function checkCollision($driverName)
{
$CONSTANT_NAME = __NAMESPACE__ . '\MEMCACHE_DRIVER_USED';
if ($driverName && is_string($driverName)) {
if (!defined($CONSTANT_NAME)) {
define($CONSTANT_NAME, $driverName);
return true;
} else if (constant($CONSTANT_NAME) !== $driverName) {
trigger_error('Memcache collision detected, you used both Memcache and Memcached driver in your script, this may leads to unexpected behaviours',
E_USER_WARNING);
return false;
}
return true;
}
return false;
}
}
<?php
/**
*
* This file is part of phpFastCache.
*
* @license MIT License (MIT)
*
* For full copyright and license information, please see the docs/CREDITS.txt file.
*
* @author Khoa Bui (khoaofgod) <khoaofgod@gmail.com> http://www.phpfastcache.com
* @author Georges.L (Geolim4) <contact@geolim4.com>
*
*/
namespace phpFastCache\Core;
use phpFastCache\Exceptions\phpFastCacheCoreException;
use phpFastCache\Exceptions\phpFastCacheDriverException;
use phpFastCache\Util\Directory;
/**
* Trait PathSeekerTrait
* @package phpFastCache\Core\Pool\IO
* @property array $config The configuration array passed via DriverBaseTrait
*/
trait PathSeekerTrait
{
/**
* @var array
*/
public $tmp = [];
/**
* @param bool $readonly
* @return string
* @throws phpFastCacheDriverException
*/
public function getPath($readonly = false)
{
/**
* Get the base system temporary directory
*/
$tmp_dir = rtrim(ini_get('upload_tmp_dir') ?: sys_get_temp_dir(), '\\/') . DIRECTORY_SEPARATOR . 'phpfastcache';
/**
* Calculate the security key
*/
{
$securityKey = array_key_exists('securityKey', $this->config) ? $this->config[ 'securityKey' ] : '';
if (!$securityKey || $securityKey === 'auto') {
if (isset($_SERVER[ 'HTTP_HOST' ])) {
$securityKey = preg_replace('/^www./', '', strtolower(str_replace(':', '_', $_SERVER[ 'HTTP_HOST' ])));
} else {
$securityKey = ($this->isPHPModule() ? 'web' : 'cli');
}
}
if ($securityKey !== '') {
$securityKey .= '/';
}
$securityKey = static::cleanFileName($securityKey);
}
/**
* Extends the temporary directory
* with the security key and the driver name
*/
$tmp_dir = rtrim($tmp_dir, '/') . DIRECTORY_SEPARATOR;
if (empty($this->config[ 'path' ]) || !is_string($this->config[ 'path' ])) {
$path = $tmp_dir;
} else {
$path = rtrim($this->config[ 'path' ], '/') . DIRECTORY_SEPARATOR;
}
$path_suffix = $securityKey . DIRECTORY_SEPARATOR . $this->getDriverName();
$full_path = Directory::getAbsolutePath($path . $path_suffix);
$full_path_tmp = Directory::getAbsolutePath($tmp_dir . $path_suffix);
$full_path_hash = md5($full_path);
/**
* In readonly mode we only attempt
* to verify if the directory exists
* or not, if it does not then we
* return the temp dir
*/
if ($readonly === true) {
if(!@file_exists($full_path) || !@is_writable($full_path)){
return $full_path_tmp;
}
return $full_path;
}else{
if (!isset($this->tmp[ $full_path_hash ]) || (!@file_exists($full_path) || !@is_writable($full_path))) {
if (!@file_exists($full_path)) {
@mkdir($full_path, $this->setChmodAuto(), true);
}elseif (!@is_writable($full_path)) {
if (!@chmod($full_path, $this->setChmodAuto()))
{
/**
* Switch back to tmp dir
* again if the path is not writable
*/
$full_path = $full_path_tmp;
if (!@file_exists($full_path)) {
@mkdir($full_path, $this->setChmodAuto(), true);
}
}
}
/**
* In case there is no directory
* writable including tye temporary
* one, we must throw an exception
*/
if (!@file_exists($full_path) || !@is_writable($full_path)) {
throw new phpFastCacheDriverException('PLEASE CREATE OR CHMOD ' . $full_path . ' - 0777 OR ANY WRITABLE PERMISSION!');
}
$this->tmp[ $full_path_hash ] = $full_path;
$this->htaccessGen($full_path, array_key_exists('htaccess', $this->config) ? $this->config[ 'htaccess' ] : false);
}
}
return realpath($full_path);
}
/**
* @param $keyword
* @return string
*/
protected function encodeFilename($keyword)
{
return md5($keyword);
}
/**
* @return bool
*/
public function isExpired()
{
trigger_error(__FUNCTION__ . '() is deprecated, use ExtendedCacheItemInterface::isExpired() instead.', E_USER_DEPRECATED);
return true;
}
/**
* @return string
* @throws \phpFastCache\Exceptions\phpFastCacheCoreException
*/
public function getFileDir()
{
return $this->getPath() . DIRECTORY_SEPARATOR . self::FILE_DIR;
}
/**
* @param $keyword
* @param bool $skip
* @return string
* @throws phpFastCacheDriverException
*/
private function getFilePath($keyword, $skip = false)
{
$path = $this->getFileDir();
if ($keyword === false) {
return $path;
}
$filename = $this->encodeFilename($keyword);
$folder = substr($filename, 0, 2);
$path = rtrim($path, '/') . '/' . $folder;
/**
* Skip Create Sub Folders;
*/
if ($skip == false) {
if (!file_exists($path)) {
if (@!mkdir($path, $this->setChmodAuto(), true)) {
throw new phpFastCacheDriverException('PLEASE CHMOD ' . $this->getPath() . ' - ' . $this->setChmodAuto() . ' OR ANY WRITABLE PERMISSION!');
}
}
}
return $path . '/' . $filename . '.txt';
}
/**
* @param $this ->config
* @return int
*/
public function setChmodAuto()
{
if (!isset($this->config[ 'default_chmod' ]) || $this->config[ 'default_chmod' ] == '' || is_null($this->config[ 'default_chmod' ])) {
return 0777;
} else {
return $this->config[ 'default_chmod' ];
}
}
/**
* @param $filename
* @return mixed
*/
protected static function cleanFileName($filename)
{
$regex = [
'/[\?\[\]\/\\\=\<\>\:\;\,\'\"\&\$\#\*\(\)\|\~\`\!\{\}]/',
'/\.$/',
'/^\./',
];
$replace = ['-', '', ''];
return trim(preg_replace($regex, $replace, trim($filename)), '-');
}
/**
* @param $path
* @param bool $create
* @throws \Exception
*/
protected function htaccessGen($path, $create = true)
{
if ($create === true) {
if (!is_writable($path)) {
try {
if(!chmod($path, 0777)){
throw new phpFastCacheDriverException('Chmod failed on : ' . $path);
}
} catch (phpFastCacheDriverException $e) {
throw new phpFastCacheDriverException('PLEASE CHMOD ' . $path . ' - 0777 OR ANY WRITABLE PERMISSION!', 0, $e);
}
}
if (!file_exists($path . "/.htaccess")) {
$html = "order deny, allow \r\n
deny from all \r\n
allow from 127.0.0.1";
$file = @fopen($path . '/.htaccess', 'w+');
if (!$file) {
throw new phpFastCacheDriverException('PLEASE CHMOD ' . $path . ' - 0777 OR ANY WRITABLE PERMISSION!');
}
fwrite($file, $html);
fclose($file);
}
}
}
}
<?php
/**
*
* This file is part of phpFastCache.
*
* @license MIT License (MIT)
*
* For full copyright and license information, please see the docs/CREDITS.txt file.
*
* @author Khoa Bui (khoaofgod) <khoaofgod@gmail.com> http://www.phpfastcache.com
* @author Georges.L (Geolim4) <contact@geolim4.com>
*
*/
namespace phpFastCache\Core;
use phpFastCache\Cache\ExtendedCacheItemInterface;
use phpFastCache\CacheManager;
use phpFastCache\Exceptions\phpFastCacheCoreException;
use Psr\Cache\CacheItemInterface;
/**
* Trait StandardPsr6StructureTrait
* @package phpFastCache\Core
*/
trait StandardPsr6StructureTrait
{
use ClassNamespaceResolverTrait;
/**
* @var array
*/
protected $deferredList = [];
/**
* @var ExtendedCacheItemInterface[]
*/
protected $itemInstances = [];
/**
* @param string $key
* @return \phpFastCache\Cache\ExtendedCacheItemInterface
* @throws \InvalidArgumentException
* @throws phpFastCacheCoreException
*/
public function getItem($key)
{
if (is_string($key)) {
if (!array_key_exists($key, $this->itemInstances)) {
/**
* @var $item ExtendedCacheItemInterface
*/
CacheManager::$ReadHits++;
$class = new \ReflectionClass((new \ReflectionObject($this))->getNamespaceName() . '\Item');
$item = $class->newInstanceArgs([$this, $key]);
$driverArray = $this->driverRead($item);
if ($driverArray) {
if(!is_array($driverArray)){
throw new phpFastCacheCoreException(sprintf('The driverRead method returned an unexpected variable type: %s', gettype($driverArray)));
}
$item->set($this->driverUnwrapData($driverArray));
$item->expiresAt($this->driverUnwrapTime($driverArray));
$item->setTags($this->driverUnwrapTags($driverArray));
if ($item->isExpired()) {
/**
* Using driverDelete() instead of delete()
* to avoid infinite loop caused by
* getItem() call in delete() method
* As we MUST return an item in any
* way, we do not de-register here
*/
$this->driverDelete($item);
} else {
$item->setHit(true);
}
} else {
$item->expiresAfter(abs((int) $this->getConfig()[ 'defaultTtl' ]));
}
}
} else {
throw new \InvalidArgumentException(sprintf('$key must be a string, got type "%s" instead.', gettype($key)));
}
return $this->itemInstances[ $key ];
}
/**
* @param \Psr\Cache\CacheItemInterface $item
* @return $this
* @throws \InvalidArgumentException
*/
public function setItem(CacheItemInterface $item)
{
if ($this->getClassNamespace() . '\\Item' === get_class($item)) {
$this->itemInstances[ $item->getKey() ] = $item;
return $this;
} else {
throw new \InvalidArgumentException(sprintf('Invalid Item Class "%s" for this driver.', get_class($item)));
}
}
/**
* @param array $keys
* @return CacheItemInterface[]
* @throws \InvalidArgumentException
*/
public function getItems(array $keys = [])
{
$collection = [];
foreach ($keys as $key) {
$collection[ $key ] = $this->getItem($key);
}
return $collection;
}
/**
* @param string $key
* @return bool
* @throws \InvalidArgumentException
*/
public function hasItem($key)
{
CacheManager::$ReadHits++;
return $this->getItem($key)->isHit();
}
/**
* @return bool
*/
public function clear()
{
CacheManager::$WriteHits++;
$this->itemInstances = [];
return $this->driverClear();
}
/**
* @param string $key
* @return bool
* @throws \InvalidArgumentException
*/
public function deleteItem($key)
{
$item = $this->getItem($key);
if ($this->hasItem($key) && $this->driverDelete($item)) {
$item->setHit(false);
CacheManager::$WriteHits++;
/**
* De-register the item instance
* then collect gc cycles
*/
$this->deregisterItem($key);
return true;
}
return false;
}
/**
* @param array $keys
* @return bool
* @throws \InvalidArgumentException
*/
public function deleteItems(array $keys)
{
$return = null;
foreach ($keys as $key) {
$result = $this->deleteItem($key);
if ($result !== false) {
$return = $result;
}
}
return (bool) $return;
}
/**
* @param \Psr\Cache\CacheItemInterface $item
* @return mixed
* @throws \InvalidArgumentException
* @throws \RuntimeException
*/
public function save(CacheItemInterface $item)
{
/**
* @var ExtendedCacheItemInterface $item
*/
if (!array_key_exists($item->getKey(), $this->itemInstances)) {
$this->itemInstances[ $item->getKey() ] = $item;
} else if(spl_object_hash($item) !== spl_object_hash($this->itemInstances[ $item->getKey() ])){
throw new \RuntimeException('Spl object hash mismatches ! You probably tried to save a detached item which has been already retrieved from cache.');
}
if ($this->driverWrite($item) && $this->driverWriteTags($item)) {
$item->setHit(true);
CacheManager::$WriteHits++;
return true;
}
return false;
}
/**
* @param \Psr\Cache\CacheItemInterface $item
* @return \Psr\Cache\CacheItemInterface
* @throws \RuntimeException
*/
public function saveDeferred(CacheItemInterface $item)
{
if (!array_key_exists($item->getKey(), $this->itemInstances)) {
$this->itemInstances[ $item->getKey() ] = $item;
}else if(spl_object_hash($item) !== spl_object_hash($this->itemInstances[ $item->getKey() ])){
throw new \RuntimeException('Spl object hash mismatches ! You probably tried to save a detached item which has been already retrieved from cache.');
}
return $this->deferredList[ $item->getKey() ] = $item;
}
/**
* @return mixed|null
* @throws \InvalidArgumentException
*/
public function commit()
{
$return = null;
foreach ($this->deferredList as $key => $item) {
$result = $this->save($item);
if ($return !== false) {
unset($this->deferredList[ $key ]);
$return = $result;
}
}
return (bool) $return;
}
}
<?php
/**
*
* This file is part of phpFastCache.
*
* @license MIT License (MIT)
*
* For full copyright and license information, please see the docs/CREDITS.txt file.
*
* @author Khoa Bui (khoaofgod) <khoaofgod@gmail.com> http://www.phpfastcache.com
* @author Georges.L (Geolim4) <contact@geolim4.com>
*
*/
namespace phpFastCache\Drivers\Apc;
use phpFastCache\Core\DriverAbstract;
use phpFastCache\Core\StandardPsr6StructureTrait;
use phpFastCache\Entities\driverStatistic;
use phpFastCache\Exceptions\phpFastCacheDriverCheckException;
use phpFastCache\Exceptions\phpFastCacheDriverException;
use Psr\Cache\CacheItemInterface;
/**
* Class Driver
* @package phpFastCache\Drivers
*/
class Driver extends DriverAbstract
{
/**
* Driver constructor.
* @param array $config
* @throws phpFastCacheDriverException
*/
public function __construct(array $config = [])
{
$this->setup($config);
if (!$this->driverCheck()) {
throw new phpFastCacheDriverCheckException(sprintf(self::DRIVER_CHECK_FAILURE, $this->getDriverName()));
}
}
/**
* @return bool
*/
public function driverCheck()
{
if (extension_loaded('apc') && ini_get('apc.enabled')) {
return true;
} else {
return false;
}
}
/**
* @param \Psr\Cache\CacheItemInterface $item
* @return mixed
* @throws \InvalidArgumentException
*/
protected function driverWrite(CacheItemInterface $item)
{
/**
* Check for Cross-Driver type confusion
*/
if ($item instanceof Item) {
$ttl = $item->getExpirationDate()->getTimestamp() - time();
return apc_store($item->getKey(), $this->driverPreWrap($item), ($ttl > 0 ? $ttl : 0));
} else {
throw new \InvalidArgumentException('Cross-Driver type confusion detected');
}
}
/**
* @param \Psr\Cache\CacheItemInterface $item
* @return mixed
*/
protected function driverRead(CacheItemInterface $item)
{
$data = apc_fetch($item->getKey(), $success);
if ($success === false) {
return null;
}
return $data;
}
/**
* @param \Psr\Cache\CacheItemInterface $item
* @return bool
* @throws \InvalidArgumentException
*/
protected function driverDelete(CacheItemInterface $item)
{
/**
* Check for Cross-Driver type confusion
*/
if ($item instanceof Item) {
return apc_delete($item->getKey());
} else {
throw new \InvalidArgumentException('Cross-Driver type confusion detected');
}
}
/**
* @return bool
*/
protected function driverClear()
{
return @apc_clear_cache() && @apc_clear_cache('user');
}
/**
* @return bool
*/
protected function driverConnect()
{
return true;
}
/********************
*
* PSR-6 Extended Methods
*
*******************/
/**
* @return driverStatistic
*/
public function getStats()
{
$stats = (array) apc_cache_info('user');
$date = (new \DateTime())->setTimestamp($stats[ 'start_time' ]);
return (new driverStatistic())
->setData(implode(', ', array_keys($this->itemInstances)))
->setInfo(sprintf("The APC cache is up since %s, and have %d item(s) in cache.\n For more information see RawData.", $date->format(DATE_RFC2822),
$stats[ 'num_entries' ]))
->setRawData($stats)
->setSize($stats[ 'mem_size' ]);
}
}
<?php
/**
*
* This file is part of phpFastCache.
*
* @license MIT License (MIT)
*
* For full copyright and license information, please see the docs/CREDITS.txt file.
*
* @author Khoa Bui (khoaofgod) <khoaofgod@gmail.com> http://www.phpfastcache.com
* @author Georges.L (Geolim4) <contact@geolim4.com>
*
*/
namespace phpFastCache\Drivers\Apc;
use phpFastCache\Cache\ExtendedCacheItemInterface;
use phpFastCache\Cache\ExtendedCacheItemPoolInterface;
use phpFastCache\Cache\ItemBaseTrait;
use phpFastCache\Drivers\Apc\Driver as ApcDriver;
/**
* Class Item
* @package phpFastCache\Drivers\Apc
*/
class Item implements ExtendedCacheItemInterface
{
use ItemBaseTrait;
/**
* Item constructor.
* @param \phpFastCache\Drivers\Apc\Driver $driver
* @param $key
* @throws \InvalidArgumentException
*/
public function __construct(ApcDriver $driver, $key)
{
if (is_string($key)) {
$this->key = $key;
$this->driver = $driver;
$this->driver->setItem($this);
$this->expirationDate = new \DateTime();
} else {
throw new \InvalidArgumentException(sprintf('$key must be a string, got type "%s" instead.', gettype($key)));
}
}
/**
* @param ExtendedCacheItemPoolInterface $driver
* @throws \InvalidArgumentException
* @return static
*/
public function setDriver(ExtendedCacheItemPoolInterface $driver)
{
if ($driver instanceof ApcDriver) {
$this->driver = $driver;
return $this;
} else {
throw new \InvalidArgumentException('Invalid driver instance');
}
}
}
<?php
/**
*
* This file is part of phpFastCache.
*
* @license MIT License (MIT)
*
* For full copyright and license information, please see the docs/CREDITS.txt file.
*
* @author Khoa Bui (khoaofgod) <khoaofgod@gmail.com> http://www.phpfastcache.com
* @author Georges.L (Geolim4) <contact@geolim4.com>
*
*/
namespace phpFastCache\Drivers\Apcu;
use phpFastCache\Core\DriverAbstract;
use phpFastCache\Core\StandardPsr6StructureTrait;
use phpFastCache\Entities\driverStatistic;
use phpFastCache\Exceptions\phpFastCacheDriverCheckException;
use phpFastCache\Exceptions\phpFastCacheDriverException;
use Psr\Cache\CacheItemInterface;
/**
* Class Driver
* @package phpFastCache\Drivers
*/
class Driver extends DriverAbstract
{
/**
* Driver constructor.
* @param array $config
* @throws phpFastCacheDriverException
*/
public function __construct(array $config = [])
{
$this->setup($config);
if (!$this->driverCheck()) {
throw new phpFastCacheDriverCheckException(sprintf(self::DRIVER_CHECK_FAILURE, $this->getDriverName()));
}
}
/**
* @return bool
*/
public function driverCheck()
{
if (extension_loaded('apcu') && ini_get('apc.enabled')) {
return true;
} else {
return false;
}
}
/**
* @param \Psr\Cache\CacheItemInterface $item
* @return mixed
* @throws \InvalidArgumentException
*/
protected function driverWrite(CacheItemInterface $item)
{
/**
* Check for Cross-Driver type confusion
*/
if ($item instanceof Item) {
$ttl = $item->getExpirationDate()->getTimestamp() - time();
return apcu_store($item->getKey(), $this->driverPreWrap($item), ($ttl > 0 ? $ttl : 0));
} else {
throw new \InvalidArgumentException('Cross-Driver type confusion detected');
}
}
/**
* @param \Psr\Cache\CacheItemInterface $item
* @return mixed
*/
protected function driverRead(CacheItemInterface $item)
{
$data = apcu_fetch($item->getKey(), $success);
if ($success === false) {
return null;
}
return $data;
}
/**
* @param \Psr\Cache\CacheItemInterface $item
* @return bool
* @throws \InvalidArgumentException
*/
protected function driverDelete(CacheItemInterface $item)
{
/**
* Check for Cross-Driver type confusion
*/
if ($item instanceof Item) {
return apcu_delete($item->getKey());
} else {
throw new \InvalidArgumentException('Cross-Driver type confusion detected');
}
}
/**
* @return bool
*/
protected function driverClear()
{
return @apcu_clear_cache() && @apcu_clear_cache('user');
}
/**
* @return bool
*/
protected function driverConnect()
{
return true;
}
/********************
*
* PSR-6 Extended Methods
*
*******************/
/**
* @return driverStatistic
*/
public function getStats()
{
$stats = (array) apcu_cache_info('user');
$date = (new \DateTime())->setTimestamp($stats[ 'start_time' ]);
return (new driverStatistic())
->setData(implode(', ', array_keys($this->itemInstances)))
->setInfo(sprintf("The APCU cache is up since %s, and have %d item(s) in cache.\n For more information see RawData.", $date->format(DATE_RFC2822), $stats[ 'num_entries' ]))
->setRawData($stats)
->setSize($stats[ 'mem_size' ]);
}
}
<?php
/**
*
* This file is part of phpFastCache.
*
* @license MIT License (MIT)
*
* For full copyright and license information, please see the docs/CREDITS.txt file.
*
* @author Khoa Bui (khoaofgod) <khoaofgod@gmail.com> http://www.phpfastcache.com
* @author Georges.L (Geolim4) <contact@geolim4.com>
*
*/
namespace phpFastCache\Drivers\Apcu;
use phpFastCache\Cache\ExtendedCacheItemInterface;
use phpFastCache\Cache\ExtendedCacheItemPoolInterface;
use phpFastCache\Cache\ItemBaseTrait;
use phpFastCache\Drivers\Apcu\Driver as ApcuDriver;
/**
* Class Item
* @package phpFastCache\Drivers\Apcu
*/
class Item implements ExtendedCacheItemInterface
{
use ItemBaseTrait;
/**
* Item constructor.
* @param \phpFastCache\Drivers\Apcu\Driver $driver
* @param $key
* @throws \InvalidArgumentException
*/
public function __construct(ApcuDriver $driver, $key)
{
if (is_string($key)) {
$this->key = $key;
$this->driver = $driver;
$this->driver->setItem($this);
$this->expirationDate = new \DateTime();
} else {
throw new \InvalidArgumentException(sprintf('$key must be a string, got type "%s" instead.', gettype($key)));
}
}
/**
* @param ExtendedCacheItemPoolInterface $driver
* @throws \InvalidArgumentException
* @return static
*/
public function setDriver(ExtendedCacheItemPoolInterface $driver)
{
if ($driver instanceof ApcuDriver) {
$this->driver = $driver;
return $this;
} else {
throw new \InvalidArgumentException('Invalid driver instance');
}
}
}
<?php
/**
*
* This file is part of phpFastCache.
*
* @license MIT License (MIT)
*
* For full copyright and license information, please see the docs/CREDITS.txt file.
*
* @author Khoa Bui (khoaofgod) <khoaofgod@gmail.com> http://www.phpfastcache.com
* @author Georges.L (Geolim4) <contact@geolim4.com>
*
*/
namespace phpFastCache\Drivers\Couchbase;
use CouchbaseCluster as CouchbaseClient;
use phpFastCache\Core\DriverAbstract;
use phpFastCache\Core\StandardPsr6StructureTrait;
use phpFastCache\Entities\driverStatistic;
use phpFastCache\Exceptions\phpFastCacheDriverCheckException;
use phpFastCache\Exceptions\phpFastCacheDriverException;
use Psr\Cache\CacheItemInterface;
/**
* Class Driver
* @package phpFastCache\Drivers
*/
class Driver extends DriverAbstract
{
/**
* @var CouchbaseClient
*/
public $instance;
/**
* @var \CouchbaseBucket[]
*/
protected $bucketInstances = [];
/**
* @var string
*/
protected $bucketCurrent = '';
/**
* Driver constructor.
* @param array $config
* @throws phpFastCacheDriverException
*/
public function __construct(array $config = [])
{
$this->setup($config);
if (!$this->driverCheck()) {
throw new phpFastCacheDriverCheckException(sprintf(self::DRIVER_CHECK_FAILURE, $this->getDriverName()));
} else {
$this->driverConnect();
}
}
/**
* @return bool
*/
public function driverCheck()
{
return extension_loaded('Couchbase');
}
/**
* @param \Psr\Cache\CacheItemInterface $item
* @return mixed
* @throws \InvalidArgumentException
*/
protected function driverWrite(CacheItemInterface $item)
{
/**
* Check for Cross-Driver type confusion
*/
if ($item instanceof Item) {
return $this->getBucket()->upsert($item->getKey(), $this->encode($this->driverPreWrap($item)), ['expiry' => $item->getTtl()]);
} else {
throw new \InvalidArgumentException('Cross-Driver type confusion detected');
}
}
/**
* @param \Psr\Cache\CacheItemInterface $item
* @return mixed
*/
protected function driverRead(CacheItemInterface $item)
{
try {
/**
* CouchbaseBucket::get() returns a CouchbaseMetaDoc object
*/
return $this->decode($this->getBucket()->get($item->getKey())->value);
} catch (\CouchbaseException $e) {
return null;
}
}
/**
* @param \Psr\Cache\CacheItemInterface $item
* @return bool
* @throws \InvalidArgumentException
*/
protected function driverDelete(CacheItemInterface $item)
{
/**
* Check for Cross-Driver type confusion
*/
if ($item instanceof Item) {
return $this->getBucket()->remove($item->getKey());
} else {
throw new \InvalidArgumentException('Cross-Driver type confusion detected');
}
}
/**
* @return bool
*/
protected function driverClear()
{
return $this->getBucket()->manager()->flush();
}
/**
* @return bool
*/
protected function driverConnect()
{
if ($this->instance instanceof CouchbaseClient) {
throw new \LogicException('Already connected to Couchbase server');
} else {
$host = isset($this->config[ 'host' ]) ? $this->config[ 'host' ] : '127.0.0.1';
//$port = isset($server[ 'port' ]) ? $server[ 'port' ] : '11211';
$password = isset($this->config[ 'password' ]) ? $this->config[ 'password' ] : '';
$username = isset($this->config[ 'username' ]) ? $this->config[ 'username' ] : '';
$buckets = isset($this->config[ 'buckets' ]) ? $this->config[ 'buckets' ] : [
[
'bucket' => 'default',
'password' => '',
],
];
$this->instance = $this->instance ?: new CouchbaseClient("couchbase://{$host}", $username, $password);
foreach ($buckets as $bucket) {
$this->bucketCurrent = $this->bucketCurrent ?: $bucket[ 'bucket' ];
$this->setBucket($bucket[ 'bucket' ], $this->instance->openBucket($bucket[ 'bucket' ], $bucket[ 'password' ]));
}
}
}
/**
* @return \CouchbaseBucket
*/
protected function getBucket()
{
return $this->bucketInstances[ $this->bucketCurrent ];
}
/**
* @param $bucketName
* @param \CouchbaseBucket $CouchbaseBucket
* @throws \LogicException
*/
protected function setBucket($bucketName, \CouchbaseBucket $CouchbaseBucket)
{
if (!array_key_exists($bucketName, $this->bucketInstances)) {
$this->bucketInstances[ $bucketName ] = $CouchbaseBucket;
} else {
throw new \LogicException('A bucket instance with this name already exists.');
}
}
/********************
*
* PSR-6 Extended Methods
*
*******************/
/**
* @return driverStatistic
*/
public function getStats()
{
$info = $this->getBucket()->manager()->info();
return (new driverStatistic())
->setSize($info[ 'basicStats' ][ 'diskUsed' ])
->setRawData($info)
->setData(implode(', ', array_keys($this->itemInstances)))
->setInfo('CouchBase version ' . $info[ 'nodes' ][ 0 ][ 'version' ] . ', Uptime (in days): ' . round($info[ 'nodes' ][ 0 ][ 'uptime' ] / 86400, 1) . "\n For more information see RawData.");
}
}
<?php
/**
*
* This file is part of phpFastCache.
*
* @license MIT License (MIT)
*
* For full copyright and license information, please see the docs/CREDITS.txt file.
*
* @author Khoa Bui (khoaofgod) <khoaofgod@gmail.com> http://www.phpfastcache.com
* @author Georges.L (Geolim4) <contact@geolim4.com>
*
*/
namespace phpFastCache\Drivers\Couchbase;
use phpFastCache\Cache\ExtendedCacheItemInterface;
use phpFastCache\Cache\ExtendedCacheItemPoolInterface;
use phpFastCache\Cache\ItemBaseTrait;
use phpFastCache\Drivers\Couchbase\Driver as CouchbaseDriver;
/**
* Class Item
* @package phpFastCache\Drivers\Apc
*/
class Item implements ExtendedCacheItemInterface
{
use ItemBaseTrait;
/**
* Item constructor.
* @param \phpFastCache\Drivers\Couchbase\Driver $driver
* @param $key
* @throws \InvalidArgumentException
*/
public function __construct(CouchbaseDriver $driver, $key)
{
if (is_string($key)) {
$this->key = $key;
$this->driver = $driver;
$this->driver->setItem($this);
$this->expirationDate = new \DateTime();
} else {
throw new \InvalidArgumentException(sprintf('$key must be a string, got type "%s" instead.', gettype($key)));
}
}
/**
* @param ExtendedCacheItemPoolInterface $driver
* @throws \InvalidArgumentException
* @return static
*/
public function setDriver(ExtendedCacheItemPoolInterface $driver)
{
if ($driver instanceof CouchbaseDriver) {
$this->driver = $driver;
return $this;
} else {
throw new \InvalidArgumentException('Invalid driver instance');
}
}
}
<?php
/**
*
* This file is part of phpFastCache.
*
* @license MIT License (MIT)
*
* For full copyright and license information, please see the docs/CREDITS.txt file.
*
* @author Khoa Bui (khoaofgod) <khoaofgod@gmail.com> http://www.phpfastcache.com
* @author Georges.L (Geolim4) <contact@geolim4.com>
*
*/
namespace phpFastCache\Drivers\Devfalse;
use phpFastCache\Core\DriverAbstract;
use phpFastCache\Entities\driverStatistic;
use phpFastCache\Exceptions\phpFastCacheDriverCheckException;
use phpFastCache\Exceptions\phpFastCacheDriverException;
use Psr\Cache\CacheItemInterface;
/**
* Class Driver
* @package phpFastCache\Drivers
*/
class Driver extends DriverAbstract
{
/**
* Driver constructor.
* @param array $config
* @throws phpFastCacheDriverException
*/
public function __construct(array $config = [])
{
$this->setup($config);
if (!$this->driverCheck()) {
throw new phpFastCacheDriverCheckException(sprintf(self::DRIVER_CHECK_FAILURE, $this->getDriverName()));
}
}
/**
* @return bool
*/
public function driverCheck()
{
return true;
}
/**
* @param \Psr\Cache\CacheItemInterface $item
* @return mixed
* @throws \InvalidArgumentException
*/
protected function driverWrite(CacheItemInterface $item)
{
/**
* Check for Cross-Driver type confusion
*/
if ($item instanceof Item) {
return true;
} else {
throw new \InvalidArgumentException('Cross-Driver type confusion detected');
}
}
/**
* @param \Psr\Cache\CacheItemInterface $item
* @return array [
* 'd' => 'THE ITEM DATA'
* 't' => 'THE ITEM DATE EXPIRATION'
* 'g' => 'THE ITEM TAGS'
* ]
*/
protected function driverRead(CacheItemInterface $item)
{
return [
self::DRIVER_DATA_WRAPPER_INDEX => false,
self::DRIVER_TAGS_WRAPPER_INDEX => [],
self::DRIVER_TIME_WRAPPER_INDEX => new \DateTime(),
];
}
/**
* @param \Psr\Cache\CacheItemInterface $item
* @return bool
* @throws \InvalidArgumentException
*/
protected function driverDelete(CacheItemInterface $item)
{
/**
* Check for Cross-Driver type confusion
*/
if ($item instanceof Item) {
return true;
} else {
throw new \InvalidArgumentException('Cross-Driver type confusion detected');
}
}
/**
* @return bool
*/
protected function driverClear()
{
return true;
}
/**
* @return bool
*/
protected function driverConnect()
{
return true;
}
/********************
*
* PSR-6 Extended Methods
*
*******************/
/**
* @return driverStatistic
*/
public function getStats()
{
$stat = new driverStatistic();
$stat->setInfo('[Devfalse] A void info string')
->setSize(0)
->setData(implode(', ', array_keys($this->itemInstances)))
->setRawData(false);
return $stat;
}
}
<?php
/**
*
* This file is part of phpFastCache.
*
* @license MIT License (MIT)
*
* For full copyright and license information, please see the docs/CREDITS.txt file.
*
* @author Khoa Bui (khoaofgod) <khoaofgod@gmail.com> http://www.phpfastcache.com
* @author Georges.L (Geolim4) <contact@geolim4.com>
*
*/
namespace phpFastCache\Drivers\Devfalse;
use phpFastCache\Cache\ExtendedCacheItemInterface;
use phpFastCache\Cache\ExtendedCacheItemPoolInterface;
use phpFastCache\Cache\ItemBaseTrait;
use phpFastCache\Drivers\Devnull\Driver as DevnullDriver;
/**
* Class Item
* @package phpFastCache\Drivers\Devnull
*/
class Item implements ExtendedCacheItemInterface
{
use ItemBaseTrait;
/**
* Item constructor.
* @param \phpFastCache\Drivers\Devnull\Driver $driver
* @param $key
* @throws \InvalidArgumentException
*/
public function __construct(DevnullDriver $driver, $key)
{
if (is_string($key)) {
$this->key = $key;
$this->driver = $driver;
$this->driver->setItem($this);
$this->expirationDate = new \DateTime();
} else {
throw new \InvalidArgumentException(sprintf('$key must be a string, got type "%s" instead.', gettype($key)));
}
}
/**
* @param ExtendedCacheItemPoolInterface $driver
* @throws \InvalidArgumentException
* @return static
*/
public function setDriver(ExtendedCacheItemPoolInterface $driver)
{
if ($driver instanceof DevnullDriver) {
$this->driver = $driver;
return $this;
} else {
throw new \InvalidArgumentException('Invalid driver instance');
}
}
}
<?php
/**
*
* This file is part of phpFastCache.
*
* @license MIT License (MIT)
*
* For full copyright and license information, please see the docs/CREDITS.txt file.
*
* @author Khoa Bui (khoaofgod) <khoaofgod@gmail.com> http://www.phpfastcache.com
* @author Georges.L (Geolim4) <contact@geolim4.com>
*
*/
namespace phpFastCache\Drivers\Devnull;
use phpFastCache\Core\DriverAbstract;
use phpFastCache\Core\StandardPsr6StructureTrait;
use phpFastCache\Entities\driverStatistic;
use phpFastCache\Exceptions\phpFastCacheDriverCheckException;
use phpFastCache\Exceptions\phpFastCacheDriverException;
use Psr\Cache\CacheItemInterface;
/**
* Class Driver
* @package phpFastCache\Drivers
*/
class Driver extends DriverAbstract
{
/**
* Driver constructor.
* @param array $config
* @throws phpFastCacheDriverException
*/
public function __construct(array $config = [])
{
$this->setup($config);
if (!$this->driverCheck()) {
throw new phpFastCacheDriverCheckException(sprintf(self::DRIVER_CHECK_FAILURE, $this->getDriverName()));
}
}
/**
* @return bool
*/
public function driverCheck()
{
return true;
}
/**
* @param \Psr\Cache\CacheItemInterface $item
* @return mixed
* @throws \InvalidArgumentException
*/
protected function driverWrite(CacheItemInterface $item)
{
/**
* Check for Cross-Driver type confusion
*/
if ($item instanceof Item) {
return true;
} else {
throw new \InvalidArgumentException('Cross-Driver type confusion detected');
}
}
/**
* @param \Psr\Cache\CacheItemInterface $item
* @return array [
* 'd' => 'THE ITEM DATA'
* 't' => 'THE ITEM DATE EXPIRATION'
* 'g' => 'THE ITEM TAGS'
* ]
*/
protected function driverRead(CacheItemInterface $item)
{
return [
self::DRIVER_DATA_WRAPPER_INDEX => null,
self::DRIVER_TAGS_WRAPPER_INDEX => [],
self::DRIVER_TIME_WRAPPER_INDEX => new \DateTime(),
];
}
/**
* @param \Psr\Cache\CacheItemInterface $item
* @return bool
* @throws \InvalidArgumentException
*/
protected function driverDelete(CacheItemInterface $item)
{
/**
* Check for Cross-Driver type confusion
*/
if ($item instanceof Item) {
return true;
} else {
throw new \InvalidArgumentException('Cross-Driver type confusion detected');
}
}
/**
* @return bool
*/
protected function driverClear()
{
return true;
}
/**
* @return bool
*/
protected function driverConnect()
{
return true;
}
/********************
*
* PSR-6 Extended Methods
*
*******************/
/**
* @return driverStatistic
*/
public function getStats()
{
$stat = new driverStatistic();
$stat->setInfo('[Devnull] A void info string')
->setSize(0)
->setData(implode(', ', array_keys($this->itemInstances)))
->setRawData(null);
return $stat;
}
}
<?php
/**
*
* This file is part of phpFastCache.
*
* @license MIT License (MIT)
*
* For full copyright and license information, please see the docs/CREDITS.txt file.
*
* @author Khoa Bui (khoaofgod) <khoaofgod@gmail.com> http://www.phpfastcache.com
* @author Georges.L (Geolim4) <contact@geolim4.com>
*
*/
namespace phpFastCache\Drivers\Devnull;
use phpFastCache\Cache\ExtendedCacheItemInterface;
use phpFastCache\Cache\ExtendedCacheItemPoolInterface;
use phpFastCache\Cache\ItemBaseTrait;
use phpFastCache\Drivers\Devnull\Driver as DevnullDriver;
/**
* Class Item
* @package phpFastCache\Drivers\Devnull
*/
class Item implements ExtendedCacheItemInterface
{
use ItemBaseTrait;
/**
* Item constructor.
* @param \phpFastCache\Drivers\Devnull\Driver $driver
* @param $key
* @throws \InvalidArgumentException
*/
public function __construct(DevnullDriver $driver, $key)
{
if (is_string($key)) {
$this->key = $key;
$this->driver = $driver;
$this->driver->setItem($this);
$this->expirationDate = new \DateTime();
} else {
throw new \InvalidArgumentException(sprintf('$key must be a string, got type "%s" instead.', gettype($key)));
}
}
/**
* @param ExtendedCacheItemPoolInterface $driver
* @throws \InvalidArgumentException
* @return static
*/
public function setDriver(ExtendedCacheItemPoolInterface $driver)
{
if ($driver instanceof DevnullDriver) {
$this->driver = $driver;
return $this;
} else {
throw new \InvalidArgumentException('Invalid driver instance');
}
}
}
<?php
/**
*
* This file is part of phpFastCache.
*
* @license MIT License (MIT)
*
* For full copyright and license information, please see the docs/CREDITS.txt file.
*
* @author Khoa Bui (khoaofgod) <khoaofgod@gmail.com> http://www.phpfastcache.com
* @author Georges.L (Geolim4) <contact@geolim4.com>
*
*/
namespace phpFastCache\Drivers\Devtrue;
use phpFastCache\Core\DriverAbstract;
use phpFastCache\Core\StandardPsr6StructureTrait;
use phpFastCache\Entities\driverStatistic;
use phpFastCache\Exceptions\phpFastCacheDriverCheckException;
use phpFastCache\Exceptions\phpFastCacheDriverException;
use Psr\Cache\CacheItemInterface;
/**
* Class Driver
* @package phpFastCache\Drivers
*/
class Driver extends DriverAbstract
{
/**
* Driver constructor.
* @param array $config
* @throws phpFastCacheDriverException
*/
public function __construct(array $config = [])
{
$this->setup($config);
if (!$this->driverCheck()) {
throw new phpFastCacheDriverCheckException(sprintf(self::DRIVER_CHECK_FAILURE, $this->getDriverName()));
}
}
/**
* @return bool
*/
public function driverCheck()
{
return true;
}
/**
* @param \Psr\Cache\CacheItemInterface $item
* @return mixed
* @throws \InvalidArgumentException
*/
protected function driverWrite(CacheItemInterface $item)
{
/**
* Check for Cross-Driver type confusion
*/
if ($item instanceof Item) {
return false;
} else {
throw new \InvalidArgumentException('Cross-Driver type confusion detected');
}
}
/**
* @param \Psr\Cache\CacheItemInterface $item
* @return array [
* 'd' => 'THE ITEM DATA'
* 't' => 'THE ITEM DATE EXPIRATION'
* 'g' => 'THE ITEM TAGS'
* ]
*/
protected function driverRead(CacheItemInterface $item)
{
return [
self::DRIVER_DATA_WRAPPER_INDEX => true,
self::DRIVER_TAGS_WRAPPER_INDEX => [],
self::DRIVER_TIME_WRAPPER_INDEX => new \DateTime(),
];
}
/**
* @param \Psr\Cache\CacheItemInterface $item
* @return bool
* @throws \InvalidArgumentException
*/
protected function driverDelete(CacheItemInterface $item)
{
/**
* Check for Cross-Driver type confusion
*/
if ($item instanceof Item) {
return false;
} else {
throw new \InvalidArgumentException('Cross-Driver type confusion detected');
}
}
/**
* @return bool
*/
protected function driverClear()
{
return false;
}
/**
* @return bool
*/
protected function driverConnect()
{
return false;
}
/********************
*
* PSR-6 Extended Methods
*
*******************/
/**
* @return driverStatistic
*/
public function getStats()
{
$stat = new driverStatistic();
$stat->setInfo('[Devtrue] A void info string')
->setSize(0)
->setData(implode(', ', array_keys($this->itemInstances)))
->setRawData(true);
return $stat;
}
}
<?php
/**
*
* This file is part of phpFastCache.
*
* @license MIT License (MIT)
*
* For full copyright and license information, please see the docs/CREDITS.txt file.
*
* @author Khoa Bui (khoaofgod) <khoaofgod@gmail.com> http://www.phpfastcache.com
* @author Georges.L (Geolim4) <contact@geolim4.com>
*
*/
namespace phpFastCache\Drivers\Devtrue;
use phpFastCache\Cache\ExtendedCacheItemInterface;
use phpFastCache\Cache\ExtendedCacheItemPoolInterface;
use phpFastCache\Cache\ItemBaseTrait;
use phpFastCache\Drivers\Devtrue\Driver as DevtrueDriver;
/**
* Class Item
* @package phpFastCache\Drivers\Devtrue
*/
class Item implements ExtendedCacheItemInterface
{
use ItemBaseTrait;
/**
* Item constructor.
* @param \phpFastCache\Drivers\Devtrue\Driver $driver
* @param $key
* @throws \InvalidArgumentException
*/
public function __construct(DevtrueDriver $driver, $key)
{
if (is_string($key)) {
$this->key = $key;
$this->driver = $driver;
$this->driver->setItem($this);
$this->expirationDate = new \DateTime();
} else {
throw new \InvalidArgumentException(sprintf('$key must be a string, got type "%s" instead.', gettype($key)));
}
}
/**
* @param ExtendedCacheItemPoolInterface $driver
* @throws \InvalidArgumentException
* @return static
*/
public function setDriver(ExtendedCacheItemPoolInterface $driver)
{
if ($driver instanceof DevtrueDriver) {
$this->driver = $driver;
return $this;
} else {
throw new \InvalidArgumentException('Invalid driver instance');
}
}
}
<?php
/**
*
* This file is part of phpFastCache.
*
* @license MIT License (MIT)
*
* For full copyright and license information, please see the docs/CREDITS.txt file.
*
* @author Khoa Bui (khoaofgod) <khoaofgod@gmail.com> http://www.phpfastcache.com
* @author Georges.L (Geolim4) <contact@geolim4.com>
*
*/
namespace phpFastCache\Drivers\Files;
use phpFastCache\Core\DriverAbstract;
use phpFastCache\Core\PathSeekerTrait;
use phpFastCache\Core\StandardPsr6StructureTrait;
use phpFastCache\Entities\driverStatistic;
use phpFastCache\Exceptions\phpFastCacheDriverCheckException;
use phpFastCache\Exceptions\phpFastCacheDriverException;
use phpFastCache\Util\Directory;
use Psr\Cache\CacheItemInterface;
/**
* Class Driver
* @package phpFastCache\Drivers
*/
class Driver extends DriverAbstract
{
use PathSeekerTrait;
/**
*
*/
const FILE_DIR = 'files';
/**
* Driver constructor.
* @param array $config
* @throws phpFastCacheDriverException
*/
public function __construct(array $config = [])
{
$this->setup($config);
if (!$this->driverCheck()) {
throw new phpFastCacheDriverCheckException(sprintf(self::DRIVER_CHECK_FAILURE, $this->getDriverName()));
}
}
/**
* @return bool
*/
public function driverCheck()
{
return is_writable($this->getFileDir()) || @mkdir($this->getFileDir(), $this->setChmodAuto(), true);
}
/**
* @param \Psr\Cache\CacheItemInterface $item
* @return mixed
* @throws \InvalidArgumentException
*/
protected function driverWrite(CacheItemInterface $item)
{
/**
* Check for Cross-Driver type confusion
*/
if ($item instanceof Item) {
$file_path = $this->getFilePath($item->getKey());
$data = $this->encode($this->driverPreWrap($item));
$toWrite = true;
/**
* Skip if Existing Caching in Options
*/
if (isset($this->config[ 'skipExisting' ]) && $this->config[ 'skipExisting' ] == true && file_exists($file_path)) {
$content = $this->readfile($file_path);
$old = $this->decode($content);
$toWrite = false;
if ($old->isExpired()) {
$toWrite = true;
}
}
/**
* Force write
*/
try {
if ($toWrite == true) {
$f = fopen($file_path, 'w+');
fwrite($f, $data);
fclose($f);
return true;
}
} catch (\Exception $e) {
return false;
}
} else {
throw new \InvalidArgumentException('Cross-Driver type confusion detected');
}
}
/**
* @param \Psr\Cache\CacheItemInterface $item
* @return mixed
*/
protected function driverRead(CacheItemInterface $item)
{
/**
* Check for Cross-Driver type confusion
*/
$file_path = $this->getFilePath($item->getKey());
if (!file_exists($file_path)) {
return null;
}
$content = $this->readfile($file_path);
return $this->decode($content);
}
/**
* @param \Psr\Cache\CacheItemInterface $item
* @return bool
* @throws \InvalidArgumentException
*/
protected function driverDelete(CacheItemInterface $item)
{
/**
* Check for Cross-Driver type confusion
*/
if ($item instanceof Item) {
$file_path = $this->getFilePath($item->getKey(), true);
if (file_exists($file_path) && @unlink($file_path)) {
return true;
} else {
return false;
}
} else {
throw new \InvalidArgumentException('Cross-Driver type confusion detected');
}
}
/**
* @return bool
*/
protected function driverClear()
{
return (bool) Directory::rrmdir($this->getPath(true));
}
/**
* @return bool
*/
protected function driverConnect()
{
return true;
}
/**
* @param string $optionName
* @param mixed $optionValue
* @return bool
* @throws \InvalidArgumentException
*/
public static function isValidOption($optionName, $optionValue)
{
parent::isValidOption($optionName, $optionValue);
switch ($optionName) {
case 'path':
return is_string($optionValue);
break;
case 'default_chmod':
return is_numeric($optionValue);
break;
case 'securityKey':
return is_string($optionValue);
break;
case 'htaccess':
return is_bool($optionValue);
break;
default:
return false;
break;
}
}
/**
* @return array
*/
public static function getValidOptions()
{
return ['path', 'default_chmod', 'securityKey', 'htaccess'];
}
/**
* @return array
*/
public static function getRequiredOptions()
{
return ['path'];
}
/********************
*
* PSR-6 Extended Methods
*
*******************/
/**
* @return driverStatistic
* @throws \phpFastCache\Exceptions\phpFastCacheCoreException
* @throws \phpFastCache\Exceptions\phpFastCacheDriverException
*/
public function getStats()
{
$stat = new driverStatistic();
$path = $this->getFilePath(false);
if (!is_dir($path)) {
throw new phpFastCacheDriverException("Can't read PATH:" . $path, 94);
}
$stat->setData(implode(', ', array_keys($this->itemInstances)))
->setRawData([])
->setSize(Directory::dirSize($path))
->setInfo('Number of files used to build the cache: ' . Directory::getFileCount($path));
return $stat;
}
}
<?php
/**
*
* This file is part of phpFastCache.
*
* @license MIT License (MIT)
*
* For full copyright and license information, please see the docs/CREDITS.txt file.
*
* @author Khoa Bui (khoaofgod) <khoaofgod@gmail.com> http://www.phpfastcache.com
* @author Georges.L (Geolim4) <contact@geolim4.com>
*
*/
namespace phpFastCache\Drivers\Files;
use phpFastCache\Cache\ExtendedCacheItemInterface;
use phpFastCache\Cache\ExtendedCacheItemPoolInterface;
use phpFastCache\Cache\ItemBaseTrait;
use phpFastCache\Drivers\Files\Driver as FilesDriver;
/**
* Class Item
* @package phpFastCache\Drivers\Apc
*/
class Item implements ExtendedCacheItemInterface
{
use ItemBaseTrait;
/**
* Item constructor.
* @param \phpFastCache\Drivers\Files\Driver $driver
* @param $key
* @throws \InvalidArgumentException
*/
public function __construct(FilesDriver $driver, $key)
{
if (is_string($key)) {
$this->expirationDate = new \DateTime();
$this->key = $key;
$this->driver = $driver;
$this->driver->setItem($this);
} else {
throw new \InvalidArgumentException(sprintf('$key must be a string, got type "%s" instead.', get_class($key)));
}
}
/**
* @param ExtendedCacheItemPoolInterface $driver
* @throws \InvalidArgumentException
* @return static
*/
public function setDriver(ExtendedCacheItemPoolInterface $driver)
{
if ($driver instanceof FilesDriver) {
$this->driver = $driver;
return $this;
} else {
throw new \InvalidArgumentException('Invalid driver instance');
}
}
}
<?php
/**
*
* This file is part of phpFastCache.
*
* @license MIT License (MIT)
*
* For full copyright and license information, please see the docs/CREDITS.txt file.
*
* @author Khoa Bui (khoaofgod) <khoaofgod@gmail.com> http://www.phpfastcache.com
* @author Georges.L (Geolim4) <contact@geolim4.com>
*
*/
namespace phpFastCache\Drivers\Leveldb;
use LevelDB as LeveldbClient;
use phpFastCache\Core\DriverAbstract;
use phpFastCache\Core\PathSeekerTrait;
use phpFastCache\Core\StandardPsr6StructureTrait;
use phpFastCache\Entities\driverStatistic;
use phpFastCache\Exceptions\phpFastCacheDriverCheckException;
use phpFastCache\Exceptions\phpFastCacheDriverException;
use phpFastCache\Util\Directory;
use Psr\Cache\CacheItemInterface;
/**
* Class Driver
* @package phpFastCache\Drivers
*/
class Driver extends DriverAbstract
{
use PathSeekerTrait;
const LEVELDB_FILENAME = '.database';
/**
* @var LeveldbClient Instance of driver service
*/
public $instance;
/**
* Driver constructor.
* @param array $config
* @throws phpFastCacheDriverException
*/
public function __construct(array $config = [])
{
$this->setup($config);
if (!$this->driverCheck()) {
throw new phpFastCacheDriverCheckException(sprintf(self::DRIVER_CHECK_FAILURE, $this->getDriverName()));
} else {
$this->driverConnect();
}
}
/**
* @return string
* @throws \phpFastCache\Exceptions\phpFastCacheCoreException
*/
public function getLeveldbFile()
{
return $this->getPath() . '/' . self::LEVELDB_FILENAME;
}
/**
* @return bool
*/
public function driverCheck()
{
return extension_loaded('Leveldb');
}
/**
* @param \Psr\Cache\CacheItemInterface $item
* @return mixed
* @throws \InvalidArgumentException
*/
protected function driverWrite(CacheItemInterface $item)
{
/**
* Check for Cross-Driver type confusion
*/
if ($item instanceof Item) {
return $this->instance->set($item->getKey(), $this->encode($this->driverPreWrap($item)));
} else {
throw new \InvalidArgumentException('Cross-Driver type confusion detected');
}
}
/**
* @param \Psr\Cache\CacheItemInterface $item
* @return mixed
*/
protected function driverRead(CacheItemInterface $item)
{
$val = $this->instance->get($item->getKey());
if ($val == false) {
return null;
} else {
return $this->decode($val);
}
}
/**
* @param \Psr\Cache\CacheItemInterface $item
* @return bool
* @throws \InvalidArgumentException
*/
protected function driverDelete(CacheItemInterface $item)
{
/**
* Check for Cross-Driver type confusion
*/
if ($item instanceof Item) {
return $this->instance->delete($item->getKey());
} else {
throw new \InvalidArgumentException('Cross-Driver type confusion detected');
}
}
/**
* @return bool
*/
protected function driverClear()
{
if ($this->instance instanceof LeveldbClient) {
$this->instance->close();
$this->instance = null;
}
$result = LeveldbClient::destroy($this->getLeveldbFile());
$this->driverConnect();
return $result;
}
/**
* @return bool
*/
protected function driverConnect()
{
if ($this->instance instanceof LeveldbClient) {
throw new \LogicException('Already connected to Leveldb database');
} else {
$this->instance = $this->instance ?: new LeveldbClient($this->getLeveldbFile());
}
}
/********************
*
* PSR-6 Extended Methods
*
*******************/
/**
* @return driverStatistic
*/
public function getStats()
{
return (new driverStatistic())
->setData(implode(', ', array_keys($this->itemInstances)))
->setInfo('Number of files used to build the cache: ' . Directory::getFileCount($this->getLeveldbFile()))
->setSize(Directory::dirSize($this->getLeveldbFile()));
}
/**
* Close connection on destruct
*/
public function __destruct()
{
if ($this->instance instanceof LeveldbClient) {
$this->instance->close();
$this->instance = null;
}
}
}
<?php
/**
*
* This file is part of phpFastCache.
*
* @license MIT License (MIT)
*
* For full copyright and license information, please see the docs/CREDITS.txt file.
*
* @author Khoa Bui (khoaofgod) <khoaofgod@gmail.com> http://www.phpfastcache.com
* @author Georges.L (Geolim4) <contact@geolim4.com>
*
*/
namespace phpFastCache\Drivers\Leveldb;
use phpFastCache\Cache\ExtendedCacheItemInterface;
use phpFastCache\Cache\ExtendedCacheItemPoolInterface;
use phpFastCache\Cache\ItemBaseTrait;
use phpFastCache\Drivers\Leveldb\Driver as LeveldbDriver;
/**
* Class Item
* @package phpFastCache\Drivers\Leveldb
*/
class Item implements ExtendedCacheItemInterface
{
use ItemBaseTrait;
/**
* Item constructor.
* @param \phpFastCache\Drivers\Leveldb\Driver $driver
* @param $key
* @throws \InvalidArgumentException
*/
public function __construct(LeveldbDriver $driver, $key)
{
if (is_string($key)) {
$this->key = $key;
$this->driver = $driver;
$this->driver->setItem($this);
$this->expirationDate = new \DateTime();
} else {
throw new \InvalidArgumentException(sprintf('$key must be a string, got type "%s" instead.', gettype($key)));
}
}
/**
* @param ExtendedCacheItemPoolInterface $driver
* @throws \InvalidArgumentException
* @return static
*/
public function setDriver(ExtendedCacheItemPoolInterface $driver)
{
if ($driver instanceof LeveldbDriver) {
$this->driver = $driver;
return $this;
} else {
throw new \InvalidArgumentException('Invalid driver instance');
}
}
}
<?php
/**
*
* This file is part of phpFastCache.
*
* @license MIT License (MIT)
*
* For full copyright and license information, please see the docs/CREDITS.txt file.
*
* @author Khoa Bui (khoaofgod) <khoaofgod@gmail.com> http://www.phpfastcache.com
* @author Georges.L (Geolim4) <contact@geolim4.com>
*
*/
namespace phpFastCache\Drivers\Memcache;
use Memcache as MemcacheSoftware;
use phpFastCache\Core\DriverAbstract;
use phpFastCache\Core\MemcacheDriverCollisionDetectorTrait;
use phpFastCache\Core\StandardPsr6StructureTrait;
use phpFastCache\Entities\driverStatistic;
use phpFastCache\Exceptions\phpFastCacheDriverCheckException;
use phpFastCache\Exceptions\phpFastCacheDriverException;
use Psr\Cache\CacheItemInterface;
/**
* Class Driver
* @package phpFastCache\Drivers
*/
class Driver extends DriverAbstract
{
use MemcacheDriverCollisionDetectorTrait;
/**
* @var int
*/
protected $memcacheFlags = 0;
/**
* Driver constructor.
* @param array $config
* @throws phpFastCacheDriverException
*/
public function __construct(array $config = [])
{
self::checkCollision('Memcache');
$this->setup($config);
if (!$this->driverCheck()) {
throw new phpFastCacheDriverCheckException(sprintf(self::DRIVER_CHECK_FAILURE, $this->getDriverName()));
} else {
$this->instance = new MemcacheSoftware();
$this->driverConnect();
if (array_key_exists('compress_data', $config) && $config[ 'compress_data' ] === true) {
$this->memcacheFlags = MEMCACHE_COMPRESSED;
}
}
}
/**
* @return bool
*/
public function driverCheck()
{
return class_exists('Memcache');
}
/**
* @param \Psr\Cache\CacheItemInterface $item
* @return mixed
* @throws \InvalidArgumentException
*/
protected function driverWrite(CacheItemInterface $item)
{
/**
* Check for Cross-Driver type confusion
*/
if ($item instanceof Item) {
return $this->instance->set($item->getKey(), $this->driverPreWrap($item), $this->memcacheFlags, $item->getTtl());
} else {
throw new \InvalidArgumentException('Cross-Driver type confusion detected');
}
}
/**
* @param \Psr\Cache\CacheItemInterface $item
* @return mixed
*/
protected function driverRead(CacheItemInterface $item)
{
$val = $this->instance->get($item->getKey());
if ($val === false) {
return null;
} else {
return $val;
}
}
/**
* @param \Psr\Cache\CacheItemInterface $item
* @return bool
* @throws \InvalidArgumentException
*/
protected function driverDelete(CacheItemInterface $item)
{
/**
* Check for Cross-Driver type confusion
*/
if ($item instanceof Item) {
return $this->instance->delete($item->getKey());
} else {
throw new \InvalidArgumentException('Cross-Driver type confusion detected');
}
}
/**
* @return bool
*/
protected function driverClear()
{
return $this->instance->flush();
}
/**
* @return bool
*/
protected function driverConnect()
{
$servers = (!empty($this->config[ 'memcache' ]) && is_array($this->config[ 'memcache' ]) ? $this->config[ 'memcache' ] : []);
if (count($servers) < 1) {
$servers = [
['127.0.0.1', 11211],
];
}
foreach ($servers as $server) {
try {
if (!$this->instance->addserver($server[ 0 ], $server[ 1 ])) {
$this->fallback = true;
}
if(!empty($server[ 'sasl_user' ]) && !empty($server[ 'sasl_password'])){
$this->instance->setSaslAuthData($server[ 'sasl_user' ], $server[ 'sasl_password']);
}
} catch (\Exception $e) {
$this->fallback = true;
}
}
}
/********************
*
* PSR-6 Extended Methods
*
*******************/
/**
* @return driverStatistic
*/
public function getStats()
{
$stats = (array) $this->instance->getstats();
$stats[ 'uptime' ] = (isset($stats[ 'uptime' ]) ? $stats[ 'uptime' ] : 0);
$stats[ 'version' ] = (isset($stats[ 'version' ]) ? $stats[ 'version' ] : 'UnknownVersion');
$stats[ 'bytes' ] = (isset($stats[ 'bytes' ]) ? $stats[ 'version' ] : 0);
$date = (new \DateTime())->setTimestamp(time() - $stats[ 'uptime' ]);
return (new driverStatistic())
->setData(implode(', ', array_keys($this->itemInstances)))
->setInfo(sprintf("The memcache daemon v%s is up since %s.\n For more information see RawData.", $stats[ 'version' ], $date->format(DATE_RFC2822)))
->setRawData($stats)
->setSize($stats[ 'bytes' ]);
}
}
<?php
/**
*
* This file is part of phpFastCache.
*
* @license MIT License (MIT)
*
* For full copyright and license information, please see the docs/CREDITS.txt file.
*
* @author Khoa Bui (khoaofgod) <khoaofgod@gmail.com> http://www.phpfastcache.com
* @author Georges.L (Geolim4) <contact@geolim4.com>
*
*/
namespace phpFastCache\Drivers\Memcache;
use phpFastCache\Cache\ExtendedCacheItemInterface;
use phpFastCache\Cache\ExtendedCacheItemPoolInterface;
use phpFastCache\Cache\ItemBaseTrait;
use phpFastCache\Drivers\Memcache\Driver as MemcacheDriver;
/**
* Class Item
* @package phpFastCache\Drivers\Apc
*/
class Item implements ExtendedCacheItemInterface
{
use ItemBaseTrait;
/**
* Item constructor.
* @param \phpFastCache\Drivers\Memcache\Driver $driver
* @param $key
* @throws \InvalidArgumentException
*/
public function __construct(MemcacheDriver $driver, $key)
{
if (is_string($key)) {
$this->key = $key;
$this->driver = $driver;
$this->driver->setItem($this);
$this->expirationDate = new \DateTime();
} else {
throw new \InvalidArgumentException(sprintf('$key must be a string, got type "%s" instead.', gettype($key)));
}
}
/**
* @param ExtendedCacheItemPoolInterface $driver
* @throws \InvalidArgumentException
* @return static
*/
public function setDriver(ExtendedCacheItemPoolInterface $driver)
{
if ($driver instanceof MemcacheDriver) {
$this->driver = $driver;
return $this;
} else {
throw new \InvalidArgumentException('Invalid driver instance');
}
}
}
<?php
/**
*
* This file is part of phpFastCache.
*
* @license MIT License (MIT)
*
* For full copyright and license information, please see the docs/CREDITS.txt file.
*
* @author Khoa Bui (khoaofgod) <khoaofgod@gmail.com> http://www.phpfastcache.com
* @author Georges.L (Geolim4) <contact@geolim4.com>
*
*/
namespace phpFastCache\Drivers\Memcached;
use Memcached as MemcachedSoftware;
use phpFastCache\Core\DriverAbstract;
use phpFastCache\Core\MemcacheDriverCollisionDetectorTrait;
use phpFastCache\Core\StandardPsr6StructureTrait;
use phpFastCache\Entities\driverStatistic;
use phpFastCache\Exceptions\phpFastCacheDriverCheckException;
use phpFastCache\Exceptions\phpFastCacheDriverException;
use Psr\Cache\CacheItemInterface;
/**
* Class Driver
* @package phpFastCache\Drivers
*/
class Driver extends DriverAbstract
{
use MemcacheDriverCollisionDetectorTrait;
/**
* Driver constructor.
* @param array $config
* @throws phpFastCacheDriverException
*/
public function __construct(array $config = [])
{
self::checkCollision('Memcached');
$this->setup($config);
if (!$this->driverCheck()) {
throw new phpFastCacheDriverCheckException(sprintf(self::DRIVER_CHECK_FAILURE, $this->getDriverName()));
} else {
$this->instance = new MemcachedSoftware();
$this->driverConnect();
}
}
/**
* @return bool
*/
public function driverCheck()
{
return class_exists('Memcached');
}
/**
* @param \Psr\Cache\CacheItemInterface $item
* @return mixed
* @throws \InvalidArgumentException
*/
protected function driverWrite(CacheItemInterface $item)
{
/**
* Check for Cross-Driver type confusion
*/
if ($item instanceof Item) {
$ttl = $item->getExpirationDate()->getTimestamp() - time();
// Memcache will only allow a expiration timer less than 2592000 seconds,
// otherwise, it will assume you're giving it a UNIX timestamp.
if ($ttl > 2592000) {
$ttl = time() + $ttl;
}
return $this->instance->set($item->getKey(), $this->driverPreWrap($item), $ttl);
} else {
throw new \InvalidArgumentException('Cross-Driver type confusion detected');
}
}
/**
* @param \Psr\Cache\CacheItemInterface $item
* @return mixed
*/
protected function driverRead(CacheItemInterface $item)
{
$val = $this->instance->get($item->getKey());
if ($val === false) {
return null;
} else {
return $val;
}
}
/**
* @param \Psr\Cache\CacheItemInterface $item
* @return bool
* @throws \InvalidArgumentException
*/
protected function driverDelete(CacheItemInterface $item)
{
/**
* Check for Cross-Driver type confusion
*/
if ($item instanceof Item) {
return $this->instance->delete($item->getKey());
} else {
throw new \InvalidArgumentException('Cross-Driver type confusion detected');
}
}
/**
* @return bool
*/
protected function driverClear()
{
return $this->instance->flush();
}
/**
* @return bool
*/
protected function driverConnect()
{
$servers = (!empty($this->config[ 'memcache' ]) && is_array($this->config[ 'memcache' ]) ? $this->config[ 'memcache' ] : []);
if (count($servers) < 1) {
$servers = [
['127.0.0.1', 11211],
];
}
foreach ($servers as $server) {
try {
if (!$this->instance->addServer($server[ 0 ], $server[ 1 ])) {
$this->fallback = true;
}
if(!empty($server[ 'sasl_user' ]) && !empty($server[ 'sasl_password'])){
$this->instance->setSaslAuthData($server[ 'sasl_user' ], $server[ 'sasl_password']);
}
} catch (\Exception $e) {
$this->fallback = true;
}
}
}
/********************
*
* PSR-6 Extended Methods
*
*******************/
/**
* @return driverStatistic
*/
public function getStats()
{
$stats = (array) $this->instance->getStats();
$stats[ 'uptime' ] = (isset($stats[ 'uptime' ]) ? $stats[ 'uptime' ] : 0);
$stats[ 'version' ] = (isset($stats[ 'version' ]) ? $stats[ 'version' ] : 'UnknownVersion');
$stats[ 'bytes' ] = (isset($stats[ 'bytes' ]) ? $stats[ 'version' ] : 0);
$date = (new \DateTime())->setTimestamp(time() - $stats[ 'uptime' ]);
return (new driverStatistic())
->setData(implode(', ', array_keys($this->itemInstances)))
->setInfo(sprintf("The memcache daemon v%s is up since %s.\n For more information see RawData.", $stats[ 'version' ], $date->format(DATE_RFC2822)))
->setRawData($stats)
->setSize($stats[ 'bytes' ]);
}
}
<?php
/**
*
* This file is part of phpFastCache.
*
* @license MIT License (MIT)
*
* For full copyright and license information, please see the docs/CREDITS.txt file.
*
* @author Khoa Bui (khoaofgod) <khoaofgod@gmail.com> http://www.phpfastcache.com
* @author Georges.L (Geolim4) <contact@geolim4.com>
*
*/
namespace phpFastCache\Drivers\Memcached;
use phpFastCache\Cache\ExtendedCacheItemInterface;
use phpFastCache\Cache\ExtendedCacheItemPoolInterface;
use phpFastCache\Cache\ItemBaseTrait;
use phpFastCache\Drivers\Memcached\Driver as MemcachedDriver;
/**
* Class Item
* @package phpFastCache\Drivers\Apc
*/
class Item implements ExtendedCacheItemInterface
{
use ItemBaseTrait;
/**
* Item constructor.
* @param \phpFastCache\Drivers\Memcache\Driver $driver
* @param $key
* @throws \InvalidArgumentException
*/
public function __construct(MemcachedDriver $driver, $key)
{
if (is_string($key)) {
$this->key = $key;
$this->driver = $driver;
$this->driver->setItem($this);
$this->expirationDate = new \DateTime();
} else {
throw new \InvalidArgumentException(sprintf('$key must be a string, got type "%s" instead.', gettype($key)));
}
}
/**
* @param ExtendedCacheItemPoolInterface $driver
* @throws \InvalidArgumentException
* @return static
*/
public function setDriver(ExtendedCacheItemPoolInterface $driver)
{
if ($driver instanceof MemcachedDriver) {
$this->driver = $driver;
return $this;
} else {
throw new \InvalidArgumentException('Invalid driver instance');
}
}
}
<?php
/**
*
* This file is part of phpFastCache.
*
* @license MIT License (MIT)
*
* For full copyright and license information, please see the docs/CREDITS.txt file.
*
* @author Khoa Bui (khoaofgod) <khoaofgod@gmail.com> http://www.phpfastcache.com
* @author Georges.L (Geolim4) <contact@geolim4.com>
*
*/
namespace phpFastCache\Drivers\Mongodb;
use LogicException;
use MongoBinData;
use MongoClient as MongodbClient;
use MongoCollection;
use MongoConnectionException;
use MongoCursorException;
use MongoDate;
use phpFastCache\Core\DriverAbstract;
use phpFastCache\Entities\driverStatistic;
use phpFastCache\Exceptions\phpFastCacheDriverCheckException;
use phpFastCache\Exceptions\phpFastCacheDriverException;
use Psr\Cache\CacheItemInterface;
/**
* Class Driver
* @package phpFastCache\Drivers
*/
class Driver extends DriverAbstract
{
/**
* @var MongodbClient
*/
public $instance;
/**
* Driver constructor.
* @param array $config
* @throws phpFastCacheDriverException
*/
public function __construct(array $config = [])
{
$this->setup($config);
if (!$this->driverCheck()) {
throw new phpFastCacheDriverCheckException(sprintf(self::DRIVER_CHECK_FAILURE, $this->getDriverName()));
} else {
$this->driverConnect();
}
}
/**
* @return bool
*/
public function driverCheck()
{
if(class_exists('MongoDB\Driver\Manager')){
trigger_error('PhpFastCache currently only support the pecl Mongo extension.<br />
The Support for the MongoDB extension will be added coming soon.', E_USER_ERROR);
}
return extension_loaded('Mongodb') && class_exists('MongoClient');
}
/**
* @param \Psr\Cache\CacheItemInterface $item
* @return mixed
* @throws \InvalidArgumentException
*/
protected function driverWrite(CacheItemInterface $item)
{
/**
* Check for Cross-Driver type confusion
*/
if ($item instanceof Item) {
try {
$result = (array) $this->getCollection()->update(
['_id' => $item->getKey()],
[
'$set' => [
self::DRIVER_TIME_WRAPPER_INDEX => ($item->getTtl() > 0 ? new MongoDate(time() + $item->getTtl()) : new MongoDate(time())),
self::DRIVER_DATA_WRAPPER_INDEX => new MongoBinData($this->encode($item->get()), MongoBinData::BYTE_ARRAY),
self::DRIVER_TAGS_WRAPPER_INDEX => new MongoBinData($this->encode($item->getTags()), MongoBinData::BYTE_ARRAY),
],
],
['upsert' => true, 'multiple' => false]
);
} catch (MongoCursorException $e) {
return false;
}
return isset($result[ 'ok' ]) ? $result[ 'ok' ] == 1 : true;
} else {
throw new \InvalidArgumentException('Cross-Driver type confusion detected');
}
}
/**
* @param \Psr\Cache\CacheItemInterface $item
* @return mixed
*/
protected function driverRead(CacheItemInterface $item)
{
$document = $this->getCollection()
->findOne(['_id' => $item->getKey()],
[self::DRIVER_DATA_WRAPPER_INDEX, self::DRIVER_TIME_WRAPPER_INDEX, self::DRIVER_TAGS_WRAPPER_INDEX /*'d', 'e'*/]);
if ($document) {
return [
self::DRIVER_DATA_WRAPPER_INDEX => $this->decode($document[ self::DRIVER_DATA_WRAPPER_INDEX ]->bin),
self::DRIVER_TIME_WRAPPER_INDEX => (new \DateTime())->setTimestamp($document[ self::DRIVER_TIME_WRAPPER_INDEX ]->sec),
self::DRIVER_TAGS_WRAPPER_INDEX => $this->decode($document[ self::DRIVER_TAGS_WRAPPER_INDEX ]->bin),
];
} else {
return null;
}
}
/**
* @param \Psr\Cache\CacheItemInterface $item
* @return bool
* @throws \InvalidArgumentException
*/
protected function driverDelete(CacheItemInterface $item)
{
/**
* Check for Cross-Driver type confusion
*/
if ($item instanceof Item) {
$deletionResult = (array) $this->getCollection()->remove(['_id' => $item->getKey()], ["w" => 1]);
return (int) $deletionResult[ 'ok' ] === 1 && !$deletionResult[ 'err' ];
} else {
throw new \InvalidArgumentException('Cross-Driver type confusion detected');
}
}
/**
* @return bool
*/
protected function driverClear()
{
return (bool) $this->getCollection()->drop()['ok'];
}
/**
* @return bool
* @throws MongoConnectionException
* @throws LogicException
*/
protected function driverConnect()
{
if ($this->instance instanceof MongodbClient) {
throw new LogicException('Already connected to Mongodb server');
} else {
$host = isset($this->config[ 'host' ]) ? $this->config[ 'host' ] : '127.0.0.1';
$port = isset($this->config[ 'port' ]) ? $this->config[ 'port' ] : '27017';
$timeout = isset($this->config[ 'timeout' ]) ? $this->config[ 'timeout' ] : 3;
$password = isset($this->config[ 'password' ]) ? $this->config[ 'password' ] : '';
$username = isset($this->config[ 'username' ]) ? $this->config[ 'username' ] : '';
/**
* @todo make an url builder
*/
$this->instance = $this->instance ?: (new MongodbClient('mongodb://' .
($username ?: '') .
($password ? ":{$password}" : '') .
($username ? '@' : '') . "{$host}" .
($port != '27017' ? ":{$port}" : ''), ['connectTimeoutMS' => $timeout * 1000]))->phpFastCache;
// $this->instance->Cache->createIndex([self::DRIVER_TIME_WRAPPER_INDEX => 1], ['expireAfterSeconds' => 0]);
}
}
/**
* @return \MongoCollection
*/
protected function getCollection()
{
return $this->instance->Cache;
}
/********************
*
* PSR-6 Extended Methods
*
*******************/
/**
* @return driverStatistic
*/
public function getStats()
{
$serverStatus = $this->getCollection()->db->command([
'serverStatus' => 1,
'recordStats' => 0,
'repl' => 0,
'metrics' => 0,
]);
$collStats = $this->getCollection()->db->command([
'collStats' => 'Cache',
'verbose' => true,
]);
$stats = (new driverStatistic())
->setInfo('MongoDB version ' . $serverStatus[ 'version' ] . ', Uptime (in days): ' . round($serverStatus[ 'uptime' ] / 86400, 1) . "\n For more information see RawData.")
->setSize((int) @$collStats[ 'size' ])
->setData(implode(', ', array_keys($this->itemInstances)))
->setRawData([
'serverStatus' => $serverStatus,
'collStats' => $collStats,
]);
return $stats;
}
}
<?php
/**
*
* This file is part of phpFastCache.
*
* @license MIT License (MIT)
*
* For full copyright and license information, please see the docs/CREDITS.txt file.
*
* @author Khoa Bui (khoaofgod) <khoaofgod@gmail.com> http://www.phpfastcache.com
* @author Georges.L (Geolim4) <contact@geolim4.com>
*
*/
namespace phpFastCache\Drivers\Mongodb;
use phpFastCache\Cache\ExtendedCacheItemInterface;
use phpFastCache\Cache\ExtendedCacheItemPoolInterface;
use phpFastCache\Cache\ItemBaseTrait;
use phpFastCache\Drivers\Mongodb\Driver as MongodbDriver;
/**
* Class Item
* @package phpFastCache\Drivers\Apc
*/
class Item implements ExtendedCacheItemInterface
{
use ItemBaseTrait;
/**
* Item constructor.
* @param \phpFastCache\Drivers\Mongodb\Driver $driver
* @param $key
* @throws \InvalidArgumentException
*/
public function __construct(MongodbDriver $driver, $key)
{
if (is_string($key)) {
$this->key = $key;
$this->driver = $driver;
$this->driver->setItem($this);
$this->expirationDate = new \DateTime();
} else {
throw new \InvalidArgumentException(sprintf('$key must be a string, got type "%s" instead.', gettype($key)));
}
}
/**
* @param ExtendedCacheItemPoolInterface $driver
* @throws \InvalidArgumentException
* @return static
*/
public function setDriver(ExtendedCacheItemPoolInterface $driver)
{
if ($driver instanceof MongodbDriver) {
$this->driver = $driver;
return $this;
} else {
throw new \InvalidArgumentException('Invalid driver instance');
}
}
}
<?php
/**
*
* This file is part of phpFastCache.
*
* @license MIT License (MIT)
*
* For full copyright and license information, please see the docs/CREDITS.txt file.
*
* @author Khoa Bui (khoaofgod) <khoaofgod@gmail.com> http://www.phpfastcache.com
* @author Georges.L (Geolim4) <contact@geolim4.com>
*
*/
namespace phpFastCache\Drivers\Predis;
use phpFastCache\Core\DriverAbstract;
use phpFastCache\Core\StandardPsr6StructureTrait;
use phpFastCache\Entities\driverStatistic;
use phpFastCache\Exceptions\phpFastCacheDriverCheckException;
use phpFastCache\Exceptions\phpFastCacheDriverException;
use Predis\Client as PredisClient;
use Psr\Cache\CacheItemInterface;
/**
* Class Driver
* @package phpFastCache\Drivers
*/
class Driver extends DriverAbstract
{
/**
* @var PredisClient Instance of driver service
*/
public $instance;
/**
* Driver constructor.
* @param array $config
* @throws phpFastCacheDriverException
*/
public function __construct(array $config = [])
{
$this->setup($config);
if (!$this->driverCheck()) {
throw new phpFastCacheDriverCheckException(sprintf(self::DRIVER_CHECK_FAILURE, $this->getDriverName()));
} else {
$this->driverConnect();
}
}
/**
* @return bool
*/
public function driverCheck()
{
if (extension_loaded('Redis')) {
trigger_error('The native Redis extension is installed, you should use Redis instead of Predis to increase performances', E_USER_NOTICE);
}
return class_exists('Predis\Client');
}
/**
* @param \Psr\Cache\CacheItemInterface $item
* @return mixed
* @throws \InvalidArgumentException
*/
protected function driverWrite(CacheItemInterface $item)
{
/**
* Check for Cross-Driver type confusion
*/
if ($item instanceof Item) {
$ttl = $item->getExpirationDate()->getTimestamp() - time();
return $this->instance->setex($item->getKey(), $ttl, $this->encode($this->driverPreWrap($item)));
} else {
throw new \InvalidArgumentException('Cross-Driver type confusion detected');
}
}
/**
* @param \Psr\Cache\CacheItemInterface $item
* @return mixed
*/
protected function driverRead(CacheItemInterface $item)
{
$val = $this->instance->get($item->getKey());
if ($val == false) {
return null;
} else {
return $this->decode($val);
}
}
/**
* @param \Psr\Cache\CacheItemInterface $item
* @return bool
* @throws \InvalidArgumentException
*/
protected function driverDelete(CacheItemInterface $item)
{
/**
* Check for Cross-Driver type confusion
*/
if ($item instanceof Item) {
return $this->instance->del($item->getKey());
} else {
throw new \InvalidArgumentException('Cross-Driver type confusion detected');
}
}
/**
* @return bool
*/
protected function driverClear()
{
return $this->instance->flushDB();
}
/**
* @return bool
*/
protected function driverConnect()
{
$config = isset($this->config[ 'predis' ]) ? $this->config[ 'predis' ] : [];
$this->instance = new PredisClient(array_merge([
'host' => '127.0.0.1',
'port' => 6379,
'password' => null,
'database' => null,
], $config));
return true;
}
/********************
*
* PSR-6 Extended Methods
*
*******************/
/**
* @return driverStatistic
*/
public function getStats()
{
$info = $this->instance->info();
$size = (isset($info['Memory']['used_memory']) ? $info['Memory']['used_memory'] : 0);
$version = (isset($info['Server']['redis_version']) ? $info['Server']['redis_version'] : 0);
$date = (isset($info['Server'][ 'uptime_in_seconds' ]) ? (new \DateTime())->setTimestamp(time() - $info['Server'][ 'uptime_in_seconds' ]) : 'unknown date');
return (new driverStatistic())
->setData(implode(', ', array_keys($this->itemInstances)))
->setRawData($this->instance->info())
->setSize($size)
->setInfo(sprintf("The Redis daemon v%s is up since %s.\n For more information see RawData. \n Driver size includes the memory allocation size.", $version, $date->format(DATE_RFC2822)));
}
}
<?php
/**
*
* This file is part of phpFastCache.
*
* @license MIT License (MIT)
*
* For full copyright and license information, please see the docs/CREDITS.txt file.
*
* @author Khoa Bui (khoaofgod) <khoaofgod@gmail.com> http://www.phpfastcache.com
* @author Georges.L (Geolim4) <contact@geolim4.com>
*
*/
namespace phpFastCache\Drivers\Predis;
use phpFastCache\Cache\ExtendedCacheItemInterface;
use phpFastCache\Cache\ExtendedCacheItemPoolInterface;
use phpFastCache\Cache\ItemBaseTrait;
use phpFastCache\Drivers\Predis\Driver as PredisDriver;
/**
* Class Item
* @package phpFastCache\Drivers\Apc
*/
class Item implements ExtendedCacheItemInterface
{
use ItemBaseTrait;
/**
* Item constructor.
* @param \phpFastCache\Drivers\Apc\Driver $driver
* @param $key
* @throws \InvalidArgumentException
*/
public function __construct(PredisDriver $driver, $key)
{
if (is_string($key)) {
$this->key = $key;
$this->driver = $driver;
$this->driver->setItem($this);
$this->expirationDate = new \DateTime();
} else {
throw new \InvalidArgumentException(sprintf('$key must be a string, got type "%s" instead.', gettype($key)));
}
}
/**
* @param ExtendedCacheItemPoolInterface $driver
* @throws \InvalidArgumentException
* @return static
*/
public function setDriver(ExtendedCacheItemPoolInterface $driver)
{
if ($driver instanceof PredisDriver) {
$this->driver = $driver;
return $this;
} else {
throw new \InvalidArgumentException('Invalid driver instance');
}
}
}
<?php
/**
*
* This file is part of phpFastCache.
*
* @license MIT License (MIT)
*
* For full copyright and license information, please see the docs/CREDITS.txt file.
*
* @author Khoa Bui (khoaofgod) <khoaofgod@gmail.com> http://www.phpfastcache.com
* @author Georges.L (Geolim4) <contact@geolim4.com>
*
*/
namespace phpFastCache\Drivers\Redis;
use phpFastCache\Core\DriverAbstract;
use phpFastCache\Core\StandardPsr6StructureTrait;
use phpFastCache\Entities\driverStatistic;
use phpFastCache\Exceptions\phpFastCacheDriverCheckException;
use phpFastCache\Exceptions\phpFastCacheDriverException;
use Psr\Cache\CacheItemInterface;
use Redis as RedisClient;
/**
* Class Driver
* @package phpFastCache\Drivers
*/
class Driver extends DriverAbstract
{
/**
* Driver constructor.
* @param array $config
* @throws phpFastCacheDriverException
*/
public function __construct(array $config = [])
{
$this->setup($config);
if (!$this->driverCheck()) {
throw new phpFastCacheDriverCheckException(sprintf(self::DRIVER_CHECK_FAILURE, $this->getDriverName()));
} else {
$this->driverConnect();
}
}
/**
* @return bool
*/
public function driverCheck()
{
return extension_loaded('Redis');
}
/**
* @param \Psr\Cache\CacheItemInterface $item
* @return mixed
* @throws \InvalidArgumentException
*/
protected function driverWrite(CacheItemInterface $item)
{
/**
* Check for Cross-Driver type confusion
*/
if ($item instanceof Item) {
$ttl = $item->getExpirationDate()->getTimestamp() - time();
return $this->instance->setex($item->getKey(), $ttl, $this->encode($this->driverPreWrap($item)));
} else {
throw new \InvalidArgumentException('Cross-Driver type confusion detected');
}
}
/**
* @param \Psr\Cache\CacheItemInterface $item
* @return mixed
*/
protected function driverRead(CacheItemInterface $item)
{
$val = $this->instance->get($item->getKey());
if ($val == false) {
return null;
} else {
return $this->decode($val);
}
}
/**
* @param \Psr\Cache\CacheItemInterface $item
* @return bool
* @throws \InvalidArgumentException
*/
protected function driverDelete(CacheItemInterface $item)
{
/**
* Check for Cross-Driver type confusion
*/
if ($item instanceof Item) {
return $this->instance->del($item->getKey());
} else {
throw new \InvalidArgumentException('Cross-Driver type confusion detected');
}
}
/**
* @return bool
*/
protected function driverClear()
{
return $this->instance->flushDB();
}
/**
* @return bool
*/
protected function driverConnect()
{
if ($this->instance instanceof RedisClient) {
throw new \LogicException('Already connected to Redis server');
} else {
$this->instance = $this->instance ?: new RedisClient();
$host = isset($this->config[ 'host' ]) ? $this->config[ 'host' ] : '127.0.0.1';
$port = isset($this->config[ 'port' ]) ? (int) $this->config[ 'port' ] : '6379';
$password = isset($this->config[ 'password' ]) ? $this->config[ 'password' ] : '';
$database = isset($this->config[ 'database' ]) ? $this->config[ 'database' ] : '';
$timeout = isset($this->config[ 'timeout' ]) ? $this->config[ 'timeout' ] : '';
if (!$this->instance->connect($host, (int) $port, (int) $timeout)) {
return false;
} else {
if ($password && !$this->instance->auth($password)) {
return false;
}
if ($database) {
$this->instance->select((int) $database);
}
return true;
}
}
}
/********************
*
* PSR-6 Extended Methods
*
*******************/
/**
* @return driverStatistic
*/
public function getStats()
{
// used_memory
$info = $this->instance->info();
$date = (new \DateTime())->setTimestamp(time() - $info[ 'uptime_in_seconds' ]);
return (new driverStatistic())
->setData(implode(', ', array_keys($this->itemInstances)))
->setRawData($info)
->setSize($info[ 'used_memory' ])
->setInfo(sprintf("The Redis daemon v%s is up since %s.\n For more information see RawData. \n Driver size includes the memory allocation size.", $info[ 'redis_version' ], $date->format(DATE_RFC2822)));
}
}
<?php
/**
*
* This file is part of phpFastCache.
*
* @license MIT License (MIT)
*
* For full copyright and license information, please see the docs/CREDITS.txt file.
*
* @author Khoa Bui (khoaofgod) <khoaofgod@gmail.com> http://www.phpfastcache.com
* @author Georges.L (Geolim4) <contact@geolim4.com>
*
*/
namespace phpFastCache\Drivers\Redis;
use phpFastCache\Cache\ExtendedCacheItemInterface;
use phpFastCache\Cache\ExtendedCacheItemPoolInterface;
use phpFastCache\Cache\ItemBaseTrait;
use phpFastCache\Drivers\Redis\Driver as RedisDriver;
/**
* Class Item
* @package phpFastCache\Drivers\Redis
*/
class Item implements ExtendedCacheItemInterface
{
use ItemBaseTrait;
/**
* Item constructor.
* @param \phpFastCache\Drivers\Redis\Driver $driver
* @param $key
* @throws \InvalidArgumentException
*/
public function __construct(RedisDriver $driver, $key)
{
if (is_string($key)) {
$this->key = $key;
$this->driver = $driver;
$this->driver->setItem($this);
$this->expirationDate = new \DateTime();
} else {
throw new \InvalidArgumentException(sprintf('$key must be a string, got type "%s" instead.', gettype($key)));
}
}
/**
* @param ExtendedCacheItemPoolInterface $driver
* @throws \InvalidArgumentException
* @return static
*/
public function setDriver(ExtendedCacheItemPoolInterface $driver)
{
if ($driver instanceof RedisDriver) {
$this->driver = $driver;
return $this;
} else {
throw new \InvalidArgumentException('Invalid driver instance');
}
}
}
<?php
/**
*
* This file is part of phpFastCache.
*
* @license MIT License (MIT)
*
* For full copyright and license information, please see the docs/CREDITS.txt file.
*
* @author Khoa Bui (khoaofgod) <khoaofgod@gmail.com> http://www.phpfastcache.com
* @author Georges.L (Geolim4) <contact@geolim4.com>
*
*/
namespace phpFastCache\Drivers\Sqlite;
use PDO;
use PDOException;
use phpFastCache\Cache\ExtendedCacheItemInterface;
use phpFastCache\Core\DriverAbstract;
use phpFastCache\Core\PathSeekerTrait;
use phpFastCache\Core\StandardPsr6StructureTrait;
use phpFastCache\Entities\driverStatistic;
use phpFastCache\Exceptions\phpFastCacheDriverCheckException;
use phpFastCache\Exceptions\phpFastCacheDriverException;
use phpFastCache\Util\Directory;
use Psr\Cache\CacheItemInterface;
/**
* Class Driver
* @package phpFastCache\Drivers
*/
class Driver extends DriverAbstract
{
use PathSeekerTrait;
/**
*
*/
const FILE_DIR = 'sqlite';
/**
*
*/
const INDEXING_FILE = 'indexing';
/**
* @var int
*/
protected $maxSize = 10; // 10 mb
/**
* @var int
*/
protected $currentDB = 1;
/**
* @var string
*/
protected $SqliteDir = '';
/**
* @var \PDO
*/
protected $indexing;
/**
* Driver constructor.
* @param array $config
* @throws phpFastCacheDriverException
*/
public function __construct(array $config = [])
{
$this->setup($config);
if (!$this->driverCheck()) {
throw new phpFastCacheDriverCheckException(sprintf(self::DRIVER_CHECK_FAILURE, $this->getDriverName()));
} else {
if (!file_exists($this->getSqliteDir()) && !@mkdir($this->getSqliteDir(), $this->setChmodAuto(), true)) {
throw new phpFastCacheDriverException(sprintf('Sqlite cannot write in "%s", aborting...', $this->getPath()));
} else {
$this->driverConnect();
}
}
}
/**
* @return string
* @throws \phpFastCache\Exceptions\phpFastCacheCoreException
*/
public function getSqliteDir()
{
return $this->SqliteDir ?: $this->getPath() . DIRECTORY_SEPARATOR . self::FILE_DIR;
}
/**
* @return bool
*/
public function driverCheck()
{
return extension_loaded('pdo_sqlite') && (is_writable($this->getSqliteDir()) || @mkdir($this->getSqliteDir(), $this->setChmodAuto(), true));
}
/**
* INIT NEW DB
* @param \PDO $db
*/
public function initDB(\PDO $db)
{
$db->exec('drop table if exists "caching"');
$db->exec('CREATE TABLE "caching" ("id" INTEGER PRIMARY KEY AUTOINCREMENT, "keyword" VARCHAR UNIQUE, "object" BLOB, "exp" INTEGER)');
$db->exec('CREATE UNIQUE INDEX "cleanup" ON "caching" ("keyword","exp")');
$db->exec('CREATE INDEX "exp" ON "caching" ("exp")');
$db->exec('CREATE UNIQUE INDEX "keyword" ON "caching" ("keyword")');
}
/**
* INIT Indexing DB
* @param \PDO $db
*/
public function initIndexing(\PDO $db)
{
// delete everything before reset indexing
$dir = opendir($this->SqliteDir);
while ($file = readdir($dir)) {
if ($file != '.' && $file != '..' && $file != 'indexing' && $file != 'dbfastcache') {
unlink($this->SqliteDir . '/' . $file);
}
}
$db->exec('drop table if exists "balancing"');
$db->exec('CREATE TABLE "balancing" ("keyword" VARCHAR PRIMARY KEY NOT NULL UNIQUE, "db" INTEGER)');
$db->exec('CREATE INDEX "db" ON "balancing" ("db")');
$db->exec('CREATE UNIQUE INDEX "lookup" ON "balancing" ("keyword")');
}
/**
* INIT Instant DB
* Return Database of Keyword
* @param $keyword
* @return int
*/
public function indexing($keyword)
{
if ($this->indexing == null) {
$createTable = false;
if (!file_exists($this->SqliteDir . '/indexing')) {
$createTable = true;
}
$PDO = new PDO("sqlite:" . $this->SqliteDir . '/' . self::INDEXING_FILE);
$PDO->setAttribute(PDO::ATTR_ERRMODE,
PDO::ERRMODE_EXCEPTION);
if ($createTable == true) {
$this->initIndexing($PDO);
}
$this->indexing = $PDO;
unset($PDO);
$stm = $this->indexing->prepare("SELECT MAX(`db`) as `db` FROM `balancing`");
$stm->execute();
$row = $stm->fetch(PDO::FETCH_ASSOC);
if (!isset($row[ 'db' ])) {
$db = 1;
} elseif ($row[ 'db' ] <= 1) {
$db = 1;
} else {
$db = $row[ 'db' ];
}
// check file size
$size = file_exists($this->SqliteDir . '/db' . $db) ? filesize($this->SqliteDir . '/db' . $db) : 1;
$size = round($size / 1024 / 1024, 1);
if ($size > $this->maxSize) {
$db++;
}
$this->currentDB = $db;
}
// look for keyword
$stm = $this->indexing->prepare("SELECT * FROM `balancing` WHERE `keyword`=:keyword LIMIT 1");
$stm->execute([
':keyword' => $keyword,
]);
$row = $stm->fetch(PDO::FETCH_ASSOC);
if (isset($row[ 'db' ]) && $row[ 'db' ] != '') {
$db = $row[ 'db' ];
} else {
/*
* Insert new to Indexing
*/
$db = $this->currentDB;
$stm = $this->indexing->prepare("INSERT INTO `balancing` (`keyword`,`db`) VALUES(:keyword, :db)");
$stm->execute([
':keyword' => $keyword,
':db' => $db,
]);
}
return $db;
}
/**
* @param $keyword
* @param bool $reset
* @return PDO
*/
public function getDb($keyword, $reset = false)
{
/**
* Default is fastcache
*/
$instant = $this->indexing($keyword);
/**
* init instant
*/
if (!isset($this->instance[ $instant ])) {
// check DB Files ready or not
$createTable = false;
if (!file_exists($this->SqliteDir . '/db' . $instant) || $reset == true) {
$createTable = true;
}
$PDO = new PDO('sqlite:' . $this->SqliteDir . '/db' . $instant);
$PDO->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
if ($createTable == true) {
$this->initDB($PDO);
}
$this->instance[ $instant ] = $PDO;
unset($PDO);
}
return $this->instance[ $instant ];
}
/**
* @param \Psr\Cache\CacheItemInterface $item
* @return mixed
* @throws \InvalidArgumentException
*/
protected function driverWrite(CacheItemInterface $item)
{
/**
* Check for Cross-Driver type confusion
*/
if ($item instanceof Item) {
$skipExisting = isset($this->config[ 'skipExisting' ]) ? $this->config[ 'skipExisting' ] : false;
$toWrite = true;
// check in cache first
$in_cache = $this->driverRead($item);
if ($skipExisting == true) {
if ($in_cache == null) {
$toWrite = true;
} else {
$toWrite = false;
}
}
if ($toWrite == true) {
try {
$stm = $this->getDb($item->getKey())
->prepare("INSERT OR REPLACE INTO `caching` (`keyword`,`object`,`exp`) values(:keyword,:object,:exp)");
$stm->execute([
':keyword' => $item->getKey(),
':object' => $this->encode($this->driverPreWrap($item)),
':exp' => time() + $item->getTtl(),
]);
return true;
} catch (\PDOException $e) {
try {
$stm = $this->getDb($item->getKey(), true)
->prepare("INSERT OR REPLACE INTO `caching` (`keyword`,`object`,`exp`) values(:keyword,:object,:exp)");
$stm->execute([
':keyword' => $item->getKey(),
':object' => $this->encode($this->driverPreWrap($item)),
':exp' => time() + $item->getTtl(),
]);
} catch (PDOException $e) {
return false;
}
}
}
return false;
} else {
throw new \InvalidArgumentException('Cross-Driver type confusion detected');
}
}
/**
* @param \Psr\Cache\CacheItemInterface $item
* @return mixed
*/
protected function driverRead(CacheItemInterface $item)
{
try {
$stm = $this->getDb($item->getKey())
->prepare("SELECT * FROM `caching` WHERE `keyword`=:keyword LIMIT 1");
$stm->execute([
':keyword' => $item->getKey(),
]);
$row = $stm->fetch(PDO::FETCH_ASSOC);
} catch (PDOException $e) {
try {
$stm = $this->getDb($item->getKey(), true)
->prepare("SELECT * FROM `caching` WHERE `keyword`=:keyword LIMIT 1");
$stm->execute([
':keyword' => $item->getKey(),
]);
$row = $stm->fetch(PDO::FETCH_ASSOC);
} catch (PDOException $e) {
return null;
}
}
if (isset($row[ 'object' ])) {
return $this->decode($row[ 'object' ]);
}
return null;
}
/**
* @param \Psr\Cache\CacheItemInterface $item
* @return bool
* @throws \InvalidArgumentException
*/
protected function driverDelete(CacheItemInterface $item)
{
/**
* Check for Cross-Driver type confusion
*/
if ($item instanceof Item) {
try {
$stm = $this->getDb($item->getKey())
->prepare("DELETE FROM `caching` WHERE (`exp` <= :U) OR (`keyword`=:keyword) ");
return $stm->execute([
':keyword' => $item->getKey(),
':U' => time(),
]);
} catch (PDOException $e) {
return false;
}
} else {
throw new \InvalidArgumentException('Cross-Driver type confusion detected');
}
}
/**
* @return bool
*/
protected function driverClear()
{
$this->instance = [];
$this->indexing = null;
// delete everything before reset indexing
$dir = opendir($this->getSqliteDir());
while ($file = readdir($dir)) {
if ($file != '.' && $file != '..') {
unlink($this->getSqliteDir() . '/' . $file);
}
}
return true;
}
/**
* @return bool
*/
protected function driverConnect()
{
if (!file_exists($this->getPath() . '/' . self::FILE_DIR)) {
if (!mkdir($this->getPath() . '/' . self::FILE_DIR, $this->setChmodAuto(), true)
) {
$this->fallback = true;
}
}
$this->SqliteDir = $this->getPath() . '/' . self::FILE_DIR;
}
/********************
*
* PSR-6 Extended Methods
*
*******************/
/**
* @return driverStatistic
* @throws PDOException
*/
public function getStats()
{
$stat = new driverStatistic();
$path = $this->getFilePath(false);
if (!is_dir($path)) {
throw new phpFastCacheDriverException("Can't read PATH:" . $path, 94);
}
$stat->setData(implode(', ', array_keys($this->itemInstances)))
->setRawData([])
->setSize(Directory::dirSize($path))
->setInfo('Number of files used to build the cache: ' . Directory::getFileCount($path));
return $stat;
}
/**
* @return array
*/
public function __sleep()
{
return array_diff(array_keys(get_object_vars($this)), ['indexing', 'instance']);
}
}
<?php
/**
*
* This file is part of phpFastCache.
*
* @license MIT License (MIT)
*
* For full copyright and license information, please see the docs/CREDITS.txt file.
*
* @author Khoa Bui (khoaofgod) <khoaofgod@gmail.com> http://www.phpfastcache.com
* @author Georges.L (Geolim4) <contact@geolim4.com>
*
*/
namespace phpFastCache\Drivers\Sqlite;
use phpFastCache\Cache\ExtendedCacheItemInterface;
use phpFastCache\Cache\ExtendedCacheItemPoolInterface;
use phpFastCache\Cache\ItemBaseTrait;
use phpFastCache\Drivers\Sqlite\Driver as SqliteDriver;
/**
* Class Item
* @package phpFastCache\Drivers\Sqlite
*/
class Item implements ExtendedCacheItemInterface
{
use ItemBaseTrait;
/**
* Item constructor.
* @param \phpFastCache\Drivers\Sqlite\Driver $driver
* @param $key
* @throws \InvalidArgumentException
*/
public function __construct(SqliteDriver $driver, $key)
{
if (is_string($key)) {
$this->key = $key;
$this->driver = $driver;
$this->driver->setItem($this);
$this->expirationDate = new \DateTime();
} else {
throw new \InvalidArgumentException(sprintf('$key must be a string, got type "%s" instead.', gettype($key)));
}
}
/**
* @param ExtendedCacheItemPoolInterface $driver
* @throws \InvalidArgumentException
* @return static
*/
public function setDriver(ExtendedCacheItemPoolInterface $driver)
{
if ($driver instanceof SqliteDriver) {
$this->driver = $driver;
return $this;
} else {
throw new \InvalidArgumentException('Invalid driver instance');
}
}
}
<?php
/**
*
* This file is part of phpFastCache.
*
* @license MIT License (MIT)
*
* For full copyright and license information, please see the docs/CREDITS.txt file.
*
* @author Khoa Bui (khoaofgod) <khoaofgod@gmail.com> http://www.phpfastcache.com
* @author Georges.L (Geolim4) <contact@geolim4.com>
*
*/
namespace phpFastCache\Drivers\Ssdb;
use phpFastCache\Core\DriverAbstract;
use phpFastCache\Core\StandardPsr6StructureTrait;
use phpFastCache\Entities\driverStatistic;
use phpFastCache\Exceptions\phpFastCacheDriverCheckException;
use phpFastCache\Exceptions\phpFastCacheDriverException;
use phpssdb\Core\SimpleSSDB;
use phpssdb\Core\SSDB;
use phpssdb\Core\SSDBException;
use Psr\Cache\CacheItemInterface;
/**
* Class Driver
* @package phpFastCache\Drivers
*/
class Driver extends DriverAbstract
{
/**
* @var SimpleSSDB
*/
public $instance;
/**
* Driver constructor.
* @param array $config
* @throws phpFastCacheDriverException
*/
public function __construct(array $config = [])
{
$this->setup($config);
if (!$this->driverCheck()) {
throw new phpFastCacheDriverCheckException(sprintf(self::DRIVER_CHECK_FAILURE, $this->getDriverName()));
} elseif (!$this->driverConnect()) {
throw new phpFastCacheDriverException('Ssdb is not connected, cannot continue.');
}
}
/**
* @return bool
*/
public function driverCheck()
{
static $driverCheck;
if ($driverCheck === null) {
return ($driverCheck = class_exists('phpssdb\Core\SSDB'));
}
return $driverCheck;
}
/**
* @param \Psr\Cache\CacheItemInterface $item
* @return mixed
* @throws \InvalidArgumentException
*/
protected function driverWrite(CacheItemInterface $item)
{
/**
* Check for Cross-Driver type confusion
*/
if ($item instanceof Item) {
return $this->instance->setx($item->getEncodedKey(), $this->encode($this->driverPreWrap($item)), $item->getTtl());
} else {
throw new \InvalidArgumentException('Cross-Driver type confusion detected');
}
}
/**
* @param \Psr\Cache\CacheItemInterface $item
* @return mixed
*/
protected function driverRead(CacheItemInterface $item)
{
$val = $this->instance->get($item->getEncodedKey());
if ($val == false) {
return null;
} else {
return $this->decode($val);
}
}
/**
* @param \Psr\Cache\CacheItemInterface $item
* @return bool
* @throws \InvalidArgumentException
*/
protected function driverDelete(CacheItemInterface $item)
{
/**
* Check for Cross-Driver type confusion
*/
if ($item instanceof Item) {
return $this->instance->del($item->getEncodedKey());
} else {
throw new \InvalidArgumentException('Cross-Driver type confusion detected');
}
}
/**
* @return bool
*/
protected function driverClear()
{
return $this->instance->flushdb('kv');
}
/**
* @return bool
* @throws phpFastCacheDriverException
*/
protected function driverConnect()
{
try {
$server = isset($this->config[ 'ssdb' ]) ? $this->config[ 'ssdb' ] : [
'host' => "127.0.0.1",
'port' => 8888,
'password' => '',
'timeout' => 2000,
];
$host = $server[ 'host' ];
$port = isset($server[ 'port' ]) ? (int) $server[ 'port' ] : 8888;
$password = isset($server[ 'password' ]) ? $server[ 'password' ] : '';
$timeout = !empty($server[ 'timeout' ]) ? (int) $server[ 'timeout' ] : 2000;
$this->instance = new SimpleSSDB($host, $port, $timeout);
if (!empty($password)) {
$this->instance->auth($password);
}
if (!$this->instance) {
return false;
} else {
return true;
}
} catch (SSDBException $e) {
throw new phpFastCacheDriverCheckException('Ssdb failed to connect with error: ' . $e->getMessage(), 0, $e);
}
}
/********************
*
* PSR-6 Extended Methods
*
*******************/
/**
* @return driverStatistic
*/
public function getStats()
{
$stat = new driverStatistic();
$info = $this->instance->info();
/**
* Data returned by Ssdb are very poorly formatted
* using hardcoded offset of pair key-value :-(
*/
$stat->setInfo(sprintf("Ssdb-server v%s with a total of %s call(s).\n For more information see RawData.", $info[ 2 ], $info[ 6 ]))
->setRawData($info)
->setData(implode(', ', array_keys($this->itemInstances)))
->setSize($this->instance->dbsize());
return $stat;
}
}
<?php
/**
*
* This file is part of phpFastCache.
*
* @license MIT License (MIT)
*
* For full copyright and license information, please see the docs/CREDITS.txt file.
*
* @author Khoa Bui (khoaofgod) <khoaofgod@gmail.com> http://www.phpfastcache.com
* @author Georges.L (Geolim4) <contact@geolim4.com>
*
*/
namespace phpFastCache\Drivers\Ssdb;
use phpFastCache\Cache\ExtendedCacheItemInterface;
use phpFastCache\Cache\ExtendedCacheItemPoolInterface;
use phpFastCache\Cache\ItemBaseTrait;
use phpFastCache\Drivers\Ssdb\Driver as SsdbDriver;
/**
* Class Item
* @package phpFastCache\Drivers\Ssdb
*/
class Item implements ExtendedCacheItemInterface
{
use ItemBaseTrait;
/**
* Item constructor.
* @param \phpFastCache\Drivers\Ssdb\Driver $driver
* @param $key
* @throws \InvalidArgumentException
*/
public function __construct(SsdbDriver $driver, $key)
{
if (is_string($key)) {
$this->key = $key;
$this->driver = $driver;
$this->driver->setItem($this);
$this->expirationDate = new \DateTime();
} else {
throw new \InvalidArgumentException(sprintf('$key must be a string, got type "%s" instead.', gettype($key)));
}
}
/**
* @param ExtendedCacheItemPoolInterface $driver
* @throws \InvalidArgumentException
* @return static
*/
public function setDriver(ExtendedCacheItemPoolInterface $driver)
{
if ($driver instanceof SsdbDriver) {
$this->driver = $driver;
return $this;
} else {
throw new \InvalidArgumentException('Invalid driver instance');
}
}
}
<?php
/**
*
* This file is part of phpFastCache.
*
* @license MIT License (MIT)
*
* For full copyright and license information, please see the docs/CREDITS.txt file.
*
* @author Khoa Bui (khoaofgod) <khoaofgod@gmail.com> http://www.phpfastcache.com
* @author Georges.L (Geolim4) <contact@geolim4.com>
*
*/
namespace phpFastCache\Drivers\Wincache;
use phpFastCache\Core\DriverAbstract;
use phpFastCache\Core\StandardPsr6StructureTrait;
use phpFastCache\Entities\driverStatistic;
use phpFastCache\Exceptions\phpFastCacheDriverCheckException;
use phpFastCache\Exceptions\phpFastCacheDriverException;
use Psr\Cache\CacheItemInterface;
/**
* Class Driver
* @package phpFastCache\Drivers
*/
class Driver extends DriverAbstract
{
/**
* Driver constructor.
* @param array $config
* @throws phpFastCacheDriverException
*/
public function __construct(array $config = [])
{
$this->setup($config);
if (!$this->driverCheck()) {
throw new phpFastCacheDriverCheckException(sprintf(self::DRIVER_CHECK_FAILURE, $this->getDriverName()));
}
}
/**
* @return bool
*/
public function driverCheck()
{
return extension_loaded('wincache') && function_exists('wincache_ucache_set');
}
/**
* @param \Psr\Cache\CacheItemInterface $item
* @return mixed
* @throws \InvalidArgumentException
*/
protected function driverWrite(CacheItemInterface $item)
{
/**
* Check for Cross-Driver type confusion
*/
if ($item instanceof Item) {
return wincache_ucache_set($item->getKey(), $this->driverPreWrap($item), $item->getTtl());
} else {
throw new \InvalidArgumentException('Cross-Driver type confusion detected');
}
}
/**
* @param \Psr\Cache\CacheItemInterface $item
* @return mixed
*/
protected function driverRead(CacheItemInterface $item)
{
$val = wincache_ucache_get($item->getKey(), $suc);
if ($suc === false) {
return null;
} else {
return $val;
}
}
/**
* @param \Psr\Cache\CacheItemInterface $item
* @return bool
* @throws \InvalidArgumentException
*/
protected function driverDelete(CacheItemInterface $item)
{
/**
* Check for Cross-Driver type confusion
*/
if ($item instanceof Item) {
return wincache_ucache_delete($item->getKey());
} else {
throw new \InvalidArgumentException('Cross-Driver type confusion detected');
}
}
/**
* @return bool
*/
protected function driverClear()
{
return wincache_ucache_clear();
}
/**
* @return bool
*/
protected function driverConnect()
{
return true;
}
/********************
*
* PSR-6 Extended Methods
*
*******************/
/**
* @return driverStatistic
*/
public function getStats()
{
$memInfo = wincache_ucache_meminfo();
$info = wincache_ucache_info();
$date = (new \DateTime())->setTimestamp(time() - $info[ 'total_cache_uptime' ]);
return (new driverStatistic())
->setInfo(sprintf("The Wincache daemon is up since %s.\n For more information see RawData.", $date->format(DATE_RFC2822)))
->setSize($memInfo[ 'memory_free' ] - $memInfo[ 'memory_total' ])
->setData(implode(', ', array_keys($this->itemInstances)))
->setRawData($memInfo);
}
}
<?php
/**
*
* This file is part of phpFastCache.
*
* @license MIT License (MIT)
*
* For full copyright and license information, please see the docs/CREDITS.txt file.
*
* @author Khoa Bui (khoaofgod) <khoaofgod@gmail.com> http://www.phpfastcache.com
* @author Georges.L (Geolim4) <contact@geolim4.com>
*
*/
namespace phpFastCache\Drivers\Wincache;
use phpFastCache\Cache\ExtendedCacheItemInterface;
use phpFastCache\Cache\ExtendedCacheItemPoolInterface;
use phpFastCache\Cache\ItemBaseTrait;
use phpFastCache\Drivers\Wincache\Driver as WincacheDriver;
/**
* Class Item
* @package phpFastCache\Drivers\Wincache
*/
class Item implements ExtendedCacheItemInterface
{
use ItemBaseTrait;
/**
* Item constructor.
* @param \phpFastCache\Drivers\Wincache\Driver $driver
* @param $key
* @throws \InvalidArgumentException
*/
public function __construct(WincacheDriver $driver, $key)
{
if (is_string($key)) {
$this->key = $key;
$this->driver = $driver;
$this->driver->setItem($this);
$this->expirationDate = new \DateTime();
} else {
throw new \InvalidArgumentException(sprintf('$key must be a string, got type "%s" instead.', gettype($key)));
}
}
/**
* @param ExtendedCacheItemPoolInterface $driver
* @throws \InvalidArgumentException
* @return static
*/
public function setDriver(ExtendedCacheItemPoolInterface $driver)
{
if ($driver instanceof WincacheDriver) {
$this->driver = $driver;
return $this;
} else {
throw new \InvalidArgumentException('Invalid driver instance');
}
}
}
<?php
/**
*
* This file is part of phpFastCache.
*
* @license MIT License (MIT)
*
* For full copyright and license information, please see the docs/CREDITS.txt file.
*
* @author Khoa Bui (khoaofgod) <khoaofgod@gmail.com> http://www.phpfastcache.com
* @author Georges.L (Geolim4) <contact@geolim4.com>
*
*/
namespace phpFastCache\Drivers\Xcache;
use phpFastCache\Core\DriverAbstract;
use phpFastCache\Core\StandardPsr6StructureTrait;
use phpFastCache\Entities\driverStatistic;
use phpFastCache\Exceptions\phpFastCacheDriverCheckException;
use phpFastCache\Exceptions\phpFastCacheDriverException;
use Psr\Cache\CacheItemInterface;
/**
* Class Driver
* @package phpFastCache\Drivers
*/
class Driver extends DriverAbstract
{
/**
* Driver constructor.
* @param array $config
* @throws phpFastCacheDriverException
*/
public function __construct(array $config = [])
{
$this->setup($config);
if (!$this->driverCheck()) {
throw new phpFastCacheDriverCheckException(sprintf(self::DRIVER_CHECK_FAILURE, $this->getDriverName()));
}
}
/**
* @return bool
*/
public function driverCheck()
{
return extension_loaded('xcache') && function_exists('xcache_get');
}
/**
* @param \Psr\Cache\CacheItemInterface $item
* @return mixed
* @throws \InvalidArgumentException
*/
protected function driverWrite(CacheItemInterface $item)
{
/**
* Check for Cross-Driver type confusion
*/
if ($item instanceof Item) {
return xcache_set($item->getKey(), $this->encode($this->driverPreWrap($item)), $item->getTtl());
} else {
throw new \InvalidArgumentException('Cross-Driver type confusion detected');
}
}
/**
* @param \Psr\Cache\CacheItemInterface $item
* @return mixed
*/
protected function driverRead(CacheItemInterface $item)
{
$data = $this->decode(xcache_get($item->getKey()));
if ($data === false || $data === '') {
return null;
}
return $data;
}
/**
* @param \Psr\Cache\CacheItemInterface $item
* @return bool
* @throws \InvalidArgumentException
*/
protected function driverDelete(CacheItemInterface $item)
{
/**
* Check for Cross-Driver type confusion
*/
if ($item instanceof Item) {
return xcache_unset($item->getKey());
} else {
throw new \InvalidArgumentException('Cross-Driver type confusion detected');
}
}
/**
* @return bool
*/
protected function driverClear()
{
$cnt = xcache_count(XC_TYPE_VAR);
for ($i = 0; $i < $cnt; $i++) {
xcache_clear_cache(XC_TYPE_VAR, $i);
}
return true;
}
/**
* @return bool
*/
protected function driverConnect()
{
return true;
}
/********************
*
* PSR-6 Extended Methods
*
*******************/
/**
* @return driverStatistic
*/
public function getStats()
{
if (!ini_get('xcache.admin.enable_auth')) {
$info = xcache_info(XC_TYPE_VAR, 0);
return (new driverStatistic())
->setSize(abs($info[ 'size' ] - $info[ 'avail' ]))
->setData(implode(', ', array_keys($this->itemInstances)))
->setInfo(sprintf("Xcache v%s with following modules loaded:\n %s", XCACHE_VERSION, str_replace(' ', ', ', XCACHE_MODULES)))
->setRawData($info);
} else {
throw new \RuntimeException("PhpFastCache is not able to read Xcache configuration. Please put this to your php.ini:\n
[xcache.admin]
xcache.admin.enable_auth = Off\n
Then reboot your webserver and make sure that the native Xcache ini configuration file does not override your setting.");
}
}
}
<?php
/**
*
* This file is part of phpFastCache.
*
* @license MIT License (MIT)
*
* For full copyright and license information, please see the docs/CREDITS.txt file.
*
* @author Khoa Bui (khoaofgod) <khoaofgod@gmail.com> http://www.phpfastcache.com
* @author Georges.L (Geolim4) <contact@geolim4.com>
*
*/
namespace phpFastCache\Drivers\Xcache;
use phpFastCache\Cache\ExtendedCacheItemInterface;
use phpFastCache\Cache\ExtendedCacheItemPoolInterface;
use phpFastCache\Cache\ItemBaseTrait;
use phpFastCache\Drivers\Xcache\Driver as XcacheDriver;
/**
* Class Item
* @package phpFastCache\Drivers\Apc
*/
class Item implements ExtendedCacheItemInterface
{
use ItemBaseTrait;
/**
* Item constructor.
* @param \phpFastCache\Drivers\Xcache\Driver $driver
* @param $key
* @throws \InvalidArgumentException
*/
public function __construct(XcacheDriver $driver, $key)
{
if (is_string($key)) {
$this->key = $key;
$this->driver = $driver;
$this->driver->setItem($this);
$this->expirationDate = new \DateTime();
} else {
throw new \InvalidArgumentException(sprintf('$key must be a string, got type "%s" instead.', gettype($key)));
}
}
/**
* @param ExtendedCacheItemPoolInterface $driver
* @throws \InvalidArgumentException
* @return static
*/
public function setDriver(ExtendedCacheItemPoolInterface $driver)
{
if ($driver instanceof XcacheDriver) {
$this->driver = $driver;
return $this;
} else {
throw new \InvalidArgumentException('Invalid driver instance');
}
}
}
<?php
/**
*
* This file is part of phpFastCache.
*
* @license MIT License (MIT)
*
* For full copyright and license information, please see the docs/CREDITS.txt file.
*
* @author Lucas Brucksch <support@hammermaps.de>
*
*/
namespace phpFastCache\Drivers\Zenddisk;
use phpFastCache\Core\DriverAbstract;
use phpFastCache\Core\StandardPsr6StructureTrait;
use phpFastCache\Entities\driverStatistic;
use phpFastCache\Exceptions\phpFastCacheDriverCheckException;
use phpFastCache\Exceptions\phpFastCacheDriverException;
use Psr\Cache\CacheItemInterface;
/**
* Class Driver (zend disk cache)
* Requires Zend Data Cache Functions from ZendServer
* @package phpFastCache\Drivers
*/
class Driver extends DriverAbstract
{
/**
* Driver constructor.
* @param array $config
* @throws phpFastCacheDriverException
*/
public function __construct(array $config = [])
{
$this->setup($config);
if (!$this->driverCheck()) {
throw new phpFastCacheDriverCheckException(sprintf(self::DRIVER_CHECK_FAILURE, $this->getDriverName()));
}
}
/**
* @return bool
*/
public function driverCheck()
{
if (extension_loaded('Zend Data Cache') && function_exists('zend_disk_cache_store')) {
return true;
} else {
return false;
}
}
/**
* @param \Psr\Cache\CacheItemInterface $item
* @return mixed
* @throws \InvalidArgumentException
*/
protected function driverWrite(CacheItemInterface $item)
{
/**
* Check for Cross-Driver type confusion
*/
if ($item instanceof Item) {
$ttl = $item->getExpirationDate()->getTimestamp() - time();
return zend_disk_cache_store($item->getKey(), $this->driverPreWrap($item), ($ttl > 0 ? $ttl : 0));
} else {
throw new \InvalidArgumentException('Cross-Driver type confusion detected');
}
}
/**
* @param \Psr\Cache\CacheItemInterface $item
* @return mixed
*/
protected function driverRead(CacheItemInterface $item)
{
$data = zend_disk_cache_fetch($item->getKey());
if ($data === false) {
return null;
}
return $data;
}
/**
* @param \Psr\Cache\CacheItemInterface $item
* @return bool
* @throws \InvalidArgumentException
*/
protected function driverDelete(CacheItemInterface $item)
{
/**
* Check for Cross-Driver type confusion
*/
if ($item instanceof Item) {
return zend_disk_cache_delete($item->getKey());
} else {
throw new \InvalidArgumentException('Cross-Driver type confusion detected');
}
}
/**
* @return bool
*/
protected function driverClear()
{
return @zend_disk_cache_clear();
}
/**
* @return bool
*/
protected function driverConnect()
{
return true;
}
/********************
*
* PSR-6 Extended Methods
*
*******************/
/**
* @return driverStatistic
*/
public function getStats()
{
$stat = new driverStatistic();
$stat->setInfo('[ZendDisk] A void info string')
->setSize(0)
->setData(implode(', ', array_keys($this->itemInstances)))
->setRawData(false);
return $stat;
}
}
<?php
/**
*
* This file is part of phpFastCache.
*
* @license MIT License (MIT)
*
* For full copyright and license information, please see the docs/CREDITS.txt file.
*
* @author Lucas Brucksch <support@hammermaps.de>
*
*/
namespace phpFastCache\Drivers\Zenddisk;
use phpFastCache\Cache\ExtendedCacheItemInterface;
use phpFastCache\Cache\ExtendedCacheItemPoolInterface;
use phpFastCache\Cache\ItemBaseTrait;
use phpFastCache\Drivers\Zenddisk\Driver as ZendDiskDriver;
/**
* Class Item
* @package phpFastCache\Drivers\Zenddisk
*/
class Item implements ExtendedCacheItemInterface
{
use ItemBaseTrait;
/**
* Item constructor.
* @param \phpFastCache\Drivers\Zenddisk\Driver $driver
* @param $key
* @throws \InvalidArgumentException
*/
public function __construct(ZendDiskDriver $driver, $key)
{
if (is_string($key)) {
$this->key = $key;
$this->driver = $driver;
$this->driver->setItem($this);
$this->expirationDate = new \DateTime();
} else {
throw new \InvalidArgumentException(sprintf('$key must be a string, got type "%s" instead.', gettype($key)));
}
}
/**
* @param ExtendedCacheItemPoolInterface $driver
* @throws \InvalidArgumentException
* @return static
*/
public function setDriver(ExtendedCacheItemPoolInterface $driver)
{
if ($driver instanceof ZendDiskDriver) {
$this->driver = $driver;
return $this;
} else {
throw new \InvalidArgumentException('Invalid driver instance');
}
}
}
<?php
/**
*
* This file is part of phpFastCache.
*
* @license MIT License (MIT)
*
* For full copyright and license information, please see the docs/CREDITS.txt file.
*
* @author Lucas Brucksch <support@hammermaps.de>
*
*/
namespace phpFastCache\Drivers\Zendshm;
use phpFastCache\Core\DriverAbstract;
use phpFastCache\Core\StandardPsr6StructureTrait;
use phpFastCache\Entities\driverStatistic;
use phpFastCache\Exceptions\phpFastCacheDriverCheckException;
use phpFastCache\Exceptions\phpFastCacheDriverException;
use Psr\Cache\CacheItemInterface;
/**
* Class Driver (zend memory cache)
* Requires Zend Data Cache Functions from ZendServer
* @package phpFastCache\Drivers
*/
class Driver extends DriverAbstract
{
/**
* Driver constructor.
* @param array $config
* @throws phpFastCacheDriverException
*/
public function __construct(array $config = [])
{
$this->setup($config);
if (!$this->driverCheck()) {
throw new phpFastCacheDriverCheckException(sprintf(self::DRIVER_CHECK_FAILURE, $this->getDriverName()));
}
}
/**
* @return bool
*/
public function driverCheck()
{
if (extension_loaded('Zend Data Cache') && function_exists('zend_shm_cache_store')) {
return true;
} else {
return false;
}
}
/**
* @param \Psr\Cache\CacheItemInterface $item
* @return mixed
* @throws \InvalidArgumentException
*/
protected function driverWrite(CacheItemInterface $item)
{
/**
* Check for Cross-Driver type confusion
*/
if ($item instanceof Item) {
$ttl = $item->getExpirationDate()->getTimestamp() - time();
return zend_shm_cache_store($item->getKey(), $this->driverPreWrap($item), ($ttl > 0 ? $ttl : 0));
} else {
throw new \InvalidArgumentException('Cross-Driver type confusion detected');
}
}
/**
* @param \Psr\Cache\CacheItemInterface $item
* @return mixed
*/
protected function driverRead(CacheItemInterface $item)
{
$data = zend_shm_cache_fetch($item->getKey());
if ($data === false) {
return null;
}
return $data;
}
/**
* @param \Psr\Cache\CacheItemInterface $item
* @return bool
* @throws \InvalidArgumentException
*/
protected function driverDelete(CacheItemInterface $item)
{
/**
* Check for Cross-Driver type confusion
*/
if ($item instanceof Item) {
return zend_shm_cache_delete($item->getKey());
} else {
throw new \InvalidArgumentException('Cross-Driver type confusion detected');
}
}
/**
* @return bool
*/
protected function driverClear()
{
return @zend_shm_cache_clear();
}
/**
* @return bool
*/
protected function driverConnect()
{
return true;
}
/********************
*
* PSR-6 Extended Methods
*
*******************/
/**
* @return driverStatistic
*/
public function getStats()
{
if(function_exists('zend_shm_cache_info')) {
$stats = (array)zend_shm_cache_info();
return (new driverStatistic())
->setData(implode(', ', array_keys($this->itemInstances)))
->setInfo(sprintf("The Zend memory have %d item(s) in cache.\n For more information see RawData.", $stats['items_total']))
->setRawData($stats)
->setSize($stats['memory_total']);
} else {
/** zend_shm_cache_info supported V8 or higher */
return (new driverStatistic())
->setData(implode(', ', array_keys($this->itemInstances)))
->setInfo("The Zend memory statistics is only supported by ZendServer V8 or higher")
->setRawData(null)
->setSize(0);
}
}
}
<?php
/**
*
* This file is part of phpFastCache.
*
* @license MIT License (MIT)
*
* For full copyright and license information, please see the docs/CREDITS.txt file.
*
* @author Lucas Brucksch <support@hammermaps.de>
*
*/
namespace phpFastCache\Drivers\Zendshm;
use phpFastCache\Cache\ExtendedCacheItemInterface;
use phpFastCache\Cache\ExtendedCacheItemPoolInterface;
use phpFastCache\Cache\ItemBaseTrait;
use phpFastCache\Drivers\Zendshm\Driver as ZendSHMDriver;
/**
* Class Item
* @package phpFastCache\Drivers\Zendshm
*/
class Item implements ExtendedCacheItemInterface
{
use ItemBaseTrait;
/**
* Item constructor.
* @param \phpFastCache\Drivers\Zendshm\Driver $driver
* @param $key
* @throws \InvalidArgumentException
*/
public function __construct(ZendSHMDriver $driver, $key)
{
if (is_string($key)) {
$this->key = $key;
$this->driver = $driver;
$this->driver->setItem($this);
$this->expirationDate = new \DateTime();
} else {
throw new \InvalidArgumentException(sprintf('$key must be a string, got type "%s" instead.', gettype($key)));
}
}
/**
* @param ExtendedCacheItemPoolInterface $driver
* @throws \InvalidArgumentException
* @return static
*/
public function setDriver(ExtendedCacheItemPoolInterface $driver)
{
if ($driver instanceof ZendSHMDriver) {
$this->driver = $driver;
return $this;
} else {
throw new \InvalidArgumentException('Invalid driver instance');
}
}
}
<?php
/**
*
* This file is part of phpFastCache.
*
* @license MIT License (MIT)
*
* For full copyright and license information, please see the docs/CREDITS.txt file.
*
* @author Khoa Bui (khoaofgod) <khoaofgod@gmail.com> http://www.phpfastcache.com
* @author Georges.L (Geolim4) <contact@geolim4.com>
*
*/
namespace phpFastCache\Entities;
use ArrayAccess;
use InvalidArgumentException;
use LogicException;
/**
* Class driverStatistic
* @package phpFastCache\Entities
*/
class driverStatistic implements ArrayAccess
{
/**
* @var string
*/
protected $info = '';
/**
* @var string
*/
protected $size = 0;
/**
* @var string
*/
protected $data = '';
/**
* @var mixed
*/
protected $rawData;
/**
* @return string|bool Return infos or false if no information available
*/
public function getInfo()
{
return $this->info;
}
/**
* @return int|bool Return size in octet or false if no information available
*/
public function getSize()
{
return $this->size;
}
/**
* @return mixed
*/
public function getData()
{
return $this->data;
}
/**
* @param $info
* @return $this
*/
public function setInfo($info)
{
$this->info = ($info ?: '');
return $this;
}
/**
* @param int $size
* @return $this
*/
public function setSize($size)
{
$this->size = ($size ?: 0);
return $this;
}
/**
* @param mixed $data
* @return $this
*/
public function setData($data)
{
$this->data = ($data ?: '');
return $this;
}
/**
* @return mixed
*/
public function getRawData()
{
return $this->rawData;
}
/**
* @param mixed $raw
* @return $this
*/
public function setRawData($raw)
{
$this->rawData = $raw;
return $this;
}
/**
* @return array
*/
public function getPublicDesc()
{
return[
'Info' => 'Cache Information',
'Size' => 'Cache Size',
'Data' => 'Cache items keys',
'RawData' => 'Cache raw data',
];
}
/*****************
* ArrayAccess
*****************/
/**
* @param string $offset
* @param string $value
* @throws InvalidArgumentException
* @throws LogicException
*/
public function offsetSet($offset, $value)
{
trigger_error($this->getDeprecatedMsg(), E_USER_DEPRECATED);
if (!is_string($offset)) {
throw new InvalidArgumentException('$offset must be a string');
} else {
if (property_exists($this, $offset)) {
$this->{$offset} = $value;
} else {
throw new LogicException("Property {$offset} does not exists");
}
}
}
/**
* @param string $offset
* @return bool
* @throws InvalidArgumentException
* @throws LogicException
*/
public function offsetExists($offset)
{
trigger_error($this->getDeprecatedMsg(), E_USER_DEPRECATED);
if (!is_string($offset)) {
throw new InvalidArgumentException('$offset must be a string');
} else {
if (property_exists($this, $offset)) {
return isset($this->{$offset});
} else {
throw new LogicException("Property {$offset} does not exists");
}
}
}
/**
* @param string $offset
* @throws InvalidArgumentException
* @throws LogicException
*/
public function offsetUnset($offset)
{
trigger_error($this->getDeprecatedMsg(), E_USER_DEPRECATED);
if (!is_string($offset)) {
throw new InvalidArgumentException('$offset must be a string');
} else {
if (property_exists($this, $offset)) {
unset($this->{$offset});
} else {
throw new LogicException("Property {$offset} does not exists");
}
}
}
/**
* @param string $offset
* @return string
* @throws InvalidArgumentException
* @throws LogicException
*/
public function offsetGet($offset)
{
trigger_error($this->getDeprecatedMsg(), E_USER_DEPRECATED);
if (!is_string($offset)) {
throw new InvalidArgumentException('$offset must be a string');
} else {
if (property_exists($this, $offset)) {
return isset($this->{$offset}) ? $this->{$offset} : null;
} else {
throw new LogicException("Property {$offset} does not exists");
}
}
}
/**
* @return string
*/
private function getDeprecatedMsg()
{
return 'You should consider upgrading your code and treat the statistic array as an object.
The arrayAccess compatibility will be removed in the next major release';
}
}
<?php
/**
*
* This file is part of phpFastCache.
*
* @license MIT License (MIT)
*
* For full copyright and license information, please see the docs/CREDITS.txt file.
*
* @author Khoa Bui (khoaofgod) <khoaofgod@gmail.com> http://www.phpfastcache.com
* @author Georges.L (Geolim4) <contact@geolim4.com>
*
*/
namespace phpFastCache\Exceptions;
use \Exception;
/**
* Class phpFastCacheCoreException
* @package phpFastCache\Exceptions
*/
class phpFastCacheCoreException extends Exception
{
}
<?php
/**
*
* This file is part of phpFastCache.
*
* @license MIT License (MIT)
*
* For full copyright and license information, please see the docs/CREDITS.txt file.
*
* @author Khoa Bui (khoaofgod) <khoaofgod@gmail.com> http://www.phpfastcache.com
* @author Georges.L (Geolim4) <contact@geolim4.com>
*
*/
namespace phpFastCache\Exceptions;
/**
* Class phpFastCacheDriverCheckException
* @package phpFastCache\Exceptions
*/
class phpFastCacheDriverCheckException extends phpFastCacheDriverException
{
}
<?php
/**
*
* This file is part of phpFastCache.
*
* @license MIT License (MIT)
*
* For full copyright and license information, please see the docs/CREDITS.txt file.
*
* @author Khoa Bui (khoaofgod) <khoaofgod@gmail.com> http://www.phpfastcache.com
* @author Georges.L (Geolim4) <contact@geolim4.com>
*
*/
namespace phpFastCache\Exceptions;
use \Exception;
/**
* Class phpFastCacheDriverException
* @package phpFastCache\Exceptions
*/
class phpFastCacheDriverException extends Exception
{
}
<a href="http://www.phpfastcache.com" title="Simple Php Caching Class">Visit www.phpfastcache.com</a>
<?php
/**
*
* This file is part of phpFastCache.
*
* @license MIT License (MIT)
*
* For full copyright and license information, please see the docs/CREDITS.txt file.
*
* @author Khoa Bui (khoaofgod) <khoaofgod@gmail.com> http://www.phpfastcache.com
* @author Georges.L (Geolim4) <contact@geolim4.com>
*
*/
namespace phpFastCache\Proxy;
use phpFastCache\Cache\ExtendedCacheItemInterface;
use phpFastCache\CacheManager;
use phpFastCache\Entities\driverStatistic;
use Psr\Cache\CacheItemInterface;
/**
* Class phpFastCache
*
* Handle methods using annotations for IDE
* because they're handled by __call()
* Check out ExtendedCacheItemInterface to see all
* the drivers methods magically implemented
*
* @method ExtendedCacheItemInterface getItem($key) Retrieve an item and returns an empty item if not found
* @method ExtendedCacheItemInterface[] getItems(array $keys) Retrieve an item and returns an empty item if not found
* @method bool hasItem() hasItem($key) Tests if an item exists
* @method bool deleteItem(string $key) Delete an item
* @method bool deleteItems(array $keys) Delete some items
* @method bool save(CacheItemInterface $item) Save an item
* @method bool saveDeferred(CacheItemInterface $item) Sets a cache item to be persisted later
* @method bool commit() Persists any deferred cache items
* @method bool clear() Allow you to completely empty the cache and restart from the beginning
* @method driverStatistic stats() Returns a driverStatistic object
* @method ExtendedCacheItemInterface getItemsByTag($tagName) Return items by a tag
* @method ExtendedCacheItemInterface[] getItemsByTags(array $tagNames) Return items by some tags
* @method bool deleteItemsByTag($tagName) Delete items by a tag
* @method bool deleteItemsByTags(array $tagNames) // Delete items by some tags
* @method void incrementItemsByTag($tagName, $step = 1) // Increment items by a tag
* @method void incrementItemsByTags(array $tagNames, $step = 1) // Increment items by some tags
* @method void decrementItemsByTag($tagName, $step = 1) // Decrement items by a tag
* @method void decrementItemsByTags(array $tagNames, $step = 1) // Decrement items by some tags
* @method void appendItemsByTag($tagName, $data) // Append items by a tag
* @method void appendItemsByTags(array $tagNames, $data) // Append items by a tags
* @method void prependItemsByTag($tagName, $data) // Prepend items by a tag
* @method void prependItemsByTags(array $tagNames, $data) // Prepend items by a tags
*/
abstract class phpFastCacheAbstractProxy
{
/**
* @var \phpFastCache\Cache\ExtendedCacheItemPoolInterface
*/
protected $instance;
/**
* phpFastCache constructor.
* @param string $driver
* @param array $config
*/
public function __construct($driver = 'auto', array $config = [])
{
$this->instance = CacheManager::getInstance($driver, $config);
}
/**
* @param $name
* @param $args
* @return mixed
* @throws \BadMethodCallException
*/
public function __call($name, $args)
{
if(method_exists($this->instance, $name)){
return call_user_func_array([$this->instance, $name], $args);
}else{
throw new \BadMethodCallException(sprintf('Method %s does not exists', $name));
}
}
}
<?php
/**
*
* This file is part of phpFastCache.
*
* @license MIT License (MIT)
*
* For full copyright and license information, please see the docs/CREDITS.txt file.
*
* @author Khoa Bui (khoaofgod) <khoaofgod@gmail.com> http://www.phpfastcache.com
* @author Georges.L (Geolim4) <contact@geolim4.com>
*
*/
namespace phpFastCache\Util;
use RecursiveDirectoryIterator;
use RecursiveIteratorIterator;
use SplFileInfo;
/**
* Class Directory
* @package phpFastCache\Util
*/
class Directory
{
/**
* Get the directory size
* @param string $directory
* @param bool $includeDirAllocSize
* @return integer
*/
public static function dirSize($directory, $includeDirAllocSize = false)
{
$size = 0;
foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($directory)) as $file) {
/**
* @var \SplFileInfo $file
*/
if ($file->isFile()) {
$size += filesize($file->getRealPath());
} else if ($includeDirAllocSize) {
$size += $file->getSize();
}
}
return $size;
}
/**
* @param string $path
* @return int
*/
public static function getFileCount($path)
{
$count = 0;
$objects = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path), \RecursiveIteratorIterator::SELF_FIRST);
foreach ($objects as $object) {
/**
* @var \SplFileInfo $object
*/
if ($object->isFile()) {
$count++;
}
}
return $count;
}
/**
* Recursively delete a directory and all of it's contents - e.g.the equivalent of `rm -r` on the command-line.
* Consistent with `rmdir()` and `unlink()`, an E_WARNING level error will be generated on failure.
*
* @param string $source absolute path to directory or file to delete.
* @param bool $removeOnlyChildren set to true will only remove content inside directory.
*
* @return bool true on success; false on failure
*/
public static function rrmdir($source, $removeOnlyChildren = false)
{
if (empty($source) || file_exists($source) === false) {
return false;
}
if (is_file($source) || is_link($source)) {
return unlink($source);
}
$files = new RecursiveIteratorIterator
(
new RecursiveDirectoryIterator($source, RecursiveDirectoryIterator::SKIP_DOTS),
RecursiveIteratorIterator::CHILD_FIRST
);
foreach ($files as $fileinfo) {
/**
* @var SplFileInfo $fileinfo
*/
if ($fileinfo->isDir()) {
if (self::rrmdir($fileinfo->getRealPath()) === false) {
return false;
}
} else if(unlink($fileinfo->getRealPath()) === false) {
return false;
}
}
if ($removeOnlyChildren === false) {
return rmdir($source);
}
return true;
}
/**
* Alias of realpath() but work
* on non-existing files
*
* @param $path
* @return string
*/
public static function getAbsolutePath($path)
{
$parts = preg_split('~[/\\\\]+~', $path, 0, PREG_SPLIT_NO_EMPTY);
$absolutes = [];
foreach ($parts as $part) {
if ('.' === $part) {
continue;
}
if ('..' === $part) {
array_pop($absolutes);
} else {
$absolutes[] = $part;
}
}
/**
* Allows to dereference char
*/
$__FILE__ = preg_replace('~^(([a-z0-9\-]+)://)~', '', __FILE__);// remove file protocols such as "phar://" etc.
$prefix = $__FILE__[0] === DIRECTORY_SEPARATOR ? DIRECTORY_SEPARATOR : '';
return $prefix . implode(DIRECTORY_SEPARATOR, $absolutes);
}
}
<?php
/**
*
* This file is part of phpFastCache.
*
* @license MIT License (MIT)
*
* For full copyright and license information, please see the docs/CREDITS.txt file.
*
* @author Khoa Bui (khoaofgod) <khoaofgod@gmail.com> http://www.phpfastcache.com
* @author Georges.L (Geolim4) <contact@geolim4.com>
*
*/
namespace phpFastCache\Util;
use phpFastCache\Exceptions\phpFastCacheCoreException;
/**
* Class Languages
* @author Khoa Bui (khoaofgod) <khoaofgod@gmail.com> http://www.phpfastcache.com
* @author Georges.L (Geolim4) <contact@geolim4.com>
*
*/
class Languages
{
public static function setEncoding($encoding = 'UTF-8', $language = null)
{
if ($language === null || !in_array($language, ['uni', 'Japanese', 'ja', 'English', 'en'], true)) {
$language = 'uni';
}
switch (strtoupper($encoding)) {
case 'UTF-8':
if (extension_loaded("mbstring")) {
mb_internal_encoding($encoding);
mb_http_output($encoding);
mb_http_input($encoding);
mb_language($language);
mb_regex_encoding($encoding);
} else {
throw new phpFastCacheCoreException("MB String need to be installed for Unicode Encoding");
}
break;
}
}
}
<?php
/**
* @file
* TeamSpeak 3 PHP Framework
*
* $Id: Abstract.php 06/06/2016 22:27:13 scp@Svens-iMac $
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @package TeamSpeak3
* @version 1.1.24
* @author Sven 'ScP' Paulsen
* @copyright Copyright (c) 2010 by Planet TeamSpeak. All rights reserved.
*/
/**
* @class TeamSpeak3_Adapter_Abstract
* @brief Provides low-level methods for concrete adapters to communicate with a TeamSpeak 3 Server.
*/
abstract class TeamSpeak3_Adapter_Abstract
{
/**
* Stores user-provided options.
*
* @var array
*/
protected $options = null;
/**
* Stores an TeamSpeak3_Transport_Abstract object.
*
* @var TeamSpeak3_Transport_Abstract
*/
protected $transport = null;
/**
* The TeamSpeak3_Adapter_Abstract constructor.
*
* @param array $options
* @return TeamSpeak3_Adapter_Abstract
*/
public function __construct(array $options)
{
$this->options = $options;
if($this->transport === null)
{
$this->syn();
}
}
/**
* The TeamSpeak3_Adapter_Abstract destructor.
*
* @return void
*/
abstract public function __destruct();
/**
* Connects the TeamSpeak3_Transport_Abstract object and performs initial actions on the remote
* server.
*
* @throws TeamSpeak3_Adapter_Exception
* @return void
*/
abstract protected function syn();
/**
* Commit pending data.
*
* @return array
*/
public function __sleep()
{
return array("options");
}
/**
* Reconnects to the remote server.
*
* @return void
*/
public function __wakeup()
{
$this->syn();
}
/**
* Returns the profiler timer used for this connection adapter.
*
* @return TeamSpeak3_Helper_Profiler_Timer
*/
public function getProfiler()
{
return TeamSpeak3_Helper_Profiler::get(spl_object_hash($this));
}
/**
* Returns the transport object used for this connection adapter.
*
* @return TeamSpeak3_Transport_Abstract
*/
public function getTransport()
{
return $this->transport;
}
/**
* Loads the transport object object used for the connection adapter and passes a given set
* of options.
*
* @param array $options
* @param string $transport
* @throws TeamSpeak3_Adapter_Exception
* @return void
*/
protected function initTransport($options, $transport = "TeamSpeak3_Transport_TCP")
{
if(!is_array($options))
{
throw new TeamSpeak3_Adapter_Exception("transport parameters must provided in an array");
}
$this->transport = new $transport($options);
}
/**
* Returns the hostname or IPv4 address the underlying TeamSpeak3_Transport_Abstract object
* is connected to.
*
* @return string
*/
public function getTransportHost()
{
return $this->getTransport()->getConfig("host", "0.0.0.0");
}
/**
* Returns the port number of the server the underlying TeamSpeak3_Transport_Abstract object
* is connected to.
*
* @return string
*/
public function getTransportPort()
{
return $this->getTransport()->getConfig("port", "0");
}
}
<?php
/**
* @file
* TeamSpeak 3 PHP Framework
*
* $Id: Blacklist.php 06/06/2016 22:27:13 scp@Svens-iMac $
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @package TeamSpeak3
* @version 1.1.24
* @author Sven 'ScP' Paulsen
* @copyright Copyright (c) 2010 by Planet TeamSpeak. All rights reserved.
*/
/**
* @class TeamSpeak3_Adapter_Blacklist
* @brief Provides methods to check if an IP address is currently blacklisted.
*/
class TeamSpeak3_Adapter_Blacklist extends TeamSpeak3_Adapter_Abstract
{
/**
* The IPv4 address or FQDN of the TeamSpeak Systems update server.
*
* @var string
*/
protected $default_host = "blacklist.teamspeak.com";
/**
* The UDP port number of the TeamSpeak Systems update server.
*
* @var integer
*/
protected $default_port = 17385;
/**
* Stores an array containing the latest build numbers.
*
* @var array
*/
protected $build_numbers = null;
/**
* Connects the TeamSpeak3_Transport_Abstract object and performs initial actions on the remote
* server.
*
* @return void
*/
public function syn()
{
if(!isset($this->options["host"]) || empty($this->options["host"])) $this->options["host"] = $this->default_host;
if(!isset($this->options["port"]) || empty($this->options["port"])) $this->options["port"] = $this->default_port;
$this->initTransport($this->options, "TeamSpeak3_Transport_UDP");
$this->transport->setAdapter($this);
TeamSpeak3_Helper_Profiler::init(spl_object_hash($this));
TeamSpeak3_Helper_Signal::getInstance()->emit("blacklistConnected", $this);
}
/**
* The TeamSpeak3_Adapter_Blacklist destructor.
*
* @return void
*/
public function __destruct()
{
if($this->getTransport() instanceof TeamSpeak3_Transport_Abstract && $this->getTransport()->isConnected())
{
$this->getTransport()->disconnect();
}
}
/**
* Returns TRUE if a specified $host IP address is currently blacklisted.
*
* @param string $host
* @throws TeamSpeak3_Adapter_Blacklist_Exception
* @return boolean
*/
public function isBlacklisted($host)
{
if(ip2long($host) === FALSE)
{
$addr = gethostbyname($host);
if($addr == $host)
{
throw new TeamSpeak3_Adapter_Blacklist_Exception("unable to resolve IPv4 address (" . $host . ")");
}
$host = $addr;
}
$this->getTransport()->send("ip4:" . $host);
$repl = $this->getTransport()->read(1);
$this->getTransport()->disconnect();
if(!count($repl))
{
return FALSE;
}
return ($repl->toInt()) ? FALSE : TRUE;
}
}
<?php
/**
* @file
* TeamSpeak 3 PHP Framework
*
* $Id: Exception.php 06/06/2016 22:27:13 scp@Svens-iMac $
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @package TeamSpeak3
* @version 1.1.24
* @author Sven 'ScP' Paulsen
* @copyright Copyright (c) 2010 by Planet TeamSpeak. All rights reserved.
*/
/**
* @class TeamSpeak3_Adapter_Blacklist_Exception
* @brief Enhanced exception class for TeamSpeak3_Adapter_Blacklist objects.
*/
class TeamSpeak3_Adapter_Blacklist_Exception extends TeamSpeak3_Adapter_Exception {}
<?php
/**
* @file
* TeamSpeak 3 PHP Framework
*
* $Id: Exception.php 06/06/2016 22:27:13 scp@Svens-iMac $
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @package TeamSpeak3
* @version 1.1.24
* @author Sven 'ScP' Paulsen
* @copyright Copyright (c) 2010 by Planet TeamSpeak. All rights reserved.
*/
/**
* @class TeamSpeak3_Adapter_Exception
* @brief Enhanced exception class for TeamSpeak3_Adapter_Abstract objects.
*/
class TeamSpeak3_Adapter_Exception extends TeamSpeak3_Exception {}
<?php
/**
* @file
* TeamSpeak 3 PHP Framework
*
* $Id: FileTransfer.php 06/06/2016 22:27:13 scp@Svens-iMac $
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @package TeamSpeak3
* @version 1.1.24
* @author Sven 'ScP' Paulsen
* @copyright Copyright (c) 2010 by Planet TeamSpeak. All rights reserved.
*/
/**
* @class TeamSpeak3_Adapter_FileTransfer
* @brief Provides low-level methods for file transfer communication with a TeamSpeak 3 Server.
*/
class TeamSpeak3_Adapter_FileTransfer extends TeamSpeak3_Adapter_Abstract
{
/**
* Connects the TeamSpeak3_Transport_Abstract object and performs initial actions on the remote
* server.
*
* @throws TeamSpeak3_Adapter_Exception
* @return void
*/
public function syn()
{
$this->initTransport($this->options);
$this->transport->setAdapter($this);
TeamSpeak3_Helper_Profiler::init(spl_object_hash($this));
TeamSpeak3_Helper_Signal::getInstance()->emit("filetransferConnected", $this);
}
/**
* The TeamSpeak3_Adapter_FileTransfer destructor.
*
* @return void
*/
public function __destruct()
{
if($this->getTransport() instanceof TeamSpeak3_Transport_Abstract && $this->getTransport()->isConnected())
{
$this->getTransport()->disconnect();
}
}
/**
* Sends a valid file transfer key to the server to initialize the file transfer.
*
* @param string $ftkey
* @throws TeamSpeak3_Adapter_FileTransfer_Exception
* @return void
*/
protected function init($ftkey)
{
if(strlen($ftkey) != 32)
{
throw new TeamSpeak3_Adapter_FileTransfer_Exception("invalid file transfer key format");
}
$this->getProfiler()->start();
$this->getTransport()->send($ftkey);
TeamSpeak3_Helper_Signal::getInstance()->emit("filetransferHandshake", $this);
}
/**
* Sends the content of a file to the server.
*
* @param string $ftkey
* @param integer $seek
* @param string $data
* @throws TeamSpeak3_Adapter_FileTransfer_Exception
* @return void
*/
public function upload($ftkey, $seek, $data)
{
$this->init($ftkey);
$size = strlen($data);
$seek = intval($seek);
$pack = 4096;
TeamSpeak3_Helper_Signal::getInstance()->emit("filetransferUploadStarted", $ftkey, $seek, $size);
for(;$seek < $size;)
{
$rest = $size-$seek;
$pack = $rest < $pack ? $rest : $pack;
$buff = substr($data, $seek, $pack);
$seek = $seek+$pack;
$this->getTransport()->send($buff);
TeamSpeak3_Helper_Signal::getInstance()->emit("filetransferUploadProgress", $ftkey, $seek, $size);
}
$this->getProfiler()->stop();
TeamSpeak3_Helper_Signal::getInstance()->emit("filetransferUploadFinished", $ftkey, $seek, $size);
if($seek < $size)
{
throw new TeamSpeak3_Adapter_FileTransfer_Exception("incomplete file upload (" . $seek . " of " . $size . " bytes)");
}
}
/**
* Returns the content of a downloaded file as a TeamSpeak3_Helper_String object.
*
* @param string $ftkey
* @param integer $size
* @param boolean $passthru
* @throws TeamSpeak3_Adapter_FileTransfer_Exception
* @return TeamSpeak3_Helper_String
*/
public function download($ftkey, $size, $passthru = FALSE)
{
$this->init($ftkey);
if($passthru)
{
return $this->passthru($size);
}
$buff = new TeamSpeak3_Helper_String("");
$size = intval($size);
$pack = 4096;
TeamSpeak3_Helper_Signal::getInstance()->emit("filetransferDownloadStarted", $ftkey, count($buff), $size);
for($seek = 0;$seek < $size;)
{
$rest = $size-$seek;
$pack = $rest < $pack ? $rest : $pack;
$data = $this->getTransport()->read($rest < $pack ? $rest : $pack);
$seek = $seek+$pack;
$buff->append($data);
TeamSpeak3_Helper_Signal::getInstance()->emit("filetransferDownloadProgress", $ftkey, count($buff), $size);
}
$this->getProfiler()->stop();
TeamSpeak3_Helper_Signal::getInstance()->emit("filetransferDownloadFinished", $ftkey, count($buff), $size);
if(strlen($buff) != $size)
{
throw new TeamSpeak3_Adapter_FileTransfer_Exception("incomplete file download (" . count($buff) . " of " . $size . " bytes)");
}
return $buff;
}
/**
* Outputs all remaining data on a TeamSpeak 3 file transfer stream using PHP's fpassthru()
* function.
*
* @param integer $size
* @throws TeamSpeak3_Adapter_FileTransfer_Exception
* @return void
*/
protected function passthru($size)
{
$buff_size = fpassthru($this->getTransport()->getStream());
if($buff_size != $size)
{
throw new TeamSpeak3_Adapter_FileTransfer_Exception("incomplete file download (" . intval($buff_size) . " of " . $size . " bytes)");
}
}
}
<?php
/**
* @file
* TeamSpeak 3 PHP Framework
*
* $Id: Exception.php 06/06/2016 22:27:13 scp@Svens-iMac $
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @package TeamSpeak3
* @version 1.1.24
* @author Sven 'ScP' Paulsen
* @copyright Copyright (c) 2010 by Planet TeamSpeak. All rights reserved.
*/
/**
* @class TeamSpeak3_Adapter_FileTransfer_Exception
* @brief Enhanced exception class for TeamSpeak3_Adapter_FileTransfer objects.
*/
class TeamSpeak3_Adapter_FileTransfer_Exception extends TeamSpeak3_Adapter_Exception {}
<?php
/**
* @file
* TeamSpeak 3 PHP Framework
*
* $Id: ServerQuery.php 06/06/2016 22:27:13 scp@Svens-iMac $
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @package TeamSpeak3
* @version 1.1.24
* @author Sven 'ScP' Paulsen
* @copyright Copyright (c) 2010 by Planet TeamSpeak. All rights reserved.
*/
/**
* @class TeamSpeak3_Adapter_ServerQuery
* @brief Provides low-level methods for ServerQuery communication with a TeamSpeak 3 Server.
*/
class TeamSpeak3_Adapter_ServerQuery extends TeamSpeak3_Adapter_Abstract
{
/**
* Stores a singleton instance of the active TeamSpeak3_Node_Host object.
*
* @var TeamSpeak3_Node_Host
*/
protected $host = null;
/**
* Stores the timestamp of the last command.
*
* @var integer
*/
protected $timer = null;
/**
* Number of queries executed on the server.
*
* @var integer
*/
protected $count = 0;
/**
* Stores an array with unsupported commands.
*
* @var array
*/
protected $block = array("help");
/**
* Connects the TeamSpeak3_Transport_Abstract object and performs initial actions on the remote
* server.
*
* @throws TeamSpeak3_Adapter_Exception
* @return void
*/
protected function syn()
{
$this->initTransport($this->options);
$this->transport->setAdapter($this);
TeamSpeak3_Helper_Profiler::init(spl_object_hash($this));
if(!$this->getTransport()->readLine()->startsWith(TeamSpeak3::READY))
{
throw new TeamSpeak3_Adapter_Exception("invalid reply from the server");
}
TeamSpeak3_Helper_Signal::getInstance()->emit("serverqueryConnected", $this);
}
/**
* The TeamSpeak3_Adapter_ServerQuery destructor.
*
* @return void
*/
public function __destruct()
{
if($this->getTransport() instanceof TeamSpeak3_Transport_Abstract && $this->transport->isConnected())
{
try
{
$this->request("quit");
}
catch(Exception $e)
{
return;
}
}
}
/**
* Sends a prepared command to the server and returns the result.
*
* @param string $cmd
* @param boolean $throw
* @throws TeamSpeak3_Adapter_Exception
* @return TeamSpeak3_Adapter_ServerQuery_Reply
*/
public function request($cmd, $throw = TRUE)
{
$query = TeamSpeak3_Helper_String::factory($cmd)->section(TeamSpeak3::SEPARATOR_CELL);
if(strstr($cmd, "\r") || strstr($cmd, "\n"))
{
throw new TeamSpeak3_Adapter_Exception("illegal characters in command '" . $query . "'");
}
elseif(in_array($query, $this->block))
{
throw new TeamSpeak3_Adapter_ServerQuery_Exception("command not found", 0x100);
}
TeamSpeak3_Helper_Signal::getInstance()->emit("serverqueryCommandStarted", $cmd);
$this->getProfiler()->start();
$this->getTransport()->sendLine($cmd);
$this->timer = time();
$this->count++;
$rpl = array();
do {
$str = $this->getTransport()->readLine();
$rpl[] = $str;
} while($str instanceof TeamSpeak3_Helper_String && $str->section(TeamSpeak3::SEPARATOR_CELL) != TeamSpeak3::ERROR);
$this->getProfiler()->stop();
$reply = new TeamSpeak3_Adapter_ServerQuery_Reply($rpl, $cmd, $this->getHost(), $throw);
TeamSpeak3_Helper_Signal::getInstance()->emit("serverqueryCommandFinished", $cmd, $reply);
return $reply;
}
/**
* Waits for the server to send a notification message and returns the result.
*
* @throws TeamSpeak3_Adapter_Exception
* @return TeamSpeak3_Adapter_ServerQuery_Event
*/
public function wait()
{
if($this->getTransport()->getConfig("blocking"))
{
throw new TeamSpeak3_Adapter_Exception("only available in non-blocking mode");
}
do {
$evt = $this->getTransport()->readLine();
} while($evt instanceof TeamSpeak3_Helper_String && !$evt->section(TeamSpeak3::SEPARATOR_CELL)->startsWith(TeamSpeak3::EVENT));
return new TeamSpeak3_Adapter_ServerQuery_Event($evt, $this->getHost());
}
/**
* Uses given parameters and returns a prepared ServerQuery command.
*
* @param string $cmd
* @param array $params
* @return string
*/
public function prepare($cmd, array $params = array())
{
$args = array();
$cells = array();
foreach($params as $ident => $value)
{
$ident = is_numeric($ident) ? "" : strtolower($ident) . TeamSpeak3::SEPARATOR_PAIR;
if(is_array($value))
{
$value = array_values($value);
for($i = 0; $i < count($value); $i++)
{
if($value[$i] === null) continue;
elseif($value[$i] === FALSE) $value[$i] = 0x00;
elseif($value[$i] === TRUE) $value[$i] = 0x01;
elseif($value[$i] instanceof TeamSpeak3_Node_Abstract) $value[$i] = $value[$i]->getId();
$cells[$i][] = $ident . TeamSpeak3_Helper_String::factory($value[$i])->escape()->toUtf8();
}
}
else
{
if($value === null) continue;
elseif($value === FALSE) $value = 0x00;
elseif($value === TRUE) $value = 0x01;
elseif($value instanceof TeamSpeak3_Node_Abstract) $value = $value->getId();
$args[] = $ident . TeamSpeak3_Helper_String::factory($value)->escape()->toUtf8();
}
}
foreach(array_keys($cells) as $ident) $cells[$ident] = implode(TeamSpeak3::SEPARATOR_CELL, $cells[$ident]);
if(count($args)) $cmd .= " " . implode(TeamSpeak3::SEPARATOR_CELL, $args);
if(count($cells)) $cmd .= " " . implode(TeamSpeak3::SEPARATOR_LIST, $cells);
return trim($cmd);
}
/**
* Returns the timestamp of the last command.
*
* @return integer
*/
public function getQueryLastTimestamp()
{
return $this->timer;
}
/**
* Returns the number of queries executed on the server.
*
* @return integer
*/
public function getQueryCount()
{
return $this->count;
}
/**
* Returns the total runtime of all queries.
*
* @return mixed
*/
public function getQueryRuntime()
{
return $this->getProfiler()->getRuntime();
}
/**
* Returns the TeamSpeak3_Node_Host object of the current connection.
*
* @return TeamSpeak3_Node_Host
*/
public function getHost()
{
if($this->host === null)
{
$this->host = new TeamSpeak3_Node_Host($this);
}
return $this->host;
}
}
<?php
/**
* @file
* TeamSpeak 3 PHP Framework
*
* $Id: Event.php 06/06/2016 22:27:13 scp@Svens-iMac $
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @package TeamSpeak3
* @version 1.1.24
* @author Sven 'ScP' Paulsen
* @copyright Copyright (c) 2010 by Planet TeamSpeak. All rights reserved.
*/
/**
* @class TeamSpeak3_Adapter_ServerQuery_Event
* @brief Provides methods to analyze and format a ServerQuery event.
*/
class TeamSpeak3_Adapter_ServerQuery_Event implements ArrayAccess
{
/**
* Stores the event type.
*
* @var TeamSpeak3_Helper_String
*/
protected $type = null;
/**
* Stores the event data.
*
* @var array
*/
protected $data = null;
/**
* Stores the event data as an unparsed string.
*
* @var TeamSpeak3_Helper_String
*/
protected $mesg = null;
/**
* Creates a new TeamSpeak3_Adapter_ServerQuery_Event object.
*
* @param TeamSpeak3_Helper_String $evt
* @param TeamSpeak3_Node_Host $con
* @throws TeamSpeak3_Adapter_Exception
* @return TeamSpeak3_Adapter_ServerQuery_Event
*/
public function __construct(TeamSpeak3_Helper_String $evt, TeamSpeak3_Node_Host $con = null)
{
if(!$evt->startsWith(TeamSpeak3::EVENT))
{
throw new TeamSpeak3_Adapter_Exception("invalid notification event format");
}
list($type, $data) = $evt->split(TeamSpeak3::SEPARATOR_CELL, 2);
if(empty($data))
{
throw new TeamSpeak3_Adapter_Exception("invalid notification event data");
}
$fake = new TeamSpeak3_Helper_String(TeamSpeak3::ERROR . TeamSpeak3::SEPARATOR_CELL . "id" . TeamSpeak3::SEPARATOR_PAIR . 0 . TeamSpeak3::SEPARATOR_CELL . "msg" . TeamSpeak3::SEPARATOR_PAIR . "ok");
$repl = new TeamSpeak3_Adapter_ServerQuery_Reply(array($data, $fake), $type);
$this->type = $type->substr(strlen(TeamSpeak3::EVENT));
$this->data = $repl->toList();
$this->mesg = $data;
TeamSpeak3_Helper_Signal::getInstance()->emit("notifyEvent", $this, $con);
TeamSpeak3_Helper_Signal::getInstance()->emit("notify" . ucfirst($this->type), $this, $con);
}
/**
* Returns the event type string.
*
* @return TeamSpeak3_Helper_String
*/
public function getType()
{
return $this->type;
}
/**
* Returns the event data array.
*
* @return array
*/
public function getData()
{
return $this->data;
}
/**
* Returns the event data as an unparsed string.
*
* @return TeamSpeak3_Helper_String
*/
public function getMessage()
{
return $this->mesg;
}
/**
* @ignore
*/
public function offsetExists($offset)
{
return array_key_exists($offset, $this->data) ? TRUE : FALSE;
}
/**
* @ignore
*/
public function offsetGet($offset)
{
if(!$this->offsetExists($offset))
{
throw new TeamSpeak3_Adapter_ServerQuery_Exception("invalid parameter", 0x602);
}
return $this->data[$offset];
}
/**
* @ignore
*/
public function offsetSet($offset, $value)
{
throw new TeamSpeak3_Node_Exception("event '" . $this->getType() . "' is read only");
}
/**
* @ignore
*/
public function offsetUnset($offset)
{
unset($this->data[$offset]);
}
/**
* @ignore
*/
public function __get($offset)
{
return $this->offsetGet($offset);
}
/**
* @ignore
*/
public function __set($offset, $value)
{
$this->offsetSet($offset, $value);
}
}
<?php
/**
* @file
* TeamSpeak 3 PHP Framework
*
* $Id: Exception.php 06/06/2016 22:27:13 scp@Svens-iMac $
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @package TeamSpeak3
* @version 1.1.24
* @author Sven 'ScP' Paulsen
* @copyright Copyright (c) 2010 by Planet TeamSpeak. All rights reserved.
*/
/**
* @class TeamSpeak3_Adapter_ServerQuery_Exception
* @brief Enhanced exception class for TeamSpeak3_Adapter_ServerQuery objects.
*/
class TeamSpeak3_Adapter_ServerQuery_Exception extends TeamSpeak3_Adapter_Exception {}
<?php
/**
* @file
* TeamSpeak 3 PHP Framework
*
* $Id: Reply.php 06/06/2016 22:27:13 scp@Svens-iMac $
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @package TeamSpeak3
* @version 1.1.24
* @author Sven 'ScP' Paulsen
* @copyright Copyright (c) 2010 by Planet TeamSpeak. All rights reserved.
*/
/**
* @class TeamSpeak3_Adapter_ServerQuery_Reply
* @brief Provides methods to analyze and format a ServerQuery reply.
*/
class TeamSpeak3_Adapter_ServerQuery_Reply
{
/**
* Stores the command used to get this reply.
*
* @var TeamSpeak3_Helper_String
*/
protected $cmd = null;
/**
* Stores the servers reply (if available).
*
* @var TeamSpeak3_Helper_String
*/
protected $rpl = null;
/**
* Stores connected TeamSpeak3_Node_Host object.
*
* @var TeamSpeak3_Node_Host
*/
protected $con = null;
/**
* Stores an assoc array containing the error info for this reply.
*
* @var array
*/
protected $err = array();
/**
* Sotres an array of events that occured before or during this reply.
*
* @var array
*/
protected $evt = array();
/**
* Indicates whether exceptions should be thrown or not.
*
* @var boolean
*/
protected $exp = TRUE;
/**
* Creates a new TeamSpeak3_Adapter_ServerQuery_Reply object.
*
* @param array $rpl
* @param string $cmd
* @param boolean $exp
* @param TeamSpeak3_Node_Host $con
* @return TeamSpeak3_Adapter_ServerQuery_Reply
*/
public function __construct(array $rpl, $cmd = null, TeamSpeak3_Node_Host $con = null, $exp = TRUE)
{
$this->cmd = new TeamSpeak3_Helper_String($cmd);
$this->con = $con;
$this->exp = (bool) $exp;
$this->fetchError(array_pop($rpl));
$this->fetchReply($rpl);
}
/**
* Returns the reply as an TeamSpeak3_Helper_String object.
*
* @return TeamSpeak3_Helper_String
*/
public function toString()
{
return (!func_num_args()) ? $this->rpl->unescape() : $this->rpl;
}
/**
* Returns the reply as a standard PHP array where each element represents one item.
*
* @return array
*/
public function toLines()
{
if(!count($this->rpl)) return array();
$list = $this->toString(0)->split(TeamSpeak3::SEPARATOR_LIST);
if(!func_num_args())
{
for($i = 0; $i < count($list); $i++) $list[$i]->unescape();
}
return $list;
}
/**
* Returns the reply as a standard PHP array where each element represents one item in table format.
*
* @return array
*/
public function toTable()
{
$table = array();
foreach($this->toLines(0) as $cells)
{
$pairs = $cells->split(TeamSpeak3::SEPARATOR_CELL);
if(!func_num_args())
{
for($i = 0; $i < count($pairs); $i++) $pairs[$i]->unescape();
}
$table[] = $pairs;
}
return $table;
}
/**
* Returns a multi-dimensional array containing the reply splitted in multiple rows and columns.
*
* @return array
*/
public function toArray()
{
$array = array();
$table = $this->toTable(1);
for($i = 0; $i < count($table); $i++)
{
foreach($table[$i] as $pair)
{
if(!count($pair))
{
continue;
}
if(!$pair->contains(TeamSpeak3::SEPARATOR_PAIR))
{
$array[$i][$pair->toString()] = null;
}
else
{
list($ident, $value) = $pair->split(TeamSpeak3::SEPARATOR_PAIR, 2);
$array[$i][$ident->toString()] = $value->isInt() ? $value->toInt() : (!func_num_args() ? $value->unescape() : $value);
}
}
}
return $array;
}
/**
* Returns a multi-dimensional assoc array containing the reply splitted in multiple rows and columns.
* The identifier specified by key will be used while indexing the array.
*
* @param $key
* @return array
*/
public function toAssocArray($ident)
{
$nodes = (func_num_args() > 1) ? $this->toArray(1) : $this->toArray();
$array = array();
foreach($nodes as $node)
{
if(isset($node[$ident]))
{
$array[(is_object($node[$ident])) ? $node[$ident]->toString() : $node[$ident]] = $node;
}
else
{
throw new TeamSpeak3_Adapter_ServerQuery_Exception("invalid parameter", 0x602);
}
}
return $array;
}
/**
* Returns an array containing the reply splitted in multiple rows and columns.
*
* @return array
*/
public function toList()
{
$array = func_num_args() ? $this->toArray(1) : $this->toArray();
if(count($array) == 1)
{
return array_shift($array);
}
return $array;
}
/**
* Returns an array containing stdClass objects.
*
* @return ArrayObject
*/
public function toObjectArray()
{
$array = (func_num_args() > 1) ? $this->toArray(1) : $this->toArray();
for($i = 0; $i < count($array); $i++)
{
$array[$i] = (object) $array[$i];
}
return $array;
}
/**
* Returns the command used to get this reply.
*
* @return TeamSpeak3_Helper_String
*/
public function getCommandString()
{
return new TeamSpeak3_Helper_String($this->cmd);
}
/**
* Returns an array of events that occured before or during this reply.
*
* @return array
*/
public function getNotifyEvents()
{
return $this->evt;
}
/**
* Returns the value for a specified error property.
*
* @param string $ident
* @param mixed $default
* @return mixed
*/
public function getErrorProperty($ident, $default = null)
{
return (array_key_exists($ident, $this->err)) ? $this->err[$ident] : $default;
}
/**
* Parses a ServerQuery error and throws a TeamSpeak3_Adapter_ServerQuery_Exception object if
* there's an error.
*
* @param string $err
* @throws TeamSpeak3_Adapter_ServerQuery_Exception
* @return void
*/
protected function fetchError($err)
{
$cells = $err->section(TeamSpeak3::SEPARATOR_CELL, 1, 3);
foreach($cells->split(TeamSpeak3::SEPARATOR_CELL) as $pair)
{
list($ident, $value) = $pair->split(TeamSpeak3::SEPARATOR_PAIR);
$this->err[$ident->toString()] = $value->isInt() ? $value->toInt() : $value->unescape();
}
TeamSpeak3_Helper_Signal::getInstance()->emit("notifyError", $this);
if($this->getErrorProperty("id", 0x00) != 0x00 && $this->exp)
{
if($permid = $this->getErrorProperty("failed_permid"))
{
if($permsid = key($this->con->request("permget permid=" . $permid, FALSE)->toAssocArray("permsid")))
{
$suffix = " (failed on " . $permsid . ")";
}
else
{
$suffix = " (failed on " . $this->cmd->section(TeamSpeak3::SEPARATOR_CELL) . " " . $permid . "/0x" . strtoupper(dechex($permid)) . ")";
}
}
elseif($details = $this->getErrorProperty("extra_msg"))
{
$suffix = " (" . trim($details) . ")";
}
else
{
$suffix = "";
}
throw new TeamSpeak3_Adapter_ServerQuery_Exception($this->getErrorProperty("msg") . $suffix, $this->getErrorProperty("id"));
}
}
/**
* Parses a ServerQuery reply and creates a TeamSpeak3_Helper_String object.
*
* @param string $rpl
* @return void
*/
protected function fetchReply($rpl)
{
foreach($rpl as $key => $val)
{
if($val->startsWith(TeamSpeak3::GREET))
{
unset($rpl[$key]);
}
elseif($val->startsWith(TeamSpeak3::EVENT))
{
$this->evt[] = new TeamSpeak3_Adapter_ServerQuery_Event($rpl[$key], $this->con);
unset($rpl[$key]);
}
}
$this->rpl = new TeamSpeak3_Helper_String(implode(TeamSpeak3::SEPARATOR_LIST, $rpl));
}
}
<?php
/**
* @file
* TeamSpeak 3 PHP Framework
*
* $Id: TSDNS.php 06/06/2016 22:27:13 scp@Svens-iMac $
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @package TeamSpeak3
* @version 1.1.24
* @author Sven 'ScP' Paulsen
* @copyright Copyright (c) 2010 by Planet TeamSpeak. All rights reserved.
*/
/**
* @class TeamSpeak3_Adapter_TSDNS
* @brief Provides methods to query a TSDNS server.
*/
class TeamSpeak3_Adapter_TSDNS extends TeamSpeak3_Adapter_Abstract
{
/**
* The TCP port number used by any TSDNS server.
*
* @var integer
*/
protected $default_port = 41144;
/**
* Connects the TeamSpeak3_Transport_Abstract object and performs initial actions on the remote
* server.
*
* @throws TeamSpeak3_Adapter_Exception
* @return void
*/
public function syn()
{
if(!isset($this->options["port"]) || empty($this->options["port"])) $this->options["port"] = $this->default_port;
$this->initTransport($this->options);
$this->transport->setAdapter($this);
TeamSpeak3_Helper_Profiler::init(spl_object_hash($this));
TeamSpeak3_Helper_Signal::getInstance()->emit("tsdnsConnected", $this);
}
/**
* The TeamSpeak3_Adapter_FileTransfer destructor.
*
* @return void
*/
public function __destruct()
{
if($this->getTransport() instanceof TeamSpeak3_Transport_Abstract && $this->getTransport()->isConnected())
{
$this->getTransport()->disconnect();
}
}
/**
* Queries the TSDNS server for a specified virtual hostname and returns the result.
*
* @param string $tsdns
* @throws TeamSpeak3_Adapter_TSDNS_Exception
* @return TeamSpeak3_Helper_String
*/
public function resolve($tsdns)
{
$this->getTransport()->sendLine($tsdns);
$repl = $this->getTransport()->readLine();
$this->getTransport()->disconnect();
if($repl->section(":", 0)->toInt() == 404)
{
throw new TeamSpeak3_Adapter_TSDNS_Exception("unable to resolve TSDNS hostname (" . $tsdns . ")");
}
TeamSpeak3_Helper_Signal::getInstance()->emit("tsdnsResolved", $tsdns, $repl);
return $repl;
}
}
<?php
/**
* @file
* TeamSpeak 3 PHP Framework
*
* $Id: Exception.php 06/06/2016 22:27:13 scp@Svens-iMac $
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @package TeamSpeak3
* @version 1.1.24
* @author Sven 'ScP' Paulsen
* @copyright Copyright (c) 2010 by Planet TeamSpeak. All rights reserved.
*/
/**
* @class TeamSpeak3_Adapter_TSDNS_Exception
* @brief Enhanced exception class for TeamSpeak3_Adapter_TSDNS objects.
*/
class TeamSpeak3_Adapter_TSDNS_Exception extends TeamSpeak3_Adapter_Exception {}
<?php
/**
* @file
* TeamSpeak 3 PHP Framework
*
* $Id: Update.php 06/06/2016 22:27:13 scp@Svens-iMac $
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @package TeamSpeak3
* @version 1.1.24
* @author Sven 'ScP' Paulsen
* @copyright Copyright (c) 2010 by Planet TeamSpeak. All rights reserved.
*/
/**
* @class TeamSpeak3_Adapter_Update
* @brief Provides methods to query the latest TeamSpeak 3 build numbers from the master server.
*/
class TeamSpeak3_Adapter_Update extends TeamSpeak3_Adapter_Abstract
{
/**
* The IPv4 address or FQDN of the TeamSpeak Systems update server.
*
* @var string
*/
protected $default_host = "update.teamspeak.com";
/**
* The UDP port number of the TeamSpeak Systems update server.
*
* @var integer
*/
protected $default_port = 17384;
/**
* Stores an array containing the latest build numbers (integer timestamps).
*
* @var array
*/
protected $build_datetimes = null;
/**
* Stores an array containing the latest version strings.
*
* @var array
*/
protected $version_strings = null;
/**
* Connects the TeamSpeak3_Transport_Abstract object and performs initial actions on the remote
* server.
*
* @throws TeamSpeak3_Adapter_Update_Exception
* @return void
*/
public function syn()
{
if(!isset($this->options["host"]) || empty($this->options["host"])) $this->options["host"] = $this->default_host;
if(!isset($this->options["port"]) || empty($this->options["port"])) $this->options["port"] = $this->default_port;
$this->initTransport($this->options, "TeamSpeak3_Transport_UDP");
$this->transport->setAdapter($this);
TeamSpeak3_Helper_Profiler::init(spl_object_hash($this));
$this->getTransport()->send(TeamSpeak3_Helper_String::fromHex(33));
if(!preg_match_all("/,?(\d+)#([0-9a-zA-Z\._-]+),?/", $this->getTransport()->read(96), $matches) || !isset($matches[1]) || !isset($matches[2]))
{
throw new TeamSpeak3_Adapter_Update_Exception("invalid reply from the server");
}
$this->build_datetimes = $matches[1];
$this->version_strings = $matches[2];
TeamSpeak3_Helper_Signal::getInstance()->emit("updateConnected", $this);
}
/**
* The TeamSpeak3_Adapter_Update destructor.
*
* @return void
*/
public function __destruct()
{
if($this->getTransport() instanceof TeamSpeak3_Transport_Abstract && $this->getTransport()->isConnected())
{
$this->getTransport()->disconnect();
}
}
/**
* Returns the current build number for a specified update channel. Note that since version
* 3.0.0, the build number represents an integer timestamp. $channel must be set to one of
* the following values:
*
* - stable
* - beta
* - alpha
* - server
*
* @param string $channel
* @throws TeamSpeak3_Adapter_Update_Exception
* @return integer
*/
public function getRev($channel = "stable")
{
switch($channel)
{
case "stable":
return isset($this->build_datetimes[0]) ? $this->build_datetimes[0] : null;
case "beta":
return isset($this->build_datetimes[1]) ? $this->build_datetimes[1] : null;
case "alpha":
return isset($this->build_datetimes[2]) ? $this->build_datetimes[2] : null;
case "server":
return isset($this->build_datetimes[3]) ? $this->build_datetimes[3] : null;
default:
throw new TeamSpeak3_Adapter_Update_Exception("invalid update channel identifier (" . $channel . ")");
}
}
/**
* Returns the current version string for a specified update channel. $channel must be set to
* one of the following values:
*
* - stable
* - beta
* - alpha
* - server
*
* @param string $channel
* @throws TeamSpeak3_Adapter_Update_Exception
* @return integer
*/
public function getVersion($channel = "stable")
{
switch($channel)
{
case "stable":
return isset($this->version_strings[0]) ? $this->version_strings[0] : null;
case "beta":
return isset($this->version_strings[1]) ? $this->version_strings[1] : null;
case "alpha":
return isset($this->version_strings[2]) ? $this->version_strings[2] : null;
case "server":
return isset($this->version_strings[3]) ? $this->version_strings[3] : null;
default:
throw new TeamSpeak3_Adapter_Update_Exception("invalid update channel identifier (" . $channel . ")");
}
}
/**
* Alias for getRev() using the 'stable' update channel.
*
* @param string $channel
* @return integer
*/
public function getClientRev()
{
return $this->getRev("stable");
}
/**
* Alias for getRev() using the 'server' update channel.
*
* @param string $channel
* @return integer
*/
public function getServerRev()
{
return $this->getRev("server");
}
/**
* Alias for getVersion() using the 'stable' update channel.
*
* @param string $channel
* @return integer
*/
public function getClientVersion()
{
return $this->getVersion("stable");
}
/**
* Alias for getVersion() using the 'server' update channel.
*
* @param string $channel
* @return integer
*/
public function getServerVersion()
{
return $this->getVersion("server");
}
}
<?php
/**
* @file
* TeamSpeak 3 PHP Framework
*
* $Id: Exception.php 06/06/2016 22:27:13 scp@Svens-iMac $
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @package TeamSpeak3
* @version 1.1.24
* @author Sven 'ScP' Paulsen
* @copyright Copyright (c) 2010 by Planet TeamSpeak. All rights reserved.
*/
/**
* @class TeamSpeak3_Adapter_Update_Exception
* @brief Enhanced exception class for TeamSpeak3_Adapter_Update objects.
*/
class TeamSpeak3_Adapter_Update_Exception extends TeamSpeak3_Adapter_Exception {}
<?php
/**
* @file
* TeamSpeak 3 PHP Framework
*
* $Id: Exception.php 06/06/2016 22:27:13 scp@Svens-iMac $
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @package TeamSpeak3
* @version 1.1.24
* @author Sven 'ScP' Paulsen
* @copyright Copyright (c) 2010 by Planet TeamSpeak. All rights reserved.
*/
/**
* @class TeamSpeak3_Exception
* @brief Enhanced exception class for TeamSpeak3 objects.
*/
class TeamSpeak3_Exception extends Exception
{
/**
* Stores custom error messages.
*
* @var array
*/
protected static $messages = array();
/**
* The TeamSpeak3_Exception constructor.
*
* @param string $mesg
* @param integer $code
* @return TeamSpeak3_Exception
*/
public function __construct($mesg, $code = 0x00)
{
parent::__construct($mesg, $code);
if(array_key_exists((int) $code, self::$messages))
{
$this->message = $this->prepareCustomMessage(self::$messages[intval($code)]);
}
TeamSpeak3_Helper_Signal::getInstance()->emit("errorException", $this);
}
/**
* Prepares a custom error message by replacing pre-defined signs with given values.
*
* @param TeamSpeak3_Helper_String $mesg
* @return TeamSpeak3_Helper_String
*/
protected function prepareCustomMessage(TeamSpeak3_Helper_String $mesg)
{
$args = array(
"code" => $this->getCode(),
"mesg" => $this->getMessage(),
"line" => $this->getLine(),
"file" => $this->getFile(),
);
return $mesg->arg($args)->toString();
}
/**
* Registers a custom error message to $code.
*
* @param integer $code
* @param string $mesg
* @throws TeamSpeak3_Exception
* @return void
*/
public static function registerCustomMessage($code, $mesg)
{
if(array_key_exists((int) $code, self::$messages))
{
throw new self("custom message for code 0x" . strtoupper(dechex($code)) . " is already registered");
}
if(!is_string($mesg))
{
throw new self("custom message for code 0x" . strtoupper(dechex($code)) . " must be a string");
}
self::$messages[(int) $code] = new TeamSpeak3_Helper_String($mesg);
}
/**
* Unregisters a custom error message from $code.
*
* @param integer $code
* @throws TeamSpeak3_Exception
* @return void
*/
public static function unregisterCustomMessage($code)
{
if(!array_key_exists((int) $code, self::$messages))
{
throw new self("custom message for code 0x" . strtoupper(dechex($code)) . " is not registered");
}
unset(self::$messages[(int) $code]);
}
/**
* Returns the class from which the exception was thrown.
*
* @return string
*/
public function getSender()
{
$trace = $this->getTrace();
return (isset($trace[0]["class"])) ? $trace[0]["class"] : "{main}";
}
}
<?php
/**
* @file
* TeamSpeak 3 PHP Framework
*
* $Id: Char.php 06/06/2016 22:27:13 scp@Svens-iMac $
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @package TeamSpeak3
* @version 1.1.24
* @author Sven 'ScP' Paulsen
* @copyright Copyright (c) 2010 by Planet TeamSpeak. All rights reserved.
*/
/**
* @class TeamSpeak3_Helper_Char
* @brief Helper class for char handling.
*/
class TeamSpeak3_Helper_Char
{
/**
* Stores the original character.
*
* @var string
*/
protected $char = null;
/**
* The TeamSpeak3_Helper_Char constructor.
*
* @param string $var
* @throws TeamSpeak3_Helper_Exception
* @return TeamSpeak3_Helper_Char
*/
public function __construct($char)
{
if(strlen($char) != 1)
{
throw new TeamSpeak3_Helper_Exception("char parameter may not contain more or less than one character");
}
$this->char = strval($char);
}
/**
* Returns true if the character is a letter.
*
* @return boolean
*/
public function isLetter()
{
return ctype_alpha($this->char);
}
/**
* Returns true if the character is a decimal digit.
*
* @return boolean
*/
public function isDigit()
{
return ctype_digit($this->char);
}
/**
* Returns true if the character is a space.
*
* @return boolean
*/
public function isSpace()
{
return ctype_space($this->char);
}
/**
* Returns true if the character is a mark.
*
* @return boolean
*/
public function isMark()
{
return ctype_punct($this->char);
}
/**
* Returns true if the character is a control character (i.e. "\t").
*
* @return boolean
*/
public function isControl()
{
return ctype_cntrl($this->char);
}
/**
* Returns true if the character is a printable character.
*
* @return boolean
*/
public function isPrintable()
{
return ctype_print($this->char);
}
/**
* Returns true if the character is the Unicode character 0x0000 ("\0").
*
* @return boolean
*/
public function isNull()
{
return ($this->char === "\0") ? TRUE : FALSE;
}
/**
* Returns true if the character is an uppercase letter.
*
* @return boolean
*/
public function isUpper()
{
return ($this->char === strtoupper($this->char)) ? TRUE : FALSE;
}
/**
* Returns true if the character is a lowercase letter.
*
* @return boolean
*/
public function isLower()
{
return ($this->char === strtolower($this->char)) ? TRUE : FALSE;
}
/**
* Returns the uppercase equivalent if the character is lowercase.
*
* @return TeamSpeak3_Helper_Char
*/
public function toUpper()
{
return ($this->isUpper()) ? $this : new self(strtoupper($this));
}
/**
* Returns the lowercase equivalent if the character is uppercase.
*
* @return TeamSpeak3_Helper_Char
*/
public function toLower()
{
return ($this->isLower()) ? $this : new self(strtolower($this));
}
/**
* Returns the ascii value of the character.
*
* @return integer
*/
public function toAscii()
{
return ord($this->char);
}
/**
* Returns the Unicode value of the character.
*
* @return integer
*/
public function toUnicode()
{
$h = ord($this->char{0});
if($h <= 0x7F)
{
return $h;
}
else if($h < 0xC2)
{
return FALSE;
}
else if($h <= 0xDF)
{
return ($h & 0x1F) << 6 | (ord($this->char{1}) & 0x3F);
}
else if($h <= 0xEF)
{
return ($h & 0x0F) << 12 | (ord($this->char{1}) & 0x3F) << 6 | (ord($this->char{2}) & 0x3F);
}
else if($h <= 0xF4)
{
return ($h & 0x0F) << 18 | (ord($this->char{1}) & 0x3F) << 12 | (ord($this->char{2}) & 0x3F) << 6 | (ord($this->char{3}) & 0x3F);
}
else
{
return FALSE;
}
}
/**
* Returns the hexadecimal value of the char.
*
* @return string
*/
public function toHex()
{
return strtoupper(dechex($this->toAscii()));
}
/**
* Returns the TeamSpeak3_Helper_Char based on a given hex value.
*
* @param string $hex
* @throws TeamSpeak3_Helper_Exception
* @return TeamSpeak3_Helper_Char
*/
public static function fromHex($hex)
{
if(strlen($hex) != 2)
{
throw new TeamSpeak3_Helper_Exception("given parameter '" . $hex . "' is not a valid hexadecimal number");
}
return new self(chr(hexdec($hex)));
}
/**
* Returns the character as a standard string.
*
* @return string
*/
public function toString()
{
return $this->char;
}
/**
* Returns the integer value of the character.
*
* @return integer
*/
public function toInt()
{
return intval($this->char);
}
/**
* Returns the character as a standard string.
*
* @return string
*/
public function __toString()
{
return $this->char;
}
}
<?php
/**
* @file
* TeamSpeak 3 PHP Framework
*
* $Id: Convert.php 06/06/2016 22:27:13 scp@Svens-iMac $
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @package TeamSpeak3
* @version 1.1.24
* @author Sven 'ScP' Paulsen
* @copyright Copyright (c) 2010 by Planet TeamSpeak. All rights reserved.
*/
/**
* @class TeamSpeak3_Helper_Convert
* @brief Helper class for data conversion.
*/
class TeamSpeak3_Helper_Convert
{
/**
* Converts bytes to a human readable value.
*
* @param integer $bytes
* @return string
*/
public static function bytes($bytes)
{
$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";
}
/**
* Converts seconds/milliseconds to a human readable value.
*
* @param integer $seconds
* @param boolean $is_ms
* @param string $format
* @return string
*/
public static function seconds($seconds, $is_ms = FALSE, $format = "%dD %02d:%02d:%02d")
{
if($is_ms) $seconds = $seconds/1000;
return sprintf($format, $seconds/60/60/24, ($seconds/60/60)%24, ($seconds/60)%60, $seconds%60);
}
/**
* Converts a given codec ID to a human readable name.
*
* @param integer $codec
* @return string
*/
public static function codec($codec)
{
if($codec == TeamSpeak3::CODEC_SPEEX_NARROWBAND)
return "Speex Narrowband";
if($codec == TeamSpeak3::CODEC_SPEEX_WIDEBAND)
return "Speex Wideband";
if($codec == TeamSpeak3::CODEC_SPEEX_ULTRAWIDEBAND)
return "Speex Ultra-Wideband";
if($codec == TeamSpeak3::CODEC_CELT_MONO)
return "CELT Mono";
if($codec == TeamSpeak3::CODEC_OPUS_VOICE)
return "Opus Voice";
if($codec == TeamSpeak3::CODEC_OPUS_MUSIC)
return "Opus Music";
return "Unknown";
}
/**
* Converts a given group type ID to a human readable name.
*
* @param integer $type
* @return string
*/
public static function groupType($type)
{
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";
}
/**
* Converts a given permission type ID to a human readable name.
*
* @param integer $type
* @return string
*/
public static function permissionType($type)
{
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";
}
/**
* Converts a given permission category value to a human readable name.
*
* @param integer $pcat
* @return string
*/
public static function permissionCategory($pcat)
{
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";
}
/**
* Converts a given log level ID to a human readable name and vice versa.
*
* @param mixed $level
* @return string
*/
public static function logLevel($level)
{
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;
}
}
/**
* Converts a specified log entry string into an array containing the data.
*
* @param string $entry
* @return array
*/
public static function logEntry($entry)
{
$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;
}
/**
* Converts a given string to a ServerQuery password hash.
*
* @param string $plain
* @return string
*/
public static function password($plain)
{
return base64_encode(sha1($plain, TRUE));
}
/**
* Returns a client-like formatted version of the TeamSpeak 3 version string.
*
* @param string $version
* @param string $format
* @return string
*/
public static function version($version, $format = "Y-m-d h: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) . ")");
}
/**
* Returns a client-like short-formatted version of the TeamSpeak 3 version string.
*
* @param string $version
* @return string
*/
public static function versionShort($version)
{
if(!$version instanceof TeamSpeak3_Helper_String)
{
$version = new TeamSpeak3_Helper_String($version);
}
return $version->section(" ", 0);
}
/**
* Tries to detect the type of an image by a given string and returns it.
*
* @param string $binary
* @return string
*/
public static function imageMimeType($binary)
{
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];
}
}
<?php
/**
* @file
* TeamSpeak 3 PHP Framework
*
* $Id: Crypt.php 06/06/2016 22:27:13 scp@Svens-iMac $
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @package TeamSpeak3
* @version 1.1.24
* @author Sven 'ScP' Paulsen
* @copyright Copyright (c) 2010 by Planet TeamSpeak. All rights reserved.
*/
/**
* @class TeamSpeak3_Helper_Crypt
* @brief Helper class for data encryption.
*/
class TeamSpeak3_Helper_Crypt
{
/**
* Stores the secret passphrase to encrypt or decrypt a given string.
*
* @var string
*/
protected $passphrase = null;
/**
* Stores an array containing 18 32-bit entries.
*
* @var array
*/
protected $p = array();
/**
* Stores an array containing 4 sub-arrays with 256 32-bit entries.
*
* @var array
*/
protected $s = array();
/**
* The TeamSpeak3_Helper_Crypt constructor.
*
* @param string $secret
* @return TeamSpeak3_Helper_Crypt
*/
public function __construct($secret)
{
$this->setDefaultKeys();
$this->setSecretKey($secret);
}
/**
* Encrypts a given string.
*
* @param string $string
* @return string
*/
public function encrypt($string)
{
$string = trim($string);
$encryp = "";
$length = strlen($string);
$string .= str_repeat(chr(0), (8-($length%8))%8);
for($i = 0; $i < $length; $i += 8)
{
list(,$xl,$xr) = unpack("N2", substr($string, $i, 8));
$this->encipher($xl, $xr);
$encryp .= pack("N2", $xl, $xr);
}
return base64_encode($encryp);
}
/**
* Decrypts a given string.
*
* @param string $string
* @return string
*/
public function decrypt($string)
{
$string = base64_decode($string);
$decryp = "";
$length = strlen($string);
$string .= str_repeat(chr(0), (8-($length%8))%8);
for($i = 0; $i < $length; $i += 8)
{
list(,$xl,$xr) = unpack("N2", substr($string, $i, 8));
$this->decipher($xl, $xr);
$decryp .= pack("N2", $xl, $xr);
}
return trim($decryp);
}
/**
* Enciphers a single 64-bit block.
*
* @param integer $xl
* @param integer $xr
*/
protected function encipher(&$xl, &$xr)
{
for($i = 0; $i < 16; $i++)
{
$temp = $xl ^ $this->p[$i];
$xl = ((($this->s[0][($temp>>24) & 255] + $this->s[1][($temp>>16) & 255]) ^ $this->s[2][($temp>>8) & 255]) + $this->s[3][$temp & 255]) ^ $xr;
$xr = $temp;
}
$xr = $xl ^ $this->p[16];
$xl = $temp ^ $this->p[17];
}
/**
* Deciphers a single 64-bit block
*
* @param integer $xl
* @param integer $xr
* @return void
*/
protected function decipher(&$xl, &$xr)
{
for($i = 17; $i > 1; $i--)
{
$temp = $xl ^ $this->p[$i];
$xl = ((($this->s[0][($temp>>24) & 255] + $this->s[1][($temp>>16) & 255]) ^ $this->s[2][($temp>>8) & 255]) + $this->s[3][$temp & 255]) ^ $xr;
$xr = $temp;
}
$xr = $xl ^ $this->p[1];
$xl = $temp ^ $this->p[0];
}
/**
* Sets the secret key using the specified pasphrase.
*
* @param string $passphrase
* @throws Habitat_Exception
* @return void
*/
protected function setSecretKey($passphrase)
{
$length = strlen($passphrase);
if(strlen($passphrase) < 1 || strlen($passphrase) > 56)
{
throw new TeamSpeak3_Helper_Exception("secret passphrase must contain at least one but less than 56 characters");
}
$k = 0;
$data = 0;
$datal = 0;
$datar = 0;
for($i = 0; $i < 18; $i++)
{
$data = 0;
for($j = 4; $j > 0; $j--)
{
$data = $data << 8 | ord($passphrase{$k});
$k = ($k+1) % $length;
}
$this->p[$i] ^= $data;
}
for($i = 0; $i <= 16; $i += 2)
{
$this->encipher($datal, $datar);
$this->p[$i] = $datal;
$this->p[$i+1] = $datar;
}
foreach($this->s as $key => $val)
{
for ($i = 0; $i < 256; $i += 2)
{
$this->encipher($datal, $datar);
$this->s[$key][$i] = $datal;
$this->s[$key][$i+1] = $datar;
}
}
}
/**
* Sets the defult p and s keys.
*
* @return void
*/
protected function setDefaultKeys()
{
$this->p = array(
0x243F6A88, 0x85A308D3, 0x13198A2E, 0x03707344, 0xA4093822, 0x299F31D0,
0x082EFA98, 0xEC4E6C89, 0x452821E6, 0x38D01377, 0xBE5466CF, 0x34E90C6C,
0xC0AC29B7, 0xC97C50DD, 0x3F84D5B5, 0xB5470917, 0x9216D5D9, 0x8979FB1B,
);
$this->s = array(
array(
0xD1310BA6, 0x98DFB5AC, 0x2FFD72DB, 0xD01ADFB7,
0xB8E1AFED, 0x6A267E96, 0xBA7C9045, 0xF12C7F99,
0x24A19947, 0xB3916CF7, 0x0801F2E2, 0x858EFC16,
0x636920D8, 0x71574E69, 0xA458FEA3, 0xF4933D7E,
0x0D95748F, 0x728EB658, 0x718BCD58, 0x82154AEE,
0x7B54A41D, 0xC25A59B5, 0x9C30D539, 0x2AF26013,
0xC5D1B023, 0x286085F0, 0xCA417918, 0xB8DB38EF,
0x8E79DCB0, 0x603A180E, 0x6C9E0E8B, 0xB01E8A3E,
0xD71577C1, 0xBD314B27, 0x78AF2FDA, 0x55605C60,
0xE65525F3, 0xAA55AB94, 0x57489862, 0x63E81440,
0x55CA396A, 0x2AAB10B6, 0xB4CC5C34, 0x1141E8CE,
0xA15486AF, 0x7C72E993, 0xB3EE1411, 0x636FBC2A,
0x2BA9C55D, 0x741831F6, 0xCE5C3E16, 0x9B87931E,
0xAFD6BA33, 0x6C24CF5C, 0x7A325381, 0x28958677,
0x3B8F4898, 0x6B4BB9AF, 0xC4BFE81B, 0x66282193,
0x61D809CC, 0xFB21A991, 0x487CAC60, 0x5DEC8032,
0xEF845D5D, 0xE98575B1, 0xDC262302, 0xEB651B88,
0x23893E81, 0xD396ACC5, 0x0F6D6FF3, 0x83F44239,
0x2E0B4482, 0xA4842004, 0x69C8F04A, 0x9E1F9B5E,
0x21C66842, 0xF6E96C9A, 0x670C9C61, 0xABD388F0,
0x6A51A0D2, 0xD8542F68, 0x960FA728, 0xAB5133A3,
0x6EEF0B6C, 0x137A3BE4, 0xBA3BF050, 0x7EFB2A98,
0xA1F1651D, 0x39AF0176, 0x66CA593E, 0x82430E88,
0x8CEE8619, 0x456F9FB4, 0x7D84A5C3, 0x3B8B5EBE,
0xE06F75D8, 0x85C12073, 0x401A449F, 0x56C16AA6,
0x4ED3AA62, 0x363F7706, 0x1BFEDF72, 0x429B023D,
0x37D0D724, 0xD00A1248, 0xDB0FEAD3, 0x49F1C09B,
0x075372C9, 0x80991B7B, 0x25D479D8, 0xF6E8DEF7,
0xE3FE501A, 0xB6794C3B, 0x976CE0BD, 0x04C006BA,
0xC1A94FB6, 0x409F60C4, 0x5E5C9EC2, 0x196A2463,
0x68FB6FAF, 0x3E6C53B5, 0x1339B2EB, 0x3B52EC6F,
0x6DFC511F, 0x9B30952C, 0xCC814544, 0xAF5EBD09,
0xBEE3D004, 0xDE334AFD, 0x660F2807, 0x192E4BB3,
0xC0CBA857, 0x45C8740F, 0xD20B5F39, 0xB9D3FBDB,
0x5579C0BD, 0x1A60320A, 0xD6A100C6, 0x402C7279,
0x679F25FE, 0xFB1FA3CC, 0x8EA5E9F8, 0xDB3222F8,
0x3C7516DF, 0xFD616B15, 0x2F501EC8, 0xAD0552AB,
0x323DB5FA, 0xFD238760, 0x53317B48, 0x3E00DF82,
0x9E5C57BB, 0xCA6F8CA0, 0x1A87562E, 0xDF1769DB,
0xD542A8F6, 0x287EFFC3, 0xAC6732C6, 0x8C4F5573,
0x695B27B0, 0xBBCA58C8, 0xE1FFA35D, 0xB8F011A0,
0x10FA3D98, 0xFD2183B8, 0x4AFCB56C, 0x2DD1D35B,
0x9A53E479, 0xB6F84565, 0xD28E49BC, 0x4BFB9790,
0xE1DDF2DA, 0xA4CB7E33, 0x62FB1341, 0xCEE4C6E8,
0xEF20CADA, 0x36774C01, 0xD07E9EFE, 0x2BF11FB4,
0x95DBDA4D, 0xAE909198, 0xEAAD8E71, 0x6B93D5A0,
0xD08ED1D0, 0xAFC725E0, 0x8E3C5B2F, 0x8E7594B7,
0x8FF6E2FB, 0xF2122B64, 0x8888B812, 0x900DF01C,
0x4FAD5EA0, 0x688FC31C, 0xD1CFF191, 0xB3A8C1AD,
0x2F2F2218, 0xBE0E1777, 0xEA752DFE, 0x8B021FA1,
0xE5A0CC0F, 0xB56F74E8, 0x18ACF3D6, 0xCE89E299,
0xB4A84FE0, 0xFD13E0B7, 0x7CC43B81, 0xD2ADA8D9,
0x165FA266, 0x80957705, 0x93CC7314, 0x211A1477,
0xE6AD2065, 0x77B5FA86, 0xC75442F5, 0xFB9D35CF,
0xEBCDAF0C, 0x7B3E89A0, 0xD6411BD3, 0xAE1E7E49,
0x00250E2D, 0x2071B35E, 0x226800BB, 0x57B8E0AF,
0x2464369B, 0xF009B91E, 0x5563911D, 0x59DFA6AA,
0x78C14389, 0xD95A537F, 0x207D5BA2, 0x02E5B9C5,
0x83260376, 0x6295CFA9, 0x11C81968, 0x4E734A41,
0xB3472DCA, 0x7B14A94A, 0x1B510052, 0x9A532915,
0xD60F573F, 0xBC9BC6E4, 0x2B60A476, 0x81E67400,
0x08BA6FB5, 0x571BE91F, 0xF296EC6B, 0x2A0DD915,
0xB6636521, 0xE7B9F9B6, 0xFF34052E, 0xC5855664,
0x53B02D5D, 0xA99F8FA1, 0x08BA4799, 0x6E85076A
),
array(
0x4B7A70E9, 0xB5B32944, 0xDB75092E, 0xC4192623,
0xAD6EA6B0, 0x49A7DF7D, 0x9CEE60B8, 0x8FEDB266,
0xECAA8C71, 0x699A17FF, 0x5664526C, 0xC2B19EE1,
0x193602A5, 0x75094C29, 0xA0591340, 0xE4183A3E,
0x3F54989A, 0x5B429D65, 0x6B8FE4D6, 0x99F73FD6,
0xA1D29C07, 0xEFE830F5, 0x4D2D38E6, 0xF0255DC1,
0x4CDD2086, 0x8470EB26, 0x6382E9C6, 0x021ECC5E,
0x09686B3F, 0x3EBAEFC9, 0x3C971814, 0x6B6A70A1,
0x687F3584, 0x52A0E286, 0xB79C5305, 0xAA500737,
0x3E07841C, 0x7FDEAE5C, 0x8E7D44EC, 0x5716F2B8,
0xB03ADA37, 0xF0500C0D, 0xF01C1F04, 0x0200B3FF,
0xAE0CF51A, 0x3CB574B2, 0x25837A58, 0xDC0921BD,
0xD19113F9, 0x7CA92FF6, 0x94324773, 0x22F54701,
0x3AE5E581, 0x37C2DADC, 0xC8B57634, 0x9AF3DDA7,
0xA9446146, 0x0FD0030E, 0xECC8C73E, 0xA4751E41,
0xE238CD99, 0x3BEA0E2F, 0x3280BBA1, 0x183EB331,
0x4E548B38, 0x4F6DB908, 0x6F420D03, 0xF60A04BF,
0x2CB81290, 0x24977C79, 0x5679B072, 0xBCAF89AF,
0xDE9A771F, 0xD9930810, 0xB38BAE12, 0xDCCF3F2E,
0x5512721F, 0x2E6B7124, 0x501ADDE6, 0x9F84CD87,
0x7A584718, 0x7408DA17, 0xBC9F9ABC, 0xE94B7D8C,
0xEC7AEC3A, 0xDB851DFA, 0x63094366, 0xC464C3D2,
0xEF1C1847, 0x3215D908, 0xDD433B37, 0x24C2BA16,
0x12A14D43, 0x2A65C451, 0x50940002, 0x133AE4DD,
0x71DFF89E, 0x10314E55, 0x81AC77D6, 0x5F11199B,
0x043556F1, 0xD7A3C76B, 0x3C11183B, 0x5924A509,
0xF28FE6ED, 0x97F1FBFA, 0x9EBABF2C, 0x1E153C6E,
0x86E34570, 0xEAE96FB1, 0x860E5E0A, 0x5A3E2AB3,
0x771FE71C, 0x4E3D06FA, 0x2965DCB9, 0x99E71D0F,
0x803E89D6, 0x5266C825, 0x2E4CC978, 0x9C10B36A,
0xC6150EBA, 0x94E2EA78, 0xA5FC3C53, 0x1E0A2DF4,
0xF2F74EA7, 0x361D2B3D, 0x1939260F, 0x19C27960,
0x5223A708, 0xF71312B6, 0xEBADFE6E, 0xEAC31F66,
0xE3BC4595, 0xA67BC883, 0xB17F37D1, 0x018CFF28,
0xC332DDEF, 0xBE6C5AA5, 0x65582185, 0x68AB9802,
0xEECEA50F, 0xDB2F953B, 0x2AEF7DAD, 0x5B6E2F84,
0x1521B628, 0x29076170, 0xECDD4775, 0x619F1510,
0x13CCA830, 0xEB61BD96, 0x0334FE1E, 0xAA0363CF,
0xB5735C90, 0x4C70A239, 0xD59E9E0B, 0xCBAADE14,
0xEECC86BC, 0x60622CA7, 0x9CAB5CAB, 0xB2F3846E,
0x648B1EAF, 0x19BDF0CA, 0xA02369B9, 0x655ABB50,
0x40685A32, 0x3C2AB4B3, 0x319EE9D5, 0xC021B8F7,
0x9B540B19, 0x875FA099, 0x95F7997E, 0x623D7DA8,
0xF837889A, 0x97E32D77, 0x11ED935F, 0x16681281,
0x0E358829, 0xC7E61FD6, 0x96DEDFA1, 0x7858BA99,
0x57F584A5, 0x1B227263, 0x9B83C3FF, 0x1AC24696,
0xCDB30AEB, 0x532E3054, 0x8FD948E4, 0x6DBC3128,
0x58EBF2EF, 0x34C6FFEA, 0xFE28ED61, 0xEE7C3C73,
0x5D4A14D9, 0xE864B7E3, 0x42105D14, 0x203E13E0,
0x45EEE2B6, 0xA3AAABEA, 0xDB6C4F15, 0xFACB4FD0,
0xC742F442, 0xEF6ABBB5, 0x654F3B1D, 0x41CD2105,
0xD81E799E, 0x86854DC7, 0xE44B476A, 0x3D816250,
0xCF62A1F2, 0x5B8D2646, 0xFC8883A0, 0xC1C7B6A3,
0x7F1524C3, 0x69CB7492, 0x47848A0B, 0x5692B285,
0x095BBF00, 0xAD19489D, 0x1462B174, 0x23820E00,
0x58428D2A, 0x0C55F5EA, 0x1DADF43E, 0x233F7061,
0x3372F092, 0x8D937E41, 0xD65FECF1, 0x6C223BDB,
0x7CDE3759, 0xCBEE7460, 0x4085F2A7, 0xCE77326E,
0xA6078084, 0x19F8509E, 0xE8EFD855, 0x61D99735,
0xA969A7AA, 0xC50C06C2, 0x5A04ABFC, 0x800BCADC,
0x9E447A2E, 0xC3453484, 0xFDD56705, 0x0E1E9EC9,
0xDB73DBD3, 0x105588CD, 0x675FDA79, 0xE3674340,
0xC5C43465, 0x713E38D8, 0x3D28F89E, 0xF16DFF20,
0x153E21E7, 0x8FB03D4A, 0xE6E39F2B, 0xDB83ADF7
),
array(
0xE93D5A68, 0x948140F7, 0xF64C261C, 0x94692934,
0x411520F7, 0x7602D4F7, 0xBCF46B2E, 0xD4A20068,
0xD4082471, 0x3320F46A, 0x43B7D4B7, 0x500061AF,
0x1E39F62E, 0x97244546, 0x14214F74, 0xBF8B8840,
0x4D95FC1D, 0x96B591AF, 0x70F4DDD3, 0x66A02F45,
0xBFBC09EC, 0x03BD9785, 0x7FAC6DD0, 0x31CB8504,
0x96EB27B3, 0x55FD3941, 0xDA2547E6, 0xABCA0A9A,
0x28507825, 0x530429F4, 0x0A2C86DA, 0xE9B66DFB,
0x68DC1462, 0xD7486900, 0x680EC0A4, 0x27A18DEE,
0x4F3FFEA2, 0xE887AD8C, 0xB58CE006, 0x7AF4D6B6,
0xAACE1E7C, 0xD3375FEC, 0xCE78A399, 0x406B2A42,
0x20FE9E35, 0xD9F385B9, 0xEE39D7AB, 0x3B124E8B,
0x1DC9FAF7, 0x4B6D1856, 0x26A36631, 0xEAE397B2,
0x3A6EFA74, 0xDD5B4332, 0x6841E7F7, 0xCA7820FB,
0xFB0AF54E, 0xD8FEB397, 0x454056AC, 0xBA489527,
0x55533A3A, 0x20838D87, 0xFE6BA9B7, 0xD096954B,
0x55A867BC, 0xA1159A58, 0xCCA92963, 0x99E1DB33,
0xA62A4A56, 0x3F3125F9, 0x5EF47E1C, 0x9029317C,
0xFDF8E802, 0x04272F70, 0x80BB155C, 0x05282CE3,
0x95C11548, 0xE4C66D22, 0x48C1133F, 0xC70F86DC,
0x07F9C9EE, 0x41041F0F, 0x404779A4, 0x5D886E17,
0x325F51EB, 0xD59BC0D1, 0xF2BCC18F, 0x41113564,
0x257B7834, 0x602A9C60, 0xDFF8E8A3, 0x1F636C1B,
0x0E12B4C2, 0x02E1329E, 0xAF664FD1, 0xCAD18115,
0x6B2395E0, 0x333E92E1, 0x3B240B62, 0xEEBEB922,
0x85B2A20E, 0xE6BA0D99, 0xDE720C8C, 0x2DA2F728,
0xD0127845, 0x95B794FD, 0x647D0862, 0xE7CCF5F0,
0x5449A36F, 0x877D48FA, 0xC39DFD27, 0xF33E8D1E,
0x0A476341, 0x992EFF74, 0x3A6F6EAB, 0xF4F8FD37,
0xA812DC60, 0xA1EBDDF8, 0x991BE14C, 0xDB6E6B0D,
0xC67B5510, 0x6D672C37, 0x2765D43B, 0xDCD0E804,
0xF1290DC7, 0xCC00FFA3, 0xB5390F92, 0x690FED0B,
0x667B9FFB, 0xCEDB7D9C, 0xA091CF0B, 0xD9155EA3,
0xBB132F88, 0x515BAD24, 0x7B9479BF, 0x763BD6EB,
0x37392EB3, 0xCC115979, 0x8026E297, 0xF42E312D,
0x6842ADA7, 0xC66A2B3B, 0x12754CCC, 0x782EF11C,
0x6A124237, 0xB79251E7, 0x06A1BBE6, 0x4BFB6350,
0x1A6B1018, 0x11CAEDFA, 0x3D25BDD8, 0xE2E1C3C9,
0x44421659, 0x0A121386, 0xD90CEC6E, 0xD5ABEA2A,
0x64AF674E, 0xDA86A85F, 0xBEBFE988, 0x64E4C3FE,
0x9DBC8057, 0xF0F7C086, 0x60787BF8, 0x6003604D,
0xD1FD8346, 0xF6381FB0, 0x7745AE04, 0xD736FCCC,
0x83426B33, 0xF01EAB71, 0xB0804187, 0x3C005E5F,
0x77A057BE, 0xBDE8AE24, 0x55464299, 0xBF582E61,
0x4E58F48F, 0xF2DDFDA2, 0xF474EF38, 0x8789BDC2,
0x5366F9C3, 0xC8B38E74, 0xB475F255, 0x46FCD9B9,
0x7AEB2661, 0x8B1DDF84, 0x846A0E79, 0x915F95E2,
0x466E598E, 0x20B45770, 0x8CD55591, 0xC902DE4C,
0xB90BACE1, 0xBB8205D0, 0x11A86248, 0x7574A99E,
0xB77F19B6, 0xE0A9DC09, 0x662D09A1, 0xC4324633,
0xE85A1F02, 0x09F0BE8C, 0x4A99A025, 0x1D6EFE10,
0x1AB93D1D, 0x0BA5A4DF, 0xA186F20F, 0x2868F169,
0xDCB7DA83, 0x573906FE, 0xA1E2CE9B, 0x4FCD7F52,
0x50115E01, 0xA70683FA, 0xA002B5C4, 0x0DE6D027,
0x9AF88C27, 0x773F8641, 0xC3604C06, 0x61A806B5,
0xF0177A28, 0xC0F586E0, 0x006058AA, 0x30DC7D62,
0x11E69ED7, 0x2338EA63, 0x53C2DD94, 0xC2C21634,
0xBBCBEE56, 0x90BCB6DE, 0xEBFC7DA1, 0xCE591D76,
0x6F05E409, 0x4B7C0188, 0x39720A3D, 0x7C927C24,
0x86E3725F, 0x724D9DB9, 0x1AC15BB4, 0xD39EB8FC,
0xED545578, 0x08FCA5B5, 0xD83D7CD3, 0x4DAD0FC4,
0x1E50EF5E, 0xB161E6F8, 0xA28514D9, 0x6C51133C,
0x6FD5C7E7, 0x56E14EC4, 0x362ABFCE, 0xDDC6C837,
0xD79A3234, 0x92638212, 0x670EFA8E, 0x406000E0
),
array(
0x3A39CE37, 0xD3FAF5CF, 0xABC27737, 0x5AC52D1B,
0x5CB0679E, 0x4FA33742, 0xD3822740, 0x99BC9BBE,
0xD5118E9D, 0xBF0F7315, 0xD62D1C7E, 0xC700C47B,
0xB78C1B6B, 0x21A19045, 0xB26EB1BE, 0x6A366EB4,
0x5748AB2F, 0xBC946E79, 0xC6A376D2, 0x6549C2C8,
0x530FF8EE, 0x468DDE7D, 0xD5730A1D, 0x4CD04DC6,
0x2939BBDB, 0xA9BA4650, 0xAC9526E8, 0xBE5EE304,
0xA1FAD5F0, 0x6A2D519A, 0x63EF8CE2, 0x9A86EE22,
0xC089C2B8, 0x43242EF6, 0xA51E03AA, 0x9CF2D0A4,
0x83C061BA, 0x9BE96A4D, 0x8FE51550, 0xBA645BD6,
0x2826A2F9, 0xA73A3AE1, 0x4BA99586, 0xEF5562E9,
0xC72FEFD3, 0xF752F7DA, 0x3F046F69, 0x77FA0A59,
0x80E4A915, 0x87B08601, 0x9B09E6AD, 0x3B3EE593,
0xE990FD5A, 0x9E34D797, 0x2CF0B7D9, 0x022B8B51,
0x96D5AC3A, 0x017DA67D, 0xD1CF3ED6, 0x7C7D2D28,
0x1F9F25CF, 0xADF2B89B, 0x5AD6B472, 0x5A88F54C,
0xE029AC71, 0xE019A5E6, 0x47B0ACFD, 0xED93FA9B,
0xE8D3C48D, 0x283B57CC, 0xF8D56629, 0x79132E28,
0x785F0191, 0xED756055, 0xF7960E44, 0xE3D35E8C,
0x15056DD4, 0x88F46DBA, 0x03A16125, 0x0564F0BD,
0xC3EB9E15, 0x3C9057A2, 0x97271AEC, 0xA93A072A,
0x1B3F6D9B, 0x1E6321F5, 0xF59C66FB, 0x26DCF319,
0x7533D928, 0xB155FDF5, 0x03563482, 0x8ABA3CBB,
0x28517711, 0xC20AD9F8, 0xABCC5167, 0xCCAD925F,
0x4DE81751, 0x3830DC8E, 0x379D5862, 0x9320F991,
0xEA7A90C2, 0xFB3E7BCE, 0x5121CE64, 0x774FBE32,
0xA8B6E37E, 0xC3293D46, 0x48DE5369, 0x6413E680,
0xA2AE0810, 0xDD6DB224, 0x69852DFD, 0x09072166,
0xB39A460A, 0x6445C0DD, 0x586CDECF, 0x1C20C8AE,
0x5BBEF7DD, 0x1B588D40, 0xCCD2017F, 0x6BB4E3BB,
0xDDA26A7E, 0x3A59FF45, 0x3E350A44, 0xBCB4CDD5,
0x72EACEA8, 0xFA6484BB, 0x8D6612AE, 0xBF3C6F47,
0xD29BE463, 0x542F5D9E, 0xAEC2771B, 0xF64E6370,
0x740E0D8D, 0xE75B1357, 0xF8721671, 0xAF537D5D,
0x4040CB08, 0x4EB4E2CC, 0x34D2466A, 0x0115AF84,
0xE1B00428, 0x95983A1D, 0x06B89FB4, 0xCE6EA048,
0x6F3F3B82, 0x3520AB82, 0x011A1D4B, 0x277227F8,
0x611560B1, 0xE7933FDC, 0xBB3A792B, 0x344525BD,
0xA08839E1, 0x51CE794B, 0x2F32C9B7, 0xA01FBAC9,
0xE01CC87E, 0xBCC7D1F6, 0xCF0111C3, 0xA1E8AAC7,
0x1A908749, 0xD44FBD9A, 0xD0DADECB, 0xD50ADA38,
0x0339C32A, 0xC6913667, 0x8DF9317C, 0xE0B12B4F,
0xF79E59B7, 0x43F5BB3A, 0xF2D519FF, 0x27D9459C,
0xBF97222C, 0x15E6FC2A, 0x0F91FC71, 0x9B941525,
0xFAE59361, 0xCEB69CEB, 0xC2A86459, 0x12BAA8D1,
0xB6C1075E, 0xE3056A0C, 0x10D25065, 0xCB03A442,
0xE0EC6E0E, 0x1698DB3B, 0x4C98A0BE, 0x3278E964,
0x9F1F9532, 0xE0D392DF, 0xD3A0342B, 0x8971F21E,
0x1B0A7441, 0x4BA3348C, 0xC5BE7120, 0xC37632D8,
0xDF359F8D, 0x9B992F2E, 0xE60B6F47, 0x0FE3F11D,
0xE54CDA54, 0x1EDAD891, 0xCE6279CF, 0xCD3E7E6F,
0x1618B166, 0xFD2C1D05, 0x848FD2C5, 0xF6FB2299,
0xF523F357, 0xA6327623, 0x93A83531, 0x56CCCD02,
0xACF08162, 0x5A75EBB5, 0x6E163697, 0x88D273CC,
0xDE966292, 0x81B949D0, 0x4C50901B, 0x71C65614,
0xE6C6C7BD, 0x327A140A, 0x45E1D006, 0xC3F27B9A,
0xC9AA53FD, 0x62A80F00, 0xBB25BFE2, 0x35BDD2F6,
0x71126905, 0xB2040222, 0xB6CBCF7C, 0xCD769C2B,
0x53113EC0, 0x1640E3D3, 0x38ABBD60, 0x2547ADF0,
0xBA38209C, 0xF746CE76, 0x77AFA1C5, 0x20756060,
0x85CBFE4E, 0x8AE88DD8, 0x7AAAF9B0, 0x4CF9AA7E,
0x1948C25C, 0x02FB8A8C, 0x01C36AE4, 0xD6EBE1F9,
0x90D4F869, 0xA65CDEA0, 0x3F09252D, 0xC208E69F,
0xB74E6132, 0xCE77E25B, 0x578FDFE3, 0x3AC372E6
)
);
}
}
<?php
/**
* @file
* TeamSpeak 3 PHP Framework
*
* $Id: Exception.php 06/06/2016 22:27:13 scp@Svens-iMac $
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @package TeamSpeak3
* @version 1.1.24
* @author Sven 'ScP' Paulsen
* @copyright Copyright (c) 2010 by Planet TeamSpeak. All rights reserved.
*/
/**
* @class TeamSpeak3_Helper_Exception
* @brief Enhanced exception class for TeamSpeak3_Helper_* objects.
*/
class TeamSpeak3_Helper_Exception extends TeamSpeak3_Exception {}
<?php
/**
* @file
* TeamSpeak 3 PHP Framework
*
* $Id: Profiler.php 06/06/2016 22:27:13 scp@Svens-iMac $
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @package TeamSpeak3
* @version 1.1.24
* @author Sven 'ScP' Paulsen
* @copyright Copyright (c) 2010 by Planet TeamSpeak. All rights reserved.
*/
/**
* @class TeamSpeak3_Helper_Profiler
* @brief Helper class for profiler handling.
*/
class TeamSpeak3_Helper_Profiler
{
/**
* Stores various timers for code profiling.
*
* @var array
*/
protected static $timers = array();
/**
* Inits a timer.
*
* @param string $name
* @return void
*/
public static function init($name = "default")
{
self::$timers[$name] = new TeamSpeak3_Helper_Profiler_Timer($name);
}
/**
* Starts a timer.
*
* @param string $name
* @return void
*/
public static function start($name = "default")
{
if(array_key_exists($name, self::$timers))
{
self::$timers[$name]->start();
}
else
{
self::$timers[$name] = new TeamSpeak3_Helper_Profiler_Timer($name);
}
}
/**
* Stops a timer.
*
* @param string $name
* @return void
*/
public static function stop($name = "default")
{
if(!array_key_exists($name, self::$timers))
{
self::init($name);
}
self::$timers[$name]->stop();
}
/**
* Returns a timer.
*
* @param string $name
* @return TeamSpeak3_Helper_Profiler_Timer
*/
public static function get($name = "default")
{
if(!array_key_exists($name, self::$timers))
{
self::init($name);
}
return self::$timers[$name];
}
}
<?php
/**
* @file
* TeamSpeak 3 PHP Framework
*
* $Id: Exception.php 06/06/2016 22:27:13 scp@Svens-iMac $
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @package TeamSpeak3
* @version 1.1.24
* @author Sven 'ScP' Paulsen
* @copyright Copyright (c) 2010 by Planet TeamSpeak. All rights reserved.
*/
/**
* @class TeamSpeak3_Helper_Profiler_Exception
* @brief Enhanced exception class for TeamSpeak3_Helper_Profiler objects.
*/
class TeamSpeak3_Helper_Profiler_Exception extends TeamSpeak3_Helper_Exception {}
<?php
/**
* @file
* TeamSpeak 3 PHP Framework
*
* $Id: Timer.php 06/06/2016 22:27:13 scp@Svens-iMac $
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @package TeamSpeak3
* @version 1.1.24
* @author Sven 'ScP' Paulsen
* @copyright Copyright (c) 2010 by Planet TeamSpeak. All rights reserved.
*/
/**
* @class TeamSpeak3_Helper_Profiler_Timer
* @brief Helper class providing profiler timers.
*/
class TeamSpeak3_Helper_Profiler_Timer
{
/**
* Indicates wether the timer is running or not.
*
* @var boolean
*/
protected $running = FALSE;
/**
* Stores the timestamp when the timer was last started.
*
* @var integer
*/
protected $started = 0;
/**
* Stores the timer name.
*
* @var string
*/
protected $name = null;
/**
* Stores various information about the server environment.
*
* @var array
*/
protected $data = array();
/**
* The TeamSpeak3_Helper_Profiler_Timer constructor.
*
* @param string $name
* @return TeamSpeak3_Helper_Profiler_Timer
*/
public function __construct($name)
{
$this->name = (string) $name;
$this->data["runtime"] = 0;
$this->data["realmem"] = 0;
$this->data["emalloc"] = 0;
$this->start();
}
/**
* Starts the timer.
*
* @return void
*/
public function start()
{
if($this->isRunning()) return;
$this->data["realmem_start"] = memory_get_usage(TRUE);
$this->data["emalloc_start"] = memory_get_usage();
$this->started = microtime(TRUE);
$this->running = TRUE;
}
/**
* Stops the timer.
*
* @return void
*/
public function stop()
{
if(!$this->isRunning()) return;
$this->data["runtime"] += microtime(TRUE) - $this->started;
$this->data["realmem"] += memory_get_usage(TRUE) - $this->data["realmem_start"];
$this->data["emalloc"] += memory_get_usage() - $this->data["emalloc_start"];
$this->started = 0;
$this->running = FALSE;
}
/**
* Return the timer runtime.
*
* @return mixed
*/
public function getRuntime()
{
if($this->isRunning())
{
$this->stop();
$this->start();
}
return $this->data["runtime"];
}
/**
* Returns the amount of memory allocated to PHP in bytes.
*
* @param boolean $realmem
* @return integer
*/
public function getMemUsage($realmem = FALSE)
{
if($this->isRunning())
{
$this->stop();
$this->start();
}
return ($realmem !== FALSE) ? $this->data["realmem"] : $this->data["emalloc"];
}
/**
* Returns TRUE if the timer is running.
*
* @return boolean
*/
public function isRunning()
{
return $this->running;
}
}
<?php
/**
* @file
* TeamSpeak 3 PHP Framework
*
* $Id: Signal.php 06/06/2016 22:27:13 scp@Svens-iMac $
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @package TeamSpeak3
* @version 1.1.24
* @author Sven 'ScP' Paulsen
* @copyright Copyright (c) 2010 by Planet TeamSpeak. All rights reserved.
*/
/**
* @class TeamSpeak3_Helper_Signal
* @brief Helper class for signal slots.
*/
class TeamSpeak3_Helper_Signal
{
/**
* Stores the TeamSpeak3_Helper_Signal object.
*
* @var TeamSpeak3_Helper_Signal
*/
protected static $instance = null;
/**
* Stores subscribed signals and their slots.
*
* @var array
*/
protected $sigslots = array();
/**
* Emits a signal with a given set of parameters.
*
* @param string $signal
* @param mixed $params
* @return mixed
*/
public function emit($signal, $params = null)
{
if(!$this->hasHandlers($signal))
{
return;
}
if(!is_array($params))
{
$params = func_get_args();
$params = array_slice($params, 1);
}
foreach($this->sigslots[$signal] as $slot)
{
$return = $slot->call($params);
}
return $return;
}
/**
* Generates a MD5 hash based on a given callback.
*
* @param mixed $callback
* @param string
* @return void
*/
public function getCallbackHash($callback)
{
if(!is_callable($callback, TRUE, $callable_name))
{
throw new TeamSpeak3_Helper_Signal_Exception("invalid callback specified");
}
return md5($callable_name);
}
/**
* Subscribes to a signal and returns the signal handler.
*
* @param string $signal
* @param mixed $callback
* @return TeamSpeak3_Helper_Signal_Handler
*/
public function subscribe($signal, $callback)
{
if(empty($this->sigslots[$signal]))
{
$this->sigslots[$signal] = array();
}
$index = $this->getCallbackHash($callback);
if(!array_key_exists($index, $this->sigslots[$signal]))
{
$this->sigslots[$signal][$index] = new TeamSpeak3_Helper_Signal_Handler($signal, $callback);
}
return $this->sigslots[$signal][$index];
}
/**
* Unsubscribes from a signal.
*
* @param string $signal
* @param mixed $callback
* @return void
*/
public function unsubscribe($signal, $callback = null)
{
if(!$this->hasHandlers($signal))
{
return;
}
if($callback !== null)
{
$index = $this->getCallbackHash($callback);
if(!array_key_exists($index, $this->sigslots[$signal]))
{
return;
}
unset($this->sigslots[$signal][$index]);
}
else
{
unset($this->sigslots[$signal]);
}
}
/**
* Returns all registered signals.
*
* @return array
*/
public function getSignals()
{
return array_keys($this->sigslots);
}
/**
* Returns TRUE there are slots subscribed for a specified signal.
*
* @param string $signal
* @return boolean
*/
public function hasHandlers($signal)
{
return empty($this->sigslots[$signal]) ? FALSE : TRUE;
}
/**
* Returns all slots for a specified signal.
*
* @param string $signal
* @return array
*/
public function getHandlers($signal)
{
if(!$this->hasHandlers($signal))
{
return $this->sigslots[$signal];
}
return array();
}
/**
* Clears all slots for a specified signal.
*
* @param string $signal
* @return void
*/
public function clearHandlers($signal)
{
if(!$this->hasHandlers($signal))
{
unset($this->sigslots[$signal]);
}
}
/**
* Returns a singleton instance of TeamSpeak3_Helper_Signal.
*
* @return TeamSpeak3_Helper_Signal
*/
public static function getInstance()
{
if(self::$instance === null)
{
self::$instance = new self();
}
return self::$instance;
}
}
<?php
/**
* @file
* TeamSpeak 3 PHP Framework
*
* $Id: Exception.php 06/06/2016 22:27:13 scp@Svens-iMac $
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @package TeamSpeak3
* @version 1.1.24
* @author Sven 'ScP' Paulsen
* @copyright Copyright (c) 2010 by Planet TeamSpeak. All rights reserved.
*/
/**
* @class TeamSpeak3_Helper_Signal_Exception
* @brief Enhanced exception class for TeamSpeak3_Helper_Signal objects.
*/
class TeamSpeak3_Helper_Signal_Exception extends TeamSpeak3_Helper_Exception {}
<?php
/**
* @file
* TeamSpeak 3 PHP Framework
*
* $Id: Handler.php 06/06/2016 22:27:13 scp@Svens-iMac $
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @package TeamSpeak3
* @version 1.1.24
* @author Sven 'ScP' Paulsen
* @copyright Copyright (c) 2010 by Planet TeamSpeak. All rights reserved.
*/
/**
* @class TeamSpeak3_Helper_Signal_Handler
* @brief Helper class providing handler functions for signals.
*/
class TeamSpeak3_Helper_Signal_Handler
{
/**
* Stores the name of the subscribed signal.
*
* @var string
*/
protected $signal = null;
/**
* Stores the callback function for the subscribed signal.
*
* @var mixed
*/
protected $callback = null;
/**
* The TeamSpeak3_Helper_Signal_Handler constructor.
*
* @param string $signal
* @param mixed $callback
* @throws TeamSpeak3_Helper_Signal_Exception
* @return TeamSpeak3_Helper_Signal_Handler
*/
public function __construct($signal, $callback)
{
$this->signal = (string) $signal;
if(!is_callable($callback))
{
throw new TeamSpeak3_Helper_Signal_Exception("invalid callback specified for signal '" . $signal . "'");
}
$this->callback = $callback;
}
/**
* Invoke the signal handler.
*
* @param array $args
* @return mixed
*/
public function call(array $args = array())
{
return call_user_func_array($this->callback, $args);
}
}
<?php
/**
* @file
* TeamSpeak 3 PHP Framework
*
* $Id: Interface.php 06/06/2016 22:27:13 scp@Svens-iMac $
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @package TeamSpeak3
* @version 1.1.24
* @author Sven 'ScP' Paulsen
* @copyright Copyright (c) 2010 by Planet TeamSpeak. All rights reserved.
*/
/**
* @class TeamSpeak3_Helper_Signal_Interface
* @brief Interface class describing the layout for TeamSpeak3_Helper_Signal callbacks.
*/
interface TeamSpeak3_Helper_Signal_Interface
{
/**
* Possible callback for '<adapter>Connected' signals.
*
* === Examples ===
* - TeamSpeak3_Helper_Signal::getInstance()->subscribe("serverqueryConnected", array($object, "onConnect"));
* - TeamSpeak3_Helper_Signal::getInstance()->subscribe("filetransferConnected", array($object, "onConnect"));
* - TeamSpeak3_Helper_Signal::getInstance()->subscribe("blacklistConnected", array($object, "onConnect"));
* - TeamSpeak3_Helper_Signal::getInstance()->subscribe("updateConnected", array($object, "onConnect"));
*
* @param TeamSpeak3_Adapter_Abstract $adapter
* @return void
*/
public function onConnect(TeamSpeak3_Adapter_Abstract $adapter);
/**
* Possible callback for '<adapter>Disconnected' signals.
*
* === Examples ===
* - TeamSpeak3_Helper_Signal::getInstance()->subscribe("serverqueryDisconnected", array($object, "onDisconnect"));
* - TeamSpeak3_Helper_Signal::getInstance()->subscribe("filetransferDisconnected", array($object, "onDisconnect"));
* - TeamSpeak3_Helper_Signal::getInstance()->subscribe("blacklistDisconnected", array($object, "onDisconnect"));
* - TeamSpeak3_Helper_Signal::getInstance()->subscribe("updateDisconnected", array($object, "onDisconnect"));
*
* @return void
*/
public function onDisconnect();
/**
* Possible callback for 'serverqueryCommandStarted' signals.
*
* === Examples ===
* - TeamSpeak3_Helper_Signal::getInstance()->subscribe("serverqueryCommandStarted", array($object, "onCommandStarted"));
*
* @param string $cmd
* @return void
*/
public function onCommandStarted($cmd);
/**
* Possible callback for 'serverqueryCommandFinished' signals.
*
* === Examples ===
* - TeamSpeak3_Helper_Signal::getInstance()->subscribe("serverqueryCommandFinished", array($object, "onCommandFinished"));
*
* @param string $cmd
* @param TeamSpeak3_Adapter_ServerQuery_Reply $reply
* @return void
*/
public function onCommandFinished($cmd, TeamSpeak3_Adapter_ServerQuery_Reply $reply);
/**
* Possible callback for 'notifyEvent' signals.
*
* === Examples ===
* - TeamSpeak3_Helper_Signal::getInstance()->subscribe("notifyEvent", array($object, "onEvent"));
*
* @param TeamSpeak3_Adapter_ServerQuery_Event $event
* @param TeamSpeak3_Node_Host $host
* @return void
*/
public function onEvent(TeamSpeak3_Adapter_ServerQuery_Event $event, TeamSpeak3_Node_Host $host);
/**
* Possible callback for 'notifyError' signals.
*
* === Examples ===
* - TeamSpeak3_Helper_Signal::getInstance()->subscribe("notifyError", array($object, "onError"));
*
* @param TeamSpeak3_Adapter_ServerQuery_Reply $reply
* @return void
*/
public function onError(TeamSpeak3_Adapter_ServerQuery_Reply $reply);
/**
* Possible callback for 'notifyServerselected' signals.
*
* === Examples ===
* - TeamSpeak3_Helper_Signal::getInstance()->subscribe("notifyServerselected", array($object, "onServerselected"));
*
* @param TeamSpeak3_Node_Host $host
* @return void
*/
public function onServerselected(TeamSpeak3_Node_Host $host);
/**
* Possible callback for 'notifyServercreated' signals.
*
* === Examples ===
* - TeamSpeak3_Helper_Signal::getInstance()->subscribe("notifyServercreated", array($object, "onServercreated"));
*
* @param TeamSpeak3_Node_Host $host
* @param integer $sid
* @return void
*/
public function onServercreated(TeamSpeak3_Node_Host $host, $sid);
/**
* Possible callback for 'notifyServerdeleted' signals.
*
* === Examples ===
* - TeamSpeak3_Helper_Signal::getInstance()->subscribe("notifyServerdeleted", array($object, "onServerdeleted"));
*
* @param TeamSpeak3_Node_Host $host
* @param integer $sid
* @return void
*/
public function onServerdeleted(TeamSpeak3_Node_Host $host, $sid);
/**
* Possible callback for 'notifyServerstarted' signals.
*
* === Examples ===
* - TeamSpeak3_Helper_Signal::getInstance()->subscribe("notifyServerstarted", array($object, "onServerstarted"));
*
* @param TeamSpeak3_Node_Host $host
* @param integer $sid
* @return void
*/
public function onServerstarted(TeamSpeak3_Node_Host $host, $sid);
/**
* Possible callback for 'notifyServerstopped' signals.
*
* === Examples ===
* - TeamSpeak3_Helper_Signal::getInstance()->subscribe("notifyServerstopped", array($object, "onServerstopped"));
*
* @param TeamSpeak3_Node_Host $host
* @param integer $sid
* @return void
*/
public function onServerstopped(TeamSpeak3_Node_Host $host, $sid);
/**
* Possible callback for 'notifyServershutdown' signals.
*
* === Examples ===
* - TeamSpeak3_Helper_Signal::getInstance()->subscribe("notifyServershutdown", array($object, "onServershutdown"));
*
* @param TeamSpeak3_Node_Host $host
* @return void
*/
public function onServershutdown(TeamSpeak3_Node_Host $host);
/**
* Possible callback for 'notifyLogin' signals.
*
* === Examples ===
* - TeamSpeak3_Helper_Signal::getInstance()->subscribe("notifyLogin", array($object, "onLogin"));
*
* @param TeamSpeak3_Node_Host $host
* @return void
*/
public function onLogin(TeamSpeak3_Node_Host $host);
/**
* Possible callback for 'notifyLogout' signals.
*
* === Examples ===
* - TeamSpeak3_Helper_Signal::getInstance()->subscribe("notifyLogout", array($object, "onLogout"));
*
* @param TeamSpeak3_Node_Host $host
* @return void
*/
public function onLogout(TeamSpeak3_Node_Host $host);
/**
* Possible callback for 'notifyTokencreated' signals.
*
* === Examples ===
* - TeamSpeak3_Helper_Signal::getInstance()->subscribe("notifyTokencreated", array($object, "onTokencreated"));
*
* @param TeamSpeak3_Node_Server $server
* @param string $token
* @return void
*/
public function onTokencreated(TeamSpeak3_Node_Server $server, $token);
/**
* Possible callback for 'filetransferHandshake' signals.
*
* === Examples ===
* - TeamSpeak3_Helper_Signal::getInstance()->subscribe("filetransferHandshake", array($object, "onFtHandshake"));
*
* @param TeamSpeak3_Adapter_FileTransfer $adapter
* @return void
*/
public function onFtHandshake(TeamSpeak3_Adapter_FileTransfer $adapter);
/**
* Possible callback for 'filetransferUploadStarted' signals.
*
* === Examples ===
* - TeamSpeak3_Helper_Signal::getInstance()->subscribe("filetransferUploadStarted", array($object, "onFtUploadStarted"));
*
* @param string $ftkey
* @param integer $seek
* @param integer $size
* @return void
*/
public function onFtUploadStarted($ftkey, $seek, $size);
/**
* Possible callback for 'filetransferUploadProgress' signals.
*
* === Examples ===
* - TeamSpeak3_Helper_Signal::getInstance()->subscribe("filetransferUploadProgress", array($object, "onFtUploadProgress"));
*
* @param string $ftkey
* @param integer $seek
* @param integer $size
* @return void
*/
public function onFtUploadProgress($ftkey, $seek, $size);
/**
* Possible callback for 'filetransferUploadFinished' signals.
*
* === Examples ===
* - TeamSpeak3_Helper_Signal::getInstance()->subscribe("filetransferUploadFinished", array($object, "onFtUploadFinished"));
*
* @param string $ftkey
* @param integer $seek
* @param integer $size
* @return void
*/
public function onFtUploadFinished($ftkey, $seek, $size);
/**
* Possible callback for 'filetransferDownloadStarted' signals.
*
* === Examples ===
* - TeamSpeak3_Helper_Signal::getInstance()->subscribe("filetransferDownloadStarted", array($object, "onFtDownloadStarted"));
*
* @param string $ftkey
* @param integer $buff
* @param integer $size
* @return void
*/
public function onFtDownloadStarted($ftkey, $buff, $size);
/**
* Possible callback for 'filetransferDownloadProgress' signals.
*
* === Examples ===
* - TeamSpeak3_Helper_Signal::getInstance()->subscribe("filetransferDownloadProgress", array($object, "onFtDownloadProgress"));
*
* @param string $ftkey
* @param integer $buff
* @param integer $size
* @return void
*/
public function onFtDownloadProgress($ftkey, $buff, $size);
/**
* Possible callback for 'filetransferDownloadFinished' signals.
*
* === Examples ===
* - TeamSpeak3_Helper_Signal::getInstance()->subscribe("filetransferDownloadFinished", array($object, "onFtDownloadFinished"));
*
* @param string $ftkey
* @param integer $buff
* @param integer $size
* @return void
*/
public function onFtDownloadFinished($ftkey, $buff, $size);
/**
* Possible callback for '<adapter>DataRead' signals.
*
* === Examples ===
* - TeamSpeak3_Helper_Signal::getInstance()->subscribe("serverqueryDataRead", array($object, "onDebugDataRead"));
* - TeamSpeak3_Helper_Signal::getInstance()->subscribe("filetransferDataRead", array($object, "onDebugDataRead"));
* - TeamSpeak3_Helper_Signal::getInstance()->subscribe("blacklistDataRead", array($object, "onDebugDataRead"));
* - TeamSpeak3_Helper_Signal::getInstance()->subscribe("updateDataRead", array($object, "onDebugDataRead"));
*
* @param string $data
* @return void
*/
public function onDebugDataRead($data);
/**
* Possible callback for '<adapter>DataSend' signals.
*
* === Examples ===
* - TeamSpeak3_Helper_Signal::getInstance()->subscribe("serverqueryDataSend", array($object, "onDebugDataSend"));
* - TeamSpeak3_Helper_Signal::getInstance()->subscribe("filetransferDataSend", array($object, "onDebugDataSend"));
* - TeamSpeak3_Helper_Signal::getInstance()->subscribe("blacklistDataSend", array($object, "onDebugDataSend"));
* - TeamSpeak3_Helper_Signal::getInstance()->subscribe("updateDataSend", array($object, "onDebugDataSend"));
*
* @param string $data
* @return void
*/
public function onDebugDataSend($data);
/**
* Possible callback for '<adapter>WaitTimeout' signals.
*
* === Examples ===
* - TeamSpeak3_Helper_Signal::getInstance()->subscribe("serverqueryWaitTimeout", array($object, "onWaitTimeout"));
* - TeamSpeak3_Helper_Signal::getInstance()->subscribe("filetransferWaitTimeout", array($object, "onWaitTimeout"));
* - TeamSpeak3_Helper_Signal::getInstance()->subscribe("blacklistWaitTimeout", array($object, "onWaitTimeout"));
* - TeamSpeak3_Helper_Signal::getInstance()->subscribe("updateWaitTimeout", array($object, "onWaitTimeout"));
*
* @param integer $time
* @param TeamSpeak3_Adapter_Abstract $adapter
* @return void
*/
public function onWaitTimeout($time, TeamSpeak3_Adapter_Abstract $adapter);
/**
* Possible callback for 'errorException' signals.
*
* === Examples ===
* - TeamSpeak3_Helper_Signal::getInstance()->subscribe("errorException", array($object, "onException"));
*
* @param TeamSpeak3_Exception $e
* @return void
*/
public function onException(TeamSpeak3_Exception $e);
}
<?php
/**
* @file
* TeamSpeak 3 PHP Framework
*
* $Id: String.php 06/06/2016 22:27:13 scp@Svens-iMac $
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @package TeamSpeak3
* @version 1.1.24
* @author Sven 'ScP' Paulsen
* @copyright Copyright (c) 2010 by Planet TeamSpeak. All rights reserved.
*/
/**
* @class TeamSpeak3_Helper_String
* @brief Helper class for string handling.
*/
class TeamSpeak3_Helper_String implements ArrayAccess, Iterator, Countable
{
/**
* Stores the original string.
*
* @var string
*/
protected $string;
/**
* @ignore
*/
protected $position = 0;
/**
* The TeamSpeak3_Helper_String constructor.
*
* @param string $string
* @return TeamSpeak3_Helper_String
*/
public function __construct($string)
{
$this->string = (string) $string;
}
/**
* Returns a TeamSpeak3_Helper_String object for thegiven string.
*
* @param string $string
* @return TeamSpeak3_Helper_String
*/
public static function factory($string)
{
return new self($string);
}
/**
* Replaces every occurrence of the string $search with the string $replace.
*
* @param string $search
* @param string $replace
* @param boolean $caseSensitivity
* @return TeamSpeak3_Helper_String
*/
public function replace($search, $replace, $caseSensitivity = TRUE)
{
if($caseSensitivity)
{
$this->string = str_replace($search, $replace, $this->string);
}
else
{
$this->string = str_ireplace($search, $replace, $this->string);
}
return $this;
}
/**
* This function replaces indexed or associative signs with given values.
*
* @param array $args
* @param string $char
* @return TeamSpeak3_Helper_String
*/
public function arg(array $args, $char = "%")
{
$args = array_reverse($args, TRUE);
foreach($args as $key => $val)
{
$args[$char . $key] = $val;
unset($args[$key]);
}
$this->string = strtr($this->string, $args);
return $this;
}
/**
* Returns true if the string starts with $pattern.
*
* @param string $pattern
* @return boolean
*/
public function startsWith($pattern)
{
return (substr($this->string, 0, strlen($pattern)) == $pattern) ? TRUE : FALSE;
}
/**
* Returns true if the string ends with $pattern.
*
* @param string $pattern
* @return boolean
*/
public function endsWith($pattern)
{
return (substr($this->string, strlen($pattern)*-1) == $pattern) ? TRUE : FALSE;
}
/**
* Returns the position of the first occurrence of a char in a string.
*
* @param string $needle
* @return integer
*/
public function findFirst($needle)
{
return strpos($this->string, $needle);
}
/**
* Returns the position of the last occurrence of a char in a string.
*
* @param string $needle
* @return integer
*/
public function findLast($needle)
{
return strrpos($this->string, $needle);
}
/**
* Returns the lowercased string.
*
* @return TeamSpeak3_Helper_String
*/
public function toLower()
{
return new self(strtolower($this->string));
}
/**
* Returns the uppercased string.
*
* @return TeamSpeak3_Helper_String
*/
public function toUpper()
{
return new self(strtoupper($this->string));
}
/**
* Returns true if the string contains $pattern.
*
* @param string $pattern
* @param boolean $regexp
* @return boolean
*/
public function contains($pattern, $regexp = FALSE)
{
if(empty($pattern))
{
return TRUE;
}
if($regexp)
{
return (preg_match("/" . $pattern . "/i", $this->string)) ? TRUE : FALSE;
}
else
{
return (stristr($this->string, $pattern) !== FALSE) ? TRUE : FALSE;
}
}
/**
* Returns part of a string.
*
* @param integer $start
* @param integer $length
* @return TeamSpeak3_Helper_String
*/
public function substr($start, $length = null)
{
$string = ($length !== null) ? substr($this->string, $start, $length) : substr($this->string, $start);
return new self($string);
}
/**
* Splits the string into substrings wherever $separator occurs.
*
* @param string $separator
* @param integer $limit
* @return array
*/
public function split($separator, $limit = 0)
{
$parts = explode($separator, $this->string, ($limit) ? intval($limit) : $this->count());
foreach($parts as $key => $val)
{
$parts[$key] = new self($val);
}
return $parts;
}
/**
* Appends $part to the string.
*
* @param string $part
* @return TeamSpeak3_Helper_String
*/
public function append($part)
{
$this->string = $this->string . strval($part);
return $this;
}
/**
* Prepends $part to the string.
*
* @param string $part
* @return TeamSpeak3_Helper_String
*/
public function prepend($part)
{
$this->string = strval($part) . $this->string;
return $this;
}
/**
* Returns a section of the string.
*
* @param string $separator
* @param integer $first
* @param integer $last
* @return TeamSpeak3_Helper_String
*/
public function section($separator, $first = 0, $last = 0)
{
$sections = explode($separator, $this->string);
$total = count($sections);
$first = intval($first);
$last = intval($last);
if($first > $total) return null;
if($first > $last) $last = $first;
for($i = 0; $i < $total; $i++)
{
if($i < $first || $i > $last)
{
unset($sections[$i]);
}
}
$string = implode($separator, $sections);
return new self($string);
}
/**
* Sets the size of the string to $size characters.
*
* @param integer $size
* @param string $char
* @return TeamSpeak3_Helper_String
*/
public function resize($size, $char = "\0")
{
$chars = ($size - $this->count());
if($chars < 0)
{
$this->string = substr($this->string, 0, $chars);
}
elseif($chars > 0)
{
$this->string = str_pad($this->string, $size, strval($char));
}
return $this;
}
/**
* Strips whitespaces (or other characters) from the beginning and end of the string.
*
* @return TeamSpeak3_Helper_String
*/
public function trim()
{
$this->string = trim($this->string);
return $this;
}
/**
* Escapes a string using the TeamSpeak 3 escape patterns.
*
* @return TeamSpeak3_Helper_String
*/
public function escape()
{
foreach(TeamSpeak3::getEscapePatterns() as $search => $replace)
{
$this->string = str_replace($search, $replace, $this->string);
}
return $this;
}
/**
* Unescapes a string using the TeamSpeak 3 escape patterns.
*
* @return TeamSpeak3_Helper_String
*/
public function unescape()
{
$this->string = strtr($this->string, array_flip(TeamSpeak3::getEscapePatterns()));
return $this;
}
/**
* Removes any non alphanumeric characters from the string.
*
* @return TeamSpeak3_Helper_String
*/
public function filterAlnum()
{
$this->string = preg_replace("/[^[:alnum:]]/", "", $this->string);
return $this;
}
/**
* Removes any non alphabetic characters from the string.
*
* @return TeamSpeak3_Helper_String
*/
public function filterAlpha()
{
$this->string = preg_replace("/[^[:alpha:]]/", "", $this->string);
return $this;
}
/**
* Removes any non numeric characters from the string.
*
* @return TeamSpeak3_Helper_String
*/
public function filterDigits()
{
$this->string = preg_replace("/[^[:digit:]]/", "", $this->string);
return $this;
}
/**
* Returns TRUE if the string is a numeric value.
*
* @return boolean
*/
public function isInt()
{
return (is_numeric($this->string) && !$this->contains(".") && !$this->contains("x")) ? TRUE : FALSE;
}
/**
* Returns the integer value of the string.
*
* @return float
* @return integer
*/
public function toInt()
{
if($this->string == pow(2, 63) || $this->string == pow(2, 64))
{
return -1;
}
return ($this->string > pow(2, 31)) ? floatval($this->string) : intval($this->string);
}
/**
* Calculates and returns the crc32 polynomial of the string.
*
* @return string
*/
public function toCrc32()
{
return crc32($this->string);
}
/**
* Calculates and returns the md5 checksum of the string.
*
* @return string
*/
public function toMd5()
{
return md5($this->string);
}
/**
* Calculates and returns the sha1 checksum of the string.
*
* @return string
*/
public function toSha1()
{
return sha1($this->string);
}
/**
* Returns TRUE if the string is UTF-8 encoded. This method searches for non-ascii multibyte
* sequences in the UTF-8 range.
*
* @return boolean
*/
public function isUtf8()
{
$pattern = array();
$pattern[] = "[\xC2-\xDF][\x80-\xBF]"; // non-overlong 2-byte
$pattern[] = "\xE0[\xA0-\xBF][\x80-\xBF]"; // excluding overlongs
$pattern[] = "[\xE1-\xEC\xEE\xEF][\x80-\xBF]{2}"; // straight 3-byte
$pattern[] = "\xED[\x80-\x9F][\x80-\xBF]"; // excluding surrogates
$pattern[] = "\xF0[\x90-\xBF][\x80-\xBF]{2}"; // planes 1-3
$pattern[] = "[\xF1-\xF3][\x80-\xBF]{3}"; // planes 4-15
$pattern[] = "\xF4[\x80-\x8F][\x80-\xBF]{2}"; // plane 16
return preg_match("%(?:" . implode("|", $pattern) . ")+%xs", $this->string);
}
/**
* Converts the string to UTF-8.
*
* @return TeamSpeak3_Helper_String
*/
public function toUtf8()
{
if(!$this->isUtf8())
{
$this->string = utf8_encode($this->string);
}
return $this;
}
/**
* Encodes the string with MIME base64 and returns the result.
*
* @return string
*/
public function toBase64()
{
return base64_encode($this->string);
}
/**
* Decodes the string with MIME base64 and returns the result as an TeamSpeak3_Helper_String
*
* @param string $base64
* @return TeamSpeak3_Helper_String
*/
public static function fromBase64($base64)
{
return new self(base64_decode($base64));
}
/**
* Returns the hexadecimal value of the string.
*
* @return string
*/
public function toHex()
{
$hex = "";
foreach($this as $char)
{
$hex .= $char->toHex();
}
return $hex;
}
/**
* Returns the TeamSpeak3_Helper_String based on a given hex value.
*
* @param string $hex
* @throws TeamSpeak3_Helper_Exception
* @return TeamSpeak3_Helper_String
*/
public static function fromHex($hex)
{
$string = "";
if(strlen($hex)%2 == 1)
{
throw new TeamSpeak3_Helper_Exception("given parameter '" . $hex . "' is not a valid hexadecimal number");
}
foreach(str_split($hex, 2) as $chunk)
{
$string .= chr(hexdec($chunk));
}
return new self($string);
}
/**
* Returns the string transliterated from UTF-8 to Latin.
*
* @return TeamSpeak3_Helper_String
*/
public function transliterate()
{
$utf8_accents = array(
"à" => "a",
"ô" => "o",
"ď" => "d",
"ḟ" => "f",
"ë" => "e",
"š" => "s",
"ơ" => "o",
"ß" => "ss",
"ă" => "a",
"ř" => "r",
"ț" => "t",
"ň" => "n",
"ā" => "a",
"ķ" => "k",
"ŝ" => "s",
"ỳ" => "y",
"ņ" => "n",
"ĺ" => "l",
"ħ" => "h",
"ṗ" => "p",
"ó" => "o",
"ú" => "u",
"ě" => "e",
"é" => "e",
"ç" => "c",
"ẁ" => "w",
"ċ" => "c",
"õ" => "o",
"ṡ" => "s",
"ø" => "o",
"ģ" => "g",
"ŧ" => "t",
"ș" => "s",
"ė" => "e",
"ĉ" => "c",
"ś" => "s",
"î" => "i",
"ű" => "u",
"ć" => "c",
"ę" => "e",
"ŵ" => "w",
"ṫ" => "t",
"ū" => "u",
"č" => "c",
"ö" => "oe",
"è" => "e",
"ŷ" => "y",
"ą" => "a",
"ł" => "l",
"ų" => "u",
"ů" => "u",
"ş" => "s",
"ğ" => "g",
"ļ" => "l",
"ƒ" => "f",
"ž" => "z",
"ẃ" => "w",
"ḃ" => "b",
"å" => "a",
"ì" => "i",
"ï" => "i",
"ḋ" => "d",
"ť" => "t",
"ŗ" => "r",
"ä" => "ae",
"í" => "i",
"ŕ" => "r",
"ê" => "e",
"ü" => "ue",
"ò" => "o",
"ē" => "e",
"ñ" => "n",
"ń" => "n",
"ĥ" => "h",
"ĝ" => "g",
"đ" => "d",
"ĵ" => "j",
"ÿ" => "y",
"ũ" => "u",
"ŭ" => "u",
"ư" => "u",
"ţ" => "t",
"ý" => "y",
"ő" => "o",
"â" => "a",
"ľ" => "l",
"ẅ" => "w",
"ż" => "z",
"ī" => "i",
"ã" => "a",
"ġ" => "g",
"ṁ" => "m",
"ō" => "o",
"ĩ" => "i",
"ù" => "u",
"į" => "i",
"ź" => "z",
"á" => "a",
"û" => "u",
"þ" => "th",
"ð" => "dh",
"æ" => "ae",
"µ" => "u",
"ĕ" => "e",
"œ" => "oe",
"À" => "A",
"Ô" => "O",
"Ď" => "D",
"Ḟ" => "F",
"Ë" => "E",
"Š" => "S",
"Ơ" => "O",
"Ă" => "A",
"Ř" => "R",
"Ț" => "T",
"Ň" => "N",
"Ā" => "A",
"Ķ" => "K",
"Ŝ" => "S",
"Ỳ" => "Y",
"Ņ" => "N",
"Ĺ" => "L",
"Ħ" => "H",
"Ṗ" => "P",
"Ó" => "O",
"Ú" => "U",
"Ě" => "E",
"É" => "E",
"Ç" => "C",
"Ẁ" => "W",
"Ċ" => "C",
"Õ" => "O",
"Ṡ" => "S",
"Ø" => "O",
"Ģ" => "G",
"Ŧ" => "T",
"Ș" => "S",
"Ė" => "E",
"Ĉ" => "C",
"Ś" => "S",
"Î" => "I",
"Ű" => "U",
"Ć" => "C",
"Ę" => "E",
"Ŵ" => "W",
"Ṫ" => "T",
"Ū" => "U",
"Č" => "C",
"Ö" => "Oe",
"È" => "E",
"Ŷ" => "Y",
"Ą" => "A",
"Ł" => "L",
"Ų" => "U",
"Ů" => "U",
"Ş" => "S",
"Ğ" => "G",
"Ļ" => "L",
"Ƒ" => "F",
"Ž" => "Z",
"Ẃ" => "W",
"Ḃ" => "B",
"Å" => "A",
"Ì" => "I",
"Ï" => "I",
"Ḋ" => "D",
"Ť" => "T",
"Ŗ" => "R",
"Ä" => "Ae",
"Í" => "I",
"Ŕ" => "R",
"Ê" => "E",
"Ü" => "Ue",
"Ò" => "O",
"Ē" => "E",
"Ñ" => "N",
"Ń" => "N",
"Ĥ" => "H",
"Ĝ" => "G",
"Đ" => "D",
"Ĵ" => "J",
"Ÿ" => "Y",
"Ũ" => "U",
"Ŭ" => "U",
"Ư" => "U",
"Ţ" => "T",
"Ý" => "Y",
"Ő" => "O",
"Â" => "A",
"Ľ" => "L",
"Ẅ" => "W",
"Ż" => "Z",
"Ī" => "I",
"Ã" => "A",
"Ġ" => "G",
"Ṁ" => "M",
"Ō" => "O",
"Ĩ" => "I",
"Ù" => "U",
"Į" => "I",
"Ź" => "Z",
"Á" => "A",
"Û" => "U",
"Þ" => "Th",
"Ð" => "Dh",
"Æ" => "Ae",
"Ĕ" => "E",
"Œ" => "Oe",
);
return new self($this->toUtf8()->replace(array_keys($utf8_accents), array_values($utf8_accents)));
}
/**
* Processes the string and replaces all accented UTF-8 characters by unaccented ASCII-7 "equivalents",
* whitespaces are replaced by a pre-defined spacer and the string is lowercase.
*
* @param string $spacer
* @return TeamSpeak3_Helper_String
*/
public function uriSafe($spacer = "-")
{
$this->string = str_replace($spacer, " ", $this->string);
$this->string = $this->transliterate();
$this->string = preg_replace("/(\s|[^A-Za-z0-9\-])+/", $spacer, trim(strtolower($this->string)));
$this->string = trim($this->string, $spacer);
return new self($this->string);
}
/**
* Replaces space characters with percent encoded strings.
*
* @return string
*/
public function spaceToPercent()
{
return str_replace(" ", "%20", $this->string);
}
/**
* Returns the string as a standard string
*
* @return string
*/
public function toString()
{
return $this->string;
}
/**
* Magical function that allows you to call PHP's built-in string functions on the TeamSpeak3_Helper_String object.
*
* @param string $function
* @param array $args
* @throws TeamSpeak3_Helper_Exception
* @return TeamSpeak3_Helper_String
*/
public function __call($function, $args)
{
if(!function_exists($function))
{
throw new TeamSpeak3_Helper_Exception("cannot call undefined function '" . $function . "' on this object");
}
if(count($args))
{
if(($key = array_search($this, $args, TRUE)) !== FALSE)
{
$args[$key] = $this->string;
}
else
{
throw new TeamSpeak3_Helper_Exception("cannot call undefined function '" . $function . "' without the " . __CLASS__ . " object parameter");
}
$return = call_user_func_array($function, $args);
}
else
{
$return = call_user_func($function, $this->string);
}
if(is_string($return))
{
$this->string = $return;
}
else
{
return $return;
}
return $this;
}
/**
* Returns the character as a standard string.
*
* @return string
*/
public function __toString()
{
return (string) $this->string;
}
/**
* @ignore
*/
public function count()
{
return strlen($this->string);
}
/**
* @ignore
*/
public function rewind()
{
$this->position = 0;
}
/**
* @ignore
*/
public function valid()
{
return $this->position < $this->count();
}
/**
* @ignore
*/
public function key()
{
return $this->position;
}
/**
* @ignore
*/
public function current()
{
return new TeamSpeak3_Helper_Char($this->string{$this->position});
}
/**
* @ignore
*/
public function next()
{
$this->position++;
}
/**
* @ignore
*/
public function offsetExists($offset)
{
return ($offset < strlen($this->string)) ? TRUE : FALSE;
}
/**
* @ignore
*/
public function offsetGet($offset)
{
return ($this->offsetExists($offset)) ? new TeamSpeak3_Helper_Char($this->string{$offset}) : null;
}
/**
* @ignore
*/
public function offsetSet($offset, $value)
{
if(!$this->offsetExists($offset)) return;
$this->string{$offset} = strval($value);
}
/**
* @ignore
*/
public function offsetUnset($offset)
{
if(!$this->offsetExists($offset)) return;
$this->string = substr_replace($this->string, "", $offset, 1);
}
}
<?php
/**
* @file
* TeamSpeak 3 PHP Framework
*
* $Id: Uri.php 06/06/2016 22:27:13 scp@Svens-iMac $
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @package TeamSpeak3
* @version 1.1.24
* @author Sven 'ScP' Paulsen
* @copyright Copyright (c) 2010 by Planet TeamSpeak. All rights reserved.
*/
/**
* @class TeamSpeak3_Helper_Uri
* @brief Helper class for URI handling.
*/
class TeamSpeak3_Helper_Uri
{
/**
* Stores the URI scheme.
*
* @var string
*/
protected $scheme = null;
/**
* Stores the URI username
*
* @var string
*/
protected $user = null;
/**
* Stores the URI password.
*
* @var string
*/
protected $pass = null;
/**
* Stores the URI host.
*
* @var string
*/
protected $host = null;
/**
* Stores the URI port.
*
* @var string
*/
protected $port = null;
/**
* Stores the URI path.
*
* @var string
*/
protected $path = null;
/**
* Stores the URI query string.
*
* @var string
*/
protected $query = null;
/**
* Stores the URI fragment string.
*
* @var string
*/
protected $fragment = null;
/**
* Stores grammar rules for validation via regex.
*
* @var array
*/
protected $regex = array();
/**
* The TeamSpeak3_Helper_Uri constructor.
*
* @param string $uri
* @throws TeamSpeak3_Helper_Exception
* @return TeamSpeak3_Helper_Uri
*/
public function __construct($uri)
{
$uri = explode(":", strval($uri), 2);
$this->scheme = strtolower($uri[0]);
$uriString = isset($uri[1]) ? $uri[1] : "";
if(!ctype_alnum($this->scheme))
{
throw new TeamSpeak3_Helper_Exception("invalid URI scheme '" . $this->scheme . "' supplied");
}
/* grammar rules for validation */
$this->regex["alphanum"] = "[^\W_]";
$this->regex["escaped"] = "(?:%[\da-fA-F]{2})";
$this->regex["mark"] = "[-_.!~*'()\[\]]";
$this->regex["reserved"] = "[;\/?:@&=+$,]";
$this->regex["unreserved"] = "(?:" . $this->regex["alphanum"] . "|" . $this->regex["mark"] . ")";
$this->regex["segment"] = "(?:(?:" . $this->regex["unreserved"] . "|" . $this->regex["escaped"] . "|[:@&=+$,;])*)";
$this->regex["path"] = "(?:\/" . $this->regex["segment"] . "?)+";
$this->regex["uric"] = "(?:" . $this->regex["reserved"] . "|" . $this->regex["unreserved"] . "|" . $this->regex["escaped"] . ")";
if(strlen($uriString) > 0)
{
$this->parseUri($uriString);
}
if(!$this->isValid())
{
throw new TeamSpeak3_Helper_Exception("invalid URI supplied");
}
}
/**
* Parses the scheme-specific portion of the URI and place its parts into instance variables.
*
* @throws TeamSpeak3_Helper_Exception
* @return void
*/
protected function parseUri($uriString = '')
{
$status = @preg_match("~^((//)([^/?#]*))([^?#]*)(\?([^#]*))?(#(.*))?$~", $uriString, $matches);
if($status === FALSE)
{
throw new TeamSpeak3_Helper_Exception("URI scheme-specific decomposition failed");
}
if(!$status) return;
$this->path = (isset($matches[4])) ? $matches[4] : '';
$this->query = (isset($matches[6])) ? $matches[6] : '';
$this->fragment = (isset($matches[8])) ? $matches[8] : '';
$status = @preg_match("~^(([^:@]*)(:([^@]*))?@)?((?(?=[[])[[][^]]+[]]|[^:]+))(:(.*))?$~", (isset($matches[3])) ? $matches[3] : "", $matches);
if($status === FALSE)
{
throw new TeamSpeak3_Helper_Exception("URI scheme-specific authority decomposition failed");
}
if(!$status) return;
$this->user = isset($matches[2]) ? $matches[2] : "";
$this->pass = isset($matches[4]) ? $matches[4] : "";
$this->host = isset($matches[5]) === TRUE ? preg_replace('~^\[([^]]+)\]$~', '\1', $matches[5]) : "";
$this->port = isset($matches[7]) ? $matches[7] : "";
}
/**
* Validate the current URI from the instance variables.
*
* @return boolean
*/
public function isValid()
{
return ($this->checkUser() && $this->checkPass() && $this->checkHost() && $this->checkPort() && $this->checkPath() && $this->checkQuery() && $this->checkFragment());
}
/**
* Returns TRUE if a given URI is valid.
*
* @param string $uri
* @return boolean
*/
public static function check($uri)
{
try
{
$uri = new self(strval($uri));
}
catch(Exception $e)
{
return FALSE;
}
return $uri->valid();
}
/**
* Returns TRUE if the URI has a scheme.
*
* @return boolean
*/
public function hasScheme()
{
return strlen($this->scheme) ? TRUE : FALSE;
}
/**
* Returns the scheme.
*
* @param mixed default
* @return TeamSpeak3_Helper_String
*/
public function getScheme($default = null)
{
return ($this->hasScheme()) ? new TeamSpeak3_Helper_String($this->scheme) : $default;
}
/**
* Returns TRUE if the username is valid.
*
* @param string $username
* @throws TeamSpeak3_Helper_Exception
* @return boolean
*/
public function checkUser($username = null)
{
if($username === null)
{
$username = $this->user;
}
if(strlen($username) == 0)
{
return TRUE;
}
$pattern = "/^(" . $this->regex["alphanum"] . "|" . $this->regex["mark"] . "|" . $this->regex["escaped"] . "|[;:&=+$,])+$/";
$status = @preg_match($pattern, $username);
if($status === FALSE)
{
throw new TeamSpeak3_Helper_Exception("URI username validation failed");
}
return ($status == 1);
}
/**
* Returns TRUE if the URI has a username.
*
* @return boolean
*/
public function hasUser()
{
return strlen($this->user) ? TRUE : FALSE;
}
/**
* Returns the username.
*
* @param mixed default
* @return TeamSpeak3_Helper_String
*/
public function getUser($default = null)
{
return ($this->hasUser()) ? new TeamSpeak3_Helper_String($this->user) : $default;
}
/**
* Returns TRUE if the password is valid.
*
* @param string $password
* @throws TeamSpeak3_Helper_Exception
* @return boolean
*/
public function checkPass($password = null)
{
if($password === null) {
$password = $this->pass;
}
if(strlen($password) == 0)
{
return TRUE;
}
$pattern = "/^(" . $this->regex["alphanum"] . "|" . $this->regex["mark"] . "|" . $this->regex["escaped"] . "|[;:&=+$,])+$/";
$status = @preg_match($pattern, $password);
if($status === FALSE)
{
throw new TeamSpeak3_Helper_Exception("URI password validation failed");
}
return ($status == 1);
}
/**
* Returns TRUE if the URI has a password.
*
* @return boolean
*/
public function hasPass()
{
return strlen($this->pass) ? TRUE : FALSE;
}
/**
* Returns the password.
*
* @param mixed default
* @return TeamSpeak3_Helper_String
*/
public function getPass($default = null)
{
return ($this->hasPass()) ? new TeamSpeak3_Helper_String($this->pass) : $default;
}
/**
* Returns TRUE if the host is valid.
*
* @param string $host
* @return boolean
*/
public function checkHost($host = null)
{
if($host === null)
{
$host = $this->host;
}
return TRUE;
}
/**
* Returns TRUE if the URI has a host.
*
* @return boolean
*/
public function hasHost()
{
return strlen($this->host) ? TRUE : FALSE;
}
/**
* Returns the host.
*
* @param mixed default
* @return TeamSpeak3_Helper_String
*/
public function getHost($default = null)
{
return ($this->hasHost()) ? new TeamSpeak3_Helper_String($this->host) : $default;
}
/**
* Returns TRUE if the port is valid.
*
* @param integer $port
* @return boolean
*/
public function checkPort($port = null)
{
if($port === null)
{
$port = $this->port;
}
return TRUE;
}
/**
* Returns TRUE if the URI has a port.
*
* @return boolean
*/
public function hasPort()
{
return strlen($this->port) ? TRUE : FALSE;
}
/**
* Returns the port.
*
* @param mixed default
* @return integer
*/
public function getPort($default = null)
{
return ($this->hasPort()) ? intval($this->port) : $default;
}
/**
* Returns TRUE if the path is valid.
*
* @param string $path
* @throws TeamSpeak3_Helper_Exception
* @return boolean
*/
public function checkPath($path = null)
{
if($path === null)
{
$path = $this->path;
}
if(strlen($path) == 0)
{
return TRUE;
}
$pattern = "/^" . $this->regex["path"] . "$/";
$status = @preg_match($pattern, $path);
if($status === FALSE)
{
throw new TeamSpeak3_Helper_Exception("URI path validation failed");
}
return ($status == 1);
}
/**
* Returns TRUE if the URI has a path.
*
* @return boolean
*/
public function hasPath()
{
return strlen($this->path) ? TRUE : FALSE;
}
/**
* Returns the path.
*
* @param mixed default
* @return TeamSpeak3_Helper_String
*/
public function getPath($default = null)
{
return ($this->hasPath()) ? new TeamSpeak3_Helper_String($this->path) : $default;
}
/**
* Returns TRUE if the query string is valid.
*
* @param string $query
* @throws TeamSpeak3_Helper_Exception
* @return boolean
*/
public function checkQuery($query = null)
{
if($query === null)
{
$query = $this->query;
}
if(strlen($query) == 0)
{
return TRUE;
}
$pattern = "/^" . $this->regex["uric"] . "*$/";
$status = @preg_match($pattern, $query);
if($status === FALSE)
{
throw new TeamSpeak3_Helper_Exception("URI query string validation failed");
}
return ($status == 1);
}
/**
* Returns TRUE if the URI has a query string.
*
* @return boolean
*/
public function hasQuery()
{
return strlen($this->query) ? TRUE : FALSE;
}
/**
* Returns an array containing the query string elements.
*
* @param mixed $default
* @return array
*/
public function getQuery($default = array())
{
if(!$this->hasQuery())
{
return $default;
}
parse_str($this->query, $queryArray);
return $queryArray;
}
/**
* Returns TRUE if the URI has a query variable.
*
* @return boolean
*/
public function hasQueryVar($key)
{
if(!$this->hasQuery()) return FALSE;
parse_str($this->query, $queryArray);
return array_key_exists($key, $queryArray) ? TRUE : FALSE;
}
/**
* Returns a single variable from the query string.
*
* @param string $key
* @param mixed $default
* @return mixed
*/
public function getQueryVar($key, $default = null)
{
if(!$this->hasQuery()) return $default;
parse_str($this->query, $queryArray);
if(array_key_exists($key, $queryArray))
{
$val = $queryArray[$key];
if(ctype_digit($val))
{
return intval($val);
}
elseif(is_string($val))
{
return new TeamSpeak3_Helper_String($val);
}
else
{
return $val;
}
}
return $default;
}
/**
* Returns TRUE if the fragment string is valid.
*
* @param string $fragment
* @throws TeamSpeak3_Helper_Exception
* @return boolean
*/
public function checkFragment($fragment = null)
{
if($fragment === null)
{
$fragment = $this->fragment;
}
if(strlen($fragment) == 0)
{
return TRUE;
}
$pattern = "/^" . $this->regex["uric"] . "*$/";
$status = @preg_match($pattern, $fragment);
if($status === FALSE)
{
throw new TeamSpeak3_Helper_Exception("URI fragment validation failed");
}
return ($status == 1);
}
/**
* Returns TRUE if the URI has a fragment string.
*
* @return boolean
*/
public function hasFragment()
{
return strlen($this->fragment) ? TRUE : FALSE;
}
/**
* Returns the fragment.
*
* @param mixed default
* @return TeamSpeak3_Helper_String
*/
public function getFragment($default = null)
{
return ($this->hasFragment()) ? new TeamSpeak3_Helper_String($this->fragment) : $default;
}
/**
* Returns a specified instance parameter from the $_REQUEST array.
*
* @param string $key
* @param mixed $default
* @return mixed
*/
public static function getUserParam($key, $default = null)
{
return (array_key_exists($key, $_REQUEST) && !empty($_REQUEST[$key])) ? self::stripslashesRecursive($_REQUEST[$key]) : $default;
}
/**
* Returns a specified environment parameter from the $_SERVER array.
*
* @param string $key
* @param mixed $default
* @return mixed
*/
public static function getHostParam($key, $default = null)
{
return (array_key_exists($key, $_SERVER) && !empty($_SERVER[$key])) ? $_SERVER[$key] : $default;
}
/**
* Returns a specified session parameter from the $_SESSION array.
*
* @param string $key
* @param mixed $default
* @return mixed
*/
public static function getSessParam($key, $default = null)
{
return (array_key_exists($key, $_SESSION) && !empty($_SESSION[$key])) ? $_SESSION[$key] : $default;
}
/**
* Returns an array containing the three main parts of a FQDN (Fully Qualified Domain Name), including the
* top-level domain, the second-level domains or hostname and the third-level domain.
*
* @param string $hostname
* @return array
*/
public static function getFQDNParts($hostname)
{
if(!preg_match("/^([a-z0-9][a-z0-9-]{0,62}\.)*([a-z0-9][a-z0-9-]{0,62}\.)+([a-z]{2,6})$/i", $hostname, $matches))
{
return array();
}
$parts["tld"] = $matches[3];
$parts["2nd"] = $matches[2];
$parts["3rd"] = $matches[1];
return $parts;
}
/**
* Returns the applications host address.
*
* @return TeamSpeak3_Helper_String
*/
public static function getHostUri()
{
$sheme = (self::getHostParam("HTTPS") == "on") ? "https" : "http";
$serverName = new TeamSpeak3_Helper_String(self::getHostParam("HTTP_HOST"));
$serverPort = self::getHostParam("SERVER_PORT");
$serverPort = ($serverPort != 80 && $serverPort != 443) ? ":" . $serverPort : "";
if($serverName->endsWith($serverPort))
{
$serverName = $serverName->replace($serverPort, "");
}
return new TeamSpeak3_Helper_String($sheme . "://" . $serverName . $serverPort);
}
/**
* Returns the applications base address.
*
* @return string
*/
public static function getBaseUri()
{
$scriptPath = new TeamSpeak3_Helper_String(dirname(self::getHostParam("SCRIPT_NAME")));
return self::getHostUri()->append(($scriptPath == DIRECTORY_SEPARATOR ? "" : $scriptPath) . "/");
}
/**
* Strips slashes from each element of an array using stripslashes().
*
* @param mixed $var
* @return mixed
*/
protected static function stripslashesRecursive($var)
{
if(!is_array($var))
{
return stripslashes(strval($var));
}
foreach($var as $key => $val)
{
$var[$key] = (is_array($val)) ? stripslashesRecursive($val) : stripslashes(strval($val));
}
return $var;
}
}
<?php
/**
* @file
* TeamSpeak 3 PHP Framework
*
* $Id: Abstract.php 06/06/2016 22:27:13 scp@Svens-iMac $
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @package TeamSpeak3
* @version 1.1.24
* @author Sven 'ScP' Paulsen
* @copyright Copyright (c) 2010 by Planet TeamSpeak. All rights reserved.
*/
/**
* @class TeamSpeak3_Node_Abstract
* @brief Abstract class describing a TeamSpeak 3 node and all it's parameters.
*/
abstract class TeamSpeak3_Node_Abstract implements RecursiveIterator, ArrayAccess, Countable
{
/**
* @ignore
*/
protected $parent = null;
/**
* @ignore
*/
protected $server = null;
/**
* @ignore
*/
protected $nodeId = 0x00;
/**
* @ignore
*/
protected $nodeList = null;
/**
* @ignore
*/
protected $nodeInfo = array();
/**
* @ignore
*/
protected $storage = array();
/**
* Sends a prepared command to the server and returns the result.
*
* @param string $cmd
* @param boolean $throw
* @return TeamSpeak3_Adapter_ServerQuery_Reply
*/
public function request($cmd, $throw = TRUE)
{
return $this->getParent()->request($cmd, $throw);
}
/**
* Uses given parameters and returns a prepared ServerQuery command.
*
* @param string $cmd
* @param array $params
* @return TeamSpeak3_Helper_String
*/
public function prepare($cmd, array $params = array())
{
return $this->getParent()->prepare($cmd, $params);
}
/**
* Prepares and executes a ServerQuery command and returns the result.
*
* @param string $cmd
* @param array $params
* @return TeamSpeak3_Adapter_ServerQuery_Reply
*/
public function execute($cmd, array $params = array())
{
return $this->request($this->prepare($cmd, $params));
}
/**
* Returns the parent object of the current node.
*
* @return TeamSpeak3_Adapter_ServerQuery
* @return TeamSpeak3_Node_Abstract
*/
public function getParent()
{
return $this->parent;
}
/**
* Returns the primary ID of the current node.
*
* @return integer
*/
public function getId()
{
return $this->nodeId;
}
/**
* Returns TRUE if the node icon has a local source.
*
* @param string $key
* @return boolean
*/
public function iconIsLocal($key)
{
return ($this[$key] > 0 && $this[$key] < 1000) ? TRUE : FALSE;
}
/**
* Returns the internal path of the node icon.
*
* @param string $key
* @return TeamSpeak3_Helper_String
*/
public function iconGetName($key)
{
$iconid = ($this[$key] < 0) ? (pow(2, 32))-($this[$key]*-1) : $this[$key];
return new TeamSpeak3_Helper_String("/icon_" . $iconid);
}
/**
* Returns a possible classname for the node which can be used as a HTML property.
*
* @param string $prefix
* @return string
*/
public function getClass($prefix = "ts3_")
{
if($this instanceof TeamSpeak3_Node_Channel && $this->isSpacer())
{
return $prefix . "spacer";
}
elseif($this instanceof TeamSpeak3_Node_Client && $this["client_type"])
{
return $prefix . "query";
}
return $prefix . TeamSpeak3_Helper_String::factory(get_class($this))->section("_", 2)->toLower();
}
/**
* Returns a unique identifier for the node which can be used as a HTML property.
*
* @return string
*/
abstract public function getUniqueId();
/**
* Returns the name of a possible icon to display the node object.
*
* @return string
*/
abstract public function getIcon();
/**
* Returns a symbol representing the node.
*
* @return string
*/
abstract public function getSymbol();
/**
* Returns the HTML code to display a TeamSpeak 3 viewer.
*
* @param TeamSpeak3_Viewer_Interface $viewer
* @return string
*/
public function getViewer(TeamSpeak3_Viewer_Interface $viewer)
{
$html = $viewer->fetchObject($this);
$iterator = new RecursiveIteratorIterator($this, RecursiveIteratorIterator::SELF_FIRST);
foreach($iterator as $node)
{
$siblings = array();
for($level = 0; $level < $iterator->getDepth(); $level++)
{
$siblings[] = ($iterator->getSubIterator($level)->hasNext()) ? 1 : 0;
}
$siblings[] = (!$iterator->getSubIterator($level)->hasNext()) ? 1 : 0;
$html .= $viewer->fetchObject($node, $siblings);
}
return $html;
}
/**
* Filters given node list array using specified filter rules.
*
* @param array $nodes
* @param array $rules
* @return array
*/
protected function filterList(array $nodes = array(), array $rules = array())
{
if(!empty($rules))
{
foreach($nodes as $node)
{
if(!$node instanceof TeamSpeak3_Node_Abstract) continue;
$props = $node->getInfo(FALSE);
$props = array_intersect_key($props, $rules);
foreach($props as $key => $val)
{
if($val instanceof TeamSpeak3_Helper_String)
{
$match = $val->contains($rules[$key], TRUE);
}
else
{
$match = $val == $rules[$key];
}
if($match === FALSE)
{
unset($nodes[$node->getId()]);
}
}
}
}
return $nodes;
}
/**
* Returns all information available on this node. If $convert is enabled, some property
* values will be converted to human-readable values.
*
* @param boolean $extend
* @param boolean $convert
* @return array
*/
public function getInfo($extend = TRUE, $convert = FALSE)
{
if($extend)
{
$this->fetchNodeInfo();
}
if($convert)
{
$info = $this->nodeInfo;
foreach($info as $key => $val)
{
$key = TeamSpeak3_Helper_String::factory($key);
if($key->contains("_bytes_"))
{
$info[$key->toString()] = TeamSpeak3_Helper_Convert::bytes($val);
}
elseif($key->contains("_bandwidth_"))
{
$info[$key->toString()] = TeamSpeak3_Helper_Convert::bytes($val) . "/s";
}
elseif($key->contains("_packets_"))
{
$info[$key->toString()] = number_format($val, null, null, ".");
}
elseif($key->contains("_packetloss_"))
{
$info[$key->toString()] = sprintf("%01.2f", floatval($val->toString())*100) . "%";
}
elseif($key->endsWith("_uptime"))
{
$info[$key->toString()] = TeamSpeak3_Helper_Convert::seconds($val);
}
elseif($key->endsWith("_version"))
{
$info[$key->toString()] = TeamSpeak3_Helper_Convert::version($val);
}
elseif($key->endsWith("_icon_id"))
{
$info[$key->toString()] = $this->iconGetName($key)->filterDigits();
}
}
return $info;
}
return $this->nodeInfo;
}
/**
* Returns the specified property or a pre-defined default value from the node info array.
*
* @param string $property
* @param mixed $default
* @return mixed
*/
public function getProperty($property, $default = null)
{
if(!$this->offsetExists($property))
{
$this->fetchNodeInfo();
}
if(!$this->offsetExists($property))
{
return $default;
}
return $this->nodeInfo[(string) $property];
}
/**
* Returns a string representation of this node.
*
* @return string
*/
public function __toString()
{
return get_class($this);
}
/**
* Returns a string representation of this node.
*
* @return string
*/
public function toString()
{
return $this->__toString();
}
/**
* Returns an assoc array filled with current node info properties.
*
* @return array
*/
public function toArray()
{
return $this->nodeList;
}
/**
* Called whenever we're using an unknown method.
*
* @param string $name
* @param array $args
* @throws TeamSpeak3_Node_Exception
* @return mixed
*/
public function __call($name, array $args)
{
if($this->getParent() instanceof TeamSpeak3_Node_Abstract)
{
return call_user_func_array(array($this->getParent(), $name), $args);
}
throw new TeamSpeak3_Node_Exception("node method '" . $name . "()' does not exist");
}
/**
* Writes data to the internal storage array.
*
* @param string $key
* @param mixed $val
* @return void
*/
protected function setStorage($key, $val)
{
$this->storage[$key] = $val;
}
/**
* Returns data from the internal storage array.
*
* @param string $key
* @param mixed $default
* @return mixed
*/
protected function getStorage($key, $default = null)
{
return !empty($this->storage[$key]) ? $this->storage[$key] : $default;
}
/**
* Deletes data from the internal storage array.
*
* @param string $key
* @return void
*/
protected function delStorage($key)
{
unset($this->storage[$key]);
}
/**
* Commit pending data.
*
* @return array
*/
public function __sleep()
{
return array("parent", "storage", "nodeId");
}
/**
* @ignore
*/
protected function fetchNodeList()
{
$this->nodeList = array();
}
/**
* @ignore
*/
protected function fetchNodeInfo()
{
return;
}
/**
* @ignore
*/
protected function resetNodeInfo()
{
$this->nodeInfo = array();
}
/**
* @ignore
*/
protected function verifyNodeList()
{
if($this->nodeList === null)
{
$this->fetchNodeList();
}
}
/**
* @ignore
*/
protected function resetNodeList()
{
$this->nodeList = null;
}
/**
* @ignore
*/
public function count()
{
$this->verifyNodeList();
return count($this->nodeList);
}
/**
* @ignore
*/
public function current()
{
$this->verifyNodeList();
return current($this->nodeList);
}
/**
* @ignore
*/
public function getChildren()
{
$this->verifyNodeList();
return $this->current();
}
/**
* @ignore
*/
public function hasChildren()
{
$this->verifyNodeList();
return $this->current()->count() > 0;
}
/**
* @ignore
*/
public function hasNext()
{
$this->verifyNodeList();
return $this->key()+1 < $this->count();
}
/**
* @ignore
*/
public function key()
{
$this->verifyNodeList();
return key($this->nodeList);
}
/**
* @ignore
*/
public function valid()
{
$this->verifyNodeList();
return $this->key() !== null;
}
/**
* @ignore
*/
public function next()
{
$this->verifyNodeList();
return next($this->nodeList);
}
/**
* @ignore
*/
public function rewind()
{
$this->verifyNodeList();
return reset($this->nodeList);
}
/**
* @ignore
*/
public function offsetExists($offset)
{
return array_key_exists((string) $offset, $this->nodeInfo) ? TRUE : FALSE;
}
/**
* @ignore
*/
public function offsetGet($offset)
{
if(!$this->offsetExists($offset))
{
$this->fetchNodeInfo();
}
if(!$this->offsetExists($offset))
{
throw new TeamSpeak3_Adapter_ServerQuery_Exception("invalid parameter", 0x602);
}
return $this->nodeInfo[(string) $offset];
}
/**
* @ignore
*/
public function offsetSet($offset, $value)
{
if(method_exists($this, "modify"))
{
return $this->modify(array((string) $offset => $value));
}
throw new TeamSpeak3_Node_Exception("node '" . get_class($this) . "' is read only");
}
/**
* @ignore
*/
public function offsetUnset($offset)
{
unset($this->nodeInfo[(string) $offset]);
}
/**
* @ignore
*/
public function __get($offset)
{
return $this->offsetGet($offset);
}
/**
* @ignore
*/
public function __set($offset, $value)
{
$this->offsetSet($offset, $value);
}
}
<?php
/**
* @file
* TeamSpeak 3 PHP Framework
*
* $Id: Channel.php 06/06/2016 22:27:13 scp@Svens-iMac $
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @package TeamSpeak3
* @version 1.1.24
* @author Sven 'ScP' Paulsen
* @copyright Copyright (c) 2010 by Planet TeamSpeak. All rights reserved.
*/
/**
* @class TeamSpeak3_Node_Channel
* @brief Class describing a TeamSpeak 3 channel and all it's parameters.
*/
class TeamSpeak3_Node_Channel extends TeamSpeak3_Node_Abstract
{
/**
* The TeamSpeak3_Node_Channel constructor.
*
* @param TeamSpeak3_Node_Server $server
* @param array $info
* @param string $index
* @throws TeamSpeak3_Adapter_ServerQuery_Exception
* @return TeamSpeak3_Node_Channel
*/
public function __construct(TeamSpeak3_Node_Server $server, array $info, $index = "cid")
{
$this->parent = $server;
$this->nodeInfo = $info;
if(!array_key_exists($index, $this->nodeInfo))
{
throw new TeamSpeak3_Adapter_ServerQuery_Exception("invalid channelID", 0x300);
}
$this->nodeId = $this->nodeInfo[$index];
}
/**
* Returns an array filled with TeamSpeak3_Node_Channel objects.
*
* @param array $filter
* @return array
*/
public function subChannelList(array $filter = array())
{
$channels = array();
foreach($this->getParent()->channelList() as $channel)
{
if($channel["pid"] == $this->getId())
{
$channels[$channel->getId()] = $channel;
}
}
return $this->filterList($channels, $filter);
}
/**
* Returns the TeamSpeak3_Node_Channel object matching the given ID.
*
* @param integer $cid
* @throws TeamSpeak3_Adapter_ServerQuery_Exception
* @return TeamSpeak3_Node_Channel
*/
public function subChannelGetById($cid)
{
if(!array_key_exists((string) $cid, $this->subChannelList()))
{
throw new TeamSpeak3_Adapter_ServerQuery_Exception("invalid channelID", 0x300);
}
return $this->channelList[(string) $cid];
}
/**
* Returns the TeamSpeak3_Node_Channel object matching the given name.
*
* @param integer $name
* @throws TeamSpeak3_Adapter_ServerQuery_Exception
* @return TeamSpeak3_Node_Channel
*/
public function subChannelGetByName($name)
{
foreach($this->subChannelList() as $channel)
{
if($channel["channel_name"] == $name) return $channel;
}
throw new TeamSpeak3_Adapter_ServerQuery_Exception("invalid channelID", 0x300);
}
/**
* Returns an array filled with TeamSpeak3_Node_Client objects.
*
* @param array $filter
* @return array
*/
public function clientList(array $filter = array())
{
$clients = array();
foreach($this->getParent()->clientList() as $client)
{
if($client["cid"] == $this->getId())
{
$clients[$client->getId()] = $client;
}
}
return $this->filterList($clients, $filter);
}
/**
* Returns the TeamSpeak3_Node_Client object matching the given ID.
*
* @param integer $clid
* @throws TeamSpeak3_Adapter_ServerQuery_Exception
* @return TeamSpeak3_Node_Client
*/
public function clientGetById($clid)
{
if(!array_key_exists($clid, $this->clientList()))
{
throw new TeamSpeak3_Adapter_ServerQuery_Exception("invalid clientID", 0x200);
}
return $this->clientList[intval($clid)];
}
/**
* Returns the TeamSpeak3_Node_Client object matching the given name.
*
* @param integer $name
* @throws TeamSpeak3_Adapter_ServerQuery_Exception
* @return TeamSpeak3_Node_Client
*/
public function clientGetByName($name)
{
foreach($this->clientList() as $client)
{
if($client["client_nickname"] == $name) return $client;
}
throw new TeamSpeak3_Adapter_ServerQuery_Exception("invalid clientID", 0x200);
}
/**
* Returns a list of permissions defined for a client in the channel.
*
* @param integer $cldbid
* @param boolean $permsid
* @return array
*/
public function clientPermList($cldbid, $permsid = FALSE)
{
return $this->getParent()->channelClientPermList($this->getId(), $cldbid, $permsid);
}
/**
* Adds a set of specified permissions to a client in a specific channel. Multiple permissions can be added by
* providing the two parameters of each permission.
*
* @param integer $cldbid
* @param integer $permid
* @param integer $permvalue
* @return void
*/
public function clientPermAssign($cldbid, $permid, $permvalue)
{
$this->getParent()->channelClientPermAssign($this->getId(), $cldbid, $permid, $permvalue);
}
/**
* Alias for clientPermAssign().
*
* @deprecated
*/
public function clientPermAssignByName($cldbid, $permname, $permvalue)
{
$this->clientPermAssign($cldbid, $permname, $permvalue);
}
/**
* Removes a set of specified permissions from a client in the channel. Multiple permissions can be removed at once.
*
* @param integer $cldbid
* @param integer $permid
* @return void
*/
public function clientPermRemove($cldbid, $permid)
{
$this->getParent()->channelClientPermRemove($this->getId(), $cldbid, $permid);
}
/**
* Alias for clientPermRemove().
*
* @deprecated
*/
public function clientPermRemoveByName($cldbid, $permname)
{
$this->clientPermRemove($cldbid, $permname);
}
/**
* Returns a list of permissions defined for the channel.
*
* @param boolean $permsid
* @return array
*/
public function permList($permsid = FALSE)
{
return $this->getParent()->channelPermList($this->getId(), $permsid);
}
/**
* Adds a set of specified permissions to the channel. Multiple permissions can be added by
* providing the two parameters of each permission.
*
* @param integer $permid
* @param integer $permvalue
* @return void
*/
public function permAssign($permid, $permvalue)
{
$this->getParent()->channelPermAssign($this->getId(), $permid, $permvalue);
}
/**
* Alias for permAssign().
*
* @deprecated
*/
public function permAssignByName($permname, $permvalue)
{
$this->permAssign($permname, $permvalue);
}
/**
* Removes a set of specified permissions from the channel. Multiple permissions can be removed at once.
*
* @param integer $permid
* @return void
*/
public function permRemove($permid)
{
$this->getParent()->channelPermRemove($this->getId(), $permid);
}
/**
* Alias for permRemove().
*
* @deprecated
*/
public function permRemoveByName($permname)
{
$this->permRemove($permname);
}
/**
* Returns a list of files and directories stored in the channels file repository.
*
* @param string $cpw
* @param string $path
* @param boolean $recursive
* @return array
*/
public function fileList($cpw = "", $path = "/", $recursive = FALSE)
{
return $this->getParent()->channelFileList($this->getId(), $cpw, $path, $recursive);
}
/**
* Returns detailed information about the specified file stored in the channels file repository.
*
* @param string $cpw
* @param string $name
* @return array
*/
public function fileInfo($cpw = "", $name = "/")
{
return $this->getParent()->channelFileInfo($this->getId(), $cpw, $name);
}
/**
* Renames a file in the channels file repository. If the two parameters $tcid and $tcpw are specified, the file
* will be moved into another channels file repository.
*
* @param string $cpw
* @param string $oldname
* @param string $newname
* @param integer $tcid
* @param string $tcpw
* @return void
*/
public function fileRename($cpw = "", $oldname = "/", $newname = "/", $tcid = null, $tcpw = null)
{
$this->getParent()->channelFileRename($this->getId(), $cpw, $oldname, $newname, $tcid, $tcpw);
}
/**
* Deletes one or more files stored in the channels file repository.
*
* @param string $cpw
* @param string $path
* @return void
*/
public function fileDelete($cpw = "", $name = "/")
{
$this->getParent()->channelFileDelete($this->getId(), $cpw, $name);
}
/**
* Creates new directory in a channels file repository.
*
* @param string $cpw
* @param string $dirname
* @return void
*/
public function dirCreate($cpw = "", $dirname = "/")
{
$this->getParent()->channelDirCreate($this->getId(), $cpw, $dirname);
}
/**
* Returns the level of the channel.
*
* @return integer
*/
public function getLevel()
{
return $this->getParent()->channelGetLevel($this->getId());
}
/**
* Returns the pathway of the channel which can be used as a clients default channel.
*
* @return string
*/
public function getPathway()
{
return $this->getParent()->channelGetPathway($this->getId());
}
/**
* Returns the possible spacer type of the channel.
*
* @return integer
*/
public function spacerGetType()
{
return $this->getParent()->channelSpacerGetType($this->getId());
}
/**
* Returns the possible spacer alignment of the channel.
*
* @return integer
*/
public function spacerGetAlign()
{
return $this->getParent()->channelSpacerGetAlign($this->getId());
}
/**
* Returns TRUE if the channel is a spacer.
*
* @return boolean
*/
public function isSpacer()
{
return $this->getParent()->channelIsSpacer($this);
}
/**
* Downloads and returns the channels icon file content.
*
* @return TeamSpeak3_Helper_String
*/
public function iconDownload()
{
if($this->iconIsLocal("channel_icon_id") || $this["channel_icon_id"] == 0) return;
$download = $this->getParent()->transferInitDownload(rand(0x0000, 0xFFFF), 0, $this->iconGetName("channel_icon_id"));
$transfer = TeamSpeak3::factory("filetransfer://" . (strstr($download["host"], ":") !== FALSE ? "[" . $download["host"] . "]" : $download["host"]) . ":" . $download["port"]);
return $transfer->download($download["ftkey"], $download["size"]);
}
/**
* Changes the channel configuration using given properties.
*
* @param array $properties
* @return void
*/
public function modify(array $properties)
{
$properties["cid"] = $this->getId();
$this->execute("channeledit", $properties);
$this->resetNodeInfo();
}
/**
* Sends a text message to all clients in the channel.
*
* @param string $msg
* @param string $cpw
* @return void
*/
public function message($msg, $cpw = null)
{
if($this->getId() != $this->getParent()->whoamiGet("client_channel_id"))
{
$this->getParent()->clientMove($this->getParent()->whoamiGet("client_id"), $this->getId(), $cpw);
}
$this->execute("sendtextmessage", array("msg" => $msg, "target" => $this->getId(), "targetmode" => TeamSpeak3::TEXTMSG_CHANNEL));
}
/**
* Deletes the channel.
*
* @param boolean $force
* @return void
*/
public function delete($force = FALSE)
{
$this->getParent()->channelDelete($this->getId(), $force);
}
/**
* Moves the channel to the parent channel specified with $pid.
*
* @param integer $pid
* @param integer $order
* @return void
*/
public function move($pid, $order = null)
{
$this->getParent()->channelMove($this->getId(), $pid, $order);
}
/**
* Sends a plugin command to all clients in the channel.
*
* @param string $plugin
* @param string $data
* @param string $cpw
* @param boolean $subscribed
* @return void
*/
public function sendPluginCmd($plugin, $data, $cpw = null, $subscribed = FALSE)
{
if($this->getId() != $this->getParent()->whoamiGet("client_channel_id"))
{
$this->getParent()->clientMove($this->getParent()->whoamiGet("client_id"), $this->getId(), $cpw);
}
$this->execute("plugincmd", array("name" => $plugin, "data" => $data, "targetmode" => $subscribed ? TeamSpeak3::PLUGINCMD_CHANNEL_SUBSCRIBED : TeamSpeak3::PLUGINCMD_CHANNEL));
}
/**
* @ignore
*/
protected function fetchNodeList()
{
$this->nodeList = array();
if($this->getParent()->getLoadClientlistFirst())
{
foreach($this->clientList() as $client)
{
if($client["cid"] == $this->getId())
{
$this->nodeList[] = $client;
}
}
foreach($this->subChannelList() as $channel)
{
if($channel["pid"] == $this->getId())
{
$this->nodeList[] = $channel;
}
}
}
else
{
foreach($this->subChannelList() as $channel)
{
if($channel["pid"] == $this->getId())
{
$this->nodeList[] = $channel;
}
}
foreach($this->clientList() as $client)
{
if($client["cid"] == $this->getId())
{
$this->nodeList[] = $client;
}
}
}
}
/**
* @ignore
*/
protected function fetchNodeInfo()
{
$this->nodeInfo = array_merge($this->nodeInfo, $this->execute("channelinfo", array("cid" => $this->getId()))->toList());
}
/**
* Returns a unique identifier for the node which can be used as a HTML property.
*
* @return string
*/
public function getUniqueId()
{
return $this->getParent()->getUniqueId() . "_ch" . $this->getId();
}
/**
* Returns the name of a possible icon to display the node object.
*
* @return string
*/
public function getIcon()
{
if($this["channel_maxclients"] != -1 && $this["channel_maxclients"] <= $this["total_clients"])
{
return "channel_full";
}
elseif($this["channel_flag_password"])
{
return "channel_pass";
}
else
{
return "channel_open";
}
}
/**
* Returns a symbol representing the node.
*
* @return string
*/
public function getSymbol()
{
return "#";
}
/**
* Returns a string representation of this node.
*
* @return string
*/
public function __toString()
{
return (string) $this["channel_name"];
}
}
<?php
/**
* @file
* TeamSpeak 3 PHP Framework
*
* $Id: Channelgroup.php 06/06/2016 22:27:13 scp@Svens-iMac $
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @package TeamSpeak3
* @version 1.1.24
* @author Sven 'ScP' Paulsen
* @copyright Copyright (c) 2010 by Planet TeamSpeak. All rights reserved.
*/
/**
* @class TeamSpeak3_Node_Channelgroup
* @brief Class describing a TeamSpeak 3 channel group and all it's parameters.
*/
class TeamSpeak3_Node_Channelgroup extends TeamSpeak3_Node_Abstract
{
/**
* The TeamSpeak3_Node_Channelgroup constructor.
*
* @param TeamSpeak3_Node_Server $server
* @param array $info
* @param string $index
* @throws TeamSpeak3_Adapter_ServerQuery_Exception
* @return TeamSpeak3_Node_Channelgroup
*/
public function __construct(TeamSpeak3_Node_Server $server, array $info, $index = "cgid")
{
$this->parent = $server;
$this->nodeInfo = $info;
if(!array_key_exists($index, $this->nodeInfo))
{
throw new TeamSpeak3_Adapter_ServerQuery_Exception("invalid groupID", 0xA00);
}
$this->nodeId = $this->nodeInfo[$index];
}
/**
* Renames the channel group specified.
*
* @param string $name
* @return void
*/
public function rename($name)
{
$this->getParent()->channelGroupRename($this->getId(), $name);
}
/**
* Deletes the channel group. If $force is set to TRUE, the channel group will be
* deleted even if there are clients within.
*
* @param boolean $force
* @return void
*/
public function delete($force = FALSE)
{
$this->getParent()->channelGroupDelete($this->getId(), $force);
}
/**
* Creates a copy of the channel group and returns the new groups ID.
*
* @param string $name
* @param integer $tcgid
* @param integer $type
* @return integer
*/
public function copy($name = null, $tcgid = 0, $type = TeamSpeak3::GROUP_DBTYPE_REGULAR)
{
return $this->getParent()->channelGroupCopy($this->getId(), $name, $tcgid, $type);
}
/**
* Returns a list of permissions assigned to the channel group.
*
* @param boolean $permsid
* @return array
*/
public function permList($permsid = FALSE)
{
return $this->getParent()->channelGroupPermList($this->getId(), $permsid);
}
/**
* Adds a set of specified permissions to the channel group. Multiple permissions
* can be added by providing the two parameters of each permission in separate arrays.
*
* @param integer $permid
* @param integer $permvalue
* @return void
*/
public function permAssign($permid, $permvalue)
{
$this->getParent()->channelGroupPermAssign($this->getId(), $permid, $permvalue);
}
/**
* Alias for permAssign().
*
* @deprecated
*/
public function permAssignByName($permname, $permvalue)
{
$this->permAssign($permname, $permvalue);
}
/**
* Removes a set of specified permissions from the channel group. Multiple
* permissions can be removed at once.
*
* @param integer $permid
* @return void
*/
public function permRemove($permid)
{
$this->getParent()->channelGroupPermRemove($this->getId(), $permid);
}
/**
* Alias for permAssign().
*
* @deprecated
*/
public function permRemoveByName($permname)
{
$this->permRemove($permname);
}
/**
* Returns a list of clients assigned to the server group specified.
*
* @return array
*/
public function clientList()
{
return $this->getParent()->channelGroupClientList($this->getId());
}
/**
* Alias for privilegeKeyCreate().
*
* @deprecated
*/
public function tokenCreate($cid, $description = null, $customset = null)
{
return $this->privilegeKeyCreate($cid, $description, $customset);
}
/**
* Creates a new privilege key (token) for the channel group and returns the key.
*
* @param integer $cid
* @param string $description
* @param string $customset
* @return TeamSpeak3_Helper_String
*/
public function privilegeKeyCreate($cid, $description = null, $customset = null)
{
return $this->getParent()->privilegeKeyCreate(TeamSpeak3::TOKEN_CHANNELGROUP, $this->getId(), $cid, $description, $customset);
}
/**
* Sends a text message to all clients residing in the channel group on the virtual server.
*
* @param string $msg
* @return void
*/
public function message($msg)
{
foreach($this as $client)
{
try
{
$this->execute("sendtextmessage", array("msg" => $msg, "target" => $client, "targetmode" => TeamSpeak3::TEXTMSG_CLIENT));
}
catch(TeamSpeak3_Adapter_ServerQuery_Exception $e)
{
/* ERROR_client_invalid_id */
if($e->getCode() != 0x0200) throw $e;
}
}
}
/**
* Downloads and returns the channel groups icon file content.
*
* @return TeamSpeak3_Helper_String
*/
public function iconDownload()
{
if($this->iconIsLocal("iconid") || $this["iconid"] == 0) return;
$download = $this->getParent()->transferInitDownload(rand(0x0000, 0xFFFF), 0, $this->iconGetName("iconid"));
$transfer = TeamSpeak3::factory("filetransfer://" . (strstr($download["host"], ":") !== FALSE ? "[" . $download["host"] . "]" : $download["host"]) . ":" . $download["port"]);
return $transfer->download($download["ftkey"], $download["size"]);
}
/**
* @ignore
*/
protected function fetchNodeList()
{
$this->nodeList = array();
foreach($this->getParent()->clientList() as $client)
{
if($client["client_channel_group_id"] == $this->getId())
{
$this->nodeList[] = $client;
}
}
}
/**
* Returns a unique identifier for the node which can be used as a HTML property.
*
* @return string
*/
public function getUniqueId()
{
return $this->getParent()->getUniqueId() . "_cg" . $this->getId();
}
/**
* Returns the name of a possible icon to display the node object.
*
* @return string
*/
public function getIcon()
{
return "group_channel";
}
/**
* Returns a symbol representing the node.
*
* @return string
*/
public function getSymbol()
{
return "%";
}
/**
* Returns a string representation of this node.
*
* @return string
*/
public function __toString()
{
return (string) $this["name"];
}
}
<?php
/**
* @file
* TeamSpeak 3 PHP Framework
*
* $Id: Client.php 06/06/2016 22:27:13 scp@Svens-iMac $
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @package TeamSpeak3
* @version 1.1.24
* @author Sven 'ScP' Paulsen
* @copyright Copyright (c) 2010 by Planet TeamSpeak. All rights reserved.
*/
/**
* @class TeamSpeak3_Node_Client
* @brief Class describing a TeamSpeak 3 client and all it's parameters.
*/
class TeamSpeak3_Node_Client extends TeamSpeak3_Node_Abstract
{
/**
* The TeamSpeak3_Node_Client constructor.
*
* @param TeamSpeak3_Node_Server $server
* @param array $info
* @param string $index
* @throws TeamSpeak3_Adapter_ServerQuery_Exception
* @return TeamSpeak3_Node_Client
*/
public function __construct(TeamSpeak3_Node_Server $server, array $info, $index = "clid")
{
$this->parent = $server;
$this->nodeInfo = $info;
if(!array_key_exists($index, $this->nodeInfo))
{
throw new TeamSpeak3_Adapter_ServerQuery_Exception("invalid clientID", 0x200);
}
$this->nodeId = $this->nodeInfo[$index];
}
/**
* Changes the clients properties using given properties.
*
* @param array $properties
* @return void
*/
public function modify(array $properties)
{
$properties["clid"] = $this->getId();
$this->execute("clientedit", $properties);
$this->resetNodeInfo();
}
/**
* Changes the clients properties using given properties.
*
* @param array $properties
* @return void
*/
public function modifyDb(array $properties)
{
$this->getParent()->clientModifyDb($this["client_database_id"], $properties);
}
/**
* Deletes the clients properties from the database.
*
* @return void
*/
public function deleteDb()
{
$this->getParent()->clientDeleteDb($this["client_database_id"]);
}
/**
* Returns a list of properties from the database for the client.
*
* @return array
*/
public function infoDb()
{
return $this->getParent()->clientInfoDb($this["client_database_id"]);
}
/**
* Sends a text message to the client.
*
* @param string $msg
* @return void
*/
public function message($msg)
{
$this->execute("sendtextmessage", array("msg" => $msg, "target" => $this->getId(), "targetmode" => TeamSpeak3::TEXTMSG_CLIENT));
}
/**
* Moves the client to another channel.
*
* @param integer $cid
* @param string $cpw
* @return void
*/
public function move($cid, $cpw = null)
{
$this->getParent()->clientMove($this->getId(), $cid, $cpw);
}
/**
* Kicks the client from his currently joined channel or from the server.
*
* @param integer $reasonid
* @param string $reasonmsg
* @return void
*/
public function kick($reasonid = TeamSpeak3::KICK_CHANNEL, $reasonmsg = null)
{
$this->getParent()->clientKick($this->getId(), $reasonid, $reasonmsg);
}
/**
* Sends a poke message to the client.
*
* @param string $msg
* @return void
*/
public function poke($msg)
{
$this->getParent()->clientPoke($this->getId(), $msg);
}
/**
* Bans the client from the server. Please note that this will create two separate
* ban rules for the targeted clients IP address and his unique identifier.
*
* @param integer $timeseconds
* @param string $reason
* @return array
*/
public function ban($timeseconds = null, $reason = null)
{
return $this->getParent()->clientBan($this->getId(), $timeseconds, $reason);
}
/**
* Returns a list of custom properties for the client.
*
* @return array
*/
public function customInfo()
{
return $this->getParent()->customInfo($this["client_database_id"]);
}
/**
* Returns an array containing the permission overview of the client.
*
* @param integer $cid
* @return array
*/
public function permOverview($cid)
{
return $this->execute("permoverview", array("cldbid" => $this["client_database_id"], "cid" => $cid, "permid" => 0))->toArray();
}
/**
* Returns a list of permissions defined for the client.
*
* @param boolean $permsid
* @return array
*/
public function permList($permsid = FALSE)
{
return $this->getParent()->clientPermList($this["client_database_id"], $permsid);
}
/**
* Adds a set of specified permissions to the client. Multiple permissions can be added by providing
* the three parameters of each permission.
*
* @param integer $permid
* @param integer $permvalue
* @param integer $permskip
* @return void
*/
public function permAssign($permid, $permvalue, $permskip = FALSE)
{
$this->getParent()->clientPermAssign($this["client_database_id"], $permid, $permvalue, $permskip);
}
/**
* Alias for permAssign().
*
* @deprecated
*/
public function permAssignByName($permname, $permvalue, $permskip = FALSE)
{
$this->permAssign($permname, $permvalue, $permskip);
}
/**
* Removes a set of specified permissions from a client. Multiple permissions can be removed at once.
*
* @param integer $permid
* @return void
*/
public function permRemove($permid)
{
$this->getParent()->clientPermRemove($this["client_database_id"], $permid);
}
/**
* Alias for permRemove().
*
* @deprecated
*/
public function permRemoveByName($permname)
{
$this->permRemove($permname);
}
/**
* Sets the channel group of a client to the ID specified.
*
* @param integer $cid
* @param integer $cgid
* @return void
*/
public function setChannelGroup($cid, $cgid)
{
$this->getParent()->clientSetChannelGroup($this["client_database_id"], $cid, $cgid);
}
/**
* Adds the client to the server group specified with $sgid.
*
* @param integer $sgid
* @return void
*/
public function addServerGroup($sgid)
{
$this->getParent()->serverGroupClientAdd($sgid, $this["client_database_id"]);
}
/**
* Removes the client from the server group specified with $sgid.
*
* @param integer $sgid
* @return void
*/
public function remServerGroup($sgid)
{
$this->getParent()->serverGroupClientDel($sgid, $this["client_database_id"]);
}
/**
* Returns the possible name of the clients avatar.
*
* @return TeamSpeak3_Helper_String
*/
public function avatarGetName()
{
return new TeamSpeak3_Helper_String("/avatar_" . $this["client_base64HashClientUID"]);
}
/**
* Downloads and returns the clients avatar file content.
*
* @return TeamSpeak3_Helper_String
*/
public function avatarDownload()
{
if($this["client_flag_avatar"] == NULL) return;
$download = $this->getParent()->transferInitDownload(rand(0x0000, 0xFFFF), 0, $this->avatarGetName());
$transfer = TeamSpeak3::factory("filetransfer://" . (strstr($download["host"], ":") !== FALSE ? "[" . $download["host"] . "]" : $download["host"]) . ":" . $download["port"]);
return $transfer->download($download["ftkey"], $download["size"]);
}
/**
* Returns a list of client connections using the same identity as this client.
*
* @return array
*/
public function getClones()
{
return $this->execute("clientgetids", array("cluid" => $this["client_unique_identifier"]))->toAssocArray("clid");
}
/**
* Returns the revision/build number from the clients version string.
*
* @return integer
*/
public function getRev()
{
return $this["client_type"] ? null : $this["client_version"]->section("[", 1)->filterDigits();
}
/**
* Returns all server and channel groups the client is currently residing in.
*
* @return array
*/
public function memberOf()
{
$groups = array($this->getParent()->channelGroupGetById($this["client_channel_group_id"]));
foreach(explode(",", $this["client_servergroups"]) as $sgid)
{
$groups[] = $this->getParent()->serverGroupGetById($sgid);
}
return $groups;
}
/**
* Downloads and returns the clients icon file content.
*
* @return TeamSpeak3_Helper_String
*/
public function iconDownload()
{
if($this->iconIsLocal("client_icon_id") || $this["client_icon_id"] == 0) return;
$download = $this->getParent()->transferInitDownload(rand(0x0000, 0xFFFF), 0, $this->iconGetName("client_icon_id"));
$transfer = TeamSpeak3::factory("filetransfer://" . (strstr($download["host"], ":") !== FALSE ? "[" . $download["host"] . "]" : $download["host"]) . ":" . $download["port"]);
return $transfer->download($download["ftkey"], $download["size"]);
}
/**
* Sends a plugin command to the client.
*
* @param string $plugin
* @param string $data
* @return void
*/
public function sendPluginCmd($plugin, $data)
{
$this->execute("plugincmd", array("name" => $plugin, "data" => $data, "targetmode" => TeamSpeak3::PLUGINCMD_CLIENT, "target" => $this->getId()));
}
/**
* @ignore
*/
protected function fetchNodeInfo()
{
if($this->offsetExists("client_type") && $this["client_type"] == 1) return;
$this->nodeInfo = array_merge($this->nodeInfo, $this->execute("clientinfo", array("clid" => $this->getId()))->toList());
}
/**
* Returns a unique identifier for the node which can be used as a HTML property.
*
* @return string
*/
public function getUniqueId()
{
return $this->getParent()->getUniqueId() . "_cl" . $this->getId();
}
/**
* Returns the name of a possible icon to display the node object.
*
* @return string
*/
public function getIcon()
{
if($this["client_type"])
{
return "client_query";
}
elseif($this["client_away"])
{
return "client_away";
}
elseif(!$this["client_output_hardware"])
{
return "client_snd_disabled";
}
elseif($this["client_output_muted"])
{
return "client_snd_muted";
}
elseif(!$this["client_input_hardware"])
{
return "client_mic_disabled";
}
elseif($this["client_input_muted"])
{
return "client_mic_muted";
}
elseif($this["client_is_channel_commander"])
{
return $this["client_flag_talking"] ? "client_cc_talk" : "client_cc_idle";
}
else
{
return $this["client_flag_talking"] ? "client_talk" : "client_idle";
}
}
/**
* Returns a symbol representing the node.
*
* @return string
*/
public function getSymbol()
{
return "@";
}
/**
* Returns a string representation of this node.
*
* @return string
*/
public function __toString()
{
return (string) $this["client_nickname"];
}
}
<?php
/**
* @file
* TeamSpeak 3 PHP Framework
*
* $Id: Exception.php 06/06/2016 22:27:13 scp@Svens-iMac $
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @package TeamSpeak3
* @version 1.1.24
* @author Sven 'ScP' Paulsen
* @copyright Copyright (c) 2010 by Planet TeamSpeak. All rights reserved.
*/
/**
* @class TeamSpeak3_Node_Exception
* @brief Enhanced exception class for TeamSpeak3_Node_Abstract objects.
*/
class TeamSpeak3_Node_Exception extends TeamSpeak3_Exception {}
<?php
/**
* @file
* TeamSpeak 3 PHP Framework
*
* $Id: Host.php 06/06/2016 22:27:13 scp@Svens-iMac $
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @package TeamSpeak3
* @version 1.1.24
* @author Sven 'ScP' Paulsen
* @copyright Copyright (c) 2010 by Planet TeamSpeak. All rights reserved.
*/
/**
* @class TeamSpeak3_Node_Host
* @brief Class describing a TeamSpeak 3 server instance and all it's parameters.
*/
class TeamSpeak3_Node_Host extends TeamSpeak3_Node_Abstract
{
/**
* @ignore
*/
protected $whoami = null;
/**
* @ignore
*/
protected $version = null;
/**
* @ignore
*/
protected $serverList = null;
/**
* @ignore
*/
protected $permissionEnds = null;
/**
* @ignore
*/
protected $permissionList = null;
/**
* @ignore
*/
protected $permissionCats = null;
/**
* @ignore
*/
protected $predefined_query_name = null;
/**
* @ignore
*/
protected $exclude_query_clients = FALSE;
/**
* @ignore
*/
protected $start_offline_virtual = FALSE;
/**
* @ignore
*/
protected $sort_clients_channels = FALSE;
/**
* The TeamSpeak3_Node_Host constructor.
*
* @param TeamSpeak3_Adapter_ServerQuery $squery
* @return TeamSpeak3_Node_Host
*/
public function __construct(TeamSpeak3_Adapter_ServerQuery $squery)
{
$this->parent = $squery;
}
/**
* Returns the primary ID of the selected virtual server.
*
* @return integer
*/
public function serverSelectedId()
{
return $this->whoamiGet("virtualserver_id", 0);
}
/**
* Returns the primary UDP port of the selected virtual server.
*
* @return integer
*/
public function serverSelectedPort()
{
return $this->whoamiGet("virtualserver_port", 0);
}
/**
* Returns the servers version information including platform and build number.
*
* @param string $ident
* @return mixed
*/
public function version($ident = null)
{
if($this->version === null)
{
$this->version = $this->request("version")->toList();
}
return ($ident && isset($this->version[$ident])) ? $this->version[$ident] : $this->version;
}
/**
* Selects a virtual server by ID to allow further interaction.
*
* @param integer $sid
* @param boolean $virtual
* @return void
*/
public function serverSelect($sid, $virtual = null)
{
if($this->whoami !== null && $this->serverSelectedId() == $sid) return;
$virtual = ($virtual !== null) ? $virtual : $this->start_offline_virtual;
$getargs = func_get_args();
$this->execute("use", array("sid" => $sid, $virtual ? "-virtual" : null));
if($sid != 0 && $this->predefined_query_name !== null)
{
$this->execute("clientupdate", array("client_nickname" => (string) $this->predefined_query_name));
}
$this->whoamiReset();
$this->setStorage("_server_use", array(__FUNCTION__, $getargs));
TeamSpeak3_Helper_Signal::getInstance()->emit("notifyServerselected", $this);
}
/**
* Alias for serverSelect().
*
* @param integer $sid
* @param boolean $virtual
* @return void
*/
public function serverSelectById($sid, $virtual = null)
{
$this->serverSelect($sid, $virtual);
}
/**
* Selects a virtual server by UDP port to allow further interaction.
*
* @param integer $port
* @param boolean $virtual
* @return void
*/
public function serverSelectByPort($port, $virtual = null)
{
if($this->whoami !== null && $this->serverSelectedPort() == $port) return;
$virtual = ($virtual !== null) ? $virtual : $this->start_offline_virtual;
$getargs = func_get_args();
$this->execute("use", array("port" => $port, $virtual ? "-virtual" : null));
if($port != 0 && $this->predefined_query_name !== null)
{
$this->execute("clientupdate", array("client_nickname" => (string) $this->predefined_query_name));
}
$this->whoamiReset();
$this->setStorage("_server_use", array(__FUNCTION__, $getargs));
TeamSpeak3_Helper_Signal::getInstance()->emit("notifyServerselected", $this);
}
/**
* Deselects the active virtual server.
*
* @return void
*/
public function serverDeselect()
{
$this->serverSelect(0);
$this->delStorage("_server_use");
}
/**
* Returns the ID of a virtual server matching the given port.
*
* @param integer $port
* @return integer
*/
public function serverIdGetByPort($port)
{
$sid = $this->execute("serveridgetbyport", array("virtualserver_port" => $port))->toList();
return $sid["server_id"];
}
/**
* Returns the port of a virtual server matching the given ID.
*
* @param integer $sid
* @return integer
*/
public function serverGetPortById($sid)
{
if(!array_key_exists((string) $sid, $this->serverList()))
{
throw new TeamSpeak3_Adapter_ServerQuery_Exception("invalid serverID", 0x400);
}
return $this->serverList[intval((string) $sid)]["virtualserver_port"];
}
/**
* Returns the TeamSpeak3_Node_Server object matching the currently selected ID.
*
* @return TeamSpeak3_Node_Server
*/
public function serverGetSelected()
{
return $this->serverGetById($this->serverSelectedId());
}
/**
* Returns the TeamSpeak3_Node_Server object matching the given ID.
*
* @param integer $sid
* @return TeamSpeak3_Node_Server
*/
public function serverGetById($sid)
{
$this->serverSelectById($sid);
return new TeamSpeak3_Node_Server($this, array("virtualserver_id" => intval($sid)));
}
/**
* Returns the TeamSpeak3_Node_Server object matching the given port number.
*
* @param integer $port
* @return TeamSpeak3_Node_Server
*/
public function serverGetByPort($port)
{
$this->serverSelectByPort($port);
return new TeamSpeak3_Node_Server($this, array("virtualserver_id" => $this->serverSelectedId()));
}
/**
* Returns the first TeamSpeak3_Node_Server object matching the given name.
*
* @param string $name
* @throws TeamSpeak3_Adapter_ServerQuery_Exception
* @return TeamSpeak3_Node_Server
*/
public function serverGetByName($name)
{
foreach($this->serverList() as $server)
{
if($server["virtualserver_name"] == $name) return $server;
}
throw new TeamSpeak3_Adapter_ServerQuery_Exception("invalid serverID", 0x400);
}
/**
* Returns the first TeamSpeak3_Node_Server object matching the given unique identifier.
*
* @param string $uid
* @throws TeamSpeak3_Adapter_ServerQuery_Exception
* @return TeamSpeak3_Node_Server
*/
public function serverGetByUid($uid)
{
foreach($this->serverList() as $server)
{
if($server["virtualserver_unique_identifier"] == $uid) return $server;
}
throw new TeamSpeak3_Adapter_ServerQuery_Exception("invalid serverID", 0x400);
}
/**
* Returns the first TeamSpeak3_Node_Server object matching the given TSDNS hostname. Like the
* TeamSpeak 3 Client, this method will start looking for a TSDNS server on the second-level
* domain including a fallback to the third-level domain of the specified $tsdns parameter.
*
* @param string $tsdns
* @throws TeamSpeak3_Adapter_ServerQuery_Exception
* @return TeamSpeak3_Node_Server
*/
public function serverGetByTSDNS($tsdns)
{
$parts = TeamSpeak3_Helper_Uri::getFQDNParts($tsdns);
$query = TeamSpeak3_Helper_String::factory(array_shift($parts));
while($part = array_shift($parts))
{
$query->prepend($part);
try
{
$port = TeamSpeak3::factory("tsdns://" . $query . "/?timeout=3")->resolve($tsdns)->section(":", 1);
return $this->serverGetByPort($port == "" ? 9987 : $port);
}
catch(TeamSpeak3_Transport_Exception $e)
{
/* skip "Connection timed out" and "Connection refused" */
if($e->getCode() != 10060 && $e->getCode() != 10061) throw $e;
}
}
throw new TeamSpeak3_Adapter_ServerQuery_Exception("invalid serverID", 0x400);
}
/**
* Creates a new virtual server using given properties and returns an assoc
* array containing the new ID and initial admin token.
*
* @param array $properties
* @return array
*/
public function serverCreate(array $properties = array())
{
$this->serverListReset();
$detail = $this->execute("servercreate", $properties)->toList();
$server = new TeamSpeak3_Node_Server($this, array("virtualserver_id" => intval($detail["sid"])));
TeamSpeak3_Helper_Signal::getInstance()->emit("notifyServercreated", $this, $detail["sid"]);
TeamSpeak3_Helper_Signal::getInstance()->emit("notifyTokencreated", $server, $detail["token"]);
return $detail;
}
/**
* Deletes the virtual server specified by ID.
*
* @param integer $sid
* @return void
*/
public function serverDelete($sid)
{
$this->serverListReset();
$this->execute("serverdelete", array("sid" => $sid));
TeamSpeak3_Helper_Signal::getInstance()->emit("notifyServerdeleted", $this, $sid);
}
/**
* Starts the virtual server specified by ID.
*
* @param integer $sid
* @return void
*/
public function serverStart($sid)
{
if($sid == $this->serverSelectedId())
{
$this->serverDeselect();
}
$this->execute("serverstart", array("sid" => $sid));
$this->serverListReset();
TeamSpeak3_Helper_Signal::getInstance()->emit("notifyServerstarted", $this, $sid);
}
/**
* Stops the virtual server specified by ID.
*
* @param integer $sid
* @return void
*/
public function serverStop($sid)
{
if($sid == $this->serverSelectedId())
{
$this->serverDeselect();
}
$this->execute("serverstop", array("sid" => $sid));
$this->serverListReset();
TeamSpeak3_Helper_Signal::getInstance()->emit("notifyServerstopped", $this, $sid);
}
/**
* Stops the entire TeamSpeak 3 Server instance by shutting down the process.
*
* @return void
*/
public function serverStopProcess()
{
TeamSpeak3_Helper_Signal::getInstance()->emit("notifyServershutdown", $this);
$this->execute("serverprocessstop");
}
/**
* Returns an array filled with TeamSpeak3_Node_Server objects.
*
* @param array $filter
* @return array
*/
public function serverList(array $filter = array())
{
if($this->serverList === null)
{
$servers = $this->request("serverlist -uid")->toAssocArray("virtualserver_id");
$this->serverList = array();
foreach($servers as $sid => $server)
{
$this->serverList[$sid] = new TeamSpeak3_Node_Server($this, $server);
}
$this->resetNodeList();
}
return $this->filterList($this->serverList, $filter);
}
/**
* Resets the list of virtual servers.
*
* @return void
*/
public function serverListReset()
{
$this->resetNodeList();
$this->serverList = null;
}
/**
* Returns a list of IP addresses used by the server instance on multi-homed machines.
*
* @return array
*/
public function bindingList($subsystem = "voice")
{
return $this->execute("bindinglist", array("subsystem" => $subsystem))->toArray();
}
/**
* Returns a list of permissions available on the server instance.
*
* @return array
*/
public function permissionList()
{
if($this->permissionList === null)
{
$this->fetchPermissionList();
}
foreach($this->permissionList as $permname => $permdata)
{
if(isset($permdata["permcatid"]) && $permdata["permgrant"])
{
continue;
}
$this->permissionList[$permname]["permcatid"] = $this->permissionGetCategoryById($permdata["permid"]);
$this->permissionList[$permname]["permgrant"] = $this->permissionGetGrantById($permdata["permid"]);
$grantsid = "i_needed_modify_power_" . substr($permname, 2);
if(!$permdata["permname"]->startsWith("i_needed_modify_power_") && !isset($this->permissionList[$grantsid]))
{
$this->permissionList[$grantsid]["permid"] = $this->permissionList[$permname]["permgrant"];
$this->permissionList[$grantsid]["permname"] = TeamSpeak3_Helper_String::factory($grantsid);
$this->permissionList[$grantsid]["permdesc"] = null;
$this->permissionList[$grantsid]["permcatid"] = 0xFF;
$this->permissionList[$grantsid]["permgrant"] = $this->permissionList[$permname]["permgrant"];
}
}
return $this->permissionList;
}
/**
* Returns a list of permission categories available on the server instance.
*
* @return array
*/
public function permissionCats()
{
if($this->permissionCats === null)
{
$this->fetchPermissionCats();
}
return $this->permissionCats;
}
/**
* Returns a list of permission category endings available on the server instance.
*
* @return array
*/
public function permissionEnds()
{
if($this->permissionEnds === null)
{
$this->fetchPermissionList();
}
return $this->permissionCats;
}
/**
* Returns an array filled with all permission categories known to the server including
* their ID, name and parent.
*
* @return array
*/
public function permissionTree()
{
$permtree = array();
foreach($this->permissionCats() as $key => $val)
{
$permtree[$val]["permcatid"] = $val;
$permtree[$val]["permcathex"] = "0x" . dechex($val);
$permtree[$val]["permcatname"] = TeamSpeak3_Helper_String::factory(TeamSpeak3_Helper_Convert::permissionCategory($val));
$permtree[$val]["permcatparent"] = $permtree[$val]["permcathex"]{3} == 0 ? 0 : hexdec($permtree[$val]["permcathex"]{2} . 0);
$permtree[$val]["permcatchilren"] = 0;
$permtree[$val]["permcatcount"] = 0;
if(isset($permtree[$permtree[$val]["permcatparent"]]))
{
$permtree[$permtree[$val]["permcatparent"]]["permcatchilren"]++;
}
if($permtree[$val]["permcatname"]->contains("/"))
{
$permtree[$val]["permcatname"] = $permtree[$val]["permcatname"]->section("/", 1)->trim();
}
foreach($this->permissionList() as $permission)
{
if($permission["permid"]["permcatid"] == $val)
{
$permtree[$val]["permcatcount"]++;
}
}
}
return $permtree;
}
/**
* Returns the IDs of all clients, channels or groups using the permission with the
* specified ID.
*
* @param integer $permid
* @return array
*/
public function permissionFind($permid)
{
if(!is_array($permid))
{
$permident = (is_numeric($permid)) ? "permid" : "permsid";
}
else
{
$permident = (is_numeric(current($permid))) ? "permid" : "permsid";
}
return $this->execute("permfind", array($permident => $permid))->toArray();
}
/**
* Returns the ID of the permission matching the given name.
*
* @param string $name
* @throws TeamSpeak3_Adapter_ServerQuery_Exception
* @return integer
*/
public function permissionGetIdByName($name)
{
if(!array_key_exists((string) $name, $this->permissionList()))
{
throw new TeamSpeak3_Adapter_ServerQuery_Exception("invalid permission ID", 0xA02);
}
return $this->permissionList[(string) $name]["permid"];
}
/**
* Returns the name of the permission matching the given ID.
*
* @param integer $permid
* @throws TeamSpeak3_Adapter_ServerQuery_Exception
* @return TeamSpeak3_Helper_String
*/
public function permissionGetNameById($permid)
{
foreach($this->permissionList() as $name => $perm)
{
if($perm["permid"] == $permid) return new TeamSpeak3_Helper_String($name);
}
throw new TeamSpeak3_Adapter_ServerQuery_Exception("invalid permission ID", 0xA02);
}
/**
* Returns the internal category of the permission matching the given ID.
*
* All pre-3.0.7 permission IDs are are 2 bytes wide. The first byte identifies the category while
* the second byte is the permission count within that group.
*
* @param integer $permid
* @return integer
*/
public function permissionGetCategoryById($permid)
{
if(!is_numeric($permid))
{
$permid = $this->permissionGetIdByName($permid);
}
if($permid < 0x1000)
{
if($this->permissionEnds === null)
{
$this->fetchPermissionList();
}
if($this->permissionCats === null)
{
$this->fetchPermissionCats();
}
$catids = array_values($this->permissionCats());
foreach($this->permissionEnds as $key => $val)
{
if($val >= $permid && isset($catids[$key]))
{
return $catids[$key];
}
}
return 0;
}
else
{
return (int) $permid >> 8;
}
}
/**
* Returns the internal ID of the i_needed_modify_power_* or grant permission.
*
* Every permission has an associated i_needed_modify_power_* permission, for example b_client_ban_create has an
* associated permission called i_needed_modify_power_client_ban_create.
*
* @param integer $permid
* @return integer
*/
public function permissionGetGrantById($permid)
{
if(!is_numeric($permid))
{
$permid = $this->permissionGetIdByName($permid);
}
if($permid < 0x1000)
{
return (int) $permid+0x8000;
}
else
{
return (int) bindec(substr(decbin($permid), -8))+0xFF00;
}
}
/**
* Adds a set of specified permissions to all regular server groups on all virtual servers. The target groups will
* be identified by the value of their i_group_auto_update_type permission specified with $sgtype.
*
* @param integer $sgtype
* @param integer $permid
* @param integer $permvalue
* @param integer $permnegated
* @param integer $permskip
* @return void
*/
public function serverGroupPermAutoAssign($sgtype, $permid, $permvalue, $permnegated = FALSE, $permskip = FALSE)
{
if(!is_array($permid))
{
$permident = (is_numeric($permid)) ? "permid" : "permsid";
}
else
{
$permident = (is_numeric(current($permid))) ? "permid" : "permsid";
}
$this->execute("servergroupautoaddperm", array("sgtype" => $sgtype, $permident => $permid, "permvalue" => $permvalue, "permnegated" => $permnegated, "permskip" => $permskip));
}
/**
* Removes a set of specified permissions from all regular server groups on all virtual servers. The target groups
* will be identified by the value of their i_group_auto_update_type permission specified with $sgtype.
*
* @param integer $sgtype
* @param integer $permid
* @return void
*/
public function serverGroupPermAutoRemove($sgtype, $permid)
{
if(!is_array($permid))
{
$permident = (is_numeric($permid)) ? "permid" : "permsid";
}
else
{
$permident = (is_numeric(current($permid))) ? "permid" : "permsid";
}
$this->execute("servergroupautodelperm", array("sgtype" => $sgtype, $permident => $permid));
}
/**
* Returns an array containing the value of a specified permission for your own client.
*
* @param integer $permid
* @return array
*/
public function selfPermCheck($permid)
{
if(!is_array($permid))
{
$permident = (is_numeric($permid)) ? "permid" : "permsid";
}
else
{
$permident = (is_numeric(current($permid))) ? "permid" : "permsid";
}
return $this->execute("permget", array($permident => $permid))->toAssocArray("permsid");
}
/**
* Changes the server instance configuration using given properties.
*
* @param array $properties
* @return void
*/
public function modify(array $properties)
{
$this->execute("instanceedit", $properties);
$this->resetNodeInfo();
}
/**
* Sends a text message to all clients on all virtual servers in the TeamSpeak 3 Server instance.
*
* @param string $msg
* @return void
*/
public function message($msg)
{
$this->execute("gm", array("msg" => $msg));
}
/**
* Displays a specified number of entries (1-100) from the servers log.
*
* @param integer $lines
* @param integer $begin_pos
* @param boolean $reverse
* @param boolean $instance
* @return array
*/
public function logView($lines = 30, $begin_pos = null, $reverse = null, $instance = TRUE)
{
return $this->execute("logview", array("lines" => $lines, "begin_pos" => $begin_pos, "instance" => $instance, "reverse" => $reverse))->toArray();
}
/**
* Writes a custom entry into the server instance log.
*
* @param string $logmsg
* @param integer $loglevel
* @return void
*/
public function logAdd($logmsg, $loglevel = TeamSpeak3::LOGLEVEL_INFO)
{
$sid = $this->serverSelectedId();
$this->serverDeselect();
$this->execute("logadd", array("logmsg" => $logmsg, "loglevel" => $loglevel));
$this->serverSelect($sid);
}
/**
* Authenticates with the TeamSpeak 3 Server instance using given ServerQuery login credentials.
*
* @param string $username
* @param string $password
* @return void
*/
public function login($username, $password)
{
$this->execute("login", array("client_login_name" => $username, "client_login_password" => $password));
$this->whoamiReset();
$crypt = new TeamSpeak3_Helper_Crypt($username);
$this->setStorage("_login_user", $username);
$this->setStorage("_login_pass", $crypt->encrypt($password));
TeamSpeak3_Helper_Signal::getInstance()->emit("notifyLogin", $this);
}
/**
* Deselects the active virtual server and logs out from the server instance.
*
* @return void
*/
public function logout()
{
$this->request("logout");
$this->whoamiReset();
$this->delStorage("_login_user");
$this->delStorage("_login_pass");
TeamSpeak3_Helper_Signal::getInstance()->emit("notifyLogout", $this);
}
/**
* Returns information about your current ServerQuery connection.
*
* @return array
*/
public function whoami()
{
if($this->whoami === null)
{
$this->whoami = $this->request("whoami")->toList();
}
return $this->whoami;
}
/**
* Returns a single value from the current ServerQuery connection info.
*
* @param string $ident
* @param mixed $default
* @return mixed
*/
public function whoamiGet($ident, $default = null)
{
if(array_key_exists($ident, $this->whoami()))
{
return $this->whoami[$ident];
}
return $default;
}
/**
* Sets a single value in the current ServerQuery connection info.
*
* @param string $ident
* @param mixed $value
* @return mixed
*/
public function whoamiSet($ident, $value = null)
{
$this->whoami();
$this->whoami[$ident] = (is_numeric($value)) ? (int) $value : TeamSpeak3_Helper_String::factory($value);
}
/**
* Resets the current ServerQuery connection info.
*
* @return void
*/
public function whoamiReset()
{
$this->whoami = null;
}
/**
* Returns the hostname or IPv4 address the adapter is connected to.
*
* @return string
*/
public function getAdapterHost()
{
return $this->getParent()->getTransportHost();
}
/**
* Returns the network port the adapter is connected to.
*
* @return string
*/
public function getAdapterPort()
{
return $this->getParent()->getTransportPort();
}
/**
* @ignore
*/
protected function fetchNodeList()
{
$servers = $this->serverList();
foreach($servers as $server)
{
$this->nodeList[] = $server;
}
}
/**
* @ignore
*/
protected function fetchNodeInfo()
{
$info1 = $this->request("hostinfo")->toList();
$info2 = $this->request("instanceinfo")->toList();
$this->nodeInfo = array_merge($this->nodeInfo, $info1, $info2);
}
/**
* @ignore
*/
protected function fetchPermissionList()
{
$reply = $this->request("permissionlist -new")->toArray();
$start = 1;
$this->permissionEnds = array();
$this->permissionList = array();
foreach($reply as $line)
{
if(array_key_exists("group_id_end", $line))
{
$this->permissionEnds[] = $line["group_id_end"];
}
else
{
$this->permissionList[$line["permname"]->toString()] = array_merge(array("permid" => $start++), $line);
}
}
}
/**
* @ignore
*/
protected function fetchPermissionCats()
{
$permcats = array();
$reflects = new ReflectionClass("TeamSpeak3");
foreach($reflects->getConstants() as $key => $val)
{
if(!TeamSpeak3_Helper_String::factory($key)->startsWith("PERM_CAT") || $val == 0xFF)
{
continue;
}
$permcats[$key] = $val;
}
$this->permissionCats = $permcats;
}
/**
* Sets a pre-defined nickname for ServerQuery clients which will be used automatically
* after selecting a virtual server.
*
* @param string $name
* @return void
*/
public function setPredefinedQueryName($name = null)
{
$this->setStorage("_query_nick", $name);
$this->predefined_query_name = $name;
}
/**
* Returns the pre-defined nickname for ServerQuery clients which will be used automatically
* after selecting a virtual server.
*
* @return string
*/
public function getPredefinedQueryName()
{
return $this->predefined_query_name;
}
/**
* Sets the option to decide whether ServerQuery clients should be excluded from node
* lists or not.
*
* @param boolean $exclude
* @return void
*/
public function setExcludeQueryClients($exclude = FALSE)
{
$this->setStorage("_query_hide", $exclude);
$this->exclude_query_clients = $exclude;
}
/**
* Returns the option to decide whether ServerQuery clients should be excluded from node
* lists or not.
*
* @return boolean
*/
public function getExcludeQueryClients()
{
return $this->exclude_query_clients;
}
/**
* Sets the option to decide whether offline servers will be started in virtual mode
* by default or not.
*
* @param boolean $virtual
* @return void
*/
public function setUseOfflineAsVirtual($virtual = FALSE)
{
$this->setStorage("_do_virtual", $virtual);
$this->start_offline_virtual = $virtual;
}
/**
* Returns the option to decide whether offline servers will be started in virtual mode
* by default or not.
*
* @return boolean
*/
public function getUseOfflineAsVirtual()
{
return $this->start_offline_virtual;
}
/**
* Sets the option to decide whether clients should be sorted before sub-channels to support
* the new TeamSpeak 3 Client display mode or not.
*
* @param boolean $first
* @return void
*/
public function setLoadClientlistFirst($first = FALSE)
{
$this->setStorage("_client_top", $first);
$this->sort_clients_channels = $first;
}
/**
* Returns the option to decide whether offline servers will be started in virtual mode
* by default or not.
*
* @return boolean
*/
public function getLoadClientlistFirst()
{
return $this->sort_clients_channels;
}
/**
* Returns the underlying TeamSpeak3_Adapter_ServerQuery object.
*
* @return TeamSpeak3_Adapter_ServerQuery
*/
public function getAdapter()
{
return $this->getParent();
}
/**
* Returns a unique identifier for the node which can be used as a HTML property.
*
* @return string
*/
public function getUniqueId()
{
return "ts3_h";
}
/**
* Returns the name of a possible icon to display the node object.
*
* @return string
*/
public function getIcon()
{
return "host";
}
/**
* Returns a symbol representing the node.
*
* @return string
*/
public function getSymbol()
{
return "+";
}
/**
* Re-authenticates with the TeamSpeak 3 Server instance using given ServerQuery login
* credentials and re-selects a previously selected virtual server.
*
* @return void
*/
public function __wakeup()
{
$username = $this->getStorage("_login_user");
$password = $this->getStorage("_login_pass");
if($username && $password)
{
$crypt = new TeamSpeak3_Helper_Crypt($username);
$this->login($username, $crypt->decrypt($password));
}
$this->predefined_query_name = $this->getStorage("_query_nick");
$this->exclude_query_clients = $this->getStorage("_query_hide", FALSE);
$this->start_offline_virtual = $this->getStorage("_do_virtual", FALSE);
$this->sort_clients_channels = $this->getStorage("_client_top", FALSE);
if($server = $this->getStorage("_server_use"))
{
$func = array_shift($server);
$args = array_shift($server);
try
{
call_user_func_array(array($this, $func), $args);
}
catch(Exception $e)
{
$class = get_class($e);
throw new $class($e->getMessage(), $e->getCode());
}
}
}
/**
* Returns a string representation of this node.
*
* @return string
*/
public function __toString()
{
return (string) $this->getAdapterHost();
}
}
<?php
/**
* @file
* TeamSpeak 3 PHP Framework
*
* $Id: Server.php 06/06/2016 22:27:13 scp@Svens-iMac $
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @package TeamSpeak3
* @version 1.1.24
* @author Sven 'ScP' Paulsen
* @copyright Copyright (c) 2010 by Planet TeamSpeak. All rights reserved.
*/
/**
* @class TeamSpeak3_Node_Server
* @brief Class describing a TeamSpeak 3 virtual server and all it's parameters.
*/
class TeamSpeak3_Node_Server extends TeamSpeak3_Node_Abstract
{
/**
* @ignore
*/
protected $channelList = null;
/**
* @ignore
*/
protected $clientList = null;
/**
* @ignore
*/
protected $sgroupList = null;
/**
* @ignore
*/
protected $cgroupList = null;
/**
* The TeamSpeak3_Node_Server constructor.
*
* @param TeamSpeak3_Node_Host $host
* @param array $info
* @param string $index
* @throws TeamSpeak3_Adapter_ServerQuery_Exception
* @return TeamSpeak3_Node_Server
*/
public function __construct(TeamSpeak3_Node_Host $host, array $info, $index = "virtualserver_id")
{
$this->parent = $host;
$this->nodeInfo = $info;
if(!array_key_exists($index, $this->nodeInfo))
{
throw new TeamSpeak3_Adapter_ServerQuery_Exception("invalid serverID", 0x400);
}
$this->nodeId = $this->nodeInfo[$index];
}
/**
* Sends a prepared command to the server and returns the result.
*
* @param string $cmd
* @param boolean $throw
* @return TeamSpeak3_Adapter_ServerQuery_Reply
*/
public function request($cmd, $throw = TRUE)
{
if($this->getId() != $this->getParent()->serverSelectedId())
{
$this->getParent()->serverSelect($this->getId());
}
return $this->getParent()->request($cmd, $throw);
}
/**
* Returns an array filled with TeamSpeak3_Node_Channel objects.
*
* @param array $filter
* @return array
*/
public function channelList(array $filter = array())
{
if($this->channelList === null)
{
$channels = $this->request("channellist -topic -flags -voice -limits -icon")->toAssocArray("cid");
$this->channelList = array();
foreach($channels as $cid => $channel)
{
$this->channelList[$cid] = new TeamSpeak3_Node_Channel($this, $channel);
}
$this->resetNodeList();
}
return $this->filterList($this->channelList, $filter);
}
/**
* Resets the list of channels online.
*
* @return void
*/
public function channelListReset()
{
$this->resetNodeList();
$this->channelList = null;
}
/**
* Creates a new channel using given properties and returns the new ID.
*
* @param array $properties
* @return integer
*/
public function channelCreate(array $properties)
{
$cid = $this->execute("channelcreate", $properties)->toList();
$this->channelListReset();
if(!isset($properties["channel_flag_permanent"]) && !isset($properties["channel_flag_semi_permanent"]))
{
$this->getParent()->whoamiSet("client_channel_id", $cid["cid"]);
}
return $cid["cid"];
}
/**
* Deletes the channel specified by $cid.
*
* @param integer $cid
* @param boolean $force
* @return void
*/
public function channelDelete($cid, $force = FALSE)
{
$this->execute("channeldelete", array("cid" => $cid, "force" => $force));
$this->channelListReset();
if(($cid instanceof TeamSpeak3_Node_Abstract ? $cid->getId() : $cid) == $this->whoamiGet("client_channel_id"))
{
$this->getParent()->whoamiReset();
}
}
/**
* Moves the channel specified by $cid to the parent channel specified with $pid.
*
* @param integer $cid
* @param integer $pid
* @param integer $order
* @return void
*/
public function channelMove($cid, $pid, $order = null)
{
$this->execute("channelmove", array("cid" => $cid, "cpid" => $pid, "order" => $order));
$this->channelListReset();
}
/**
* Returns TRUE if the given TeamSpeak3_Node_Channel object is a spacer.
*
* @param TeamSpeak3_Node_Channel $channel
* @return boolean
*/
public function channelIsSpacer(TeamSpeak3_Node_Channel $channel)
{
return (preg_match("/\[[^\]]*spacer[^\]]*\]/", $channel) && $channel["channel_flag_permanent"] && !$channel["pid"]) ? TRUE : FALSE;
}
/**
* Creates a new channel spacer and returns the new ID. The first parameter $ident is used to create a
* unique spacer name on the virtual server.
*
* @param string $ident
* @param mixed $type
* @param integer $align
* @param integer $order
* @param integer $maxclients
* @throws TeamSpeak3_Adapter_ServerQuery_Exception
* @return integer
*/
public function channelSpacerCreate($ident, $type = TeamSpeak3::SPACER_SOLIDLINE, $align = TeamSpeak3::SPACER_ALIGN_REPEAT, $order = null, $maxclients = 0)
{
$properties = array(
"channel_name_phonetic" => "channel spacer",
"channel_codec" => TeamSpeak3::CODEC_OPUS_VOICE,
"channel_codec_quality" => 0x00,
"channel_flag_permanent" => TRUE,
"channel_flag_maxclients_unlimited" => FALSE,
"channel_flag_maxfamilyclients_unlimited" => FALSE,
"channel_flag_maxfamilyclients_inherited" => FALSE,
"channel_maxclients" => $maxclients,
"channel_order" => $order,
);
switch($align)
{
case TeamSpeak3::SPACER_ALIGN_REPEAT:
$properties["channel_name"] = "[*spacer" . strval($ident) . "]";
break;
case TeamSpeak3::SPACER_ALIGN_LEFT:
$properties["channel_name"] = "[lspacer" . strval($ident) . "]";
break;
case TeamSpeak3::SPACER_ALIGN_RIGHT:
$properties["channel_name"] = "[rspacer" . strval($ident) . "]";
break;
case TeamSpeak3::SPACER_ALIGN_CENTER:
$properties["channel_name"] = "[cspacer" . strval($ident) . "]";
break;
default:
throw new TeamSpeak3_Adapter_ServerQuery_Exception("missing required parameter", 0x606);
break;
}
switch($type)
{
case (string) TeamSpeak3::SPACER_SOLIDLINE:
$properties["channel_name"] .= "___";
break;
case (string) TeamSpeak3::SPACER_DASHLINE:
$properties["channel_name"] .= "---";
break;
case (string) TeamSpeak3::SPACER_DOTLINE:
$properties["channel_name"] .= "...";
break;
case (string) TeamSpeak3::SPACER_DASHDOTLINE:
$properties["channel_name"] .= "-.-";
break;
case (string) TeamSpeak3::SPACER_DASHDOTDOTLINE:
$properties["channel_name"] .= "-..";
break;
default:
$properties["channel_name"] .= strval($type);
break;
}
return $this->channelCreate($properties);
}
/**
* Returns the possible type of a channel spacer.
*
* @param integer $cid
* @throws TeamSpeak3_Adapter_ServerQuery_Exception
* @return integer
*/
public function channelSpacerGetType($cid)
{
$channel = $this->channelGetById($cid);
if(!$this->channelIsSpacer($channel))
{
throw new TeamSpeak3_Adapter_ServerQuery_Exception("invalid channel flags", 0x307);
}
switch($channel["channel_name"]->section("]", 1))
{
case "___":
return TeamSpeak3::SPACER_SOLIDLINE;
case "---":
return TeamSpeak3::SPACER_DASHLINE;
case "...":
return TeamSpeak3::SPACER_DOTLINE;
case "-.-":
return TeamSpeak3::SPACER_DASHDOTLINE;
case "-..":
return TeamSpeak3::SPACER_DASHDOTDOTLINE;
default:
return TeamSpeak3::SPACER_CUSTOM;
}
}
/**
* Returns the possible alignment of a channel spacer.
*
* @param integer $cid
* @throws TeamSpeak3_Adapter_ServerQuery_Exception
* @return integer
*/
public function channelSpacerGetAlign($cid)
{
$channel = $this->channelGetById($cid);
if(!$this->channelIsSpacer($channel) || !preg_match("/\[(.*)spacer.*\]/", $channel, $matches) || !isset($matches[1]))
{
throw new TeamSpeak3_Adapter_ServerQuery_Exception("invalid channel flags", 0x307);
}
switch($matches[1])
{
case "*":
return TeamSpeak3::SPACER_ALIGN_REPEAT;
case "c":
return TeamSpeak3::SPACER_ALIGN_CENTER;
case "r":
return TeamSpeak3::SPACER_ALIGN_RIGHT;
default:
return TeamSpeak3::SPACER_ALIGN_LEFT;
}
}
/**
* Returns a list of permissions defined for a specific channel.
*
* @param integer $cid
* @param boolean $permsid
* @return array
*/
public function channelPermList($cid, $permsid = FALSE)
{
return $this->execute("channelpermlist", array("cid" => $cid, $permsid ? "-permsid" : null))->toAssocArray($permsid ? "permsid" : "permid");
}
/**
* Adds a set of specified permissions to a channel. Multiple permissions can be added by
* providing the two parameters of each permission.
*
* @param integer $cid
* @param integer $permid
* @param integer $permvalue
* @return void
*/
public function channelPermAssign($cid, $permid, $permvalue)
{
if(!is_array($permid))
{
$permident = (is_numeric($permid)) ? "permid" : "permsid";
}
else
{
$permident = (is_numeric(current($permid))) ? "permid" : "permsid";
}
$this->execute("channeladdperm", array("cid" => $cid, $permident => $permid, "permvalue" => $permvalue));
}
/**
* Removes a set of specified permissions from a channel. Multiple permissions can be removed at once.
*
* @param integer $cid
* @param integer $permid
* @return void
*/
public function channelPermRemove($cid, $permid)
{
if(!is_array($permid))
{
$permident = (is_numeric($permid)) ? "permid" : "permsid";
}
else
{
$permident = (is_numeric(current($permid))) ? "permid" : "permsid";
}
$this->execute("channeldelperm", array("cid" => $cid, $permident => $permid));
}
/**
* Returns a list of permissions defined for a client in a specific channel.
*
* @param integer $cid
* @param integer $cldbid
* @param boolean $permsid
* @return array
*/
public function channelClientPermList($cid, $cldbid, $permsid = FALSE)
{
return $this->execute("channelclientpermlist", array("cid" => $cid, "cldbid" => $cldbid, $permsid ? "-permsid" : null))->toAssocArray($permsid ? "permsid" : "permid");
}
/**
* Adds a set of specified permissions to a client in a specific channel. Multiple permissions can be added by
* providing the two parameters of each permission.
*
* @param integer $cid
* @param integer $cldbid
* @param integer $permid
* @param integer $permvalue
* @return void
*/
public function channelClientPermAssign($cid, $cldbid, $permid, $permvalue)
{
if(!is_array($permid))
{
$permident = (is_numeric($permid)) ? "permid" : "permsid";
}
else
{
$permident = (is_numeric(current($permid))) ? "permid" : "permsid";
}
$this->execute("channelclientaddperm", array("cid" => $cid, "cldbid" => $cldbid, $permident => $permid, "permvalue" => $permvalue));
}
/**
* Removes a set of specified permissions from a client in a specific channel. Multiple permissions can be removed at once.
*
* @param integer $cid
* @param integer $cldbid
* @param integer $permid
* @return void
*/
public function channelClientPermRemove($cid, $cldbid, $permid)
{
if(!is_array($permid))
{
$permident = (is_numeric($permid)) ? "permid" : "permsid";
}
else
{
$permident = (is_numeric(current($permid))) ? "permid" : "permsid";
}
$this->execute("channelclientdelperm", array("cid" => $cid, "cldbid" => $cldbid, $permident => $permid));
}
/**
* Returns a list of files and directories stored in the specified channels file repository.
*
* @param integer $cid
* @param string $cpw
* @param string $path
* @param boolean $recursive
* @return array
*/
public function channelFileList($cid, $cpw = "", $path = "/", $recursive = FALSE)
{
$files = $this->execute("ftgetfilelist", array("cid" => $cid, "cpw" => $cpw, "path" => $path))->toArray();
$count = count($files);
for($i = 0; $i < $count; $i++)
{
$files[$i]["sid"] = $this->getId();
$files[$i]["cid"] = $files[0]["cid"];
$files[$i]["path"] = $files[0]["path"];
$files[$i]["src"] = new TeamSpeak3_Helper_String($cid ? $files[$i]["path"] : "/");
if(!$files[$i]["src"]->endsWith("/"))
{
$files[$i]["src"]->append("/");
}
$files[$i]["src"]->append($files[$i]["name"]);
if($recursive && $files[$i]["type"] == TeamSpeak3::FILE_TYPE_DIRECTORY)
{
$files = array_merge($files, $this->channelFileList($cid, $cpw, $path . $files[$i]["name"], $recursive));
}
}
uasort($files, array(__CLASS__, "sortFileList"));
return $files;
}
/**
* Returns detailed information about the specified file stored in a channels file repository.
*
* @param integer $cid
* @param string $cpw
* @param string $name
* @return array
*/
public function channelFileInfo($cid, $cpw = "", $name = "/")
{
$info = $this->execute("ftgetfileinfo", array("cid" => $cid, "cpw" => $cpw, "name" => $name))->toArray();
return array_pop($info);
}
/**
* Renames a file in a channels file repository. If the two parameters $tcid and $tcpw are specified, the file
* will be moved into another channels file repository.
*
* @param integer $cid
* @param string $cpw
* @param string $oldname
* @param string $newname
* @param integer $tcid
* @param string $tcpw
* @return void
*/
public function channelFileRename($cid, $cpw = "", $oldname = "/", $newname = "/", $tcid = null, $tcpw = null)
{
$this->execute("ftrenamefile", array("cid" => $cid, "cpw" => $cpw, "oldname" => $oldname, "newname" => $newname, "tcid" => $tcid, "tcpw" => $tcpw));
}
/**
* Deletes one or more files stored in a channels file repository.
*
* @param integer $cid
* @param string $cpw
* @param string $name
* @return void
*/
public function channelFileDelete($cid, $cpw = "", $name = "/")
{
$this->execute("ftdeletefile", array("cid" => $cid, "cpw" => $cpw, "name" => $name));
}
/**
* Creates new directory in a channels file repository.
*
* @param integer $cid
* @param string $cpw
* @param string $dirname
* @return void
*/
public function channelDirCreate($cid, $cpw = "", $dirname = "/")
{
$this->execute("ftcreatedir", array("cid" => $cid, "cpw" => $cpw, "dirname" => $dirname));
}
/**
* Returns the level of a channel.
*
* @param integer $cid
* @return integer
*/
public function channelGetLevel($cid)
{
$channel = $this->channelGetById($cid);
$levelno = 0;
if($channel["pid"])
{
$levelno = $this->channelGetLevel($channel["pid"])+1;
}
return $levelno;
}
/**
* Returns the pathway of a channel which can be used as a clients default channel.
*
* @param integer $cid
* @return string
*/
public function channelGetPathway($cid)
{
$channel = $this->channelGetById($cid);
$pathway = $channel["channel_name"];
if($channel["pid"])
{
$pathway = $this->channelGetPathway($channel["pid"]) . "/" . $channel["channel_name"];
}
return $pathway;
}
/**
* Returns the TeamSpeak3_Node_Channel object matching the given ID.
*
* @param integer $cid
* @throws TeamSpeak3_Adapter_ServerQuery_Exception
* @return TeamSpeak3_Node_Channel
*/
public function channelGetById($cid)
{
if(!array_key_exists((string) $cid, $this->channelList()))
{
throw new TeamSpeak3_Adapter_ServerQuery_Exception("invalid channelID", 0x300);
}
return $this->channelList[intval((string) $cid)];
}
/**
* Returns the TeamSpeak3_Node_Channel object matching the given name.
*
* @param string $name
* @throws TeamSpeak3_Adapter_ServerQuery_Exception
* @return TeamSpeak3_Node_Channel
*/
public function channelGetByName($name)
{
foreach($this->channelList() as $channel)
{
if($channel["channel_name"] == $name) return $channel;
}
throw new TeamSpeak3_Adapter_ServerQuery_Exception("invalid channelID", 0x300);
}
/**
* Returns an array filled with TeamSpeak3_Node_Client objects.
*
* @param array $filter
* @return array
*/
public function clientList(array $filter = array())
{
if($this->clientList === null)
{
$clients = $this->request("clientlist -uid -away -badges -voice -info -times -groups -icon -country -ip")->toAssocArray("clid");
$this->clientList = array();
foreach($clients as $clid => $client)
{
if($this->getParent()->getExcludeQueryClients() && $client["client_type"]) continue;
$this->clientList[$clid] = new TeamSpeak3_Node_Client($this, $client);
}
uasort($this->clientList, array(__CLASS__, "sortClientList"));
$this->resetNodeList();
}
return $this->filterList($this->clientList, $filter);
}
/**
* Resets the list of clients online.
*
* @return void
*/
public function clientListReset()
{
$this->resetNodeList();
$this->clientList = null;
}
/**
* Returns a list of clients matching a given name pattern.
*
* @param string $pattern
* @return array
*/
public function clientFind($pattern)
{
return $this->execute("clientfind", array("pattern" => $pattern))->toAssocArray("clid");
}
/**
* Returns a list of client identities known by the virtual server. By default, the server spits out 25 entries
* at once.
*
* @param integer $offset
* @param integer $limit
* @return array
*/
public function clientListDb($offset = null, $limit = null)
{
return $this->execute("clientdblist -count", array("start" => $offset, "duration" => $limit))->toAssocArray("cldbid");
}
/**
* Returns the number of client identities known by the virtual server.
*
* @return integer
*/
public function clientCountDb()
{
return current($this->execute("clientdblist -count", array("duration" => 1))->toList("count"));
}
/**
* Returns a list of properties from the database for the client specified by $cldbid.
*
* @param integer $cldbid
* @return array
*/
public function clientInfoDb($cldbid)
{
return $this->execute("clientdbinfo", array("cldbid" => $cldbid))->toList();
}
/**
* Returns a list of client database IDs matching a given pattern. You can either search for a clients
* last known nickname or his unique identity by using the $uid option.
*
* @param string $pattern
* @param boolean $uid
* @return array
*/
public function clientFindDb($pattern, $uid = FALSE)
{
return array_keys($this->execute("clientdbfind", array("pattern" => $pattern, ($uid) ? "-uid" : null))->toAssocArray("cldbid"));
}
/**
* Returns the number of regular clients online.
*
* @return integer
*/
public function clientCount()
{
if($this->isOffline()) return 0;
return $this["virtualserver_clientsonline"]-$this["virtualserver_queryclientsonline"];
}
/**
* Returns the TeamSpeak3_Node_Client object matching the given ID.
*
* @param integer $clid
* @throws TeamSpeak3_Adapter_ServerQuery_Exception
* @return TeamSpeak3_Node_Client
*/
public function clientGetById($clid)
{
if(!array_key_exists((string) $clid, $this->clientList()))
{
throw new TeamSpeak3_Adapter_ServerQuery_Exception("invalid clientID", 0x200);
}
return $this->clientList[intval((string) $clid)];
}
/**
* Returns the TeamSpeak3_Node_Client object matching the given name.
*
* @param string $name
* @throws TeamSpeak3_Adapter_ServerQuery_Exception
* @return TeamSpeak3_Node_Client
*/
public function clientGetByName($name)
{
foreach($this->clientList() as $client)
{
if($client["client_nickname"] == $name) return $client;
}
throw new TeamSpeak3_Adapter_ServerQuery_Exception("invalid clientID", 0x200);
}
/**
* Returns the TeamSpeak3_Node_Client object matching the given unique identifier.
*
* @param string $uid
* @throws TeamSpeak3_Adapter_ServerQuery_Exception
* @return TeamSpeak3_Node_Client
*/
public function clientGetByUid($uid)
{
foreach($this->clientList() as $client)
{
if($client["client_unique_identifier"] == $uid) return $client;
}
throw new TeamSpeak3_Adapter_ServerQuery_Exception("invalid clientID", 0x200);
}
/**
* Returns the TeamSpeak3_Node_Client object matching the given database ID.
*
* @param integer $dbid
* @throws TeamSpeak3_Adapter_ServerQuery_Exception
* @return TeamSpeak3_Node_Client
*/
public function clientGetByDbid($dbid)
{
foreach($this->clientList() as $client)
{
if($client["client_database_id"] == $dbid) return $client;
}
throw new TeamSpeak3_Adapter_ServerQuery_Exception("invalid clientID", 0x200);
}
/**
* Returns an array containing the last known nickname and the database ID of the client matching
* the unique identifier specified with $cluid.
*
* @param string $cluid
* @return array
*/
public function clientGetNameByUid($cluid)
{
return $this->execute("clientgetnamefromuid", array("cluid" => $cluid))->toList();
}
/**
* Returns an array containing a list of active client connections using the unique identifier
* specified with $cluid.
*
* @param string $cluid
* @return array
*/
public function clientGetIdsByUid($cluid)
{
return $this->execute("clientgetids", array("cluid" => $cluid))->toAssocArray("clid");
}
/**
* Returns an array containing the last known nickname and the unique identifier of the client
* matching the database ID specified with $cldbid.
*
* @param string $cldbid
* @return array
*/
public function clientGetNameByDbid($cldbid)
{
return $this->execute("clientgetnamefromdbid", array("cldbid" => $cldbid))->toList();
}
/**
* Returns an array containing the names and IDs of all server groups the client specified with
* $cldbid is is currently residing in.
*
* @param string $cldbid
* @return array
*/
public function clientGetServerGroupsByDbid($cldbid)
{
return $this->execute("servergroupsbyclientid", array("cldbid" => $cldbid))->toAssocArray("sgid");
}
/**
* Moves a client to another channel.
*
* @param integer $clid
* @param integer $cid
* @param string $cpw
* @return void
*/
public function clientMove($clid, $cid, $cpw = null)
{
$this->clientListReset();
$this->execute("clientmove", array("clid" => $clid, "cid" => $cid, "cpw" => $cpw));
if($clid instanceof TeamSpeak3_Node_Abstract)
{
$clid = $clid->getId();
}
if($cid instanceof TeamSpeak3_Node_Abstract)
{
$cid = $cid->getId();
}
if(!is_array($clid) && $clid == $this->whoamiGet("client_id"))
{
$this->getParent()->whoamiSet("client_channel_id", $cid);
}
}
/**
* Kicks one or more clients from their currently joined channel or from the server.
*
* @param integer $clid
* @param integer $reasonid
* @param string $reasonmsg
* @return void
*/
public function clientKick($clid, $reasonid = TeamSpeak3::KICK_CHANNEL, $reasonmsg = null)
{
$this->clientListReset();
$this->execute("clientkick", array("clid" => $clid, "reasonid" => $reasonid, "reasonmsg" => $reasonmsg));
}
/**
* Sends a poke message to a client.
*
* @param integer $clid
* @param string $msg
* @return void
*/
public function clientPoke($clid, $msg)
{
$this->execute("clientpoke", array("clid" => $clid, "msg" => $msg));
}
/**
* Bans the client specified with ID $clid from the server. Please note that this will create two separate
* ban rules for the targeted clients IP address and his unique identifier.
*
* @param integer $clid
* @param integer $timeseconds
* @param string $reason
* @return array
*/
public function clientBan($clid, $timeseconds = null, $reason = null)
{
$this->clientListReset();
$bans = $this->execute("banclient", array("clid" => $clid, "time" => $timeseconds, "banreason" => $reason))->toAssocArray("banid");
return array_keys($bans);
}
/**
* Changes the clients properties using given properties.
*
* @param string $cldbid
* @param array $properties
* @return void
*/
public function clientModifyDb($cldbid, array $properties)
{
$properties["cldbid"] = $cldbid;
$this->execute("clientdbedit", $properties);
}
/**
* Deletes a clients properties from the database.
*
* @param string $cldbid
* @return void
*/
public function clientDeleteDb($cldbid)
{
$this->execute("clientdbdelete", array("cldbid" => $cldbid));
}
/**
* Sets the channel group of a client to the ID specified.
*
* @param integer $cldbid
* @param integer $cid
* @param integer $cgid
* @return void
*/
public function clientSetChannelGroup($cldbid, $cid, $cgid)
{
$this->execute("setclientchannelgroup", array("cldbid" => $cldbid, "cid" => $cid, "cgid" => $cgid));
}
/**
* Returns a list of permissions defined for a client.
*
* @param integer $cldbid
* @param boolean $permsid
* @return array
*/
public function clientPermList($cldbid, $permsid = FALSE)
{
$this->clientListReset();
return $this->execute("clientpermlist", array("cldbid" => $cldbid, $permsid ? "-permsid" : null))->toAssocArray($permsid ? "permsid" : "permid");
}
/**
* Adds a set of specified permissions to a client. Multiple permissions can be added by providing
* the three parameters of each permission.
*
* @param integer $cldbid
* @param integer $permid
* @param integer $permvalue
* @param integer $permskip
* @return void
*/
public function clientPermAssign($cldbid, $permid, $permvalue, $permskip = FALSE)
{
if(!is_array($permid))
{
$permident = (is_numeric($permid)) ? "permid" : "permsid";
}
else
{
$permident = (is_numeric(current($permid))) ? "permid" : "permsid";
}
$this->execute("clientaddperm", array("cldbid" => $cldbid, $permident => $permid, "permvalue" => $permvalue, "permskip" => $permskip));
}
/**
* Removes a set of specified permissions from a client. Multiple permissions can be removed at once.
*
* @param integer $cldbid
* @param integer $permid
* @return void
*/
public function clientPermRemove($cldbid, $permid)
{
if(!is_array($permid))
{
$permident = (is_numeric($permid)) ? "permid" : "permsid";
}
else
{
$permident = (is_numeric(current($permid))) ? "permid" : "permsid";
}
$this->execute("clientdelperm", array("cldbid" => $cldbid, $permident => $permid));
}
/**
* Returns a list of server groups available.
*
* @param filter $filter
* @return array
*/
public function serverGroupList(array $filter = array())
{
if($this->sgroupList === null)
{
$this->sgroupList = $this->request("servergrouplist")->toAssocArray("sgid");
foreach($this->sgroupList as $sgid => $group)
{
$this->sgroupList[$sgid] = new TeamSpeak3_Node_Servergroup($this, $group);
}
uasort($this->sgroupList, array(__CLASS__, "sortGroupList"));
}
return $this->filterList($this->sgroupList, $filter);
}
/**
* Resets the list of server groups.
*
* @return void
*/
public function serverGroupListReset()
{
$this->sgroupList = null;
}
/**
* Creates a new server group using the name specified with $name and returns its ID.
*
* @param string $name
* @param integer $type
* @return integer
*/
public function serverGroupCreate($name, $type = TeamSpeak3::GROUP_DBTYPE_REGULAR)
{
$this->serverGroupListReset();
$sgid = $this->execute("servergroupadd", array("name" => $name, "type" => $type))->toList();
return $sgid["sgid"];
}
/**
* Creates a copy of an existing server group specified by $ssgid and returns the new groups ID.
*
* @param integer $ssgid
* @param string $name
* @param integer $tsgid
* @param integer $type
* @return integer
*/
public function serverGroupCopy($ssgid, $name = null, $tsgid = 0, $type = TeamSpeak3::GROUP_DBTYPE_REGULAR)
{
$this->serverGroupListReset();
$sgid = $this->execute("servergroupcopy", array("ssgid" => $ssgid, "tsgid" => $tsgid, "name" => $name, "type" => $type))->toList();
if($tsgid && $name)
{
$this->serverGroupRename($tsgid, $name);
}
return count($sgid) ? $sgid["sgid"] : intval($tsgid);
}
/**
* Renames the server group specified with $sgid.
*
* @param integer $sgid
* @param string $name
* @return void
*/
public function serverGroupRename($sgid, $name)
{
$this->serverGroupListReset();
$this->execute("servergrouprename", array("sgid" => $sgid, "name" => $name));
}
/**
* Deletes the server group specified with $sgid. If $force is set to 1, the server group
* will be deleted even if there are clients within.
*
* @param integer $sgid
* @param boolean $force
* @return void
*/
public function serverGroupDelete($sgid, $force = FALSE)
{
$this->serverGroupListReset();
$this->execute("servergroupdel", array("sgid" => $sgid, "force" => $force));
}
/**
* Returns the TeamSpeak3_Node_Servergroup object matching the given ID.
*
* @param integer $sgid
* @throws TeamSpeak3_Adapter_ServerQuery_Exception
* @return TeamSpeak3_Node_Servergroup
*/
public function serverGroupGetById($sgid)
{
if(!array_key_exists((string) $sgid, $this->serverGroupList()))
{
throw new TeamSpeak3_Adapter_ServerQuery_Exception("invalid groupID", 0xA00);
}
return $this->sgroupList[intval((string) $sgid)];
}
/**
* Returns the TeamSpeak3_Node_Servergroup object matching the given name.
*
* @param string $name
* @param integer $type
* @throws TeamSpeak3_Adapter_ServerQuery_Exception
* @return TeamSpeak3_Node_Servergroup
*/
public function serverGroupGetByName($name, $type = TeamSpeak3::GROUP_DBTYPE_REGULAR)
{
foreach($this->serverGroupList() as $group)
{
if($group["name"] == $name && $group["type"] == $type) return $group;
}
throw new TeamSpeak3_Adapter_ServerQuery_Exception("invalid groupID", 0xA00);
}
/**
* Returns a list of permissions assigned to the server group specified.
*
* @param integer $sgid
* @param boolean $permsid
* @return array
*/
public function serverGroupPermList($sgid, $permsid = FALSE)
{
return $this->execute("servergrouppermlist", array("sgid" => $sgid, $permsid ? "-permsid" : null))->toAssocArray($permsid ? "permsid" : "permid");
}
/**
* Adds a set of specified permissions to the server group specified. Multiple permissions
* can be added by providing the four parameters of each permission in separate arrays.
*
* @param integer $sgid
* @param integer $permid
* @param integer $permvalue
* @param integer $permnegated
* @param integer $permskip
* @return void
*/
public function serverGroupPermAssign($sgid, $permid, $permvalue, $permnegated = FALSE, $permskip = FALSE)
{
if(!is_array($permid))
{
$permident = (is_numeric($permid)) ? "permid" : "permsid";
}
else
{
$permident = (is_numeric(current($permid))) ? "permid" : "permsid";
}
$this->execute("servergroupaddperm", array("sgid" => $sgid, $permident => $permid, "permvalue" => $permvalue, "permnegated" => $permnegated, "permskip" => $permskip));
}
/**
* Removes a set of specified permissions from the server group specified with $sgid. Multiple
* permissions can be removed at once.
*
* @param integer $sgid
* @param integer $permid
* @return void
*/
public function serverGroupPermRemove($sgid, $permid)
{
if(!is_array($permid))
{
$permident = (is_numeric($permid)) ? "permid" : "permsid";
}
else
{
$permident = (is_numeric(current($permid))) ? "permid" : "permsid";
}
$this->execute("servergroupdelperm", array("sgid" => $sgid, $permident => $permid));
}
/**
* Returns a list of clients assigned to the server group specified.
*
* @param integer $sgid
* @return array
*/
public function serverGroupClientList($sgid)
{
if($this["virtualserver_default_server_group"] == $sgid)
{
return array();
}
return $this->execute("servergroupclientlist", array("sgid" => $sgid, "-names"))->toAssocArray("cldbid");
}
/**
* Adds a client to the server group specified. Please note that a client cannot be
* added to default groups or template groups.
*
* @param integer $sgid
* @param integer $cldbid
* @return void
*/
public function serverGroupClientAdd($sgid, $cldbid)
{
$this->clientListReset();
$this->execute("servergroupaddclient", array("sgid" => $sgid, "cldbid" => $cldbid));
}
/**
* Removes a client from the server group specified.
*
* @param integer $sgid
* @param integer $cldbid
* @return void
*/
public function serverGroupClientDel($sgid, $cldbid)
{
$this->execute("servergroupdelclient", array("sgid" => $sgid, "cldbid" => $cldbid));
}
/**
* Returns an ordered array of regular server groups available based on a pre-defined
* set of rules.
*
* @return array
*/
public function serverGroupGetProfiles()
{
$profiles = array();
foreach($this->serverGroupList() as $sgid => $sgroup)
{
if($sgroup["type"] != TeamSpeak3::GROUP_DBTYPE_REGULAR) continue;
$profiles[$sgid] = array(
"b_permission_modify_power_ignore" => 0,
"i_group_needed_member_add_power" => 0,
"i_group_member_add_power" => 0,
"i_group_needed_member_remove_power" => 0,
"i_group_member_remove_power" => 0,
"i_needed_modify_power_count" => 0,
"i_needed_modify_power_total" => 0,
"i_permission_modify_power" => 0,
"i_group_needed_modify_power" => 0,
"i_group_modify_power" => 0,
"i_client_needed_modify_power" => 0,
"i_client_modify_power" => 0,
"b_virtualserver_servergroup_create" => 0,
"b_virtualserver_servergroup_delete" => 0,
"b_client_ignore_bans" => 0,
"b_client_ignore_antiflood" => 0,
"b_group_is_permanent" => 0,
"i_client_needed_ban_power" => 0,
"i_client_needed_kick_power" => 0,
"i_client_needed_move_power" => 0,
"i_client_talk_power" => 0,
"__sgid" => $sgid,
"__name" => $sgroup->toString(),
"__node" => $sgroup,
);
try
{
$perms = $this->serverGroupPermList($sgid, TRUE);
$grant = isset($perms["i_permission_modify_power"]) ? $perms["i_permission_modify_power"]["permvalue"] : null;
}
catch(TeamSpeak3_Adapter_ServerQuery_Exception $e)
{
/* ERROR_database_empty_result */
if($e->getCode() != 0x501) throw $e;
$perms = array();
$grant = null;
}
foreach($perms as $permsid => $perm)
{
if(in_array($permsid, array_keys($profiles[$sgid])))
{
$profiles[$sgid][$permsid] = $perm["permvalue"];
}
elseif(TeamSpeak3_Helper_String::factory($permsid)->startsWith("i_needed_modify_power_"))
{
if(!$grant || $perm["permvalue"] > $grant) continue;
$profiles[$sgid]["i_needed_modify_power_total"] = $profiles[$sgid]["i_needed_modify_power_total"]+$perm["permvalue"];
$profiles[$sgid]["i_needed_modify_power_count"]++;
}
}
}
array_multisort($profiles, SORT_DESC);
return $profiles;
}
/**
* Tries to identify the post powerful/weakest server group on the virtual server and returns
* the ID.
*
* @param integer $mode
* @return TeamSpeak3_Node_Servergroup
*/
public function serverGroupIdentify($mode = TeamSpeak3::GROUP_IDENTIFIY_STRONGEST)
{
$profiles = $this->serverGroupGetProfiles();
$best_guess_profile = ($mode == TeamSpeak3::GROUP_IDENTIFIY_STRONGEST) ? array_shift($profiles) : array_pop($profiles);
return $this->serverGroupGetById($best_guess_profile["__sgid"]);
}
/**
* Returns a list of channel groups available.
*
* @param array $filter
* @return array
*/
public function channelGroupList(array $filter = array())
{
if($this->cgroupList === null)
{
$this->cgroupList = $this->request("channelgrouplist")->toAssocArray("cgid");
foreach($this->cgroupList as $cgid => $group)
{
$this->cgroupList[$cgid] = new TeamSpeak3_Node_Channelgroup($this, $group);
}
uasort($this->cgroupList, array(__CLASS__, "sortGroupList"));
}
return $this->filterList($this->cgroupList, $filter);
}
/**
* Resets the list of channel groups.
*
* @return void
*/
public function channelGroupListReset()
{
$this->cgroupList = null;
}
/**
* Creates a new channel group using the name specified with $name and returns its ID.
*
* @param string $name
* @param integer $type
* @return integer
*/
public function channelGroupCreate($name, $type = TeamSpeak3::GROUP_DBTYPE_REGULAR)
{
$this->channelGroupListReset();
$cgid = $this->execute("channelgroupadd", array("name" => $name, "type" => $type))->toList();
return $cgid["cgid"];
}
/**
* Creates a copy of an existing channel group specified by $scgid and returns the new groups ID.
*
* @param integer $scgid
* @param string $name
* @param integer $tcgid
* @param integer $type
* @return integer
*/
public function channelGroupCopy($scgid, $name = null, $tcgid = 0, $type = TeamSpeak3::GROUP_DBTYPE_REGULAR)
{
$this->channelGroupListReset();
$cgid = $this->execute("channelgroupcopy", array("scgid" => $scgid, "tcgid" => $tcgid, "name" => $name, "type" => $type))->toList();
if($tcgid && $name)
{
$this->channelGroupRename($tcgid, $name);
}
return count($cgid) ? $cgid["cgid"] : intval($tcgid);
}
/**
* Renames the channel group specified with $cgid.
*
* @param integer $cgid
* @param string $name
* @return void
*/
public function channelGroupRename($cgid, $name)
{
$this->channelGroupListReset();
$this->execute("channelgrouprename", array("cgid" => $cgid, "name" => $name));
}
/**
* Deletes the channel group specified with $cgid. If $force is set to 1, the channel group
* will be deleted even if there are clients within.
*
* @param integer $sgid
* @param boolean $force
* @return void
*/
public function channelGroupDelete($cgid, $force = FALSE)
{
$this->channelGroupListReset();
$this->execute("channelgroupdel", array("cgid" => $cgid, "force" => $force));
}
/**
* Returns the TeamSpeak3_Node_Channelgroup object matching the given ID.
*
* @param integer $cgid
* @throws TeamSpeak3_Adapter_ServerQuery_Exception
* @return TeamSpeak3_Node_Channelgroup
*/
public function channelGroupGetById($cgid)
{
if(!array_key_exists((string) $cgid, $this->channelGroupList()))
{
throw new TeamSpeak3_Adapter_ServerQuery_Exception("invalid groupID", 0xA00);
}
return $this->cgroupList[intval((string) $cgid)];
}
/**
* Returns the TeamSpeak3_Node_Channelgroup object matching the given name.
*
* @param string $name
* @param integer $type
* @throws TeamSpeak3_Adapter_ServerQuery_Exception
* @return TeamSpeak3_Node_Channelgroup
*/
public function channelGroupGetByName($name, $type = TeamSpeak3::GROUP_DBTYPE_REGULAR)
{
foreach($this->channelGroupList() as $group)
{
if($group["name"] == $name && $group["type"] == $type) return $group;
}
throw new TeamSpeak3_Adapter_ServerQuery_Exception("invalid groupID", 0xA00);
}
/**
* Returns a list of permissions assigned to the channel group specified.
*
* @param integer $cgid
* @param boolean $permsid
* @return array
*/
public function channelGroupPermList($cgid, $permsid = FALSE)
{
return $this->execute("channelgrouppermlist", array("cgid" => $cgid, $permsid ? "-permsid" : null))->toAssocArray($permsid ? "permsid" : "permid");
}
/**
* Adds a set of specified permissions to the channel group specified. Multiple permissions
* can be added by providing the two parameters of each permission in separate arrays.
*
* @param integer $cgid
* @param integer $permid
* @param integer $permvalue
* @return void
*/
public function channelGroupPermAssign($cgid, $permid, $permvalue)
{
if(!is_array($permid))
{
$permident = (is_numeric($permid)) ? "permid" : "permsid";
}
else
{
$permident = (is_numeric(current($permid))) ? "permid" : "permsid";
}
$this->execute("channelgroupaddperm", array("cgid" => $cgid, $permident => $permid, "permvalue" => $permvalue));
}
/**
* Removes a set of specified permissions from the channel group specified with $cgid. Multiple
* permissions can be removed at once.
*
* @param integer $cgid
* @param integer $permid
* @return void
*/
public function channelGroupPermRemove($cgid, $permid)
{
if(!is_array($permid))
{
$permident = (is_numeric($permid)) ? "permid" : "permsid";
}
else
{
$permident = (is_numeric(current($permid))) ? "permid" : "permsid";
}
$this->execute("channelgroupdelperm", array("cgid" => $cgid, $permident => $permid));
}
/**
* Returns all the client and/or channel IDs currently assigned to channel groups. All three
* parameters are optional so you're free to choose the most suitable combination for your
* requirements.
*
* @param integer $cgid
* @param integer $cid
* @param integer $cldbid
* @return array
*/
public function channelGroupClientList($cgid = null, $cid = null, $cldbid = null)
{
if($this["virtualserver_default_channel_group"] == $cgid)
{
return array();
}
return $this->execute("channelgroupclientlist", array("cgid" => $cgid, "cid" => $cid, "cldbid" => $cldbid))->toArray();
}
/**
* Restores the default permission settings on the virtual server and returns a new initial
* administrator privilege key.
*
* @return TeamSpeak3_Helper_String
*/
public function permReset()
{
$token = $this->request("permreset")->toList();
TeamSpeak3_Helper_Signal::getInstance()->emit("notifyTokencreated", $this, $token["token"]);
return $token["token"];
}
/**
* Removes any assignment of the permission specified with $permid on the selected virtual server
* and returns the number of removed assignments on success.
*
* @param integer $permid
* @return integer
*/
public function permRemoveAny($permid)
{
$assignments = $this->permissionFind($permid);
foreach($assignments as $assignment)
{
switch($assignment["t"])
{
case TeamSpeak3::PERM_TYPE_SERVERGROUP:
$this->serverGroupPermRemove($assignment["id1"], $assignment["p"]);
break;
case TeamSpeak3::PERM_TYPE_CLIENT:
$this->clientPermRemove($assignment["id2"], $assignment["p"]);
break;
case TeamSpeak3::PERM_TYPE_CHANNEL:
$this->channelPermRemove($assignment["id2"], $assignment["p"]);
break;
case TeamSpeak3::PERM_TYPE_CHANNELGROUP:
$this->channelGroupPermRemove($assignment["id1"], $assignment["p"]);
break;
case TeamSpeak3::PERM_TYPE_CHANNELCLIENT:
$this->channelClientPermRemove($assignment["id2"], $assignment["id1"], $assignment["p"]);
break;
default:
throw new TeamSpeak3_Adapter_ServerQuery_Exception("convert error", 0x604);
}
}
return count($assignments);
}
/**
* Initializes a file transfer upload. $clientftfid is an arbitrary ID to identify the file transfer on client-side.
*
* @param integer $clientftfid
* @param integer $cid
* @param string $name
* @param integer $size
* @param string $cpw
* @param boolean $overwrite
* @param boolean $resume
* @throws TeamSpeak3_Adapter_ServerQuery_Exception
* @return array
*/
public function transferInitUpload($clientftfid, $cid, $name, $size, $cpw = "", $overwrite = FALSE, $resume = FALSE)
{
$upload = $this->execute("ftinitupload", array("clientftfid" => $clientftfid, "cid" => $cid, "name" => $name, "cpw" => $cpw, "size" => $size, "overwrite" => $overwrite, "resume" => $resume))->toList();
if(array_key_exists("status", $upload) && $upload["status"] != 0x00)
{
throw new TeamSpeak3_Adapter_ServerQuery_Exception($upload["msg"], $upload["status"]);
}
$upload["cid"] = $cid;
$upload["file"] = $name;
if(!array_key_exists("ip", $upload) || $upload["ip"]->startsWith("0.0.0.0"))
{
$upload["ip"] = $this->getParent()->getAdapterHost();
$upload["host"] = $upload["ip"];
}
else
{
$upload["ip"] = $upload["ip"]->section(",");
$upload["host"] = $upload["ip"];
}
TeamSpeak3_Helper_Signal::getInstance()->emit("filetransferUploadInit", $upload["ftkey"], $upload);
return $upload;
}
/**
* Initializes a file transfer download. $clientftfid is an arbitrary ID to identify the file transfer on client-side.
*
* @param integer $clientftfid
* @param integer $cid
* @param string $name
* @param string $cpw
* @param integer $seekpos
* @throws TeamSpeak3_Adapter_ServerQuery_Exception
* @return array
*/
public function transferInitDownload($clientftfid, $cid, $name, $cpw = "", $seekpos = 0)
{
$download = $this->execute("ftinitdownload", array("clientftfid" => $clientftfid, "cid" => $cid, "name" => $name, "cpw" => $cpw, "seekpos" => $seekpos))->toList();
if(array_key_exists("status", $download) && $download["status"] != 0x00)
{
throw new TeamSpeak3_Adapter_ServerQuery_Exception($download["msg"], $download["status"]);
}
$download["cid"] = $cid;
$download["file"] = $name;
if(!array_key_exists("ip", $download) || $download["ip"]->startsWith("0.0.0.0"))
{
$download["ip"] = $this->getParent()->getAdapterHost();
$download["host"] = $download["ip"];
}
else
{
$download["ip"] = $download["ip"]->section(",");
$download["host"] = $download["ip"];
}
TeamSpeak3_Helper_Signal::getInstance()->emit("filetransferDownloadInit", $download["ftkey"], $download);
return $download;
}
/**
* Displays a list of running file transfers on the selected virtual server. The output contains the path to
* which a file is uploaded to, the current transfer rate in bytes per second, etc.
*
* @return array
*/
public function transferList()
{
return $this->request("ftlist")->toAssocArray("serverftfid");
}
/**
* Stops the running file transfer with server-side ID $serverftfid.
*
* @param integer $serverftfid
* @param boolean $delete
* @return void
*/
public function transferStop($serverftfid, $delete = FALSE)
{
$this->execute("ftstop", array("serverftfid" => $serverftfid, "delete" => $delete));
}
/**
* Downloads and returns the servers icon file content.
*
* @return TeamSpeak3_Helper_String
*/
public function iconDownload()
{
if($this->iconIsLocal("virtualserver_icon_id") || $this["virtualserver_icon_id"] == 0) return;
$download = $this->transferInitDownload(rand(0x0000, 0xFFFF), 0, $this->iconGetName("virtualserver_icon_id"));
$transfer = TeamSpeak3::factory("filetransfer://" . (strstr($download["host"], ":") !== FALSE ? "[" . $download["host"] . "]" : $download["host"]) . ":" . $download["port"]);
return $transfer->download($download["ftkey"], $download["size"]);
}
/**
* Uploads a given icon file content to the server and returns the ID of the icon.
*
* @param string $data
* @return integer
*/
public function iconUpload($data)
{
$crc = crc32($data);
$size = strlen($data);
$upload = $this->transferInitUpload(rand(0x0000, 0xFFFF), 0, "/icon_" . $crc, $size);
$transfer = TeamSpeak3::factory("filetransfer://" . (strstr($upload["host"], ":") !== FALSE ? "[" . $upload["host"] . "]" : $upload["host"]) . ":" . $upload["port"]);
$transfer->upload($upload["ftkey"], $upload["seekpos"], $data);
return $crc;
}
/**
* Changes the virtual server configuration using given properties.
*
* @param array $properties
* @return void
*/
public function modify(array $properties)
{
$this->execute("serveredit", $properties);
$this->resetNodeInfo();
}
/**
* Sends a text message to all clients on the virtual server.
*
* @param string $msg
* @return void
*/
public function message($msg)
{
$this->execute("sendtextmessage", array("msg" => $msg, "target" => $this->getId(), "targetmode" => TeamSpeak3::TEXTMSG_SERVER));
}
/**
* Returns a list of offline messages you've received. The output contains the senders unique identifier,
* the messages subject, etc.
*
* @return array
*/
public function messageList()
{
return $this->request("messagelist")->toAssocArray("msgid");
}
/**
* Sends an offline message to the client specified by $cluid.
*
* @param string $cluid
* @param string $subject
* @param string $message
* @return void
*/
public function messageCreate($cluid, $subject, $message)
{
$this->execute("messageadd", array("cluid" => $cluid, "subject" => $subject, "message" => $message));
}
/**
* Deletes an existing offline message with ID $msgid from your inbox.
*
* @param integer $msgid
* @return void
*/
public function messageDelete($msgid)
{
$this->execute("messagedel", array("msgid" => $msgid));
}
/**
* Returns an existing offline message with ID $msgid from your inbox.
*
* @param integer $msgid
* @param boolean $flag_read
* @return array
*/
public function messageRead($msgid, $flag_read = TRUE)
{
$msg = $this->execute("messageget", array("msgid" => $msgid))->toList();
if($flag_read)
{
$this->execute("messageget", array("msgid" => $msgid, "flag" => $flag_read));
}
return $msg;
}
/**
* Creates and returns snapshot data for the selected virtual server.
*
* @param string $mode
* @return string
*/
public function snapshotCreate($mode = TeamSpeak3::SNAPSHOT_STRING)
{
$snapshot = $this->request("serversnapshotcreate")->toString(FALSE);
switch($mode)
{
case TeamSpeak3::SNAPSHOT_BASE64:
return $snapshot->toBase64();
break;
case TeamSpeak3::SNAPSHOT_HEXDEC:
return $snapshot->toHex();
break;
default:
return (string) $snapshot;
break;
}
}
/**
* Deploys snapshot data on the selected virtual server. If no virtual server is selected (ID 0),
* the data will be used to create a new virtual server from scratch.
*
* @param string $data
* @param string $mode
* @return array
*/
public function snapshotDeploy($data, $mode = TeamSpeak3::SNAPSHOT_STRING)
{
switch($mode)
{
case TeamSpeak3::SNAPSHOT_BASE64:
$data = TeamSpeak3_Helper_String::fromBase64($data);
break;
case TeamSpeak3::SNAPSHOT_HEXDEC:
$data = TeamSpeak3_Helper_String::fromHex($data);
break;
default:
$data = TeamSpeak3_Helper_String::factory($data);
break;
}
$detail = $this->request("serversnapshotdeploy " . $data)->toList();
if(array_key_exists("sid", $detail))
{
TeamSpeak3_Helper_Signal::getInstance()->emit("notifyServercreated", $this->getParent(), $detail["sid"]);
}
return $detail;
}
/**
* Registers for a specified category of events on a virtual server to receive notification
* messages. Depending on the notifications you've registered for, the server will send you
* a message on every event.
*
* @param string $event
* @param integer $id
* @return void
*/
public function notifyRegister($event, $id = 0)
{
$this->execute("servernotifyregister", array("event" => $event, "id" => $id));
}
/**
* Unregisters all events previously registered with servernotifyregister so you will no
* longer receive notification messages.
*
* @return void
*/
public function notifyUnregister()
{
$this->request("servernotifyunregister");
}
/**
* Alias for privilegeKeyList().
*
* @deprecated
*/
public function tokenList($translate = FALSE)
{
return $this->privilegeKeyList();
}
/**
* Returns a list of privilege keys (tokens) available. If $resolve is set to TRUE the values
* of token_id1 and token_id2 will be translated into the appropriate group and/or channel
* names.
*
* @param boolean $resolve
* @return array
*/
public function privilegeKeyList($resolve = FALSE)
{
$tokens = $this->request("privilegekeylist")->toAssocArray("token");
if($resolve)
{
foreach($tokens as $token => $array)
{
$func = $array["token_type"] ? "channelGroupGetById" : "serverGroupGetById";
try
{
$tokens[$token]["token_id1"] = $this->$func($array["token_id1"])->name;
}
catch(Exception $e)
{
/* ERROR_channel_invalid_id */
if($e->getCode() != 0xA00) throw $e;
}
try
{
if($array["token_type"]) $tokens[$token]["token_id2"] = $this->channelGetById($array["token_id2"])->getPathway();
}
catch(Exception $e)
{
/* ERROR_permission_invalid_group_id */
if($e->getCode() != 0x300) throw $e;
}
}
}
return $tokens;
}
/**
* Alias for privilegeKeyCreate().
*
* @deprecated
*/
public function tokenCreate($type = TeamSpeak3::TOKEN_SERVERGROUP, $id1, $id2 = 0, $description = null, $customset = null)
{
return $this->privilegeKeyCreate($type, $id1, $id2, $description, $customset);
}
/**
* Creates a new privilege key (token) and returns the key.
*
* @param integer $type
* @param integer $id1
* @param integer $id2
* @param string $description
* @param string $customset
* @return TeamSpeak3_Helper_String
*/
public function privilegeKeyCreate($type = TeamSpeak3::TOKEN_SERVERGROUP, $id1, $id2 = 0, $description = null, $customset = null)
{
$token = $this->execute("privilegekeyadd", array("tokentype" => $type, "tokenid1" => $id1, "tokenid2" => $id2, "tokendescription" => $description, "tokencustomset" => $customset))->toList();
TeamSpeak3_Helper_Signal::getInstance()->emit("notifyTokencreated", $this, $token["token"]);
return $token["token"];
}
/**
* Alias for privilegeKeyDelete().
*
* @deprecated
*/
public function tokenDelete($token)
{
$this->privilegeKeyDelete($token);
}
/**
* Deletes a token specified by key $token.
*
* @param string $token
* @return void
*/
public function privilegeKeyDelete($token)
{
$this->execute("privilegekeydelete", array("token" => $token));
}
/**
* Alias for privilegeKeyUse().
*
* @deprecated
*/
public function tokenUse($token)
{
$this->privilegeKeyUse($token);
}
/**
* Use a token key gain access to a server or channel group. Please note that the server will
* automatically delete the token after it has been used.
*
* @param string $token
* @return void
*/
public function privilegeKeyUse($token)
{
$this->execute("privilegekeyuse", array("token" => $token));
}
/**
* Returns a list of custom client properties specified by $ident.
*
* @param string $ident
* @param string $pattern
* @return array
*/
public function customSearch($ident, $pattern = "%")
{
return $this->execute("customsearch", array("ident" => $ident, "pattern" => $pattern))->toArray();
}
/**
* Returns a list of custom properties for the client specified by $cldbid.
*
* @param integer $cldbid
* @return array
*/
public function customInfo($cldbid)
{
return $this->execute("custominfo", array("cldbid" => $cldbid))->toArray();
}
/**
* Returns a list of active bans on the selected virtual server.
*
* @return array
*/
public function banList()
{
return $this->request("banlist")->toAssocArray("banid");
}
/**
* Deletes all active ban rules from the server.
*
* @return void
*/
public function banListClear()
{
$this->request("bandelall");
}
/**
* Adds a new ban rule on the selected virtual server. All parameters are optional but at least one
* of the following rules must be set: ip, name, or uid.
*
* @param array $rules
* @param integer $timeseconds
* @param string $reason
* @return integer
*/
public function banCreate(array $rules, $timeseconds = null, $reason = null)
{
$rules["time"] = $timeseconds;
$rules["banreason"] = $reason;
$banid = $this->execute("banadd", $rules)->toList();
return $banid["banid"];
}
/**
* Deletes the specified ban rule from the server.
*
* @param integer $banid
* @return void
*/
public function banDelete($banid)
{
$this->execute("bandel", array("banid" => $banid));
}
/**
* Returns a list of complaints on the selected virtual server. If $tcldbid is specified, only
* complaints about the targeted client will be shown.
*
* @param integer $tcldbid
* @return array
*/
public function complaintList($tcldbid = null)
{
return $this->execute("complainlist", array("tcldbid" => $tcldbid))->toArray();
}
/**
* Deletes all active complaints about the client with database ID $tcldbid from the server.
*
* @param integer $tcldbid
* @return void
*/
public function complaintListClear($tcldbid)
{
$this->execute("complaindelall", array("tcldbid" => $tcldbid));
}
/**
* Submits a complaint about the client with database ID $tcldbid to the server.
*
* @param integer $tcldbid
* @param string $message
* @return void
*/
public function complaintCreate($tcldbid, $message)
{
$this->execute("complainadd", array("tcldbid" => $tcldbid, "message" => $message));
}
/**
* Deletes the complaint about the client with ID $tcldbid submitted by the client with ID $fcldbid from the server.
*
* @param integer $tcldbid
* @param integer $fcldbid
* @return void
*/
public function complaintDelete($tcldbid, $fcldbid)
{
$this->execute("complaindel", array("tcldbid" => $tcldbid, "fcldbid" => $fcldbid));
}
/**
* Returns a list of temporary server passwords.
*
* @param boolean $resolve
* @return array
*/
public function tempPasswordList($resolve = FALSE)
{
$passwords = $this->request("servertemppasswordlist")->toAssocArray("pw_clear");
if($resolve)
{
foreach($passwords as $password => $array)
{
try
{
$channel = $this->channelGetById($array["tcid"]);
$passwords[$password]["tcname"] = $channel->toString();
$passwords[$password]["tcpath"] = $channel->getPathway();
}
catch(Exception $e)
{
/* ERROR_channel_invalid_id */
if($e->getCode() != 0xA00) throw $e;
}
}
}
return $passwords;
}
/**
* Sets a new temporary server password specified with $pw. The temporary password will be
* valid for the number of seconds specified with $duration. The client connecting with this
* password will automatically join the channel specified with $tcid. If tcid is set to 0,
* the client will join the default channel.
*
* @param string $pw
* @param integer $duration
* @param integer $tcid
* @param string $tcpw
* @param string $desc
* @return void
*/
public function tempPasswordCreate($pw, $duration, $tcid = 0, $tcpw = "", $desc = "")
{
$this->execute("servertemppasswordadd", array("pw" => $pw, "duration" => $duration, "tcid" => $tcid, "tcpw" => $tcpw, "desc" => $desc));
}
/**
* Deletes the temporary server password specified with $pw.
*
* @param string $pw
* @return void
*/
public function tempPasswordDelete($pw)
{
$this->execute("servertemppassworddel", array("pw" => $pw));
}
/**
* Displays a specified number of entries (1-100) from the servers log.
*
* @param integer $lines
* @param integer $begin_pos
* @param boolean $reverse
* @param boolean $instance
* @return array
*/
public function logView($lines = 30, $begin_pos = null, $reverse = null, $instance = null)
{
return $this->execute("logview", array("lines" => $lines, "begin_pos" => $begin_pos, "instance" => $instance, "reverse" => $reverse))->toArray();
}
/**
* Writes a custom entry into the virtual server log.
*
* @param string $logmsg
* @param integer $loglevel
* @return void
*/
public function logAdd($logmsg, $loglevel = TeamSpeak3::LOGLEVEL_INFO)
{
$this->execute("logadd", array("logmsg" => $logmsg, "loglevel" => $loglevel));
}
/**
* Returns detailed connection information of the virtual server.
*
* @return array
*/
public function connectionInfo()
{
return $this->request("serverrequestconnectioninfo")->toList();
}
/**
* Deletes the virtual server.
*
* @return void
*/
public function delete()
{
$this->getParent()->serverDelete($this->getId());
}
/**
* Starts the virtual server.
*
* @return void
*/
public function start()
{
$this->getParent()->serverStart($this->getId());
}
/**
* Stops the virtual server.
*
* @return void
*/
public function stop()
{
$this->getParent()->serverStop($this->getId());
}
/**
* Sends a plugin command to all clients connected to the server.
*
* @param string $plugin
* @param string $data
* @return void
*/
public function sendPluginCmd($plugin, $data)
{
$this->execute("plugincmd", array("name" => $plugin, "data" => $data, "targetmode" => TeamSpeak3::PLUGINCMD_SERVER));
}
/**
* Changes the properties of your own client connection.
*
* @param array $properties
* @return void
*/
public function selfUpdate(array $properties)
{
$this->execute("clientupdate", $properties);
foreach($properties as $ident => $value)
{
$this->whoamiSet($ident, $value);
}
}
/**
* Updates your own ServerQuery login credentials using a specified username. The password
* will be auto-generated.
*
* @param string $username
* @return TeamSpeak3_Helper_String
*/
public function selfUpdateLogin($username)
{
$password = $this->execute("clientsetserverquerylogin", array("client_login_name" => $username))->toList();
return $password["client_login_password"];
}
/**
* Returns an array containing the permission overview of your own client.
*
* @return array
*/
public function selfPermOverview()
{
return $this->execute("permoverview", array("cldbid" => $this->whoamiGet("client_database_id"), "cid" => $this->whoamiGet("client_channel_id"), "permid" => 0))->toArray();
}
/**
* @ignore
*/
protected function fetchNodeList()
{
$this->nodeList = array();
foreach($this->channelList() as $channel)
{
if($channel["pid"] == 0)
{
$this->nodeList[] = $channel;
}
}
}
/**
* @ignore
*/
protected function fetchNodeInfo()
{
$this->nodeInfo = array_merge($this->nodeInfo, $this->request("serverinfo")->toList());
}
/**
* Internal callback funtion for sorting of client objects.
*
* @param TeamSpeak3_Node_Client $a
* @param TeamSpeak3_Node_Client $b
* @return integer
*/
protected static function sortClientList(TeamSpeak3_Node_Client $a, TeamSpeak3_Node_Client $b)
{
if(get_class($a) != get_class($b))
{
return 0;
/* workaround for PHP bug #50688 */
throw new TeamSpeak3_Adapter_ServerQuery_Exception("invalid parameter", 0x602);
}
if(!$a instanceof TeamSpeak3_Node_Client)
{
return 0;
/* workaround for PHP bug #50688 */
throw new TeamSpeak3_Adapter_ServerQuery_Exception("convert error", 0x604);
}
if($a->getProperty("client_talk_power", 0) != $b->getProperty("client_talk_power", 0))
{
return ($a->getProperty("client_talk_power", 0) > $b->getProperty("client_talk_power", 0)) ? -1 : 1;
}
if($a->getProperty("client_is_talker", 0) != $b->getProperty("client_is_talker", 0))
{
return ($a->getProperty("client_is_talker", 0) > $b->getProperty("client_is_talker", 0)) ? -1 : 1;
}
return strcmp(strtolower($a["client_nickname"]), strtolower($b["client_nickname"]));
}
/**
* Internal callback funtion for sorting of group objects.
*
* @param TeamSpeak3_Node_Abstract $a
* @param TeamSpeak3_Node_Abstract $b
* @return integer
*/
protected static function sortGroupList(TeamSpeak3_Node_Abstract $a, TeamSpeak3_Node_Abstract $b)
{
if(get_class($a) != get_class($b))
{
return 0;
/* workaround for PHP bug #50688 */
throw new TeamSpeak3_Adapter_ServerQuery_Exception("invalid parameter", 0x602);
}
if(!$a instanceof TeamSpeak3_Node_Servergroup && !$a instanceof TeamSpeak3_Node_Channelgroup)
{
return 0;
/* workaround for PHP bug #50688 */
throw new TeamSpeak3_Adapter_ServerQuery_Exception("convert error", 0x604);
}
if($a->getProperty("sortid", 0) != $b->getProperty("sortid", 0) && $a->getProperty("sortid", 0) != 0 && $b->getProperty("sortid", 0) != 0)
{
return ($a->getProperty("sortid", 0) < $b->getProperty("sortid", 0)) ? -1 : 1;
}
return ($a->getId() < $b->getId()) ? -1 : 1;
}
/**
* Internal callback funtion for sorting of file list items.
*
* @param array $a
* @param array $b
* @return integer
*/
protected static function sortFileList(array $a, array $b)
{
if(!array_key_exists("src", $a) || !array_key_exists("src", $b) || !array_key_exists("type", $a) || !array_key_exists("type", $b))
{
return 0;
throw new TeamSpeak3_Adapter_ServerQuery_Exception("invalid parameter", 0x602);
}
if($a["type"] != $b["type"])
{
return ($a["type"] < $b["type"]) ? -1 : 1;
}
return strcmp(strtolower($a["src"]), strtolower($b["src"]));
}
/**
* Returns TRUE if the virtual server is online.
*
* @return boolean
*/
public function isOnline()
{
return ($this["virtualserver_status"] == "online") ? TRUE : FALSE;
}
/**
* Returns TRUE if the virtual server is offline.
*
* @return boolean
*/
public function isOffline()
{
return ($this["virtualserver_status"] == "offline") ? TRUE : FALSE;
}
/**
* Returns a unique identifier for the node which can be used as a HTML property.
*
* @return string
*/
public function getUniqueId()
{
return $this->getParent()->getUniqueId() . "_s" . $this->getId();
}
/**
* Returns the name of a possible icon to display the node object.
*
* @return string
*/
public function getIcon()
{
if($this["virtualserver_clientsonline"]-$this["virtualserver_queryclientsonline"] >= $this["virtualserver_maxclients"])
{
return "server_full";
}
elseif($this["virtualserver_flag_password"])
{
return "server_pass";
}
else
{
return "server_open";
}
}
/**
* Returns a symbol representing the node.
*
* @return string
*/
public function getSymbol()
{
return "$";
}
/**
* Returns a string representation of this node.
*
* @return string
*/
public function __toString()
{
return (string) $this["virtualserver_name"];
}
}
<?php
/**
* @file
* TeamSpeak 3 PHP Framework
*
* $Id: Servergroup.php 06/06/2016 22:27:13 scp@Svens-iMac $
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @package TeamSpeak3
* @version 1.1.24
* @author Sven 'ScP' Paulsen
* @copyright Copyright (c) 2010 by Planet TeamSpeak. All rights reserved.
*/
/**
* @class TeamSpeak3_Node_Servergroup
* @brief Class describing a TeamSpeak 3 server group and all it's parameters.
*/
class TeamSpeak3_Node_Servergroup extends TeamSpeak3_Node_Abstract
{
/**
* The TeamSpeak3_Node_Servergroup constructor.
*
* @param TeamSpeak3_Node_Server $server
* @param array $info
* @param string $index
* @throws TeamSpeak3_Node_Exception
* @return TeamSpeak3_Node_Servergroup
*/
public function __construct(TeamSpeak3_Node_Server $server, array $info, $index = "sgid")
{
$this->parent = $server;
$this->nodeInfo = $info;
if(!array_key_exists($index, $this->nodeInfo))
{
throw new TeamSpeak3_Node_Exception("invalid groupID", 0xA00);
}
$this->nodeId = $this->nodeInfo[$index];
}
/**
* Renames the server group specified.
*
* @param string $name
* @return void
*/
public function rename($name)
{
$this->getParent()->serverGroupRename($this->getId(), $name);
}
/**
* Deletes the server group. If $force is set to 1, the server group will be
* deleted even if there are clients within.
*
* @param boolean $force
* @return void
*/
public function delete($force = FALSE)
{
$this->getParent()->serverGroupDelete($this->getId(), $force);
}
/**
* Creates a copy of the server group and returns the new groups ID.
*
* @param string $name
* @param integer $tsgid
* @param integer $type
* @return integer
*/
public function copy($name = null, $tsgid = 0, $type = TeamSpeak3::GROUP_DBTYPE_REGULAR)
{
return $this->getParent()->serverGroupCopy($this->getId(), $name, $tsgid, $type);
}
/**
* Returns a list of permissions assigned to the server group.
*
* @param boolean $permsid
* @return array
*/
public function permList($permsid = FALSE)
{
return $this->getParent()->serverGroupPermList($this->getId(), $permsid);
}
/**
* Adds a set of specified permissions to the server group. Multiple permissions
* can be added by providing the four parameters of each permission in separate arrays.
*
* @param integer $permid
* @param integer $permvalue
* @param integer $permnegated
* @param integer $permskip
* @return void
*/
public function permAssign($permid, $permvalue, $permnegated = FALSE, $permskip = FALSE)
{
$this->getParent()->serverGroupPermAssign($this->getId(), $permid, $permvalue, $permnegated, $permskip);
}
/**
* Alias for permAssign().
*
* @deprecated
*/
public function permAssignByName($permname, $permvalue, $permnegated = FALSE, $permskip = FALSE)
{
$this->permAssign($permname, $permvalue, $permnegated, $permskip);
}
/**
* Removes a set of specified permissions from the server group. Multiple
* permissions can be removed at once.
*
* @param integer $permid
* @return void
*/
public function permRemove($permid)
{
$this->getParent()->serverGroupPermRemove($this->getId(), $permid);
}
/**
* Alias for permRemove().
*
* @deprecated
*/
public function permRemoveByName($permname)
{
$this->permRemove($permname);
}
/**
* Returns a list of clients assigned to the server group specified.
*
* @return array
*/
public function clientList()
{
return $this->getParent()->serverGroupClientList($this->getId());
}
/**
* Adds a client to the server group specified. Please note that a client cannot be
* added to default groups or template groups.
*
* @param integer $cldbid
* @return void
*/
public function clientAdd($cldbid)
{
$this->getParent()->serverGroupClientAdd($this->getId(), $cldbid);
}
/**
* Removes a client from the server group.
*
* @param integer $cldbid
* @return void
*/
public function clientDel($cldbid)
{
$this->getParent()->serverGroupClientDel($this->getId(), $cldbid);
}
/**
* Alias for privilegeKeyCreate().
*
* @deprecated
*/
public function tokenCreate($description = null, $customset = null)
{
return $this->privilegeKeyCreate($description, $customset);
}
/**
* Creates a new privilege key (token) for the server group and returns the key.
*
* @param string $description
* @param string $customset
* @return TeamSpeak3_Helper_String
*/
public function privilegeKeyCreate($description = null, $customset = null)
{
return $this->getParent()->privilegeKeyCreate(TeamSpeak3::TOKEN_SERVERGROUP, $this->getId(), 0, $description, $customset);
}
/**
* Sends a text message to all clients residing in the server group on the virtual server.
*
* @param string $msg
* @return void
*/
public function message($msg)
{
foreach($this as $client)
{
try
{
$this->execute("sendtextmessage", array("msg" => $msg, "target" => $client, "targetmode" => TeamSpeak3::TEXTMSG_CLIENT));
}
catch(TeamSpeak3_Adapter_ServerQuery_Exception $e)
{
/* ERROR_client_invalid_id */
if($e->getCode() != 0x0200) throw $e;
}
}
}
/**
* Downloads and returns the server groups icon file content.
*
* @return TeamSpeak3_Helper_String
*/
public function iconDownload()
{
if($this->iconIsLocal("iconid") || $this["iconid"] == 0) return;
$download = $this->getParent()->transferInitDownload(rand(0x0000, 0xFFFF), 0, $this->iconGetName("iconid"));
$transfer = TeamSpeak3::factory("filetransfer://" . (strstr($download["host"], ":") !== FALSE ? "[" . $download["host"] . "]" : $download["host"]) . ":" . $download["port"]);
return $transfer->download($download["ftkey"], $download["size"]);
}
/**
* @ignore
*/
protected function fetchNodeList()
{
$this->nodeList = array();
foreach($this->getParent()->clientList() as $client)
{
if(in_array($this->getId(), explode(",", $client["client_servergroups"])))
{
$this->nodeList[] = $client;
}
}
}
/**
* Returns a unique identifier for the node which can be used as a HTML property.
*
* @return string
*/
public function getUniqueId()
{
return $this->getParent()->getUniqueId() . "_sg" . $this->getId();
}
/**
* Returns the name of a possible icon to display the node object.
*
* @return string
*/
public function getIcon()
{
return "group_server";
}
/**
* Returns a symbol representing the node.
*
* @return string
*/
public function getSymbol()
{
return "%";
}
/**
* Returns a string representation of this node.
*
* @return string
*/
public function __toString()
{
return (string) $this["name"];
}
}
<?php
/**
* @file
* TeamSpeak 3 PHP Framework
*
* $Id: TeamSpeak3.php 06/06/2016 22:27:13 scp@Svens-iMac $
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @package TeamSpeak3
* @version 1.1.24
* @author Sven 'ScP' Paulsen
* @copyright Copyright (c) 2010 by Planet TeamSpeak. All rights reserved.
*/
/**
* @class TeamSpeak3
* @brief Factory class all for TeamSpeak 3 PHP Framework objects.
*/
class TeamSpeak3
{
/**
* TeamSpeak 3 protocol welcome message.
*/
const READY = "TS3";
/**
* TeamSpeak 3 protocol greeting message prefix.
*/
const GREET = "Welcome";
/**
* TeamSpeak 3 protocol error message prefix.
*/
const ERROR = "error";
/**
* TeamSpeak 3 protocol event message prefix.
*/
const EVENT = "notify";
/**
* TeamSpeak 3 protocol server connection handler ID prefix.
*/
const SCHID = "selected";
/**
* TeamSpeak 3 PHP Framework version.
*/
const LIB_VERSION = "1.1.24";
/*@
* TeamSpeak 3 protocol separators.
*/
const SEPARATOR_LINE = "\n"; //!< protocol line separator
const SEPARATOR_LIST = "|"; //!< protocol list separator
const SEPARATOR_CELL = " "; //!< protocol cell separator
const SEPARATOR_PAIR = "="; //!< protocol pair separator
/*@
* TeamSpeak 3 log levels.
*/
const LOGLEVEL_CRITICAL = 0x00; //!< 0: these messages stop the program
const LOGLEVEL_ERROR = 0x01; //!< 1: everything that is really bad
const LOGLEVEL_WARNING = 0x02; //!< 2: everything that might be bad
const LOGLEVEL_DEBUG = 0x03; //!< 3: output that might help find a problem
const LOGLEVEL_INFO = 0x04; //!< 4: informational output
const LOGLEVEL_DEVEL = 0x05; //!< 5: development output
/*@
* TeamSpeak 3 token types.
*/
const TOKEN_SERVERGROUP = 0x00; //!< 0: server group token (id1={groupID} id2=0)
const TOKEN_CHANNELGROUP = 0x01; //!< 1: channel group token (id1={groupID} id2={channelID})
/*@
* TeamSpeak 3 codec identifiers.
*/
const CODEC_SPEEX_NARROWBAND = 0x00; //!< 0: speex narrowband (mono, 16bit, 8kHz)
const CODEC_SPEEX_WIDEBAND = 0x01; //!< 1: speex wideband (mono, 16bit, 16kHz)
const CODEC_SPEEX_ULTRAWIDEBAND = 0x02; //!< 2: speex ultra-wideband (mono, 16bit, 32kHz)
const CODEC_CELT_MONO = 0x03; //!< 3: celt mono (mono, 16bit, 48kHz)
const CODEC_OPUS_VOICE = 0x04; //!< 3: opus voice (interactive)
const CODEC_OPUS_MUSIC = 0x05; //!< 3: opus music (interactive)
/*@
* TeamSpeak 3 codec encryption modes.
*/
const CODEC_CRYPT_INDIVIDUAL = 0x00; //!< 0: configure per channel
const CODEC_CRYPT_DISABLED = 0x01; //!< 1: globally disabled
const CODEC_CRYPT_ENABLED = 0x02; //!< 2: globally enabled
/*@
* TeamSpeak 3 kick reason types.
*/
const KICK_CHANNEL = 0x04; //!< 4: kick client from channel
const KICK_SERVER = 0x05; //!< 5: kick client from server
/*@
* TeamSpeak 3 text message target modes.
*/
const TEXTMSG_CLIENT = 0x01; //!< 1: target is a client
const TEXTMSG_CHANNEL = 0x02; //!< 2: target is a channel
const TEXTMSG_SERVER = 0x03; //!< 3: target is a virtual server
/*@
* TeamSpeak 3 plugin command target modes.
*/
const PLUGINCMD_CHANNEL = 0x01; //!< 1: send plugincmd to all clients in current channel
const PLUGINCMD_SERVER = 0x02; //!< 2: send plugincmd to all clients on server
const PLUGINCMD_CLIENT = 0x03; //!< 3: send plugincmd to all given client ids
const PLUGINCMD_CHANNEL_SUBSCRIBED = 0x04; //!< 4: send plugincmd to all subscribed clients in current channel
/*@
* TeamSpeak 3 host message modes.
*/
const HOSTMSG_NONE = 0x00; //!< 0: display no message
const HOSTMSG_LOG = 0x01; //!< 1: display message in chatlog
const HOSTMSG_MODAL = 0x02; //!< 2: display message in modal dialog
const HOSTMSG_MODALQUIT = 0x03; //!< 3: display message in modal dialog and close connection
/*@
* TeamSpeak 3 host banner modes.
*/
const HOSTBANNER_NO_ADJUST = 0x00; //!< 0: do not adjust
const HOSTBANNER_IGNORE_ASPECT = 0x01; //!< 1: adjust but ignore aspect ratio
const HOSTBANNER_KEEP_ASPECT = 0x02; //!< 2: adjust and keep aspect ratio
/*@
* TeamSpeak 3 client identification types.
*/
const CLIENT_TYPE_REGULAR = 0x00; //!< 0: regular client
const CLIENT_TYPE_SERVERQUERY = 0x01; //!< 1: query client
/*@
* TeamSpeak 3 permission group database types.
*/
const GROUP_DBTYPE_TEMPLATE = 0x00; //!< 0: template group (used for new virtual servers)
const GROUP_DBTYPE_REGULAR = 0x01; //!< 1: regular group (used for regular clients)
const GROUP_DBTYPE_SERVERQUERY = 0x02; //!< 2: global query group (used for ServerQuery clients)
/*@
* TeamSpeak 3 permission group name modes.
*/
const GROUP_NAMEMODE_HIDDEN = 0x00; //!< 0: display no name
const GROUP_NAMEMODE_BEFORE = 0x01; //!< 1: display name before client nickname
const GROUP_NAMEMODE_BEHIND = 0x02; //!< 2: display name after client nickname
/*@
* TeamSpeak 3 permission group identification types.
*/
const GROUP_IDENTIFIY_STRONGEST = 0x01; //!< 1: identify most powerful group
const GROUP_IDENTIFIY_WEAKEST = 0x02; //!< 2: identify weakest group
/*@
* TeamSpeak 3 permission types.
*/
const PERM_TYPE_SERVERGROUP = 0x00; //!< 0: server group permission
const PERM_TYPE_CLIENT = 0x01; //!< 1: client specific permission
const PERM_TYPE_CHANNEL = 0x02; //!< 2: channel specific permission
const PERM_TYPE_CHANNELGROUP = 0x03; //!< 3: channel group permission
const PERM_TYPE_CHANNELCLIENT = 0x04; //!< 4: channel-client specific permission
/*@
* TeamSpeak 3 permission categories.
*/
const PERM_CAT_GLOBAL = 0x10; //!< 00010000: global permissions
const PERM_CAT_GLOBAL_INFORMATION = 0x11; //!< 00010001: global permissions -> global information
const PERM_CAT_GLOBAL_SERVER_MGMT = 0x12; //!< 00010010: global permissions -> virtual server management
const PERM_CAT_GLOBAL_ADM_ACTIONS = 0x13; //!< 00010011: global permissions -> global administrative actions
const PERM_CAT_GLOBAL_SETTINGS = 0x14; //!< 00010100: global permissions -> global settings
const PERM_CAT_SERVER = 0x20; //!< 00100000: virtual server permissions
const PERM_CAT_SERVER_INFORMATION = 0x21; //!< 00100001: virtual server permissions -> virtual server information
const PERM_CAT_SERVER_ADM_ACTIONS = 0x22; //!< 00100010: virtual server permissions -> virtual server administrative actions
const PERM_CAT_SERVER_SETTINGS = 0x23; //!< 00100011: virtual server permissions -> virtual server settings
const PERM_CAT_CHANNEL = 0x30; //!< 00110000: channel permissions
const PERM_CAT_CHANNEL_INFORMATION = 0x31; //!< 00110001: channel permissions -> channel information
const PERM_CAT_CHANNEL_CREATE = 0x32; //!< 00110010: channel permissions -> create channels
const PERM_CAT_CHANNEL_MODIFY = 0x33; //!< 00110011: channel permissions -> edit channels
const PERM_CAT_CHANNEL_DELETE = 0x34; //!< 00110100: channel permissions -> delete channels
const PERM_CAT_CHANNEL_ACCESS = 0x35; //!< 00110101: channel permissions -> access channels
const PERM_CAT_GROUP = 0x40; //!< 01000000: group permissions
const PERM_CAT_GROUP_INFORMATION = 0x41; //!< 01000001: group permissions -> group information
const PERM_CAT_GROUP_CREATE = 0x42; //!< 01000010: group permissions -> create groups
const PERM_CAT_GROUP_MODIFY = 0x43; //!< 01000011: group permissions -> edit groups
const PERM_CAT_GROUP_DELETE = 0x44; //!< 01000100: group permissions -> delete groups
const PERM_CAT_CLIENT = 0x50; //!< 01010000: client permissions
const PERM_CAT_CLIENT_INFORMATION = 0x51; //!< 01010001: client permissions -> client information
const PERM_CAT_CLIENT_ADM_ACTIONS = 0x52; //!< 01010010: client permissions -> client administrative actions
const PERM_CAT_CLIENT_BASICS = 0x53; //!< 01010011: client permissions -> client basic communication
const PERM_CAT_CLIENT_MODIFY = 0x54; //!< 01010100: client permissions -> edit clients
const PERM_CAT_FILETRANSFER = 0x60; //!< 01100000: file transfer permissions
const PERM_CAT_NEEDED_MODIFY_POWER = 0xFF; //!< 11111111: needed permission modify power (grant) permissions
/*@
* TeamSpeak 3 file types.
*/
const FILE_TYPE_DIRECTORY = 0x00; //!< 0: file is directory
const FILE_TYPE_REGULAR = 0x01; //!< 1: file is regular
/*@
* TeamSpeak 3 server snapshot types.
*/
const SNAPSHOT_STRING = 0x00; //!< 0: default string
const SNAPSHOT_BASE64 = 0x01; //!< 1: base64 string
const SNAPSHOT_HEXDEC = 0x02; //!< 2: hexadecimal string
/*@
* TeamSpeak 3 channel spacer types.
*/
const SPACER_SOLIDLINE = 0x00; //!< 0: solid line
const SPACER_DASHLINE = 0x01; //!< 1: dash line
const SPACER_DOTLINE = 0x02; //!< 2: dot line
const SPACER_DASHDOTLINE = 0x03; //!< 3: dash dot line
const SPACER_DASHDOTDOTLINE = 0x04; //!< 4: dash dot dot line
const SPACER_CUSTOM = 0x05; //!< 5: custom format
/*@
* TeamSpeak 3 channel spacer alignments.
*/
const SPACER_ALIGN_LEFT = 0x00; //!< 0: alignment left
const SPACER_ALIGN_RIGHT = 0x01; //!< 1: alignment right
const SPACER_ALIGN_CENTER = 0x02; //!< 2: alignment center
const SPACER_ALIGN_REPEAT = 0x03; //!< 3: repeat until the whole line is filled
/*@
* TeamSpeak 3 reason identifiers.
*/
const REASON_NONE = 0x00; //!< 0: no reason
const REASON_MOVE = 0x01; //!< 1: channel switched or moved
const REASON_SUBSCRIPTION = 0x02; //!< 2: subscription added or removed
const REASON_TIMEOUT = 0x03; //!< 3: client connection timed out
const REASON_CHANNEL_KICK = 0x04; //!< 4: client kicked from channel
const REASON_SERVER_KICK = 0x05; //!< 5: client kicked from server
const REASON_SERVER_BAN = 0x06; //!< 6: client banned from server
const REASON_SERVER_STOP = 0x07; //!< 7: server stopped
const REASON_DISCONNECT = 0x08; //!< 8: client disconnected
const REASON_CHANNEL_UPDATE = 0x09; //!< 9: channel information updated
const REASON_CHANNEL_EDIT = 0x0A; //!< 10: channel information edited
const REASON_DISCONNECT_SHUTDOWN = 0x0B; //!< 11: client disconnected on server shutdown
/**
* Stores an array containing various chars which need to be escaped while communicating
* with a TeamSpeak 3 Server.
*
* @var array
*/
protected static $escape_patterns = array(
"\\" => "\\\\", // backslash
"/" => "\\/", // slash
" " => "\\s", // whitespace
"|" => "\\p", // pipe
";" => "\\;", // semicolon
"\a" => "\\a", // bell
"\b" => "\\b", // backspace
"\f" => "\\f", // formfeed
"\n" => "\\n", // newline
"\r" => "\\r", // carriage return
"\t" => "\\t", // horizontal tab
"\v" => "\\v" // vertical tab
);
/**
* Factory for TeamSpeak3_Adapter_Abstract classes. $uri must be formatted as
* "<adapter>://<user>:<pass>@<host>:<port>/<options>#<flags>". All parameters
* except adapter, host and port are optional.
*
* === Supported Options ===
* - timeout
* - blocking
* - nickname
* - no_query_clients
* - use_offline_as_virtual
* - clients_before_channels
* - server_id|server_uid|server_port|server_name|server_tsdns
* - channel_id|channel_name
* - client_id|client_uid|client_name
*
* === Supported Flags (only one per $uri) ===
* - no_query_clients
* - use_offline_as_virtual
* - clients_before_channels
*
* === URI Examples ===
* - serverquery://127.0.0.1:10011/
* - serverquery://127.0.0.1:10011/?server_port=9987&channel_id=1
* - serverquery://127.0.0.1:10011/?server_port=9987&channel_id=1#no_query_clients
* - serverquery://127.0.0.1:10011/?server_port=9987&client_name=ScP
* - filetransfer://127.0.0.1:30011/
* - blacklist
* - update
*
* @param string $uri
* @return TeamSpeak3_Adapter_Abstract
* @return TeamSpeak3_Node_Abstract
* @return TeamSpeak3_Node_Host
* @return TeamSpeak3_Node_Server
*/
public static function factory($uri)
{
self::init();
$uri = new TeamSpeak3_Helper_Uri($uri);
$adapter = self::getAdapterName($uri->getScheme());
$options = array("host" => $uri->getHost(), "port" => $uri->getPort(), "timeout" => (int) $uri->getQueryVar("timeout", 10), "blocking" => (int) $uri->getQueryVar("blocking", 1));
self::loadClass($adapter);
$object = new $adapter($options);
if($object instanceof TeamSpeak3_Adapter_ServerQuery)
{
$node = $object->getHost();
if($uri->hasUser() && $uri->hasPass())
{
$node->login($uri->getUser(), $uri->getPass());
}
if($uri->hasQueryVar("nickname"))
{
$node->setPredefinedQueryName($uri->getQueryVar("nickname"));
}
if($uri->getFragment() == "use_offline_as_virtual")
{
$node->setUseOfflineAsVirtual(TRUE);
}
elseif($uri->hasQueryVar("use_offline_as_virtual"))
{
$node->setUseOfflineAsVirtual($uri->getQueryVar("use_offline_as_virtual") ? TRUE : FALSE);
}
if($uri->getFragment() == "clients_before_channels")
{
$node->setLoadClientlistFirst(TRUE);
}
elseif($uri->hasQueryVar("clients_before_channels"))
{
$node->setLoadClientlistFirst($uri->getQueryVar("clients_before_channels") ? TRUE : FALSE);
}
if($uri->getFragment() == "no_query_clients")
{
$node->setExcludeQueryClients(TRUE);
}
elseif($uri->hasQueryVar("no_query_clients"))
{
$node->setExcludeQueryClients($uri->getQueryVar("no_query_clients") ? TRUE : FALSE);
}
if($uri->hasQueryVar("server_id"))
{
$node = $node->serverGetById($uri->getQueryVar("server_id"));
}
elseif($uri->hasQueryVar("server_uid"))
{
$node = $node->serverGetByUid($uri->getQueryVar("server_uid"));
}
elseif($uri->hasQueryVar("server_port"))
{
$node = $node->serverGetByPort($uri->getQueryVar("server_port"));
}
elseif($uri->hasQueryVar("server_name"))
{
$node = $node->serverGetByName($uri->getQueryVar("server_name"));
}
elseif($uri->hasQueryVar("server_tsdns"))
{
$node = $node->serverGetByTSDNS($uri->getQueryVar("server_tsdns"));
}
if($node instanceof TeamSpeak3_Node_Server)
{
if($uri->hasQueryVar("channel_id"))
{
$node = $node->channelGetById($uri->getQueryVar("channel_id"));
}
elseif($uri->hasQueryVar("channel_name"))
{
$node = $node->channelGetByName($uri->getQueryVar("channel_name"));
}
if($uri->hasQueryVar("client_id"))
{
$node = $node->clientGetById($uri->getQueryVar("client_id"));
}
if($uri->hasQueryVar("client_uid"))
{
$node = $node->clientGetByUid($uri->getQueryVar("client_uid"));
}
elseif($uri->hasQueryVar("client_name"))
{
$node = $node->clientGetByName($uri->getQueryVar("client_name"));
}
}
return $node;
}
return $object;
}
/**
* Loads a class from a PHP file. The filename must be formatted as "$class.php".
*
* include() is not prefixed with the @ operator because if the file is loaded and
* contains a parse error, execution will halt silently and this is difficult to debug.
*
* @param string $class
* @throws LogicException
* @return boolean
*/
protected static function loadClass($class)
{
if(class_exists($class, FALSE) || interface_exists($class, FALSE))
{
return;
}
if(preg_match("/[^a-z0-9\\/\\\\_.-]/i", $class))
{
throw new LogicException("illegal characters in classname '" . $class . "'");
}
$file = self::getFilePath($class) . ".php";
if(!file_exists($file) || !is_readable($file))
{
throw new LogicException("file '" . $file . "' does not exist or is not readable");
}
if(class_exists($class, FALSE) || interface_exists($class, FALSE))
{
throw new LogicException("class '" . $class . "' does not exist");
}
return include_once($file);
}
/**
* Generates a possible file path for $name.
*
* @param string $name
* @return string
*/
protected static function getFilePath($name)
{
$path = str_replace("_", DIRECTORY_SEPARATOR, $name);
$path = str_replace(__CLASS__, dirname(__FILE__), $path);
return $path;
}
/**
* Returns the name of an adapter class by $name.
*
* @param string $name
* @param string $namespace
* @throws TeamSpeak3_Adapter_Exception
* @return string
*/
protected static function getAdapterName($name, $namespace = "TeamSpeak3_Adapter_")
{
$path = self::getFilePath($namespace);
$scan = scandir($path);
foreach($scan as $node)
{
$file = TeamSpeak3_Helper_String::factory($node)->toLower();
if($file->startsWith($name) && $file->endsWith(".php"))
{
return $namespace . str_replace(".php", "", $node);
}
}
throw new TeamSpeak3_Adapter_Exception("adapter '" . $name . "' does not exist");
}
/**
* spl_autoload() suitable implementation for supporting class autoloading.
*
* @param string $class
* @return boolean
*/
public static function autoload($class)
{
if(substr($class, 0, strlen(__CLASS__)) != __CLASS__) return;
try
{
self::loadClass($class);
return TRUE;
}
catch(Exception $e)
{
return FALSE;
}
}
/**
* Checks for required PHP features, enables autoloading and starts a default profiler.
*
* @throws LogicException
* @return void
*/
public static function init()
{
if(version_compare(phpversion(), "5.2.1") == -1)
{
throw new LogicException("this particular software cannot be used with the installed version of PHP");
}
if(!function_exists("stream_socket_client"))
{
throw new LogicException("network functions are not available in this PHP installation");
}
if(!function_exists("spl_autoload_register"))
{
throw new LogicException("autoload functions are not available in this PHP installation");
}
if(!class_exists("TeamSpeak3_Helper_Profiler"))
{
spl_autoload_register(array(__CLASS__, "autoload"));
}
TeamSpeak3_Helper_Profiler::start();
}
/**
* Returns an assoc array containing all escape patterns available on a TeamSpeak 3
* Server.
*
* @return array
*/
public static function getEscapePatterns()
{
return self::$escape_patterns;
}
/**
* Debug helper function. This is a wrapper for var_dump() that adds the pre-format tags,
* cleans up newlines and indents, and runs htmlentities() before output.
*
* @param mixed $var
* @param bool $echo
* @return string
*/
public static function dump($var, $echo = TRUE)
{
ob_start();
var_dump($var);
$output = preg_replace("/\]\=\>\n(\s+)/m", "] => ", ob_get_clean());
if(PHP_SAPI == "cli")
{
$output = PHP_EOL . PHP_EOL . $output . PHP_EOL;
}
else
{
$output = "<pre>" . htmlspecialchars($output, ENT_QUOTES, "utf-8") . "</pre>";
}
if($echo) echo($output);
return $output;
}
}
/*!
* \mainpage API Documentation
*
* \section welcome_sec Introduction
*
* \subsection welcome1 What is the TS3 PHP Framework?
* Initially released in January 2010, the TS3 PHP Framework is a powerful, open source, object-oriented framework
* implemented in PHP 5 and licensed under the GNU General Public License. It's based on simplicity and a rigorously
* tested agile codebase. Extend the functionality of your servers with scripts or create powerful web applications
* to manage all features of your TeamSpeak 3 Server instances.
*
* Tested. Thoroughly. Enterprise-ready and built with agile methods, the TS3 PHP Framework has been unit-tested from
* the start to ensure that all code remains stable and easy for you to extend, re-test with your extensions, and
* further maintain.
*
* \subsection welcome2 Why should I use the TS3 PHP Framework rather than other PHP libraries?
* The TS3 PHP Framework is a is a modern use-at-will framework that provides individual components to communicate
* with the TeamSpeak 3 Server.
*
* There are lots of arguments for the TS3 PHP Framework in comparison with other PHP based libraries. It is the most
* dynamic and feature-rich piece of software in its class. In addition, it's always up-to-date and 100% compatible to
* almost any TeamSpeak 3 Server version available.
*
* \section sysreqs_sec Requirements
* The TS3 PHP Framework currently supports PHP 5.2.1 or later, but we strongly recommend the most current release of
* PHP for critical security and performance enhancements. If you want to create a web application using the TS3 PHP
* Framework, you need a PHP 5 interpreter with a web server configured to handle PHP scripts correctly.
*
* Note that the majority of TS3 PHP Framework development and deployment is done on nginx, so there is more community
* experience and testing performed on nginx than on other web servers.
*
* \section feature_sec Features
* Features of the TS3 PHP Framework include:
*
* - Fully object-oriented PHP 5 and E_STRICT compliant components
* - Access to all TeamSpeak 3 Server features via ServerQuery
* - Integrated full featured and customizable TSViewer interfaces
* - Full support for file transfers to up- and /or download custom icons and other stuff
* - Powerful error handling capablities using exceptions and customizable error messages
* - Query mechanisms for several official services such as the blacklist and auto-update servers
* - Dynamic signal slots for event based scripting
* - ...
*
* \section example_sec Usage Examples
*
* \subsection example1 1. Kick a single Client from a Virtual Server
* @code
* // load framework files
* require_once("libraries/TeamSpeak3/TeamSpeak3.php");
*
* // connect to local server, authenticate and spawn an object for the virtual server on port 9987
* $ts3_VirtualServer = TeamSpeak3::factory("serverquery://username:password@127.0.0.1:10011/?server_port=9987");
*
* // kick the client with ID 123 from the server
* $ts3_VirtualServer->clientKick(123, TeamSpeak3::KICK_SERVER, "evil kick XD");
*
* // spawn an object for the client by unique identifier and do the kick
* $ts3_VirtualServer->clientGetByUid("FPMPSC6MXqXq751dX7BKV0JniSo=")->kick(TeamSpeak3::KICK_SERVER, "evil kick XD");
*
* // spawn an object for the client by current nickname and do the kick
* $ts3_VirtualServer->clientGetByName("ScP")->kick(TeamSpeak3::KICK_SERVER, "evil kick XD");
* @endcode
*
* \subsection example2 2. Kick all Clients from a Virtual Server
* @code
* // load framework files
* require_once("libraries/TeamSpeak3/TeamSpeak3.php");
*
* // connect to local server, authenticate and spawn an object for the virtual server on port 9987
* $ts3_VirtualServer = TeamSpeak3::factory("serverquery://username:password@127.0.0.1:10011/?server_port=9987");
*
* // query clientlist from virtual server
* $arr_ClientList = $ts3_VirtualServer->clientList();
*
* // kick all clients online with a single command
* $ts3_VirtualServer->clientKick($arr_ClientList, TeamSpeak3::KICK_SERVER, "evil kick XD");
* @endcode
*
* \subsection example3 3. Print the Nicknames of connected Android Clients
* @code
* // load framework files
* require_once("libraries/TeamSpeak3/TeamSpeak3.php");
*
* // connect to local server, authenticate and spawn an object for the virtual server on port 9987
* $ts3_VirtualServer = TeamSpeak3::factory("serverquery://username:password@127.0.0.1:10011/?server_port=9987");
*
* // query clientlist from virtual server and filter by platform
* $arr_ClientList = $ts3_VirtualServer->clientList(array("client_platform" => "Android"));
*
* // walk through list of clients
* foreach($arr_ClientList as $ts3_Client)
* {
* echo $ts3_Client . " is using " . $ts3_Client["client_platform"] . "<br />\n";
* }
* @endcode
*
* \subsection example4 4. Modify the Settings of each Virtual Server
* @code
* // load framework files
* require_once("libraries/TeamSpeak3/TeamSpeak3.php");
*
* // connect to local server, authenticate and spawn an object for the server instance
* $ts3_ServerInstance = TeamSpeak3::factory("serverquery://username:password@127.0.0.1:10011/");
*
* // walk through list of virtual servers
* foreach($ts3_ServerInstance as $ts3_VirtualServer)
* {
* // modify the virtual servers hostbanner URL only using the ArrayAccess interface
* $ts3_VirtualServer["virtualserver_hostbanner_gfx_url"] = "http://www.example.com/banners/banner01_468x60.jpg";
*
* // modify the virtual servers hostbanner URL only using property overloading
* $ts3_VirtualServer->virtualserver_hostbanner_gfx_url = "http://www.example.com/banners/banner01_468x60.jpg";
*
* // modify multiple virtual server properties at once
* $ts3_VirtualServer->modify(array(
* "virtualserver_hostbutton_tooltip" => "My Company",
* "virtualserver_hostbutton_url" => "http://www.example.com",
* "virtualserver_hostbutton_gfx_url" => "http://www.example.com/buttons/button01_24x24.jpg",
* ));
* }
* @endcode
*
* \subsection example5 5. Create a Privilege Key for a Server Group
* @code
* // load framework files
* require_once("libraries/TeamSpeak3/TeamSpeak3.php");
*
* // connect to local server, authenticate and spawn an object for the virtual server on port 9987
* $ts3_VirtualServer = TeamSpeak3::factory("serverquery://username:password@127.0.0.1:10011/?server_port=9987");
*
* // spawn an object for the group using a specified name
* $arr_ServerGroup = $ts3_VirtualServer->serverGroupGetByName("Admins");
*
* // create the privilege key
* $ts3_PrivilegeKey = $arr_ServerGroup->privilegeKeyCreate();
* @endcode
*
* \subsection example6 6. Modify the Permissions of Admins on each Virtual Server
* @code
* // load framework files
* require_once("libraries/TeamSpeak3/TeamSpeak3.php");
*
* // connect to local server, authenticate and spawn an object for the server instance
* $ts3_ServerInstance = TeamSpeak3::factory("serverquery://username:password@127.0.0.1:10011/");
*
* // walk through list of virtual servers
* foreach($ts3_ServerInstance as $ts3_VirtualServer)
* {
* // identify the most powerful group on the virtual server
* $ts3_ServerGroup = $ts3_VirtualServer->serverGroupIdentify();
*
* // assign a new permission
* $ts3_ServerGroup->permAssign("b_virtualserver_modify_hostbanner", TRUE);
*
* // revoke an existing permission
* $ts3_ServerGroup->permRemove("b_virtualserver_modify_maxclients");
* }
* @endcode
*
* \subsection example7 7. Create a new Virtual Server
* @code
* // load framework files
* require_once("libraries/TeamSpeak3/TeamSpeak3.php");
*
* // connect to local server, authenticate and spawn an object for the server instance
* $ts3_ServerInstance = TeamSpeak3::factory("serverquery://username:password@127.0.0.1:10011/");
*
* // create a virtual server and get its ID
* $new_sid = $ts3_ServerInstance->serverCreate(array(
* "virtualserver_name" => "My TeamSpeak 3 Server",
* "virtualserver_maxclients" => 64,
* "virtualserver_hostbutton_tooltip" => "My Company",
* "virtualserver_hostbutton_url" => "http://www.example.com",
* "virtualserver_hostbutton_gfx_url" => "http://www.example.com/buttons/button01_24x24.jpg",
* ));
* @endcode
*
* \subsection example8 8. Create a hierarchical Channel Stucture
* @code
* // load framework files
* require_once("libraries/TeamSpeak3/TeamSpeak3.php");
*
* // connect to local server, authenticate and spawn an object for the virtual server on port 9987
* $ts3_VirtualServer = TeamSpeak3::factory("serverquery://username:password@127.0.0.1:10011/?server_port=9987");
*
* // create a top-level channel and get its ID
* $top_cid = $ts3_VirtualServer->channelCreate(array(
* "channel_name" => "My Channel",
* "channel_topic" => "This is a top-level channel",
* "channel_codec" => TeamSpeak3::CODEC_SPEEX_WIDEBAND,
* "channel_flag_permanent" => TRUE,
* ));
*
* // create a sub-level channel and get its ID
* $sub_cid = $ts3_VirtualServer->channelCreate(array(
* "channel_name" => "My Sub-Channel",
* "channel_topic" => "This is a sub-level channel",
* "channel_codec" => TeamSpeak3::CODEC_SPEEX_NARROWBAND,
* "channel_flag_permanent" => TRUE,
* "cpid" => $top_cid,
* ));
* @endcode
*
* \subsection example9 9. Send a Text Message to outdated Clients
* @code
* // load framework files
* require_once("libraries/TeamSpeak3/TeamSpeak3.php");
*
* // connect to local server, authenticate and spawn an object for the virtual server on port 9987
* $ts3_VirtualServer = TeamSpeak3::factory("serverquery://username:password@127.0.0.1:10011/?server_port=9987");
*
* // connect to default update server
* $ts3_UpdateServer = TeamSpeak3::factory("update");
*
* // walk through list of clients on virtual server
* foreach($ts3_VirtualServer->clientList() as $ts3_Client)
* {
* // skip query clients
* if($ts3_Client["client_type"]) continue;
*
* // send test message if client build is outdated
* if($ts3_Client->getRev() < $ts3_UpdateServer->getClientRev())
* {
* $ts3_Client->message("[COLOR=red]your client is [B]outdated[/B]... update to [U]" . $ts3_UpdateServer->getClientVersion() . "[/U] now![/COLOR]");
* }
* }
* @endcode
*
* \subsection example10 10. Check if the Server Instance is Outdated or Blacklisted
* @code
* // load framework files
* require_once("libraries/TeamSpeak3/TeamSpeak3.php");
*
* // connect to local server, authenticate and spawn an object for the server instance
* $ts3_ServerInstance = TeamSpeak3::factory("serverquery://username:password@127.0.0.1:10011/");
*
* // connect to default update server
* $ts3_UpdateServer = TeamSpeak3::factory("update");
*
* // send global text message if the server is outdated
* if($ts3_ServerInstance->version("build") < $ts3_UpdateServer->getServerRev())
* {
* $ts3_ServerInstance->message("[COLOR=red]your server is [B]outdated[/B]... update to [U]" . $ts3_UpdateServer->getServerVersion() . "[/U] now![/COLOR]");
* }
*
* // connect to default blacklist server
* $ts3_BlacklistServer = TeamSpeak3::factory("blacklist");
*
* // send global text message if the server is blacklisted
* if($ts3_BlacklistServer->isBlacklisted($ts3_ServerInstance))
* {
* $ts3_ServerInstance->message("[COLOR=red]your server is [B]blacklisted[/B]... disconnect now![/COLOR]");
* }
* @endcode
*
* \subsection example11 11. Create a simple TSViewer for your Website
* @code
* // load framework files
* require_once("libraries/TeamSpeak3/TeamSpeak3.php");
*
* // connect to local server, authenticate and spawn an object for the virtual server on port 9987
* $ts3_VirtualServer = TeamSpeak3::factory("serverquery://username:password@127.0.0.1:10011/?server_port=9987");
*
* // build and display HTML treeview using custom image paths (remote icons will be embedded using data URI sheme)
* echo $ts3_VirtualServer->getViewer(new TeamSpeak3_Viewer_Html("images/viewericons/", "images/countryflags/", "data:image"));
* @endcode
*
* \subsection example12 12. Update all outdated Audio Codecs to their Opus equivalent
* @code
* // load framework files
* require_once("libraries/TeamSpeak3/TeamSpeak3.php");
*
* // connect to local server, authenticate and spawn an object for the virtual server on port 9987
* $ts3_VirtualServer = TeamSpeak3::factory("serverquery://username:password@127.0.0.1:10011/?server_port=9987");
*
* // walk through list of chanels
* foreach($ts3_VirtualServer->channelList() as $ts3_Channel)
* {
* if($ts3_Channel["channel_codec"] == TeamSpeak3::CODEC_CELT_MONO)
* {
* $ts3_Channel["channel_codec"] = TeamSpeak3::CODEC_OPUS_MUSIC;
* }
* elseif($ts3_Channel["channel_codec"] != TeamSpeak3::CODEC_OPUS_MUSIC)
* {
* $ts3_Channel["channel_codec"] = TeamSpeak3::CODEC_OPUS_VOICE;
* }
* }
* @endcode
*
* \subsection example13 13. Display the Avatar of a connected User
* @code
* // load framework files
* require_once("libraries/TeamSpeak3/TeamSpeak3.php");
*
* // connect to local server, authenticate and spawn an object for the virtual server on port 9987
* $ts3_VirtualServer = TeamSpeak3::factory("serverquery://username:password@127.0.0.1:10011/?server_port=9987");
*
* // spawn an object for the client using a specified nickname
* $ts3_Client = $ts3_VirtualServer->clientGetByName("John Doe");
*
* // download the clients avatar file
* $avatar = $ts3_Client->avatarDownload();
*
* // send header and display image
* header("Content-Type: " . TeamSpeak3_Helper_Convert::imageMimeType($avatar));
* echo $avatar;
* @endcode
*
* \subsection example14 14. Create a Simple Bot waiting for Events
* @code
* // load framework files
* require_once("libraries/TeamSpeak3/TeamSpeak3.php");
*
* // connect to local server in non-blocking mode, authenticate and spawn an object for the virtual server on port 9987
* $ts3_VirtualServer = TeamSpeak3::factory("serverquery://username:password@127.0.0.1:10011/?server_port=9987&blocking=0");
*
* // get notified on incoming private messages
* $ts3_VirtualServer->notifyRegister("textprivate");
*
* // register a callback for notifyTextmessage events
* TeamSpeak3_Helper_Signal::getInstance()->subscribe("notifyTextmessage", "onTextmessage");
*
* // wait for events
* while(1) $ts3_VirtualServer->getAdapter()->wait();
*
* // define a callback function
* function onTextmessage(TeamSpeak3_Adapter_ServerQuery_Event $event, TeamSpeak3_Node_Host $host)
* {
* echo "Client " . $event["invokername"] . " sent textmessage: " . $event["msg"];
* }
* @endcode
*
* \subsection example15 15. Handle Errors using Exceptions and Custom Error Messages
* @code
* // load framework files
* require_once("libraries/TeamSpeak3/TeamSpeak3.php");
*
* // register custom error message (supported placeholders are: %file, %line, %code and %mesg)
* TeamSpeak3_Exception::registerCustomMessage(0x300, "The specified channel does not exist; server said: %mesg");
*
* try
* {
* // connect to local server, authenticate and spawn an object for the virtual server on port 9987
* $ts3_VirtualServer = TeamSpeak3::factory("serverquery://username:password@127.0.0.1:10011/?server_port=9987");
*
* // spawn an object for the channel using a specified name
* $ts3_Channel = $ts3_VirtualServer->channelGetByName("I do not exist");
* }
* catch(TeamSpeak3_Exception $e)
* {
* // print the error message returned by the server
* echo "Error " . $e->getCode() . ": " . $e->getMessage();
* }
* @endcode
*
* \subsection example16 16. Save Connection State in Persistent Session Variable
* @code
* // load framework files
* require_once("libraries/TeamSpeak3/TeamSpeak3.php");
*
* // start a PHP session
* session_start();
*
* // connect to local server, authenticate and spawn an object for the virtual server on port 9987
* $ts3_VirtualServer = TeamSpeak3::factory("serverquery://username:password@127.0.0.1:10011/?server_port=9987");
*
* // save connection state (including login and selected virtual server)
* $_SESSION["_TS3"] = serialize($ts3_VirtualServer);
* @endcode
*
* \subsection example17 17. Restore Connection State from Persistent Session Variable
* @code
* // load framework files
* require_once("libraries/TeamSpeak3/TeamSpeak3.php");
*
* // start a PHP session
* session_start();
*
* // restore connection state
* $ts3_VirtualServer = unserialize($_SESSION["_TS3"]);
*
* // send a text message to the server
* $ts3_VirtualServer->message("Hello World!");
* @endcode
*
* Speed up new development and reduce maintenance costs by using the TS3 PHP Framework!
*/
<?php
/**
* @file
* TeamSpeak 3 PHP Framework
*
* $Id: Abstract.php 06/06/2016 22:27:13 scp@Svens-iMac $
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @package TeamSpeak3
* @version 1.1.24
* @author Sven 'ScP' Paulsen
* @copyright Copyright (c) 2010 by Planet TeamSpeak. All rights reserved.
*/
/**
* @class TeamSpeak3_Transport_Abstract
* @brief Abstract class for connecting to a TeamSpeak 3 Server through different ways of transport.
*/
abstract class TeamSpeak3_Transport_Abstract
{
/**
* Stores user-provided configuration settings.
*
* @var array
*/
protected $config = null;
/**
* Stores the stream resource of the connection.
*
* @var resource
*/
protected $stream = null;
/**
* Stores the TeamSpeak3_Adapter_Abstract object using this transport.
*
* @var TeamSpeak3_Adapter_Abstract
*/
protected $adapter = null;
/**
* The TeamSpeak3_Transport_Abstract constructor.
*
* @param array $config
* @throws TeamSpeak3_Transport_Exception
* @return TeamSpeak3_Transport_Abstract
*/
public function __construct(array $config)
{
if(!array_key_exists("host", $config))
{
throw new TeamSpeak3_Transport_Exception("config must have a key for 'host' which specifies the server host name");
}
if(!array_key_exists("port", $config))
{
throw new TeamSpeak3_Transport_Exception("config must have a key for 'port' which specifies the server port number");
}
if(!array_key_exists("timeout", $config))
{
$config["timeout"] = 10;
}
if(!array_key_exists("blocking", $config))
{
$config["blocking"] = 1;
}
$this->config = $config;
}
/**
* Commit pending data.
*
* @return array
*/
public function __sleep()
{
return array("config");
}
/**
* Reconnects to the remote server.
*
* @return void
*/
public function __wakeup()
{
$this->connect();
}
/**
* The TeamSpeak3_Transport_Abstract destructor.
*
* @return void
*/
public function __destruct()
{
if($this->adapter instanceof TeamSpeak3_Adapter_Abstract)
{
$this->adapter->__destruct();
}
$this->disconnect();
}
/**
* Connects to a remote server.
*
* @throws TeamSpeak3_Transport_Exception
* @return void
*/
abstract public function connect();
/**
* Disconnects from a remote server.
*
* @return void
*/
abstract public function disconnect();
/**
* Reads data from the stream.
*
* @param integer $length
* @throws TeamSpeak3_Transport_Exception
* @return TeamSpeak3_Helper_String
*/
abstract public function read($length = 4096);
/**
* Writes data to the stream.
*
* @param string $data
* @return void
*/
abstract public function send($data);
/**
* Returns the underlying stream resource.
*
* @return resource
*/
public function getStream()
{
return $this->stream;
}
/**
* Returns the configuration variables in this adapter.
*
* @param string $key
* @param mixed $default
* @return array
*/
public function getConfig($key = null, $default = null)
{
if($key !== null)
{
return array_key_exists($key, $this->config) ? $this->config[$key] : $default;
}
return $this->config;
}
/**
* Sets the TeamSpeak3_Adapter_Abstract object using this transport.
*
* @param TeamSpeak3_Adapter_Abstract $adapter
* @return void
*/
public function setAdapter(TeamSpeak3_Adapter_Abstract $adapter)
{
$this->adapter = get_class($adapter);
}
/**
* Returns the TeamSpeak3_Adapter_Abstract object using this transport.
*
* @return TeamSpeak3_Adapter_Abstract
*/
public function getAdapter()
{
return $this->adapter;
}
/**
* Returns the adapter type.
*
* @return string
*/
public function getAdapterType()
{
if($this->adapter instanceof TeamSpeak3_Adapter_Abstract)
{
$string = TeamSpeak3_Helper_String::factory($this->adapter);
return $string->substr($string->findLast("_"))->replace(array("_", " "), "")->toString();
}
return "Unknown";
}
/**
* Returns header/meta data from stream pointer.
*
* @throws TeamSpeak3_Transport_Exception
* @return array
*/
public function getMetaData()
{
if($this->stream === null)
{
throw new TeamSpeak3_Transport_Exception("unable to retrieve header/meta data from stream pointer");
}
return stream_get_meta_data($this->stream);
}
/**
* Returns TRUE if the transport is connected.
*
* @return boolean
*/
public function isConnected()
{
return (is_resource($this->stream)) ? TRUE : FALSE;
}
/**
* Blocks a stream until data is available for reading if the stream is connected
* in non-blocking mode.
*
* @param integer $time
* @return void
*/
protected function waitForReadyRead($time = 0)
{
if(!$this->isConnected() || $this->config["blocking"]) return;
do
{
$read = array($this->stream);
$null = null;
if($time)
{
TeamSpeak3_Helper_Signal::getInstance()->emit(strtolower($this->getAdapterType()) . "WaitTimeout", $time, $this->getAdapter());
}
$time = $time+$this->config["timeout"];
}
while(@stream_select($read, $null, $null, $this->config["timeout"]) == 0);
}
}
<?php
/**
* @file
* TeamSpeak 3 PHP Framework
*
* $Id: Exception.php 06/06/2016 22:27:13 scp@Svens-iMac $
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @package TeamSpeak3
* @version 1.1.24
* @author Sven 'ScP' Paulsen
* @copyright Copyright (c) 2010 by Planet TeamSpeak. All rights reserved.
*/
/**
* @class TeamSpeak3_Transport_Exception
* @brief Enhanced exception class for TeamSpeak3_Transport_Abstract objects.
*/
class TeamSpeak3_Transport_Exception extends TeamSpeak3_Exception {}
<?php
/**
* @file
* TeamSpeak 3 PHP Framework
*
* $Id: TCP.php 06/06/2016 22:27:13 scp@Svens-iMac $
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @package TeamSpeak3
* @version 1.1.24
* @author Sven 'ScP' Paulsen
* @copyright Copyright (c) 2010 by Planet TeamSpeak. All rights reserved.
*/
/**
* @class TeamSpeak3_Transport_TCP
* @brief Class for connecting to a remote server through TCP.
*/
class TeamSpeak3_Transport_TCP extends TeamSpeak3_Transport_Abstract
{
/**
* Connects to a remote server.
*
* @throws TeamSpeak3_Transport_Exception
* @return void
*/
public function connect()
{
if($this->stream !== null) return;
$host = strval($this->config["host"]);
$port = strval($this->config["port"]);
$address = "tcp://" . (strstr($host, ":") !== FALSE ? "[" . $host . "]" : $host) . ":" . $port;
$timeout = (int) $this->config["timeout"];
$this->stream = @stream_socket_client($address, $errno, $errstr, $timeout);
if($this->stream === FALSE)
{
throw new TeamSpeak3_Transport_Exception(TeamSpeak3_Helper_String::factory($errstr)->toUtf8()->toString(), $errno);
}
@stream_set_timeout($this->stream, $timeout);
@stream_set_blocking($this->stream, $this->config["blocking"] ? 1 : 0);
}
/**
* Disconnects from a remote server.
*
* @return void
*/
public function disconnect()
{
if($this->stream === null) return;
$this->stream = null;
TeamSpeak3_Helper_Signal::getInstance()->emit(strtolower($this->getAdapterType()) . "Disconnected");
}
/**
* Reads data from the stream.
*
* @param integer $length
* @throws TeamSpeak3_Transport_Exception
* @return TeamSpeak3_Helper_String
*/
public function read($length = 4096)
{
$this->connect();
$this->waitForReadyRead();
$data = @stream_get_contents($this->stream, $length);
TeamSpeak3_Helper_Signal::getInstance()->emit(strtolower($this->getAdapterType()) . "DataRead", $data);
if($data === FALSE)
{
throw new TeamSpeak3_Transport_Exception("connection to server '" . $this->config["host"] . ":" . $this->config["port"] . "' lost");
}
return new TeamSpeak3_Helper_String($data);
}
/**
* Reads a single line of data from the stream.
*
* @param string $token
* @throws TeamSpeak3_Transport_Exception
* @return TeamSpeak3_Helper_String
*/
public function readLine($token = "\n")
{
$this->connect();
$line = TeamSpeak3_Helper_String::factory("");
while(!$line->endsWith($token))
{
$this->waitForReadyRead();
$data = @fgets($this->stream, 4096);
TeamSpeak3_Helper_Signal::getInstance()->emit(strtolower($this->getAdapterType()) . "DataRead", $data);
if($data === FALSE)
{
if($line->count())
{
$line->append($token);
}
else
{
throw new TeamSpeak3_Transport_Exception("connection to server '" . $this->config["host"] . ":" . $this->config["port"] . "' lost");
}
}
else
{
$line->append($data);
}
}
return $line->trim();
}
/**
* Writes data to the stream.
*
* @param string $data
* @return void
*/
public function send($data)
{
$this->connect();
@stream_socket_sendto($this->stream, $data);
TeamSpeak3_Helper_Signal::getInstance()->emit(strtolower($this->getAdapterType()) . "DataSend", $data);
}
/**
* Writes a line of data to the stream.
*
* @param string $data
* @param string $separator
* @return void
*/
public function sendLine($data, $separator = "\n")
{
$size = strlen($data);
$pack = 4096;
for($seek = 0 ;$seek < $size;)
{
$rest = $size-$seek;
$pack = $rest < $pack ? $rest : $pack;
$buff = substr($data, $seek, $pack);
$seek = $seek+$pack;
if($seek >= $size) $buff .= $separator;
$this->send($buff);
}
}
}
<?php
/**
* @file
* TeamSpeak 3 PHP Framework
*
* $Id: UDP.php 06/06/2016 22:27:13 scp@Svens-iMac $
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @package TeamSpeak3
* @version 1.1.24
* @author Sven 'ScP' Paulsen
* @copyright Copyright (c) 2010 by Planet TeamSpeak. All rights reserved.
*/
/**
* @class TeamSpeak3_Transport_UDP
* @brief Class for connecting to a remote server through UDP.
*/
class TeamSpeak3_Transport_UDP extends TeamSpeak3_Transport_Abstract
{
/**
* Connects to a remote server.
*
* @throws TeamSpeak3_Transport_Exception
* @return void
*/
public function connect()
{
if($this->stream !== null) return;
$host = strval($this->config["host"]);
$port = strval($this->config["port"]);
$address = "udp://" . (strstr($host, ":") !== FALSE ? "[" . $host . "]" : $host) . ":" . $port;
$timeout = (int) $this->config["timeout"];
$this->stream = @stream_socket_client($address, $errno, $errstr, $timeout);
if($this->stream === FALSE)
{
throw new TeamSpeak3_Transport_Exception(TeamSpeak3_Helper_String::factory($errstr)->toUtf8()->toString(), $errno);
}
@stream_set_timeout($this->stream, $timeout);
@stream_set_blocking($this->stream, $this->config["blocking"] ? 1 : 0);
}
/**
* Disconnects from a remote server.
*
* @return void
*/
public function disconnect()
{
if($this->stream === null) return;
$this->stream = null;
TeamSpeak3_Helper_Signal::getInstance()->emit(strtolower($this->getAdapterType()) . "Disconnected");
}
/**
* Reads data from the stream.
*
* @param integer $length
* @throws TeamSpeak3_Transport_Exception
* @return TeamSpeak3_Helper_String
*/
public function read($length = 4096)
{
$this->connect();
$this->waitForReadyRead();
$data = @fread($this->stream, $length);
TeamSpeak3_Helper_Signal::getInstance()->emit(strtolower($this->getAdapterType()) . "DataRead", $data);
if($data === FALSE)
{
throw new TeamSpeak3_Transport_Exception("connection to server '" . $this->config["host"] . ":" . $this->config["port"] . "' lost");
}
return new TeamSpeak3_Helper_String($data);
}
/**
* Writes data to the stream.
*
* @param string $data
* @return void
*/
public function send($data)
{
$this->connect();
@stream_socket_sendto($this->stream, $data);
TeamSpeak3_Helper_Signal::getInstance()->emit(strtolower($this->getAdapterType()) . "DataSend", $data);
}
}
<?php
/**
* @file
* TeamSpeak 3 PHP Framework
*
* $Id: Text.php 06/06/2016 22:27:13 scp@Svens-iMac $
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @package TeamSpeak3
* @version 1.1.24
* @author Sven 'ScP' Paulsen
* @copyright Copyright (c) 2010 by Planet TeamSpeak. All rights reserved.
*/
/**
* @class TeamSpeak3_Viewer_Html
* @brief Renders nodes used in HTML-based TeamSpeak 3 viewers.
*/
class TeamSpeak3_Viewer_Html implements TeamSpeak3_Viewer_Interface
{
/**
* A pre-defined pattern used to display a node in a TeamSpeak 3 viewer.
*
* @var string
*/
protected $pattern = "<table id='%0' class='%1' summary='%2'><tr class='%3'><td class='%4'>%5</td><td class='%6' title='%7'>%8 %9</td><td class='%10'>%11%12</td></tr></table>\n";
/**
* The TeamSpeak3_Node_Abstract object which is currently processed.
*
* @var TeamSpeak3_Node_Abstract
*/
protected $currObj = null;
/**
* An array filled with siblingsfor the TeamSpeak3_Node_Abstract object which is currently
* processed.
*
* @var array
*/
protected $currSib = null;
/**
* An internal counter indicating the number of fetched TeamSpeak3_Node_Abstract objects.
*
* @var integer
*/
protected $currNum = 0;
/**
* The relative URI path where the images used by the viewer can be found.
*
* @var string
*/
protected $iconpath = null;
/**
* The relative URI path where the country flag icons used by the viewer can be found.
*
* @var string
*/
protected $flagpath = null;
/**
* The relative path of the file transter client script on the server.
*
* @var string
*/
protected $ftclient = null;
/**
* Stores an array of local icon IDs.
*
* @var array
*/
protected $cachedIcons = array(100, 200, 300, 400, 500, 600);
/**
* Stores an array of remote icon IDs.
*
* @var array
*/
protected $remoteIcons = array();
/**
* The TeamSpeak3_Viewer_Html constructor.
*
* @param string $iconpath
* @param string $flagpath
* @param string $ftclient
* @param string $pattern
* @return void
*/
public function __construct($iconpath = "images/viewer/", $flagpath = null, $ftclient = null, $pattern = null)
{
$this->iconpath = $iconpath;
$this->flagpath = $flagpath;
$this->ftclient = $ftclient;
if($pattern)
{
$this->pattern = $pattern;
}
}
/**
* Returns the code needed to display a node in a TeamSpeak 3 viewer.
*
* @param TeamSpeak3_Node_Abstract $node
* @param array $siblings
* @return string
*/
public function fetchObject(TeamSpeak3_Node_Abstract $node, array $siblings = array())
{
$this->currObj = $node;
$this->currSib = $siblings;
$args = array(
$this->getContainerIdent(),
$this->getContainerClass(),
$this->getContainerSummary(),
$this->getRowClass(),
$this->getPrefixClass(),
$this->getPrefix(),
$this->getCorpusClass(),
$this->getCorpusTitle(),
$this->getCorpusIcon(),
$this->getCorpusName(),
$this->getSuffixClass(),
$this->getSuffixIcon(),
$this->getSuffixFlag(),
);
return TeamSpeak3_Helper_String::factory($this->pattern)->arg($args);
}
/**
* Returns a unique identifier for the current node which can be used as a HTML id
* property.
*
* @return string
*/
protected function getContainerIdent()
{
return $this->currObj->getUniqueId();
}
/**
* Returns a dynamic string for the current container element which can be used as
* a HTML class property.
*
* @return string
*/
protected function getContainerClass()
{
return "ts3_viewer " . $this->currObj->getClass(null);
}
/**
* Returns the ID of the current node which will be used as a summary element for
* the container element.
*
* @return integer
*/
protected function getContainerSummary()
{
return $this->currObj->getId();
}
/**
* Returns a dynamic string for the current row element which can be used as a HTML
* class property.
*
* @return string
*/
protected function getRowClass()
{
return ++$this->currNum%2 ? "row1" : "row2";
}
/**
* Returns a string for the current prefix element which can be used as a HTML class
* property.
*
* @return string
*/
protected function getPrefixClass()
{
return "prefix " . $this->currObj->getClass(null);
}
/**
* Returns the HTML img tags to display the prefix of the current node.
*
* @return string
*/
protected function getPrefix()
{
$prefix = "";
if(count($this->currSib))
{
$last = array_pop($this->currSib);
foreach($this->currSib as $sibling)
{
$prefix .= ($sibling) ? $this->getImage("tree_line.gif") : $this->getImage("tree_blank.png");
}
$prefix .= ($last) ? $this->getImage("tree_end.gif") : $this->getImage("tree_mid.gif");
}
return $prefix;
}
/**
* Returns a string for the current corpus element which can be used as a HTML class
* property. If the current node is a channel spacer the class string will contain
* additional class names to allow further customization of the content via CSS.
*
* @return string
*/
protected function getCorpusClass()
{
$extras = "";
if($this->currObj instanceof TeamSpeak3_Node_Channel && $this->currObj->isSpacer())
{
switch($this->currObj->spacerGetType())
{
case (string) TeamSpeak3::SPACER_SOLIDLINE:
$extras .= " solidline";
break;
case (string) TeamSpeak3::SPACER_DASHLINE:
$extras .= " dashline";
break;
case (string) TeamSpeak3::SPACER_DASHDOTLINE:
$extras .= " dashdotline";
break;
case (string) TeamSpeak3::SPACER_DASHDOTDOTLINE:
$extras .= " dashdotdotline";
break;
case (string) TeamSpeak3::SPACER_DOTLINE:
$extras .= " dotline";
break;
}
switch($this->currObj->spacerGetAlign())
{
case TeamSpeak3::SPACER_ALIGN_CENTER:
$extras .= " center";
break;
case TeamSpeak3::SPACER_ALIGN_RIGHT:
$extras .= " right";
break;
case TeamSpeak3::SPACER_ALIGN_LEFT:
$extras .= " left";
break;
}
}
return "corpus " . $this->currObj->getClass(null) . $extras;
}
/**
* Returns the HTML img tags which can be used to display the various icons for a
* TeamSpeak_Node_Abstract object.
*
* @return string
*/
protected function getCorpusTitle()
{
if($this->currObj instanceof TeamSpeak3_Node_Server)
{
return "ID: " . $this->currObj->getId() . " | Clients: " . $this->currObj->clientCount() . "/" . $this->currObj["virtualserver_maxclients"] . " | Uptime: " . TeamSpeak3_Helper_Convert::seconds($this->currObj["virtualserver_uptime"]);
}
elseif($this->currObj instanceof TeamSpeak3_Node_Channel && !$this->currObj->isSpacer())
{
return "ID: " . $this->currObj->getId() . " | Codec: " . TeamSpeak3_Helper_Convert::codec($this->currObj["channel_codec"]) . " | Quality: " . $this->currObj["channel_codec_quality"];
}
elseif($this->currObj instanceof TeamSpeak3_Node_Client)
{
return "ID: " . $this->currObj->getId() . " | Version: " . TeamSpeak3_Helper_Convert::versionShort($this->currObj["client_version"]) . " | Platform: " . $this->currObj["client_platform"];
}
elseif($this->currObj instanceof TeamSpeak3_Node_Servergroup || $this->currObj instanceof TeamSpeak3_Node_Channelgroup)
{
return "ID: " . $this->currObj->getId() . " | Type: " . TeamSpeak3_Helper_Convert::groupType($this->currObj["type"]) . " (" . ($this->currObj["savedb"] ? "Permanent" : "Temporary") . ")";
}
}
/**
* Returns a HTML img tag which can be used to display the status icon for a
* TeamSpeak_Node_Abstract object.
*
* @return string
*/
protected function getCorpusIcon()
{
if($this->currObj instanceof TeamSpeak3_Node_Channel && $this->currObj->isSpacer()) return;
return $this->getImage($this->currObj->getIcon() . ".png");
}
/**
* Returns a string for the current corpus element which contains the display name
* for the current TeamSpeak_Node_Abstract object.
*
* @return string
*/
protected function getCorpusName()
{
if($this->currObj instanceof TeamSpeak3_Node_Channel && $this->currObj->isSpacer())
{
if($this->currObj->spacerGetType() != TeamSpeak3::SPACER_CUSTOM) return;
$string = $this->currObj["channel_name"]->section("]", 1, 99);
if($this->currObj->spacerGetAlign() == TeamSpeak3::SPACER_ALIGN_REPEAT)
{
$string->resize(30, $string);
}
return htmlspecialchars($string);
}
if($this->currObj instanceof TeamSpeak3_Node_Client)
{
$before = array();
$behind = array();
foreach($this->currObj->memberOf() as $group)
{
if($group->getProperty("namemode") == TeamSpeak3::GROUP_NAMEMODE_BEFORE)
{
$before[] = "[" . htmlspecialchars($group["name"]) . "]";
}
elseif($group->getProperty("namemode") == TeamSpeak3::GROUP_NAMEMODE_BEHIND)
{
$behind[] = "[" . htmlspecialchars($group["name"]) . "]";
}
}
return implode("", $before) . " " . htmlspecialchars($this->currObj) . " " . implode("", $behind);
}
return htmlspecialchars($this->currObj);
}
/**
* Returns a string for the current suffix element which can be used as a HTML
* class property.
*
* @return string
*/
protected function getSuffixClass()
{
return "suffix " . $this->currObj->getClass(null);
}
/**
* Returns the HTML img tags which can be used to display the various icons for a
* TeamSpeak_Node_Abstract object.
*
* @return string
*/
protected function getSuffixIcon()
{
if($this->currObj instanceof TeamSpeak3_Node_Server)
{
return $this->getSuffixIconServer();
}
elseif($this->currObj instanceof TeamSpeak3_Node_Channel)
{
return $this->getSuffixIconChannel();
}
elseif($this->currObj instanceof TeamSpeak3_Node_Client)
{
return $this->getSuffixIconClient();
}
}
/**
* Returns the HTML img tags which can be used to display the various icons for a
* TeamSpeak_Node_Server object.
*
* @return string
*/
protected function getSuffixIconServer()
{
$html = "";
if($this->currObj["virtualserver_icon_id"])
{
if(!$this->currObj->iconIsLocal("virtualserver_icon_id") && $this->ftclient)
{
if(!isset($this->cacheIcon[$this->currObj["virtualserver_icon_id"]]))
{
try {
$download = $this->currObj->transferInitDownload(rand(0x0000, 0xFFFF), 0, $this->currObj->iconGetName("virtualserver_icon_id"));
} catch(TeamSpeak3_Exception $e) {
return;
}
if($this->ftclient == "data:image")
{
$download = TeamSpeak3::factory("filetransfer://" . (strstr($download["host"], ":") !== FALSE ? "[" . $download["host"] . "]" : $download["host"]) . ":" . $download["port"])->download($download["ftkey"], $download["size"]);
}
$this->cacheIcon[$this->currObj["virtualserver_icon_id"]] = $download;
}
else
{
$download = $this->cacheIcon[$this->currObj["virtualserver_icon_id"]];
}
if($this->ftclient == "data:image")
{
$html .= $this->getImage("data:" . TeamSpeak3_Helper_Convert::imageMimeType($download) . ";base64," . base64_encode($download), "Server Icon", null, FALSE);
}
else
{
$html .= $this->getImage($this->ftclient . "?ftdata=" . base64_encode(serialize($download)), "Server Icon", null, FALSE);
}
}
elseif(in_array($this->currObj["virtualserver_icon_id"], $this->cachedIcons))
{
$html .= $this->getImage("group_icon_" . $this->currObj["virtualserver_icon_id"] . ".png", "Server Icon");
}
}
return $html;
}
/**
* Returns the HTML img tags which can be used to display the various icons for a
* TeamSpeak_Node_Channel object.
*
* @return string
*/
protected function getSuffixIconChannel()
{
if($this->currObj instanceof TeamSpeak3_Node_Channel && $this->currObj->isSpacer()) return;
$html = "";
if($this->currObj["channel_flag_default"])
{
$html .= $this->getImage("channel_flag_default.png", "Default Channel");
}
if($this->currObj["channel_flag_password"])
{
$html .= $this->getImage("channel_flag_password.png", "Password-protected");
}
if($this->currObj["channel_codec"] == TeamSpeak3::CODEC_CELT_MONO || $this->currObj["channel_codec"] == TeamSpeak3::CODEC_OPUS_MUSIC)
{
$html .= $this->getImage("channel_flag_music.png", "Music Codec");
}
if($this->currObj["channel_needed_talk_power"])
{
$html .= $this->getImage("channel_flag_moderated.png", "Moderated");
}
if($this->currObj["channel_icon_id"])
{
if(!$this->currObj->iconIsLocal("channel_icon_id") && $this->ftclient)
{
if(!isset($this->cacheIcon[$this->currObj["channel_icon_id"]]))
{
try {
$download = $this->currObj->getParent()->transferInitDownload(rand(0x0000, 0xFFFF), 0, $this->currObj->iconGetName("channel_icon_id"));
} catch(TeamSpeak3_Exception $e) {
return;
}
if($this->ftclient == "data:image")
{
$download = TeamSpeak3::factory("filetransfer://" . (strstr($download["host"], ":") !== FALSE ? "[" . $download["host"] . "]" : $download["host"]) . ":" . $download["port"])->download($download["ftkey"], $download["size"]);
}
$this->cacheIcon[$this->currObj["channel_icon_id"]] = $download;
}
else
{
$download = $this->cacheIcon[$this->currObj["channel_icon_id"]];
}
if($this->ftclient == "data:image")
{
$html .= $this->getImage("data:" . TeamSpeak3_Helper_Convert::imageMimeType($download) . ";base64," . base64_encode($download), "Channel Icon", null, FALSE);
}
else
{
$html .= $this->getImage($this->ftclient . "?ftdata=" . base64_encode(serialize($download)), "Channel Icon", null, FALSE);
}
}
elseif(in_array($this->currObj["channel_icon_id"], $this->cachedIcons))
{
$html .= $this->getImage("group_icon_" . $this->currObj["channel_icon_id"] . ".png", "Channel Icon");
}
}
return $html;
}
/**
* Returns the HTML img tags which can be used to display the various icons for a
* TeamSpeak_Node_Client object.
*
* @return string
*/
protected function getSuffixIconClient()
{
$html = "";
if($this->currObj["client_is_priority_speaker"])
{
$html .= $this->getImage("client_priority.png", "Priority Speaker");
}
if($this->currObj["client_is_channel_commander"])
{
$html .= $this->getImage("client_cc.png", "Channel Commander");
}
if($this->currObj["client_is_talker"])
{
$html .= $this->getImage("client_talker.png", "Talk Power granted");
}
elseif($cntp = $this->currObj->getParent()->channelGetById($this->currObj["cid"])->channel_needed_talk_power)
{
if($cntp > $this->currObj["client_talk_power"])
{
$html .= $this->getImage("client_mic_muted.png", "Insufficient Talk Power");
}
}
foreach($this->currObj->memberOf() as $group)
{
if(!$group["iconid"]) continue;
$type = ($group instanceof TeamSpeak3_Node_Servergroup) ? "Server Group" : "Channel Group";
if(!$group->iconIsLocal("iconid") && $this->ftclient)
{
if(!isset($this->cacheIcon[$group["iconid"]]))
{
try {
$download = $group->getParent()->transferInitDownload(rand(0x0000, 0xFFFF), 0, $group->iconGetName("iconid"));
} catch(TeamSpeak3_Exception $e) {
return;
}
if($this->ftclient == "data:image")
{
$download = TeamSpeak3::factory("filetransfer://" . (strstr($download["host"], ":") !== FALSE ? "[" . $download["host"] . "]" : $download["host"]) . ":" . $download["port"])->download($download["ftkey"], $download["size"]);
}
$this->cacheIcon[$group["iconid"]] = $download;
}
else
{
$download = $this->cacheIcon[$group["iconid"]];
}
if($this->ftclient == "data:image")
{
$html .= $this->getImage("data:" . TeamSpeak3_Helper_Convert::imageMimeType($download) . ";base64," . base64_encode($download), $group . " [" . $type . "]", null, FALSE);
}
else
{
$html .= $this->getImage($this->ftclient . "?ftdata=" . base64_encode(serialize($download)), $group . " [" . $type . "]", null, FALSE);
}
}
elseif(in_array($group["iconid"], $this->cachedIcons))
{
$html .= $this->getImage("group_icon_" . $group["iconid"] . ".png", $group . " [" . $type . "]");
}
}
if($this->currObj["client_icon_id"])
{
if(!$this->currObj->iconIsLocal("client_icon_id") && $this->ftclient)
{
if(!isset($this->cacheIcon[$this->currObj["client_icon_id"]]))
{
try {
$download = $this->currObj->getParent()->transferInitDownload(rand(0x0000, 0xFFFF), 0, $this->currObj->iconGetName("client_icon_id"));
} catch(TeamSpeak3_Exception $e) {
return;
}
if($this->ftclient == "data:image")
{
$download = TeamSpeak3::factory("filetransfer://" . (strstr($download["host"], ":") !== FALSE ? "[" . $download["host"] . "]" : $download["host"]) . ":" . $download["port"])->download($download["ftkey"], $download["size"]);
}
$this->cacheIcon[$this->currObj["client_icon_id"]] = $download;
}
else
{
$download = $this->cacheIcon[$this->currObj["client_icon_id"]];
}
if($this->ftclient == "data:image")
{
$html .= $this->getImage("data:" . TeamSpeak3_Helper_Convert::imageMimeType($download) . ";base64," . base64_encode($download), "Client Icon", null, FALSE);
}
else
{
$html .= $this->getImage($this->ftclient . "?ftdata=" . base64_encode(serialize($download)), "Client Icon", null, FALSE);
}
}
elseif(in_array($this->currObj["client_icon_id"], $this->cachedIcons))
{
$html .= $this->getImage("group_icon_" . $this->currObj["client_icon_id"] . ".png", "Client Icon");
}
}
return $html;
}
/**
* Returns a HTML img tag which can be used to display the country flag for a
* TeamSpeak_Node_Client object.
*
* @return string
*/
protected function getSuffixFlag()
{
if(!$this->currObj instanceof TeamSpeak3_Node_Client) return;
if($this->flagpath && $this->currObj["client_country"])
{
return $this->getImage($this->currObj["client_country"]->toLower() . ".png", $this->currObj["client_country"], null, FALSE, TRUE);
}
}
/**
* Returns the code to display a custom HTML img tag.
*
* @param string $name
* @param string $text
* @param string $class
* @param boolean $iconpath
* @param boolean $flagpath
* @return string
*/
protected function getImage($name, $text = "", $class = null, $iconpath = TRUE, $flagpath = FALSE)
{
$src = "";
if($iconpath)
{
$src = $this->iconpath;
}
if($flagpath)
{
$src = $this->flagpath;
}
return "<img src='" . $src . $name . "' title='" . $text . "' alt='' align='top' />";
}
}
<?php
/**
* @file
* TeamSpeak 3 PHP Framework
*
* $Id: Interface.php 06/06/2016 22:27:13 scp@Svens-iMac $
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @package TeamSpeak3
* @version 1.1.24
* @author Sven 'ScP' Paulsen
* @copyright Copyright (c) 2010 by Planet TeamSpeak. All rights reserved.
*/
/**
* @class TeamSpeak3_Viewer_Interface
* @brief Interface class describing a TeamSpeak 3 viewer.
*/
interface TeamSpeak3_Viewer_Interface
{
/**
* Returns the code needed to display a node in a TeamSpeak 3 viewer.
*
* @param TeamSpeak3_Node_Abstract $node
* @param array $siblings
* @return string
*/
public function fetchObject(TeamSpeak3_Node_Abstract $node, array $siblings = array());
}
<?php
/**
* @file
* TeamSpeak 3 PHP Framework
*
* $Id: Text.php 06/06/2016 22:27:13 scp@Svens-iMac $
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @package TeamSpeak3
* @version 1.1.24
* @author Sven 'ScP' Paulsen
* @copyright Copyright (c) 2010 by Planet TeamSpeak. All rights reserved.
*/
/**
* @class TeamSpeak3_Viewer_Text
* @brief Renders nodes used in ASCII-based TeamSpeak 3 viewers.
*/
class TeamSpeak3_Viewer_Text implements TeamSpeak3_Viewer_Interface
{
/**
* A pre-defined pattern used to display a node in a TeamSpeak 3 viewer.
*
* @var string
*/
protected $pattern = "%0%1 %2\n";
/**
* Returns the code needed to display a node in a TeamSpeak 3 viewer.
*
* @param TeamSpeak3_Node_Abstract $node
* @param array $siblings
* @return string
*/
public function fetchObject(TeamSpeak3_Node_Abstract $node, array $siblings = array())
{
$this->currObj = $node;
$this->currSib = $siblings;
$args = array(
$this->getPrefix(),
$this->getCorpusIcon(),
$this->getCorpusName(),
);
return TeamSpeak3_Helper_String::factory($this->pattern)->arg($args);
}
/**
* Returns the ASCII string to display the prefix of the current node.
*
* @return string
*/
protected function getPrefix()
{
$prefix = "";
if(count($this->currSib))
{
$last = array_pop($this->currSib);
foreach($this->currSib as $sibling)
{
$prefix .= ($sibling) ? "| " : " ";
}
$prefix .= ($last) ? "\\-" : "|-";
}
return $prefix;
}
/**
* Returns an ASCII string which can be used to display the status icon for a
* TeamSpeak_Node_Abstract object.
*
* @return string
*/
protected function getCorpusIcon()
{
return $this->currObj->getSymbol();
}
/**
* Returns a string for the current corpus element which contains the display name
* for the current TeamSpeak_Node_Abstract object.
*
* @return string
*/
protected function getCorpusName()
{
return $this->currObj;
}
}
GNU GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The GNU General Public License is a free, copyleft license for
software and other kinds of works.
The licenses for most software and other practical works are designed
to take away your freedom to share and change the works. By contrast,
the GNU General Public License is intended to guarantee your freedom to
share and change all versions of a program--to make sure it remains free
software for all its users. We, the Free Software Foundation, use the
GNU General Public License for most of our software; it applies also to
any other work released this way by its authors. You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
them if you wish), that you receive source code or can get it if you
want it, that you can change the software or use pieces of it in new
free programs, and that you know you can do these things.
To protect your rights, we need to prevent others from denying you
these rights or asking you to surrender the rights. Therefore, you have
certain responsibilities if you distribute copies of the software, or if
you modify it: responsibilities to respect the freedom of others.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must pass on to the recipients the same
freedoms that you received. You must make sure that they, too, receive
or can get the source code. And you must show them these terms so they
know their rights.
Developers that use the GNU GPL protect your rights with two steps:
(1) assert copyright on the software, and (2) offer you this License
giving you legal permission to copy, distribute and/or modify it.
For the developers' and authors' protection, the GPL clearly explains
that there is no warranty for this free software. For both users' and
authors' sake, the GPL requires that modified versions be marked as
changed, so that their problems will not be attributed erroneously to
authors of previous versions.
Some devices are designed to deny users access to install or run
modified versions of the software inside them, although the manufacturer
can do so. This is fundamentally incompatible with the aim of
protecting users' freedom to change the software. The systematic
pattern of such abuse occurs in the area of products for individuals to
use, which is precisely where it is most unacceptable. Therefore, we
have designed this version of the GPL to prohibit the practice for those
products. If such problems arise substantially in other domains, we
stand ready to extend this provision to those domains in future versions
of the GPL, as needed to protect the freedom of users.
Finally, every program is threatened constantly by software patents.
States should not allow patents to restrict development and use of
software on general-purpose computers, but in those that do, we wish to
avoid the special danger that patents applied to a free program could
make it effectively proprietary. To prevent this, the GPL assures that
patents cannot be used to render the program non-free.
The precise terms and conditions for copying, distribution and
modification follow.
TERMS AND CONDITIONS
0. Definitions.
"This License" refers to version 3 of the GNU General Public License.
"Copyright" also means copyright-like laws that apply to other kinds of
works, such as semiconductor masks.
"The Program" refers to any copyrightable work licensed under this
License. Each licensee is addressed as "you". "Licensees" and
"recipients" may be individuals or organizations.
To "modify" a work means to copy from or adapt all or part of the work
in a fashion requiring copyright permission, other than the making of an
exact copy. The resulting work is called a "modified version" of the
earlier work or a work "based on" the earlier work.
A "covered work" means either the unmodified Program or a work based
on the Program.
To "propagate" a work means to do anything with it that, without
permission, would make you directly or secondarily liable for
infringement under applicable copyright law, except executing it on a
computer or modifying a private copy. Propagation includes copying,
distribution (with or without modification), making available to the
public, and in some countries other activities as well.
To "convey" a work means any kind of propagation that enables other
parties to make or receive copies. Mere interaction with a user through
a computer network, with no transfer of a copy, is not conveying.
An interactive user interface displays "Appropriate Legal Notices"
to the extent that it includes a convenient and prominently visible
feature that (1) displays an appropriate copyright notice, and (2)
tells the user that there is no warranty for the work (except to the
extent that warranties are provided), that licensees may convey the
work under this License, and how to view a copy of this License. If
the interface presents a list of user commands or options, such as a
menu, a prominent item in the list meets this criterion.
1. Source Code.
The "source code" for a work means the preferred form of the work
for making modifications to it. "Object code" means any non-source
form of a work.
A "Standard Interface" means an interface that either is an official
standard defined by a recognized standards body, or, in the case of
interfaces specified for a particular programming language, one that
is widely used among developers working in that language.
The "System Libraries" of an executable work include anything, other
than the work as a whole, that (a) is included in the normal form of
packaging a Major Component, but which is not part of that Major
Component, and (b) serves only to enable use of the work with that
Major Component, or to implement a Standard Interface for which an
implementation is available to the public in source code form. A
"Major Component", in this context, means a major essential component
(kernel, window system, and so on) of the specific operating system
(if any) on which the executable work runs, or a compiler used to
produce the work, or an object code interpreter used to run it.
The "Corresponding Source" for a work in object code form means all
the source code needed to generate, install, and (for an executable
work) run the object code and to modify the work, including scripts to
control those activities. However, it does not include the work's
System Libraries, or general-purpose tools or generally available free
programs which are used unmodified in performing those activities but
which are not part of the work. For example, Corresponding Source
includes interface definition files associated with source files for
the work, and the source code for shared libraries and dynamically
linked subprograms that the work is specifically designed to require,
such as by intimate data communication or control flow between those
subprograms and other parts of the work.
The Corresponding Source need not include anything that users
can regenerate automatically from other parts of the Corresponding
Source.
The Corresponding Source for a work in source code form is that
same work.
2. Basic Permissions.
All rights granted under this License are granted for the term of
copyright on the Program, and are irrevocable provided the stated
conditions are met. This License explicitly affirms your unlimited
permission to run the unmodified Program. The output from running a
covered work is covered by this License only if the output, given its
content, constitutes a covered work. This License acknowledges your
rights of fair use or other equivalent, as provided by copyright law.
You may make, run and propagate covered works that you do not
convey, without conditions so long as your license otherwise remains
in force. You may convey covered works to others for the sole purpose
of having them make modifications exclusively for you, or provide you
with facilities for running those works, provided that you comply with
the terms of this License in conveying all material for which you do
not control copyright. Those thus making or running the covered works
for you must do so exclusively on your behalf, under your direction
and control, on terms that prohibit them from making any copies of
your copyrighted material outside their relationship with you.
Conveying under any other circumstances is permitted solely under
the conditions stated below. Sublicensing is not allowed; section 10
makes it unnecessary.
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
No covered work shall be deemed part of an effective technological
measure under any applicable law fulfilling obligations under article
11 of the WIPO copyright treaty adopted on 20 December 1996, or
similar laws prohibiting or restricting circumvention of such
measures.
When you convey a covered work, you waive any legal power to forbid
circumvention of technological measures to the extent such circumvention
is effected by exercising rights under this License with respect to
the covered work, and you disclaim any intention to limit operation or
modification of the work as a means of enforcing, against the work's
users, your or third parties' legal rights to forbid circumvention of
technological measures.
4. Conveying Verbatim Copies.
You may convey verbatim copies of the Program's source code as you
receive it, in any medium, provided that you conspicuously and
appropriately publish on each copy an appropriate copyright notice;
keep intact all notices stating that this License and any
non-permissive terms added in accord with section 7 apply to the code;
keep intact all notices of the absence of any warranty; and give all
recipients a copy of this License along with the Program.
You may charge any price or no price for each copy that you convey,
and you may offer support or warranty protection for a fee.
5. Conveying Modified Source Versions.
You may convey a work based on the Program, or the modifications to
produce it from the Program, in the form of source code under the
terms of section 4, provided that you also meet all of these conditions:
a) The work must carry prominent notices stating that you modified
it, and giving a relevant date.
b) The work must carry prominent notices stating that it is
released under this License and any conditions added under section
7. This requirement modifies the requirement in section 4 to
"keep intact all notices".
c) You must license the entire work, as a whole, under this
License to anyone who comes into possession of a copy. This
License will therefore apply, along with any applicable section 7
additional terms, to the whole of the work, and all its parts,
regardless of how they are packaged. This License gives no
permission to license the work in any other way, but it does not
invalidate such permission if you have separately received it.
d) If the work has interactive user interfaces, each must display
Appropriate Legal Notices; however, if the Program has interactive
interfaces that do not display Appropriate Legal Notices, your
work need not make them do so.
A compilation of a covered work with other separate and independent
works, which are not by their nature extensions of the covered work,
and which are not combined with it such as to form a larger program,
in or on a volume of a storage or distribution medium, is called an
"aggregate" if the compilation and its resulting copyright are not
used to limit the access or legal rights of the compilation's users
beyond what the individual works permit. Inclusion of a covered work
in an aggregate does not cause this License to apply to the other
parts of the aggregate.
6. Conveying Non-Source Forms.
You may convey a covered work in object code form under the terms
of sections 4 and 5, provided that you also convey the
machine-readable Corresponding Source under the terms of this License,
in one of these ways:
a) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by the
Corresponding Source fixed on a durable physical medium
customarily used for software interchange.
b) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by a
written offer, valid for at least three years and valid for as
long as you offer spare parts or customer support for that product
model, to give anyone who possesses the object code either (1) a
copy of the Corresponding Source for all the software in the
product that is covered by this License, on a durable physical
medium customarily used for software interchange, for a price no
more than your reasonable cost of physically performing this
conveying of source, or (2) access to copy the
Corresponding Source from a network server at no charge.
c) Convey individual copies of the object code with a copy of the
written offer to provide the Corresponding Source. This
alternative is allowed only occasionally and noncommercially, and
only if you received the object code with such an offer, in accord
with subsection 6b.
d) Convey the object code by offering access from a designated
place (gratis or for a charge), and offer equivalent access to the
Corresponding Source in the same way through the same place at no
further charge. You need not require recipients to copy the
Corresponding Source along with the object code. If the place to
copy the object code is a network server, the Corresponding Source
may be on a different server (operated by you or a third party)
that supports equivalent copying facilities, provided you maintain
clear directions next to the object code saying where to find the
Corresponding Source. Regardless of what server hosts the
Corresponding Source, you remain obligated to ensure that it is
available for as long as needed to satisfy these requirements.
e) Convey the object code using peer-to-peer transmission, provided
you inform other peers where the object code and Corresponding
Source of the work are being offered to the general public at no
charge under subsection 6d.
A separable portion of the object code, whose source code is excluded
from the Corresponding Source as a System Library, need not be
included in conveying the object code work.
A "User Product" is either (1) a "consumer product", which means any
tangible personal property which is normally used for personal, family,
or household purposes, or (2) anything designed or sold for incorporation
into a dwelling. In determining whether a product is a consumer product,
doubtful cases shall be resolved in favor of coverage. For a particular
product received by a particular user, "normally used" refers to a
typical or common use of that class of product, regardless of the status
of the particular user or of the way in which the particular user
actually uses, or expects or is expected to use, the product. A product
is a consumer product regardless of whether the product has substantial
commercial, industrial or non-consumer uses, unless such uses represent
the only significant mode of use of the product.
"Installation Information" for a User Product means any methods,
procedures, authorization keys, or other information required to install
and execute modified versions of a covered work in that User Product from
a modified version of its Corresponding Source. The information must
suffice to ensure that the continued functioning of the modified object
code is in no case prevented or interfered with solely because
modification has been made.
If you convey an object code work under this section in, or with, or
specifically for use in, a User Product, and the conveying occurs as
part of a transaction in which the right of possession and use of the
User Product is transferred to the recipient in perpetuity or for a
fixed term (regardless of how the transaction is characterized), the
Corresponding Source conveyed under this section must be accompanied
by the Installation Information. But this requirement does not apply
if neither you nor any third party retains the ability to install
modified object code on the User Product (for example, the work has
been installed in ROM).
The requirement to provide Installation Information does not include a
requirement to continue to provide support service, warranty, or updates
for a work that has been modified or installed by the recipient, or for
the User Product in which it has been modified or installed. Access to a
network may be denied when the modification itself materially and
adversely affects the operation of the network or violates the rules and
protocols for communication across the network.
Corresponding Source conveyed, and Installation Information provided,
in accord with this section must be in a format that is publicly
documented (and with an implementation available to the public in
source code form), and must require no special password or key for
unpacking, reading or copying.
7. Additional Terms.
"Additional permissions" are terms that supplement the terms of this
License by making exceptions from one or more of its conditions.
Additional permissions that are applicable to the entire Program shall
be treated as though they were included in this License, to the extent
that they are valid under applicable law. If additional permissions
apply only to part of the Program, that part may be used separately
under those permissions, but the entire Program remains governed by
this License without regard to the additional permissions.
When you convey a copy of a covered work, you may at your option
remove any additional permissions from that copy, or from any part of
it. (Additional permissions may be written to require their own
removal in certain cases when you modify the work.) You may place
additional permissions on material, added by you to a covered work,
for which you have or can give appropriate copyright permission.
Notwithstanding any other provision of this License, for material you
add to a covered work, you may (if authorized by the copyright holders of
that material) supplement the terms of this License with terms:
a) Disclaiming warranty or limiting liability differently from the
terms of sections 15 and 16 of this License; or
b) Requiring preservation of specified reasonable legal notices or
author attributions in that material or in the Appropriate Legal
Notices displayed by works containing it; or
c) Prohibiting misrepresentation of the origin of that material, or
requiring that modified versions of such material be marked in
reasonable ways as different from the original version; or
d) Limiting the use for publicity purposes of names of licensors or
authors of the material; or
e) Declining to grant rights under trademark law for use of some
trade names, trademarks, or service marks; or
f) Requiring indemnification of licensors and authors of that
material by anyone who conveys the material (or modified versions of
it) with contractual assumptions of liability to the recipient, for
any liability that these contractual assumptions directly impose on
those licensors and authors.
All other non-permissive additional terms are considered "further
restrictions" within the meaning of section 10. If the Program as you
received it, or any part of it, contains a notice stating that it is
governed by this License along with a term that is a further
restriction, you may remove that term. If a license document contains
a further restriction but permits relicensing or conveying under this
License, you may add to a covered work material governed by the terms
of that license document, provided that the further restriction does
not survive such relicensing or conveying.
If you add terms to a covered work in accord with this section, you
must place, in the relevant source files, a statement of the
additional terms that apply to those files, or a notice indicating
where to find the applicable terms.
Additional terms, permissive or non-permissive, may be stated in the
form of a separately written license, or stated as exceptions;
the above requirements apply either way.
8. Termination.
You may not propagate or modify a covered work except as expressly
provided under this License. Any attempt otherwise to propagate or
modify it is void, and will automatically terminate your rights under
this License (including any patent licenses granted under the third
paragraph of section 11).
However, if you cease all violation of this License, then your
license from a particular copyright holder is reinstated (a)
provisionally, unless and until the copyright holder explicitly and
finally terminates your license, and (b) permanently, if the copyright
holder fails to notify you of the violation by some reasonable means
prior to 60 days after the cessation.
Moreover, your license from a particular copyright holder is
reinstated permanently if the copyright holder notifies you of the
violation by some reasonable means, this is the first time you have
received notice of violation of this License (for any work) from that
copyright holder, and you cure the violation prior to 30 days after
your receipt of the notice.
Termination of your rights under this section does not terminate the
licenses of parties who have received copies or rights from you under
this License. If your rights have been terminated and not permanently
reinstated, you do not qualify to receive new licenses for the same
material under section 10.
9. Acceptance Not Required for Having Copies.
You are not required to accept this License in order to receive or
run a copy of the Program. Ancillary propagation of a covered work
occurring solely as a consequence of using peer-to-peer transmission
to receive a copy likewise does not require acceptance. However,
nothing other than this License grants you permission to propagate or
modify any covered work. These actions infringe copyright if you do
not accept this License. Therefore, by modifying or propagating a
covered work, you indicate your acceptance of this License to do so.
10. Automatic Licensing of Downstream Recipients.
Each time you convey a covered work, the recipient automatically
receives a license from the original licensors, to run, modify and
propagate that work, subject to this License. You are not responsible
for enforcing compliance by third parties with this License.
An "entity transaction" is a transaction transferring control of an
organization, or substantially all assets of one, or subdividing an
organization, or merging organizations. If propagation of a covered
work results from an entity transaction, each party to that
transaction who receives a copy of the work also receives whatever
licenses to the work the party's predecessor in interest had or could
give under the previous paragraph, plus a right to possession of the
Corresponding Source of the work from the predecessor in interest, if
the predecessor has it or can get it with reasonable efforts.
You may not impose any further restrictions on the exercise of the
rights granted or affirmed under this License. For example, you may
not impose a license fee, royalty, or other charge for exercise of
rights granted under this License, and you may not initiate litigation
(including a cross-claim or counterclaim in a lawsuit) alleging that
any patent claim is infringed by making, using, selling, offering for
sale, or importing the Program or any portion of it.
11. Patents.
A "contributor" is a copyright holder who authorizes use under this
License of the Program or a work on which the Program is based. The
work thus licensed is called the contributor's "contributor version".
A contributor's "essential patent claims" are all patent claims
owned or controlled by the contributor, whether already acquired or
hereafter acquired, that would be infringed by some manner, permitted
by this License, of making, using, or selling its contributor version,
but do not include claims that would be infringed only as a
consequence of further modification of the contributor version. For
purposes of this definition, "control" includes the right to grant
patent sublicenses in a manner consistent with the requirements of
this License.
Each contributor grants you a non-exclusive, worldwide, royalty-free
patent license under the contributor's essential patent claims, to
make, use, sell, offer for sale, import and otherwise run, modify and
propagate the contents of its contributor version.
In the following three paragraphs, a "patent license" is any express
agreement or commitment, however denominated, not to enforce a patent
(such as an express permission to practice a patent or covenant not to
sue for patent infringement). To "grant" such a patent license to a
party means to make such an agreement or commitment not to enforce a
patent against the party.
If you convey a covered work, knowingly relying on a patent license,
and the Corresponding Source of the work is not available for anyone
to copy, free of charge and under the terms of this License, through a
publicly available network server or other readily accessible means,
then you must either (1) cause the Corresponding Source to be so
available, or (2) arrange to deprive yourself of the benefit of the
patent license for this particular work, or (3) arrange, in a manner
consistent with the requirements of this License, to extend the patent
license to downstream recipients. "Knowingly relying" means you have
actual knowledge that, but for the patent license, your conveying the
covered work in a country, or your recipient's use of the covered work
in a country, would infringe one or more identifiable patents in that
country that you have reason to believe are valid.
If, pursuant to or in connection with a single transaction or
arrangement, you convey, or propagate by procuring conveyance of, a
covered work, and grant a patent license to some of the parties
receiving the covered work authorizing them to use, propagate, modify
or convey a specific copy of the covered work, then the patent license
you grant is automatically extended to all recipients of the covered
work and works based on it.
A patent license is "discriminatory" if it does not include within
the scope of its coverage, prohibits the exercise of, or is
conditioned on the non-exercise of one or more of the rights that are
specifically granted under this License. You may not convey a covered
work if you are a party to an arrangement with a third party that is
in the business of distributing software, under which you make payment
to the third party based on the extent of your activity of conveying
the work, and under which the third party grants, to any of the
parties who would receive the covered work from you, a discriminatory
patent license (a) in connection with copies of the covered work
conveyed by you (or copies made from those copies), or (b) primarily
for and in connection with specific products or compilations that
contain the covered work, unless you entered into that arrangement,
or that patent license was granted, prior to 28 March 2007.
Nothing in this License shall be construed as excluding or limiting
any implied license or other defenses to infringement that may
otherwise be available to you under applicable patent law.
12. No Surrender of Others' Freedom.
If conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot convey a
covered work so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you may
not convey it at all. For example, if you agree to terms that obligate you
to collect a royalty for further conveying from those to whom you convey
the Program, the only way you could satisfy both those terms and this
License would be to refrain entirely from conveying the Program.
13. Use with the GNU Affero General Public License.
Notwithstanding any other provision of this License, you have
permission to link or combine any covered work with a work licensed
under version 3 of the GNU Affero General Public License into a single
combined work, and to convey the resulting work. The terms of this
License will continue to apply to the part which is the covered work,
but the special requirements of the GNU Affero General Public License,
section 13, concerning interaction through a network will apply to the
combination as such.
14. Revised Versions of this License.
The Free Software Foundation may publish revised and/or new versions of
the GNU General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the
Program specifies that a certain numbered version of the GNU General
Public License "or any later version" applies to it, you have the
option of following the terms and conditions either of that numbered
version or of any later version published by the Free Software
Foundation. If the Program does not specify a version number of the
GNU General Public License, you may choose any version ever published
by the Free Software Foundation.
If the Program specifies that a proxy can decide which future
versions of the GNU General Public License can be used, that proxy's
public statement of acceptance of a version permanently authorizes you
to choose that version for the Program.
Later license versions may give you additional or different
permissions. However, no additional obligations are imposed on any
author or copyright holder as a result of your choosing to follow a
later version.
15. Disclaimer of Warranty.
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
16. Limitation of Liability.
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
SUCH DAMAGES.
17. Interpretation of Sections 15 and 16.
If the disclaimer of warranty and limitation of liability provided
above cannot be given local legal effect according to their terms,
reviewing courts shall apply local law that most closely approximates
an absolute waiver of all civil liability in connection with the
Program, unless a warranty or assumption of liability accompanies a
copy of the Program in return for a fee.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
state the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
{one line to give the program's name and a brief idea of what it does.}
Copyright (C) {year} {name of author}
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Also add information on how to contact you by electronic and paper mail.
If the program does terminal interaction, make it output a short
notice like this when it starts in an interactive mode:
{project} Copyright (C) {year} {fullname}
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, your program's commands
might be different; for a GUI interface, you would use an "about box".
You should also get your employer (if you work as a programmer) or school,
if any, to sign a "copyright disclaimer" for the program, if necessary.
For more information on this, and how to apply and follow the GNU GPL, see
<http://www.gnu.org/licenses/>.
The GNU General Public License does not permit incorporating your program
into proprietary programs. If your program is a subroutine library, you
may consider it more useful to permit linking proprietary applications with
the library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License. But first, please read
<http://www.gnu.org/philosophy/why-not-lgpl.html>.

The MIT License (MIT)

Copyright (c) 2016 - 2018 Wruczek wruczekk@gmail.com and contributors

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.




Website screenshot

More screenshots | 🇩🇪 Für ein Deutsches Readme klicke hier

Need help? Join our telegram group for news, announcements, help and general chat about ts-website.


ts-website - free website for your TeamSpeak 3 server


Useful links

Main Features

  • News page, dynamic server status, admin list with status, server viewer, ban list and rules page
  • Multiple languages with auto-detection for default language
  • Supports for PHP 5 and 7, Apache 2 and nginx
  • Modern and responsive design
  • Caching
  • Free and Open source, under MIT license

Other stuff

I am happy to take any programming-related requests, add additional features or modify the code to suit your needs for a small donation :) I am experienced at Java, PHP, HTML, CSS, Javascript, SQL, server configurations ect.

For business enquiries only: wruczekk at gmail.com, for anything else please join our Telegram group.

<?php
require_once __DIR__ . "/include/header.php";
require_once __DIR__ . "/lib/parsedown/parsedown.php";
$parsedown = new Parsedown();
$path = __DIR__ . "/config/rules.md";
if (!file_exists($path)) {
echo '<div class="alert alert-danger"><p class="text-center">' . translate($lang["rules"]["filenotfound"]) . '</div>';
} else {
$file = readFileContent($path);
if (!$file) {
echo '<div class="alert alert-danger"><p class="text-center">' . translate($lang["rules"]["readerror"]) . '</div>';
} else {
?>
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title"><i class="fa fa-book" aria-hidden="true"></i> <?php tl($lang["rules"]["title"]); ?></h3>
</div>
<div class="panel-body">
<?php echo $parsedown->text($file); ?>
</div>
</div>
<?php
}}
// *******
// METHODS
// *******
function readFileContent($file) {
$fopen = @fopen($file, "r");
if (!$fopen) return false;
$text = fread($fopen, filesize($file));
fclose($fopen);
return $text;
}
require_once __DIR__ . "/include/footer.php";
?>
<?php
require_once __DIR__ . "/include/header.php";
require_once __DIR__ . "/include/tsutils.php";
require_once __DIR__ . "/include/cacheutils.class.php";
$cacheutils = new CacheUtils('tsviewer');
if($cacheutils->isExpired()) {
$cacheutils->setValue([getViewer(), date('d-m-Y H:i:s')], 300);
}
$tsviewer = $cacheutils->getValue();
// print_r ($tsviewer);
function getViewer() {
global $lang;
try {
$tsAdmin = getTeamspeakConnection("#no_query_clients");
$base = "lib/ts3phpframework/images";
return $tsAdmin->getViewer(new TeamSpeak3_Viewer_Html("$base/viewer/", "$base/flags/", "data:image"));
} catch (TeamSpeak3_Exception $e) {
return '<div class="alert alert-danger"><p class="text-center">' . translate($lang["general"]["scripterror"], [$e->getCode(), $e->getMessage()]) . '</p></div>';
}
}
?>
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title"><i class="fa fa-eye" aria-hidden="true"></i> <?php tl($lang["viewer"]["title"]); ?></h3>
</div>
<div class="panel-body">
<?php echo $tsviewer[0]; ?>
</div>
<div class="panel-footer">
<?php tl($lang["viewer"]["lastupdate"], [$tsviewer[1]]); ?><!-- <span style="float: right">Podgląd odświeża się co 30 sekund</span> -->
</div>
</div>
<?php
require_once __DIR__ . "/include/footer.php";
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment