memcache_ui.php 1.8 KB

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