* Date: 12 okt 2015
 * Time: 12:47
 */
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();
$botSettings = $functions->getDbTableArray('settings');
$youtubePlayerSettings = $functions->getDbTableArray('youtubePlayer');
$requestQueue = preg_split('/\\n/', trim($functions->getOtherFile($dataStore->getVar('paths', 'youtubePlaylist'))));
$defaultPlaylist = preg_split('/\\n/', trim($functions->getOtherFile($dataStore->getVar('paths', 'defaultYoutubePlaylist'))));
$defaultPlaylistLength = 0;
$requestQueueLength = 0;
$requestQueueDataRows = '';
$defaultPlaylistDataRows = '';
foreach ($defaultPlaylist as $item) {
    preg_match('/[0-9]+\\.\\s(.*)\\s\\(([a-z0-9=?\\/.:_-]+)\\)$/i', $functions->cleanYTVideoTitle($item), $matches);
    $defaultPlaylistDataRows .= '<tr><td>' . ($defaultPlaylistLength + 1) . '.</td><td>' . trim($matches[1]) . '</td><td><div class="btn-toolbar" style="width:125px;">' . $templates->botCommandButton('playsong ' . str_replace('https://youtube.com/watch?v=', '', $matches[2]), '<span class="fa fa-play"></span>', 'success btn-sm') . $templates->botCommandButton('musicplayer deldefault ' . $defaultPlaylistLength, '<span class="fa fa-trash"></span>', 'danger btn-sm') . $templates->botCommandButton('d !chat Youtube link for ' . $matches[1] . ' -> ' . $matches[2], '<span class="fa fa-link"></span>', 'default btn-sm') . '</div></td></tr>';
    ++$defaultPlaylistLength;
}
foreach ($requestQueue as $item) {
    if ($item == '') {
        continue;
    }
    preg_match('/(.*)\\s\\(.+\\s([a-z0-9_]+)\\)$/i', $functions->cleanYTVideoTitle($item), $matches);
 * User: Robin | Juraji
 * Date: 12 okt 2015
 * Time: 12:47
 */
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();
$pointSettings = $functions->getDbTableArray('pointSettings');
$raffleFiles = array_reverse(preg_split('/\\n/', trim($functions->getOtherFile('./addons/raffleSystem/'))));
$previousRaffleFileDataRows = '';
foreach ($raffleFiles as $id => $raffleFile) {
    if ($raffleFile == '') {
        continue;
    }
    $fileContents = preg_split('/\\n/', str_replace('New Raffle: ', '', $functions->getOtherFile('./addons/raffleSystem/' . $raffleFile)));
    $previousRaffleFileDataRows .= '<tr>' . '<td>' . getRaffleFileDateString($raffleFile) . ($id == 0 ? '<br /><span class="text-muted">(Entire file)</span>' : '') . '</td>' . '<td>' . ($id == 0 ? join('<br />', $fileContents) : $fileContents[0]) . '</td>' . '</tr>';
}
function getRaffleFileDateString($raffleFile)
{
    $raffleFile = str_replace(['raffle_', '.txt'], '', $raffleFile);
    $fileDate = DateTime::createFromFormat('d-m-Y_G:i:s_e', $raffleFile);
    return $fileDate ? $fileDate->format('d-m-Y H:i:s') : '';
}
?>
$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':
            $icon = 'fa-plug';
            break;
     if (array_key_exists('command', $input) && $input['username']) {
         echo json_encode($connection->send('!' . $input['command'], array_key_exists(strtolower($input['username']), $functions->getDbTableArray('visited')) ? $input['username'] : $dataStore->getVar('connector', 'channelOwner')));
     } else {
         $functions->sendBackError('Command is empty');
     }
     break;
 case 'getIni':
     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':
/**
 * Created by PhpStorm.
 * User: Robin | Juraji
 * Date: 14-12-2015
 * Time: 15:34
 */
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();
$fileName = filter_input(INPUT_GET, 'file');
$logDataRows = '';
if ($fileName) {
    $logFileContents = preg_split('/\\n/', trim($functions->getOtherFile($fileName)));
    foreach ($logFileContents as $line) {
        $logDataRows .= '<tr><td>' . $line . '</td></tr>';
    }
}
?>
<!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"/>
 * Time: 12:41
 */
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();
$botSettings = $functions->getDbTableArray('settings');
$botStreamInfo = $functions->getDbTableArray('streamInfo');
$noticeCount = count($functions->getDbTableArray('notices'));
$latestFollower = checkFile($functions->getOtherFile($dataStore->getVar('paths', 'latestFollower')));
$latestDonator = checkFile($functions->getOtherFile($dataStore->getVar('paths', 'latestDonation')));
function checkFile($file)
{
    return trim($file) == '' || substr(trim($file), 0, 1) == '<' ? false : $file;
}
?>
<div class="app-part">
  <div class="panel panel-default">
    <div class="panel-heading">
      <h3 class="panel-title">Dashboard <span class="text-muted">Update stream info</span></h3>
    </div>
    <div class="panel-body">
      <?php 
echo $latestFollower ? '<h4><small>Latest Follower</small> ' . $latestFollower . '</h4>' : '';
?>