Exemple #1
0
 /**
  * Construct the exception
  *
  * @param  string $msg
  * @param  int $code
  * @param  Exception $previous
  * @return void
  */
 public function __construct($msg = '', $code = 0, Exception $previous = null)
 {
     $debug = KantFactory::getConfig()->get('debug');
     if ($debug == false) {
         header($_SERVER["SERVER_PROTOCOL"] . " 404 Not Found");
         header("Status: 404 Not Found");
         header("X-Powered-By: KantPHP Framework");
         echo '404 File Not Found!';
         exit;
     }
     if (version_compare(PHP_VERSION, '5.3.0', '<')) {
         parent::__construct($msg, (int) $code);
         $this->_previous = $previous;
     } else {
         $error = array();
         $error['message'] = $msg;
         $trace = $this->getTrace();
         if ('E' == $trace[0]['function']) {
             $error['file'] = $trace[0]['file'];
             $error['line'] = $trace[0]['line'];
         } else {
             $error['file'] = $this->getFile();
             $error['line'] = $this->getLine();
         }
         $error['trace'] = $this->getTraceAsString();
         Log::write($error['message'], Log::ERR);
         $exceptionFile = KANT_PATH . 'View/system/exception.php';
         include $exceptionFile;
         exit;
         //            parent::__construct($msg, (int) $code, $previous);
     }
 }
Exemple #2
0
 /**
  * Widget
  * 
  * @param string $widgetname
  * @param string $method
  * @param array $data
  * @param boolean $return
  * @return boolean
  * @throws KantException
  */
 public function widget($widgetname, $method, $data = array(), $return = false)
 {
     $dispatchInfo = KantFactory::getConfig()->get('dispatchInfo');
     $module = isset($dispatchInfo['module']) ? ucfirst($dispatchInfo['module']) : '';
     $classname = ucfirst($widgetname) . 'Widget';
     if ($module) {
         $filepath = APP_PATH . 'Module' . DIRECTORY_SEPARATOR . $module . DIRECTORY_SEPARATOR . 'Widget' . DIRECTORY_SEPARATOR . $classname . '.php';
     } else {
         $filepath = APP_PATH . 'Widget' . DIRECTORY_SEPARATOR . $classname . '.php';
     }
     if (file_exists($filepath)) {
         include_once $filepath;
         if (!class_exists($classname)) {
             throw new KantException("Class {$classname} does not exists");
         }
         if (!method_exists($classname, $method)) {
             throw new KantException("Method {$method} does not exists");
         }
         $widget = new $classname();
         $content = call_user_func_array(array($widget, $method), $data);
         if ($return) {
             return $content;
         } else {
             echo $content;
         }
     }
 }
Exemple #3
0
 public static function parseConfig($config = "")
 {
     if ($config == "") {
         $config = KantFactory::getConfig()->get('cache.default');
     } elseif (is_string($config)) {
         $config = KantFactory::getConfig()->get('cache.' . $config);
     }
     return $config;
 }
Exemple #4
0
 public function __construct($config = "")
 {
     if ($config == '') {
         $this->cookieConfig = KantFactory::getConfig()->get('cookie');
     } else {
         if ($config != $this->cookieConfig) {
             $this->cookieConfig = array_merge($config, $this->cookieConfig);
         }
     }
 }
Exemple #5
0
 /**
  * Get current user defined language
  * 
  * @return
  */
 public function getLang()
 {
     static $lang = null;
     if (empty($lang)) {
         $lang = !empty($_COOKIE['lang']) ? $_COOKIE['lang'] : KantFactory::getConfig()->get('lang');
         if (empty($lang)) {
             $lang = 'en_US';
         }
     }
     return $lang;
 }
Exemple #6
0
 public static function buildDirSecure($dirs)
 {
     $config = KantFactory::getConfig()->get('config');
     $dir_secure_filename = !empty($config['dir_secure_filename']) ? $config['dir_secure_filename'] : 'index.html';
     $files = explode(",", $dir_secure_filename);
     $content = !empty($config['dir_secure_content']) ? $config['dir_secure_content'] : '';
     foreach ($files as $filename) {
         foreach ($dirs as $dir) {
             file_put_contents($dir . $filename, $content);
         }
     }
 }
Exemple #7
0
 /**
  * Parse Config
  * 
  * @param array/string $config
  * @return array/string
  */
 protected function parseConfig($config = "")
 {
     if ($config == '') {
         $config = KantFactory::getConfig()->get('database.default');
     } elseif (is_string($config) && false === strpos($config, '/')) {
         $config = KantFactory::getConfig()->get('database.' . $config);
     }
     if (is_string($config)) {
         return $this->parseDsn($config);
     } else {
         return $config;
     }
 }
 /**
  * Build module
  */
 public function buildModule()
 {
     //build module
     if (KantFactory::getConfig()->get('check_app_dir')) {
         if (!defined('CREATE_MODULE')) {
             return;
         }
         $module = CREATE_MODULE;
         if (is_dir(MODULE_PATH . $module) == false) {
             Build::checkDir($module);
         }
     }
 }
Exemple #9
0
 /**
  * Parse route
  * 
  * @param type $pathinfo
  */
 protected static function parseRoute($pathinfo)
 {
     $route = [null, null, null];
     $var = [];
     $pathinfo = trim($pathinfo, "/");
     //Special pathinof as demo/index/get/a,100/b,101?c=102&d=103
     if (strpos($pathinfo, "?") !== false) {
         $parse = explode("?", $pathinfo);
         $path = explode('/', $parse[0]);
         if (!empty($parse[1])) {
             parse_str($parse[1], $query);
             foreach ($query as $key => $val) {
                 $dispatchInfo[$key] = urldecode($val);
             }
         }
     } else {
         //Normal pathinfo as demo/index/get/a,100/b,101
         $path = explode('/', $pathinfo);
     }
     $routeConfig = KantFactory::getConfig()->get("route");
     $module = array_shift($path);
     $module = !empty($module) ? $module : $routeConfig['module'];
     $controller = !empty($path) ? array_shift($path) : $routeConfig['ctrl'];
     $action = !empty($path) ? array_shift($path) : $routeConfig['act'];
     if ($action) {
         if (strpos($action, "?") !== false) {
             $action = substr($action, 0, strpos($action, "?"));
         }
         $urlsuffix = KantFactory::getConfig()->get('url_suffix');
         if ($urlsuffix) {
             if (strpos($action, "&") !== false) {
                 $action = substr($action, 0, strpos($action, $urlsuffix));
             }
         } else {
             if (strpos($action, "&") !== false) {
                 $action = substr($action, 0, strpos($action, "&"));
             }
         }
         while ($next = array_shift($path)) {
             $query = preg_split("/[?&]/", $next);
             if (!empty($query)) {
                 foreach ($query as $key => $val) {
                     $arr = preg_split("/[,:=-]/", $val, 2);
                     if (!empty($arr[1])) {
                         $var[$arr[0]] = urldecode($arr[1]);
                     }
                 }
             }
         }
     }
     $route = [$module, $controller, $action];
     return ['route' => $route, 'var' => $var];
 }
Exemple #10
0
 public function __construct()
 {
     $this->cookie = KantFactory::getCookie();
 }
Exemple #11
0
 /**
  * Get Tpl Dir
  */
 protected function getTplDir($module = '')
 {
     if ($module == '') {
         $module = isset($this->dispatchInfo[0]) ? strtolower($this->dispatchInfo[0]) : '';
     }
     $theme = KantFactory::getConfig()->get('theme');
     if ($module) {
         $tpldir = TPL_PATH . $theme . DIRECTORY_SEPARATOR . $module . DIRECTORY_SEPARATOR;
     } else {
         $tpldir = TPL_PATH . $theme . DIRECTORY_SEPARATOR;
     }
     return $tpldir;
 }
Exemple #12
0
 /**
  * 
  * Page redirection with message 
  * 
  * @param string $message
  * @param string $url
  * @param integer $second
  */
 public function redirect($message, $url = 'goback', $second = 3)
 {
     $redirectTpl = KantFactory::getConfig()->get('redirect_tpl');
     if ($redirectTpl) {
         include TPL_PATH . $redirectTpl . '.php';
     } else {
         include KANT_PATH . 'View' . DIRECTORY_SEPARATOR . 'system/redirect.php';
     }
     exit;
 }
Exemple #13
0
<?php

use Kant\KantFactory;
//Application path
define('APP_PATH', dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . 'Application' . DIRECTORY_SEPARATOR);
include APP_PATH . 'Kantphp/Framework.php';
$app = KantFactory::getApplication('Development');
$app->boot();
Exemple #14
0
 /**
  * Auto check token
  * 
  * @return boolean
  */
 protected function autoCheckToken($data)
 {
     // token(false)
     if (isset($this->options['token']) && $this->options['token'] === false) {
         return true;
     }
     $tokenConfig = KantFactory::getConfig()->get('token');
     if ($tokenConfig['switch']) {
         $name = !empty($tokenConfig['name']) ? $tokenConfig['name'] : "__hash__";
         if (!isset($data[$name]) || !isset($_SESSION[$name])) {
             return false;
         }
         list($key, $value) = explode('_', $data[$name]);
         if (isset($_SESSION[$name][$key]) && $value && $_SESSION[$name][$key] === $value) {
             unset($_SESSION[$name][$key]);
             return true;
         }
         if ($tokenConfig['reset']) {
             unset($_SESSION[$name][$key]);
         }
         return false;
     }
     return true;
 }