Exemple #1
0
 public function CreateController($controller = null, $action = null)
 {
     if (is_null($controller) and is_null($action)) {
         $routerConfig = Config::load('router');
         if (empty($_GET['task'])) {
             $_GET['task'] = $routerConfig->get('NAME_CONTROLLER');
         }
         if (empty($_GET['action'])) {
             $_GET['action'] = $routerConfig->get('NAME_MODEL');
         }
         $this->controller = $_GET['task'];
         $this->action = $_GET['action'];
     } else {
         $this->controller = $controller;
         $this->action = $action;
     }
     if (strstr($this->controller, ",") !== False) {
         $url = explode(',', $this->controller);
         $urlCount = count($url) - 1;
         $subControler = '';
         for ($i = 0; $i < $urlCount; $i++) {
             $subControler .= $url[$i] . '/';
         }
         $this->controller = $url[$urlCount];
     } else {
         $subControler = null;
     }
     // Does the class exist?
     $patchController = appDir . '../app/Controller/' . $subControler . '' . $this->controller . '.php';
     //var_dump($patchController);
     if (file_exists($patchController)) {
         include_once $patchController;
         $path = null;
     }
     $xsubControler = str_replace("/", "\\", $subControler);
     try {
         if (!class_exists('\\Controller\\' . $xsubControler . '' . $this->controller . 'Controller')) {
             throw new BaseException('Bad controller error');
         }
     } catch (BaseException $e) {
         if (ini_get('display_errors') == "on") {
             echo $e->getMessage() . '<br />
             File: ' . $e->getFile() . '<br />
             Code line: ' . $e->getLine() . '<br /> 
             Trace: ' . $e->getTraceAsString();
             exit;
         }
         $routerConfig = Config::load('router');
         header("HTTP/1.0 404 Not Found");
         $this->router->redirect($routerConfig->get('404'));
         exit;
     }
     $this->controller = '\\Controller\\' . $xsubControler . '' . $this->controller . 'Controller';
     return new $this->controller($this->baseClass);
 }
Exemple #2
0
 public function page()
 {
     $smartyConfig = Config::load('smarty');
     $view = $this->loadView('index');
     $patchController = $smartyConfig->get('setTemplateDir', appDir . '../app/View/templates') . '/page/' . htmlspecialchars($_GET['action']) . $smartyConfig->get('fileExtension', '.html.php');
     if (file_exists($patchController)) {
         $view->render('page/' . htmlspecialchars($_GET['action']));
     } else {
         $this->router->redirect('page/index');
     }
 }
Exemple #3
0
 /**
  * Przekazuje kod do szablonu Smarty
  *
  * @param string $name Nazwa pliku
  * @param string $path Ścieżka do szablonu
  *
  * @return void
  */
 public function renderInclude($name, $path = null)
 {
     $smartyConfig = Config::load('view/smarty');
     $pathFile = pathFile($name);
     $folder = $pathFile[0];
     $name = $pathFile[1];
     $path = $smartyConfig->get('setTemplateDir') . '/' . $folder . $name . $smartyConfig->get('fileExtension', '.html.php');
     try {
         if (is_file($path)) {
             $this->smarty->display($path);
         } else {
             throw new \Exception('Can not open template ' . $name . ' in: ' . $path);
         }
     } catch (Exception $e) {
         echo $e->getMessage() . '<br />
             File: ' . $e->getFile() . '<br />
             Code line: ' . $e->getLine() . '<br />
             Trace: ' . $e->getTraceAsString();
         exit;
     }
 }
Exemple #4
0
 /**
  * Add a message to the queue
  * 
  * @param  string   $type           The type of message to add
  * @param  string   $message        The message
  * @param  string   $redirect    (optional) If set, the user will be redirected to this URL
  * @return  bool 
  * 
  */
 public function add($type, $message, $redirect = null)
 {
     if (!isset($type) or !isset($message[0])) {
         return false;
     }
     // Replace any shorthand codes with their full version
     if (strlen(trim($type)) == 1) {
         $type = str_replace(array('h', 'i', 'w', 'e', 's'), array('help', 'info', 'warning', 'error', 'success'), $type);
     }
     try {
         if (!in_array($type, $this->msgTypes)) {
             // Make sure it's a valid message type
             throw new BaseException('"' . strip_tags($type) . '" is not a valid message type!', 501);
         }
     } catch (BaseException $e) {
         if (ini_get('display_errors') == "on") {
             echo $e->getMessage() . '<br />
             File: ' . $e->getFile() . '<br />
             Code line: ' . $e->getLine() . '<br /> 
             Trace: ' . $e->getTraceAsString();
             exit;
         }
         $routerConfig = Config::load('router');
         header("HTTP/1.0 501 Not Implemented");
         echo $e->getMessage();
         exit;
     }
     $get = $this->session->get('flash_messages');
     $get[$type][] = $message;
     $this->session->set('flash_messages', $get);
     if (!is_null($redirect)) {
         $router = new Router();
         $router->redirect($redirect);
         exit;
     }
     return true;
 }
Exemple #5
0
 private function loadObject($name, $type)
 {
     if (!in_array($type, array('Model', 'View'))) {
         return false;
     }
     $pathFile = pathFile($name);
     $folder = $pathFile[0];
     $name = $pathFile[1];
     $n = str_replace($type, '', $name);
     $path = appDir . '../app/' . $type . '/' . $folder . $n . '.php';
     if (!empty($folder)) {
         $name = '\\' . $type . '\\' . str_replace(array('\\', '/'), '\\', $folder) . $name . $type;
     } else {
         $name = '\\' . $type . '\\' . $name . $type;
     }
     try {
         if (is_file($path)) {
             include_once $path;
             $ob = new $name($this->baseClass);
             $ob->init();
         } else {
             throw new BaseException('Can not open ' . $type . ' ' . $name . ' in: ' . $path);
         }
     } catch (BaseException $e) {
         if (ini_get('display_errors') == "on") {
             echo $e->getMessage() . '<br />
             File: ' . $e->getFile() . '<br />
             Code line: ' . $e->getLine() . '<br /> 
             Trace: ' . $e->getTraceAsString();
             exit;
         }
         $routerConfig = Config::load('router');
         header("HTTP/1.0 400 Bad Request");
         echo $e->getMessage();
         exit;
     }
     return $ob;
 }
Exemple #6
0
 public function parseGets()
 {
     $routerConfig = Config::load('router');
     if (MOD_REWRITE) {
         $sRequest = preg_replace('!' . $this->sURI . '(.*)$!i', '$1', $_SERVER['REQUEST_URI']);
         if (substr($sRequest, -1) != '/') {
             $sRequest .= '/';
         }
         $sGets = $this->parseUrl($sRequest);
         parse_str($sGets, $aGets);
         $_GET['NAME_CONTROLLER'] = !empty($aGets['NAME_CONTROLLER']) ? $aGets['NAME_CONTROLLER'] : $routerConfig->get('NAME_CONTROLLER');
         unset($aGets['NAME_CONTROLLER']);
         $_GET['NAME_MODEL'] = !empty($aGets['NAME_MODEL']) ? $aGets['NAME_MODEL'] : $routerConfig->get('NAME_MODEL');
         unset($aGets['NAME_MODEL']);
         $_GET = array_merge($_GET, $aGets);
     } else {
         $sRequest = preg_replace('!' . $this->sURI . '(.*)$!i', '$1', $_SERVER['REQUEST_URI']);
         if (substr($sRequest, 0, 1) == '?') {
             $sRequest = substr($sRequest, 1);
         }
         $sGets = $sRequest;
         $sGets = str_replace("index.php?", "", $sGets);
         parse_str($sGets, $output);
         $_GET['NAME_CONTROLLER'] = !empty($output['NAME_CONTROLLER']) ? $output['NAME_CONTROLLER'] : $routerConfig->get('NAME_CONTROLLER');
         $_GET['NAME_MODEL'] = !empty($output['NAME_MODEL']) ? $output['NAME_MODEL'] : $routerConfig->get('NAME_MODEL');
     }
 }
Exemple #7
0
 public function __construct()
 {
     $this->templateConfig = Config::load('view/defaultConfig');
 }