| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- <?php
- if ( ! empty( $_GET['preview'] ) ) {
- $post_id = filter_input( INPUT_GET, 'post_id', FILTER_SANITIZE_NUMBER_INT );
- $slug = get_post_meta($post_id, '_slug_zrzutka', true);
-
- } else {
- $slug = get_post_meta(get_the_ID(), '_slug_zrzutka', true);
- }
- if (false === ($html = get_transient($slug))) {
- $url = "https://zrzutka.pl/" . $slug;
-
- // Używamy cURL do pobrania zawartości strony
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL, $url);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
- curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
- curl_setopt($ch, CURLOPT_VERBOSE, true);
- // curl_setopt($ch, CURLOPT_STDERR, $wrapper);
-
- $html = curl_exec($ch);
- curl_close($ch);
-
- set_transient($slug, $html, 60 * 15);
- }
- // Sprawdzamy, czy udało się pobrać zawartość
- if (!$html) {
- echo "Nie udało się pobrać zawartości ze strony.";
- }
- // Tworzymy nowy obiekt DOMDocument i wczytujemy pobraną zawartość
- $dom = new DOMDocument;
- @$dom->loadHTML($html); // @ jest używane, aby stłumić ostrzeżenia generowane przez niepoprawny HTML
- // Tworzymy obiekt DOMXPath do wyszukiwania elementów
- $xpath = new DOMXPath($dom);
- // Szukamy elementu z klasą 'h3' w obrębie diva o atrybucie 'data-action' równym 'chip-show-amounts'
- $amountNode = $xpath->query('//div[@data-action="chip-show-amounts"]//div[@class="h3 m-0"]')->item(0);
- // Szukamy elementu z sumą ceny
- $sumNode = $xpath->query('//div[@data-action="chip-show-amounts"]//span[@data-action="chip-target-sum"]')->item(0);
- // Wyświetlamy znalezione wartości
- if ($amountNode && $sumNode) {
- $amount = strip_tags(trim($amountNode->textContent));
- $sum = strip_tags(trim($sumNode->textContent));
- // Parsowanie kwot jako liczby całkowite
- $amountNumber = intval(str_replace(' ', '', $amount));
- $sumNumber = intval(str_replace(' ', '', $sum));
- // Obliczamy procentowy udział
- $percent = ($amountNumber / $sumNumber) * 100;
- // Tworzymy pasek postępu
- $progressBar = "<div style='width: 100%; margin-top: 0.25em; background-color: #e0e0e0; border-radius: 20px; height: 20px; overflow: hidden;'>
- <div style='width: $percent%; background-color: #e64164; text-align: center; color: white; border-radius: 10px; padding: 5px; height: 50%;'></div>
- </div>
- <p class='has-small-font-size'>Mamy już <strong>$amountNumber zł</strong> z <strong>$sumNumber zł</strong>!</p>
- ";
- echo $progressBar;
- } else {
- echo "";
- }
- ?>
|