centralnicgroup-opensource / rtldev-middleware-whmcs

CentralNic's WHMCS Software Bundle
https://centralnicreseller.com
Other
39 stars 15 forks source link

Transliteration hook doesn't work with registrations ? #196

Closed chrismfz closed 3 years ago

chrismfz commented 3 years ago

For years we had a transliteration hook (in includes/hooks/) running with another provider. We had a function to change from Greek to Greeklish beased on the Greeklish ISO ( https://en.wikipedia.org/wiki/ISO_843 )

https://docs.whmcs.com/Custom_Transliteration

Switching from them to hexonet, with the migration hook/plugin everything is fine. Transfers too.

But with ispapi for registrations and registrations only, this hook stopped / or the plugin ignores it ? I don't know. Hexonet doesn't accept Greek characters and I am getting errors like: Invalid attribute value; INVALID CONTACT [OWNERCONTACT (Invalid attribute value; Invalid char in NAME [Α])] For contact name, city, address, and so on. The "A" it's just the first Greek character of the full name.

KaiSchwarz-cnic commented 3 years ago

We in general ignore transliterations by using $params["original"] in our registrar module functions because dealing with unicode chars shouldn't be problematic. Therefore having data/inputs unchanged is important and the reason why we are using the above approach. I will report this to our backend engineers and will keep you posted.

Just for reference, would you mind providing us that transliteration implementation?

chrismfz commented 3 years ago

Hi papakai, we use this:

[root@pluto hooks]# cat greeklish.php
<?php

function hook_transliterate($string) {
    $string = str_replace("α","a",$string);
    $string = str_replace("ά","a",$string);
    $string = str_replace("Α","A",$string);
    $string = str_replace("Ά","A",$string);

    $string = str_replace("β","v",$string);
    $string = str_replace("Β","v",$string);

    $string = str_replace("α","a",$string);
    $string = str_replace("α","a",$string);

    $string = str_replace("Γ","G",$string);
    $string = str_replace("γ","g",$string);

    $string = str_replace("Δ","D",$string);
    $string = str_replace("δ","d",$string);

    $string = str_replace("ε","e",$string);
        $string = str_replace("Ε","E",$string);
        $string = str_replace("έ","e",$string);
        $string = str_replace("Έ","E",$string);

        $string = str_replace("Ζ","Z",$string);
        $string = str_replace("ζ","z",$string);

        $string = str_replace("Η","I",$string);
        $string = str_replace("η","i",$string);
        $string = str_replace("ή","i",$string);
        $string = str_replace("Ή","I",$string);

        $string = str_replace("Θ","Th",$string);
        $string = str_replace("θ","th",$string);

        $string = str_replace("Ι","I",$string);
        $string = str_replace("ι","i",$string);
        $string = str_replace("ί","i",$string);
        $string = str_replace("Ί","i",$string);

        $string = str_replace("Κ","K",$string);
        $string = str_replace("κ","k",$string);

        $string = str_replace("Λ","L",$string);
        $string = str_replace("λ","l",$string);

        $string = str_replace("Μ","M",$string);
        $string = str_replace("μ","m",$string);

        $string = str_replace("Ν","N",$string);
        $string = str_replace("ν","n",$string);

        $string = str_replace("Ξ","X",$string);
        $string = str_replace("ξ","x",$string);

        $string = str_replace("Ο","O",$string);
        $string = str_replace("ο","o",$string);
        $string = str_replace("Ό","O",$string);
        $string = str_replace("ό","o",$string);

        $string = str_replace("Π","P",$string);
        $string = str_replace("π","p",$string);

        $string = str_replace("Ρ","R",$string);
        $string = str_replace("ρ","r",$string);

        $string = str_replace("Σ","S",$string);
        $string = str_replace("σ","s",$string);
        $string = str_replace("ς","s",$string);

        $string = str_replace("Τ","T",$string);
        $string = str_replace("τ","t",$string);

        $string = str_replace("Υ","Y",$string);
        $string = str_replace("υ","y",$string);
        $string = str_replace("ύ","y",$string);
        $string = str_replace("Ύ","Y",$string);

        $string = str_replace("Φ","F",$string);
        $string = str_replace("φ","f",$string);

        $string = str_replace("Χ","Ch",$string);
        $string = str_replace("χ","ch",$string);

        $string = str_replace("Ψ","Ps",$string);
        $string = str_replace("ψ","ps",$string);

        $string = str_replace("Ω","O",$string);
        $string = str_replace("ω","o",$string);
        $string = str_replace("ώ","o",$string);
        $string = str_replace("Ώ","O",$string);

    return $string;
}

add_hook("Transliteration",1,"hook_transliterate");

?>
KaiSchwarz-cnic commented 3 years ago

@chrismfz I've discussed this deeply with our backend engineers. Our systems are UTF-8 ready, but finally it depends on the registry provider behind that TLD. So, for gTLDs/nTLDs it might be working with language specific characters, but not with some ccTLDs.

I'll dive into reviewing our module to either considering $params (the transliterated data) or to provide a build-in possibility (how ever it might look like). One reason why we used $params["original"] over $params was that there had been problems with IDNs - but this was long before I started with WHMCS Development (and maybe a result of a buggy old WHMCS Version). I'll have to analyze this to ensure nothing breaks - WHMCS comes with a default transliteration which might then influence IDNs. Basically / IMHO transliteration should only influence contact data, that's what I have to analyze first.

I'll keep you posted.

KaiSchwarz-cnic commented 3 years ago

@chrismfz this is in work and results are already looking good. We will start shipping the transliteration with our registrar module, but still you have to copy that file to includes/hooks as replacement for your existing transliteration. In addition to the greeklish transliteration it will also cover replacing html entities with their utf-8 representations.

It will just need a bit of time until we release. The next update is coming with huge improvements regarding additional domain fields and updating contact information.

Do you have additional transliterations in place, or is it just about the greeklish one?

chrismfz commented 3 years ago

Only the greeklish! Thank you <3 !

KaiSchwarz-cnic commented 3 years ago

btw., having add_hook("Transliteration",1,"hook_transliterate"); in place isn't required any longer. That's what they point out in the docs. I tested it, and yes it really works without that line of code. You just need to have the function hook_transliterate defined and in place. Even the file name doesn't matter in /includes/hooks. (I wasn't even able to find this hook somewhere defined)

Still, other projects are also using it:

I left the cyrillic chars out of our upcoming release and also the Greeklish ones might get deprecated in future. We will add such things step by step to our Backend API (some are already there), so that all integrations can benefit of it and there, these transliterations will just happen where special characters are not supported on registry provider side, with whmcs this is always happening.

KaiSchwarz-cnic commented 3 years ago

Released as v6.0.4. Read my Notes here before upgrading.