4images Forum & Community
General / Allgemeines => Chit Chat => Topic started by: V@no on January 01, 2003, 11:18:32 AM
-
Hi!
can someone help me out with this little task?
I cant figure out how those preg_match/preg_replace works...
if someone could help me a little bit...
when a user enter a URL " http://site.com/document.php?huh=0 "
I get part of that URL ( /document.php?huh=0 ) by " $REQUEST_URI; "
now I need check if there is already ?l= or &l= if not then add one at the end...
can someone help me plz? I'm trying fix the script with language chooser....
thx!
-
not being a php coder myself but maybe we can do it together ;)
I just assume you store the URL part in a variable $url then this could work
if (!preg_match("/\&l=/", $url) && !preg_match("/\?l=/", $url)) {
$url .= "\&l="; //or whatever you wanna add
}
else ; // do nothing
Didn't try it myself but please let me know once you figured how to do it.
cheers,
Bernd
-
hmm...it didnt work for me... :?
and I figured out how I can add language selection to any page, but it works only with TWO languages and it's so...bad coding...that's all I have php knolege right now...
this should be add to /includes/page_header.php file if ($config['language_dir'] == "russian"){
$selected_lang = $lang['lang_russian'];
$selected_lang2 = $lang['lang_english'];
$selected_lang3 = eregi_replace ('\?l=russian&','?',$site_sess->url($self_url));
$selected_lang3 = eregi_replace ('&l=russian&','&',$selected_lang3);
$selected_lang3 = eregi_replace ('\?l=russian','',$selected_lang3);
$selected_lang3 = eregi_replace ('&l=russian','',$selected_lang3);
}else{
$selected_lang = $lang['lang_english'];
$selected_lang2 = $lang['lang_russian'];
$selected_lang3 = (eregi('\?',$site_sess->url($self_url)) ? $site_sess->url($self_url."&l=russian") : $site_sess->url($self_url."?l=russian"));
}
$lang_select = "<FORM action=".$selected_lang3." method=\"post\" name=\"Language\">
<SELECT class=\"select\" name=\"service\" onChange=\"submit()\">
<OPTION selected value=\"\">".$selected_lang."</OPTION>
<OPTION value=\"\">".$selected_lang2."</OPTION>
</SELECT>
</form>";
and then register {lang_select} that u can add to any of your templates with this line:
"lang_select" => $lang_select,
of course there is a much simplier and better way to do so, maybe someone can figure it out?
-
Try this:
// We add the session id with "&" not "&"
$lang_url = $site_sess->url($self_url, "&");
// Now we can better remove the "l" parameter
$lang_url = preg_replace("/[?|&]l=[^?|&]*/", "", $lang_url);
// We replace "&" with "&" to make it valid XHTML
$lang_url = str_replace("&", "&", $lang_url);
$lang_select = "<form action=\"".$lang_url."\" method=\"get\">\n";
$lang_select .= "<select class=\"select\" name=\"l\" onChange=\"submit()\">\n";
// Now we open the "lang" folder, read out all available languages
// and add it as options to the dropdown.
$handle = opendir(ROOT_PATH."lang");
while ($folder = @readdir($handle)) {
if (@is_dir(ROOT_PATH."lang/".$folder) && $folder != "." && $folder != "..") {
$lang_select .= "<option value=\"".$folder."\"";
// If the folder name matches the current language,
// show the option as selected
if ($folder == $config['language_dir']) {
$lang_select .= " selected=\"selected\"";
}
$lang_select .= ">".$folder."</option>\n";
}
}
$lang_select .= "</select>\n</form>";
// Register the dropdown code for the template engine
$site_template->register_vars("lang_select", $lang_select);
Jan
-
yay! u are the man, Jan!
maybe it's good idea stick this thead as [MOD] ?! :?
now I even got german language! eheh
[EDITED]
but now it cant be added to any pages, because on lang selection it redirect to index.php page...
-
Normally the variable $self_url should be the actual file. It should work on every page...
Jan
-
yes, well, when I look at source of the page, it shows for ex. "<form action="category.php?cat_id=3" method="get"> witch is perfectly correct.
but when u chose different language it redirect to index.php.
so, I checked in apache access log and i found that after I choose different languge it send request for category.php?l=russian and cat_id=3 dissapiers somewhere...
that's probably something in the way <form> handle the get request?
-
Maybe you should try to change the form method to "post". For me it works with "get".
Jan
-
with post its kind of wierd happening...
but, here is modified code that will dosplay pictures (flags in my case)
or u can easy change it to have text links or anything.:
$lang_url = $site_sess->url($self_url, "&");
$lang_url = preg_replace("/[?|&]l=[^?|&]*/", "", $lang_url);
$lang_url = str_replace("&", "&", $lang_url);
$handle = opendir(ROOT_PATH."lang");
$lang_select = "";
while ($folder = @readdir($handle)) {
if (@is_dir(ROOT_PATH."lang/".$folder) && $folder != "." && $folder != "..") {
if ($folder != $config['language_dir']) {
$lang_select .= "<a class=\"lang\" href=\"".$lang_url.(preg_match("/\?/", $lang_url) ? "&" : "?")."l=".$folder."\"><img src=\"".TEMPLATE_PATH."/images/".$folder.".gif\" border=\"0\" alt=\"".$folder."\"></a> ";
}else{
$lang_select .= "<img src=\"".TEMPLATE_PATH."/images/".$folder."2.gif\" border=\"0\" alt=\"".$folder."\"> ";
}
}
}
>> the bold lines are images that will be displaed, the names of images are the same as language folders. then needs to be in /templates/yourtemplate/images/ folder
>> the red letter is suffix for image name, its needed if u want use different picture for curent language picture, in my case I chosed print faded picture. u can delete it.
if u need nice animated pictures of flags, u can try www.gifworks.com also there is u can edit pictures, without even download anything. I cut and resized flags that I use on my site using their pictures and editing tools.
thx, Jan, I would never could do this without your help!
[EDITED]
also, here is little change if u dont want " l= " for default language:
$lang_select .= "<a class=\"lang\" href=\"".$lang_url.(preg_match("/english/i",$folder) ? "" : ((preg_match("/\?/", $lang_url) ? "&" : "?")."l=".$folder))."\"><img src=\"".TEMPLATE_PATH."/images/".$folder.".gif\" border=\"0\" alt=\"".$folder."\"></a> ";
-
hmm...ok, again something came up...
seems that " $site_sess->url($self_url, "&"); " doesnt return what is after " ? " when uses "action=" (member.php?action=showprofile&user_id=4)
so, if u looking at users profile and change lang. it will open "lost password" page.
-
Try to replace
$lang_url = $site_sess->url($self_url, "&");
$lang_url = preg_replace("/[?|&]l=[^?|&]*/", "", $lang_url);
$lang_url = str_replace("&", "&", $lang_url);
with
$query_string = '';
if (!empty($HTTP_GET_VARS)) {
foreach ($HTTP_GET_VARS as $key => $val) {
if ($key != "l") {
$query_string .= ($query_string != '' ? '&' : '?').$key."=".$val;
}
}
}
$lang_url = $site_sess->url($PHP_SELF.$query_string);
Jan
-
thx, Jan.
it does fixed action= problem, but now it doesnt change language on that page, it change ones, and there is already tag l=lang it doesnt remove it, and just add another l=lang tag...
-
Ok sorry, my fault.
Replace
$lang_url = $site_sess->url($PHP_SELF.$query_string);
with
$lang_url = $site_sess->url($PHP_SELF.$query_string, '&');
$lang_url = preg_replace("/[?|&]l=[^?|&]*/", "", $lang_url);
$lang_url = str_replace("&", "&", $lang_url);
Jan
-
woohoo!
now I can say: EXELENT!
thx again and again!
-
yes, u were right, Jan, I changed "get" to "post" and now it works perfectly with drop down form!
here is full working code:$query_string = '';
if (!empty($HTTP_GET_VARS)) {
foreach ($HTTP_GET_VARS as $key => $val) {
if ($key != "l") {
$query_string .= ($query_string != '' ? '&' : '?').$key."=".$val;
}
}
}
// We add the session id with "&" not "&"
$lang_url = $site_sess->url($PHP_SELF.$query_string, '&');
// Now we can better remove the "l" parameter
$lang_url = preg_replace("/[?|&]l=[^?|&]*/", "", $lang_url);
// We replace "&" with "&" to make it valid XHTML
$lang_url = str_replace("&", "&", $lang_url);
$lang_select = "<form action=\"".$lang_url."\" method=\"post\">\n";
$lang_select .= "<select class=\"select\" name=\"l\" onChange=\"submit()\">\n";
// Now we open the "lang" folder, read out all available languages
// and add it as options to the dropdown.
$handle = opendir(ROOT_PATH."lang");
while ($folder = @readdir($handle)) {
if (@is_dir(ROOT_PATH."lang/".$folder) && $folder != "." && $folder != "..") {
$lang_select .= "<option value=\"".$folder."\"";
// If the folder name matches the current language,
// show the option as selected
if ($folder == $config['language_dir']) {
$lang_select .= " selected=\"selected\"";
}
$lang_select .= ">".$folder."</option>\n";
}
}
$lang_select .= "</select>\n</form>";
// Register the dropdown code for the template engine
$site_template->register_vars("lang_select", $lang_select);
-
yes, u were right, Jan, I changed "get" to "post" and now it works perfectly with drop down form!
here is full working code:$query_string = '';
if (!empty($HTTP_GET_VARS)) {
foreach ($HTTP_GET_VARS as $key => $val) {
if ($key != "l") {
$query_string .= ($query_string != '' ? '&' : '?').$key."=".$val;
}
}
}
// We add the session id with "&" not "&"
$lang_url = $site_sess->url($PHP_SELF.$query_string, '&');
// Now we can better remove the "l" parameter
$lang_url = preg_replace("/[?|&]l=[^?|&]*/", "", $lang_url);
// We replace "&" with "&" to make it valid XHTML
$lang_url = str_replace("&", "&", $lang_url);
$lang_select = "<form action=\"".$lang_url."\" method=\"post\">\n";
$lang_select .= "<select class=\"select\" name=\"l\" onChange=\"submit()\">\n";
// Now we open the "lang" folder, read out all available languages
// and add it as options to the dropdown.
$handle = opendir(ROOT_PATH."lang");
while ($folder = @readdir($handle)) {
if (@is_dir(ROOT_PATH."lang/".$folder) && $folder != "." && $folder != "..") {
$lang_select .= "<option value=\"".$folder."\"";
// If the folder name matches the current language,
// show the option as selected
if ($folder == $config['language_dir']) {
$lang_select .= " selected=\"selected\"";
}
$lang_select .= ">".$folder."</option>\n";
}
}
$lang_select .= "</select>\n</form>";
// Register the dropdown code for the template engine
$site_template->register_vars("lang_select", $lang_select);
Welche Dateien muss ich hierfür ändern und an welche Stelle muss ich den neuen Code einfügen? Das ist mir noch nicht klar....