For those of you with TI websites...

A General Discussion forum for TI calculators

Moderator: MaxCoderz Staff

Post Reply
User avatar
benryves
Maxcoderz Staff
Posts: 3087
Joined: Thu 16 Dec, 2004 10:06 pm
Location: Croydon, England
Contact:

For those of you with TI websites...

Post by benryves »

Here's a PHP script you might find useful!

Code: Select all

<script language="php">
$handle = @fopen("http://www.ticalc.org/archives/files/authors/62/6296.html","r");
$buffer = '';
$curPos = 0;
if (!$handle) {
	echo ("Could not connect to ticalc.org!");
} else {
	global $buffer, $curPos;
	while (!feof ($handle)) { 
		$buffer .= fgets($handle, 4096);
	}
	fclose($handle);
	
	$rankBusiness = getBetweenText('Ranked number ',' in our ');
	$rankBusinessCount = getBetweenText(' of busiest authors with ',' files.');
	$rankAllTime = getBetweenText('Ranked number ',' in our ');
	$rankAllTimeCount = getBetweenText(' authors all time with ',' downloads.');
	$rankWeek = getBetweenText('Ranked number ',' in our ');
	$rankWeekCount = getBetweenText(' seven days with ',' downloads.');
	
	echo "Total downloads: $rankAllTimeCount (Ranked #$rankAllTime)<br />";
	echo "Downloads this week: $rankWeekCount (Ranked #$rankWeek)<br />";
	echo "Overall business: Ranked $rankBusiness with $rankBusinessCount files.<hr />";
	
	$colours = array("#BCCCFF","#FFF9C7");
	$colourIndex = 0;
	
	while (1) {
		$url = getBetweenText('<A HREF="/archives/files/fileinfo/','"><');
		if ($url===false) break;
		
		$url = "http://www.ticalc.org/archives/files/fileinfo/".$url;
		
		$name = getBetweenText("<TD class=t1 VALIGN=\"TOP\">\n","\n</TD>");
		$group = getBetweenText("<TD class=t1 VALIGN=\"TOP\">\n","\n</TD>");
		
		echo "<table bgcolor=\"$colours[$colourIndex]\" cellpadding=\"2\" cellspacing=\"0\" width=\"100%\"><tr><td><a href=\"{$url}\" target=\"_blank\">$name</a></td><td align=\"right\">$group</td></tr></table>";
		$colourIndex = 1-$colourIndex;
	}

}

function getBetweenText($before, $after) {
	global $buffer, $curPos;
	$curPos = strpos($buffer, $before, $curPos);
	if ($curPos===false) {
		return false;
	} else {
		$curPos+=strlen($before);
		$e = strpos($buffer, $after, $curPos);
		return substr($buffer, $curPos, $e-$curPos);
	}
}


</script>
You can see it in action on my website. Maybe someone finds it useful. :) Just change the URL at the top with the URL of your author page!

I did have a version that grabs all the stats for each individual program, but at that point it starts to get a bit slow![/url]
User avatar
tr1p1ea
Maxcoderz Staff
Posts: 4141
Joined: Thu 16 Dec, 2004 10:06 pm
Location: I cant seem to get out of this cryogenic chamber!
Contact:

Post by tr1p1ea »

Hey thats really cool ben! ... this will come in handy :).
"My world is Black & White. But if I blink fast enough, I see it in Grayscale."
Image
Image
User avatar
benryves
Maxcoderz Staff
Posts: 3087
Joined: Thu 16 Dec, 2004 10:06 pm
Location: Croydon, England
Contact:

Post by benryves »

tr1p1ea wrote:Hey thats really cool ben! ... this will come in handy :).
Thanks - not the best code for sharing, but it's very simple and adds a nice functionality.
User avatar
Madskillz
Calc Wizard
Posts: 745
Joined: Fri 17 Dec, 2004 10:22 pm
Location: Wandering around in the Jungle...
Contact:

Post by Madskillz »

very cool Ben! :D
The Revolution is here...
Kozak
Maxcoderz Staff
Posts: 791
Joined: Fri 17 Dec, 2004 5:33 pm
Location: On the dark side of the moon.
Contact:

Post by Kozak »

It would be a nice idea to cache the results so you won't have to check ticalc every time the page loads. With much visitors it can get slow. Also you should check if allow_url_fopen is allowed so you can give more detailed error report if the script fails. It's a nice scripts nonetheless.
"They say that sea was created by a man named Maarten Zwartbol, a long time ago...." - Duck, an old Corbin version
CoBB
MCF Legend
Posts: 1601
Joined: Mon 20 Dec, 2004 8:45 am
Location: Budapest, Absurdistan
Contact:

Post by CoBB »

Actually it's enough to update the data once every day.
Post Reply