Initial URLify of vid desc and profile
This commit is contained in:
parent
9364a2e212
commit
4188fcf064
5 changed files with 37 additions and 5 deletions
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\RedisCache;
|
||||
use App\Constants\CacheMethods;
|
||||
use App\Constants\TextExtras;
|
||||
use App\Models\BaseTemplate;
|
||||
|
||||
use TikScraper\Constants\UserAgents as TikScraperUserAgents;
|
||||
|
||||
class Wrappers {
|
||||
/**
|
||||
* Setup of Latte template engine
|
||||
|
|
@ -92,6 +91,30 @@ class Wrappers {
|
|||
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);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue