1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
site.php
См. документацию.
1<?php
2namespace Bitrix\Landing\Transfer\Import;
3
4use Bitrix\Landing\History;
5use Bitrix\Landing\Metrika;
6use Bitrix\Main\Loader;
7use Bitrix\Main\Event;
8use Bitrix\Main\ORM\Data\AddResult;
9use Bitrix\Main\Localization\Loc;
10use Bitrix\Main\ModuleManager;
11use Bitrix\Main\Web\Json;
12use Bitrix\Rest\Marketplace;
13use Bitrix\Rest\Configuration;
14use Bitrix\Landing\Hook\Page\Copyright;
15use Bitrix\Landing\Hook\Page\B24button;
16use Bitrix\Landing\Rights;
17use Bitrix\Landing\Site as SiteCore;
18use Bitrix\Landing\Landing as LandingCore;
19use Bitrix\Landing\Site\Type;
20use Bitrix\Landing\Transfer\AppConfiguration;
21use Bitrix\Landing\Block;
22use Bitrix\Landing\File;
23use Bitrix\Landing\Hook;
24use Bitrix\Landing\Template;
25use Bitrix\Landing\TemplateRef;
26use Bitrix\Landing\Manager;
27use Bitrix\Landing\Syspage;
28use Bitrix\Landing\Internals\BlockTable;
29use Bitrix\Landing\Site\Scope;
30
31Loc::loadMessages(__FILE__);
32
36class Site
37{
43 public static function getUrl(string $type): string
44 {
45 if (!\Bitrix\Main\Loader::includeModule('rest'))
46 {
47 return '';
48 }
51 );
52 }
53
59 public static function getInitManifest(Event $event): ?array
60 {
61 $manifest = [
62 'NEXT' => false,
63 ];
64
65 $code = $event->getParameter('CODE');
66 if ($code === 'landing_mainpage')
67 {
68 $mainpageManager = new \Bitrix\Landing\Mainpage\Manager();
69 $siteId = $mainpageManager->getConnectedSiteId();
70 if ($siteId)
71 {
72 $manifest['SETTING'] = [
73 'replaceSiteId' => $siteId,
74 ];
75 }
76 }
77
78 return $manifest;
79 }
80
87 protected static function importSite(array $data, Configuration\Structure $structure): AddResult
88 {
89 $code = isset($data['CODE']) ? $data['CODE'] : null;
90
91 // clear old keys
92 $notAllowedKeys = [
93 'ID', 'DOMAIN_ID', 'DATE_CREATE', 'DATE_MODIFY',
94 'CREATED_BY_ID', 'MODIFIED_BY_ID', 'CODE',
95 ];
96 foreach ($notAllowedKeys as $key)
97 {
98 if (isset($data[$key]))
99 {
100 unset($data[$key]);
101 }
102 }
103
104 // if site path are exist, create random one
105 if ($code)
106 {
107 $check = SiteCore::getList([
108 'select' => [
109 'ID',
110 ],
111 'filter' => [
112 '=CODE' => $code,
113 ],
114 ]);
115 if ($check->fetch())
116 {
117 $code = null;
118 }
119 }
120 if (!$code)
121 {
122 $code = strtolower(\randString(10));
123 }
124 $data['CODE'] = $code;
125 $data['ACTIVE'] = 'Y';
126
127 // files
128 $files = [];
129 foreach (Hook::HOOKS_CODES_FILES as $hookCode)
130 {
131 if (
132 isset($data['ADDITIONAL_FIELDS'][$hookCode]) &&
133 $data['ADDITIONAL_FIELDS'][$hookCode] > 0
134 )
135 {
136 $unpackFile = $structure->getUnpackFile($data['ADDITIONAL_FIELDS'][$hookCode]);
137 if ($unpackFile)
138 {
139 $files[] = $data['ADDITIONAL_FIELDS'][$hookCode] = AppConfiguration::saveFile(
140 $unpackFile
141 );
142 }
143 else
144 {
145 unset($data['ADDITIONAL_FIELDS'][$hookCode]);
146 }
147 }
148 }
149
150 $res = SiteCore::add($data);
151
152 // save files to site
153 if ($files && $res->isSuccess())
154 {
155 foreach ($files as $fileId)
156 {
157 File::addToSite($res->getId(), $fileId);
158 }
159 }
160
161 return $res;
162 }
163
169 public static function nextStep(Event $event): ?array
170 {
171 $code = $event->getParameter('CODE');
172 $content = $event->getParameter('CONTENT');
173 $ratio = $event->getParameter('RATIO');
174 $contextUser = $event->getParameter('CONTEXT_USER');
175 $userId = $event->getParameter('USER_ID');
176 $settings = $event->getParameter('SETTING');
177 $additional = $event->getParameter('ADDITIONAL_OPTION');
178 $structure = new Configuration\Structure($contextUser);
179 $return = [
180 'RATIO' => $ratio[$code] ?? [],
181 'ERROR_EXCEPTION' => [],
182 ];
183
184 if (!isset($content['~DATA']))
185 {
186 return null;
187 }
188
189 if ($userId)
190 {
192 }
193
194 $isPageImport = $return['RATIO']['IS_PAGE_IMPORT'] ?? false;
195 $isPageStep = false;
196
197 if (isset($ratio[$code]['SITE_ID']) && (int)$ratio[$code]['SITE_ID'] > 0)
198 {
199 $isPageStep = true;
200 }
201 elseif ($additional && (int)$additional['siteId'] > 0)
202 {
203 $return['RATIO']['SITE_ID'] = (int)$additional['siteId'];
204 $isPageImport = $return['RATIO']['IS_PAGE_IMPORT'] ?? true;
205 }
206
207 // check if not add new site - just replace lid
208 $isReplaceLanding = false;
209 if (isset($ratio[$code]['REPLACE_LID']) && (int)$ratio[$code]['REPLACE_LID'] > 0)
210 {
211 $isReplaceLanding = true;
212 }
213 elseif ($additional && (int)$additional['replaceLid'] > 0)
214 {
215 $return['RATIO']['REPLACE_LID'] = (int)$additional['replaceLid'];
216 $isReplaceLanding = true;
217 }
218
219 $isReplaceSiteLandings = false;
220 if ($settings && (int)$settings['replaceSiteId'] > 0)
221 {
222 $return['RATIO']['REPLACE_SITE_ID'] = (int)$settings['replaceSiteId'];
223 $return['RATIO']['SITE_ID'] = (int)$settings['replaceSiteId'];
224 $isReplaceSiteLandings = true;
225 }
226
227 $siteId = (int)$return['RATIO']['SITE_ID'];
228 $isReplace = $isReplaceLanding || $isReplaceSiteLandings;
229
230 // common ratio params
231 $data = self::prepareData($content['~DATA']);
232 $data = self::prepareAdditionalFields($data, $additional);
233 Type::setScope($data['TYPE']);
234 if ($data['TYPE'] === 'MAINPAGE')
235 {
236 (new \Bitrix\Landing\Mainpage\Manager())->onStartPageCreation();
237 }
238
239 if ($isReplace && !$isPageStep)
240 {
241 $additionalFieldsSite = $data['ADDITIONAL_FIELDS'] ?? [];
242 $additionalFieldsSite = array_filter(
243 $additionalFieldsSite,
244 function ($code) {
245 return in_array($code, Hook::HOOKS_CODES_DESIGN);
246 },
247 ARRAY_FILTER_USE_KEY
248 );
249 $return['RATIO']['ADDITIONAL_FIELDS_SITE'] = $additionalFieldsSite;
250 $return['RATIO']['ADDITIONAL_FIELDS_SITE_BEFORE'] = Landing::getAdditionalFieldsForReplaceBySite($siteId);
251
252 // for history
253 if ($isReplaceSiteLandings)
254 {
255 $landings = LandingCore::getList([
256 'select' => ['ID', 'TPL_ID'],
257 'filter' => [
258 'SITE_ID' => $siteId,
259 '=DELETED' => 'N',
260 ],
261 ]);
262 while ($landing = $landings->fetch())
263 {
264 $lid = (int)$landing['ID'];
265 $return['RATIO']['LANDINGS_BEFORE'][] = $lid;
266
267 $tmpLinking = TemplateRef::getForLanding($lid);
268 if (!empty($tmpLinking))
269 {
270 $return['RATIO']['TEMPLATE_LINKING_BEFORE'][$lid] = [
271 'TPL_ID' => (int)$landing['TPL_ID'],
272 'TEMPLATE_REF' => $tmpLinking,
273 ];
274 }
275 }
276 }
277 }
278 if (!isset($return['RATIO']['SPECIAL_PAGES']))
279 {
280 $return['RATIO']['SPECIAL_PAGES'] = [
281 'LANDING_ID_INDEX' => isset($data['LANDING_ID_INDEX']) ? (int)$data['LANDING_ID_INDEX'] : 0,
282 'LANDING_ID_404' => isset($data['LANDING_ID_404']) ? (int)$data['LANDING_ID_404'] : 0,
283 'LANDING_ID_503' => isset($data['LANDING_ID_503']) ? (int)$data['LANDING_ID_503'] : 0,
284 ];
285 }
286 $return['RATIO']['IS_PAGE_IMPORT'] = $isPageImport;
287 $return['RATIO']['TYPE'] = $data['TYPE'];
288
289 if (isset($data['TEMPLATES']) && is_array($data['TEMPLATES']))
290 {
291 $return['RATIO']['TEMPLATES'] = $data['TEMPLATES'];
292 }
293
294 // site import
295 if (!$isPageImport && !$isPageStep && !$isReplace)
296 {
297 $res = self::importSite($data, $structure);
298 if ($res->isSuccess())
299 {
300 $return['RATIO']['BLOCKS'] = [];
301 $return['RATIO']['BLOCKS_PENDING'] = [];
302 $return['RATIO']['LANDINGS'] = [];
303 $return['RATIO']['TEMPLATES'] = $return['RATIO']['TEMPLATES'] ?? [];
304 $return['RATIO']['TEMPLATE_LINKING'] = [];
305 $return['RATIO']['SITE_ID'] = $res->getId();
306 $return['RATIO']['FOLDERS_NEW'] = $data['FOLDERS_NEW'] ?? [];
307 $return['RATIO']['SYS_PAGES'] = $data['SYS_PAGES'];
308
309 if (isset($data['TPL_ID']) && $data['TPL_ID'])
310 {
311 $return['RATIO']['TEMPLATE_LINKING'][-1 * $res->getId()] = [
312 'TPL_ID' => (int)$data['TPL_ID'],
313 'TEMPLATE_REF' => (array)($data['TEMPLATE_REF'] ?? []),
314 ];
315 }
316
317 return $return;
318 }
319
320 $return['ERROR_EXCEPTION'] = $res->getErrorMessages();
321
322 return $return;
323 }
324
325 // First step (site import) for replaces
326 if ($isReplace && !$isPageStep && $siteId)
327 {
328 // check by scope that replaced site have same type with import.
329 $checkByType = SiteCore::getList([
330 'select' => ['ID'],
331 'filter' => [
332 '=ID' => $siteId,
333 ],
334 ]);
335 if (!$checkByType->fetch())
336 {
337 $return['ERROR_EXCEPTION'] = Loc::getMessage('LANDING_IMPORT_ERROR_REPLACED_SITE_TYPE_INVALID');
338
339 return $return;
340 }
341
342 $return['RATIO']['TEMPLATE_LINKING'][-1 * $siteId] = [
343 'TPL_ID' => (int)$data['TPL_ID'],
344 'TEMPLATE_REF' => (array)($data['TEMPLATE_REF'] ?? []),
345 ];
346 }
347
348 // something went wrong, site was not created
349 if (!isset($siteId))
350 {
351 $return['ERROR_EXCEPTION'][] = Loc::getMessage('LANDING_IMPORT_ERROR_SITE_ID_NOT_FOUND');
352 return $return;
353 }
354
355 // skip import site step if import page in existing site
356 if (!isset($data['SITE_ID']))
357 {
358 return $return;
359 }
360
361 // not site imports
362 if ($isReplaceLanding)
363 {
365 }
366
368 }
369
375 protected static function prepareData(array $data): array
376 {
377 if (!isset($data['TYPE']))
378 {
379 $data['TYPE'] = 'PAGE';
380 }
381
382 $data['LANG'] = Manager::getZone();
383
384 return $data;
385 }
386
393 protected static function prepareAdditionalFields(array $data, ?array $additional): array
394 {
395 if ($additional)
396 {
397 if (isset($additional['theme']) && $additional['theme'])
398 {
399 $color = $additional['theme'];
400 if ($color[0] !== '#')
401 {
402 $color = '#' . $color;
403 }
404 $data['ADDITIONAL_FIELDS']['THEME_COLOR'] = $color;
405 unset($data['ADDITIONAL_FIELDS']['THEME_CODE']);
406 $data['ADDITIONAL_FIELDS']['THEME_USE'] = 'Y';
407 }
408
409 if (isset($additional['title']) && $additional['title'])
410 {
411 $data['TITLE'] = $additional['title'];
412 }
413 }
414
415 //default widget value
416 $buttons = B24button::getButtons();
417 $buttonKeys = array_keys($buttons);
418 if (!empty($buttonKeys))
419 {
420 $data['ADDITIONAL_FIELDS']['B24BUTTON_CODE'] = $buttonKeys[0];
421 }
422 else
423 {
424 $data['ADDITIONAL_FIELDS']['B24BUTTON_CODE'] = 'N';
425 }
426 //default site boost
427 $data['ADDITIONAL_FIELDS']['SPEED_USE_WEBPACK'] = 'Y';
428 $data['ADDITIONAL_FIELDS']['SPEED_USE_LAZY'] = 'Y';
429 //default powered by b24
430 $data['ADDITIONAL_FIELDS']['COPYRIGHT_SHOW'] = 'Y';
431 $data['ADDITIONAL_FIELDS']['COPYRIGHT_CODE'] = Copyright::getRandomPhraseId();
432 //default cookie
433 if (in_array(Manager::getZone(), ['es', 'de', 'fr', 'it', 'pl', 'uk']))
434 {
435 $data['ADDITIONAL_FIELDS']['COOKIES_USE'] = 'Y';
436 }
437
438 return $data;
439 }
440
447 protected static function linkingPendingBlocks(array $pendingIds, array $replace): void
448 {
449 $replaceEncoded = base64_encode(serialize($replace));
450 $res = BlockTable::getList([
451 'select' => [
452 'ID',
453 ],
454 'filter' => [
455 'ID' => $pendingIds,
456 ],
457 ]);
458 while ($row = $res->fetch())
459 {
460 $blockInstance = new Block($row['ID']);
461 if ($blockInstance->exist())
462 {
463 $blockInstance->updateNodes([
465 'REPLACE' => $replaceEncoded,
466 ],
467 ]);
468 $blockInstance->save();
469 }
470 }
471 }
472
479 protected static function updateFolderIds(int $siteId, array $folderMapIds): void
480 {
482 'select' => [
483 'ID', 'FOLDER_ID',
484 ],
485 'filter' => [
486 'SITE_ID' => $siteId,
487 'FOLDER_ID' => array_keys($folderMapIds),
488 ],
489 ]);
490 while ($row = $res->fetch())
491 {
492 if (isset($folderMapIds[$row['FOLDER_ID']]))
493 {
494 LandingCore::update($row['ID'], [
495 'FOLDER_ID' => $folderMapIds[$row['FOLDER_ID']],
496 ]);
497 }
498 }
499 }
500
508 protected static function addFolders(int $siteId, array $foldersNew, array $landingMapIds): void
509 {
510 if (!$foldersNew)
511 {
512 return;
513 }
514
515 $folderMapIds = [];
516 foreach ($foldersNew as $folderId => $folder)
517 {
518 $indexId = null;
519
520 if (!$folder['PARENT_ID'])
521 {
522 unset($folder['PARENT_ID']);
523 }
524
525 if ($folder['INDEX_ID'] ?? null)
526 {
527 $indexId = $landingMapIds[$folder['INDEX_ID']] ?? null;
528 unset($folder['INDEX_ID']);
529 }
530
531 $res = SiteCore::addFolder($siteId, $folder);
532 if ($res->isSuccess())
533 {
534 if ($indexId)
535 {
536 $resLanding = LandingCore::update($indexId, [
537 'FOLDER_ID' => $res->getId(),
538 ]);
539 if ($resLanding->isSuccess())
540 {
541 \Bitrix\Landing\Folder::update($res->getId(), [
542 'INDEX_ID' => $indexId,
543 ]);
544 }
545 }
546 $folderMapIds[$folderId] = $res->getId();
547 }
548 }
549
550 $newFolders = SiteCore::getFolders($siteId);
551 foreach ($newFolders as $folder)
552 {
553 if ($folderMapIds[$folder['PARENT_ID']] ?? null)
554 {
555 \Bitrix\Landing\Folder::update($folder['ID'], [
556 'PARENT_ID' => $folderMapIds[$folder['PARENT_ID']],
557 ]);
558 }
559 }
560
561 self::updateFolderIds($siteId, $folderMapIds);
562 }
563
569 public static function onFinish(Event $event): array
570 {
571 $ratio = $event->getParameter('RATIO');
572 $userId = $event->getParameter('USER_ID');
573
574 if ($userId)
575 {
577 }
578
579 if (isset($ratio['LANDING']))
580 {
582 $siteType = $ratio['LANDING']['TYPE'];
583 $siteId = $ratio['LANDING']['SITE_ID'] ?? null;
584 $blocks = $ratio['LANDING']['BLOCKS'] ?? null;
585 $landings = $ratio['LANDING']['LANDINGS'] ?? [];
586 $blocksPending = $ratio['LANDING']['BLOCKS_PENDING'] ?? null;
587 $foldersRef = $ratio['LANDING']['FOLDERS_REF'] ?? null;
588 $templatesOld = $ratio['LANDING']['TEMPLATES'] ?? [];
589 $templateLinking = $ratio['LANDING']['TEMPLATE_LINKING'] ?? [];
590 $specialPages = $ratio['LANDING']['SPECIAL_PAGES'] ?? null;
591 $sysPages = $ratio['LANDING']['SYS_PAGES'] ?? null;
592 $foldersNew = $ratio['LANDING']['FOLDERS_NEW'] ?? [];
593 $additional = $event->getParameter('ADDITIONAL_OPTION') ?? [];
594
595 Type::setScope($siteType);
596
597 // if import just page in existing site
598 $isPageImport = $ratio['LANDING']['IS_PAGE_IMPORT'] ?? false;
599 $isReplaceLanding = isset($ratio['LANDING']['REPLACE_LID']) && (int)$ratio['LANDING']['REPLACE_LID'] > 0;
600 $isReplaceSiteLandings = (int)($ratio['LANDING']['REPLACE_SITE_ID'] ?? 0) > 0;
601 $isReplace = $isReplaceLanding || $isReplaceSiteLandings;
602 if ($isReplaceSiteLandings && $siteId)
603 {
604 self::onFinishReplaceSite($event);
605 }
606
607 // index page for multipage, or just once - for sigle page import
608 $mainPageId = null;
609 if (!empty($landings))
610 {
611 $mainPageId = reset($landings);
612 if (
613 $siteId
614 && $specialPages
615 && $specialPages['LANDING_ID_INDEX']
616 && $landings[$specialPages['LANDING_ID_INDEX']]
617 )
618 {
619 $mainPageId = $landings[$specialPages['LANDING_ID_INDEX']];
620 }
621 }
622
623 if ($blocksPending)
624 {
625 self::linkingPendingBlocks($blocksPending, [
626 'block' => $blocks,
627 'landing' => $landings,
628 ]);
629 }
630
631 // replace links in blocks content
632 if ($blocks)
633 {
634 $replace = [];
635 ksort($blocks);
636 ksort($landings);
637 $blocks = array_reverse($blocks, true);
638 $landings = array_reverse($landings, true);
639 foreach ($blocks as $oldId => $newId)
640 {
641 $replace['/#block' . $oldId . '([^\d]{1})/'] = '#block' . $newId . '$1';
642 }
643 foreach ($landings as $oldId => $newId)
644 {
645 $replace['/#landing' . $oldId . '([^\d]{1})/'] = '#landing' . $newId . '$1';
646 }
647
648 $res = BlockTable::getList([
649 'select' => [
650 'ID', 'CONTENT',
651 ],
652 'filter' => [
653 'ID' => array_values($blocks),
654 '!ID' => $blocksPending,
655 ],
656 ]);
657 while ($row = $res->fetch())
658 {
659 $count = 0;
660 $row['CONTENT'] = preg_replace(
661 array_keys($replace),
662 array_values($replace),
663 $row['CONTENT'],
664 -1,
665 $count
666 );
667 if ($count)
668 {
669 BlockTable::update($row['ID'], [
670 'CONTENT' => $row['CONTENT'],
671 ]);
672 }
673 }
674 }
675
676 if (!$isReplace)
677 {
678 // move pages to the folders if needed (backward compatibility)
679 if ($foldersRef)
680 {
682 'select' => [
683 'ID', 'FOLDER_ID',
684 ],
685 'filter' => [
686 'SITE_ID' => $siteId,
687 'FOLDER_ID' => array_keys($foldersRef),
688 ],
689 ]);
690 while ($row = $res->fetch())
691 {
692 LandingCore::update($row['ID'], [
693 'FOLDER_ID' => $foldersRef[$row['FOLDER_ID']],
694 ]);
695 }
696 }
697
698 // add folders and move pages (new format)
699 self::addFolders($siteId, $foldersNew, $landings);
700 }
701
702 if (!$isPageImport || $isReplaceSiteLandings)
703 {
704 // gets actual layouts
705 $templatesNew = [];
706 $templatesRefs = [];
708 'select' => [
709 'ID', 'XML_ID',
710 ],
711 ]);
712 while ($row = $res->fetch())
713 {
714 $templatesNew[$row['XML_ID']] = $row['ID'];
715 }
716 foreach ($templatesOld as $oldId => $oldXmlId)
717 {
718 if (is_string($oldXmlId) && isset($templatesNew[$oldXmlId]))
719 {
720 $templatesRefs[$oldId] = $templatesNew[$oldXmlId];
721 }
722 }
723
724 // set layouts to site and landings
725 foreach ($templateLinking as $entityId => $templateItem)
726 {
727 $tplId = $templateItem['TPL_ID'];
728 $tplRefs = [];
729 if (isset($templatesRefs[$tplId]))
730 {
731 $tplId = $templatesRefs[$tplId];
732 foreach ($templateItem['TEMPLATE_REF'] as $areaId => $landingId)
733 {
734 if (intval($landingId) && isset($landings[$landingId]))
735 {
736 $tplRefs[$areaId] = $landings[$landingId];
737 }
738 }
739 if ($entityId < 0)
740 {
741 SiteCore::update(-1 * $entityId, [
742 'TPL_ID' => $tplId,
743 ]);
744 TemplateRef::setForSite(-1 * $entityId, $tplRefs);
745 }
746 else
747 {
749 'TPL_ID' => $tplId,
750 ]);
752 }
753 }
754 }
755
756 // replace special pages in site (503, 404)
757 if ($specialPages && $siteId)
758 {
759 foreach ($specialPages as $code => $id)
760 {
761 $specialPages[$code] = isset($landings[$id]) ? $landings[$id] : 0;
762 }
763 SiteCore::update($siteId, $specialPages);
764 }
765
766 // system pages
767 if (is_array($sysPages) && $siteId)
768 {
769 foreach ($sysPages as $sysPage)
770 {
771 if (isset($landings[$sysPage['LANDING_ID']]))
772 {
773 Syspage::set($siteId, $sysPage['TYPE'], $landings[$sysPage['LANDING_ID']]);
774 }
775 }
776 }
777 }
778
779 //set default additional fields for page
780 if ($mainPageId && !$isReplaceLanding)
781 {
782 self::setAdditionalPageFields($mainPageId, $additional);
783 }
784
786
787 // LINK for "go to site" button
788 $linkAttrs = [
789 'class' => 'ui-btn ui-btn-md ui-btn-success ui-btn-round',
790 'data-is-site' => 'Y',
791 'data-site-id' => $siteId,
792 'href' => '#' . $siteId,
793 'target' => '_top',
794 ];
795 if ($mainPageId)
796 {
797 $linkAttrs['data-is-landing'] = 'Y';
798 $linkAttrs['data-landing-id'] = $mainPageId;
799 }
800 $linkText = Loc::getMessage('LANDING_IMPORT_FINISH_GOTO_SITE');
801 if ($siteType === 'KNOWLEDGE')
802 {
803 $linkAttrs['href'] = \Bitrix\Landing\Site::getPublicUrl($siteId);
804 }
805 elseif ($siteType === 'PAGE' && empty($additional))
806 {
807 $linkText = Loc::getMessage('LANDING_IMPORT_FINISH_GOTO_PAGE');
808 $url = Manager::getOption('tmp_last_show_url', '');
809 if ($url === '' && ModuleManager::isModuleInstalled('bitrix24'))
810 {
811 $linkAttrs['href'] = '/sites/';
812 }
813 elseif ($url !== '')
814 {
815 $linkAttrs['href'] = str_replace(
816 [
817 '#site_show#',
818 '#landing_edit#',
819 ],
820 [
821 $siteId,
822 $siteId,
823 ],
824 $url
825 );
826 }
827 }
828 elseif ($siteType === 'MAINPAGE')
829 {
830 $linkText = Loc::getMessage('LANDING_IMPORT_FINISH_GOTO_MAINPAGE');
831 if (Loader::includeModule('intranet'))
832 {
833 $manager = new \Bitrix\Landing\Mainpage\Manager();
834 $manager->onFinishPageCreation();
835
836 $linkAttrs['href'] = Scope\Mainpage::getPublicationPath() ?? '/';
837 }
838 }
839
840 if ($isReplaceLanding)
841 {
842 $linkAttrs['data-replace-lid'] = (int)$ratio['LANDING']['REPLACE_LID'];
843 }
844
845 $domList = [
846 [
847 'TAG' => 'a',
848 'DATA' => [
849 'attrs' => $linkAttrs,
850 'text' => $linkText,
851 ],
852 ],
853 ];
854
855 if (mb_strpos($linkAttrs['href'], '#') !== 0)
856 {
857 $script = "setTimeout(() => {
858 top.window.location.href='{$linkAttrs['href']}';
859 }, 5000);";
860 $domList[] = [
861 'TAG' => 'script',
862 'DATA' => [
863 'html' => $script,
864 ],
865 ];
866 }
867
868 if (
869 !empty($additional)
870 && array_key_exists('st_category', $additional)
871 && array_key_exists('st_event', $additional)
872 && Metrika\Categories::tryFrom($additional['st_category'])
873 && Metrika\Events::tryFrom($additional['st_event'])
874 )
875 {
876 $metrika = new Metrika\Metrika(
877 Metrika\Categories::tryFrom($additional['st_category']),
878 Metrika\Events::tryFrom($additional['st_event']),
879 );
880 $metrika->setStatus(Metrika\Statuses::Success);
881 $metrika->setType(Metrika\Types::template);
882
883 if (array_key_exists('st_section', $additional))
884 {
885 $metrika->setSection(Metrika\Sections::tryFrom($additional['st_section']));
886 }
887 $metrika
888 ->setParam(1, 'appCode', $additional['appCode'] ?? '')
889 ->setParam(3, 'siteId', $siteId)
890 ->send()
891 ;
892 }
893
894 return [
895 'CREATE_DOM_LIST' => $domList,
896 'ADDITIONAL' => [
897 'id' => $siteId,
898 'publicUrl' => \Bitrix\Landing\Site::getPublicUrl($siteId),
899 'imageUrl' => Manager::getUrlFromFile(\Bitrix\Landing\Site::getPreview($siteId)),
900 ],
901 ];
902 }
903
905
906 return [];
907 }
908
909 protected static function setAdditionalPageFields($landingId, array $additional): void
910 {
911 $additionalFields = [];
912
913 // set Title and Description to mainpage
914 if (!empty($additional))
915 {
916 if (isset($additional['title']))
917 {
918 $additionalFields['METAMAIN_TITLE'] = $additional['title'];
919 $additionalFields['METAOG_TITLE'] = $additional['title'];
920
921 LandingCore::update($landingId, [
922 'TITLE' => $additional['title'],
923 ]);
924 }
925 if (isset($additional['description']))
926 {
927 $additionalFields['METAMAIN_DESCRIPTION'] = $additional['description'];
928 $additionalFields['METAOG_DESCRIPTION'] = $additional['description'];
929 }
930 }
931
932 LandingCore::saveAdditionalFields($landingId, $additionalFields);
933 }
934
940 protected static function onFinishReplaceSite(Event $event): void
941 {
942 $ratio = $event->getParameter('RATIO');
943 $siteId = $ratio['LANDING']['SITE_ID'] ?? null;
944
945 if (!$siteId)
946 {
947 return;
948 }
949
950 History::deactivate();
951
952 $landingsBefore = $ratio['LANDING']['LANDINGS_BEFORE'] ?? [];
953 $landings = $ratio['LANDING']['LANDINGS'] ?? [];
954 foreach ($landingsBefore as $lidToDelete)
955 {
956 TemplateRef::deleteArea($lidToDelete);
957 LandingCore::markDelete($lidToDelete);
958 }
959
960 $specialPages = $ratio['LANDING']['SPECIAL_PAGES'] ?? null;
961 if (
962 $specialPages
963 && $specialPages['LANDING_ID_INDEX']
964 && $landings[$specialPages['LANDING_ID_INDEX']]
965 )
966 {
967 $index = $landings[$specialPages['LANDING_ID_INDEX']];
968 }
969 SiteCore::update($siteId, [
970 'LANDING_ID_INDEX' => $index ?? 0
971 ]);
972
973 $additionalFieldsSiteBefore = $ratio['LANDING']['ADDITIONAL_FIELDS_SITE_BEFORE'] ?? [];
974 $additionalFieldsSite = $ratio['LANDING']['ADDITIONAL_FIELDS_SITE'] ?? [];
975 if (!empty($additionalFieldsSite))
976 {
977 SiteCore::saveAdditionalFields($siteId, $additionalFieldsSite);
978 }
979
980 // todo: for future, not using yet
981 $useHistory = false;
982 if ($useHistory)
983 {
984 $templateLinkingBefore = $ratio['LANDING']['TEMPLATE_LINKING_BEFORE'] ?? [];
985 $templateLinking = $ratio['LANDING']['TEMPLATE_LINKING'] ?? [];
986
987 History::activate();
988 $history = new History($siteId, History::ENTITY_TYPE_LANDING);
989 $history->push('REPLACE_SITE_LANDINGS', [
990 'siteId' => $siteId,
991
992 'landingsBefore' => $landingsBefore,
993 'landings' => $landings,
994
995 'templateLinkingBefore' => $templateLinkingBefore,
996 'templateLinking' => $templateLinking,
997
998 'additionalFieldsSiteBefore' => $additionalFieldsSiteBefore,
999 'additionalFieldsSite' => $additionalFieldsSite,
1000 ]);
1001 }
1002 }
1003}
$count
Определения admin_tab.php:4
$type
Определения options.php:106
if(!is_object($USER)||! $USER->IsAuthorized()) $userId
Определения check_mail.php:18
static addToSite(int $id, int $fileId, bool $temp=false)
Определения file.php:228
static getButtons()
Определения b24button.php:40
static saveAdditionalFields(Entity\Event $event)
Определения site.php:1329
static getOption($code, $default=null)
Определения manager.php:160
static getZone()
Определения manager.php:930
static getUrlFromFile($file)
Определения manager.php:1082
static getList(array $params=array())
Определения template.php:20
static setContextUserId(int $uid)
Определения rights.php:168
static setGlobalOn()
Определения rights.php:116
static setGlobalOff()
Определения rights.php:107
static getPublicationPath()
Определения mainpage.php:49
static set($id, $type, $lid=false)
Определения syspage.php:30
static getForLanding($id)
Определения templateref.php:153
static deleteArea($lid)
Определения templateref.php:213
static setForLanding($id, array $data=array())
Определения templateref.php:130
static setForSite($id, array $data=array())
Определения templateref.php:116
static saveFile(array $file)
Определения appconfiguration.php:311
static getAdditionalFieldsForReplaceBySite(int $siteId)
Определения landing.php:1002
static replaceLanding(Event $event)
Определения landing.php:613
static importLanding(Event $event)
Определения landing.php:424
static importSite(array $data, Configuration\Structure $structure)
Определения site.php:87
static updateFolderIds(int $siteId, array $folderMapIds)
Определения site.php:479
static setAdditionalPageFields($landingId, array $additional)
Определения site.php:909
static linkingPendingBlocks(array $pendingIds, array $replace)
Определения site.php:447
static prepareAdditionalFields(array $data, ?array $additional)
Определения site.php:393
static nextStep(Event $event)
Определения site.php:169
static getInitManifest(Event $event)
Определения site.php:59
static getUrl(string $type)
Определения site.php:43
static onFinish(Event $event)
Определения site.php:569
static onFinishReplaceSite(Event $event)
Определения site.php:940
static addFolders(int $siteId, array $foldersNew, array $landingMapIds)
Определения site.php:508
static prepareData(array $data)
Определения site.php:375
setScope($scope)
Определения controller.php:373
Определения event.php:5
static update($primary, array $data)
Определения file.php:228
static getList(array $parameters=array())
Определения datamanager.php:431
static getConfigurationImportManifestUrl($code)
Определения url.php:532
$content
Определения commerceml.php:144
$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
if(!is_null($config))($config as $configItem)(! $configItem->isVisible()) $code
Определения options.php:195
$siteId
Определения ajax.php:8
randString($pass_len=10, $pass_chars=false)
Определения tools.php:2154
Определения cookies.php:2
Определения agent.php:3
$files
Определения mysql_to_pgsql.php:30
$manager
Определения office365push.php:39
$entityId
Определения payment.php:4
$settings
Определения product_settings.php:43
$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
$url
Определения iframe.php:7