From 629d9fd7113386577503fa4de1c900523adb6ddc Mon Sep 17 00:00:00 2001 From: Bruno21 Date: Sat, 9 Apr 2022 15:30:38 +0200 Subject: [PATCH] 09-04-2022 -localization work fine -prepare for $_SESSION --- functions.php | 216 ++++++++++++++++++++++++++++++++-------------- index.php | 36 ++------ insert_bdd.php | 7 +- maps2.php | 150 -------------------------------- photo-du-mois.php | 24 +++++- 5 files changed, 181 insertions(+), 252 deletions(-) delete mode 100644 maps2.php diff --git a/functions.php b/functions.php index 70d9311..73c42ef 100644 --- a/functions.php +++ b/functions.php @@ -372,6 +372,7 @@ function list_dir($dir) { } closedir($handle); sort($files); + $i = 0; global $myLanguages; $myLanguages = array(); @@ -391,77 +392,140 @@ function list_dir($dir) { return $myLanguages; } +function _locale_language_from_browser($languages) { + if (empty($_SERVER['HTTP_ACCEPT_LANGUAGE'])) { + return FALSE; + } + + // The Accept-Language header contains information about the language + // preferences configured in the user's browser / operating system. + // RFC 2616 (section 14.4) defines the Accept-Language header as follows: + // Accept-Language = "Accept-Language" ":" + // 1#( language-range [ ";" "q" "=" qvalue ] ) + // language-range = ( ( 1*8ALPHA *( "-" 1*8ALPHA ) ) | "*" ) + // Samples: "hu, en-us;q=0.66, en;q=0.33", "hu,en-us;q=0.5" + $browser_langcodes = array(); + if (preg_match_all('@(?<=[, ]|^)([a-zA-Z-]+|\\*)(?:;q=([0-9.]+))?(?:$|\\s*,\\s*)@', trim($_SERVER['HTTP_ACCEPT_LANGUAGE']), $matches, PREG_SET_ORDER)) { + foreach ($matches as $match) { + + // We can safely use strtolower() here, tags are ASCII. + // RFC2616 mandates that the decimal part is no more than three digits, + // so we multiply the qvalue by 1000 to avoid floating point comparisons. + $langcode = strtolower($match[1]); + $qvalue = isset($match[2]) ? (double) $match[2] : 1; + $browser_langcodes[$langcode] = (int) ($qvalue * 1000); + } + } + +//_pr($browser_langcodes); + + // We should take pristine values from the HTTP headers, but Internet Explorer + // from version 7 sends only specific language tags (eg. fr-CA) without the + // corresponding generic tag (fr) unless explicitly configured. In that case, + // we assume that the lowest value of the specific tags is the value of the + // generic language to be as close to the HTTP 1.1 spec as possible. + // See http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.4 and + // http://blogs.msdn.com/b/ie/archive/2006/10/17/accept-language-header-for-internet-explorer-7.aspx + asort($browser_langcodes); + foreach ($browser_langcodes as $langcode => $qvalue) { + $generic_tag = strtok($langcode, '-'); + if (!isset($browser_langcodes[$generic_tag])) { + $browser_langcodes[$generic_tag] = $qvalue; + } + } + +echo "browser_langcodes
"; +_pr($browser_langcodes); +echo "languages
"; +_pr($languages); + + // Find the enabled language with the greatest qvalue, following the rules + // of RFC 2616 (section 14.4). If several languages have the same qvalue, + // prefer the one with the greatest weight. + $best_match_langcode = FALSE; + $max_qvalue = 0; + foreach ($languages as $langcode => $language) { + + // Language tags are case insensitive (RFC2616, sec 3.10). + $langcode = strtolower($langcode); + + // If nothing matches below, the default qvalue is the one of the wildcard + // language, if set, or is 0 (which will never match). + $qvalue = isset($browser_langcodes['*']) ? $browser_langcodes['*'] : 0; + + // Find the longest possible prefix of the browser-supplied language + // ('the language-range') that matches this site language ('the language tag'). + $prefix = $langcode; + echo "prefix: " . $prefix . "
"; + + do { + if (isset($browser_langcodes[$prefix])) { + $qvalue = $browser_langcodes[$prefix]; + break; + } + } while ($prefix = substr($prefix, 0, strrpos($prefix, '-'))); + + // Find the best match. + if ($qvalue > $max_qvalue) { + $best_match_langcode = $language->language; + $max_qvalue = $qvalue; + } + } + +_pr($best_match_langcode); +echo "bml" . $best_match_langcode . "
"; + + return $best_match_langcode; +} + + function locale_language_from_browser($languages) { - if (empty($_SERVER['HTTP_ACCEPT_LANGUAGE'])) { - return FALSE; + // 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_langs = array(); + + if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) { + $browser_accept = explode(",", $_SERVER['HTTP_ACCEPT_LANGUAGE']); + foreach ($browser_accept as $langpart) { + // The language part is either a code or a code with a quality. + // We cannot do anything with a * code, so it is skipped. + // If the quality is missing, it is assumed to be 1 according to the RFC. + if (preg_match("!([a-z-]+)(;q=([0-9\\.]+))?!", trim($langpart), $found)) { + $browser_langs[$found[1]] = (isset($found[3]) ? (float) $found[3] : 1.0); } - - // The Accept-Language header contains information about the language - // preferences configured in the user's browser / operating system. - // RFC 2616 (section 14.4) defines the Accept-Language header as follows: - // Accept-Language = "Accept-Language" ":" - // 1#( language-range [ ";" "q" "=" qvalue ] ) - // language-range = ( ( 1*8ALPHA *( "-" 1*8ALPHA ) ) | "*" ) - // Samples: "hu, en-us;q=0.66, en;q=0.33", "hu,en-us;q=0.5" - $browser_langcodes = array(); - if (preg_match_all('@(?<=[, ]|^)([a-zA-Z-]+|\\*)(?:;q=([0-9.]+))?(?:$|\\s*,\\s*)@', trim($_SERVER['HTTP_ACCEPT_LANGUAGE']), $matches, PREG_SET_ORDER)) { - foreach ($matches as $match) { - - // We can safely use strtolower() here, tags are ASCII. - // RFC2616 mandates that the decimal part is no more than three digits, - // so we multiply the qvalue by 1000 to avoid floating point comparisons. - $langcode = strtolower($match[1]); - $qvalue = isset($match[2]) ? (double) $match[2] : 1; - $browser_langcodes[$langcode] = (int) ($qvalue * 1000); + } + } + + // Order the codes by quality + arsort($browser_langs); + //Array ( [en-us] => 1 [en] => 0.7 [fr] => 0.3 ) Firefox Fr + //Array ( [fr-] => 1 [en-] => 1 [fr] => 0.8 [en] => 0.4 ) Chrome 5 Fr + //Array ( [fr-fr] => 1 ) Safari Fr + //Array ( [fr-fr] => 1 ) iCab Fr + //Array ( [zh-] => 1 [fr] => 1 [pt-] => 1 [en-] => 1 [en] => 0.9 [ja] => 0.7 [de] => 0.6 [es] => 0.5 [it] => 0.4 [pt] => 0.3 [pl] => 0.1 [ru] => 0.1 [ko] => 0.1 [sv] => 0.1 [nl] => 0.1 [nb] => 0.1 [da] => 0.1 [fi] => 0.1 ) Opera 10.6 + + // Try to find the first preferred language we have + foreach ($browser_langs as $langcode => $q) { + foreach ($languages as $value) { + /* + $string = strtolower(str_replace('_','-',$value)); + echo $langcode . '-' . $q . '-' . $value . '
'; + if ($string == $langcode) { + echo $value; + return $value; + break; } - } - - // We should take pristine values from the HTTP headers, but Internet Explorer - // from version 7 sends only specific language tags (eg. fr-CA) without the - // corresponding generic tag (fr) unless explicitly configured. In that case, - // we assume that the lowest value of the specific tags is the value of the - // generic language to be as close to the HTTP 1.1 spec as possible. - // See http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.4 and - // http://blogs.msdn.com/b/ie/archive/2006/10/17/accept-language-header-for-internet-explorer-7.aspx - asort($browser_langcodes); - foreach ($browser_langcodes as $langcode => $qvalue) { - $generic_tag = strtok($langcode, '-'); - if (!isset($browser_langcodes[$generic_tag])) { - $browser_langcodes[$generic_tag] = $qvalue; + */ + //echo $langcode . '-' . $q . '-' . $value . '
'; + if (substr($langcode, 0, 2) == substr($value, 0, 2)) { + $lang = $value; + break 2; } - } - - // Find the enabled language with the greatest qvalue, following the rules - // of RFC 2616 (section 14.4). If several languages have the same qvalue, - // prefer the one with the greatest weight. - $best_match_langcode = FALSE; - $max_qvalue = 0; - foreach ($languages as $langcode => $language) { - - // Language tags are case insensitive (RFC2616, sec 3.10). - $langcode = strtolower($langcode); - - // If nothing matches below, the default qvalue is the one of the wildcard - // language, if set, or is 0 (which will never match). - $qvalue = isset($browser_langcodes['*']) ? $browser_langcodes['*'] : 0; - - // Find the longest possible prefix of the browser-supplied language - // ('the language-range') that matches this site language ('the language tag'). - $prefix = $langcode; - do { - if (isset($browser_langcodes[$prefix])) { - $qvalue = $browser_langcodes[$prefix]; - break; - } - } while ($prefix = substr($prefix, 0, strrpos($prefix, '-'))); - - // Find the best match. - if ($qvalue > $max_qvalue) { - $best_match_langcode = $language->language; - $max_qvalue = $qvalue; - } - } - return $best_match_langcode; + } + } + + //if (!isset($lang)) $lang = 'fr_FR'; + return $lang; } function localize($domain) { @@ -472,10 +536,27 @@ function localize($domain) { $dir_locales = $root . '/Locale'; $liste_locale = list_dir($dir_locales); + //echo "liste_locale:
"; + //_pr($liste_locale); + /* + Array + ( + [0] => de_DE + [1] => en_US + [2] => es_ES + [3] => fr_FR + ) + */ + if ((!isset($_POST['lang'])) and (!isset($_GET['lang']))) $langue = locale_language_from_browser($liste_locale); else $langue = $_REQUEST['lang']; + $langue .= ".utf-8"; + //echo $langue; + //echo "
HTTP_ACCEPT_LANGUAGE: " . $_SERVER['HTTP_ACCEPT_LANGUAGE']; + //$domain = 'sentier'; + $_SESSION["lang"]=$langue; putenv('LC_ALL=' . $langue); $loc = setlocale(LC_ALL, $langue); @@ -486,4 +567,5 @@ function localize($domain) { $nation = array('fr_FR' => gettext('French'), 'en_US' => gettext('English') , 'de_DE' => gettext('German'), 'es_ES' => gettext('Spanish') ); } + ?> \ No newline at end of file diff --git a/index.php b/index.php index 2571fb0..ca972ec 100644 --- a/index.php +++ b/index.php @@ -1,5 +1,5 @@ - + @@ -43,28 +43,6 @@ $pv_URIprotocol = isset($_SERVER["HTTPS"]) ? (($_SERVER["HTTPS"]==="on" || $_SER $host = $pv_URIprotocol . $_SERVER['HTTP_HOST']; $wp = (($_SERVER['SERVER_NAME'] == "sur-le-sentier.fr") ? "blog" : "wordpress"); - -/* -//if ($_SERVER['SERVER_NAME'] == 'airbook.local') -$root = $_SERVER['DOCUMENT_ROOT']; -//$root = dirname($_SERVER['SCRIPT_FILENAME']); // /Users/bruno/Sites/sls -include($root.'/lib2/localize.php'); -$dir_locales = $root . '/Locale'; - -$liste_locale = list_dir($dir_locales); -if ((!isset($_POST['lang'])) and (!isset($_GET['lang']))) $langue = locale_language_from_browser($myLanguages); -else $langue = $_REQUEST['lang']; - -$domain = 'sentier'; -putenv('LC_ALL=' . $langue); -$loc = setlocale(LC_ALL, $langue); - -bindtextdomain($domain, $root . '/Locale/'); -bind_textdomain_codeset($domain, 'UTF-8'); -textdomain($domain); - -$nation = array('fr_FR' => gettext('French'), 'en_US' => gettext('English') , 'de_DE' => gettext('German'), 'es_ES' => gettext('Spanish') ); -*/ ?> @@ -72,14 +50,14 @@ $nation = array('fr_FR' => gettext('French'), 'en_US' => gettext('English') , 'd - - - - - - - -

- -prepare($query4); - $stmt->execute(array($limit, $offset)); - - $result = $stmt->fetchAll(PDO::FETCH_ASSOC); - $rowcount = count($result); - - $conn4 = null; - } - catch(PDOException $e) { - echo $e->getMessage(); - } - - //_pr($result); -?> - -
- - - - - -

@ 2022

- - - - - - - \ No newline at end of file diff --git a/photo-du-mois.php b/photo-du-mois.php index e595ff0..797e7cf 100644 --- a/photo-du-mois.php +++ b/photo-du-mois.php @@ -33,7 +33,8 @@ else $page = intval($_GET['page']); fetchAll(PDO::FETCH_ASSOC); $rowcount = count($result); + //_pr($result); + $conn4 = null; } catch(PDOException $e) { @@ -116,9 +119,26 @@ try { $date = $result[$i]['date']; $lb = data_for_lightbox($result[$i]); + + // + if (!empty($lb['gps'])) { + $map = '' . " \u{30FB} \u{2693} " . ''; + + $meta = $lb['exif'] . $map; + } else { + $meta = ''; + } + + + + // data-lcl-author="' . htmlspecialchars($lb['exif']) . '" + // + + _pr($lb); + //echo $lb['exif']; echo '
'; - echo ''; + echo ''; echo '' . htmlspecialchars($lb['title']) . ''; echo ""; echo '' . month($date) . '';