Exemplo n.º 1
0
//删除来源
func (c Copyfrom) Delete(copyfrom *models.Copyfrom) revel.Result {
	var id string = c.Params.Get("id")

	data := make(map[string]string)

	if len(id) > 0 {

		Id, err := strconv.ParseInt(id, 10, 64)
		if err != nil {
			revel.WARN.Println(err)
		}

		if copyfrom.DelByID(Id) {
			data["status"] = "1"
			data["message"] = "删除成功!"
			return c.RenderJson(data)
		} else {
			data["status"] = "0"
			data["message"] = "删除失败!"
			return c.RenderJson(data)
		}

	} else {
		data["status"] = "0"
		data["message"] = "删除失败!"
		return c.RenderJson(data)
	}
}
Exemplo n.º 2
0
func (c Copyfrom) Index(copyfrom *models.Copyfrom) revel.Result {
	title := "来源管理--GoCMS管理系统"

	var page string = c.Params.Get("page")

	//判断是否是系统的分隔符
	separator := "/"
	if os.IsPathSeparator('\\') {
		separator = "\\"
	} else {
		separator = "/"
	}

	config_file := (revel.BasePath + "/conf/config.conf")
	config_file = strings.Replace(config_file, "/", separator, -1)
	config_conf, _ := config.ReadDefault(config_file)

	//前台网站地址
	sitedomain, _ := config_conf.String("website", "website.sitedomain")

	if len(page) > 0 {
		Page, err := strconv.ParseInt(page, 10, 64)
		if err != nil {
			revel.WARN.Println(err)
		}

		copyfrom_list, pages := copyfrom.GetByAll(Page, 10)

		c.Render(title, copyfrom_list, sitedomain, pages)
	} else {
		copyfrom_list, pages := copyfrom.GetByAll(1, 10)

		c.Render(title, copyfrom_list, sitedomain, pages)
	}

	return c.RenderTemplate("Extend/Copyfrom/Index.html")
}
Exemplo n.º 3
0
//编辑内容
func (c Content) Edit(article *models.Article) revel.Result {

	if c.Request.Method == "GET" {
		title := "内容--GoCMS编辑内容"

		var cid string = c.Params.Get("cid")
		var id string = c.Params.Get("id")

		if len(cid) > 0 {

			Cid, err := strconv.ParseInt(cid, 10, 64)
			if err != nil {
				revel.WARN.Println(err)
			}

			Id, err := strconv.ParseInt(id, 10, 64)
			if err != nil {
				revel.WARN.Println(err)
			}

			//内容
			article_info := article.GetById(Id)

			//栏目信息
			category := new(models.Category)
			category_info := category.GetById(Cid)

			//来源
			copyfrom := new(models.Copyfrom)
			copyfrom_list := copyfrom.GetRoleList()

			c.Render(title, cid, category_info, article_info, copyfrom_list)
			return c.RenderTemplate("Content/Manage/Edit.html")
		} else {
			c.Render(title, cid)
			return c.RenderTemplate("Content/Manage/Edit.html")
		}

	} else {

		var dosubmit string = c.Params.Get("dosubmit")
		var dosubmit_continue string = c.Params.Get("dosubmit_continue")

		var cid string = c.Params.Get("cid")
		var id string = c.Params.Get("id")

		Id, err := strconv.ParseInt(id, 10, 64)
		if err != nil {
			revel.WARN.Println(err)
		}

		var title string = c.Params.Get("title")
		if len(title) > 0 {
			article.Title = title
		} else {
			c.Flash.Error("请输入标题!")
			c.Flash.Out["url"] = "/Content/Add/" + cid + "/"
			return c.Redirect("/Message/")
		}

		var style_color string = c.Params.Get("style_color")
		article.Color = style_color
		var style_font_weight string = c.Params.Get("style_font_weight")
		article.Font = style_font_weight

		var thumb string = c.Params.Get("thumb")
		if len(thumb) > 0 {

			//判断是否是系统的分隔符
			separator := "/"
			if os.IsPathSeparator('\\') {
				separator = "\\"
			} else {
				separator = "/"
			}

			config_file := (revel.BasePath + "/conf/config.conf")
			config_file = strings.Replace(config_file, "/", separator, -1)
			config_conf, _ := config.ReadDefault(config_file)

			//前台网站地址
			sitedomain, _ := config_conf.String("website", "website.sitedomain")
			thumb = strings.Replace(thumb, sitedomain, "", -1)

			article.Thumb = thumb
		} else {
			article.Thumb = ""
		}

		var content string = c.Params.Get("content")
		if len(content) > 0 {
			article.Content = content
		} else {
			c.Flash.Error("请输入内容!")
			c.Flash.Out["url"] = "/Content/Add/" + cid + "/"
			return c.Redirect("/Message/")
		}

		var copyfrom string = c.Params.Get("copyfrom")
		if len(copyfrom) > 0 {
			article.Copyfrom = copyfrom
		} else {
			article.Copyfrom = ""
		}

		var keywords string = c.Params.Get("keywords")
		if len(keywords) > 0 {
			article.Keywords = keywords
		} else {
			article.Keywords = ""
		}

		var description string = c.Params.Get("description")
		if len(description) > 0 {
			article.Description = description
		} else {

			//是否截取内容
			var add_introduce string = c.Params.Get("add_introduce")
			if add_introduce == "1" {
				var introcude_length string = c.Params.Get("introcude_length")

				Introcude_length, err := strconv.ParseInt(introcude_length, 10, 64)
				if err != nil {
					revel.WARN.Println(err)
				}

				description = utils.Html2str(content)

				article.Description = utils.Substr(description, Introcude_length)
			} else {
				article.Description = ""
			}

		}

		var relation string = c.Params.Get("relation")
		if len(relation) > 0 {
			article.Relation = relation
		} else {
			article.Relation = ""
		}

		var pagetype string = c.Params.Get("pagetype")
		if len(pagetype) > 0 {

			Pagetype, err := strconv.ParseInt(pagetype, 10, 64)
			if err != nil {
				revel.WARN.Println(err)
			}

			article.Pagetype = Pagetype
		} else {
			article.Pagetype = 0
		}

		var maxcharperpage string = c.Params.Get("maxcharperpage")
		if len(maxcharperpage) > 0 {
			Maxcharperpage, err := strconv.ParseInt(maxcharperpage, 10, 64)
			if err != nil {
				revel.WARN.Println(err)
			}

			article.Maxcharperpage = Maxcharperpage
		} else {
			article.Maxcharperpage = 10000
		}

		var istop string = c.Params.Get("istop")
		if len(istop) > 0 {
			Istop, err := strconv.ParseInt(istop, 10, 64)
			if err != nil {
				revel.WARN.Println(err)
			}

			article.Istop = Istop
		} else {
			article.Istop = 0
		}

		var status string = c.Params.Get("status")
		if len(status) > 0 {
			Status, err := strconv.ParseInt(status, 10, 64)
			if err != nil {
				revel.WARN.Println(err)
			}

			article.Status = Status
		} else {
			article.Status = 1
		}

		var iscomment string = c.Params.Get("iscomment")
		if len(iscomment) > 0 {
			Iscomment, err := strconv.ParseInt(iscomment, 10, 64)
			if err != nil {
				revel.WARN.Println(err)
			}

			article.Iscomment = Iscomment
		} else {
			article.Status = 1
		}

		if article.Edit(Id) {

			if len(dosubmit) > 0 {
				c.Flash.Success("编辑内容成功!")
				c.Flash.Out["url"] = "/Content/list/" + cid + "/"
				return c.Redirect("/Message/")
			} else if len(dosubmit_continue) > 0 {
				c.Flash.Success("编辑内容成功!")
				c.Flash.Out["url"] = "/Content/add/" + cid + "/"
				return c.Redirect("/Message/")
			} else {
				c.Flash.Success("编辑内容成功!")
				c.Flash.Out["url"] = "/Content/list/" + cid + "/"
				return c.Redirect("/Message/")
			}

		} else {
			c.Flash.Error("编辑内容失败")
			c.Flash.Out["url"] = "/Content/edit/" + cid + "/" + id + "/"
			return c.Redirect("/Message/")
		}
	}
}
Exemplo n.º 4
0
//添加来源
func (c Copyfrom) Add(copyfrom *models.Copyfrom) revel.Result {

	if c.Request.Method == "GET" {
		title := "添加来源--GoCMS管理系统"

		c.Render(title)
		return c.RenderTemplate("Extend/Copyfrom/Add.html")
	} else {

		//接收上传文件
		thumb, header, err := c.Request.FormFile("thumb")
		if err != nil {
			//来源logo
			copyfrom.Thumb = ""
		} else {
			defer thumb.Close()

			//判断是否是系统的分隔符
			separator := "/"
			if os.IsPathSeparator('\\') {
				separator = "\\"
			} else {
				separator = "/"
			}

			fileData, _ := ioutil.ReadAll(thumb)

			if len(fileData) >= 1024*1024*2 {
				c.Flash.Error("你上传大小为" + utils.FileSize(len(fileData)) + ",文件应小于2M!")
				c.Flash.Out["url"] = "/Copyfrom/Add/"
				return c.Redirect("/Message/")
			}

			basepath, _ := filepath.Abs("")
			config_file := (revel.BasePath + "/conf/config.conf")
			config_file = strings.Replace(config_file, "/", separator, -1)
			config_conf, _ := config.ReadDefault(config_file)

			//上传文件目录
			upload_dir, _ := config_conf.String("upload", "upload.dir")
			//允许上传的后缀名
			filesuffix, _ := config_conf.String("upload", "upload.filesuffix")

			//文件类型检测
			if !strings.Contains(filesuffix, path.Ext(header.Filename)) {
				c.Flash.Error("文件只支持图片!")
				c.Flash.Out["url"] = "/Copyfrom/Add/"
				return c.Redirect("/Message/")
			}

			//文件保存目录
			web_save_path := fmt.Sprintf("/%s/copyfrom/%s", upload_dir, time.Now().Format("2006/01/02/"))
			save_path := fmt.Sprintf("%s/www/%s/copyfrom/%s", basepath, upload_dir, time.Now().Format("2006/01/02/"))
			//字符串替换 /替换为系统分隔符
			save_path = strings.Replace(save_path, "/", separator, -1)

			//新文件名
			rand.Seed(time.Now().UnixNano())
			rand_num := rand.Intn(99999)
			new_file_name := time.Now().Format("20060102150404") + strconv.Itoa(rand_num) + path.Ext(header.Filename)

			//创建目录
			error := os.MkdirAll(save_path, os.ModePerm)
			if error != nil {
				c.Flash.Error(error.Error())
				c.Flash.Out["url"] = "/Copyfrom/Add/"
				return c.Redirect("/Message/")
			}

			//保存文件
			file_dir := save_path + new_file_name
			save_url := web_save_path + new_file_name

			e := ioutil.WriteFile(file_dir, fileData, os.ModePerm)
			if e != nil {
				c.Flash.Error(e.Error())
				c.Flash.Out["url"] = "/Copyfrom/Add/"
				return c.Redirect("/Message/")
			}

			//来源logo
			copyfrom.Thumb = save_url
		}

		//来源名称
		var sitename string = c.Params.Get("sitename")
		if len(sitename) > 0 {
			copyfrom.Sitename = sitename
		} else {
			c.Flash.Error("请输入来源名称!")
			c.Flash.Out["url"] = "/Copyfrom/Add/"
			return c.Redirect("/Message/")
		}

		//来源链接
		var siteurl string = c.Params.Get("siteurl")
		if len(siteurl) > 0 {
			copyfrom.Siteurl = siteurl
		} else {
			c.Flash.Error("请输入来源链接!")
			c.Flash.Out["url"] = "/Copyfrom/Add/"
			return c.Redirect("/Message/")
		}

		if copyfrom.Save() {

			//******************************************
			//管理员日志
			if UserID, ok := c.Session["UserID"]; ok {
				UserID, err := strconv.ParseInt(UserID, 10, 64)
				if err != nil {
					revel.WARN.Println(err)
				}

				admin := new(models.Admin)
				admin_info := admin.GetById(UserID)

				logs := new(models.Logs)
				desc := "添加来源:" + sitename + "|^|来源管理"
				logs.Save(admin_info, c.Controller, desc)
			}

			//*****************************************

			c.Flash.Success("添加来源成功!")
			c.Flash.Out["url"] = "/Copyfrom/"
			return c.Redirect("/Message/")
		} else {
			c.Flash.Error("添加来源失败")
			c.Flash.Out["url"] = "/Copyfrom/Add/"
			return c.Redirect("/Message/")
		}

	}
}