Subversion Repositories oidinfo_new_design

Rev

Rev 2 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 daniel-mar 1
#!/usr/bin/php
2
<?php
3
 
4
// This script re-generates the static pages by
5
// taking the template and inserting following data:
6
// - Replace %%CONTENT%% with content
7
// - Replace %%TITLE%% with the title
8
 
9
// -----------------------------------------------------------------------------
10
 
11
// You don't need to run this PHP script using the web browser.
12
// You can run it as shell script in the SSH terminal!
13
// Feel free to translate this script to OCaml :-)
14
 
15
// -----------------------------------------------------------------------------
16
 
17
//          "Input file"       "Output file"  "Title"
18
 
19
echo '<pre>';
20
 
21
_regenerate('density.raw.htm',         'density.htm',         'OID repository - Most populated OID arcs');
22
_regenerate('advanced-search.raw.htm', 'advanced-search.htm', 'OID repository - Advanced Search');
23
_regenerate('basic-search.raw.htm',    'basic-search.htm',    'OID repository - Search');
24
_regenerate('faq.raw.htm',             'faq.htm',             'OID repository - FAQ');
25
_regenerate('disclaimer.raw.htm',      'disclaimer.htm',      'OID repository - Terms of use');
26
_regenerate('display-example.raw.htm', 'display-example.htm', 'OID repository - Display example');
27
_regenerate('getting-an-oid-in-xml.raw.htm', 'getting-an-oid-in-xml.htm', 'OID repository - Getting an OID description in XML for JSON');
28
_regenerate('index.raw.htm',           'index.htm',           'OID repository - Home');
29
_regenerate('introduction.raw.htm',    'introduction.htm',    'OID repository - Introduction');
30
_regenerate('name-forms.raw.htm',      'name-forms.htm',      'OID repository - Standardized NameForms');
31
_regenerate('regexp.raw.htm',          'regexp.htm',          'OID repository - Search - Regexp');
32
_regenerate('registrant-account-charter.raw.htm', 'registrant-account-charter.htm', 'OID repository - Registrant account charter');
33
_regenerate('standards.raw.htm',       'standards.htm',       'OID repository - International standards on OIDs');
34
_regenerate('submit.raw.htm',          'submit.htm',          'OID repository - Submit');
35
_regenerate('country_codes.raw.htm',   'country_codes.htm',   'OID repository - Correspondence table between country codes and OIDs');
36
_regenerate('country_oids.raw.htm',    'country_oids.htm',    'OID repository - Country OIDs');
37
_regenerate('captured-standards.raw.htm',    'captured-standards.htm',    'OID repository - Captured Standards');
38
 
39
// Attention! HTML files which are not in the base directory need following
40
//            <head> becomes <head><base href="../">
41
_regenerate('doc/index.raw.htm',       'doc/index.htm',       'OID repository - Informative documents');
42
_regenerate('errors/200.raw.htm',      'errors/200.htm',      'OID repository - Error 200');
43
_regenerate('errors/302.raw.htm',      'errors/302.htm',      'OID repository - Error 302');
44
_regenerate('errors/304.raw.htm',      'errors/304.htm',      'OID repository - Error 304');
45
_regenerate('errors/400.raw.htm',      'errors/400.htm',      'OID repository - Server error');
46
_regenerate('errors/401.raw.htm',      'errors/401.htm',      'OID repository - Error 401');
47
_regenerate('errors/403-404.raw.htm',  'errors/403-404.htm',  'OID repository - Not found');
48
_regenerate('errors/500.raw.htm',      'errors/500.htm',      'OID repository - Internal server error');
49
_regenerate('errors/501.raw.htm',      'errors/501.htm',      'OID repository - Error 501');
50
_regenerate('errors/502.raw.htm',      'errors/502.htm',      'OID repository - Error 502');
51
_regenerate('errors/503.raw.htm',      'errors/503.htm',      'OID repository - Error 503');
52
 
53
// Attention! Additionally, management files need:
54
//            <div class="wrapper"> becomes <div class="wrapper_in_management">
55
_regenerate('gestion/index.raw.htm',   'gestion/index.htm',   'OID repository - Management');
56
_regenerate('gestion/replace.raw.htm', 'gestion/replace.htm', 'OID repository - Search and replace');
57
 
58
 
59
echo "Done!\n";
60
echo '</pre>';
61
 
62
// -----------------------------------------------------------------------------
63
 
64
function _regenerate($input_file, $output_file, $title) {
65
 
66
	$is_outside_basedir = strpos($input_file, '/') !== false;
67
 
68
	// Change relative path to absolute path
69
	$input_file = __DIR__ . '/../' . $input_file;
70
	$output_file = __DIR__ . '/../' . $output_file;
71
 
72
	// Security checks
73
	if (!file_exists($input_file))
74
		die("File does not exist: $input_file\n");
75
	if (file_exists($output_file) && (filemtime($output_file) > filemtime($input_file)))
76
		die("Output file is newer than input file! $output_file\n");
77
 
78
	// Trim <a> etc.
79
	/*
80
	trim_tag_contents($input_file, 'a');
81
	trim_tag_contents($input_file, 'strong');
82
	trim_tag_contents($input_file, 'b');
83
	trim_tag_contents($input_file, 'code');
84
	trim_tag_contents($input_file, 'i');
85
	*/
86
 
87
	// Load template
88
	$cont = file_get_contents(__DIR__ . '/../__template_begin.htm')."\n".
89
		'%%CONTENT%%'."\n".
90
		file_get_contents(__DIR__ . '/../__template_end.htm');
91
 
92
	// Replace template strings
93
	$cont = str_replace('%%CONTENT%%', file_get_contents($input_file), $cont);
94
	$cont = str_replace('%%TITLE%%', $title, $cont);
95
	if ($output_file == __DIR__ . '/../' . 'index.htm') {
96
		$cont = str_replace('%%FOOTER_TEXT%%', '&nbsp;'/*'This site is sponsored by <a href="https://www.orange.com">Orange S.A.</a>'*/, $cont);
97
	} else {
98
		$cont = str_replace('%%FOOTER_TEXT%%', '', $cont);
99
	}
100
 
101
	// Files outside the base directory
102
	if ($is_outside_basedir) {
103
		$cont = str_replace('<head>', '<head><base href="../">', $cont);
104
		$cont = str_replace('<div class="wrapper">', '<div class="wrapper_in_management">', $cont);
105
	}
106
 
107
	if (!file_exists($output_file) || (file_get_contents($output_file) != $cont)) {
108
		file_put_contents($output_file, $cont);
109
		echo "Generated $output_file\n";
110
	}
111
 
112
	touch($output_file, filemtime($input_file));
113
}
114
 
115
 
116
function trim_tag_contents($input_file, $tag) {
117
	$xxx = file_get_contents($input_file);
118
	$xxx_orig = $xxx;
119
	while (preg_match('@(<'.$tag.'[^>]*>)\s@ismU', $xxx)) {
120
		$xxx = preg_replace('@(<'.$tag.'[^>]*>)\s@ismU', '\\1', $xxx);
121
	}
122
	while (preg_match('@\s(</'.$tag.'>)@ismU', $xxx)) {
123
		$xxx = preg_replace('@\s(</'.$tag.'>)@ismU', '\\1', $xxx);
124
	}
125
	if ($xxx_orig != $xxx) {
126
		file_put_contents($input_file, $xxx);
127
	}
128
}