Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
url.php
1<?php
3{
4
9 class Templates
10 {
11 protected $directory = "marketplace/";
12 protected $directoryAdmin = '/bitrix/admin/';
13 protected $pages = [
14 "index" => "",
15 "list" => "list/",
16 "detail" => "detail/#ID#/",
17 "edit" => "edit/#ID#/",
18 ];
19 protected $pageListAdmin = [];
20 protected $adminSectionMode = false;
21 private static $localDir = null;
22 private static array $instance = [];
23
24 private function __construct()
25 {
26 if (defined('ADMIN_SECTION'))
27 {
28 $this->adminSectionMode = true;
29 }
30 }
32 protected function getPage(string $code): string
33 {
34 return $this->adminSectionMode && !empty($this->pageListAdmin[$code])
35 ? $this->directoryAdmin . $this->pageListAdmin[$code]
36 : $this->getDir() . $this->pages[$code]
37 ;
38 }
40 final public static function getInstance()
41 {
42 if (!array_key_exists(static::class, static::$instance))
43 {
44 static::$instance[static::class] = new static();
45 }
46
47 return static::$instance[static::class];
48 }
49
56 public function addUrlFrom($url, $from) : string
57 {
58 if($from !== '')
59 {
60 if (mb_strpos($url, '?') === false)
61 {
62 $url .= '?from=' . $from;
63 }
64 else
65 {
66 $url .= '&from=' . $from;
67 }
68 }
69
70 return $url;
71 }
73 public function getIndexUrl($from = '')
74 {
75 $url = $this->getDir() . $this->pages["index"];
76 $url = $this->addUrlFrom($url, $from);
77
78 return $url;
79 }
81 public function getDetailUrl($id = null, $from = '')
82 {
83 $url = $this->getReplacedId($this->pages["detail"], $id);
84 $url = $this->addUrlFrom($url, $from);
85
86 return $url;
87 }
89 public function getEditUrl($id = null)
90 {
91 return $this->getReplacedId($this->pages["edit"], $id);
92 }
94 public function getDir()
95 {
96 if (null === self::$localDir)
97 {
99 $site = \Bitrix\Main\Context::getCurrent()->getSiteObject();
100 if ($site && $site->getDir() != '')
101 {
102 $siteId = $site->getLid();
103 $path = [\Bitrix\Main\SiteTable::getDocumentRoot($siteId), $site->getDir(), $this->directory];
104 $dir = new \Bitrix\Main\IO\Directory(\Bitrix\Main\IO\Path::combine($path), $siteId);
105 if ($dir->isExists())
106 {
107 self::$localDir = \Bitrix\Main\IO\Path::combine([self::$localDir, $site->getDir()]);
108 }
109 }
110 }
111 $res = \Bitrix\Main\IO\Path::combine([self::$localDir, $this->directory]);
112 if (mb_substr($res, 0, -1) !== \Bitrix\Main\IO\Path::DIRECTORY_SEPARATOR)
114 return $res;
115 }
117 protected function getReplacedId(string $url, $id = null)
118 {
119 $url = $this->getDir().$url;
120 if (!is_null($id))
121 $url = str_replace("#ID#", $id, $url);
122 return $url;
123 }
125 protected function getReplaced(string $url, $replace = null, $subject = null)
126 {
127 $url = $this->getDir().$url;
128 if (!is_null($replace) && !is_null($subject))
129 $url = str_replace($replace, $subject, $url);
130 return $url;
131 }
132 }
134 class Marketplace extends Templates
136 protected $directory = "marketplace/";
137 protected $pages = [
138 "index" => "",
139 "list" => "installed/",
140 "detail" => "detail/#ID#/",
141 "category" => "category/#ID#/",
142 "category_placement" => "?placement=#CODE#",
143 "placement_view" => "view/#APP#/",
144 "placement" => "placement/#PLACEMENT_ID#/",
145 "booklet" => "booklet/#CODE#/"
146 ];
148 public function getCategoryUrl($id = null, $from = '')
149 {
150 if ($id === null)
151 {
152 $url = $this->getReplacedId($this->pages['index']);
153 }
154 else
155 {
156 $url = $this->getReplacedId($this->pages['category'], $id);
157 }
158
159 return $this->addUrlFrom($url, $from);
160 }
162 public function getCategoryByPlacement($code, $from = '')
163 {
164 $url = $this->getReplaced($this->pages['category_placement'], '#CODE#', $code);
165
166 return $this->addUrlFrom($url, $from);
167 }
169 public function getSubscriptionBuyUrl()
170 {
171 $result = '';
172 if (ModuleManager::isModuleInstalled('bitrix24'))
173 {
174 $result = '/settings/license_buy.php?product=subscr';
175 }
176 else
177 {
178 $region = Option::get('main', '~PARAM_CLIENT_LANG', LANGUAGE_ID);
179
180 if ($region === 'ru')
181 {
182 $result = 'https://www.1c-bitrix.ru/buy/products/b24.php?subscr=y';
183 }
184 elseif ($region === 'ua')
185 {
186 $result = 'https://www.bitrix.ua/buy/products/b24.php?subscr=y';
187 }
188 elseif ($region === 'by')
189 {
190 $result = 'https://www.1c-bitrix.by/buy/products/b24.php?subscr=y';
191 }
192 }
193
194 return $result;
195 }
197 public function getPlacementUrl($placementId, $params)
198 {
199 $placementId = intval($placementId);
200 $replace = null;
201 $subject = null;
202 if ($placementId > 0)
203 {
204 $replace = [
205 '#PLACEMENT_ID#'
206 ];
207 $subject = [
208 $placementId
209 ];
210 }
211 $url = $this->getReplaced($this->pages["placement"], $replace, $subject);
212
213 if(is_array($params))
214 {
215 $uri = new \Bitrix\Main\Web\Uri($url);
216 $uri->addParams(
217 [
218 'params' => $params
219 ]
220 );
221 $url = $uri->getUri();
222 }
223 return $url;
224 }
226 public function getBooklet($code = null, $from = '')
227 {
228 $replace = null;
229 $subject = null;
230 if (!is_null($code))
231 {
232 $replace = [
233 "#CODE#"
234 ];
235 $subject = [
236 $code
237 ];
238 }
239 $url = $this->getReplaced($this->pages["booklet"], $replace, $subject);
240
241 $url = $this->addUrlFrom($url, $from);
242
243 return $url;
244 }
246 public function getPlacementViewUrl($appCode, $params)
247 {
248 $replace = null;
249 $subject = null;
250 if ($appCode)
251 {
252 $replace = [
253 '#APP#'
254 ];
255 $subject = [
256 $appCode
257 ];
258 }
259 $url = $this->getReplaced($this->pages["placement_view"], $replace, $subject);
260
261 if (is_array($params))
262 {
263 $uri = new \Bitrix\Main\Web\Uri($url);
264 $uri->addParams(
265 [
266 'params' => $params
267 ]
268 );
269 $url = $uri->getUri();
270 }
271
272 return $url;
273 }
275 class Application extends Templates
277 protected $directory = "marketplace/app/";
278 protected $pages = [
279 "index" => "",
280 "list" => "",
281 "detail" => "#ID#/",
282 "edit" => "edit/#ID#/"
283 ];
284 }
286 class LocalApplication extends Templates
288 protected $directory = "marketplace/local/";
289 protected $pages = [
290 "index" => "",
291 "list" => "list/",
292 "detail" => "detail/#ID#/",
293 "edit" => "edit/#ID#/"
294 ];
295 }
297 class Configuration extends Templates
299 protected $directory = 'marketplace/configuration/';
300 protected $pages = [
301 'index' => '',
302 'placement' => 'placement/#PLACEMENT_CODE#/',
303 'section' => 'section/#MANIFEST_CODE#/',
304 'import' => 'import/',
305 'import_app' => 'import/#APP_CODE#/',
306 'import_rollback' => 'import_rollback/#APP#/',
307 'import_zip' => 'import_zip/#ZIP_ID#/',
308 'import_manifest' => 'import_#MANIFEST_CODE#/',
309 'export' => 'export_#MANIFEST_CODE#/',
310 'export_element' => 'export_#MANIFEST_CODE#/#ITEM_CODE#/'
311 ];
313 protected $pageListAdmin = [
314 'import_zip' => 'rest_import_zip.php?id=#ZIP_ID#',
315 ];
317 public function getPlacement($code = null, $context = null)
318 {
319 $replace = null;
320 $subject = null;
321 if (!is_null($code))
322 {
323 $replace = [
324 '#PLACEMENT_CODE#'
325 ];
326 $subject = [
327 $code
328 ];
329 }
330 $url = $this->getReplaced($this->getPage('placement'), $replace, $subject);
331
332 if(!is_null($context))
333 {
334 $uri = new \Bitrix\Main\Web\Uri($url);
335 $uri->addParams(
336 [
337 "from" => $context
338 ]
339 );
340 $url = $uri->getUri();
341 }
342 return $url;
343 }
345 public function getSection($manifestCode = null)
346 {
347 $replace = null;
348 $subject = null;
349 if (!is_null($manifestCode))
350 {
351 $replace = [
352 '#MANIFEST_CODE#'
353 ];
354 $subject = [
355 $manifestCode
356 ];
357 }
358 return $this->getReplaced($this->getPage('section'), $replace, $subject);
359 }
361 public function getImport()
362 {
363 return $this->getReplaced($this->getPage('import'));
364 }
366 public function getImportManifest($manifestCode)
367 {
368 $replace = null;
369 $subject = null;
370 if (!is_null($manifestCode))
371 {
372 $replace = [
373 '#MANIFEST_CODE#'
374 ];
375 $subject = [
376 $manifestCode
377 ];
378 }
379 return $this->getReplaced($this->getPage('import_manifest'), $replace, $subject);
380 }
382 public function getImportApp($code = null)
383 {
384 $replace = null;
385 $subject = null;
386 if (!is_null($code))
387 {
388 $replace = [
389 '#APP_CODE#'
390 ];
391 $subject = [
392 $code
393 ];
394 }
395 return $this->getReplaced($this->getPage('import_app'), $replace, $subject);
396 }
398 public function getImportRollback($appCode)
399 {
400 $replace = [
401 '#APP#'
402 ];
403 $subject = [
404 $appCode
405 ];
406
407 return $this->getReplaced($this->getPage('import_rollback'), $replace, $subject);
408 }
410 public function getImportZip($zipId, $from)
411 {
412 $replace = [
413 '#ZIP_ID#'
414 ];
415 $subject = [
416 (int) $zipId
417 ];
418 $url = $this->getReplaced($this->getPage('import_zip'), $replace, $subject);
419
420 return $this->addUrlFrom($url, $from);
421 }
423 public function getExport($manifestCode = null)
424 {
425 $replace = null;
426 $subject = null;
427 if (!is_null($manifestCode))
428 {
429 $replace = [
430 '#MANIFEST_CODE#'
431 ];
432 $subject = [
433 $manifestCode
434 ];
435 }
436 return $this->getReplaced($this->getPage('export'), $replace, $subject);
437 }
439 public function getExportElement($manifestCode = null, $itemCode = null)
440 {
441 $replace = null;
442 $subject = null;
443 if (!is_null($manifestCode))
444 {
445 $replace = [
446 '#MANIFEST_CODE#',
447 '#ITEM_CODE#'
448 ];
449 $subject = [
450 $manifestCode,
451 $itemCode
452 ];
453 }
454 return $this->getReplaced($this->getPage('export_element'), $replace, $subject);
455 }
457 protected function getReplaced(string $url, $replace = null, $subject = null)
458 {
459 if (!is_null($replace) && !is_null($subject))
460 {
461 $url = str_replace($replace, $subject, $url);
462 }
463
464 return $url;
465 }
466 }
467}
469{
470
471 use Bitrix\Rest\Marketplace\Urls\Marketplace as MarketplaceUrls;
472 use Bitrix\Rest\Marketplace\Urls\Application as ApplicationUrls;
473 use Bitrix\Rest\Marketplace\Urls\LocalApplication as LocalApplicationUrls;
477 class Url
479 public static function getCategoryUrl($id = null, $from = '')
480 {
481 return MarketplaceUrls::getInstance()->getCategoryUrl($id, $from);
482 }
484 public static function getCategoryByPlacement($code, $from = '')
485 {
486 return MarketplaceUrls::getInstance()->getCategoryByPlacement($code, $from);
487 }
489 public static function getApplicationDetailUrl($id = null, $from = '')
490 {
491 return MarketplaceUrls::getInstance()->getDetailUrl($id, $from);
493 public static function getApplicationUrl($id = null)
494 {
495 return ApplicationUrls::getInstance()->getDetailUrl($id);
496 }
497
502 public static function getApplicationAddUrl()
503 {
504 return LocalApplicationUrls::getInstance()->getIndexUrl();
506 public static function getWidgetAddUrl()
507 {
508 return "";
509 }
510
518 public static function getApplicationPlacementUrl($placementId = null, $params = null)
519 {
520 return DevOps::getInstance()->getPlacementUrl((int)$placementId, $params);
521 }
523 public static function getApplicationPlacementViewUrl($appCode = null, $params = null)
524 {
525 return MarketplaceUrls::getInstance()->getPlacementViewUrl($appCode, $params);
526 }
528 public static function getMarketplaceUrl($from = '')
529 {
530 return MarketplaceUrls::getInstance()->getIndexUrl($from);
531 }
533 public static function getBookletUrl($code = null, $from = '')
534 {
535 return MarketplaceUrls::getInstance()->getBooklet($code, $from);
536 }
538 public static function getConfigurationUrl()
539 {
540 return Configuration::getInstance()->getIndexUrl();
541 }
543 public static function getConfigurationPlacementUrl($code = null, $context = null)
544 {
545 return Configuration::getInstance()->getPlacement($code, $context);
546 }
548 public static function getConfigurationSectionUrl($manifestCode = null)
549 {
550 return Configuration::getInstance()->getSection($manifestCode);
551 }
553 public static function getConfigurationImportUrl()
554 {
555 return Configuration::getInstance()->getImport();
556 }
558 public static function getConfigurationImportManifestUrl($code)
559 {
560 return Configuration::getInstance()->getImportManifest($code);
561 }
563 public static function getConfigurationImportAppUrl($code = null)
564 {
565 return Configuration::getInstance()->getImportApp($code);
566 }
568 public static function getConfigurationImportRollbackUrl($appCode)
569 {
570 return Configuration::getInstance()->getImportRollback($appCode);
571 }
573 public static function getConfigurationImportZipUrl($zipId, $from = '')
574 {
575 return Configuration::getInstance()->getImportZip($zipId, $from);
576 }
578 public static function getConfigurationExportUrl($manifestCode = null)
579 {
580 return Configuration::getInstance()->getExport($manifestCode);
581 }
583 public static function getConfigurationExportElementUrl($manifestCode = null, $itemCode = null)
584 {
585 return Configuration::getInstance()->getExportElement($manifestCode, $itemCode);
586 }
588 public static function getSubscriptionBuyUrl() : string
589 {
590 return MarketplaceUrls::getInstance()->getSubscriptionBuyUrl();
591 }
592 }
593}
594
const DIRECTORY_SEPARATOR
Definition path.php:12
static isModuleInstalled($moduleName)
static getCategoryUrl($id=null, $from='')
Definition url.php:478
getReplaced(string $url, $replace=null, $subject=null)
Definition url.php:456
getExportElement($manifestCode=null, $itemCode=null)
Definition url.php:438
getPlacement($code=null, $context=null)
Definition url.php:316
getBooklet($code=null, $from='')
Definition url.php:225
getCategoryUrl($id=null, $from='')
Definition url.php:147
getPlacementViewUrl($appCode, $params)
Definition url.php:245
getPlacementUrl($placementId, $params)
Definition url.php:196
getCategoryByPlacement($code, $from='')
Definition url.php:161
getReplacedId(string $url, $id=null)
Definition url.php:116
getReplaced(string $url, $replace=null, $subject=null)
Definition url.php:124
getDetailUrl($id=null, $from='')
Definition url.php:80