Files
html/api/pages-orphans-list.php
opus dc3941434d
Some checks failed
WEVAL NonReg / nonreg (push) Has been cancelled
auto-sync via WEVIA git_sync_all intent 2026-04-21T15:17:42+02:00
2026-04-21 15:17:42 +02:00

117 lines
5.4 KiB
PHP

<?php
/**
* Pages orphans list API V96.19
* User WTP shows "54 pages orphelines détectées. Voir la liste"
* But no API existed to return structured list with wire suggestions
*
* Endpoint: /api/pages-orphans-list.php
* Returns: 54 orphans with category, last_modified, size, wire_suggestion
*/
header('Content-Type: application/json; charset=utf-8');
header('Access-Control-Allow-Origin: *');
$DOCROOT = '/var/www/html';
// Read pages-index.php output if exists, else scan directly
$orphans_file = "$DOCROOT/api/orphans-json.json";
$data = @json_decode(@file_get_contents($orphans_file), true);
if (!is_array($data) || empty($data)) {
// Fallback scan: find .html files not referenced from index.html or WTP
$all_html = glob("$DOCROOT/*.html");
$referenced = [];
$anchor_files = [
'index.html', 'weval-technology-platform.html', 'wtp.html',
'admin-v2.html', 'admin.html', 'architecture.html', 'dg-command-center.html',
'enterprise-model.html', 'wevia-master.html', 'tools-hub.html', 'apps.html',
'agents-archi.html', 'nonreg.html', 'portal.html', 'portal-executive.html',
'lean6sigma-dashboard.html', 'cartographie-screens.html', 'pages-index.html',
'unified-hub.html', 'wevia-autonomy-dashboard.html', 'enterprise.html',
'ethica-hub.html', 'cloudflare-hub.html', 'huawei-cloud.html', 'orphans-hub.html', 'go-100pct.html',
'wevia-backoffice.html', 'wevia-business-visual-studio.html',
];
foreach ($anchor_files as $af) {
$af_path = "$DOCROOT/$af";
if (file_exists($af_path)) {
$content = file_get_contents($af_path);
if (preg_match_all('/href="\/?([a-z0-9_\-\xc0-\xff%]+\.html)"/iu', $content, $matches)) {
foreach ($matches[1] as $m) $referenced[$m] = true;
}
}
}
$orphans = [];
foreach ($all_html as $path) {
$name = basename($path);
// V96.21 filter out backup/gold files (legitimate archives, not real orphans)
if (preg_match("/\\.(gold|backup|bak|orig|pre-|\\.pre-|\\.GOLD-)/i", $name)) continue;
if (preg_match("/^\\./", $name)) continue; // hidden
if (preg_match("/(\\d{8}|\\d{14})\\.html$/", $name)) continue; // date-stamped backups
if (!isset($referenced[$name])) {
$orphans[] = [
'file' => $name,
'size_bytes' => filesize($path),
'last_modified' => date('c', filemtime($path)),
'age_days' => round((time() - filemtime($path)) / 86400),
];
}
}
// Enrich with category + suggestion
$categorize = function($name) {
$n = strtolower($name);
if (strpos($n, 'ethica') !== false) return ['marketing', 'Add link in WTP Marketing & Email module'];
if (strpos($n, 'wevia') !== false) return ['ai', 'Add link in WTP Intelligence IA module'];
if (strpos($n, 'wevads') !== false) return ['marketing', 'Add link in WTP Marketing & Email module'];
if (strpos($n, 'sap') !== false || strpos($n, 'vistex') !== false) return ['erp', 'Add link in WTP ERP Integrations module'];
if (strpos($n, 'huawei') !== false || strpos($n, 'cloud') !== false) return ['cloud', 'Add link in WTP Operations & Infra module'];
if (strpos($n, 'agent') !== false) return ['ai', 'Add link in WTP Intelligence IA / RH & Talent'];
if (strpos($n, 'test') !== false || strpos($n, 'demo') !== false) return ['dev', 'Archive to /tests/ or /demos/ folder'];
if (strpos($n, 'admin') !== false || strpos($n, 'dashboard') !== false) return ['operations', 'Add to WTP Operations & Infra'];
if (strpos($n, 'security') !== false || strpos($n, 'gdpr') !== false) return ['security', 'Add to WTP Security & Compliance'];
if (strpos($n, 'consent') !== false || strpos($n, 'privacy') !== false) return ['legal', 'Link from footer legal/privacy'];
if (strpos($n, 'ia') !== false || strpos($n, '-ai') !== false) return ['ai', 'Add link in WTP Intelligence IA'];
if (strpos($n, 'landing') !== false || strpos($n, 'nearshore') !== false) return ['marketing-landing', 'Verify SEO referenced, else add to sitemap'];
return ['other', 'Manual review - may be archived'];
};
foreach ($orphans as &$o) {
list($cat, $sug) = $categorize($o['file']);
$o['category'] = $cat;
$o['wire_suggestion'] = $sug;
}
unset($o); // WAVE 207 fix PHP by-ref leak
// WAVE 207 dedup by file name (defensive)
$seen = [];
$unique = [];
foreach ($orphans as $o2) {
if (!isset($seen[$o2['file']])) {
$seen[$o2['file']] = 1;
$unique[] = $o2;
}
}
$orphans = $unique;
// Count by category
$by_cat = [];
foreach ($orphans as $o) {
$by_cat[$o['category']] = ($by_cat[$o['category']] ?? 0) + 1;
}
arsort($by_cat);
$data = [
'total_html_pages' => count($all_html),
'referenced' => count($referenced),
'orphans_count' => count($orphans),
'orphans' => $orphans,
'by_category' => $by_cat,
'scan_anchors' => $anchor_files,
];
}
$data['v'] = 'V96.19-pages-orphans-opus';
$data['ts'] = date('c');
$data['note'] = 'Scan files in /var/www/html/*.html not referenced from index/WTP. Wire suggestions provided per file.';
echo json_encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE);