@php
$CATS = ['politics'=>'Politics','us'=>'US','world-news'=>'World News','sports'=>'Sports','business'=>'Business','technology'=>'Technology','entertainment'=>'Entertainment','science'=>'Science','lifestyle'=>'Lifestyle','opinion'=>'Opinion'];
$NAV = ['politics','us','world-news','sports','business','technology','entertainment','science','lifestyle'];
try { $nowET = new DateTime('now', new DateTimeZone('America/New_York')); } catch (Exception $e) { $nowET = new DateTime('now'); }
$todayET = $nowET->format('Y-m-d');
$yestET = date('Y-m-d', strtotime($todayET . ' -1 day'));
$cslug = (string)($params['category_slug'] ?? '');
$hslug = (string)($params['headline_slug'] ?? '');
$catLabel = $CATS[$cslug] ?? ucwords(str_replace('-', ' ', $cslug));
$head = (string)($item['headline'] ?? '');
$dek = trim((string)($item['dek'] ?? ''));
$kick = trim((string)($item['kicker'] ?? ''));
$img = trim((string)($item['image_url'] ?? ''));
$cap = trim((string)($item['image_caption'] ?? ''));
$by = trim((string)($item['byline'] ?? ''));
if ($by === '') { $by = 'PressTemps Newsroom'; }
$dl = trim((string)($item['dateline'] ?? ''));
$rt = trim((string)($item['read_time'] ?? ''));
$bodyRaw = (string)($item['body_html'] ?? '');
$srcRaw = trim((string)($item['sources_html'] ?? ''));
$kpRaw = trim((string)($item['key_points'] ?? ''));
$tagsCsv = trim((string)($item['tags'] ?? ''));
$adate = ''; $atime = '';
foreach ($selfq as $sr) { $adate = substr((string)($sr['date'] ?? ''), 0, 10); $atime = trim((string)($sr['time_et'] ?? '')); break; }
$dateLabel = '';
if ($adate === $todayET) { $dateLabel = 'Today' . ($atime !== '' ? ', ' . $atime . ' ET' : ''); }
elseif ($adate === $yestET) { $dateLabel = 'Yesterday' . ($atime !== '' ? ', ' . $atime . ' ET' : ''); }
else { $ts = strtotime($adate); $dateLabel = ($ts ? date('F j, Y', $ts) : $adate); }
$metaLine = 'Published ' . $dateLabel;
if ($rt !== '') { $metaLine .= ' · ' . $rt; }
$ini = '';
foreach (explode(' ', $by) as $bp) { if (strlen($ini) >= 2) { break; } if ($bp !== '') { $ini .= strtoupper(substr($bp, 0, 1)); } }
if ($ini === '') { $ini = 'PT'; }
$fmt = function ($it) use ($todayET, $yestET, $CATS) {
$d = substr((string)($it['date'] ?? ''), 0, 10);
$t = trim((string)($it['time_et'] ?? ''));
if ($d === $todayET) { return ($t !== '' ? $t . ' ET' : 'Today'); }
if ($d === $yestET) { return 'Yesterday'; }
$ts = strtotime($d);
return ($ts ? date('M j, Y', $ts) : $d);
};
$navHtml = '';
foreach ($NAV as $cs) { $on = ($cs === $cslug) ? ' pt-on' : ''; $navHtml .= '' . htmlspecialchars($CATS[$cs]) . ''; }
$navHtml .= '';
$figHtml = '';
if ($img !== '') {
$figHtml = '
';
if ($cap !== '') { $figHtml .= '' . htmlspecialchars($cap) . ' '; }
$figHtml .= ' ';
}
$kpHtml = '';
if ($kpRaw !== '') {
$lines = preg_split('/\\r\\n|\\r|\\n/', $kpRaw);
$rowsHtml = '';
foreach ($lines as $ln) { $ln = trim(ltrim(trim($ln), '-•* ')); if ($ln === '') { continue; } $rowsHtml .= ''; }
}
$srcHtml = '';
if ($srcRaw !== '') { $srcHtml = ''; }
$tagHtml = '';
if ($tagsCsv !== '') {
$chips = '';
foreach (explode(',', $tagsCsv) as $tp) { $tp = trim($tp); if ($tp === '') { continue; } $chips .= '' . htmlspecialchars($tp) . ''; }
if ($chips !== '') { $tagHtml = '';
}
if ($latestHtml !== '') { $latestHtml = ''; }
$mrRows = [];
foreach ($trendq as $r) { $rhs = (string)($r['headline_slug'] ?? ''); if ($rhs === '' || $rhs === $hslug) { continue; } $rk = trim((string)($r['trending_rank'] ?? '')); if ($rk === '') { $rk = '9'; } $mrRows[str_pad($rk, 2, '0', STR_PAD_LEFT) . '#' . count($mrRows)] = $r; }
ksort($mrRows);
if (count($mrRows) < 5) { foreach ($latestq as $r) { if (count($mrRows) >= 5) { break; } $rhs = (string)($r['headline_slug'] ?? ''); if ($rhs === '' || $rhs === $hslug) { continue; } $mrRows['z#' . count($mrRows)] = $r; } }
$mrHtml = ''; $mn = 0;
foreach ($mrRows as $r) { if ($mn >= 5) { break; } $mn++; $rcs = (string)($r['category_slug'] ?? ''); $rhs = (string)($r['headline_slug'] ?? ''); $rcl = $CATS[$rcs] ?? $rcs; $mrHtml .= '' . htmlspecialchars((string)($r['headline'] ?? '')) . ''; }
if ($mrHtml !== '') { $mrHtml = ''; }
$relHtml = ''; $rn = 0;
foreach ($relatedq as $r) {
if ($rn >= 4) { break; }
$rhs = (string)($r['headline_slug'] ?? ''); if ($rhs === '' || $rhs === $hslug) { continue; }
$rn++;
$rcs = (string)($r['category_slug'] ?? ''); $rimg = trim((string)($r['image_url'] ?? '')); $rh = (string)($r['headline'] ?? '');
$thumb = ($rimg !== '') ? '
' : '';
$relHtml .= '' . $thumb . ' ';
}
$out = '';
$out .= '';
$out .= 'PressTemps ';
$out .= '';
$out .= '';
$out .= ' ';
if ($relHtml !== '') {
$out .= 'More on this story
All ' . htmlspecialchars($catLabel) . ' ';
}
$footNav1 = ['politics','us','world-news','sports','business'];
$footNav2 = ['technology','entertainment','science','lifestyle','opinion'];
$fc1 = ''; foreach ($footNav1 as $cs) { $fc1 .= '' . htmlspecialchars($CATS[$cs]) . ''; }
$fc2 = ''; foreach ($footNav2 as $cs) { $fc2 .= '' . htmlspecialchars($CATS[$cs]) . ''; }
$out .= '';
@endphp
' . htmlspecialchars($ln) . '
'; }
if ($rowsHtml !== '') { $kpHtml = 'What to know
' . $rowsHtml . 'Sources
' . $srcRaw . '' . $chips . '
'; }
}
$latestHtml = ''; $ln = 0;
foreach ($latestq as $r) {
if ($ln >= 4) { break; }
$rhs = (string)($r['headline_slug'] ?? ''); $rcs = (string)($r['category_slug'] ?? '');
if ($rhs === '' || $rhs === $hslug) { continue; }
$ln++;
$latestHtml .= '' . htmlspecialchars($fmt($r)) . '
' . htmlspecialchars((string)($r['headline'] ?? '')) . 'Latest updates
' . $latestHtml . 'Most read
' . $mrHtml . '' . htmlspecialchars($CATS[$rcs] ?? $rcs) . '
' . htmlspecialchars($rh) . '
US Edition
Your source for latest news
' . htmlspecialchars($catLabel) . '';
if ($kick !== '') { $out .= ''; }
elseif ($dl !== '') { $out .= ''; }
$out .= '
';
$out .= '' . htmlspecialchars($head) . '
'; if ($dek !== '') { $out .= '' . htmlspecialchars($dek) . '
'; } $out .= ''; $out .= $figHtml; $out .= $kpHtml; $out .= '' . $bodyRaw . '
';
$out .= $srcHtml;
$out .= $tagHtml;
$out .= '' . $relHtml . '
{!! $out !!}