Initial commit
This commit is contained in:
commit
6b5a84dfa4
33 changed files with 1535 additions and 0 deletions
86
core/core.php
Normal file
86
core/core.php
Normal file
|
|
@ -0,0 +1,86 @@
|
|||
<?php
|
||||
|
||||
require('functions.php');
|
||||
|
||||
$parameters = $product . "/" . $year;
|
||||
$path = $year . "/" . $product;
|
||||
|
||||
$resource_url = resource_url();
|
||||
$canonical_url = current_url($lang, $parameters);
|
||||
|
||||
$data_path = "data/wine/" . $path . ".json";
|
||||
$img = $resource_url."img/" . $path . ".webp";
|
||||
|
||||
//JSON
|
||||
$data = json_decode(file_get_contents($data_path));
|
||||
$translation = json_decode(file_get_contents("data/translations.json"));
|
||||
|
||||
// DATA
|
||||
$product_name = $data->product;
|
||||
$parcel = $data->parcel;
|
||||
$region = $data->region;
|
||||
$winegrower = $data->winegrower;
|
||||
$capacity = $data->capacity;
|
||||
$alcohol = $data->alcohol;
|
||||
$energy = $data->energy;
|
||||
$energy_converted = floor(kcal2kj($energy));
|
||||
$fats = $data->fats;
|
||||
$saturated_fats = $data->saturated_fats;
|
||||
$carbohydrates = $data->carbohydrates;
|
||||
$sugar = $data->sugar;
|
||||
$proteins = $data->proteins;
|
||||
$salt = $data->salt;
|
||||
$color = $data->color;
|
||||
$composition = $data->composition;
|
||||
|
||||
// TRANSLATIONS
|
||||
$tr_lang = $translation->$lang->lang;
|
||||
$tr_ingredients = $translation->$lang->ingredients;
|
||||
$tr_nutrional = $translation->$lang->nutrional;
|
||||
$tr_capacity = $translation->$lang->capacity;
|
||||
$tr_energy = $translation->$lang->energy;
|
||||
$tr_fats = $translation->$lang->fats;
|
||||
$tr_saturated_fats = $translation->$lang->saturated_fats;
|
||||
$tr_carbohydrates = $translation->$lang->carbohydrates;
|
||||
$tr_sugar = $translation->$lang->sugar;
|
||||
$tr_proteins = $translation->$lang->proteins;
|
||||
$tr_salt = $translation->$lang->salt;
|
||||
$tr_color = $translation->$lang->$color;
|
||||
$tr_title = $translation->$lang->title;
|
||||
$tr_description = $translation->$lang->description;
|
||||
|
||||
// STRING BUILDERS
|
||||
$name = $product_name . " " . $year;
|
||||
$details = $tr_color . " / " . $capacity . "L / " . $alcohol . "% vol";
|
||||
$head_title = $name . " | " . $winegrower . " | " . $tr_title;
|
||||
$head_description = sprintf($tr_description, $name, $winegrower);
|
||||
|
||||
//INGREDIENTS
|
||||
$ingredients = "";
|
||||
$nb_components = 0;
|
||||
foreach ($composition as $component) {
|
||||
$ingredients .= translate_and_format($translation->$lang, $component);
|
||||
$sub_components = isset($component->components) ? $component->components : null;
|
||||
|
||||
if ($sub_components != null) {
|
||||
$ingredients .= ' (';
|
||||
|
||||
$nb_sub_components = 0;
|
||||
foreach ($sub_components as $sub_component) {
|
||||
$ingredients .= translate_and_format($translation->$lang, $sub_component);
|
||||
$nb_sub_components++;
|
||||
if($nb_sub_components < sizeof($sub_components)){
|
||||
$ingredients .= ', ';
|
||||
}
|
||||
}
|
||||
$ingredients .= ')';
|
||||
|
||||
}
|
||||
$nb_components++;
|
||||
if($nb_components < sizeof($composition)){
|
||||
$ingredients .= ', ';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
?>
|
||||
51
core/functions.php
Normal file
51
core/functions.php
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
<?php
|
||||
function kcal2kj(int $kcal)
|
||||
{
|
||||
return $kcal * 4.1868;
|
||||
}
|
||||
|
||||
function is_https(){
|
||||
return !empty($_SERVER['HTTPS']) &&
|
||||
(strtolower($_SERVER['HTTPS']) == 'on' ||
|
||||
$_SERVER['HTTPS'] == '1');
|
||||
}
|
||||
|
||||
function base_url()
|
||||
{
|
||||
$protocol = is_https() ? 'https://' : 'http://';
|
||||
$server = $_SERVER['SERVER_NAME'];
|
||||
//$port = $_SERVER['SERVER_PORT'] ? ':'.$_SERVER['SERVER_PORT'] : '';
|
||||
return $protocol.$server;
|
||||
}
|
||||
|
||||
function resource_url()
|
||||
{
|
||||
return base_url() . dirname($_SERVER['PHP_SELF'])."/";;
|
||||
}
|
||||
|
||||
function current_url($lang, $parameters){
|
||||
return resource_url() . $lang . "/" . $parameters;
|
||||
}
|
||||
|
||||
{
|
||||
$protocol = is_https() ? 'https://' : 'http://';
|
||||
$server = $_SERVER['SERVER_NAME'];
|
||||
//$port = $_SERVER['SERVER_PORT'] ? ':'.$_SERVER['SERVER_PORT'] : '';
|
||||
return $protocol.$server;
|
||||
}
|
||||
|
||||
|
||||
function translate_and_format($translation, $ingredient)
|
||||
{
|
||||
$ingredient_id = $ingredient->id;
|
||||
$tranlated = $translation->$ingredient_id;
|
||||
|
||||
$is_allergen = isset($ingredient->allergen) ? $ingredient->allergen : false;
|
||||
if ($is_allergen) {
|
||||
$format = '<strong>%s</strong>';
|
||||
$tranlated = sprintf($format, $tranlated);
|
||||
}
|
||||
return $tranlated;
|
||||
}
|
||||
|
||||
?>
|
||||
132
core/layout.php
Executable file
132
core/layout.php
Executable file
|
|
@ -0,0 +1,132 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="<?= $lang ?>">
|
||||
<head>
|
||||
<title><?= $head_title ?></title>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<meta name="description" content="<?= $head_description ?>" />
|
||||
<meta name="msapplication-TileColor" content="#da532c" />
|
||||
<meta name="theme-color" content="#ffffff" />
|
||||
<link rel="canonical" href="<?= $canonical_url ?>" />
|
||||
<!--<link rel="icon" href="images/icons/favicon.ico">
|
||||
<link rel="icon" type="image/svg+xml" href="images/icons/favicon.svg">
|
||||
<link rel="icon" type="image/png" href="images/icons/favicon.png">
|
||||
<link rel="apple-touch-icon" sizes="180x180" href="images/icons/apple-touch-icon.png">
|
||||
<link rel="icon" type="image/png" sizes="32x32" href="images/icons/favicon-32x32.png">
|
||||
<link rel="icon" type="image/png" sizes="16x16" href="images/icons/favicon-16x16.png">
|
||||
<link rel="mask-icon" href="images/icons/safari-pinned-tab.svg" color="#5bbad5">-->
|
||||
<link rel="stylesheet" type="text/css" href="<?= $resource_url ?>css/main.css" />
|
||||
</head>
|
||||
<body>
|
||||
<nav class="mega-menu">
|
||||
<ul class="mega-menu-main">
|
||||
<li class="lvl-0">
|
||||
<span class="lang">
|
||||
<a href="#"><?= $tr_lang ?></a>
|
||||
<img alt="lang" src="<?= $resource_url ?>icon/lang.svg" loading="lazy" />
|
||||
</span>
|
||||
<ul class="mega-menu-tab">
|
||||
<li class="lvl-1">
|
||||
<ul class="lvl-2">
|
||||
<li><a href="<?= current_url("bg", $parameters) ?>">български език</a></li>
|
||||
<li><a href="<?= current_url("cs", $parameters) ?>">Česky</a></li>
|
||||
<li><a href="<?= current_url("da", $parameters) ?>">Dansk</a></li>
|
||||
<li><a href="<?= current_url("de", $parameters) ?>">Deutsch</a></li>
|
||||
<li><a href="<?= current_url("el", $parameters) ?>">Ελληνικά</a></li>
|
||||
<li><a href="<?= current_url("en", $parameters) ?>">English</a></li>
|
||||
<li><a href="<?= current_url("es", $parameters) ?>">Español</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li class="lvl-1">
|
||||
<ul class="lvl-2">
|
||||
<li><a href="<?= current_url("et", $parameters) ?>">Eesti keel</a></li>
|
||||
<li><a href="<?= current_url("fi", $parameters) ?>">Suomen kieli</a></li>
|
||||
<li><a href="<?= current_url("fr", $parameters) ?>">Français</a></li>
|
||||
<li><a href="<?= current_url("ga", $parameters) ?>">Gaeilge</a></li>
|
||||
<li><a href="<?= current_url("hr", $parameters) ?>">Hrvatski</a></li>
|
||||
<li><a href="<?= current_url("hu", $parameters) ?>">Magyar</a></li>
|
||||
<li><a href="<?= current_url("it", $parameters) ?>">Italiano</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li class="lvl-1">
|
||||
<ul class="lvl-2">
|
||||
<li><a href="<?= current_url("lt", $parameters) ?>">Lietuvių kalba</a></li>
|
||||
<li><a href="<?= current_url("mt", $parameters) ?>">Malti</a></li>
|
||||
<li><a href="<?= current_url("pl", $parameters) ?>">Polski</a></li>
|
||||
<li><a href="<?= current_url("ro", $parameters) ?>">Română</a></li>
|
||||
<li><a href="<?= current_url("sk", $parameters) ?>">Slovenčina</a></li>
|
||||
<li><a href="<?= current_url("sl", $parameters) ?>">Slovenščina</a></li>
|
||||
<li><a href="<?= current_url("sv", $parameters) ?>">Svenska</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
</nav>
|
||||
|
||||
<div class="content">
|
||||
<section class="main">
|
||||
<img src="<?= $img ?>" alt="<?= $name ?>" loading="lazy" />
|
||||
</section>
|
||||
|
||||
<section class="details">
|
||||
<div class="name">
|
||||
<h1><?= $name ?></h1>
|
||||
<p><?= $parcel ?></p>
|
||||
</div>
|
||||
<h2><?= $winegrower ?></h2>
|
||||
<h3><?= $details ?></h3>
|
||||
<p><?= $region ?></p>
|
||||
</section>
|
||||
|
||||
|
||||
<section class="ingredients">
|
||||
<h4><?= $tr_ingredients ?></h4>
|
||||
<p><?= $ingredients ?></p>
|
||||
</section>
|
||||
|
||||
<section class="facts">
|
||||
<h4><?= $tr_nutrional ?></h4>
|
||||
<table>
|
||||
<tr>
|
||||
<td></td>
|
||||
<td><?= $tr_capacity ?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><?= $tr_energy ?></td>
|
||||
<td><?= $energy_converted ?>kJ - <?= $energy ?>kcal</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<div><?= $tr_fats ?></div>
|
||||
<div class="marged"><?= $tr_saturated_fats ?></div>
|
||||
</td>
|
||||
<td>
|
||||
<div><?= $fats ?>g</div>
|
||||
<div><?= $saturated_fats ?>g</div>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<div><?= $tr_carbohydrates ?></div>
|
||||
<div class="marged"><?= $tr_sugar ?></div>
|
||||
</td>
|
||||
<td>
|
||||
<div><?= $carbohydrates ?>g</div>
|
||||
<div><?= $sugar ?>g</div>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><?= $tr_proteins ?></td>
|
||||
<td><?= $proteins ?>g</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><?= $tr_salt ?></td>
|
||||
<td><<?= $salt ?>g</td>
|
||||
</tr>
|
||||
</table>
|
||||
</section>
|
||||
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
Loading…
Add table
Add a link
Reference in a new issue