🏡 index : ~doyle/zpan.git

author Jordan Doyle <jordan@doyle.wf> 2016-06-22 17:47:28.0 +00:00:00
committer Jordan Doyle <jordan@doyle.wf> 2016-06-22 17:47:28.0 +00:00:00
commit
022e5719555fbaeeba5c2a3620f145099bde1b12 [patch]
tree
c8c0772d16a7eb598a0d41f3f3fef977d1941e85
parent
378a23cc1f652b37b5fe4674a8026865b9d9f866
download
022e5719555fbaeeba5c2a3620f145099bde1b12.tar.gz

Add panel stats



Diff

 .env.example                             |   3 +-
 .gitignore                               |   1 +-
 app/Http/Controllers/StatsController.php |  27 +++-
 app/Http/routes.php                      |   2 +-
 app/Models/User.php                      |  10 +-
 app/Models/UserField.php                 |  20 +++-
 composer.json                            |   3 +-
 composer.lock                            | 224 +++++++++++++++++++++++++++++++-
 storage/stats.json                       |   1 +-
 9 files changed, 283 insertions(+), 8 deletions(-)

diff --git a/.env.example b/.env.example
index 48ded41..cc5d00c 100644
--- a/.env.example
+++ b/.env.example
@@ -15,6 +15,9 @@ DB_DATABASE=homestead
DB_USERNAME=homestead
DB_PASSWORD=secret

HABBO_FIELD=field7
SHOUTCAST_ADMIN=password

FORUM_CONNECTION=mysql
FORUM_HOST=127.0.0.1
FORUM_PORT=3306
diff --git a/.gitignore b/.gitignore
index d6e661a..7b2f0c5 100644
--- a/.gitignore
+++ b/.gitignore
@@ -8,3 +8,4 @@ Homestead.json
_ide_helper.php
.idea
bower_components
/storage/stats.json
diff --git a/app/Http/Controllers/StatsController.php b/app/Http/Controllers/StatsController.php
index 9592503..e794df3 100644
--- a/app/Http/Controllers/StatsController.php
+++ b/app/Http/Controllers/StatsController.php
@@ -4,7 +4,9 @@ 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 @@ class StatsController extends Controller
            $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 @@ class StatsController extends Controller
                        ->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) {
diff --git a/app/Http/routes.php b/app/Http/routes.php
index d81176d..82dac25 100644
--- a/app/Http/routes.php
+++ b/app/Http/routes.php
@@ -119,6 +119,6 @@ Route::group(['middleware' => 'api', 'as' => 'api::', 'prefix' => 'api'], functi
    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']);
});
diff --git a/app/Models/User.php b/app/Models/User.php
index d0b0f4c..2a9d0d4 100644
--- a/app/Models/User.php
+++ b/app/Models/User.php
@@ -50,6 +50,16 @@ class User extends Authenticatable
    }

    /**
     * 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
diff --git a/app/Models/UserField.php b/app/Models/UserField.php
new file mode 100644
index 0000000..71f5667
--- /dev/null
+++ b/app/Models/UserField.php
@@ -0,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;
}
diff --git a/composer.json b/composer.json
index 565a943..ab19571 100644
--- a/composer.json
+++ b/composer.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",
diff --git a/composer.lock b/composer.lock
index 631ffd4..9294f66 100644
--- a/composer.lock
+++ b/composer.lock
@@ -4,8 +4,8 @@
        "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": {
@@ -1579,6 +1750,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",
            "version": "1.0.0",
            "source": {
diff --git a/storage/stats.json b/storage/stats.json
deleted file mode 100644
index f001048..0000000
--- a/storage/stats.json
+++ /dev/null
@@ -1 +0,0 @@
{"dj":"Unset","listeners":2,"artist":"Sigma & Rita Ora","song":"Coming Home"}
\ No newline at end of file