improved mxinfosearcher

This commit is contained in:
kremsy 2014-01-08 22:15:36 +01:00
parent 8854d4ac58
commit 0d7f02a89a
3 changed files with 134 additions and 47 deletions

View File

@ -45,9 +45,6 @@ class ManiaExchangeInfoSearcher {
$mapTypes = $scriptInfos["CompatibleMapTypes"]; $mapTypes = $scriptInfos["CompatibleMapTypes"];
$mapTypeArray = explode(",", $mapTypes); $mapTypeArray = explode(",", $mapTypes);
var_dump($mapTypes);
var_dump($mapTypeArray);
// compile search URL // compile search URL
$url = 'http://' . $titlePrefix . '.mania-exchange.com/tracksearch?api=on'; $url = 'http://' . $titlePrefix . '.mania-exchange.com/tracksearch?api=on';
/* if ($name != '') /* if ($name != '')
@ -60,13 +57,13 @@ class ManiaExchangeInfoSearcher {
} }
$url .= '&priord=' . $searchOrder; $url .= '&priord=' . $searchOrder;
$url .= '&limit=' . 1; //TODO $url .= '&limit=' . $maxMapsReturned; //TODO
$url .= '&mtype=' . $mapTypeArray[0]; $url .= '&mtype=' . $mapTypeArray[0];
// $mapInfo = FileUtil::loadFile($url, "application/json"); //TODO use mp fileutil // $mapInfo = FileUtil::loadFile($url, "application/json"); //TODO use mp fileutil
$mapInfo = $this->get_file($url); $mapInfo = $this->get_file($url);
var_dump($url); var_dump($url);
return;
//TODO errors //TODO errors
/*if ($file === false) { /*if ($file === false) {
$this->error = 'Connection or response error on ' . $url; $this->error = 'Connection or response error on ' . $url;
@ -90,16 +87,12 @@ class ManiaExchangeInfoSearcher {
return null; return null;
} }
$maps = array(); $maps = array();
foreach($mxMapList as $map) { foreach($mxMapList as $map) {
var_dump($map);
if(!empty($map)) { if(!empty($map)) {
array_push($maps, new MXInfo($titlePrefix, $map)); array_push($maps, new MXMapInfo($titlePrefix, $map));
} }
} }
var_dump($maps);
return $maps; return $maps;
} }
@ -151,16 +144,9 @@ class ManiaExchangeInfoSearcher {
} }
class MXInfo { class MXMapInfo {
public $section, $prefix, $id, public $prefix, $id, $name, $userid, $author, $uploaded, $updated, $type, $maptype, $titlepack, $style, $envir, $mood, $dispcost, $lightmap, $modname, $exever, $exebld, $routes, $length, $unlimiter, $laps, $diffic, $lbrating, $trkvalue, $replaytyp, $replayid, $replaycnt, $acomment, $awards, $comments, $rating, $ratingex, $ratingcnt, $pageurl, $replayurl, $imageurl, $thumburl, $dloadurl;
$name, $userid, $author, $uploaded, $updated,
$type, $maptype, $titlepack, $style, $envir, $mood,
$dispcost, $lightmap, $modname,
$exever, $exebld, $routes, $length, $unlimiter, $laps, $diffic,
$lbrating, $trkvalue, $replaytyp, $replayid, $replaycnt,
$acomment, $awards, $comments, $rating, $ratingex, $ratingcnt,
$pageurl, $replayurl, $imageurl, $thumburl, $dloadurl;
/** /**
* Returns map object with all available data from MX map data * Returns map object with all available data from MX map data
@ -169,24 +155,28 @@ class MXInfo {
* MX URL prefix * MX URL prefix
* @param Object $map * @param Object $map
* The MX map data from MXInfoSearcher * The MX map data from MXInfoSearcher
* @return MXInfo * @return MXMapInfo
*/ */
public function MXInfo($prefix, $mx) { public function __construct($prefix, $mx) {
$this->prefix = $prefix; $this->prefix = $prefix;
if($mx) { if($mx) {
if ($this->prefix == 'tm') if($this->prefix == 'tm') {
$dir = 'tracks'; $dir = 'tracks';
else // 'sm' || 'qm' } else // 'sm' || 'qm'
{
$dir = 'maps'; $dir = 'maps';
}
//temporary fix //temporary fix
if($this->prefix == 'tm' || !property_exists($mx, "MapID")) if($this->prefix == 'tm' || !property_exists($mx, "MapID")) {
$this->id = $mx->TrackID; $this->id = $mx->TrackID;
else } else {
$this->id = $mx->MapID; $this->id = $mx->MapID;
}
// $this->id = ($this->prefix == 'tm') ? $mx->TrackID : $mx->MapID; // $this->id = ($this->prefix == 'tm') ? $mx->TrackID : $mx->MapID;
$this->name = $mx->Name; $this->name = $mx->Name;
$this->userid = $mx->UserID; $this->userid = $mx->UserID;
$this->author = $mx->Username; $this->author = $mx->Username;
$this->uploaded = $mx->UploadedAt; $this->uploaded = $mx->UploadedAt;
@ -219,10 +209,11 @@ class MXInfo {
$this->ratingex = isset($mx->RatingExact) ? $mx->RatingExact : 0.0; $this->ratingex = isset($mx->RatingExact) ? $mx->RatingExact : 0.0;
$this->ratingcnt = isset($mx->RatingCount) ? $mx->RatingCount : 0; $this->ratingcnt = isset($mx->RatingCount) ? $mx->RatingCount : 0;
if ($this->trkvalue == 0 && $this->lbrating > 0) if($this->trkvalue == 0 && $this->lbrating > 0) {
$this->trkvalue = $this->lbrating; $this->trkvalue = $this->lbrating;
elseif ($this->lbrating == 0 && $this->trkvalue > 0) } elseif($this->lbrating == 0 && $this->trkvalue > 0) {
$this->lbrating = $this->trkvalue; $this->lbrating = $this->trkvalue;
}
$search = array(chr(31), '[b]', '[/b]', '[i]', '[/i]', '[u]', '[/u]', '[url]', '[/url]'); $search = array(chr(31), '[b]', '[/b]', '[i]', '[/i]', '[u]', '[/u]', '[url]', '[/url]');
$replace = array('<br/>', '<b>', '</b>', '<i>', '</i>', '<u>', '</u>', '<i>', '</i>'); $replace = array('<br/>', '<b>', '</b>', '<i>', '</i>', '<u>', '</u>', '<i>', '</i>');
@ -239,6 +230,8 @@ class MXInfo {
} else { } else {
$this->replayurl = ''; $this->replayurl = '';
} }
//var_dump($this->pageurl);
} }
} // MXInfo } // MXInfo
} // class MXInfo } // class MXInfo

View File

@ -227,3 +227,99 @@ class MXInfoSearcher implements Iterator,Countable {
} // class MXInfoSearcher } // class MXInfoSearcher
class MXInfo {
public $section, $prefix, $id,
$name, $userid, $author, $uploaded, $updated,
$type, $maptype, $titlepack, $style, $envir, $mood,
$dispcost, $lightmap, $modname,
$exever, $exebld, $routes, $length, $unlimiter, $laps, $diffic,
$lbrating, $trkvalue, $replaytyp, $replayid, $replaycnt,
$acomment, $awards, $comments, $rating, $ratingex, $ratingcnt,
$pageurl, $replayurl, $imageurl, $thumburl, $dloadurl;
/**
* Returns map object with all available data from MX map data
*
* @param String $section
* MX section
* @param String $prefix
* MX URL prefix
* @param Object $map
* The MX map data from MXInfoSearcher
* @return MXInfo
*/
public function MXInfo($section, $prefix, $mx) {
$this->section = $section;
$this->prefix = $prefix;
if ($mx) {
if ($this->prefix == 'tm')
$dir = 'tracks';
else // 'sm' || 'qm'
$dir = 'maps';
//temporary fix
if($this->prefix == 'tm' || !property_exists($mx, "MapID"))
$this->id = $mx->TrackID;
else
$this->id = $mx->MapID;
// $this->id = ($this->prefix == 'tm') ? $mx->TrackID : $mx->MapID;
$this->name = $mx->Name;
$this->userid = $mx->UserID;
$this->author = $mx->Username;
$this->uploaded = $mx->UploadedAt;
$this->updated = $mx->UpdatedAt;
$this->type = $mx->TypeName;
$this->maptype = isset($mx->MapType) ? $mx->MapType : '';
$this->titlepack = isset($mx->TitlePack) ? $mx->TitlePack : '';
$this->style = isset($mx->StyleName) ? $mx->StyleName : '';
$this->envir = $mx->EnvironmentName;
$this->mood = $mx->Mood;
$this->dispcost = $mx->DisplayCost;
$this->lightmap = $mx->Lightmap;
$this->modname = isset($mx->ModName) ? $mx->ModName : '';
$this->exever = $mx->ExeVersion;
$this->exebld = $mx->ExeBuild;
$this->routes = isset($mx->RouteName) ? $mx->RouteName : '';
$this->length = isset($mx->LengthName) ? $mx->LengthName : '';
$this->unlimiter = isset($mx->UnlimiterRequired) ? $mx->UnlimiterRequired : false;
$this->laps = isset($mx->Laps) ? $mx->Laps : 0;
$this->diffic = $mx->DifficultyName;
$this->lbrating = isset($mx->LBRating) ? $mx->LBRating : 0;
$this->trkvalue = isset($mx->TrackValue) ? $mx->TrackValue : 0;
$this->replaytyp = isset($mx->ReplayTypeName) ? $mx->ReplayTypeName : '';
$this->replayid = isset($mx->ReplayWRID) ? $mx->ReplayWRID : 0;
$this->replaycnt = isset($mx->ReplayCount) ? $mx->ReplayCount : 0;
$this->acomment = $mx->Comments;
$this->awards = isset($mx->AwardCount) ? $mx->AwardCount : 0;
$this->comments = $mx->CommentCount;
$this->rating = isset($mx->Rating) ? $mx->Rating : 0.0;
$this->ratingex = isset($mx->RatingExact) ? $mx->RatingExact : 0.0;
$this->ratingcnt = isset($mx->RatingCount) ? $mx->RatingCount : 0;
if ($this->trkvalue == 0 && $this->lbrating > 0)
$this->trkvalue = $this->lbrating;
elseif ($this->lbrating == 0 && $this->trkvalue > 0)
$this->lbrating = $this->trkvalue;
$search = array(chr(31), '[b]', '[/b]', '[i]', '[/i]', '[u]', '[/u]', '[url]', '[/url]');
$replace = array('<br/>', '<b>', '</b>', '<i>', '</i>', '<u>', '</u>', '<i>', '</i>');
$this->acomment = str_ireplace($search, $replace, $this->acomment);
$this->acomment = preg_replace('/\[url=.*\]/', '<i>', $this->acomment);
$this->pageurl = 'http://' . $this->prefix . '.mania-exchange.com/' . $dir . '/view/' . $this->id;
$this->imageurl = 'http://' . $this->prefix . '.mania-exchange.com/' . $dir . '/screenshot/normal/' . $this->id;
$this->thumburl = 'http://' . $this->prefix . '.mania-exchange.com/' . $dir . '/screenshot/small/' . $this->id;
$this->dloadurl = 'http://' . $this->prefix . '.mania-exchange.com/' . $dir . '/download/' . $this->id;
if ($this->prefix == 'tm' && $this->replayid > 0) {
$this->replayurl = 'http://' . $this->prefix . '.mania-exchange.com/replays/download/' . $this->replayid;
} else {
$this->replayurl = '';
}
}
} // MXInfo
} // class MXInfo

View File

@ -157,8 +157,6 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
$i = 0; $i = 0;
$y -= 10; $y -= 10;
foreach($maps as $map) { foreach($maps as $map) {
var_dump($map);
return;
$mapFrame = new Frame(); $mapFrame = new Frame();
$frame->add($mapFrame); $frame->add($mapFrame);
$array = array($map->id => $x + 5, $map->name => $x + 17, $map->author => $x + 65, $map->mood => $x + 100, $map->maptype => $x + 115); $array = array($map->id => $x + 5, $map->name => $x + 17, $map->author => $x + 65, $map->mood => $x + 100, $map->maptype => $x + 115);