commit 40122774006dc57587cfe261b721947161b1eb33
parent 24e625eddd69d8235572ca9eaaf3a419990305fb
Author: Peter Kosyh <p.kosyh@gmail.com>
Date: Tue, 2 Feb 2021 12:45:01 +0300
merge
Diffstat:
18 files changed, 192 insertions(+), 85 deletions(-)
diff --git a/LICENSE b/LICENSE
@@ -1,6 +1,6 @@
MIT License
-Copyright (c) 2020 Peter Kosyh
+Copyright (c) 2020-2021 Peter Kosyh
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
diff --git a/ii-node/lib/style.css b/ii-node/lib/style.css
@@ -174,6 +174,7 @@ body {
#topic .subj a, #topic .subj a:hover, #topic .subj a:visited {
color: #000000;
font-size: large;
+ font-weight: bold;
text-decoration: none;
}
#topic .reply a, #topic .reply a:hover, #topic .reply a:visited {
@@ -256,6 +257,14 @@ body {
image-rendering: pixelated;
}
+.more {
+ color: black;
+ color: #ea5555;
+ text-decoration: underline;
+ font-weight: bold;
+ font-size: smaller;
+}
+
.avatar {
width: 4em;
float: left;
diff --git a/ii-node/tpl/blog.tpl b/ii-node/tpl/blog.tpl
@@ -0,0 +1,26 @@
+{{template "header.tpl" $}}
+{{template "pager.tpl" $}}
+<a class="rss" href="/{{.BasePath}}">Echo</a> :: <a class="rss" href="{{.PfxPath}}/echo+topics/{{.Echo}}/rss">RSS</a>
+<div id="topic">
+{{range $k, $v := .Topics }}
+{{ with .Head }}
+<a name="{{.MsgId}}"></a>
+
+<div class="msg">
+<a class="msgid" href="/blog/{{.MsgId}}#{{.MsgId}}">#</a><span class="subj"> <a href="/blog/{{. | repto}}#{{. | repto}}">{{with .Subj}}{{.}}{{else}}No subject{{end}}</a></span><br>
+<span class="info"><a href="{{$.PfxPath}}/from/{{.From}}">{{.From}}</a>({{.Addr}}) — {{.To}}<br>{{.Date | fdate}}</span><br>
+
+<div class="text">
+<br>
+{{$more := (print "... <a class='more' href='" $.PfxPath "/" .MsgId "#" .MsgId "'>[ Read it >> ]</a>")}}
+{{msg_trunc . 280 $more}}
+<br>
+{{ end }}
+<span class="reply"><a href="/blog/{{.Tail.MsgId}}#{{.Tail.MsgId}}">{{.Count}} Replies</a></span>
+</div>
+</div>
+{{ end }}
+</div>
+
+{{template "pager.tpl" $}}
+{{template "footer.tpl"}}
diff --git a/ii-node/tpl/edit.tpl b/ii-node/tpl/edit.tpl
@@ -2,7 +2,7 @@
{{ $msg := index .Msg 0 }}
{{ with $msg }}
<table id="edit">
-<form method="post" enctype="application/x-www-form-urlencoded" action="/{{.MsgId}}/edit">
+<form method="post" enctype="application/x-www-form-urlencoded" action="{{$.PfxPath}}/{{.MsgId}}/edit">
<tr><td class="odd">
<input type="hidden" name="id" value="{{.MsgId}}">
<input type="hidden" name="repto" value="{{ . | repto}}">
diff --git a/ii-node/tpl/footer.tpl b/ii-node/tpl/footer.tpl
@@ -1,5 +1,5 @@
<div id="footer">
-Powered by <a href="https://github.com/gl00my/ii-go">ii-go</a> / 2020
+Powered by <a href="https://github.com/gl00my/ii-go">ii-go</a> / 2021
</div>
</div>
</body>
diff --git a/ii-node/tpl/header.tpl b/ii-node/tpl/header.tpl
@@ -6,7 +6,8 @@
<meta name="viewport" content="width=device-width; initial-scale=1.0">
<link rel="icon" href="/lib/icon.png" type="image/png">
<link rel="stylesheet" type="text/css" href="/lib/style.css">
-{{ if eq .Template "query.tpl" }}<link href="/{{.BasePath}}/rss" type="application/atom+xml" rel="alternate" title="{{.Sysname}} {{.BasePath}} :: Atom feed" />{{ end }}
+{{ if eq .Template "query.tpl" }}<link href="{{.PfxPath}}/{{.BasePath}}/rss" type="application/rss+xml" rel="alternate" title="{{.Sysname}} {{.BasePath}} :: RSS feed" />{{ end }}
+{{ if eq .Template "blog.tpl" }}<link href="{{.PfxPath}}/{{.BasePath}}+topics/rss" type="application/rss+xml" rel="alternate" title="{{.Sysname}} {{.BasePath}} :: RSS feed" />{{ end }}
<title>{{.Sysname}}</title>
</head>
@@ -16,12 +17,16 @@
<tr>
<td class="title">
<span class="logo"><a href="/"><img class="logo" src="/lib/icon.png">{{.Sysname}}</a></span>
- {{ if eq .BasePath "" }}
- <span class="info">II/IDEC networks :: <a href="/echo/all">New posts</a>
- {{ else if gt (len .Topics) 0}}
- <span class="info">II/IDEC networks {{ with .Echo }} :: <a href="/echo/{{.}}">{{.}}</a> :: <span class="info">{{index $.Echolist.Info .}}</span>{{end}}
+{{ if eq .BasePath "" }}
+ <span class="info">II/IDEC networks :: <a href="{{ $.PfxPath }}/echo/all">New posts</a>
+{{ else if gt (len .Topics) 0}}
+ <span class="info">II/IDEC networks {{ with .Echo }} :: <a href="{{$.PfxPath}}/echo/{{.}}">{{.}}</a> :: <span class="info">{{index $.Echolist.Info .}}</span>{{end}}
{{ else }}
- <span class="info">II/IDEC networks {{ with .Echo }} :: <a href="/{{.}}">{{.}}</a> :: <span class="info">{{index $.Echolist.Info .}}</span>{{end}}
+ {{ if eq .Template "query.tpl" }}
+ <span class="info">II/IDEC networks {{ with .Echo }} :: <a href="{{$.PfxPath}}/{{.}}">{{.}}</a> :: <span class="info">{{index $.Echolist.Info .}} / feed</span>{{end}}
+ {{ else }}
+ <span class="info">II/IDEC networks {{ with .Echo }} :: <a href="{{$.PfxPath}}/{{.}}">{{.}}</a> :: <span class="info">{{index $.Echolist.Info .}}</span>{{end}}
+ {{ end }}
{{ end }}
</span>
</td>
@@ -37,9 +42,9 @@
{{ with .Echo }}
{{ if $.Topic }}
- :: <a href="/{{$.Topic}}/reply/new">New</a>
+ :: <a href="{{$.PfxPath}}/{{$.Topic}}/reply/new">New</a>
{{ else }}
- :: <a href="/{{.}}/new">New</a>
+ :: <a href="{{$.PfxPath}}/{{.}}/new">New</a>
{{ end }}
{{ end }}
diff --git a/ii-node/tpl/index.tpl b/ii-node/tpl/index.tpl
@@ -12,12 +12,12 @@
{{ else }}
<tr class="odd">
{{ end }}
-<td class="echo"><a href="/{{.Name}}/">{{.Name}}</a><br>
+<td class="echo"><a href="{{$.PfxPath}}/{{.Name}}/">{{.Name}}</a><br>
<span class="info">{{ index $.Echolist.Info .Name }}</span>
</td>
<td class="topics extra">{{.Topics}}</td>
<td class="count extra">{{.Count}}</td>
-<td class="info">{{with .Msg}}<span class="subj">{{.Subj}}</span><br><a href="/echo/{{.Echo}}">{{.Date | fdate}}</a> by {{.From}}{{end}}</td>
+<td class="info">{{with .Msg}}<span class="subj">{{.Subj}}</span><br><a href="{{$.PfxPath}}/echo/{{.Echo}}">{{.Date | fdate}}</a> by {{.From}}{{end}}</td>
</tr>
{{ end }}
</table>
diff --git a/ii-node/tpl/login.tpl b/ii-node/tpl/login.tpl
@@ -1,6 +1,6 @@
{{template "header.tpl" $}}
-<form method="post" enctype="application/x-www-form-urlencoded" action="/login">
+<form method="post" enctype="application/x-www-form-urlencoded" action="{{.PfxPath}}/login">
<table id="login" cellspacing=0 cellpadding=0>
<tr class="odd"><td>
diff --git a/ii-node/tpl/new.tpl b/ii-node/tpl/new.tpl
@@ -1,9 +1,9 @@
{{template "header.tpl" $}}
<table id="edit">
{{ if eq .Echo "" }}
-<form method="post" enctype="application/x-www-form-urlencoded" action="/new">
+<form method="post" enctype="application/x-www-form-urlencoded" action="{{.PfxPath}}/new">
{{ else }}
-<form method="post" enctype="application/x-www-form-urlencoded" action="/{{.Echo}}/new">
+<form method="post" enctype="application/x-www-form-urlencoded" action="{{.PfxPath}}/{{.Echo}}/new">
{{ end }}
<tr><td class="odd">
{{ if eq .Echo "" }}
diff --git a/ii-node/tpl/pager.tpl b/ii-node/tpl/pager.tpl
@@ -10,7 +10,9 @@ Pages:
{{ if eq . $.Page }}
<span class="selected">{{.}}</span>
{{ else }}
-<a href="/{{$.BasePath}}/{{.}}">{{.}}</a>
+
+<a href="{{$.PfxPath}}/{{$.BasePath}}/{{.}}">{{.}}</a>
+
{{ end }}
{{ end }}
</div>
diff --git a/ii-node/tpl/preview.tpl b/ii-node/tpl/preview.tpl
@@ -16,9 +16,9 @@
<table id="edit">
{{ if eq $.Echo "" }}
-<form method="post" enctype="application/x-www-form-urlencoded" action="/new">
+<form method="post" enctype="application/x-www-form-urlencoded" action="{{$.PfxPath}}/new">
{{ else }}
-<form method="post" enctype="application/x-www-form-urlencoded" action="/{{.Echo}}/new">
+<form method="post" enctype="application/x-www-form-urlencoded" action="{{$.PfxPath}}/{{.Echo}}/new">
{{ end }}
<tr><td class="even">
{{ if eq $.Echo "" }}
diff --git a/ii-node/tpl/profile.tpl b/ii-node/tpl/profile.tpl
@@ -6,11 +6,11 @@
<tr class="even"><td>Auth:</td><td>{{.User.Secret}}</td></tr>
<tr class="odd"><td>e-mail:</td><td>{{.User.Mail}}</td></tr>
<tr class="even"><td>Addr:</td><td>{{.Selected}}</td></tr>
-<tr class="odd"><td class="links" colspan="2"><a href="/from/{{.User.Name}}">/from/{{.User.Name}}</a> :: <a href="/to/{{.User.Name}}">/to/{{.User.Name}}</a>
+<tr class="odd"><td class="links" colspan="2"><a href="{{.PfxPath}}/from/{{.User.Name}}">/from/{{.User.Name}}</a> :: <a href="{{.PfxPath}}/to/{{.User.Name}}">/to/{{.User.Name}}</a>
</td></tr>
<tr><td class="even" colspan="2">
-<form method="post" enctype="application/x-www-form-urlencoded" action="/avatar/{{.User.Name}}">
+<form method="post" enctype="application/x-www-form-urlencoded" action="{{.PfxPath}}/avatar/{{.User.Name}}">
<textarea type="text" name="avatar" class="message" cols=60 row=16 placeholder="Add XPM avatar here">{{.Info}}</textarea>
</td></tr>
<tr><td class="odd center" colspan="2">
diff --git a/ii-node/tpl/query.tpl b/ii-node/tpl/query.tpl
@@ -1,25 +1,25 @@
{{template "header.tpl" $}}
{{template "pager.tpl" $}}
-<a class="rss" href="/{{.BasePath}}/rss">RSS</a>
+<a class="rss" href="{{.PfxPath}}/{{.BasePath}}/rss">RSS</a>
<div id="topic">
{{ range .Msg }}
<div class="msg">
{{ if has_avatar .From }}
<img class="avatar" src="/avatar/{{.From}}">
{{ end }}
-<a class="msgid" href="/{{.MsgId}}#{{.MsgId}}">#</a><span class="subj"> <a href="/{{. | repto}}#{{. | repto}}">{{with .Subj}}{{.}}{{else}}No subject{{end}}</a></span><br>
-<span class="echo"><a href="/{{.Echo}}">{{.Echo}}</a></span><br>
+<a class="msgid" href="{{$.PfxPath}}/{{.MsgId}}#{{.MsgId}}">#</a><span class="subj"> <a href="{{$.PfxPath}}/{{. | repto}}#{{. | repto}}">{{with .Subj}}{{.}}{{else}}No subject{{end}}</a></span><br>
+<span class="echo"><a href="{{$.PfxPath}}/{{.Echo}}">{{.Echo}}</a></span><br>
<span class="info">{{.From}}({{.Addr}}) — {{.To}}<br>{{.Date | fdate}}</span><br>
<div class="text">
<br>
-{{. | msg_text}}
+{{ msg_text . }}
<br>
{{if $.User.Name}}
-<span class="reply"><a href="/{{.MsgId}}/reply/new">Reply</a> :: </span>
-<span class="reply"><a href="/{{.MsgId}}/reply">Quote</a></span>
+<span class="reply"><a href="{{$.PfxPath}}/{{.MsgId}}/reply/new">Reply</a> :: </span>
+<span class="reply"><a href="{{$.PfxPath}}/{{.MsgId}}/reply">Quote</a></span>
{{end}}
{{ if msg_access . $.User }}
- :: <span class="reply"><a href="/{{.MsgId}}/edit">Edit</a></span>
+ :: <span class="reply"><a href="{{$.PfxPath}}/{{.MsgId}}/edit">Edit</a></span>
{{ end }}
{{if $.User.Name}}
<br>
diff --git a/ii-node/tpl/reply.tpl b/ii-node/tpl/reply.tpl
@@ -1,7 +1,7 @@
{{template "header.tpl" $}}
<table id="edit">
{{ with index .Msg 0 }}
-<form method="post" enctype="application/x-www-form-urlencoded" action="/{{.Echo}}/new">
+<form method="post" enctype="application/x-www-form-urlencoded" action="{{$.PfxPath}}/{{.Echo}}/new">
<tr><td class="odd">
<input type="text" name="to" class="to" placeholder="{{.To}}" value="{{.To}}"><br>
<input type="text" name="subj" class="subj" placeholder="{{.Subj}}" value="{{.Subj}}"><br>
diff --git a/ii-node/tpl/topic.tpl b/ii-node/tpl/topic.tpl
@@ -11,18 +11,18 @@
{{ if has_avatar .From }}
<img class="avatar" src="/avatar/{{.From}}">
{{ end }}
-<a class="msgid" href="/{{.MsgId}}#{{.MsgId}}">#</a><span class="subj"> <a href="/{{. | repto}}#{{. | repto}}">{{with .Subj}}{{.}}{{else}}No subject{{end}}</a></span><br>
-<span class="info"><a href="/from/{{.From}}">{{.From}}</a>({{.Addr}}) — {{.To}}<br>{{.Date | fdate}}</span><br>
+<a class="msgid" href="{{$.PfxPath}}/{{.MsgId}}#{{.MsgId}}">#</a><span class="subj"> <a href="{{$.PfxPath}}/{{. | repto}}#{{. | repto}}">{{with .Subj}}{{.}}{{else}}No subject{{end}}</a></span><br>
+<span class="info"><a href="{{$.PfxPath}}/from/{{.From}}">{{.From}}</a>({{.Addr}}) — {{.To}}<br>{{.Date | fdate}}</span><br>
<div class="text">
<br>
{{. | msg_text}}
<br>
{{if $.User.Name}}
-<span class="reply"><a href="/{{.MsgId}}/reply/new">Reply</a> :: </span>
-<span class="reply"><a href="/{{.MsgId}}/reply">Quote</a></span>
+<span class="reply"><a href="{{$.PfxPath}}/{{.MsgId}}/reply/new">Reply</a> :: </span>
+<span class="reply"><a href="{{$.PfxPath}}/{{.MsgId}}/reply">Quote</a></span>
{{end}}
{{ if msg_access . $.User }}
- :: <span class="reply"><a href="/{{.MsgId}}/edit">Edit</a></span>
+ :: <span class="reply"><a href="{{$.PfxPath}}/{{.MsgId}}/edit">Edit</a></span>
{{ end }}
{{if $.User.Name}}
<br>
diff --git a/ii-node/tpl/topics.tpl b/ii-node/tpl/topics.tpl
@@ -1,5 +1,6 @@
{{template "header.tpl" $}}
{{template "pager.tpl" $}}
+<a class="rss" href="/blog/{{.BasePath}}">Blog</a> :: <a class="rss" href="/echo/{{.BasePath}}">Feed</a>
<table id="topiclist" cellspacing=0 cellpadding=0>
<tr class="title">
<th>Topics</th>
diff --git a/ii-node/web.go b/ii-node/web.go
@@ -25,6 +25,7 @@ type WebContext struct {
Msg []*ii.Msg
Error string
Echo string
+ PfxPath string
Page int
Pages int
Pager []int
@@ -66,7 +67,7 @@ func www_register(ctx *WebContext, w http.ResponseWriter, r *http.Request) error
ii.Info.Printf("Can not edit user %s: %s", ctx.User.Name, err)
return err
}
- http.Redirect(w, r, "/login", http.StatusSeeOther)
+ http.Redirect(w, r, ctx.PfxPath + "/login", http.StatusSeeOther)
return nil
}
user := r.FormValue("username")
@@ -79,7 +80,7 @@ func www_register(ctx *WebContext, w http.ResponseWriter, r *http.Request) error
return err
}
ii.Info.Printf("Registered user: %s", user)
- http.Redirect(w, r, "/login", http.StatusSeeOther)
+ http.Redirect(w, r, ctx.PfxPath + "/login", http.StatusSeeOther)
default:
return nil
}
@@ -109,7 +110,7 @@ func www_login(ctx *WebContext, w http.ResponseWriter, r *http.Request) error {
cookie := http.Cookie{Name: "pauth", Value: udb.Secret(user), Expires: exp}
http.SetCookie(w, &cookie)
ii.Info.Printf("User logged in: %s\n", user)
- http.Redirect(w, r, "/", http.StatusSeeOther)
+ http.Redirect(w, r, ctx.PfxPath + "/", http.StatusSeeOther)
return nil
}
return errors.New("Wrong method")
@@ -141,7 +142,7 @@ func www_logout(ctx *WebContext, w http.ResponseWriter, r *http.Request) error {
}
cookie := http.Cookie{Name: "pauth", Value: "", Expires: time.Unix(0, 0)}
http.SetCookie(w, &cookie)
- http.Redirect(w, r, "/", http.StatusSeeOther)
+ http.Redirect(w, r, ctx.PfxPath + "/", http.StatusSeeOther)
return nil
}
@@ -272,7 +273,7 @@ func www_avatar(ctx *WebContext, w http.ResponseWriter, r *http.Request, user st
ii.Error.Printf("Error saving avatar: " + user)
return errors.New("Error saving avatar")
}
- http.Redirect(w, r, "/profile", http.StatusSeeOther)
+ http.Redirect(w, r, ctx.PfxPath + "/profile", http.StatusSeeOther)
return nil
}
// var id int32
@@ -352,6 +353,14 @@ func Select(ctx *WebContext, q ii.Query) []string {
return ctx.www.db.SelectIDS(q)
}
+func trunc(str string, limit int) string {
+ result := []rune(str)
+ if len(result) > limit {
+ return string(result[:limit])
+ }
+ return str
+}
+
func www_query(ctx *WebContext, w http.ResponseWriter, r *http.Request, q ii.Query, page int, rss bool) error {
db := ctx.www.db
req := ctx.BasePath
@@ -381,32 +390,40 @@ func www_query(ctx *WebContext, w http.ResponseWriter, r *http.Request, q ii.Que
ctx.Topic = db.Name + " :: " + req
fmt.Fprintf(w,
`<?xml version="1.0" encoding="UTF-8"?>
-<feed xmlns="http://www.w3.org/2005/Atom">
-<title>%s</title>
-<subtitle>RSS feed with last messages</subtitle>
-<link href="%s" rel="self" />
-<id>%s/%s</id>
-`,
- str_esc(ctx.Topic), ctx.www.Host, ctx.www.Host, ctx.BasePath)
+ <rss version="2.0"
+ xmlns:content="http://purl.org/rss/1.0/modules/content/"
+ xmlns:dc="http://purl.org/dc/elements/1.1/"
+ xmlns:media="http://search.yahoo.com/mrss/"
+ xmlns:atom="http://www.w3.org/2005/Atom"
+ xmlns:georss="http://www.georss.org/georss">
+ <channel>
+ <title>%s</title>
+ <link>%s/%s</link>
+ <description>
+ %s
+ </description>
+ <language>ru</language>`,
+ str_esc(ctx.Topic), ctx.www.Host, ctx.BasePath, str_esc(ctx.Topic))
for _, m := range ctx.Msg {
fmt.Fprintf(w,
- `<entry>
- <title>%s</title>
- <id>%s</id>
- <link href="%s/%s#%s" />
- <updated>%s</updated>
- <content type="html">%s%s</content>
- <author><name>%s</name></author>
-</entry>
+ `<item><title>%s</title><guid>%s</guid><pubDate>%s</pubDate><author>%s</author><link>%s/%s</link>
+ <description>
+ %s...
+ </description>
+ <content:encoded>
+<![CDATA[
+%s
+%s
+]]>
+</content:encoded></item>
`,
- str_esc(m.Subj), m.MsgId, ctx.www.Host, m.MsgId, m.MsgId,
- time.Unix(m.Date, 0).Format("2006-01-02 15:04:05"),
- str_esc(fmt.Sprintf("%s -> %s<br><br>", m.From, m.To)),
- str_esc(msg_text(m)),
- str_esc(m.From))
+ str_esc(m.Subj), m.MsgId, time.Unix(m.Date, 0).Format("2006-01-02 15:04:05"),
+ str_esc(m.From), ctx.www.Host + ctx.PfxPath, m.MsgId,
+ str_esc(trunc(m.Text, 280)),
+ fmt.Sprintf("%s -> %s<br><br>", m.From, m.To),
+ msg_text(m))
}
- fmt.Fprintf(w,
- `</feed>
+ fmt.Fprintf(w, `</channel></rss>
`)
return nil
}
@@ -416,8 +433,7 @@ func www_query(ctx *WebContext, w http.ResponseWriter, r *http.Request, q ii.Que
func www_topics(ctx *WebContext, w http.ResponseWriter, r *http.Request, page int) error {
db := ctx.www.db
- echo := ctx.BasePath
- ctx.Echo = echo
+ echo := ctx.Echo
mis := db.LookupIDS(Select(ctx, ii.Query{Echo: echo}))
ii.Trace.Printf("www topics: %s", echo)
topicsIds := db.GetTopics(mis)
@@ -431,18 +447,20 @@ func www_topics(ctx *WebContext, w http.ResponseWriter, r *http.Request, page in
topic := Topic{}
topic.Ids = t
topic.Count = len(topic.Ids) - 1
- topic.Last = db.LookupFast(topic.Ids[topic.Count], false)
+ if ctx.PfxPath == "/blog" {
+ topic.Last = db.LookupFast(topic.Ids[0], false)
+ } else {
+ topic.Last = db.LookupFast(topic.Ids[topic.Count], false)
+ }
if topic.Last == nil {
ii.Error.Printf("Skip wrong message: %s\n", t[0])
continue
}
topics = append(topics, &topic)
}
-
sort.SliceStable(topics, func(i, j int) bool {
return topics[i].Last.Num > topics[j].Last.Num
})
- ctx.BasePath = echo
tcount := len(topics)
start := makePager(ctx, tcount, page)
nr := PAGE_SIZE
@@ -458,6 +476,12 @@ func www_topics(ctx *WebContext, w http.ResponseWriter, r *http.Request, page in
nr--
}
ii.Trace.Printf("Stop to generate topics")
+
+ if ctx.PfxPath == "/blog" {
+ ctx.Template = "blog.tpl"
+ err := ctx.www.tpl.ExecuteTemplate(w, "blog.tpl", ctx)
+ return err
+ }
ctx.Template = "topics.tpl"
err := ctx.www.tpl.ExecuteTemplate(w, "topics.tpl", ctx)
return err
@@ -479,6 +503,9 @@ func www_topic(ctx *WebContext, w http.ResponseWriter, r *http.Request, page int
topic := mi.Id
for p := mi; p != nil; p = db.LookupFast(p.Repto, false) {
+ if p.Repto == p.Id {
+ break
+ }
if p.Echo != mi.Echo {
continue
}
@@ -532,7 +559,7 @@ func www_blacklist(ctx *WebContext, w http.ResponseWriter, r *http.Request) erro
ii.Error.Printf("Error blacklisting: %s", id)
return err
}
- http.Redirect(w, r, "/", http.StatusSeeOther)
+ http.Redirect(w, r, ctx.PfxPath + "/", http.StatusSeeOther)
return nil
}
@@ -589,6 +616,9 @@ func www_new(ctx *WebContext, w http.ResponseWriter, r *http.Request) error {
msg := r.FormValue("msg")
repto := r.FormValue("repto")
id := r.FormValue("id")
+ if repto == id {
+ repto = ""
+ }
newecho := r.FormValue("echo")
if newecho != "" {
echo = newecho
@@ -630,7 +660,7 @@ func www_new(ctx *WebContext, w http.ResponseWriter, r *http.Request) error {
ii.Error.Printf("Error while storig new topic %s: %s", m.MsgId, err)
return err
}
- http.Redirect(w, r, "/"+m.MsgId+"#"+m.MsgId, http.StatusSeeOther)
+ http.Redirect(w, r, ctx.PfxPath + "/"+m.MsgId+"#"+m.MsgId, http.StatusSeeOther)
return nil
}
if !edit {
@@ -751,6 +781,10 @@ func msg_esc(l string) string {
}
func msg_text(m *ii.Msg) string {
+ return msg_trunc(m, 0, "")
+}
+
+func msg_trunc(m *ii.Msg, maxlen int, more string) string {
if m == nil {
return ""
}
@@ -818,7 +852,13 @@ func msg_text(m *ii.Msg) string {
} else {
l = msg_esc(l)
}
- f += l + "<br>\n"
+ f += l
+ if maxlen > 0 && len(f) > maxlen {
+ f += more + "<br>\n"
+ break
+ } else {
+ f += "<br>\n"
+ }
}
if pre {
pre = false
@@ -843,8 +883,14 @@ func WebInit(www *WWW) {
"msg_text": func(m *ii.Msg) template.HTML {
return template.HTML(msg_text(m))
},
+ "msg_trunc": func(m *ii.Msg, len int, more string) template.HTML {
+ return template.HTML(msg_trunc(m, len, more))
+ },
"repto": func(m ii.Msg) string {
r, _ := m.Tag("repto")
+ if r == "" {
+ return m.MsgId
+ }
return r
},
"msg_quote": msg_quote,
@@ -904,22 +950,26 @@ func _handleWWW(ctx *WebContext, w http.ResponseWriter, r *http.Request) error {
args := strings.Split(path, "/")
ctx.Echolist = ctx.www.edb
ctx.Ref = r.Header.Get("Referer")
- if path == "" {
+ if len(args) > 1 && args[0] == "blog" {
+ ctx.PfxPath = "/blog"
+ args = args[1:]
+ }
+ if args[0] == "" {
ctx.BasePath = ""
return www_index(ctx, w, r)
- } else if path == "login" {
+ } else if args[0] == "login" {
ctx.BasePath = "login"
return www_login(ctx, w, r)
- } else if path == "logout" {
+ } else if args[0] == "logout" {
ctx.BasePath = "logout"
return www_logout(ctx, w, r)
- } else if path == "profile" {
+ } else if args[0] == "profile" {
ctx.BasePath = "profile"
return www_profile(ctx, w, r)
- } else if path == "register" {
+ } else if args[0] == "register" {
ctx.BasePath = "register"
return www_register(ctx, w, r)
- } else if path == "reset" {
+ } else if args[0] == "reset" {
ctx.Template = "reset.tpl"
return ctx.www.tpl.ExecuteTemplate(w, "reset.tpl", ctx)
} else if args[0] == "avatar" {
@@ -930,25 +980,21 @@ func _handleWWW(ctx *WebContext, w http.ResponseWriter, r *http.Request) error {
return www_avatar(ctx, w, r, args[1])
} else if ii.IsMsgId(args[0]) {
page := 0
+ ctx.BasePath = args[0]
if len(args) > 1 {
if args[1] == "reply" {
- ctx.BasePath = args[0]
return www_reply(ctx, w, r, !(len(args) > 2 && args[2] == "new"))
} else if args[1] == "edit" {
- ctx.BasePath = args[0]
return www_edit(ctx, w, r)
} else if args[1] == "blacklist" {
- ctx.BasePath = args[0]
return www_blacklist(ctx, w, r)
} else if args[1] == "base64" {
- ctx.BasePath = args[0]
return www_base64(ctx, w, r)
}
fmt.Sscanf(args[1], "%d", &page)
}
- ctx.BasePath = args[0]
return www_topic(ctx, w, r, page)
- } else if path == "new" {
+ } else if args[0] == "new" {
ctx.BasePath = ""
return www_new(ctx, w, r)
} else if args[0] == "to" {
@@ -981,7 +1027,7 @@ func _handleWWW(ctx *WebContext, w http.ResponseWriter, r *http.Request) error {
}
ctx.BasePath = "from/" + args[1]
return www_query(ctx, w, r, ii.Query{From: args[1]}, page, rss)
- } else if args[0] == "echo" {
+ } else if args[0] == "echo" || args[0] == "echo+topics" {
page := 1
rss := false
if len(args) < 2 {
@@ -1000,10 +1046,17 @@ func _handleWWW(ctx *WebContext, w http.ResponseWriter, r *http.Request) error {
}
ctx.Echo = q.Echo
q.Start = -PAGE_SIZE
- ctx.BasePath = "echo/" + args[1]
+ if args[0] == "echo+topics" {
+ q.Repto = "!"
+ ctx.BasePath = "echo+topics/" + args[1]
+ } else {
+ ctx.BasePath = "echo/" + args[1]
+ }
return www_query(ctx, w, r, q, page, rss)
} else if ii.IsEcho(args[0]) {
page := 1
+ ctx.Echo = args[0]
+ ctx.BasePath = args[0]
if len(args) > 1 {
if args[1] == "new" {
ctx.BasePath = args[0]
@@ -1011,7 +1064,6 @@ func _handleWWW(ctx *WebContext, w http.ResponseWriter, r *http.Request) error {
}
fmt.Sscanf(args[1], "%d", &page)
}
- ctx.BasePath = args[0]
return www_topics(ctx, w, r, page)
} else {
w.WriteHeader(http.StatusNotFound)
diff --git a/ii/db.go b/ii/db.go
@@ -491,7 +491,11 @@ func (db *DB) Match(info MsgInfo, r Query) bool {
if r.Echo != "" && r.Echo != info.Echo {
return false
}
- if r.Repto != "" && r.Repto != info.Repto {
+ if r.Repto == "!" {
+ if info.Repto != "" {
+ return false
+ }
+ } else if r.Repto != "" && r.Repto != info.Repto {
return false
}
if r.To != "" && r.To != info.To {
@@ -679,6 +683,9 @@ func (db *DB) GetTopics(mi []*MsgInfo) map[string][]string {
}
var l []*MsgInfo
for p := m; p != nil; p = db.LookupFast(p.Repto, false) {
+ if p.Repto == p.Id { // self answer?
+ break
+ }
if m.Echo != p.Echo {
continue
}
@@ -761,6 +768,11 @@ func (db *DB) _Store(m *Msg, edit bool) error {
if _, ok := db.Idx.Hash[m.MsgId]; ok && !edit { // exist and not edit
return errors.New("Already exists")
}
+ if repto != "" {
+ if _, ok := db.Idx.Hash[repto]; !ok { // repto is absent, we should avoid loops!
+ return errors.New("Wrong repto")
+ }
+ }
fi, err := os.Stat(db.BundlePath())
var off int64
if err == nil {