alltube/index.php

83 lines
1.8 KiB
PHP
Raw Normal View History

2016-08-01 18:04:44 +02:00
<?php
2016-09-08 00:28:28 +02:00
2015-10-31 15:42:25 +01:00
require_once __DIR__.'/vendor/autoload.php';
use Alltube\Config;
2017-01-10 23:39:58 +01:00
use Alltube\Controller\FrontController;
2017-05-30 22:20:16 +02:00
use Alltube\LocaleManager;
2017-05-29 21:11:59 +02:00
use Alltube\LocaleMiddleware;
use Alltube\UglyRouter;
use Alltube\ViewFactory;
use Slim\App;
2015-10-29 21:19:40 +01:00
2016-10-26 17:16:17 +02:00
if (isset($_SERVER['REQUEST_URI']) && strpos($_SERVER['REQUEST_URI'], '/index.php') !== false) {
2016-07-27 02:19:29 +02:00
header('Location: '.str_ireplace('/index.php', '/', $_SERVER['REQUEST_URI']));
die;
}
if (is_file(__DIR__.'/config/config.yml')) {
Config::setFile(__DIR__.'/config/config.yml');
}
$app = new App();
2016-03-30 01:39:47 +02:00
$container = $app->getContainer();
$config = Config::getInstance();
if ($config->uglyUrls) {
$container['router'] = new UglyRouter();
}
$container['view'] = ViewFactory::create($container);
if (!class_exists('Locale')) {
die('You need to install the intl extension for PHP.');
}
2017-05-30 22:20:16 +02:00
$container['locale'] = new LocaleManager($_COOKIE);
$app->add(new LocaleMiddleware($container));
2016-03-30 01:39:47 +02:00
$controller = new FrontController($container, $_COOKIE);
2016-04-08 19:06:41 +02:00
2016-09-08 00:28:28 +02:00
$container['errorHandler'] = [$controller, 'error'];
2016-05-01 01:25:08 +02:00
2015-10-29 21:23:02 +01:00
$app->get(
'/',
2016-09-08 00:28:28 +02:00
[$controller, 'index']
2016-06-09 21:15:44 +02:00
)->setName('index');
2015-10-29 21:23:02 +01:00
$app->get(
'/extractors',
2016-09-08 00:28:28 +02:00
[$controller, 'extractors']
2016-03-30 01:39:47 +02:00
)->setName('extractors');
$app->any(
'/info',
[$controller, 'info']
)->setName('info');
// Legacy route.
$app->any('/video', [$controller, 'info']);
$app->any(
'/watch',
[$controller, 'video']
);
2015-10-31 11:48:14 +01:00
$app->get(
'/download',
[$controller, 'download']
)->setName('download');
// Legacy route.
$app->get('/redirect', [$controller, 'download']);
2018-03-20 12:02:21 +01:00
$app->get(
'/json',
[$controller, 'json']
)->setName('json');
2017-05-30 22:20:16 +02:00
$app->get(
'/locale/{locale}',
[$controller, 'locale']
)->setName('locale');
try {
$app->run();
} catch (SmartyException $e) {
die('Smarty could not compile the template file: '.$e->getMessage());
}