Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Re: Switch language menu for all users
- using
register_callback("plug", "admin","",0);put my snippet after the rest of the page code, so when I save the selected language, there’s only the footer of the page that change with the new language immediately (but when I look at an other tab : all is OK). - The best way is to put the snippet at the top of the page just after the body tag, but
register_callback("plug", "admin","",1);put it out of the html code. - is there’s a way to put my snippet just after the body tag, before the rest of the txp page code will be loaded ?
- is the “rewrite on the fly” of the buffer is the only solution ?
françois
Offline
Re: Switch language menu for all users
register_callback("plug", "admin","",0); and use Javascript to insert the HTML in the right spot.
Offline
Re: Switch language menu for all users
ruud a écrit:
register_callback("plug", "admin","",0);and use Javascript to insert the HTML in the right spot.
Thanks ruud : will have a look at this Javascript way.
françois
Offline
Re: Switch language menu for all users
Well I’ve used Javascript with DOM to put my dropdown menu on the right place of the DOM : it’s OK.
… but I have the same issue : when the code is loaded by PHP, “my” snippet is executed after the rest of the page (register_callback("plug", "admin","",0)), so when I save the selected language, there’s only the footer of the page that changed immediately with the new language.
I think that I should take the buffer on the fly and work on it : but at now, I can’t figure out how to capture it : I saw developpers using
function myfunc($buffer) ....
but I don’t understand where $buffer come from : any idea are welcome ;-)
Last edited by fpradignac (2007-12-12 08:13:25)
françois
Offline
#20 2007-12-12 08:08:30
- net-carver
- Archived Plugin Author
- Registered: 2006-03-08
- Posts: 1,648
Re: Switch language menu for all users
— Steve
Offline
Re: Switch language menu for all users
Thanks Steve, I saw and try ob_start() but for now, it’s a bite “esotheric” for me … but I will take more time to understand this PHP buffering output function : it’s the good way for me.
françois
Offline
Re: Switch language menu for all users
OK ! I’ve got it now, just a little improvment and it will be good for me.
françois
Offline
#23 2007-12-12 10:12:21
- net-carver
- Archived Plugin Author
- Registered: 2006-03-08
- Posts: 1,648
Re: Switch language menu for all users
françois
back again — but sounds like you worked out the missing connection between your function myfunc($buffer) and the ob_start( 'myfunc' ); for yourself. <grin>
— Steve
Offline
Re: Switch language menu for all users
The language choice can be done like that (0 as last parameter in register_callback), but once the language is chosen, you use a callback to change the language before the page begins rendering (1 as last parameter). So you need 2 register_callbacks.
Offline
Re: Switch language menu for all users
ruud a écrit:
The language choice can be done like that (
0as last parameter in register_callback), but once the language is chosen, you use a callback to change the language before the page begins rendering (1as last parameter). So you need 2 register_callbacks.
Thanks ruud, but with only one register_callback and the last parameter at 1 I made it work.
register_callback("prad_switch_lang", "admin","",1);function prad_switch_lang(): select and change the languagefunction xxx()capture the buffer withob_start()function yyy()built the HTML andreturn
I’ll give you this plugin to test it soon ;-)
françois
Offline
Re: Switch language menu for all users
prad_switch_lang is born.
Just have a look here .
Compatibility with 4.0.2 > 4.0.5
Last edited by fpradignac (2007-12-12 20:10:17)
françois
Offline
#27 2007-12-13 01:00:53
- net-carver
- Archived Plugin Author
- Registered: 2006-03-08
- Posts: 1,648
Re: Switch language menu for all users
françois
Congratulations!!! I just pulled it and tried it, and it seems to work fine for me. Thank you for the credits too.
I notice you do this in prad_switch_lang()…
if (!$message && ps('step')=='list_languages' && ps('language'))
{
$locale = doSlash(getlocale(ps('language')));
safe_update("txp_prefs","val='".doSlash(ps('language'))."'", "name='language'");
safe_update("txp_prefs","val='". $locale ."'", "name='locale'");
$textarray = load_lang(doSlash(ps('language')));
$locale = setlocale(LC_ALL, $locale);
$message = gTxt('preferences_saved');
}
But you could try…
$language = ps('language');
if (!$message && ps('step')=='list_languages' && $language)
{
$locale = doSlash(getlocale($language));
safe_update("txp_prefs","val='".doSlash($language)."'", "name='language'");
safe_update("txp_prefs","val='". $locale ."'", "name='locale'");
$textarray = load_lang(doSlash($language));
$locale = setlocale(LC_ALL, $locale);
$message = gTxt('preferences_saved');
}
for a little more efficiency.
Finally, a couple of things I’ve found out (the hard way) about using output buffer processing routines like prad_switch_langHTML($buffer)…
- If any error occurs at all in them, you’ll get a blank page as a result. So if you ever see a totally blank
admin > usertab, it’s probably an error in your routine. - If you ever need to access an object that was created before the output buffer processing started then you’ll find that the object is already destroyed by the time your routine is called if you are using php5 — but on php4 it will still be in existence.
— Steve
Offline
Re: Switch language menu for all users
fpradignac,
It’s really nice that you sorted it out and produced a plugin too :)
But to notice that prad_ shoud be a three lettered prefix , not a four, as the quideline says.
Cheers!
Offline
Re: Switch language menu for all users
Gocom a écrit:
But to notice that
prad_shoud be a three lettered prefix , not a four, as the quideline says.
Yes, but I’m still recorded in his list with my four letters prefix. I’ll look at this point : can I have 2 prefix ? prad_ for my older ones and prd_ for th new one ?
But please Gocom test it, I saw that you don’t downloaded it ;-))))
_Steve
Thanks for testing !!!
Has you can see in my hard code, I’m not a programmer, I’ve just hack a function of txp_prefs.php, so your help is very important to make a «cleaner» code.
- I don’t know how to test and break if “If any error occurs”.
- I don’t understand the scope of your remark ? Should I have to improve this point ?
françois
Offline
#30 2007-12-13 06:13:36
- net-carver
- Archived Plugin Author
- Registered: 2006-03-08
- Posts: 1,648
Re: Switch language menu for all users
françois
No, no need to change anything — it works fine as it is — what I posted was just an optional ‘tweak’ that saves you calling the ps() routine repeatedly.
Regarding the output buffer stuff: I was just sharing some hard-won experience. The MLP pack makes use of buffer processing quite a lot and its hard to debug code inside these processing routines.
— Steve
Offline