generate.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. $builder = new HTMLPurifier_ConfigSchema_InterchangeBuilder();
  26. $interchange = new HTMLPurifier_ConfigSchema_Interchange();
  27. $builder->buildDir($interchange);
  28. $loader = dirname(__FILE__) . '/../config-schema.php';
  29. if (file_exists($loader)) include $loader;
  30. $interchange->validate();
  31. $style = 'plain'; // use $_GET in the future, careful to validate!
  32. $configdoc_xml = 'configdoc.xml';
  33. $xml_builder = new HTMLPurifier_ConfigSchema_Builder_Xml();
  34. $xml_builder->openURI($configdoc_xml);
  35. $xml_builder->build($interchange);
  36. unset($xml_builder); // free handle
  37. $xslt = new ConfigDoc_HTMLXSLTProcessor();
  38. $xslt->importStylesheet(dirname(__FILE__) . "/styles/$style.xsl");
  39. $output = $xslt->transformToHTML($configdoc_xml);
  40. if (!$output) {
  41. echo "Error in generating files\n";
  42. exit(1);
  43. }
  44. // write out
  45. file_put_contents("$style.html", $output);
  46. if (php_sapi_name() != 'cli') {
  47. // output (instant feedback if it's a browser)
  48. echo $output;
  49. } else {
  50. echo 'Files generated successfully.';
  51. }