old-extract-schema.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #!/usr/bin/php
  2. <?php
  3. chdir(dirname(__FILE__));
  4. require_once 'common.php';
  5. assertCli();
  6. echo "Please do not run this script. It is here for historical purposes only.";
  7. exit;
  8. /**
  9. * @file
  10. * Extracts all definitions inside a configuration schema
  11. * (HTMLPurifier_ConfigSchema) and exports them as plain text files.
  12. *
  13. * @todo Extract version numbers.
  14. */
  15. define('HTMLPURIFIER_SCHEMA_STRICT', true); // description data needs to be collected
  16. require_once dirname(__FILE__) . '/../library/HTMLPurifier.auto.php';
  17. // We need includes to ensure all HTMLPurifier_ConfigSchema calls are
  18. // performed.
  19. require_once 'HTMLPurifier.includes.php';
  20. // Also, these extra files will be necessary.
  21. require_once 'HTMLPurifier/Filter/ExtractStyleBlocks.php';
  22. /**
  23. * Takes a hash and saves its contents to library/HTMLPurifier/ConfigSchema/
  24. */
  25. function saveHash($hash) {
  26. if ($hash === false) return;
  27. $dir = realpath(dirname(__FILE__) . '/../library/HTMLPurifier/ConfigSchema');
  28. $name = $hash['ID'] . '.txt';
  29. $file = $dir . '/' . $name;
  30. if (file_exists($file)) {
  31. trigger_error("File already exists; skipped $name");
  32. return;
  33. }
  34. $file = new FSTools_File($file);
  35. $file->open('w');
  36. $multiline = false;
  37. foreach ($hash as $key => $value) {
  38. $multiline = $multiline || (strpos($value, "\n") !== false);
  39. if ($multiline) {
  40. $file->put("--$key--" . PHP_EOL);
  41. $file->put(str_replace("\n", PHP_EOL, $value) . PHP_EOL);
  42. } else {
  43. if ($key == 'ID') {
  44. $file->put("$value" . PHP_EOL);
  45. } else {
  46. $file->put("$key: $value" . PHP_EOL);
  47. }
  48. }
  49. }
  50. $file->close();
  51. }
  52. $schema = HTMLPurifier_ConfigSchema::instance();
  53. $adapter = new HTMLPurifier_ConfigSchema_StringHashReverseAdapter($schema);
  54. foreach ($schema->info as $ns => $ns_array) {
  55. saveHash($adapter->get($ns));
  56. foreach ($ns_array as $dir => $x) {
  57. saveHash($adapter->get($ns, $dir));
  58. }
  59. }
  60. // vim: et sw=4 sts=4