connect_error) { throw new Exception("Database connection failed: " . $mysqli->connect_error); } $stmt = $mysqli->prepare(" SELECT a.id, t.title, a.slug, a.created_at, a.main_image FROM articles a JOIN article_translations t ON a.id = t.article_id WHERE t.lang = ? AND a.category = 'books' ORDER BY a.created_at DESC "); $stmt->bind_param('s', $currentLang); $stmt->execute(); $new_articles = $stmt->get_result()->fetch_all(MYSQLI_ASSOC); $stmt->close(); $mysqli->close(); } catch (Exception $e) { error_log($e->getMessage()); } // 2. Načtení STARÝCH článků z books.html $old_articles = []; $html_content = @file_get_contents(__DIR__ . '/books.html'); if ($html_content !== false) { $dom = new DOMDocument(); libxml_use_internal_errors(true); // Oprava pro kódování $html_content = mb_encode_numericentity( $html_content, [0x80, 0x10FFFF, 0, ~0], 'UTF-8' ); $dom->loadHTML($html_content); $xpath = new DOMXPath($dom); $nodes = $xpath->query("//li[contains(@class, 'tile-small')]"); foreach ($nodes as $node) { $link = $xpath->query(".//a[contains(@class, 'tile-pan')]", $node)->item(0); $title = $xpath->query(".//p[contains(@class, 'meta')]", $node)->item(0); if ($link && $title) { preg_match('/url\(\s*[\'"](.*?)[\'"]\s*\)/', $link->getAttribute('style'), $matches); $image = $matches[1] ?? ''; $href = $link->getAttribute('href'); // Ošetření data $file_path = __DIR__ . '/' . $href; $date = file_exists($file_path) ? date('j.n.Y', filemtime($file_path)) : date('j.n.Y'); $old_articles[] = [ 'slug' => pathinfo($href, PATHINFO_FILENAME), 'title' => trim($title->nodeValue), 'image' => $image, 'href' => $href, 'date' => $date ]; } } } // 3. Sloučení článků $all_articles = array_merge($new_articles, $old_articles); ?> <?= $currentLang === 'cs' ? 'Knihy' : 'Books' ?>