Skip to content

Commit

Permalink
validator update
Browse files Browse the repository at this point in the history
  • Loading branch information
drunyacoder committed Mar 15, 2014
1 parent 29b50ea commit e99154b
Show file tree
Hide file tree
Showing 5 changed files with 219 additions and 119 deletions.
2 changes: 2 additions & 0 deletions changes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ v2.5 RC1 *

64. Фикс CSS3 лоадера при логине.

65. Апдейт валидатора.



**************************
Expand Down
76 changes: 26 additions & 50 deletions modules/news/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -592,22 +592,16 @@ public function add_form ()
}


// Check for preview or errors
$data = array('title' => null, 'main_text' => null, 'in_cat' => null, 'description' => null, 'tags' => null,
'sourse' => null, 'sourse_email' => null, 'sourse_site' => null, 'commented' => null, 'available' => null);
$data = array_merge($data, $markers);
$data = Validate::getCurrentInputsValues($data);


$data = $this->Register['Validate']->getAndMergeFormPost($this->getValidateRules(), $markers);
$data['preview'] = $this->Parser->getPreview($data['main_text']);
$data['errors'] = $this->Parser->getErrors();
$data['errors'] = $this->Register['Validate']->getErrors();
if (isset($_SESSION['viewMessage'])) unset($_SESSION['viewMessage']);
if (isset($_SESSION['FpsForm'])) unset($_SESSION['FpsForm']);


$SectionsModel = $this->Register['ModManager']->getModelInstance($this->module . 'Sections');
$sql = $SectionsModel->getCollection();
$data['cats_selector'] = $this->_buildSelector($sql, ((!empty($data['in_cat'])) ? $data['in_cat'] : false));
$data['cats_selector'] = $this->_buildSelector($sql, ((!empty($data['cats_selector'])) ? $data['cats_selector'] : false));


//comments and hide
Expand Down Expand Up @@ -657,56 +651,29 @@ public function add()
}


$errors .= $this->Register['Validate']->check($this->getValidateRules());


$fields = array('description', 'tags', 'sourse', 'sourse_email', 'sourse_site');
$fields_settings = $this->Register['Config']->read('fields', $this->module);
foreach ($fields as $field) {
if (empty($_POST[$field]) && in_array($field, $fields_settings)) {
$$field = null;
} else {
$$field = trim($_POST[$field]);
}
}

// Обрезаем переменные до длины, указанной в параметре maxlength тега input
$title = trim(mb_substr($_POST['title'], 0, 128));
$add = trim($_POST['main_text']);
$in_cat = intval($_POST['cats_selector']);
$commented = (!empty($_POST['commented'])) ? 1 : 0;
$available = (!empty($_POST['available'])) ? 1 : 0;
$errors .= $this->Register['Validate']->check($this->getValidateRules());
$form_fields = $this->Register['Validate']->getFormFields($this->getValidateRules());

// Если пользователь хочет посмотреть на сообщение перед отправкой
if ( isset( $_POST['viewMessage'] ) ) {
$_SESSION['viewMessage'] = array_merge(array('title' => null, 'main_text' => null, 'in_cat' => $in_cat,
'description' => null, 'tags' => null, 'sourse' => null, 'sourse_email' => null,
'sourse_site' => null, 'commented' => null, 'available' => null), $_POST);
$_SESSION['viewMessage'] = array_merge($form_fields, $_POST);
redirect('/' . $this->module . '/add_form/');
}


if (!empty($in_cat)) {

if (!empty($_POST['cats_selector'])) {
$categoryModel = $this->Register['ModManager']->getModelInstance($this->module . 'Sections');
$cat = $categoryModel->getById($in_cat);
$cat = $categoryModel->getById($_POST['cats_selector']);
if (empty($cat)) $errors .= '<li>' . __('Can not find category') . '</li>'."\n";
}


// Errors
if (!empty($errors)) {
$_SESSION['FpsForm'] = array_merge(array('title' => null, 'main_text' => null, 'in_cat' => $in_cat,
'description' => null, 'tags' => null, 'sourse' => null, 'sourse_email' => null,
'sourse_site' => null, 'commented' => null, 'available' => null), $_POST);
$_SESSION['FpsForm']['error'] = '<p class="errorMsg">' . __('Some error in form') . '</p>'.
"\n".'<ul class="errorMsg">' . "\n" . $errors . '</ul>' . "\n";
$_SESSION['FpsForm'] = array_merge($form_fields, $_POST);
$_SESSION['FpsForm']['error'] = $this->Register['Validate']->wrapErrors($errors);
redirect('/' . $this->module . '/add_form/');
}


if (!$this->ACL->turn(array($this->module, 'record_comments_management'), false)) $commented = '1';
if (!$this->ACL->turn(array($this->module, 'hide_material'), false)) $available = '1';


// Защита от того, чтобы один пользователь не добавил
// 100 материалов за одну минуту
if ( isset( $_SESSION['unix_last_post'] ) and ( time()-$_SESSION['unix_last_post'] < 10 ) ) {
Expand All @@ -717,7 +684,7 @@ public function add()
// Auto tags generation
if (empty($tags)) {
$TagGen = new MetaTags;
$tags = $TagGen->getTags($add);
$tags = $TagGen->getTags($_POST['main_text']);
$tags = (!empty($tags) && is_array($tags)) ? implode(',', array_keys($tags)) : '';
}

Expand All @@ -726,15 +693,25 @@ public function add()
$this->Register['Cache']->clean(CACHE_MATCHING_ANY_TAG, array('module_' . $this->module));
$this->DB->cleanSqlCache();

// Формируем SQL-запрос на добавление темы
// SQL query to add row
$post = $this->Register['Validate']->getAndMergeFormPost($this->getValidateRules(), array(), true);
extract($post);

// Обрезаем переменные до длины, указанной в параметре maxlength тега input
$commented = (!empty($_POST['commented'])) ? 1 : 0;
$available = (!empty($_POST['available'])) ? 1 : 0;
if (!$this->ACL->turn(array($this->module, 'record_comments_management'), false)) $commented = '1';
if (!$this->ACL->turn(array($this->module, 'hide_material'), false)) $available = '1';


$max_lenght = $this->Register['Config']->read('max_lenght', $this->module);
$add = mb_substr($add, 0, $max_lenght);
$add = mb_substr($main_text, 0, $max_lenght);
$res = array(
'title' => $title,
'main' => $add,
'date' => new Expr('NOW()'),
'author_id' => $_SESSION['user']['id'],
'category_id' => $in_cat,
'category_id' => $cats_selector,
'description' => $description,
'tags' => $tags,
'sourse' => $sourse,
Expand All @@ -745,7 +722,6 @@ public function add()
'view_on_home' => $cat->getView_on_home(),
'premoder' => 'confirmed',
);

if ($this->ACL->turn(array($this->module, 'materials_require_premoder'), false)) {
$res['premoder'] = 'nochecked';
}
Expand Down
5 changes: 4 additions & 1 deletion sys/inc/bootstrap.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,10 @@ public function __construct()
$this->Register['ACL'] = new ACL(ROOT . '/sys/settings/');
$this->Register['Cache'] = new Cache;
$this->Register['PrintText'] = new PrintText;
$this->Register['Validate'] = new Validate();
$this->Register['Validate'] = new Validate(function($errors){
$viewer = new Fps_Viewer_Manager(new Fps_Viewer_Loader());
return $viewer->view('infomessage.html', array('info_message' => $errors));
});
$this->Register['ModManager'] = new ModulesManager(ROOT . '/sys/settings/modules_access.php');
$this->Register['PluginController'] = new Plugins;
$this->Register['URL'] = new AtmUrl;
Expand Down
14 changes: 4 additions & 10 deletions sys/inc/module.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
| @Author: Andrey Brykin (Drunya) |
| @Email: [email protected] |
| @Site: http://fapos.net |
| @Version: 1.5.9 |
| @Version: 1.6.2 |
| @Project: CMS |
| @Package CMS Fapos |
| @Subpackege Module Class |
| @Copyright ©Andrey Brykin 2010-2013 |
| @Last mod. 2013/04/24 |
| @Copyright ©Andrey Brykin |
| @Last mod. 2014/03/14 |
\-----------------------------------------------*/

/*-----------------------------------------------\
Expand Down Expand Up @@ -76,7 +76,7 @@ class Module {
/**
* @var database object
*/
protected $Database;
protected $DB;
/**
* uses for work with actions log
*
Expand All @@ -89,12 +89,6 @@ class Module {
* @var parser object
*/
protected $Parser;
/**
* contains system settings
*
* @var (array) system settings
*/
public $set;

/**
* Access control list
Expand Down
Loading

0 comments on commit e99154b

Please sign in to comment.