From eb5af6ebd1d82139a14597de8e354ec0e707ae66 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Steffen=20Schro=CC=88der?= Date: Tue, 13 May 2014 17:09:38 +0200 Subject: [PATCH] readded old deprecated util classes --- application/core/ColorUtil.php | 60 ++++++++ application/core/CommandLineHelper.php | 37 +++++ application/core/Formatter.php | 191 +++++++++++++++++++++++++ 3 files changed, 288 insertions(+) create mode 100644 application/core/ColorUtil.php create mode 100644 application/core/CommandLineHelper.php create mode 100644 application/core/Formatter.php diff --git a/application/core/ColorUtil.php b/application/core/ColorUtil.php new file mode 100644 index 00000000..8e3ac196 --- /dev/null +++ b/application/core/ColorUtil.php @@ -0,0 +1,60 @@ + + * @copyright 2014 ManiaControl Team + * @license http://www.gnu.org/licenses/ GNU General Public License, Version 3 + * @deprecated Use \ManiaControl\Utils\ColorUtil + */ +abstract class ColorUtil { + + /** + * Convert the given float value to a color code from red to green + * + * @param float $value + * @return string + * @deprecated Use \ManiaControl\Utils\ColorUtil + */ + public static function floatToStatusColor($value) { + $value = floatval($value); + $red = 1.; + $green = 1.; + if ($value < 0.5) { + $green = $value * 2.; + } + if ($value > 0.5) { + $red = 2. * (1. - $value); + } + $red = ColorUtil::floatToCode($red); + $green = ColorUtil::floatToCode($green); + return $red . $green . '0'; + } + + /** + * Get hex color representation of the float + * + * @param float $value + * @return string + * @deprecated Use \ManiaControl\Utils\ColorUtil + */ + public static function floatToCode($value) { + $value = floatval($value); + if ($value < 0.) { + $value = 0.; + } + if ($value > 1.) { + $value = 1.; + } + $value *= 15.; + $value = (int)round($value); + if ($value < 10) { + return (string)$value; + } + $codes = array(10 => 'a', 11 => 'b', 12 => 'c', 13 => 'd', 14 => 'e', 15 => 'f'); + return $codes[$value]; + } +} diff --git a/application/core/CommandLineHelper.php b/application/core/CommandLineHelper.php new file mode 100644 index 00000000..f1505e6a --- /dev/null +++ b/application/core/CommandLineHelper.php @@ -0,0 +1,37 @@ + + * @copyright 2014 ManiaControl Team + * @license http://www.gnu.org/licenses/ GNU General Public License, Version 3 + * @deprecated Use \ManiaControl\Utils\CommandLineHelper + */ +class CommandLineHelper { + + /** + * Get the Command Line Parameter with the given Name + * + * @param string $paramName + * @return mixed + * @deprecated Use \ManiaControl\Utils\CommandLineHelper + */ + public static function getParameter($paramName) { + global $argv; + $paramName = (string)$paramName; + foreach ($argv as $arg) { + $parts = explode('=', $arg, 2); + if (count($parts) < 2) { + continue; + } + if ($parts[0] !== $paramName) { + continue; + } + return $parts[1]; + } + return null; + } +} diff --git a/application/core/Formatter.php b/application/core/Formatter.php new file mode 100644 index 00000000..c28ea1b3 --- /dev/null +++ b/application/core/Formatter.php @@ -0,0 +1,191 @@ + + * @copyright 2014 ManiaControl Team + * @license http://www.gnu.org/licenses/ GNU General Public License, Version 3 + * @deprecated Use \ManiaControl\Utils\Formatter + */ +abstract class Formatter { + + /** + * Return the given Text with Escaping around it + * + * @param string $text + * @return string + * @deprecated Use \ManiaControl\Utils\Formatter + */ + public static function escapeText($text) { + return '$<' . $text . '$>'; + } + + /** + * Format the given Time (in Milliseconds) + * + * @param int $time + * @return string + * @deprecated Use \ManiaControl\Utils\Formatter + */ + public static function formatTime($time) { + if (!is_int($time)) { + $time = (int)$time; + } + $milliseconds = $time % 1000; + $seconds = floor($time / 1000); + $minutes = floor($seconds / 60); + $hours = floor($minutes / 60); + $minutes -= $hours * 60; + $seconds -= $hours * 60 + $minutes * 60; + $format = ($hours > 0 ? $hours . ':' : ''); + $format .= ($hours > 0 && $minutes < 10 ? '0' : '') . $minutes . ':'; + $format .= ($seconds < 10 ? '0' : '') . $seconds . ':'; + $format .= ($milliseconds < 100 ? '0' : '') . ($milliseconds < 10 ? '0' : '') . $milliseconds; + return $format; + } + + /** + * Format a Time to H:M:S + * + * @param int $seconds + * @return string + * @deprecated Use \ManiaControl\Utils\Formatter + */ + public static function formatTimeHMS($seconds) { + $minutes = floor($seconds / 60); + $hours = floor($minutes / 60); + $minutes -= $hours * 60; + $seconds -= ($hours * 3600 + $minutes * 60); + + $hours = ($hours < 10 ? '0' : '') . $hours; + $minutes = ($minutes < 10 ? '0' : '') . $minutes;; + $seconds = ($seconds < 10 ? '0' : '') . $seconds;; + + return $hours . ":" . $minutes . ":" . $seconds; + } + + /** + * Format an elapsed time String (2 days ago...) by a given timestamp + * + * @param int $ptime + * @return string + * @deprecated Use \ManiaControl\Utils\Formatter + */ + public static function time_elapsed_string($ptime) { + $etime = time() - $ptime; + + if ($etime < 1) { + return '0 seconds'; + } + + $a = array(12 * 30 * 24 * 60 * 60 => 'year', 30 * 24 * 60 * 60 => 'month', 24 * 60 * 60 => 'day', 60 * 60 => 'hour', 60 => 'minute', 1 => 'second'); + + foreach ($a as $secs => $str) { + $d = $etime / $secs; + if ($d >= 1) { + $r = round($d); + return $r . ' ' . $str . ($r > 1 ? 's' : '') . ' ago'; + } + } + return ''; + } + + /** + * Format the given Time (Seconds) to hh:mm:ss + * + * @param int $seconds + * @return string + * @deprecated Use \ManiaControl\Utils\Formatter + */ + public static function formatTimeH($seconds) { + return date("H:i:s", $seconds); + } + + /** + * Convert the given Time (Seconds) to MySQL Timestamp + * + * @param int $seconds + * @return string + * @deprecated Use \ManiaControl\Utils\Formatter + */ + public static function formatTimestamp($seconds) { + return date("Y-m-d H:i:s", $seconds); + } + + /** + * Remove possibly dangerous Codes + * (Dangerous Codes are Links and Formats that might screw up the following Styling) + * + * @param string $string + * @return string + * @deprecated Use \ManiaControl\Utils\Formatter + */ + public static function stripDirtyCodes($string) { + $string = self::stripLinks($string); + $string = preg_replace('/(?]/iu', '$1', $string); + return $string; + } + + /** + * Remove Links from the String + * + * @param string $string + * @return string + * @deprecated Use \ManiaControl\Utils\Formatter + */ + public static function stripLinks($string) { + return preg_replace('/(? 'AFG', 'Albania' => 'ALB', 'Algeria' => 'ALG', 'Andorra' => 'AND', 'Angola' => 'ANG', 'Argentina' => 'ARG', 'Armenia' => 'ARM', 'Aruba' => 'ARU', 'Australia' => 'AUS', 'Austria' => 'AUT', 'Azerbaijan' => 'AZE', 'Bahamas' => 'BAH', 'Bahrain' => 'BRN', 'Bangladesh' => 'BAN', 'Barbados' => 'BAR', 'Belarus' => 'BLR', 'Belgium' => 'BEL', 'Belize' => 'BIZ', 'Benin' => 'BEN', 'Bermuda' => 'BER', 'Bhutan' => 'BHU', 'Bolivia' => 'BOL', 'Bosnia&Herzegovina' => 'BIH', 'Botswana' => 'BOT', 'Brazil' => 'BRA', 'Brunei' => 'BRU', 'Bulgaria' => 'BUL', 'Burkina Faso' => 'BUR', 'Burundi' => 'BDI', 'Cambodia' => 'CAM', 'Cameroon' => 'CAR', // actually CMR + 'Canada' => 'CAN', 'Cape Verde' => 'CPV', 'Central African Republic' => 'CAF', 'Chad' => 'CHA', 'Chile' => 'CHI', 'China' => 'CHN', 'Chinese Taipei' => 'TPE', 'Colombia' => 'COL', 'Congo' => 'CGO', 'Costa Rica' => 'CRC', 'Croatia' => 'CRO', 'Cuba' => 'CUB', 'Cyprus' => 'CYP', 'Czech Republic' => 'CZE', 'Czech republic' => 'CZE', 'DR Congo' => 'COD', 'Denmark' => 'DEN', 'Djibouti' => 'DJI', 'Dominica' => 'DMA', 'Dominican Republic' => 'DOM', 'Ecuador' => 'ECU', 'Egypt' => 'EGY', 'El Salvador' => 'ESA', 'Eritrea' => 'ERI', 'Estonia' => 'EST', 'Ethiopia' => 'ETH', 'Fiji' => 'FIJ', 'Finland' => 'FIN', 'France' => 'FRA', 'Gabon' => 'GAB', 'Gambia' => 'GAM', 'Georgia' => 'GEO', 'Germany' => 'GER', 'Ghana' => 'GHA', 'Greece' => 'GRE', 'Grenada' => 'GRN', 'Guam' => 'GUM', 'Guatemala' => 'GUA', 'Guinea' => 'GUI', 'Guinea-Bissau' => 'GBS', 'Guyana' => 'GUY', 'Haiti' => 'HAI', 'Honduras' => 'HON', 'Hong Kong' => 'HKG', 'Hungary' => 'HUN', 'Iceland' => 'ISL', 'India' => 'IND', 'Indonesia' => 'INA', 'Iran' => 'IRI', 'Iraq' => 'IRQ', 'Ireland' => 'IRL', 'Israel' => 'ISR', 'Italy' => 'ITA', 'Ivory Coast' => 'CIV', 'Jamaica' => 'JAM', 'Japan' => 'JPN', 'Jordan' => 'JOR', 'Kazakhstan' => 'KAZ', 'Kenya' => 'KEN', 'Kiribati' => 'KIR', 'Korea' => 'KOR', 'Kuwait' => 'KUW', 'Kyrgyzstan' => 'KGZ', 'Laos' => 'LAO', 'Latvia' => 'LAT', 'Lebanon' => 'LIB', 'Lesotho' => 'LES', 'Liberia' => 'LBR', 'Libya' => 'LBA', 'Liechtenstein' => 'LIE', 'Lithuania' => 'LTU', 'Luxembourg' => 'LUX', 'Macedonia' => 'MKD', 'Malawi' => 'MAW', 'Malaysia' => 'MAS', 'Mali' => 'MLI', 'Malta' => 'MLT', 'Mauritania' => 'MTN', 'Mauritius' => 'MRI', 'Mexico' => 'MEX', 'Moldova' => 'MDA', 'Monaco' => 'MON', 'Mongolia' => 'MGL', 'Montenegro' => 'MNE', 'Morocco' => 'MAR', 'Mozambique' => 'MOZ', 'Myanmar' => 'MYA', 'Namibia' => 'NAM', 'Nauru' => 'NRU', 'Nepal' => 'NEP', 'Netherlands' => 'NED', 'New Zealand' => 'NZL', 'Nicaragua' => 'NCA', 'Niger' => 'NIG', 'Nigeria' => 'NGR', 'Norway' => 'NOR', 'Oman' => 'OMA', 'Other Countries' => 'OTH', 'Pakistan' => 'PAK', 'Palau' => 'PLW', 'Palestine' => 'PLE', 'Panama' => 'PAN', 'Paraguay' => 'PAR', 'Peru' => 'PER', 'Philippines' => 'PHI', 'Poland' => 'POL', 'Portugal' => 'POR', 'Puerto Rico' => 'PUR', 'Qatar' => 'QAT', 'Romania' => 'ROM', // actually ROU + 'Russia' => 'RUS', 'Rwanda' => 'RWA', 'Samoa' => 'SAM', 'San Marino' => 'SMR', 'Saudi Arabia' => 'KSA', 'Senegal' => 'SEN', 'Serbia' => 'SCG', // actually SRB + 'Sierra Leone' => 'SLE', 'Singapore' => 'SIN', 'Slovakia' => 'SVK', 'Slovenia' => 'SLO', 'Somalia' => 'SOM', 'South Africa' => 'RSA', 'Spain' => 'ESP', 'Sri Lanka' => 'SRI', 'Sudan' => 'SUD', 'Suriname' => 'SUR', 'Swaziland' => 'SWZ', 'Sweden' => 'SWE', 'Switzerland' => 'SUI', 'Syria' => 'SYR', 'Taiwan' => 'TWN', 'Tajikistan' => 'TJK', 'Tanzania' => 'TAN', 'Thailand' => 'THA', 'Togo' => 'TOG', 'Tonga' => 'TGA', 'Trinidad and Tobago' => 'TRI', 'Tunisia' => 'TUN', 'Turkey' => 'TUR', 'Turkmenistan' => 'TKM', 'Tuvalu' => 'TUV', 'Uganda' => 'UGA', 'Ukraine' => 'UKR', 'United Arab Emirates' => 'UAE', 'United Kingdom' => 'GBR', 'United States of America' => 'USA', 'Uruguay' => 'URU', 'Uzbekistan' => 'UZB', 'Vanuatu' => 'VAN', 'Venezuela' => 'VEN', 'Vietnam' => 'VIE', 'Yemen' => 'YEM', 'Zambia' => 'ZAM', 'Zimbabwe' => 'ZIM'); + if (array_key_exists($country, $nations)) { + return $nations[$country]; + } + if ($country) { + trigger_error("Couldn't map Country: '{$country}'!"); + } + return 'OTH'; + } +}