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; private $Parser;
/** /**
* [$RealID transfer osu! UserID to ID]
* [$OsuID transfer osu! ID to UserID] * [$OsuID transfer osu! ID to UserID]
* @var [string]
*/
public $RealID, $OsuID;
/**
* [$PlayCount User Playcount] * [$PlayCount User Playcount]
* [$Performance User Performance] * [$Performance User Performance]
* [$Rank User Ranking] * [$Rank User Ranking]
* [$Occupation Check user occupation] * [$Occupation Check user occupation]
* @var [string] * @var [string]
*/ */
private $OsuID, $PlayCount, $Performance, $Rank, $Occupation; private $PlayCount, $Performance, $Rank, $Occupation;
/** /**
* [$mode osu! mode * [$mode osu! mode
* 0 = osu! standard (standard) * 0 = osu! standard (standard)
@@ -24,8 +29,10 @@
* 3 = osu!mania (mania) * 3 = osu!mania (mania)
* ] * ]
* @var [int] * @var [int]
* [$occu User Occupation Data]
* @var [string]
*/ */
private $mode; private $mode, $occu;
/** /**
* [$data_profile description] * [$data_profile description]
* [$data_userdata description] * [$data_userdata description]
@@ -51,7 +58,7 @@
* ] * ]
* @var [int] * @var [int]
*/ */
public function SelectMode($mode) private function SelectMode($mode)
{ {
switch(strtolower($mode)) switch(strtolower($mode))
{ {
@@ -81,11 +88,17 @@
* [CheckUser Get osu! UserID] * [CheckUser Get osu! UserID]
* @param [string] $osuid [osu! ID] * @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 // Transfer osu! ID to Num
$this->data_profile = $this->Parser->WEBParsing('https://osu.ppy.sh/u/' . $osuid); $this->data_profile = $this->Parser->WEBParsing('https://osu.ppy.sh/u/' . $osuid);
$this->OsuID = $this->Parser->splits($this->data_profile, 'var userId = ', ';'); $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)) if(empty($this->OsuID))
return false; return false;
@@ -94,22 +107,49 @@
} }
public function CheckOccupation() public function CheckOccupation()
{ {
/** if(empty($this->OsuID))
* md5 = $OsuID|date('Ymd')|$mode throw new \Exception('Please, CheckUser(OsuID) first!');
* 20 string (substr) if(empty($this->occu))
*/ $this->GetOccupation();
$occu = substr(md5($this->OsuID.'|' . date('Ymd') . '|' . $this->mode), 0, 20);
if ($occu === $this->Occupation) if ($this->occu === $this->Occupation)
return true; return true;
else 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() private function GetUserData()
{ {
if(empty($this->OsuID)) if(empty($this->OsuID))
throw new \Exception('Please, CheckUser(OsuID) first!'); throw new \Exception('Please, CheckUser(OsuID) first!');
if(empty($this->data_userdata)) 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); $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] * [CheckPlayCount Get PlayCount]
@@ -117,23 +157,16 @@
public function CheckPlayCount() public function CheckPlayCount()
{ {
$this->GetUserData(); $this->GetUserData();
$this->PlayCount = $this->Parser->splits($this->data_userdata, '<b>Play Count</b>: ', '</div>');
return $this->PlayCount; return $this->PlayCount;
} }
public function CheckPerformance() public function CheckPerformance()
{ {
$this->GetUserData(); $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; return $this->Performance;
} }
public function CheckRank() public function CheckRank()
{ {
$this->GetUserData(); $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; return $this->Rank;
} }
public function ResetObject() public function ResetObject()
+16 -5
View File
@@ -1,20 +1,31 @@
<?php <?php
require_once 'include.php'; require_once 'include.php';
$Check = new OsuTournament\Check(); $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) if ($Check->CheckOccupation() === true)
echo '<br>You are applied!'; echo '<br>You are applied!';
else else
echo '<br>Please change occupation to ' . $Check->CheckOccupation(); echo '<br>Please change occupation to ' . $Check->GetOccupation() . '<br>Your Occupation : ' . $occu;
echo '<br>'; echo '<br>';
if (empty($Check->CheckPerformance()))
echo 'Error<br>';
echo 'Performance : ' . $Check->CheckPerformance(); echo 'Performance : ' . $Check->CheckPerformance();
echo '<br>'; echo '<br>';
echo 'Ranking : ' . $Check->CheckRank(); 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 '<br>';
echo 'Performance : ' . $Check->CheckPerformance(); echo 'Performance : ' . $Check->CheckPerformance();