1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
copyright.php
См. документацию.
1<?php
2
3namespace Bitrix\Landing\Hook\Page;
4
5use Bitrix\Landing\Hook;
6use Bitrix\Landing\Landing;
7use Bitrix\Landing\Manager;
8use Bitrix\Landing\Field;
9use Bitrix\Landing\Internals\HookDataTable;
10use Bitrix\Landing\Restriction\Site;
11use Bitrix\Main\Application;
12use Bitrix\Main\Localization\Loc;
13use Bitrix\Main\Web\Uri;
14use Bitrix\Main\UI\Extension;
15
17{
18 protected const PAGE_TYPE_PAGE = 'PAGE';
19 protected const PAGE_TYPE_STORE = 'STORE';
20
21 protected const REGIONS_RU_LANG = ['ru', 'by', 'kz', 'uz'];
22
23 private $lang;
24 private $siteId;
25
29 protected const RANDOM_PHRASE_COUNT = 32;
30
35 protected function getMap()
36 {
37 return [
38 'SHOW' => new Field\Checkbox('SHOW', [
39 'title' => Manager::isB24()
40 ? Loc::getMessage('LANDING_HOOK_COPYRIGHT_SHOW')
41 : Loc::getMessage('LANDING_HOOK_COPYRIGHT_SHOW_SMN'),
42 ]),
43 'CODE' => new Field\Text('CODE', [
44 'title' => Loc::getMessage('LANDING_HOOK_COPYRIGHT_CODE'),
45 ]),
46 ];
47 }
48
53 public function isFree()
54 {
55 return false;
56 }
57
62 public function isLocked()
63 {
65 'limit_sites_powered_by'
66 );
67 }
68
73 public function enabled()
74 {
75 if ($this->issetCustomExec())
76 {
77 return true;
78 }
79
80 if ($this->isLocked())
81 {
82 return true;
83 }
84
85 return $this->fields['SHOW']->getValue() !== 'N';
86 }
87
92 public function exec()
93 {
94 if ($this->execCustom())
95 {
96 return;
97 }
98
99 $this->setLang(Manager::getZone());
100 }
101
107 public function setLang(?string $lang): void
108 {
109 $this->lang = $this->lang ?: $lang;
110 }
111
116 protected function getLang(): string
117 {
118 return $this->lang ?: Manager::getZone();
119 }
120
126 public function setSiteId(?int $siteId): void
127 {
128 $this->siteId = $this->siteId ?: $siteId;
129 }
130
135 protected function getSiteId(): string
136 {
137 return $this->siteId ?: 0;
138 }
139
144 protected function isRuLang(): bool
145 {
146 return in_array($this->getLang(), self::REGIONS_RU_LANG, true);
147 }
148
153 public function view(): string
154 {
155 $isTermsFooterShow = Site::isTermsFooterShow();
156 $isHookEnabled = $this->enabled();
157 if ($isTermsFooterShow || $isHookEnabled)
158 {
159 $footer = '<div class="bitrix-footer">';
160 $footer .= '<span class="bitrix-footer-text">';
161 if ($isHookEnabled)
162 {
163 $footer .= '<div class="bitrix-footer-seo">';
164 $footer .= $this->getCommonText();
165 $footer .= $this->getAdditionalText();
166 $footer .= '</div>';
167 $footer .= $this->getTermsContent();
168 }
169 if ($isTermsFooterShow && !$isHookEnabled)
170 {
171 $footer .= $this->getTermsContent();
172 }
173 $footer .= '</span>';
174 $footer .= '</div>';
175
176 Extension::load('ui.hint');
177 $footer .= "<script>BX.ready(function() {BX.UI.Hint.init(BX('.bitrix-footer-terms'))})</script>";
178
179 return $footer;
180 }
181
182 return '';
183 }
184
185 protected function getCommonText(): ?string
186 {
187 $isB24 = Manager::isB24();
188 $lang = $this->getLang();
189
190 $commonText = Loc::getMessage('LANDING_HOOK_COPYRIGHT_TEXT_COMMON', null, $lang);
191 $logoUrl = Manager::getUrlFromFile(
192 '/bitrix/images/landing/copyright/logo_'
193 . (in_array($lang, ['ru', 'ua', 'en']) ? $lang : 'en')
194 . '.svg?1'
195 );
196 $logoAlt = Loc::getMessage('LANDING_HOOK_COPYRIGHT_LOGO_ALT', null, $lang);
197 $logo = '<img src="' . $logoUrl . '" alt="' . $logoAlt . '">';
198
199 // RU
200 if ($isB24 && $this->isRuLang())
201 {
202 return str_replace(
203 [
204 '#LOGO#',
205 '<linklogo>', '</linklogo>',
206 '<linksite>', '</linksite>',
207 '<linkcrm>', '</linkcrm>',
208 ],
209 [
210 $logo, '', '', '', '', '', '',
211 ],
212 $commonText
213 );
214 }
215
216 // SMN
217 $component = $this->getPublicComponent();
218 if (!$isB24)
219 {
220 $advCode = $component->getAdvCode();
221
222 return
223 Loc::getMessage('LANDING_HOOK_COPYRIGHT_TEXT_SMN_1')
224 . '<a href="https://www.1c-bitrix.ru/?' . $advCode . '" target="_blank" class="bitrix-footer-link">'
225 . Loc::getMessage('LANDING_HOOK_COPYRIGHT_TEXT_SMN_2')
226 . '</a>'
227 ;
228 }
229
230 // Not RU and B24
231 $linkSite = $component->getRefLink('websites', true, true);
232 if ($linkSite)
233 {
234 return Loc::getMessage(
235 'LANDING_HOOK_COPYRIGHT_TEXT_COMMON_EN',
236 [
237 '#LOGO#' => $logo,
238 '<linksite>' => '<a class="bitrix-footer-link" target="_blank" href="' . $linkSite . '">',
239 '</linksite>' => '</a>',
240 ],
241 $lang
242 );
243 }
244
245 // default
246 return str_replace(
247 [
248 '#LOGO#',
249 '<linklogo>', '</linklogo>',
250 '<linksite>', '</linksite>',
251 '<linkcrm>', '</linkcrm>',
252 ],
253 [
254 $logo, '', '', '', '', '', '',
255 ],
256 $commonText
257 );
258 }
259
264 protected function getAdditionalText(): string
265 {
266 if (!$this->isRuLang() || !Manager::isB24())
267 {
268 return '';
269 }
270
271 $type = strtoupper(Landing::getSiteType());
272 $phrases = $this->getRandomPhraseCollection($type);
273 $code = (int)$this->fields['CODE']->getValue() ?: 1;
274 $text = $phrases[$code] ?: $phrases[1];
275 if (is_array($text))
276 {
277 $text = $text[0];
278 }
279 $component = $this->getPublicComponent();
280
281 $link = $component->getRefLink('websites', true, true);
282 if ($type === self::PAGE_TYPE_STORE)
283 {
284 $link = str_replace('features/sites.php', 'features/shop.php', $link);
285 }
286
287 return '. <a href="' . $link . '" class="bitrix-footer-link">' . $text . '</a>';
288 }
289
290 protected function getPublicComponent(): \LandingPubComponent
291 {
295 static $component = null;
296
297 if (!$component)
298 {
299 $componentClass = \CBitrixComponent::includeComponentClass('bitrix:landing.pub');
300 $component = new $componentClass;
301 $component->setZone($this->getLang());
302 }
303
304 return $component;
305 }
306
307 protected function getTermsContent(): string
308 {
309 $reportUrl = $this->getReportUrl();
310 $reportLinkOpen =
311 '<a class="bitrix-footer-link" target="_blank" rel="nofollow" href="'
312 . $reportUrl->getUri()
313 . '">'
314 ;
315 $reportText = Loc::getMessage('LANDING_HOOK_COPYRIGHT_TEXT_CONTENT_LINK_REPORT_2', [
316 '#a1#' => $reportLinkOpen,
317 '#a2#' => '</a>',
318 ]);
319
320 $hintText = Loc::getMessage('LANDING_HOOK_COPYRIGHT_TEXT_CONTENT_LINK_REPORT_HINT');
321
322 return <<<HTML
323 <div class="bitrix-footer-terms">
324 <span class="bitrix-footer-link bitrix-footer-link-report">$reportText</span>
325 <span class="bitrix-footer-hint" data-hint="$hintText"></span>
326 </div>
327 HTML;
328 }
329
330 private function getReportUrl(): Uri
331 {
332 $links = [
333 'en' => [
334 'report' => 'https://www.bitrix24.com/abuse/',
335 ],
336 'ru' => [
337 'report' => 'https://www.bitrix24.ru/abuse/',
338 ],
339 'br' => [
340 'report' => 'https://www.bitrix24.com.br/abuse/',
341 ],
342 'de' => [
343 'report' => 'https://www.bitrix24.de/abuse/',
344 ],
345 'la' => [
346 'report' => 'https://www.bitrix24.es/abuse/',
347 ],
348 'ua' => [
349 'report' => 'https://www.bitrix24.ua/abuse/',
350 ],
351 'kz' => [
352 'report' => 'https://www.bitrix24.kz/abuse/',
353 ],
354 'by' => [
355 'report' => 'https://www.bitrix24.by/abuse/',
356 ],
357 'uz' => [
358 'report' => 'https://www.bitrix24.uz/abuse/',
359 ],
360 ];
361
362 $lang = $this->getLang();
363 $reportUrl = new Uri($links[$lang]['report'] ?? $links['com']['report']);
364
365 $protocol = Manager::isHttps() ? 'https://' : 'http://';
366 $fromUrl = $protocol . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
367 $portalName = \COption::getOptionString('main', 'server_name', '');
368 $senderPage = strtoupper(Landing::getSiteType());
369
370 $reportUrl->addParams([
371 'sender_page' => urlencode($senderPage),
372 'hostname' => urlencode($portalName),
373 'siteId' => urlencode($this->getSiteId()),
374 'from_url' => urlencode($fromUrl),
375 ]);
376
377 return $reportUrl;
378 }
379
384 protected function getRandomPhraseCollection(string $type): array
385 {
386 $phrases = [];
387
388 if ($this->isRuLang())
389 {
390 Loc::loadMessages(Manager::getDocRoot() . '/bitrix/modules/landing/lib/hook/page/copyright_notranslate.php');
391 if ($type === self::PAGE_TYPE_STORE)
392 {
393 for ($i = 1; $i <= self::RANDOM_PHRASE_COUNT; $i++)
394 {
395 $phrases[$i] = Loc::getMessage('LANDING_HOOK_COPYRIGHT_TEXT_STORE_' . $i, null, 'ru');
396 }
397 }
398 // default
399 else
400 {
401 for ($i = 1; $i <= self::RANDOM_PHRASE_COUNT; $i++)
402 {
403 $phrases[$i] = Loc::getMessage('LANDING_HOOK_COPYRIGHT_TEXT_PAGE_' . $i, null, 'ru');
404 }
405 }
406 }
407
408 return $phrases;
409 }
410
415 public static function getRandomPhraseId(): int
416 {
417 return rand(1, self::RANDOM_PHRASE_COUNT);
418 }
419
429 public static function onCopy(?array $data, int $entityId, string $type, bool $publication = false): ?array
430 {
431 // only for site
432 if ($type !== Hook::ENTITY_TYPE_SITE)
433 {
434 return $data;
435 }
436
437 $data = $data ?: [];
438 $newData = $data;
439
440 if (!isset($newData['SHOW']))
441 {
442 $newData['SHOW'] = 'Y';
443 }
444 if (
445 !isset($newData['CODE'])
446 || !$publication
447 )
448 {
449 $newData['CODE'] = self::getRandomPhraseId();
450 }
451
452 // update
453 if (
454 $data !== $newData
455 && $publication
456 )
457 {
458 $fields = [
459 'HOOK' => 'COPYRIGHT',
460 'ENTITY_ID' => $entityId,
461 'ENTITY_TYPE' => $type,
462 'PUBLIC' => 'N',
463 ];
464 $existing = HookDataTable::getList([
465 'select' => ['ID', 'CODE'],
466 'filter' => $fields,
467 ]);
468 while ($row = $existing->fetch())
469 {
470 $res = HookDataTable::update($row['ID'], [
471 'VALUE' => $newData[$row['CODE']],
472 ]);
473 if ($res->isSuccess())
474 {
475 unset($newData[$row['CODE']]);
476 }
477 }
478
479 if (!empty($newData))
480 {
481 foreach($newData as $code => $value)
482 {
483 $fieldsAdd = $fields;
484 $fieldsAdd['CODE'] = $code;
485 $fieldsAdd['VALUE'] = $value;
486 HookDataTable::add($fieldsAdd);
487 }
488 }
489 }
490
491 return $newData;
492 }
493}
$type
Определения options.php:106
issetCustomExec()
Определения page.php:253
$fields
Определения page.php:18
execCustom()
Определения page.php:262
static isB24()
Определения manager.php:1135
static getDocRoot()
Определения manager.php:180
static isHttps()
Определения manager.php:1032
static getZone()
Определения manager.php:930
static getUrlFromFile($file)
Определения manager.php:1082
static isAllowed(string $code, array $params=[], string $cacheSalt='')
Определения manager.php:214
Определения uri.php:17
$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
$protocol
Определения .description.php:9
$_SERVER["DOCUMENT_ROOT"]
Определения cron_frame.php:9
if(!is_null($config))($config as $configItem)(! $configItem->isVisible()) $code
Определения options.php:195
if(!defined('SITE_ID')) $lang
Определения include.php:91
$value
Определения Param.php:39
$entityId
Определения payment.php:4
$text
Определения template_pdf.php:79
lang
Определения options.php:182
$i
Определения factura.php:643