Diff
1 year ago
audit-log
1 year ago
dashboard
1 year ago
rest-api
1 year ago
.htaccess
7 years ago
Diff.php
6 years ago
GeoLite2-Country.mmdb
1 year ago
IPTraf.php
1 year ago
IPTrafList.php
1 year ago
WFLSPHP52Compatability.php
6 years ago
compat.php
8 years ago
diffResult.php
1 year ago
email_genericAlert.php
5 years ago
email_newIssues.php
3 years ago
email_unlockRequest.php
5 years ago
email_unsubscribeRequest.php
4 years ago
flags.php
7 years ago
live_activity.php
4 years ago
menu_dashboard.php
3 years ago
menu_dashboard_options.php
3 years ago
menu_firewall.php
3 years ago
menu_firewall_blocking.php
4 years ago
menu_firewall_blocking_options.php
3 years ago
menu_firewall_waf.php
4 years ago
menu_firewall_waf_options.php
3 years ago
menu_install.php
3 years ago
menu_options.php
1 year ago
menu_scanner.php
2 years ago
menu_scanner_credentials.php
1 year ago
menu_scanner_options.php
3 years ago
menu_support.php
1 year ago
menu_tools.php
1 year ago
menu_tools_auditlog.php
1 year ago
menu_tools_diagnostic.php
1 year ago
menu_tools_importExport.php
4 years ago
menu_tools_livetraffic.php
2 years ago
menu_tools_twoFactor.php
4 years ago
menu_tools_whois.php
3 years ago
menu_wordfence_central.php
3 years ago
noc1.key
7 years ago
sodium_compat_fast.php
2 years ago
sysinfo.php
1 year ago
viewFullActivityLog.php
4 years ago
wf503.php
2 years ago
wfAPI.php
1 year ago
wfActivityReport.php
1 year ago
wfAdminNoticeQueue.php
4 years ago
wfAlerts.php
5 years ago
wfArray.php
3 years ago
wfAuditLog.php
1 year ago
wfBrowscap.php
3 years ago
wfBrowscapCache.php
7 years ago
wfBulkCountries.php
2 years ago
wfCache.php
3 years ago
wfCentralAPI.php
1 year ago
wfConfig.php
1 year ago
wfCrawl.php
1 year ago
wfCredentialsController.php
1 year ago
wfCrypt.php
6 years ago
wfCurlInterceptor.php
3 years ago
wfDB.php
1 year ago
wfDashboard.php
1 year ago
wfDateLocalization.php
2 years ago
wfDeactivationOption.php
3 years ago
wfDiagnostic.php
1 year ago
wfDict.php
8 years ago
wfDirectoryIterator.php
7 years ago
wfFileUtils.php
2 years ago
wfHelperBin.php
11 years ago
wfHelperString.php
1 year ago
wfIPWhitelist.php
5 years ago
wfImportExportController.php
5 years ago
wfInaccessibleDirectoryException.php
2 years ago
wfInvalidPathException.php
3 years ago
wfIpLocation.php
3 years ago
wfIpLocator.php
3 years ago
wfIssues.php
1 year ago
wfJWT.php
7 years ago
wfLicense.php
3 years ago
wfLockedOut.php
2 years ago
wfLog.php
1 year ago
wfMD5BloomFilter.php
8 years ago
wfModuleController.php
7 years ago
wfNotification.php
8 years ago
wfOnboardingController.php
1 year ago
wfPersistenceController.php
1 year ago
wfRESTAPI.php
7 years ago
wfScan.php
2 years ago
wfScanEngine.php
1 year ago
wfScanEntrypoint.php
3 years ago
wfScanFile.php
1 year ago
wfScanFileLink.php
3 years ago
wfScanFileListItem.php
1 year ago
wfScanFileProperties.php
1 year ago
wfScanMonitor.php
2 years ago
wfScanPath.php
3 years ago
wfSchema.php
1 year ago
wfStyle.php
1 year ago
wfSupportController.php
1 year ago
wfUnlockMsg.php
5 years ago
wfUpdateCheck.php
1 year ago
wfUtils.php
1 year ago
wfVersionCheckController.php
3 years ago
wfVersionSupport.php
1 year ago
wfView.php
5 years ago
wfViewResult.php
1 year ago
wfWebsite.php
3 years ago
wordfenceClass.php
1 year ago
wordfenceConstants.php
1 year ago
wordfenceHash.php
1 year ago
wordfenceScanner.php
1 year ago
wordfenceURLHoover.php
2 years ago
wfIpLocation.php
65 lines
| 1 | <?php |
| 2 | |
| 3 | class wfIpLocation { |
| 4 | |
| 5 | const LANGUAGE_DEFAULT = 'en'; |
| 6 | const LANGUAGE_SEPARATOR = '_'; |
| 7 | |
| 8 | private $record; |
| 9 | |
| 10 | public function __construct($record) { |
| 11 | $this->record = is_array($record) ? $record : array(); |
| 12 | } |
| 13 | |
| 14 | public function getCountryRecord() { |
| 15 | if (array_key_exists('country', $this->record)) { |
| 16 | $country = $this->record['country']; |
| 17 | if (is_array($country)) |
| 18 | return $country; |
| 19 | } |
| 20 | return array(); |
| 21 | } |
| 22 | |
| 23 | public function getCountryField($field) { |
| 24 | $country = $this->getCountryRecord(); |
| 25 | if (array_key_exists($field, $country)) |
| 26 | return $country[$field]; |
| 27 | return null; |
| 28 | } |
| 29 | |
| 30 | public function getCountryCode() { |
| 31 | $isoCode = $this->getCountryField('iso_code'); |
| 32 | if (is_string($isoCode) && strlen($isoCode) === 2) |
| 33 | return $isoCode; |
| 34 | return null; |
| 35 | } |
| 36 | |
| 37 | private function findBestLanguageMatch($options, $preferredLanguage = self::LANGUAGE_DEFAULT) { |
| 38 | $languages = array(); |
| 39 | if (is_string($preferredLanguage)) |
| 40 | $languages[] = $preferredLanguage; |
| 41 | if (strpos($preferredLanguage, self::LANGUAGE_SEPARATOR) !== false) { |
| 42 | $components = explode(self::LANGUAGE_SEPARATOR, $preferredLanguage); |
| 43 | $baseLanguage = $components[0]; |
| 44 | if ($baseLanguage !== self::LANGUAGE_DEFAULT) |
| 45 | $languages[] = $baseLanguage; |
| 46 | } |
| 47 | if ($preferredLanguage !== self::LANGUAGE_DEFAULT) |
| 48 | $languages[] = self::LANGUAGE_DEFAULT; |
| 49 | foreach ($languages as $language) { |
| 50 | if (array_key_exists($language, $options)) |
| 51 | return $options[$language]; |
| 52 | } |
| 53 | if (!empty($options)) |
| 54 | return reset($options); |
| 55 | return null; |
| 56 | } |
| 57 | |
| 58 | public function getCountryName($preferredLanguage = self::LANGUAGE_DEFAULT) { |
| 59 | $names = $this->getCountryField('names'); |
| 60 | if (is_array($names) && !empty($names)) |
| 61 | return $this->findBestLanguageMatch($names, $preferredLanguage); |
| 62 | return null; |
| 63 | } |
| 64 | |
| 65 | } |