<commit_before><?php
class com_meego_planet_calculate
{
    private static function prepare_return($value, $modifier)
    {
        return (float) $value * $modifier;
    }
    
    public static function delicious($url, $modifier = 1)
    {
        $json = file_get_contents('http://badges.del.icio.us/feeds/json/url/data?hash=' . md5($url));
        if (empty($json))
        {
            return self::prepare_return(0, $modifier);
        }
        
        $item_data = json_decode($json);
        if (!isset($item_data[0]->total_posts))
        {
            return self::prepare_return(0, $modifier);
        }
        
        return self::prepare_return($item_data[0]->total_posts, $modifier);
    }

    public static function twitter($url, $modifier = 1)
    {
        $json = file_get_contents('http://search.twitter.com/search.json?q=' . urlencode($url));
        if (empty($json))
        {
            return self::prepare_return(0, $modifier);
        }
        
        $item_data = json_decode($json);
        if (!isset($item_data->results))
        {
            return self::prepare_return(0, $modifier);
        }
        
        return self::prepare_return(count($item_data->results), $modifier);
    }

    public static function facebook($url, $modifier = 1)
    {
        $fql = 'SELECT total_count from link_stat where url="' . rawurlencode($url) . '"';
        $json = file_get_contents('http://api.facebook.com/method/fql.query?format=json&query=' . urlencode($fql));
        if (empty($json))
        {
            return self::prepare_return(0, $modifier);
        }
        
        $item_data = json_decode($json);  
        if (   !isset($item_data[0])
            || !isset($item_data[0]->total_count))
        {
            return self::prepare_return(0, $modifier);
        }
        
        return self::prepare_return($item_data[0]->total_count, $modifier);
    }

    public static function hackernews($url, $modifier = 1)
    {
        $json = @file_get_contents('http://api.ihackernews.com/getid?url=' . urlencode($url));
        $score = 0;
        if (empty($json))
        {
            return self::prepare_return($score, $modifier);
        }
        
        $post_ids = json_decode($json);
        if (   empty($post_ids)
            || !is_array($post_ids))<commit_msg>We already handle potential HTTP errors<commit_after><?php
class com_meego_planet_calculate
{
    private static function prepare_return($value, $modifier)
    {
        return (float) $value * $modifier;
    }
    
    public static function delicious($url, $modifier = 1)
    {
        $json = @file_get_contents('http://badges.del.icio.us/feeds/json/url/data?hash=' . md5($url));
        if (empty($json))
        {
            return self::prepare_return(0, $modifier);
        }
        
        $item_data = json_decode($json);
        if (!isset($item_data[0]->total_posts))
        {
            return self::prepare_return(0, $modifier);
        }
        
        return self::prepare_return($item_data[0]->total_posts, $modifier);
    }

    public static function twitter($url, $modifier = 1)
    {
        $json = @file_get_contents('http://search.twitter.com/search.json?q=' . urlencode($url));
        if (empty($json))
        {
            return self::prepare_return(0, $modifier);
        }
        
        $item_data = json_decode($json);
        if (!isset($item_data->results))
        {
            return self::prepare_return(0, $modifier);
        }
        
        return self::prepare_return(count($item_data->results), $modifier);
    }

    public static function facebook($url, $modifier = 1)
    {
        $fql = 'SELECT total_count from link_stat where url="' . rawurlencode($url) . '"';
        $json = @file_get_contents('http://api.facebook.com/method/fql.query?format=json&query=' . urlencode($fql));
        if (empty($json))
        {
            return self::prepare_return(0, $modifier);
        }
        
        $item_data = json_decode($json);  
        if (   !isset($item_data[0])
            || !isset($item_data[0]->total_count))
        {
            return self::prepare_return(0, $modifier);
        }
        
        return self::prepare_return($item_data[0]->total_count, $modifier);
    }

    public static function hackernews($url, $modifier = 1)
    {
        $json = @file_get_contents('http://api.ihackernews.com/getid?url=' . urlencode($url));
        $score = 0;
        if (empty($json))
        {
            return self::prepare_return($score, $modifier);
        }
        
        $post_ids = json_decode($json);
        if (   empty($post_ids)
            || !is_array($post_ids))
{'fraction_non_alphanumeric': 0.14836223506743737, 'fraction_numerical': 0.007278955255833868, 'mean_word_length': 2.1825613079019073, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1620875', 'n_tokens_mistral': 1457, 'n_tokens_neox': 1434, 'n_words': 232}