Skip to content

Commit

Permalink
Исправлены баги с функциями string_parse_list и string_explode_list;
Browse files Browse the repository at this point in the history
Массовая рассылка из админки с опциями выбора пресета типографа и замены переноса строк на тег br;
Запоминание параметров последней рассылки;
Убрано неправильное предупреждение формы "Изменения могут не сохраниться" при настройке полей;
Подготовка 2.17.1.
  • Loading branch information
fuzegit committed Dec 29, 2024
1 parent 8e4431f commit 866d386
Show file tree
Hide file tree
Showing 18 changed files with 290 additions and 72 deletions.
2 changes: 1 addition & 1 deletion system/config/version.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[version]
major = 2
minor = 17
build = 0
build = 1
date = 20241227
4 changes: 4 additions & 0 deletions system/controllers/admin/actions/install_finish.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ public function run() {
return $this->redirectToAction('install');
}

if (function_exists('opcache_reset')) {
@opcache_reset();
}

$installer = new cmsInstaller($this->getInstallPackagesPath('root'), $this->controller);

// id дополнения передаётся при установке из каталога дополнений
Expand Down
24 changes: 16 additions & 8 deletions system/controllers/messages/backend/actions/pmailing.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ class actionMessagesPmailing extends cmsAction {

public function run($group_id = 0) {

$form = $this->getForm('pmailing');
$history_key = 'admin_pmailing';

$mailing = array_merge((cmsUser::getUPS($history_key) ?: []), ['groups' => [$group_id]]);

$mailing = ['groups' => [$group_id]];
$form = $this->getForm('pmailing');

if ($this->request->has('submit')) {

Expand Down Expand Up @@ -46,19 +48,23 @@ public function run($group_id = 0) {

if ($recipients) {
if (isset($recipients[$sender_id])) {
unset($recipients[$sender_id]);
//unset($recipients[$sender_id]);
}
}

if ($recipients) {

$this->controller_messages->addRecipients(array_keys($recipients))->setSender($sender_id);

$mailing['message_text'] = cmsEventsManager::hook('html_filter', $mailing['message_text']);
$message_text = cmsEventsManager::hook('html_filter', [
'text' => $mailing['message_text'],
'typograph_id' => $mailing['typograph_id'],
'is_auto_br' => $mailing['is_br'] ? true : null
]);

if ($mailing['type'] === 'message') {

$messages_ids = $this->controller_messages->sendMessage($mailing['message_text']);
$messages_ids = $this->controller_messages->sendMessage($message_text);

$count = is_array($messages_ids) ? count($messages_ids) : ($messages_ids ? 1 : 0);

Expand All @@ -76,15 +82,15 @@ public function run($group_id = 0) {
$this->controller_messages->sendNoticeEmail('messages_new', [
'user_url' => href_to_profile($sender, false, true),
'user_nickname' => $sender_nickname,
'message' => strip_tags($mailing['message_text'])
'message' => strip_tags($message_text)
]);
}
}

if ($mailing['type'] === 'notify') {

$notices_ids = $this->controller_messages->sendNoticePM(array(
'content' => $mailing['message_text']
'content' => $message_text
));

$count = is_array($notices_ids) ? count($notices_ids) : ($notices_ids ? 1 : 0);
Expand All @@ -101,7 +107,7 @@ public function run($group_id = 0) {

foreach ($emails as $email => $nickname) {
$this->controller_messages->sendEmail(['email' => $email], [
'text' => $mailing['message_text']
'text' => $message_text
], ['nickname' => $nickname]);
}

Expand All @@ -112,6 +118,8 @@ public function run($group_id = 0) {
LANG_PM_PMAILING_SENDED,
html_spellcount($count, string_lang('LANG_PM_' . $mailing['type']), false, false, 0)
), ($count ? 'success' : 'info'));

cmsUser::setUPS($history_key, $mailing);
}

if (!$recipients) {
Expand Down
17 changes: 17 additions & 0 deletions system/controllers/messages/backend/forms/form_pmailing.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,20 @@ public function init() {
['required']
]
]),
new fieldList('typograph_id', [
'title' => LANG_PARSER_TYPOGRAPH,
'generator' => function ($item) {
$items = [];
$presets = (new cmsModel())->get('typograph_presets') ?: [];
foreach ($presets as $preset) {
$items[$preset['id']] = $preset['title'];
}
return $items;
},
'rules' => [
['required']
]
]),
new fieldList('type', [
'title' => LANG_PM_PMAILING_TYPE,
'items' => [
Expand All @@ -114,6 +128,9 @@ public function init() {
['email']
],
'visible_depend' => ['type' => ['show' => ['message']]]
]),
new fieldCheckbox('is_br', [
'title' => LANG_PM_PMAILING_IS_BR
])
]
]
Expand Down
1 change: 1 addition & 0 deletions system/languages/en/controllers/messages/messages.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
define('LANG_PM_SENDER_USER_ID', 'From whose name should I send');
define('LANG_PM_SENDER_USER_ID_HINT', 'Enter the user email. If not specified, the message will be sent from you.');
define('LANG_PM_PMAILING_NOT_RECIPIENTS', 'No recipients according to specified criteria');
define('LANG_PM_PMAILING_IS_BR', 'Replace line breaks with HTML br tag');
define('LANG_PM_IS_ENABLE_PM', 'Enable private messages');
define('LANG_PM_SELECT_FIRST_CONTACT', 'Automatically select the first contact from the list');
define('LANG_PM_SELECT_FIRST_CONTACT_HINT', 'When opening a message box');
1 change: 1 addition & 0 deletions system/languages/ru/controllers/messages/messages.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
define('LANG_PM_SENDER_USER_ID', 'От чьего имени отправлять');
define('LANG_PM_SENDER_USER_ID_HINT', 'Введите email пользователя. Если не указан, сообщение будет отправлено от вас.');
define('LANG_PM_PMAILING_NOT_RECIPIENTS', 'Нет получателей по заданным критериям');
define('LANG_PM_PMAILING_IS_BR', 'Заменять перенос строк на HTML тег br');
define('LANG_PM_IS_ENABLE_PM', 'Включить личные сообщения');
define('LANG_PM_SELECT_FIRST_CONTACT', 'Автоматически выбирать первый контакт из списка');
define('LANG_PM_SELECT_FIRST_CONTACT_HINT', 'При открытии окна сообщений');
6 changes: 3 additions & 3 deletions system/libs/strings.helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ function string_parse_list($string_list) {

foreach ($rows as $row) {

if (preg_match('/^{(.*)}$/', $row, $matches)) {
if (preg_match('/^{(.*)}/', $row, $matches)) {
if (!$is_logged) { continue; }
$row = $matches[1];
}
Expand Down Expand Up @@ -119,8 +119,8 @@ function string_explode_list($string_list, $index_as_value = false) {
$index = $parts[0];
$value = $parts[1];
} else {
$index = $index_as_value ? $row : (string)($count + 1);
$value = $row;
$index = $index_as_value ? $parts[0] : (string)($count + 1);
$value = $parts[0];
}

$items[$index] = $value;
Expand Down
2 changes: 2 additions & 0 deletions system/traits/controllers/actions/formFieldItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,8 @@ public function run($ctype_id = null, $field_id = null, $is_copy = null) {
}
}

$form->show_unsave_notice = false;

return $this->cms_template->render($this->tpl_name, [
'do' => $do,
'ctype' => $ctype,
Expand Down
14 changes: 7 additions & 7 deletions templates/admincoreui/controllers/admin/form_field.tpl.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ function loadFieldTypeOptions(field){
type: field_type
}, function(data){

if (!data) { return; }
if (!data || data.error || !data.html) {

if(data.error){
icms.modal.alert(data.message, 'ui_error'); return;
}
if(data.error){
icms.modal.alert(data.message, 'ui_error');
}

if(!data.html){
icms.forms.initUnsaveNotice();
return;
}

Expand All @@ -55,12 +55,12 @@ function loadFieldTypeOptions(field){

$('#tab-type').after($(data.html));

icms.forms.initUnsaveNotice();

icms.events.run('loadfieldtypeoptions', data.html);

}, 'json');

}

}

$(function(){
Expand Down
23 changes: 14 additions & 9 deletions templates/modern/js/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ icms.forms = (function ($) {
this.submitted = false;
this.form_changed = false;
this.csrf_token = false;
this.is_init_unsave_notice = false;

var _this = this;

Expand Down Expand Up @@ -458,32 +459,36 @@ icms.forms = (function ($) {

this.initUnsaveNotice = function(){

var init_data = {};
if (this.is_init_unsave_notice) {
return;
}
this.is_init_unsave_notice = true;

let init_data = {};

$('form').each(function(i){
init_data[i] = _this.toJSON($(this));
$(this).attr('data-notice_id', i);
});

$(document).on('change', '.form-tabs input, .form-tabs select, .form-tabs textarea', function (e) {
var form = $(this).closest('form');
_this.form_changed = (JSON.stringify(init_data[form.attr('data-notice_id')]) !== JSON.stringify(_this.toJSON(form))) ? true : false;
let form = $(this).closest('form');
_this.form_changed = JSON.stringify(init_data[form.attr('data-notice_id')]) !== JSON.stringify(_this.toJSON(form));
});
$(document).on('submit', 'form', function () {
$(this).find('.button-submit').addClass('disabled is-busy');
icms.forms.submitted = true;
});
$(window).on('beforeunload', function (e) {
if (icms.forms.form_changed && !icms.forms.submitted) {
var e = e || window.event;
var msg = LANG_SUBMIT_NOT_SAVE;
if (e) {
e.returnValue = msg;
if (_this.form_changed && !_this.submitted) {
let ev = e || window.event;
let msg = LANG_SUBMIT_NOT_SAVE;
if (ev) {
ev.returnValue = msg;
}
return msg;
}
});

};

this.initCollapsedFieldset = function(form_id){
Expand Down
19 changes: 1 addition & 18 deletions update/current/install.php
Original file line number Diff line number Diff line change
@@ -1,30 +1,13 @@
<?php
/**
* 2.16.3 => 2.17.0
* 2.17.0 => 2.17.1
*/
function install_package(){

$core = cmsCore::getInstance();
$admin = cmsCore::getController('admin');
$content_model = cmsCore::getModel('content');

if(!$core->db->isFieldExists('tags', 'description', false)){
$core->db->query("ALTER TABLE `{#}tags` ADD `description` TEXT NULL DEFAULT NULL AFTER `tag`;");
}

if(!$core->db->isFieldExists('widgets_bind', 'url_mask_not', false)){
$core->db->query("ALTER TABLE `{#}widgets_bind` ADD `url_mask_not` TEXT NULL DEFAULT NULL COMMENT 'Отрицательные маски виджета' AFTER `groups_hide`;");
}

$ctypes = $content_model->getContentTypes();

foreach($ctypes as $ctype){

$table_name = $content_model->table_prefix . $ctype['name'] . '_props';

$content_model->db->query("UPDATE `{#}{$table_name}` SET `type`='listbitmask' WHERE `type` = 'list_multiple'");
}

////////////////////////////////////////////////////////////////////////////
////////////// Новые правила доступа ///////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
Expand Down
20 changes: 0 additions & 20 deletions update/current/install.sql
Original file line number Diff line number Diff line change
@@ -1,20 +0,0 @@
ALTER TABLE `{#}perms_rules` CHANGE `name` `name` VARCHAR(64) NOT NULL COMMENT 'Название правила';

DROP TABLE IF EXISTS `{#}csp_logs`;
CREATE TABLE `{#}csp_logs` (
`id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT,
`date_pub` timestamp NOT NULL DEFAULT current_timestamp(),
`blocked_uri` varchar(255) DEFAULT NULL,
`referrer` varchar(255) DEFAULT NULL,
`line_number` smallint(6) DEFAULT NULL,
`document_uri` varchar(255) DEFAULT NULL,
`violated_directive` varchar(64) DEFAULT NULL,
`effective_directive` varchar(64) DEFAULT NULL,
`status_code` smallint(6) DEFAULT NULL,
`ip` varbinary(16) DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `date_pub` (`date_pub`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Логи CSP';

DELETE FROM {#}controllers WHERE `name` = 'csp';
INSERT INTO `{#}controllers` (`title`, `name`, `is_enabled`, `options`, `author`, `url`, `version`, `is_backend`, `is_external`) VALUES ('Content Security Policy', 'csp', 1, '---\nenable_csp: null\ncsp_str: \"default-src \'self\'; script-src \'unsafe-eval\' \'nonce-{nonce}\' \'strict-dynamic\'; style-src \'self\' data: \'unsafe-inline\' https://fonts.googleapis.com; img-src \'self\' data: https://instantcms.ru; font-src \'self\' data: https://fonts.gstatic.com\"\nis_report_only: 1\nenable_report: 1\n', 'InstantCMS Team', 'https://instantcms.ru', '2.0', 1, NULL);
6 changes: 3 additions & 3 deletions update/current/manifest.en.ini
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@ type = "system"
[version]
major = "2"
minor = "17"
build = "0"
build = "1"
date = "20241227"

[depends]
core = "2.16.3"
core = "2.17.0"

[author]
name = "InstantCMS Team"
url = "https://instantcms.ru"

[description]
text[] = "Release details:"
text[] = "https://instantcms.ru/novosti/release2170.html"
text[] = "https://instantcms.ru/novosti/release2171.html"
6 changes: 3 additions & 3 deletions update/current/manifest.ru.ini
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@ type = "system"
[version]
major = "2"
minor = "17"
build = "0"
build = "1"
date = "20241227"

[depends]
core = "2.16.3"
core = "2.17.0"

[author]
name = "InstantCMS Team"
url = "https://instantcms.ru"

[description]
text[] = "Описание обновления:"
text[] = "https://instantcms.ru/novosti/release2170.html"
text[] = "https://instantcms.ru/novosti/release2171.html"
Loading

0 comments on commit 866d386

Please sign in to comment.