/** * Tamil Nadu TRB Auto Fetch + PDF Reader * Version: PRO+ Tamil UI + Cache + Responsive Cards + New Badge + Filter UI */ use Smalot\PdfParser\Parser; if (!defined('ABSPATH')) exit; function thedal_fetch_trb_jobs_cached() { $cache_key = 'thedal_trb_jobs_cache'; $cached = get_transient($cache_key); if ($cached) return $cached; $url = "https://www.trb.tn.gov.in/notification.php?language=LG-1&status=Active"; $html = @file_get_contents($url); if (!$html) return "

⚠️ TRB இணையதளத்துடன் இணைக்க முடியவில்லை.

"; libxml_use_internal_errors(true); $dom = new DOMDocument(); @$dom->loadHTML($html); $xpath = new DOMXPath($dom); $rows = $xpath->query("//table//tr"); $output = "
"; foreach ($rows as $index => $row) { if ($index === 0) continue; $cols = $row->getElementsByTagName("td"); if ($cols->length < 3) continue; $title = trim($cols->item(1)->textContent); $date = trim($cols->item(2)->textContent); $pdfLink = $cols->item(1)->getElementsByTagName("a")->item(0); $href = $pdfLink ? $pdfLink->getAttribute("href") : "#"; if (strpos($href, 'http') !== 0) $href = "https://www.trb.tn.gov.in/" . ltrim($href, '/'); $is_new = (time() - strtotime($date) < 5 * DAY_IN_SECONDS) ? " 🆕 New" : ""; // --- PDF Content Extraction --- $pdfSummary = "

🔍 அறிவிப்பு உள்ளடக்கம் வாசிக்கப்படுகிறது...

"; $tempFile = sys_get_temp_dir() . "/trb_temp.pdf"; if (@file_put_contents($tempFile, @file_get_contents($href))) { try { $parser = new Parser(); $pdf = $parser->parseFile($tempFile); $text = mb_strtolower($pdf->getText(), 'UTF-8'); preg_match('/(\d+)\s+vacanc/i', $text, $vac); preg_match('/qualification[s]?:?\s*(.*)/i', $text, $qual); preg_match('/last\s*date[:\-]?\s*(.*?)\n/i', $text, $last); preg_match('/அணுகல்\s*தேதி[:\-]?\s*(.*?)\n/u', $text, $t_last); $pdfSummary = ""; } catch (Exception $e) { $pdfSummary = "

PDF உள்ளடக்கம் படிக்க முடியவில்லை.

"; } } $output .= "

📘 {$title}{$is_new}

📅 வெளியிடப்பட்ட தேதி: {$date}

{$pdfSummary} 📄 அறிவிப்பு பார்க்க (PDF)
"; } $output .= "
"; set_transient($cache_key, $output, 6 * HOUR_IN_SECONDS); return $output; } add_shortcode('trb_jobs', 'thedal_fetch_trb_jobs_cached'); // 🔎 Filter UI function trb_jobs_filter_ui() { return '
All Teaching Engineering PDF Only
'; } add_shortcode('trb_jobs_filter', 'trb_jobs_filter_ui'); // 🎨 Custom CSS function trb_custom_css() { ?> add_action('wp_head', 'trb_custom_css');