:
, (. .4). .
. (. .5), (. .6).
(. .7). (. .8).
. .
. .9.
0.10 . 38.02 /. : html 2256 bytes (57.4%) css 1674 bytes (42.6%) 3930 bytes
3.
.
:
,
Smarty. Smarty.
, .
, .
Drupal Wordpress:
,
Drupal Wordpress:
1. , PHP MySQL :
2. , - PHP MySQL :
3. PHP MySQL :
4. PHP. , :
5. , PHP : -
6. . . PHP. : -
|
|
7. HTML, JavaScript, PHP MySQL. Web- : -
8. PHP : -
9. PHP/MySQL : -
10. PHP : -
. .1. Google Chrome 15.0.874.106 m
. .2. Internet explorer 7 64x
. .3. Opera v11.51
. .4.
. .5.
. .6.
. A.7.
. A.8.
. .9.
Index.php
//
define('ROOT', TRUE);
//
require_once('config.php');
//
header("Content-type: text/html; charset=".sait_charset);
//
session_start();
//
require_once(core_dir.'core.class.php');
$core = new core;
Config.php
if (!defined('ROOT')) die();
// : 0 - ; E_ALL -
error_reporting(E_ALL);
//
define('sait_charset', 'utf-8');
//
define('title_sait', 'Blogyyy - '); //
define('limit_entry', 5); //
define('core_dir', 'core/'); //
define('DB_NAME', "core/sqlite.db"); //
// Smarty
define('smarty_dir', core_dir.'smarty/Smarty.class.php'); //
define('smarty_template_dir', 'templates/'); //
define('smarty_compile_dir', 'tmp/templates_c/'); //
define('smarty_cache_dir', 'tmp/cache/'); //
define('smarty_caching', false); // (true) (false)
define('smarty_debugging', false); // (true) (false) smarty
Core.class.php
if (!defined("ROOT")) die;
/**
*
*
*
*/
class core
{
protected $smarty;
protected $func;
/**
*
*
*
*/
function __construct()
{
// Smarty
require_once(smarty_dir);
$this->smarty = new Smarty();
// Smarty
$this->smarty->template_dir = smarty_template_dir;
$this->smarty->compile_dir = smarty_compile_dir;
$this->smarty->cache_dir = smarty_cache_dir;
// Smarty
$this->smarty->caching = smarty_caching;
$this->smarty->debugging = smarty_debugging;
//
require_once('core/func.class.php');
$this->func= new func;
//
if (!file_exists(DB_NAME))
$this->page_reg(true);
else
$this->_Load();
}
/**
*
*
|
|
*
*/
private function _Load()
{
//
if (isset($_GET['c']))
$controler = trim(strip_tags($_GET['c']));
else
$controler = 'index';
//
switch ($controler)
{
case 'index':
$this->page_index();
break;
case 'add':
$this->page_edit();
break;
case 'creat':
$this->page_edit(true);
break;
case 'login':
$this->page_login();
break;
case 'logout':
$this->page_logout();
break;
case 'view':
$this->page_view_entry();
break;
case 'del':
$this->page_del();
break;
case 'reg':
$this->page_reg();
break;
case 'a_statistic':
$this->statistic();
break;
default:
$this->page_404();
break;
}
}
/**
*
*
* str: $page - Smarty templates
* str: $title -
* array: $data = array() -
* str: $head = "" - <head></head>
*
*/
protected function _LoadPage($page, $title, $data = array(), $head = '')
{
//
$this->smarty->assign('title', $title.' - '.title_sait);
$this->smarty->assign('page_title', $title);
$this->smarty->assign('title_sait', title_sait);
$this->smarty->assign('charset', sait_charset);
$this->smarty->assign('head', $head);
foreach ($data as $key=>$val)
$this->smarty->assign($key, $val);
//
$this->smarty->display('header.html');
$this->smarty->display($page.'.html');
$this->smarty->display('foter.html');
}
/**
*
*
*
*
*/
function page_index()
{
//
if (isset($_GET['page']))
{
$page = abs((int)$_GET['page']);
if ($page)
$this->func->page = $page;
}
//
$data['list_array'] = $this->func->read_list();
$data['nav'] = $this->func->nav;
$this->_LoadPage('view_index', ' ', $data);
}
/**
*
* 404
*
*/
private function page_404()
{
$this->_LoadPage('404', '404 ');
exit;
}
/**
*
* /
*
*/
private function page_edit($up = false)
{
//
if(!isset($_SESSION['id']))
$this->page_404();
//
if ($up){
$row = $this->func->view_entry($_GET['id']);
//
if ($_SESSION['id']!= $row['avtor'] and $_SESSION['UG']!= '7')
$this->page_404();
//
$this->func->title = $row['title'];
$this->func->entry = htmlspecialchars($row['entry']);
$this->func->anons = $row['anons'];
$id = $_GET['id'];
}else{
$id = null;
}
// post
if ($_SERVER['REQUEST_METHOD'] == 'POST')
$this->func->edit($_POST, $id);
//
$head = '<script type="text/javascript" src="ckeditor/ckeditor.js"></script>';
$data['error'] = $this->func->error;
$data['tems'] = $this->func->title;
$data['entry'] = $this->func->entry;
$data['anons'] = $this->func->anons;
if ($up)
$title = ' ';
else
$title = ' ';
$this->_LoadPage('edit', $title, $data, $head);
}
/**
*
*
*
*/
function statistic(){
if ($_SESSION['UG']!= 7)
$this->page_404();
if (isset($_GET['config']) && $_GET['config'] == 'del')
$this->func->del_user($_GET['id']);
if (isset($_GET['del_view']))
|
|
$this->func->del_entry($_GET['del_view']);
if (isset($_GET['config']) && $_GET['config'] == 'view'){
$row = $this->func->get_user_entry($_GET['id']);
$data['view_list'] = $row[0];
$data['user'] = $row[1]['name'];
$data['idd'] = $_GET['id'];
$this->_LoadPage('statistic_view', ' '.$row[1]['name'], $data);
exit();
}
$data['user_list'] = $this->func->get_user_list();
$this->_LoadPage('statistic', '', $data);
}
/**
*
*
*
*/
function page_view_entry()
{
$row = $this->func->view_entry($_GET['id']);
if ($row)
$this->_LoadPage('view_entry', $row['title'], array('list' => $row));
else
$this->page_404();
}
/**
*
*
*
*/
function page_login()
{
//
if ($row = $this->func->auth($_POST['login'], $_POST['pass'])){
// , id
$_SESSION['id'] = $row['id'];
$_SESSION['name'] = $row['name'];
$_SESSION['UG'] = $row['UG'];
$this->_LoadPage('message', '', array('message' => ", ".$row['name']));
}else{
//
$this->_LoadPage('message', '', array('message' => " /"));
}
}
/**
*
*
*
*/
function page_del()
{
//
if(!isset($_SESSION['id']))
$this->page_404();
if (!$this->func->del($_GET['id']))
$this->_LoadPage('message', ' ', array('message' => " !"));
}
/**
*
*
*
*/
function page_logout()
{
//
unset($_SESSION['id']);
unset($_SESSION['name']);
unset($_SESSION['UG']);
//
$this->_LoadPage('message', '', array('message' => " "));
}
/**
*
*
*
*/
private function page_reg($install = false)
{
if(isset($_SESSION['id']))
$this->page_404();
if ($_SERVER['REQUEST_METHOD'] == 'POST')
{
$this->func->reg($_POST, $install);
}
$data['error'] = $this->func->error;
$data['name'] = $this->func->name;
$data['login'] = $this->func->login;
$data['mail'] = $this->func->mail;
if ($install){
$data['reg_group'] = ' ';
$title = ' CMS Bloggg';
}else{
$data['reg_group'] = '';
$title = '';
}
$this->_LoadPage('reg', $title, $data);
}
}
Func.class.php
if (!defined("ROOT")) die;
/**
*
* , ,
*
*/
class func
{
protected $_db;
public $error;
public $title;
public $entry;
public $anons;
public $name;
public $login;
public $pass;
public $mail;
public $page = 1;
public $nav = false;
/**
*
*
*
*/
function __construct()
{
// SQLite
require_once(core_dir.'dblite.class.php');
$this->_db= new dblite;
}
/**
*
*
*
*/
function reg($post, $install=false)
{
//
$this->name = $this->valid($post['name']);
$this->login = $this->valid($post['login']);
$this->pass = $this->valid($post['pass']);
|
|
$this->mail = $this->valid($post['mail']);
if (empty($this->name))
$this->error.= '<p> <strong></strong> </p>';
if (empty($this->mail))
$this->error.= '<p> <strong>E-mail</strong> </p>';
if (!preg_match("/^([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]+)*@([a-z0-9\-]+\.)+[a-z]{2,6}$/ix", $this->mail))
$this->error.= '<p> <strong>E-mail</strong> e-mail </p>';
if (empty($this->login))
$this->error.= '<p> <strong></strong> </p>';
if (empty($this->pass))
$this->error.= '<p> <strong></strong> </p>';
if (md5($this->pass)!= md5($post['re_pass']))
$this->error.= '<p><strong></strong> </p>';
if (!$install)
{
$res = $this->_db->select('users', 'id', "login = '".md5($this->login)."'");
if ($res->fetch() &&!empty($this->login))
$this->error.= '<p> <strong></strong> </p>';
$res = $this->_db->select('users', 'id', "mail = '$this->mail'");
if ($res->fetch() &&!empty($this->mail))
$this->error.= '<p> <strong>E-mail\'</strong> </p>';
}
if ($this->error)
{
$this->set_error();
return false;
}
//
if ($install)
{
//
$this->_db->install();
$UG = 7; //
}else{
$UG = 5; //
}
//
$res = $this->_db->insert('users',
'id, name, login, pass, mail, UG', "'".time()."','".$this->name."',
'".md5($this->login)."', '".md5($this->pass)."', '".$this->mail."', '".$UG."'");
//
if($res)
{
mail($this->mail, ' !', ' ))) '.$this->login.'
. )))');
$_SESSION['name'] = $this->name;
$_SESSION['id'] = $this->_db->last_id;
$_SESSION['UG'] = $UG;
//
header('Location: /');
return true;
}else{
//
$this->error = "<p> .</p>";
$this->set_error();
return false;
}
}
/**
*
*
*
*/
function valid($val, $type = "str", $val_db=true)
{
switch ($type)
{
case "str":
$val = trim(strip_tags($val));
if ($val_db)
$val = sqlite_escape_string($val);
return $val;
break;
case "int":
$val = abs((int)$val);
if ($val_db)
$val = sqlite_escape_string($val);
return $val;
break;
case "text":
$val = trim($val);
$val = sqlite_escape_string($val);
return $val;
break;
default:
if ($val_db)
$val = sqlite_escape_string($val);
return $val;
break;
}
}
/**
*
*
*
*/
function edit($post, $id = null)
{
// ,
$this->title = $this->valid($post['tems']);
if(empty($this->title))
$this->error.= '<p> <strong></strong> </p>';
$this->entry = $this->valid($post['text'], "text");
if (empty($this->entry))
$this->error.= '<p> <strong></strong> </p>';
$this->anons = substr($this->valid($post['anons'], "str"), 0, 400);
if (empty($this->anons))
$this->error.= '<p> <strong></strong> </p>';
// false
if ($this->error)
{
$this->set_error();
return false;
}
//
if (!empty($id)){
$id = $this->valid($id, 'int');
$res = $this->_db->update('entry', "title='$this->title', anons='$this->anons', entry='$this->entry'", "id = '$id'");
}else{
$res = $this->_db->insert('entry', 'title, anons, entry, date, avtor', "'".$this->title."', '".$this->anons."', '".$this->entry."', '".time()."', '".$_SESSION['id']."'");
|
|
$id = $this->_db->last_id;
}
//
if($res)
{
//
header('Location: /?c=view&id='.$id);
return true;
}else{
//
$this->error = "<p> .</p>";
$this->set_error();
return false;
}
}
/**
*
* /
*
*/
function auth($login, $pass)
{
$login = md5($login);
$pass = md5($pass);
$res =$this->_db->select('users', 'id, name, UG', "login = '$login' and pass = '$pass'");
$row = $res->fetch(SQLITE_ASSOC);
return $row;
}
/**
*
*
*
*/
function get_user_entry($id){
$id = $this->valid($id, 'int');
$res = $this->_db->select('entry', 'id, title, date', "avtor = '$id'", "", "date desc");
$row[0] = $res->fetchAll(SQLITE_ASSOC);
$res = $this->_db->select('users', 'name', "id = '$id'");
$row[1] = $res->fetch(SQLITE_ASSOC);
return $row;
}
/**
*
*
*
*/
function get_user_list(){
$res =$this->_db->select('users', 'id, name, mail, UG');
$row = $res->fetchAll(SQLITE_ASSOC);
return $row;
}
/**
*
*
*
*/
function del_user($id){
$id = $this->valid($id, 'int');
$res = $this->_db->delete('users', 'id = "'.$id.'"');
return $res;
}
/**
*
*
*
*/
function del_entry($id){
$id = $this->valid($id, 'int');
$res = $this->_db->delete('entry', 'id = "'.$id.'"');
return $res;
}
/**
*
*
*
*/
function read_list()
{
//
$res =$this->_db->select('entry', 'COUNT(*)');
$row = $res->fetch();
// //
$num_entry = $row[0];
if ($num_entry > limit_entry)
{
$all_page = ceil($num_entry/limit_entry);
if ($this->page > 2)
$nav = '<b><a href="/"> </a></b>';
if ($this->page > 1)
$nav.= '<a href="/?page='.($this->page-1).'"></a>';
for ($i=1; $all_page+1; $i++)
{
if ($i == $this->page)
$nav.= "<b>$i</b>";
else
$nav.= "<a href='/?page=$i'>$i</a>";
}
if ($this->page+1 <= $this->all_page)
$nav.= '<a href="/?page='.($this->page+1).'"></a>';
if ($this->page < $all_page-1)
$nav.= "<b><a href='/?page={$all_page}'> </a></b>";
$this->nav = $nav;
}
//
$limit = limit_entry;
$end_limit = $this->page*limit_entry;
if ($end_limit>limit_entry)
$start_limit = $end_limit-limit_entry;
else
$start_limit = 0;
if ($end_limit>$num_entry)
$end_limit = $num_entry;
//
$res = $this->_db->select('entry JOIN users',
'entry.id id, title, anons, date, avtor, users.name name',
"entry.avtor = users.id", "$start_limit, $limit", "date desc");
//
if ($res)
return $res->fetchAll(SQLITE_ASSOC);
else
return false;
}
/**
*
*
*
*/
function view_entry($id)
{
$id = $this->valid($id, 'int');
$res = $this->_db->select('entry JOIN users',
'entry.id id, title, entry, anons, date, avtor, users.name name',
"entry.avtor = users.id and entry.id = '$id'");
if ($res)
return $res->fetch(SQLITE_ASSOC);
else
return false;
}
/**
*
*
*
*/
function del($id)
{
$id = $this->valid($id, 'int');
if ($_SESSION['UG'] == '7')
$res = $this->_db->delete('entry', "id = '$id'");
else
$res = $this->_db->delete('entry', "id = '$id' and avtor = '$_SESSION[id]'");
if($res)
header("Location: /");
else
return false;
}
/**
*
*
*
*/
function set_error()
{
$this->error = '<div class="error"><h3>:</h3>'.$this->error.'</div>';
}
}
Dblite.class.php
if (!defined("ROOT")) die;
/**
*
* SQLite
*
*/
class dblite
{
const tmp_ERROR = "tmp/sql_error.log";
protected $_db;
public $last_id;
/**
*
*
*
*
*
*/
function __construct(){
if (file_exists(DB_NAME))
$this->_db = new SQLiteDatabase(DB_NAME);
}
/**
*
*
*
*/
function install(){
$this->_db = new SQLiteDatabase(DB_NAME);
$sql = "CREATE TABLE entry(
id INTEGER PRIMARY KEY,
title TEXT,
anons TEXT,
entry TEXT,
date INTEGER,
avtor INTEGER
);";
$this->sql_try($sql);
$sql = "CREATE TABLE users(
id INTEGER PRIMARY KEY,
name TEXT,
login TEXT,
pass TEXT,
mail TEXT,
UG INTEGER
);";
$this->sql_try($sql);
}
/**
*
*
* str: $table -
* str: $from -
* str: $where - where
* str: $limit = "" -
* str: $order = "" -
*/
function select($table, $from, $where = "", $limit="", $order = ""){
$sql = "SELECT $from from $table";
if (!empty($where))
$sql.= " WHERE ".$where;
if (!empty($order))
$sql.= " ORDER BY ".$order;
if (!empty($limit))
$sql.= " LIMIT ".$limit;
if ($this->sql_try($sql))
return $this->_db->query($sql);
else
return false;
}
/**
*
*
* str: $table -
* str: $key -
* str: $val -
*/
function insert($table, $key, $val){
$sql = "INSERT INTO $table ($key) VALUES ($val)";
return $this->sql_try($sql);
}
/**
*
*
* str: $table -
* str: $item -
* str: $where - where
*/
function update($table, $item, $where){
$sql = "UPDATE $table SET $item WHERE $where";
return $this->sql_try($sql);
}
/**
*
*
* str: $table -
* str: $where - where
*/
function delete($table, $where){
$sql = "DELETE FROM $table WHERE $where";
return $this->sql_try($sql);
}
/**
*
*
* TRUE
* FALSE tmp_ERROR
*
*/
function sql_try($sql)
{
try{
$res = $this->_db->query($sql);
if (!$res)
throw new SQLiteException(sqlite_error_string($this->_db->lastError()));
$this->last_id = $this->_db->lastInsertRowid();
return true;
}catch(SQLiteException $e){
if(!file_exists(self::tmp_ERROR))
file_put_contents(self::tmp_ERROR, "$e \n");
else
file_put_contents(self::tmp_ERROR, file_get_contents(self::tmp_ERROR)."$e \n");
return false;
}
}
/**
*
*
*
*
*/
function __destruct(){
unset($this->_db);
}
}