Plugin Directory

Changeset 1380986


Ignore:
Timestamp:
03/29/2016 11:56:57 AM (10 years ago)
Author:
mortay
Message:
  • Reduced requests timeout to 1 second.
  • Various modifications.
Location:
social-counters/trunk
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • social-counters/trunk/counters/bitacoras.php

    r417895 r1380986  
    44
    55function social_counter__defaults__bitacoras( $defaults = array() ) {
    6    
     6
    77    $key = social_counter__bitacoras_key();
    88    if ( !empty($key) )
    99        $defaults[] = 'bitacoras';
    10    
     10
    1111    return $defaults;
    1212}
     
    1616function social_counters__admin_list__bitacoras( $codeExit = '', $postparam = false ) {
    1717    global $post;
    18    
     18
    1919    $_post = ( $postparam ) ? $postparam : $post;
    20    
     20
    2121    $key = social_counter__bitacoras_key();
    2222    if ( $_post && !empty($key) ) {
    2323        return $codeExit . '<div class="misc-pub-section">Bitacoras: ' . social_counter__get('bitacoras', $_post, false) . '</div>';
    2424    }
    25    
     25
    2626    return $codeExit;
    2727
     
    3232function social_counter__get__bitacoras( $codeExit = '', $postparam = false, $linked = true ) {
    3333    global $post;
    34    
     34
    3535    $_post = ( $postparam ) ? $postparam : $post;
    36    
     36
    3737    $shared_counter = 0;
    38    
     38
    3939    $key = social_counter__bitacoras_key();
    4040    if ( $_post && !empty($key) ) {
    41        
     41
    4242        $share_counter_meta = get_post_meta($_post->ID, '_shared_counter_bitacoras_v2', true);
    43        
    44         if ( !is_single() && $share_counter_meta !== false ) {
    45            
     43
     44        if ( !is_single() && !empty($share_counter_meta) && $share_counter_meta !== false ) {
     45
    4646            $shared_counter = $share_counter_meta;
    47            
     47
    4848        }else{
    49            
     49
    5050            if ( function_exists('json_decode') ) {
    5151                $post_url = apply_filters('social_counters_post_url_bitacoras', get_permalink($_post->ID), $_post);
    5252                $post_url = urlencode($post_url);
    53                
     53
    5454                $url_request = 'http://api.bitacoras.com/anotacion/key/'. social_counter__bitacoras_key() .'/format/'. 'json' .'/url/{url}/';
    5555                $url_request = str_replace('{url}', $post_url, $url_request);
    56                
    57                 $data = wp_remote_retrieve_body(wp_remote_get($url_request));
    58                
     56
     57                $data = wp_remote_retrieve_body(wp_remote_get($url_request, array('timeout' => 1,)));
     58
    5959                if ( !empty($data) ) {
    6060                    $data = json_decode($data);
    61                    
     61
    6262                    if ( $data->status == 'success' ) {
    6363                        $shared_counter = $data->data->votos;
     
    6565                }
    6666            }
    67            
     67
    6868            update_post_meta($_post->ID, '_shared_counter_bitacoras_v2', $shared_counter);
    69            
     69
    7070        }
    7171    }
    72    
     72
    7373    $shared_counter = ( empty($shared_counter) ) ? 0 : $shared_counter;
    74    
     74
    7575    $shared_counter = '<span>'.$shared_counter.'</span>';
    7676    $shared_classes = 'social-counter social-counter-'. __('lang-dir', 'social-counters') .'-bitacoras';
     
    8181        $shared_counter = '<span class="'. $shared_classes .'">'.$shared_counter.'</span>';
    8282    }
    83    
     83
    8484    return $codeExit . $shared_counter;
    8585}
     
    8989function social_counters__share_url__bitacoras( $postparam = false ) {
    9090    global $post;
    91    
     91
    9292    $_post = ( $postparam ) ? $postparam : $post;
    93    
     93
    9494    $key = social_counter__bitacoras_key();
    9595    if ( $_post && !empty($key) ) {
    96        
     96
    9797        $post_title = urlencode( apply_filters('social_counters__the_title', get_the_title($_post->ID)) );
    9898        $url_string = urlencode( apply_filters('social_counters_share_url_bitacoras', get_permalink($_post->ID), $_post) );
    99        
     99
    100100        $bitacoras_url = 'http://bitacoras.com/anotaciones/' . $url_string . '/';
    101        
     101
    102102        return $bitacoras_url;
    103103    }
    104    
     104
    105105    return "#ERROR";
    106106}
     
    109109function social_counter__bitacoras_key() {
    110110    $bitacoras_key = '';
    111    
     111
    112112    if ( defined('SOCIAL_COUNTER__BITACORAS_KEY') )
    113113        $bitacoras_key = SOCIAL_COUNTER__BITACORAS_KEY;
    114    
     114
    115115    return $bitacoras_key;
    116116}
  • social-counters/trunk/counters/facebook.php

    r532303 r1380986  
    1212function social_counters__admin_list__facebook( $codeExit = '', $postparam = false ) {
    1313    global $post;
    14    
     14
    1515    $_post = ( $postparam ) ? $postparam : $post;
    16    
     16
    1717    if ( $_post ) {
    1818        return $codeExit . '<div class="misc-pub-section">Facebook: ' . social_counter__get('facebook', $_post, false) . '</div>';
    1919    }
    20    
     20
    2121    return $codeExit;
    2222
     
    2727function social_counter__get__facebook( $codeExit = '', $postparam = false, $linked = true ) {
    2828    global $post;
    29    
     29
    3030    $_post = ( $postparam ) ? $postparam : $post;
    31    
     31
    3232    $shared_counter = 0;
    33    
     33
    3434    if ( $_post ) {
    35        
     35
    3636        $share_counter_meta = get_post_meta($_post->ID, '_shared_counter_facebook_v2', true);
    37        
    38         if ( !is_single() && $share_counter_meta !== false ) {
    39            
     37
     38        if ( !is_single() && !empty($share_counter_meta) && $share_counter_meta !== false ) {
     39
    4040            $shared_counter = $share_counter_meta;
    41            
     41
    4242        }else{
    43            
     43
    4444            if ( function_exists('json_decode') ) {
    4545                $post_url = apply_filters('social_counters_post_url_facebook', get_permalink($_post->ID), $_post);
    46                 $post_url = urlencode($post_url);
    47                
     46
    4847                //$url_request = 'http://api.facebook.com/restserver.php?format=json&method=links.getStats&urls={url}';
    49                 $url_request = 'http://graph.facebook.com/?id={url}';
    50                 $url_request = str_replace('{url}', $post_url, $url_request);
    51                
    52                 $data = wp_remote_retrieve_body(wp_remote_get($url_request));
    53                
     48                $url_request = 'http://graph.facebook.com/';
     49                    $url_request = add_query_arg('id', $post_url, $url_request);
     50
     51                $data = wp_remote_retrieve_body(wp_remote_get($url_request, array('timeout' => 1,)));
     52
    5453                if ( !empty($data) ) {
    5554                    $data = json_decode($data);
     
    5857                }
    5958            }
    60            
     59
    6160            if ( $share_counter_meta )
    6261                $shared_counter = ( is_numeric($shared_counter) && $shared_counter >= $share_counter_meta ) ? $shared_counter : $share_counter_meta;
    63            
     62
    6463            update_post_meta($_post->ID, '_shared_counter_facebook_v2', $shared_counter);
    65            
     64
    6665        }
    6766    }
    68    
     67
    6968    $shared_counter = ( empty($shared_counter) ) ? 0 : $shared_counter;
    70    
     69
    7170    $shared_counter = '<span>'.$shared_counter.'</span>';
    7271    $shared_classes = 'social-counter social-counter-'. __('lang-dir', 'social-counters') .'-facebook';
     
    7776        $shared_counter = '<span class="'. $shared_classes .'">'.$shared_counter.'</span>';
    7877    }
    79    
     78
    8079    return $codeExit . $shared_counter;
    8180}
     
    8584function social_counters__share_url__facebook( $postparam = false ) {
    8685    global $post;
    87    
     86
    8887    $_post = ( $postparam ) ? $postparam : $post;
    89    
     88
    9089    if ( $_post ) {
    91        
     90
    9291        $post_title = urlencode( apply_filters('social_counters__the_title', get_the_title($_post->ID)) );
    9392        $url_string = urlencode( apply_filters('social_counters_share_url_facebook', get_permalink($_post->ID), $_post) );
    94        
     93
    9594        $facebook_url = 'http://www.facebook.com/sharer.php?u=' . $url_string . '&amp;t=' . $post_title .'';
    96        
     95
    9796        return $facebook_url;
    9897    }
    99    
     98
    10099    return "#ERROR";
    101100}
  • social-counters/trunk/counters/google-buzz.php

    r532303 r1380986  
    1212function social_counters__admin_list__gbuzz( $codeExit = '', $postparam = false ) {
    1313    global $post;
    14    
     14
    1515    $_post = ( $postparam ) ? $postparam : $post;
    16    
     16
    1717    if ( $_post ) {
    1818        return $codeExit . '<div class="misc-pub-section">Google Buzz: ' . social_counter__get('gbuzz', $_post, false) . '</div>';
    1919    }
    20    
     20
    2121    return $codeExit;
    2222
     
    2727function social_counters__get__gbuzz( $codeExit = '', $postparam = false, $linked = true ) {
    2828    global $post;
    29    
     29
    3030    $_post = ( $postparam ) ? $postparam : $post;
    31    
     31
    3232    $shared_counter = 0;
    33    
     33
    3434    if ( $_post ) {
    35        
     35
    3636        $share_counter_meta = get_post_meta($_post->ID, '_shared_counter_gbuzz_v2', true);
    37        
    38         if ( !is_single() && $share_counter_meta !== false ) {
    39            
     37
     38        if ( !is_single() && !empty($share_counter_meta) && $share_counter_meta !== false ) {
     39
    4040            $shared_counter = $share_counter_meta;
    41            
     41
    4242        }else{
    43            
     43
    4444            $post_url = apply_filters('social_counters_post_url_gbuzz', get_permalink($_post->ID), $_post);
    4545            $post_url = urlencode($post_url);
    46            
     46
    4747            $url_request = 'http://www.google.com/buzz/api/buzzThis/buzzCounter?url={url}';
    4848            $url_request = str_replace('{url}', $post_url, $url_request);
    49            
    50             $data = trim(wp_remote_retrieve_body(wp_remote_get($url_request)));
    51            
     49
     50            $data = trim(wp_remote_retrieve_body(wp_remote_get($url_request, array('timeout' => 1,))));
     51
    5252            if ( !empty($data) ) {
    5353                $data = str_replace('google_buzz_set_count({"http://', '', $data);
    5454                $data = str_replace('});', '', $data);
    5555                $data = explode(":", $data);
    56                
     56
    5757                $shared_counter = trim($data[1]);
    5858            }
    59            
     59
    6060            if ( $share_counter_meta )
    6161                $shared_counter = ( is_numeric($shared_counter) && $shared_counter >= $share_counter_meta ) ? $shared_counter : $share_counter_meta;
    62            
     62
    6363            update_post_meta($_post->ID, '_shared_counter_gbuzz_v2', $shared_counter);
    64            
     64
    6565        }
    6666    }
    67    
     67
    6868    $shared_counter = ( empty($shared_counter) ) ? 0 : $shared_counter;
    69    
     69
    7070    $shared_counter = '<span>'.$shared_counter.'</span>';
    7171    $shared_classes = 'social-counter social-counter-'. __('lang-dir', 'social-counters') .'-gbuzz';
     
    7676        $shared_counter = '<span class="'. $shared_classes .'">'.$shared_counter.'</span>';
    7777    }
    78    
     78
    7979    return $codeExit . $shared_counter;
    8080}
     
    8484function social_counters__share_url__gbuzz( $postparam = false ) {
    8585    global $post;
    86    
     86
    8787    $_post = ( $postparam ) ? $postparam : $post;
    88    
     88
    8989    if ( $_post ) {
    90        
     90
    9191        $post_title = urlencode( apply_filters('social_counters__the_title', get_the_title($_post->ID)) );
    9292        $post_url = urlencode( apply_filters('social_counters_share_url_gbuzz', get_permalink($_post->ID), $_post) );
    93        
    94         $buzz_url = 'http://www.google.com/buzz/post?url='. $post_url .'';
    95        
     93
     94        $buzz_url = 'http://www.google.com/buzz/post';
     95            $buzz_url = add_query_arg('url', $post_url, $buzz_url);
     96
    9697        return $buzz_url;
    9798    }
    98    
     99
    99100    return "#ERROR";
    100101}
  • social-counters/trunk/counters/linkedin.php

    r532303 r1380986  
    3636        $share_counter_meta = get_post_meta($_post->ID, '_shared_counter_linkedin_v2', true);
    3737       
    38         if ( !is_single() && $share_counter_meta !== false ) {
     38        if ( !is_single() && !empty($share_counter_meta) && $share_counter_meta !== false ) {
    3939           
    4040            $shared_counter = $share_counter_meta;
     
    107107        $url_request .= $url_request_params;
    108108       
    109         $data = wp_remote_retrieve_body(wp_remote_get($url_request));
     109        $data = wp_remote_retrieve_body(wp_remote_get($url_request, array('timeout' => 1,)));
    110110       
    111111        $url_request_params = '';
  • social-counters/trunk/counters/meneame.php

    r532303 r1380986  
    1212function social_counters__admin_list__meneame( $codeExit = '', $postparam = false ) {
    1313    global $post;
    14    
     14
    1515    $_post = ( $postparam ) ? $postparam : $post;
    16    
     16
    1717    if ( $_post ) {
    1818        return $codeExit . '<div class="misc-pub-section">Meneame: ' . social_counter__get('meneame', $_post, false) . '</div>';
    1919    }
    20    
     20
    2121    return $codeExit;
    2222
     
    2727function social_counter__get__meneame( $codeExit = '', $postparam = false, $linked = true ) {
    2828    global $post;
    29    
     29
    3030    $_post = ( $postparam ) ? $postparam : $post;
    31    
     31
    3232    $shared_counter = 0;
    33    
     33
    3434    if ( $_post ) {
    35        
     35
    3636        $share_counter_meta = get_post_meta($_post->ID, '_shared_counter_meneame_v2', true);
    37        
    38         if ( !is_single() && $share_counter_meta !== false ) {
    39            
     37
     38        if ( !is_single() && !empty($share_counter_meta) && $share_counter_meta !== false ) {
     39
    4040            $shared_counter = $share_counter_meta;
    41            
     41
    4242        }else{
    43            
     43
    4444            $post_url = apply_filters('social_counters_post_url_meneame', get_permalink($_post->ID), $_post);
    4545            $post_url = $post_url; //urlencode($post_url);
    46            
     46
    4747            $url_request = 'http://meneame.net/api/url.php?all=1&url={url}';
    4848            $url_request = str_replace('{url}', $post_url, $url_request);
    49            
    50             $data = trim(wp_remote_retrieve_body(wp_remote_get($url_request)));
    51            
     49
     50            $data = trim(wp_remote_retrieve_body(wp_remote_get($url_request, array('timeout' => 1,))));
     51
    5252            if ( !empty($data) ) {
    5353                $data_lines = explode("\n", trim($data));
    54                
     54
    5555                if ( sizeof($data_lines) >= 1 ) {
    56                    
     56
    5757                    foreach ( $data_lines as $data_line ) {
    5858                        $line = explode(" ", trim($data_line));
     
    6161                        }
    6262                    }
    63                    
     63
    6464                }
    6565            }
    66            
     66
    6767            if ( $share_counter_meta )
    6868                $shared_counter = ( is_numeric($shared_counter) && $shared_counter >= $share_counter_meta ) ? $shared_counter : $share_counter_meta;
    69            
     69
    7070            update_post_meta($_post->ID, '_shared_counter_meneame_v2', $shared_counter);
    71            
     71
    7272        }
    7373    }
    74    
     74
    7575    $shared_counter = ( empty($shared_counter) ) ? 0 : $shared_counter;
    76    
     76
    7777    $shared_counter = '<span>'.$shared_counter.'</span>';
    7878    $shared_classes = 'social-counter social-counter-'. __('lang-dir', 'social-counters') .'-meneame';
     
    8383        $shared_counter = '<span class="'. $shared_classes .'">'.$shared_counter.'</span>';
    8484    }
    85    
     85
    8686    return $codeExit . $shared_counter;
    8787}
     
    9191function social_counters__share_url__meneame( $postparam = false ) {
    9292    global $post;
    93    
     93
    9494    $_post = ( $postparam ) ? $postparam : $post;
    95    
     95
    9696    if ( $_post ) {
    9797        $post_title = urlencode( apply_filters('social_counters__the_title', get_the_title($_post->ID)) );
    9898        $url_string = urlencode( apply_filters('social_counters_share_url_meneame', get_permalink($_post->ID), $_post) );
    99        
     99
    100100        $meneame_url = 'http://meneame.net/submit.php?url=' . $url_string . '&amp;title=' . $post_title .'';
    101        
     101
    102102        return $meneame_url;
    103103    }
    104    
     104
    105105    return "#ERROR";
    106106}
     
    108108function social_counters__vote_url__meneame( $postparam = false ) {
    109109    global $post;
    110    
     110
    111111    $_post = ( $postparam ) ? $postparam : $post;
    112    
     112
    113113    $share_vote_url = '#';
    114    
     114
    115115    if ( $_post ) {
    116        
     116
    117117        $share_vote_url_meta = get_post_meta($_post->ID, '_shared_vote_url_meneame', true);
    118        
     118
    119119        if ( !is_single() && $share_vote_url_meta ) {
    120            
     120
    121121            $share_vote_url = $share_vote_url_meta;
    122            
     122
    123123        }else{
    124            
     124
    125125            $post_url = apply_filters('social_counters_post_url_meneame', get_permalink($_post->ID), $_post);
    126126            $post_url = $post_url; //urlencode($post_url);
    127            
     127
    128128            $url_request = 'http://meneame.net/api/url.php?url={url}';
    129129            $url_request = str_replace('{url}', $post_url, $url_request);
    130            
    131             $data = trim(wp_remote_retrieve_body(wp_remote_get($url_request)));
    132            
     130
     131            $data = trim(wp_remote_retrieve_body(wp_remote_get($url_request, array('timeout' => 1,))));
     132
    133133            if ( !empty($data) ) {
    134134                $data_lines = explode("\n", trim($data));
    135                
     135
    136136                if ( sizeof($data_lines) >= 1 ) {
    137                    
     137
    138138                    foreach ( $data_lines as $data_line ) {
    139139                        $line = explode(" ", trim($data_line));
     
    143143                        }
    144144                    }
    145                    
     145
    146146                }
    147147            }
    148            
     148
    149149            update_post_meta($_post->ID, '_shared_vote_url_meneame', $share_vote_url);
    150            
     150
    151151        }
    152        
     152
    153153        return $share_vote_url;
    154154    }
    155    
     155
    156156    return "#ERROR";
    157157}
  • social-counters/trunk/counters/tuenti.php

    r391639 r1380986  
    1212function social_counters__admin_list__tuenti( $codeExit = '', $postparam = false ) {
    1313    global $post;
    14    
     14
    1515    $_post = ( $postparam ) ? $postparam : $post;
    16    
     16
    1717    if ( $_post ) {
    1818        return $codeExit . '<div class="misc-pub-section">Tuenti: ' . social_counter__get('tuenti', $_post, false) . '</div>';
    1919    }
    20    
     20
    2121    return $codeExit;
    2222
     
    2727function social_counter__get__tuenti( $codeExit = '', $postparam = false, $linked = true ) {
    2828    global $post;
    29    
     29
    3030    $_post = ( $postparam ) ? $postparam : $post;
    31    
     31
    3232    $shared_counter = ''; // <span>'.$shared_counter.'</span>';
    3333    $shared_classes = 'social-counter social-counter-'. __('lang-dir', 'social-counters') .'-tuenti';
     
    3838        $shared_counter = '<span class="'. $shared_classes .'">'.$shared_counter.'</span>';
    3939    }
    40    
     40
    4141    return $codeExit . $shared_counter;
    4242}
     
    4646function social_counters__share_url__tuenti( $postparam = false ) {
    4747    global $post;
    48    
     48
    4949    $_post = ( $postparam ) ? $postparam : $post;
    50    
     50
    5151    if ( $_post ) {
    52        
     52
    5353        $url_string = apply_filters('social_counters_share_url_tuenti', get_permalink($_post->ID), $_post);
    54        
     54
    5555        $post_title = apply_filters('social_counters__the_title', get_the_title($_post->ID));
    5656        $post_title = substr($post_title, 0, 140 - ( 3 + ( strlen($pre_string) + strlen($url_string) + strlen($login_string) ) ));
    57        
    58         $service_url = 'http://www.tuenti.com/share?url=' . urlencode($url_string);
    59        
     57
     58        $service_url = 'http://www.tuenti.com/share';
     59            $service_url = add_query_arg('url', $url_string, $service_url);
     60
    6061        return $service_url;
    6162    }
    62    
     63
    6364    return "#ERROR";
    6465}
  • social-counters/trunk/counters/twitter.php

    r532303 r1380986  
    1212function social_counters__admin_list__twitter( $codeExit = '', $postparam = false ) {
    1313    global $post;
    14    
     14
    1515    $_post = ( $postparam ) ? $postparam : $post;
    16    
     16
    1717    if ( $_post ) {
    1818        return $codeExit . '<div class="misc-pub-section">Twitter: ' . social_counter__get('twitter', $_post, false) . '</div>';
    1919    }
    20    
     20
    2121    return $codeExit;
    2222
     
    2727function social_counter__get__twitter( $codeExit = '', $postparam = false, $linked = true ) {
    2828    global $post;
    29    
     29
    3030    $_post = ( $postparam ) ? $postparam : $post;
    31    
     31
    3232    $shared_counter = 0;
    33    
     33
    3434    if ( $_post ) {
    35        
     35
    3636        $share_counter_meta = get_post_meta($_post->ID, '_shared_counter_twitter_v2', true);
    37        
    38         if ( !is_single() && $share_counter_meta !== false ) {
    39            
     37
     38        if ( !is_single() && !empty($share_counter_meta) && $share_counter_meta !== false ) {
     39
    4040            $shared_counter = $share_counter_meta;
    41            
     41
    4242        }else{
    43            
     43
    4444            $post_url = apply_filters('social_counters_post_url_twitter', get_permalink($_post->ID), $_post);
    4545            $post_url = urlencode($post_url);
    46            
     46
    4747            // Search in TWEETMEME
    4848            // $shared_counter = social_counters__twitter__tweetmeme($post_url, $shared_counter);
    4949            // Search in TWITTER
    5050            $shared_counter = social_counters__twitter__twitter($post_url, $shared_counter);
    51            
     51
    5252            if ( $share_counter_meta ) {
    5353                $shared_counter = ( is_numeric($shared_counter) && $shared_counter >= $share_counter_meta ) ? $shared_counter : $share_counter_meta;
    5454            }
    55            
     55
    5656            update_post_meta($_post->ID, '_shared_counter_twitter_v2', $shared_counter);
    5757        }
    5858    }
    59            
     59
    6060    $shared_counter = ( empty($shared_counter) ) ? 0 : $shared_counter;
    61    
     61
    6262    $shared_counter = '<span>'.$shared_counter.'</span>';
    6363    $shared_classes = 'social-counter social-counter-'. __('lang-dir', 'social-counters') .'-twitter';
     
    6868        $shared_counter = '<span class="'. $shared_classes .'">'.$shared_counter.'</span>';
    6969    }
    70    
     70
    7171    return $codeExit . $shared_counter;
    7272}
     
    7676function social_counters__share_url__twitter( $postparam = false ) {
    7777    global $post;
    78    
     78
    7979    $_post = ( $postparam ) ? $postparam : $post;
    80    
     80
    8181    if ( $_post ) {
    82        
     82
    8383        $pre_string = 'RT';
    8484        $login_string = '@'. social_counters__twitter_user() .'';
    8585        $url_string = apply_filters('social_counters_share_url_twitter', get_permalink($_post->ID), $_post);
    86        
     86
    8787        $post_title = apply_filters('social_counters__the_title', get_the_title($_post->ID));
    8888        $post_title = substr($post_title, 0, 140 - ( 3 + ( strlen($pre_string) + strlen($url_string) + strlen($login_string) ) ));
    89        
    90         $twitter_url = 'http://twitter.com/intent/tweet?text=' . urlencode($pre_string . ' ' . $login_string . ' ' . $post_title . ' ' .$url_string);
    91        
     89
     90        $twitter_url = 'http://twitter.com/intent/tweet';
     91            $twitter_url = add_query_arg('text', $pre_string . ' ' . $login_string . ' ' . $post_title . ' ' .$url_string, $twitter_url);
     92
    9293        return $twitter_url;
    9394    }
    94    
     95
    9596    return "#ERROR";
    9697}
     
    99100function social_counters__twitter_user() {
    100101    $twitter_user = '';
    101    
     102
    102103    if ( defined('SOCIAL_COUNTER__TWITTER_USER') )
    103104        $twitter_user = SOCIAL_COUNTER__TWITTER_USER;
    104        
     105
    105106    if ( empty($twitter_user) && defined('SOCIAL_COUNTER_TWITTER_USER') )
    106107        $twitter_user = SOCIAL_COUNTER_TWITTER_USER;
    107    
     108
    108109    return $twitter_user;
    109110}
     
    121122
    122123function social_counters__twitter__tweetmeme( $post_url = '', $shared_counter = 0 ) {
    123    
     124
    124125    if ( !empty($post_url) ) {
    125        
     126
    126127        $url_request_params = '?url={url}';
    127128        $url_request_params = str_replace('{url}', $post_url, $url_request_params);
    128        
     129
    129130        $url_request = 'http://api.tweetmeme.com/url_info.php';
    130131        $url_request .= $url_request_params;
    131        
    132         $data = wp_remote_retrieve_body(wp_remote_get($url_request));
    133        
     132
     133        $data = wp_remote_retrieve_body(wp_remote_get($url_request, array('timeout' => 1)));
     134
    134135        $url_request_params = '';
    135136        if ( !empty($data) ) {
    136137            $data = unserialize($data);
    137                
     138
    138139            if ( isset($data['status']) && $data['status'] == 'failure' ) {
    139140                $shared_counter = '<em title="'. $data['comment'] .'">0</em>';
     
    142143            }
    143144        }
    144        
     145
    145146    }
    146    
     147
    147148    return $shared_counter;
    148149}
    149150
    150151function social_counters__twitter__twitter( $post_url = '', $shared_counter = 0 ) {
    151    
     152
    152153    if ( !empty($post_url) ) {
    153        
     154
    154155        $url_request_params = '?url={url}';
    155156        $url_request_params = str_replace('{url}', $post_url, $url_request_params);
    156        
     157
    157158        $url_request = 'http://urls.api.twitter.com/1/urls/count.json';
    158159        $url_request .= $url_request_params;
    159        
    160         $data = wp_remote_retrieve_body(wp_remote_get($url_request));
    161        
     160
     161        $data = wp_remote_retrieve_body(wp_remote_get($url_request, array('timeout' => 1,)));
     162
    162163        $url_request_params = '';
    163164        if ( !empty($data) && function_exists('json_decode') ) {
    164165            $data = json_decode($data);
    165                
     166
    166167            if ( isset($data->count) && $data->count > $shared_counter )
    167168                $shared_counter = $data->count;
    168169        }
    169        
     170
    170171    }
    171    
     172
    172173    return $shared_counter;
    173174}
  • social-counters/trunk/readme.txt

    r532303 r1380986  
    33Tags: social, social bookmarking, counter, twitter, facebook, google, meneame, tuenti, bitacoras.com
    44Requires at least: 2.9
    5 Tested up to: 3.3.1
    6 Stable tag: 2.2.8
     5Tested up to: 4.4.1
     6Stable tag: 2.2.9
    77
    88It allows to place social sharing links with counters (if available) to the most popular social networks: Menéame,Twitter,Facebook,...
     
    5151
    5252== Changelog ==
     53
     54= 2.2.9 =
     55* Reduced requests timeout to 1 second.
     56* Various modifications.
    5357
    5458= 2.2.8 =
  • social-counters/trunk/social-counters.php

    r532303 r1380986  
    44Plugin URI: http://blogestudio.com/plugin/social-counters/
    55Description:  Get Counters from Social Webs
    6 Version: 2.2.8
     6Version: 2.2.9
    77Author: Alejandro Carravedo (Blogestudio)
    88Author URI: http://blogestudio.com
     
    11111.1.0   - Solucionado error con la cache de contador
    1212        - Solucionado error de conexion con Meneame.
    13        
     13
    14141.2.0   - Cambiado sistema de cuento de Twitter por Tweetmeme, el primero obvia todo lo que no sea la URL concreta. (15.06.2010)
    1515        - Anyadida funcion "social_counter__twitter__login_string" para cambiar el usuario de ReTweet.
    16        
     16
    17172.0.0   - Reprogramacion del plugin para funcionar por filtros y acciones, por ahora.
    1818        - ToDo: Funcionamiento por clases!!
     
    22222.1.0   - Anadido parametro para enviar el objecto POST a las funciones "the_" (postparam).
    2323        - Cambiado sistema de "share" en Twitter
    24        
     24
    25252.1.1   - Cambiado sistema de contador en Twitter, ahora se usa el propio Twitter, no TweetMeMe
    2626        - Reparado contador de Facebook, ahora funciona con el Graph API, han quitado de sopetón los datos del REST API.
    27        
     27
    28282.2.0   - Anadido el contador de "Bitacoras"
    2929        - Anadido el contador de "LinkedIn"
     
    38382.2.4   - Solucionado error con las URLs internas del plugin y el Domain Mapping
    3939        - Solucionado error con WPML y orden de carga del idioma.
    40        
     40
    41412.2.5   - Cambio de version en el README!!
    4242
     
    4646
    47472.2.8   - Cambio en el sistema de caché para acelerar la carga de las páginas.
    48        
     48
     492.2.9   - Reducidos los timeouts de las solicitudes a "1".
     50
    4951*** Configuraciones ***
    5052SOCIAL_COUNTER__LOAD_CSS : Ponerlo a FALSE para que no cargue el estilo por defecto.
     
    100102/* CSS Load */
    101103function social_counters__init() {
    102    
     104
    103105    // Cargamos los idiomas
    104106    load_plugin_textdomain('social-counters', '', dirname( plugin_basename( __FILE__ ) ) .'/langs/');
    105    
     107
    106108    if ( SOCIAL_COUNTER__LOAD_CSS )
    107109        wp_enqueue_style( 'social-counters', social_counters__url() .'css/social-counters.css', array(), '2.2.3', 'screen');
    108    
     110
    109111}
    110112add_action('init', 'social_counters__init');
     
    124126
    125127function the_social_counters__get( $social_counters = array(), $postparam = false ) {
    126    
     128
    127129    $default_social_counters = apply_filters('social_counter__defaults', array());
    128    
    129    
     130
     131
    130132    $social_counters = ( sizeof($social_counters) > 0 ) ? $social_counters : $default_social_counters;
    131    
     133
    132134    $codeExit = '';
    133135    foreach ( $social_counters as $social_counter ) {
    134136        $codeExit .= social_counter__get($social_counter, $postparam);
    135137    }
    136    
     138
    137139    $mini_counters = ( defined('SOCIAL_COUNTER__LOAD_CSS_SMALL') ) ? SOCIAL_COUNTER__LOAD_CSS_SMALL : false;
    138    
     140
    139141    $codeExit = ( !empty($codeExit) ) ? '<div class="social-counters'. ( $mini_counters ? ' social-counters-mini' : '' ) .'">'. $codeExit .'</div>' : '';
    140    
     142
    141143    return $codeExit;
    142144}
     
    149151
    150152function social_counter__get( $social_counter = '', $postparam = false, $linked = true ) {
    151    
     153
    152154    $codeExit = apply_filters('social_counter__get__'.$social_counter, '', $postparam, $linked);
    153155    $codeExit  = ( empty($codeExit) ) ? false : $codeExit;
    154    
     156
    155157    return $codeExit;
    156158}
     
    158160
    159161function social_counters__the_title__filter( $title ) {
    160    
     162
    161163    $title = str_replace(
    162164        array(
     
    167169            '&quot;', // "
    168170            '&amp;quot;', // "
    169            
     171
    170172            '&#8230;' // ...
    171173        ),
     
    177179            '"',
    178180            '"',
    179            
     181
    180182            '...',
    181183        ),
    182184        $title
    183185    );
    184    
     186
    185187    return $title;
    186188}
Note: See TracChangeset for help on using the changeset viewer.