-
-
Notifications
You must be signed in to change notification settings - Fork 747
Expand file tree
/
Copy pathdebug_server.py
More file actions
71 lines (54 loc) · 3.15 KB
/
debug_server.py
File metadata and controls
71 lines (54 loc) · 3.15 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
import os
import re
class MockHandler:
def process_php_file(self, filename):
print(f"Processing {filename}")
if not os.path.exists(filename): return ""
with open(filename, 'r', encoding='utf-8') as f:
content = f.read()
def replace_include_block(match):
inc_file = match.group(1)
return self.process_php_file(inc_file)
content = re.sub(r'<\?php\s+include\s*\(\s*["\']([^"\']+)["\']\s*\);\s*\?>', replace_include_block, content, flags=re.DOTALL | re.IGNORECASE)
def replace_include_only(match):
inc_file = match.group(1)
return self.process_php_file(inc_file)
content = re.sub(r'include\s*\(\s*["\']([^"\']+)["\']\s*\);', replace_include_only, content, flags=re.IGNORECASE)
return content
def process_php_header_logic(self, html, lan_suffix):
print("Processing header logic")
html = html.replace("'.$html_attributes.'", "")
html = html.replace("'.$subtitle.'", "")
if 'highlight.min.js' in html:
html = re.sub(r'<\?php\s+echo\s+\'\s+<link.*?highlight\.min\.js.*?\?>',
'<link type="text/css" rel="stylesheet" href="$path/css/github.css">\n<script type="text/javascript" src="$path/src/highlight.min.js"></script>',
html, flags=re.DOTALL)
glsl_canvas = '<script type="text/javascript" src="$path/src/glslCanvas/build/GlslCanvas.js"></script>'
# Mock assumption for file check
html = re.sub(r'<\?php\s+if \(file_exists.*?GlslCanvas\.js.*?\?>', glsl_canvas, html, flags=re.DOTALL)
glsl_editor = '''
<link type="text/css" rel="stylesheet" href="$path/src/glslEditor/build/glslEditor.css">
<script type="application/javascript" src="$path/src/glslEditor/build/glslEditor.js"></script>
'''
html = re.sub(r'<\?php\s+if \(file_exists.*?glslEditor\.js.*?\?>', glsl_editor, html, flags=re.DOTALL)
glsl_gallery = '''
<link type="text/css" rel="stylesheet" href="$path/src/glslGallery/build/glslGallery.css">
<script type="application/javascript" src="$path/src/glslGallery/build/glslGallery.js"></script>
'''
html = re.sub(r'<\?php\s+if \(file_exists.*?glslGallery\.js.*?\?>', glsl_gallery, html, flags=re.DOTALL)
main_style = '<link type="text/css" rel="stylesheet" href="$path/css/style.css">'
lang_style = ''
if lan_suffix != '':
style_name = f'css/style{lan_suffix}.css'
# Mock existence check
lang_style = f'<link type="text/css" rel="stylesheet" href="$path/{style_name}">'
html = re.sub(r'<\?php\s+echo\s+\'\s+<link type="text/css" rel="stylesheet" href="\'.\$path\.\'/css/style\.css.*?\?>',
main_style + lang_style, html, flags=re.DOTALL)
return html
h = MockHandler()
header = h.process_php_file('header.php')
toc = h.process_php_file('toc-header.php')
footer = h.process_php_file('footer.php')
header = h.process_php_header_logic(header, '-tr')
full = header + toc + "CONTENT" + footer
print("Full length:", len(full))