FossilOrigin-Name: cff813d2d65c0ce99156358724ecff352e0c5a25feb605f2a46f48b0869cf80b
This commit is contained in:
nekobit 2022-07-28 05:14:24 +00:00
parent 253f55dd36
commit 9069a17a41
10 changed files with 216 additions and 165 deletions

View File

@ -2,7 +2,7 @@ package l10n;
use Exporter 'import';
our @EXPORT = qw( %L10N );
our @EXPORT = qw( &lang %L10N );
our %L10N = (
EN_US => {
@ -86,6 +86,11 @@ our %L10N = (
NOTIF_COMPACT_POLL => 'poll',
},
# TODO bring over Spanish and Chinese
);
);
sub lang
{
$L10N{'EN_US'}->{shift(@_)}
}
return 1;

View File

@ -2,7 +2,7 @@ use strict;
use warnings;
# Modules
use Template;
use l10n qw( %L10N );
use l10n qw( &lang %L10N );
use notifications qw( notification_compact );
use template_helpers qw( &to_template );
use status ();
@ -27,7 +27,7 @@ sub base_page
prefix => '',
ssn => $ssn,
title => $L10N{'EN_US'}->{'APP_NAME'},
lang => sub { $L10N{'EN_US'}->{shift(@_)} },
lang => \&lang,
main => $main,
sidebar_opacity => $ssn->{config}->{sidebar_opacity} / 255,
acct => $ssn->{account},

View File

@ -1,5 +1,6 @@
package notifications;
use strict;
use warnings;
use Exporter 'import';
our @EXPORT = qw( notification_compact );

View File

@ -1,5 +1,6 @@
package status;
use strict;
use warnings;
use Exporter 'import';
our @EXPORT = qw( status );
@ -20,7 +21,17 @@ sub status
sub content_status
{
my ($ssn, $data, $statuses) = @_;
my ($ssn, $data, $status, $statuses_before, $statuses_after) = @_;
to_template(\%name, \$data->{'content_status.tt'});
my %vars = (
ssn => $ssn,
data => $data,
create_status => \&status,
status => $status,
statuses_before => $statuses_before,
statuses_after => $statuses_after,
);
to_template(\%vars, \$data->{'content_status.tt'});
}

View File

@ -1,5 +1,6 @@
package template_helpers;
use strict;
use warnings;
use Exporter 'import';
our @EXPORT = qw( &to_template );

View File

@ -21,6 +21,7 @@
#include "../templates/main.ctt"
#include "../templates/notif_compact.ctt"
#include "../templates/status.ctt"
#include "../templates/content_status.ctt"
HV* template_files;
pthread_mutex_t perl_mutex = PTHREAD_MUTEX_INITIALIZER;
@ -32,7 +33,7 @@ void init_template_files()
hv_stores(template_files, "main.tt", newSVpv(data_main_tt, data_main_tt_size));
hv_stores(template_files, "notif_compact.tt", newSVpv(data_notif_compact_tt, data_notif_compact_tt_size));
hv_stores(template_files, "status.tt", newSVpv(data_status_tt, data_status_tt_size));
hv_stores(template_files, "content_status.tt", newSVpv(data_status_tt, data_status_tt_size));
hv_stores(template_files, "content_status.tt", newSVpv(data_content_status_tt, data_content_status_tt_size));
}
void cleanup_template_files()

View File

@ -1066,6 +1066,16 @@ void content_status(PATH_ARGS, uint8_t flags)
HV* session_hv = perlify_session(ssn);
XPUSHs(newRV_inc((SV*)session_hv));
XPUSHs(newRV_inc((SV*)template_files));
XPUSHs(newRV_inc((SV*)perlify_status(&status)));
if (statuses_before)
XPUSHs(newRV_inc((AV*)perlify_statuses(statuses_before, stat_before_len)));
else
XPUSHs(&PL_sv_undef);
if (statuses_after)
XPUSHs(newRV_inc((AV*)perlify_statuses(statuses_after, stat_after_len)));
else
XPUSHs(&PL_sv_undef);
// ARGS
PUTBACK;
call_pv("status::content_status", G_SCALAR);
@ -1134,3 +1144,18 @@ HV* perlify_status(const struct mstdnt_status* status)
return status_hv;
}
AV* perlify_statuses(const struct mstdnt_status* statuses, size_t len)
{
if (!(statuses && len)) return NULL;
AV* av = newAV();
av_extend(av, len-1);
for (int i = 0; i < len; ++i)
{
av_store(av, i, newRV_inc((SV*)perlify_status(statuses + i)));
}
return av;
}

View File

@ -136,6 +136,7 @@ void notice_redirect(PATH_ARGS);
void api_status_interact(PATH_ARGS);
// Perl
HV* perlify_status(const struct mstdnt_status* status);
HV* perlify_status(const struct mstdnt_status* status);
AV* perlify_statuses(const struct mstdnt_status* statuses, size_t len);
#endif // STATUS_H

View File

@ -1 +1,7 @@
asdasd
[% FOREACH i IN statuses_before %]
[% create_status(ssn, data, i) %]
[% END %]
[% create_status(ssn, data, status) %]
[% FOREACH i IN statuses_after %]
[% create_status(ssn, data, i) %]
[% END %]

View File

@ -1,157 +1,157 @@
<!DOCTYPE html>
<html [% IF ssn.config.background_url %]style="background:url('[% ssn.config.background_url %]')"[% END %]>
<head>
<meta charset="utf-8">
<title>$title</title>
<link rel="icon" type="image/png" href="/favicon.png">
<link rel="stylesheet" type="text/css" href="/treebird.css">
[% IF !(ssn.config.theme == "treebird" && ssn.config.themeclr == 0) %]
<link
rel="stylesheet"
type="text/css"
href="/[% ssn.config.theme %][% IF ssn.config.themeclr %]-dark[% END %].css">
[% END %]
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="{{ %s : title }} is a decentralized social media platform">
[% IF ssn.config.sidebar_opacity %]
<style>
:root { --sidebar-opacity: [% sidebar_opacity %]; }
</style>
[% END %]
</head>
<body>
<div id="main-page">
<header id="navbar">
<label for="leftbar-show">
<svg class="leftbar-btn navbar-btn" xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="#000000" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="3" y1="12" x2="21" y2="12"></line><line x1="3" y1="6" x2="21" y2="6"></line><line x1="3" y1="18" x2="21" y2="18"></line></svg>
</label>
<a href="{{ %s : prefix }}/"><img src="/treebird_logo.png" height="42"></a>
<span class="info">$title</span>
<label for="rightbar-show">
<svg class="rightbar-btn navbar-btn" xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="#000000" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M22 17H2a3 3 0 0 0 3-3V9a7 7 0 0 1 14 0v5a3 3 0 0 0 3 3zm-8.27 4a2 2 0 0 1-3.46 0"></path></svg>
</label>
<label for="searchbar-show">
<svg class="search-btn-show" xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="#000000" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="11" cy="11" r="8"></circle><line x1="21" y1="21" x2="16.65" y2="16.65"></line></svg>
</label>
<input type="checkbox" class="hidden" id="searchbar-show">
<div id="navbar-right-container">
<div id="navbar-right">
[% IF !ssn.logged_in -%]
<a href="login" id="login-header">Login / Register</a>
[%- END %]
<!-- Searchbox -->
<form action="{{ %s : prefix }}/search" method="get">
<input type="text" class="group group-left group-inputbox" placeholder="[% lang('SEARCH_PLACEHOLDER') %]" id="searchbox" name="q"><!-- i hate HTML
--><input type="submit" class="btn group group-right" value="[% lang('SEARCH_BUTTON') %]">
</form>
</div>
<head>
<meta charset="utf-8">
<title>$title</title>
<link rel="icon" type="image/png" href="/favicon.png">
<link rel="stylesheet" type="text/css" href="/treebird.css">
[% IF !(ssn.config.theme == "treebird" && ssn.config.themeclr == 0) %]
<link
rel="stylesheet"
type="text/css"
href="/[% ssn.config.theme %][% IF ssn.config.themeclr %]-dark[% END %].css">
[% END %]
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="{{ %s : title }} is a decentralized social media platform">
[% IF ssn.config.sidebar_opacity %]
<style>
:root { --sidebar-opacity: [% sidebar_opacity %]; }
</style>
[% END %]
</head>
<body>
<div id="main-page">
<header id="navbar">
<label for="leftbar-show">
<svg class="leftbar-btn navbar-btn" xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="#000000" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="3" y1="12" x2="21" y2="12"></line><line x1="3" y1="6" x2="21" y2="6"></line><line x1="3" y1="18" x2="21" y2="18"></line></svg>
</label>
<a href="{{ %s : prefix }}/"><img src="/treebird_logo.png" height="42"></a>
<span class="info">$title</span>
<label for="rightbar-show">
<svg class="rightbar-btn navbar-btn" xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="#000000" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M22 17H2a3 3 0 0 0 3-3V9a7 7 0 0 1 14 0v5a3 3 0 0 0 3 3zm-8.27 4a2 2 0 0 1-3.46 0"></path></svg>
</label>
<label for="searchbar-show">
<svg class="search-btn-show" xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="#000000" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="11" cy="11" r="8"></circle><line x1="21" y1="21" x2="16.65" y2="16.65"></line></svg>
</label>
<input type="checkbox" class="hidden" id="searchbar-show">
<div id="navbar-right-container">
<div id="navbar-right">
[% IF !ssn.logged_in -%]
<a href="login" id="login-header">Login / Register</a>
[%- END %]
<!-- Searchbox -->
<form action="{{ %s : prefix }}/search" method="get">
<input type="text" class="group group-left group-inputbox" placeholder="[% lang('SEARCH_PLACEHOLDER') %]" id="searchbox" name="q"><!-- i hate HTML
--><input type="submit" class="btn group group-right" value="[% lang('SEARCH_BUTTON') %]">
</form>
</div>
</div>
</header>
<input type="checkbox" id="leftbar-show" class="hidden">
<input type="checkbox" id="rightbar-show" class="hidden">
<table id="content" class="ui-table">
<!-- Navigation -->
<tr>
<td id="leftbar" class="sidebar">
<ul>
<li><a class="sidebarbtn {{ %s : active_home }}" href="$prefix/">[% lang('HOME') %]</a></li>
<li><a class="sidebarbtn {{ %s : active_local }}" href="$prefix/local/">[% lang('LOCAL') %]</a></li>
<li><a class="sidebarbtn {{ %s : active_federated }}" href="$prefix/federated/">[% lang('FEDERATED') %]</a></li>
<li><a class="sidebarbtn {{ %s : active_notifications }}" href="$prefix/notifications">[% lang('NOTIFICATIONS') %]</a></li>
<li><a class="sidebarbtn {{ %s : active_lists }}" href="$prefix/lists">[% lang('LISTS') %]</a></li>
<li><a class="sidebarbtn {{ %s : active_favourites }}" href="$prefix/favourites">[% lang('FAVOURITES') %]</a></li>
<li><a class="sidebarbtn {{ %s : active_bookmarks }}" href="$prefix/bookmarks">[% lang('BOOKMARKS') %]</a></li>
<li><a class="sidebarbtn {{ %s : active_direct }}" href="$prefix/direct">[% lang('DIRECT') %]</a></li>
<li><a class="sidebarbtn {{ %s : active_chats }}" href="$prefix/chats">Chats</a></li>
<li><a class="sidebarbtn {{ %s : active_config }}" href="$prefix/config">[% lang('CONFIG') %]</a></li>
</ul>
{{ %s : sidebar_leftbar }}
<!-- <div class="static-html" id="instance-panel"></div> -->
<div class="mini-links">
<a href="{{%s:prefix}}/about">About</a>
<span class="bullet-separate">&bull;</span>
<a href="{{%s:prefix}}/about/license">License</a>
<span class="bullet-separate">&bull;</span>
<a href="https://fossil.nekobit.net/treebird">Source code</a>
</div>
</td>
<!-- Display for posts -->
<td id="main">
$main
</td>
<!-- Notifications and such -->
<td id="rightbar" class="sidebar">
[% IF ssn.cookies.logged_in %]
<div class="account-sidebar"
[%- IF acct.header -%]
style="background: linear-gradient(var(--account-overlay-gradient-top), var(--account-overlay-gradient-bottom)), url([% acct.header %]);"
[%- END %]>
<table class="acct-info">
<tr>
<td>
<img src="[% acct.avatar %]" class="acct-pfp" loading="lazy">
</td>
<td class="acct-info-right">
<span class="username">[% acct.username %]</span>
<span class="acct">@<span class="acct-js-grep">[% acct.acct %]</span></span>
</td>
</tr>
</table>
<table class="acct-stats">
<tr>
<td class="header-btn btn">
<a href="$prefix/@[% acct.acct %]">
<span class="btn-header">[% lang('TAB_STATUSES') %]</span>
<span class="btn-content">[% acct.statuses_count %]</span>
</a>
</td>
<td class="header-btn btn">
<a href="$prefix/@[% acct.acct %]/following">
<span class="btn-header">[% lang('TAB_FOLLOWING') %]</span>
<span class="btn-content">[% acct.following_count %]</span>
</a>
</td>
<td class="header-btn btn">
<a href="$prefix/@[% acct.acct %]/followers">
<span class="btn-header">[% lang('TAB_FOLLOWERS') %]</span>
<span class="btn-content">[% acct.followers_count %]</span>
</a>
</td>
</tr>
</table>
</div>
<!-- Notifications -->
[% FOREACH notif IN notifs %]
[% notification_compact(ssn, data, notif) %]
[% END %]
[% ELSE %]
<div class="sidebar-login">
<form action="$prefix/login" method="post">
<div class="form-group">
<label for="login-username">[% lang('USERNAME') %]: </label>
<input type="text" id="login-username" name="username">
</div>
<div class="form-group">
<label for="login-password">[% lang('PASSWORD') %]: </label>
<input type="password" id="login-password" name="password"><br>
</div>
<div class="form-group">
<input class="btn" type="submit" value="[% lang('LOGIN_BTN') %]">
</div>
</form>
</div>
[% END %]
</td>
</tr>
</table>
</div>
</header>
<input type="checkbox" id="leftbar-show" class="hidden">
<input type="checkbox" id="rightbar-show" class="hidden">
<table id="content" class="ui-table">
<!-- Navigation -->
<tr>
<td id="leftbar" class="sidebar">
<ul>
<li><a class="sidebarbtn {{ %s : active_home }}" href="$prefix/">[% lang('HOME') %]</a></li>
<li><a class="sidebarbtn {{ %s : active_local }}" href="$prefix/local/">[% lang('LOCAL') %]</a></li>
<li><a class="sidebarbtn {{ %s : active_federated }}" href="$prefix/federated/">[% lang('FEDERATED') %]</a></li>
<li><a class="sidebarbtn {{ %s : active_notifications }}" href="$prefix/notifications">[% lang('NOTIFICATIONS') %]</a></li>
<li><a class="sidebarbtn {{ %s : active_lists }}" href="$prefix/lists">[% lang('LISTS') %]</a></li>
<li><a class="sidebarbtn {{ %s : active_favourites }}" href="$prefix/favourites">[% lang('FAVOURITES') %]</a></li>
<li><a class="sidebarbtn {{ %s : active_bookmarks }}" href="$prefix/bookmarks">[% lang('BOOKMARKS') %]</a></li>
<li><a class="sidebarbtn {{ %s : active_direct }}" href="$prefix/direct">[% lang('DIRECT') %]</a></li>
<li><a class="sidebarbtn {{ %s : active_chats }}" href="$prefix/chats">Chats</a></li>
<li><a class="sidebarbtn {{ %s : active_config }}" href="$prefix/config">[% lang('CONFIG') %]</a></li>
</ul>
{{ %s : sidebar_leftbar }}
<!-- <div class="static-html" id="instance-panel"></div> -->
<div class="mini-links">
<a href="{{%s:prefix}}/about">About</a>
<span class="bullet-separate">&bull;</span>
<a href="{{%s:prefix}}/about/license">License</a>
<span class="bullet-separate">&bull;</span>
<a href="https://fossil.nekobit.net/treebird">Source code</a>
</div>
</td>
<!-- Display for posts -->
<td id="main">
$main
</td>
<!-- Notifications and such -->
<td id="rightbar" class="sidebar">
[% IF ssn.cookies.logged_in %]
<div class="account-sidebar"
[%- IF acct.header -%]
style="background: linear-gradient(var(--account-overlay-gradient-top), var(--account-overlay-gradient-bottom)), url([% acct.header %]);"
[%- END %]>
<table class="acct-info">
<tr>
<td>
<img src="[% acct.avatar %]" class="acct-pfp" loading="lazy">
</td>
<td class="acct-info-right">
<span class="username">[% acct.username %]</span>
<span class="acct">@<span class="acct-js-grep">[% acct.acct %]</span></span>
</td>
</tr>
</table>
<table class="acct-stats">
<tr>
<td class="header-btn btn">
<a href="$prefix/@[% acct.acct %]">
<span class="btn-header">[% lang('TAB_STATUSES') %]</span>
<span class="btn-content">[% acct.statuses_count %]</span>
</a>
</td>
<td class="header-btn btn">
<a href="$prefix/@[% acct.acct %]/following">
<span class="btn-header">[% lang('TAB_FOLLOWING') %]</span>
<span class="btn-content">[% acct.following_count %]</span>
</a>
</td>
<td class="header-btn btn">
<a href="$prefix/@[% acct.acct %]/followers">
<span class="btn-header">[% lang('TAB_FOLLOWERS') %]</span>
<span class="btn-content">[% acct.followers_count %]</span>
</a>
</td>
</tr>
</table>
</div>
<!-- Notifications -->
[% FOREACH notif IN notifs %]
[% notification_compact(ssn, data, notif) %]
[% END %]
[% ELSE %]
<div class="sidebar-login">
<form action="$prefix/login" method="post">
<div class="form-group">
<label for="login-username">[% lang('USERNAME') %]: </label>
<input type="text" id="login-username" name="username">
</div>
<div class="form-group">
<label for="login-password">[% lang('PASSWORD') %]: </label>
<input type="password" id="login-password" name="password"><br>
</div>
<div class="form-group">
<input class="btn" type="submit" value="[% lang('LOGIN_BTN') %]">
</div>
</form>
</div>
[% END %]
</td>
</tr>
</table>
</div>
<!-- Source -->
<script src="$prefix/js/main.js"></script>
<script src="$prefix/js/emoji.js"></script>
</body>
<!-- Source -->
<script src="$prefix/js/main.js"></script>
<script src="$prefix/js/emoji.js"></script>
</body>
</html>