Example #1
0
 public function __construct()
 {
     if (class_exists('Memcache')) {
         $this->memcache = new Memcache();
         $config = Vinal::app()->config("cache");
         $this->memcache->connect($config->server, $config->port);
     }
 }
Example #2
0
 public function __construct()
 {
     if (!isset($this->config)) {
         $this->config = Vinal::app()->config("database");
     }
     if (!isset(self::$i)) {
         self::$i = new mysqli($this->config->dbHost, $this->config->dbUser, $this->config->dbPass, $this->config->dbBase);
     }
     self::$i->query("SET NAMES utf8");
 }
Example #3
0
 public function run($controller = '', $action = '')
 {
     try {
         Loader::I()->run();
         //Автозагрузка классов
         //Мультиязычность
         //Кеширование
         if (Vinal::app()->config("general")->cache == true) {
             $this->cache = new VCache();
         }
         $this->database = Loader::I()->loadClass('database');
         $route = new VRouting();
         if (VF::app()->user->isAuth()) {
             VF::app()->database->update('users', array('last_view' => time()), 'id = ' . VF::app()->user->getId());
         }
         if (isset($_GET['lang_id'])) {
             if ((int) $_GET['lang_id'] > 2 && $_GET['lang_id'] < 1) {
                 $_GET['lang_id'] = 1;
             }
             setcookie('lang_id', (int) $_GET['lang_id'], time() + 9000000, '/');
             $_COOKIE['lang_id'] = (int) $_GET['lang_id'];
             VF::app()->lang_id = (int) $_GET['lang_id'];
         }
         if ($_SERVER['HTTP_CF_CONNECTING_IP'] == '108.46.198.12' || $_SERVER['HTTP_CF_CONNECTING_IP'] == '67.80.30.28') {
             $this->is_admin = true;
         }
         if (preg_match('/android/is', $_SERVER['HTTP_USER_AGENT']) && !preg_match('#index/android#', $_SERVER['REQUEST_URI']) && !preg_match('#auth#', $_SERVER['REQUEST_URI'])) {
             if (isset($_GET['na'])) {
                 setcookie('no_android_page', 1, time() + 9000000, '/');
             } else {
                 if (isset($_COOKIE['no_android_page'])) {
                 } else {
                     $this->redirect('/index/android/?r=' . urlencode($_SERVER['REQUEST_URI']));
                 }
             }
         }
         if (!isset($_COOKIE['lang_id'])) {
             $lang = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2);
             if ($lang == 'ru' || $lang == 'by' || $lang == 'ua' || $lang == 'kz') {
                 $lang_id = 1;
             } else {
                 $lang_id = 2;
             }
             setcookie('lang_id', $lang_id, time() + 9000000, '/');
             VF::app()->lang_id = $lang_id;
         } else {
             VF::app()->lang_id = (int) $_COOKIE['lang_id'];
         }
         $route->run($controller, $action);
     } catch (ClassesException $e) {
         echo $e->getMessage();
         //TODO: Вывод ошибок
     }
 }
Example #4
0
 public function run($controller = '', $action = '')
 {
     if (!empty($controller) && !empty($action)) {
         $this->loadMethod($this->loadController($controller), $action);
     } else {
         $request_url = $_SERVER['REQUEST_URI'];
         $routing = Vinal::app()->config('general')->routing;
         $route = explode("/", $request_url);
         VF::app()->_route = $route;
         if ($route[1] == 'ru' || $route[1] == 'by' || $route[1] == 'us') {
             header("Location: " . str_replace(array("ru/", 'by/', 'us/'), array('', '', ''), $_SERVER['REQUEST_URI']));
             die;
         }
         foreach ($routing as $key => $r) {
             if ($key == $request_url) {
                 $route = explode("/", $r);
                 break;
             } else {
                 $chk_url = str_replace(array('.', '?', '*', '&'), array('\\.', '\\?', '\\*', '\\&'), $key);
                 if (preg_match('#<.*?:.*?>#is', $chk_url)) {
                     $chk_url = preg_replace('/<(.*?):(.*?)>/is', '($2{1,})', $chk_url);
                     if (preg_match("#{$chk_url}#is", $request_url, $a)) {
                         $route = explode("/", $r);
                         preg_match_all('#<(.*?):(.*?)>#is', $key, $b);
                         foreach ($b[1] as $k => $c) {
                             if ($c == 'controller') {
                                 $route[0] = $a[$k + 1];
                             } elseif ($c == 'action') {
                                 $route[1] = $a[$k + 1];
                             } else {
                                 $route['params'][$c] = $a[$k + 1];
                             }
                         }
                         if (count($route) > 0) {
                             break;
                         }
                     }
                 }
             }
         }
         if (!empty($route)) {
             $controller = $this->loadController($route[0]);
             $controller->id = $route[0];
             Vinal::app()->controller_id = $route[0];
             Vinal::app()->action_id = $route[1];
             $this->loadMethod($controller, $route[1], $route['params']);
         } else {
             throw new ClassesException(404);
         }
         //TODO: Сделать страницу 404
     }
 }
Example #5
0
 public function renderPartial($view, $params = array(), $return = false)
 {
     $config = Vinal::app()->config("general");
     $tpl_dir = $config->templates_dir;
     if (preg_match('/errors/ius', $view)) {
         $tpl_dir = str_replace(array('<controller>'), array(''), $tpl_dir);
     } else {
         $tpl_dir = str_replace(array('<controller>'), array(Vinal::app()->controller_id), $tpl_dir);
     }
     $tpl_file = __ROOT__ . $tpl_dir . $view . '.php';
     $render = $this->load($tpl_file, $params);
     if ($return == true) {
         return $render;
     } else {
         echo $render;
     }
 }
Example #6
0
 public function loadClass($name)
 {
     if ($name == 'database') {
         //Получаем тип базы данных
         $config = Vinal::app()->config("database");
         $dbType = $config->dbType;
         $name = "{$dbType}DataBase";
     }
     $name = ucfirst($name);
     $this->autoClasses($name);
     if (class_exists($name)) {
     } elseif (class_exists('V' . $name)) {
         $name = 'V' . $name;
     } else {
         return false;
     }
     if (isset(self::$_classes[$name])) {
         return self::$_classes[$name];
     }
     $class = new $name();
     self::$_classes[$name] = $class;
     return $class;
 }
Example #7
0
<?php

error_reporting(E_ERROR | E_WARNING | E_PARSE);
ini_set('display_errors', 1);
header("Content-type: text/html; Charset=UTF-8");
define('__ROOT__', dirname(__FILE__) . '/');
define('FILES_ROOT', __ROOT__ . 'files/');
define('FILE_SIZE', 1024);
if ($_SERVER['HTTP_USER_AGENT'] == 'Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)' && isset($_GET['search']['ingredient_id']) && !empty($_GET['search']['ingredient_id'])) {
    header('HTTP/1.0 403 Forbidden');
    die('You are forbidden!');
}
$_request_end = substr($_SERVER['REQUEST_URI'], -4, 4);
if ($_request_end == '.mjs' || substr($_SERVER['REQUEST_URI'], -5, 5) == '.mcss') {
    include __ROOT__ . 'tpl/min/nginx-mininification.php';
    die;
}
include __ROOT__ . '/framework/vinal.php';
Vinal::app()->run();
Example #8
0
 public function renderPartial($view, $params = array(), $return = false)
 {
     return Vinal::app()->render->renderPartial($view, $params, $return);
 }