Lek Posted February 13, 2019 Share Posted February 13, 2019 Hello, I would like to show idn domain in the client area/my domains in utf8. For example instead of seei xn--tst-qla.de it should be able to see both: xn--tst-qla.de and täst.de I already have the php that translate from idn to utf8 so I just should insert a duplication of the database query. Which one is the file that contain that specific line? I attached an image to better understand. In the image there is no correspondence is an example. Thank you, bye. Lek 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted February 13, 2019 Share Posted February 13, 2019 4 hours ago, Lek said: I already have the php that translate from idn to utf8 so I just should insert a duplication of the database query. Which one is the file that contain that specific line? I suppose you could do this with a hook (looping though the array and adding a new element - though you may still need to edit the template), but you should be able to do it with a minor template tweak to clientareadomains.tpl and changing... <td><a href="http://{$domain.domain}" target="_blank">{$domain.domain}</a></td> to... <td><a href="http://{$domain.domain}" target="_blank">{if $domain.domain|strstr:'xn--'}{$domain.domain}<br>{idn_to_utf8($domain.domain)}{else}{$domain.domain}{/if}</a></td> that original line of template code is the same in v7.7.1 as it is in v6.3 (which I think is the version that you use)... so it should work for your template too. 0 Quote Link to comment Share on other sites More sharing options...
Lek Posted February 14, 2019 Author Share Posted February 14, 2019 Yes this is exactly what I was looking for but for some reasons in my system the idn_to_utf8($domain.domain) or echo idn_to_utf8('xn--tst-qla.de'); does not work, instead it does work this: <?php // for those who has PHP older than version 5.3 class IDN { // adapt bias for punycode algorithm private static function punyAdapt( $delta, $numpoints, $firsttime ) { $delta = $firsttime ? $delta / 700 : $delta / 2; $delta += $delta / $numpoints; for ($k = 0; $delta > 455; $k += 36) $delta = intval($delta / 35); return $k + (36 * $delta) / ($delta + 38); } // translate character to punycode number private static function decodeDigit($cp) { $cp = strtolower($cp); if ($cp >= 'a' && $cp <= 'z') return ord($cp) - ord('a'); elseif ($cp >= '0' && $cp <= '9') return ord($cp) - ord('0')+26; } // make utf8 string from unicode codepoint number private static function utf8($cp) { if ($cp < 128) return chr($cp); if ($cp < 2048) return chr(192+($cp >> 6)).chr(128+($cp & 63)); if ($cp < 65536) return chr(224+($cp >> 12)). chr(128+(($cp >> 6) & 63)). chr(128+($cp & 63)); if ($cp < 2097152) return chr(240+($cp >> 18)). chr(128+(($cp >> 12) & 63)). chr(128+(($cp >> 6) & 63)). chr(128+($cp & 63)); // it should never get here } // main decoding function private static function decodePart($input) { if (substr($input,0,4) != "xn--") // prefix check... return $input; $input = substr($input,4); // discard prefix $a = explode("-",$input); if (count($a) > 1) { $input = str_split(array_pop($a)); $output = str_split(implode("-",$a)); } else { $output = array(); $input = str_split($input); } $n = 128; $i = 0; $bias = 72; // init punycode vars while (!empty($input)) { $oldi = $i; $w = 1; for ($k = 36;;$k += 36) { $digit = IDN::decodeDigit(array_shift($input)); $i += $digit * $w; if ($k <= $bias) $t = 1; elseif ($k >= $bias + 26) $t = 26; else $t = $k - $bias; if ($digit < $t) break; $w *= intval(36 - $t); } $bias = IDN::punyAdapt( $i-$oldi, count($output)+1, $oldi == 0 ); $n += intval($i / (count($output) + 1)); $i %= count($output) + 1; array_splice($output,$i,0,array(IDN::utf8($n))); $i++; } return implode("",$output); } public static function decodeIDN($name) { // split it, parse it and put it back together return implode( ".", array_map("IDN::decodePart",explode(".",$name)) ); } } echo IDN::decodeIDN($_SERVER['HTTP_HOST']); ?> I don't know why the idn_to_utf8 does not work, I have php 5.6 it should work. Anyway how can I add the above php instruction in the .tpl? So I will then use IDN::decodeIDN instead of idn_to_utf8. Thank you, bye. Lek 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted February 14, 2019 Share Posted February 14, 2019 11 hours ago, Lek said: I don't know why the idn_to_utf8 does not work, I have php 5.6 it should work. I suggest you have a serious word with your host as to why the feature isn't working... as you say, it should be... and that above screenshot was from a v7.7 running on 5.6 given the alternative of having to go around the houses with multiple lines of code that you should be able to do with one, i'd put more effort into working this issue out with your host. 11 hours ago, Lek said: Anyway how can I add the above php instruction in the .tpl? So I will then use IDN::decodeIDN instead of idn_to_utf8. i'm tempted to say wrap it in {php} tags and see if that works... but if you think the answer is to use {php} in a smarty template like that, then you're asking the wrong question... it's not a good idea. what I would do would be to use a hook - take the domains array, loop though it, run your php function on the domain value, create a new idn domain value, return the array back to the template... and then in the template, you should have a new variable you can add to the template... but having said all that, I really would suggest contacting your host as to why idn_to_utf8 isn't working (perhaps it needs installing or enabling by them)... solving that would be far simpler than writing that hook! 0 Quote Link to comment Share on other sites More sharing options...
Lek Posted February 15, 2019 Author Share Posted February 15, 2019 Hello brian! You direct me in the right direction. It was an hosting related feature. To let idn_to_utf8 works also intl must be enable. So I did enable it and now it is OK, I can read the domain in both Latin and Thai characters. Thank you very much. By the way, I did try and then abandoned the idea of wrap php in tpl in the {php} tags but did not work. Maybe should be enable other things in the smarty. I wrap the whole code at the really top of the page. But at this point really it does not matter. Have a nice day, bye. Lek 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted February 15, 2019 Share Posted February 15, 2019 2 hours ago, Lek said: You direct me in the right direction. It was an hosting related feature. To let idn_to_utf8 works also intl must be enable. So I did enable it and now it is OK, I can read the domain in both Latin and Thai characters. i'd glad that you got this resolved! 0 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.