Initial URLify of vid desc and profile
This commit is contained in:
parent
9364a2e212
commit
4188fcf064
7
app/Constants/TextExtras.php
Normal file
7
app/Constants/TextExtras.php
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
<?php
|
||||||
|
namespace App\Constants;
|
||||||
|
|
||||||
|
abstract class TextExtras {
|
||||||
|
const USER = 0;
|
||||||
|
const HASHTAG = 1;
|
||||||
|
}
|
|
@ -5,10 +5,9 @@ use App\Cache\ApcuCache;
|
||||||
use App\Cache\JSONCache;
|
use App\Cache\JSONCache;
|
||||||
use App\Cache\RedisCache;
|
use App\Cache\RedisCache;
|
||||||
use App\Constants\CacheMethods;
|
use App\Constants\CacheMethods;
|
||||||
|
use App\Constants\TextExtras;
|
||||||
use App\Models\BaseTemplate;
|
use App\Models\BaseTemplate;
|
||||||
|
|
||||||
use TikScraper\Constants\UserAgents as TikScraperUserAgents;
|
|
||||||
|
|
||||||
class Wrappers {
|
class Wrappers {
|
||||||
/**
|
/**
|
||||||
* Setup of Latte template engine
|
* Setup of Latte template engine
|
||||||
|
@ -92,6 +91,30 @@ class Wrappers {
|
||||||
return UrlBuilder::download($url, $username, $id, $watermark);
|
return UrlBuilder::download($url, $username, $id, $watermark);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Add URLs to video descriptions
|
||||||
|
// TODO: Make it work with unicode characters such as emojis
|
||||||
|
$latte->addFunction('render_desc', function (string $desc, array $textExtras = []): string {
|
||||||
|
$sanitizedDesc = htmlspecialchars($desc);
|
||||||
|
$out = $sanitizedDesc;
|
||||||
|
foreach ($textExtras as $extra) {
|
||||||
|
$url = '';
|
||||||
|
$text = mb_substr($desc, $extra->start, $extra->end - $extra->start, 'UTF-8');
|
||||||
|
switch ($extra->type) {
|
||||||
|
// User URL
|
||||||
|
case TextExtras::USER:
|
||||||
|
$url = UrlBuilder::user(htmlspecialchars($extra->userUniqueId));
|
||||||
|
break;
|
||||||
|
// Hashtag URL
|
||||||
|
case TextExtras::HASHTAG:
|
||||||
|
$url = UrlBuilder::tag(htmlspecialchars($extra->hashtagName));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
$out = str_replace($text, "<a href=\"$url\">$text</a>", $out);
|
||||||
|
}
|
||||||
|
return $out;
|
||||||
|
});
|
||||||
|
|
||||||
$latte->render(Misc::getView($template), $base);
|
$latte->render(Misc::getView($template), $base);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
{if !empty($item->challenges)}
|
{if !empty($item->challenges)}
|
||||||
<p>{include './common/tags.latte', challenges: $item->challenges}</p>
|
<p>{include './common/tags.latte', challenges: $item->challenges}</p>
|
||||||
{/if}
|
{/if}
|
||||||
<p n:ifcontent>{$item->desc}</p>
|
<p n:ifcontent>{render_desc($item->desc, $item->textExtra)|noescape}</p>
|
||||||
<p>Song: {$item->music->title}</p>
|
<p>Song: {$item->music->title}</p>
|
||||||
<audio controls preload="none" src="{url_stream($item->music->playUrl)}"></audio>
|
<audio controls preload="none" src="{url_stream($item->music->playUrl)}"></audio>
|
||||||
{include './common/stats.latte', playCount: $item->stats->playCount, diggCount: $item->stats->diggCount, commentCount: $item->stats->commentCount, shareCount: $item->stats->shareCount}
|
{include './common/stats.latte', playCount: $item->stats->playCount, diggCount: $item->stats->diggCount, commentCount: $item->stats->commentCount, shareCount: $item->stats->shareCount}
|
||||||
|
|
|
@ -15,8 +15,10 @@
|
||||||
{if $info->detail->privateAccount}
|
{if $info->detail->privateAccount}
|
||||||
<p><strong>Private account</strong></p>
|
<p><strong>Private account</strong></p>
|
||||||
{/if}
|
{/if}
|
||||||
<p></p>
|
|
||||||
<p>{$info->detail->signature}</p>
|
<p>{$info->detail->signature}</p>
|
||||||
|
{if isset($info->detail->bioLink)}
|
||||||
|
<p>Link: <a href="{$info->detail->bioLink->link}">{$info->detail->bioLink->link}</a></p>
|
||||||
|
{/if}
|
||||||
<p>Following: {number($info->stats->followingCount)} / Followers: {number($info->stats->followerCount)}</p>
|
<p>Following: {number($info->stats->followingCount)} / Followers: {number($info->stats->followerCount)}</p>
|
||||||
<p>Hearts: {number($info->stats->heartCount)} / Videos: {$info->stats->videoCount}</p>
|
<p>Hearts: {number($info->stats->heartCount)} / Videos: {$info->stats->videoCount}</p>
|
||||||
{/block}
|
{/block}
|
||||||
|
|
|
@ -33,7 +33,7 @@
|
||||||
<p>{include '../components/themes/common/tags.latte', challenges: $item->challenges}</p>
|
<p>{include '../components/themes/common/tags.latte', challenges: $item->challenges}</p>
|
||||||
{/if}
|
{/if}
|
||||||
<div class="content">
|
<div class="content">
|
||||||
<p n:ifcontent>{$item->desc}</p>
|
<p n:ifcontent>{render_desc($item->desc, $item->textExtra)|noescape}</p>
|
||||||
<p>Song: {$item->music->title}</p>
|
<p>Song: {$item->music->title}</p>
|
||||||
<audio controls preload="none" src="{url_stream($item->music->playUrl)}"></audio>
|
<audio controls preload="none" src="{url_stream($item->music->playUrl)}"></audio>
|
||||||
{include '../components/themes/common/stats.latte', playCount: $item->stats->playCount, diggCount: $item->stats->diggCount, commentCount: $item->stats->commentCount, shareCount: $item->stats->shareCount}
|
{include '../components/themes/common/stats.latte', playCount: $item->stats->playCount, diggCount: $item->stats->diggCount, commentCount: $item->stats->commentCount, shareCount: $item->stats->shareCount}
|
||||||
|
|
Loading…
Reference in a new issue