memcache_ui.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. *
  12. * Recommended:
  13. * - intl extension
  14. * - on Ubuntu 11.04, this implies removing libidn, libsimplepie, and
  15. * dokuwiki, among others
  16. * - tidy extension
  17. */
  18. namespace Memcache_UI {
  19. /**
  20. * Wrapper around php tidy class.
  21. *
  22. * @param string $html
  23. *
  24. * @return void
  25. */
  26. function applyTidy (&$html) {
  27. $config = array(
  28. 'indent' => TRUE,
  29. 'output-xhtml' => TRUE,
  30. 'sort-attributes' => 'alpha',
  31. 'wrap' => 200,
  32. );
  33. $tidy = new \tidy();
  34. $tidy->parseString($html, $config, 'utf8');
  35. $tidy->cleanRepair();
  36. $html = (string) $tidy;
  37. }
  38. function main() {
  39. try {
  40. ob_start();
  41. //echo '<pre>';
  42. // Set-up autoloader: it cannot autoload itself.
  43. $package = 'Memcache_UI';
  44. require "$package/Core/Autoloader.inc";
  45. $classLoader = new \SplClassLoader($package, dirname(__FILE__));
  46. $classLoader->setFileExtension('.inc');
  47. $classLoader->register();
  48. // Set up the context
  49. $context = new Core\Context();
  50. $context->setMessage("Dirname: [". $context->getBase() . "]", LOG_DEBUG);
  51. $context->setMessage("Path: [". $context->getPath() . "]", LOG_DEBUG);
  52. // Obtain the routing information
  53. $router = new Core\Router($context);
  54. $item = $router->getRoute();
  55. $page = new $item['page class']($context, $item);
  56. $page->emitHeaders();
  57. echo $page;
  58. $html = ob_get_clean();
  59. // Filter it on output
  60. if ($context->getTidy()) {
  61. applyTidy($html);
  62. }
  63. echo $html;
  64. }
  65. catch (Exception $e) {
  66. echo '<pre>';
  67. echo $e->getMessage() . PHP_EOL;
  68. echo $e->getTraceAsString();
  69. echo "</pre>";
  70. }
  71. }
  72. main();
  73. }