diff --git a/src/Controllers/BaseController.php b/src/Controllers/BaseController.php deleted file mode 100755 index ee544ad..0000000 --- a/src/Controllers/BaseController.php +++ /dev/null @@ -1,129 +0,0 @@ -load = $this; - - require_once "Handler.php"; - global $loadedModules; - - $handler = new Handler( $loadedModules, array()); - $modelName = $handler->checkModuleLoaded( ); - if( in_array($modelName, $loadedModules)){ - $modelPath = $handler->getLoadedBasePath( ); - include_once ($modelPath.'Config/app.php'); - } - } - - public function model( $model = null){ - if( empty( $model )){ - $trace = debug_backtrace(); - $model = substr( $trace[0]['class'],0,-10); - if( isset($trace[1])){ - $model = substr( $trace[1]['class'],0,-10); - } - //return debug_backtrace(); - } - //check if model class exists actually - require_once "Handler.php"; - global $loadedModules; - - $handler = new Handler( $loadedModules, array()); - $modelFolder = $handler->getLoadedBasePath( ); - - if($modelFolder=='') $modelFolder = APPNAME.'/Models/'; - else $modelFolder = $modelFolder.'/Models/'; - - if( file_exists( $modelFolder.$model.'.php')){ - require_once $modelFolder.$model.'.php'; - return new $model; - } else{ - $this->handleError('missing_model','Model class '.$model.' not found in '.$modelFolder.$model.'.php'); - } - - } - - public function _view( $view = null){ - $trace = debug_backtrace(); //_pr($trace,1); - if( empty( $view )){ - if( isset($trace[1])){ - $view = $trace[1]['function']; - $viewFolder = substr($trace[1]['class'],0,-10); - $mainObjLayOutTheme = (array)$trace[1]['object']; - } else{ - $view = $trace[0]['function']; - $viewFolder = substr($trace[0]['class'],0,-10); - $mainObjLayOutTheme = (array)$trace[0]['object']; - } - } else{ - if( isset($trace[1])){ - $viewFolder = substr($trace[1]['class'],0,-10); - $mainObjLayOutTheme = (array)$trace[1]['object']; - } else{ - $viewFolder = substr($trace[0]['class'],0,-10); - $mainObjLayOutTheme = (array)$trace[0]['object']; - } - } - //check if view class exists actually - require_once "Handler.php"; - global $loadedModules; - - $handler = new Handler( $loadedModules, array()); - $viewFolderReal = $handler->getLoadedBasePath( ); - if($viewFolderReal=='') $viewFolderReal = APPNAME.'/Views/'; - else $viewFolderReal = $viewFolderReal.'/Views/'; - - if( file_exists( $viewFolderReal.$viewFolder.'/'.$view.'.php')){ - foreach( $this->container as $key=>$val ){ - $$key = $val; - } //_pr($mainObjLayOutTheme);exit; - $oldContent = ob_get_clean(); - ob_start(); - $pageTitle1 = empty($mainObjLayOutTheme['pageTitle']) ? '' : $mainObjLayOutTheme['pageTitle']; - include ( $viewFolderReal.$viewFolder.'/'.$view.'.php'); - $bodyContent = ob_get_clean(); - //now we need to load this content inside our theme's layout file - //theme and layout may be defined in place - //1. calling function - //2. calling function's controller - //3. calling functions' controller's parent class and so on... - $loadTheme = empty($mainObjLayOutTheme['theme']) ? 'default' : $mainObjLayOutTheme['theme']; - $loadLayOut = empty($mainObjLayOutTheme['layout']) ? 'default' : $mainObjLayOutTheme['layout']; - ///now load template and themes - ob_start(); - include ( APPNAME.'/Themes/'.$loadTheme.'/'.$loadLayOut.'.php'); - $themeNlayOut = ob_get_clean(); - echo $themeNlayOut;exit; - } else{ - $this->handleError('missing_view','view class '.$view.' not found in '.$viewFolderReal.$viewFolder.'/'.$view.'.php'); - } - } - - public function handleError( $error_type, $msg ) - { - ob_start(); - if( ERROR_LEVEL == 'development' ){ - $bodyContent = $msg; - } - $loadTheme = empty($mainObjLayOutTheme['theme']) ? 'default' : $mainObjLayOutTheme['theme']; - include ( APPNAME.'/Themes/'.$loadTheme.'/404.php'); - $themeNlayOut = ob_get_clean(); - echo $themeNlayOut; - header("HTTP/1.0 404 Not Found"); - exit; - } - - public function load( ){ - //$trace = debug_backtrace(); _pr($trace); - } - - public function set( $var, $data=null){ - $this->container[$var] = $data; - } - -} \ No newline at end of file diff --git a/src/Core/Cruzer.php b/src/Core/Cruzer.php index 27218e3..1522ba2 100644 --- a/src/Core/Cruzer.php +++ b/src/Core/Cruzer.php @@ -1,640 +1,726 @@ - * @since v 1.0.0 + * Basic functions for Cruzer Framework + * @author RN Kushwaha + * @since v 1.0.0 */ - public static function humanTiming ($time, $reseverse = false ) { - if( $reseverse === true ){ - $time = strtotime($time) - time(); - } else{ - $time = time() - strtotime($time); - } +if( !function_exists('humanTiming')){ + function humanTiming ($time, $reseverse = false ) { + if( $reseverse === true ){ + $time = strtotime($time) - time(); + } else{ + $time = time() - strtotime($time); + } - $time = ($time<1)? 1 : $time; - $tokens = array ( - 31536000 => 'year', - 2592000 => 'month', - 604800 => 'week', - 86400 => 'day', - 3600 => 'hour', - 60 => 'minute', - 1 => 'second' - ); + $time = ($time<1)? 1 : $time; + $tokens = array ( + 31536000 => 'year', + 2592000 => 'month', + 604800 => 'week', + 86400 => 'day', + 3600 => 'hour', + 60 => 'minute', + 1 => 'second' + ); + + foreach ($tokens as $unit => $text) { + if ($time < $unit) continue; + $numberOfUnits = floor($time / $unit); + return $numberOfUnits.' '.$text.(($numberOfUnits>1)?'s':''); + } + } +} - foreach ($tokens as $unit => $text) { - if ($time < $unit) continue; - $numberOfUnits = floor($time / $unit); - return $numberOfUnits.' '.$text.(($numberOfUnits>1)?'s':''); - } +if( !function_exists('_status')){ + function _status( $status, $formated = true, $statusFor='default' ){ + if( $formated === false && $statusFor == 'default' ){ + switch ($status) { + case '1': $st = 'Active'; break; + case '0': $st = 'Inactive'; break; + case '2': $st = 'Blocked'; break; + default: $st = 'Pending'; break; + } + } elseif( $formated === false && $statusFor == 'shipments' ){ + switch ($status) { + case '1': $st = 'Approved'; break; + case '2': $st = 'Available'; break; + case '3': $st = 'Cancelled'; break; + case '4': $st = 'Customs'; break; + case '5': $st = 'Delivered'; break; + case '6': $st = 'Delivered-Pending Payment'; break; + case '7': $st = 'Dispenser'; break; + case '8': $st = 'Distribution'; break; + case '9': $st = 'Earring Collection'; break; + case '10': $st = 'Effective'; break; + case '11': $st = 'In Transit'; break; + case '12': $st = 'In warehouse'; break; + case '13': $st = 'Invoiced'; break; + case '14': $st = 'On route'; break; + case '15': $st = 'Packaged'; break; + case '16': $st = 'Received Office'; break; + default: $st = 'Pending'; break; + } + } elseif( $formated === true && $statusFor == 'shipments' ){ + switch ($status) { + case '1': $st = 'Approved'; break; + case '2': $st = 'Available'; break; + case '3': $st = 'Cancelled'; break; + case '4': $st = 'Customs'; break; + case '5': $st = 'Delivered'; break; + case '6': $st = 'Delivered-Pending Payment'; break; + case '7': $st = 'Dispenser'; break; + case '8': $st = 'Distribution'; break; + case '9': $st = 'Earring Collection'; break; + case '10': $st = 'Effective'; break; + case '11': $st = 'In Transit'; break; + case '12': $st = 'In warehouse'; break; + case '13': $st = 'Invoiced'; break; + case '14': $st = 'On route'; break; + case '15': $st = 'Packaged'; break; + case '16': $st = 'Received Office'; break; + default: $st = 'Pending'; break; + } + } elseif( $formated === false && $statusFor == 'notifications' ){ + switch ($status) { + case '0': $st = 'Unread'; break; + case '1': $st = 'Viewed'; break; + default: $st = 'Pending'; break; + } + } elseif( $formated === true && $statusFor == 'notifications' ){ + switch ($status) { + case '0': $st = 'Unread'; break; + case '1': $st = 'Viewed'; break; + default: $st = 'Pending'; break; + } + } else{ + switch ($status) { + case '1': $st = 'Active'; break; + case '0': $st = 'Inactive'; break; + case '2': $st = 'Blocked'; break; + default: $st = 'Pending'; break; + } + } + + return $st; } +} - public static function _status( $status, $formated = true, $statusFor='default' ){ - if( $formated === false && $statusFor == 'default' ){ - switch ($status) { - case '1': $st = 'Active'; break; - case '0': $st = 'Inactive'; break; - case '2': $st = 'Blocked'; break; - default: $st = 'Pending'; break; - } - } elseif( $formated === false && $statusFor == 'shipments' ){ - switch ($status) { - case '1': $st = 'Approved'; break; - case '2': $st = 'Available'; break; - case '3': $st = 'Cancelled'; break; - case '4': $st = 'Customs'; break; - case '5': $st = 'Delivered'; break; - case '6': $st = 'Delivered-Pending Payment'; break; - case '7': $st = 'Dispenser'; break; - case '8': $st = 'Distribution'; break; - case '9': $st = 'Earring Collection'; break; - case '10': $st = 'Effective'; break; - case '11': $st = 'In Transit'; break; - case '12': $st = 'In warehouse'; break; - case '13': $st = 'Invoiced'; break; - case '14': $st = 'On route'; break; - case '15': $st = 'Packaged'; break; - case '16': $st = 'Received Office'; break; - default: $st = 'Pending'; break; - } - } elseif( $formated === true && $statusFor == 'shipments' ){ - switch ($status) { - case '1': $st = 'Approved'; break; - case '2': $st = 'Available'; break; - case '3': $st = 'Cancelled'; break; - case '4': $st = 'Customs'; break; - case '5': $st = 'Delivered'; break; - case '6': $st = 'Delivered-Pending Payment'; break; - case '7': $st = 'Dispenser'; break; - case '8': $st = 'Distribution'; break; - case '9': $st = 'Earring Collection'; break; - case '10': $st = 'Effective'; break; - case '11': $st = 'In Transit'; break; - case '12': $st = 'In warehouse'; break; - case '13': $st = 'Invoiced'; break; - case '14': $st = 'On route'; break; - case '15': $st = 'Packaged'; break; - case '16': $st = 'Received Office'; break; - default: $st = 'Pending'; break; - } - } elseif( $formated === false && $statusFor == 'notifications' ){ - switch ($status) { - case '0': $st = 'Unread'; break; - case '1': $st = 'Viewed'; break; - default: $st = 'Pending'; break; - } - } elseif( $formated === true && $statusFor == 'notifications' ){ - switch ($status) { - case '0': $st = 'Unread'; break; - case '1': $st = 'Viewed'; break; - default: $st = 'Pending'; break; - } - } else{ - switch ($status) { - case '1': $st = 'Active'; break; - case '0': $st = 'Inactive'; break; - case '2': $st = 'Blocked'; break; - default: $st = 'Pending'; break; - } +if( !function_exists('_formatFlightTime')){ + function _formatFlightTime( $time, $full=true ){ + $newTime1 = explode('T',$time); + if( isset($newTime1[1]) ){ + $newTime2 = str_replace('+','-', $newTime1[1]); + $newTime = explode('-', $newTime2); + if( is_array($newTime) && count($newTime)){ + if( $full === true ){ + $format['time'] = $newTime[0]; + if(isset($newTime) && count($newTime)>1 ) $format['deduction'] = $newTime[1]; + $format['date'] = $newTime1[0]; + return $format; + } else{ + return $newTime[0]; + } } + } + } +} - return $st; - } +if( !function_exists('__status')){ + function __status( $status, $formated = true, $statusFor='default' ){ + echo _status($status, $formated, $statusFor); + } +} - public static function _formatFlightTime( $time, $full=true ){ - $newTime1 = explode('T',$time); - if( isset($newTime1[1]) ){ - $newTime2 = str_replace('+','-', $newTime1[1]); - $newTime = explode('-', $newTime2); - if( is_array($newTime) && count($newTime)){ - if( $full === true ){ - $format['time'] = $newTime[0]; - if(isset($newTime) && count($newTime)>1 ) $format['deduction'] = $newTime[1]; - $format['date'] = $newTime1[0]; - return $format; - } else{ - return $newTime[0]; - } - } - } - } - public static function __status( $status, $formated = true, $statusFor='default' ){ - echo _status($status, $formated, $statusFor); - } +if( !function_exists('_matchUrl')){ + function _matchUrl( $urlToMatch='', $requestUrl ){ + if( preg_match('/^'.str_replace('/','\/',$urlToMatch).'/', $requestUrl)){ + return true; + } + return false; + } +} - public static function _matchUrl( $urlToMatch='', $requestUrl ){ - if( preg_match('/^'.str_replace('/','\/',$urlToMatch).'/', $requestUrl)){ - return true; - } +if( !function_exists('_pr')){ + function _pr( $arr=array(), $exit=false){ + echo "
";
+        print_r($arr);
+        echo "
";
+        if($exit){
+            exit();
+        }
+    }
+}
 
-          return false;
-      }
+if( !function_exists('__br')){
+    function __br( $repeat = 1 ){
+        if($repeat>0){
+            for ($i=0; $i < $repeat; $i++) {
+                echo "
"; + } + } + } +} - public static function _pr( $arr=array(), $exit=false){ - echo "
";
-          print_r($arr);
-          echo "
";
-          if($exit){
-              exit();
-          }
-      }
+if( !function_exists('_')){
+    function _( $string = null, $print = false ){
+        if(func_num_args()==2){
+            if( $print ){
+                echo htmlspecialchars($string);
+            } else{
+                 return htmlspecialchars($string);
+            }
+        } else{
+            return htmlspecialchars($string);
+        }
+    }
+}
 
-      public static function __br( $repeat = 1 ){
-          if($repeat>0){
-              for ($i=0; $i < $repeat; $i++) {
-                  echo "
"; - } - } - } +if( !function_exists('__')){ + function __( $string = null, $escape = true){ + if($escape === true){ + echo htmlspecialchars($string); + } else{ + echo $string; + } + } +} - public static function _( $string = null, $print = false ){ - if(func_num_args()==2){ - if( $print ){ - echo htmlspecialchars($string); - } else{ - return htmlspecialchars($string); - } - } else{ - return htmlspecialchars($string); - } - } +if( !function_exists('_form')){ + function _form( $action='', $options = array(), $csrf = true ){ + $form = '
$value) { + $form.= $key.'="'.$value.'"'; + } + } + $form.= '>'; - if( isset($options) && count($options) ){ - foreach ($options as $key => $value) { - $form.= $key.'="'.$value.'"'; - } - } - $form.= '>'; + if($csrf === true){ + $form.= _CSRF(true); + } - if($csrf === true){ - $form.= _CSRF(true); - } - return $form; - } + return $form; + } +} - public static function __form( $action='', $options = array(), $csrf = true ){ - echo _form( $action, $options, $csrf ); - } +if( !function_exists('__form')){ + function __form( $action='', $options = array(), $csrf = true ){ + echo _form( $action, $options, $csrf ); + } +} - public static function _CSRF( $full_field = false ){ - $token = session_id(); - $token = sha1($token.SALT); +if( !function_exists('_CSRF')){ + function _CSRF( $full_field = false ){ + $token = session_id(); + $token = sha1($token.SALT); - if( $full_field === true ){ - return ''; - } - return $token; - } + if( $full_field === true ){ + return ''; + } + return $token; + } +} - public static function _checkCSRF( $csrf='', $terminate = true, $terminate_msg = 'Invalid Token' ){ - if( $csrf == '' ){ - $csrf = isset($_POST['_csrf']) ? $_POST['_csrf'] : (isset($_GET['_csrf']) ? $_GET['_csrf'] : '' ); - } +if( !function_exists('_checkCSRF')){ + function _checkCSRF( $csrf='', $terminate = true, $terminate_msg = 'Invalid Token' ){ + if( $csrf == '' ){ + $csrf = isset($_POST['_csrf']) ? $_POST['_csrf'] : (isset($_GET['_csrf']) ? $_GET['_csrf'] : '' ); + } - if( $csrf !== _CSRF() && $terminate === true ){ - __($terminate_msg);exit; - } + if( $csrf !== _CSRF() && $terminate === true ){ + __($terminate_msg);exit; + } - return $csrf === _CSRF(); - } + return $csrf === _CSRF(); + } +} - public static function _a( $title, $link, $options = array(), $escape = false ){ - if( $escape === false ){ - $anchor = ' $value) { - $anchor.= $key.'="'.$value.'"'; - } - } - $anchor.= '>'.$title.''; - } else{ - $anchor = ' $value) { + $anchor.= $key.'="'.$value.'"'; + } + } + $anchor.= '>'.$title.''; + } else{ + $anchor = ' $value) { - $anchor.= _($key).'="'._($value).'"'; - } - } - $anchor.= '>'._($title).''; - } + if( isset($options) && count($options) ){ + foreach ($options as $key => $value) { + $anchor.= _($key).'="'._($value).'"'; + } + } + $anchor.= '>'._($title).''; + } - return $anchor; - } - - public static function __a( $title, $link, $options = array(), $escape = false ){ - echo _a($title, $link, $options , $escape ); - } - - public static function _css( $links, $defer = false, $version = false ){ - $css = ''; - if( is_array($links) && count($links) ){ - foreach ($links as $key => $value) { - if($version) $value = $value.'?v='.$version; - $css.= ' $value) { + if($version) $value = $value.'?v='.$version; + $css.= ' $value) { - if($version) $value = $value.'?v='.$version; - $js.= ''."\r\n"; + } + }elseif( $links!=''){ + if($version) $links = $links.'?v='.$version; + $js.= '