| Server IP : 127.0.0.1 / Your IP : 192.168.99.1 Web Server : Apache/2.4.35 (Win64) OpenSSL/1.1.1b mod_fcgid/2.3.9 System : Windows NT WIN-JEJMB9EN0L0 10.0 build 14393 (Windows Server 2016) AMD64 User : Administrator ( 0) PHP Version : 7.4.33 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : D:/bpkd_/admin/lib/ |
Upload File : |
<?php
// lib/PortalBeritaService.php
// Service untuk fetch berita dari portalberita.lumajangkab.go.id
class PortalBeritaService {
protected $apiUrl = 'https://portalberita.lumajangkab.go.id/api/berita.php';
protected $apiToken = '$2y$10$wALz2CBxlzBFxaA4WyHeqOexj9gvFeN3vFrQLT/1vfNhON6Pdrdla';
/**
* Fetch berita dari API
* @param int $limit Jumlah berita
* @param int $page Halaman (opsional)
* @return array
*/
public function fetchBerita($limit = 5, $page = 1) {
$url = $this->apiUrl . '?' . http_build_query([
'limit' => $limit,
'page' => $page
]);
$ch = curl_init();
curl_setopt_array($ch, [
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 30,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_HTTPHEADER => [
'Lumajang-Berita: ' . $this->apiToken,
'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36'
]
]);
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$error = curl_error($ch);
curl_close($ch);
if ($error || $httpCode !== 200) {
error_log("PortalBerita API Error: " . ($error ?: $httpCode));
return ['total' => 0, 'item' => []];
}
$result = json_decode($response, true);
return $result ?: ['total' => 0, 'item' => []];
}
/**
* Generate hash unik untuk URL repost
*/
public function generateUrlHash() {
return substr(md5(uniqid() . rand() . time()), 0, 12);
}
}