Rev 2 | View as "text/php" | Blame | Compare with Previous | Last modification | View Log | RSS feed
#!/usr/bin/php
<?php
// This script re-generates the static pages by
// taking the template and inserting following data:
// - Replace %%CONTENT%% with content
// - Replace %%TITLE%% with the title
// -----------------------------------------------------------------------------
// You don't need to run this PHP script using the web browser.
// You can run it as shell script in the SSH terminal!
// Feel free to translate this script to OCaml :-)
// -----------------------------------------------------------------------------
// "Input file" "Output file" "Title"
echo '<pre>';
_regenerate('density.raw.htm', 'density.htm', 'OID repository - Most populated OID arcs');
_regenerate('advanced-search.raw.htm', 'advanced-search.htm', 'OID repository - Advanced Search');
_regenerate('basic-search.raw.htm', 'basic-search.htm', 'OID repository - Search');
_regenerate('faq.raw.htm', 'faq.htm', 'OID repository - FAQ');
_regenerate('disclaimer.raw.htm', 'disclaimer.htm', 'OID repository - Terms of use');
_regenerate('display-example.raw.htm', 'display-example.htm', 'OID repository - Display example');
_regenerate('getting-an-oid-in-xml.raw.htm', 'getting-an-oid-in-xml.htm', 'OID repository - Getting an OID description in XML for JSON');
_regenerate('index.raw.htm', 'index.htm', 'OID repository - Home');
_regenerate('introduction.raw.htm', 'introduction.htm', 'OID repository - Introduction');
_regenerate('name-forms.raw.htm', 'name-forms.htm', 'OID repository - Standardized NameForms');
_regenerate('regexp.raw.htm', 'regexp.htm', 'OID repository - Search - Regexp');
_regenerate('registrant-account-charter.raw.htm', 'registrant-account-charter.htm', 'OID repository - Registrant account charter');
_regenerate('standards.raw.htm', 'standards.htm', 'OID repository - International standards on OIDs');
_regenerate('submit.raw.htm', 'submit.htm', 'OID repository - Submit');
_regenerate('country_codes.raw.htm', 'country_codes.htm', 'OID repository - Correspondence table between country codes and OIDs');
_regenerate('country_oids.raw.htm', 'country_oids.htm', 'OID repository - Country OIDs');
_regenerate('captured-standards.raw.htm', 'captured-standards.htm', 'OID repository - Captured Standards');
// Attention! HTML files which are not in the base directory need following
// <head> becomes <head><base href="../">
_regenerate('doc/index.raw.htm', 'doc/index.htm', 'OID repository - Informative documents');
_regenerate('errors/200.raw.htm', 'errors/200.htm', 'OID repository - Error 200');
_regenerate('errors/302.raw.htm', 'errors/302.htm', 'OID repository - Error 302');
_regenerate('errors/304.raw.htm', 'errors/304.htm', 'OID repository - Error 304');
_regenerate('errors/400.raw.htm', 'errors/400.htm', 'OID repository - Server error');
_regenerate('errors/401.raw.htm', 'errors/401.htm', 'OID repository - Error 401');
_regenerate('errors/403-404.raw.htm', 'errors/403-404.htm', 'OID repository - Not found');
_regenerate('errors/500.raw.htm', 'errors/500.htm', 'OID repository - Internal server error');
_regenerate('errors/501.raw.htm', 'errors/501.htm', 'OID repository - Error 501');
_regenerate('errors/502.raw.htm', 'errors/502.htm', 'OID repository - Error 502');
_regenerate('errors/503.raw.htm', 'errors/503.htm', 'OID repository - Error 503');
// Attention! Additionally, management files need:
// <div class="wrapper"> becomes <div class="wrapper_in_management">
_regenerate('gestion/index.raw.htm', 'gestion/index.htm', 'OID repository - Management');
_regenerate('gestion/replace.raw.htm', 'gestion/replace.htm', 'OID repository - Search and replace');
echo "Done!\n";
echo '</pre>';
// -----------------------------------------------------------------------------
function _regenerate($input_file, $output_file, $title) {
$is_outside_basedir = strpos($input_file, '/') !== false;
// Change relative path to absolute path
$input_file = __DIR__ . '/../' . $input_file;
$output_file = __DIR__ . '/../' . $output_file;
// Security checks
if (!file_exists($input_file))
die("File does not exist: $input_file\n");
if (file_exists($output_file) && (filemtime($output_file) > filemtime($input_file)))
die("Output file is newer than input file! $output_file\n");
// Trim <a> etc.
/*
trim_tag_contents($input_file, 'a');
trim_tag_contents($input_file, 'strong');
trim_tag_contents($input_file, 'b');
trim_tag_contents($input_file, 'code');
trim_tag_contents($input_file, 'i');
*/
// Load template
$cont = file_get_contents(__DIR__ . '/../__template_begin.htm')."\n".
'%%CONTENT%%'."\n".
file_get_contents(__DIR__ . '/../__template_end.htm');
// Replace template strings
$cont = str_replace('%%CONTENT%%', file_get_contents($input_file), $cont);
$cont = str_replace('%%TITLE%%', $title, $cont);
if ($output_file == __DIR__ . '/../' . 'index.htm') {
$cont = str_replace('%%FOOTER_TEXT%%', ' '/*'This site is sponsored by <a href="https://www.orange.com">Orange S.A.</a>'*/, $cont);
} else {
$cont = str_replace('%%FOOTER_TEXT%%', '', $cont);
}
// Files outside the base directory
if ($is_outside_basedir) {
$cont = str_replace('<head>', '<head><base href="../">', $cont);
$cont = str_replace('<div class="wrapper">', '<div class="wrapper_in_management">', $cont);
}
if (!file_exists($output_file) || (file_get_contents($output_file) != $cont)) {
file_put_contents($output_file, $cont);
echo "Generated $output_file\n";
}
touch($output_file, filemtime($input_file));
}
function trim_tag_contents($input_file, $tag) {
$xxx = file_get_contents($input_file);
$xxx_orig = $xxx;
while (preg_match('@(<'.$tag.'[^>]*>)\s@ismU', $xxx)) {
$xxx = preg_replace('@(<'.$tag.'[^>]*>)\s@ismU', '\\1', $xxx);
}
while (preg_match('@\s(</'.$tag.'>)@ismU', $xxx)) {
$xxx = preg_replace('@\s(</'.$tag.'>)@ismU', '\\1', $xxx);
}
if ($xxx_orig != $xxx) {
file_put_contents($input_file, $xxx);
}
}