<commit_before><?php

	/*
		Socialworth - A demo script for determining the popularity of a url
		against social networks. By <NAME> (<EMAIL>)

		https://github.com/evansims/socialworth

		---

		Although this script is intended primarily to be used as a template
		for building your own variations of this concept, the script can
		be queried as-is for a JSON response. See demo.html for a working
		example.

		---

		This script is an expansion of Jonathan Moore's gist:
		https://gist.github.com/2640302
	*/

	// Get these values from http://www.seomoz.org/api/keys/
	define('SEOMOZ_ID', '');
	define('SEOMOZ_KEY', '');











	ob_start();

	$url = (isset($_GET['url']) ? $_GET['url'] : FALSE);
	if(!$url) die();

	$urlseo = parse_url($url);
	if(!isset($urlseo['path'])) {
		$url .= '/';
		$urlseo = parse_url($url);
	}

	$api = NULL;
	$counter = 0;
	$expires = time() + 300;
	$urlseo = "{$urlseo['host']}{$urlseo['path']}";
	$seomoz_sig = (SEOMOZ_ID && SEOMOZ_KEY ? urlencode(base64_encode(hash_hmac('sha1', SEOMOZ_ID . "\n" . $expires, SEOMOZ_KEY, true))) : '');
	$breakdown = array();

	$endpoints = array(

		// Mozscape Backlinks
		array(
			'name'     => 'mozscape',
			'method'   => 'GET',
			'url'      => "http://lsapi.seomoz.com/linkscape/url-metrics/{$urlseo}?Cols=32&AccessID=" . SEOMOZ_ID . "&Expires={$expires}&Signature={$seomoz_sig}",
			'callback' => function($resp) {
				if(isset($resp->ueid)) {
					return (int)$resp->ueid;
				} else {
					return 0;
				}
			}),

		// Facebook
		array(
			'name'     => 'facebook',
			'method'   => 'GET',
			'url'      => 'https://graph.facebook.com/fql?q=' . urlencode("SELECT like_count, total_count, share_count, click_count, comment_count FROM link_stat WHERE url = \"{$url}\""),
			"callback" => function($resp) {
				if(isset($resp->data[0]->total_count)) {
					return (int)$resp->data[0]->total_count;
				} else {
					return 0;
				}
			}),

		// Pinterest
		array(
			'name'     => 'pinterest',
			'method'   => 'GET',
			'url'      => "http://api.pinterest.com/v1/urls/count.json?callback=&url={$url}",
			"callback" => function($resp) {
				$resp = json_decode(substr($resp, 1, -1));
				if(isset($resp->count)) {
					return (int)$resp->count;
				} else {
					return 0;
				}
			}),

		// Twitter
		array(
			'name'     => 'twitter',
			'method'   => 'GET',<commit_msg>Apply Pinterest API fix suggested by @dsposito<commit_after><?php

	/*
		Socialworth - A demo script for determining the popularity of a url
		against social networks. By <NAME> (<EMAIL>)

		https://github.com/evansims/socialworth

		---

		Although this script is intended primarily to be used as a template
		for building your own variations of this concept, the script can
		be queried as-is for a JSON response. See demo.html for a working
		example.

		---

		This script is an expansion of Jonathan Moore's gist:
		https://gist.github.com/2640302
	*/

	// Get these values from http://www.seomoz.org/api/keys/
	define('SEOMOZ_ID', '');
	define('SEOMOZ_KEY', '');











	ob_start();

	$url = (isset($_GET['url']) ? $_GET['url'] : FALSE);
	if(!$url) die();

	$urlseo = parse_url($url);
	if(!isset($urlseo['path'])) {
		$url .= '/';
		$urlseo = parse_url($url);
	}

	$api = NULL;
	$counter = 0;
	$expires = time() + 300;
	$urlseo = "{$urlseo['host']}{$urlseo['path']}";
	$seomoz_sig = (SEOMOZ_ID && SEOMOZ_KEY ? urlencode(base64_encode(hash_hmac('sha1', SEOMOZ_ID . "\n" . $expires, SEOMOZ_KEY, true))) : '');
	$breakdown = array();

	$endpoints = array(

		// Mozscape Backlinks
		array(
			'name'     => 'mozscape',
			'method'   => 'GET',
			'url'      => "http://lsapi.seomoz.com/linkscape/url-metrics/{$urlseo}?Cols=32&AccessID=" . SEOMOZ_ID . "&Expires={$expires}&Signature={$seomoz_sig}",
			'callback' => function($resp) {
				if(isset($resp->ueid)) {
					return (int)$resp->ueid;
				} else {
					return 0;
				}
			}),

		// Facebook
		array(
			'name'     => 'facebook',
			'method'   => 'GET',
			'url'      => 'https://graph.facebook.com/fql?q=' . urlencode("SELECT like_count, total_count, share_count, click_count, comment_count FROM link_stat WHERE url = \"{$url}\""),
			"callback" => function($resp) {
				if(isset($resp->data[0]->total_count)) {
					return (int)$resp->data[0]->total_count;
				} else {
					return 0;
				}
			}),

		// Pinterest
		array(
			'name'     => 'pinterest',
			'method'   => 'GET',
			'url'      => "http://api.pinterest.com/v1/urls/count.json?url={$url}",
			"callback" => function($resp) {
				$resp = json_decode(substr($resp, strpos($resp, '{'), -1));
				if(isset($resp->count)) {
					return (int)$resp->count;
				} else {
					return 0;
				}
			}),

		// Twitter
		array(
			'name'     => 'twitter',
			'method'   => 'GET',
{'fraction_non_alphanumeric': 0.19569801771404471, 'fraction_numerical': 0.009911429776465626, 'mean_word_length': 3.0817555938037864, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 51, 'https://': 6, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2045258', 'n_tokens_mistral': 2013, 'n_tokens_neox': 1734, 'n_words': 363}