diff --git a/public/css/style-night.css b/public/css/style-night.css index 289d160e..f4ffb023 100644 --- a/public/css/style-night.css +++ b/public/css/style-night.css @@ -123,3 +123,10 @@ a:hover { #mainmenu a.nightswitch { background-image: url(/img/moon.png); } + +/* Force images on description to fit width */ +#description img { + display: block; + max-width: 100%; + height: auto; +} diff --git a/public/css/style.css b/public/css/style.css index 02cec37b..e6402444 100644 --- a/public/css/style.css +++ b/public/css/style.css @@ -104,7 +104,8 @@ td { .comment-row td:first-of-type { vertical-align: top; - text-align: right; + text-align: left; + color:#bbb; } /* Table style & fixes */ @@ -339,3 +340,10 @@ footer { color: #616161; text-shadow: -1px -1px #999999; } + +/* Force images on description to fit width */ +#description img { + display: block; + max-width: 100%; + height: auto; +} diff --git a/router/modpanel.go b/router/modpanel.go index d48c5b5c..681e72b8 100644 --- a/router/modpanel.go +++ b/router/modpanel.go @@ -3,6 +3,7 @@ package router import ( + "fmt" "html" "html/template" "net/http" @@ -10,6 +11,7 @@ import ( "strconv" "github.com/ewhal/nyaa/model" + "github.com/ewhal/nyaa/service" "github.com/ewhal/nyaa/service/comment" "github.com/ewhal/nyaa/service/report" "github.com/ewhal/nyaa/service/torrent" @@ -50,6 +52,7 @@ func IndexModPanel(w http.ResponseWriter, r *http.Request) { users, _ := userService.RetrieveUsersForAdmin(offset, 0) comments, _ := commentService.GetAllComments(offset, 0, "", "") torrentReports, _, _ := reportService.GetAllTorrentReports(offset, 0) + fmt.Println(torrentReports) languages.SetTranslationFromRequest(panelIndex, r, "en-us") htv := PanelIndexVbs{torrents, torrentReports, users, comments, NewSearchForm(), currentUser, r.URL} @@ -246,6 +249,13 @@ func TorrentDeleteModPanel(w http.ResponseWriter, r *http.Request) { if userPermission.HasAdmin(currentUser) { _ = form.NewErrors() _, _ = torrentService.DeleteTorrent(id) + + //delete reports of torrent + whereParams := serviceBase.CreateWhereParams("torrent_id = ?", id) + reports, _, _ := reportService.GetTorrentReportsOrderBy(&whereParams, "", 0, 0) + for _, report := range reports { + reportService.DeleteTorrentReport(report.ID) + } url, _ := Router.Get("mod_tlist").URL() http.Redirect(w, r, url.String()+"?deleted", http.StatusSeeOther) } else { diff --git a/router/templateVariables.go b/router/templateVariables.go index c1907ca6..20d852f5 100644 --- a/router/templateVariables.go +++ b/router/templateVariables.go @@ -59,6 +59,7 @@ type UserProfileEditVariables struct { UserForm userForms.UserForm FormErrors map[string][]string FormInfos map[string][]string + Languages map[string]string Search SearchForm Navigation Navigation User *model.User diff --git a/router/userHandler.go b/router/userHandler.go index 2e74b855..67a53d7b 100755 --- a/router/userHandler.go +++ b/router/userHandler.go @@ -115,7 +115,8 @@ func UserDetailsHandler(w http.ResponseWriter, r *http.Request) { languages.SetTranslationFromRequest(viewProfileEditTemplate, r, "en-us") searchForm := NewSearchForm() searchForm.HideAdvancedSearch = true - htv := UserProfileEditVariables{&userProfile, b, form.NewErrors(), form.NewInfos(), searchForm, Navigation{}, currentUser, r.URL, mux.CurrentRoute(r)} + availableLanguages := languages.GetAvailableLanguages() + htv := UserProfileEditVariables{&userProfile, b, form.NewErrors(), form.NewInfos(), availableLanguages, searchForm, Navigation{}, currentUser, r.URL, mux.CurrentRoute(r)} err := viewProfileEditTemplate.ExecuteTemplate(w, "index.html", htv) if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) @@ -158,7 +159,8 @@ func UserProfileFormHandler(w http.ResponseWriter, r *http.Request) { } } } - htv := UserProfileEditVariables{&userProfile, b, err, infos, NewSearchForm(), Navigation{}, currentUser, r.URL, mux.CurrentRoute(r)} + availableLanguages := languages.GetAvailableLanguages() + htv := UserProfileEditVariables{&userProfile, b, err, infos, availableLanguages, NewSearchForm(), Navigation{}, currentUser, r.URL, mux.CurrentRoute(r)} errorTmpl := viewProfileEditTemplate.ExecuteTemplate(w, "index.html", htv) if errorTmpl != nil { http.Error(w, errorTmpl.Error(), http.StatusInternalServerError) diff --git a/service/report/report.go b/service/report/report.go index caf2e958..9b640625 100644 --- a/service/report/report.go +++ b/service/report/report.go @@ -19,7 +19,7 @@ func CreateTorrentReport(torrentReport model.TorrentReport) error { return nil } -func DeleteTorrentReport(id int) (error, int) { +func DeleteTorrentReport(id uint) (error, int) { var torrentReport model.TorrentReport if db.ORM.First(&torrentReport, id).RecordNotFound() { return errors.New("Trying to delete a torrent report that does not exists."), http.StatusNotFound diff --git a/templates/_profile_edit.html b/templates/_profile_edit.html index a3496f45..c5198f00 100644 --- a/templates/_profile_edit.html +++ b/templates/_profile_edit.html @@ -23,7 +23,10 @@
{{ range (index $.FormErrors "language")}} diff --git a/templates/view.html b/templates/view.html index f50a2252..b9ee04f2 100644 --- a/templates/view.html +++ b/templates/view.html @@ -1,100 +1,100 @@ {{define "title"}}{{.Torrent.Name}}{{end}} {{define "contclass"}}cont-view{{end}} {{define "content"}} -
- {{with .Torrent}} -
- - - - - - - - - - - - - - - - - - - - - {{if ne .WebsiteLink ""}} - - - - - {{end}} - - - - - - - - - - - - - - - - - {{ range $index, $element := .Comments }} - - - - - {{end}} -
{{T "name"}} - {{.Name}} - -
{{T "hash"}}{{.Hash}}
{{T "date"}}{{.Date}}
{{T "size"}}{{.Filesize}}
Uploader - {{.UploaderName}} - {{if ne .OldUploader ""}} - ({{.OldUploader}}) - {{end}} -
{{T "Link"}}{{.WebsiteLink}}
{{T "links"}} - - Download! - - - - Torrent file - - - Report! - +
+ {{with .Torrent}} +
+
+
+
+
+
+

{{.Name}}

+
+ +

Uploaded by {{.UploaderName}}

+
+
+
+
+
+
+ + Download! + + {{if ne .TorrentLink ""}} + + Torrent file + + + Report! + {{end}} {{ if HasAdmin $.User}} {{ T "delete" }} {{end}} -
{{T "description"}}{{.Description}}
{{T "comments"}}
- {{$index}} {{.Username}} - {{.Content}}
- {{end}} -
-
- {{/* There should be a better way to use translation on this... */}} - - + + +
+
+
+
+

{{T "hash"}}

+

{{.Hash}}

+
+

{{T "date"}}

+

{{.Date}}

+
+

{{T "size"}}

+

{{.Filesize}}

+
+ {{if ne .WebsiteLink ""}} +

{{T "Link"}}

+

{{.WebsiteLink}}

+
+ {{end}} +
- {{with .Captcha}} {{block "captcha" .}}{{end}} {{end}} - - +
+
+

{{T "description"}}

+
{{.Description}}
+
+
+
+
+

{{T "comments"}}

+ {{ range $index, $element := .Comments }} +
+
+ {{$index}} {{.Username}} +
+
+ {{.Content}} +
+
+ {{end}} +
+
+ + {{end}} +
+
+
+
+ {{/* There should be a better way to use translation on this... */}} + + +
+ {{with .Captcha}} {{block "captcha" .}}{{end}} {{end}} + +
+
+
{{with .Torrent}} {{end}} diff --git a/translations/it-it.all.json b/translations/it-it.all.json index a00317c8..787ab652 100644 --- a/translations/it-it.all.json +++ b/translations/it-it.all.json @@ -25,7 +25,7 @@ }, { "id":"signup_box_title", - "translation": "Iscriviti È gratuito e lo sara per sempre." + "translation": "Iscriviti È gratuito e lo sarà per sempre." }, { "id":"username", @@ -269,7 +269,7 @@ }, { "id": "answer_is_nyaa_db_lost", - "translation": "Abbiamo un database dei torrent di nyaa fino al 5 Aprile/s> 1° Maggio. Questo vuol dire che quasi niente è andato perduto." + "translation": "Abbiamo un database dei torrent di nyaa fino al 5 Aprile 1° Maggio. Questo vuol dire che quasi niente è andato perduto." }, { "id": "answer_is_sukebei_db_lost", diff --git a/util/languages/translation.go b/util/languages/translation.go index d907a8d2..aa25588d 100644 --- a/util/languages/translation.go +++ b/util/languages/translation.go @@ -3,6 +3,7 @@ package languages import ( "fmt" "github.com/nicksnyder/go-i18n/i18n" + "github.com/ewhal/nyaa/service/user" "html/template" "net/http" ) @@ -33,6 +34,22 @@ func TfuncWithFallback(language string, languages ...string) (i18n.TranslateFunc }, nil } +func GetAvailableLanguages() (languages map[string]string) { + languages = make(map[string]string) + var T i18n.TranslateFunc + for _, languageTag := range i18n.LanguageTags() { + T, _ = i18n.Tfunc(languageTag) + /* Translation files should have an ID with the translated language name. + If they don't, just use the languageTag */ + if languageName := T("language_name"); languageName != "language_name" { + languages[languageTag] = languageName; + } else { + languages[languageTag] = languageTag + } + } + return +} + func SetTranslation(tmpl *template.Template, language string, languages ...string) i18n.TranslateFunc { T, _ := TfuncWithFallback(language, languages...) tmpl.Funcs(map[string]interface{}{ @@ -44,12 +61,19 @@ func SetTranslation(tmpl *template.Template, language string, languages ...strin } func SetTranslationFromRequest(tmpl *template.Template, r *http.Request, defaultLanguage string) i18n.TranslateFunc { + userLanguage := "" + user, _, err := userService.RetrieveCurrentUser(r) + if err == nil { + userLanguage = user.Language; + } + cookie, err := r.Cookie("lang") cookieLanguage := "" if err == nil { cookieLanguage = cookie.Value } + // go-i18n supports the format of the Accept-Language header, thankfully. headerLanguage := r.Header.Get("Accept-Language") - return SetTranslation(tmpl, cookieLanguage, headerLanguage, defaultLanguage) + return SetTranslation(tmpl, userLanguage, cookieLanguage, headerLanguage, defaultLanguage) }