31-03-2022
index.php maps.php photo-du-mois.php insert_bdd.php functions.php (localize($domain), data_for_lightbox($data)
This commit is contained in:
208
functions.php
208
functions.php
@@ -268,4 +268,212 @@ class AdvancedFilesystemIterator extends ArrayIterator
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
Suppress keywords like _vert_, _violet_...
|
||||
*/
|
||||
function clean_keywords($keywords) {
|
||||
$v = preg_replace( "/_\w+_/", "", $keywords );
|
||||
$v = str_replace(",,", ",", $v);
|
||||
//$v= (substr($v, strlen($v)-1) == ",") ? substr($v, 0, -1) : $v;
|
||||
$v= rtrim($v, ",");
|
||||
$v= ltrim($v, ",");
|
||||
return $v;
|
||||
}
|
||||
|
||||
function data_for_lightbox($data) {
|
||||
|
||||
$filename = $data['filename'];
|
||||
$title_thumb = pathinfo($filename, PATHINFO_FILENAME);
|
||||
|
||||
$aperture = $data['aperture'];
|
||||
$model = $data['model'];
|
||||
$objectif = $data['lens'];
|
||||
$speed = $data['speed'];
|
||||
$iso = $data['iso'];
|
||||
$exif = $model . " \u{30FB} " . $objectif . " \u{30FB} " . $speed . " \u{30FB} " . $aperture . " \u{30FB} " . $iso . "ISO";
|
||||
|
||||
|
||||
$title = $data['title'];
|
||||
$legende = $data['legende'];
|
||||
$file = basename($filename);
|
||||
if (!empty($title)) {
|
||||
$x = $title;
|
||||
$y = ($legende != "") ? $legende : "";
|
||||
}
|
||||
elseif (!empty($legende)) {
|
||||
$x= $legende;
|
||||
$y = "";
|
||||
}
|
||||
else {
|
||||
$x = $file;
|
||||
$y = "";
|
||||
}
|
||||
|
||||
$creator = $data['creator'];
|
||||
|
||||
$big = host() . $data['filename'];
|
||||
$thumb = host() . str_replace("photos/img", "photos/thumb", $data['filename']);
|
||||
|
||||
$keywords = str_replace(',', " \u{30FB} ", clean_keywords($data['keywords']));
|
||||
|
||||
$lightbox = array();
|
||||
$lightbox['title_thumb'] = $title_thumb;
|
||||
$lightbox['exif'] = $exif;
|
||||
$lightbox['title'] = $x;
|
||||
$lightbox['legende'] = $y;
|
||||
$lightbox['thumb'] = $thumb;
|
||||
$lightbox['big'] = $big;
|
||||
$lightbox['keywords'] = $keywords;
|
||||
$lightbox['creator'] = $creator;
|
||||
|
||||
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) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
// 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;
|
||||
}
|
||||
}
|
||||
|
||||
// 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;
|
||||
}
|
||||
|
||||
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);
|
||||
if ((!isset($_POST['lang'])) and (!isset($_GET['lang']))) $langue = locale_language_from_browser($liste_locale);
|
||||
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') );
|
||||
}
|
||||
|
||||
|
||||
function _host() {
|
||||
if (isset($_SERVER['HTTPS'])) {
|
||||
if ($_SERVER['HTTPS'] == 'on') $secure = 1;
|
||||
else $secure = 0;
|
||||
}
|
||||
else $secure = 0;
|
||||
|
||||
$host = (($secure == 1) ? 'https' : "http") . '://' . $_SERVER['HTTP_HOST'];
|
||||
|
||||
return $host;
|
||||
}
|
||||
|
||||
?>
|
||||
Reference in New Issue
Block a user