MCPcopy Index your code
hub / github.com/writefreely/writefreely / handleViewCollectionLang

Function handleViewCollectionLang

collections.go:1122–1225  ·  view source on GitHub ↗
(app *App, w http.ResponseWriter, r *http.Request)

Source from the content-addressed store, hash-verified

1120}
1121
1122func handleViewCollectionLang(app *App, w http.ResponseWriter, r *http.Request) error {
1123 vars := mux.Vars(r)
1124 lang := vars["lang"]
1125
1126 cr := &collectionReq{}
1127 err := processCollectionRequest(cr, vars, w, r)
1128 if err != nil {
1129 return err
1130 }
1131
1132 u, err := checkUserForCollection(app, cr, r, false)
1133 if err != nil {
1134 return err
1135 }
1136
1137 page := getCollectionPage(vars)
1138
1139 c, err := processCollectionPermissions(app, cr, u, w, r)
1140 if c == nil || err != nil {
1141 return err
1142 }
1143
1144 coll, _ := newDisplayCollection(c, cr, page)
1145 coll.Language = lang
1146 coll.NavSuffix = fmt.Sprintf("/lang:%s", lang)
1147
1148 ttlPosts, err := app.db.GetCollLangTotalPosts(coll.ID, lang)
1149 if err != nil {
1150 log.Error("Unable to getCollLangTotalPosts: %s", err)
1151 }
1152 pagePosts := coll.Format.PostsPerPage()
1153 coll.TotalPages = int(math.Ceil(float64(ttlPosts) / float64(pagePosts)))
1154 if coll.TotalPages > 0 && page > coll.TotalPages {
1155 redirURL := fmt.Sprintf("/lang:%s/page/%d", lang, coll.TotalPages)
1156 if !app.cfg.App.SingleUser {
1157 redirURL = fmt.Sprintf("/%s%s%s", cr.prefix, coll.Alias, redirURL)
1158 }
1159 return impart.HTTPError{http.StatusFound, redirURL}
1160 }
1161
1162 coll.Posts, _ = app.db.GetLangPosts(app.cfg, c, lang, page, cr.isCollOwner)
1163 if err != nil {
1164 return ErrCollectionPageNotFound
1165 }
1166
1167 // Serve collection
1168 displayPage := struct {
1169 CollectionPage
1170 Tag string
1171 }{
1172 CollectionPage: CollectionPage{
1173 DisplayCollection: coll,
1174 StaticPage: pageForReq(app, r),
1175 IsCustomDomain: cr.isCustomDomain,
1176 },
1177 Tag: lang,
1178 }
1179 var owner *User

Callers

nothing calls this directly

Calls 14

IsSilencedMethod · 0.95
processCollectionRequestFunction · 0.85
checkUserForCollectionFunction · 0.85
getCollectionPageFunction · 0.85
newDisplayCollectionFunction · 0.85
pageForReqFunction · 0.85
GetCollLangTotalPostsMethod · 0.80
PostsPerPageMethod · 0.80
GetLangPostsMethod · 0.80

Tested by

no test coverage detected