19:08
Этот коммит содержится в:
@@ -21,7 +21,6 @@ class CAPTCHAController extends Controller{
|
||||
$view->setHTTPHeader('Pragma: no-cache');
|
||||
$model = new Model();
|
||||
$view->image = $model->getImage();
|
||||
$_SESSION['CAPTCHA'] = $model->code;
|
||||
$view->render();
|
||||
}
|
||||
}
|
@@ -11,6 +11,8 @@ namespace PTEST\C;
|
||||
|
||||
use PFRM\Controller;
|
||||
use PFRM\View as View;
|
||||
use PTEST\M\AdModel as Model;
|
||||
use PTEST\M\CAPTCHAModel;
|
||||
|
||||
class IndexController extends Controller {
|
||||
|
||||
@@ -20,7 +22,78 @@ class IndexController extends Controller {
|
||||
$view->render();
|
||||
}
|
||||
|
||||
public function pageAction( $numder ) {
|
||||
print "number = ".$numder;
|
||||
public function pageAction( $number ) {
|
||||
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
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() {
|
||||
}
|
||||
|
||||
public function setUserName() {
|
||||
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 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() {
|
||||
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 {
|
||||
|
||||
public $code;
|
||||
public function verify( $code ) {
|
||||
return strtoupper( $code ) == $_SESSION['CAPTCHA'] ? true : "Неверный код с картинки";
|
||||
}
|
||||
|
||||
public function getImage() {
|
||||
global $app;
|
||||
@@ -58,7 +60,7 @@ class CAPTCHAModel {
|
||||
$image_data = ob_get_contents();
|
||||
ob_end_clean();
|
||||
|
||||
$this->code = $captcha;
|
||||
$_SESSION['CAPTCHA'] = $captcha;
|
||||
|
||||
return $image_data;
|
||||
}
|
||||
|
@@ -1,6 +1,8 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="ru-RU">
|
||||
<head>
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<meta charset="utf-8">
|
||||
<link rel="stylesheet" href="/css/style.css">
|
||||
<script src="/js/script.js"></script>
|
||||
|
41
src/V/new.php
Обычный файл
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');
|
||||
|
||||
$app = new PFRM\App();
|
||||
|
||||
$app->config = (object) [
|
||||
$config = (object) [
|
||||
"views_dir" => __DIR__ . '/V/',
|
||||
"public_dir" => dirname(__DIR__) . '/public/',
|
||||
"db" => (object) [
|
||||
@@ -27,8 +26,11 @@ $app->config = (object) [
|
||||
"site_name" => "Доска объявлений"
|
||||
];
|
||||
|
||||
$app = new PFRM\App( $config );
|
||||
|
||||
$app->setRoute( '/^\/CAPTCHA.png\?*\d*$/', 'CAPTCHA' );
|
||||
$app->setRoute( '|^/page/(?<id>\d+)/$|', 'Index', 'page');
|
||||
$app->setRoute( '|^/new/$|', 'Index', 'new');
|
||||
$app->setRoute( '|^/view_table/((?<id>\d+)/)*$|', 'Index', 'table');
|
||||
$app->setRoute( '/^.*$/', 'error404' );
|
||||
|
||||
|
Ссылка в новой задаче
Block a user