[Release] Vote counter (xtremetop100, PHP+JavaScript)

07/08/2013 15:25 _Emme_#1
First of all, make sure you have [Only registered and activated users can see links. Click Here To Register...].

We will go through three easy steps.

1) Fetch content from xtremetop100
2) Load it into an HTML-element
3) Find the correct element for votecount and retrieve it


PHP:
Code:
$voteContents = file_get_contents('http://www.xtremetop100.com/conquer-online');
HTML:
Code:
<div id="voteContents" style="display: none;"><?=$voteContents?></div>
JavaScript (jQuery):
Code:
function GetVotes(serverid)
{
  return $("#voteContents").find('a[href="out.php?site=' + serverid + '"]').first().parent().next(".stats1").find("span").eq(1).html();
}
You can now, via JavaScript (jQuery if you ask me) populate any element with the count. To do so, simply do this.


Lets say we have an element with the class "voteCounts"
<span class="voteCounts"></span>

We can now do:
Code:
$(".voteCounts").text(GetVotes(1132343528))
The ID is your server ID.

I chose to go with PHP over JSONp for external fetching of data. Whoever uses this should also consider making an AJAX-call to populate the #voteContents once the document is ready, to avoid any possible delay.


Enjoy.
07/08/2013 18:26 turk55#2
simple, yet effective =p
07/08/2013 19:39 _Emme_#3
The only "trick" with this is knowing your JavaScript. You could parse it all via PHP, but it won't be as clean. Here's an example in raw PHP(very unclean). It fetches amount of votes and the current rank.


PHP Code:
<?php
function getVotes($parts) { return ($parts[1][449 2] == "<" $parts[1][449].$parts[1][449 1] : $parts[1][449].$parts[1][449 1].$parts[1][449 2]); }
function 
getRank($parts$pos) { return ($parts[0][$pos 24] == "<" $parts[0][$pos 23] : $parts[0][$pos 23].$parts[0][$pos 24]); }
function 
rankPos($haystack){
    
$pos strpos(strrev($haystack), strrev('number'), 0);
    return (
$pos === false)?false:( strlen($haystack) - $pos strlen('number') );
}

$contents file_get_contents('http://www.xtremetop100.com/conquer-online'); 
$ar explode('COServer'$contents);

$votes getVotes($ar);
$totalVotes $votes;
$rank getRank($arrankPos($ar[0]));

echo 
'Rank: '.$rank.'<br/>Total votes: '.$votes;
?>
07/09/2013 00:50 Super Aids#4
Should I be honest. It's neat, but quite useless. 99% of the votes are fake on xtremetop100, for the matter on any voting websites.
07/09/2013 01:09 _Emme_#5
Depends on how you see it though. Almost every private server uses xtremetop100, this is just a way for them to present amount of votes (and rank easily done) on their website.

Would be a nice addon don't you think?
07/09/2013 09:41 Super Aids#6
Yup, my point was that the votes are generated by bots, thus is kind of a fake rank most servers have, since it's not based on actual player votes.
07/09/2013 18:07 go for it#7
definitely nice snippet but there is more useful items you can do, ex. earning points system (surveys and tasks like at super rewards)
as of what i remember the hardest part is to manage the connections between member login , db and website confirmation to reward members (i couldn't get it working so don't trust what i just said :P )
that would definitely be the greatest thing one can do to co community
07/09/2013 19:38 _Emme_#8
@Aids
I know what you mean but doesn't remove the fact that people still use it.

@go_for_it
Do you mean for servers to put up and reward players, and the server making money out of it? Do you know any service that is real. I have stumbled across some but they all ended up being fake or having to register your phone etc - I don't like that kind of stuff.

Just give me the tools I need and I'll do the logic and functionality for it all, no worries.
07/09/2013 20:31 go for it#9
Quote:
Originally Posted by 'Emil View Post
@Aids
I know what you mean but doesn't remove the fact that people still use it.

@go_for_it
Do you mean for servers to put up and reward players, and the server making money out of it? Do you know any service that is real. I have stumbled across some but they all ended up being fake or having to register your phone etc - I don't like that kind of stuff.

Just give me the tools I need and I'll do the logic and functionality for it all, no worries.
well i use a simple common sense to figure out who's real and who's fake by going to big games around and find what they use
imvu and crossfire/z8games are using so many of that rewarding systems for years, every website they use are real (as they been using it for years)
there is no worries about getting sued as the only one who will complain is tq, which should send you first a warning asking you to take the private server down
but the most important questions is, are they going to accept you ? (they have restrictions for your website also your services) but generally i've seen a crossfire private server using it

anyway it's not hard but it takes serious web programming skills
07/09/2013 21:06 _Emme_#10
If it requires me to apply for it etc then screw it. Feel free to come up with other ideas for things to release.
07/09/2013 21:26 go for it#11
Quote:
Originally Posted by 'Emil View Post
If it requires me to apply for it etc then screw it. Feel free to come up with other ideas for things to release.
well it doesn't require alot (just general info) but no phone vitrification or even ssn or visa but still that's up to you ^^