SkunkyArt/user/gallery.go

72 lines
1.6 KiB
Go

package user
import (
"encoding/json"
"skunkyart/util"
"strconv"
)
func Gallery(name *string, output chan string, page string, folders ...string) {
{
var tmp struct {
Posts, Name, Nav, Folders string
TP int
}
var j struct {
Gruser struct {
Page struct {
Modules []struct {
Name string
ModuleData struct {
FolderDeviations struct {
Username string
TotalPageCount int
Deviations []util.Deviation
}
}
}
}
}
Owner struct {
IsGroup bool
}
}
rawjson := util.Puppy("dauserprofile/init/gallery?username=" + *name + "&page=" + page + "&deviations_limit=50&with_subfolders=false")
err := json.Unmarshal([]byte(rawjson), &j)
util.Err(err)
e := rerror(&rawjson)
if e != "" {
output <- e
}
for _, a := range j.Gruser.Page.Modules {
if a.ModuleData.FolderDeviations.Username != "" {
tmp.Name = a.ModuleData.FolderDeviations.Username
}
if a.ModuleData.FolderDeviations.TotalPageCount != 0 {
tmp.TP = a.ModuleData.FolderDeviations.TotalPageCount
}
for _, a := range a.ModuleData.FolderDeviations.Deviations {
tmp.Posts += util.Images(a, a.Media, false)
}
tmp.Nav = ""
path := "user/"
if j.Owner.IsGroup {
path = "group/"
}
for x := 0; x < tmp.TP; x++ {
tmp.Nav += "<a href=\"" + util.Conf.Base_uri + path + tmp.Name + "?a=gallery&p=" + strconv.Itoa(x+1) + "\">" + strconv.Itoa(x+1) + "</a> "
}
for _, a := range folders {
tmp.Folders = a
}
}
output <- util.TmpExec("templates/user/gallery.htm", &tmp)
}
}