-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathentity.php
More file actions
289 lines (263 loc) · 13.6 KB
/
entity.php
File metadata and controls
289 lines (263 loc) · 13.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
<?php
/**
* Entity Detail Page
* Shows all documents related to a specific entity (person, org, location)
*/
$page_title = 'Entity Details - Epstein Suite';
require_once __DIR__ . '/includes/db.php';
$entityId = isset($_GET['id']) ? (int)$_GET['id'] : 0;
$entity = null;
$documents = [];
$relatedEntities = [];
$page = isset($_GET['p']) ? max(1, (int)$_GET['p']) : 1;
$limit = 20;
$offset = ($page - 1) * $limit;
$totalDocs = 0;
try {
$pdo = db();
// Fetch entity
$stmt = $pdo->prepare("SELECT * FROM entities WHERE id = ?");
$stmt->execute([$entityId]);
$entity = $stmt->fetch(PDO::FETCH_ASSOC);
if ($entity) {
// Get total document count
$stmt = $pdo->prepare("SELECT COUNT(*) FROM document_entities WHERE entity_id = ?");
$stmt->execute([$entityId]);
$totalDocs = (int)$stmt->fetchColumn();
// Fetch documents linked to this entity
$stmt = $pdo->prepare("
SELECT d.id, d.title, d.file_type, d.data_set, d.ai_summary, d.created_at,
de.frequency as mention_count
FROM documents d
JOIN document_entities de ON de.document_id = d.id
WHERE de.entity_id = ?
ORDER BY de.frequency DESC, d.created_at DESC
LIMIT ? OFFSET ?
");
$stmt->execute([$entityId, $limit, $offset]);
$documents = $stmt->fetchAll(PDO::FETCH_ASSOC);
// Fetch related entities (entities that appear in the same documents)
$stmt = $pdo->prepare("
SELECT e.id, e.name, e.type, COUNT(DISTINCT de2.document_id) as shared_docs
FROM entities e
JOIN document_entities de2 ON de2.entity_id = e.id
WHERE de2.document_id IN (
SELECT document_id FROM document_entities WHERE entity_id = ?
)
AND e.id != ?
GROUP BY e.id
ORDER BY shared_docs DESC
LIMIT 20
");
$stmt->execute([$entityId, $entityId]);
$relatedEntities = $stmt->fetchAll(PDO::FETCH_ASSOC);
}
} catch (Exception $e) {
// Silent fail
}
if (!$entity) {
header("HTTP/1.0 404 Not Found");
echo "Entity not found.";
exit;
}
$page_title = htmlspecialchars($entity['name']) . ' - Epstein Suite';
$meta_description = htmlspecialchars($entity['name']) . ' appears in ' . number_format($totalDocs) . ' Epstein-related documents. View all document mentions, related entities, and connections in the DOJ files.';
$og_title = htmlspecialchars($entity['name']) . ' - Entity Profile';
$og_description = 'Explore ' . number_format($totalDocs) . ' documents mentioning ' . htmlspecialchars($entity['name']) . ' in the Epstein files archive.';
$extra_head_tags = [];
$entitySchemaType = match (strtoupper($entity['type'] ?? '')) {
'PERSON' => 'Person',
'ORG', 'ORGANIZATION' => 'Organization',
'LOCATION' => 'Place',
default => 'Thing',
};
$entitySchema = [
'@context' => 'https://schema.org',
'@type' => $entitySchemaType,
'name' => $entity['name'],
'url' => 'https://epsteinsuite.com/entity.php?id=' . (int)$entity['id'],
'description' => $entity['name'] . ' is mentioned in ' . number_format($totalDocs) . ' documents in the Epstein Suite archive.',
];
if (!empty($relatedEntities)) {
$entitySchema['relatedTo'] = array_map(function ($re) {
return [
'@type' => match (strtoupper($re['type'] ?? '')) {
'PERSON' => 'Person',
'ORG', 'ORGANIZATION' => 'Organization',
default => 'Thing',
},
'name' => $re['name'],
'url' => 'https://epsteinsuite.com/entity.php?id=' . (int)$re['id'],
];
}, array_slice($relatedEntities, 0, 10));
}
$extra_head_tags[] = '<script type="application/ld+json">' . json_encode($entitySchema, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE) . '</script>';
$breadcrumbSchema = [
'@context' => 'https://schema.org',
'@type' => 'BreadcrumbList',
'itemListElement' => [
['@type' => 'ListItem', 'position' => 1, 'name' => 'Search', 'item' => 'https://epsteinsuite.com/'],
['@type' => 'ListItem', 'position' => 2, 'name' => 'Contacts', 'item' => 'https://epsteinsuite.com/contacts.php'],
['@type' => 'ListItem', 'position' => 3, 'name' => $entity['name']],
]
];
$extra_head_tags[] = '<script type="application/ld+json">' . json_encode($breadcrumbSchema, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE) . '</script>';
require_once __DIR__ . '/includes/header_suite.php';
$totalPages = ceil($totalDocs / $limit);
// Entity type styling
$typeColors = [
'PERSON' => 'bg-purple-100 text-purple-700 border-purple-200',
'ORG' => 'bg-blue-100 text-blue-700 border-blue-200',
'ORGANIZATION' => 'bg-blue-100 text-blue-700 border-blue-200',
'LOCATION' => 'bg-green-100 text-green-700 border-green-200',
];
$typeIcons = [
'PERSON' => '👤',
'ORG' => '🏢',
'ORGANIZATION' => '🏢',
'LOCATION' => '📍',
];
$typeColor = $typeColors[$entity['type']] ?? 'bg-slate-100 text-slate-700 border-slate-200';
$typeIcon = $typeIcons[$entity['type']] ?? '📌';
?>
<main class="flex-1 w-full max-w-6xl mx-auto px-4 sm:px-6 lg:px-8 py-8">
<!-- Breadcrumb -->
<nav class="text-sm text-slate-500 mb-6">
<a href="/" class="hover:text-blue-600">Search</a>
<span class="mx-2">›</span>
<a href="/contacts.php" class="hover:text-blue-600">Contacts</a>
<span class="mx-2">›</span>
<span class="text-slate-800"><?= htmlspecialchars($entity['name']) ?></span>
</nav>
<!-- Entity Header -->
<div class="bg-white rounded-2xl border border-slate-200 p-6 mb-8">
<div class="flex items-start gap-4">
<div class="w-16 h-16 rounded-xl <?= $typeColor ?> border flex items-center justify-center text-3xl flex-shrink-0">
<?= $typeIcon ?>
</div>
<div class="flex-1">
<h1 class="text-2xl font-bold text-slate-900 mb-1"><?= htmlspecialchars($entity['name']) ?></h1>
<div class="flex items-center gap-3">
<span class="inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium <?= $typeColor ?> border">
<?= htmlspecialchars($entity['type']) ?>
</span>
<span class="text-sm text-slate-500">
Appears in <strong><?= number_format($totalDocs) ?></strong> documents
</span>
</div>
</div>
<div class="flex-shrink-0">
<a href="/?q=<?= urlencode($entity['name']) ?>" class="inline-flex items-center gap-2 px-4 py-2 bg-blue-600 text-white rounded-lg hover:bg-blue-700 transition-colors text-sm font-medium">
<svg class="w-4 h-4" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z" />
</svg>
Search All
</a>
</div>
</div>
</div>
<div class="grid grid-cols-1 lg:grid-cols-3 gap-8">
<!-- Documents List -->
<div class="lg:col-span-2">
<div class="bg-white rounded-2xl border border-slate-200 overflow-hidden">
<div class="px-6 py-4 border-b border-slate-200">
<h2 class="font-semibold text-slate-900">Documents (<?= number_format($totalDocs) ?>)</h2>
</div>
<?php if (empty($documents)): ?>
<div class="p-6 text-center text-slate-500">
No documents found for this entity.
</div>
<?php else: ?>
<div class="divide-y divide-slate-100">
<?php foreach ($documents as $doc): ?>
<a href="/document.php?id=<?= $doc['id'] ?>" class="block p-4 hover:bg-slate-50 transition-colors">
<div class="flex items-start gap-3">
<div class="w-10 h-10 bg-slate-100 rounded-lg flex items-center justify-center text-lg flex-shrink-0">
<?php
echo match($doc['file_type'] ?? '') {
'pdf' => '📕',
'jpg', 'jpeg', 'png' => '🖼️',
'video', 'mp4' => '🎬',
default => '📄'
};
?>
</div>
<div class="flex-1 min-w-0">
<h3 class="font-medium text-slate-900 truncate"><?= htmlspecialchars($doc['title']) ?></h3>
<?php if (!empty($doc['ai_summary'])): ?>
<p class="text-sm text-slate-500 line-clamp-2 mt-1"><?= htmlspecialchars(substr($doc['ai_summary'], 0, 150)) ?>...</p>
<?php endif; ?>
<div class="flex items-center gap-3 mt-2 text-xs text-slate-400">
<span><?= htmlspecialchars($doc['data_set'] ?? 'Unknown') ?></span>
<?php if ($doc['mention_count'] > 1): ?>
<span class="text-purple-600"><?= $doc['mention_count'] ?> mentions</span>
<?php endif; ?>
</div>
</div>
</div>
</a>
<?php endforeach; ?>
</div>
<!-- Pagination -->
<?php if ($totalPages > 1): ?>
<div class="px-6 py-4 border-t border-slate-200 flex items-center justify-between">
<div class="text-sm text-slate-500">
Page <?= $page ?> of <?= $totalPages ?>
</div>
<div class="flex gap-2">
<?php if ($page > 1): ?>
<a href="?id=<?= $entityId ?>&p=<?= $page - 1 ?>" class="px-3 py-1 bg-slate-100 text-slate-700 rounded hover:bg-slate-200 text-sm">← Prev</a>
<?php endif; ?>
<?php if ($page < $totalPages): ?>
<a href="?id=<?= $entityId ?>&p=<?= $page + 1 ?>" class="px-3 py-1 bg-slate-100 text-slate-700 rounded hover:bg-slate-200 text-sm">Next →</a>
<?php endif; ?>
</div>
</div>
<?php endif; ?>
<?php endif; ?>
</div>
</div>
<!-- Sidebar -->
<div class="space-y-6">
<!-- Related Entities -->
<?php if (!empty($relatedEntities)): ?>
<div class="bg-white rounded-2xl border border-slate-200 overflow-hidden">
<div class="px-4 py-3 border-b border-slate-200">
<h3 class="font-semibold text-slate-900 text-sm">Related Entities</h3>
<p class="text-xs text-slate-500">Appear in same documents</p>
</div>
<div class="p-4 space-y-2 max-h-96 overflow-y-auto">
<?php foreach ($relatedEntities as $re):
$reColor = $typeColors[$re['type']] ?? 'bg-slate-100 text-slate-600';
$reIcon = $typeIcons[$re['type']] ?? '📌';
?>
<a href="/entity.php?id=<?= $re['id'] ?>" class="flex items-center gap-2 p-2 rounded-lg hover:bg-slate-50 transition-colors">
<span class="text-sm"><?= $reIcon ?></span>
<span class="flex-1 text-sm text-slate-800 truncate"><?= htmlspecialchars($re['name']) ?></span>
<span class="text-xs text-slate-400"><?= $re['shared_docs'] ?></span>
</a>
<?php endforeach; ?>
</div>
</div>
<?php endif; ?>
<!-- Quick Actions -->
<div class="bg-white rounded-2xl border border-slate-200 p-4">
<h3 class="font-semibold text-slate-900 text-sm mb-3">Quick Actions</h3>
<div class="space-y-2">
<a href="/?q=<?= urlencode($entity['name']) ?>" class="flex items-center gap-2 p-2 rounded-lg hover:bg-slate-50 transition-colors text-sm text-slate-700">
<span>🔍</span> Search all mentions
</a>
<a href="/contacts.php?type=<?= urlencode($entity['type']) ?>" class="flex items-center gap-2 p-2 rounded-lg hover:bg-slate-50 transition-colors text-sm text-slate-700">
<span>👥</span> Browse all <?= strtolower($entity['type']) ?>s
</a>
<a href="/drive.php?q=<?= urlencode($entity['name']) ?>" class="flex items-center gap-2 p-2 rounded-lg hover:bg-slate-50 transition-colors text-sm text-slate-700">
<span>📂</span> Search in Drive
</a>
</div>
</div>
</div>
</div>
</main>
<?php require_once __DIR__ . '/includes/footer_suite.php'; ?>
</body>
</html>