Skip to content

Commit 13ae80e

Browse files
committed
Совместимость InstantCMS 2.16.0
1 parent f79a2e6 commit 13ae80e

File tree

13 files changed

+245
-242
lines changed

13 files changed

+245
-242
lines changed

clientExamples/instantcms/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
## Использование
1010

11-
Заполнить константы api_key, api_point, api_point_execute своими данными.
11+
Заполнить константы api_key, api_point, api_point_execute своими данными (example.com заменить на свой домен).
1212
Создать директорию /cache/api/. В ней будут кэшироваться ответы.
1313

1414
Вызовы можно осуществлять из любого места кода InstantCMS

clientExamples/instantcms/api.php

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -86,24 +86,27 @@ public static function getMethod($name, $params = [], $cacheable = false, $is_up
8686
$api_point = self::getApiPoint();
8787
}
8888

89-
$cache_file = cmsConfig::get('cache_path') . 'api/' . md5($name . serialize($params) . cmsCore::getLanguageName()) . '.dat';
89+
if ($cacheable) {
90+
91+
$cache_file = cmsConfig::get('cache_path') . 'api/' . md5($name . serialize($params) . cmsCore::getLanguageName()) . '.dat';
92+
93+
if (is_readable($cache_file)) {
9094

91-
if ($cacheable && is_readable($cache_file)) {
95+
$time_diff = (time() - filemtime($cache_file));
9296

93-
$time_diff = (time() - filemtime($cache_file));
97+
if ($time_diff < self::cache_time) {
9498

95-
if ($time_diff < self::cache_time) {
99+
$result = include $cache_file;
96100

97-
$result = include $cache_file;
101+
if ($result) {
102+
return $result;
103+
} else {
104+
unlink($cache_file);
105+
}
98106

99-
if ($result) {
100-
return $result;
101107
} else {
102108
unlink($cache_file);
103109
}
104-
105-
} else {
106-
unlink($cache_file);
107110
}
108111
}
109112

@@ -123,9 +126,7 @@ public static function getMethod($name, $params = [], $cacheable = false, $is_up
123126

124127
} elseif (cmsUser::isLogged()) {
125128

126-
$user = cmsUser::getInstance();
127-
128-
curl_setopt($curl, CURLOPT_HTTPHEADER, ['Cookie: ' . $user->api_session_name . '=' . $user->api_session_id]);
129+
curl_setopt($curl, CURLOPT_HTTPHEADER, ['Cookie: ' . cmsUser::sessionGet('user_session:session_name') . '=' . cmsUser::sessionGet('user_session:session_id')]);
129130

130131
} elseif (cmsUser::isSessionSet('guest_session:session_id')) {
131132

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 = "3"
8+
minor = "4"
99
build = "0"
10-
date = "20200409"
10+
date = "20230620"
1111

1212
[depends]
13-
core = "2.11.0"
13+
core = "2.14.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 = "3"
8+
minor = "4"
99
build = "0"
10-
date = "20200409"
10+
date = "20230620"
1111

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

1515
[author]
1616
name = "InstantCMS Team"

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

Lines changed: 44 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22
/******************************************************************************/
33
// //
44
// InstantMedia //
5-
// http://instantmedia.ru/, [email protected] //
6-
// written by Fuze //
5+
// http://instantmedia.ru/ //
6+
// written by Fuze //
77
// //
88
/******************************************************************************/
99

1010
class actionApiMethod extends cmsAction {
1111

12-
private $method_params = array();
12+
private $method_params = [];
1313
private $method_controller_name = null;
1414
private $method_action_name = null;
1515

@@ -18,21 +18,19 @@ class actionApiMethod extends cmsAction {
1818
* @var object
1919
*/
2020
private $method_controller = null;
21+
2122
/**
2223
* Объект класса api метода
2324
* @var object
2425
*/
25-
private $method_action = null;
26+
private $method_action = null;
2627

27-
public function __construct($controller, $params=array()){
28+
public function __construct($controller, $params = []) {
2829

2930
parent::__construct($controller, $params);
3031

3132
$this->loadApiKey();
3233

33-
// для метода after ставим коллбэк, нам не нужен вывод на экран шаблона
34-
$this->setCallback('after', array(array($controller, 'renderJSON')));
35-
3634
}
3735

3836
/**
@@ -44,7 +42,10 @@ public function __construct($controller, $params=array()){
4442
private function initMethod($method_name) {
4543

4644
$this->method_name = $method_name;
47-
if(empty($this->method_name)){ return $this; }
45+
46+
if (!$this->method_name) {
47+
return $this;
48+
}
4849

4950
$segments = explode('.', $method_name);
5051

@@ -53,40 +54,37 @@ private function initMethod($method_name) {
5354

5455
$this->method_controller_name = trim($segments[0]);
5556

56-
if ($this->method_controller_name && !preg_match('/^[a-z]{1}[a-z0-9_]*$/', $this->method_controller_name)){
57+
if ($this->method_controller_name && !preg_match('/^[a-z]{1}[a-z0-9_]*$/', $this->method_controller_name)) {
5758
$this->method_controller_name = null;
5859
}
5960

6061
if ($this->method_controller_name && !cmsCore::isControllerExists($this->method_controller_name)) {
6162
$this->method_controller_name = null;
6263
}
6364

64-
if($this->method_controller_name){
65+
if ($this->method_controller_name) {
6566
$this->method_controller = cmsCore::getController($this->method_controller_name, $this->request);
6667
}
67-
6868
}
6969
// действие
7070
if (isset($segments[1])) {
7171

7272
$this->method_action_name = trim($segments[1]);
7373

74-
if ($this->method_action_name && !preg_match('/^[a-z]{1}[a-z0-9_]*$/', $this->method_action_name)){
74+
if ($this->method_action_name && !preg_match('/^[a-z]{1}[a-z0-9_]*$/', $this->method_action_name)) {
7575
$this->method_action_name = null;
7676
}
7777

78-
if($this->method_action_name && $this->method_controller !== null){
79-
$this->method_controller->current_action = 'api_'.$this->method_controller_name.'_'.$this->method_action_name;
78+
if ($this->method_action_name && $this->method_controller !== null) {
79+
$this->method_controller->current_action = 'api_' . $this->method_controller_name . '_' . $this->method_action_name;
8080
}
81-
8281
}
8382
// Параметры действия
84-
if (count($segments) > 2){
83+
if (count($segments) > 2) {
8584
$this->method_params = array_slice($segments, 2);
8685
}
8786

8887
return $this;
89-
9088
}
9189

9290
/**
@@ -279,7 +277,6 @@ public function run($method_name = null){
279277

280278
// действия после успешного запроса
281279
return $this->afterRequest();
282-
283280
}
284281

285282
/**
@@ -289,25 +286,25 @@ public function run($method_name = null){
289286
private function afterRequest() {
290287

291288
// записываем в лог, если включено
292-
if(!empty($this->options['log_success'])){
293-
$this->model->log(array(
294-
'request_time' => number_format(cmsCore::getTime(), 4),
295-
'method' => $this->method_name,
296-
'key_id' => $this->key['id']
297-
));
289+
if (!empty($this->options['log_success'])) {
290+
291+
$this->model->log([
292+
'request_time' => number_format((microtime(true) - $this->start_time), 4),
293+
'method' => $this->method_name,
294+
'key_id' => $this->key['id']
295+
]);
298296
}
299297

300298
return true;
301-
302299
}
303300

304301
private function validateMethodParams() {
305302

306-
if(empty($this->method_action->request_params)){
303+
if (empty($this->method_action->request_params)) {
307304
return false;
308305
}
309306

310-
$errors = array();
307+
$errors = [];
311308

312309
// валидация аналогична валидации форм
313310
foreach ($this->method_action->request_params as $param_name => $rules) {
@@ -320,44 +317,44 @@ private function validateMethodParams() {
320317

321318
$this->request->set($param_name, $value);
322319

323-
} elseif(!is_null($value) && isset($rules['default'])){
320+
} elseif (!is_null($value) && isset($rules['default'])) {
324321

325322
$value = $this->request->get($param_name, $rules['default']);
326323

327324
// для применения типизации переменной
328325
$this->request->set($param_name, $value);
329-
330326
}
331327

332-
if(!empty($rules['rules'])){
328+
if (!empty($rules['rules'])) {
333329
foreach ($rules['rules'] as $rule) {
334330

335-
if (!$rule) { continue; }
331+
if (!$rule) {
332+
continue;
333+
}
336334

337335
$validate_function = "validate_{$rule[0]}";
338336

339337
$rule[] = $value;
340338

341339
unset($rule[0]);
342340

343-
$result = call_user_func_array(array($this, $validate_function), $rule);
341+
$result = call_user_func_array([$this, $validate_function], $rule);
344342

345343
// если получилось false, то дальше не проверяем, т.к.
346344
// ошибка уже найдена
347345
if ($result !== true) {
348346
$errors[$param_name] = $result;
349347
break;
350348
}
351-
352349
}
353350
}
354-
355351
}
356352

357-
if (!sizeof($errors)) { return false; }
353+
if (!sizeof($errors)) {
354+
return false;
355+
}
358356

359357
return $errors;
360-
361358
}
362359

363360
/**
@@ -367,23 +364,27 @@ private function validateMethodParams() {
367364
public function checkRequest() {
368365

369366
$parent_succes = parent::checkRequest();
370-
if(!$parent_succes){ return false; }
371367

372-
if(empty($this->method_name) ||
368+
if (!$parent_succes) {
369+
return false;
370+
}
371+
372+
if (empty($this->method_name) ||
373373
empty($this->method_controller_name) ||
374-
$this->method_controller === null){
374+
$this->method_controller === null) {
375+
375376
return $this->error(3);
376377
}
377378

378-
if(empty($this->method_action_name)){
379+
if (empty($this->method_action_name)) {
379380
return $this->error(8);
380381
}
381382

382-
if(!$this->method_controller->isEnabled()){
383+
if (!$this->method_controller->isEnabled()) {
383384
return $this->error(23);
384385
}
385386

386-
$check_method_name = $this->method_controller_name.'.'.$this->method_action_name;
387+
$check_method_name = $this->method_controller_name . '.' . $this->method_action_name;
387388

388389
$is_view = !$this->key['key_methods']['allow'] || in_array($check_method_name, $this->key['key_methods']['allow']);
389390
$is_hide = $this->key['key_methods']['disallow'] && in_array($check_method_name, $this->key['key_methods']['disallow']);
@@ -394,7 +395,6 @@ public function checkRequest() {
394395
}
395396

396397
return true;
397-
398398
}
399399

400400
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ public function run($ctype_name){
154154
if (empty($this->ctype['options']['list_on'])) { return; }
155155

156156
// параметры
157-
$perpage = (empty($this->ctype['options']['limit']) ? content::perpage : $this->ctype['options']['limit']);
157+
$perpage = (empty($this->ctype['options']['limit']) ? 10 : $this->ctype['options']['limit']);
158158
$page = $this->request->get('page');
159159
$hide_root = !empty($this->ctype['options']['is_empty_root']) && $this->cat['id'] == 1;
160160

0 commit comments

Comments
 (0)