I want some kind of review on this simple algoritm. It's pretty messy and I would like to know what I can do better. I had a hard time getting good variablenames for example.
This class reads from pages in Goldeneye ranking on the-elite.net. http://www.the-elite.net/GE/stage12.htm for example it looks up the name and returns the points the time is worth from the three diffrent difficults.
Code: Select all
<?php
class Goldeneye
{
var $homepage;
var $a;
var $sa;
var $ooa;
var $tr;
var $endtr;
var $nextrow;
var $data;
var $check;
/**********************
Function name: Goldeneye()
Description: Constructor
Purpose: Set values to the variables.
Arguments: Nothing
Returns: Nothing
************************/
function Goldeneye()
{
$this->a = 0;
$this->sa = 0;
$this->ooa = 0;
$this->tr = 0;
$this->endtr = 0;
$this->nextrow = 0;
$this->check = 0;
$this->homepage = "http://www.the-elite.net/GE/";
}
/**********************
Function name: GetColor()
Description: Get colors from ranking.
Purpose: Get colors from external homepage.
Arguments: $stage, $player
Returns: $apoints, $sapoints, $ooapoints
************************/
function GetColor($stage, $player)
{
if($stage == "all")
{
GetAllColor();
}
$fp = fopen($this->homepage . $stage . ".htm", 'r');
while(!feof($fp))
{
$this->data = fgets($fp, 1024);
if(stristr($this->data, "</tr>"))
{
$this->endtr = 1;
$this->tr = 0;
}
if($this->nextrow == 1)
{
if($this->check == 1)
{
if($this->endtr == 1)
{
$tempooa = $temp;
$this->check = 0;
$this->nextrow = 0;
$this->endtr = 0;
}
elseif($this->endtr == 0)
{
$tempsa = $temp;
$this->check = 0;
$this->nextrow = 0;
}
}
elseif($this->tr == 1)
{
$tempa = $this->data;
$this->tr = 0;
$this->nextrow = 0;
}
else
{
$temp = $this->data;
$this->check = 1;
}
}
if(stristr($this->data, "<tr>"))
{
$this->tr = 1;
$this->endtr = 0;
}
elseif(stristr($this->data, " <font color=\"#FFFF80\">"))
{
$this->tr = 0;
}
elseif(stristr($this->data, "$player</td>"))
{
$this->nextrow = 1;
}
}
fclose($fp);
$this->a = substr($tempa,-8,2);
$this->sa = substr($tempsa,-8,2);
$this->ooa = substr($tempooa,-8,2);
if($this->a == "00")
{
$this->a = 100;
}
elseif($this->sa == "00")
{
$this->sa = 100;
}
elseif($this->ooa == "00")
{
$this->ooa = 100;
}
return array ($this->a, $this->sa, $this->ooa);
}
}
?>Code: Select all
<?php
include("inc/class_goldeneye.php");
$Goldeneye = new Goldeneye();
$result = $Goldeneye->GetColor("stage1", "Patrik Nilsson");
$result = $Goldeneye->GetColor("stage3", "Axel Andersson");
?>