wp-go/internal/plugins/posts.go

37 lines
1014 B
Go
Raw Permalink Normal View History

2023-01-12 12:42:16 +00:00
package plugins
import (
"fmt"
"github.com/fthvgb1/wp-go/internal/pkg/models"
2023-01-12 12:42:16 +00:00
"github.com/gin-gonic/gin"
)
func NewPostPlugin(ctx *gin.Context, scene int) *Plugin[models.Posts] {
2023-01-12 12:42:16 +00:00
p := NewPlugin[models.Posts](nil, -1, nil, scene, ctx)
p.Push(Digest)
return p
}
func ApplyPlugin(p *Plugin[models.Posts], post *models.Posts) {
p.post = post
p.Next()
p.index = -1
}
func PasswordProjectTitle(post *models.Posts) {
if post.PostPassword != "" {
post.PostTitle = fmt.Sprintf("密码保护:%s", post.PostTitle)
}
}
func PasswdProjectContent(post *models.Posts) {
if post.PostContent != "" {
format := `
<form action="/login" class="post-password-form" method="post">
<p>此内容受密码保护如需查阅请在下列字段中输入您的密码</p>
<p><label for="pwbox-%d">密码 <input name="post_password" id="pwbox-%d" type="password" size="20"></label> <input type="submit" name="Submit" value="提交"></p>
</form>`
post.PostContent = fmt.Sprintf(format, post.Id, post.Id)
}
}