[TYPO3-english] Add language parameter to external link

Joerg Wagner [DigiLog] news.netfielders.de at digilog.de
Fri Mar 27 13:26:02 CET 2009


Here is an updated version of the PHP function in file 
ts_user_functions.php that takes the scheme into account that can be 
selected together with the external URL:


<?php
class user_functions{

   function user_addLangIdToExternalUrl($content, $conf){
     // get params from calling TS
     $pLangUID = $conf['langUID'];  // config.sys_language_uid

     // if link type is "external url" replace link to redirecting page 
with external url and add language param
     if($this->cObj->data['doktype']==3){
       $urlSchemes = array(0=>'', 1=>'http://', 2=>'ftp://', 
3=>'mailto:', 4=>'https://');
       $content = preg_replace('/(<a[^>]*href=")[^"]*("[^>]*>)/i', 
'$1'.$urlSchemes[$this->cObj->data['urltype']].$this->cObj->data['url']."?L=$pLangUID".'$2', 
$content);
     }

     return $content;
   }

}
?>


Joerg Wagner schrieb:
> Hello Tony,
> 
>  > I would like to append the currently active L parameter to the 
> external link ...
> 
> I had a similar problem with menu items that had to link to external 
> urls and also needed the L parameter to be attached. Took me quite some 
> time to solve it. Maybe my solution can be adapted to your problem.
> 
> 
> TS-Setup:
> 
> config.sys_language_uid = 0
> [globalVar = GP:L=1]
>   config.sys_language_uid = 1
> [global]
> [globalVar = GP:L=2]
>   config.sys_language_uid = 2
> [global]
> ...
> 
> includeLibs.myUserFunctions = fileadmin/templates/php/ts_user_functions.php
> 
> ...
> 
> # TS of the menu that contains external URLs:
> lib.mainMenu = HMENU
> lib.mainMenu {
>   1 = GMENU
>   1 {
>     NO {
>       allStdWrap.postUserFunc.langUID < config.sys_language_uid
>       allStdWrap.postUserFunc = user_functions->user_addLangIdToExternalUrl
>       ...
>     }
>   ...
>   }
> }
> 
> 
> 
> The PHP function in file ts_user_functions.php:
> 
> <?php
> class user_functions{
>   function user_addLangIdToExternalUrl($content, $conf){
>     // get params from calling TS
>     $pLangUID = $conf['langUID'];  // config.sys_language_uid
> 
>     // if link type is "external url" replace link to redirecting page 
> with external url and add language param
>     if($this->cObj->data['doktype']==3){
>       $content = preg_replace('/(<a[^>]*href=")[^"]*("[^>]*>)/i', 
> '$1http://'.$this->cObj->data['url']."?L=$pLangUID".'$2', $content);
>     }
> 
>     return $content;
>   }
> }
> ?>
> 
> 
> Should work for TMENU too. Side effect is that the href attribute of the 
> modified links points directly to the external urls instead of an 
> internal page id that is normally internally redirected by TYPO3.
> 
> Hope that helps,
> Jörg.
> 
> 
> 
> Stephan Bauer schrieb:
>  > Hallo,
>  >
>  > ich möchte per typoscript einen Paramter an einen externen Link in 
> einem Text-Content-Element anhängen.
>  > Z.B. im Textfeld steht der Link
>  > <link www.test.de>Hier klicken</link>
>  >
>  > An diesen Link möchte ich die aktuelle Sprache meiner Seite anhängen 
> (z.B. ?lang=de)
>  >
>  > Zusätzlich möchte ich noch eine per user_func
>  > generierte Checksumme anhängen (z.B. &check=098f6bcd)
>  >
>  > Ich habe mich zu tode gesucht und nichts gefunden.
>  >
>  > Vielen Dank im Voraus.
>  >
>  > Grüße
>  >
>  > Stephan
>  >
> 
> 
> 
> 
> Tony Lush schrieb:
>> I have a TYPO3 site in three languages that links to a sister catalog 
>> site that is also in the same languages. I would like to append the 
>> currently active L parameter to the external link so the user goes 
>> directly to the correct language. The languages are English, Spanish 
>> and Chinese, TYPO3 4.2.2, RealURL 1.5.2.
>>
>> Thank you -- Tony Lush


More information about the TYPO3-english mailing list