コード例 #1
0
ファイル: OsuAPI.php プロジェクト: BTCTaras/osusig
 /**
  * Gets user information for a specific game mode
  *
  * @param string $username The player's username
  * @param string [$mode] The game mode
  *
  * @return array|bool
  */
 public function getUserForMode($username, $mode = 0)
 {
     if ($mode < 4) {
         $user = $this->mc->get("osusigv3_user_" . $mode . "_" . strtolower($username));
         if (!$user) {
             $request = $this->request('get_user', ['u' => $username, 'm' => $mode]);
             if (isset($request) && isset($request[0])) {
                 $this->mc->set("osusigv3_user_" . $mode . "_" . strtolower($username), $request[0], 180);
                 return $request[0];
             }
         } else {
             return $user;
         }
         return false;
     } else {
         $errorImage = new ErrorImage();
         $errorImage->generate("Invalid mode", "You specified an invalid mode\nfor the signature.");
         return false;
     }
     return false;
 }
コード例 #2
0
ファイル: TemplateNormal.php プロジェクト: BTCTaras/osusig
 public function __construct(OsuSignature $signature)
 {
     parent::__construct($signature);
     $user = $signature->getUser();
     $this->setCard(new CardRegular($user));
     $isCountryRank = isset($_GET['countryrank']);
     $removeAvatarMargin = isset($_GET['removeavmargin']);
     $showPP = isset($_GET['pp']);
     $pp = $showPP ? $_GET['pp'] : -1;
     $darkHeader = isset($_GET['darkheader']);
     $showRankedScore = isset($_GET['rankedscore']);
     $showXPBar = isset($_GET['xpbar']);
     if ($showPP && ($pp < 0 || $pp > 3)) {
         $errorImage = new ErrorImage();
         $errorImage->generate("Invalid parameter", "Parameter 'pp' has an\ninvalid value");
     }
     $userRank = $user['pp_rank'];
     $userRank = $userRank ? $userRank : '?';
     $userCountryRank = $user['pp_country_rank'];
     $userCountryRank = $userCountryRank ? $userCountryRank : '?';
     $mode = isset($_GET['mode']) ? $_GET['mode'] : 'osu';
     $iconmode = 0;
     switch ($mode) {
         case 0:
             $mode = 'osu';
             $iconmode = 0;
             break;
         case 1:
             $mode = 'taiko';
             $iconmode = 3;
             break;
         case 2:
             $mode = 'ctb';
             $iconmode = 2;
             break;
         case 3:
             $mode = 'mania';
             $iconmode = 1;
             break;
     }
     $username = $user['username'];
     $ppText = $user['pp_raw'];
     $accuracy = $user['accuracy'];
     $playcount = $user['playcount'];
     $level = $user['level'];
     $headerTextColour = $darkHeader ? '#555555' : '#FFFFFF';
     $avatar = new ComponentAvatar($signature, CardRegular::SIG_MARGIN + ($removeAvatarMargin ? 4 : 6), CardRegular::SIG_MARGIN + ($removeAvatarMargin ? 4 : 6), $removeAvatarMargin ? 80 : 76, $removeAvatarMargin ? 80 : 76);
     $rank = new ComponentLabel($signature, $isCountryRank ? 325 : 287, 32, '#' . number_format($userRank) . ($isCountryRank ? " (" . '#' . number_format($userCountryRank) . ')' : ""), ComponentLabel::FONT_REGULAR, $headerTextColour, $isCountryRank ? 12 : 14, \Imagick::ALIGN_RIGHT, 0);
     $mode = new ComponentLabel($signature, $isCountryRank ? 313 : 290, $isCountryRank ? 18 : 31, json_decode('"\\ue00' . $iconmode . '"'), ComponentLabel::FONT_OSU, $headerTextColour, $isCountryRank ? 12 : 14, \Imagick::ALIGN_LEFT, $isCountryRank ? 12 : 14);
     $flag = new ComponentFlag($signature, $isCountryRank ? 294 : 307, $isCountryRank ? 10 : 21, $isCountryRank ? 13 : 18, $isCountryRank ? 9 : 12);
     $nameFontSize = 24;
     $nameFont = ComponentLabel::FONT_DIRECTORY . ComponentLabel::FONT_MEDIUM;
     $nameDimensions = imagettfbbox(static::getGDFontSize($nameFontSize), 0, $nameFont, $username);
     $nameTextWidth = abs($nameDimensions[4] - $nameDimensions[0]);
     while ($nameTextWidth > ($isCountryRank ? 235 : 198) - $rank->getActualWidth()) {
         $nameDimensions = imagettfbbox(static::getGDFontSize($nameFontSize), 0, $nameFont, $username);
         $nameTextWidth = abs($nameDimensions[4] - $nameDimensions[0]);
         $nameFontSize -= 0.5;
     }
     $name = new ComponentLabel($signature, 90, 32, $username, ComponentLabel::FONT_MEDIUM, $headerTextColour, $nameFontSize, \Imagick::ALIGN_LEFT, -2);
     $accuracyLabel = new ComponentLabel($signature, 91, 56, "Accuracy", ComponentLabel::FONT_REGULAR, '#555555', 14, \Imagick::ALIGN_LEFT);
     $playCountLabel = new ComponentLabel($signature, 91, 73, $showRankedScore ? "Ranked Score" : "Play Count", ComponentLabel::FONT_REGULAR, '#555555', 14, \Imagick::ALIGN_LEFT);
     $accuracyText = round($accuracy, 2) . '%' . ($showPP && $pp == 1 ? ' (' . number_format(floor($ppText)) . 'pp)' : '');
     $accuracyValueLabel = new ComponentLabel($signature, 325, 56, $accuracyText, ComponentLabel::FONT_BOLD, '#555555', 14, \Imagick::ALIGN_RIGHT, -2);
     $playCountText = number_format($playcount) . ($showPP && $pp == 0 ? ' (' . number_format(floor($ppText)) . 'pp)' : ($showXPBar ? '' : ' (lv' . floor($level) . ')'));
     $playCountValueLabel = new ComponentLabel($signature, 325, 73, $showRankedScore ? Utils::largeNumberFormat($user['ranked_score']) : $playCountText, ComponentLabel::FONT_BOLD, '#555555', 14, \Imagick::ALIGN_RIGHT, -2);
     $this->addComponent($avatar);
     $this->addComponent($rank);
     $this->addComponent($mode);
     $this->addComponent($flag);
     $this->addComponent($name);
     $this->addComponent($accuracyLabel);
     $this->addComponent($playCountLabel);
     $this->addComponent($accuracyValueLabel);
     $this->addComponent($playCountValueLabel);
     if ($showPP && $pp == 2) {
         $ppLabel = new ComponentLabel($signature, $isCountryRank ? 290 : 326, 18, number_format(floor($ppText)) . 'pp', ComponentLabel::FONT_REGULAR, $headerTextColour, 10, \Imagick::ALIGN_RIGHT, -2);
         $this->addComponent($ppLabel);
     }
     $onlineIndicator = isset($_GET['onlineindicator']) ? $_GET['onlineindicator'] : false;
     $online = $onlineIndicator == 2 || $onlineIndicator == 3 ? Utils::isUserOnline($user['username']) : false;
     if ($online) {
         $onlineIndicatorImage = new ComponentImage($signature, $avatar->x + $avatar->getWidth() - 17, $avatar->y + $avatar->getHeight() - 17, ComponentImage::IMG_DIRECTORY . 'online_indicator.png');
         $this->addComponent($onlineIndicatorImage);
     }
     if ($showXPBar) {
         $xpBar = new ComponentXPBar($signature, 92, 79, isset($_GET['xpbarhex']) ? '' : '#ffa200', 233, 4);
         $this->addComponent($xpBar);
     }
     // I don't know either.
     $this->extraWidth = CardRegular::SIG_MARGIN * 2 + 1;
     $this->extraHeight = $removeAvatarMargin ? 1 : 3;
 }
コード例 #3
0
 public function run()
 {
     $bDebug = defined('DEBUG') && DEBUG;
     try {
         // get profile URL
         $sXmlUrl = $this->getProfileUrl(false);
         // load config
         $oCommonConfig = FileConfig::getInstance('common.cfg');
         $oImageConfig = FileConfig::getInstance('image.cfg');
         $oGPCConfig = GPCConfig::getInstance('get');
         // load config vars
         $iCacheLifetime = $oCommonConfig->getInteger('cache.lifetime', 600);
         $sCacheDir = $oCommonConfig->getString('cache.dir', 'cache');
         $bImageFallback = $oImageConfig->getString('image.fallback', true);
         $sDefaultLayout = $oImageConfig->getString('image.layout.default', 'small');
         $sDefaultTheme = $oImageConfig->getString('image.theme.default', 'default');
         $sLayout = $oGPCConfig->getStringAlnum('layout', $sDefaultLayout);
         $sTheme = $oGPCConfig->getStringAlnum('theme', $sDefaultTheme);
         // init cache
         $oImageCache = new Cache($sCacheDir, $iCacheLifetime, 'png');
         $oImageFile = $oImageCache->getFile($_SERVER['QUERY_STRING']);
         $sImageBase = 'image/layouts';
         if (!file_exists("{$sImageBase}/{$sLayout}")) {
             if (!file_exists("{$sImageBase}/{$sDefaultLayout}")) {
                 throw new RuntimeException('Default layout folder not found');
             }
             $sLayout = $sDefaultLayout;
         }
         $sLayoutDir = "{$sImageBase}/{$sLayout}";
         include "{$sLayoutDir}/SteamProfileImage.php";
         try {
             // do we have a cached version of the profile image?
             if (!$oImageFile->isCached()) {
                 $oProfileImage = new SteamProfileImage();
                 // try to generate the profile image
                 $oProfileImage->createProfile($sXmlUrl, $sLayoutDir, $sTheme);
                 // save it to cache
                 $oProfileImage->toPng($oImageFile->getPath());
                 // clear stat cache to ensure that the rest of the
                 // script will notice the file modification
                 clearstatcache();
             }
             $this->displayImage($oImageFile);
         } catch (SteamProfileImageException $e) {
             // on debug mode, re-throw
             if ($bDebug) {
                 $ep = $e->getPrevious();
                 throw $ep == null ? $e : $ep;
             }
             // an exception was thrown in SteamProfileImage,
             // but a themed error image could have been generated
             try {
                 // try a fallback to the cached image first
                 if ($bImageFallback && $oImageFile->exists()) {
                     $this->displayImage($oImageFile);
                 } else {
                     // try to display the error image
                     $oProfileImage->toPng();
                 }
             } catch (Exception $f) {
                 // didn't work, re-throw the source exception
                 throw $e;
             }
         } catch (Exception $e) {
             // on debug mode, re-throw
             if ($bDebug) {
                 $ep = $e->getPrevious();
                 throw $ep == null ? $e : $ep;
             }
             // an exception was thrown in SteamProfileImage,
             // but we could try a fallback to the cached image
             if ($bImageFallback && $oImageFile->exists()) {
                 // redirect to cached image file
                 $this->displayImage($oImageFile);
             } else {
                 // nothing cached, re-throw exception
                 throw $e;
             }
         }
     } catch (Exception $e) {
         // quite fatal error, try to render a fail-safe error image
         if ($bDebug || !GDImage::isAvailable()) {
             $oHeader = new HTTPHeader();
             $oHeader->setResponse('Content-Type', 'text/plain');
             echo $bDebug ? "{$e}\n" : $e->getMessage();
         } else {
             $ErrorImage = new ErrorImage($e->getMessage());
             $ErrorImage->toPng();
         }
     }
 }
コード例 #4
0
ファイル: sig.php プロジェクト: BTCTaras/osusig
<?php

// Thanks to Cygnix
// Created by Lemmmy
require_once "p/.priv.php";
function __autoload($class_name)
{
    $directory = 'class/';
    if (file_exists($directory . $class_name . '.php')) {
        require_once $directory . $class_name . '.php';
        return;
    }
}
$api = new OsuAPI(constant("AKEY"));
$user = $api->getUserForMode($_GET['uname'], isset($_GET['mode']) ? $_GET['mode'] : 0);
if (!$user) {
    $errorImage = new ErrorImage();
    $errorImage->generate("User not found", "The user you tried to generate \na signature for was not found.");
}
$colour = isset($_GET['colour']) && !empty($_GET['colour']) ? $_GET['colour'] : 'pink';
$sig = new OsuSignature($user, 'TemplateNormal');
$sig->generate(PredefinedColours::getPredefinedColour($colour));