Edit style / function

This commit is contained in:
hakasenyang
2016-12-11 03:56:06 +09:00
parent e2acd2d964
commit 07e09b9dc6
2 changed files with 67 additions and 23 deletions
+51 -18
View File
@@ -8,14 +8,19 @@
*/
private $Parser;
/**
* [$RealID transfer osu! UserID to ID]
* [$OsuID transfer osu! ID to UserID]
* @var [string]
*/
public $RealID, $OsuID;
/**
* [$PlayCount User Playcount]
* [$Performance User Performance]
* [$Rank User Ranking]
* [$Occupation Check user occupation]
* @var [string]
*/
private $OsuID, $PlayCount, $Performance, $Rank, $Occupation;
private $PlayCount, $Performance, $Rank, $Occupation;
/**
* [$mode osu! mode
* 0 = osu! standard (standard)
@@ -24,8 +29,10 @@
* 3 = osu!mania (mania)
* ]
* @var [int]
* [$occu User Occupation Data]
* @var [string]
*/
private $mode;
private $mode, $occu;
/**
* [$data_profile description]
* [$data_userdata description]
@@ -51,7 +58,7 @@
* ]
* @var [int]
*/
public function SelectMode($mode)
private function SelectMode($mode)
{
switch(strtolower($mode))
{
@@ -81,11 +88,17 @@
* [CheckUser Get osu! UserID]
* @param [string] $osuid [osu! ID]
*/
public function CheckUser($osuid)
public function CheckUser($osuid, $mode)
{
if ($osuid !== $this->OsuID && $osuid !== $this->RealID)
$this->ResetObject();
$this->SelectMode($mode);
// Transfer osu! ID to Num
$this->data_profile = $this->Parser->WEBParsing('https://osu.ppy.sh/u/' . $osuid);
$this->OsuID = $this->Parser->splits($this->data_profile, 'var userId = ', ';');
$this->RealID = $this->Parser->splits($this->data_profile, '<title>', '\'s profile</title>');
if(empty($this->OsuID))
return false;
@@ -94,22 +107,49 @@
}
public function CheckOccupation()
{
/**
* md5 = $OsuID|date('Ymd')|$mode
* 20 string (substr)
*/
$occu = substr(md5($this->OsuID.'|' . date('Ymd') . '|' . $this->mode), 0, 20);
if ($occu === $this->Occupation)
if(empty($this->OsuID))
throw new \Exception('Please, CheckUser(OsuID) first!');
if(empty($this->occu))
$this->GetOccupation();
if ($this->occu === $this->Occupation)
return true;
else
return $occu;
return $this->Occupation;
}
public function GetOccupation()
{
/**
* md5 = $RealID / $OsuID / date('Ymd') / $mode
* 20 string (substr)
*/
if(empty($this->OsuID))
throw new \Exception('Please, CheckUser(OsuID) first!');
if(empty($this->occu))
$this->occu = substr(md5($this->RealID . $this->OsuID . date('Ymd') . $this->mode), 0, 20);
return $this->occu;
}
private function GetUserData()
{
if(empty($this->OsuID))
throw new \Exception('Please, CheckUser(OsuID) first!');
if(empty($this->data_userdata))
$this->data_userdata = $this->Parser->WEBParsing('https://osu.ppy.sh/pages/include/profile-general.php?u=' . $this->OsuID . '&m=' . $this->mode);
else
return true;
if (strpos($this->data_userdata, 'This user has not yet played any ranked maps in osu! mode.') === true)
return false;
if (strpos($this->data_userdata, 'This user has not played enough, or has not played recently.') === false)
{
$this->PlayCount = $this->Parser->splits($this->data_userdata, '<b>Play Count</b>: ', '</div>');
$this->Performance = str_replace(',', NULL, $this->Parser->splits($this->data_userdata, 'Performance</a>: ', 'pp'));
$this->Rank = str_replace(',', NULL, $this->Parser->splits($this->data_userdata, 'pp (#', ')'));
}
else
return false;
}
/**
* [CheckPlayCount Get PlayCount]
@@ -117,23 +157,16 @@
public function CheckPlayCount()
{
$this->GetUserData();
$this->PlayCount = $this->Parser->splits($this->data_userdata, '<b>Play Count</b>: ', '</div>');
return $this->PlayCount;
}
public function CheckPerformance()
{
$this->GetUserData();
if (strpos($this->data_userdata, 'This user has not played enough, or has not played recently.'))
return false;
$this->Performance = str_replace(',', NULL, $this->Parser->splits($this->data_userdata, 'Performance</a>: ', 'pp'));
return $this->Performance;
}
public function CheckRank()
{
$this->GetUserData();
if (strpos($this->data_userdata, 'This user has not played enough, or has not played recently.'))
return false;
$this->Rank = str_replace(',', NULL, $this->Parser->splits($this->data_userdata, 'pp (#', ')'));
return $this->Rank;
}
public function ResetObject()
+16 -5
View File
@@ -1,20 +1,31 @@
<?php
require_once 'include.php';
$Check = new OsuTournament\Check();
$Check->SelectMode(0);
echo $Check->CheckUser('peppy');
$Check->CheckUser(2558286, 0);
echo $Check->RealID . ' (' . $Check->OsuID . ')';
$occu = $Check->CheckOccupation();
if ($Check->CheckOccupation() === true)
echo '<br>You are applied!';
else
echo '<br>Please change occupation to ' . $Check->CheckOccupation();
echo '<br>Please change occupation to ' . $Check->GetOccupation() . '<br>Your Occupation : ' . $occu;
echo '<br>';
if (empty($Check->CheckPerformance()))
echo 'Error<br>';
echo 'Performance : ' . $Check->CheckPerformance();
echo '<br>';
echo 'Ranking : ' . $Check->CheckRank();
echo '<br><br>';
$Check->ResetObject();
$Check->CheckUser('Angelsim', 0);
echo $Check->RealID . ' (' . $Check->OsuID . ')';
$occu = $Check->CheckOccupation();
echo $Check->CheckUser('ExampleToNotUser');
if ($Check->CheckOccupation() === true)
echo '<br>You are applied!';
else
echo '<br>Please change occupation to ' . $Check->GetOccupation() . '<br>Your Occupation : ' . $occu;
echo '<br>';
echo 'Performance : ' . $Check->CheckPerformance();