1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71:
<?php
class Utils
{
const USER_AGENT = "osu!next Signature Generator - lemmmy.pw/osusig/ - v3";
const ONLINE_URL = "http://onlineindicator.lemmmy.pw:3960";
private static $mc;
public static function getMemcache() {
if (!isset(self::$mc)) {
self::$mc = new Memcached();
self::$mc->addServer("localhost", 11211);
}
return self::$mc;
}
public static function largeNumberFormat($number) {
$n = round($number);
$n_number_format = number_format($n);
$n_array = explode(',', $n_number_format);
$n_parts = array('k', 'M', 'B', 'T');
$n_count_parts = count($n_array) - 1;
$n_display = $n_array[0] . ((int) $n_array[1][0] !== 0 ? '.' . $n_array[1][0] : '');
$n_display .= $n_parts[$n_count_parts - 1];
return $n_display;
}
public static function isUserOnline($username) {
$onlineStatus = self::$mc->get("osusig_v3_online_" . $username);
if (!isset($onlineStatus) || empty($onlineStatus)) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, self::ONLINE_URL . '?u=' . str_replace(' ', '_', $username));
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_USERAGENT, self::USER_AGENT);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT_MS, 1250);
$response = json_decode(curl_exec($ch));
curl_close($ch);
self::$mc->set("osusig_v3_online_" . $username, $response->online, 60);
return $response->online;
} else {
return $onlineStatus;
}
}
}