From 649b8e5351437727683dc350cb138599795b2e54 Mon Sep 17 00:00:00 2001 From: Pierre Rudloff Date: Sun, 8 Jan 2017 23:51:14 +0100 Subject: [PATCH 1/6] Remove unused redirects --- .htaccess | 3 --- 1 file changed, 3 deletions(-) diff --git a/.htaccess b/.htaccess index 8ccd69c8..5b53e939 100644 --- a/.htaccess +++ b/.htaccess @@ -21,7 +21,4 @@ RewriteRule ^(.*)$ https://www.alltubedownload.net/$1 [R=301,L] RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^ index.php [QSA,L] -Redirect permanent /api.php /video -Redirect permanent /extractors.php /extractors - AddOutputFilterByType DEFLATE text/css text/html application/javascript font/truetype From 52ae6eaefff26607dd0fa3c4903820108f74d5c2 Mon Sep 17 00:00:00 2001 From: Pierre Rudloff Date: Mon, 9 Jan 2017 00:05:49 +0100 Subject: [PATCH 2/6] Add ifmodule conditions in .htaccess --- .htaccess | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/.htaccess b/.htaccess index 5b53e939..32a41b4c 100644 --- a/.htaccess +++ b/.htaccess @@ -1,5 +1,7 @@ -AddType application/x-web-app-manifest+json .webapp -Addtype font/truetype .ttf + + AddType application/x-web-app-manifest+json .webapp + Addtype font/truetype .ttf + ExpiresActive On @@ -21,4 +23,6 @@ RewriteRule ^(.*)$ https://www.alltubedownload.net/$1 [R=301,L] RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^ index.php [QSA,L] -AddOutputFilterByType DEFLATE text/css text/html application/javascript font/truetype + + AddOutputFilterByType DEFLATE text/css text/html application/javascript font/truetype + From 4562c888599265d048df614977872341c76c952b Mon Sep 17 00:00:00 2001 From: Pierre Rudloff Date: Tue, 10 Jan 2017 23:09:57 +0100 Subject: [PATCH 3/6] youtube-dl update --- composer.json | 6 +++--- composer.lock | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/composer.json b/composer.json index eb602b70..3d917196 100644 --- a/composer.json +++ b/composer.json @@ -19,7 +19,7 @@ "squizlabs/php_codesniffer": "~2.7.0", "phpunit/phpunit": "~5.7.2", "ffmpeg/ffmpeg": "dev-release", - "rg3/youtube-dl": "~2016.12.22", + "rg3/youtube-dl": "~2017.01.10", "rudloff/rtmpdump-bin": "~2.3", "heroku/heroku-buildpack-php": "*" }, @@ -35,10 +35,10 @@ "type": "package", "package": { "name": "rg3/youtube-dl", - "version": "2016.12.22", + "version": "2017.01.10", "dist": { "type": "zip", - "url": "https://github.com/rg3/youtube-dl/archive/2016.12.22.zip" + "url": "https://github.com/rg3/youtube-dl/archive/2017.01.10.zip" } } }, diff --git a/composer.lock b/composer.lock index 660f8554..f9f96e3f 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "content-hash": "91e14c843bc92c4d5af1ec7abcddf15a", + "content-hash": "16268cc5135ed42aedf75446f4e39bd7", "packages": [ { "name": "aura/session", @@ -1466,10 +1466,10 @@ }, { "name": "rg3/youtube-dl", - "version": "2016.12.22", + "version": "2017.01.10", "dist": { "type": "zip", - "url": "https://github.com/rg3/youtube-dl/archive/2016.12.22.zip", + "url": "https://github.com/rg3/youtube-dl/archive/2017.01.10.zip", "reference": null, "shasum": null }, From 9f112c15b9948a548a297b077c2ff2a2b4a3c3ed Mon Sep 17 00:00:00 2001 From: Pierre Rudloff Date: Tue, 10 Jan 2017 23:37:29 +0100 Subject: [PATCH 4/6] Add an uglyUrls option that disables URL rewriting (fixes #88) --- classes/Config.php | 6 +++ classes/UglyRouter.php | 60 ++++++++++++++++++++++++ config.example.yml | 1 + controllers/FrontController.php | 1 + index.php | 6 +++ templates/index.tpl | 3 ++ templates/video.tpl | 3 ++ tests/UglyRouterTest.php | 82 +++++++++++++++++++++++++++++++++ 8 files changed, 162 insertions(+) create mode 100644 classes/UglyRouter.php create mode 100644 tests/UglyRouterTest.php diff --git a/classes/Config.php b/classes/Config.php index c57c848a..a66955cb 100644 --- a/classes/Config.php +++ b/classes/Config.php @@ -75,6 +75,12 @@ class Config */ public $curl_params = []; + /** + * Disable URL rewriting. + * @var boolean + */ + public $uglyUrls = false; + /** * YAML config file path. * diff --git a/classes/UglyRouter.php b/classes/UglyRouter.php new file mode 100644 index 00000000..a81471bc --- /dev/null +++ b/classes/UglyRouter.php @@ -0,0 +1,60 @@ +getUri()->getQuery(), $args); + $uri = '/'; + if (isset($args['page'])) { + $uri .= $args['page']; + } + + return $this->createDispatcher()->dispatch( + $request->getMethod(), + $uri + ); + } + + /** + * Build the path for a named route including the base path + * + * @param string $name Route name + * @param array $data Named argument replacement data + * @param array $queryParams Optional query string parameters + * + * @return string + * + * @throws \RuntimeException If named route does not exist + * @throws \InvalidArgumentException If required data not provided + */ + public function pathFor($name, array $data = [], array $queryParams = []) + { + $url = str_replace('/', '/?page=', $this->relativePathFor($name, $data, $queryParams)); + + if ($this->basePath) { + $url = $this->basePath . $url; + } + + return $url; + } +} diff --git a/config.example.yml b/config.example.yml index ca03f0b5..7fb80eff 100644 --- a/config.example.yml +++ b/config.example.yml @@ -11,3 +11,4 @@ convert: false avconv: vendor/bin/ffmpeg rtmpdump: vendor/bin/rtmpdump curl: /usr/bin/curl +uglyUrls: false diff --git a/controllers/FrontController.php b/controllers/FrontController.php index d42aebcd..c4421fe9 100644 --- a/controllers/FrontController.php +++ b/controllers/FrontController.php @@ -85,6 +85,7 @@ public function index(Request $request, Response $response) 'index.tpl', [ 'convert' => $this->config->convert, + 'uglyUrls' => $this->config->uglyUrls, 'class' => 'index', 'description' => 'Easily download videos from Youtube, Dailymotion, Vimeo and other websites.', ] diff --git a/index.php b/index.php index 6db8190a..feca012c 100644 --- a/index.php +++ b/index.php @@ -2,6 +2,8 @@ require_once __DIR__.'/vendor/autoload.php'; use Alltube\Controller\FrontController; +use Alltube\Config; +use Alltube\UglyRouter; if (isset($_SERVER['REQUEST_URI']) && strpos($_SERVER['REQUEST_URI'], '/index.php') !== false) { header('Location: '.str_ireplace('/index.php', '/', $_SERVER['REQUEST_URI'])); @@ -10,6 +12,10 @@ $app = new \Slim\App(); $container = $app->getContainer(); +$config = Config::getInstance(); +if ($config->uglyUrls) { + $container['router'] = new UglyRouter(); +} $container['view'] = function ($c) { $view = new \Slim\Views\Smarty(__DIR__.'/templates/'); diff --git a/templates/index.tpl b/templates/index.tpl index 93f44ebc..66eb1ab2 100644 --- a/templates/index.tpl +++ b/templates/index.tpl @@ -12,6 +12,9 @@ + {if uglyUrls} + + {/if}
{if $convert}
diff --git a/templates/video.tpl b/templates/video.tpl index 6f11251d..678ffbd1 100644 --- a/templates/video.tpl +++ b/templates/video.tpl @@ -24,6 +24,9 @@

+ {if uglyUrls} + + {/if}