Permalink
Browse files

Merge branch 'release-0.7.2-beta'

  • Loading branch information...
2 parents b3fe973 + 3a1d0c4 commit c8e8cacfef573919a718f1b5ac0ac4fc6022ca94 @Rudloff committed Jan 10, 2017
Showing with 183 additions and 16 deletions.
  1. +7 −6 .htaccess
  2. +7 −0 classes/Config.php
  3. +61 −0 classes/UglyRouter.php
  4. +3 −3 composer.json
  5. +3 −3 composer.lock
  6. +1 −0 config.example.yml
  7. +4 −3 controllers/FrontController.php
  8. +6 −0 index.php
  9. +1 −1 package.json
  10. +3 −0 templates/index.tpl
  11. +3 −0 templates/video.tpl
  12. +84 −0 tests/UglyRouterTest.php
View
@@ -1,5 +1,7 @@
-AddType application/x-web-app-manifest+json .webapp
-Addtype font/truetype .ttf
+<ifmodule mod_expires.c>
+ AddType application/x-web-app-manifest+json .webapp
+ Addtype font/truetype .ttf
+</ifmodule>
<ifmodule mod_expires.c>
ExpiresActive On
@@ -21,7 +23,6 @@ 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
+<ifmodule mod_filter.c>
+ AddOutputFilterByType DEFLATE text/css text/html application/javascript font/truetype
+</ifmodule>
View
@@ -76,6 +76,13 @@ class Config
public $curl_params = [];
/**
+ * Disable URL rewriting.
+ *
+ * @var bool
+ */
+ public $uglyUrls = false;
+
+ /**
* YAML config file path.
*
* @var string
@@ -0,0 +1,61 @@
+<?php
+/**
+ * UglyRouter class.
+ */
+
+namespace Alltube;
+
+use Psr\Http\Message\ServerRequestInterface;
+use Slim\Router;
+
+/**
+ * Extend Slim's router class in order to disable URL rewriting.
+ */
+class UglyRouter extends Router
+{
+ /**
+ * Dispatch router for HTTP request.
+ *
+ * @param ServerRequestInterface $request The current HTTP request object
+ *
+ * @return array
+ *
+ * @link https://github.com/nikic/FastRoute/blob/master/src/Dispatcher.php
+ */
+ public function dispatch(ServerRequestInterface $request)
+ {
+ parse_str($request->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
+ *
+ * @throws \RuntimeException If named route does not exist
+ * @throws \InvalidArgumentException If required data not provided
+ *
+ * @return string
+ */
+ 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;
+ }
+}
View
@@ -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"
}
}
},
View
@@ -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
},
View
@@ -11,3 +11,4 @@ convert: false
avconv: vendor/bin/ffmpeg
rtmpdump: vendor/bin/rtmpdump
curl: /usr/bin/curl
+uglyUrls: false
@@ -84,9 +84,10 @@ public function index(Request $request, Response $response)
$response,
'index.tpl',
[
- 'convert' => $this->config->convert,
- 'class' => 'index',
- 'description' => 'Easily download videos from Youtube, Dailymotion, Vimeo and other websites.',
+ 'convert' => $this->config->convert,
+ 'uglyUrls' => $this->config->uglyUrls,
+ 'class' => 'index',
+ 'description' => 'Easily download videos from Youtube, Dailymotion, Vimeo and other websites.',
]
);
}
View
@@ -1,7 +1,9 @@
<?php
require_once __DIR__.'/vendor/autoload.php';
+use Alltube\Config;
use Alltube\Controller\FrontController;
+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/');
View
@@ -1,7 +1,7 @@
{
"name": "alltube",
"description": "HTML GUI for youtube-dl",
- "version": "0.7.1",
+ "version": "0.7.2-beta",
"author": "Pierre Rudloff",
"bugs": "https://github.com/Rudloff/alltube/issues",
"dependencies": {
View
@@ -12,6 +12,9 @@
<input class="URLinput" type="url" name="url" id="url"
required autofocus placeholder="http://example.com/video" />
</span>
+ {if uglyUrls}
+ <input type="hidden" name="page" value="video" />
+ {/if}
<input class="downloadBtn" type="submit" value="Download" /><br/>
{if $convert}
<div class="mp3">
View
@@ -24,6 +24,9 @@
<h3><label for="format">Available formats:</label></h3>
<form action="{path_for name="redirect"}">
<input type="hidden" name="url" value="{$video->webpage_url}" />
+ {if uglyUrls}
+ <input type="hidden" name="page" value="redirect" />
+ {/if}
<select name="format" id="format" class="formats monospace">
<optgroup label="Generic formats">
<option value="best[protocol^=http]">
@@ -0,0 +1,84 @@
+<?php
+/**
+ * UglyRouterTest class.
+ */
+
+namespace Alltube\Test;
+
+use Alltube\UglyRouter;
+use Slim\Http\Environment;
+use Slim\Http\Headers;
+use Slim\Http\Request;
+use Slim\Http\Stream;
+use Slim\Http\Uri;
+
+/**
+ * Unit tests for the UglyRouter class.
+ */
+class UglyRouterTest extends \PHPUnit_Framework_TestCase
+{
+ /**
+ * UglyRouter instance.
+ *
+ * @var UglyRouter
+ */
+ private $router;
+
+ /**
+ * Prepare tests.
+ */
+ protected function setUp()
+ {
+ $this->router = new UglyRouter();
+ $this->router->map(['GET'], '/foo', 'print')->setName('foo');
+ }
+
+ /**
+ * Test the dispatch() function.
+ *
+ * @return void
+ */
+ public function testDispatch()
+ {
+ $this->assertEquals(
+ [1, 'route0', []],
+ $this->router->dispatch(
+ new Request(
+ 'GET',
+ Uri::createFromString('http://example.com/?page=foo'),
+ Headers::createFromEnvironment(new Environment()),
+ [],
+ [],
+ new Stream(fopen('php://temp', 'r'))
+ )
+ )
+ );
+ }
+
+ /**
+ * Test the pathFor() function.
+ *
+ * @return void
+ */
+ public function testPathFor()
+ {
+ $this->assertEquals(
+ '/?page=foo',
+ $this->router->pathFor('foo', [], [])
+ );
+ }
+
+ /**
+ * Test the pathFor() function with a base path.
+ *
+ * @return void
+ */
+ public function testPathForWithBasePath()
+ {
+ $this->router->setBasePath('/bar');
+ $this->assertEquals(
+ '/bar/?page=foo',
+ $this->router->pathFor('foo', [], [])
+ );
+ }
+}

0 comments on commit c8e8cac

Please sign in to comment.