fetchTags(0); $query = $_GET['q'] ?? ''; if ($query) { $items = array_filter($items, function($item) use ($query) { return mb_stripos($item['title'], $query) !== false; }); } return view('pages.uttayarndham.index', [ 'items' => array_values($items), 'query' => $query, 'seo' => [ 'title' => 'Uttayarndham (ທັມມະ) - ຄຳສອນພຸດທະ', 'description' => 'Uttayarndham ຮວບຮວມບົດຄວາມທັມມະ', 'keywords' => 'uttayarndham, ທັມມະ, ທັມ, ຄຳສອນພຸດທະ', ] ]); } public function apiList() { $page = max(0, intval($_GET['page'] ?? 0)); $items = $this->fetchTags($page); $html = @file_get_contents( self::BASE_URL . '/keyword/tags' . ($page > 0 ? '?page=' . $page : ''), false, $this->getStreamContext() ); // Check if there's a "load more" button or pagination $hasMore = $html !== false && (preg_match('/ki-more/', $html) === 1 || preg_match('/rel="next"/', $html) === 1); $this->json([ 'items' => $items, 'page' => $page, 'total' => ($page * 20) + count($items), 'hasMore' => $hasMore, ]); } public function apiContent() { $url = $_GET['url'] ?? ''; if (!$url) { http_response_code(400); $this->json(['error' => 'Missing url parameter']); return; } $fullUrl = strpos($url, 'http') === 0 ? $url : self::BASE_URL . $url; $html = @file_get_contents($fullUrl, false, $this->getStreamContext()); if ($html === false) { http_response_code(404); $this->json(['error' => 'Content not found']); return; } preg_match('/]*>(.*?)<\/h1>/s', $html, $titleMatches); $title = $titleMatches[1] ?? ''; $content = ''; preg_match('/]*>(.*?)<\/article>/s', $html, $articleMatches); if (!empty($articleMatches[1])) { $content = $articleMatches[1]; } if (empty($content)) { preg_match('/
]*>(.*?)<\/div>/s', $html, $divMatches); $content = $divMatches[1] ?? ''; } if (empty($content)) { preg_match('/
]*>(.*?)<\/div>/s', $html, $idMatches); $content = $idMatches[1] ?? ''; } $content = strip_tags($content, '