[Function] get_version()

This forum is now closed as part of retiring phpBB2.
Forum rules
READ: phpBB.com Board-Wide Rules and Regulations

This forum is now closed due to phpBB2.0 being retired.
Locked
afterlife_69
I've Been Banned!
Posts: 630
Joined: Tue Nov 30, 2004 10:35 am

[Function] get_version()

Post by afterlife_69 » Wed Aug 10, 2005 3:37 pm

This function will grab the MOD version from the topic on phpBB.com

Usage:

Code: Select all

get_version('302467'); // This will get the version from http://www.phpbb.com/phpBB/viewtopic.php?t=302467 
Function:

Code: Select all

function get_version($id, $page = "http://www.phpbb.com/phpBB/viewtopic.php?t=")
{
    $handle = fopen($page.$id,"r");
    $topic_text = "";
    while (!feof($handle))
    {
        $topic_text .= fread($handle, 8192);
    }
    fclose($handle);
    $matches = array();
    preg_match("#MOD Version</span>:\s([0-9]+\.[0-9]+\.[0-9]+)#is",$topic_text,$matches);
    return $matches[1];
}
Rewritten by Flaming_cows to look for the MOD Version line on the phpBB.com post.
Last edited by afterlife_69 on Thu Aug 11, 2005 2:55 pm, edited 3 times in total.

User avatar
Flaming_cows
Registered User
Posts: 761
Joined: Sat Jul 05, 2003 1:43 am
Contact:

Post by Flaming_cows » Wed Aug 10, 2005 3:52 pm

This is the exact equivalent of:

Code: Select all

file_get_contents("http://www.meetthe1337.com/my_version.txt");
Your whole function is ridiculous, from sending the HTTP request by hand to exploding()'ing and then concatenating the string you got from the file (in which you don't even use '.=' to concatenate, but rather do it in the form $x=$x.$y;).

afterlife_69
I've Been Banned!
Posts: 630
Joined: Tue Nov 30, 2004 10:35 am

Post by afterlife_69 » Wed Aug 10, 2005 4:23 pm

:| i did that for nothing?!

User avatar
Flaming_cows
Registered User
Posts: 761
Joined: Sat Jul 05, 2003 1:43 am
Contact:

Post by Flaming_cows » Wed Aug 10, 2005 4:30 pm

It was a nice effort, but I'm afraid so.

afterlife_69
I've Been Banned!
Posts: 630
Joined: Tue Nov 30, 2004 10:35 am

Post by afterlife_69 » Wed Aug 10, 2005 4:32 pm

:( oh well... back to making that DoS script ^^

User avatar
A_Jelly_Doughnut
Former Team Member
Posts: 34457
Joined: Sat Jan 18, 2003 1:26 am
Location: Where the Rivers Run
Contact:

Post by A_Jelly_Doughnut » Wed Aug 10, 2005 9:37 pm

Well, file_get_contents() wouldn't be allowed in a MOD because it didn't become available until php 4.3.0.

I certainly wouldn't call your work ridiculous, afterlife_69, but it could use some work (especially the concatation). I'd just use

Code: Select all

$version = implode('.', $version_info);
A Donut's Blog
"Bach's Prelude (Cello Suite No. 1) is driving Indiana country roads in Autumn" - Ann Kish

afterlife_69
I've Been Banned!
Posts: 630
Joined: Tue Nov 30, 2004 10:35 am

Post by afterlife_69 » Wed Aug 10, 2005 10:20 pm

fixed it up since you told me bout the php version stuff ^^ its nice now.

User avatar
Flaming_cows
Registered User
Posts: 761
Joined: Sat Jul 05, 2003 1:43 am
Contact:

Post by Flaming_cows » Wed Aug 10, 2005 11:07 pm

A_Jelly_Doughnut wrote: Well, file_get_contents() wouldn't be allowed in a MOD because it didn't become available until php 4.3.0.

Okay, but he's still going to ridiculous lengths with the fputs() for the HTTP request. A simple fopen()/fread() will suffice.

Code: Select all

$file = "http://meetthe1337.com/my_version.txt";
$handle = fopen($file, "r");
$version = fread($handle, filesize($file));
fclose($handle);
I certainly wouldn't call your work ridiculous, afterlife_69, but it could use some work (especially the concatation). I'd just use

Code: Select all

$version = implode('.', $version_info);

Or just, y'know, don't explode it in the first place. :roll:

afterlife_69
I've Been Banned!
Posts: 630
Joined: Tue Nov 30, 2004 10:35 am

Post by afterlife_69 » Thu Aug 11, 2005 12:11 am

i used that get method because thats what the original phpBB version checker uses.

User avatar
smithy_dll
Former Team Member
Posts: 7630
Joined: Tue Jan 08, 2002 6:27 am
Location: Australia
Name: Lachlan Smith
Contact:

Post by smithy_dll » Thu Aug 11, 2005 6:39 am

would it be more useful to check against the topic's body text in the MOD Release Forum?

afterlife_69
I've Been Banned!
Posts: 630
Joined: Tue Nov 30, 2004 10:35 am

Post by afterlife_69 » Thu Aug 11, 2005 11:40 am

but then wouldnt a cirten line have to be specified?

User avatar
battye
Extension Customisations
Extension Customisations
Posts: 10933
Joined: Wed Feb 11, 2004 11:02 am
Location: Australia
Contact:

Post by battye » Thu Aug 11, 2005 1:13 pm

A_Jelly_Doughnut wrote: Well, file_get_contents() wouldn't be allowed in a MOD because it didn't become available until php 4.3.0.


It can, you just have to mention that 4.3 or above is required in the Author Notes.
Customisations Team Member

User avatar
webmacster87
Former Team Member
Posts: 3758
Joined: Fri Jun 11, 2004 2:30 am
Location: San Mateo, CA
Name: Douglas Bell
Contact:

Post by webmacster87 » Thu Aug 11, 2005 1:51 pm

If you want a version checker for your MODs, I might recommend looking at this.

User avatar
Flaming_cows
Registered User
Posts: 761
Joined: Sat Jul 05, 2003 1:43 am
Contact:

Post by Flaming_cows » Thu Aug 11, 2005 2:06 pm

smithy_dll wrote: would it be more useful to check against the topic's body text in the MOD Release Forum?

Code: Select all

function get_version($id, $page = "http://www.phpbb.com/phpBB/viewtopic.php?p=")
{
	$handle = fopen($page.$id,"r");
	$topic_text = "";
	while ( !feof($handle) )
	{
		$topic_text .= fread($handle, 8192);
	}
	fclose($handle);
	$matches = array();
	preg_match("#MOD Version</span>:\s([0-9]+\.[0-9]+\.[0-9]+)#is",$topic_text,$matches);
	return $matches[1];
}
Example Page: http://luserkill.net/misc/ver.php?id=846925
The MOD used in the example page is this MOD.

afterlife_69
I've Been Banned!
Posts: 630
Joined: Tue Nov 30, 2004 10:35 am

Post by afterlife_69 » Thu Aug 11, 2005 2:58 pm

Updated with flamingcows code and gave him full credit.

Locked

Return to “[2.0.x] MOD Writers Discussion”