From 81f32c3e61c61ae16b40bb54a256ccb6d8fe472c Mon Sep 17 00:00:00 2001 From: Pierre Rudloff Date: Wed, 30 Mar 2016 01:39:47 +0200 Subject: [PATCH] Use Slim 3.3 (fixes #49) --- composer.json | 5 +- composer.lock | 315 +++++++++++++++----------------- controllers/FrontController.php | 81 +++++--- index.php | 24 +-- templates/footer.tpl | 2 +- templates/head.tpl | 19 +- templates/header.tpl | 4 +- templates/index.tpl | 8 +- templates/logo.tpl | 4 +- templates/video.tpl | 6 +- 10 files changed, 234 insertions(+), 234 deletions(-) diff --git a/composer.json b/composer.json index dc5d1cf..3f7b532 100644 --- a/composer.json +++ b/composer.json @@ -7,9 +7,8 @@ "require": { "smarty/smarty": "~3.1.29", "rg3/youtube-dl": "2016.03.14", - "slim/slim": "~2.6.2", - "slim/views": "~0.1.3", - "rudloff/smarty-plugin-noscheme": "~0.1.0", + "slim/slim": "~3.3.0", + "mathmarques/smarty-view": "~1.0.0", "symfony/yaml": "~3.0.0", "ffmpeg/ffmpeg": "~2.8.2" }, diff --git a/composer.lock b/composer.lock index d4fa979..434d7ae 100644 --- a/composer.lock +++ b/composer.lock @@ -4,9 +4,36 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "hash": "d4b9e76dbda3af97316a38bfe163ac00", - "content-hash": "6eb27104cc39af34f798d35fb3f381ac", + "hash": "22d65db5d1fd37d20bc4b2ad6736ab4a", + "content-hash": "bbf51588b3930e62a675a947d23aa6b0", "packages": [ + { + "name": "container-interop/container-interop", + "version": "1.1.0", + "source": { + "type": "git", + "url": "https://github.com/container-interop/container-interop.git", + "reference": "fc08354828f8fd3245f77a66b9e23a6bca48297e" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/container-interop/container-interop/zipball/fc08354828f8fd3245f77a66b9e23a6bca48297e", + "reference": "fc08354828f8fd3245f77a66b9e23a6bca48297e", + "shasum": "" + }, + "type": "library", + "autoload": { + "psr-4": { + "Interop\\Container\\": "src/Interop/Container/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "Promoting the interoperability of container objects (DIC, SL, etc.)", + "time": "2014-12-30 15:22:37" + }, { "name": "ffmpeg/ffmpeg", "version": "2.8.4", @@ -22,102 +49,123 @@ "type": "library" }, { - "name": "jeremykendall/php-domain-parser", - "version": "3.0.0", + "name": "mathmarques/smarty-view", + "version": "1.0", "source": { "type": "git", - "url": "https://github.com/jeremykendall/php-domain-parser.git", - "reference": "896e7e70f02bd4fd77190052799bc61e4d779672" + "url": "https://github.com/mathmarques/Smarty-View.git", + "reference": "0e7e34611d78183efbf748fa351be3faf09bcbce" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/jeremykendall/php-domain-parser/zipball/896e7e70f02bd4fd77190052799bc61e4d779672", - "reference": "896e7e70f02bd4fd77190052799bc61e4d779672", + "url": "https://api.github.com/repos/mathmarques/Smarty-View/zipball/0e7e34611d78183efbf748fa351be3faf09bcbce", + "reference": "0e7e34611d78183efbf748fa351be3faf09bcbce", "shasum": "" }, "require": { - "ext-curl": "*", - "ext-intl": "*", - "ext-mbstring": "*", - "php": ">=5.3.0" + "php": ">=5.5.0", + "slim/slim": "^3.0", + "smarty/smarty": "~3.1" }, "require-dev": { - "jeremykendall/debug-die": "0.0.1.*", - "mikey179/vfsstream": "~1.4", - "phpunit/phpunit": "~4.4" + "phpunit/phpunit": "^4.8.0" }, - "bin": [ - "bin/parse", - "bin/update-psl" - ], "type": "library", "autoload": { - "psr-0": { - "Pdp\\": "src/" + "psr-4": { + "Slim\\Views\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Matheus Marques", + "email": "matheusocmarques@gmail.com", + "homepage": "http://matheusmarques.com" + } + ], + "description": "Slim Framework 3 view helper built on top of the Smarty templating component", + "keywords": [ + "framework", + "slim", + "smarty", + "template", + "view" + ], + "time": "2015-12-07 21:31:37" + }, + { + "name": "nikic/fast-route", + "version": "v0.6.0", + "source": { + "type": "git", + "url": "https://github.com/nikic/FastRoute.git", + "reference": "31fa86924556b80735f98b294a7ffdfb26789f22" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/nikic/FastRoute/zipball/31fa86924556b80735f98b294a7ffdfb26789f22", + "reference": "31fa86924556b80735f98b294a7ffdfb26789f22", + "shasum": "" + }, + "require": { + "php": ">=5.4.0" + }, + "type": "library", + "autoload": { + "psr-4": { + "FastRoute\\": "src/" }, "files": [ - "src/pdp-parse-url.php" + "src/functions.php" ] }, "notification-url": "https://packagist.org/downloads/", "license": [ - "MIT" + "BSD-3-Clause" ], "authors": [ { - "name": "Jeremy Kendall", - "homepage": "http://about.me/jeremykendall", - "role": "Developer" - }, - { - "name": "Contributors", - "homepage": "https://github.com/jeremykendall/php-domain-parser/graphs/contributors" + "name": "Nikita Popov", + "email": "nikic@php.net" } ], - "description": "Public Suffix List based URL parsing implemented in PHP.", - "homepage": "https://github.com/jeremykendall/php-domain-parser", + "description": "Fast request router for PHP", "keywords": [ - "Public Suffix List", - "domain parsing", - "url parsing" + "router", + "routing" ], - "time": "2015-03-30 12:49:45" + "time": "2015-06-18 19:15:47" }, { - "name": "league/uri", - "version": "4.1.0", + "name": "pimple/pimple", + "version": "v3.0.2", "source": { "type": "git", - "url": "https://github.com/thephpleague/uri.git", - "reference": "a4f0ea3323745214c955af2f6451d7743f30a076" + "url": "https://github.com/silexphp/Pimple.git", + "reference": "a30f7d6e57565a2e1a316e1baf2a483f788b258a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/thephpleague/uri/zipball/a4f0ea3323745214c955af2f6451d7743f30a076", - "reference": "a4f0ea3323745214c955af2f6451d7743f30a076", + "url": "https://api.github.com/repos/silexphp/Pimple/zipball/a30f7d6e57565a2e1a316e1baf2a483f788b258a", + "reference": "a30f7d6e57565a2e1a316e1baf2a483f788b258a", "shasum": "" }, "require": { - "ext-fileinfo": "*", - "ext-intl": "*", - "ext-mbstring": "*", - "jeremykendall/php-domain-parser": "^3.0", - "php": ">=5.5.9", - "psr/http-message": "^1.0" - }, - "require-dev": { - "fabpot/php-cs-fixer": "^1.9", - "phpunit/phpunit": "^4.0" + "php": ">=5.3.0" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "4.1-dev" + "dev-master": "3.0.x-dev" } }, "autoload": { - "psr-4": { - "League\\Uri\\": "src" + "psr-0": { + "Pimple": "src/" } }, "notification-url": "https://packagist.org/downloads/", @@ -126,26 +174,17 @@ ], "authors": [ { - "name": "Ignace Nyamagana Butera", - "email": "nyamsprod@gmail.com", - "homepage": "https://nyamsprod.com" + "name": "Fabien Potencier", + "email": "fabien@symfony.com" } ], - "description": "URI manipulation library", - "homepage": "http://url.thephpleague.com", + "description": "Pimple, a simple Dependency Injection Container", + "homepage": "http://pimple.sensiolabs.org", "keywords": [ - "data", - "data-uri", - "ftp", - "http", - "parse_url", - "psr-7", - "rfc3986", - "uri", - "url", - "ws" + "container", + "dependency injection" ], - "time": "2016-02-18 14:46:01" + "time": "2015-09-11 15:10:35" }, { "name": "psr/http-message", @@ -206,114 +245,35 @@ }, "type": "library" }, - { - "name": "rudloff/smarty-plugin-noscheme", - "version": "0.1.0", - "source": { - "type": "git", - "url": "https://github.com/Rudloff/smarty-plugin-noscheme.git", - "reference": "537bcb2f7576252af70d8f9f817bfe050d873072" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/Rudloff/smarty-plugin-noscheme/zipball/537bcb2f7576252af70d8f9f817bfe050d873072", - "reference": "537bcb2f7576252af70d8f9f817bfe050d873072", - "shasum": "" - }, - "require": { - "league/uri": "~4.0" - }, - "require-dev": { - "symfony/var-dumper": "~2.7.6" - }, - "type": "library", - "notification-url": "https://packagist.org/downloads/", - "license": [ - "GPL-3.0" - ], - "authors": [ - { - "name": "Pierre Rudloff", - "email": "contact@rudloff.pro", - "homepage": "https://rudloff.pro/", - "role": "Developer" - } - ], - "description": "Smarty modifier that removes the scheme in URLs", - "time": "2015-10-31 10:25:47" - }, { "name": "slim/slim", - "version": "2.6.2", + "version": "3.3.0", "source": { "type": "git", "url": "https://github.com/slimphp/Slim.git", - "reference": "20a02782f76830b67ae56a5c08eb1f563c351a37" + "reference": "939f2e85d57508de9cff241d10091cd972f221c3" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/slimphp/Slim/zipball/20a02782f76830b67ae56a5c08eb1f563c351a37", - "reference": "20a02782f76830b67ae56a5c08eb1f563c351a37", + "url": "https://api.github.com/repos/slimphp/Slim/zipball/939f2e85d57508de9cff241d10091cd972f221c3", + "reference": "939f2e85d57508de9cff241d10091cd972f221c3", "shasum": "" }, "require": { - "php": ">=5.3.0" + "container-interop/container-interop": "^1.1", + "nikic/fast-route": "^0.6", + "php": ">=5.5.0", + "pimple/pimple": "^3.0", + "psr/http-message": "^1.0" }, - "suggest": { - "ext-mcrypt": "Required for HTTP cookie encryption" - }, - "type": "library", - "autoload": { - "psr-0": { - "Slim": "." - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Josh Lockhart", - "email": "info@joshlockhart.com", - "homepage": "http://www.joshlockhart.com/" - } - ], - "description": "Slim Framework, a PHP micro framework", - "homepage": "http://github.com/codeguy/Slim", - "keywords": [ - "microframework", - "rest", - "router" - ], - "time": "2015-03-08 18:41:17" - }, - { - "name": "slim/views", - "version": "0.1.3", - "source": { - "type": "git", - "url": "https://github.com/slimphp/Slim-Views.git", - "reference": "8561c785e55a39df6cb6f95c3aba3281a60ed5b0" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/slimphp/Slim-Views/zipball/8561c785e55a39df6cb6f95c3aba3281a60ed5b0", - "reference": "8561c785e55a39df6cb6f95c3aba3281a60ed5b0", - "shasum": "" - }, - "require": { - "php": ">=5.3.0", - "slim/slim": ">=2.4.0" - }, - "suggest": { - "smarty/smarty": "Smarty templating system", - "twig/twig": "Twig templating system" + "require-dev": { + "phpunit/phpunit": "^4.0", + "squizlabs/php_codesniffer": "^2.5" }, "type": "library", "autoload": { "psr-4": { - "Slim\\Views\\": "./" + "Slim\\": "Slim" } }, "notification-url": "https://packagist.org/downloads/", @@ -321,25 +281,36 @@ "MIT" ], "authors": [ + { + "name": "Rob Allen", + "email": "rob@akrabat.com", + "homepage": "http://akrabat.com" + }, { "name": "Josh Lockhart", - "email": "info@joshlockhart.com", - "homepage": "http://www.joshlockhart.com/" + "email": "hello@joshlockhart.com", + "homepage": "https://joshlockhart.com" + }, + { + "name": "Gabriel Manricks", + "email": "gmanricks@me.com", + "homepage": "http://gabrielmanricks.com" }, { "name": "Andrew Smith", "email": "a.smith@silentworks.co.uk", - "homepage": "http://thoughts.silentworks.co.uk/" + "homepage": "http://silentworks.co.uk" } ], - "description": "Smarty and Twig View Parser package for the Slim Framework", - "homepage": "http://github.com/codeguy/Slim-Views", + "description": "Slim is a PHP micro framework that helps you quickly write simple yet powerful web applications and APIs", + "homepage": "http://slimframework.com", "keywords": [ - "extensions", - "slimphp", - "templating" + "api", + "framework", + "micro", + "router" ], - "time": "2014-12-09 23:48:51" + "time": "2016-03-10 21:37:40" }, { "name": "smarty/smarty", diff --git a/controllers/FrontController.php b/controllers/FrontController.php index 8a1074f..c4bd33a 100644 --- a/controllers/FrontController.php +++ b/controllers/FrontController.php @@ -30,63 +30,77 @@ class FrontController /** * Display index page * + * @param Request $request PSR-7 request + * @param Response $response PSR-7 response + * * @return void */ - static function index() + static function index($request, $response) { - global $app; + global $container; $config = Config::getInstance(); - $app->render( + $container->view->render( + $response, 'head.tpl', array( 'class'=>'index' ) ); - $app->render( + $container->view->render( + $response, 'header.tpl' ); - $app->render( + $container->view->render( + $response, 'index.tpl', array( 'convert'=>$config->convert ) ); - $app->render('footer.tpl'); + $container->view->render($response, 'footer.tpl'); } /** * Display a list of extractors * + * @param Request $request PSR-7 request + * @param Response $response PSR-7 response + * * @return void */ - static function extractors() + static function extractors($request, $response) { - global $app; - $app->render( + global $container; + $container->view->render( + $response, 'head.tpl', array( 'class'=>'extractors' ) ); - $app->render('header.tpl'); - $app->render('logo.tpl'); - $app->render( + $container->view->render($response, 'header.tpl'); + $container->view->render($response, 'logo.tpl'); + $container->view->render( + $response, 'extractors.tpl', array( 'extractors'=>VideoDownload::listExtractors() ) ); - $app->render('footer.tpl'); + $container->view->render($response, 'footer.tpl'); } /** * Dislay information about the video * + * @param Request $request PSR-7 request + * @param Response $response PSR-7 response + * * @return void */ - static function video() + static function video($request, $response) { - global $app; + global $container; $config = Config::getInstance(); if (isset($_GET["url"])) { if (isset($_GET['audio'])) { @@ -147,56 +161,63 @@ class FrontController } else { try { $video = VideoDownload::getJSON($_GET["url"]); - $app->render( + $container->view->render( + $response, 'head.tpl', array( 'class'=>'video' ) ); - $app->render( + $container->view->render( + $response, 'video.tpl', array( 'video'=>$video ) ); - $app->render('footer.tpl'); + $container->view->render($response, 'footer.tpl'); } catch (\Exception $e) { $error = $e->getMessage(); } } } if (isset($error)) { - $app->render( + $container->view->render( + $response, 'head.tpl', array( 'class'=>'video' ) ); - $app->render( + $container->view->render( + $response, 'error.tpl', array( 'errors'=>$error ) ); - $app->render('footer.tpl'); + $container->view->render($response, 'footer.tpl'); } } /** * Redirect to video file * + * @param Request $request PSR-7 request + * @param Response $response PSR-7 response + * * @return void */ - static function redirect() + static function redirect($request, $response) { global $app; if (isset($_GET["url"])) { try { $video = VideoDownload::getURL($_GET["url"]); - $app->redirect($video['url']); + return $response->withRedirect($video['url']); } catch (\Exception $e) { - $app->response->headers->set('Content-Type', 'text/plain'); echo $e->getMessage().PHP_EOL; + return $response->withHeader('Content-Type', 'text/plain'); } } } @@ -204,18 +225,22 @@ class FrontController /** * Output JSON info about the video * + * @param Request $request PSR-7 request + * @param Response $response PSR-7 response + * * @return void */ - static function json() + static function json($request, $response) { global $app; if (isset($_GET["url"])) { - $app->response->headers->set('Content-Type', 'application/json'); try { $video = VideoDownload::getJSON($_GET["url"]); - echo json_encode($video); + return $response->withJson($video); } catch (\Exception $e) { - echo json_encode(array('success'=>false, 'error'=>$e->getMessage())); + return $response->withJson( + array('success'=>false, 'error'=>$e->getMessage()) + ); } } } diff --git a/index.php b/index.php index 181ffa0..c136e46 100644 --- a/index.php +++ b/index.php @@ -15,16 +15,16 @@ require_once __DIR__.'/vendor/autoload.php'; use Alltube\VideoDownload; -$app = new \Slim\Slim( - array( - 'view' => new \Slim\Views\Smarty() - ) -); -$view = $app->view(); -$view->parserExtensions = array( - __DIR__.'/vendor/slim/views/SmartyPlugins', - __DIR__.'/vendor/rudloff/smarty-plugin-noscheme/' -); +$app = new \Slim\App(); +$container = $app->getContainer(); +$container['view'] = function ($c) { + $view = new \Slim\Views\Smarty(__DIR__.'/templates/'); + + $view->addSlimPlugins($c['router'], $c['request']->getUri()); + + return $view; +}; + $app->get( '/', array('Alltube\Controller\FrontController', 'index') @@ -32,11 +32,11 @@ $app->get( $app->get( '/extractors', array('Alltube\Controller\FrontController', 'extractors') -)->name('extractors'); +)->setName('extractors'); $app->get( '/video', array('Alltube\Controller\FrontController', 'video') -)->name('video'); +)->setName('video'); $app->get( '/redirect', array('Alltube\Controller\FrontController', 'redirect') diff --git a/templates/footer.tpl b/templates/footer.tpl index 41347f5..17dae57 100644 --- a/templates/footer.tpl +++ b/templates/footer.tpl @@ -17,6 +17,6 @@ · - + diff --git a/templates/head.tpl b/templates/head.tpl index 1383ae2..5c30192 100644 --- a/templates/head.tpl +++ b/templates/head.tpl @@ -4,21 +4,26 @@ - + AllTube Download - - - - + +{if isset($smarty.server.HTTPS)} + {$scheme = "https://"} +{else} + {$scheme = "http://"} +{/if} + + + - + - + diff --git a/templates/header.tpl b/templates/header.tpl index dfa1df2..fc42083 100644 --- a/templates/header.tpl +++ b/templates/header.tpl @@ -1,8 +1,8 @@
diff --git a/templates/index.tpl b/templates/index.tpl index b6bdf87..7f4fff3 100644 --- a/templates/index.tpl +++ b/templates/index.tpl @@ -1,7 +1,7 @@
-
-
+ @@ -20,10 +20,10 @@ {/if}
- See all supported websites + See all supported websites

Drag this to your bookmarks bar:

- Bookmarklet + Bookmarklet
diff --git a/templates/logo.tpl b/templates/logo.tpl index b063181..311f294 100644 --- a/templates/logo.tpl +++ b/templates/logo.tpl @@ -1,4 +1,4 @@

- -AllTube Download + +AllTube Download

diff --git a/templates/video.tpl b/templates/video.tpl index 3548013..b24024c 100644 --- a/templates/video.tpl +++ b/templates/video.tpl @@ -9,13 +9,13 @@ href="{$video->webpage_url}"> {$video->title}. Google Cast™ is disabled Google Cast™ -Casting to ChromeCast…

{if isset($video->thumbnail)}