Skip to content

Commit f1a15ad

Browse files
committed
новые методы для сообщений,
различные правки для актуальной версий InstantCMS
1 parent d65b517 commit f1a15ad

22 files changed

+651
-86
lines changed

manifest.en.ini

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ addon_id = "600"
55

66
[version]
77
major = "2"
8-
minor = "1"
8+
minor = "2"
99
build = "0"
10-
date = "20180913"
10+
date = "20190409"
1111

1212
[depends]
13-
core = "2.5.0"
13+
core = "2.11.0"
1414

1515
[author]
1616
name = "InstantCMS Team"

manifest.ru.ini

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ addon_id = "600"
55

66
[version]
77
major = "2"
8-
minor = "1"
8+
minor = "2"
99
build = "0"
10-
date = "20180913"
10+
date = "20190409"
1111

1212
[depends]
13-
core = "2.5.0"
13+
core = "2.11.0"
1414

1515
[author]
1616
name = "InstantCMS Team"

package/system/controllers/api/actions/method.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,8 @@ public function run($method_name = null){
206206
// ставим ключ API в свойство
207207
$this->method_action->key = $this->key;
208208
$this->method_action->method_name = $this->method_name;
209+
// опции api в свойство
210+
$this->method_action->api_options = $this->options;
209211

210212
// валидация параметров запроса
211213
$params_error = $this->validateMethodParams();

package/system/controllers/api/api_actions/api_auth_confirm.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,15 +82,11 @@ public function run(){
8282

8383
cmsUser::setUserSession($this->user);
8484

85-
$update_data = array(
86-
'ip' => cmsUser::getIp()
87-
);
88-
89-
$this->model->update('{users}', $this->user['id'], $update_data, true);
85+
$this->model_users->updateUserIp($this->user['id']);
9086

9187
cmsEventsManager::hook('auth_login', $this->user['id']);
9288

93-
unset($this->user['password'], $this->user['password_salt'], $this->user['pass_token'], $this->user['date_token'], $this->user['ip'], $this->user['is_admin']);
89+
unset($this->user['password_hash'], $this->user['password'], $this->user['password_salt'], $this->user['pass_token'], $this->user['date_token'], $this->user['ip'], $this->user['is_admin']);
9490

9591
$auth_user = array(
9692
'session_name' => session_name(),

package/system/controllers/api/api_actions/api_auth_login.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class actionAuthApiAuthLogin extends cmsAction {
5252
'user_info' => array( // название ключа в $this->result
5353
'type' => 'item', // list или item
5454
'unsets' => array( // массив названий ключей для удаления
55-
'password', 'password_salt', 'pass_token', 'date_token', 'ip', 'is_admin'
55+
'password_hash', 'password', 'password_salt', 'pass_token', 'date_token', 'ip', 'is_admin'
5656
)
5757
)
5858
);
@@ -81,7 +81,7 @@ public function validateApiRequest() {
8181

8282
$this->user = $this->model_users->getUser($logged_id);
8383

84-
if ($this->user['is_admin']) {
84+
if (empty($this->api_options['allow_admin_login']) && $this->user['is_admin']) {
8585

8686
cmsUser::logout();
8787

package/system/controllers/api/api_actions/api_content_add_item.php

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -199,9 +199,8 @@ public function validateApiRequest($ctype_name = null) {
199199

200200
}
201201

202-
if (!$errors){
203-
list($this->item, $errors) = cmsEventsManager::hook('content_validate', array($this->item, $errors));
204-
}
202+
list($this->item, $errors) = cmsEventsManager::hook('content_validate', array($this->item, $errors));
203+
list($this->item, $errors, $this->ctype, $this->fields) = cmsEventsManager::hook("content_{$ctype['name']}_validate", array($this->item, $errors, $this->ctype, $this->fields), null, $this->request);
205204

206205
if($errors){
207206

@@ -288,26 +287,6 @@ public function run($ctype_name){
288287
$this->item = cmsEventsManager::hook('content_before_add', $this->item);
289288
$this->item = cmsEventsManager::hook("content_{$this->ctype['name']}_before_add", $this->item);
290289

291-
// SEO параметры
292-
$item_seo = $this->prepareItemSeo($this->item, $this->fields, $this->ctype);
293-
if(empty($this->ctype['options']['is_manual_title']) && !empty($this->ctype['options']['seo_title_pattern'])){
294-
$this->item['seo_title'] = string_replace_keys_values_extended($this->ctype['options']['seo_title_pattern'], $item_seo);
295-
}
296-
if ($this->ctype['is_auto_keys']){
297-
if(!empty($this->ctype['options']['seo_keys_pattern'])){
298-
$this->item['seo_keys'] = string_replace_keys_values_extended($this->ctype['options']['seo_keys_pattern'], $item_seo);
299-
} else {
300-
$this->item['seo_keys'] = string_get_meta_keywords($this->item['content']);
301-
}
302-
}
303-
if ($this->ctype['is_auto_desc']){
304-
if(!empty($this->ctype['options']['seo_desc_pattern'])){
305-
$this->item['seo_desc'] = string_get_meta_description(string_replace_keys_values_extended($this->ctype['options']['seo_desc_pattern'], $item_seo));
306-
} else {
307-
$this->item['seo_desc'] = string_get_meta_description($this->item['content']);
308-
}
309-
}
310-
311290
$this->item = $this->model->addContentItem($this->ctype, $this->item, $this->fields);
312291

313292
$this->bindItemToParents($this->ctype, $this->item, $this->parents);

package/system/controllers/api/api_actions/api_content_get_item.php

Lines changed: 16 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -174,30 +174,6 @@ public function run($ctype_name){
174174
}
175175
}
176176

177-
// Комментарии
178-
if ($this->ctype['is_comments'] &&
179-
$this->ctype['is_approved'] &&
180-
$this->ctype['is_comments_on'] &&
181-
$this->isControllerEnabled('comments')){
182-
183-
$this->item['is_comments_on'] = true;
184-
185-
} else {
186-
$this->item['is_comments_on'] = false;
187-
}
188-
189-
// Рейтинг. Если выключен, убираем ячейку из ответа
190-
if (!$this->ctype['is_rating'] && !$this->isControllerEnabled('rating')){
191-
unset($this->item['rating']);
192-
}
193-
194-
// Получаем теги
195-
if ($this->ctype['is_tags']){
196-
$this->item['tags'] = cmsCore::getModel('tags')->getTagsForTarget($this->name, $this->ctype['name'], $this->item['id']);
197-
} else {
198-
unset($this->item['tags']);
199-
}
200-
201177
list($this->ctype, $this->item, $fields) = cmsEventsManager::hook('content_before_item', array($this->ctype, $this->item, $fields));
202178
list($this->ctype, $this->item, $fields) = cmsEventsManager::hook("content_{$this->ctype['name']}_before_item", array($this->ctype, $this->item, $fields));
203179
list($this->ctype, $this->item, $fields) = cmsEventsManager::hook('api_content_before_item', array($this->ctype, $this->item, $fields));
@@ -209,8 +185,24 @@ public function run($ctype_name){
209185

210186
if (empty($this->item[$name]) || $field['is_system']) { continue; }
211187

188+
// проверяем что группа пользователя имеет доступ к чтению этого поля
212189
if ($field['groups_read'] && !$this->cms_user->isInGroups($field['groups_read'])) {
190+
// если группа пользователя не имеет доступ к чтению этого поля,
191+
// проверяем на доступ к нему для авторов
192+
if (!empty($this->item['user_id']) && !empty($field['options']['author_access'])){
193+
194+
if (!in_array('is_read', $field['options']['author_access'])){
195+
unset($this->item[$name]); continue;
196+
}
197+
198+
if ($this->item['user_id'] == $this->cms_user->id){
199+
unset($this->item[$name]); continue;
200+
}
201+
202+
}
203+
213204
unset($this->item[$name]); continue;
205+
214206
}
215207

216208
if (in_array($field['type'], array('images','image'))){
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<?php
2+
3+
class actionMessagesApiMessagesDeleteContact extends cmsAction {
4+
5+
public $lock_explicit_call = true;
6+
7+
public $result;
8+
9+
public $auth_required = true;
10+
11+
public $check_sig = true;
12+
13+
public $request_params = array(
14+
'contact_id' => array(
15+
'default' => 0,
16+
'rules' => array(
17+
array('required'),
18+
array('digits')
19+
)
20+
)
21+
);
22+
23+
private $contact_id;
24+
25+
public function validateApiRequest() {
26+
27+
$this->contact_id = $this->request->get('contact_id');
28+
29+
$contact = $this->model->getContact($this->cms_user->id, $this->contact_id);
30+
31+
if (!$contact){
32+
return array(
33+
'error_code' => 100,
34+
'error_msg' => '',
35+
'request_params' => array(
36+
'contact_id' => ERR_VALIDATE_INVALID
37+
)
38+
);
39+
}
40+
41+
return false;
42+
43+
}
44+
45+
public function run(){
46+
47+
$this->model->deleteContact($this->cms_user->id, $this->contact_id);
48+
49+
$count = $this->model->getContactsCount($this->cms_user->id);
50+
51+
$this->result = array(
52+
'count' => $count
53+
);
54+
55+
}
56+
57+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
3+
class actionMessagesApiMessagesDeleteMesages extends cmsAction {
4+
5+
public $lock_explicit_call = true;
6+
7+
public $result;
8+
9+
public $auth_required = true;
10+
11+
public $check_sig = true;
12+
13+
public $request_params = array(
14+
'message_ids' => array(
15+
'default' => [],
16+
'rules' => array(
17+
array('required')
18+
)
19+
)
20+
);
21+
22+
public function run(){
23+
24+
$_message_ids = $this->request->get('message_ids');
25+
26+
$message_ids = [];
27+
28+
foreach ($_message_ids as $message_id) {
29+
$message_ids[] = (int)$message_id;
30+
}
31+
32+
$delete_msg_ids = $this->model->deleteMessages($this->cms_user->id, $message_ids);
33+
34+
if($delete_msg_ids){
35+
$message_ids = array_diff($message_ids, $delete_msg_ids);
36+
}
37+
38+
$this->result = array(
39+
'remove_text' => LANG_PM_IS_DELETE,
40+
'message_ids' => $message_ids,
41+
'delete_msg_ids' => $delete_msg_ids
42+
);
43+
44+
}
45+
46+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
3+
class actionMessagesApiMessagesDeleteNotice extends cmsAction {
4+
5+
public $lock_explicit_call = true;
6+
7+
public $result;
8+
9+
public $auth_required = true;
10+
11+
public $request_params = array(
12+
'id' => array(
13+
'default' => 0,
14+
'rules' => array(
15+
array('digits')
16+
)
17+
)
18+
);
19+
20+
public function run(){
21+
22+
$notice_id = $this->request->get('id');
23+
24+
if($notice_id){
25+
26+
$notice = $this->model->getNotice($notice_id);
27+
28+
if($notice && $notice['user_id'] == $this->cms_user->id && !empty($notice['options']['is_closeable'])){
29+
$this->model->deleteNotice($notice_id);
30+
}
31+
32+
} else {
33+
$this->model->deleteUserNotices($this->cms_user->id);
34+
}
35+
36+
$this->result = array(
37+
'count' => $this->model->getNoticesCount($this->cms_user->id)
38+
);
39+
40+
}
41+
42+
}

0 commit comments

Comments
 (0)