$dataStore = new PBPanel\Util\DataStore();
$connection = new \PBPanel\Util\BotConnectionHandler($dataStore);
$functions = new \PBPanel\Util\FunctionLibrary($dataStore, $connection);
$templates = new \PBPanel\Util\ComponentTemplates();
if (\PBPanel\AppLoader::runInstall($dataStore)) {
    require_once 'install.php';
    exit;
}
if (\PBPanel\AppLoader::updateAvailable($dataStore)) {
    require_once 'update.php';
    exit;
}
$session->createToken();
$botSettings = $functions->getDbTableArray('settings');
$isBotOnline = $connection->testConnection()[2] == 52;
$hostHandlerActive = $functions->getDbTableValueByKey('modules.ini', 'hostHandler.js', true);
$subscribeHandlerActive = $functions->getDbTableValueByKey('modules.ini', 'subscribeHandler.js', true);
$musicPlayerCurrentSong = $functions->getOtherFile($dataStore->getVar('paths', 'youtubeCurrentSong'));
$NOHosts = -1;
$NOSubscribers = -1;
$partsList = $functions->getPartsList();
$renderedMenu = '';
foreach ($partsList as $parentName => $subItems) {
    $parentId = 'menu-parent-' . $parentName;
    $renderedMenu .= '<li class="dropdown" id="' . $parentId . '"><a nohref class="dropdown-toggle" role="button">' . ucwords($parentName) . '</a><ul class="dropdown-menu" role="menu">';
    $icon = 'fa-cog';
    switch ($parentName) {
        case 'games':
            $icon = 'fa-gamepad';
            break;
        case 'extras':
     if (array_key_exists('uri', $input)) {
         $functions->getDbTableArray($input['uri'], false);
     } else {
         $functions->sendBackError('Missing ini uri');
     }
     break;
 case 'getOtherFile':
     if (array_key_exists('uri', $input)) {
         $functions->getOtherFile($input['uri'], false);
     } else {
         $functions->sendBackError('Missing ini uri');
     }
     break;
 case 'getIniValueByKey':
     if (array_key_exists('uri', $input) && array_key_exists('key', $input)) {
         $functions->sendBackOk($functions->getDbTableValueByKey($input['uri'], $input['key']));
     } else {
         $functions->sendBackError('Missing parameters');
     }
     break;
 case 'getCurrentTitle':
     $functions->getCurrentTitle();
     break;
 case 'getMusicPlayerPlaylist':
     $functions->sendBackOk($functions->getMusicPlayerPlaylist($dataStore->getVar('paths', 'youtubePlaylist')));
     break;
 case 'saveToConfig':
     if (array_key_exists('settingPath', $input) && array_key_exists('setting', $input)) {
         $path = explode('/', $input['settingPath']);
         if ($dataStore->setVar($path[0], $path[1], $input['setting'])) {
             $functions->sendBackOk('Setting Saved');
require_once '../../../AppLoader.class.php';
\PBPanel\AppLoader::load();
$session = new \PBPanel\Util\PanelSession();
if (!$session->checkSessionToken(filter_input(INPUT_POST, 'token'))) {
    die('Invalid session token. Are you trying to hack me?!');
}
$dataStore = new \PBPanel\Util\DataStore();
$connection = new \PBPanel\Util\BotConnectionHandler($dataStore);
$functions = new \PBPanel\Util\FunctionLibrary($dataStore, $connection);
$templates = new \PBPanel\Util\ComponentTemplates();
$phpInput = $functions->getPhpInput();
$minTimeSec = 3600;
$viewersDataRows = '';
$groups = $functions->getDbTableArray('groups');
$psName = ucfirst($functions->getDbTableValueByKey('pointSettings', 'pointNameMultiple'));
$followers = $functions->getDbTableArray('followed');
$viewerGroups = $functions->getDbTableArray('group');
$lastSeen = $functions->getDbTableArray('lastseen');
$viewerRanks = $functions->getDbTableArray('viewerRanks');
$viewerPoints = $functions->getDbTableArray('points');
$viewerTime = $functions->getDbTableArray('time');
$incRaids = $functions->getDbTableArray('incommingRaids');
if ($psName == '0') {
    $psName = 'Points';
}
if (array_key_exists('time', $phpInput)) {
    $minTimeSec = intval($phpInput['time']);
}
$viewers = array_filter(array_keys($viewerTime), function ($username) use($viewerTime, $minTimeSec) {
    return intval($viewerTime[$username]) > $minTimeSec;
/**
 * Created by PhpStorm.
 * User: Robin | Juraji
 * Date: 10-12-2015
 * Time: 19:49
 */
require_once '../../AppLoader.class.php';
\PBPanel\AppLoader::load();
$dataStore = new \PBPanel\Util\DataStore();
$connection = new PBPanel\Util\BotConnectionHandler($dataStore);
$functions = new \PBPanel\Util\FunctionLibrary($dataStore, $connection);
$templates = new \PBPanel\Util\ComponentTemplates();
// Call this file like ".../external-example2.php?username=[USERNAME]"
$username = filter_input(INPUT_GET, 'username');
if ($username) {
    $singleUserPoints = $functions->getDbTableValueByKey('points', strtolower($username), true);
} else {
    die('Call this file like ".../external-example2.php?username=[USERNAME]"');
}
?>
<!DOCTYPE html>
<html>
<head lang="en">
  <meta charset="UTF-8">
  <title></title>
  <link href="app/css/<?php 
echo $dataStore->getVar('misc', 'theme', 'style_dark');
?>
.css"
        rel="stylesheet" type="text/css"/>
  <link rel="icon" href="../../favicon.ico" type="image/x-icon"/>
<?php

/**
 * Created by PhpStorm.
 * User: Robin | Juraji
 * Date: 10-12-2015
 * Time: 19:49
 */
require_once '../../AppLoader.class.php';
\PBPanel\AppLoader::load();
$dataStore = new \PBPanel\Util\DataStore();
$connection = new PBPanel\Util\BotConnectionHandler($dataStore);
$functions = new \PBPanel\Util\FunctionLibrary($dataStore, $connection);
$templates = new \PBPanel\Util\ComponentTemplates();
// Call this file like ".../external-example2-api-like.php?username=[USERNAME]"
$username = filter_input(INPUT_GET, 'username');
if ($username) {
    $userTime = intval($functions->getDbTableValueByKey('time', strtolower($username), true));
    echo json_encode(['username' => $username, 'points' => $functions->getDbTableValueByKey('points', strtolower($username), true), 'timeInSeconds' => $userTime, 'timeHMS' => sprintf("%02d%s%02d%s%02d", floor($userTime / 3600), ':', $userTime / 60 % 60, ':', $userTime % 60)]);
} else {
    die('Call this file like ".../external-example2-api-like.php?username=[USERNAME]"');
}