Author Topic: any php coders? ((;  (Read 27863 times)

0 Members and 1 Guest are viewing this topic.

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Administrator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
any php coders? ((;
« 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!
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

Offline bernd

  • Full Member
  • ***
  • Posts: 214
    • View Profile
Re: any php coders? ((;
« Reply #1 on: January 03, 2003, 09:58:17 PM »
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

Code: [Select]
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

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Administrator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
any php coders? ((;
« Reply #2 on: January 03, 2003, 10:43:12 PM »
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
Code: [Select]
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:
Code: [Select]
 "lang_select" => $lang_select,

of course there is a much simplier and better way to do so, maybe someone can figure it out?
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

Offline Jan

  • Administrator
  • 4images Guru
  • *****
  • Posts: 5.024
    • View Profile
    • 4images - Image Gallery Management System
any php coders? ((;
« Reply #3 on: January 04, 2003, 09:35:29 AM »
Try this:

Code: [Select]
// We add the session id with "&" not "&amp;"
$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 "&amp;" to make it valid XHTML
$lang_url = str_replace("&", "&amp;", $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
Your first three "must do" before you ask a question:
1. Forum rules
2. FAQ
3. Search

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Administrator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
any php coders? ((;
« Reply #4 on: January 05, 2003, 05:58:27 PM »
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...
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

Offline Jan

  • Administrator
  • 4images Guru
  • *****
  • Posts: 5.024
    • View Profile
    • 4images - Image Gallery Management System
any php coders? ((;
« Reply #5 on: January 05, 2003, 07:48:32 PM »
Normally the variable $self_url should be the actual file. It should work on every page...

Jan
Your first three "must do" before you ask a question:
1. Forum rules
2. FAQ
3. Search

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Administrator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
any php coders? ((;
« Reply #6 on: January 05, 2003, 09:10:36 PM »
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?
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

Offline Jan

  • Administrator
  • 4images Guru
  • *****
  • Posts: 5.024
    • View Profile
    • 4images - Image Gallery Management System
any php coders? ((;
« Reply #7 on: January 05, 2003, 09:32:22 PM »
Maybe you should try to change the form method to "post". For me it works with "get".

Jan
Your first three "must do" before you ask a question:
1. Forum rules
2. FAQ
3. Search

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Administrator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
any php coders? ((;
« Reply #8 on: January 05, 2003, 10:24:21 PM »
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.:
Quote
$lang_url = $site_sess->url($self_url, "&");
$lang_url = preg_replace("/[?|&]l=[^?|&]*/", "", $lang_url);
$lang_url = str_replace("&", "&amp;", $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>&nbsp;";
    }else{
    $lang_select .= "<img src=\"".TEMPLATE_PATH."/images/".$folder."2.gif\" border=\"0\" alt=\"".$folder."\">&nbsp;";
    }
  }
}

>> 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:
Quote
     $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>&nbsp;";
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Administrator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
any php coders? ((;
« Reply #9 on: January 05, 2003, 11:12:38 PM »
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.
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

Offline Jan

  • Administrator
  • 4images Guru
  • *****
  • Posts: 5.024
    • View Profile
    • 4images - Image Gallery Management System
any php coders? ((;
« Reply #10 on: January 06, 2003, 10:23:08 AM »
Try to replace
Code: [Select]
$lang_url = $site_sess->url($self_url, "&");
$lang_url = preg_replace("/[?|&]l=[^?|&]*/", "", $lang_url);
$lang_url = str_replace("&", "&amp;", $lang_url);

with
Code: [Select]
$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
Your first three "must do" before you ask a question:
1. Forum rules
2. FAQ
3. Search

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Administrator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
any php coders? ((;
« Reply #11 on: January 06, 2003, 10:54:37 AM »
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...
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

Offline Jan

  • Administrator
  • 4images Guru
  • *****
  • Posts: 5.024
    • View Profile
    • 4images - Image Gallery Management System
any php coders? ((;
« Reply #12 on: January 06, 2003, 11:11:55 AM »
Ok sorry, my fault.

Replace
Code: [Select]
$lang_url = $site_sess->url($PHP_SELF.$query_string);
with
Code: [Select]
$lang_url = $site_sess->url($PHP_SELF.$query_string, '&');
$lang_url = preg_replace("/[?|&]l=[^?|&]*/", "", $lang_url);
$lang_url = str_replace("&", "&amp;", $lang_url);

Jan
Your first three "must do" before you ask a question:
1. Forum rules
2. FAQ
3. Search

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Administrator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
any php coders? ((;
« Reply #13 on: January 06, 2003, 12:13:56 PM »
woohoo!
now I can say: EXELENT!
thx again and again!
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Administrator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
any php coders? ((;
« Reply #14 on: January 07, 2003, 01:15:11 AM »
yes, u were right, Jan, I changed "get" to "post" and now it works perfectly with drop down form!

here is full working code:
Code: [Select]
$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 "&amp;"
$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 "&amp;" to make it valid XHTML
$lang_url = str_replace("&", "&amp;", $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);
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

 

Post your comments here