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
|
<?php
/**
* Post-processing of the DokuWiki documentation export.
*
* @link https://adodb.org/dokuwiki/doku.php?id=admin:offline_docs_build
*
* This file is part of ADOdb, a Database Abstraction Layer library for PHP.
*
* @package ADOdb
* @link https://adodb.org Project's web site and documentation
* @link https://github.com/ADOdb/ADOdb Source code and issue tracker
*
* The ADOdb Library is dual-licensed, released under both the BSD 3-Clause
* and the GNU Lesser General Public Licence (LGPL) v2.1 or, at your option,
* any later version. This means you can use it in proprietary products.
* See the LICENSE.md file distributed with this source code for details.
* @license BSD-3-Clause
* @license LGPL-2.1-or-later
*
* @copyright 2015 Damien Regad, Mark Newnham and the ADOdb community
* @author Mark Newnham
*/
/**
* Recurses a directory and deletes files inside
*
* Copied from php.net
*
* @param string $dir The driectory name
* $return null
*/
function delTree($dir) {
$files = array_diff(scandir($dir), array('.','..'));
foreach ($files as $file) {
(is_dir("$dir/$file")) ? delTree("$dir/$file") : unlink("$dir/$file");
}
return rmdir($dir);
}
/**
* Initializes the listdiraux method with a starting directory point
*
* copied from php.net
*
* @param string $dir Starting directory
* @return array FQ list of files
*/
function listdir($dir='.') {
if (!is_dir($dir)) {
return false;
}
$files = array();
listdiraux($dir, $files);
return $files;
}
/**
* Recurses a directory structure and creates a list of files
*
* @param string $dir Starting directory
* @param string[] $files By reference, the current file list
* @return null
*/
function listdiraux($dir, &$files) {
$handle = opendir($dir);
while (($file = readdir($handle)) !== false) {
if ($file == '.' || $file == '..') {
continue;
}
if (preg_match('/v6$/',$file))
/*
* This is only v5 documentation
*/
continue;
$filepath = $dir == '.' ? $file : $dir . '/' . $file;
if (is_link($filepath))
continue;
if (is_file($filepath))
$files[] = $filepath;
else if (is_dir($filepath))
listdiraux($filepath, $files);
}
closedir($handle);
}
/*
* Clean up the documentation directory from prior use
*/
if (is_dir('documentation'))
deltree('documentation');
mkdir('documentation');
$files = listdir('documentation-base');
sort($files, SORT_LOCALE_STRING);
/*
* Loop through files in documentation-base directory, creating a mirror
* structure in documentation, and applying the post-process rules defined
* below
*/
foreach ($files as $f) {
$r = str_replace('documentation-base','documentation',$f);
$dList = explode ('/',$r);
$titleList = $dList;
/*
* Get rid of the initial directory
*/
array_shift($titleList);
$depth = count($dList) -2;
$dSlash = '';
while(count($dList) > 1)
{
$dSlash .= array_shift($dList) . '/';
if (!is_dir($dSlash))
mkdir($dSlash);
}
if (!is_file($f))
continue;
if (substr($f,-4) <> 'html')
{
/*
* An image or something else, copy unmodified
*/
copy ($f,$r);
continue;
}
$prepend = str_repeat('../',$depth);
$doc = new DOMDocument();
@$doc->loadHTMLFile($f);
/*
* Remove Page Tools Group
*/
$xpath = new DOMXPath($doc);
/*
* Remove Top Menu Tools Group, and add a link to the ADOdb site
*/
$nodes = $xpath->query("//div[@class='tools group']");
foreach($nodes as $node) {
$pn = $node->parentNode;
$pn->removeChild($node);
$newChild = $doc->createElement('div','');
$newDiv = $pn->appendChild($newChild);
$newDiv->setAttribute('style','text-align:right');
$newChild = $doc->createElement('a','ADOdb Web Site');
$newA = $newDiv->appendChild($newChild);
$newA->setAttribute('href','https://adodb.org');
}
/*
* Remove Trace
*/
$nodes = $xpath->query("//div[@class='breadcrumbs']");
foreach($nodes as $node) {
$node->parentNode->removeChild($node);
}
/*
* Remove Side Menu Tools Group
*/
$nodes = $xpath->query("//div[@id='dokuwiki__pagetools']");
foreach($nodes as $node) {
$node->parentNode->removeChild($node);
}
/*
* Fix main links
*/
$nodes = $xpath->query("//a[@class='wikilink1']");
foreach($nodes as $node) {
$n = $node->getAttribute('title');
$p = $prepend . str_replace(':','/',$n) . '.html';
$node->setAttribute('href', $p);
}
/*
* Fix In Page links
*/
$nodes = $xpath->query("//a[@class='wikilink2']");
foreach($nodes as $node) {
$n = $node->getAttribute('title');
$p = $prepend . str_replace(':','/',$n) . '.html';
$node->setAttribute('href', $p);
}
/*
* Make Graphic point to first page. This will break if the image size
* ever changes.
*/
$corePage = $prepend . '/index.html';
$nodes = $xpath->query("//img[@width='176']");
foreach($nodes as $node) {
$node->parentNode->setAttribute('href', $corePage);
}
/*
* Change title of page
*/
$nodes = $xpath->query("//title");
foreach($nodes as $node) {
$docTitle = implode(':',$titleList);
$docTitle = str_replace('.html','',$docTitle);
$pn = $node->parentNode;
$pn->removeChild($node);
$newChild = $doc->createElement('title',$docTitle);
$pn->appendChild($newChild);
}
$doc->saveHTMLFile($r);
echo $r, "\n";
}
/*
* Now remove the original index and replace it with the hardcopy documentation one
*/
unlink ('documentation/index.html');
rename('documentation/adodb_index.html','documentation/index.html');
/*
* We could add in an auto zip and upload here, but this is a good place to
* stop and check the output
*/
|