Commits

Anonymous committed c8d03a1

initial commit.

Comments (0)

Files changed (2)

+<?php
+
+$result_error = array("error"=>"HTML parsing error.");
+
+$site = $_GET["site"];
+if(preg_match("#[^.\w\d]#", $site)) {
+	die(json_encode(array("error"=>"Invalid site parameter.")));
+}
+$userid = $_GET["userid"];
+if(preg_match("#[^\d]#", $userid)) {
+	die(json_encode(array("error"=>"Invalid userid parameter")));
+}
+
+$site_translations = array(
+	"stackoverflow"=>"stackoverflow.com",
+	"meta.stackoverflow"=>"meta.stackoverflow.com",
+	"serverfault"=>"serverfault.com",
+	"meta.serverfault"=>"meta.serverfault.com",
+	"superuser"=>"superuser.com",
+	"meta.superuser"=>"meta.superuser.com",
+	"askubuntu"=>"askubuntu.com",
+	"meta.askubuntu"=>"meta.askubuntu.com");
+
+if(array_key_exists($site, $site_translations)) {
+	$site = $site_translations[$site];
+} else {
+	$site = $site . ".stackexchange.com";
+}
+
+
+$rep_html = file_get_contents("http://$site/users/$userid/?tab=reputation&sort=graph");
+
+$startpos = strpos($rep_html, "rawData");
+if($startpos === false) {
+	die(json_encode(array("error"=>"HTML parsing error. (Can't find rawData)")));
+}
+
+$rep_html = substr($rep_html, $startpos);
+
+$endpos = strpos($rep_html, ";");
+if($endps === false) {
+	die(json_encode(array("error"=>"HTML parsing error. (Can't find array ending)")));
+}
+
+$rep_html = substr($rep_html, 0, $endpos);
+
+//print($rep_html);
+
+preg_match_all("#\d+,\d+,\d+,(\d+)#",$rep_html, $daily_rep_matches, PREG_PATTERN_ORDER);
+
+$repcount = 0;
+
+if($daily_rep_matches && count($daily_rep_matches)>1 && count($daily_rep_matches[1])) {
+	foreach($daily_rep_matches[1] as $rep_str) {
+		//print("$rep_str\n");
+		if(intval($rep_str) > 199) {
+			$repcount = $repcount + 1;
+		}
+	}
+}
+
+die(json_encode(array("repcount"=>$repcount)));
+
+?>
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
+ 
+<html>
+<head>
+<title>Stinking Badges!</title>
+
+<link type="text/css" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/themes/cupertino/jquery-ui.css" rel="Stylesheet" />	
+<style type="text/css">
+
+	body{ font: 90% "Trebuchet MS", sans-serif; margin: 20px;}
+	td{padding:5px;}
+	tr{border: 1px solid black;}
+	.skill_active{color: red; font-weight:bold;}
+	table {border-collapse:collapse;}
+	.post-score { 
+		padding: 3px 3px 3px 2px;
+		height: 15px;
+		line-height: 1.3;
+		margin-right: 10px;
+		text-align: center;
+		min-width: 20px;
+	}
+	.progress-bar {
+		width: 300px;
+		height:15px;
+		padding: 5px;
+	}
+
+	
+</style>
+<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script>
+<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/jquery-ui.min.js"></script>
+<script type="text/javascript" src="../js/api.js"></script>
+<script type="text/javascript" src="../js/common.js"></script>
+<script type="text/javascript" src="../js/jquery.iecors.js"></script>
+
+<script type="text/javascript" src="../js/jquery.cookies.min.js"></script>
+<script type="text/javascript">
+  var _gaq = _gaq || [];
+  _gaq.push(['_setAccount', 'UA-26396490-1']);
+  _gaq.push(['_trackPageview']);
+  (function() {
+    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
+    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
+    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
+  })();
+</script>
+<script type="text/javascript" language="javascript">
+
+var user_site = "stackoverflow";
+var user_id = 0;
+
+var top_tag_list = [];
+
+function on_top_tag_success(json) {
+	if(!('items' in json)) {
+		return;
+	}
+	
+	var good_output = "";
+	var bad_output = "";
+	var site_url = stackexchange_site_array[user_site].site_url;
+	
+	var user_tag_list = {};
+	
+	for(var item_id in json.items) {
+		var item = json.items[item_id];
+		user_tag_list[item['tag_name']] = item['answer_score'];	
+	}
+	
+	var good_tag_count = 0;
+	for(var tag_num in top_tag_list) {
+		var tag = top_tag_list[tag_num];
+		var tag_score = "?";
+		if(tag in user_tag_list) {
+			tag_score = user_tag_list[tag];
+			
+		}
+		if(tag_score > 15) {
+			good_tag_count++;
+			good_output = good_output + '<a target="_blank" class=tag href="'+site_url+'/search?q=user:'
+				+user_id+'+['+tag+']">'+tag+"</a> ("+tag_score+") ";
+		} else {
+			bad_output = bad_output + '<a target="_blank" class=tag href="'+site_url+'/search?q=user:'
+				+user_id+'+['+tag+']">'+tag+"</a> ("+tag_score+") ";
+		}
+	}
+	
+	var output = "<p>Top tags where your answer score is above 15: "+good_tag_count+"</p>\n"+
+		"<p>Top tags above 15 votes: "+good_output+"</p>\n"+
+		"<p>Top tags below 15 votes: "+bad_output+"</p>\n";
+	
+	$("#generalist-result").html(output);
+	
+	var progress_bar_value = 0;
+	
+	if(good_tag_count > 20) {
+		progress_bar_value = 100;
+	} else {
+		progress_bar_value = good_tag_count*100/20;
+	}
+	
+	
+	$("#generalist-progress").progressbar("value", progress_bar_value);
+	
+}
+
+function on_tag_list_success(json) {
+	if(!('items' in json)) {
+		return;
+	}
+	
+	top_tag_list = []
+	
+	for(var item_id in json['items']) {
+		var item = json.items[item_id];
+		top_tag_list.push(item['name']);
+	}
+	
+	api_call("/users/"+user_id+"/top-answer-tags/", 
+		{site: user_site, filter:'!n0IbH.9B9.'}, 
+		on_top_tag_success);
+	
+	
+	
+}
+
+var vote_list_common_args = {pagesize:10, order:'desc', sort:'votes' };
+
+function on_vote_list_success(json, output_id) {
+	if(!('items' in json)) {
+		$('#'+output_id).html("An error occurred...");
+		return;
+	}
+	
+	output_html = "";
+	var count = 0;
+	
+	for(var item_id in json['items']) {
+		var item = json['items'][item_id];
+		count++;
+		output_html = output_html + 
+			"<span class=\"post-score\">"+item['score']+
+			'</span> <a target="_blank" href="'+stackexchange_site_array[user_site].site_url+
+			'/questions/'+item['question_id']+'">'+item['title']+"</a><br>\n";
+	}
+	if(count) {
+		$('#'+output_id).html(output_html);
+	} else {
+		$('#'+output_id).html("None of your posts are close to this badge :(");
+	}
+	
+}
+
+function on_rep_count_success(json) {
+	if(!('repcount' in json)) {
+		$("#legendary-progress").progressbar("value", 0);
+		$("#legendary-count").text("?");
+		return;
+	}
+	
+	var progress_bar_value = 0;
+	if(json.repcount > 150) {
+		progress_bar_value = 100;
+	} else {
+		progress_bar_value = json.repcount*100/150;
+	}
+	$("#legendary-progress").progressbar("value", progress_bar_value);
+	$("#legendary-count").text(json.repcount+ " of 150. ("+Math.floor(progress_bar_value)+"%)");
+}
+
+
+function refresh_all() {
+
+
+	$.ajax({
+		type: "GET",
+		url: "dailyrep.php", 
+		data: {site:user_site, userid:user_id},
+		success: on_rep_count_success,
+		dataType:"json",
+	});
+	
+	api_call("tags", {site: user_site, pagesize:40,order:'desc',sort:'popular'}, on_tag_list_success, on_error);
+	
+	api_call("/users/"+user_id+"/questions/", 
+		$.extend({site: user_site, min: '7', max: '9', filter:'!)qk0x1x-Z8ryVmFbK.yk'}, vote_list_common_args),
+		function (json) { on_vote_list_success(json, "question_list_bronze") });
+		
+	api_call("/users/"+user_id+"/questions/", 
+		$.extend({site: user_site, min: '20', max: '24', filter:'!)qk0x1x-Z8ryVmFbK.yk'}, vote_list_common_args),
+		function (json) { on_vote_list_success(json, "question_list_silver") });
+		
+	api_call("/users/"+user_id+"/questions/", 
+		$.extend({site: user_site, min: '90', max: '99', filter:'!)qk0x1x-Z8ryVmFbK.yk'}, vote_list_common_args),
+		function (json) { on_vote_list_success(json, "question_list_gold") });
+		
+	
+	api_call("/users/"+user_id+"/answers/", 
+		$.extend({site: user_site, min: '7', max: '9', filter:'!mRNa90ViDb'}, vote_list_common_args),
+		function (json) { on_vote_list_success(json, "answer_list_bronze") });
+		
+	api_call("/users/"+user_id+"/answers/", 
+		$.extend({site: user_site, min: '20', max: '24', filter:'!mRNa90ViDb'}, vote_list_common_args),
+		function (json) { on_vote_list_success(json, "answer_list_silver") });
+		
+	api_call("/users/"+user_id+"/answers/", 
+		$.extend({site: user_site, min: '90', max: '99', filter:'!mRNa90ViDb'}, vote_list_common_args),
+		function (json) { on_vote_list_success(json, "answer_list_gold") });
+}
+
+function reset_output() {
+	$("#account").html("(No account information loaded yet)");
+
+	$("#legendary-progress").progressbar("value", 0);
+	$("#legendary-count").text("?");
+	
+	$("#generalist-progress").progressbar("value", 0);
+	$("#generalist-result").html('<img src="../common/load.gif">');
+
+	$("#question_list_bronze").html('<img src="../common/load.gif">');
+	$("#question_list_silver").html('<img src="../common/load.gif">');
+	$("#question_list_gold").html('<img src="../common/load.gif">');
+	
+	$("#answer_list_bronze").html('<img src="../common/load.gif">');
+	$("#answer_list_silver").html('<img src="../common/load.gif">');
+	$("#answer_list_gold").html('<img src="../common/load.gif">');
+}
+
+function on_auth_success(json) {
+	
+	var user = json.items[0];
+	if(user == null) {
+		$("#account").html("You don't have an account on this site!");
+		return;
+	}
+	
+	user_id = user['user_id'];
+	$("#account").html('<a target="_blank" href="'+stackexchange_site_array[user_site].site_url+'/users/'+user_id+'">'+
+		user['display_name'] + "</a>");
+	//api_call("tags", {pagesize:40,order:'desc',sort:'popular'}, on_tag_list_success, on_error);
+	
+	refresh_all();
+
+	
+}
+
+function on_error(request, status, error) {
+	alert("An error has occurred!");
+}
+
+$(document).ready(function() {
+	var client_id = 74;
+	var args = {key:encodeURI('tD7YpcY3WuQGUz*f47P21g((')};
+	
+	try {
+		var stored_user_site = $.cookies.get('badges_user_site');
+		if(stored_user_site != null) user_site = stored_user_site;
+	} catch (err) {
+	
+	}
+	
+	//var cur_site = $("#siteselect").find('[value="'+user_site+'"]');
+	$("#siteselect").val(user_site);
+	$("#siteselect").change(function (e) {
+		user_site = $("#siteselect").val();
+		$.cookies.set('badges_user_site', $("#siteselect").val());
+		reset_output();
+		api_auth(user_site, on_auth_success, on_error);
+		
+		
+	});
+	
+	$("#legendary-progress").progressbar();
+	$("#generalist-progress").progressbar();
+	
+	$("#refresh").click(function (e) {
+		reset_output();
+		refresh_all();
+		e.preventDefault();
+	});
+
+	$("#token_reset").click(function (e) {
+		api_reset_access_token(client_id);
+		e.preventDefault();
+	});
+
+
+	
+	api_init(client_id, args);
+	
+	api_auth(user_site, on_auth_success, on_error);
+	
+	
+});
+</script>
+
+</head>
+<body>
+<h1>StinkingBadges</h1>
+
+<i>Badges?  We don't need no <a href="http://www.youtube.com/watch?v=TFwprS_L6tg">stinking badges!</a></i>
+
+<p><a href="#" id="refresh">Refresh</a> - <a href="#" id="token_reset">Reset Access Token</a></p>
+
+
+<p>Check my progress on: <select id="siteselect">
+<option value="stackoverflow">Stack Overflow</option>
+<option value="serverfault">Server Fault</option>
+<option value="superuser">Super User</option>
+<option value="meta.stackoverflow">Meta Stack Overflow</option>
+<option value="webapps">Web Applications</option>
+<option value="meta.webapps">Web Applications Meta</option>
+<option value="gaming">Gaming</option>
+<option value="meta.gaming">Gaming Meta</option>
+<option value="webmasters">Webmasters</option>
+<option value="meta.webmasters">Webmasters Meta</option>
+<option value="cooking">Cooking</option>
+<option value="meta.cooking">Cooking Meta</option>
+<option value="gamedev">Game Development</option>
+<option value="meta.gamedev">Game Development Meta</option>
+<option value="photo">Photography</option>
+<option value="meta.photo">Photography Meta</option>
+<option value="stats">Statistical Analysis</option>
+<option value="meta.stats">Statistical Analysis Meta</option>
+<option value="math">Mathematics</option>
+<option value="meta.math">Mathematics Meta</option>
+<option value="diy">Home Improvement</option>
+<option value="meta.diy">Home Improvement Meta</option>
+<option value="meta.superuser">Meta Super User</option>
+<option value="meta.serverfault">Meta Server Fault</option>
+<option value="gis">GIS</option>
+<option value="meta.gis">GIS Meta</option>
+<option value="tex">TeX - LaTeX</option>
+<option value="meta.tex">TeX - LaTeX Meta</option>
+<option value="askubuntu">Ask Ubuntu</option>
+<option value="meta.askubuntu">Ask Ubuntu Meta</option>
+<option value="money">Personal Finance and Money</option>
+<option value="meta.money">Personal Finance and Money Meta</option>
+<option value="english">English Language and Usage</option>
+<option value="meta.english">English Language and Usage Meta</option>
+<option value="stackapps">Stack Apps</option>
+<option value="ux">User Experience</option>
+<option value="meta.ux">User Experience Meta</option>
+<option value="unix">Unix and Linux</option>
+<option value="meta.unix">Unix and Linux Meta</option>
+<option value="wordpress">WordPress</option>
+<option value="meta.wordpress">WordPress Meta</option>
+<option value="cstheory">Theoretical Computer Science</option>
+<option value="meta.cstheory">Theoretical Computer Science Meta</option>
+<option value="apple">Apple</option>
+<option value="meta.apple">Apple Meta</option>
+<option value="rpg">Role-playing Games</option>
+<option value="meta.rpg">Role-playing Games Meta</option>
+<option value="bicycles">Bicycles</option>
+<option value="meta.bicycles">Bicycles Meta</option>
+<option value="programmers">Programmers</option>
+<option value="meta.programmers">Programmers Meta</option>
+<option value="electronics">Electrical Engineering</option>
+<option value="meta.electronics">Electrical Engineering Meta</option>
+<option value="android">Android Enthusiasts</option>
+<option value="meta.android">Android Enthusiasts Meta</option>
+<option value="answers.onstartups">OnStartups</option>
+<option value="meta.answers.onstartups">OnStartups Meta</option>
+<option value="boardgames">Board and Card Games</option>
+<option value="meta.boardgames">Board and Card Games Meta</option>
+<option value="physics">Physics</option>
+<option value="meta.physics">Physics Meta</option>
+<option value="homebrew">Homebrew</option>
+<option value="meta.homebrew">Homebrew Meta</option>
+<option value="security">IT Security</option>
+<option value="meta.security">IT Security Meta</option>
+<option value="writers">Writers</option>
+<option value="meta.writers">Writers Meta</option>
+<option value="avp">Audio-Video Production</option>
+<option value="meta.avp">Audio-Video Production Meta</option>
+<option value="graphicdesign">Graphic Design</option>
+<option value="meta.graphicdesign">Graphic Design Meta</option>
+<option value="dba">Database Administrators</option>
+<option value="meta.dba">Database Administrators Meta</option>
+<option value="scifi">Science Fiction and Fantasy</option>
+<option value="meta.scifi">Science Fiction and Fantasy Meta</option>
+<option value="discuss.area51">Area 51 Discussions</option>
+<option value="codereview">Code Review</option>
+<option value="meta.codereview">Code Review Meta</option>
+<option value="codegolf">Code Golf</option>
+<option value="meta.codegolf">Code Golf Meta</option>
+<option value="quant">Quantitative Finance</option>
+<option value="meta.quant">Quantitative Finance Meta</option>
+<option value="pm">Project Management</option>
+<option value="meta.pm">Project Management Meta</option>
+<option value="skeptics">Skeptics</option>
+<option value="meta.skeptics">Skeptics Meta</option>
+<option value="fitness">Fitness and Nutrition</option>
+<option value="meta.fitness">Fitness and Nutrition Meta</option>
+<option value="drupal">Drupal Answers</option>
+<option value="meta.drupal">Drupal Answers Meta</option>
+<option value="mechanics">Motor Vehicle Maintenance and Repair</option>
+<option value="meta.mechanics">Motor Vehicle Maintenance and Repair Meta</option>
+<option value="parenting">Parenting</option>
+<option value="meta.parenting">Parenting Meta</option>
+<option value="sharepoint">SharePoint</option>
+<option value="meta.sharepoint">SharePoint Meta</option>
+<option value="music">Musical Practice and Performance</option>
+<option value="meta.music">Musical Practice and Performance Meta</option>
+<option value="sqa">Software Quality Assurance and Testing</option>
+<option value="meta.sqa">Software Quality Assurance and Testing Meta</option>
+<option value="judaism">Jewish Life and Learning</option>
+<option value="meta.judaism">Jewish Life and Learning Meta</option>
+<option value="german">German Language and Usage</option>
+<option value="meta.german">German Language and Usage Meta</option>
+<option value="japanese">Japanese Language and Usage</option>
+<option value="meta.japanese">Japanese Language and Usage Meta</option>
+<option value="astronomy">Astronomy</option>
+<option value="meta.astronomy">Astronomy Meta</option>
+<option value="philosophy">Philosophy</option>
+<option value="meta.philosophy">Philosophy Meta</option>
+<option value="gardening">Gardening and Landscaping</option>
+<option value="meta.gardening">Gardening and Landscaping Meta</option>
+<option value="travel">Travel</option>
+<option value="meta.travel">Travel Meta</option>
+<option value="productivity">Personal Productivity</option>
+<option value="meta.productivity">Personal Productivity Meta</option>
+<option value="crypto">Cryptography</option>
+<option value="meta.crypto">Cryptography Meta</option>
+<option value="literature">Literature</option>
+<option value="meta.literature">Literature Meta</option>
+<option value="dsp">Signal Processing</option>
+<option value="meta.dsp">Signal Processing Meta</option>
+<option value="french">French Language and Usage</option>
+<option value="meta.french">French Language and Usage Meta</option>
+<option value="christianity">Christianity</option>
+<option value="meta.christianity">Christianity Meta</option>
+<option value="bitcoin">Bitcoin</option>
+<option value="meta.bitcoin">Bitcoin Meta</option>
+<option value="linguistics">Linguistics</option>
+<option value="meta.linguistics">Linguistics Meta</option>
+<option value="theoreticalphysics">Theoretical Physics</option>
+<option value="meta.theoreticalphysics">Theoretical Physics Meta</option>
+<option value="hermeneutics">Biblical Hermeneutics</option>
+<option value="meta.hermeneutics">Biblical Hermeneutics Meta</option>
+<option value="history">History</option>
+<option value="meta.history">History Meta</option>
+<option value="economics">Economics</option>
+<option value="meta.economics">Economics Meta</option>
+<option value="healthcareit">Healthcare IT</option>
+<option value="meta.healthcareit">Healthcare IT Meta</option>
+<option value="bricks">LEGO&#174; Answers</option>
+<option value="meta.bricks">LEGO&#174; Answers Meta</option>
+<option value="firearms">Firearms</option>
+<option value="meta.firearms">Firearms Meta</option>
+<option value="spanish">Spanish Language and Usage</option>
+<option value="meta.spanish">Spanish Language and Usage Meta</option>
+<option value="scicomp">Computational Science</option>
+<option value="meta.scicomp">Computational Science Meta</option>
+<option value="movies">Movies and TV</option>
+<option value="meta.movies">Movies and TV Meta</option>
+<option value="chinese">Chinese Language and Usage</option>
+<option value="meta.chinese">Chinese Language and Usage Meta</option>
+<option value="biology">Biology</option>
+<option value="meta.biology">Biology Meta</option>
+<option value="poker">Poker</option>
+<option value="meta.poker">Poker Meta</option>
+<option value="sexuality">Sexuality</option>
+<option value="meta.sexuality">Sexuality Meta</option>
+<option value="mathematica">Mathematica</option>
+<option value="meta.mathematica">Mathematica Meta</option>
+<option value="cogsci">Cognitive Sciences</option>
+<option value="meta.cogsci">Cognitive Sciences Meta</option>
+</select></p>
+<p>
+Your account on this site: <span id="account">(No account information loaded yet)</span>
+</p>
+<p></p>
+
+<div class="legendary">
+<h3>Progress towards Legendary</h3>
+
+<div id="legendary-progress-container"><div class="progress-bar" id="legendary-progress"></div></div>
+
+<p>Days at or above 200 rep: <span id="legendary-count"></span></p>
+
+</div>
+
+<div class="generalist">
+<h3>Progress towards Generalist</h3>
+<p><b>Note:</b> I can only pull the top 30 tags from your profile, so if you see a (?) next to a tag,
+this indicates that I ran out of data before I could get your count on this tag.  
+</p>
+<p><b>Note 2:</b> Some sites do not yet qualify for generalist, see 
+<a _target="blank" href="http://blog.stackoverflow.com/2010/05/generalist-badge-implemented/">this blog post</a> for more details.</p>
+<div id="generalist-progress-container"><div class="progress-bar" id="generalist-progress"></div></div>
+
+
+<div id="generalist-result"><img src="../common/load.gif"></div>
+
+</div>
+
+<div class="badgelist">
+<h3>Questions close to "Nice Question" (10 upvotes)</h3>
+<div id="question_list_bronze"><img src="../common/load.gif"></div>
+
+</div>
+
+<div class="badgelist">
+<h3>Questions close to "Good Question" (25 upvotes)</h3>
+<div id="question_list_silver"><img src="../common/load.gif"></div>
+</div>
+
+<div class="badgelist">
+<h3>Questions close to "Great Question" (100 upvotes)</h3>
+<div id="question_list_gold"><img src="../common/load.gif"></div>
+</div>
+
+<div class="badgelist">
+<h3>Answers close to "Nice Answer" (10 upvotes)</h3>
+<div id="answer_list_bronze"><img src="../common/load.gif"></div>
+</div>
+
+<div class="badgelist">
+<h3>Answers close to "Good Answer" (25 upvotes)</h3>
+<div id="answer_list_silver"><img src="../common/load.gif"></div>
+</div>
+
+<div class="badgelist">
+<h3>Answers close to "Great Answer" (100 upvotes)</h3>
+<div id="answer_list_gold"><img src="../common/load.gif"></div>
+</div>
+
+<div id="pagefooter"></div>
+</body>
+</html>