memcache_ui.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. namespace Memcache_UI {
  3. /**
  4. * Wrapper around php tidy class.
  5. *
  6. * @param string $html
  7. *
  8. * @return void
  9. */
  10. function applyTidy (&$html) {
  11. $config = array(
  12. 'indent' => TRUE,
  13. 'output-xhtml' => TRUE,
  14. 'sort-attributes' => 'alpha',
  15. 'wrap' => 200,
  16. );
  17. $tidy = new tidy();
  18. $tidy->parseString($html, $config, 'utf8');
  19. $tidy->cleanRepair();
  20. $html = (string) $tidy;
  21. }
  22. function main() {
  23. try {
  24. ob_start();
  25. //echo '<pre>';
  26. // Set-up autoloader: it cannot autoload itself.
  27. $package = 'Memcache_UI';
  28. require "$package/Core/Autoloader.inc";
  29. $classLoader = new \SplClassLoader($package, dirname(__FILE__));
  30. $classLoader->setFileExtension('.inc');
  31. $classLoader->register();
  32. // Set up the context
  33. $context = new Core\Context();
  34. $context->setMessage("Dirname: [". $context->getBase() . "]", LOG_DEBUG);
  35. $context->setMessage("Path: [". $context->getPath() . "]", LOG_DEBUG);
  36. // Obtain the routing information
  37. $router = new Core\Router($context);
  38. $item = $router->getRoute();
  39. $page = new $item['page class']($context, $item);
  40. $page->emitHeaders();
  41. echo $page;
  42. $html = ob_get_clean();
  43. // Filter it on output
  44. if ($context->getTidy()) {
  45. applyTidy($html);
  46. }
  47. echo $html;
  48. }
  49. catch (Exception $e) {
  50. echo '<pre>';
  51. echo $e->getMessage() . PHP_EOL;
  52. echo $e->getTraceAsString();
  53. echo "</pre>";
  54. }
  55. }
  56. main();
  57. }