diff --git a/classes/Config.php b/classes/Config.php index c57c848..a66955c 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 0000000..a81471b --- /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 ca03f0b..7fb80ef 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 d42aebc..c4421fe 100644 --- a/controllers/FrontController.php +++ b/controllers/FrontController.php @@ -85,6 +85,7 @@ class FrontController '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 6db8190..feca012 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 @@ if (isset($_SERVER['REQUEST_URI']) && strpos($_SERVER['REQUEST_URI'], '/index.ph $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 93f44eb..66eb1ab 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 6f11251..678ffbd 100644 --- a/templates/video.tpl +++ b/templates/video.tpl @@ -24,6 +24,9 @@

+ {if uglyUrls} + + {/if}