From 4188fcf0642bd16174b250f16b819aa9e7bce427 Mon Sep 17 00:00:00 2001 From: Pablo Ferreiro Date: Sun, 2 Apr 2023 19:55:04 +0200 Subject: [PATCH] Initial URLify of vid desc and profile --- app/Constants/TextExtras.php | 7 ++++++ app/Helpers/Wrappers.php | 27 +++++++++++++++++++++-- templates/components/themes/default.latte | 2 +- templates/views/user.latte | 4 +++- templates/views/video.latte | 2 +- 5 files changed, 37 insertions(+), 5 deletions(-) create mode 100644 app/Constants/TextExtras.php diff --git a/app/Constants/TextExtras.php b/app/Constants/TextExtras.php new file mode 100644 index 0000000..b4debf4 --- /dev/null +++ b/app/Constants/TextExtras.php @@ -0,0 +1,7 @@ +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, "$text", $out); + } + return $out; + }); + $latte->render(Misc::getView($template), $base); } diff --git a/templates/components/themes/default.latte b/templates/components/themes/default.latte index 41af404..da3556a 100644 --- a/templates/components/themes/default.latte +++ b/templates/components/themes/default.latte @@ -17,7 +17,7 @@ {if !empty($item->challenges)}

{include './common/tags.latte', challenges: $item->challenges}

{/if} -

{$item->desc}

+

{render_desc($item->desc, $item->textExtra)|noescape}

Song: {$item->music->title}

{include './common/stats.latte', playCount: $item->stats->playCount, diggCount: $item->stats->diggCount, commentCount: $item->stats->commentCount, shareCount: $item->stats->shareCount} diff --git a/templates/views/user.latte b/templates/views/user.latte index 2e07961..f8708a6 100644 --- a/templates/views/user.latte +++ b/templates/views/user.latte @@ -15,8 +15,10 @@ {if $info->detail->privateAccount}

Private account

{/if} -

{$info->detail->signature}

+ {if isset($info->detail->bioLink)} +

Link: {$info->detail->bioLink->link}

+ {/if}

Following: {number($info->stats->followingCount)} / Followers: {number($info->stats->followerCount)}

Hearts: {number($info->stats->heartCount)} / Videos: {$info->stats->videoCount}

{/block} diff --git a/templates/views/video.latte b/templates/views/video.latte index 6283506..c142d22 100644 --- a/templates/views/video.latte +++ b/templates/views/video.latte @@ -33,7 +33,7 @@

{include '../components/themes/common/tags.latte', challenges: $item->challenges}

{/if}
-

{$item->desc}

+

{render_desc($item->desc, $item->textExtra)|noescape}

Song: {$item->music->title}

{include '../components/themes/common/stats.latte', playCount: $item->stats->playCount, diggCount: $item->stats->diggCount, commentCount: $item->stats->commentCount, shareCount: $item->stats->shareCount}