2024-06-13 04:49:55 +04:00
|
|
|
package web
|
|
|
|
|
|
|
|
import "fmt"
|
|
|
|
import "strconv"
|
|
|
|
import "strings"
|
2024-06-25 04:37:35 +04:00
|
|
|
import "time"
|
2024-06-13 04:49:55 +04:00
|
|
|
import "net/http"
|
|
|
|
|
2024-09-14 18:36:08 +04:00
|
|
|
import "github.com/invopop/ctxi18n/i18n"
|
|
|
|
|
2024-06-13 04:49:55 +04:00
|
|
|
import "git.arav.su/Arav/justguestbook"
|
|
|
|
|
|
|
|
import "git.arav.su/Arav/dwelling-home/pkg/util"
|
|
|
|
|
2024-06-30 00:42:40 +04:00
|
|
|
templ Guestbook(captchaID, owner string, entries []*justguestbook.Entry, pageCount, pageCur int64, r *http.Request) {
|
2024-09-17 03:11:10 +04:00
|
|
|
@base(i18n.T(ctx, "base.section.guestbook"), i18n.T(ctx, "guestbook.description"), i18n.T(ctx, "guestbook.keywords"), "/guestbook", r, guestbookHead()) {
|
2024-06-19 01:08:05 +04:00
|
|
|
<form id="new-post" action="/api/guestbook" method="POST">
|
2024-09-14 18:36:08 +04:00
|
|
|
<input type="text" name="name" maxlength="80" placeholder={ i18n.T(ctx, "guestbook.form.name") }/>
|
|
|
|
<input type="text" name="website" maxlength="255" placeholder={ i18n.T(ctx, "guestbook.form.website") }/>
|
|
|
|
<textarea name="message" maxlength="4096" placeholder={ i18n.T(ctx, "guestbook.form.message") } required></textarea>
|
2024-06-19 01:08:05 +04:00
|
|
|
<span class="checkboxes">
|
|
|
|
<input type="checkbox" name="hide_website" id="hide-website" checked/>
|
2024-09-14 18:36:08 +04:00
|
|
|
<label for="hide-website">{ i18n.T(ctx, "guestbook.form.hide-website-1") } <small>{ i18n.T(ctx, "guestbook.form.hide-website-2") }</small></label>
|
2024-06-19 01:08:05 +04:00
|
|
|
<br/>
|
2024-09-15 02:55:36 +04:00
|
|
|
<small>@templ.Raw(i18n.T(ctx, "guestbook.form.quote-usage", i18n.M{"sign":">"}))</small>
|
2024-06-19 01:08:05 +04:00
|
|
|
</span>
|
|
|
|
<span class="captcha">
|
|
|
|
<input type="hidden" name="captcha_id" value={ captchaID }/>
|
|
|
|
<img src={ string(templ.URL(fmt.Sprintf("/api/captcha/%s/image", captchaID))) } alt="CAPTCHA" width="160" height="40"/>
|
|
|
|
<input type="text" name="captcha_answer" maxlength="6" placeholder="CAPTCHA" required/>
|
2024-09-15 02:55:36 +04:00
|
|
|
<small>@templ.Raw(i18n.T(ctx, "guestbook.form.captcha-validity", i18n.M{"valid":"<b>10</b>"}))</small>
|
2024-06-19 01:08:05 +04:00
|
|
|
</span>
|
2024-09-14 18:36:08 +04:00
|
|
|
<input type="submit" value={ i18n.T(ctx, "guestbook.form.send-post") }/>
|
2024-06-19 01:08:05 +04:00
|
|
|
</form>
|
|
|
|
<section id="posts">
|
|
|
|
for _, entry := range entries {
|
|
|
|
<article>
|
|
|
|
<header>
|
2024-09-15 15:09:55 +04:00
|
|
|
{{ created_tz := util.ToClientTimezone(entry.Created, r).Format("02.01.2006 15:04:05 -07:00") }}
|
2024-06-19 01:08:05 +04:00
|
|
|
{{ website := "" }}
|
|
|
|
if !entry.HideWebsite {
|
|
|
|
{{ website = entry.Website }}
|
|
|
|
}
|
2024-09-14 18:36:08 +04:00
|
|
|
{ strconv.FormatInt(entry.ID, 10) } { i18n.T(ctx, "guestbook.post.by") } <span class="highlighted">{ entry.Name }</span> <em>{ website }</em> { i18n.T(ctx, "guestbook.post.on") } <time datetime={ entry.Created.Format(time.RFC3339) }>{ created_tz }</time>
|
2024-06-19 01:08:05 +04:00
|
|
|
</header>
|
|
|
|
for _, line := range strings.Split(entry.Message, "\n") {
|
2024-06-25 04:37:35 +04:00
|
|
|
<p
|
2024-06-19 01:08:05 +04:00
|
|
|
if len(line) > 0 && line[0] == '>' {
|
2024-06-25 04:37:35 +04:00
|
|
|
class="quote"
|
|
|
|
}>{ line }</p>
|
2024-06-19 01:08:05 +04:00
|
|
|
}
|
|
|
|
if entry.Reply != nil {
|
|
|
|
<div class="reply">
|
|
|
|
<header>
|
2024-09-15 15:09:55 +04:00
|
|
|
{{ reply_created_tz := util.ToClientTimezone(entry.Reply.Created, r).Format("02.01.2006 15:04:05 -07:00") }}
|
2024-09-14 18:36:08 +04:00
|
|
|
{ i18n.T(ctx, "guestbook.post.reply") } <span class="highlighted">{ owner }</span> { i18n.T(ctx, "guestbook.post.on") } <time datetime={ entry.Reply.Created.Format(time.RFC3339) }>{ reply_created_tz }</time>
|
2024-06-19 01:08:05 +04:00
|
|
|
</header>
|
|
|
|
for _, line := range strings.Split(entry.Reply.Message, "\n") {
|
2024-06-25 04:37:35 +04:00
|
|
|
<p
|
2024-06-19 01:08:05 +04:00
|
|
|
if len(line) > 0 && line[0] == '>' {
|
2024-06-25 04:37:35 +04:00
|
|
|
class="quote"
|
|
|
|
}>@templ.Raw(line)</p>
|
2024-06-19 01:08:05 +04:00
|
|
|
}
|
|
|
|
</div>
|
|
|
|
}
|
|
|
|
</article>
|
|
|
|
}
|
|
|
|
if len(entries) == 0 {
|
2024-09-14 18:36:08 +04:00
|
|
|
<p class="center">{ i18n.T(ctx, "guestbook.post.no-posts") }</p>
|
2024-06-19 01:08:05 +04:00
|
|
|
}
|
|
|
|
</section>
|
|
|
|
if pageCount > 1 {
|
|
|
|
<section id="pagination">
|
2024-06-19 05:07:20 +04:00
|
|
|
for n := int64(1); n <= pageCount; n++ {
|
2024-06-19 01:08:05 +04:00
|
|
|
{{ strN := strconv.FormatInt(n, 10) }}
|
2024-06-30 00:42:40 +04:00
|
|
|
if n == pageCur {
|
|
|
|
<span> { strN }</span>
|
|
|
|
{{ continue }}
|
|
|
|
}
|
2024-06-19 01:08:05 +04:00
|
|
|
<a href={ templ.URL("/guestbook?p=" + strN) }>{ strN }</a>
|
|
|
|
}
|
|
|
|
</section>
|
|
|
|
}
|
|
|
|
}
|
2024-06-13 04:49:55 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
templ guestbookHead() {
|
2024-06-19 01:08:05 +04:00
|
|
|
<link rel="stylesheet" href="/assets/css/guestbook.css"/>
|
|
|
|
<script src="/assets/js/captcha_refresh.js" defer></script>
|
|
|
|
}
|