PageRenderTime 24ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/application/library/shared.php

https://gitlab.com/klausmig/CloudSemanticWeb
PHP | 111 lines | 88 code | 13 blank | 10 comment | 16 complexity | 3422d4d86ae99f8e23faf4f9becd0f28 MD5 | raw file
  1. <?php
  2. require_once(ROOT . DS . 'application' . DS . 'library' . DS . 'controller.class.php');
  3. require_once(ROOT . DS . 'application' . DS . 'library' . DS . 'SQLQuery.class.php');
  4. require_once(ROOT . DS . 'application' . DS . 'library' . DS . 'model.class.php');
  5. require_once(ROOT . DS . 'application' . DS . 'models' . DS . 'User.php');
  6. require_once(ROOT . DS . 'application' . DS . 'models' . DS . 'Slide.php');
  7. require_once(ROOT . DS . 'application' . DS . 'models' . DS . 'DeckList.php');
  8. require_once(ROOT . DS . 'application' . DS . 'models' . DS . 'Deck.php');
  9. require_once(ROOT . DS . 'application' . DS . 'models' . DS . 'Stream.php');
  10. require_once(ROOT . DS . 'application' . DS . 'models' . DS . 'Statistics.php');
  11. require_once(ROOT . DS . 'application' . DS . 'models' . DS . 'Style.php');
  12. require_once(ROOT . DS . 'application' . DS . 'models' . DS . 'Transition.php');
  13. require_once(ROOT . DS . 'application' . DS . 'models' . DS . 'Question.php');
  14. /** Check if environment is development and display errors **/
  15. function setReporting() {
  16. if (DEVELOPMENT_ENVIRONMENT == true) {
  17. error_reporting(E_ALL);
  18. ini_set('display_errors','On');
  19. } else {
  20. error_reporting(E_ALL);
  21. ini_set('display_errors','Off');
  22. ini_set('log_errors', 'On');
  23. ini_set('error_log', ROOT.DS.'tmp'.DS.'logs'.DS.'error.log');
  24. }
  25. }
  26. /** Check for Magic Quotes and remove them **/
  27. function stripSlashesDeep($value) {
  28. $value = is_array($value) ? array_map('stripSlashesDeep', $value) : stripslashes($value);
  29. return $value;
  30. }
  31. function removeMagicQuotes() {
  32. if ( get_magic_quotes_gpc() ) {
  33. $_GET = stripSlashesDeep($_GET );
  34. $_POST = stripSlashesDeep($_POST );
  35. $_COOKIE = stripSlashesDeep($_COOKIE);
  36. }
  37. }
  38. /** Check register globals and remove them **/
  39. function unregisterGlobals() {
  40. if (ini_get('register_globals')) {
  41. $array = array('_SESSION', '_POST', '_GET', '_COOKIE', '_REQUEST', '_SERVER', '_ENV', '_FILES');
  42. foreach ($array as $value) {
  43. foreach ($GLOBALS[$value] as $key => $var) {
  44. if ($var === $GLOBALS[$key]) {
  45. unset($GLOBALS[$key]);
  46. }
  47. }
  48. }
  49. }
  50. }
  51. /** Main Call Function **/
  52. function callHook() {
  53. global $url;
  54. //print_r("<span>" . $url . "</span>");
  55. $urlArray = array();
  56. $urlArray = explode("/",$url);
  57. $controller = $urlArray[0];
  58. //print_r($controller);
  59. array_shift($urlArray);
  60. $action = $urlArray[0];
  61. array_shift($urlArray);
  62. $queryString = $urlArray;
  63. $controllerName = $controller;
  64. $controller = ucwords($controller);
  65. $model = rtrim($controller, 's');
  66. $controller .= 'Controller';
  67. __autoload($controller);
  68. $dispatch = new $controller($model,$controllerName,$action);
  69. if ((int)method_exists($controller, $action)) {
  70. call_user_func_array(array($dispatch,$action),$queryString);
  71. } else {
  72. /* TODO: Error Generation Code Here */
  73. }
  74. }
  75. /** Autoload any classes that are required **/
  76. function __autoload($className) {
  77. if (file_exists(ROOT . DS . 'application' . DS . 'library' . DS . $className . '.class.php')) {
  78. require_once(ROOT . DS . 'application' . DS . 'library' . DS . $className . '.class.php');
  79. } else if (file_exists(ROOT . DS . 'application' . DS . 'controllers' . DS . $className . '.php')) {
  80. require_once(ROOT . DS . 'application' . DS . 'controllers' . DS . $className . '.php');
  81. } else if (file_exists(ROOT . DS . 'application' . DS . 'models' . DS . $className . '.php')) {
  82. require_once(ROOT . DS . 'application' . DS . 'models' . DS . $className . '.php');
  83. } else {
  84. if ($className != strtolower($className))
  85. {
  86. __autoload(strtolower($className));
  87. }
  88. else
  89. {
  90. /* Error Generation Code Here */
  91. }
  92. }
  93. }
  94. // basic stuff here
  95. setReporting();
  96. removeMagicQuotes();
  97. unregisterGlobals();
  98. callHook();