1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
publicaction.php
См. документацию.
1<?php
2namespace Bitrix\Landing;
3
4use Bitrix\Main\Application;
5use Bitrix\Rest\AppTable;
6use Bitrix\Landing\Site\Type;
7use Bitrix\Main\Localization\Loc;
8use Bitrix\Main\ModuleManager;
9
10Loc::loadMessages(__FILE__);
11
13{
17 const REST_SCOPE_DEFAULT = 'landing';
18
22 const REST_SCOPE_CLOUD = 'landing_cloud';
23
27 public const REST_USAGE_TYPE_BLOCK = 'blocks';
28
32 public const REST_USAGE_TYPE_PAGE = 'pages';
33
38 protected static $restApp = null;
39
44 protected static $rawData = null;
45
50 protected static function getNamespacePublicClasses()
51 {
52 return __NAMESPACE__ . '\\PublicAction';
53 }
54
62 protected static function getMethodInfo($action, $data = array())
63 {
64 $info = array();
65
66 // if action exist and is callable
67 if ($action && mb_strpos($action, '::'))
68 {
69 $actionOriginal = $action;
70 $action = self::getNamespacePublicClasses() . '\\' . $action;
71 if (is_callable(explode('::', $action)))
72 {
73 [$class, $method] = explode('::', $action);
74 $info = array(
75 'action' => $actionOriginal,
76 'class' => $class,
77 'method' => $method,
78 'params_init' => array(),
79 'params_missing' => array()
80 );
81 // parse func params
82 $reflection = new \ReflectionMethod($class, $method);
83 $static = $reflection->getStaticVariables();
84 $mixedParams = isset($static['mixedParams'])
85 ? $static['mixedParams']
86 : [];
87 foreach ($reflection->getParameters() as $param)
88 {
89 $name = $param->getName();
90 if (isset($data[$name]))
91 {
92 if (!in_array($name, $mixedParams))
93 {
94 if (
95 $param->isArray() &&
96 !is_array($data[$name])
97 ||
98 !$param->isArray() &&
99 is_array($data[$name])
100
101 )
102 {
103 throw new \Bitrix\Main\ArgumentTypeException(
104 $name
105 );
106 }
107 }
108 $info['params_init'][$name] = $data[$name];
109 }
110 elseif ($param->isDefaultValueAvailable())
111 {
112 $info['params_init'][$name] = $param->getDefaultValue();
113 }
114 else
115 {
116 $info['params_missing'][] = $name;
117 }
118 }
119 }
120 }
121
122 return $info;
123 }
124
131 protected static function checkForExtranet(): bool
132 {
134 {
135 return true;
136 }
137
138 if (Type::getCurrentScopeId() === Type::SCOPE_CODE_GROUP)
139 {
140 return true;
141 }
142
143 if (\Bitrix\Main\Loader::includeModule('extranet'))
144 {
145 return \CExtranet::isIntranetUser(
146 \CExtranet::getExtranetSiteID(),
148 );
149 }
150
151 return true;
152 }
153
162 protected static function actionProcessing($action, $data, $isRest = false)
163 {
164 if (!is_array($data))
165 {
166 $data = array();
167 }
168
169 if (isset($data['scope']))
170 {
171 Type::setScope($data['scope']);
172 }
173
174 $error = new Error;
175
176 // not for guest
177 if (!Manager::getUserId() || !self::checkForExtranet())
178 {
179 $error->addError(
180 'ACCESS_DENIED',
181 Loc::getMessage('LANDING_ACCESS_DENIED2')
182 );
183 }
184 // tmp flag for compatibility
185 else if (
186 ModuleManager::isModuleInstalled('bitrix24') &&
187 Manager::getOption('temp_permission_admin_only') &&
188 !\CBitrix24::isPortalAdmin(Manager::getUserId())
189 )
190 {
191 $error->addError(
192 'ACCESS_DENIED',
193 Loc::getMessage('LANDING_ACCESS_DENIED2')
194 );
195 }
196 // check common permission
197 else if (
200 null,
201 true
202 )
203 )
204 {
205 $error->addError(
206 'ACCESS_DENIED',
207 Loc::getMessage('LANDING_ACCESS_DENIED2')
208 );
209 }
210 else if (!Manager::isB24() && Manager::getApplication()->getGroupRight('landing') < 'W')
211 {
212 $error->addError(
213 'ACCESS_DENIED',
214 Loc::getMessage('LANDING_ACCESS_DENIED2')
215 );
216 }
217 // if method::action exist in PublicAction, call it
218 elseif (($action = self::getMethodInfo($action, $data)))
219 {
220 if (!$isRest && !check_bitrix_sessid())
221 {
222 $error->addError(
223 'SESSION_EXPIRED',
224 Loc::getMessage('LANDING_SESSION_EXPIRED')
225 );
226 }
227 if (!empty($action['params_missing']))
228 {
229 $error->addError(
230 'MISSING_PARAMS',
231 Loc::getMessage('LANDING_MISSING_PARAMS', array(
232 '#MISSING#' => implode(', ', $action['params_missing'])
233 ))
234 );
235 }
236 if (method_exists($action['class'], 'init'))
237 {
238 $result = call_user_func_array(
239 array($action['class'], 'init'),
240 []
241 );
242 if (!$result->isSuccess())
243 {
244 $error->copyError($result->getError());
245 }
246 }
247 // all right - execute
248 if ($error->isEmpty())
249 {
250 try
251 {
252 $result = call_user_func_array(
253 array($action['class'], $action['method']),
254 $action['params_init']
255 );
256 // answer
257 if ($result === null)// void is accepted as success
258 {
259 return array(
260 'type' => 'success',
261 'result' => true
262 );
263 }
264 else if ($result->isSuccess())
265 {
266 $restResult = $result->getResult();
267 $event = new \Bitrix\Main\Event('landing', 'onSuccessRest', [
268 'result' => $restResult,
269 'action' => $action
270 ]);
271 $event->send();
272 foreach ($event->getResults() as $eventResult)
273 {
274 if (($modified = $eventResult->getModified()))
275 {
276 if (isset($modified['result']))
277 {
278 $restResult = $modified['result'];
279 }
280 }
281 }
282 return array(
283 'type' => 'success',
284 'result' => $restResult
285 );
286 }
287 else
288 {
289 $error->copyError($result->getError());
290 }
291 }
292 catch (\TypeError $e)
293 {
294 $error->addError(
295 'TYPE_ERROR',
296 $e->getMessage()
297 );
298 }
299 catch (\Exception $e)
300 {
301 $error->addError(
302 'SYSTEM_ERROR',
303 $e->getMessage()
304 );
305 }
306 }
307 }
308 // error
309 $errors = array();
310 foreach ($error->getErrors() as $error)
311 {
312 $errors[] = array(
313 'error' => $error->getCode(),
314 'error_description' => $error->getMessage()
315 );
316 }
317 if (!$isRest)
318 {
319 return [
320 'sessid' => bitrix_sessid(),
321 'type' => 'error',
322 'result' => $errors
323 ];
324 }
325 else
326 {
327 return [
328 'type' => 'error',
329 'result' => $errors
330 ];
331 }
332 }
333
338 public static function getRawData()
339 {
340 return self::$rawData;
341 }
342
348 public static function ajaxProcessing()
349 {
350 $context = Application::getInstance()->getContext();
351 $request = $context->getRequest();
352 $files = $request->getFileList();
353 $postlist = $context->getRequest()->getPostList();
354
355 Type::setScope($request->get('type'));
356
357 // multiple commands
358 if (
359 $request->offsetExists('batch')
360 && is_array($request->get('batch'))
361 )
362 {
363 $result = array();
364 // additional site id detect
365 if ($request->offsetExists('site_id'))
366 {
367 $siteId = $request->get('site_id');
368 }
369 foreach ($request->get('batch') as $key => $batchItem)
370 {
371 if (
372 isset($batchItem['action']) &&
373 isset($batchItem['data'])
374 )
375 {
376 $batchItem['data'] = (array)$batchItem['data'];
377 if (isset($siteId))
378 {
379 $batchItem['data']['siteId'] = $siteId;
380 }
381 if ($files)
382 {
383 foreach ($files as $code => $file)
384 {
385 $batchItem['data'][$code] = $file;
386 }
387 }
388 $rawData = $postlist->getRaw('batch');
389 if (isset($rawData[$key]['data']))
390 {
391 self::$rawData = $rawData[$key]['data'];
392 }
393 $result[$key] = self::actionProcessing(
394 $batchItem['action'],
395 $batchItem['data']
396 );
397 }
398 }
399
400 return $result;
401 }
402
403 // or single command
404 else if (
405 $request->offsetExists('action')
406 && $request->offsetExists('data')
407 && is_array($request->get('data'))
408 )
409 {
410 $data = $request->get('data');
411 // additional site id detect
412 if ($request->offsetExists('site_id'))
413 {
414 $data['siteId'] = $request->get('site_id');
415 }
416 if ($files)
417 {
418 foreach ($files as $code => $file)
419 {
420 $data[$code] = $file;
421 }
422 }
423 $rawData = $postlist->getRaw('data');
424 if (isset($rawData['data']))
425 {
426 self::$rawData = $rawData['data'];
427 }
428 return self::actionProcessing(
429 $request->get('action'),
430 $data
431 );
432 }
433
434 return null;
435 }
436
442 public static function restBase()
443 {
444 static $restMethods = array();
445
446 if (empty($restMethods))
447 {
448 $restMethods[self::REST_SCOPE_DEFAULT] = array();
449 $restMethods[self::REST_SCOPE_CLOUD] = array();
450
451 $classes = array(
452 self::REST_SCOPE_DEFAULT => array(
453 'block', 'site', 'landing', 'repo', 'template',
454 'demos', 'role', 'syspage', 'chat', 'repowidget'
455 ),
456 self::REST_SCOPE_CLOUD => array(
457 'cloud'
458 )
459 );
460
461 // then methods list for each class
462 foreach ($classes as $scope => $classList)
463 {
464 foreach ($classList as $className)
465 {
466 $fullClassName = self::getNamespacePublicClasses() . '\\' . $className;
467 $class = new \ReflectionClass($fullClassName);
468 $methods = $class->getMethods(\ReflectionMethod::IS_PUBLIC);
469 foreach ($methods as $method)
470 {
471 $static = $method->getStaticVariables();
472 if (!isset($static['internal']) || !$static['internal'])
473 {
474 $command = $scope.'.'.
475 mb_strtolower($className).'.'.
476 mb_strtolower($method->getName());
477 $restMethods[$scope][$command] = array(
478 __CLASS__, 'restGateway'
479 );
480 }
481 }
482 }
483 }
484 }
485
486 return array(
487 self::REST_SCOPE_DEFAULT => $restMethods[self::REST_SCOPE_DEFAULT],
488 self::REST_SCOPE_CLOUD => $restMethods[self::REST_SCOPE_CLOUD]
489 );
490 }
491
500 public static function restGateway($fields, $t, $server)
501 {
502 // get context app
503 self::$restApp = AppTable::getByClientId($server->getClientId());
504 // prepare method and call action
505 $method = $server->getMethod();
506 $method = mb_substr($method, mb_strpos($method, '.') + 1);// delete module-prefix
507 $method = preg_replace('/\./', '\\', $method, substr_count($method, '.') - 1);
508 $method = str_replace('.', '::', $method);
509 $result = self::actionProcessing(
510 $method,
511 $fields,
512 true
513 );
514 // prepare answer
515 if ($result['type'] == 'error')
516 {
517 foreach ($result['result'] as $error)
518 {
519 throw new \Bitrix\Rest\RestException(
520 $error['error_description'],
521 $error['error']
522 );
523 }
524 }
525 else
526 {
527 return $result['result'];
528 }
529 }
530
535 public static function restApplication()
536 {
537 return self::$restApp;
538 }
539
545 public static function restApplicationDelete($app)
546 {
547 if (isset($app['APP_ID']) && $app['APP_ID'])
548 {
549 if (($app = AppTable::getByClientId($app['APP_ID'])))
550 {
556 }
557 }
558 }
559
566 {
567 $parameters = $event->getParameters();
568
569 if ($app = AppTable::getByClientId($parameters['ID']))
570 {
571 $stat = self::getRestStat(true);
572 if (isset($stat[self::REST_USAGE_TYPE_BLOCK][$app['CODE']]))
573 {
574 $eventResult = new \Bitrix\Main\EventResult(
575 \Bitrix\Main\EventResult::ERROR,
576 new \Bitrix\Main\Error(
577 Loc::getMessage('LANDING_REST_DELETE_EXIST_BLOCKS'),
578 'LANDING_EXISTS_BLOCKS'
579 )
580 );
581
582 return $eventResult;
583 }
584 else if (isset($stat[self::REST_USAGE_TYPE_PAGE][$app['CODE']]))
585 {
586 $eventResult = new \Bitrix\Main\EventResult(
587 \Bitrix\Main\EventResult::ERROR,
588 new \Bitrix\Main\Error(
589 Loc::getMessage('LANDING_REST_DELETE_EXIST_PAGES'),
590 'LANDING_EXISTS_PAGES'
591 )
592 );
593
594 return $eventResult;
595 }
596 }
597 }
598
606 public static function getRestStat(bool $humanFormat = false, bool $onlyActive = true, array $additionalFilter = []): array
607 {
608 $blockCnt = [];
609 $fullStat = [
610 self::REST_USAGE_TYPE_BLOCK => [],
611 self::REST_USAGE_TYPE_PAGE => []
612 ];
613 $activeValues = $onlyActive ? 'Y' : ['Y', 'N'];
614 $filter = [
615 '=%CODE' => 'repo_%',
616 '=DELETED' => 'N',
617 '=PUBLIC' => $activeValues,
618 '=LANDING.ACTIVE' => $activeValues,
619 '=LANDING.SITE.ACTIVE' => $activeValues
620 ];
621
622 if (isset($additionalFilter['SITE_ID']))
623 {
624 $filter['LANDING.SITE_ID'] = $additionalFilter['SITE_ID'];
625 }
626
628
629 // gets all partners active block, placed on pages
630 $res = Internals\BlockTable::getList([
631 'select' => [
632 'CODE', 'CNT'
633 ],
634 'filter' => $filter,
635 'group' => [
636 'CODE'
637 ],
638 'runtime' => [
639 new \Bitrix\Main\Entity\ExpressionField('CNT', 'COUNT(*)')
640 ]
641 ]);
642 while ($row = $res->fetch())
643 {
644 $blockCnt[mb_substr($row['CODE'], 5)] = $row['CNT'];
645 }
646
647 // gets apps for this blocks
649 'select' => [
650 'ID', 'APP_CODE'
651 ],
652 'filter' => [
653 'ID' => array_keys($blockCnt)
654 ]
655 ]);
656 while ($row = $res->fetch())
657 {
658 if (!$row['APP_CODE'])
659 {
660 continue;
661 }
662 if (!isset($fullStat[self::REST_USAGE_TYPE_BLOCK][$row['APP_CODE']]))
663 {
664 $fullStat[self::REST_USAGE_TYPE_BLOCK][$row['APP_CODE']] = 0;
665 }
666 $fullStat[self::REST_USAGE_TYPE_BLOCK][$row['APP_CODE']] += $blockCnt[$row['ID']];
667 }
668 unset($blockCnt);
669
670 // gets additional partners active block with not empty INITIATOR_APP_CODE, placed on pages
671 $filter['!CODE'] = $filter['CODE'];
672 unset($filter['CODE']);
673 $filter['!=INITIATOR_APP_CODE'] = null;
674 $res = Internals\BlockTable::getList([
675 'select' => [
676 'INITIATOR_APP_CODE', 'CNT'
677 ],
678 'filter' => $filter,
679 'group' => [
680 'INITIATOR_APP_CODE'
681 ],
682 'runtime' => [
683 new \Bitrix\Main\Entity\ExpressionField('CNT', 'COUNT(*)')
684 ]
685 ]);
686 while ($row = $res->fetch())
687 {
688 $appCode = $row['INITIATOR_APP_CODE'];
689 if (!isset($fullStat[self::REST_USAGE_TYPE_BLOCK][$appCode]))
690 {
691 $fullStat[self::REST_USAGE_TYPE_BLOCK][$appCode] = 0;
692 }
693 $fullStat[self::REST_USAGE_TYPE_BLOCK][$appCode] += $row['CNT'];
694 }
695
696 // gets all partners active pages
697 $filter = [
698 '=DELETED' => 'N',
699 '=ACTIVE' => $activeValues,
700 '=SITE.ACTIVE' => $activeValues,
701 '!=INITIATOR_APP_CODE' => null
702 ];
703 if (isset($additionalFilter['SITE_ID']))
704 {
705 $filter['SITE_ID'] = $additionalFilter['SITE_ID'];
706 }
708 'select' => [
709 'INITIATOR_APP_CODE', 'CNT'
710 ],
711 'filter' => $filter,
712 'group' => [
713 'INITIATOR_APP_CODE'
714 ],
715 'runtime' => [
716 new \Bitrix\Main\Entity\ExpressionField('CNT', 'COUNT(*)')
717 ]
718 ]);
719 while ($row = $res->fetch())
720 {
721 $appCode = $row['INITIATOR_APP_CODE'];
722 if (!isset($fullStat[self::REST_USAGE_TYPE_PAGE][$appCode]))
723 {
724 $fullStat[self::REST_USAGE_TYPE_PAGE][$appCode] = 0;
725 }
726 $fullStat[self::REST_USAGE_TYPE_PAGE][$appCode] += $row['CNT'];
727 }
728
729 // get client id for apps
730 if (!$humanFormat && \Bitrix\Main\Loader::includeModule('rest'))
731 {
732 $appsCode = array_merge(
733 array_keys($fullStat[self::REST_USAGE_TYPE_BLOCK]),
734 array_keys($fullStat[self::REST_USAGE_TYPE_PAGE])
735 );
736 $fullStatNew = [
737 self::REST_USAGE_TYPE_BLOCK => [],
738 self::REST_USAGE_TYPE_PAGE => []
739 ];
740 if ($appsCode)
741 {
742 $appsCode = array_unique($appsCode);
743 $res = AppTable::getList([
744 'select' => [
745 'CLIENT_ID', 'CODE'
746 ],
747 'filter' => [
748 '=CODE' => $appsCode
749 ]
750 ]);
751 while ($row = $res->fetch())
752 {
753 foreach ($fullStat as $code => $stat)
754 {
755 if (isset($stat[$row['CODE']]))
756 {
757 $fullStatNew[$code][$row['CLIENT_ID']] = $stat[$row['CODE']];
758 }
759 }
760 }
761 }
762
763 return $fullStatNew;
764 }
765
767
768 return $fullStat;
769 }
770}
if(!Loader::includeModule('catalog')) if(!AccessController::getCurrent() ->check(ActionDictionary::ACTION_PRICE_EDIT)) if(!check_bitrix_sessid()) $request
Определения catalog_reindex.php:36
static deleteByAppCode($code)
Определения demos.php:27
static isB24()
Определения manager.php:1135
static getOption($code, $default=null)
Определения manager.php:160
static getApplication()
Определения manager.php:71
static getUserId()
Определения manager.php:107
static isAdmin()
Определения manager.php:135
static deleteByAppId($id)
Определения placement.php:17
static getList(array $params=[])
Определения landing.php:594
static getList(array $params=array())
Определения repo.php:625
static restApplicationDelete($app)
Определения publicaction.php:545
static beforeRestApplicationDelete(\Bitrix\Main\Event $event)
Определения publicaction.php:565
static getRestStat(bool $humanFormat=false, bool $onlyActive=true, array $additionalFilter=[])
Определения publicaction.php:606
static getNamespacePublicClasses()
Определения publicaction.php:50
static restGateway($fields, $t, $server)
Определения publicaction.php:500
const REST_SCOPE_CLOUD
Определения publicaction.php:22
static getRawData()
Определения publicaction.php:338
static $restApp
Определения publicaction.php:38
const REST_USAGE_TYPE_PAGE
Определения publicaction.php:32
static restApplication()
Определения publicaction.php:535
static actionProcessing($action, $data, $isRest=false)
Определения publicaction.php:162
static ajaxProcessing()
Определения publicaction.php:348
const REST_SCOPE_DEFAULT
Определения publicaction.php:17
static $rawData
Определения publicaction.php:44
const REST_USAGE_TYPE_BLOCK
Определения publicaction.php:27
static getMethodInfo($action, $data=array())
Определения publicaction.php:62
static restBase()
Определения publicaction.php:442
static checkForExtranet()
Определения publicaction.php:131
static deleteByAppCode($code)
Определения repo.php:216
const ADDITIONAL_RIGHTS
Определения rights.php:33
static setOff()
Определения rights.php:89
static setOn()
Определения rights.php:98
static hasAdditionalRight($code, $type=null, bool $checkExtraRights=false, bool $strict=false)
Определения rights.php:1027
setScope($scope)
Определения controller.php:373
Определения error.php:15
$data['IS_AVAILABLE']
Определения .description.php:13
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$res
Определения filter_act.php:7
$result
Определения get_property_values.php:14
$errors
Определения iblock_catalog_edit.php:74
$filter
Определения iblock_catalog_list.php:54
$app
Определения proxy.php:8
$context
Определения csv_new_setup.php:223
if(!is_null($config))($config as $configItem)(! $configItem->isVisible()) $code
Определения options.php:195
$siteId
Определения ajax.php:8
if($NS['step']==6) if( $NS[ 'step']==7) if(COption::GetOptionInt('main', 'disk_space', 0) > 0) $info
Определения backup.php:924
check_bitrix_sessid($varname='sessid')
Определения tools.php:4686
bitrix_sessid()
Определения tools.php:4656
$name
Определения menu_edit.php:35
Определения agent.php:3
Определения ufield.php:9
$files
Определения mysql_to_pgsql.php:30
Определения buffer.php:3
$event
Определения prolog_after.php:141
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения prolog_main_admin.php:393
if(empty($signedUserToken)) $key
Определения quickway.php:257
$method
Определения index.php:27
$error
Определения subscription_card_product.php:20
$action
Определения file_dialog.php:21
$fields
Определения yandex_run.php:501