Exemplo n.º 1
0
 protected function checkAuthorizate()
 {
     $sess = App::getInstance()->getSession();
     if (!$sess->getByName('login_id') || !$sess->getByName('login_name')) {
         $router = App::getInstance()->getRouter();
         if ($router->getCurrentPath() != $router->getPathByName('backend_index')) {
             $this->redirect('backend_index');
         }
     }
 }
Exemplo n.º 2
0
 public function __construct()
 {
     $configDB = App::getInstance()->getConfigParam('db_parameters');
     $dsn = "mysql:host={$configDB['database_host']};dbname={$configDB['database_name']};charset={$configDB['database_encoding']}";
     $opt = array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC);
     /**
      * Соединение создается 1 раз и хранится в классе App
      */
     if (!App::getInstance()->getConnectionDB()) {
         $coonection = new PDO($dsn, $configDB['database_user'], $configDB['database_password'], $opt);
         App::getInstance()->setConnectionDB($coonection);
     }
     $this->_connection = App::getInstance()->getConnectionDB();
 }
Exemplo n.º 3
0
 protected function preSave(&$data)
 {
     if (isset($_POST['file_old'])) {
         $data['file'] = $_POST['file_old'];
     }
     if (!$data['id'] || empty($_FILES['file']['name']) || !$data['file']) {
         return false;
     }
     $configTwigUpload = App::getInstance()->getConfigParam('upload_files');
     if (!isset($configTwigUpload['images_category_and_product'])) {
         throw new \Exception('Неверные Параметры конфигурации upload_files');
     }
     $id = (int) $data['id'];
     $file = App::getInstance()->getCurrDir() . '/web' . $configTwigUpload['images_category_and_product'] . '/category/' . $id . '.*';
     array_map('unlink', glob($file));
 }
 public function indexAction()
 {
     $component = new TopMenuComponent($this);
     $componentResp = $component->toString();
     $componentNotify = new NotifyComponent($this);
     $componentNotifyResp = $componentNotify->toString();
     $sess = App::getInstance()->getSession();
     if ($this->getRequestParam('exit', false)) {
         $sess->set('login_id', null);
         $sess->set('login_name', null);
         $this->redirect('backend_index');
     }
     $username = '';
     if (!$sess->getByName('login_id') || !$sess->getByName('login_name')) {
         $formUser = new LoginFormType($this);
         if ($_POST) {
             $res = array();
             $res['redirect'] = false;
             if ($formUser->fillAndIsValid()) {
                 $tblUser = new Users();
                 $login = $tblUser->login($formUser->getData());
                 if (isset($login['id']) && isset($login['name'])) {
                     $sess->set('login_id', $login['id']);
                     $sess->set('login_name', $login['name']);
                     $res['redirect'] = true;
                 } else {
                     $formUser->addFormError('Неверные данные');
                 }
             }
             $res['form'] = $formUser->render();
             header('Content-Type: application/json');
             echo json_encode($res);
             die;
         }
         $formLogin = $formUser->render();
     } else {
         $formLogin = false;
         $username = $sess->getByName('login_name');
     }
     $this->render(array('componentMenu' => $componentResp, 'formLogin' => $formLogin, 'username' => $username, 'componentNotify' => $componentNotifyResp), 'Backend/Default/index.html');
 }
Exemplo n.º 5
0
 public function render($data, $template)
 {
     $configTwig = App::getInstance()->getConfigParam('twig_params');
     if (!isset($configTwig['cache_path']) || !isset($configTwig['templates_path'])) {
         throw new \Exception('Неверные Параметры конфигурации twig');
     }
     $loader = new Twig_Loader_Filesystem(ROOT . '/../' . $configTwig['templates_path']);
     /**
      * add template path plugins
      */
     foreach (App::getInstance()->getPlugins() as $plagin) {
         $loader->addPath(ROOT . '/../Plugins/' . $plagin->getName() . '/Templates');
     }
     $isProd = App::getInstance()->isProd();
     $this->_environment = new Twig_Environment($loader, array('cache' => ROOT . '/../' . $configTwig['cache_path'], 'auto_reload' => !$isProd, 'debug' => !$isProd));
     if (!$isProd) {
         $this->_environment->addExtension(new \Twig_Extension_Debug());
     }
     App::getInstance()->setResponse($this->_environment->render($template, $data));
     return App::getInstance()->getResponse();
 }
Exemplo n.º 6
0
#!/usr/bin/env php
<?php 
set_time_limit(0);
use System\App;
const ROOT = __DIR__;
require_once ROOT . '/../vendor/autoload.php';
spl_autoload_register('AutoLoader');
function AutoLoader($className)
{
    $file = str_replace('\\', DIRECTORY_SEPARATOR, $className);
    require_once ROOT . '/../' . $file . '.php';
}
$app = App::getInstance(App::RUN_IN_CONSOLE);
$app->setArgs($argv);
$app->run();
Exemplo n.º 7
0
<?php

session_start();
date_default_timezone_set('Asia/Jakarta');
require 'vendor/autoload.php';
foreach (glob('system/*') as $system) {
    require $system;
}
foreach (glob('app/models/*') as $model) {
    require $model;
}
foreach (glob('app/controllers/*') as $controller) {
    require $controller;
}
use system\App;
App::run(require 'app/config/config.php');
Exemplo n.º 8
0
<?php

/**
 * MicroAsterisco
 * Microframework criado como pratica de estudo da
 * linguagem PHP e aplicação de alguns conceito de
 * padrão de projetos
 * @author Alan Freire - alan_freire@msn.com
 */
/**
 * Inclusão do arquivo de configuração
 */
include_once 'src/config.php';
/**
 * Verfica se o sistema está em modo de desenvolvimento
 * e configura o PHP para mostrar ou não os erros
 */
error_reporting(DEV_MOD ? E_ALL : false);
ini_set('display_errors', DEV_MOD ? true : false);
/**
 * Executa a aplicação.
 */
try {
    \System\App::run(filter_input(INPUT_GET, 'url', FILTER_SANITIZE_STRING));
} catch (Exception $e) {
    echo $e->getMessage();
}
Exemplo n.º 9
0
 protected function run()
 {
     $countPages = ceil($this->getCount() / $this->getCurrLimit());
     $page = $this->getPage();
     if ($page > $countPages || $page < 1) {
         $this->setPage(1);
     }
     $from = ($this->getPage() - 1) * $this->getCurrLimit();
     $this->setFrom($from);
     $to = $this->getFrom() + $this->getCurrLimit() - 1;
     $this->setTo($to);
     $pages = array();
     for ($i = 1; $i <= $countPages; $i++) {
         $pages[] = $i;
     }
     $paramsArr = $this->_params;
     $params = App::getInstance()->getRouter()->getCurrentPath() . '?';
     if ($paramsArr) {
         if (isset($paramsArr['page'])) {
             unset($paramsArr['page']);
         }
         if (isset($paramsArr['limit'])) {
             unset($paramsArr['limit']);
         }
         $i = 0;
         foreach ($paramsArr as $key => $value) {
             $params .= $i == 0 ? '' : '&';
             $params .= $key . '=' . $value;
             $i++;
         }
     }
     return $this->render(array('limites' => $this->getLimits(), 'curLimit' => $this->getCurrLimit(), 'page' => $this->getPage(), 'pages' => $pages, 'url' => $params), $this->getTemplate());
 }
Exemplo n.º 10
0
 /**
  * @param array $data
  * @param $template
  * @return string
  */
 protected function renderTmpl($data = array(), $template)
 {
     return App::getInstance()->getTemplater()->render($data, $template);
 }
Exemplo n.º 11
0
<?php

use system\App;
require_once __DIR__ . '/system/autoload.php';
App::run();
Exemplo n.º 12
0
<?php

use System\App;
const ROOT = __DIR__;
require_once ROOT . '/../vendor/autoload.php';
/**
 * Загружать классы по неймспейсу
 */
spl_autoload_register('AutoLoader');
function AutoLoader($className)
{
    $file = str_replace('\\', DIRECTORY_SEPARATOR, $className);
    require_once ROOT . '/../' . $file . '.php';
}
//Инициализация
$app = App::getInstance();
$app->run();
Exemplo n.º 13
0
 private function getPlugins()
 {
     $app = App::getInstance();
     return $app->getPlugins();
 }
Exemplo n.º 14
0
 /**
  * @param $name
  * @return mixed
  */
 protected function getRoutePathByName($name)
 {
     return App::getInstance()->getRouter()->getPathByName($name);
 }
Exemplo n.º 15
0
        <link rel="stylesheet" type="text/css" href="./assets/css/bootstrap.min.css">
        <style type="text/css">
        body {
            margin-top: 3rem;
        }
        </style>
    </head>
    <body>
        <div class="container">
            <div class="row">
                <div class="jumbotron">
                    <h1 class="text-center"><span class="glyphicon glyphicon-thumbs-down" aria-hidden="true"></span> Error 404</h1>
                    <p class="text-center">
                        Nós não conseguimos encontrar a página que você está procurando em
                        <em><?php 
echo \System\App::correntUrl();
?>
</em>.
                    </p>
                    <p class="text-center">
                        <a href="<?php 
echo BASE_URL;
?>
" class="btn btn-primary btn-lg">                            
                            <span class="glyphicon glyphicon-home" aria-hidden="true"></span>
                            Voltar para a Home
                        </a>
                    </p>
                </div>
                <div class="col-md-6">
                    <h3>O que aconteceu?</h3>
Exemplo n.º 16
0
 /**
  * @param $message
  * @return bool
  */
 protected function addNotify($message)
 {
     return App::getInstance()->getSession()->addNotify($message);
 }