2023-01-20 10:10:13 +00:00
|
|
|
package plugins
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2023-05-04 12:37:06 +00:00
|
|
|
"github.com/fthvgb1/wp-go/app/wpconfig"
|
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
|
|
|
"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")
|
2023-02-20 17:07:32 +00:00
|
|
|
q.Add("r", strings.ToLower(wpconfig.GetOption("avatar_rating")))
|
2023-01-20 10:10:13 +00:00
|
|
|
u = fmt.Sprintf("%s?%s", u, q.Encode())
|
|
|
|
return
|
|
|
|
}
|