Mise-à-jour sur-le-sentier.fr

version 2
This commit is contained in:
2024-12-10 11:39:15 +01:00
parent 26b17d9232
commit d8f28b47b8
55 changed files with 8972 additions and 1159 deletions

View File

@@ -1,10 +1,92 @@
<?php
function _pr($d) {
echo "<div style='border: 1px solid#ccc; padding: 10px;'>";
echo '<strong>' . debug_backtrace()[0]['file'] . ' ' . debug_backtrace()[0]['line'] . '</strong>';
echo "</div>";
echo '<pre>';
if(is_array($d)) {
print_r($d);
} else if(is_object($d)) {
var_dump($d);
}
echo '</pre>';
}
/**
* Simple helper to debug to the console
*
* @param Array, Object, String $data
* @return String
*/
function debug_to_console( $data ) {
$output = '';
if ( is_array( $data ) ) {
$output .= "<script>console.warn( 'Debug Objects with Array.' ); console.log( '" . implode( ',', $data) . "' );</script>";
} else if ( is_object( $data ) ) {
$data = var_export( $data, TRUE );
$data = explode( "\n", $data );
foreach( $data as $line ) {
if ( trim( $line ) ) {
$line = addslashes( $line );
$output .= "console.log( '{$line}' );";
}
}
$output = "<script>console.warn( 'Debug Objects with Object.' ); $output</script>";
} else {
$output .= "<script>console.log( 'Debug Objects: {$data}' );</script>";
}
echo $output;
}
/* Fonction month(): convertit le mois (nb) en mois (texte) francais
photo-du-mois.php
*/
function convert_bytes($val , $type_val , $type_wanted){
$tab_val = array("o", "ko", "Mo", "Go", "To", "Po", "Eo");
if (!(in_array($type_val, $tab_val) && in_array($type_wanted, $tab_val)))
return 0;
$tab = array_flip($tab_val);
$diff = $tab[$type_val] - $tab[$type_wanted];
if ($diff > 0)
return ($val * pow(1024, $diff));
if ($diff < 0)
return ($val / pow(1024, -$diff));
return ($val);
}
function taille_fichier($octets) {
$resultat = $octets;
for ($i=0; $i < 8 && $resultat >= 1024; $i++) {
$resultat = $resultat / 1024;
}
if ($i > 0) {
return preg_replace('/,00$/', '', number_format($resultat, 2, ',', ''))
. ' ' . substr('KMGTPEZY',$i-1,1) . 'o';
} else {
return $resultat . ' o';
}
}
function formatBytes($bytes, $precision = 2) {
$units = array('o', 'Ko', 'Mo', 'Go', 'To');
$bytes = max($bytes, 0);
$pow = floor(($bytes ? log($bytes) : 0) / log(1024));
$pow = min($pow, count($units) - 1);
// Uncomment one of the following alternatives
// $bytes /= pow(1024, $pow);
$bytes /= (1 << (10 * $pow));
return round($bytes, $precision) . " " .$units[$pow];
}
function month($w) {
$m = date('m', strtotime($w)); // month
$y = date('Y', strtotime($w)); // year
@@ -77,10 +159,12 @@ function get_gps($exif) {
$GPSLongitude = isset($exif['GPS']['GPSLongitude']) ? $exif['GPS']['GPSLongitude'] : '';
$GPSAltitude = isset($exif['GPS']['GPSAltitude']) ? $exif['GPS']['GPSAltitude'] : '';
/*
echo $GPSLatitude;
echo $GPSLongitude;
echo $GPSAltitude;
*/
$lat_degrees = count($GPSLatitude) > 0 ? gps2Num($GPSLatitude[0]) : 0;
$lat_minutes = count($GPSLatitude) > 1 ? gps2Num($GPSLatitude[1]) : 0;
$lat_seconds = count($GPSLatitude) > 2 ? gps2Num($GPSLatitude[2]) : 0;
@@ -115,29 +199,29 @@ function get_gps($exif) {
insert_bdd.php
*/
function create_thumb($thumb_w, $thumb_h, $image) {
list($origin_w, $origin_h) = getimagesize($image);
$origin_ratio = round($origin_w / $origin_h, 1);
$outFile = str_replace("photos/img", "photos/thumb", $image);
list($origin_w, $origin_h) = getimagesize($image);
$origin_ratio = round($origin_w / $origin_h, 1);
$outFile = str_replace("photos/img", "photos/thumb", $image);
if ($origin_w != null && $origin_h != null) {
if ($thumb_w / $thumb_h > $origin_ratio) {
$thumb_w = $thumb_h * $origin_ratio;
} else {
$thumb_h = $thumb_w / $origin_ratio;
}
if ($origin_w != null && $origin_h != null) {
if ($thumb_w / $thumb_h > $origin_ratio) {
$thumb_w = $thumb_h * $origin_ratio;
} else {
$thumb_h = $thumb_w / $origin_ratio;
}
if ($origin_w >= 400 && $origin_h >= 400) {
$image = new Imagick($image); // !!!
$image->thumbnailImage($thumb_w, $thumb_h);
$image->writeImage($outFile);
$image->destroy();
}
if ($origin_w >= 400 && $origin_h >= 400) {
$image = new Imagick($image); // !!!
$image->thumbnailImage($thumb_w, $thumb_h);
$image->writeImage($outFile);
$image->destroy();
}
}
}
/* Fonction in_bdd(): test si la photo est déjà dans la bdd
insert_bdd.php
@@ -166,23 +250,6 @@ function in_bdd($image) {
}
//
function _pr($d) {
echo "<div style='border: 1px solid#ccc; padding: 10px;'>";
echo '<strong>' . debug_backtrace()[0]['file'] . ' ' . debug_backtrace()[0]['line'] . '</strong>';
echo "</div>";
echo '<pre>';
if(is_array($d)) {
print_r($d);
} else if(is_object($d)) {
var_dump($d);
}
echo '</pre>';
}
/* return geo exif in a nice form
*/
@@ -227,8 +294,9 @@ function host() {
if ($_SERVER['HTTP_HOST'] == "sur-le-sentier.fr") {
$host = $pv_URIprotocol . $_SERVER['HTTP_HOST'] . "/";
}
elseif ($_SERVER['HTTP_HOST'] == "airbook.local") {
$host = $pv_URIprotocol . $_SERVER['HTTP_HOST'] . "/sls/";
elseif ($_SERVER['HTTP_HOST'] == "sur-le-sentier.airbook.local") {
//$host = $pv_URIprotocol . $_SERVER['HTTP_HOST'] . "/sls/";
$host = $pv_URIprotocol . $_SERVER['HTTP_HOST'] . "/";
}
return $host;
}
@@ -279,8 +347,34 @@ function clean_keywords($keywords) {
return $v;
}
function conv_date($dateoriginal, $format) {
$locale = getenv('LC_ALL=');
if ($format == 1) {
$formatter = new IntlDateFormatter($locale, IntlDateFormatter::FULL, IntlDateFormatter::SHORT, "Europe/Paris");
// vendredi 16 septembre 2022 à 19:17
}
elseif ($format == 2) {
$formatter = new IntlDateFormatter($locale, IntlDateFormatter::LONG, IntlDateFormatter::LONG, "Europe/Paris");
// 16 septembre 2022 à 19:17:22 UTC+2
}
elseif ($format == 3) {
$formatter = new IntlDateFormatter($locale, IntlDateFormatter::MEDIUM, IntlDateFormatter::MEDIUM, "Europe/Paris");
// 16 sept. 2022, 19:17:22
}
elseif ($format == 4) {
$formatter = new IntlDateFormatter($locale, IntlDateFormatter::MEDIUM, IntlDateFormatter::SHORT, "Europe/Paris");
// 16 sept. 2022, 19:17
}
$date = new DateTime($dateoriginal);
return $formatter->format($date);
}
function data_for_lightbox($data) {
//$query4 = "INSERT OR IGNORE INTO photos (filename, filesize, dateoriginal, lens, speed, correctexpo, iso, usercomment, comment, model, metering, flash, focal, program, wb, mode, width, height, html, aperture, software, lat, long, alt, keywords, title, creator, city, department, code, country, copyright, legende);
$filename = $data['filename'];
$title_thumb = pathinfo($filename, PATHINFO_FILENAME);
@@ -291,17 +385,25 @@ function data_for_lightbox($data) {
$iso = $data['iso'];
$exif = $model . " \u{30FB} " . $objectif . " \u{30FB} " . $speed . " \u{30FB} " . $aperture . " \u{30FB} " . $iso . "ISO";
$correctexpo = $data['correctexpo'];
$metering = $data['metering'];
$program = $data['program'];
$wb = $data['wb'];
$software = $data['software'];
$dateoriginal = conv_date($data['dateoriginal'], 4);
$focal = $data['focal'];
$flash = $data['flash'];
$latitude = $data['lat'];
$longitude = $data['long'];
$altitude = $data['alt'];
$da = isset($exif['EXIF']['DateTimeOriginal']) ? $exif['EXIF']['DateTimeOriginal'] : '';
$gps = (!empty($longitude) && !empty($latitude)) ? $latitude . "," . $longitude : "";
//$gps = $longitude . "," . $latitude;
$title = $data['title'];
$legende = $data['legende'];
$file = basename($filename);
if (!empty($title)) {
@@ -316,6 +418,13 @@ function data_for_lightbox($data) {
$x = $file;
$y = "";
}
if (!empty($gps)) {
$map = '<a href = "https://maps.google.com/maps?q=' . $gps . '&t=&z=9&ie=UTF8&iwloc=&output=embed" title="' . $title . '" data-lcl-txt="' . $legende . '">' . " \u{30FB} \u{2693} " . '</a>';
}
else {
$map = '';
}
$creator = $data['creator'];
@@ -323,6 +432,45 @@ function data_for_lightbox($data) {
$thumb = host() . str_replace("photos/img", "photos/thumb", $data['filename']);
$keywords = str_replace(',', " \u{30FB} ", clean_keywords($data['keywords']));
$copyright = $data['copyright'];
$city = $data['city'];
$department = $data['department'];
$code = $data['code'];
$country = $data['country'];
$comment = $data['comment'];
$usercomment = $data['usercomment'];
$description = "<table>";
$description .= "<tr><td>" . gettext("Date") . "</td><td>" . $dateoriginal . "</td></tr>";
$description .= "<tr><td>" . gettext("Speed") . "</td><td>" . $speed . "</td></tr>";
$description .= "<tr><td>" . gettext("Aperture") . "</td><td>" . $aperture . "</td></tr>";
$description .= "<tr><td>" . gettext("Iso") . "</td><td>" . $iso . "</td></tr>";
$description .= "<tr><td>" . gettext("Model") . "</td><td>". $model . "</td></tr>";
$description .= "<tr><td>" . gettext("Lens") . "</td><td>" . $objectif . "</td></tr>";
$description .= "<tr><td>" . gettext("Focal") . "</td><td>" . $focal . "</td></tr>";
$description .= "<tr><td>" . gettext("Exposure Correction") . "</td><td>" . $correctexpo . "</td></tr>";
$description .= "<tr><td>" . gettext("Metering") . "</td><td>". $metering . "</td></tr>";
$description .= "<tr><td>" . gettext("Program") . "</td><td>" . $program . "</td></tr>";
$description .= "<tr><td>" . gettext("White balance") . "</td><td>" . $wb . "</td></tr>";
if (! strcasecmp($flash, "Off") == 0) {
$description .= "<tr><td>" . gettext("Flash") . "</td><td>" . $flash . "</td></tr>";
}
$description .= "<tr><td>" . gettext("Software") . "</td><td>" . $software . "</td></tr>";
$description .= "<tr><td>" . gettext("Keywords") . "</td><td>" . $keywords . "</td></tr>";
(!empty($copyright)) && $description .= "<tr><td>" . gettext("Copyright") . "</td><td>" . $copyright . "</td></tr>";
(!empty($city)) && $description .= "<tr><td>" . gettext("City") . "</td><td>" . $city . "</td></tr>";
(!empty($department)) && $description .= "<tr><td>" . gettext("Department") . "</td><td>" . $department . "</td></tr>";
$code = (!empty($code)) ? " (" . $code . ")" : "";
(!empty($country)) && $description .= "<tr><td>" . gettext("Country") . "</td><td>" . $country . $code . "</td></tr>";
(!empty($map)) && $description .= "<tr><td>GPS</td><td>" . $map . "</td></tr>";
((!empty($comment)) || (!empty($usercomment))) && $description .= "<tr><td>&nbsp;</td><td>&nbsp;</td></tr>";
(!empty($comment)) && $description .= "<tr><td>" . gettext("Comment") . "</td><td>" . $comment . "</td></tr>";
(!empty($usercomment)) && $description .= "<tr><td>" . gettext("User comment") . "</td><td>" . $usercomment . "</td></tr>";
$description .= "</table>";
$lightbox = array();
$lightbox['title_thumb'] = $title_thumb;
@@ -334,6 +482,7 @@ function data_for_lightbox($data) {
$lightbox['keywords'] = $keywords;
$lightbox['creator'] = $creator;
$lightbox['gps'] = $gps;
$lightbox['description'] = $description;
/*
Array
@@ -346,240 +495,10 @@ function data_for_lightbox($data) {
[big] => https://airbook.local/sls/photos/img/12_2021.jpg
[keywords] => Carduelis carduelis ・ chardonneret élégant
[creator] => @Bruno Pesenti
[description] => <table>...</table>
)
*/
return $lightbox;
}
/* ----------------------------------------------------
Localization:
-list_dir($dir) : liste le dossier des locales (Locale)
-locale_language_from_browser($languages) : Identify language from the Accept-language HTTP header
-localize() : fonction à ajouter sur chaque page
-----------------------------------------------------*/
function list_dir($dir) {
if ($handle = opendir($dir)) {
$files = array();
while(false!==($file = readdir($handle))) {
if (is_dir($dir . '/' . $file)) {
$files[] = $file;
}
}
closedir($handle);
sort($files);
$i = 0;
global $myLanguages;
$myLanguages = array();
foreach($files as $f) {
if (strstr($f,'.') == false) {
$myLanguages[$i] = $f;
$i++;
}
//$myLanguages[] = $f;
}
}
else {
echo 'error: missing language files';
exit;
}
//print_r($myLanguages);
return $myLanguages;
}
//function _locale_language_from_browser($languages) {
function _locale_language_from_browser() {
if (empty($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
return FALSE;
}
$languages = "";
// 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($match);
echo $langcode . '-' . $qvalue . '-' . $browser_langcodes[$langcode] . '<br>';
}
}
//_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<br>";
_pr($browser_langcodes);
echo "languages<br>";
_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 . "<br>";
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 . "<br>";
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;
}
}
}
return $lang;
}
function localize($domain) {
//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);
/*
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'];
if ((empty($_REQUEST['lang'])) and (empty($_SESSION['language']))){
$langue = locale_language_from_browser($liste_locale);
}
elseif (!empty($_REQUEST['lang'])) {
$langue = $_REQUEST['lang'];
$_SESSION['language'] = $_REQUEST['lang'];
}
else $langue = $_SESSION['language'];
$langue .= ".utf8";
/*
if (isset($_GET['lang'])) echo "_GET lang: " . $_GET['lang'] . "<br>";
else echo "_GET lang: NULL" . "<br>";
if (isset($_REQUEST['lang'])) echo "_REQUEST lang: " . $_REQUEST['lang'] . "<br>";
else echo "_REQUEST lang: NULL" . "<br>";
if (isset($_SESSION['language'])) echo "_SESSION language: " . $_SESSION['language'] . "<br>";
else echo "_SESSION language: NULL" . "<br>";
echo "langue: " . $langue . "<br>";
*/
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') );
}
?>