Example #1
0
func AdminPlugin(context *GoInk.Context) {
	if context.Method == "POST" {
		action := context.String("action")
		if action == "" {
			Json(context, false).End()
			return
		}
		pln := context.String("plugin")
		if action == "activate" {
			plugin.Activate(pln)
			plugin.Update(context.App())
			Json(context, true).End()
			context.Do("plugin_activated", pln)
			return
		}
		if action == "deactivate" {
			plugin.Deactivate(pln)
			Json(context, true).End()
			context.Do("plugin_deactivated", pln)
			return
		}
		context.Status = 405
		Json(context, false).End()
		return
	}
	context.Layout("admin/admin")
	context.Render("admin/plugin", map[string]interface{}{
		"Title":   "插件",
		"Plugins": plugin.GetPlugins(),
	})
}
Example #2
0
func Rss(ctx *GoInk.Context) {
	baseUrl := model.GetSetting("site_url")
	article, _ := model.GetPublishArticleList(1, 20)
	author := model.GetUsersByRole("ADMIN")[0]

	articleMap := make([]map[string]string, len(article))
	for i, a := range article {
		m := make(map[string]string)
		m["Title"] = a.Title
		m["Link"] = strings.Replace(baseUrl+a.Link(), baseUrl+"/", baseUrl, -1)
		m["Author"] = author.Nick
		str := utils.Markdown2Html(a.Content())
		str = strings.Replace(str, `src="/`, `src="`+strings.TrimSuffix(baseUrl, "/")+"/", -1)
		str = strings.Replace(str, `href="/`, `href="`+strings.TrimSuffix(baseUrl, "/")+"/", -1)
		m["Desc"] = str
		m["Created"] = time.Unix(a.CreateTime, 0).Format(time.RFC822)
		articleMap[i] = m
	}

	ctx.ContentType("application/rss+xml;charset=UTF-8")

	bytes, e := ctx.App().View().Render("rss.xml", map[string]interface{}{
		"Title":    model.GetSetting("site_title"),
		"Link":     baseUrl,
		"Desc":     model.GetSetting("site_description"),
		"Created":  time.Unix(utils.Now(), 0).Format(time.RFC822),
		"Articles": articleMap,
	})
	if e != nil {
		panic(e)
	}
	ctx.Body = bytes
}
Example #3
0
func CmdBackup(context *GoInk.Context) {
	if context.Method == "POST" {
		file, e := cmd.DoBackup(context.App(), true)
		if e != nil {
			Json(context, false).Set("msg", e.Error()).End()
			return
		}
		Json(context, true).Set("file", file).End()
		context.Do("bakcup_success", file)
		model.CreateMessage("backup", "[1]"+file)
		return
	}
	if context.Method == "DELETE" {
		file := context.String("file")
		if file == "" {
			Json(context, false).End()
			return
		}
		cmd.RemoveBackupFile(file)
		Json(context, true).End()
		context.Do("backup_delete", file)
		return
	}
	files, _ := cmd.GetBackupFiles()
	context.Layout("admin/cmd")
	context.Render("admin/cmd/backup", map[string]interface{}{
		"Files": files,
		"Title": "备份",
	})
}
Example #4
0
func SetThemeCache(ctx *GoInk.Context, cache bool) {
	ctx.App().View().NoCache()
	ctx.App().View().IsCache = cache
	if cache {
		model.SetSetting("theme_cache", "true")
	} else {
		model.SetSetting("theme_cache", "false")
	}
	model.SyncSettings()
}
Example #5
0
func CmdLogs(context *GoInk.Context) {
	if context.Method == "DELETE" {
		cmd.RemoveLogFile(context.App(), context.String("file"))
		Json(context, true).End()
		return
	}
	context.Layout("admin/cmd")
	context.Render("admin/cmd/log", map[string]interface{}{
		"Title": "日志",
		"Logs":  cmd.GetLogs(context.App()),
	})
}
Example #6
0
func SiteMap(ctx *GoInk.Context) {
	baseUrl := model.GetSetting("site_url")
	println(baseUrl)
	article, _ := model.GetPublishArticleList(1, 50)
	navigators := model.GetNavigators()
	now := time.Unix(utils.Now(), 0).Format(time.RFC3339)

	articleMap := make([]map[string]string, len(article))
	for i, a := range article {
		m := make(map[string]string)
		m["Link"] = strings.Replace(baseUrl+a.Link(), baseUrl+"/", baseUrl, -1)
		m["Created"] = time.Unix(a.CreateTime, 0).Format(time.RFC3339)
		articleMap[i] = m
	}

	navMap := make([]map[string]string, 0)
	for _, n := range navigators {
		m := make(map[string]string)
		if n.Link == "/" {
			continue
		}
		if strings.HasPrefix(n.Link, "/") {
			m["Link"] = strings.Replace(baseUrl+n.Link, baseUrl+"/", baseUrl, -1)
		} else {
			m["Link"] = n.Link
		}
		m["Created"] = now
		navMap = append(navMap, m)
	}

	ctx.ContentType("text/xml")
	bytes, e := ctx.App().View().Render("sitemap.xml", map[string]interface{}{
		"Title":      model.GetSetting("site_title"),
		"Link":       baseUrl,
		"Created":    now,
		"Articles":   articleMap,
		"Navigators": navMap,
	})
	if e != nil {
		panic(e)
	}
	ctx.Body = bytes

}
Example #7
0
func CmdTheme(ctx *GoInk.Context) {
	if ctx.Method == "POST" {
		change := ctx.String("cache")
		if change != "" {
			cmd.SetThemeCache(ctx, change == "true")
			Json(ctx, true).End()
			return
		}
		theme := ctx.String("theme")
		if theme != "" {
			model.SetSetting("site_theme", theme)
			model.SyncSettings()
			Json(ctx, true).End()
			return
		}
		return
	}
	ctx.Layout("admin/cmd")
	ctx.Render("admin/cmd/theme", map[string]interface{}{
		"Title":        "主题",
		"Themes":       cmd.GetThemes(ctx.App().Get("view_dir")),
		"CurrentTheme": model.GetSetting("site_theme"),
	})
}
Example #8
0
func FileUpload(context *GoInk.Context) {
	var req *http.Request
	req = context.Request
	req.ParseMultipartForm(32 << 20)
	f, h, e := req.FormFile("file")
	if e != nil {
		Json(context, false).Set("msg", e.Error()).End()
		return
	}
	data, _ := ioutil.ReadAll(f)
	maxSize := context.App().Config().Int("app.upload_size")
	defer func() {
		f.Close()
		data = nil
		h = nil
	}()
	if len(data) >= maxSize {
		Json(context, false).Set("msg", "文件应小于10M").End()
		return
	}
	if !strings.Contains(context.App().Config().String("app.upload_files"), path.Ext(h.Filename)) {
		Json(context, false).Set("msg", "文件只支持Office文件,图片和zip存档").End()
		return
	}
	ff := new(model.File)
	ff.Name = h.Filename
	ff.Type = context.StringOr("type", "image")
	ff.Size = int64(len(data))
	ff.ContentType = h.Header["Content-Type"][0]
	ff.Author, _ = strconv.Atoi(context.Cookie("token-user"))
	ff.Url = model.CreateFilePath(context.App().Get("upload_dir"), ff)
	e = ioutil.WriteFile(ff.Url, data, os.ModePerm)
	if e != nil {
		Json(context, false).Set("msg", e.Error()).End()
		return
	}
	model.CreateFile(ff)
	Json(context, true).Set("file", ff).End()
	context.Do("attach_created", ff)
}