Created
June 6, 2014 15:30
-
-
Save lifeofguenter/c4d0b772976edc141d1f to your computer and use it in GitHub Desktop.
[PATCH] internationalisation + WHMCS > 5.2.2 (backward compatible) (whmcs coza module)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/modules/registrars/cozaepp/cozaepp.php b/modules/registrars/cozaepp/cozaepp.php | |
index ddb5716..0406c91 100644 | |
--- a/modules/registrars/cozaepp/cozaepp.php | |
+++ b/modules/registrars/cozaepp/cozaepp.php | |
@@ -799,18 +799,35 @@ | |
return $values; | |
} | |
+ $rev = _cozaepp_getRevision(); | |
+ if($rev === 1) { | |
+ $key_company = 'Company Name'; | |
+ $key_address1 = 'Address 1'; | |
+ $key_address2 = 'Address 2'; | |
+ $key_city = 'City'; | |
+ $key_postcode = 'Postcode'; | |
+ $key_country = 'Country'; | |
+ } else { | |
+ $key_company = 'Organisation'; | |
+ $key_address1 = 'Address line 1'; | |
+ $key_address2 = 'Address line 2'; | |
+ $key_city = 'TownCity'; | |
+ $key_postcode = 'TownCity'; | |
+ $key_country = 'Country Code'; | |
+ } | |
+ | |
$nodes = $doc->getElementsByTagName('postalInfo'); | |
for ($i = 0; ($i < $nodes->length); $i++) { | |
- if ($nodes->item($i)->getAttributeNode('type')->nodeValue == 'loc') { | |
+ if ($nodes->item($i)->getAttributeNode('type')->nodeValue == 'loc' || $nodes->item($i)->getAttributeNode('type')->nodeValue == 'int') { | |
$childNodes = $nodes->item($i); | |
$results["Registrant"]["Contact Name"] = $childNodes->getElementsByTagName('name')->item(0)->nodeValue; | |
- $results["Registrant"]["Organisation"] = $childNodes->getElementsByTagName('org')->item(0)->nodeValue; | |
- $results["Registrant"]["Address line 1"] = $childNodes->getElementsByTagName('street')->item(0)->nodeValue; | |
- $results["Registrant"]["Address line 2"] = $childNodes->getElementsByTagName('street')->item(1)->nodeValue; | |
- $results["Registrant"]["TownCity"] = $childNodes->getElementsByTagName('city')->item(0)->nodeValue; | |
+ $results["Registrant"][$key_company] = $childNodes->getElementsByTagName('org')->item(0)->nodeValue; | |
+ $results["Registrant"][$key_address1] = $childNodes->getElementsByTagName('street')->item(0)->nodeValue; | |
+ $results["Registrant"][$key_address2] = $childNodes->getElementsByTagName('street')->item(1)->nodeValue; | |
+ $results["Registrant"][$key_city] = $childNodes->getElementsByTagName('city')->item(0)->nodeValue; | |
$results["Registrant"]["State"] = $childNodes->getElementsByTagName('sp')->item(0)->nodeValue; | |
- $results["Registrant"]["Zip code"] = $childNodes->getElementsByTagName('pc')->item(0)->nodeValue; | |
- $results["Registrant"]["Country Code"] = $childNodes->getElementsByTagName('cc')->item(0)->nodeValue; | |
+ $results["Registrant"][$key_postcode] = $childNodes->getElementsByTagName('pc')->item(0)->nodeValue; | |
+ $results["Registrant"][$key_country] = $childNodes->getElementsByTagName('cc')->item(0)->nodeValue; | |
} | |
} | |
@@ -833,6 +850,13 @@ | |
# Fetching contact details | |
$results = _getContactDetails($sld . '.' . $tld); | |
+ $rev = _cozaepp_getRevision(); | |
+ if($rev === 1) { | |
+ $keys = array("Contact Name","Company Name","Address 1","Address 2","City","State","Postcode","Country","Phone","Email"); | |
+ } else { | |
+ $keys = array("Contact Name","Organisation","Address line 1","Address line 2","TownCity","State","Zip code","Country Code","Phone","Email"); | |
+ } | |
+ | |
# If there was an error return it | |
if (isset($results["error"])) { | |
return $results; | |
@@ -840,10 +864,7 @@ | |
# What we going to do here is make sure all the attirbutes we return back are set | |
# If we don't do this WHMCS won't display the options for editing | |
- foreach ( | |
- array("Contact Name","Organisation","Address line 1","Address line 2","TownCity","State","Zip code","Country Code","Phone","Email") | |
- as $item | |
- ) { | |
+ foreach ($keys as $item) { | |
# Check if the item is set | |
if ($results["Registrant"][$item] == "") { | |
# Just set it to - | |
@@ -862,21 +883,61 @@ | |
# Function to save contact details | |
function cozaepp_SaveContactDetails($params) { | |
+ | |
+ $rev = _cozaepp_getRevision(); | |
+ | |
# Grab variables | |
$tld = $params["tld"]; | |
$sld = $params["sld"]; | |
# Registrant details | |
$registrant_name = $params["contactdetails"]["Registrant"]["Contact Name"]; | |
- $registrant_org = $params["contactdetails"]["Registrant"]["Organisation"]; | |
- $registrant_address1 = $params["contactdetails"]["Registrant"]["Address line 1"]; | |
- $registrant_address2 = $params["contactdetails"]["Registrant"]["Address line 2"]; | |
- $registrant_town = $params["contactdetails"]["Registrant"]["TownCity"]; | |
+ | |
+ if($rev === 1) { | |
+ $registrant_org = $params["contactdetails"]["Registrant"]["Company Name"]; | |
+ $registrant_address1 = $params["contactdetails"]["Registrant"]["Address 1"]; | |
+ $registrant_address2 = $params["contactdetails"]["Registrant"]["Address 2"]; | |
+ $registrant_town = $params["contactdetails"]["Registrant"]["City"]; | |
+ $registrant_zipcode = $params["contactdetails"]["Registrant"]["Postcode"]; | |
+ $registrant_countrycode = $params["contactdetails"]["Registrant"]["Country"]; | |
+ } else { | |
+ $registrant_org = $params["contactdetails"]["Registrant"]["Organisation"]; | |
+ $registrant_address1 = $params["contactdetails"]["Registrant"]["Address line 1"]; | |
+ $registrant_address2 = $params["contactdetails"]["Registrant"]["Address line 2"]; | |
+ $registrant_town = $params["contactdetails"]["Registrant"]["TownCity"]; | |
+ $registrant_zipcode = $params["contactdetails"]["Registrant"]["Zip code"]; | |
+ $registrant_countrycode = $params["contactdetails"]["Registrant"]["Country Code"]; | |
+ } | |
+ | |
$registrant_state = $params["contactdetails"]["Registrant"]["State"]; | |
- $registrant_zipcode = $params["contactdetails"]["Registrant"]["Zip code"]; | |
- $registrant_countrycode = $params["contactdetails"]["Registrant"]["Country Code"]; | |
$registrant_phone = $params["contactdetails"]["Registrant"]["Phone"]; | |
#$registrant_fax = '', | |
$registrant_email = $params["contactdetails"]["Registrant"]["Email"]; | |
+ | |
+ # Günter Grodotzki <[email protected]> - 20140606 | |
+ # Support International Contacts | |
+ if ($registrant_countrycode === 'ZA') { | |
+ $postalInfoType = 'loc'; | |
+ } else { | |
+ $postalInfoType = 'int'; | |
+ # according to https://www.registry.net.za/content.php?wiki=1&contentid=9&title=Contact%20Create#command | |
+ # we need to translit everything to ascii | |
+ # also sane SysAdmins should set up a corret locale, won't change this | |
+ # in PHP itself due to race condition | |
+ # see: http://www.php.net/manual/en/function.iconv.php#74101 | |
+ $registrant_name = _cozaepp_AsciiTranslit($registrant_name); | |
+ $registrant_org = _cozaepp_AsciiTranslit($registrant_org); | |
+ $registrant_address1 = _cozaepp_AsciiTranslit($registrant_address1); | |
+ $registrant_address2 = _cozaepp_AsciiTranslit($registrant_address2); | |
+ $registrant_town = _cozaepp_AsciiTranslit($registrant_town); | |
+ // state is optional, though max length is 16, it might not work with | |
+ // a lot of international states, so lets just void it... | |
+ //$registrant_state = iconv('UTF-8', 'ASCII//TRANSLIT', $registrant_state); | |
+ $registrant_state = '-'; | |
+ $registrant_zipcode = _cozaepp_AsciiTranslit($registrant_zipcode); | |
+ $registrant_countrycode = _cozaepp_AsciiTranslit($registrant_countrycode); | |
+ $registrant_phone = _cozaepp_AsciiTranslit($registrant_phone); | |
+ $registrant_email = _cozaepp_AsciiTranslit($registrant_email); | |
+ } | |
# Get client instance | |
try { | |
@@ -920,7 +981,7 @@ | |
<contact:update> | |
<contact:id>'.$registrant.'</contact:id> | |
<contact:chg> | |
- <contact:postalInfo type="loc"> | |
+ <contact:postalInfo type="'.$postalInfoType.'"> | |
<contact:name>'.$registrant_name.'</contact:name> | |
<contact:org>'.$registrant_org.'</contact:org> | |
<contact:addr> | |
@@ -1361,6 +1422,23 @@ | |
return $contact; | |
} | |
+ $rev = _cozaepp_getRevision(); | |
+ if($rev === 1) { | |
+ $key_company = 'Company Name'; | |
+ $key_address1 = 'Address 1'; | |
+ $key_address2 = 'Address 2'; | |
+ $key_city = 'City'; | |
+ $key_postcode = 'Postcode'; | |
+ $key_country = 'Country'; | |
+ } else { | |
+ $key_company = 'Organisation'; | |
+ $key_address1 = 'Address line 1'; | |
+ $key_address2 = 'Address line 2'; | |
+ $key_city = 'TownCity'; | |
+ $key_postcode = 'TownCity'; | |
+ $key_country = 'Country Code'; | |
+ } | |
+ | |
# Check for available contact id | |
$registrant = _cozaepp_CheckContact($sld . '.' . $tld); | |
@@ -1374,14 +1452,14 @@ | |
<contact:id>'.$registrant.'</contact:id> | |
<contact:postalInfo type="loc"> | |
<contact:name>'.$contact["Registrant"]["Contact Name"].'</contact:name> | |
- <contact:org>'.$contact["Registrant"]["Organisation"].'</contact:org> | |
+ <contact:org>'.$contact["Registrant"][$key_company].'</contact:org> | |
<contact:addr> | |
- <contact:street>'.$contact["Registrant"]["Address line 1"].'</contact:street> | |
- <contact:street>'.$contact["Registrant"]["Address line 2"].'</contact:street> | |
- <contact:city>'.$contact["Registrant"]["TownCity"].'</contact:city> | |
+ <contact:street>'.$contact["Registrant"][$key_address1].'</contact:street> | |
+ <contact:street>'.$contact["Registrant"][$key_address2].'</contact:street> | |
+ <contact:city>'.$contact["Registrant"][$key_city].'</contact:city> | |
<contact:sp>'.$contact["Registrant"]["State"].'</contact:sp> | |
- <contact:pc>'.$contact["Registrant"]["Zip code"].'</contact:pc> | |
- <contact:cc>'.$contact["Registrant"]["Country Code"].'</contact:cc> | |
+ <contact:pc>'.$contact["Registrant"][$key_postcode].'</contact:pc> | |
+ <contact:cc>'.$contact["Registrant"][$key_country].'</contact:cc> | |
</contact:addr> | |
</contact:postalInfo> | |
<contact:voice>'.$contact["Registrant"]["Phone"].'</contact:voice> | |
@@ -1732,3 +1810,57 @@ | |
return $values; | |
} | |
+/** | |
+ * Get hashmap revision according to the installed WHMCS version. Fallbacks to | |
+ * legacy version. | |
+ * ATTENTION: might break on newer versions, so always check before upgrading | |
+ * @author Günter Grodotzki <[email protected]> | |
+ * @return int | |
+ */ | |
+function _cozaepp_getRevision() { | |
+ | |
+ global $whmcs; | |
+ | |
+ if(isset($whmcs) && | |
+ $whmcs instanceof WHMCS_Application && | |
+ method_exists($whmcs, 'getVersion') && | |
+ $whmcs->getVersion() instanceof WHMCS_Version_SemanticVersion && | |
+ WHMCS_Version_SemanticVersion::compare($whmcs->getVersion(), new WHMCS_Version_SemanticVersion('5.2.1'), '>') | |
+ ) { | |
+ $rev = 1; | |
+ } else { | |
+ $rev = 0; | |
+ } | |
+ | |
+ // don't just simply return true/false, return a actual incremental revision | |
+ // number... | |
+ return $rev; | |
+} | |
+ | |
+/** | |
+ * ASCII//Translit wrapper | |
+ * @author Günter Grodotzki <[email protected]> | |
+ * @param string $string | |
+ * @return string | |
+ */ | |
+function _cozaepp_AsciiTranslit($string) { | |
+ | |
+ // ATTENTION!!! | |
+ // iconv needs to rely on setlocale or else it can return gibberisch, | |
+ // unfortunately setlocale is NOT thread safe (php-fpm, fastcgi, IIS, etc.) | |
+ // and CAN break if other scripts are using that function as well | |
+ // INSTEAD, lets use intl/icu, this is completely thread-safe. Unfortunately | |
+ // you will need at least php5.4, icu 4.8 and latest intl pecl - but if you | |
+ // have not been living under a rock the past years, I am pretty sure you | |
+ // will have a upated ENV, else checkout the following gist for debian | |
+ // squeeze instructions: | |
+ // https://gist.github.com/lifeofguenter/45d71d622a4aeea06346 | |
+ | |
+ if(function_exists('transliterator_transliterate')) { | |
+ $string = transliterator_transliterate('Any-Latin; Latin-ASCII; [\u0100-\u7fff] remove', $string); | |
+ } else { | |
+ setlocale('en_US.utf8'); | |
+ $string = iconv('UTF-8', 'ASCII//TRANSLIT//IGNORE', $string); | |
+ } | |
+ return $string; | |
+} | |
\ No newline at end of file |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment