Add panel stats
Diff
.env.example | 3 +++
.gitignore | 1 +
composer.json | 3 ++-
composer.lock | 224 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
storage/stats.json | 1 -
app/Http/routes.php | 2 +-
app/Models/User.php | 10 ++++++++++
app/Models/UserField.php | 20 ++++++++++++++++++++
app/Http/Controllers/StatsController.php | 27 ++++++++++++++++++++++++++-
9 files changed, 283 insertions(+), 8 deletions(-)
@@ -15,6 +15,9 @@
DB_USERNAME=homestead
DB_PASSWORD=secret
HABBO_FIELD=field7
SHOUTCAST_ADMIN=password
FORUM_CONNECTION=mysql
FORUM_HOST=127.0.0.1
FORUM_PORT=3306
@@ -8,3 +8,4 @@
_ide_helper.php
.idea
bower_components
/storage/stats.json
@@ -15,7 +15,8 @@
"pusher/pusher-php-server": "^2.4",
"vinkla/pusher": "^2.3",
"matto1990/lastfm-api": "^1.2",
"barryvdh/laravel-debugbar": "^2.2"
"barryvdh/laravel-debugbar": "^2.2",
"guzzlehttp/guzzle": "^6.2"
},
"require-dev": {
"fzaninotto/faker": "~1.4",
@@ -1,11 +1,11 @@
{
"_readme": [
"This file locks the dependencies of your project to a known state",
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically"
],
"hash": "8b016d3e58f6580f0512a20c8972dcb2",
"content-hash": "221d4887f8f973a10cb8d082d012ebb9",
"hash": "c8ebcba5d02048a924fd8e48bdf1649e",
"content-hash": "9044440d7da7de27e7c6fd6818d2b919",
"packages": [
{
"name": "barryvdh/laravel-cors",
@@ -793,6 +793,177 @@
"time": "2016-04-26 14:27:59"
},
{
"name": "guzzlehttp/guzzle",
"version": "6.2.0",
"source": {
"type": "git",
"url": "https://github.com/guzzle/guzzle.git",
"reference": "d094e337976dff9d8e2424e8485872194e768662"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/guzzle/guzzle/zipball/d094e337976dff9d8e2424e8485872194e768662",
"reference": "d094e337976dff9d8e2424e8485872194e768662",
"shasum": ""
},
"require": {
"guzzlehttp/promises": "~1.0",
"guzzlehttp/psr7": "~1.1",
"php": ">=5.5.0"
},
"require-dev": {
"ext-curl": "*",
"phpunit/phpunit": "~4.0",
"psr/log": "~1.0"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "6.2-dev"
}
},
"autoload": {
"files": [
"src/functions_include.php"
],
"psr-4": {
"GuzzleHttp\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Michael Dowling",
"email": "mtdowling@gmail.com",
"homepage": "https://github.com/mtdowling"
}
],
"description": "Guzzle is a PHP HTTP client library",
"homepage": "http://guzzlephp.org/",
"keywords": [
"client",
"curl",
"framework",
"http",
"http client",
"rest",
"web service"
],
"time": "2016-03-21 20:02:09"
},
{
"name": "guzzlehttp/promises",
"version": "1.2.0",
"source": {
"type": "git",
"url": "https://github.com/guzzle/promises.git",
"reference": "c10d860e2a9595f8883527fa0021c7da9e65f579"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/guzzle/promises/zipball/c10d860e2a9595f8883527fa0021c7da9e65f579",
"reference": "c10d860e2a9595f8883527fa0021c7da9e65f579",
"shasum": ""
},
"require": {
"php": ">=5.5.0"
},
"require-dev": {
"phpunit/phpunit": "~4.0"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.0-dev"
}
},
"autoload": {
"psr-4": {
"GuzzleHttp\\Promise\\": "src/"
},
"files": [
"src/functions_include.php"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Michael Dowling",
"email": "mtdowling@gmail.com",
"homepage": "https://github.com/mtdowling"
}
],
"description": "Guzzle promises library",
"keywords": [
"promise"
],
"time": "2016-05-18 16:56:05"
},
{
"name": "guzzlehttp/psr7",
"version": "1.3.0",
"source": {
"type": "git",
"url": "https://github.com/guzzle/psr7.git",
"reference": "31382fef2889136415751badebbd1cb022a4ed72"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/guzzle/psr7/zipball/31382fef2889136415751badebbd1cb022a4ed72",
"reference": "31382fef2889136415751badebbd1cb022a4ed72",
"shasum": ""
},
"require": {
"php": ">=5.4.0",
"psr/http-message": "~1.0"
},
"provide": {
"psr/http-message-implementation": "1.0"
},
"require-dev": {
"phpunit/phpunit": "~4.0"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.0-dev"
}
},
"autoload": {
"psr-4": {
"GuzzleHttp\\Psr7\\": "src/"
},
"files": [
"src/functions_include.php"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Michael Dowling",
"email": "mtdowling@gmail.com",
"homepage": "https://github.com/mtdowling"
}
],
"description": "PSR-7 message implementation",
"keywords": [
"http",
"message",
"stream",
"uri"
],
"time": "2016-04-13 19:56:01"
},
{
"name": "jakub-onderka/php-console-color",
"version": "0.1",
"source": {
@@ -1577,6 +1748,55 @@
}
],
"time": "2015-02-03 12:10:50"
},
{
"name": "psr/http-message",
"version": "1.0",
"source": {
"type": "git",
"url": "https://github.com/php-fig/http-message.git",
"reference": "85d63699f0dbedb190bbd4b0d2b9dc707ea4c298"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/php-fig/http-message/zipball/85d63699f0dbedb190bbd4b0d2b9dc707ea4c298",
"reference": "85d63699f0dbedb190bbd4b0d2b9dc707ea4c298",
"shasum": ""
},
"require": {
"php": ">=5.3.0"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.0.x-dev"
}
},
"autoload": {
"psr-4": {
"Psr\\Http\\Message\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "PHP-FIG",
"homepage": "http://www.php-fig.org/"
}
],
"description": "Common interface for HTTP messages",
"keywords": [
"http",
"http-message",
"psr",
"psr-7",
"request",
"response"
],
"time": "2015-05-04 20:22:00"
},
{
"name": "psr/log",
@@ -1,1 +1,0 @@
{"dj":"Unset","listeners":2,"artist":"Sigma & Rita Ora","song":"Coming Home"}
@@ -119,6 +119,6 @@
Route::get('timetable', ['as' => 'timetable', 'uses' => 'DJ\TimetableController@getJSONTimetable']);
Route::get('event/all', ['as' => 'events', 'uses' => 'Event\TimetableController@getJSONTimetable']);
Route::get('event/current', ['as' => 'event.current', 'uses' => 'Event\TimetableController@getCurrentEvent']);
Route::get('stats', ['as' => 'stats', 'uses' => 'StatsController@s']);
Route::get('stats', ['as' => 'stats', 'uses' => 'StatsController@index']);
Route::post('request', ['as' => 'request', 'uses' => 'DJ\RequestController@request']);
});
@@ -50,6 +50,16 @@
}
/**
* Get this user's custom fields.
*
* @return HasOne
*/
public function fields()
{
return $this->hasOne(UserField::class, 'userid');
}
/**
* Get this user's display group.
*
* @return Group
@@ -1,0 +1,20 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Watson\Rememberable\Rememberable;
/**
* Custom fields set by the user on the forum.
*
* @author Jordan Doyle <jordan@doyle.wf>
*/
class UserField extends Model
{
use Rememberable;
protected $connection = 'forum';
protected $table = 'userfield';
protected $primaryKey = 'userid';
public $timestamps = false;
}
@@ -1,10 +1,12 @@
<?php
namespace App\Http\Controllers;
use App\Http\Requests;
use App\Models\ConnectionInfo;
use App\Models\Timetable;
use App\Models\User;
use Carbon\Carbon;
use GuzzleHttp\Client;
use LastFmApi\Api\AuthApi;
use LastFmApi\Api\TrackApi;
use stdClass;
@@ -30,12 +32,12 @@
$ret = [];
if (empty($stats->songtitle)) {
$ret = ['status' => false];
return ['status' => false];
} else {
$old = file_exists(storage_path('stats.json')) ?
json_decode(file_get_contents(storage_path('stats.json'))) : false;
$ret['dj'] = empty($stats->dj) ? ($old ? $old->dj : 'Unset') : $stats->dj;
$ret['dj'] = empty($stats->dj) ? ($old ? $old->dj : false) : $stats->dj;
$ret['listeners'] = $stats->currentlisteners;
if (!$ret['dj']) {
@@ -45,7 +47,26 @@
->where('hour', Carbon::now()->hour)
->first();
$ret['dj'] = $timetable ? $timetable->user->getDisplayName()->toHtml() : 'Offline';
$ret['raw_dj'] = $timetable ? $timetable->user->username : 'Offline';
$ret['dj'] = $ret['raw_dj'];
}
if ($ret['raw_dj'] !== 'Offline') {
$user = User::where('username', $ret['raw_dj'])->first();
if (!$user) {
// user doesn't exist (unknown user/slot isn't booked), kick him from the radio.
$client = new Client;
$client->request('GET', "http://{$connection->ip}:{$connection->port}/admin.cgi?sid=1&mode=kicksrc", [
'auth' => ['admin', env('SHOUTCAST_ADMIN')]
]);
abort(404);
}
$ret['dj'] = $user->getDisplayName()->toHtml();
$ret['habbo'] = $user->fields->{env('HABBO_FIELD')};
} else {
$ret['habbo'] = '';
}
if (count(explode(' - ', $stats->songtitle, 2)) == 2) {