Files
cdnPRO/ibramakeup/index.php
Jacek Pyziak 2a0369ad2c Add XML feed processing scripts for laitica.pl and wyprzedaze.pl
- Implemented XML fetching and processing for laitica.pl, replacing domain links and saving the modified XML to laitica_feed.xml.
- Created a similar script for wyprzedaze.pl, with domain link replacements and saving to wyprzedaze_feed.xml.
- Both scripts handle errors for XML fetching and parsing, ensuring robust operation.
2025-11-18 22:52:05 +01:00

60 lines
2.0 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
// Adres źródłowego pliku XML
$sourceUrl = 'https://xml-feed.app.softitdigital.com/ibra-makeup.myshopify.com/feeds/view/cmi5215vf1f4czycu5150rxkp.xml';
// Dokąd zapisujemy plik na serwerze (relatywnie do tego skryptu)
$outputFile = __DIR__ . '/ibra-makeup_feed.xml';
// Domena do podmiany
$oldDomain = 'https://ibra-makeup.myshopify.com';
$newDomain = 'https://ibra-makeup.pl';
// --- 1. Pobranie XML ---
$xmlString = @file_get_contents($sourceUrl);
if ($xmlString === false) {
die('Nie udało się pobrać pliku XML ze źródła.');
}
// --- 2. Wczytanie XML z przestrzeniami nazw ---
$xml = @simplexml_load_string($xmlString);
if ($xml === false) {
die('Nie udało się zinterpretować pliku XML.');
}
// Pobranie listy namespaceów (m.in. "g")
$namespaces = $xml->getNamespaces(true);
// Upewniamy się, że mamy namespace "g"
if (!isset($namespaces['g'])) {
die('W pliku XML nie znaleziono przestrzeni nazw "g".');
}
// --- 3. Podmiana domeny w każdym <g:link> ---
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;
}
}
// --- 4. Zapis zmodyfikowanego 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 ---
$scheme = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') ? 'https' : 'http';
$host = $_SERVER['HTTP_HOST'] ?? 'localhost';
$path = rtrim(dirname($_SERVER['PHP_SELF']), '/\\');
$fileUrl = $scheme . '://' . $host . $path . '/ibra-makeup_feed.xml';
echo 'Nowy plik XML został zapisany tutaj: <a href="' . htmlspecialchars($fileUrl, ENT_QUOTES, 'UTF-8') . '">' . htmlspecialchars($fileUrl, ENT_QUOTES, 'UTF-8') . '</a>';