Этот коммит содержится в:
Igor V Belousov 2017-01-25 19:08:19 +03:00
родитель 656c7455bf
Коммит de702d59a4
13 изменённых файлов: 476 добавлений и 23 удалений

64
dump.sql Обычный файл
Просмотреть файл

@ -0,0 +1,64 @@
-- MySQL dump 10.15 Distrib 10.0.28-MariaDB, for debian-linux-gnueabihf (armv7l)
--
-- Host: ptest Database: ptest
-- ------------------------------------------------------
-- Server version 10.0.28-MariaDB-0+deb8u1
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;
/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
/*!40103 SET TIME_ZONE='+00:00' */;
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;
--
-- Current Database: `ptest`
--
-- CREATE DATABASE /*!32312 IF NOT EXISTS*/ `ptest` /*!40100 DEFAULT CHARACTER SET utf8 */;
-- USE `ptest`;
--
-- Table structure for table `Ad`
--
DROP TABLE IF EXISTS `Ad`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `Ad` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`username` varchar(255) NOT NULL,
`email` varchar(255) NOT NULL,
`homepage` varchar(255) DEFAULT NULL,
`ip` varchar(40) DEFAULT NULL,
`browser` varchar(1024) DEFAULT NULL,
`ptext` text,
`pdate` datetime DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Dumping data for table `Ad`
--
LOCK TABLES `Ad` WRITE;
/*!40000 ALTER TABLE `Ad` DISABLE KEYS */;
/*!40000 ALTER TABLE `Ad` ENABLE KEYS */;
UNLOCK TABLES;
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;
/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
-- Dump completed on 2017-01-25 0:47:49

Просмотреть файл

@ -17,12 +17,30 @@ class App {
protected $route_table; protected $route_table;
function __construct() { public $dbh;
public $config;
function __construct( $config ) {
$this->config = $config;
date_default_timezone_set('Europe/Moscow'); date_default_timezone_set('Europe/Moscow');
error_reporting(E_ALL); error_reporting(E_ALL);
$this->user_agent = $_SERVER['HTTP_USER_AGENT']; $this->user_agent = $_SERVER['HTTP_USER_AGENT'];
$this->user_IP = $_SERVER['REMOTE_ADDR']; $this->user_IP = $_SERVER['REMOTE_ADDR'];
$this->setRoute( '|^/$|', 'Index', 'index' ); $this->setRoute( '|^/$|', 'Index', 'index' );
$dsn = 'mysql:host=' . $this->config->db->host
. ';dbname=' . $this->config->db->dbname . ';charset=utf8';
try {
$this->dbh = new \PDO(
$dsn,
$this->config->db->user,
$this->config->db->password
);
} catch (\PDOException $exception) {
die( 'Нет подключения к MySQL: ' . $exception->getMessage() );
}
} }
/** /**
@ -43,6 +61,18 @@ class App {
return $this->user_IP; return $this->user_IP;
} }
public function getPostObj( $array ) {
$out = [];
foreach ( $array as $value ) {
if ( isset( $_POST[ $value ] ) ) {
$out[ $value ] = $_POST[ $value ];
} else {
$out[ $value ] = false;
}
}
return (object) $out;
}
/** /**
* Установка маршрута * Установка маршрута
* *
@ -64,6 +94,13 @@ class App {
exit(0); exit(0);
} }
public function routeRun( $controller, $action = 'index', $params = [] ) {
$a = $this->config->controller_namespace . $controller . 'Controller';
$obj = new $a;
call_user_func_array( [ $obj, $action . 'Action' ], $params );
exit(0);
}
/** /**
* Запуск маршрутов * Запуск маршрутов
*/ */

62
frm/Model.php Обычный файл
Просмотреть файл

@ -0,0 +1,62 @@
<?php
/**
* Created by PhpStorm.
* User: Игорь
* Date: 24.01.2017
* Time: 12:47
*/
namespace PFRM;
use PTEST\M\AdModel;
class Model {
protected $_table_name;
public $app;
function __construct() {
global $app;
$this->app = $app;
$this->_table_name = preg_replace( '/^.*\\\(.*)Model$/', "$1", get_called_class() );
}
public function save() {
$operation = "INSERT INTO ";
$suffix = "";
if ( isset( $this->table_id ) ) {
$operation = "UPDATE ";
$suffix = " WHERE id = :id";
}
$table_columns = NULL;
$pseudo_columns = NULL;
foreach ($this as $key => $value ) {
if ( preg_match('/^table_(?<name>.*)/', $key, $matches) ) {
if ( $matches['name'] != 'id' && isset( $this->$key ) ) {
$table_columns[] = $matches['name'];
$pseudo_columns[] = ':' . $matches['name'];
}
}
}
if ( is_array( $table_columns ) ) {
$names = ' ( ' . implode( ',', $table_columns ) . ' ) ';
$pseudo_names = ' ( ' . implode( ',', $pseudo_columns ) . ' ) ';
$stmt = $this->app->dbh->prepare( $operation . $this->_table_name . $names . ' VALUES ' . $pseudo_names . $suffix );
foreach ($table_columns as $value) {
$tmp_str = 'table_' . $value;
$stmt->bindParam( ':' . $value, $this->$tmp_str );
}
if ( isset( $this->table_id ) ) {
$stmt->bindParam( ':id', $this->table_id );
}
$stmt->execute();
}
}
static public function findFirst( $condition ) {
}
}

Просмотреть файл

@ -71,3 +71,35 @@ a
& > img & > img
-w (320/2) -w (320/2)
-h (120/2) -h (120/2)
clear both
-d block
form
-w 320
.form-element
-m 0 -8 10 -8
-p 6 8
&--error
-bg #ffeeee
background -moz-repeating-linear-gradient(-45deg,transparent 0px,transparent 11px,rgba(255,0,0,.2)12px), -moz-repeating-linear-gradient(45deg,transparent 0px,transparent 11px,rgba(255,0,0,.2)12px)
background -webkit-repeating-linear-gradient(-45deg,transparent 0px,transparent 11px,rgba(255,0,0,.2)12px), -webkit-repeating-linear-gradient(45deg,transparent 0px,transparent 11px,rgba(255,0,0,.2)12px)
background repeating-linear-gradient(-45deg,transparent 0px,transparent 11px,rgba(255,0,0,.2)12px), repeating-linear-gradient(45deg,transparent 0px,transparent 11px,rgba(255,0,0,.2)12px)
-ff _ffa
-fs 15
-lh 30
-fw 700
-c #111
&__input
&__textarea
-w 100%
outline none
-br 0 none
-brb 2 solid $link_color_border
transit border-bottom .15s ease-out 0s
-p 4 0
&:focus
-brb 2 solid $link_hover_color_border

Просмотреть файл

@ -1 +1 @@
html{font-family:sans-serif;line-height:1.15;-ms-text-size-adjust:100%;-webkit-text-size-adjust:100%}body{margin:0}article,aside,footer,header,nav,section{display:block}h1{font-size:2em;margin:.67em 0}figcaption,figure,main{display:block}figure{margin:1em 40px}hr{box-sizing:content-box;height:0;overflow:visible}pre{font-family:monospace,monospace;font-size:1em}a{background-color:transparent;-webkit-text-decoration-skip:objects}a:active,a:hover{outline-width:0}abbr[title]{border-bottom:none;text-decoration:underline dotted}b,strong{font-weight:bolder}code,kbd,samp{font-family:monospace,monospace;font-size:1em}dfn{font-style:italic}mark{background-color:#ff0;color:#000}small{font-size:80%}sub,sup{font-size:75%;line-height:0;position:relative;vertical-align:baseline}sub{bottom:-.25em}sup{top:-.5em}audio,video{display:inline-block}audio:not([controls]){display:none;height:0}img{border-style:none}svg:not(:root){overflow:hidden}button,input,optgroup,select,textarea{font-family:sans-serif;font-size:100%;line-height:1.15;margin:0}button,input{overflow:visible}button,select{text-transform:none}button,html [type="button"],[type="reset"],[type="submit"]{-webkit-appearance:button}button::-moz-focus-inner,[type="button"]::-moz-focus-inner,[type="reset"]::-moz-focus-inner,[type="submit"]::-moz-focus-inner{border-style:none;padding:0}button:-moz-focusring,[type="button"]:-moz-focusring,[type="reset"]:-moz-focusring,[type="submit"]:-moz-focusring{outline:1px dotted ButtonText}fieldset{border:1px solid silver;margin:0 2px;padding:.35em .625em .75em}legend{box-sizing:border-box;color:inherit;display:table;max-width:100%;padding:0;white-space:normal}progress{display:inline-block;vertical-align:baseline}textarea{overflow:auto}[type="checkbox"],[type="radio"]{box-sizing:border-box;padding:0}[type="number"]::-webkit-inner-spin-button,[type="number"]::-webkit-outer-spin-button{height:auto}[type="search"]{-webkit-appearance:textfield;outline-offset:-2px}[type="search"]::-webkit-search-cancel-button,[type="search"]::-webkit-search-decoration{-webkit-appearance:none}::-webkit-file-upload-button{-webkit-appearance:button;font:inherit}details,menu{display:block}summary{display:list-item}canvas{display:inline-block}template,[hidden]{display:none}body{font-family:Verdana,"Geneva CY","DejaVu Sans",sans-serif;font-size:16px}a{color:#0063ff;text-decoration:none;border-bottom:1px solid rgba(0,99,255,.3)}a:visited{color:#cf00cf;border-bottom-color:rgba(207,0,207,.3)}a:hover,a:visited:hover{color:#ff475d;border-bottom-color:rgba(255,71,93,.24)}.page__container{max-width:800px;margin:0 auto}.header{padding:30px;background:#ffcc56;background:-moz-repeating-linear-gradient(178deg,rgba(255,204,86,.5)8px,rgba(255,140,0,.5)18px);background:-webkit-repeating-linear-gradient(178deg,rgba(255,204,86,.5)8px,rgba(255,140,0,.5)18px);background:repeating-linear-gradient(178deg,rgba(255,204,86,.5)8px,rgba(255,140,0,.5)18px);-moz-box-shadow:2px 3px 15px #eb4 inset;-webkit-box-shadow:2px 3px 15px #eb4 inset;box-shadow:2px 3px 15px #eb4 inset;-webkit-border-radius:2px;-moz-border-radius:2px;-o-border-radius:2px;-ms-border-radius:2px;-khtml-border-radius:2px;border-radius:2px;margin-top:30px;margin-bottom:60px;text-align:center}.header__title{line-height:1;margin:0;font-family:"Times New Roman","Times CY","Nimbus Roman No9 L",serif;font-style:italic;text-shadow:1px 1px 1px #a76f19;font-size:52px}.page-title{padding-bottom:35px}.content{padding-bottom:76px}.footer{border-top:1px solid #dead6f;padding-top:24px;font-size:85%;color:#232425;padding-bottom:40px}#CAPTCHA>img{width:160px;height:60px} html{font-family:sans-serif;line-height:1.15;-ms-text-size-adjust:100%;-webkit-text-size-adjust:100%}body{margin:0}article,aside,footer,header,nav,section{display:block}h1{font-size:2em;margin:.67em 0}figcaption,figure,main{display:block}figure{margin:1em 40px}hr{box-sizing:content-box;height:0;overflow:visible}pre{font-family:monospace,monospace;font-size:1em}a{background-color:transparent;-webkit-text-decoration-skip:objects}a:active,a:hover{outline-width:0}abbr[title]{border-bottom:none;text-decoration:underline dotted}b,strong{font-weight:bolder}code,kbd,samp{font-family:monospace,monospace;font-size:1em}dfn{font-style:italic}mark{background-color:#ff0;color:#000}small{font-size:80%}sub,sup{font-size:75%;line-height:0;position:relative;vertical-align:baseline}sub{bottom:-.25em}sup{top:-.5em}audio,video{display:inline-block}audio:not([controls]){display:none;height:0}img{border-style:none}svg:not(:root){overflow:hidden}button,input,optgroup,select,textarea{font-family:sans-serif;font-size:100%;line-height:1.15;margin:0}button,input{overflow:visible}button,select{text-transform:none}button,html [type="button"],[type="reset"],[type="submit"]{-webkit-appearance:button}button::-moz-focus-inner,[type="button"]::-moz-focus-inner,[type="reset"]::-moz-focus-inner,[type="submit"]::-moz-focus-inner{border-style:none;padding:0}button:-moz-focusring,[type="button"]:-moz-focusring,[type="reset"]:-moz-focusring,[type="submit"]:-moz-focusring{outline:1px dotted ButtonText}fieldset{border:1px solid silver;margin:0 2px;padding:.35em .625em .75em}legend{box-sizing:border-box;color:inherit;display:table;max-width:100%;padding:0;white-space:normal}progress{display:inline-block;vertical-align:baseline}textarea{overflow:auto}[type="checkbox"],[type="radio"]{box-sizing:border-box;padding:0}[type="number"]::-webkit-inner-spin-button,[type="number"]::-webkit-outer-spin-button{height:auto}[type="search"]{-webkit-appearance:textfield;outline-offset:-2px}[type="search"]::-webkit-search-cancel-button,[type="search"]::-webkit-search-decoration{-webkit-appearance:none}::-webkit-file-upload-button{-webkit-appearance:button;font:inherit}details,menu{display:block}summary{display:list-item}canvas{display:inline-block}template,[hidden]{display:none}body{font-family:Verdana,"Geneva CY","DejaVu Sans",sans-serif;font-size:16px}a{color:#0063ff;text-decoration:none;border-bottom:1px solid rgba(0,99,255,.3)}a:visited{color:#cf00cf;border-bottom-color:rgba(207,0,207,.3)}a:hover,a:visited:hover{color:#ff475d;border-bottom-color:rgba(255,71,93,.24)}.page__container{max-width:800px;margin:0 auto}.header{padding:30px;background:#ffcc56;background:-moz-repeating-linear-gradient(178deg,rgba(255,204,86,.5)8px,rgba(255,140,0,.5)18px);background:-webkit-repeating-linear-gradient(178deg,rgba(255,204,86,.5)8px,rgba(255,140,0,.5)18px);background:repeating-linear-gradient(178deg,rgba(255,204,86,.5)8px,rgba(255,140,0,.5)18px);-moz-box-shadow:2px 3px 15px #eb4 inset;-webkit-box-shadow:2px 3px 15px #eb4 inset;box-shadow:2px 3px 15px #eb4 inset;-webkit-border-radius:2px;-moz-border-radius:2px;-o-border-radius:2px;-ms-border-radius:2px;-khtml-border-radius:2px;border-radius:2px;margin-top:30px;margin-bottom:60px;text-align:center}.header__title{line-height:1;margin:0;font-family:"Times New Roman","Times CY","Nimbus Roman No9 L",serif;font-style:italic;text-shadow:1px 1px 1px #a76f19;font-size:52px}.page-title{padding-bottom:35px}.content{padding-bottom:76px}.footer{border-top:1px solid #dead6f;padding-top:24px;font-size:85%;color:#232425;padding-bottom:40px}#CAPTCHA>img{width:160px;height:60px;clear:both;display:block}form{width:320px}.form-element{margin:0 -8px 10px;padding:6px 8px}.form-element--error{background:#fee;background:-moz-repeating-linear-gradient(-45deg,transparent 0,transparent 11px,rgba(255,0,0,.2)12px),-moz-repeating-linear-gradient(45deg,transparent 0,transparent 11px,rgba(255,0,0,.2)12px);background:-webkit-repeating-linear-gradient(-45deg,transparent 0,transparent 11px,rgba(255,0,0,.2)12px),-webkit-repeating-linear-gradient(45deg,transparent 0,transparent 11px,rgba(255,0,0,.2)12px);background:repeating-linear-gradient(-45deg,transparent 0,transparent 11px,rgba(255,0,0,.2)12px),repeating-linear-gradient(45deg,transparent 0,transparent 11px,rgba(255,0,0,.2)12px);font-family:Arial,"Helvetica CY","Nimbus Sans L",sans-serif;font-size:15px;line-height:30px;font-weight:700;color:#111}.form-element__input,.form-element__textarea{width:100%;outline:none;border:0 none;border-bottom:2px solid rgba(0,99,255,.3);-webkit-transition:border-bottom .15s ease-out 0s;-moz-transition:border-bottom .15s ease-out 0s;-o-transition:border-bottom .15s ease-out 0s;transition:border-bottom .15s ease-out 0s;padding:4px 0}.form-element__input:focus,.form-element__textarea:focus{border-bottom:2px solid rgba(255,71,93,.24)}

Просмотреть файл

@ -261,4 +261,40 @@ a:visited:hover {
#CAPTCHA > img { #CAPTCHA > img {
width: 160px; width: 160px;
height: 60px; height: 60px;
clear: both;
display: block;
}
form {
width: 320px;
}
.form-element {
margin: 0 -8px 10px -8px;
padding: 6px 8px;
}
.form-element--error {
background: #fee;
background: -moz-repeating-linear-gradient(-45deg, transparent 0px, transparent 11px, rgba(255,0,0,0.2) 12px), -moz-repeating-linear-gradient(45deg, transparent 0px, transparent 11px, rgba(255,0,0,0.2) 12px);
background: -webkit-repeating-linear-gradient(-45deg, transparent 0px, transparent 11px, rgba(255,0,0,0.2) 12px), -webkit-repeating-linear-gradient(45deg, transparent 0px, transparent 11px, rgba(255,0,0,0.2) 12px);
background: repeating-linear-gradient(-45deg, transparent 0px, transparent 11px, rgba(255,0,0,0.2) 12px), repeating-linear-gradient(45deg, transparent 0px, transparent 11px, rgba(255,0,0,0.2) 12px);
font-family: Arial, "Helvetica CY", "Nimbus Sans L", sans-serif;
font-size: 15px;
line-height: 30px;
font-weight: 700;
color: #111;
}
.form-element__input,
.form-element__textarea {
width: 100%;
outline: none;
border: 0 none;
border-bottom: 2px solid rgba(0,99,255,0.3);
-webkit-transition: border-bottom 0.15s ease-out 0s;
-moz-transition: border-bottom 0.15s ease-out 0s;
-o-transition: border-bottom 0.15s ease-out 0s;
transition: border-bottom 0.15s ease-out 0s;
padding: 4px 0;
}
.form-element__input:focus,
.form-element__textarea:focus {
border-bottom: 2px solid rgba(255,71,93,0.24);
} }

Просмотреть файл

@ -21,7 +21,6 @@ class CAPTCHAController extends Controller{
$view->setHTTPHeader('Pragma: no-cache'); $view->setHTTPHeader('Pragma: no-cache');
$model = new Model(); $model = new Model();
$view->image = $model->getImage(); $view->image = $model->getImage();
$_SESSION['CAPTCHA'] = $model->code;
$view->render(); $view->render();
} }
} }

Просмотреть файл

@ -11,6 +11,8 @@ namespace PTEST\C;
use PFRM\Controller; use PFRM\Controller;
use PFRM\View as View; use PFRM\View as View;
use PTEST\M\AdModel as Model;
use PTEST\M\CAPTCHAModel;
class IndexController extends Controller { class IndexController extends Controller {
@ -20,7 +22,78 @@ class IndexController extends Controller {
$view->render(); $view->render();
} }
public function pageAction( $numder ) { public function pageAction( $number ) {
print "number = ".$numder;
}
public function newAction() {
$view = new View('new');
$view->page_title = 'Новое объявление';
if ($_SERVER['REQUEST_METHOD']=='POST'){
$errors = NULL;
$model = new Model();
$posts = $this->app->getPostObj([ 'name', 'email', 'homepage', 'CAPTCHA', 'text']);
if ( $posts->name ) {
$not_err = $model->setUserName($posts->name);
if ( $not_err !== true ) {
$errors['name'] = $not_err;
}
} else {
$errors['name'] = "Обязательное поле";
}
if ( $posts->email ) {
$not_err = $model->setEmail($posts->email);
if ( $not_err !== true ) {
$errors['email'] = $not_err;
}
} else {
$errors['email'] = "Обязательное поле";
}
if ( $posts->homepage ) {
$not_err = $model->setHomepage($posts->homepage);
if ( $not_err !== true ) {
$errors['homepage'] = $not_err;
}
}
if ( $posts->CAPTCHA ) {
$CAPTCHA_model = new CAPTCHAModel();
$not_err = $CAPTCHA_model->verify( $posts->CAPTCHA );
if ( $not_err !== true ) {
$errors['CAPTCHA'] = $not_err;
}
} else {
$errors['CAPTCHA'] = "Обязательное поле";
}
if ( $posts->text ) {
$model->setText($posts->text);
} else {
$errors['text'] = "Обязательное поле";
}
if ( is_array( $errors ) ) {
$view->errors = (object) $errors;
$view->post_data = $posts;
$view->render();
return;
} else {
$model->setBrowser( $this->app->getUserAgent() );
$model->setIp( $this->app->getUserIP() );
$model->setDate( date("Y-m-d H:i:s") );
$model->save();
$this->app->Redirect('/');
return;
}
}
$view->render();
} }
} }

Просмотреть файл

@ -8,36 +8,139 @@
namespace PTEST\M; namespace PTEST\M;
use PFRM\Model;
class AdModel { class AdModel extends Model{
protected $id; protected $table_id;
protected $username; protected $table_username;
protected $email; protected $table_email;
protected $ip; protected $table_homepage;
protected $browser; protected $table_ip;
protected $text; protected $table_browser;
protected $date; protected $table_ptext;
function __construct() { protected $table_pdate;
/**
* @param $username
*
* @return bool|string
*/
public function setUserName( $username ) {
if ( preg_match( '/[a-z,\d]{3,}/i', $username ) ) {
$this->table_username = $username;
return true;
} else {
return "Только цифры и буквы латинского алфавита, минимум 3";
} }
public function setUserName() {
} }
public function getUserName(){ public function getUserName(){
return $this->username; return $this->table_username;
} }
/**
* @param mixed $email
*
* @return bool|string
*/
public function setEmail( $email ) {
if ( preg_match('/.+@.+\..+/i', $email ) ) {
$this->table_email = $email;
return true;
} else {
return "Введите коректный e-mail адрес";
}
}
/**
* @return mixed
*/
public function getEmail() { public function getEmail() {
return $this->email; return $this->table_email;
} }
/**
* @param mixed $homepage
*
* @return bool|string
*/
public function setHomepage( $homepage ) {
if ( preg_match('|https?://.*\..*|i', $homepage ) ) {
$this->table_homepage = $homepage;
return true;
} else {
return "Введите коректный адрес";
}
}
/**
* @return mixed
*/
public function getHomepage() {
return $this->table_homepage;
}
/**
* @param mixed $ip
*/
public function setIp( $ip ) {
$this->table_ip = $ip;
}
/**
* @return mixed
*/
public function getIp() {
return $this->table_ip;
}
/**
* @param mixed $browser
*/
public function setBrowser( $browser ) {
$this->table_browser = $browser;
}
/**
* @return mixed
*/
public function getBrowser() {
return $this->table_browser;
}
/**
* @param mixed $text
*/
public function setText( $text ) {
$this->table_ptext = strip_tags($text);
}
/**
* @return mixed
*/
public function getText() {
return $this->table_ptext;
}
/**
* @param mixed $date
*/
public function setDate( $date ) {
$this->table_pdate = $date;
}
/**
* @return mixed
*/
public function getDate() {
return $this->table_pdate;
}
} }

Просмотреть файл

@ -11,7 +11,9 @@ namespace PTEST\M;
class CAPTCHAModel { class CAPTCHAModel {
public $code; public function verify( $code ) {
return strtoupper( $code ) == $_SESSION['CAPTCHA'] ? true : "Неверный код с картинки";
}
public function getImage() { public function getImage() {
global $app; global $app;
@ -58,7 +60,7 @@ class CAPTCHAModel {
$image_data = ob_get_contents(); $image_data = ob_get_contents();
ob_end_clean(); ob_end_clean();
$this->code = $captcha; $_SESSION['CAPTCHA'] = $captcha;
return $image_data; return $image_data;
} }

Просмотреть файл

@ -1,6 +1,8 @@
<!DOCTYPE html> <!DOCTYPE html>
<html lang="ru-RU"> <html lang="ru-RU">
<head> <head>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta charset="utf-8"> <meta charset="utf-8">
<link rel="stylesheet" href="/css/style.css"> <link rel="stylesheet" href="/css/style.css">
<script src="/js/script.js"></script> <script src="/js/script.js"></script>

41
src/V/new.php Обычный файл
Просмотреть файл

@ -0,0 +1,41 @@
<?php
require __DIR__ . '/inc/head.php';
ob_start();
?>
<article>
<h1 class="page-title"><?php echo $this->page_title ?></h1>
<div class="content">
<form action="" method="post">
<div class="form-element<?php echo ($this->errors->name)?' form-element--error':''; ?>">
<input class="form-element__input" type="text" name="name" placeholder="Имя" tabindex="1" value="<?php echo ($this->post_data->name)?$this->post_data->name:'';?>">
<div class="form-element__error"><?php echo ($this->errors->name)?$this->errors->name:''; ?></div>
</div>
<div class="form-element<?php echo ($this->errors->email)?' form-element--error':''; ?>">
<input class="form-element__input" type="text" name="email" placeholder="e-mail" tabindex="2" value="<?php echo ($this->post_data->email)?$this->post_data->email:'';?>">
<div class="form-element__error"><?php echo ($this->errors->email)?$this->errors->email:''; ?></div>
</div>
<div class="form-element<?php echo ($this->errors->homepage)?' form-element--error':''; ?>">
<input class="form-element__input" type="text" name="homepage" placeholder="Домашняя страница" tabindex="3" value="<?php echo ($this->post_data->homepage)?$this->post_data->homepage:'';?>">
<div class="form-element__error"><?php echo ($this->errors->homepage)?$this->errors->homepage:''; ?></div>
</div>
<div id="CAPTCHA" class="form-element<?php echo ($this->errors->CAPTCHA)?' form-element--error':''; ?>">
<img src="/CAPTCHA.png?<?php echo rand(1000,9999) . time(); ?>" alt="">
<input class="form-element__input" type="text" name="CAPTCHA" placeholder="Введите текст с картинки" tabindex="4">
<div class="form-element__error"><?php echo ($this->errors->CAPTCHA)?$this->errors->CAPTCHA:''; ?></div>
</div>
<div class="form-element<?php echo ($this->errors->text)?' form-element--error':''; ?>">
<textarea class="form-element__textarea" name="text" id="" cols="30" rows="10" placeholder="Текст объявления" tabindex="5"><?php echo ($this->post_data->text)?$this->post_data->text:'';?></textarea>
<div class="form-element__error"><?php echo ($this->errors->text)?$this->errors->text:''; ?></div>
</div>
<input type="submit" value="Отправить">
</form>
</div>
</article>
<?php
$this->content = ob_get_contents();
ob_end_clean();
require __DIR__ . '/inc/body.php';

Просмотреть файл

@ -11,9 +11,8 @@ require_once __DIR__ . '/../vendor/autoload.php';
setlocale(LC_ALL,'ru_RU.UTF-8'); setlocale(LC_ALL,'ru_RU.UTF-8');
$app = new PFRM\App();
$app->config = (object) [ $config = (object) [
"views_dir" => __DIR__ . '/V/', "views_dir" => __DIR__ . '/V/',
"public_dir" => dirname(__DIR__) . '/public/', "public_dir" => dirname(__DIR__) . '/public/',
"db" => (object) [ "db" => (object) [
@ -27,8 +26,11 @@ $app->config = (object) [
"site_name" => "Доска объявлений" "site_name" => "Доска объявлений"
]; ];
$app = new PFRM\App( $config );
$app->setRoute( '/^\/CAPTCHA.png\?*\d*$/', 'CAPTCHA' ); $app->setRoute( '/^\/CAPTCHA.png\?*\d*$/', 'CAPTCHA' );
$app->setRoute( '|^/page/(?<id>\d+)/$|', 'Index', 'page'); $app->setRoute( '|^/page/(?<id>\d+)/$|', 'Index', 'page');
$app->setRoute( '|^/new/$|', 'Index', 'new');
$app->setRoute( '|^/view_table/((?<id>\d+)/)*$|', 'Index', 'table'); $app->setRoute( '|^/view_table/((?<id>\d+)/)*$|', 'Index', 'table');
$app->setRoute( '/^.*$/', 'error404' ); $app->setRoute( '/^.*$/', 'error404' );