[TYPO3] set language variable from TS
Sebastian Fuchs
sebastian at hexerei.net
Wed Jun 28 18:14:38 CEST 2006
Hi,
just wanted to post my solution to my problem. probably it helps
somebody....
for the country selection i use now a menu generated by a userfunction.
This userfunction takes 3 TS varaibles defining
a. the Page UIDs of the menu items to show
b. the sys_language uids to link to
c. the sys_language uids to display the link in
with this function i am sure that the different country trees are
entered in a defined language.
it is called by this TS-snip:
temp.menu_international = COA
temp.menu_international {
20 < temp.menu_mask
20.special = userfunction
20.special.userFunc = user_menuFunc->makeInternationalMenu
20.special.userFunc.value = 3,270,540
20.special.userFunc.lang = 1,2,5
20.special.userFunc.displaylang = -1
}
the file has to be included and now the class-code:
require_once(PATH_tslib."class.tslib_pibase.php");
class user_menuFunc extends tslib_pibase {
var $prefixId = "user_menuFunc"; // Same as class name
var $scriptRelPath = "scripts/class.user_menuFunc.php"; // Path to this
script relative to the extension dir.
/** Build the international menu
* conf parameters are:
* userFunc.value = comma-sep-list of page uids in the menu (e.g. 3,244)
* userFunc.lang = comma-sep-list of language_uids to link to or
single negative value for all entries to link to (e.g 0,3,5 or -5)
* userFunc.displaylang = comma-sep-list of language_uids to display
the link in or single negative value for all entries display in (e.g
0,0,1,3,5 or -5)
* @param string Content-String
* @param array TS-Configuration Array
* @return array of menu entries
* @access public
*/
function makeInternationalMenu($content,$conf){
//debug($conf);
if ( isset($conf['userFunc.']) && isset($conf['userFunc.']['value']) ) {
$pid_arr = t3lib_div::intExplode(',',$conf['userFunc.']['value']);
$lang_arr = t3lib_div::intExplode(',',$conf['userFunc.']['lang']);
$displaylang_arr =
t3lib_div::intExplode(',',$conf['userFunc.']['displaylang']);
$ret_arr = array();
for($i=0;$i<count($pid_arr);$i++){
if( $lang_arr[0] < 0 || !isset($lang_arr[$i])){
$lang_id = abs($lang_arr[0]);
} else {
$lang_id = $lang_arr[$i];
}
if( $displaylang_arr[0] < 0 || !isset($displaylang_arr[$i])){
$displaylang_id = abs($displaylang_arr[0]);
} else {
$displaylang_id = $displaylang_arr[$i];
}
$uid = $pid_arr[$i];
if($displaylang_id>0) {
$res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*',
'pages_language_overlay', 'pid='.$uid.' AND
sys_language_uid='.$displaylang_id , 'uid,title');
$row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res);
} else {
$row = $this->pi_getRecord('pages',$uid,1);
}
if ( is_array($row) ) {
$titel = $row['title'];
} else {
continue;
}
if( $lang_id>0 ){
$param=array('L'=>$lang_id);
} else {
$param=array('L'=>0);
}
$ret_arr[$i] = array(
'title' => $titel,
'_OVERRIDE_HREF' => $this->pi_getPageLink($uid,'',$param),
);
}
return $ret_arr;
} else {
return array();
}
} // makeInternationalMenu
}
greetings,
sebastian
More information about the TYPO3-english
mailing list