index.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. exec("find tmp -mmin +4 | sed 's/\s/\\&/g' | xargs rm -rf");
  3. exec("mkdir tmp");
  4. // awkward command to clear files older then 4 minutes from tmp
  5. use App\Controllers\HomeController;
  6. use App\Controller;
  7. //use App\Models\HomeModel;
  8. $error_reporting = 1; // 1 = errors 0 = none
  9. if ($error_reporting == 1){
  10. ini_set('display_errors', 1);
  11. ini_set('display_startup_errors', 1);
  12. error_reporting(E_ALL);}
  13. session_start();
  14. $_SESSION["messages"] = null;
  15. if (array_key_exists("messages", $_COOKIE)) {
  16. }
  17. else{
  18. $_COOKIE["messages"] = null;
  19. }
  20. require(__DIR__ . "/../vendor/autoload.php");
  21. global $config;
  22. $config = parse_ini_file(__DIR__ . "/../config/config.php");
  23. $loader = new Twig_Loader_Filesystem(__DIR__ . "/../views/");
  24. $twig = new Twig_Environment($loader);
  25. $twig->addGlobal('config', $config);
  26. require(__DIR__ . "/../app/View.php");
  27. $router = new AltoRouter();
  28. $router->setBasePath('');
  29. $router->map('GET','/', "App\Controllers\HomeController#index", 'home');
  30. $router->map('GET|POST','/upload', "App\Controllers\HomeController#upload", 'upload');
  31. $router->map('GET|POST','/print', "App\Controllers\HomeController#print", 'print');
  32. $match = $router->match();
  33. list( $controller, $action ) = explode( '#', $match['target'] );
  34. if ( is_callable(array($controller, $action)) ) {
  35. $obj = new $controller($twig);
  36. call_user_func_array(array($obj,$action), array($match['params']));
  37. } else if ($match['target']==''){
  38. echo 'Error: no route was matched';
  39. //possibly throw a 404 error
  40. } else {
  41. echo 'Error: can not call '.$controller.'#'.$action;
  42. //possibly throw a 404 error
  43. }