How coppermine stores language settings? How coppermine stores language settings?
 

News:

CPG Release 1.6.26
Correct PHP8.2 issues with user and language managers.
Additional fixes for PHP 8.2
Correct PHP8 error with SMF 2.0 bridge.
Correct IPTC supplimental category parsing.
Download and info HERE

Main Menu

How coppermine stores language settings?

Started by maolu, August 23, 2005, 09:30:28 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

maolu

Hi everybody.

I'm trying to understand the way used in coppermine to store the language selected by a user.
How can it remember the last language you selected and show the gallery in that lang at the next visit?
Is it a cookie?!?

And in what part of the code can i find the commands that read this information?

Thankyou a lot.


Joachim Müller


maolu

ok thx.
So how can i get, via php, the language stored in this cookie?

Joachim Müller

The user language is stored in $USER['lang']To get a list of everything that coppermine "knows" about a user, tryprint_r($USER);

maolu

i tried with
echo $USER['lang'];
but i get a costant result "r" :(

Right now i tested reading directly the cookie and it seems to work

$decoded = base64_decode($cpg133_data);
$lines = explode (":",$decoded);
$lastline = array_pop($lines);
$pieces = explode("\"",$lastline);
$currentLanguage = $pieces[1];

;D

maolu

OK, i have still problem with this issue... :\'( :\'( :\'(

The purpose is to be able to get and set the language values used in the gallery.
The reason is that i want to have also other pages in my site and of course if someone (I.E.) selects "english language" for the "LINKS" page, the same language has to be set also for the Coppermine Gallery and viceversa.

Right now the only functioning method i found in order to GET the language, as explined before,  is this:

function my_get_language($cookie)
{
    $decoded = base64_decode($cookie);
    $lines = explode (":",$decoded);
    $lastline = array_pop($lines);
    $pieces = explode("\"",$lastline);
    $currentLanguage = $pieces[1];
    return $currentLanguage;
}



In order to SET the language i use this method:

function my_set_language($cookieName, $cookie, $newLang)
{
    //GETS CURRENT LANGUAGE
    $decoded = base64_decode($cookie);
    $lines = explode (":",$decoded);
    $lastline = array_pop($lines);
    $pieces = explode("\"",$lastline);
    $currentLanguage = $pieces[1];
   
    //CREATES STRING WITH NEW LANGUAGE INFORMATION
    $decoded = base64_decode($cookie);
    $nonLanguageText = explode($currentLanguage, $decoded);
    $newLanguageString = base64_encode($nonLanguageText[0].$newLang.$nonLanguageText[1]);
   
    //SETS THE COOKIE WITH NEW LANGUAGE SETTINGS
    setcookie ($cookieName, $newLanguageString, time() + 86400, "/");
   
}



The problem is that right now it's not working... ::) :-[
So i tryed as a test to simply delete the Coppemine cookie using this:

setcookie("cpg133_data", "", time() - 3000, "");

But this is not worknig too, so i assume i'm not catching the point of the problem.
Can you help me?

Of course any kind of simpler solution is more then well accepted and if you say me "ehi you stupid, don't you know that you can use the function setGalleryCookieEasyer()!!" i'll be happy to hear that!
;D ;D ;D

Nibbler

Look at the lang handling code in include/init.inc.php

maolu

you mean this?

if (isset($USER['lang']) && !strstr($USER['lang'], '/') && file_exists('lang/' . $USER['lang'] . '.php')) {
    $CONFIG['default_lang'] = $CONFIG['lang'];          // Save default language
    $CONFIG['lang'] = strtr($USER['lang'], '$/\\:*?"\'<>|`', '____________');
} elseif ($CONFIG['charset'] == 'utf-8') {
    include('include/select_lang.inc.php');
    if (file_exists('lang/' . $USER['lang'] . '.php')) {
        $CONFIG['default_lang'] = $CONFIG['lang'];      // Save default language
        $CONFIG['lang'] = $USER['lang'];
    }
} else {
    unset($USER['lang']);
}


By now it's not so clean to me how to use this if i want to set/get the language from outside the gallery's php files.
:-\\ ???

I mean, what could i do?
From a custom php file can i set language this way?
$CONFIG['lang'] = "english"

Am I missing something?

maolu

Really no one knows it? ???

Somebody can tell me the reason why i cannot write into the Coppermine's cookies?

thx.

Joachim Müller

If you need custom information to be written, write your own cookie - don't abuse coppermine's cookie.

maolu

Quote from: GauGau on August 26, 2005, 09:21:51 AM
If you need custom information to be written, write your own cookie - don't abuse coppermine's cookie.

Did you read what i wrote?!?! >:(

No custom information, i'm talking about the selected language. I only want to use the selected coppermine language also outside of the galley, this way unifying it in all my site.