'description' => '(Y-m-d H:i:s format):' ) ), ); } public function getSitePref($prefKey, $cached = true, $default = false) { $query = sprintf( "SELECT prefValue FROM clint_v1_prod.clint_site_prefs WHERE prefKey = '%s'", $prefKey ); $resultSet = $this->smartLocalCachedQuery($query, $this->mtime("prefs"), 60 * 60 * 72, "row"); return $resultSet ? trim($resultSet[0][0]) : $default; } public function setSitePref($prefKey, $prefValue) { $query = sprintf( "INSERT INTO clint_v1_prod.clint_site_prefs (prefKey, prefValue) VALUES ('%s', '%s') ON DUPLICATE KEY UPDATE prefValue = '%s'", $this->escapeString($prefKey), $this->escapeString($prefValue), $this->escapeString($prefValue) ); $result = $this->sqlQuery($query); $this->touch("prefs"); return $result; } public function hasSuspiciousTransactionsProtection() { return ($this->getSitePref('suspicious_transactions') == 'on'); } public function hasAds() { return ($this->getSitePref('ads') == 'on'); } public function hasChat() { return ($this->getSitePref('chat') == 'on'); } public function hasSolo() { return ($this->getSitePref('solo_enabled') == 'on'); } public function hasVideoAds() { return ($this->getSitePref('videoads_enable') == 'on'); } public function mustReportError() { return ($this->getSitePref('mail_reporter_enable') == 'on'); } public function getWebApiURL() { return '/jars/api'; } // Your .po and .mo files should be at $locale_dir/$locale/LC_MESSAGES/messages.{po,mo} public function getLocaleDir() { return $this->getDocRoot().'/locale/'; // if ( IS_DEV ) return '/home/seb/boostr/www/locale'; //$_SERVER['DOCUMENT_ROOT'].'/locale'; // else return '/home/clint/www.urban-rivals.com/www/locale'; } public function getDocRoot() { global $corePath; return $corePath.'/../www/'; // if ( IS_DEV ) return '/home/seb/boostr/www/'; // else return '/home/clint/www.urban-rivals.com/www/'; } public function getAvailablesLocales() { if (IS_DEV || stripos(UrbanRequest()->getRequestURI(), '/admin/') !== false) { return array('en', 'fr', 'es', 'de', 'pt', 'ru', 'it', 'nl', 'pl', 'el', 'ro', 'cs', 'tr'); } else { return array('en', 'fr', 'es', 'de', 'pt', 'ru', 'it', 'nl', 'pl', 'el', 'ro', 'cs', 'tr'); } } public function setLocale($locale) { if ($locale != $this->locale) { // Initialize gettext mb_internal_encoding("UTF-8"); $localeGettext = $this->getLanguageLocalePoByLocale($locale); putenv("LANGUAGE=$localeGettext"); putenv("LANG=$localeGettext"); setlocale(LC_MESSAGES, substr($localeGettext, 0, 5).".utf8"); setlocale(LC_TIME, substr($localeGettext, 0, 5).".utf8"); setlocale(LC_COLLATE, substr($localeGettext, 0, 5).".utf8"); if ($locale != 'tr') { setlocale(LC_CTYPE, substr($localeGettext, 0, 5).".utf8"); } else { setlocale(LC_CTYPE, 'en_US.utf8'); } bindtextdomain('UrbanRivals', $this->getLocaleDir()); bind_textdomain_codeset('UrbanRivals', 'UTF-8'); textdomain('UrbanRivals'); $this->locale = $locale; } } public function getLocale() { return $this->locale; } public function changeLocale($locale) { if (!$this->previousLocale) { $this->previousLocale = $this->locale; } $this->setLocale($locale); } public function restoreLocale() { if ($this->previousLocale) { $this->setLocale($this->previousLocale); } $this->previousLocale = null; } public function loadLocaleMappingArray() { if (!isset($this->localeMappingArray)) { $query = "SELECT * FROM clint_v1_prod.langue"; $resultSet = $this->cachedSqlQuery($query, 60 * 60 * 24 * 7, 'assoc'); $this->localeMappingArray = array(); foreach ($resultSet as $localeDef) { $id_language = $localeDef['idlangue']; $name_language = $localeDef['langue']; $code_language = $localeDef['code']; $default_country_code = $localeDef['default_country_code']; // Let be a little smarter than that :) $web_locale_language = substr($code_language, 0, 2); // Old compatibility $addAtEuroLanguages = array('fr', 'en', 'de', 'es', 'nl', 'it'); $po_locale_language = $code_language.(inArray($web_locale_language, $addAtEuroLanguages) ? '@euro' : ''); // Hack: need to be cleaned $this->localeMappingArray[] = array( 'id' => $id_language, 'code' => $code_language, 'name' => $name_language, 'locale' => $web_locale_language, 'locale_po' => $po_locale_language, 'default_country_code' => $default_country_code ); } } return $this->localeMappingArray; } public function getLanguagePropertiesByID($id_langue, $property = 'name') { $languagesProperties = $this->loadLocaleMappingArray(); foreach ($languagesProperties as $languageProperties) { if ($languageProperties['id'] == $id_langue) { return $languageProperties[$property]; } } // In case we don't find anything, return the properties for english return $this->getLanguagePropertiesByID(2, $property); } public function getLanguagePropertiesByLocale($locale, $property = 'name') { $languagesProperties = $this->loadLocaleMappingArray(); foreach ($languagesProperties as $languageProperties) { if ($languageProperties['locale'] == $locale) { return $languageProperties[$property]; } } // In case we don't find anything, return the properties for english return $this->getLanguagePropertiesByID(2, $property); } public function getLanguageLocaleByID($id_langue) { return $this->getLanguagePropertiesByID($id_langue, 'locale'); } public function getLanguageLocalePoByID($id_langue) { return $this->getLanguagePropertiesByID($id_langue, 'locale_po'); } public function getLanguageNameByID($id_langue) { return $this->getLanguagePropertiesByID($id_langue, 'name'); } public function getLanguageLocalePoByLocale($locale) { return $this->getLanguagePropertiesByLocale($locale, 'locale_po'); } public function getLanguageIDByLocale($locale) { return $this->getLanguagePropertiesByLocale($locale, 'id'); } public function getLanguageNameByLocale($locale) { return $this->getLanguagePropertiesByLocale($locale, 'name'); } public function getDefaultCountryCodeByLocale($locale) { return $this->getLanguagePropertiesByLocale($locale, 'default_country_code'); } public function countryIsRecognized($countryCode) { return in_array($countryCode, $this->getCountryCodes()); } public function getCountryName($countryCode) { static $lookup = array(); if ($countryCode == 'gb') { $countryCode = 'uk'; } if (!$lookup) { $lookup = array_combine($this->getCountryCodes(), $this->getCountryNames()); } return isset($lookup[$countryCode]) ? $lookup[$countryCode] : ($countryCode == "eu" ? "Europe" : ""); } public function getCountryCodes() { return UrbanToolbox::array_extract_column($this->getCountries(), 'code'); } public function getCountryNames() { return UrbanToolbox::array_extract_column($this->getCountries(), 'country'); } public function getCountries() { $query = "SELECT `iso_3166-1_alpha-2` as code, country FROM clint_v1_prod.clint_country ORDER BY country"; return $this->cachedSqlQuery($query, 60 * 60 * 24 * 7, 'assoc'); } public function getCountriesForSelect() { $query = "SELECT `iso_3166-1_alpha-2` as code, country FROM clint_v1_prod.clint_country ORDER BY country"; $resultSet = $this->cachedSqlQuery($query, 60 * 60 * 24 * 7, 'assoc'); $countries = array(); foreach ($resultSet as $row) { $countries[$row['country']] = $row['code']; } return $countries; } public function getCountryForLanguage($lang) { return self::$language2country[$lang][0]; } public function getLocaleForCountry($country) { foreach (self::$language2country as $locale => $countries) { if (inArray($country, $countries)) { return $locale; } } return 'en'; } public function getXPByLevelTable() { // XP needed for a character to reach a level $ExpLvl = array(); $ExpLvl[1]=0; $ExpLvl[2]=500; $ExpLvl[3]=1500; $ExpLvl[4]=3000; $ExpLvl[5]=5000; $ExpLvl[6]=0; return $ExpLvl; } public function isEasterBonus() { $start = mktime(0, 0, 0, 3, 30, 2013); $end = mktime(0, 0, 0, 4, 2, 2013); $now = time(); return ($start < $now) && ($now < $end); } public function generatePassword($nb_characters, $prepend = '') { $code = $prepend; $keytable = array("0","1","2","3","4","5","6","7","8","9"); for ($i=0; $i < 25; $i++) { $keytable[] = chr($i+65); } while (strlen($code) < $nb_characters) { $code .= $keytable[array_rand($keytable)]; } return $code; } public function getGradesList() { $query = "SELECT * FROM clint_v2_prod.clint_new_grade ORDER BY points_min ASC"; return $this->cachedSqlQuery($query, 60 * 60 * 24 * 7); } public function getNewGradesList() { return array( 'novice' => array( 'min' => array('cards' => 0) ), 'senior' => array( 'min' => array('percentage' => 2) ), 'veteran' => array( 'min' => array('percentage' => 5) ), 'hero' => array( 'min' => array('percentage' => 10) ), 'master' => array( 'min' => array('percentage' => 20) ), 'guru' => array( 'min' => array('percentage' => 30) ), 'imperator' => array( 'min' => array('percentage' => 50) ), 'titan' => array( 'min' => array('percentage' => 70) ), 'colossus' => array( 'min' => array('percentage' => 90) ), 'legend' => array( 'min' => array('percent_available' => 100, 'percent_legendary' => 100), ), 'divinity' => array( 'min' => array('percent_available' => 100, 'percent_collector' => 100) ), 'eternal' => array( 'min' => array('cards' => UrbanCharacters()->getTotalCharacters()) ) ); } public function isPlayerOverOrEqualToGrade($myPlayer, $min_grade) { if ($myPlayer->isModerator()) { return true; } else { return $this->isGradeOverOrEqualToGrade($myPlayer->getURGrade(), $min_grade); } return false; } public function isPlayerBelowOrEqualToGrade($myPlayer, $max_grade) { if ($myPlayer->isModerator()) { return true; } else { return $this->isGradeBelowOrEqualToGrade($myPlayer->getURGrade(), $max_grade); } return false; } public function isGradeOverOrEqualToGrade($player_grade, $min_grade) { if (!trim($min_grade)) { return true; } $player_grade = strtolower($player_grade); $min_grade = strtolower($min_grade); if ($player_grade == $min_grade) { return true; } else { $gradesList = $this->getNewGradesList(); foreach ($gradesList as $grade => $details) { if ($player_grade == $grade) { return false; } if ($min_grade == $grade) { return true; } } } return false; } public function isGradeBelowOrEqualToGrade($player_grade, $max_grade) { if (!trim($max_grade)) { return true; } $player_grade = strtolower($player_grade); $max_grade = strtolower($max_grade); if ($player_grade == $max_grade) { return true; } else { $gradesList = array_reverse($this->getNewGradesList()); foreach ($gradesList as $grade => $details) { if ($player_grade == $grade) { return false; } if ($max_grade == $grade) { return true; } } } return false; } public function getMenuBGList() { $query = "SELECT mb.* FROM clint_v1_prod.clint_menu_background mb ORDER BY name ASC"; return $this->cachedSqlQuery($query, 60 * 60 * 24 * 7); } public function getPreferedModeOptionsAndLabels() { return array('normal' => _("Normal"), 'no random' => _("No random"), 'any' => _("Room default or opponent's choice")); } public function getCharactersPerPageOptions() { return array(12, 20, 28, 36, 52); } public function getSubjectsPerPageOptions() { return array(20,25,30,40,50); } public function getMessagesPerPageOptions() { return array(10,15,20,25,30,40,50); } public function getLoginForbiddenWords() { return array('nazi','kate','fuck','dick','suck','encul','tamere','pede','moderator','staff', 'urban', 'rivals'); } public static function memcacheConnectionError($host, $port) { if (UrbanRequest()->getHost()) { UrbanConfig()->log( "Error connecting to memcache server %s %s for request %s | %s | %s | %s", $host, $port, UrbanRequest()->getHost(), UrbanRequest()->getRequestURI() ? UrbanRequest()->getRequestURI() : "", UrbanRequest()->getScriptName() ? UrbanRequest()->getScriptName() : "", UrbanRequest()->getQueryString() ? UrbanRequest()->getQueryString() : "" ); } else { UrbanConfig()->log("Error connecting to memcache server %s %s", $host, $port); } } public static function getMainRedisServer() { if (IS_DEV) { return array( 'host' => '127.0.0.1', 'port' => 6379 ); } else { return array( 'host' => 'urutil1', 'port' => 6379 ); } } public function getMainMemcachedServers() { if (IS_DEV) { return array( array( 'host' => 'localhost', 'port' => 11211, 'persistent' => true, 'weight' => 1, 'timeout' => 1, 'retry_interval' => 15, 'status' => true ) ); } else { return array( array( 'host' => 'urutil1', 'port' => 11211, 'persistent' => true, 'weight' => 1, 'timeout' => 1, 'retry_interval' => 15, 'status' => true ) ); } } public function getRabbitMQHost() { return array( 'host' => 'urutil1', 'port' => 5672, 'user' => 'urban', 'password' => '8kz?XaC7mS3qe~uwHeW7r{/n5OxxK$;y' ); } public function getNodeJSServer() { if (IS_DEV) { return [ 'server' => 'localhost', 'port' => 8088, 'timeout' => 5// in seconds ]; } else { return [ 'server' => 'wss://urnode1.urban-rivals.com', 'port' => 8088, 'timeout' => 5// in seconds ]; } } public function getAIConfig() { return array( 'vhost' => '/', 'exchange' => 'ia', 'queue' => 'incoming', 'routingKey' => 'incoming' ); } public function getMainMysqlMaster() { if (IS_DEV) { return [ 'server' => 'localhost:3306', 'username' => 'root', 'password' => 'apoillesputes', 'database' => 'clint_v2_prod' ]; } else { return [ 'server' => 'ur-db.cluster-cmdtbxssctsv.eu-west-1.rds.amazonaws.com', 'username' => 'clint', 'password' => 'Ya9rg9HUxXQYdBJa', 'database' => 'clint_v2_prod' ]; } } public function getMainMysqlSlaves() { if (IS_DEV) { return [ [ 'server' => 'localhost:3306', 'username' => 'root', 'password' => 'apoillesputes', 'database' => 'clint_v2_prod', 'weight' => 1 ] ]; } else { return [ [ 'server' => 'ur-db-slave1.cmdtbxssctsv.eu-west-1.rds.amazonaws.com', 'username' => 'roclint', 'password' => 'z5AREbJFSnev5UH4', 'database' => 'clint_v2_prod', 'weight' => 1 ] ]; } } public function getMainMysqlStatSlaves() { return $this->getMainMysqlSlaves(); } public function getSharedanceHost() { if (IS_DEV) { return '127.0.0.1'; } else { return 'urutil1'; } } public function getSphinxServer() { if (IS_DEV) { return 'localhost'; } else { return 'urutil1'; } } public static function getFrontServers() { return array( "urweb1", "urweb2", "urweb3", "urweb4" ); } public static function getStaticServers() { return array( "urstatic1" ); } public function getPeriods() { return array( 'day' => _("today"), 'week' => _("week"), 'month' => _("month"), 'overall' => _("overall") ); } public function getFlagSizeFromImageSize($imageSize) { if (!$imageSize) { $imageSize = 'small'; } $imageSize2OldSize = array( 'small' => 16, 'medium' => 24, 'large' => 32, 'extralarge' => 48); return $imageSize2OldSize[strtolower($imageSize)]; } public function getOldSizeFromImageSize($imageSize) { if (!$imageSize) { $imageSize = 'small'; } $imageSize2OldSize = array( 'small' => 128, 'medium' => 160, 'large' => 240); return $imageSize2OldSize[strtolower($imageSize)]; } public function getOldFormatCodeFromImageSizeAndFormat($imageSize, $imageFormat) { if (!$imageSize) { $imageSize = 'small'; } if (!$imageFormat) { $imageFormat = 'png'; } $imageSize2OldSize = array( 'small' => 128, 'medium' => 160, 'large' => 240); $imageFormat2OldFormat = array( 'gif' => 'g', 'png' => 'p'); return $imageSize2OldSize[strtolower($imageSize)].$imageFormat2OldFormat[strtolower($imageFormat)]; } public function getLevelRequired($feature) { $levelRequirements = array('event' => 40); return intval($levelRequirements[strtolower($feature)]); } public function getGoogleAnalyticsJS($opt_pageURL = false, $id = 'UA-865172-1') { if ($this->analytics) { $js = ''; return $js; } return ''; } public function getFacebookPixelCode() { return IS_DEV ? '' : ' '; } public function dieIfReachedThreshold($action, $threshold, $timeout_per_try = 30) { // Skip test for admins if (getPlayer() && getPlayer()->isModerator()) { return; } $key = md5(strtolower($action.UrbanRequest()->getIpAddress())); $val = (int)$this->getCachedVar($key); $val++; $timeout = $timeout_per_try * $val; $this->setCachedVar($key, $val, $timeout); if ($val > $threshold) { // Let spider crawl if (stripos(gethostbyaddr(UrbanRequest()->getIpAddress()), 'spider') === false) { // Mute log UrbanConfig()->log("Stopped ".$action." by threshold ".UrbanRequest()->getIpAddress()." (".$timeout."s)"); die("Too many attempts, try again later."); } } } public function outputDebug() { if (DataAccess::getInstance()->getDebugInfos() && DataAccess::getInstance()->hasGlobalDebug()) { echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; $i = 0; $totalTime = 0; foreach (DataAccess::getInstance()->getDebugInfos() as $debugInfo) { switch ($debugInfo['type']) { case 'begin_smartcache': { echo ''; echo ''; echo ''; echo ''; } break; case 'end_smartcache': { echo ''; echo ''; echo ''; echo ''; } break; case 'db_query': { echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; } break; case 'memcache_query': { echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; } break; } $totalTime += $debugInfo['time']; ++$i; } echo ''; echo ''; echo ''; echo '
timetypeshardkindquery
smartcache begin'; echo $debugInfo['query'].'
smartcache end
'.sprintf('%.3f', ($debugInfo['time'] * 1000)).' msdb'.$debugInfo['shard'].''.($debugInfo['slave'] ? 'slave' : 'master').''.$debugInfo['query'].'
'.sprintf('%.3f', ($debugInfo['time'] * 1000)).' msmemcache'.$debugInfo['shard'].''.($debugInfo['local'] ? 'local' : 'distributed').''.nl2br(print_r($debugInfo['query'], true)).'
total time: '.sprintf('%.3f', ($totalTime * 1000)).' ms
'; } } public function log() { $args = func_get_args(); $msg = $args[0]; unset($args[0]); if (func_num_args() > 1) { $msg = vsprintf($msg, $args); } error_log($msg, E_USER_WARNING); } public function getTrailerURL() { $trailer = array( 'en' => 'https://www.youtube.com/embed/I6S3hNR_HyE' // 'en' => 'https://www.youtube.com/embed/9dX2Mab_yTU', // 'fr' => 'https://www.youtube.com/embed/IkDRpLnX06E', // 'es' => 'https://www.youtube.com/embed/cbPAYgfSrGE', // 'de' => 'https://www.youtube.com/embed/dVNbAdQfy7Y', // 'pt' => 'https://www.youtube.com/embed/sPxUwViDYwI', // 'ru' => 'https://www.youtube.com/embed/ovjvVMXJxCg', // 'it' => 'https://www.youtube.com/embed/K9ktgo_Au3w', // 'nl' => 'https://www.youtube.com/embed/TWIKvA1_8hk', // 'pl' => 'https://www.youtube.com/embed/-xuXu3yVT0E', // 'el' => 'https://www.youtube.com/embed/kmDUD44ckO4', // 'ro' => 'https://www.youtube.com/embed/lWDd_rUDNZw', // 'cs' => 'https://www.youtube.com/embed/LO2ITlFXLSE', // 'tr' => 'https://www.youtube.com/embed/P6m1iZxppa0' ); return (array_key_exists($this->getLocale(), $trailer) ? $trailer[ $this->getLocale() ] : $trailer['en']); } public function getT1FormatName() { return 'Type 1'; //return IS_DEV ? 'Type 1' : 'Extended25'; } public function getT2FormatName() { return 'Type 2'; //return IS_DEV ? 'Type 2' : 'Extended'; } public function getT3FormatName() { return 'Survivor Type 3'; //return IS_DEV ? 'Type 2' : 'Extended'; } public function getOAuthCredential() { $crendential = array('key' => '', 'secret' => ''); if (IS_DEV) { $crendential['key'] = 'd78447250331ad1c6665b61d51949afa053b52eef'; $crendential['secret'] = '0304519b56a7279dff106d47e28dabe0'; } else { // TODO : when we put PROD data $crendential['key'] = '476b8b02d82e095224aab06e621257b304bf3b010'; $crendential['secret'] = '704974dfbb591d48101207957895a5b6'; } return $crendential; } }