From b3d251c8d54d706554651b2cdd10e3a186b179c4 Mon Sep 17 00:00:00 2001 From: Jacek Pyziak Date: Thu, 20 Nov 2025 23:46:17 +0100 Subject: [PATCH] Add emoji removal function and enhance XML processing for multiple feeds --- ibramakeup/index.php | 78 +++++++++++++++++++++++++++++++---------- laitica.pl/index.php | 71 ++++++++++++++++++++++++++++--------- wyprzedaze.pl/index.php | 71 ++++++++++++++++++++++++++++--------- 3 files changed, 168 insertions(+), 52 deletions(-) diff --git a/ibramakeup/index.php b/ibramakeup/index.php index 644e38a..9108203 100644 --- a/ibramakeup/index.php +++ b/ibramakeup/index.php @@ -1,4 +1,13 @@ getNamespaces(true); // Upewniamy się, że mamy namespace "g" -if (!isset($namespaces['g'])) { - die('W pliku XML nie znaleziono przestrzeni nazw "g".'); +if (!isset($namespaces['g'])) +{ + die('W pliku XML nie znaleziono przestrzeni nazw "g".'); } -// --- 3. Podmiana domeny w każdym --- -foreach ($xml->channel->item as $item) { - // Dzieci w przestrzeni nazw g - $gChildren = $item->children($namespaces['g']); +// --- 3. Podmiana domeny + zamiana price <-> sale_price --- +foreach ($xml->channel->item as $item) +{ - if (isset($gChildren->link)) { - $currentLink = (string) $gChildren->link; - // Podmiana samej domeny na nową - $newLink = str_replace($oldDomain, $newDomain, $currentLink); - $gChildren->link = $newLink; - } + // Dzieci w przestrzeni nazw g + $gChildren = $item->children($namespaces['g']); + + // --- Podmiana linku --- + if (isset($gChildren->link)) + { + $currentLink = (string) $gChildren->link; + $newLink = str_replace($oldDomain, $newDomain, $currentLink); + $gChildren->link = $newLink; + } + + // --- Zamiana price <-> sale_price jeśli sale_price istnieje --- + if (isset($gChildren->sale_price) && trim((string)$gChildren->sale_price) !== '') + { + + $originalPrice = (string)$gChildren->price; + $salePrice = (string)$gChildren->sale_price; + + // Zamiana wartości + $gChildren->price = $salePrice; + $gChildren->sale_price = $originalPrice; + } + + if (isset($gChildren->identifier_exists)) + { + $gChildren->identifier_exists = 'true'; + } + + $gChildren->google_product_category = 'Health & Beauty > Personal Care > Cosmetics'; + + // --- Usuwanie emoji z opisu --- + if (isset($gChildren->description)) + { + $cleanDescription = removeEmoji((string)$gChildren->description); + $gChildren->description = $cleanDescription; + } } // --- 4. Zapis zmodyfikowanego XML na serwerze --- -if ($xml->asXML($outputFile) === false) { - die('Nie udało się zapisać zmodyfikowanego pliku XML na serwerze.'); +if ($xml->asXML($outputFile) === false) +{ + die('Nie udało się zapisać zmodyfikowanego pliku XML na serwerze.'); } // --- 5. Zbudowanie URL do zapisanego pliku i wyświetlenie go --- diff --git a/laitica.pl/index.php b/laitica.pl/index.php index fa61a22..1eacf62 100644 --- a/laitica.pl/index.php +++ b/laitica.pl/index.php @@ -1,4 +1,12 @@ getNamespaces(true); // Upewniamy się, że mamy namespace "g" -if (!isset($namespaces['g'])) { - die('W pliku XML nie znaleziono przestrzeni nazw "g".'); +if (!isset($namespaces['g'])) +{ + die('W pliku XML nie znaleziono przestrzeni nazw "g".'); } // --- 3. Podmiana domeny w każdym --- -foreach ($xml->channel->item as $item) { - // Dzieci w przestrzeni nazw g - $gChildren = $item->children($namespaces['g']); +foreach ($xml->channel->item as $item) +{ + // Dzieci w przestrzeni nazw g + $gChildren = $item->children($namespaces['g']); - if (isset($gChildren->link)) { - $currentLink = (string) $gChildren->link; - // Podmiana samej domeny na nową - $newLink = str_replace($oldDomain, $newDomain, $currentLink); - $gChildren->link = $newLink; - } + if (isset($gChildren->link)) + { + $currentLink = (string) $gChildren->link; + // Podmiana samej domeny na nową + $newLink = str_replace($oldDomain, $newDomain, $currentLink); + $gChildren->link = $newLink; + } + + // --- Zamiana price <-> sale_price jeśli sale_price istnieje --- + if (isset($gChildren->sale_price) && trim((string)$gChildren->sale_price) !== '') + { + + $originalPrice = (string)$gChildren->price; + $salePrice = (string)$gChildren->sale_price; + + // Zamiana wartości + $gChildren->price = $salePrice; + $gChildren->sale_price = $originalPrice; + } + + if (isset($gChildren->identifier_exists)) + { + $gChildren->identifier_exists = 'true'; + } + // --- Usuwanie emoji z opisu --- + if (isset($gChildren->description)) + { + $cleanDescription = removeEmoji((string)$gChildren->description); + $gChildren->description = $cleanDescription; + } } // --- 4. Zapis zmodyfikowanego XML na serwerze --- -if ($xml->asXML($outputFile) === false) { - die('Nie udało się zapisać zmodyfikowanego pliku XML na serwerze.'); +if ($xml->asXML($outputFile) === false) +{ + die('Nie udało się zapisać zmodyfikowanego pliku XML na serwerze.'); } // --- 5. Zbudowanie URL do zapisanego pliku i wyświetlenie go --- diff --git a/wyprzedaze.pl/index.php b/wyprzedaze.pl/index.php index a141f27..ff3e86c 100644 --- a/wyprzedaze.pl/index.php +++ b/wyprzedaze.pl/index.php @@ -1,4 +1,12 @@ getNamespaces(true); // Upewniamy się, że mamy namespace "g" -if (!isset($namespaces['g'])) { - die('W pliku XML nie znaleziono przestrzeni nazw "g".'); +if (!isset($namespaces['g'])) +{ + die('W pliku XML nie znaleziono przestrzeni nazw "g".'); } // --- 3. Podmiana domeny w każdym --- -foreach ($xml->channel->item as $item) { - // Dzieci w przestrzeni nazw g - $gChildren = $item->children($namespaces['g']); +foreach ($xml->channel->item as $item) +{ + // Dzieci w przestrzeni nazw g + $gChildren = $item->children($namespaces['g']); - if (isset($gChildren->link)) { - $currentLink = (string) $gChildren->link; - // Podmiana samej domeny na nową - $newLink = str_replace($oldDomain, $newDomain, $currentLink); - $gChildren->link = $newLink; - } + if (isset($gChildren->link)) + { + $currentLink = (string) $gChildren->link; + // Podmiana samej domeny na nową + $newLink = str_replace($oldDomain, $newDomain, $currentLink); + $gChildren->link = $newLink; + } + + // --- Zamiana price <-> sale_price jeśli sale_price istnieje --- + if (isset($gChildren->sale_price) && trim((string)$gChildren->sale_price) !== '') + { + + $originalPrice = (string)$gChildren->price; + $salePrice = (string)$gChildren->sale_price; + + // Zamiana wartości + $gChildren->price = $salePrice; + $gChildren->sale_price = $originalPrice; + } + + if (isset($gChildren->identifier_exists)) + { + $gChildren->identifier_exists = 'true'; + } + // --- Usuwanie emoji z opisu --- + if (isset($gChildren->description)) + { + $cleanDescription = removeEmoji((string)$gChildren->description); + $gChildren->description = $cleanDescription; + } } // --- 4. Zapis zmodyfikowanego XML na serwerze --- -if ($xml->asXML($outputFile) === false) { - die('Nie udało się zapisać zmodyfikowanego pliku XML na serwerze.'); +if ($xml->asXML($outputFile) === false) +{ + die('Nie udało się zapisać zmodyfikowanego pliku XML na serwerze.'); } // --- 5. Zbudowanie URL do zapisanego pliku i wyświetlenie go ---