diff --git a/install/languages/en/sql/base.sql b/install/languages/en/sql/base.sql index ea43a931a..b67bb98c3 100755 --- a/install/languages/en/sql/base.sql +++ b/install/languages/en/sql/base.sql @@ -939,7 +939,8 @@ INSERT INTO `{#}events` (`id`, `event`, `listener`, `ordering`, `is_enabled`) VA (214, 'render_widget_menu_menu', 'bootstrap4', 214, 1), (215, 'engine_start', 'redirect', 215, 1), (216, 'restore_user', 'comments', 216, 1), -(217, 'set_user_is_deleted', 'comments', 217, 1); +(217, 'set_user_is_deleted', 'comments', 217, 1), +(218, 'comments_after_delete_list', 'moderation', 218, 1); DROP TABLE IF EXISTS `{#}groups`; CREATE TABLE `{#}groups` ( diff --git a/install/languages/ru/sql/base.sql b/install/languages/ru/sql/base.sql index 69bf36a70..4b635c937 100755 --- a/install/languages/ru/sql/base.sql +++ b/install/languages/ru/sql/base.sql @@ -939,7 +939,8 @@ INSERT INTO `{#}events` (`id`, `event`, `listener`, `ordering`, `is_enabled`) VA (214, 'render_widget_menu_menu', 'bootstrap4', 214, 1), (215, 'engine_start', 'redirect', 215, 1), (216, 'restore_user', 'comments', 216, 1), -(217, 'set_user_is_deleted', 'comments', 217, 1); +(217, 'set_user_is_deleted', 'comments', 217, 1), +(218, 'comments_after_delete_list', 'moderation', 218, 1); DROP TABLE IF EXISTS `{#}groups`; CREATE TABLE `{#}groups` ( diff --git a/system/controllers/comments/model.php b/system/controllers/comments/model.php index 1be4a0bac..7a94f114a 100755 --- a/system/controllers/comments/model.php +++ b/system/controllers/comments/model.php @@ -109,11 +109,7 @@ public function deleteComment($comment, $is_delete = false) { continue; } - @unlink(cmsConfig::get('upload_path') . $file['path']); - - $files_model->filterEqual('path', $file['path']); - - $files_model->deleteFiltered('uploaded_files'); + $files_model->deleteFile($file); } } @@ -168,42 +164,42 @@ public function deleteComments($target_controller, $target_subject, $target_id = $this->unlockFilters(); - if ($comments) { + if (!$comments) { - $ids = array_keys($comments); + $this->resetFilters(); - $this->deleteFiltered('comments'); + return false; + } - $this->filterIn('comment_id', $ids)->deleteFiltered('comments_rating'); + $ids = array_keys($comments); - cmsCache::getInstance()->clean('comments.list'); + $this->deleteFiltered('comments'); - // Удаляем изображения - $files_model = cmsCore::getModel('files'); + $this->filterIn('comment_id', $ids)->deleteFiltered('comments_rating'); - foreach ($comments as $content_html) { - $paths = string_html_get_images_path($content_html); - if ($paths) { - foreach ($paths as $path) { - - $file = $files_model->getFileByPath($path); - if (!$file) { - continue; - } + cmsCache::getInstance()->clean('comments.list'); - @unlink(cmsConfig::get('upload_path') . $file['path']); + // Удаляем изображения + $files_model = cmsCore::getModel('files'); - $files_model->filterEqual('path', $file['path']); + foreach ($comments as $content_html) { + $paths = string_html_get_images_path($content_html); + if ($paths) { + foreach ($paths as $path) { - $files_model->deleteFiltered('uploaded_files'); + $file = $files_model->getFileByPath($path); + if (!$file) { + continue; } + + $files_model->deleteFile($file); } } - - cmsEventsManager::hook('comments_after_delete_list', $ids); } - return $comments ? true : false; + cmsEventsManager::hook('comments_after_delete_list', $ids); + + return true; } public function setCommentsIsDeleted($target_controller, $target_subject, $target_id, $delete = 1) { diff --git a/system/controllers/moderation/hooks/comments_after_delete_list.php b/system/controllers/moderation/hooks/comments_after_delete_list.php new file mode 100755 index 000000000..780ef636e --- /dev/null +++ b/system/controllers/moderation/hooks/comments_after_delete_list.php @@ -0,0 +1,19 @@ +model->closeModeratorTask('comments', $comment_id, false, $this->cms_user->id); + + if(!empty($this->options['clear_log_after_delete'])){ + $this->model->logDeleteTarget('comments', 'comments', $comment_id); + } + } + + return $ids; + } + +} diff --git a/system/fields/html.php b/system/fields/html.php index 5bda69771..f64acb63b 100755 --- a/system/fields/html.php +++ b/system/fields/html.php @@ -9,106 +9,106 @@ class fieldHtml extends cmsFormField { public $var_type = 'string'; public function getOptions(){ - return array( - new fieldList('editor', array( - 'title' => LANG_PARSER_HTML_EDITOR, - 'default' => cmsConfig::get('default_editor'), - 'generator' => function($item){ - $items = []; + return [ + new fieldList('editor', [ + 'title' => LANG_PARSER_HTML_EDITOR, + 'default' => cmsConfig::get('default_editor'), + 'generator' => function ($item) { + $items = []; $editors = cmsCore::getWysiwygs(); - foreach($editors as $editor){ + foreach ($editors as $editor) { $items[$editor] = ucfirst($editor); } $ps = cmsCore::getModel('wysiwygs')->getPresetsList(); - if($ps){ + if ($ps) { foreach ($ps as $key => $value) { $items[$key] = $value; } } return $items; } - )), - new fieldList('editor_presets', array( - 'title' => LANG_PARSER_HTML_EDITOR_GR, - 'is_multiple' => true, - 'dynamic_list' => true, - 'select_title' => LANG_SELECT, - 'multiple_keys' => array( - 'group_id' => 'field', 'preset_id' => 'field_select' - ), - 'generator' => function($item){ + ]), + new fieldList('editor_presets', [ + 'title' => LANG_PARSER_HTML_EDITOR_GR, + 'is_multiple' => true, + 'dynamic_list' => true, + 'select_title' => LANG_SELECT, + 'multiple_keys' => [ + 'group_id' => 'field', 'preset_id' => 'field_select' + ], + 'generator' => function ($item) { $users_model = cmsCore::getModel('users'); $items = []; $groups = $users_model->getGroups(false); - foreach($groups as $group){ + foreach ($groups as $group) { $items[$group['id']] = $group['title']; } return $items; }, - 'values_generator' => function() { - $items = []; + 'values_generator' => function () { + $items = []; $editors = cmsCore::getWysiwygs(); - foreach($editors as $editor){ + foreach ($editors as $editor) { $items[$editor] = ucfirst($editor); } $ps = cmsCore::getModel('wysiwygs')->getPresetsList(); - if($ps){ + if ($ps) { foreach ($ps as $key => $value) { $items[$key] = $value; } } return $items; } - )), - new fieldCheckbox('is_html_filter', array( - 'title' => LANG_PARSER_HTML_FILTERING, + ]), + new fieldCheckbox('is_html_filter', [ + 'title' => LANG_PARSER_HTML_FILTERING, 'extended_option' => true - )), - new fieldCheckbox('parse_patterns', array( + ]), + new fieldCheckbox('parse_patterns', [ 'title' => LANG_PARSER_PARSE_PATTERNS, - 'hint' => LANG_PARSER_PARSE_PATTERNS_HINT - )), - new fieldCheckbox('build_redirect_link', array( - 'title' => LANG_PARSER_BUILD_REDIRECT_LINK, + 'hint' => LANG_PARSER_PARSE_PATTERNS_HINT + ]), + new fieldCheckbox('build_redirect_link', [ + 'title' => LANG_PARSER_BUILD_REDIRECT_LINK, 'is_visible' => cmsController::enabled('redirect') - )), - new fieldNumber('teaser_len', array( - 'title' => LANG_PARSER_HTML_TEASER_LEN, - 'hint' => LANG_PARSER_HTML_TEASER_LEN_HINT, + ]), + new fieldNumber('teaser_len', [ + 'title' => LANG_PARSER_HTML_TEASER_LEN, + 'hint' => LANG_PARSER_HTML_TEASER_LEN_HINT, 'extended_option' => true - )), - new fieldString('teaser_postfix', array( + ]), + new fieldString('teaser_postfix', [ 'title' => LANG_PARSER_HTML_TEASER_POSTFIX, - 'visible_depend' => array('options:teaser_len' => array('hide' => array(''))), - 'default' => '', + 'visible_depend' => ['options:teaser_len' => ['hide' => ['']]], + 'default' => '', 'extended_option' => true - )), - new fieldList('teaser_type', array( - 'title' => LANG_PARSER_HTML_TEASER_TYPE, - 'items' => array( + ]), + new fieldList('teaser_type', [ + 'title' => LANG_PARSER_HTML_TEASER_TYPE, + 'items' => [ '' => LANG_PARSER_HTML_TEASER_TYPE_NULL, 's' => LANG_PARSER_HTML_TEASER_TYPE_S, 'w' => LANG_PARSER_HTML_TEASER_TYPE_W - ), - 'visible_depend' => array('options:teaser_len' => array('hide' => array(''))), + ], + 'visible_depend' => ['options:teaser_len' => ['hide' => ['']]], 'extended_option' => true - )), - new fieldCheckbox('show_show_more', array( - 'title' => LANG_PARSER_SHOW_SHOW_MORE, - 'default' => false, - 'visible_depend' => array('options:teaser_len' => array('hide' => array(''))), + ]), + new fieldCheckbox('show_show_more', [ + 'title' => LANG_PARSER_SHOW_SHOW_MORE, + 'default' => false, + 'visible_depend' => ['options:teaser_len' => ['hide' => ['']]], 'extended_option' => true - )), - new fieldCheckbox('in_fulltext_search', array( - 'title' => LANG_PARSER_IN_FULLTEXT_SEARCH, - 'hint' => LANG_PARSER_IN_FULLTEXT_SEARCH_HINT, + ]), + new fieldCheckbox('in_fulltext_search', [ + 'title' => LANG_PARSER_IN_FULLTEXT_SEARCH, + 'hint' => LANG_PARSER_IN_FULLTEXT_SEARCH_HINT, 'default' => false - )) - ); + ]) + ]; } public function getFilterInput($value) { @@ -150,8 +150,8 @@ public function parse($value){ if ($this->getOption('is_html_filter')){ $value = cmsEventsManager::hook('html_filter', [ 'text' => $value, - 'is_auto_br' => $this->getOption('editor') == 'markitup', - 'build_smiles' => $this->getOption('editor') == 'markitup', // пока что только так + 'is_auto_br' => $this->getOption('editor') === 'markitup', + 'build_smiles' => $this->getOption('editor') === 'markitup', // пока что только так 'build_redirect_link' => (bool)$this->getOption('build_redirect_link') ]); $value = string_replace_svg_icons($value); @@ -187,7 +187,7 @@ public function parseTeaser($value) { $value = cmsEventsManager::hook('html_filter', [ 'text' => $value, 'is_auto_br' => false, - 'build_smiles' => $this->getOption('editor') == 'markitup', // пока что только так + 'build_smiles' => $this->getOption('editor') === 'markitup', // пока что только так 'build_redirect_link' => (bool)$this->getOption('build_redirect_link') ]); } @@ -203,27 +203,25 @@ public function applyFilter($model, $value) { return $model->filterLike($this->name, "%{$value}%"); } - public function afterStore($item, $model, $action){ + public function afterStore($item, $model, $action) { - if($action == 'add' && !empty($item[$this->name])){ + if ($action === 'add' && !empty($item[$this->name])) { $paths = string_html_get_images_path($item[$this->name]); - if($paths){ - foreach($paths as $path){ + if ($paths) { + foreach ($paths as $path) { $model->filterEqual('path', $path)->filterIsNull('target_id'); $model->updateFiltered('uploaded_files', ['target_id' => $item['id']], true); - } } - } return; } - public function delete($value){ + public function delete($value) { if (is_empty_value($value)) { return true; @@ -231,29 +229,25 @@ public function delete($value){ $paths = string_html_get_images_path($value); - if($paths){ + if ($paths) { $files_model = cmsCore::getModel('files'); - foreach($paths as $path){ + foreach ($paths as $path) { $file = $files_model->getFileByPath($path); - if(!$file){ continue; } - - @unlink(cmsConfig::get('upload_path').$file['path']); - - $files_model->filterEqual('path', $file['path']); - - $files_model->deleteFiltered('uploaded_files'); + if (!$file) { + continue; + } + $files_model->deleteFile($file); } - } return true; } - public function getInput($value){ + public function getInput($value) { $this->data = cmsCore::getController('wysiwygs')->getEditorParams([ 'editor' => $this->getOption('editor'), @@ -261,7 +255,7 @@ public function getInput($value){ 'presets' => $this->getOption('editor_presets', []) ]); - if(empty($this->data['options']['id'])){ + if (empty($this->data['options']['id'])) { $this->data['options']['id'] = $this->id; } diff --git a/system/fields/string.php b/system/fields/string.php index 22ec3ce9b..b04b37fc3 100755 --- a/system/fields/string.php +++ b/system/fields/string.php @@ -9,7 +9,7 @@ class fieldString extends cmsFormField { public $type = 'text'; public function getOptions() { - return array( + return [ new fieldNumber('min_length', [ 'title' => LANG_PARSER_TEXT_MIN_LEN, 'default' => 0 @@ -52,7 +52,7 @@ public function getOptions() { 'default' => false, 'extended_option' => true ]) - ); + ]; } public function getRules() { @@ -102,18 +102,22 @@ public function parse($value) { } public function applyFilter($model, $value) { + switch ($this->getOption('in_filter_as')) { + case 'select': return $model->filterEqual($this->name, $value); + case 'checkbox': if ($value) { // работает и без этого return $model->filterNotNull($this->name); } - return $model; - case 'input': + default: return $model->filterLike($this->name, '%' . $value . '%'); } + + return $model; } public function getFilterInput($value) { @@ -127,10 +131,15 @@ public function getFilterInput($value) { } public function store($value, $is_submitted, $old_value = null) { - if (!$value) { return ''; } + + if (is_empty_value($value)) { + return ''; + } + if ($this->getProperty('is_clean_disable') === true) { return trim($value); } + return strip_tags(trim($value)); } diff --git a/system/fields/text.php b/system/fields/text.php index 90be47708..af15bafb0 100755 --- a/system/fields/text.php +++ b/system/fields/text.php @@ -9,51 +9,51 @@ class fieldText extends cmsFormField { public $var_type = 'string'; public $size = 5; - public function getOptions(){ - return array( - new fieldNumber('min_length', array( - 'title' => LANG_PARSER_TEXT_MIN_LEN, + public function getOptions() { + return [ + new fieldNumber('min_length', [ + 'title' => LANG_PARSER_TEXT_MIN_LEN, 'default' => 0 - )), - new fieldNumber('max_length', array( - 'title' => LANG_PARSER_TEXT_MAX_LEN, + ]), + new fieldNumber('max_length', [ + 'title' => LANG_PARSER_TEXT_MAX_LEN, 'default' => 4096 - )), - new fieldCheckbox('show_symbol_count', array( + ]), + new fieldCheckbox('show_symbol_count', [ 'title' => LANG_PARSER_SHOW_SYMBOL_COUNT - )), - new fieldCheckbox('is_strip_tags', array( + ]), + new fieldCheckbox('is_strip_tags', [ 'title' => LANG_PARSER_IS_STRIP_TAGS - )), - new fieldCheckbox('is_html_filter', array( - 'title' => LANG_PARSER_HTML_FILTERING, - 'extended_option' => true - )), - new fieldCheckbox('parse_patterns', array( + ]), + new fieldCheckbox('is_html_filter', [ + 'title' => LANG_PARSER_HTML_FILTERING, + 'extended_option' => true + ]), + new fieldCheckbox('parse_patterns', [ 'title' => LANG_PARSER_PARSE_PATTERNS, - 'hint' => LANG_PARSER_PARSE_PATTERNS_HINT - )), - new fieldCheckbox('build_redirect_link', array( - 'title' => LANG_PARSER_BUILD_REDIRECT_LINK, + 'hint' => LANG_PARSER_PARSE_PATTERNS_HINT + ]), + new fieldCheckbox('build_redirect_link', [ + 'title' => LANG_PARSER_BUILD_REDIRECT_LINK, 'is_visible' => cmsController::enabled('redirect') - )), - new fieldNumber('teaser_len', array( - 'title' => LANG_PARSER_HTML_TEASER_LEN, - 'hint' => LANG_PARSER_HTML_TEASER_LEN_HINT, - 'extended_option' => true - )), - new fieldCheckbox('show_show_more', array( - 'title' => LANG_PARSER_SHOW_SHOW_MORE, - 'default' => false, - 'visible_depend' => array('options:teaser_len' => array('hide' => array(''))), - 'extended_option' => true - )), - new fieldCheckbox('in_fulltext_search', array( - 'title' => LANG_PARSER_IN_FULLTEXT_SEARCH, - 'hint' => LANG_PARSER_IN_FULLTEXT_SEARCH_HINT, + ]), + new fieldNumber('teaser_len', [ + 'title' => LANG_PARSER_HTML_TEASER_LEN, + 'hint' => LANG_PARSER_HTML_TEASER_LEN_HINT, + 'extended_option' => true + ]), + new fieldCheckbox('show_show_more', [ + 'title' => LANG_PARSER_SHOW_SHOW_MORE, + 'default' => false, + 'visible_depend' => ['options:teaser_len' => ['hide' => ['']]], + 'extended_option' => true + ]), + new fieldCheckbox('in_fulltext_search', [ + 'title' => LANG_PARSER_IN_FULLTEXT_SEARCH, + 'hint' => LANG_PARSER_IN_FULLTEXT_SEARCH_HINT, 'default' => false - )) - ); + ]) + ]; } public function getFilterInput($value) { @@ -124,7 +124,7 @@ public function parse($value){ public function afterParse($value, $item){ - if (!$value){ + if (is_empty_value($value)) { return ''; } @@ -149,12 +149,15 @@ public function getStringValue($value){ } public function store($value, $is_submitted, $old_value = null) { - if (!$value) { + + if (is_empty_value($value)) { return ''; } + if ($this->getProperty('is_strip_tags') === true || $this->getOption('is_strip_tags')) { return trim(strip_tags($value)); } + return parent::store($value, $is_submitted, $old_value); } @@ -168,10 +171,10 @@ public function applyFilter($model, $value) { public function getInput($value){ - $this->data['attributes'] = $this->getProperty('attributes')?:[]; - $this->data['attributes']['rows'] = $this->getOption('size')?:$this->getProperty('size'); - $this->data['attributes']['id'] = $this->id; - $this->data['attributes']['required'] = (array_search(['required'], $this->getRules()) !== false); + $this->data['attributes'] = $this->getProperty('attributes') ?: []; + $this->data['attributes']['rows'] = $this->getOption('size') ?: $this->getProperty('size'); + $this->data['attributes']['id'] = $this->id; + $this->data['attributes']['required'] = (array_search(['required'], $this->getRules()) !== false); return parent::getInput($value); }