In this repo i store all my websites, each in a different branch
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

101 lines
2.7 KiB

  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: mhaaz
  5. * Date: 11/24/2017
  6. * Time: 10:50 AM
  7. */
  8. require 'vendor/autoload.php';
  9. require 'include/functions.php';
  10. $config = [
  11. 'settings' => [
  12. 'displayErrorDetails' => true,
  13. ],
  14. ];
  15. $app = new Slim\App($config);
  16. // Fetch DI Container
  17. $container = $app->getContainer();
  18. // Register Twig View helper
  19. $container['view'] = function ($c) {
  20. $view = new \Slim\Views\Twig('include/views', [
  21. //'cache' => 'include/cache'
  22. ]);
  23. // Instantiate and add Slim specific extension
  24. $basePath = rtrim(str_ireplace('index.php', '', $c['request']->getUri()->getBasePath()), '/');
  25. $view->addExtension(new \Slim\Views\TwigExtension($c['router'], $basePath));
  26. return $view;
  27. };
  28. //Override the default Not Found Handler
  29. $container['notFoundHandler'] = function ($c) {
  30. return function ($request, $response) use ($c) {
  31. return $c['view']->render($response->withStatus(404), '404.html', [
  32. "myMagic" => "Let's roll"
  33. ]);
  34. };
  35. };
  36. $app->get('/', function ($request, $response, $args){
  37. $page = 1;
  38. $page = $page ? (int)$page : 1;
  39. $posts = find_posts($page);
  40. $pagination = has_pagination($page);
  41. $random = random_posts();
  42. return $this->view->render($response, 'index.new.html', [
  43. 'posts' => $posts,
  44. 'pagination' => $pagination,
  45. 'page' => $page,
  46. 'random'=> $random
  47. ]);
  48. //return $response->write(print_r($pageination,true));
  49. });
  50. $app->get('/page=[{page:[0-9]+}]', function ($request, $response, $args){
  51. if($args['page'] != 1){
  52. $page = $args['page'];
  53. }else{
  54. return $response->withRedirect('/');
  55. }
  56. $page = $page ? (int)$page : 1;
  57. $posts = find_posts($page);
  58. if(empty($posts)){
  59. return $this->view->render($response->withStatus(404), "404.html");
  60. }
  61. $pagination = has_pagination($page);
  62. $random = random_posts();
  63. return $this->view->render($response, 'index.new.html', [
  64. 'posts' => $posts,
  65. 'pagination' => $pagination,
  66. 'page' => $page,
  67. 'random'=> $random
  68. ]);
  69. //return $response->write(print_r($pageination,true));
  70. });
  71. $app->get('/{year:[0-9]{4}+}/{month:[0-9]{2}+}/{name}', function ($request, $response, $args){
  72. $post = find_post($args['year'],$args['month'],$args['name']);
  73. $random = random_posts();
  74. if(empty($post)){
  75. return $this->view->render($response->withStatus(404), "404.html");
  76. }
  77. return $this->view->render($response, 'post.new.html', [
  78. 'post' => $post,
  79. 'random'=> $random
  80. ]);
  81. });
  82. $app->run();