index.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. /*
  3. * Copyright (C) 2014 Jeroen De Meerleer <me@jeroened.be>
  4. *
  5. * This program is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. // define location of your library
  19. //define('PATH_LIBRARY', dirname(__FILE__) . "/spoon");
  20. error_reporting(E_ALL);
  21. ini_set('display_errors', '1');
  22. // add this to the include path
  23. //set_include_path(get_include_path() . PATH_SEPARATOR . PATH_LIBRARY);
  24. // Initialize framework
  25. require_once 'spoon/spoon.php';
  26. // Add required shizzle
  27. require_once "config.php";
  28. require_once "controller.class.php";
  29. require_once "controllers.php";
  30. require_once "models.php";
  31. require_once "dbcon.php";
  32. // Let's hit the road
  33. $site = new init();
  34. class init {
  35. public $working_dir;
  36. public $controller = "pageClass";
  37. public $method = "index";
  38. public $id = "0";
  39. public
  40. function __construct() {
  41. $this->working_dir = $this->get_working_directory();
  42. $this->controller = $this->get_controller();
  43. $this->method = $this->get_method();
  44. $this->id = $this->get_id();
  45. // Hit that monster
  46. $monster = new $this->controller();
  47. $monster->controller = $this->controller;
  48. $monster->method = $this->method;
  49. $monster->id = $this->id;
  50. $monster->{
  51. $this->method}
  52. ();
  53. }
  54. public
  55. function get_controller() {
  56. $query_array = explode('/', $_SERVER['REQUEST_URI']);
  57. $controller = (!empty($query_array[1])) ? $query_array[1] :
  58. "page";
  59. $r_value = $controller . "Class";
  60. return $r_value;
  61. }
  62. public
  63. function get_method() {
  64. $query = explode('?', $_SERVER['REQUEST_URI']);
  65. $query_array = explode('/', $query[0]);
  66. $r_value = (!empty($query_array[2])) ? $query_array[2] :
  67. "index";
  68. return $r_value;
  69. }
  70. public
  71. function get_id() {
  72. $query_array = explode('/', $_SERVER['REQUEST_URI']);
  73. $r_value = (!empty($query_array[3])) ? $query_array[3] :
  74. -1;
  75. return $r_value;
  76. }
  77. public
  78. function get_working_directory() {
  79. $value_r = explode('/', $_SERVER['REQUEST_URI']);
  80. unset($value_r[count($value_r)-1]);
  81. $r_value = implode('/', $value_r);
  82. return $r_value . '/';
  83. }
  84. }