-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathindex.php
More file actions
60 lines (48 loc) · 1.76 KB
/
index.php
File metadata and controls
60 lines (48 loc) · 1.76 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
<?php
if ( isset ( $_GET [ 'id' ] ) && trim ( $_GET [ "id" ] ) == 'working' ) {
$handbookFile = 'working.htm';
} else {
$handbookFile = 'current-version.htm';
}
$input = new DOMDocument();
$input -> loadHTMLFile ( $handbookFile );
$menu = $input -> createElement ( "ul" );
$menu -> setAttribute ( "id", "anchor-menu" );
$content = $input -> getElementByID ( "content" );
$lastMenuItem = null;
$subMenu = null;
foreach ( $content -> childNodes as $child ) {
if( $child -> nodeName == 'h3' ) {
$li = $input -> createElement ( "li" );
$anchor = $input -> createElement ( "a", $child-> nodeValue );
$anchor -> setAttribute ( 'href', "#" . $child->getAttribute ( 'id' ) );
$li -> appendChild ( $anchor );
$menu -> appendChild ( $li );
$lastMenuItem = $li;
$subMenu = null;
}
if( $child -> nodeName == 'h4' ) {
$li = $input -> createElement ( "li" );
$anchor = $input -> createElement ( "a", $child-> nodeValue );
$anchor -> setAttribute ( 'href', "#" . $child->getAttribute ( 'id' ) );
$li -> appendChild ( $anchor );
if ( $subMenu == null ) {
$subMenu = $input -> createElement ( "ul" );
$lastMenuItem -> appendChild ( $subMenu );
}
$subMenu -> appendChild ( $li );
}
}
$li = $input -> createElement ( "li" );
$anchor = $input -> createElement ( "a", "Comments" );
$anchor -> setAttribute ( 'href', "#comments-header" );
$li -> appendChild ( $anchor );
$menu -> appendChild ( $li );
$menuHeader = $input -> createElement ( "h2" );
$menuHeader -> setAttribute ( "id", "menu-header" );
$menuHeader -> nodeValue = 'Navigation';
$menuTag = $input -> getElementByID ( "nav-anchor-menu" );
$menuTag -> appendChild ( $menuHeader );
$menuTag -> appendChild ( $menu );
print $input -> saveHTML();
?>