09-04-2022

-localization work fine
-prepare for $_SESSION
This commit is contained in:
2022-04-09 15:30:38 +02:00
parent 01ee106fcf
commit 629d9fd711
5 changed files with 181 additions and 252 deletions

View File

@@ -372,6 +372,7 @@ function list_dir($dir) {
} }
closedir($handle); closedir($handle);
sort($files); sort($files);
$i = 0; $i = 0;
global $myLanguages; global $myLanguages;
$myLanguages = array(); $myLanguages = array();
@@ -391,7 +392,7 @@ function list_dir($dir) {
return $myLanguages; return $myLanguages;
} }
function locale_language_from_browser($languages) { function _locale_language_from_browser($languages) {
if (empty($_SERVER['HTTP_ACCEPT_LANGUAGE'])) { if (empty($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
return FALSE; return FALSE;
} }
@@ -416,6 +417,8 @@ function locale_language_from_browser($languages) {
} }
} }
//_pr($browser_langcodes);
// We should take pristine values from the HTTP headers, but Internet Explorer // 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 // from version 7 sends only specific language tags (eg. fr-CA) without the
// corresponding generic tag (fr) unless explicitly configured. In that case, // corresponding generic tag (fr) unless explicitly configured. In that case,
@@ -431,6 +434,11 @@ function locale_language_from_browser($languages) {
} }
} }
echo "browser_langcodes<br>";
_pr($browser_langcodes);
echo "languages<br>";
_pr($languages);
// Find the enabled language with the greatest qvalue, following the rules // Find the enabled language with the greatest qvalue, following the rules
// of RFC 2616 (section 14.4). If several languages have the same qvalue, // of RFC 2616 (section 14.4). If several languages have the same qvalue,
// prefer the one with the greatest weight. // prefer the one with the greatest weight.
@@ -448,6 +456,8 @@ function locale_language_from_browser($languages) {
// Find the longest possible prefix of the browser-supplied language // Find the longest possible prefix of the browser-supplied language
// ('the language-range') that matches this site language ('the language tag'). // ('the language-range') that matches this site language ('the language tag').
$prefix = $langcode; $prefix = $langcode;
echo "prefix: " . $prefix . "<br>";
do { do {
if (isset($browser_langcodes[$prefix])) { if (isset($browser_langcodes[$prefix])) {
$qvalue = $browser_langcodes[$prefix]; $qvalue = $browser_langcodes[$prefix];
@@ -461,9 +471,63 @@ function locale_language_from_browser($languages) {
$max_qvalue = $qvalue; $max_qvalue = $qvalue;
} }
} }
_pr($best_match_langcode);
echo "bml" . $best_match_langcode . "<br>";
return $best_match_langcode; return $best_match_langcode;
} }
function locale_language_from_browser($languages) {
// 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);
}
}
}
// 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 . '<br>';
if ($string == $langcode) {
echo $value;
return $value;
break;
}
*/
//echo $langcode . '-' . $q . '-' . $value . '<br>';
if (substr($langcode, 0, 2) == substr($value, 0, 2)) {
$lang = $value;
break 2;
}
}
}
//if (!isset($lang)) $lang = 'fr_FR';
return $lang;
}
function localize($domain) { function localize($domain) {
//if ($_SERVER['SERVER_NAME'] == 'airbook.local') //if ($_SERVER['SERVER_NAME'] == 'airbook.local')
$root = $_SERVER['DOCUMENT_ROOT']; $root = $_SERVER['DOCUMENT_ROOT'];
@@ -472,10 +536,27 @@ function localize($domain) {
$dir_locales = $root . '/Locale'; $dir_locales = $root . '/Locale';
$liste_locale = list_dir($dir_locales); $liste_locale = list_dir($dir_locales);
//echo "liste_locale: <br>";
//_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); if ((!isset($_POST['lang'])) and (!isset($_GET['lang']))) $langue = locale_language_from_browser($liste_locale);
else $langue = $_REQUEST['lang']; else $langue = $_REQUEST['lang'];
$langue .= ".utf-8";
//echo $langue;
//echo "<br>HTTP_ACCEPT_LANGUAGE: " . $_SERVER['HTTP_ACCEPT_LANGUAGE'];
//$domain = 'sentier'; //$domain = 'sentier';
$_SESSION["lang"]=$langue;
putenv('LC_ALL=' . $langue); putenv('LC_ALL=' . $langue);
$loc = setlocale(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') ); $nation = array('fr_FR' => gettext('French'), 'en_US' => gettext('English') , 'de_DE' => gettext('German'), 'es_ES' => gettext('Spanish') );
} }
?> ?>

View File

@@ -1,5 +1,5 @@
<!DOCTYPE html> <!DOCTYPE html>
<html lang="fr-FR"> <html lang="en">
<head> <head>
<meta charset="UTF-8" /> <meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta http-equiv="X-UA-Compatible" content="IE=edge">
@@ -43,28 +43,6 @@ $pv_URIprotocol = isset($_SERVER["HTTPS"]) ? (($_SERVER["HTTPS"]==="on" || $_SER
$host = $pv_URIprotocol . $_SERVER['HTTP_HOST']; $host = $pv_URIprotocol . $_SERVER['HTTP_HOST'];
$wp = (($_SERVER['SERVER_NAME'] == "sur-le-sentier.fr") ? "blog" : "wordpress"); $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') );
*/
?> ?>
</head> </head>
@@ -72,14 +50,14 @@ $nation = array('fr_FR' => gettext('French'), 'en_US' => gettext('English') , 'd
<body> <body>
<script> <script>
$("#exemple, body").vegas({ $("#exemple, body").vegas({
slides: [ slides: [
<?php <?php
foreach($fileList as $filename){ foreach($fileList as $filename){
echo '{ src: "' . $filename . '" },' . "\r\n"; echo '{ src: "' . $filename . '" },' . "\r\n";
} }
?>
?>
], ],
animation: 'random', animation: 'random',
animationDuration: '20000', animationDuration: '20000',

View File

@@ -5,7 +5,7 @@
<meta charset="UTF-8"> <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge"> <meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Insert photos in Sqlite base</title> <title><?php gettext('Insert photos in Sqlite base'; ?></title>
<link rel="stylesheet" href="css/sls.css" /> <link rel="stylesheet" href="css/sls.css" />
<link rel='stylesheet' href='css/lc_lightbox.min.css' /> <link rel='stylesheet' href='css/lc_lightbox.min.css' />
@@ -118,7 +118,6 @@ foreach($dir as $file){
} }
$mod = isset($exif['IFD0']['Model']) ? $exif['IFD0']['Model'] : ''; $mod = isset($exif['IFD0']['Model']) ? $exif['IFD0']['Model'] : '';
//_pr($exif);
# YYYY-MM-DD HH:MM:SS.SSS - 2019:10:01 14:03:12 # YYYY-MM-DD HH:MM:SS.SSS - 2019:10:01 14:03:12
$da = isset($exif['EXIF']['DateTimeOriginal']) ? $exif['EXIF']['DateTimeOriginal'] : ''; $da = isset($exif['EXIF']['DateTimeOriginal']) ? $exif['EXIF']['DateTimeOriginal'] : '';
@@ -388,7 +387,7 @@ $nb_avant = (isset($avant)) ? $avant : 0;
echo '<h3>' . gettext('Creation of thumbnails') . ' ('. $th_w . 'px x ' . $th_h . 'px) ' . gettext('in the folder') . ' <i>photos/thumb/</i>.</h3>'; echo '<h3>' . gettext('Creation of thumbnails') . ' ('. $th_w . 'px x ' . $th_h . 'px) ' . gettext('in the folder') . ' <i>photos/thumb/</i>.</h3>';
//$b = ($z > 1) ? 'nouvelles images' : 'nouvelle image';
$b = ($z > 1) ? gettext('new images') : gettext('new image'); $b = ($z > 1) ? gettext('new images') : gettext('new image');
echo '<h3>' . gettext('Insertion of ') . $z . ' ' . $b . gettext(' in database') . '...</h3>'; echo '<h3>' . gettext('Insertion of ') . $z . ' ' . $b . gettext(' in database') . '...</h3>';
@@ -481,7 +480,7 @@ try {
//$row = $stmt->fetchAll(PDO::FETCH_ASSOC); //$row = $stmt->fetchAll(PDO::FETCH_ASSOC);
//_pr($result); //_pr($result);
echo '<h3>Lecture des photos ajoutées:</h3>'; echo '<h3>' . gettext('Reading added photos') . ':</h3>';
echo '<div id="add_to_bdd">'; echo '<div id="add_to_bdd">';
echo '<table class="styled-table">'; echo '<table class="styled-table">';
echo '<thead>'; echo '<thead>';

150
maps2.php
View File

@@ -1,150 +0,0 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Photo du mois</title>
<link rel="stylesheet" href="css/sls.css">
<link rel='stylesheet' href='css/lc_lightbox.min.css' />
<link rel='stylesheet' href='css/open_close_fx.css' />
<link rel='stylesheet' href='css/minimal.css' />
<style>
#map{
width: 100%;
height: 400px;
}
#mapCanvas {
width: 100%;
height: 650px;
}
</style>
<?php include 'functions.php'; ?>
<script src='https://code.jquery.com/jquery-3.2.1.min.js'></script>
<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyB7cAx3NSH4dPM3Sx2oQeud7Zr-KaGXmLk"></script>
</head>
<body>
<h1 class="_h1"><?php echo gettext("Photo du mois"); ?></h1>
<?php
$page = 1;
try {
$conn4 = new PDO('sqlite:db_photo.sqlite3');
$query4 = "SELECT filename, date, lens, exposure, iso, width, height, html, aperture, model, lat, long, alt, legende, copyright, titre, createur, keywords FROM photos WHERE lat != '' ORDER BY date DESC LIMIT ? OFFSET ?";
//nb d'archive par page
$limit = 13;
$offset = $limit * ($page -1);
//echo "offset: " . $offset;
$stmt = $conn4->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);
?>
<div id="mapCanvas"></div>
<script>
function initMap() {
var map;
var bounds = new google.maps.LatLngBounds();
var mapOptions = {
mapTypeId: 'roadmap'
};
// Display a map on the web page
map = new google.maps.Map(document.getElementById("mapCanvas"), mapOptions);
map.setTilt(100);
// Multiple markers location, latitude, and longitude
var markers = [
<?php
$a = "";
for( $i = 0; $i < $rowcount; $i++) {
$a .= '["'.$result[$i]['filename'].'", '.$result[$i]['lat'].', '.$result[$i]['long'].'],' . "\r\n";
}
$a = substr_replace($a, '', -3, 1);
echo $a;
?>
];
// Info window content
var infoWindowContent = [
<?php
$b = "";
for( $i = 0; $i < $rowcount; $i++) {
$b .= '[\'<div class="info_content"><h3>' . $result[$i]['filename'] . '</h3><p>' . $result[$i]['lat'] . '</p></div>\'],' . "\r\n";
}
$b = substr_replace($b, '', -3, 1);
echo $b;
?>
];
// Add multiple markers to map
var infoWindow = new google.maps.InfoWindow(), marker, i;
// Place each marker on the map
for( i = 0; i < markers.length; i++ ) {
var position = new google.maps.LatLng(markers[i][1], markers[i][2]);
bounds.extend(position);
marker = new google.maps.Marker({
position: position,
map: map,
icon: markers[i][3],
title: markers[i][0]
});
// Add info window to marker
google.maps.event.addListener(marker, 'click', (function(marker, i) {
return function() {
infoWindow.setContent(infoWindowContent[i][0]);
infoWindow.open(map, marker);
}
})(marker, i));
// Center the map to fit all markers on the screen
map.fitBounds(bounds);
}
// Set zoom level
var boundsListener = google.maps.event.addListener((map), 'bounds_changed', function(event) {
this.setZoom(6);
google.maps.event.removeListener(boundsListener);
});
}
// Load initialize function
google.maps.event.addDomListener(window, 'load', initMap);
</script>
<p><em><small>@ 2022</small></em></p>
<script src='js/lc_lightbox.min.js'></script>
<script src='js/alloy_finger.min.js'></script>
</body>
</html>

View File

@@ -33,7 +33,8 @@ else $page = intval($_GET['page']);
<?php <?php
try { try {
$conn4 = new PDO('sqlite:db_photo.sqlite3'); $conn4 = new PDO('sqlite:db_photo.sqlite3');
$query4 = "SELECT filename, date, lens, speed, iso, width, height, html, aperture, model, lat, long, alt, legende, copyright, title, creator, keywords, metering, flash, focal, wb, program FROM photos WHERE id='26' ORDER BY date DESC LIMIT ? OFFSET ?"; // WHERE id='26'
$query4 = "SELECT filename, date, lens, speed, iso, width, height, html, aperture, model, lat, long, alt, legende, copyright, title, creator, keywords, metering, flash, focal, wb, program FROM photos ORDER BY date DESC LIMIT ? OFFSET ?";
//nb d'archive par page //nb d'archive par page
$limit = 13; $limit = 13;
$offset = $limit * ($page -1); $offset = $limit * ($page -1);
@@ -44,6 +45,8 @@ try {
$result = $stmt->fetchAll(PDO::FETCH_ASSOC); $result = $stmt->fetchAll(PDO::FETCH_ASSOC);
$rowcount = count($result); $rowcount = count($result);
//_pr($result);
$conn4 = null; $conn4 = null;
} }
catch(PDOException $e) { catch(PDOException $e) {
@@ -117,8 +120,25 @@ try {
$lb = data_for_lightbox($result[$i]); $lb = data_for_lightbox($result[$i]);
//
if (!empty($lb['gps'])) {
$map = '<a href = "https://maps.google.com/maps?q=' . $lb['gps'] . '&t=&z=9&ie=UTF8&iwloc=&output=embed" title="' . $lb['title'] . '" data-lcl-txt="' . $lb['legende'] . '">' . " \u{30FB} \u{2693} " . '</a>';
$meta = $lb['exif'] . $map;
} else {
$meta = '';
}
// data-lcl-author="' . htmlspecialchars($lb['exif']) . '"
//
_pr($lb);
//echo $lb['exif'];
echo '<div class="item">'; echo '<div class="item">';
echo '<a href ="' . $lb['big'] . '" title="' . htmlspecialchars($lb['title']) . '" data-lcl-txt="' . htmlspecialchars($lb['title']) .'" data-lcl-author="' . htmlspecialchars($lb['exif']) . '">'; echo '<a href ="' . $lb['big'] . '" title="' . htmlspecialchars($lb['title']) . '" data-lcl-txt="' . htmlspecialchars($lb['title']) .'" data-lcl-author="' . htmlspecialchars($meta) . '">';
echo '<img src="' . $lb['thumb'] . '" alt="' . htmlspecialchars($lb['title']) . '" />'; echo '<img src="' . $lb['thumb'] . '" alt="' . htmlspecialchars($lb['title']) . '" />';
echo "</a>"; echo "</a>";
echo '<span class="caption">' . month($date) . '</span>'; echo '<span class="caption">' . month($date) . '</span>';