PageRenderTime 51ms CodeModel.GetById 27ms RepoModel.GetById 0ms app.codeStats 0ms

/library/shared.php

https://github.com/macro-solutions/mudis-nyca
PHP | 91 lines | 58 code | 15 blank | 18 comment | 8 complexity | 7724979062cbfb4cca81bbe61f9535e4 MD5 | raw file
  1. <?php
  2. /** Check if environment is development and display errors **/
  3. function setReporting() {
  4. if (DEVELOPMENT_ENVIRONMENT == true) {
  5. error_reporting(E_ALL);
  6. ini_set('display_errors','On');
  7. } else {
  8. error_reporting(E_ALL);
  9. ini_set('display_errors','Off');
  10. ini_set('log_errors', 'On');
  11. ini_set('error_log', ROOT.DS.'tmp'.DS.'logs'.DS.'error.log');
  12. }
  13. }
  14. /** Check for Magic Quotes and remove them **/
  15. function stripSlashesDeep($value) {
  16. $value = is_array($value) ? array_map('stripSlashesDeep', $value) : stripslashes($value);
  17. return $value;
  18. }
  19. function removeMagicQuotes() {
  20. if ( get_magic_quotes_gpc() ) {
  21. $_GET = stripSlashesDeep($_GET );
  22. $_POST = stripSlashesDeep($_POST );
  23. $_COOKIE = stripSlashesDeep($_COOKIE);
  24. }
  25. }
  26. /** Check register globals and remove them **/
  27. function unregisterGlobals() {
  28. if (ini_get('register_globals')) {
  29. $array = array('_SESSION', '_POST', '_GET', '_COOKIE', '_REQUEST', '_SERVER', '_ENV', '_FILES');
  30. foreach ($array as $value) {
  31. foreach ($GLOBALS[$value] as $key => $var) {
  32. if ($var === $GLOBALS[$key]) {
  33. unset($GLOBALS[$key]);
  34. }
  35. }
  36. }
  37. }
  38. }
  39. /** Main Call Function **/
  40. function callHook() {
  41. global $url;
  42. $urlArray = array();
  43. $urlArray = explode("/",$url);
  44. $controller = $urlArray[0];
  45. array_shift($urlArray);
  46. $action = $urlArray[0];
  47. array_shift($urlArray);
  48. $queryString = $urlArray;
  49. $controllerName = $controller;
  50. $controller = ucwords($controller);
  51. $model = $controller;
  52. $controller .= 'Controller';
  53. $dispatch = new $controller($model,$controllerName,$action);
  54. if ((int)method_exists($controller, $action)) {
  55. call_user_func_array(array($dispatch,$action),$queryString);
  56. } else {
  57. /* Error Generation Code Here */
  58. }
  59. }
  60. /** Autoload any classes that are required **/
  61. // function __autoload($className) {
  62. // if (file_exists(ROOT . DS . 'library' . DS . strtolower($className) . '.class.php')) {
  63. // echo ROOT . DS . 'library' . DS . strtolower($className) . '.class.php<br/>';
  64. // require_once(ROOT . DS . 'library' . DS . strtolower($className) . '.class.php');
  65. // } else if (file_exists(ROOT . DS . 'application' . DS . 'controllers' . DS . strtolower($className) . '.php')) {
  66. // require_once(ROOT . DS . 'application' . DS . 'controllers' . DS . strtolower($className) . '.php');
  67. // } else if (file_exists(ROOT . DS . 'application' . DS . 'models' . DS . strtolower($className) . '.php')) {
  68. // require_once(ROOT . DS . 'application' . DS . 'models' . DS . strtolower($className) . '.php');
  69. // } else {
  70. // /* Error Generation Code Here */
  71. // }
  72. // }
  73. setReporting();
  74. removeMagicQuotes();
  75. unregisterGlobals();
  76. callHook();