wine-facts/core/core.php

87 lines
2.6 KiB
PHP
Raw Normal View History

2024-06-20 16:46:25 +02:00
<?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 .= ', ';
}
}
?>