Changed rendering template and router
This commit is contained in:
parent
5ae3b5c11c
commit
328f70e4f6
|
@ -31,7 +31,7 @@ indent_size = 2
|
||||||
indent_style = space
|
indent_style = space
|
||||||
indent_size = 4
|
indent_size = 4
|
||||||
|
|
||||||
[**.blade.php]
|
[**.latte]
|
||||||
indent_style = tab
|
indent_style = tab
|
||||||
indent_size = 2
|
indent_size = 2
|
||||||
|
|
||||||
|
|
1
.env.example
Normal file
1
.env.example
Normal file
|
@ -0,0 +1 @@
|
||||||
|
APP_SUBDIR=/ # Subpath your app is running, defaults to /
|
|
@ -20,5 +20,6 @@ php -S localhost:8080
|
||||||
|
|
||||||
## Credits
|
## Credits
|
||||||
* [TikTok-API-PHP](https://github.com/ssovit/TikTok-API-PHP)
|
* [TikTok-API-PHP](https://github.com/ssovit/TikTok-API-PHP)
|
||||||
* [bramus/router](https://github.com/bramus/router)
|
* [steampixel/simple-php-router](https://github.com/steampixel/simple-php-router)
|
||||||
|
* [PHP dotenv](https://github.com/vlucas/phpdotenv)
|
||||||
* [Bulma](https://github.com/jgthms/bulma)
|
* [Bulma](https://github.com/jgthms/bulma)
|
||||||
|
|
|
@ -7,7 +7,8 @@
|
||||||
"php": "^8.0.0",
|
"php": "^8.0.0",
|
||||||
"ext-curl": "*",
|
"ext-curl": "*",
|
||||||
"ssovit/tiktok-api": "^2.0",
|
"ssovit/tiktok-api": "^2.0",
|
||||||
"bramus/router": "^1.6",
|
"steampixel/simple-php-router": "^0.7.0",
|
||||||
"jenssegers/blade": "^1.4"
|
"latte/latte": "^2.10",
|
||||||
|
"vlucas/phpdotenv": "^5.4"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
1376
composer.lock
generated
1376
composer.lock
generated
File diff suppressed because it is too large
Load diff
75
index.php
75
index.php
|
@ -2,11 +2,15 @@
|
||||||
require __DIR__ . "/vendor/autoload.php";
|
require __DIR__ . "/vendor/autoload.php";
|
||||||
require __DIR__ . "/helpers/domains.php";
|
require __DIR__ . "/helpers/domains.php";
|
||||||
require __DIR__ . "/helpers/settings_elements.php";
|
require __DIR__ . "/helpers/settings_elements.php";
|
||||||
|
use Steampixel\Route;
|
||||||
|
|
||||||
use Jenssegers\Blade\Blade;
|
// LOAD DOTENV
|
||||||
|
$dotenv = Dotenv\Dotenv::createImmutable(__DIR__);
|
||||||
|
$dotenv->load();
|
||||||
|
|
||||||
function getApi(array $proxy_elements): \Sovit\TikTok\Api {
|
function getApi(array $proxy_elements): \Sovit\TikTok\Api {
|
||||||
$options = [];
|
$options = [];
|
||||||
|
// Proxy config
|
||||||
if (in_array($proxy_elements, $_COOKIE)) {
|
if (in_array($proxy_elements, $_COOKIE)) {
|
||||||
foreach ($proxy_elements as $proxy_element) {
|
foreach ($proxy_elements as $proxy_element) {
|
||||||
$options[$proxy_element] = $_COOKIE[$proxy_element];
|
$options[$proxy_element] = $_COOKIE[$proxy_element];
|
||||||
|
@ -16,19 +20,27 @@ function getApi(array $proxy_elements): \Sovit\TikTok\Api {
|
||||||
return $api;
|
return $api;
|
||||||
}
|
}
|
||||||
|
|
||||||
$router = new \Bramus\Router\Router();
|
function getLatte(): \Latte\Engine {
|
||||||
|
$latte = new Latte\Engine;
|
||||||
|
$latte->setTempDirectory('./cache/views');
|
||||||
|
return $latte;
|
||||||
|
}
|
||||||
|
|
||||||
$router->get('/', function () {
|
function getView(string $template): string {
|
||||||
|
return "./views/{$template}.latte";
|
||||||
|
}
|
||||||
|
|
||||||
|
Route::add('/', function () {
|
||||||
http_response_code(302);
|
http_response_code(302);
|
||||||
header('Location: ./home');
|
header('Location: ./home');
|
||||||
});
|
});
|
||||||
|
|
||||||
$router->get('/home', function () {
|
Route::add('/home', function () {
|
||||||
$blade = new Blade('./views', './cache/views');
|
$latte = getLatte();
|
||||||
echo $blade->render('home');
|
$latte->render('./views/home.latte');
|
||||||
});
|
});
|
||||||
|
|
||||||
$router->get('/images', function () use ($domains) {
|
Route::add('/images', function () use ($domains) {
|
||||||
if (!isset($_GET['url'])) {
|
if (!isset($_GET['url'])) {
|
||||||
die('You need to send a url!');
|
die('You need to send a url!');
|
||||||
}
|
}
|
||||||
|
@ -41,13 +53,13 @@ $router->get('/images', function () use ($domains) {
|
||||||
$img = file_get_contents($url, false, stream_context_create(['http' => ['ignore_errors' => true]]));
|
$img = file_get_contents($url, false, stream_context_create(['http' => ['ignore_errors' => true]]));
|
||||||
if ($img) {
|
if ($img) {
|
||||||
header('Content-Type: image/jpeg');
|
header('Content-Type: image/jpeg');
|
||||||
echo $img;
|
return $img;
|
||||||
} else {
|
} else {
|
||||||
echo 'Error while getting image!';
|
return 'Error while getting image!';
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
$router->get('/audios', function () use ($domains) {
|
Route::add('/audios', function () use ($domains) {
|
||||||
if (!isset($_GET['url'])) {
|
if (!isset($_GET['url'])) {
|
||||||
die('You need to send a url!');
|
die('You need to send a url!');
|
||||||
}
|
}
|
||||||
|
@ -59,13 +71,13 @@ $router->get('/audios', function () use ($domains) {
|
||||||
$audio = file_get_contents($url, false, stream_context_create(['http' => ['ignore_errors' => true]]));
|
$audio = file_get_contents($url, false, stream_context_create(['http' => ['ignore_errors' => true]]));
|
||||||
if ($audio) {
|
if ($audio) {
|
||||||
header('Content-Type: audio/mp3');
|
header('Content-Type: audio/mp3');
|
||||||
echo $audio;
|
return $audio;
|
||||||
} else {
|
} else {
|
||||||
echo 'Error while getting audio!';
|
return 'Error while getting audio!';
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
$router->get('/stream', function () use ($domains) {
|
Route::add('/stream', function () use ($domains) {
|
||||||
if (!isset($_GET['url'])) {
|
if (!isset($_GET['url'])) {
|
||||||
die('You need to send a url!');
|
die('You need to send a url!');
|
||||||
}
|
}
|
||||||
|
@ -77,48 +89,54 @@ $router->get('/stream', function () use ($domains) {
|
||||||
die('Not a valid URL');
|
die('Not a valid URL');
|
||||||
}
|
}
|
||||||
|
|
||||||
header('Content-Disposition: attachment; filename="tiktok.mp4"');
|
if (isset($_GET['download'])) {
|
||||||
|
header('Content-Disposition: attachment; filename="tiktok.mp4"');
|
||||||
|
}
|
||||||
|
|
||||||
$streamer = new \Sovit\TikTok\Stream();
|
$streamer = new \Sovit\TikTok\Stream();
|
||||||
$streamer->stream($url);
|
$streamer->stream($url);
|
||||||
});
|
});
|
||||||
|
|
||||||
$router->get("/trending", function () use ($proxy_elements) {
|
Route::add("/trending", function () use ($proxy_elements) {
|
||||||
$cursor = 0;
|
$cursor = 0;
|
||||||
if (isset($_GET['cursor']) && is_numeric($_GET['cursor'])) {
|
if (isset($_GET['cursor']) && is_numeric($_GET['cursor'])) {
|
||||||
$cursor = (int) $_GET['cursor'];
|
$cursor = (int) $_GET['cursor'];
|
||||||
}
|
}
|
||||||
$blade = new Blade('./views', './cache/views');
|
$latte = getLatte();
|
||||||
$api = getApi($proxy_elements);
|
$api = getApi($proxy_elements);
|
||||||
$feed = $api->getTrendingFeed($cursor);
|
$feed = $api->getTrendingFeed($cursor);
|
||||||
if ($feed) {
|
if ($feed) {
|
||||||
echo $blade->render('trending', ['feed' => $feed]);
|
$latte->render(getView('trending'), ['feed' => $feed]);
|
||||||
} else {
|
} else {
|
||||||
echo 'ERROR!';
|
return 'ERROR!';
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
$router->get("/@([^/]+)", function (string $username) use ($proxy_elements) {
|
Route::add("/@([^/]+)", function (string $username) use ($proxy_elements) {
|
||||||
$cursor = 0;
|
$cursor = 0;
|
||||||
if (isset($_GET['cursor']) && is_numeric($_GET['cursor'])) {
|
if (isset($_GET['cursor']) && is_numeric($_GET['cursor'])) {
|
||||||
$cursor = (int) $_GET['cursor'];
|
$cursor = (int) $_GET['cursor'];
|
||||||
}
|
}
|
||||||
$blade = new Blade('./views', './cache/views');
|
$latte = getLatte();
|
||||||
$api = getApi($proxy_elements);
|
$api = getApi($proxy_elements);
|
||||||
$feed = $api->getUserFeed($username, $cursor);
|
$feed = $api->getUserFeed($username, $cursor);
|
||||||
if ($feed) {
|
if ($feed) {
|
||||||
echo $blade->render('user', ['feed' => $feed]);
|
if ($feed->info->detail->user->privateAccount) {
|
||||||
|
http_response_code(400);
|
||||||
|
return 'Private account detected! Not supported';
|
||||||
|
}
|
||||||
|
$latte->render(getView('user'), ['feed' => $feed]);
|
||||||
} else {
|
} else {
|
||||||
echo 'ERROR!';
|
return 'ERROR!';
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
$router->get("/settings", function () use ($proxy_elements) {
|
Route::add("/settings", function () use ($proxy_elements) {
|
||||||
$blade = new Blade('./views', './cache/views');
|
$latte = getLatte();
|
||||||
echo $blade->render('settings', ["proxy_elements" => $proxy_elements]);
|
$latte->render(getView('settings'), ["proxy_elements" => $proxy_elements]);
|
||||||
});
|
});
|
||||||
|
|
||||||
$router->post("/settings", function () use ($proxy_elements) {
|
Route::add("/settings", function () use ($proxy_elements) {
|
||||||
if (in_array($proxy_elements, $_POST)) {
|
if (in_array($proxy_elements, $_POST)) {
|
||||||
foreach ($proxy_elements as $proxy_element) {
|
foreach ($proxy_elements as $proxy_element) {
|
||||||
setcookie($proxy_element, $_POST[$proxy_element], time()+60*60*24*30, '/', '', true, true);
|
setcookie($proxy_element, $_POST[$proxy_element], time()+60*60*24*30, '/', '', true, true);
|
||||||
|
@ -126,6 +144,7 @@ $router->post("/settings", function () use ($proxy_elements) {
|
||||||
}
|
}
|
||||||
http_response_code(302);
|
http_response_code(302);
|
||||||
header('Location: ./home');
|
header('Location: ./home');
|
||||||
});
|
}, 'POST');
|
||||||
|
|
||||||
$router->run();
|
$subdir = getenv('APP_SUBDIR');
|
||||||
|
Route::run($subdir);
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
<link rel="stylesheet" href="https://unpkg.com/bulmaswatch/superhero/bulmaswatch.min.css">
|
<link rel="stylesheet" href="https://unpkg.com/bulmaswatch/superhero/bulmaswatch.min.css">
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
@include('navbar')
|
{include 'navbar.latte'}
|
||||||
<section class="hero is-primary">
|
<section class="hero is-primary">
|
||||||
<div class="hero-body">
|
<div class="hero-body">
|
||||||
<div class="container">
|
<div class="container">
|
||||||
|
@ -19,6 +19,6 @@
|
||||||
<section class="section">
|
<section class="section">
|
||||||
<p>TODO</p>
|
<p>TODO</p>
|
||||||
</section>
|
</section>
|
||||||
@include('footer')
|
{include 'footer.latte'}
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
|
@ -1,30 +1,28 @@
|
||||||
<section class="section">
|
<section class="section">
|
||||||
<div class="columns is-multiline is-vcentered">
|
<div class="columns is-multiline is-vcentered">
|
||||||
@foreach ($feed->items as $item)
|
{foreach $feed->items as $item}
|
||||||
<div class="column is-one-quarter">
|
<div class="column is-one-quarter">
|
||||||
<a id="{{$item->id}}" href="#{{$item->id}}" class="clickable-img"
|
<a id="{$item->id}" href="#{$item->id}" class="clickable-img"
|
||||||
data-video_url="./stream?url={{ $item->video->playAddr }}"
|
data-video_url="./stream?url={$item->video->playAddr}"
|
||||||
data-video_download="./stream?url={{urlencode($item->video->downloadAddr)}}"
|
data-video_download="./stream?url={urlencode($item->video->downloadAddr)}&download=1"
|
||||||
data-desc="{{ $item->desc }}"
|
data-desc="{$item->desc}"
|
||||||
data-video_width="{{ $item->video->width }}"
|
data-video_width="{$item->video->width}"
|
||||||
data-video_height="{{ $item->video->height }}"
|
data-video_height="{$item->video->height}"
|
||||||
data-music_title="{{ $item->music->title }}"
|
data-music_title="{$item->music->title}"
|
||||||
data-music_url="./audios?url={{ urlencode($item->music->playUrl) }}">
|
data-music_url="./audios?url={urlencode($item->music->playUrl)}">
|
||||||
<img loading="lazy" src="./images?url={{ urlencode($item->video->originCover) }}"/>
|
<img loading="lazy" src="./images?url={urlencode($item->video->originCover)}"/>
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
@endforeach
|
{/foreach}
|
||||||
</div>
|
</div>
|
||||||
<div class="buttons">
|
<div class="buttons">
|
||||||
@isset ($_GET['cursor'])
|
<a n:ifset="$_GET['cursor']" class="button is-danger" href="?cursor=0">First</a>
|
||||||
<a class="button is-danger" href="?cursor=0">First</a>
|
|
||||||
@endisset
|
|
||||||
<a class="button is-danger" href="javascript:history.back()">Back</a>
|
<a class="button is-danger" href="javascript:history.back()">Back</a>
|
||||||
@if ($feed->hasMore)
|
{if $feed->hasMore}
|
||||||
<a class="button is-success" href="?cursor={{ $feed->maxCursor }}">Next</a>
|
<a n-if="$feed->hasMore" class="button is-success" href="?cursor={$feed->maxCursor}">Next</a>
|
||||||
@else
|
{else}
|
||||||
<a class="button is-success" disabled title="No more videos available">Next</a>
|
<a class="button is-success" disabled title="No more videos available">Next</a>
|
||||||
@endif
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
<div id="modal" class="modal">
|
<div id="modal" class="modal">
|
||||||
|
@ -42,7 +40,7 @@
|
||||||
<a id="download_button" target="_blank" class="button is-info" href="" download>Download</a>
|
<a id="download_button" target="_blank" class="button is-info" href="" download>Download</a>
|
||||||
<p id="audio_title"></p>
|
<p id="audio_title"></p>
|
||||||
<audio id="audio" controls preload="none"></audio>
|
<audio id="audio" controls preload="none"></audio>
|
||||||
<div class="buttons">
|
<div class="buttons is-centered">
|
||||||
<button id="back-button" class="button is-danger">Back</button>
|
<button id="back-button" class="button is-danger">Back</button>
|
||||||
<button id="next-button" class="button is-success">Next</button>
|
<button id="next-button" class="button is-success">Next</button>
|
||||||
</div>
|
</div>
|
|
@ -10,7 +10,7 @@
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
@include('navbar')
|
{include 'navbar.latte'}
|
||||||
<section class="hero is-fullheight-with-navbar">
|
<section class="hero is-fullheight-with-navbar">
|
||||||
<div class="hero-body">
|
<div class="hero-body">
|
||||||
<div class="container has-text-centered">
|
<div class="container has-text-centered">
|
||||||
|
@ -33,10 +33,10 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="hero-foot">
|
<div class="hero-foot">
|
||||||
@include('footer')
|
{include 'footer.latte'}
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
<script>
|
<script n:syntax=off>
|
||||||
const goToUser = (e) => {
|
const goToUser = (e) => {
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
const formData = new FormData(e.target)
|
const formData = new FormData(e.target)
|
|
@ -8,7 +8,7 @@
|
||||||
<link rel="stylesheet" href="https://unpkg.com/bulmaswatch/superhero/bulmaswatch.min.css">
|
<link rel="stylesheet" href="https://unpkg.com/bulmaswatch/superhero/bulmaswatch.min.css">
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
@include('navbar')
|
{include 'navbar.latte'}
|
||||||
<section class="hero is-primary">
|
<section class="hero is-primary">
|
||||||
<div class="hero-body">
|
<div class="hero-body">
|
||||||
<div class="container">
|
<div class="container">
|
||||||
|
@ -20,14 +20,14 @@
|
||||||
<!-- Proxy settings -->
|
<!-- Proxy settings -->
|
||||||
<p class="title">Proxy</p>
|
<p class="title">Proxy</p>
|
||||||
<form action="./settings" method="POST">
|
<form action="./settings" method="POST">
|
||||||
@foreach ( $proxy_elements as $element)
|
{foreach $proxy_elements as $proxy_element}
|
||||||
<div class="field">
|
<div class="field">
|
||||||
<label class="label">{{ $element }}</label>
|
<label class="label">{$proxy_element}</label>
|
||||||
<div class="control">
|
<div class="control">
|
||||||
<input name="{{ $element }}" class="input" value="{{ isset($_COOKIE[$element]) ? $_COOKIE[$element] : ''}}" required />
|
<input name="{$proxy_element}" class="input" value="{isset($_COOKIE[$proxy_element]) ? $_COOKIE[$proxy_element] : ''}" required />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@endforeach
|
{/foreach}
|
||||||
<div class="field">
|
<div class="field">
|
||||||
<div class="control">
|
<div class="control">
|
||||||
<button class="button is-success" type="submit">Submit</button>
|
<button class="button is-success" type="submit">Submit</button>
|
||||||
|
@ -35,6 +35,6 @@
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
</section>
|
</section>
|
||||||
@include('footer')
|
{include 'footer.latte'}
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
|
@ -9,6 +9,7 @@
|
||||||
<link rel="stylesheet" href="../styles/feed.css">
|
<link rel="stylesheet" href="../styles/feed.css">
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
{include 'navbar.latte'}
|
||||||
<section class="hero is-primary">
|
<section class="hero is-primary">
|
||||||
<div class="hero-body">
|
<div class="hero-body">
|
||||||
<div class="container">
|
<div class="container">
|
||||||
|
@ -16,8 +17,7 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
@include('navbar')
|
{include 'feed.latte'}
|
||||||
@include('feed')
|
{include 'footer.latte'}
|
||||||
@include('footer')
|
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
|
@ -4,21 +4,21 @@
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
<meta http-equiv="X-UA-Compatible" content="ie=edge">
|
<meta http-equiv="X-UA-Compatible" content="ie=edge">
|
||||||
<title>{{ $feed->info->detail->user->nickname }} - TikTok</title>
|
<title>{$feed->info->detail->user->nickname} - TikTok</title>
|
||||||
<link rel="stylesheet" href="https://unpkg.com/bulmaswatch/superhero/bulmaswatch.min.css">
|
<link rel="stylesheet" href="https://unpkg.com/bulmaswatch/superhero/bulmaswatch.min.css">
|
||||||
<link rel="stylesheet" href="../styles/feed.css">
|
<link rel="stylesheet" href="../styles/feed.css">
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
@include('navbar')
|
{include 'navbar.latte'}
|
||||||
<section class="hero is-primary">
|
<section class="hero is-primary">
|
||||||
<div class="hero-body">
|
<div class="hero-body">
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<p class="title">{{ $feed->info->detail->user->uniqueId }}'s profile</p>
|
<p class="title">{$feed->info->detail->user->uniqueId}'s profile</p>
|
||||||
<p class="subtitle">{{ $feed->info->detail->user->signature }}</p>
|
<p class="subtitle">{$feed->info->detail->user->signature}</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
@include('feed')
|
{include 'feed.latte'}
|
||||||
@include('footer')
|
{include 'footer.latte'}
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
Loading…
Reference in a new issue