Skip to content

Commit

Permalink
хук на удаление комментария, исправлена ошибка, когда при ошибке форм…
Browse files Browse the repository at this point in the history
…ы сбрасываются указанные ранее дополнительные категории, правильные атрибуты без значения
  • Loading branch information
fuze committed Nov 5, 2015
1 parent 8de71c2 commit 15c4f5b
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 38 deletions.
33 changes: 17 additions & 16 deletions system/controllers/comments/actions/delete.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,38 +7,39 @@ public function run(){
if (!$this->request->isAjax()){ cmsCore::error404(); }
if (!cmsUser::isAllowed('comments', 'delete')){ cmsCore::error404(); }

$comment_id = $this->request->get('id');
$comment = $this->model->getComment((int)$this->request->get('id'));

// Проверяем валидность
$is_valid = is_numeric($comment_id);
// Проверяем
if (!$comment){

if (!$is_valid){
$result = array(
cmsTemplate::getInstance()->renderJSON($result = array(
'error' => true,
'message' => LANG_ERROR
);
cmsTemplate::getInstance()->renderJSON($result);
));

}

$user = cmsUser::getInstance();

$comment = $this->model->getComment($comment_id);

if (!cmsUser::isAllowed('comments', 'edit', 'all')) {
if (cmsUser::isAllowed('comments', 'edit', 'own') && $comment['user']['id'] != $user->id) {
$result = array('error' => true, 'message' => LANG_ERROR);
cmsTemplate::getInstance()->renderJSON($result);

cmsTemplate::getInstance()->renderJSON(array(
'error' => true,
'message' => LANG_ERROR
));

}
}

$this->model->deleteComment($comment_id);
$this->model->deleteComment($comment['id']);

cmsEventsManager::hook('comments_after_hide', $comment['id']);

$result = array(
cmsTemplate::getInstance()->renderJSON(array(
'error' => false,
'message' => LANG_COMMENT_DELETED
);

cmsTemplate::getInstance()->renderJSON($result);
));

}

Expand Down
30 changes: 16 additions & 14 deletions system/controllers/content/actions/item_add.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,21 @@ public function run(){
list($item, $errors) = cmsEventsManager::hook('content_validate', array($item, $errors));
}

// несколько категорий
if (!empty($ctype['options']['is_cats_multi'])){
$add_cats = $this->request->get('add_cats');
if (is_array($add_cats)){
foreach($add_cats as $index=>$cat_id){
if (!is_numeric($cat_id) || !$cat_id){
unset($add_cats[$index]);
}
}
if ($add_cats){
$item['add_cats'] = $add_cats;
}
}
}

if (!$errors){

unset($item['ctype_name']);
Expand Down Expand Up @@ -185,20 +200,6 @@ public function run(){
if (!isset($item['is_pub'])) { $item['is_pub'] = $is_pub; }
if (!empty($item['is_pub'])) { $item['is_pub'] = $is_pub; }

if (!empty($ctype['options']['is_cats_multi'])){
$add_cats = $this->request->get('add_cats');
if (is_array($add_cats)){
foreach($add_cats as $index=>$cat_id){
if (!is_numeric($cat_id) || !$cat_id){
unset($add_cats[$index]);
}
}
if ($add_cats){
$item['add_cats'] = $add_cats;
}
}
}

$item = cmsEventsManager::hook("content_before_add", $item);
$item = cmsEventsManager::hook("content_{$ctype['name']}_before_add", $item);

Expand Down Expand Up @@ -251,6 +252,7 @@ public function run(){
'is_moderator' => $is_moderator,
'is_premoderation' => $is_premoderation,
'is_load_props' => !isset($errors),
'add_cats' => isset($add_cats) ? $add_cats : array(),
'errors' => isset($errors) ? $errors : false
));

Expand Down
10 changes: 8 additions & 2 deletions system/libs/html.helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,12 @@ function html_attr_str($attributes){
unset($attributes['class']);
if (sizeof($attributes)){
foreach($attributes as $key=>$val){
if(is_bool($val)){
if($val === true){
$attr_str .= "{$key} ";
}
continue;
}
$attr_str .= "{$key}=\"{$val}\" ";
}
}
Expand Down Expand Up @@ -560,10 +566,10 @@ function html_select($name, $items, $selected = '', $attributes = array()){
if($optgroup !== false){
$html .= "\t".'</optgroup>'."\n";
}

$html .= '</select>'."\n";
return $html;

}

function html_select_range($name, $start, $end, $step, $add_lead_zero=false, $selected='', $attributes=array()){
Expand Down
6 changes: 0 additions & 6 deletions templates/default/content/default_list_tiles.tpl.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,6 @@

</div>

<?php
$is_tags = $ctype['is_tags'] &&
!empty($ctype['options']['is_tags_in_list']) &&
$item['tags'];
?>

<?php
$show_bar = $ctype['is_rating'] ||
$fields['date_pub']['is_in_list'] ||
Expand Down

0 comments on commit 15c4f5b

Please sign in to comment.