/library/SHARED.php
PHP | 174 lines | 90 code | 40 blank | 44 comment | 11 complexity | 370685a30217fcf400e6aa744941c7ed MD5 | raw file
- <?php
- /**
- * functions for the MVC
- *
- * @author Jason Torgrimson
- * @copyright Advanced Technology Solutions, Inc..
- * @since July 01, 2010
- * @package SchoolSite
- */
-
-
- /**
- * Check if environment is development and display errors
- */
- function setReporting(){
- if (DEVELOPMENT_ENVIRONMENT == true){
- error_reporting(E_ALL);
- ini_set('display_errors','On');
- }else{
- error_reporting(E_ALL);
- ini_set('display_errors','Off');
- ini_set('log_errors', 'On');
- ini_set('error_log', ROOT_PATH . '/config/logs/error.log');
- }
- }
-
-
- /**
- * Check for Magic Quotes and remove them
- */
- function stripSlashesDeep($value){
- $value = is_array($value) ? array_map('stripSlashesDeep', $value) : stripslashes($value);
- return $value;
- }
-
-
- /**
- * Check for Magic Quotes and remove them
- */
- function removeMagicQuotes(){
- if(get_magic_quotes_gpc()){
- $_GET = stripSlashesDeep($_GET );
- $_POST = stripSlashesDeep($_POST );
- $_COOKIE = stripSlashesDeep($_COOKIE);
- }
- }
-
-
- /**
- * Check register globals and remove them
- */
- function unregisterGlobals(){
- if (ini_get('register_globals')) {
- $array = array('_SESSION', '_POST', '_GET', '_COOKIE', '_REQUEST', '_SERVER', '_ENV', '_FILES');
- foreach ($array as $value) {
- foreach ($GLOBALS[$value] as $key => $var) {
- if ($var === $GLOBALS[$key]) {
- unset($GLOBALS[$key]);
- }
- }
- }
- }
- }
-
-
- /**
- * Main Call Function for MVC
- */
- function callHook(){
- global $url;
-
- // place url in array
- $urlArray = array();
- $urlArray = explode("/",$url);
-
- // get controller and action if they exsist in URL
- if(count($urlArray) > 0 &&
- $urlArray[0] != ''){
-
- $controller = array_shift($urlArray);
-
- if(count($urlArray) > 0 &&
- $urlArray[0] != ''){
- $action = array_shift($urlArray);
- }else{
- $action = 'index';
- }
- }else{
- $controller = 'index';
- $action = 'index';
- }
-
- // save the left over array as query stream
- $queryString = $urlArray;
-
- $controllerName = $controller;
- $controller = ucwords($controller);
- $model = rtrim($controller, 's');
- $controller .= 'Controller';
- $dispatch = new $controller($model,$controllerName,$action);
-
- if((int)method_exists($controller, $action)){
- call_user_func_array(array($dispatch,$action),$queryString);
- }else{
- /* Error Generation Code Here */
- }
- }
-
-
- /**
- * Autoload any classes that are required
- *
- * @param string $className The class name that the autoloader automatically tries to load
- */
- function __autoload($className) {
- if(file_exists(ROOT_PATH . '/library/' . strtoupper($className) . '.php')){
- require_once(ROOT_PATH . '/library/' . strtoupper($className) . '.php');
-
- }elseif(file_exists(ROOT_PATH . '/library/' . strtolower($className) . '.php')){
- require_once(ROOT_PATH . '/library/' . strtolower($className) . '.php');
-
- }elseif(file_exists(ROOT_PATH . '/application/controllers/' . strtolower($className) . '.php')){
- require_once(ROOT_PATH . '/application/controllers/' . strtolower($className) . '.php');
-
- }elseif(file_exists(ROOT_PATH . '/application/models/' . strtolower($className) . '.php')){
- require_once(ROOT_PATH . '/application/models/' . strtolower($className) . '.php');
-
- }else{
- /* Error Generation Code Here */
- }
- }
-
- // prepare system for launch
- setReporting();
- removeMagicQuotes();
- unregisterGlobals();
-
- // create variable registry
- $registry = array();
- // get pointer to db and configure it
- $registry['db'] = new db;
- $registry['db']->database_driver(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
-
- // get pointer for data validation
- $registry['data_validation'] = new data_validation;
-
- // get pointer for misc functions object
- $registry['functions'] = new functions;
-
- // get pointer for auth
- $registry['auth'] = new authentication;
-
- // get pointer for file management
- $registry['file_management'] = new file_management;
-
- // get pointer for module
- $registry['module'] = new module;
-
- // get pointer for navigation
- $registry['navigation'] = new navigation;
-
- // get pointer for security image
- $registry['security_image'] = new security_image;
-
-
-
-
-
-
- // launch mvc
- callHook();
-
-
- ?>