['nf_title' => 'Page not found', 'nf_p' => 'Sorry, nothing was found at this address.', 'home' => 'Home', 'leads_h' => 'Requests received', 'leads_empty' => 'No requests yet.', 'c_date' => 'Date', 'c_name' => 'Name', 'c_email' => 'Email', 'c_phone' => 'Phone', 'c_msg' => 'Message', 'c_ip' => 'IP', 'sent' => 'Thank you! Your message has been sent successfully.', 'invalid' => 'One or more fields have an error.', 'required' => 'This field is required.', 'cat_uncat' => 'Uncategorized', 'cat_blog' => 'Blog', 'ty_posts' => 'Posts', 'ty_pages' => 'Pages'], 'ro' => ['nf_title' => 'Pagina nu a fost găsită', 'nf_p' => 'Pagina nu a fost găsită.', 'home' => 'Acasă', 'leads_h' => 'Solicitări primite', 'leads_empty' => 'Încă nicio solicitare.', 'c_date' => 'Data', 'c_name' => 'Nume', 'c_email' => 'Email', 'c_phone' => 'Telefon', 'c_msg' => 'Mesaj', 'c_ip' => 'IP', 'sent' => 'Mulțumim! Mesajul a fost trimis cu succes.', 'invalid' => 'Unul sau mai multe câmpuri au o eroare.', 'required' => 'Câmp obligatoriu.', 'cat_uncat' => 'Necategorizat', 'cat_blog' => 'Blog', 'ty_posts' => 'Articole', 'ty_pages' => 'Pagini'], ]; return $S[$l][$k] ?? $k; } $CFG = cfg(); $BASE = wp_base(); $VER = '6.5.5'; $THEME = $CFG['theme']; $path = parse_url($_SERVER['REQUEST_URI'] ?? '/', PHP_URL_PATH); $path = '/' . trim(rawurldecode($path), '/'); $CF7 = '/wp-json/contact-form-7/v1/contact-forms/123/feedback'; if (strpos($path, '/pages/') === 0 || $path === '/pages' || strpos($path, '/data/') === 0 || $path === '/data') { http_response_code(403); echo 'Forbidden'; exit; } if ($path === '/wp-admin' || strpos($path, '/wp-admin/') === 0) { if ($path === '/wp-admin/admin-ajax.php') { header('Content-Type: text/html; charset=UTF-8'); header('X-Robots-Tag: noindex'); echo '0'; exit; } header('Location: ' . $BASE . '/wp-login.php?redirect_to=' . rawurlencode($BASE . '/wp-admin/') . '&reauth=1', true, 302); exit; } if ($path === $CF7) { handle_cf7_feedback(); exit; } if ($path === '/leads') { render_leads($BASE); exit; } switch ($path) { case '/wp-json': json_headers(); echo json_encode(rest_root($BASE), JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT); exit; case '/wp-json/wp/v2/posts': json_headers(); $ps = pages_of_type('post'); header('X-WP-Total: ' . count($ps)); header('X-WP-TotalPages: 1'); echo json_encode(array_map(fn($p) => rest_item($p, $BASE, 'posts'), $ps), JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT); exit; case '/wp-json/wp/v2/pages': json_headers(); $ps = pages_of_type('page'); header('X-WP-Total: ' . count($ps)); header('X-WP-TotalPages: 1'); echo json_encode(array_map(fn($p) => rest_item($p, $BASE, 'pages'), $ps), JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT); exit; case '/wp-json/wp/v2/users': json_headers(); echo json_encode([rest_user($BASE)], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT); exit; case '/wp-json/wp/v2/categories': json_headers(); echo json_encode(rest_categories(), JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT); exit; case '/wp-json/wp/v2/comments': json_headers(); echo json_encode([], JSON_PRETTY_PRINT); exit; case '/wp-json/wp/v2/types': json_headers(); echo json_encode(rest_types($BASE), JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT); exit; case '/wp-json/pll/v1/languages': json_headers(); echo json_encode(rest_languages(), JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT); exit; case '/xmlrpc.php': header('Content-Type: text/plain; charset=UTF-8'); header('Allow: POST'); echo 'XML-RPC server accepts POST requests only.'; exit; case '/wp-cron.php': http_response_code(200); exit; case '/feed': render_feed($BASE); exit; case '/wp-sitemap.xml': render_sitemap_index($BASE); exit; case '/wp-sitemap-posts-post-1.xml': render_sitemap_posts($BASE); exit; } foreach (cfg()['pages'] as $file => $info) { if ($path === '/' . $file) { header('Location: ' . $BASE . pretty_url($info), true, 301); exit; } } foreach (cfg()['pages'] as $file => $info) { if ($path === '/' . trim(pretty_url($info), '/') || ($info['slug'] === '' && $path === '/')) { render_page($BASE, $VER, $THEME, $file, $info); exit; } } if ($path === '/index.php') { header('Location: ' . $BASE . '/', true, 301); exit; } render_404($BASE, $VER, $THEME); exit; function wp_base() { $fwd = strtolower(trim(explode(',', $_SERVER['HTTP_X_FORWARDED_PROTO'] ?? '')[0])); $https = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') || $fwd === 'https' || strtolower($_SERVER['HTTP_X_FORWARDED_SSL'] ?? '') === 'on' || stripos($_SERVER['HTTP_CF_VISITOR'] ?? '', '"https"') !== false || (int)($_SERVER['SERVER_PORT'] ?? 0) === 443; $host = $_SERVER['HTTP_X_FORWARDED_HOST'] ?? ($_SERVER['HTTP_HOST'] ?? 'localhost'); $host = trim(explode(',', $host)[0]); return ($https ? 'https' : 'http') . '://' . $host; } function pretty_url($info) { return $info['slug'] === '' ? '/' : '/' . $info['slug'] . '/'; } function pages_of_type($type) { $out = []; foreach (cfg()['pages'] as $file => $info) { if (($info['type'] ?? 'page') === $type && empty($info['noindex'])) { $out[$file] = $info; } } return $out; } function body_class($info) { $id = $info['id']; if ($info['slug'] === '') return "home page-template-default page page-id-$id wp-singular"; if (($info['type'] ?? 'page') === 'post') return "post-template-default single single-post postid-$id wp-singular"; return "page page-template-default page-id-$id wp-singular"; } function render_page($base, $ver, $theme, $file, $info) { $html = @file_get_contents(__DIR__ . '/pages/' . $file); if ($html === false) { render_404($base, $ver, $theme); return; } $CFG = cfg(); header('Link: <' . $base . '/wp-json/>; rel="https://api.w.org/"', false); header('Link: <' . $base . '/wp-json/wp/v2/pages/2>; rel="alternate"; title="JSON"; type="application/json"', false); header('X-Pingback: ' . $base . '/xmlrpc.php'); header('X-Powered-By: PHP/8.2.12'); header('Content-Type: text/html; charset=UTF-8'); $amap = []; foreach ($CFG['assets'] as $dir) { $amap['"' . $dir . '/'] = '"' . $base . '/wp-content/themes/' . $theme . '/' . $dir . '/'; $amap["'" . $dir . '/'] = "'" . $base . '/wp-content/themes/' . $theme . '/' . $dir . '/'; } $html = strtr($html, $amap); $map = []; foreach ($CFG['pages'] as $f => $i) { $map[$f] = $base . pretty_url($i); } $files = array_keys($map); usort($files, fn($a, $b) => strlen($b) - strlen($a)); $alt = implode('|', array_map(fn($f) => preg_quote($f, '~'), $files)); $html = preg_replace_callback('~href="(' . $alt . ')(#[^"]*|\?[^"]*)?"~i', function ($m) use ($map) { return 'href="' . $map[$m[1]] . (isset($m[2]) ? $m[2] : '') . '"'; }, $html); if (!empty($CFG['form']['thankyou'])) { $thank = $base . '/' . trim($CFG['form']['thankyou'], '/') . '/'; $endpoint = $base . '/wp-json/contact-form-7/v1/contact-forms/123/feedback'; $locale = $CFG['locale']; $pid = $info['id']; $html = preg_replace_callback('/