Albirew/nyaa-pantsu
Archivé
1
0
Bifurcation 0

Merge remote-tracking branch 'refs/remotes/origin/master' into delete-button

Cette révision appartient à :
akuma06 2017-05-10 22:03:28 +02:00
révision 21a2e70692
10 fichiers modifiés avec 151 ajouts et 97 suppressions

Voir le fichier

@ -123,3 +123,10 @@ a:hover {
#mainmenu a.nightswitch { #mainmenu a.nightswitch {
background-image: url(/img/moon.png); background-image: url(/img/moon.png);
} }
/* Force images on description to fit width */
#description img {
display: block;
max-width: 100%;
height: auto;
}

Voir le fichier

@ -104,7 +104,8 @@ td {
.comment-row td:first-of-type { .comment-row td:first-of-type {
vertical-align: top; vertical-align: top;
text-align: right; text-align: left;
color:#bbb;
} }
/* Table style & fixes */ /* Table style & fixes */
@ -339,3 +340,10 @@ footer {
color: #616161; color: #616161;
text-shadow: -1px -1px #999999; text-shadow: -1px -1px #999999;
} }
/* Force images on description to fit width */
#description img {
display: block;
max-width: 100%;
height: auto;
}

Voir le fichier

@ -3,6 +3,7 @@
package router package router
import ( import (
"fmt"
"html" "html"
"html/template" "html/template"
"net/http" "net/http"
@ -10,6 +11,7 @@ import (
"strconv" "strconv"
"github.com/ewhal/nyaa/model" "github.com/ewhal/nyaa/model"
"github.com/ewhal/nyaa/service"
"github.com/ewhal/nyaa/service/comment" "github.com/ewhal/nyaa/service/comment"
"github.com/ewhal/nyaa/service/report" "github.com/ewhal/nyaa/service/report"
"github.com/ewhal/nyaa/service/torrent" "github.com/ewhal/nyaa/service/torrent"
@ -50,6 +52,7 @@ func IndexModPanel(w http.ResponseWriter, r *http.Request) {
users, _ := userService.RetrieveUsersForAdmin(offset, 0) users, _ := userService.RetrieveUsersForAdmin(offset, 0)
comments, _ := commentService.GetAllComments(offset, 0, "", "") comments, _ := commentService.GetAllComments(offset, 0, "", "")
torrentReports, _, _ := reportService.GetAllTorrentReports(offset, 0) torrentReports, _, _ := reportService.GetAllTorrentReports(offset, 0)
fmt.Println(torrentReports)
languages.SetTranslationFromRequest(panelIndex, r, "en-us") languages.SetTranslationFromRequest(panelIndex, r, "en-us")
htv := PanelIndexVbs{torrents, torrentReports, users, comments, NewSearchForm(), currentUser, r.URL} 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) { if userPermission.HasAdmin(currentUser) {
_ = form.NewErrors() _ = form.NewErrors()
_, _ = torrentService.DeleteTorrent(id) _, _ = 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() url, _ := Router.Get("mod_tlist").URL()
http.Redirect(w, r, url.String()+"?deleted", http.StatusSeeOther) http.Redirect(w, r, url.String()+"?deleted", http.StatusSeeOther)
} else { } else {

Voir le fichier

@ -59,6 +59,7 @@ type UserProfileEditVariables struct {
UserForm userForms.UserForm UserForm userForms.UserForm
FormErrors map[string][]string FormErrors map[string][]string
FormInfos map[string][]string FormInfos map[string][]string
Languages map[string]string
Search SearchForm Search SearchForm
Navigation Navigation Navigation Navigation
User *model.User User *model.User

Voir le fichier

@ -115,7 +115,8 @@ func UserDetailsHandler(w http.ResponseWriter, r *http.Request) {
languages.SetTranslationFromRequest(viewProfileEditTemplate, r, "en-us") languages.SetTranslationFromRequest(viewProfileEditTemplate, r, "en-us")
searchForm := NewSearchForm() searchForm := NewSearchForm()
searchForm.HideAdvancedSearch = true 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) err := viewProfileEditTemplate.ExecuteTemplate(w, "index.html", htv)
if err != nil { if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError) 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) errorTmpl := viewProfileEditTemplate.ExecuteTemplate(w, "index.html", htv)
if errorTmpl != nil { if errorTmpl != nil {
http.Error(w, errorTmpl.Error(), http.StatusInternalServerError) http.Error(w, errorTmpl.Error(), http.StatusInternalServerError)

Voir le fichier

@ -19,7 +19,7 @@ func CreateTorrentReport(torrentReport model.TorrentReport) error {
return nil return nil
} }
func DeleteTorrentReport(id int) (error, int) { func DeleteTorrentReport(id uint) (error, int) {
var torrentReport model.TorrentReport var torrentReport model.TorrentReport
if db.ORM.First(&torrentReport, id).RecordNotFound() { if db.ORM.First(&torrentReport, id).RecordNotFound() {
return errors.New("Trying to delete a torrent report that does not exists."), http.StatusNotFound return errors.New("Trying to delete a torrent report that does not exists."), http.StatusNotFound

Voir le fichier

@ -23,7 +23,10 @@
<div class="col-lg-8"> <div class="col-lg-8">
<div class="ui-select"> <div class="ui-select">
<select id="language" name="language" class="form-control"> <select id="language" name="language" class="form-control">
<option value="en-us" {{ if eq .Language "en-us" }}selected{{end}}>{{T "english"}} ({{ T "default" }})</option> {{ $userLanguage := .Language }}
{{ range $tag, $translatedName := $.Languages }}
<option value="{{ $tag }}" {{ if or (eq $userLanguage $tag) (and (eq $userLanguage "") (eq $tag "en-us")) }}selected{{end}}>{{ $translatedName }} {{if eq $tag "en-us"}}({{ T "default" }}){{end}}</option>
{{ end }}
</select> </select>
</div> </div>
{{ range (index $.FormErrors "language")}} {{ range (index $.FormErrors "language")}}

Voir le fichier

@ -1,100 +1,100 @@
{{define "title"}}{{.Torrent.Name}}{{end}} {{define "title"}}{{.Torrent.Name}}{{end}}
{{define "contclass"}}cont-view{{end}} {{define "contclass"}}cont-view{{end}}
{{define "content"}} {{define "content"}}
<div class="blockBody"> <div class="blockBody">
{{with .Torrent}} {{with .Torrent}}
<hr> <hr>
<table class="table table-borderless"> <div class="content" style="margin-bottom: 2em;">
<tr {{if eq .Status 2}}class="remake"{{end}} <div class="row">
{{if eq .Status 3}}class="trusted"{{end}} <div class="col-md-8">
{{if eq .Status 4}}class="aplus"{{end}}> <div class="row">
<td>{{T "name"}}</td> <div class="col-md-12">
<td> <h3 style="word-break:break-all" {{if eq .Status 2}}class="remake" {{end}} {{if eq .Status 3}}class="trusted" {{end}} {{if eq .Status 4}}class="aplus"{{end}}>{{.Name}}</h3>
{{.Name}} <div class="uploaded_by">
<img style="float:right" src="{{$.URL.Parse (printf "/img/torrents/%s.png" .SubCategory) }}"> <img style="float:left; margin-right: 1em;" src="{{$.URL.Parse (printf "/img/torrents/%s.png" .SubCategory) }}">
</td> <h4>Uploaded by <a href="{{$.URL.Parse (printf "/user/%d/-" .UploaderID) }}">{{.UploaderName}}</a></h4>
</tr> </div>
<tr> </div>
<td>{{T "hash"}}</td> </div>
<td class="torrent-hash">{{.Hash}}</td> <br />
</tr> <div class="row">
<tr> <div class="col-md-12">
<td>{{T "date"}}</td> <a style="margin: 5px;" aria-label="Magnet Button" href="{{.Magnet}}" type="button" class="btn btn-lg btn-success download-btn">
<td class="date-full">{{.Date}}</td> <span class="glyphicon glyphicon-magnet" aria-hidden="true"></span> Download!
</tr> </a>
<tr> {{if ne .TorrentLink ""}}
<td>{{T "size"}}</td> <a style="margin: 5px;" aria-label="Torrent file" href="{{.TorrentLink}}" type="button" class="btn btn-lg btn-success download-btn">
<td>{{.Filesize}}</td> <span class="glyphicon glyphicon-floppy-save" aria-hidden="true"></span> Torrent file
</tr> </a>
<tr> <a style="margin: 5px;" aria-label="Report button" href="{{.TorrentLink}}" type="button" data-toggle="modal" data-target="#reportModal" class="btn btn-danger btn-lg download-btn">
<td>Uploader</td> <span class="glyphicon glyphicon-remove" aria-hidden="true"></span> Report!
<td> </a> {{end}}
<a href="{{$.URL.Parse (printf "/user/%d/-" .UploaderID) }}">{{.UploaderName}}</a>
{{if ne .OldUploader ""}}
({{.OldUploader}})
{{end}}
</td>
{{if ne .WebsiteLink ""}}
<tr>
<td>{{T "Link"}}</td>
<td><a href="{{.WebsiteLink}}">{{.WebsiteLink}}</td>
</tr>
{{end}}
<tr>
<td>{{T "links"}}</td>
<td>
<a aria-label="Magnet Button" href="{{.Magnet}}" type="button" class="btn btn-success download-btn">
<span class="glyphicon glyphicon-magnet" aria-hidden="true"></span> Download!
</a>
<a style="padding-left: 0.5em"></a>
<a aria-label="Torrent file" href="{{.TorrentLink}}" type="button" class="btn btn-success download-btn">
<span class="glyphicon glyphicon-floppy-save" aria-hidden="true"></span> Torrent file
</a>
<a aria-label="Report button" href="{{.TorrentLink}}" type="button" data-toggle="modal" data-target="#reportModal" class="btn btn-danger download-btn">
<span class="glyphicon glyphicon-remove" aria-hidden="true"></span> Report!
</a>
{{ if HasAdmin $.User}} {{ if HasAdmin $.User}}
<a href="{{ genRoute "mod_tdelete" }}?id={{ .ID }}" class="btn btn-danger btn-lg" onclick="if (!confirm('Are you sure?')) return false;"><i class="glyphicon glyphicon-trash"></i>{{ T "delete" }}</a> <a href="{{ genRoute "mod_tdelete" }}?id={{ .ID }}" class="btn btn-danger btn-lg" onclick="if (!confirm('Are you sure?')) return false;"><i class="glyphicon glyphicon-trash"></i>{{ T "delete" }}</a>
{{end}} {{end}}
</td>
</tr>
<tr> </div>
<td>{{T "description"}}</td> </div>
<td>{{.Description}}</td> </div>
</tr> <div class="col-md-4">
<tr style="height:2em"> <h4>{{T "hash"}}</h4>
<td></td> <p>{{.Hash}}</p>
<td></td> <hr>
</tr> <h4>{{T "date"}}</h4>
<tr> <p>{{.Date}}</p>
<td>{{T "comments"}}</td> <hr>
<td></td> <h4>{{T "size"}}</h4>
</tr> <p>{{.Filesize}}</p>
{{ range $index, $element := .Comments }} <hr>
<tr class="comment-row" id="comment_{{$index}}"> {{if ne .WebsiteLink ""}}
<td> <h4>{{T "Link"}}</h4>
<a href="#comment_{{$index}}">{{$index}}</a> {{.Username}} <p><a href="{{.WebsiteLink}}">{{.WebsiteLink}}</a></p>
</td> <hr>
<td>{{.Content}}</td> {{end}}
</tr> </div>
{{end}}
</table>
{{end}}
<form method="post">
<div class="form-group">
{{/* There should be a better way to use translation on this... */}}
<label for="comment">{{ if gt .User.ID 0}} {{T "submit_a_comment_as_username" .User.Username}} {{else}} {{T "submit_a_comment_as_anonymous"}} {{end}}</label>
<textarea name="comment" class="form-control" rows="5"></textarea>
</div> </div>
{{with .Captcha}} {{block "captcha" .}}{{end}} {{end}} <div class="row" id="description">
<input type="submit" value="{{T " submit "}}"> <div class="col-md-12">
</form> <h4>{{T "description"}}</h4>
<div style="word-break:break-all;">{{.Description}}</div>
</div>
</div>
<div class="row" id="comments">
<div class="col-md-12">
<h4>{{T "comments"}}</h4>
{{ range $index, $element := .Comments }}
<div class="row comment-row" id="comment_{{$index}}">
<div class="col-md-4">
<a href="#comment_{{$index}}">{{$index}}</a> {{.Username}}
</div>
<div class="col-md-8">
{{.Content}}
</div>
</div>
{{end}}
</div>
</div>
</div>
{{end}}
<div class="row" style="margin-bottom: 2em;">
<div class="col-md-12">
<form method="post">
<div class="form-group">
{{/* There should be a better way to use translation on this... */}}
<label for="comment">{{ if gt .User.ID 0}} {{T "submit_a_comment_as_username" .User.Username}} {{else}} {{T "submit_a_comment_as_anonymous"}} {{end}}</label>
<textarea name="comment" class="form-control" rows="5"></textarea>
</div>
{{with .Captcha}} {{block "captcha" .}}{{end}} {{end}}
<input type="submit" value="{{T " submit "}}">
</form>
</div>
</div>
</div> </div>
{{with .Torrent}} {{with .Torrent}}
<div id="reportModal" class="modal fade" role="dialog"> <div id="reportModal" class="modal fade" role="dialog">
<div class="modal-dialog"> <div class="modal-dialog">
<!-- Modal content--> <!-- Modal content-->
<div class="modal-content"> <div class="modal-content">
<div class="modal-header"> <div class="modal-header">
@ -106,15 +106,14 @@
<form method="post" action="/report/{{.ID}}"> <form method="post" action="/report/{{.ID}}">
<input type="radio" name="report_type" value="illegal"> Illegal content <br/> <input type="radio" name="report_type" value="illegal"> Illegal content <br/>
<input type="radio" name="report_type" value="spam"> Spam / garbage <input type="radio" name="report_type" value="spam"> Spam / garbage
{{end}} {{end}}
{{with .Captcha}} {{block "captcha" .}}{{end}} {{end}} {{with .Captcha}} {{block "captcha" .}}{{end}} {{end}}
<button type="submit" class="btn btn-default">Report!</button> <button type="submit" class="btn btn-default">Report!</button>
</form> <br /> </form> <br />
</div> </div>
<div class="modal-footer"> <div class="modal-footer">
</div> </div>
</div> </div>
</div> </div>
</div> </div>
{{end}} {{end}}

Voir le fichier

@ -25,7 +25,7 @@
}, },
{ {
"id":"signup_box_title", "id":"signup_box_title",
"translation": "Iscriviti <small>È gratuito e lo sara per sempre.</small>" "translation": "Iscriviti <small>È gratuito e lo sarà per sempre.</small>"
}, },
{ {
"id":"username", "id":"username",
@ -269,7 +269,7 @@
}, },
{ {
"id": "answer_is_nyaa_db_lost", "id": "answer_is_nyaa_db_lost",
"translation": "Abbiamo un database dei torrent di nyaa fino al <s>5 Aprile/s> 1° Maggio. Questo vuol dire che quasi niente è andato perduto." "translation": "Abbiamo un database dei torrent di nyaa fino al <s>5 Aprile</s> 1° Maggio. Questo vuol dire che quasi niente è andato perduto."
}, },
{ {
"id": "answer_is_sukebei_db_lost", "id": "answer_is_sukebei_db_lost",

Voir le fichier

@ -3,6 +3,7 @@ package languages
import ( import (
"fmt" "fmt"
"github.com/nicksnyder/go-i18n/i18n" "github.com/nicksnyder/go-i18n/i18n"
"github.com/ewhal/nyaa/service/user"
"html/template" "html/template"
"net/http" "net/http"
) )
@ -33,6 +34,22 @@ func TfuncWithFallback(language string, languages ...string) (i18n.TranslateFunc
}, nil }, 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 { func SetTranslation(tmpl *template.Template, language string, languages ...string) i18n.TranslateFunc {
T, _ := TfuncWithFallback(language, languages...) T, _ := TfuncWithFallback(language, languages...)
tmpl.Funcs(map[string]interface{}{ 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 { 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") cookie, err := r.Cookie("lang")
cookieLanguage := "" cookieLanguage := ""
if err == nil { if err == nil {
cookieLanguage = cookie.Value cookieLanguage = cookie.Value
} }
// go-i18n supports the format of the Accept-Language header, thankfully. // go-i18n supports the format of the Accept-Language header, thankfully.
headerLanguage := r.Header.Get("Accept-Language") headerLanguage := r.Header.Get("Accept-Language")
return SetTranslation(tmpl, cookieLanguage, headerLanguage, defaultLanguage) return SetTranslation(tmpl, userLanguage, cookieLanguage, headerLanguage, defaultLanguage)
} }