Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
customextensions.php
1<?php
2
4
6use \Bitrix\Landing\Block;
7use \Bitrix\Landing\Internals\BlockTable;
9
11{
12 protected const EXT_POPUP = 'landing_popup_link';
13 protected const EXT_JQUERY = 'landing_jquery';
14 protected const CRITICAL_EXTENSIONS = ['landing_jquery'];
15 protected const HTML_BLOCK_CODE = 'html';
16
21 protected static function saveExtensions(Block $block): void
22 {
23 $newExtensions = [];
24 $content = $block->getContent();
25 if (!$content)
26 {
27 return;
28 }
29
30 // <a href=> and data-url=""
31 if (preg_match('/target=["\']_popup["\']/i', $content))
32 {
33 $newExtensions[] = self::EXT_POPUP;
34 }
35 // pseudo-urls
36 if(preg_match_all('/data-pseudo-url=["\'][^"\']*_popup[^"\']*["\']/i', $content, $pseudoUrls))
37 {
38 foreach ($pseudoUrls[0] as $pseudoUrl)
39 {
40 $params = htmlspecialcharsback($pseudoUrl);
41 $params = str_replace('data-pseudo-url=', '', $params);
42 $params = substr($params,0,-1);
43 $params = substr($params,1);
44 // preserve JSON syntax error if params in wrong format
45 try
46 {
47 $params = Json::decode($params);
48 if($params['enabled'])
49 {
50 $newExtensions[] = self::EXT_POPUP;
51 break;
52 }
53 }
54 catch (\Exception $e){}
55 }
56 }
57
58 // for partners using jQuery always
59 // todo: add flag 'no_jq' for different jq?
60 if ($block->getRepoId())
61 {
62 $newExtensions[] = self::EXT_JQUERY;
63 }
64
65 if ($block->getCode() === self::HTML_BLOCK_CODE)
66 {
67 $newExtensions[] = self::EXT_JQUERY;
68 }
69
70 if (!empty($newExtensions))
71 {
72 $extensions = ($block->getAsset()['ext'] ?? []) ?: [];
73 $extensions = array_merge($newExtensions, $extensions);
74 $block->saveAssets([
75 'ext' => array_unique($extensions)
76 ]);
77 $block->save();
78 }
79 }
80
85 public static function processing(Block $block): void
86 {
88 }
89
95 // todo: add version landing updater
96 public static function processingLanding(int $landingId): void
97 {
98 $res = BlockTable::getList([
99 'select' => [
100 'ID'
101 ],
102 'filter' => [
103 'LID' => $landingId,
104 '=DELETED' => 'N'
105 ]
106 ]);
107 while ($row = $res->fetch())
108 {
109 $block = new Block($row['ID']);
110 self::processing($block);
111 $block->save();
112 }
113 }
114
120 public static function view(Block $block): void
121 {
122 $blockAssets = $block->getAssets();
123 if (isset($blockAssets['ext']))
124 {
125 $assets = Assets\Manager::getInstance();
126 foreach ($blockAssets['ext'] as $ext)
127 {
128 $location = Assets\Location::getDefaultLocation();
129 if (in_array($ext, self::CRITICAL_EXTENSIONS, true))
130 {
131 $location = Assets\Location::LOCATION_BEFORE_ALL;
132 }
133 $assets->addAsset($ext, $location);
134 }
135 }
136 }
137}
save(array $additionalFields=[])
Definition block.php:3136
saveAssets(array $assets)
Definition block.php:3067
getAsset($type=null)
Definition block.php:2446