-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlessons_viewer.php
More file actions
208 lines (195 loc) · 7.07 KB
/
Copy pathlessons_viewer.php
File metadata and controls
208 lines (195 loc) · 7.07 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
<?php
// Define the base URL for the Drupal JSON:API endpoint
$base_url = "http://d10dev.calidev.org/jsonapi/node/lesson";
// -------------------------------------------------------------------------
// SCENARIO A: XML Source Viewer Mode
// -------------------------------------------------------------------------
if (isset($_GET['view_xml']) && !empty($_GET['view_xml'])) {
$lesson_id = $_GET['view_xml'];
// Fetch only the specific lesson node via its UUID to get its XML field
$single_lesson_url = $base_url . '/' . urlencode($lesson_id) . '?fields[node--lesson]=title,field_lesson_xml';
$response = @file_get_contents($single_lesson_url);
$title = "XML Viewer";
$xml_content = "";
$error_msg = "";
if ($response !== false) {
$payload = json_decode($response, true);
if (isset($payload['data'])) {
$title = $payload['data']['attributes']['title'] ?? 'Untitled Lesson';
$xml_content = $payload['data']['attributes']['field_lesson_xml'] ?? '';
} else {
$error_msg = "Lesson data structure could not be read.";
}
} else {
$error_msg = "Failed to fetch the XML payload for this lesson.";
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>XML Source: <?php echo htmlspecialchars($title); ?></title>
<style>
body {
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
margin: 40px;
background-color: #f4f6f8;
color: #333;
}
.viewer-container {
max-width: 1000px;
margin: 0 auto;
background: #fff;
padding: 30px;
border-radius: 8px;
box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}
.nav-back {
display: inline-block;
margin-bottom: 20px;
color: #0056b3;
text-decoration: none;
font-weight: bold;
}
.nav-back:hover { text-decoration: underline; }
h1 { margin-top: 0; color: #111; font-size: 1.75rem; border-bottom: 2px solid #eaeaea; padding-bottom: 10px;}
pre {
background: #282c34;
color: #abb2bf;
padding: 20px;
border-radius: 6px;
overflow-x: auto;
font-family: "Courier New", Courier, monospace;
font-size: 0.95rem;
line-height: 1.5;
border: 1px solid #1e2127;
}
.error { background: #f8d7da; color: #721c24; padding: 15px; border-radius: 4px; }
</style>
</head>
<body>
<div class="viewer-container">
<a class="nav-back" href="?">← Back to Lessons Directory</a>
<h1>XML Content Document for: <?php echo htmlspecialchars($title); ?></h1>
<?php if (!empty($error_msg)): ?>
<p class="error"><?php echo $error_msg; ?></p>
<?php elseif (empty($xml_content) || $xml_content === '-'): ?>
<p style="color: #666; font-style: italic;">No valid XML manifest content is available for this lesson record (Field value is empty or '-').</p>
<?php else: ?>
<pre><code><?php echo htmlspecialchars($xml_content); ?></code></pre>
<?php endif; ?>
</div>
</body>
</html>
<?php
exit; // Halt execution so the main listing page does not render underneath
}
// -------------------------------------------------------------------------
// SCENARIO B: Main Directory Listing Mode (Default View)
// -------------------------------------------------------------------------
$params = [
'filter' => [
'field_lesson_type' => 'CALI Author'
],
'fields' => [
'node--lesson' => 'id,title,body' // Grab the UUID ('id') alongside title and body
]
];
$full_url = $base_url . '?' . http_build_query($params);
$response = @file_get_contents($full_url);
$lessons = [];
if ($response !== false) {
$payload = json_decode($response, true);
$lessons = $payload['data'] ?? [];
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>CALI Author Lessons</title>
<style>
body {
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
line-height: 1.6;
color: #333;
max-width: 800px;
margin: 40px auto;
padding: 0 20px;
background-color: #f9f9f9;
}
h1 {
color: #111;
border-bottom: 2px solid #ddd;
padding-bottom: 10px;
margin-bottom: 30px;
}
.lesson-card {
background: #fff;
padding: 25px;
margin-bottom: 20px;
border-radius: 8px;
box-shadow: 0 2px 4px rgba(0,0,0,0.05);
border: 1px solid #eef0f2;
position: relative;
}
.lesson-title {
margin-top: 0;
color: #0056b3;
font-size: 1.5rem;
padding-right: 140px; /* Make space for action button */
}
.lesson-body {
color: #444;
margin-bottom: 15px;
}
.xml-btn {
display: inline-block;
background-color: #eef2f7;
color: #337ab7;
padding: 6px 12px;
border-radius: 4px;
text-decoration: none;
font-size: 0.85rem;
font-weight: 600;
border: 1px solid #dcdfe6;
transition: all 0.2s ease;
}
.xml-btn:hover {
background-color: #337ab7;
color: #fff;
border-color: #337ab7;
}
.no-results {
padding: 20px;
background: #fff3cd;
color: #856404;
border-radius: 4px;
}
</style>
</head>
<body>
<h1>CALI Author Lessons Directory</h1>
<?php if (!empty($lessons)): ?>
<?php foreach ($lessons as $lesson): ?>
<?php
$uuid = $lesson['id']; // Unique API Resource ID used to fetch this specific entity
$title = htmlspecialchars($lesson['attributes']['title'] ?? 'Untitled Lesson');
$body = $lesson['attributes']['body']['processed'] ?? '<p>No description available.</p>';
?>
<article class="lesson-card">
<h2 class="lesson-title"><?php echo $title; ?></h2>
<div class="lesson-body">
<?php echo $body; ?>
</div>
<a class="xml-btn" href="?view_xml=<?php echo urlencode($uuid); ?>">
</> View XML Source
</a>
</article>
<?php endforeach; ?>
<?php else: ?>
<p class="no-results">No lessons found or failed to connect to the API endpoint.</p>
<?php endif; ?>
</body>
</html>