diff --git a/controllers/feed/helpers.go b/controllers/feed/helpers.go index 7a49e013..4fb788dd 100644 --- a/controllers/feed/helpers.go +++ b/controllers/feed/helpers.go @@ -39,6 +39,7 @@ func getTorrentList(c *gin.Context) (torrents []models.Torrent, createdAsTime ti title = "Sukebei Pantsu" } + pagenum := 1 if page == "" && offset > 0 { // first page for offset is 0 pagenum = offset + 1 @@ -86,7 +87,12 @@ func getTorrentList(c *gin.Context) (torrents []models.Torrent, createdAsTime ti user = 0 } - _, torrents, _, err = search.AuthorizedQuery(c, pagenum, currentUser.CurrentOrJanitor(uint(user)), currentUser.CurrentOrJanitor(uint(user))) + var searchParam search.TorrentParam + searchParam, torrents, _, err = search.AuthorizedQuery(c, pagenum, currentUser.CurrentOrJanitor(uint(user)), currentUser.CurrentOrJanitor(uint(user))) + + if searchParam.NameLike != "" { + title += " - " + searchParam.NameLike + } return } diff --git a/controllers/torrent/comment.go b/controllers/torrent/comment.go index 4924edd1..5bf0b704 100644 --- a/controllers/torrent/comment.go +++ b/controllers/torrent/comment.go @@ -9,11 +9,10 @@ import ( "github.com/NyaaPantsu/nyaa/controllers/router" "github.com/NyaaPantsu/nyaa/models/comments" "github.com/NyaaPantsu/nyaa/models/torrents" + "github.com/NyaaPantsu/nyaa/models" "github.com/NyaaPantsu/nyaa/utils/captcha" - "github.com/NyaaPantsu/nyaa/utils/filelist" msg "github.com/NyaaPantsu/nyaa/utils/messages" "github.com/NyaaPantsu/nyaa/utils/sanitize" - "github.com/NyaaPantsu/nyaa/templates" "github.com/gin-gonic/gin" ) @@ -39,6 +38,9 @@ func PostCommentHandler(c *gin.Context) { if currentUser.IsBanned() { messages.AddErrorT("errors", "account_banned") } + if torrent.Status == models.TorrentStatusBlocked && !currentUser.CurrentOrJanitor(torrent.UploaderID) { + messages.AddErrorT("errors", "torrent_locked") + } content := sanitize.Sanitize(c.PostForm("comment"), "comment") userID := currentUser.ID @@ -60,12 +62,5 @@ func PostCommentHandler(c *gin.Context) { } } - captchaID := "" - //Generate a captcha - if currentUser.NeedsCaptcha() { - captchaID = captcha.GetID() - } - - folder := filelist.FileListToFolder(torrent.FileList, "root") - templates.Torrent(c, torrent.ToJSON(), folder, captchaID) + ViewHandler(c) } diff --git a/models/torrent.go b/models/torrent.go index a533157f..41da309c 100644 --- a/models/torrent.go +++ b/models/torrent.go @@ -312,7 +312,11 @@ func (t *Torrent) ToJSON() TorrentJSON { } for _, c := range t.Comments { if c.User != nil { - commentsJSON = append(commentsJSON, CommentJSON{Username: c.User.Username, UserID: int(c.User.ID), UserStatus: c.User.GetRole(), Content: sanitize.MarkdownToHTML(c.Content), Date: c.CreatedAt.UTC(), UserAvatar: c.User.MD5}) + role := c.User.GetRole() + if t.UploaderID == c.User.ID && !c.User.IsBanned() { + role = "userstatus_uploader" + } + commentsJSON = append(commentsJSON, CommentJSON{Username: c.User.Username, UserID: int(c.User.ID), UserStatus: role, Content: sanitize.MarkdownToHTML(c.Content), Date: c.CreatedAt.UTC(), UserAvatar: c.User.MD5}) } else { commentsJSON = append(commentsJSON, CommentJSON{}) } diff --git a/models/torrents/helpers.go b/models/torrents/helpers.go index a04f1ad8..8285dc18 100644 --- a/models/torrents/helpers.go +++ b/models/torrents/helpers.go @@ -37,13 +37,11 @@ func NewTorrentEvent(user *models.User, torrent *models.Torrent) error { url := "/view/" + strconv.FormatUint(uint64(torrent.ID), 10) if user.ID > 0 && config.Get().Users.DefaultUserSettings["new_torrent"] { // If we are a member and notifications for new torrents are enabled user.GetFollowers() // We populate the liked field for users - if len(user.Followers) > 0 { // If we are followed by at least someone - for _, follower := range user.Followers { - follower.ParseSettings() // We need to call it before checking settings - if follower.Settings.Get("new_torrent") { - T, _, _ := publicSettings.TfuncAndLanguageWithFallback(follower.Language, follower.Language) // We need to send the notification to every user in their language - notifications.NotifyUser(&follower, torrent.Identifier(), fmt.Sprintf(T("new_torrent_uploaded"), torrent.Name, user.Username), url, follower.Settings.Get("new_torrent_email")) - } + for _, follower := range user.Followers { + follower.ParseSettings() // We need to call it before checking settings + if follower.Settings.Get("new_torrent") { + T, _, _ := publicSettings.TfuncAndLanguageWithFallback(follower.Language, follower.Language) // We need to send the notification to every user in their language + notifications.NotifyUser(&follower, torrent.Identifier(), fmt.Sprintf(T("new_torrent_uploaded"), torrent.Name, user.Username), url, follower.Settings.Get("new_torrent_email")) } } } diff --git a/models/user.go b/models/user.go index 5016d931..05d98c69 100644 --- a/models/user.go +++ b/models/user.go @@ -260,17 +260,19 @@ func (u *User) ToJSON() UserJSON { } // GetLikings : Gets who is followed by the user -func (u *User) GetLikings() { +func (u *User) GetLikings() int { var liked []User ORM.Joins("JOIN user_follows on user_follows.following=?", u.ID).Where("users.user_id = user_follows.user_id").Group("users.user_id").Find(&liked) u.Likings = liked + return len(u.Likings) } // GetFollowers : Gets who is following the user -func (u *User) GetFollowers() { +func (u *User) GetFollowers() int { var likings []User ORM.Joins("JOIN user_follows on user_follows.user_id=?", u.ID).Where("users.user_id = user_follows.following").Group("users.user_id").Find(&likings) u.Followers = likings + return len(u.Followers) } // SetFollow : Makes a user follow another @@ -278,6 +280,7 @@ func (u *User) SetFollow(follower *User) { if follower.ID > 0 && u.ID > 0 { var userFollows = UserFollows{UserID: u.ID, FollowerID: follower.ID} ORM.Create(&userFollows) + u.Likings = append(u.Likings, *follower) } } @@ -286,6 +289,15 @@ func (u *User) RemoveFollow(follower *User) { if follower.ID > 0 && u.ID > 0 { var userFollows = UserFollows{UserID: u.ID, FollowerID: follower.ID} ORM.Delete(&userFollows) + for i, followr := range u.Likings { + if followr.ID == follower.ID { + u.Likings[i] = u.Likings[len(u.Likings)-1] + // The very last follower will take the place of the one that is getting deleted in the array + u.Likings = u.Likings[:len(u.Likings)-1] + // We now proceed to delete the very last array element since it got copied to another position + return + } + } } } diff --git a/public/css/main.css b/public/css/main.css index da2eebd8..79c6483e 100644 --- a/public/css/main.css +++ b/public/css/main.css @@ -452,8 +452,12 @@ select.form-input { margin-bottom: 0; width: 85px!important; } +.refine-container-2 [name="hash"] { + float: right; + width: 187px!important; +} .refine-date { - width: 98px!important; + width: 135px!important; } .categories a { @@ -462,7 +466,7 @@ select.form-input { padding: 10px 5px; } -#announce { +.announce { margin-bottom: 4px; padding: 7px 10px; background-color: #D9EDF7; @@ -470,7 +474,7 @@ select.form-input { border-radius: 7px; } -#announce:before { +.announce:before { content: "!"; vertical-align: middle; float: left; @@ -478,6 +482,13 @@ select.form-input { font-size: 2.2em; font-weight: bold; } +.announcement-content :first-child { + margin-top: 0; +} + +.announcement-content :last-child { + margin-bottom: 0; +} .results { padding: 0!important; @@ -857,6 +868,9 @@ html, body { float: none!important; max-width: none; } + .refine-container-2 [name="hash"] { + float: none; + } .upload-form-table .table-checkboxes { padding: 3px 0!important; width: 100%; diff --git a/public/css/themes/classic.css b/public/css/themes/classic.css index 4e693089..791e1279 100644 --- a/public/css/themes/classic.css +++ b/public/css/themes/classic.css @@ -767,14 +767,9 @@ span.tag { .torrent-info-data #subscribe-link::before, .torrent-info-data #subscribe-link:: after { color: #111111; } -.content > p:first-child+div.centered+div.refine+div #reportPopup { - top: 145px; -} -.content > p:first-child+div#announce+div.refine+div #reportPopup { - top: 110px; -} -.content > div#announce:first-child+div.refine+div #reportPopup { - top: 65px; + +.box { + position: relative; } #reportPopup { text-decoration: underline dotted; @@ -783,8 +778,8 @@ span.tag { background: none; color: #106655!important; position: absolute; - top: 103px; - right: 11px; + top: 6px; + right: 0; } .comment-content :first-child { margin-top: 5px; diff --git a/public/css/themes/classic_colors.css b/public/css/themes/classic_colors.css index 29f2a4b7..57d0cab6 100644 --- a/public/css/themes/classic_colors.css +++ b/public/css/themes/classic_colors.css @@ -163,7 +163,7 @@ td.tr-le, .error-text { background-size: 100%; } -#announce { +.announce { color: #3a4249; background-color: #fff5e7; border-color: #ecd2ae; diff --git a/public/css/themes/tomorrow.css b/public/css/themes/tomorrow.css index d9bd6513..b01a4c71 100644 --- a/public/css/themes/tomorrow.css +++ b/public/css/themes/tomorrow.css @@ -238,7 +238,7 @@ a.form-input[class*="btn"]:hover { background: #cc4f4f; } -#announce { +.announce { color: #3a4249; background-color: #F4E0C9; border-color: #ae875b; diff --git a/templates/admin/announcement_form.jet.html b/templates/admin/announcement_form.jet.html index 5ce2bbe3..4f8b5c64 100644 --- a/templates/admin/announcement_form.jet.html +++ b/templates/admin/announcement_form.jet.html @@ -7,7 +7,7 @@
- + {{ yield errors(name="Message")}}
@@ -19,3 +19,7 @@
{{end}} +{{ block footer_js()}} + + +{{end}} diff --git a/templates/admin/torrentlist.jet.html b/templates/admin/torrentlist.jet.html index 82b23e83..1aad6094 100644 --- a/templates/admin/torrentlist.jet.html +++ b/templates/admin/torrentlist.jet.html @@ -99,7 +99,7 @@ var deleteButtons = document.querySelectorAll("button.form-input.btn-red") e.preventDefault() if(needConfirmation && !confirm("Are you sure?")) { return - } else if(!needConfirmation) { + } else { var form = this.parentNode var formInputs = form.querySelectorAll('input') var query = "" diff --git a/templates/helpers.go b/templates/helpers.go index bec28d8e..159d25f1 100644 --- a/templates/helpers.go +++ b/templates/helpers.go @@ -55,12 +55,12 @@ func NewSearchForm(c *gin.Context) SearchForm { ShowRefine: false, SizeType: sizeType, User: c.Query("user"), - UserName: "", + UserName: "", DateType: c.Query("dateType"), MinSize: c.Query("minSize"), // We need to overwrite the value here, since size are formatted MaxSize: c.Query("maxSize"), // We need to overwrite the value here, since size are formatted FromDate: c.Query("fromDate"), // We need to overwrite the value here, since we can have toDate instead and date are formatted ToDate: c.Query("toDate"), // We need to overwrite the value here, since date are formatted - SearchURL: "/search", + SearchURL: "/search", } } diff --git a/templates/layouts/index_site.jet.html b/templates/layouts/index_site.jet.html index 22944a3a..7e985fca 100644 --- a/templates/layouts/index_site.jet.html +++ b/templates/layouts/index_site.jet.html @@ -12,7 +12,7 @@ {{ block content_body_base()}} {{ if isset(Infos["system"])}} {{ range Infos["system"]}} -
{{T("announcement")}}
{{ .|raw }}
+
{{T("announcement")}}
{{ .|raw }}
{{ end }} {{ end }} {{ yield search_refine(url=URL.Parse(Search.SearchURL)) }} diff --git a/templates/layouts/partials/helpers/search.jet.html b/templates/layouts/partials/helpers/search.jet.html index e182fe82..c8f97901 100644 --- a/templates/layouts/partials/helpers/search.jet.html +++ b/templates/layouts/partials/helpers/search.jet.html @@ -52,10 +52,9 @@ {{ T("from")}} - + {{ T("to")}} - - {{ T("exclude_user") }}: + {{T("sort_by")}} @@ -71,6 +70,7 @@ + {{ T("exclude_user") }}:
@@ -83,7 +83,7 @@ {{end}} Hash: - + Tags: diff --git a/templates/site/torrents/upload.jet.html b/templates/site/torrents/upload.jet.html index bdfdcd67..56496188 100644 --- a/templates/site/torrents/upload.jet.html +++ b/templates/site/torrents/upload.jet.html @@ -66,27 +66,6 @@ - - - -
- - - - - - -
- - - - - - -
- - - {{ T("torrent_tags")}}: diff --git a/templates/site/torrents/view.jet.html b/templates/site/torrents/view.jet.html index d11fb940..ed2d6f84 100644 --- a/templates/site/torrents/view.jet.html +++ b/templates/site/torrents/view.jet.html @@ -155,6 +155,23 @@
+ {{ if User.IsModerator() }} +
+ {{ yield csrf_field()}} + + + + + + + + + {{ range _, lang := Torrent.Languages}} + + {{end}} + +
+ {{end}}
{{ T("magnet_link")}}
diff --git a/templates/site/user/notifications.jet.html b/templates/site/user/notifications.jet.html index 0a761e9a..13474c17 100644 --- a/templates/site/user/notifications.jet.html +++ b/templates/site/user/notifications.jet.html @@ -1,6 +1,6 @@ {{ extends "layouts/profile" }} {{ import "layouts/partials/menu/profile" }} -{{block title()}}{{ T("profile_edit_page", User.Username) }}{{end}} +{{block title()}}{{ T("my_notifications") }}{{end}} {{ block profile_navigation()}}{{ yield profile_menu(route="profile") }}{{end}} {{block profile_content()}} diff --git a/templates/template.go b/templates/template.go index 86dd3301..71ddc906 100644 --- a/templates/template.go +++ b/templates/template.go @@ -180,7 +180,7 @@ func userProfileBase(c *gin.Context, templateName string, userProfile *models.Us } variables.Set("UserProfile", userProfile) - variables.Set("NbTorrents", []int64{int64(nbTorrents),uploadedSize}) + variables.Set("NbTorrents", []int64{int64(nbTorrents), uploadedSize}) Render(c, path.Join(SiteDir, "user", templateName), variables) } diff --git a/templates/template_functions.go b/templates/template_functions.go index 7816e86a..086114c2 100644 --- a/templates/template_functions.go +++ b/templates/template_functions.go @@ -346,7 +346,7 @@ func torrentFileExists(hash string, TorrentLink string) bool { return true } Openfile, err := os.Open(fmt.Sprintf("%s%c%s.torrent", config.Get().Torrents.FileStorage, os.PathSeparator, hash)) - if err != nil { + if err != nil || len(TorrentLink) == 0 { //File doesn't exist return false } diff --git a/utils/messages/messages.go b/utils/messages/messages.go index 97b671c8..41b737da 100644 --- a/utils/messages/messages.go +++ b/utils/messages/messages.go @@ -6,6 +6,7 @@ import ( "github.com/NyaaPantsu/nyaa/models/notifications" "github.com/NyaaPantsu/nyaa/utils/publicSettings" + "github.com/NyaaPantsu/nyaa/utils/sanitize" "github.com/gin-gonic/gin" "github.com/nicksnyder/go-i18n/i18n" ) @@ -34,7 +35,7 @@ func GetMessages(c *gin.Context) *Messages { mes := &Messages{make(map[string][]string), make(map[string][]string), c, T} announcements, _ := notifications.CheckAnnouncement() for _, announcement := range announcements { - mes.AddInfo("system", announcement.Content) + mes.AddInfo("system", string(sanitize.MarkdownToHTML(announcement.Content))) } c.Set(MessagesKey, mes) return mes diff --git a/utils/search/datefilter.go b/utils/search/datefilter.go index c4ec8554..5fc35663 100644 --- a/utils/search/datefilter.go +++ b/utils/search/datefilter.go @@ -32,7 +32,7 @@ func (d *DateFilter) ParseOld(s string, dateType string) bool { } // Parse parses a date to a datefilter object and return true if it succeeded -// This functions accept only date formatted in this way YYYY/MM/DD +// This function accept dates formatted in these way YYYY/MM/DD AND YYYY-MM-DD func (d *DateFilter) Parse(s string) bool { if s == "" { *d = "" @@ -40,8 +40,11 @@ func (d *DateFilter) Parse(s string) bool { } date, err := time.Parse("2006/01/02", s) if err != nil { - *d = "" - return false + date, err = time.Parse("2006-01-02", s) + if err != nil { + *d = "" + return false + } } *d = DateFilter(date.Format("2006-01-02")) return true diff --git a/utils/search/torrentParam.go b/utils/search/torrentParam.go index 11be217b..e64ec381 100644 --- a/utils/search/torrentParam.go +++ b/utils/search/torrentParam.go @@ -252,8 +252,9 @@ func (p *TorrentParam) toESQuery(c *gin.Context) *Query { if p.Status != ShowAll { query.Append(p.Status.ToESQuery()) - } else if !p.Locked { - query.Append(fmt.Sprintf("!(status:%d)", 5)) + } + if !p.Locked { + query.Append("!status:5") } @@ -410,7 +411,8 @@ func (p *TorrentParam) toDBQuery(c *gin.Context) *Query { } if p.Status != 0 { query.Append(p.Status.ToDBQuery()) - } else if !p.Locked { + } + if !p.Locked { query.Append("status IS NOT ?", 5) } @@ -452,6 +454,12 @@ func (p *TorrentParam) toDBQuery(c *gin.Context) *Query { querySplit := strings.Fields(p.NameLike) for _, word := range querySplit { + if word[0] == '-' && len(word) > 1 { + //Exclude words starting with - + query.Append("torrent_name NOT "+searchOperator, "%"+word[1:]+"%") + continue + } + firstRune, _ := utf8.DecodeRuneInString(word) if len(word) == 1 && unicode.IsPunct(firstRune) { // some queries have a single punctuation character @@ -525,5 +533,6 @@ func (p *TorrentParam) Clone() TorrentParam { Languages: p.Languages, MinSize: p.MinSize, MaxSize: p.MaxSize, + Locked: p.Locked, } } diff --git a/utils/search/torrentParam_test.go b/utils/search/torrentParam_test.go index b84009a6..b1573abd 100644 --- a/utils/search/torrentParam_test.go +++ b/utils/search/torrentParam_test.go @@ -57,14 +57,14 @@ func TestTorrentParam_ToESQuery(t *testing.T) { Test TorrentParam Expected string }{ - {TorrentParam{}, "!(status:5)"}, - {TorrentParam{NameLike: "lol"}, "!(status:5)"}, - {TorrentParam{NameLike: "lol", FromID: 12}, "!(status:5) id:>12"}, - {TorrentParam{NameLike: "lol", FromID: 12, FromDate: DateFilter("2017-08-01"), ToDate: DateFilter("2017-08-05")}, "!(status:5) id:>12 date: [2017-08-01 2017-08-05]"}, - {TorrentParam{NameLike: "lol", FromID: 12, ToDate: DateFilter("2017-08-05")}, "!(status:5) id:>12 date: [* 2017-08-05]"}, - {TorrentParam{NameLike: "lol", FromID: 12, FromDate: DateFilter("2017-08-01")}, "!(status:5) id:>12 date: [2017-08-01 *]"}, - {TorrentParam{NameLike: "lol", FromID: 12, Category: Categories{&Category{3, 12}}}, "(category: 3 AND sub_category: 12) !(status:5) id:>12"}, - {TorrentParam{NameLike: "lol", FromID: 12, Category: Categories{&Category{3, 12}, &Category{3, 12}}}, "((category: 3 AND sub_category: 12) OR (category: 3 AND sub_category: 12)) !(status:5) id:>12"}, + {TorrentParam{}, "!status:5"}, + {TorrentParam{NameLike: "lol"}, "!status:5"}, + {TorrentParam{NameLike: "lol", FromID: 12}, "!status:5 id:>12"}, + {TorrentParam{NameLike: "lol", FromID: 12, FromDate: DateFilter("2017-08-01"), ToDate: DateFilter("2017-08-05")}, "!status:5 id:>12 date: [2017-08-01 2017-08-05]"}, + {TorrentParam{NameLike: "lol", FromID: 12, ToDate: DateFilter("2017-08-05")}, "!status:5 id:>12 date: [* 2017-08-05]"}, + {TorrentParam{NameLike: "lol", FromID: 12, FromDate: DateFilter("2017-08-01")}, "!status:5 id:>12 date: [2017-08-01 *]"}, + {TorrentParam{NameLike: "lol", FromID: 12, Category: Categories{&Category{3, 12}}}, "(category: 3 AND sub_category: 12) !status:5 id:>12"}, + {TorrentParam{NameLike: "lol", FromID: 12, Category: Categories{&Category{3, 12}, &Category{3, 12}}}, "((category: 3 AND sub_category: 12) OR (category: 3 AND sub_category: 12)) !status:5 id:>12"}, } for _, test := range tests {