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_size = 4
|
||||
|
||||
[**.blade.php]
|
||||
[**.latte]
|
||||
indent_style = tab
|
||||
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
|
||||
* [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)
|
||||
|
|
|
@ -7,7 +7,8 @@
|
|||
"php": "^8.0.0",
|
||||
"ext-curl": "*",
|
||||
"ssovit/tiktok-api": "^2.0",
|
||||
"bramus/router": "^1.6",
|
||||
"jenssegers/blade": "^1.4"
|
||||
"steampixel/simple-php-router": "^0.7.0",
|
||||
"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__ . "/helpers/domains.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 {
|
||||
$options = [];
|
||||
// Proxy config
|
||||
if (in_array($proxy_elements, $_COOKIE)) {
|
||||
foreach ($proxy_elements as $proxy_element) {
|
||||
$options[$proxy_element] = $_COOKIE[$proxy_element];
|
||||
|
@ -16,19 +20,27 @@ function getApi(array $proxy_elements): \Sovit\TikTok\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);
|
||||
header('Location: ./home');
|
||||
});
|
||||
|
||||
$router->get('/home', function () {
|
||||
$blade = new Blade('./views', './cache/views');
|
||||
echo $blade->render('home');
|
||||
Route::add('/home', function () {
|
||||
$latte = getLatte();
|
||||
$latte->render('./views/home.latte');
|
||||
});
|
||||
|
||||
$router->get('/images', function () use ($domains) {
|
||||
Route::add('/images', function () use ($domains) {
|
||||
if (!isset($_GET['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]]));
|
||||
if ($img) {
|
||||
header('Content-Type: image/jpeg');
|
||||
echo $img;
|
||||
return $img;
|
||||
} 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'])) {
|
||||
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]]));
|
||||
if ($audio) {
|
||||
header('Content-Type: audio/mp3');
|
||||
echo $audio;
|
||||
return $audio;
|
||||
} 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'])) {
|
||||
die('You need to send a url!');
|
||||
}
|
||||
|
@ -77,48 +89,54 @@ $router->get('/stream', function () use ($domains) {
|
|||
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->stream($url);
|
||||
});
|
||||
|
||||
$router->get("/trending", function () use ($proxy_elements) {
|
||||
Route::add("/trending", function () use ($proxy_elements) {
|
||||
$cursor = 0;
|
||||
if (isset($_GET['cursor']) && is_numeric($_GET['cursor'])) {
|
||||
$cursor = (int) $_GET['cursor'];
|
||||
}
|
||||
$blade = new Blade('./views', './cache/views');
|
||||
$latte = getLatte();
|
||||
$api = getApi($proxy_elements);
|
||||
$feed = $api->getTrendingFeed($cursor);
|
||||
if ($feed) {
|
||||
echo $blade->render('trending', ['feed' => $feed]);
|
||||
$latte->render(getView('trending'), ['feed' => $feed]);
|
||||
} else {
|
||||
echo 'ERROR!';
|
||||
return 'ERROR!';
|
||||
}
|
||||
});
|
||||
|
||||
$router->get("/@([^/]+)", function (string $username) use ($proxy_elements) {
|
||||
Route::add("/@([^/]+)", function (string $username) use ($proxy_elements) {
|
||||
$cursor = 0;
|
||||
if (isset($_GET['cursor']) && is_numeric($_GET['cursor'])) {
|
||||
$cursor = (int) $_GET['cursor'];
|
||||
}
|
||||
$blade = new Blade('./views', './cache/views');
|
||||
$latte = getLatte();
|
||||
$api = getApi($proxy_elements);
|
||||
$feed = $api->getUserFeed($username, $cursor);
|
||||
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 {
|
||||
echo 'ERROR!';
|
||||
return 'ERROR!';
|
||||
}
|
||||
});
|
||||
|
||||
$router->get("/settings", function () use ($proxy_elements) {
|
||||
$blade = new Blade('./views', './cache/views');
|
||||
echo $blade->render('settings', ["proxy_elements" => $proxy_elements]);
|
||||
Route::add("/settings", function () use ($proxy_elements) {
|
||||
$latte = getLatte();
|
||||
$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)) {
|
||||
foreach ($proxy_elements as $proxy_element) {
|
||||
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);
|
||||
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">
|
||||
</head>
|
||||
<body>
|
||||
@include('navbar')
|
||||
{include 'navbar.latte'}
|
||||
<section class="hero is-primary">
|
||||
<div class="hero-body">
|
||||
<div class="container">
|
||||
|
@ -19,6 +19,6 @@
|
|||
<section class="section">
|
||||
<p>TODO</p>
|
||||
</section>
|
||||
@include('footer')
|
||||
{include 'footer.latte'}
|
||||
</body>
|
||||
</html>
|
|
@ -1,30 +1,28 @@
|
|||
<section class="section">
|
||||
<div class="columns is-multiline is-vcentered">
|
||||
@foreach ($feed->items as $item)
|
||||
{foreach $feed->items as $item}
|
||||
<div class="column is-one-quarter">
|
||||
<a id="{{$item->id}}" href="#{{$item->id}}" class="clickable-img"
|
||||
data-video_url="./stream?url={{ $item->video->playAddr }}"
|
||||
data-video_download="./stream?url={{urlencode($item->video->downloadAddr)}}"
|
||||
data-desc="{{ $item->desc }}"
|
||||
data-video_width="{{ $item->video->width }}"
|
||||
data-video_height="{{ $item->video->height }}"
|
||||
data-music_title="{{ $item->music->title }}"
|
||||
data-music_url="./audios?url={{ urlencode($item->music->playUrl) }}">
|
||||
<img loading="lazy" src="./images?url={{ urlencode($item->video->originCover) }}"/>
|
||||
<a id="{$item->id}" href="#{$item->id}" class="clickable-img"
|
||||
data-video_url="./stream?url={$item->video->playAddr}"
|
||||
data-video_download="./stream?url={urlencode($item->video->downloadAddr)}&download=1"
|
||||
data-desc="{$item->desc}"
|
||||
data-video_width="{$item->video->width}"
|
||||
data-video_height="{$item->video->height}"
|
||||
data-music_title="{$item->music->title}"
|
||||
data-music_url="./audios?url={urlencode($item->music->playUrl)}">
|
||||
<img loading="lazy" src="./images?url={urlencode($item->video->originCover)}"/>
|
||||
</a>
|
||||
</div>
|
||||
@endforeach
|
||||
{/foreach}
|
||||
</div>
|
||||
<div class="buttons">
|
||||
@isset ($_GET['cursor'])
|
||||
<a class="button is-danger" href="?cursor=0">First</a>
|
||||
@endisset
|
||||
<a n:ifset="$_GET['cursor']" class="button is-danger" href="?cursor=0">First</a>
|
||||
<a class="button is-danger" href="javascript:history.back()">Back</a>
|
||||
@if ($feed->hasMore)
|
||||
<a class="button is-success" href="?cursor={{ $feed->maxCursor }}">Next</a>
|
||||
@else
|
||||
{if $feed->hasMore}
|
||||
<a n-if="$feed->hasMore" class="button is-success" href="?cursor={$feed->maxCursor}">Next</a>
|
||||
{else}
|
||||
<a class="button is-success" disabled title="No more videos available">Next</a>
|
||||
@endif
|
||||
{/if}
|
||||
</div>
|
||||
</section>
|
||||
<div id="modal" class="modal">
|
||||
|
@ -42,7 +40,7 @@
|
|||
<a id="download_button" target="_blank" class="button is-info" href="" download>Download</a>
|
||||
<p id="audio_title"></p>
|
||||
<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="next-button" class="button is-success">Next</button>
|
||||
</div>
|
|
@ -10,7 +10,7 @@
|
|||
</head>
|
||||
|
||||
<body>
|
||||
@include('navbar')
|
||||
{include 'navbar.latte'}
|
||||
<section class="hero is-fullheight-with-navbar">
|
||||
<div class="hero-body">
|
||||
<div class="container has-text-centered">
|
||||
|
@ -33,10 +33,10 @@
|
|||
</div>
|
||||
</div>
|
||||
<div class="hero-foot">
|
||||
@include('footer')
|
||||
{include 'footer.latte'}
|
||||
</div>
|
||||
</section>
|
||||
<script>
|
||||
<script n:syntax=off>
|
||||
const goToUser = (e) => {
|
||||
e.preventDefault()
|
||||
const formData = new FormData(e.target)
|
|
@ -8,7 +8,7 @@
|
|||
<link rel="stylesheet" href="https://unpkg.com/bulmaswatch/superhero/bulmaswatch.min.css">
|
||||
</head>
|
||||
<body>
|
||||
@include('navbar')
|
||||
{include 'navbar.latte'}
|
||||
<section class="hero is-primary">
|
||||
<div class="hero-body">
|
||||
<div class="container">
|
||||
|
@ -20,14 +20,14 @@
|
|||
<!-- Proxy settings -->
|
||||
<p class="title">Proxy</p>
|
||||
<form action="./settings" method="POST">
|
||||
@foreach ( $proxy_elements as $element)
|
||||
{foreach $proxy_elements as $proxy_element}
|
||||
<div class="field">
|
||||
<label class="label">{{ $element }}</label>
|
||||
<label class="label">{$proxy_element}</label>
|
||||
<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>
|
||||
@endforeach
|
||||
{/foreach}
|
||||
<div class="field">
|
||||
<div class="control">
|
||||
<button class="button is-success" type="submit">Submit</button>
|
||||
|
@ -35,6 +35,6 @@
|
|||
</div>
|
||||
</form>
|
||||
</section>
|
||||
@include('footer')
|
||||
{include 'footer.latte'}
|
||||
</body>
|
||||
</html>
|
|
@ -9,6 +9,7 @@
|
|||
<link rel="stylesheet" href="../styles/feed.css">
|
||||
</head>
|
||||
<body>
|
||||
{include 'navbar.latte'}
|
||||
<section class="hero is-primary">
|
||||
<div class="hero-body">
|
||||
<div class="container">
|
||||
|
@ -16,8 +17,7 @@
|
|||
</div>
|
||||
</div>
|
||||
</section>
|
||||
@include('navbar')
|
||||
@include('feed')
|
||||
@include('footer')
|
||||
{include 'feed.latte'}
|
||||
{include 'footer.latte'}
|
||||
</body>
|
||||
</html>
|
|
@ -4,21 +4,21 @@
|
|||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<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="../styles/feed.css">
|
||||
</head>
|
||||
<body>
|
||||
@include('navbar')
|
||||
{include 'navbar.latte'}
|
||||
<section class="hero is-primary">
|
||||
<div class="hero-body">
|
||||
<div class="container">
|
||||
<p class="title">{{ $feed->info->detail->user->uniqueId }}'s profile</p>
|
||||
<p class="subtitle">{{ $feed->info->detail->user->signature }}</p>
|
||||
<p class="title">{$feed->info->detail->user->uniqueId}'s profile</p>
|
||||
<p class="subtitle">{$feed->info->detail->user->signature}</p>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
@include('feed')
|
||||
@include('footer')
|
||||
{include 'feed.latte'}
|
||||
{include 'footer.latte'}
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in a new issue