-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathpositions.php
More file actions
280 lines (238 loc) · 13.2 KB
/
positions.php
File metadata and controls
280 lines (238 loc) · 13.2 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
<?php
$subpath = $_SERVER['REQUEST_URI'];
$incpath = "assets/inc";
include($incpath . "/config.php");
include($headerInc);
include("header_common_he.php.inc")
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Thesis Opportunities</title>
<!-- Include style file -->
<link rel="stylesheet" type="text/css" href="<?php echo $designCss;?>">
<link rel="stylesheet" type="text/css" href="<?php echo $publicationCss;?>">
</head>
<body>
<div class="sub-body">
<!-- ++++++++++++++++++++ Start Main Content of the page here! +++++++++++++++++++++ -->
<div class="publications-container">
<h1 class="page-title">Theses Opportunities</h1>
<?php
$url = "https://www.physi.uni-heidelberg.de/Jobs/jobs.php";
$raw_html_content = file_get_contents($url);
$output_html_for_theses = '';
if ($raw_html_content !== false) {
$doc = new DOMDocument();
// Use @ to suppress warnings from potentially malformed HTML from the source
// Prepending XML encoding declaration can help with character encoding issues
@$doc->loadHTML('<?xml encoding="utf-8" ?>' . $raw_html_content);
$xpath = new DOMXPath($doc);
// Helper function to extract and format theses
function extractAndFormatThesesForProfessor(DOMXPath $xpath, $sourceSectionHeading, $displaySectionHeading, $professorKeyword) {
$thesesData = [];
$sectionOutput = '';
// Find the h2 heading for the section
$headingNodes = $xpath->query("//h2[contains(text(), '$sourceSectionHeading')]");
if ($headingNodes->length > 0) {
$currentHeadingNode = $headingNodes->item(0);
// The table is expected inside a <div style="overflow: auto;"> following the h2
$tableContainerDiv = $xpath->query("following-sibling::div[contains(@style, 'overflow: auto')][1]", $currentHeadingNode)->item(0);
$tableNode = null;
if ($tableContainerDiv) {
$tableNode = $xpath->query("./table[1]", $tableContainerDiv)->item(0);
}
if ($tableNode) {
$rows = $xpath->query(".//tr", $tableNode);
foreach ($rows as $row) {
$cells = $xpath->query(".//td", $row);
$professorCellText = '';
if ($cells->length > 1) { // Professor name is usually in the second cell
$professorCellText = $cells->item(1)->nodeValue;
}
if (strpos($professorCellText, $professorKeyword) !== false) {
$titleLinkNode = $xpath->query(".//a", $cells->item(0))->item(0);
if ($titleLinkNode) {
$title = trim($titleLinkNode->nodeValue);
$href = trim($titleLinkNode->getAttribute('href'));
// Ensure URL is absolute
if (!preg_match('/^https?:\/\//i', $href)) {
$href = 'http://www.physi.uni-heidelberg.de' . (substr($href, 0, 1) === '/' ? '' : '/') . $href;
}
$thesesData[] = ['title' => $title, 'link' => $href];
}
}
}
}
}
if (!empty($thesesData)) {
// This div.opportunity-section-box will now be inside .all-opportunities-box
$sectionOutput .= '<div class="opportunity-section-box">';
$sectionOutput .= '<h2 class="publication-section-title">' . htmlspecialchars($displaySectionHeading) . '</h2>';
$sectionOutput .= '<ul class="opportunity-list">';
foreach ($thesesData as $thesis) {
$sectionOutput .= '<li><a href="' . htmlspecialchars($thesis['link']) . '">' . htmlspecialchars($thesis['title']) . '</a></li>';
}
$sectionOutput .= '</ul>';
$sectionOutput .= '</div>';
}
return $sectionOutput;
}
// Extract Bachelor Theses
$bachelor_theses_html = extractAndFormatThesesForProfessor($xpath, 'Bachelorarbeiten', 'Bachelor Theses', 'Schöning');
// Extract Master Theses
$master_theses_html = extractAndFormatThesesForProfessor($xpath, 'Master Arbeiten', 'Master Theses', 'Schöning');
// If there's content for either, wrap them in the main box
if (!empty($bachelor_theses_html) || !empty($master_theses_html)) {
echo '<div class="all-opportunities-box">';
echo $bachelor_theses_html;
// Add a small separator if both sections have content and are displayed
if (!empty($bachelor_theses_html) && !empty($master_theses_html)) {
// This could be a styled div or just rely on margins of .opportunity-section-box
}
echo $master_theses_html;
echo '</div>';
}
} else {
echo "<p>Error fetching content for Theses Opportunities.</p>";
}
?>
<div class="publications-container">
<div id="past-theses" class="publication-section">
<h2>Past Theses</h2>
<ul class="publications">
<?php
physi_publications("gruppe='ATLAS' OR gruppe = 'mu3e' OR titel='Characterization of a Monolithic Pixel Sensor Prototype in HV-CMOS Technology for the High-Luminosity LHC' OR autor='Arthur E. Bolz' OR autor='Sebastian Dittmeier'
OR autor='Aleem Ahmad Tariq Sheikh'");
?>
</ul>
</div>
</div>
</div>
<!-- ++++++++++++++++++++ End Main Content of the page here! +++++++++++++++++++++ -->
<br>
</div>
<script type="text/javascript">
document.addEventListener('DOMContentLoaded', function() {
const styleTags = document.querySelectorAll('style');
styleTags.forEach(tag => {
// Check for the specific @import rule that identifies the problematic block
if (tag.innerHTML.includes('@import url(https://www.physi.uni-heidelberg.de/design/css/style.css)')) {
tag.remove();
}
});
const sectionContainer = document.getElementById('past-theses');
if (!sectionContainer) {
return;
}
const originalUl = sectionContainer.querySelector('ul.publications');
if (!originalUl) {
return;
}
const tableCell = originalUl.querySelector('table td');
if (!tableCell) {
// No table cell found, likely no theses output or structure is different.
return;
}
const newContentFragment = document.createDocumentFragment();
let currentYearUl = null;
tableCell.childNodes.forEach(node => {
if (node.nodeType === Node.ELEMENT_NODE) { // Process only element nodes
if (node.tagName === 'H3') {
// If a currentYearUl exists from the previous year, append it.
if (currentYearUl && currentYearUl.hasChildNodes()) {
newContentFragment.appendChild(currentYearUl);
}
const yearDiv = document.createElement('div');
yearDiv.className = 'publication-year';
yearDiv.appendChild(node.cloneNode(true)); // Clone the H3
newContentFragment.appendChild(yearDiv);
currentYearUl = document.createElement('ul');
currentYearUl.className = 'publications';
} else if (node.tagName === 'B') {
if (!currentYearUl) {
// This handles cases where thesis items might appear before any H3,
// though the typical structure has H3 first.
currentYearUl = document.createElement('ul');
currentYearUl.className = 'publications';
// If this is the very first set of items without a year, this UL needs to be added to the fragment.
// However, the logic appends currentYearUl when next H3 is found or at the end.
// For items truly without a year header, they'd be grouped into the first UL.
}
const li = document.createElement('li');
const titleLinkOriginal = node.querySelector('a');
if (titleLinkOriginal) {
const pTitle = document.createElement('p');
pTitle.className = 'title';
pTitle.textContent = titleLinkOriginal.textContent;
li.appendChild(pTitle);
let currentNodePtr = node.nextSibling; // Expected: <br>
let authorText = '';
let detailsText = '';
// Traverse to find <i> (author) and subsequent text node (details)
// Skip the <br> immediately after <b>
if (currentNodePtr && currentNodePtr.nodeType === Node.ELEMENT_NODE && currentNodePtr.tagName === 'BR') {
currentNodePtr = currentNodePtr.nextSibling;
}
// Skip any whitespace text nodes before <i>
while (currentNodePtr && currentNodePtr.nodeType === Node.TEXT_NODE && currentNodePtr.textContent.trim() === '') {
currentNodePtr = currentNodePtr.nextSibling;
}
// Check if current node is <i> for author
if (currentNodePtr && currentNodePtr.nodeType === Node.ELEMENT_NODE && currentNodePtr.tagName === 'I') {
authorText = currentNodePtr.textContent;
// The details text node (e.g., "(Masterarbeit, 2024)") is the next sibling of <i>
let detailsNodeCandidate = currentNodePtr.nextSibling;
if (detailsNodeCandidate && detailsNodeCandidate.nodeType === Node.TEXT_NODE) {
detailsText = detailsNodeCandidate.textContent.trim();
}
}
// Append author if found
if (authorText) {
li.appendChild(document.createTextNode(authorText));
li.appendChild(document.createElement('br'));
}
// Create and append publication links div
const linksDiv = document.createElement('div');
linksDiv.className = 'publication-links';
const pdfLink = document.createElement('a');
pdfLink.href = titleLinkOriginal.href;
pdfLink.textContent = 'PDF'; // Or a more descriptive text like "Thesis Document"
linksDiv.appendChild(pdfLink);
li.appendChild(linksDiv);
// Append details text if found
if (detailsText) {
// Add a leading space if author was also present, for better formatting.
li.appendChild(document.createTextNode((authorText ? ' ' : '') + detailsText));
}
if (currentYearUl) {
currentYearUl.appendChild(li);
} else {
// Fallback for items not under a year (should ideally not happen with H3 structure)
newContentFragment.appendChild(li);
}
}
}
}
});
// Append the UL for the last processed year
if (currentYearUl && currentYearUl.hasChildNodes()) {
newContentFragment.appendChild(currentYearUl);
}
// Replace the old table structure with the new structured content
if (newContentFragment.hasChildNodes()) {
originalUl.remove(); // Remove the old <ul> which contains the table
sectionContainer.appendChild(newContentFragment);
} else if (tableCell.childNodes.length > 0) {
// Content was present but not transformed, log a warning.
console.warn('Past theses content found in table but could not be transformed. HTML structure might be unexpected.');
}
});
</script>
</body>
</html>
<?php
include($footerInc);
?>