applied common formatting
This commit is contained in:
@ -7,10 +7,10 @@ use ManiaControl\Formatter;
|
||||
/**
|
||||
* Mania Exchange Map Info Object
|
||||
*
|
||||
* @author Xymph
|
||||
* @updated kremsy
|
||||
* @copyright ManiaControl Copyright © 2014 ManiaControl Team
|
||||
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
||||
* @author Xymph
|
||||
* @updated kremsy <kremsy@maniacontrol.com>
|
||||
* @copyright 2014 ManiaControl Team
|
||||
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
||||
*/
|
||||
class MXMapInfo {
|
||||
public $prefix, $id, $uid, $name, $userid, $author, $uploaded, $updated, $type, $maptype;
|
||||
@ -19,6 +19,7 @@ class MXMapInfo {
|
||||
public $replaytyp, $replayid, $replaycnt, $acomment, $awards, $comments;
|
||||
public $pageurl, $replayurl, $imageurl, $thumburl, $downloadurl, $dir;
|
||||
public $ratingVoteCount, $ratingVoteAverage;
|
||||
|
||||
/**
|
||||
* Returns map object with all available data from MX map data
|
||||
*
|
||||
@ -76,7 +77,7 @@ class MXMapInfo {
|
||||
$this->comments = $mx->CommentCount;
|
||||
|
||||
$this->ratingVoteCount = isset($mx->RatingVoteCount) ? $mx->RatingVoteCount : 0;
|
||||
$this->ratingVoteAverage = isset($mx->RatingVoteAverage) ? $mx->RatingVoteAverage : 0;
|
||||
$this->ratingVoteAverage = isset($mx->RatingVoteAverage) ? $mx->RatingVoteAverage : 0;
|
||||
|
||||
if ($this->trkvalue == 0 && $this->lbrating > 0) {
|
||||
$this->trkvalue = $this->lbrating;
|
||||
|
@ -29,9 +29,9 @@ use ManiaControl\Players\Player;
|
||||
/**
|
||||
* ManiaExchange List Widget Class
|
||||
*
|
||||
* @author steeffeen & kremsy
|
||||
* @copyright ManiaControl Copyright © 2014 ManiaControl Team
|
||||
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
||||
* @author ManiaControl Team <mail@maniacontrol.com>
|
||||
* @copyright 2014 ManiaControl Team
|
||||
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
||||
*/
|
||||
class ManiaExchangeList implements CallbackListener, ManialinkPageAnswerListener {
|
||||
/*
|
||||
@ -66,6 +66,33 @@ class ManiaExchangeList implements CallbackListener, ManialinkPageAnswerListener
|
||||
$this->maniaControl->manialinkManager->registerManialinkPageAnswerListener(self::ACTION_SEARCH_AUTHOR, $this, 'showList');
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle ManialinkPageAnswer Callback
|
||||
*
|
||||
* @param array $callback
|
||||
*/
|
||||
public function handleManialinkPageAnswer(array $callback) {
|
||||
$actionId = $callback[1][2];
|
||||
$actionArray = explode('.', $actionId);
|
||||
if (count($actionArray) <= 2) {
|
||||
return;
|
||||
}
|
||||
|
||||
$action = $actionArray[0] . '.' . $actionArray[1];
|
||||
$login = $callback[1][1];
|
||||
$player = $this->maniaControl->playerManager->getPlayer($login);
|
||||
$mapId = (int)$actionArray[2];
|
||||
|
||||
switch ($action) {
|
||||
case self::ACTION_GET_MAPS_FROM_AUTHOR:
|
||||
$callback[1][2] = 'auth:' . $actionArray[2];
|
||||
$this->showList($callback, $player);
|
||||
break;
|
||||
case self::ACTION_ADD_MAP:
|
||||
$this->maniaControl->mapManager->addMapFromMx($mapId, $player->login);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows the List
|
||||
@ -80,7 +107,7 @@ class ManiaExchangeList implements CallbackListener, ManialinkPageAnswerListener
|
||||
$author = '';
|
||||
$environment = '';
|
||||
if (count($params) >= 1) {
|
||||
foreach($params as $param) {
|
||||
foreach ($params as $param) {
|
||||
if ($param == '/xlist' || $param == MapCommands::ACTION_OPEN_XLIST) {
|
||||
continue;
|
||||
}
|
||||
@ -130,8 +157,8 @@ class ManiaExchangeList implements CallbackListener, ManialinkPageAnswerListener
|
||||
//Create ManiaLink
|
||||
$maniaLink = new ManiaLink(ManialinkManager::MAIN_MLID);
|
||||
$script = $maniaLink->getScript();
|
||||
$paging = new Paging();
|
||||
$script->addFeature($paging);
|
||||
$paging = new Paging();
|
||||
$script->addFeature($paging);
|
||||
|
||||
// Main frame
|
||||
$frame = $this->maniaControl->manialinkManager->styleManager->getDefaultListFrame($script, $paging);
|
||||
@ -151,7 +178,7 @@ class ManiaExchangeList implements CallbackListener, ManialinkPageAnswerListener
|
||||
$i = 0;
|
||||
$y = $height / 2 - 16;
|
||||
$pageFrames = array();
|
||||
foreach($maps as $map) { //TODO order possibilities
|
||||
foreach ($maps as $map) { //TODO order possibilities
|
||||
/** @var MxMapInfo $map */
|
||||
if (!isset($pageFrame)) {
|
||||
$pageFrame = new Frame();
|
||||
@ -162,7 +189,7 @@ class ManiaExchangeList implements CallbackListener, ManialinkPageAnswerListener
|
||||
array_push($pageFrames, $pageFrame);
|
||||
$y = $height / 2 - 16;
|
||||
|
||||
$paging->addPage($pageFrame);
|
||||
$paging->addPage($pageFrame);
|
||||
}
|
||||
|
||||
// Map Frame
|
||||
@ -179,7 +206,7 @@ class ManiaExchangeList implements CallbackListener, ManialinkPageAnswerListener
|
||||
|
||||
/** @var MxMapInfo $map */
|
||||
$time = Formatter::time_elapsed_string(strtotime($map->updated));
|
||||
$array = array('$s'. $map->id => $x + 3.5, '$s'. $map->name => $x + 12.5, '$s'. $map->author => $x + 59, '$s'. str_replace("Arena", "", $map->maptype) => $x + 103, '$s'. $map->mood => $x + 118, '$s'. $time => $x + 130);
|
||||
$array = array('$s' . $map->id => $x + 3.5, '$s' . $map->name => $x + 12.5, '$s' . $map->author => $x + 59, '$s' . str_replace("Arena", "", $map->maptype) => $x + 103, '$s' . $map->mood => $x + 118, '$s' . $time => $x + 130);
|
||||
$labels = $this->maniaControl->manialinkManager->labelLine($mapFrame, $array);
|
||||
/** @var Label_Text $authorLabel */
|
||||
$authorLabel = $labels[2];
|
||||
@ -195,8 +222,8 @@ class ManiaExchangeList implements CallbackListener, ManialinkPageAnswerListener
|
||||
$mxQuad->setX($x + 56);
|
||||
$mxQuad->setUrl($map->pageurl);
|
||||
$mxQuad->setZ(0.01);
|
||||
$description = 'View $<' . $map->name . '$> on Mania-Exchange';
|
||||
$mxQuad->addTooltipLabelFeature($descriptionLabel, $description);
|
||||
$description = 'View $<' . $map->name . '$> on Mania-Exchange';
|
||||
$mxQuad->addTooltipLabelFeature($descriptionLabel, $description);
|
||||
|
||||
if ($this->maniaControl->authenticationManager->checkPermission($player, MapManager::SETTING_PERMISSION_ADD_MAP)) {
|
||||
$addQuad = new Quad_Icons64x64_1();
|
||||
@ -208,8 +235,8 @@ class ManiaExchangeList implements CallbackListener, ManialinkPageAnswerListener
|
||||
$addQuad->setAction(self::ACTION_ADD_MAP . '.' . $map->id);
|
||||
$addQuad->setZ(0.01);
|
||||
|
||||
$description = 'Add-Map: $<' . $map->name . '$>';
|
||||
$addQuad->addTooltipLabelFeature($descriptionLabel, $description);
|
||||
$description = 'Add-Map: $<' . $map->name . '$>';
|
||||
$addQuad->addTooltipLabelFeature($descriptionLabel, $description);
|
||||
}
|
||||
|
||||
//Award Quad
|
||||
@ -230,7 +257,7 @@ class ManiaExchangeList implements CallbackListener, ManialinkPageAnswerListener
|
||||
}
|
||||
|
||||
//Map Karma
|
||||
$karma = $map->ratingVoteAverage / 100;
|
||||
$karma = $map->ratingVoteAverage / 100;
|
||||
$voteCount = $map->ratingVoteCount;
|
||||
if (is_numeric($karma) && $voteCount > 0) {
|
||||
$karmaGauge = new Gauge();
|
||||
@ -312,35 +339,6 @@ class ManiaExchangeList implements CallbackListener, ManialinkPageAnswerListener
|
||||
$this->maniaControl->manialinkManager->displayWidget($maniaLink, $player, 'ManiaExchangeList');
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle ManialinkPageAnswer Callback
|
||||
*
|
||||
* @param array $callback
|
||||
*/
|
||||
public function handleManialinkPageAnswer(array $callback) {
|
||||
$actionId = $callback[1][2];
|
||||
$actionArray = explode('.', $actionId);
|
||||
if (count($actionArray) <= 2) {
|
||||
return;
|
||||
}
|
||||
|
||||
$action = $actionArray[0] . '.' . $actionArray[1];
|
||||
$login = $callback[1][1];
|
||||
$player = $this->maniaControl->playerManager->getPlayer($login);
|
||||
$mapId = (int)$actionArray[2];
|
||||
|
||||
switch($action) {
|
||||
case self::ACTION_GET_MAPS_FROM_AUTHOR:
|
||||
$callback[1][2] = 'auth:' . $actionArray[2];
|
||||
$this->showList($callback, $player);
|
||||
break;
|
||||
case self::ACTION_ADD_MAP:
|
||||
$this->maniaControl->mapManager->addMapFromMx($mapId, $player->login);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Unset the player if he opened another Main Widget
|
||||
*
|
||||
@ -364,5 +362,4 @@ class ManiaExchangeList implements CallbackListener, ManialinkPageAnswerListener
|
||||
unset($this->mapListShown[$player->login]);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
@ -10,8 +10,8 @@ use Maniaplanet\DedicatedServer\Xmlrpc\NotInScriptModeException;
|
||||
/**
|
||||
* Mania Exchange Info Searcher Class
|
||||
*
|
||||
* @author steeffeen & kremsy
|
||||
* @copyright ManiaControl Copyright © 2014 ManiaControl Team
|
||||
* @author ManiaControl Team <mail@maniacontrol.com>
|
||||
* @copyright 2014 ManiaControl Team
|
||||
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
||||
*/
|
||||
class ManiaExchangeManager {
|
||||
@ -57,49 +57,6 @@ class ManiaExchangeManager {
|
||||
$this->maniaControl = $maniaControl;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Store Map Info from MX and store the mxid in the database and the mx info in the map object
|
||||
*
|
||||
* @param $mxMapInfos
|
||||
*/
|
||||
public function updateMapObjectsWithManiaExchangeIds($mxMapInfos) {
|
||||
$mysqli = $this->maniaControl->database->mysqli;
|
||||
// Save map data
|
||||
$saveMapQuery = "UPDATE `" . MapManager::TABLE_MAPS . "`
|
||||
SET `mxid` = ?
|
||||
WHERE `uid` = ?;";
|
||||
$saveMapStatement = $mysqli->prepare($saveMapQuery);
|
||||
if ($mysqli->error) {
|
||||
trigger_error($mysqli->error);
|
||||
return;
|
||||
}
|
||||
$saveMapStatement->bind_param('is', $mapMxId, $mapUId);
|
||||
foreach($mxMapInfos as $mxMapInfo) {
|
||||
/** @var MXMapInfo $mxMapInfo */
|
||||
$mapMxId = $mxMapInfo->id;
|
||||
$mapUId = $mxMapInfo->uid;
|
||||
$saveMapStatement->execute();
|
||||
if ($saveMapStatement->error) {
|
||||
trigger_error($saveMapStatement->error);
|
||||
}
|
||||
|
||||
//Take the uid out of the vector
|
||||
if (isset($this->mxIdUidVector[$mxMapInfo->id])) {
|
||||
$uid = $this->mxIdUidVector[$mxMapInfo->id];
|
||||
} else {
|
||||
$uid = $mxMapInfo->uid;
|
||||
}
|
||||
$map = $this->maniaControl->mapManager->getMapByUid($uid);
|
||||
if ($map) {
|
||||
// TODO: how does it come that $map can be empty here? we got an error report for that
|
||||
/** @var Map $map */
|
||||
$map->mx = $mxMapInfo;
|
||||
}
|
||||
}
|
||||
$saveMapStatement->close();
|
||||
}
|
||||
|
||||
/**
|
||||
* Unset Map by Mx Id
|
||||
*
|
||||
@ -138,7 +95,7 @@ class ManiaExchangeManager {
|
||||
}
|
||||
|
||||
$id = 0;
|
||||
foreach($maps as $map) {
|
||||
foreach ($maps as $map) {
|
||||
/** @var Map $map */
|
||||
$fetchMapStatement->bind_param('i', $map->index);
|
||||
$fetchMapStatement->execute();
|
||||
@ -182,37 +139,6 @@ class ManiaExchangeManager {
|
||||
$fetchMapStatement->close();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Map Info Asynchronously
|
||||
*
|
||||
* @param $id
|
||||
* @param $function
|
||||
* @return bool
|
||||
*/
|
||||
public function getMapInfo($id, $function) {
|
||||
// Get Title Prefix
|
||||
$titlePrefix = $this->maniaControl->mapManager->getCurrentMap()->getGame();
|
||||
|
||||
// compile search URL
|
||||
$url = 'http://api.mania-exchange.com/' . $titlePrefix . '/maps/?ids=' . $id;
|
||||
|
||||
return $this->maniaControl->fileReader->loadFile($url, function ($mapInfo, $error) use (&$function, $titlePrefix, $url) {
|
||||
$mxMapInfo = null;
|
||||
if ($error) {
|
||||
trigger_error($error);
|
||||
} else {
|
||||
$mxMapList = json_decode($mapInfo);
|
||||
if ($mxMapList === null) {
|
||||
trigger_error('Cannot decode searched JSON data from ' . $url);
|
||||
} else {
|
||||
$mxMapInfo = new MXMapInfo($titlePrefix, $mxMapList[0]);
|
||||
}
|
||||
}
|
||||
call_user_func($function, $mxMapInfo);
|
||||
}, "application/json");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the Whole MapList from MX by Mixed Uid and Id String fetch
|
||||
*
|
||||
@ -244,7 +170,7 @@ class ManiaExchangeManager {
|
||||
}
|
||||
|
||||
$maps = array();
|
||||
foreach($mxMapList as $map) {
|
||||
foreach ($mxMapList as $map) {
|
||||
if ($map) {
|
||||
$mxMapObject = new MXMapInfo($titlePrefix, $map);
|
||||
if ($mxMapObject) {
|
||||
@ -260,6 +186,78 @@ class ManiaExchangeManager {
|
||||
return $success;
|
||||
}
|
||||
|
||||
/**
|
||||
* Store Map Info from MX and store the mxid in the database and the mx info in the map object
|
||||
*
|
||||
* @param $mxMapInfos
|
||||
*/
|
||||
public function updateMapObjectsWithManiaExchangeIds($mxMapInfos) {
|
||||
$mysqli = $this->maniaControl->database->mysqli;
|
||||
// Save map data
|
||||
$saveMapQuery = "UPDATE `" . MapManager::TABLE_MAPS . "`
|
||||
SET `mxid` = ?
|
||||
WHERE `uid` = ?;";
|
||||
$saveMapStatement = $mysqli->prepare($saveMapQuery);
|
||||
if ($mysqli->error) {
|
||||
trigger_error($mysqli->error);
|
||||
return;
|
||||
}
|
||||
$saveMapStatement->bind_param('is', $mapMxId, $mapUId);
|
||||
foreach ($mxMapInfos as $mxMapInfo) {
|
||||
/** @var MXMapInfo $mxMapInfo */
|
||||
$mapMxId = $mxMapInfo->id;
|
||||
$mapUId = $mxMapInfo->uid;
|
||||
$saveMapStatement->execute();
|
||||
if ($saveMapStatement->error) {
|
||||
trigger_error($saveMapStatement->error);
|
||||
}
|
||||
|
||||
//Take the uid out of the vector
|
||||
if (isset($this->mxIdUidVector[$mxMapInfo->id])) {
|
||||
$uid = $this->mxIdUidVector[$mxMapInfo->id];
|
||||
} else {
|
||||
$uid = $mxMapInfo->uid;
|
||||
}
|
||||
$map = $this->maniaControl->mapManager->getMapByUid($uid);
|
||||
if ($map) {
|
||||
// TODO: how does it come that $map can be empty here? we got an error report for that
|
||||
/** @var Map $map */
|
||||
$map->mx = $mxMapInfo;
|
||||
}
|
||||
}
|
||||
$saveMapStatement->close();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Map Info Asynchronously
|
||||
*
|
||||
* @param $id
|
||||
* @param $function
|
||||
* @return bool
|
||||
*/
|
||||
public function getMapInfo($id, $function) {
|
||||
// Get Title Prefix
|
||||
$titlePrefix = $this->maniaControl->mapManager->getCurrentMap()->getGame();
|
||||
|
||||
// compile search URL
|
||||
$url = 'http://api.mania-exchange.com/' . $titlePrefix . '/maps/?ids=' . $id;
|
||||
|
||||
return $this->maniaControl->fileReader->loadFile($url, function ($mapInfo, $error) use (&$function, $titlePrefix, $url) {
|
||||
$mxMapInfo = null;
|
||||
if ($error) {
|
||||
trigger_error($error);
|
||||
} else {
|
||||
$mxMapList = json_decode($mapInfo);
|
||||
if ($mxMapList === null) {
|
||||
trigger_error('Cannot decode searched JSON data from ' . $url);
|
||||
} else {
|
||||
$mxMapInfo = new MXMapInfo($titlePrefix, $mxMapList[0]);
|
||||
}
|
||||
}
|
||||
call_user_func($function, $mxMapInfo);
|
||||
}, "application/json");
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch a MapList Asynchronously
|
||||
*
|
||||
@ -302,13 +300,13 @@ class ManiaExchangeManager {
|
||||
if ($titlePrefix != "tm") {
|
||||
$url .= '&minexebuild=' . self::MIN_EXE_BUILD;
|
||||
}
|
||||
|
||||
|
||||
// Get MapTypes
|
||||
try {
|
||||
$scriptInfos = $this->maniaControl->client->getModeScriptInfo();
|
||||
$mapTypes = $scriptInfos->compatibleMapTypes;
|
||||
$url .= '&mtype=' . $mapTypes;
|
||||
} catch(NotInScriptModeException $e) {
|
||||
} catch (NotInScriptModeException $e) {
|
||||
}
|
||||
|
||||
$success = $this->maniaControl->fileReader->loadFile($url, function ($mapInfo, $error) use (&$function, $titlePrefix) {
|
||||
@ -332,7 +330,7 @@ class ManiaExchangeManager {
|
||||
}
|
||||
|
||||
$maps = array();
|
||||
foreach($mxMapList as $map) {
|
||||
foreach ($mxMapList as $map) {
|
||||
if (!empty($map)) {
|
||||
array_push($maps, new MXMapInfo($titlePrefix, $map));
|
||||
}
|
||||
@ -352,7 +350,7 @@ class ManiaExchangeManager {
|
||||
* @return int
|
||||
*/
|
||||
private function getEnvironment($env) {
|
||||
switch($env) {
|
||||
switch ($env) {
|
||||
case 'TMCanyon':
|
||||
return 1;
|
||||
case 'TMStadium':
|
||||
|
Reference in New Issue
Block a user