1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- <?php
- /**
- * Memcache User Interface. Main file.
- *
- * @author Frederic G. MARAND <fgm@osinet.fr>
- *
- * @copyright (c) 2011 Frederic G. MARAND
- *
- * Requirements:
- * - PHP >= 5.3
- * - intl extension
- *
- * Recommended:
- * - tidy extension
- */
- namespace Memcache_UI {
- /**
- * Wrapper around php tidy class.
- *
- * @param string $html
- *
- * @return void
- */
- function applyTidy (&$html) {
- $config = array(
- 'indent' => TRUE,
- 'output-xhtml' => TRUE,
- 'sort-attributes' => 'alpha',
- 'wrap' => 200,
- );
- $tidy = new \tidy();
- $tidy->parseString($html, $config, 'utf8');
- $tidy->cleanRepair();
- $html = (string) $tidy;
- }
- function main() {
- try {
- ob_start();
- //echo '<pre>';
- // Set-up autoloader: it cannot autoload itself.
- $package = 'Memcache_UI';
- require "$package/Core/Autoloader.inc";
- $classLoader = new \SplClassLoader($package, dirname(__FILE__));
- $classLoader->setFileExtension('.inc');
- $classLoader->register();
- // Set up the context
- $context = new Core\Context();
- $context->setMessage("Dirname: [". $context->getBase() . "]", LOG_DEBUG);
- $context->setMessage("Path: [". $context->getPath() . "]", LOG_DEBUG);
- // Obtain the routing information
- $router = new Core\Router($context);
- $item = $router->getRoute();
- $page = new $item['page class']($context, $item);
- $page->emitHeaders();
- echo $page;
- $html = ob_get_clean();
- // Filter it on output
- if ($context->getTidy()) {
- applyTidy($html);
- }
- echo $html;
- }
- catch (Exception $e) {
- echo '<pre>';
- echo $e->getMessage() . PHP_EOL;
- echo $e->getTraceAsString();
- echo "</pre>";
- }
- }
- main();
- }
|