Skip to content

Instantly share code, notes, and snippets.

View rafasashi's full-sized avatar
👍
Happy

Raphaël Dartigues rafasashi

👍
Happy
View GitHub Profile

Share Counts

I have always struggled with getting all the various share buttons from Facebook, Twitter, Google Plus, Pinterest, etc to align correctly and to not look like a tacky explosion of buttons. Seeing a number of sites rolling their own share buttons with counts, for example The Next Web I decided to look into the various APIs on how to simply return the share count.

If you want to roll up all of these into a single jQuery plugin check out Sharrre

Many of these API calls and methods are undocumented, so anticipate that they will change in the future. Also, if you are planning on rolling these out across a site I would recommend creating a simple endpoint that periodically caches results from all of the APIs so that you are not overloading the services will requests.

Twitter

<?php
function custom_strlen($str=''){
$strlen=0;
if(is_string($str)){
if(function_exists('mb_strlen')){
$strlen= mb_strlen($str);
}
else{
$strlen= strlen($str);
function count_char($str='',$char=''){
$count=0;
if(function_exists('mb_substr_count')){
$count=mb_substr_count($str,$char);
}
else{
$count=substr_count($str,$char);
}
return $count;
}
function custom_trim($str,$trim=''){
if($trim==''){
$str=trim($str);
}
if($trim==' '){
$str=preg_replace('/^\p{Z}+|\p{Z}+$/u', '', $str);
}
else{
$str=custom_ltrim($str,$trim);
$str=custom_rtrim($str,$trim);
function custom_substr($content='',$pos_start=0,$num_char=1){
$substr='';
if(function_exists('mb_substr')){
$substr=mb_substr($content,$pos_start,$num_char,CHARSET);
}
else{
$substr=substr($content,$pos_start,$num_char);
}
return $substr;
}
function custom_str_case($string='', $case='lower'){
$lower = array(
"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u",
"v", "w", "x", "y", "z", "à", "á", "â", "ã", "ä", "å", "æ", "ç", "è", "é", "ê", "ë", "ì", "í", "î", "ï",
"ð", "ñ", "ò", "ó", "ô", "õ", "ö", "ø", "ù", "ú", "û", "ü", "ý", "а", "б", "в", "г", "д", "е", "ё", "ж",
"з", "и", "й", "к", "л", "м", "н", "о", "п", "р", "с", "т", "у", "ф", "х", "ц", "ч", "ш", "щ", "ъ", "ы",
"ь", "э", "ю", "я"
);
$upper = array(
function custom_strpos($strpos_in='',$strpos_of=''){
$result=false;
if($strpos_of!=''){
$result=strpos($strpos_in,$strpos_of);
}
return $result;
}
@rafasashi
rafasashi / custom_ftok.php
Created April 27, 2015 09:30
custom ftok function for windows
function custom_ftok($pathname='', $proj=''){
$ftok=false;
if(function_exists('ftok')){
$ftok = ftok($pathname, $proj);
}
else{
function custom_json_decode(&$contents=NULL, $normalize_contents=true, $force_array=true){
//---------------decode contents---------------------
$decoded_contents=NULL;
if(is_string($contents)){
$decoded_contents=json_decode($contents,$force_array);