Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
helper.php
1<?php
2
4
12
13class Helper
14{
15 const TYPE_SECTION_TOTAL = 'total';
16 const STRUCTURE_FILES_NAME = 'files';
17 const STRUCTURE_SMALL_FILES_NAME = 'small_files';
19 const DEFAULT_ARCHIVE_NAME = 'configuration';
21
22 public const MODE_IMPORT = 'IMPORT';
23 public const MODE_ROLLBACK = 'ROLLBACK';
24 public const MODE_EXPORT = 'EXPORT';
25
26 protected $prefixStatisticBasic = 'DEFAULT_';
27 protected $prefixAppContext = 'app';
28 protected $prefixUserContext = 'configuration';
29 protected $optionEnableZipMod = 'enable_mod_zip';
30 protected $optionMaxImportFileSize = 'import_max_size';
31 protected $optionBasicAppList = 'uses_basic_app_list';
32 protected $defaultMaxSizeImport = 250;
33 protected $appConfigurationFolderBackup = 'appConfiguration';
34 protected $basicManifest = [
35 'vertical_crm'
36 ];
37
39 private static $instance = null;
40 private $sanitizer = null;
41 private function __construct()
42 {
43
44 }
45
49 public static function getInstance(): Helper
50 {
51 if (self::$instance === null)
52 {
53 self::$instance = new Helper();
54 }
55
56 return self::$instance;
57 }
58
63 public function enabledZipMod()
64 {
66 {
67 return true;
68 }
69 else
70 {
71 return Option::get('rest', $this->optionEnableZipMod, 'N') == 'Y';
72 }
73 }
74
78 public function getMaxFileSize()
79 {
80 if (!ModuleManager::isModuleInstalled('bitrix24'))
81 {
82 $size = Option::get('rest', $this->optionMaxImportFileSize, '');
83 }
84
85 if (empty($size))
86 {
88 }
89
90 return $size;
91 }
92
98 public function getContextUser($postfix)
99 {
100 $result = $this->prefixUserContext;
101
102 $postfix = preg_replace('/[^a-zA-Z0-9_]/', '', $postfix);
103
104 global $USER;
105 if ($USER->IsAuthorized())
106 {
107 $user = $USER->GetID();
108 }
109 else
110 {
111 $user = 0;
112 }
113
114 $result .= $user.$postfix;
115 return $result;
116 }
117
123 public function getContextAction($appId = 0)
124 {
125 $result = 'external';
126 $appId = intval($appId);
127 if ($appId > 0)
128 {
129 $result = $this->prefixAppContext.$appId;
130 }
131
132 return $result;
133 }
134
142 public function sanitize($value, &$bad = false, $splitter = ' ')
143 {
144 if (!is_bool($bad))
145 {
146 $bad = false;
147 }
148
149 if ($this->sanitizer === null)
150 {
151 $this->sanitizer = false;
152 if (Loader::includeModule('security'))
153 {
154 $this->sanitizer = new Auditor\Xss(
155 $splitter
156 );
157 }
158 }
159
160 if ($this->sanitizer)
161 {
162 // bad value exists
163 if (is_array($value))
164 {
165 foreach ($value as &$val)
166 {
167 $val = $this->sanitize($val, $bad, $splitter);
168 }
169 unset($val);
170 }
171 elseif ($this->sanitizer->process($value))
172 {
173 $bad = true;
174 $value = $this->sanitizer->getFilteredValue();
175 }
176 }
177
178 return $value;
179 }
180
181 public function getStorageBackupParam()
182 {
183 return [
185 'MODULE_ID' => 'rest',
186 'ENTITY_TYPE' => ProxyDiskType::className(),
187 'ENTITY_ID' => 1,
188 ];
189 }
190
191 public function getStorageBackup()
192 {
193 $storage = false;
194 if (Loader::includeModule('disk'))
195 {
196 $storage = \Bitrix\Disk\Driver::getInstance()->addStorageIfNotExist(
197 $this->getStorageBackupParam()
198 );
199 }
200 return $storage;
201 }
202
203 //uses configuration app
209 public function isBasicManifest($code)
210 {
211 return (in_array($code, $this->basicManifest)) ? true : false;
212 }
213
219 public function getBasicApp($manifestCode)
220 {
221 $result = false;
222 $appList = $this->getBasicAppList();
223 if (isset($appList[$manifestCode]))
224 {
225 $result = $appList[$manifestCode];
226 }
227
228 return $result;
229 }
230
234 public function getBasicAppList()
235 {
236 $data = Option::get('rest', $this->optionBasicAppList);
237 if ($data)
238 {
239 $data = Json::decode($data);
240 }
241 else
242 {
243 $data = [];
244 }
245
246 return $data;
247 }
248
254 public function setBasicApp($manifestCode, $appCode)
255 {
256 $result = false;
257 if ($this->isBasicManifest($manifestCode))
258 {
259 $appList = $this->getBasicAppList();
260 $appList[$manifestCode] = $appCode;
261 Option::set('rest', $this->optionBasicAppList, Json::encode($appList));
262 $result = true;
263 }
264
265 return $result;
266 }
267
272 public function deleteBasicApp($manifestCode)
273 {
274 $result = false;
275 if ($this->isBasicManifest($manifestCode))
276 {
277 $appList = $this->getBasicAppList();
278 if (isset($appList[$manifestCode]))
279 {
280 unset($appList[$manifestCode]);
281 Option::set('rest', $this->optionBasicAppList, Json::encode($appList));
282 }
283 $result = true;
284 }
285
286 return $result;
287 }
288
292 public function sendStatistic()
293 {
294 $appList = $this->getBasicAppList();
295 foreach ($appList as $manifest => $appCode)
296 {
297 UsageStatTable::logConfiguration($appCode, $this->prefixStatisticBasic . mb_strtoupper($manifest));
298 }
300
301 return true;
302 }
303
308 public static function sendStatisticAgent()
309 {
310 self::getInstance()->sendStatistic();
311
312 return '\Bitrix\Rest\Configuration\Helper::sendStatisticAgent();';
313 }
314
324 public static function checkAccessManifest($params, $uses = []): bool
325 {
326 return Manifest::isEntityAvailable('', $params, $uses);
327 }
328}
static isModuleInstalled($moduleName)
setBasicApp($manifestCode, $appCode)
Definition helper.php:254
static checkAccessManifest($params, $uses=[])
Definition helper.php:324
sanitize($value, &$bad=false, $splitter=' ')
Definition helper.php:142
static isEntityAvailable(string $entityCode, array $option, $uses=[])
Definition manifest.php:156
static logConfiguration($clientId, $clientCode)