wp-go/internal/plugins/gravatar.go

32 lines
742 B
Go
Raw Permalink Normal View History

2023-01-20 10:10:13 +00:00
package plugins
import (
"fmt"
2023-01-28 15:12:46 +00:00
"github.com/fthvgb1/wp-go/helper/number"
2023-01-21 11:31:23 +00:00
str "github.com/fthvgb1/wp-go/helper/strings"
2023-01-20 10:10:13 +00:00
"github.com/fthvgb1/wp-go/internal/wpconfig"
"net/url"
"strings"
)
func Gravatar(email string, isTls bool) (u string) {
email = strings.Trim(email, " \t\n\r\000\x0B")
2023-01-28 15:12:46 +00:00
num := number.Rand(0, 2)
2023-01-20 10:10:13 +00:00
h := ""
if email != "" {
2023-01-21 11:31:23 +00:00
h = str.Md5(strings.ToLower(email))
2023-01-20 10:10:13 +00:00
num = int(h[0] % 3)
}
if isTls {
u = fmt.Sprintf("%s%s", "https://secure.gravatar.com/avatar/", h)
} else {
u = fmt.Sprintf("http://%d.gravatar.com/avatar/%s", num, h)
}
q := url.Values{}
q.Add("s", "112")
q.Add("d", "mm")
q.Add("r", strings.ToLower(wpconfig.Options.Value("avatar_rating")))
u = fmt.Sprintf("%s?%s", u, q.Encode())
return
}