index.php<?php
$aplication = "aplication";
$system = "system";
$template = "template";
define("SYSPATH", $_SERVER['DOCUMENT_ROOT'] . "/" . $system . "/");
define("APPATH" , $_SERVER['DOCUMENT_ROOT'] . "/" . $aplication . "/");
define("TPLPATH", $_SERVER['DOCUMENT_ROOT'] . "/" . $template . "/");
define("KEY" , true);
error_reporting(E_ALL | E_STRICT);
if(!file_exists(SYSPATH) || !file_exists(APPATH) || !file_exists(TPLPATH))
{
exit("Скрипт поврежден. Он не может работать с повреждениями. Воть так воть :)");
}
require SYSPATH . 'bootstrap.php';
echo $request->body();
echo "<br /><br />Время выполнения скрипта: <i><b>" . microtime(true) . "</b></i>";
.htaccessAddDefaultCharset UTF-8
php_flag magic_quotes_gpc Off
Options Indexes FollowSymLinks
DirectoryIndex index.php
php_value max_execution_time 200
php_value max_input_time 200
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?url=$1 [L,QSA]
</IfModule>
system/bootstrap.php<?php if(!defined('KEY')) die("No success. КОроче валяй отсюдо, по добру, по здорову");
date_default_timezone_set('Europe/Moscow');
setlocale(LC_ALL, 'en_US.utf-8');
function getUrlController ()
{
if(!empty($_REQUEST['url']))
{
$match = explode("/", $_REQUEST['url']);
require SYSPATH . 'config/url.php';
if(count($url) > 0)
{
foreach($url as $key=>$value)
{
if(preg_match($key, $_REQUEST['url']))
{
$result = $value;
}
}
if(empty($result))
{
$result = $match[0];
}
return $result;
}
else
{
return $match[0];
}
}
else
{
return null;
}
}
function getDefaultHelpers ($helpers)
{
foreach($helpers as $helper)
{
require APPATH . 'helpers/' . $helper . ".php"
;
}
return false;
}
function getDefaultLibraryes ($libraries)
{
foreach($libraries as $library)
{
require APPATH . 'libraries/' . $library . ".php"
;
}
return false;
}
function error ($error_text)
{
exit($error_text);
}
require SYSPATH . 'zzika/controller.php';
require SYSPATH . 'zzika/http.php';
require SYSPATH . 'zzika/cookie.php';
require SYSPATH . 'zzika/load.php';
require SYSPATH . 'zzika/user_controller.php';
require SYSPATH . 'zzika/core.php';
$request = new Zzika;
system/zzika/core.php<?php if(!defined('KEY')) die("No success. КОроче валяй отсюдо, по добру, по здорову");
class Zzika
{
public $config;
public $database;
public $autoload;
public $load;
public $http;
public $cookie;
function __construct ()
{
require SYSPATH . 'config/config.php';
$this->config = $config;
require SYSPATH . 'config/database.php';
$this->database = $database;
require SYSPATH . 'config/autoload.php';
$this->autoload = $autoload;
unset($config, $database, $autoload);
$this->main = new load;
$this->hd = new headers;
}
public function body ()
{
if(count($this->autoload['helpers']) > 0)
{
getDefaultHelpers($this->autoload['helpers']);
}
if(count($this->autoload['libraryes']))
{
getDefaultLibraryes($this->autoload['libraryes']);
}
if(isset($this->config['auto_dbconnect']))
{
$this->main->mysql_DBconncet($this->database);
}
$urlController = getUrlController();
$controller = empty($urlController) ? $this->config['default_controller']:$urlController;
$controller_path = APPATH . 'controllers/' . $controller . '.php';
if(!file_exists($controller_path))
{
error('Отсутсвует контроллер: <b>' . $controller . '</b>');
}
else
{
require $controller_path;
$controller_obj = new $controller;
echo $controller_obj->index();
$this->hd->get_headers();
$this->main->get_views();
}
unset($this->main);
}
}
system/zzika/controller.php<?php if(!defined('KEY')) die("No success. КОроче валяй отсюдо, по добру, по здорову");
class controller
{
static $connect;
public function mysql_DBconncet ($database)
{
self::$connect = mysql_connect($database['mysql_host'], $database['mysql_user'], $database['mysql_password']);
if(self::$connect == true)
{
mysql_select_db($database['mysql_dbname'], self::$connect);
mysql_query("SET NAMES '".$database['mysql_charset']."'", self::$connect);
}
else
{
error('Невозсожно подключится к БД ' . $database['mysql_dbname']);
}
}
public function mysql_DBquery ($query_string)
{
return mysql_query($query_string) or error('Произлшла ошибка: ' . mysql_error());
}
}
system/zzika/http.php<?php if(!defined('KEY')) die("No success. КОроче валяй отсюдо, по добру, по здорову");
class headers
{
public static $headers = array();
public static $cookies = array();
public static function send ($header)
{
self::$headers[] = $header;
return false;
}
public static function get_headers ()
{
foreach(self::$cookies as $k=>$v)
{
setcookie($v['name'], $v['value'], $v['time']);
}
foreach(self::$headers as $key=>$value)
{
header($value);
}
self::$cookies = false;
self::$headers = false;
return false;
}
}
system/zzika/cookie.php<?php if(!defined('KEY')) die("No success. КОроче валяй отсюдо, по добру, по здорову");
class cookie extends headers
{
public function set($name, $value, $time = null)
{
self::$cookies[] = array('name'=>$name, 'value'=>$value, 'time'=>$time);
}
public function get($name)
{
if(empty($_COOKIE[$name]))
{
return null;
}
else
{
return $_COOKIE[$name];
}
}
public function del ($name)
{
setcookie($name, "", time()+0);
}
}
system/zzika/load.php<?php if(!defined('KEY')) die("No success. КОроче валяй отсюдо, по добру, по здорову");
class load extends controller
{
public static $view_complate;
public static function library ($name)
{
$dir = SYSPATH . 'library/' . $name . '.php';
if(file_exists($dir))
{
require $dir;
}
else
{
error('Отсутсвует библиотека: <b>' . $dir . '</b>');
}
}
public function view ($name, $variables = null)
{
if(isset($variables))
{
extract($variables);
}
$view_path = APPATH . "views/" . $name . ".php";
if(file_exists($view_path))
{
$view_dir = file_get_contents($view_path);
self::$view_complate[] = eval('?>' . $view_dir);
}
else
{
exit('error');
}
}
public static function get_views()
{
$text = self::$view_complate;
$result = "";
if(count($text) > 0)
{
foreach($text as $key=>$value)
{
$result .= $value;
}
}
return $result;
}
public function model($name, $class_name)
{
$className = isset($class_name) ? $class_name:$name;
$model_path = APPATH . 'models/' . $name . ".php";
if(file_exists($model_path))
{
require $model_path;
$obj = new $className;
return $obj->index();
}
else
{
error('Отсутсвует модель: <b>'.$className.'</b>');
}
}
}
system/zzika/user_controller.php<?php if(!defined('KEY')) die("No success. КОроче валяй отсюдо, по добру, по здорову");
class user_controller
{
public $load;
public $http;
public $cookie;
function __construct ()
{
$this->load = new load;
$this->http = new headers;
$this->cookie = new cookie;
}
}
system/config/autoload.php<?php if(!defined('KEY')) die("No success. КОроче валяй отсюдо, по добру, по здорову");
$autoload = array(
'libraryes' => array(),
'helpers' => array(),
);
system/config/config.php<?php if(!defined('KEY')) die("No success. КОроче валяй отсюдо, по добру, по здорову");
$config = array(
'site_name' => "Просто сайт",
'default_controller' => "welcome",
'auto_dbconnect' => false,
);
system/config/database.php<?php if(!defined('KEY')) die("No success. КОроче валяй отсюдо, по добру, по здорову");
$database = array();
$database['mysql_host'] = "localhost";
$database['mysql_user'] = "root2";
$database['mysql_password'] = "";
$database['mysql_dbname'] = "mvc";
$database['mysql_dbprefix'] = "mvc_";
$database['mysql_charset'] = "utf-8";
system/config/url.php<?php if(!defined('KEY')) die("No success. КОроче валяй отсюдо, по добру, по здорову");
$url = array(
'#^[a-z0-9]+[/]{1}[a-zA-Z0-9_]+[\.]html$#' => 'news',
);
aplication/controllers/welocme.php<?php
class welcome extends user_controller
{
public function index()
{
$this->cookie->set("kuka", "kuka", time()+3600);
$this->load->view('test', array('kuka'=>$this->cookie->get("kuka")));
$this->http->send('content-type: text/html; charset=utf-8');
}
}
aplication/views/test.php<?php
echo $kuka;