mirror of
https://github.com/frontendnetwork/vegancheck.me
synced 2024-11-15 00:27:08 +00:00
Added faster API-call, Added response for invalid codes
This commit is contained in:
parent
ac909d7346
commit
bfb87144a8
1 changed files with 7 additions and 2 deletions
|
@ -4,10 +4,12 @@ if (empty($barcode)){
|
|||
}
|
||||
|
||||
else {
|
||||
$data = file_get_contents('https://world.openfoodfacts.org/api/v0/product/'.$barcode.'.json');
|
||||
$data = file_get_contents('https://world.openfoodfacts.org/api/v0/product/'.$barcode);
|
||||
$product = json_decode($data);
|
||||
$array = $product->product->ingredients_analysis_tags;
|
||||
$name = $product->product->product_name;
|
||||
$response = $product->status_verbose;
|
||||
|
||||
if (in_array("en:non-vegan", $array)) {
|
||||
echo '<span class="non-vegan animated fadeIn">"'.$name.'" ist nicht vegan.</span>';
|
||||
}
|
||||
|
@ -17,6 +19,9 @@ else {
|
|||
elseif (in_array("en:vegan", $array)) {
|
||||
echo '<span class="vegan animated fadeIn">"'.$name.'" ist Vegan!</span>';
|
||||
}
|
||||
elseif ($response == "no code or invalid code"){
|
||||
echo '<div class="animated fadeIn"><span class="missing">Mit diesem Barcode stimmt etwas nicht.</span></div>';
|
||||
}
|
||||
else {
|
||||
echo '<div class="animated fadeIn"><span>Dieses Produkt haben wir noch nicht in unserer Datenbank.</span><p class="missing">Willst du es hinzufügen? <a href="https://world.openfoodfacts.org/cgi/product.pl?code='.$barcode.'">Dieses Produkt hinzufügen bei OpenFoodFacts</a>.</p></div>';
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue