generate.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. /**
  3. * Generates XML and HTML documents describing configuration.
  4. * @note PHP 5.2+ only!
  5. */
  6. /*
  7. TODO:
  8. - make XML format richer
  9. - extend XSLT transformation (see the corresponding XSLT file)
  10. - allow generation of packaged docs that can be easily moved
  11. - multipage documentation
  12. - determine how to multilingualize
  13. - add blurbs to ToC
  14. */
  15. if (version_compare(PHP_VERSION, '5.2', '<')) exit('PHP 5.2+ required.');
  16. error_reporting(E_ALL | E_STRICT);
  17. chdir(dirname(__FILE__));
  18. // load dual-libraries
  19. require_once '../extras/HTMLPurifierExtras.auto.php';
  20. require_once '../library/HTMLPurifier.auto.php';
  21. // setup HTML Purifier singleton
  22. HTMLPurifier::getInstance(array(
  23. 'AutoFormat.PurifierLinkify' => true
  24. ));
  25. $interchange = HTMLPurifier_ConfigSchema_InterchangeBuilder::buildFromDirectory();
  26. $interchange->validate();
  27. $style = 'plain'; // use $_GET in the future, careful to validate!
  28. $configdoc_xml = 'configdoc.xml';
  29. $xml_builder = new HTMLPurifier_ConfigSchema_Builder_Xml();
  30. $xml_builder->openURI($configdoc_xml);
  31. $xml_builder->build($interchange);
  32. unset($xml_builder); // free handle
  33. $xslt = new ConfigDoc_HTMLXSLTProcessor();
  34. $xslt->importStylesheet(dirname(__FILE__) . "/styles/$style.xsl");
  35. $output = $xslt->transformToHTML($configdoc_xml);
  36. if (!$output) {
  37. echo "Error in generating files\n";
  38. exit(1);
  39. }
  40. // write out
  41. file_put_contents("$style.html", $output);
  42. if (php_sapi_name() != 'cli') {
  43. // output (instant feedback if it's a browser)
  44. echo $output;
  45. } else {
  46. echo 'Files generated successfully.';
  47. }
  48. // vim: et sw=4 sts=4