Skip to content

Instantly share code, notes, and snippets.

Avatar

Chris G. swchris

View GitHub Profile
@swchris
swchris / get_social_avatar.php
Last active Sep 27, 2016 — forked from jcsrb/gist:1081548
PHP function (conversion of @jcsrb Javascript function at https://gist.github.com/jcsrb/1081548) to output URL for social icons from google, facebook, gravatar, twitter, tumblr and instagram)
View get_social_avatar.php
<?
function get_avatar_from_service($service, $userid, $size) {
// Based on original Javascript function at https://gist.github.com/jcsrb/1081548
// this return the url that redirects to the according user image/avatar/profile picture
// implemented services: google profiles, facebook, gravatar, twitter, tumblr, default fallback
// for google use get_avatar_from_service('google', profile-name or user-id , size-in-px )
// for facebook use get_avatar_from_service('facebook', vanity url or user-id , size-in-px or size-as-word )
// for gravatar use get_avatar_from_service('gravatar', md5 hash email@adress, size-in-px )
// for twitter (via avatars.io) use get_avatar_from_service('twitter', username, default )
// for tumblr use get_avatar_from_service('tumblr', blog-url, size-in-px )
View extensions.conf
exten => _X.,1,Set(CURL_RESULT=${CURL(http://domain.com/test.txt)})
same => n,GotoIf($["${CURL_RESULT}" = "1"]?result1:result2)
same => n(result1),Verbose(Result 1)
same => n,Hangup
same => n(result2),Verbose(Result other)
same => n,Hangup
View extensions.conf
exten => _X.,1,Set(CURL_RESULT=${CURL(http://domain.com/test.json)})
same => n,Set(result=${JSONELEMENT(CURL_RESULT,result/subfield)})
same => n,GotoIf($["${result}" = "1"]?result1:result2)
same => n(result1),Verbose(Result 1)
View test.json
{
"result": {
"subfield": 1
}
}