diff --git a/composer.lock b/composer.lock index fb7a3ad..2582fb5 100755 --- a/composer.lock +++ b/composer.lock @@ -1,24 +1,23 @@ { "_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", + "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "hash": "25cbf2308918f775e251cffcf914c557", - "content-hash": "a9efe46743688d5b1f2f64de7f780195", + "content-hash": "85fd9d3cc030402a776db7f7553ced3f", "packages": [ { "name": "composer/installers", - "version": "v1.0.24", + "version": "v1.5.0", "source": { "type": "git", "url": "https://github.com/composer/installers.git", - "reference": "1cf7cc4b89d5e8549bbb7d6ab1de75da13d27988" + "reference": "049797d727261bf27f2690430d935067710049c2" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/composer/installers/zipball/1cf7cc4b89d5e8549bbb7d6ab1de75da13d27988", - "reference": "1cf7cc4b89d5e8549bbb7d6ab1de75da13d27988", + "url": "https://api.github.com/repos/composer/installers/zipball/049797d727261bf27f2690430d935067710049c2", + "reference": "049797d727261bf27f2690430d935067710049c2", "shasum": "" }, "require": { @@ -30,7 +29,7 @@ }, "require-dev": { "composer/composer": "1.0.*@dev", - "phpunit/phpunit": "4.1.*" + "phpunit/phpunit": "^4.8.36" }, "type": "composer-plugin", "extra": { @@ -60,71 +59,92 @@ "keywords": [ "Craft", "Dolibarr", + "Eliasis", "Hurad", "ImageCMS", + "Kanboard", + "Lan Management System", "MODX Evo", "Mautic", + "Maya", "OXID", + "Plentymarkets", + "Porto", + "RadPHP", "SMF", "Thelia", "WolfCMS", "agl", "aimeos", "annotatecms", + "attogram", "bitrix", "cakephp", "chef", + "cockpit", "codeigniter", "concrete5", "croogo", "dokuwiki", "drupal", + "eZ Platform", "elgg", + "expressionengine", "fuelphp", "grav", "installer", + "itop", "joomla", "kohana", "laravel", + "lavalite", "lithium", "magento", + "majima", "mako", "mediawiki", "modulework", + "modx", "moodle", + "osclass", "phpbb", "piwik", "ppi", "puppet", + "pxcms", + "reindex", "roundcube", "shopware", "silverstripe", + "sydes", "symfony", "typo3", "wordpress", + "yawik", "zend", "zikula" ], - "time": "2016-04-05 11:42:46" + "time": "2017-12-29T09:13:20+00:00" }, { "name": "fuel/auth", - "version": "dev-1.8/master", + "version": "1.8.1", "source": { "type": "git", "url": "https://github.com/fuel/auth.git", - "reference": "a645dbe2f80b6b4cecb069b57ea70150b6e53929" + "reference": "b19a63e27903760d41a8641b8a42b1ddaaa646f2" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/fuel/auth/zipball/a645dbe2f80b6b4cecb069b57ea70150b6e53929", - "reference": "a645dbe2f80b6b4cecb069b57ea70150b6e53929", + "url": "https://api.github.com/repos/fuel/auth/zipball/b19a63e27903760d41a8641b8a42b1ddaaa646f2", + "reference": "b19a63e27903760d41a8641b8a42b1ddaaa646f2", "shasum": "" }, "require": { "composer/installers": "~1.0" }, "type": "fuel-package", + "notification-url": "https://packagist.org/downloads/", "license": [ "MIT" ], @@ -136,30 +156,27 @@ ], "description": "FuelPHP 1.x Auth Package", "homepage": "https://github.com/fuel/auth", - "support": { - "source": "https://github.com/fuel/auth/tree/1.8/develop", - "issues": "https://github.com/fuel/auth/issues" - }, - "time": "2016-01-23 12:30:25" + "time": "2018-04-18T14:45:14+00:00" }, { "name": "fuel/core", - "version": "dev-1.8/master", + "version": "1.8.0.3", "source": { "type": "git", "url": "https://github.com/fuel/core.git", - "reference": "26f6432a9f41659280c70ba47c16170adf1e7611" + "reference": "c8e190b22cb9fc1a9acfdde4ed7487e04051bbe7" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/fuel/core/zipball/26f6432a9f41659280c70ba47c16170adf1e7611", - "reference": "26f6432a9f41659280c70ba47c16170adf1e7611", + "url": "https://api.github.com/repos/fuel/core/zipball/c8e190b22cb9fc1a9acfdde4ed7487e04051bbe7", + "reference": "c8e190b22cb9fc1a9acfdde4ed7487e04051bbe7", "shasum": "" }, "require": { "composer/installers": "~1.0" }, "type": "fuel-package", + "notification-url": "https://packagist.org/downloads/", "license": [ "MIT" ], @@ -171,30 +188,27 @@ ], "description": "FuelPHP 1.x Core", "homepage": "https://github.com/fuel/core", - "support": { - "source": "https://github.com/fuel/core/tree/1.8/master", - "issues": "https://github.com/fuel/core/issues" - }, - "time": "2016-04-09 16:28:31" + "time": "2016-07-21T08:45:05+00:00" }, { "name": "fuel/email", - "version": "dev-1.8/master", + "version": "1.8.1", "source": { "type": "git", "url": "https://github.com/fuel/email.git", - "reference": "79133b3951068bbcff9a9c7b77f9f27a777ebdbd" + "reference": "a12df7db925c81f3ace52cdec3dfd925193c8e4b" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/fuel/email/zipball/79133b3951068bbcff9a9c7b77f9f27a777ebdbd", - "reference": "79133b3951068bbcff9a9c7b77f9f27a777ebdbd", + "url": "https://api.github.com/repos/fuel/email/zipball/a12df7db925c81f3ace52cdec3dfd925193c8e4b", + "reference": "a12df7db925c81f3ace52cdec3dfd925193c8e4b", "shasum": "" }, "require": { "composer/installers": "~1.0" }, "type": "fuel-package", + "notification-url": "https://packagist.org/downloads/", "license": [ "MIT" ], @@ -206,30 +220,27 @@ ], "description": "FuelPHP 1.x Email Package", "homepage": "https://github.com/fuel/email", - "support": { - "source": "https://github.com/fuel/email/tree/1.8/develop", - "issues": "https://github.com/fuel/email/issues" - }, - "time": "2016-01-23 12:31:34" + "time": "2018-04-18T14:49:14+00:00" }, { "name": "fuel/oil", - "version": "dev-1.8/master", + "version": "1.8.1.1", "source": { "type": "git", "url": "https://github.com/fuel/oil.git", - "reference": "b29b80f29f090b9ad12b931da6e979587de6ced1" + "reference": "548d0fc1c07793e21128ecd4ebf5badc36908865" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/fuel/oil/zipball/b29b80f29f090b9ad12b931da6e979587de6ced1", - "reference": "b29b80f29f090b9ad12b931da6e979587de6ced1", + "url": "https://api.github.com/repos/fuel/oil/zipball/548d0fc1c07793e21128ecd4ebf5badc36908865", + "reference": "548d0fc1c07793e21128ecd4ebf5badc36908865", "shasum": "" }, "require": { "composer/installers": "~1.0" }, "type": "fuel-package", + "notification-url": "https://packagist.org/downloads/", "license": [ "MIT" ], @@ -241,30 +252,27 @@ ], "description": "FuelPHP 1.x Oil Package", "homepage": "https://github.com/fuel/oil", - "support": { - "source": "https://github.com/fuel/oil/tree/1.8/develop", - "issues": "https://github.com/fuel/oil/issues" - }, - "time": "2016-01-23 12:32:54" + "time": "2018-05-03T20:59:29+00:00" }, { "name": "fuel/orm", - "version": "dev-1.8/master", + "version": "1.8.1.2", "source": { "type": "git", "url": "https://github.com/fuel/orm.git", - "reference": "2c1da635127c9fbedc9c76132fc904188892c365" + "reference": "372a5ffbbef797c4532eaf0283c9483309809206" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/fuel/orm/zipball/2c1da635127c9fbedc9c76132fc904188892c365", - "reference": "2c1da635127c9fbedc9c76132fc904188892c365", + "url": "https://api.github.com/repos/fuel/orm/zipball/372a5ffbbef797c4532eaf0283c9483309809206", + "reference": "372a5ffbbef797c4532eaf0283c9483309809206", "shasum": "" }, "require": { "composer/installers": "~1.0" }, "type": "fuel-package", + "notification-url": "https://packagist.org/downloads/", "license": [ "MIT" ], @@ -276,30 +284,27 @@ ], "description": "FuelPHP 1.x ORM Package", "homepage": "https://github.com/fuel/orm", - "support": { - "source": "https://github.com/fuel/orm/tree/1.8/develop", - "issues": "https://github.com/fuel/orm/issues" - }, - "time": "2016-02-07 12:09:12" + "time": "2018-04-22T10:09:22+00:00" }, { "name": "fuel/parser", - "version": "dev-1.8/master", + "version": "1.8.1", "source": { "type": "git", "url": "https://github.com/fuel/parser.git", - "reference": "bec50ec304e696d72dba7f13494828532c6e18df" + "reference": "c8725e112ef59f70f73ddff754a9fe762229fa88" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/fuel/parser/zipball/bec50ec304e696d72dba7f13494828532c6e18df", - "reference": "bec50ec304e696d72dba7f13494828532c6e18df", + "url": "https://api.github.com/repos/fuel/parser/zipball/c8725e112ef59f70f73ddff754a9fe762229fa88", + "reference": "c8725e112ef59f70f73ddff754a9fe762229fa88", "shasum": "" }, "require": { "composer/installers": "~1.0" }, "type": "fuel-package", + "notification-url": "https://packagist.org/downloads/", "license": [ "MIT" ], @@ -311,11 +316,7 @@ ], "description": "FuelPHP 1.x Parser Package", "homepage": "https://github.com/fuel/parser", - "support": { - "source": "https://github.com/fuel/parser/tree/1.8/develop", - "issues": "https://github.com/fuel/parser/issues" - }, - "time": "2016-03-12 12:08:41" + "time": "2018-04-18T14:52:18+00:00" }, { "name": "fuelphp/upload", @@ -365,7 +366,7 @@ "file uploads", "upload" ], - "time": "2015-11-04 17:19:56" + "time": "2015-11-04T17:19:56+00:00" }, { "name": "michelf/php-markdown", @@ -416,7 +417,7 @@ "keywords": [ "markdown" ], - "time": "2013-11-29 17:09:24" + "time": "2013-11-29T17:09:24+00:00" }, { "name": "monolog/monolog", @@ -478,7 +479,7 @@ "logging", "psr-3" ], - "time": "2013-04-23 10:09:48" + "time": "2013-04-23T10:09:48+00:00" }, { "name": "phpseclib/phpseclib", @@ -566,26 +567,34 @@ "x.509", "x509" ], - "time": "2015-08-04 04:48:03" + "time": "2015-08-04T04:48:03+00:00" }, { "name": "psr/log", - "version": "1.0.0", + "version": "1.0.2", "source": { "type": "git", "url": "https://github.com/php-fig/log.git", - "reference": "fe0936ee26643249e916849d48e3a51d5f5e278b" + "reference": "4ebe3a8bf773a19edfe0a84b6585ba3d401b724d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/php-fig/log/zipball/fe0936ee26643249e916849d48e3a51d5f5e278b", - "reference": "fe0936ee26643249e916849d48e3a51d5f5e278b", + "url": "https://api.github.com/repos/php-fig/log/zipball/4ebe3a8bf773a19edfe0a84b6585ba3d401b724d", + "reference": "4ebe3a8bf773a19edfe0a84b6585ba3d401b724d", "shasum": "" }, + "require": { + "php": ">=5.3.0" + }, "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, "autoload": { - "psr-0": { - "Psr\\Log\\": "" + "psr-4": { + "Psr\\Log\\": "Psr/Log/" } }, "notification-url": "https://packagist.org/downloads/", @@ -599,33 +608,35 @@ } ], "description": "Common interface for logging libraries", + "homepage": "https://github.com/php-fig/log", "keywords": [ "log", "psr", "psr-3" ], - "time": "2012-12-21 11:40:51" + "time": "2016-10-10T12:19:37+00:00" } ], "packages-dev": [ { "name": "fuel/docs", - "version": "dev-1.8/master", + "version": "1.8.1", "source": { "type": "git", "url": "https://github.com/fuel/docs.git", - "reference": "d16972d39cef5f936779fca83bb19037cc2a3140" + "reference": "819d65d744ef29cacec96649a6f39be28c854038" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/fuel/docs/zipball/d16972d39cef5f936779fca83bb19037cc2a3140", - "reference": "d16972d39cef5f936779fca83bb19037cc2a3140", + "url": "https://api.github.com/repos/fuel/docs/zipball/819d65d744ef29cacec96649a6f39be28c854038", + "reference": "819d65d744ef29cacec96649a6f39be28c854038", "shasum": "" }, "require": { "composer/installers": "~1.0" }, "type": "fuel-package", + "notification-url": "https://packagist.org/downloads/", "license": [ "MIT" ], @@ -637,28 +648,16 @@ ], "description": "FuelPHP 1.x Documenataion", "homepage": "https://github.com/fuel/docs", - "support": { - "source": "https://github.com/fuel/docs/tree/1.8/master", - "issues": "https://github.com/fuel/docs/issues" - }, - "time": "2016-04-09 11:48:09" + "time": "2018-04-17T16:29:24+00:00" } ], "aliases": [], "minimum-stability": "stable", - "stability-flags": { - "fuel/core": 20, - "fuel/auth": 20, - "fuel/email": 20, - "fuel/oil": 20, - "fuel/orm": 20, - "fuel/parser": 20, - "fuel/docs": 20 - }, + "stability-flags": [], "prefer-stable": false, "prefer-lowest": false, "platform": { - "php": ">=5.3.3" + "php": ">=5.6.33" }, "platform-dev": [] } diff --git a/composer.phar b/composer.phar index 7e548b6..96fa2df 100755 Binary files a/composer.phar and b/composer.phar differ diff --git a/fuel/app/classes/controller/admin.php b/fuel/app/classes/controller/admin.php index 71caa62..2df54ef 100755 --- a/fuel/app/classes/controller/admin.php +++ b/fuel/app/classes/controller/admin.php @@ -1,22 +1,60 @@ admin) + if(!$user) Response::redirect('/login'); + + if(!$user->admin) + Response::redirect('/home'); + + $this->template->user = Session::get('user'); + + $this->template->js_bottom = []; } public function action_index() { - Response::forge(View::forge('admin/index')); + $body = View::forge('admin/index'); + + $this->template->body = $body; + } + + public function action_servers() + { + $this->template->js_bottom = ['plex_alert.js', 'server_refresh.js']; + + $body = View::forge('admin/servers'); + + $servers = Model_Server::find_all(); + + $body->set('servers', $servers); + + $this->template->body = $body; + } + + public function action_users() + { + $this->template->js_bottom = ['plex_alert.js']; + + $body = View::forge('admin/users'); + + $users = Model_User::find_all(); + + $body->set('users', $users); + + $this->template->body = $body; } } \ No newline at end of file diff --git a/fuel/app/classes/controller/admin/libraries.php b/fuel/app/classes/controller/admin/libraries.php new file mode 100644 index 0000000..490145c --- /dev/null +++ b/fuel/app/classes/controller/admin/libraries.php @@ -0,0 +1,36 @@ +template->js_bottom = ['plex_alert.js', 'server_refresh.js']; + + $body = View::forge('admin/libraries'); + + $libraries = Model_Library::find_all(); + + $body->set('libraries', $libraries); + + $this->template->body = $body; + } + + public function action_permissions() + { + $this->template->js_bottom = ['plex_alert.js']; + + $body = View::forge('admin/libraries/permissions'); + + $library_id = $this->param('library_id'); + + $permissions = Model_Permission::find_all(); + + $body->set('permissions', $permissions); + $body->set('user', Session::get('user')); + + $this->template->body = $body; + } +} \ No newline at end of file diff --git a/fuel/app/classes/controller/home.php b/fuel/app/classes/controller/home.php index decdc7b..7395b05 100755 --- a/fuel/app/classes/controller/home.php +++ b/fuel/app/classes/controller/home.php @@ -12,23 +12,25 @@ class Controller_Home extends Controller_Template public function before() { parent::before(); + $user = Session::get('user'); $sessionServer = Session::get('server'); - $sessionLibraries = Session::get('libraries'); if(!$user) Response::redirect('/login'); - $server = $sessionServer ? Model_Server::find_by_pk($sessionServer->id) : Model_Server::find_all()[0]; + $server = $sessionServer ? Model_Server::find_by_pk($sessionServer->id) : Model_Server::find_one_by('user_id', $user->id); if(!$server) Response::redirect('/login'); - $libraries = $sessionLibraries ?: $server->getLibraries(); + //var_dump($sessionLibraries);die(); + + $libraries = $server->getLibraries(); $this->template->user = Session::get('user'); - $this->template->server = $server; - $this->template->libraries = $libraries; + $this->template->MenuServer = $server; + $this->template->MenuLibraries = $libraries; $this->template->js_bottom = ['clappr.min.js', 'player.js']; } @@ -39,21 +41,21 @@ class Controller_Home extends Controller_Template $server_id = $this->param('server_id'); - if($server_id) { + if($server_id !== NULL) { $server = Model_Server::find_by_pk($server_id); if($server) - $this->template->server = $server; + $this->template->MenuServer = $server; } - $this->template->libraries = $this->template->server->getLibraries(); + Session::delete('server'); + Session::set('server', $this->template->MenuServer); - Session::set('server', $this->template->server); - Session::set('libraries', $this->template->libraries); + $this->template->MenuLibraries = $this->template->MenuServer->getLibraries(); - $episodes = Model_Movie::getThirtyLastedTvShows($this->template->server); + $episodes = Model_Movie::getThirtyLastedTvShows($this->template->MenuServer); - $movies = Model_Movie::getThirtyLastedMovies($this->template->server); + $movies = Model_Movie::getThirtyLastedMovies($this->template->MenuServer); $body->set('episodes', $episodes); $body->set('movies', $movies); diff --git a/fuel/app/classes/controller/library.php b/fuel/app/classes/controller/library.php index 9b9e24a..2e72133 100644 --- a/fuel/app/classes/controller/library.php +++ b/fuel/app/classes/controller/library.php @@ -22,9 +22,17 @@ class Controller_Library extends Controller_Home $content = null; if($library->type === 'movie') { - $content = Model_Movie::find_by('library_id', $library->id); + $content = Model_Movie::find_by(function ($query) use ($library_id){ + $query->where('library_id', $library_id) + ->order_by('title', 'ASC') + ; + }); } else if($library->type === 'show') { - $content = Model_Tvshow::find_by('library_id', $library->id); + $content = Model_Tvshow::find_by(function ($query) use ($library_id){ + $query->where('library_id', $library_id) + ->order_by('title', 'ASC') + ; + }); } $body->set('movies', $content); diff --git a/fuel/app/classes/controller/login.php b/fuel/app/classes/controller/login.php index 79ba833..2cbc7c1 100755 --- a/fuel/app/classes/controller/login.php +++ b/fuel/app/classes/controller/login.php @@ -35,6 +35,9 @@ class Controller_Login extends Controller if (Input::method() === 'POST') { if($user = Model_User::Login($login, $password)) { + $user->lastlogin = time(); + $user->save(); + Session::set('user', $user); Response::redirect('/home'); } diff --git a/fuel/app/classes/controller/logout.php b/fuel/app/classes/controller/logout.php index 00f8540..078a2f4 100644 --- a/fuel/app/classes/controller/logout.php +++ b/fuel/app/classes/controller/logout.php @@ -3,11 +3,6 @@ use Fuel\Core\Controller; use Fuel\Core\Response; use Fuel\Core\Session; -use Fuel\Core\View; -use Fuel\Core\Asset; -use Fuel\Core\Input; -use Fuel\Core\Config; -use Fuel\Core\FuelException; class Controller_Logout extends Controller { diff --git a/fuel/app/classes/controller/rest/browse.php b/fuel/app/classes/controller/rest/browse.php index 142c0cd..280aa92 100644 --- a/fuel/app/classes/controller/rest/browse.php +++ b/fuel/app/classes/controller/rest/browse.php @@ -26,25 +26,32 @@ class Controller_Rest_Browse extends Controller_Rest } if(!$server) - $this->response(array('error' => true, 'message' => 'No server found!')); + return $this->response(array('error' => true, 'message' => 'No server found!')); $this->response($server); } public function get_library() { - $library = Model_Library::find_one_by(function($query) { + $library_id = Input::get('library_id'); + + $library = Model_Library::find_one_by(function($query) use ($library_id) { $query - ->select('library.*', 'server.id as server_id', 'server.name as server_name') + ->select_array([ + 'library.*', + ['server.id', 'server_id'], + ['server.name', 'server_name'] + ]) ->join('server', 'LEFT') ->on('server.id', '=','library.server_id' ) ->where('server.user_id', Session::get('user')->id) + ->and_where('library.id', $library_id) ->and_where('server.disable', 0) ; }); if(!$library) - $this->response(array('error' => true, 'message' => 'No server found!')); + return $this->response(array('error' => true, 'message' => 'No server found!')); $this->response($library); } @@ -58,22 +65,25 @@ class Controller_Rest_Browse extends Controller_Rest ) )); - $this->response($servers); + return $this->response($servers); } public function put_server() { - $server_id = Input::put('server_id'); + try { + $server_id = Input::put('server_id'); - $server = Model_Server::find_by('id', $server_id); + $server = Model_Server::find_by('id', $server_id); + if (!$server) + return $this->response(array('error' => true, 'message' => 'No server found!')); - if(!$server) - $this->response(array('error' => true, 'message' => 'No server found!')); + Model_Server::BrowseServeur($server); - Model_Server::BrowseServeur($server); - - $this->response(['error' => false, 'message' => 'Servers informations update!']); + return $this->response(['error' => false, 'message' => 'Servers informations update!']); + } catch (Exception $e) { + return $this->response(['error' => true, 'message' => $e->getMessage()]); + } } public function get_libraries() @@ -83,12 +93,12 @@ class Controller_Rest_Browse extends Controller_Rest $server = Model_Server::find_by_pk($server_id); if(!$server) - $this->response(array('error' => true, 'message' => 'No server found!')); + return $this->response(array('error' => true, 'message' => 'No server found!')); $libraries = Model_Library::BrowseLibraries($server); if(!$libraries) - $this->response(array('error' => true, 'message' => 'No library found!')); + return $this->response(array('error' => true, 'message' => 'No library found!')); $this->response(['error' => false, 'libraries' => $libraries]); } @@ -102,10 +112,10 @@ class Controller_Rest_Browse extends Controller_Rest $library = Model_Library::find_by_pk($library_id); if(!$server) - $this->response(array('error' => true, 'message' => 'No server found!')); + return $this->response(array('error' => true, 'message' => 'No server found!')); if(!$library) - $this->response(array('error' => true, 'message' => 'No library found!')); + return $this->response(array('error' => true, 'message' => 'No library found!')); return Model_Library::getSectionsContent($server, $library); } @@ -119,15 +129,15 @@ class Controller_Rest_Browse extends Controller_Rest $tvshow = Model_Tvshow::find_by_pk($tvshow_id); if(!$server) - $this->response(array('error' => true, 'message' => 'No server found!')); + return $this->response(array('error' => true, 'message' => 'No server found!')); if(!$tvshow) - $this->response(array('error' => true, 'message' => 'No tvshow found!')); + return $this->response(array('error' => true, 'message' => 'No tvshow found!')); $seasons = Model_Tvshow::getTvShowSeasons($server,$tvshow); if(!$seasons) - $this->response(array('error' => true, 'message' => 'No season found!')); + return $this->response(array('error' => true, 'message' => 'No season found!')); $this->response(['error' => false, 'seasons' => $seasons]); } @@ -141,15 +151,15 @@ class Controller_Rest_Browse extends Controller_Rest $season = Model_Season::find_by_pk($season_id); if(!$server) - $this->response(array('error' => true, 'message' => 'No server found!')); + return $this->response(array('error' => true, 'message' => 'No server found!')); if(!$season) - $this->response(array('error' => true, 'message' => 'No season found!')); + return $this->response(array('error' => true, 'message' => 'No season found!')); $movies = Model_Season::getMovies($server,$season); if(!$movies) - $this->response(array('error' => true, 'message' => 'No movie found!')); + return $this->response(array('error' => true, 'message' => 'No movie found!')); $this->response(array_merge(['error' => false], $movies)); } diff --git a/fuel/app/classes/controller/rest/install.php b/fuel/app/classes/controller/rest/install.php index c7f66c3..811875e 100755 --- a/fuel/app/classes/controller/rest/install.php +++ b/fuel/app/classes/controller/rest/install.php @@ -8,6 +8,7 @@ use Fuel\Core\FuelException; use Fuel\Core\Input; use Fuel\Core\Request; use Fuel\Core\Str; +use function PHPSTORM_META\type; class Controller_Rest_Install extends Controller_Rest { @@ -92,6 +93,7 @@ class Controller_Rest_Install extends Controller_Rest 'password' => array('constraint' => 255, 'type' => 'varchar'), 'admin' => array('constraint' => 1, 'type' => 'int', 'default' => 0), 'lastlogin' => array('constraint' => 11, 'type' => 'int'), + 'parent_id' => array('constraint' => 36, 'type' => 'varchar', 'default' => null, 'null' => true), 'disable' => array('constraint' => 1, 'type' => 'int', 'default' => 0) ), array('id'), false, 'InnoDB', 'utf8_unicode_ci' @@ -187,7 +189,7 @@ class Controller_Rest_Install extends Controller_Rest 'plex_key' => array('constraint' => 36, 'type' => 'varchar'), 'number' => array('constraint' => 11, 'type' => 'int'), 'title' => array('constraint' => 255, 'type' => 'varchar'), - 'thumb' => array('constraint' => 255, 'type' => 'varchar'), + 'thumb' => array('constraint' => 255, 'type' => 'varchar', 'null' => true), 'art' => array('constraint' => 255, 'type' => 'varchar', 'null' => true), 'leafCount' => array('constraint' => 11, 'type' => 'int', 'null' => true), 'addedAt' => array('constraint' => 11, 'type' => 'int', 'null' => true), @@ -304,12 +306,32 @@ class Controller_Rest_Install extends Controller_Rest 'id' => array('constraint' => 36, 'type' => 'varchar'), 'file_id' => array('constraint' => 11, 'type' => 'int'), 'user_id' => array('constraint' => 36, 'type' => 'varchar'), + 'watching_time' => array('constraint' => 11, 'type' => 'int'), + 'ended' => array('constraint' => 1, 'type' => 'int', 'default' => 0), 'disable' => array('constraint' => 1, 'type' => 'int', 'default' => 0) ), array('id'), false, 'InnoDB', 'utf8_unicode_ci' ); $logs .= 'User Watching table create!'."\r\n"; + $logs .= 'Creation table user settings'."\r\n"; + /** + * CREATE TABLE USER'S WATCHING + */ + DBUtil::create_table( + 'user_settings', + array( + 'id' => array('constraint' => 36, 'type' => 'varchar'), + 'language' => array('constraint' => 36, 'type' => 'varchar'), + 'refresh' => array('constraint' => 11, 'type' => 'int'), + 'trailer' => array('constraint' => 11, 'type' => 'int', 'default' => 0), + 'subtitle' => array('constraint' => 11, 'type' => 'int'), + 'quality' => array('constraint' => 11, 'type' => 'int', 'default' => -1) + ), + array('id'), false, 'InnoDB', 'utf8_unicode_ci' + ); + $logs .= 'User Watching table create!'."\r\n"; + $logs .= 'Create Foreign key'."\r\n"; /** * FOREIGN KEY @@ -434,6 +456,16 @@ class Controller_Rest_Install extends Controller_Rest 'on_update' => 'NO ACTION', 'on_delete' => 'NO ACTION', )); + DBUtil::add_foreign_key('user', array( + 'constraint' => 'constraintUserUser', + 'key' => 'parent_id', + 'reference' => array( + 'table' => 'user', + 'column' => 'id', + ), + 'on_update' => 'NO ACTION', + 'on_delete' => 'NO ACTION', + )); $logs .= 'Foreign key create!'."\r\n"; diff --git a/fuel/app/classes/controller/rest/settings.php b/fuel/app/classes/controller/rest/settings.php index 146257c..a8bf92b 100644 --- a/fuel/app/classes/controller/rest/settings.php +++ b/fuel/app/classes/controller/rest/settings.php @@ -30,7 +30,7 @@ class Controller_Rest_Settings extends Controller_Rest if(!$result) throw new FuelException('Can not connect to your server!'); - $server = $server_id === null ? Model_Server::forge() : Model_Server::find_by_pk($server_id); + $server = ($server_id === '' ? Model_Server::forge() : Model_Server::find_by_pk($server_id)); $server->set([ 'user_id' => Session::get('user')->id, 'url' => $url, @@ -66,6 +66,34 @@ class Controller_Rest_Settings extends Controller_Rest } } + public function put_library() + { + try { + $library = Input::put('library_id'); + + $library = Model_Library::find_one_by(function($query) use($library) { + $query + ->join('server', 'LEFT') + ->on('server.id', '=','library.server_id' ) + ->where('server.user_id', Session::get('user')->id) + ->and_where('library.id', $library) + ->and_where('library.disable', 1) + ->and_where('server.disable', 0) + ; + }); + + if(!$library) + throw new FuelException('No disable library found!'); + + $library->set(['disable' => 0]); + $library->save(); + + return $this->response(array('error' => false)); + } catch (FuelException $e) { + return $this->response(array('error' => true, 'message' => $e->getMessage() ?: 'Wrong parameters'), 400); + } + } + public function delete_library() { try { diff --git a/fuel/app/classes/model/library.php b/fuel/app/classes/model/library.php index 7d4f281..96de899 100644 --- a/fuel/app/classes/model/library.php +++ b/fuel/app/classes/model/library.php @@ -1,6 +1,8 @@ url . ($server->port? ':' . $server->port : '') . '/library/sections?X-Plex-Token=' . $server->token, 'curl'); - $curl->execute(); + $curl = Request::forge('http://' . $server->url . ($server->port ? ':' . $server->port : '') . '/library/sections?X-Plex-Token=' . $server->token, 'curl'); + $curl->execute(); - if($curl->response()->status !== 200) - return false; + if ($curl->response()->status !== 200) + return false; - $list_libraries = Format::forge($curl->response()->body, 'xml')->to_array(); + $list_libraries = Format::forge($curl->response()->body, 'xml')->to_array(); - if(!isset($list_libraries['Directory'])) - return false; + if (!isset($list_libraries['Directory'])) + return false; - $list_libraries = $list_libraries['Directory']; + $list_libraries = $list_libraries['Directory']; - foreach ($list_libraries as $index => $library) { - $library = !isset($list_libraries['@attributes']) ? $library : $list_libraries; + foreach ($list_libraries as $index => $library) { + $library = !isset($list_libraries['@attributes']) ? $library : $list_libraries; - $new_library = Model_Library::find_by_pk($library['@attributes']['uuid']) ?: Model_Library::forge(); + $new_library = Model_Library::find_by_pk($library['@attributes']['uuid']) ?: Model_Library::forge(); - if(isset($new_library->disable) && $new_library->disable) - continue; + if ((isset($new_library->disable) && $new_library->disable) || ($library['@attributes']['type'] !== 'show' && $library['@attributes']['type'] !== 'movie')) + continue; - $libraries_id_array[] = ['id' => $library['@attributes']['uuid'], 'name' => $library['@attributes']['title']]; + $libraries_id_array[] = ['id' => $library['@attributes']['uuid'], 'name' => $library['@attributes']['title']]; - $new_library->set(array( - 'id' => $library['@attributes']['uuid'], - 'plex_key' => $library['@attributes']['key'], - 'server_id' => $server->id, - 'name' => $library['@attributes']['title'], - 'type' => $library['@attributes']['type'], - 'updatedAt' => $library['@attributes']['updatedAt'], - 'createdAt' => $library['@attributes']['createdAt'], - 'scannedAt' => $library['@attributes']['scannedAt'] - )); + $new_library->set(array( + 'id' => $library['@attributes']['uuid'], + 'plex_key' => $library['@attributes']['key'], + 'server_id' => $server->id, + 'name' => $library['@attributes']['title'], + 'type' => $library['@attributes']['type'], + 'updatedAt' => $library['@attributes']['updatedAt'], + 'createdAt' => $library['@attributes']['createdAt'], + 'scannedAt' => $library['@attributes']['scannedAt'] + )); - $new_library->save(); + $new_library->save(); - //self::getSectionsContent($server, $new_library); + //self::getSectionsContent($server, $new_library); - if(isset($list_libraries['@attributes'])) - break; - } + if (isset($list_libraries['@attributes'])) + break; + } - return $libraries_id_array; + return $libraries_id_array; + } catch (Exception $exception) { + throw new FuelException($exception->getMessage(),$exception->getCode()); + } } /** * @param $server * @param $library * @return bool - * @throws Exception * @throws FuelException - * @throws HttpNotFoundException - * @throws \FuelException */ public static function getSectionsContent($server, $library) { diff --git a/fuel/app/classes/model/movie.php b/fuel/app/classes/model/movie.php index cb5239f..edb4739 100644 --- a/fuel/app/classes/model/movie.php +++ b/fuel/app/classes/model/movie.php @@ -157,6 +157,10 @@ class Model_Movie extends Model_Overwrite } } + /** + * @return array|mixed + * @throws FuelException + */ public function getMetaData() { try { @@ -183,8 +187,26 @@ class Model_Movie extends Model_Overwrite //ROLES $this->metadata['Role'] = isset($array['Video']['Role']) ? $array['Video']['Role'] : null; + $this->metadata['Stream'] = []; + $this->metadata['Stream']['Video'] = []; + $this->metadata['Stream']['Audio'] = []; + $this->metadata['Stream']['SubTitle'] = []; + + if(isset($array['Video']['Media']['Part']['Stream'])) { + foreach ($array['Video']['Media']['Part']['Stream'] as $stream) { + if($stream['@attributes']['streamType'] === '1') + $this->metadata['Stream']['Video'][] = $stream['@attributes']; + else if($stream['@attributes']['streamType'] === '2') + $this->metadata['Stream']['Audio'][] = $stream['@attributes']; + else if($stream['@attributes']['streamType'] === '3') + $this->metadata['Stream']['SubTitle'][] = $stream['@attributes']; + } + } + Cache::set($this->id . '.metadata', $this->metadata); return $this->metadata; + } catch (Exception $exception) { + throw new FuelException($exception->getMessage(),$exception->getCode()); } } @@ -208,7 +230,7 @@ class Model_Movie extends Model_Overwrite return ($hours > 0 ? $hours . ' h ' : '') . $minutes . ' min'; } - public function getDuractionMovie() + public function getDurationMovie() { $init = $this->duration; @@ -225,7 +247,7 @@ class Model_Movie extends Model_Overwrite if (!$this->_server) $this->getServer(); - $curl = Request::forge('http://' . $this->_server->url . ($this->_server->port ? ':' . $this->_server->port : '') . '/video/:/transcode/universal/start?identifier=[PlexShare]&path=http%3A%2F%2F127.0.0.1%3A32400' . urlencode($this->plex_key) . '&mediaIndex=0&partIndex=0&protocol=hls&offset=0&fastSeek=1&directStream=0&directPlay=1&videoQuality=100&maxVideoBitrate=2294&subtitleSize=100&audioBoost=100&X-Plex-Platform=Chrome&X-Plex-Token=' . $this->_server->token, 'curl'); + $curl = Request::forge('http://' . $this->_server->url . ($this->_server->port ? ':' . $this->_server->port : '') . '/video/:/transcode/universal/start.m3u8?identifier=[PlexShare]&path=http%3A%2F%2F127.0.0.1%3A32400' . urlencode($this->plex_key) . '&mediaIndex=0&partIndex=0&protocol=hls&offset=0&fastSeek=1&directStream=0&directPlay=1&videoQuality=100&maxVideoBitrate=2294&subtitleSize=100&audioBoost=100&X-Plex-Platform=Chrome&X-Plex-Token=' . $this->_server->token, 'curl'); //$curl = Request::forge('http://' . $this->_server->url . ($this->_server->port ? ':' . $this->_server->port : '') . '/video/:/transcode/universal/start?identifier=[PlexShare]&path=http%3A%2F%2F127.0.0.1%3A32400' . urlencode($this->plex_key) . '&mediaIndex=0&partIndex=0&protocol=hls&offset=0&fastSeek=1&directStream=0&directPlay=1&videoQuality=100&videoResolution=576x320&maxVideoBitrate=2294&subtitleSize=100&audioBoost=100&X-Plex-Platform=Chrome&X-Plex-Token=' . $this->_server->token, 'curl'); $curl->execute(); @@ -245,8 +267,8 @@ class Model_Movie extends Model_Overwrite $this->_session = $split[1]; return 'http://' . $this->_server->url . ($this->_server->port ? ':' . $this->_server->port : '') . '/video/:/transcode/universal/session/' . $this->_session . '/base/index.m3u8'; - }catch (Exception $exception) { - throw new FuelException('TOKEN MAYBE OUTDATED',$exception->getCode()); + } catch (Exception $exception) { + throw new FuelException('Cannot connect to the server.
The token must be outdated!',$exception->getCode()); } } @@ -298,9 +320,9 @@ class Model_Movie extends Model_Overwrite 'summary' => $XMLmovie['@attributes']['summary'], 'rating' => isset($XMLmovie['@attributes']['rating']) ? $XMLmovie['@attributes']['rating'] : null, 'year' => isset($XMLmovie['@attributes']['year']) ? $XMLmovie['@attributes']['year'] : null, - 'thumb' => $XMLmovie['@attributes']['thumb'], + 'thumb' => isset($XMLmovie['@attributes']['thumb']) ? $XMLmovie['@attributes']['thumb'] : null, 'art' => isset($XMLmovie['@attributes']['art']) ? $XMLmovie['@attributes']['art'] : null, - 'duration' => $XMLmovie['@attributes']['duration'], + 'duration' => isset($XMLmovie['@attributes']['duration']) ? $XMLmovie['@attributes']['duration'] : null, 'originallyAvailableAt' => isset($XMLmovie['@attributes']['originallyAvailableAt']) ? $XMLmovie['@attributes']['originallyAvailableAt'] : null, 'addedAt' => $XMLmovie['@attributes']['addedAt'], 'updatedAt' => $XMLmovie['@attributes']['updatedAt'] diff --git a/fuel/app/classes/model/season.php b/fuel/app/classes/model/season.php index 1fdf6eb..51f59c8 100644 --- a/fuel/app/classes/model/season.php +++ b/fuel/app/classes/model/season.php @@ -1,5 +1,7 @@ id; - - $season = Model_Season::find(function ($query) use ($XMLseason, $tvshow_id){ - /** @var Database_Query_Builder_Select $query */ - return $query - ->select('*') - ->where('plex_key', $XMLseason['@attributes']['key']) - ->and_where('tv_show_id', $tvshow_id) - ; - })[0] ?: Model_Season::forge(); - - $season->set([ - 'tv_show_id' => $tvshow->id, - 'plex_key' => $XMLseason['@attributes']['key'], - 'number' => $XMLseason['@attributes']['index'], - 'title' => $XMLseason['@attributes']['title'], - 'thumb' => $XMLseason['@attributes']['thumb'], - 'art' => isset($XMLseason['@attributes']['art']) ? $XMLseason['@attributes']['art'] : null, - 'leafCount' => $XMLseason['@attributes']['leafCount'], - 'addedAt' => $XMLseason['@attributes']['addedAt'], - 'updatedAt' => $XMLseason['@attributes']['updatedAt'] - ]); - - $season->save(); - - $season_id_array[] = ['id' => $season->id, 'name' => $season->title]; - - if(isset($seasons['@attributes'])) - break; + try { + $season_id_array = []; + + foreach ($seasons as $XMLseason) { + $XMLseason = !isset($seasons['@attributes']) ? $XMLseason : $seasons; + + // Not browsing array ALL EPISODES + if (isset($seasons[0]) && $seasons[0] === $XMLseason) + continue; + + $tvshow_id = $tvshow->id; + + $season = Model_Season::find(function ($query) use ($XMLseason, $tvshow_id) { + /** @var Database_Query_Builder_Select $query */ + return $query + ->select('*') + ->where('plex_key', $XMLseason['@attributes']['key']) + ->and_where('tv_show_id', $tvshow_id); + })[0] ?: Model_Season::forge(); + + $season->set([ + 'tv_show_id' => $tvshow->id, + 'plex_key' => $XMLseason['@attributes']['key'], + 'number' => $XMLseason['@attributes']['index'], + 'title' => $XMLseason['@attributes']['title'], + 'thumb' => isset($XMLseason['@attributes']['thumb']) ? $XMLseason['@attributes']['thumb'] : null, + 'art' => isset($XMLseason['@attributes']['art']) ? $XMLseason['@attributes']['art'] : null, + 'leafCount' => isset($XMLseason['@attributes']['leafCount']) ? $XMLseason['@attributes']['leafCount'] : null, + 'addedAt' => $XMLseason['@attributes']['addedAt'], + 'updatedAt' => isset($XMLseason['@attributes']['updatedAt']) ? $XMLseason['@attributes']['updatedAt'] : null + ]); + + $season->save(); + + $season_id_array[] = ['id' => $season->id, 'name' => $season->title]; + + if (isset($seasons['@attributes'])) + break; + } + + return $season_id_array; + } catch (Exception $exception) { + throw new FuelException($exception->getMessage(),$exception->getCode()); } - - return $season_id_array; } + /** + * @param $server + * @param $season + * @return array|bool + * @throws FuelException + */ public static function getMovies($server, $season) { - $curl = Request::forge('http://' . $server->url . ($server->port ? ':' . $server->port : '') . $season->plex_key . '?X-Plex-Token=' . $server->token, 'curl'); - $curl->execute(); + try { + $curl = Request::forge('http://' . $server->url . ($server->port ? ':' . $server->port : '') . $season->plex_key . '?X-Plex-Token=' . $server->token, 'curl'); + $curl->execute(); - if ($curl->response()->status !== 200) - return false; + if ($curl->response()->status !== 200) + return false; - $movies = Format::forge($curl->response()->body, 'xml')->to_array(); + $movies = Format::forge($curl->response()->body, 'xml')->to_array(); - if(isset($movies['Video'])) - return ['movies' => Model_Movie::BrowseMovies($server, $movies['Video'], null, $season)]; + if (isset($movies['Video'])) + return ['movies' => Model_Movie::BrowseMovies($server, $movies['Video'], null, $season)]; + } catch (Exception $exception) { + throw new FuelException($exception->getMessage(),$exception->getCode()); + } } public function getEpisodes() diff --git a/fuel/app/classes/model/server.php b/fuel/app/classes/model/server.php index af00de3..600cdee 100755 --- a/fuel/app/classes/model/server.php +++ b/fuel/app/classes/model/server.php @@ -53,38 +53,42 @@ class Model_Server extends Model_Overwrite */ public static function BrowseServeur($_servers = null) { - $servers = $_servers ?: Model_Server::find(); + $servers = $_servers ?: Model_Server::find_all(); foreach ($servers as $server) { - if($server->disable) - continue; + try{ + if($server->disable) + continue; $curl = Request::forge('http://' . $server->url . ($server->port? ':' . $server->port : '') . '/?X-Plex-Token=' . $server->token, 'curl'); - $curl->execute(); + $curl->execute(); - $dataServer = Format::forge($curl->response()->body, 'xml')->to_array(); + $dataServer = Format::forge($curl->response()->body, 'xml')->to_array(); - if (!isset($dataServer['@attributes'])) { - $server->set('online', 0); - $server->save(); - } - - $dataServer = $dataServer['@attributes']; + if (!isset($dataServer['@attributes'])) { + $server->set(['online' => 0]); + $server->save(); + } - $server->set(['lastcheck' => time()]); + $dataServer = $dataServer['@attributes']; - ($server->name !== $dataServer['friendlyName']) ? $server->set(['name' => $dataServer['friendlyName']]) : null; - ($server->name !== $dataServer['platform']) ? $server->set(['plateforme' => $dataServer['platform']]) : null; - ($server->name !== $dataServer['platformVersion']) ? $server->set(['platformVersion' => $dataServer['platformVersion']]) : null; - ($server->name !== $dataServer['updatedAt']) ? $server->set(['updatedAt' => $dataServer['updatedAt']]) : null; - ($server->name !== $dataServer['version']) ? $server->set(['version' => $dataServer['version']]) : null; + $server->set(['lastcheck' => time()]); - $server->set(['online' => 1]); + ($server->name !== $dataServer['friendlyName']) ? $server->set(['name' => $dataServer['friendlyName']]) : null; + ($server->plateforme !== $dataServer['platform']) ? $server->set(['plateforme' => $dataServer['platform']]) : null; + ($server->platformVersion !== $dataServer['platformVersion']) ? $server->set(['platformVersion' => $dataServer['platformVersion']]) : null; + ($server->updatedAt !== $dataServer['updatedAt']) ? $server->set(['updatedAt' => $dataServer['updatedAt']]) : null; + ($server->version !== $dataServer['version']) ? $server->set(['version' => $dataServer['version']]) : null; - $server->save(); + $server->set(['online' => 1]); - //Model_Library::BrowseLibraries($server); + $server->save(); + }catch (Exception $exception) { + $server->set(['online' => 0]); + $server->save(); + throw new FuelException($exception->getMessage(),$exception->getCode()); + } } } diff --git a/fuel/app/classes/model/tvshow.php b/fuel/app/classes/model/tvshow.php index 777355e..71ed80c 100644 --- a/fuel/app/classes/model/tvshow.php +++ b/fuel/app/classes/model/tvshow.php @@ -1,6 +1,7 @@ id; - - $tvshow = Model_Tvshow::find(function ($query) use ($subsection, $library_id){ - /** @var Database_Query_Builder_Select $query */ - return $query - ->select('*') - ->where('plex_key', $subsection['@attributes']['key']) - ->and_where('library_id', $library_id) - ; - })[0] ?: Model_Tvshow::forge(); - - $tvshow->set([ - 'library_id' => $library->id, - 'plex_key' => $subsection['@attributes']['key'], - 'studio' => isset($subsection['@attributes']['studio']) ? $subsection['@attributes']['studio'] : null, - 'title' => $subsection['@attributes']['title'], - 'contentRating' => isset($subsection['@attributes']['contentRating']) ? $subsection['@attributes']['contentRating'] : null, - 'summary' => isset($subsection['@attributes']['summary']) ? $subsection['@attributes']['summary'] : null, - 'rating' => isset($subsection['@attributes']['rating']) ? $subsection['@attributes']['rating'] : null, - 'year' => isset($subsection['@attributes']['year']) ? $subsection['@attributes']['year'] : null, - 'thumb' => isset($subsection['@attributes']['thumb']) ? $subsection['@attributes']['thumb'] : null, - 'art' => isset($subsection['@attributes']['art']) ? $subsection['@attributes']['art'] : null, - 'banner' => isset($subsection['@attributes']['banner']) ? $subsection['@attributes']['banner'] : null, - 'theme' => isset($subsection['@attributes']['theme']) ? $subsection['@attributes']['theme'] : null, - 'originallyAvailableAt' => isset($subsection['@attributes']['originallyAvailableAt']) ? $subsection['@attributes']['originallyAvailableAt'] : null, - 'leafCount' => $subsection['@attributes']['leafCount'], - 'addedAt' => $subsection['@attributes']['addedAt'], - 'updatedAt' => $subsection['@attributes']['updatedAt'] - ]); - - $tvshow->save(); - - $tvshows_id_array[] = ['id' => $tvshow->id, 'name' => $tvshow->title]; - - //self::getTvShowSeasons($server, $tvshow); - - if(isset($subsections['@attributes'])) - break; + try { + $tvshows_id_array = []; + + foreach ($subsections as $subsection) { + $subsection = !isset($subsections['@attributes']) ? $subsection : $subsections; + + $library_id = $library->id; + + $tvshow = Model_Tvshow::find(function ($query) use ($subsection, $library_id) { + /** @var Database_Query_Builder_Select $query */ + return $query + ->select('*') + ->where('plex_key', $subsection['@attributes']['key']) + ->and_where('library_id', $library_id); + })[0] ?: Model_Tvshow::forge(); + + $tvshow->set([ + 'library_id' => $library->id, + 'plex_key' => $subsection['@attributes']['key'], + 'studio' => isset($subsection['@attributes']['studio']) ? $subsection['@attributes']['studio'] : null, + 'title' => $subsection['@attributes']['title'], + 'contentRating' => isset($subsection['@attributes']['contentRating']) ? $subsection['@attributes']['contentRating'] : null, + 'summary' => isset($subsection['@attributes']['summary']) ? $subsection['@attributes']['summary'] : null, + 'rating' => isset($subsection['@attributes']['rating']) ? $subsection['@attributes']['rating'] : null, + 'year' => isset($subsection['@attributes']['year']) ? $subsection['@attributes']['year'] : null, + 'thumb' => isset($subsection['@attributes']['thumb']) ? $subsection['@attributes']['thumb'] : null, + 'art' => isset($subsection['@attributes']['art']) ? $subsection['@attributes']['art'] : null, + 'banner' => isset($subsection['@attributes']['banner']) ? $subsection['@attributes']['banner'] : null, + 'theme' => isset($subsection['@attributes']['theme']) ? $subsection['@attributes']['theme'] : null, + 'originallyAvailableAt' => isset($subsection['@attributes']['originallyAvailableAt']) ? $subsection['@attributes']['originallyAvailableAt'] : null, + 'leafCount' => isset($subsection['@attributes']['leafCount']) ? $subsection['@attributes']['leafCount'] : null, + 'addedAt' => $subsection['@attributes']['addedAt'], + 'updatedAt' => isset($subsection['@attributes']['updatedAt']) ? $subsection['@attributes']['updatedAt'] : null + ]); + + $tvshow->save(); + + $tvshows_id_array[] = ['id' => $tvshow->id, 'name' => $tvshow->title]; + + //self::getTvShowSeasons($server, $tvshow); + + if (isset($subsections['@attributes'])) + break; + } + + return $tvshows_id_array; + } catch (Exception $exception) { + throw new FuelException($exception->getMessage(),$exception->getCode()); } - - return $tvshows_id_array; } + /** + * @param $server + * @param $tvshow + * @return array|bool + * @throws FuelException + */ public static function getTvShowSeasons($server, $tvshow) { - $curl = Request::forge('http://' . $server->url . ($server->port ? ':' . $server->port : '') . $tvshow->plex_key . '?X-Plex-Token=' . $server->token, 'curl'); - $curl->execute(); + try { + $curl = Request::forge('http://' . $server->url . ($server->port ? ':' . $server->port : '') . $tvshow->plex_key . '?X-Plex-Token=' . $server->token, 'curl'); + $curl->execute(); - if ($curl->response()->status !== 200) - return false; + if ($curl->response()->status !== 200) + return false; - $seasons = Format::forge($curl->response()->body, 'xml')->to_array(); + $seasons = Format::forge($curl->response()->body, 'xml')->to_array(); - if(isset($seasons['Directory'])) - return Model_Season::BrowseSeason($server, $seasons['Directory'], $tvshow); + if (isset($seasons['Directory'])) + return Model_Season::BrowseSeason($server, $seasons['Directory'], $tvshow); + } catch (Exception $exception) { + throw new FuelException($exception->getMessage(),$exception->getCode()); + } } public function getSeasons() { - if(!$this->_seasons) - $this->_seasons = Model_Season::find_by('tv_show_id', $this->id); + if(!$this->_seasons) { + $id = $this->id; + $this->_seasons = Model_Season::find_by(function ($query) use ($id) { + $query + ->where('tv_show_id', $id) + ->order_by('number', 'ASC') + ; + }); + } return $this->_seasons; } diff --git a/fuel/app/classes/model/user.php b/fuel/app/classes/model/user.php index 2ce96a4..2c47466 100755 --- a/fuel/app/classes/model/user.php +++ b/fuel/app/classes/model/user.php @@ -38,10 +38,11 @@ class Model_User extends Model_Overwrite { $result = self::find_one_by(function ($query) use ($login,$password){ return $query - ->where('user.password', $password) + ->where('password', $password) + ->and_where('parent_id', null) ->and_where_open() - ->where('user.email', $login) - ->or_where('user.username', $login) + ->where('email', $login) + ->or_where('username', $login) ->and_where_close() ; }); @@ -51,4 +52,22 @@ class Model_User extends Model_Overwrite else return false; } + + public function getLastLogin() + { + $dateString = date('Y/m/d H:i:s', time()); + $now = new DateTime($dateString); + + $dateString = date('Y-m-d H:i:s', $this->lastlogin); + $time = new DateTime($dateString); + + $diff = date_diff($now, $time); + + $days = $diff->days . 'd '; + $hours = $diff->h . 'h '; + $minutes = $diff->i . 'min '; + $seconds = $diff->s . 's'; + + return $days.$hours.$minutes.$seconds; + } } \ No newline at end of file diff --git a/fuel/app/config/config.php b/fuel/app/config/config.php index 30dfb0c..5153aa4 100755 --- a/fuel/app/config/config.php +++ b/fuel/app/config/config.php @@ -43,7 +43,7 @@ return array( */ // 'index_file' => false, - // 'profiling' => false, + 'profiling' => true, /** * Default location for the file cache @@ -188,7 +188,7 @@ return array( /** * Cookie settings */ - // 'cookie' => array( + 'cookie' => array( // Number of seconds before the cookie expires // 'expiration' => 0, // Restrict the path that the cookie is available to @@ -196,10 +196,10 @@ return array( // Restrict the domain that the cookie is available to // 'domain' => null, // Only transmit cookies over secure connections - // 'secure' => false, + // 'secure' => true, // Only transmit cookies over HTTP, disabling Javascript access - // 'http_only' => false, - // ), + // 'http_only' => true, + ), /** * Validation settings diff --git a/fuel/app/config/session.php b/fuel/app/config/session.php index 126a7f4..a68be1e 100644 --- a/fuel/app/config/session.php +++ b/fuel/app/config/session.php @@ -44,7 +44,7 @@ return array( 'cookie_path' => '/', // cookie http_only flag (optional, default = use the cookie class default) - 'cookie_http_only' => true, + 'cookie_http_only' => null, // whether or not to encrypt the session cookie (optional, default is true) 'encrypt_cookie' => true, @@ -85,19 +85,19 @@ return array( // special configuration settings for cookie based sessions 'cookie' => array( - 'cookie_name' => 'plexshare_ccn', // name of the session cookie for cookie based sessions + 'cookie_name' => 'plexshare_cid', // name of the session cookie for cookie based sessions ), // specific configuration settings for file based sessions 'file' => array( - 'cookie_name' => 'plexshare_fcn', // name of the session cookie for file based sessions + 'cookie_name' => 'plexshare_fid', // name of the session cookie for file based sessions 'path' => '/tmp', // path where the session files should be stored 'gc_probability' => 5, // probability % (between 0 and 100) for garbage collection ), // specific configuration settings for memcached based sessions 'memcached' => array( - 'cookie_name' => 'plexshare_mcn', // name of the session cookie for memcached based sessions + 'cookie_name' => 'plexshare_mid', // name of the session cookie for memcached based sessions 'servers' => array( // array of servers and portnumbers that run the memcached service 'default' => array('host' => '127.0.0.1', 'port' => 11211, 'weight' => 100), ), @@ -105,7 +105,7 @@ return array( // specific configuration settings for database based sessions 'db' => array( - 'cookie_name' => 'plexshare_dcn', // name of the session cookie for database based sessions + 'cookie_name' => 'plexshare_did', // name of the session cookie for database based sessions 'database' => null, // name of the database name (as configured in config/db.php) 'table' => 'sessions', // name of the sessions table 'gc_probability' => 5, // probability % (between 0 and 100) for garbage collection @@ -113,7 +113,7 @@ return array( // specific configuration settings for redis based sessions 'redis' => array( - 'cookie_name' => 'plexshare_rcn', // name of the session cookie for redis based sessions + 'cookie_name' => 'plexshare_rid', // name of the session cookie for redis based sessions 'database' => 'default', // name of the redis database to use (as configured in config/db.php) ), ); diff --git a/fuel/app/tasks/server.php b/fuel/app/tasks/server.php new file mode 100644 index 0000000..78ef4a7 --- /dev/null +++ b/fuel/app/tasks/server.php @@ -0,0 +1,133 @@ +url . ($server->port ? ':' . $server->port : '') . '?X-Plex-Token=' . $server->token, 'curl'); + $curl->execute(); + + if ($curl->response()->status !== 200) + throw new FuelException('No session found!'); + + $server->set([ + 'lastcheck' => time(), + 'online' => 1 + ]); + + $server->save(); + } catch (Exception $exception) { + $server->set([ + 'lastcheck' => time(), + 'online' => 0 + ]); + + $server->save(); + } + } + } + + public function browseServers() + { + $time = ini_get('max_execution_time'); + + $servers = Model_Server::find_all(); + + if($time > 0 && $time < ($servers * 5 * 60)) { + ini_set('max_execution_time', 5 * $servers); + } + + foreach ($servers as $server) { + try { + Model_Server::BrowseServeur([$server]); + } catch (Exception $exception) { + echo 'Server: ' . $server->name . ' ERROR: ' . $exception->getMessage() . "\n\r"; + } + try { + $this->browseLibraries($server); + } catch (Exception $exception) { + + } + } + } + + private function browseLibraries($server) + { + Model_Library::BrowseLibraries($server); + + $this->browseSubContent($server); + } + + private function browseSubContent($server) + { + $libraries = Model_Library::find_by('server_id',$server->id); + + foreach ($libraries as $library) { + Model_Library::getSectionsContent($server, $library); + } + + $this->browseSeasons($server); + } + + private function browseSeasons($server) + { + $server_id = $server->id; + + $tv_shows = Model_Tvshow::find(function ($query) use ($server_id) { + $query + ->select('tvshow.*') + ->join('library') + ->on('tvshow.library_id', '=', 'library.id') + ->where('library.server_id', $server_id) + ; + }); + + foreach ($tv_shows as $tv_show) { + Model_Tvshow::getTvShowSeasons($server,$tv_show); + } + + $this->browseMovies($server); + } + + private function browseMovies($server) + { + $server_id = $server->id; + + $seasons = Model_Season::find(function ($query) use ($server_id) { + $query + ->select('season.*') + ->join('tvshow') + ->on('season.tv_show_id', '=', 'tvshow.id') + ->join('library') + ->on('tvshow.library_id', '=', 'library.id') + ->where('library.server_id', $server_id) + ; + }); + + foreach ($seasons as $season) { + Model_Season::getMovies($server,$season); + } + } +} diff --git a/fuel/app/views/admin/body.php b/fuel/app/views/admin/body.php new file mode 100644 index 0000000..7107707 --- /dev/null +++ b/fuel/app/views/admin/body.php @@ -0,0 +1,51 @@ + + PlexShare :: Administration + + + + + + + +
+ $user]); ?> +
+
+
+
+
+
+
+
+
+
+
+ +

Administration

+ +
+
+
+
+
+ + + + \ No newline at end of file diff --git a/fuel/app/views/admin/index.php b/fuel/app/views/admin/index.php new file mode 100644 index 0000000..a3f898b --- /dev/null +++ b/fuel/app/views/admin/index.php @@ -0,0 +1,83 @@ +
+
+
+
+
+ +
+
+
+
+

Version 0.1A

+
+ + +

+ Aidez-nous à traduire cette application dans votre langue ici. +

+
+
+ + +

Number in second, you want to check new content on server.

+
+
+

Audio & + sous-titres

+
+

Augmente le volume si le son est converti de multi-canal à + stéréo.

+
+
+

Détermine si le serveur doit incruster les sous-titres lors de + l'encodage, en fonction du format des sous-titres. Eviter l'incrustation des + sous-titres améliore les performances du serveur, mais n'est possible qu'avec le + lecteur HTML5.

+

Bonus

+
+
+ +
+
+
+
+
\ No newline at end of file diff --git a/fuel/app/views/admin/libraries.php b/fuel/app/views/admin/libraries.php new file mode 100644 index 0000000..a9cdfc4 --- /dev/null +++ b/fuel/app/views/admin/libraries.php @@ -0,0 +1,172 @@ +
+
+
+ +
+ + + HF-Server + + + +
+
+
+
    + + +
  • +
    +
    + + + + + disable) : ?> + + + + + +
    +

    + name; ?> + +

    +
    +
    +
    getLastUpdate(); ?>
    + +
    + type; ?> +
    +
    getServer()->name; ?>
    +
    +
    + Linux + Debian 8 +
    +
    +
    +
    +
  • + + +
+
+
+
+ \ No newline at end of file diff --git a/fuel/app/views/admin/servers.php b/fuel/app/views/admin/servers.php new file mode 100644 index 0000000..65dcf6b --- /dev/null +++ b/fuel/app/views/admin/servers.php @@ -0,0 +1,164 @@ +
+
+ + +
+
+
+
    + + +
  • +
    + +
    + + + + +
    +

    name; ?>

    +
    +
    +
    getLastCheck(); ?>
    + +
    + version; ?> +
    +
    Plex Media Server
    +
    +
    + plateforme; ?> + platformVersion; ?> +
    +
    +
    +
    +
  • + + +
+
+
+
+ \ No newline at end of file diff --git a/fuel/app/views/admin/users.php b/fuel/app/views/admin/users.php new file mode 100644 index 0000000..3a21a15 --- /dev/null +++ b/fuel/app/views/admin/users.php @@ -0,0 +1,125 @@ +
+
+
+
+
+
    + + +
  • +
    +
    + + + + disable) : ?> + + + + + +
    +

    + username; ?> + +

    +
    +
    +
    + getLastLogin(); ?> +
    +
    + email; ?> +
    +
    admin ? 'Admin' : 'User'; ?>
    +
    +
    +
    +
  • + + +
+
+
+
+ \ No newline at end of file diff --git a/fuel/app/views/episode/index.php b/fuel/app/views/episode/index.php index b1a2b18..ec6cc68 100644 --- a/fuel/app/views/episode/index.php +++ b/fuel/app/views/episode/index.php @@ -15,14 +15,15 @@
- - + +
@@ -213,7 +214,7 @@
@@ -238,6 +239,18 @@
\ No newline at end of file diff --git a/fuel/app/views/layout/body.php b/fuel/app/views/layout/body.php index 8f81aff..c988cf5 100644 --- a/fuel/app/views/layout/body.php +++ b/fuel/app/views/layout/body.php @@ -15,7 +15,7 @@
- $libraries, 'server' => $server]); ?> + $MenuLibraries, 'MenuServer' => $MenuServer]); ?>
@@ -34,8 +34,8 @@
- id === $server->id) : ?> + id === $MenuServer->id) : ?> @@ -63,16 +63,12 @@
- - + \ No newline at end of file diff --git a/fuel/app/views/layout/header.php b/fuel/app/views/layout/header.php index 183221a..4f4f589 100644 --- a/fuel/app/views/layout/header.php +++ b/fuel/app/views/layout/header.php @@ -1,5 +1,5 @@ - Plex + PlexShare 1.0 by Chewbaka diff --git a/fuel/app/views/layout/index.php b/fuel/app/views/layout/index.php index 692c4fc..7d292ad 100644 --- a/fuel/app/views/layout/index.php +++ b/fuel/app/views/layout/index.php @@ -4,8 +4,8 @@ isset($body) ? $body : null, 'user' => isset($user) ? $user : null, - 'libraries' => isset($libraries) ? $libraries : null, - 'server' => isset($server) ? $server : null, + 'MenuLibraries' => isset($MenuLibraries) ? $MenuLibraries : null, + 'MenuServer' => isset($MenuServer) ? $MenuServer : null, 'js_bottom' => isset($js_bottom) ? $js_bottom : null, ]); ?> \ No newline at end of file diff --git a/fuel/app/views/layout/nav_bar_header.php b/fuel/app/views/layout/nav_bar_header.php index b9a5744..c95ace4 100644 --- a/fuel/app/views/layout/nav_bar_header.php +++ b/fuel/app/views/layout/nav_bar_header.php @@ -19,8 +19,9 @@
  • - + + 0
  • - + 0