cvs: phpweb / my.php /include langchooser.inc

From: Date: Thu, 13 Mar 2003 17:06:26 +0000
Subject: cvs: phpweb / my.php /include langchooser.inc
Groups: php.mirrors 
Request: Send a blank email to php-mirrors+get-16320@lists.php.net to get a copy of this message
goba Thu Mar 13 12:06:26 2003 EDT Added files: /phpweb my.php Modified files: /phpweb/include langchooser.inc Log: Adding new array creation to langchooser, so we can inform users about how we have parsed their accept-language Add the first version of my.php (which will enable users to set their own languages). Please don't spread the word, this needs testing, before it can go live for all users... Index: phpweb/include/langchooser.inc diff -u phpweb/include/langchooser.inc:1.13 phpweb/include/langchooser.inc:1.14 --- phpweb/include/langchooser.inc:1.13 Tue Mar 11 16:28:57 2003 +++ phpweb/include/langchooser.inc Thu Mar 13 12:06:25 2003 @@ -1,6 +1,6 @@ <?php // -*- C++ -*- -// $Id: langchooser.inc,v 1.13 2003/03/11 21:28:57 goba Exp $ +// $Id: langchooser.inc,v 1.14 2003/03/13 17:06:25 goba Exp $ /* @@ -17,6 +17,12 @@ language, or will not exist if there are only implications on the preferred language. + $UA_LANGS will contain the user agent language settings + parsed as an array. The language names are corrected for + php.net usage in this array. This is just to present to + the user in case he would like to get information on the + parsed language information (see /my.php). + The $_SERVER['STRIPPED_URI'] var is also set to the stripped request URI (in case of a shortcut, the language is stipped, so the shortcut handling code @@ -29,7 +35,7 @@ // The code is encapsulated in a function, // so the variable namespace is not polluted -list($LANG, $EXPL_LANG) = language_choose_code(); +list($LANG, $EXPL_LANG, $UA_LANGS) = language_choose_code(); // Compatibility if ($EXPL_LANG == '') { unset($EXPL_LANG); } @@ -72,11 +78,13 @@ $explicitly_specified = $flang; } } + + // MYPHPNET handling should be added here // Specified by the user via the browser's Accept Language setting // Samples: "hu, en-us;q=0.66, en;q=0.33", "hu,en-us;q=0.5" $browser_accept = explode(",", $_SERVER['HTTP_ACCEPT_LANGUAGE']); - $browser_langs = array(); + $browser_langs = array(); $parsed_langs = array(); // Go through all language preference specs foreach ($browser_accept as $langpref) { @@ -113,7 +121,7 @@ } // Add language to priority order - language_add($langdata[0], $languages); + $parsed_langs[] = language_add($langdata[0], $languages); } // Language preferred by this mirror site @@ -134,7 +142,7 @@ } // Return with all found data - return array($selected, $explicitly_specified); + return array($selected, $explicitly_specified, $parsed_langs); } Index: phpweb/my.php +++ phpweb/my.php <?php include_once 'prepend.inc'; commonHeader("My PHP.net"); // Languages array copy and options to list $langs = $LANGUAGES; $options = array(); // We have post data, and it is an available language if (isset($_POST['my_lang']) && isset($langs[$_POST['my_lang']])) { // Set the language in a cookie for a year and for all *.php.net servers setcookie("MYPHPNET", $_POST['my_lang'], time() + 60*60*24*365, '/', '.php.net'); // Add this as first option, selected $options[] = '<option value="' . $_POST['my_lang'] . '" selected>' . $langs[$_POST['my_lang']] . "</option>\n"; // Remove, so it is not listed two times unset($langs[$_POST['lang']]); } // We have recevied a cookie and it is an available language elseif (isset($_COOKIE['MYPHPNET']) && isset($langs[$_COOKIE['MYPHPNET']])) { // Add this as first option, selected $options[] = '<option value="' . $_COOKIE['MYPHPNET'] . '" selected>' . $langs[$_COOKIE['MYPHPNET']] . "</option>\n"; // Remove, so it is not listed two times unset($langs[$_COOKIE['MYPHPNET']]); } // We have no cookie and no form submitted else { // Add this as first option, selected $options[] = "<option value=\"not_set\" selected>Not Set</option>\n"; } // Add all other languages foreach ($lang as $code => $name) { $options[] = '<option value="' . $code . '">' . $name . "</option>\n"; } // Assemble form from collected data $langpref = "<form action=\"/my.php\" method=\"POST\">\n<select name=\"my_lang\">\n" . join("", $options) . "</select>\n</form>"; ?> <h1>My PHP.net</h1> <p> This page allows you to customize the PHP.net site to some degree to your own liking. Currently you can only set the language you prefer, thus overriding any other automatic language selection. </p> <p> These settings will be active on all official PHP.net mirror sites, and are stored using cookies, so you need to have cookies enabled to let your settings work. </p> <h2>Preferred language</h2> <p> If you use a shortcut or search for a function, the language used is determined by checking for the following settings. The list is in priority order, the first is the most important. </p> <ul> <li>Your preferred language: <?php echo $langpref; ?></li> <li>Your Accept-Language browser setting: <?php echo join(", ", $UA_LANGS); ?></li> <li>The mirror's default language: <?php echo default_language(); ?></li> <li>English [en]</li> </ul> <p> These settings are only overriden in case you have passed a language setting URL parameter or POST data to a page or you are viewing a manual page in a particular language. In these cases, the explicit specification overrides the language selected from the above list. </p> <p> The language setting is honored when you use an <a href="/urlhowto.php">URL shortcut</a>, when you start a function list search on a non-manual page, when you visit the <a href="/download-docs.php">manual download</a> or <a href="/docs.php">language selection</a> pages, etc. </p> <?php commonFooter(); ?>

« previous php.mirrors (#16320) next »