Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
copyright.php
1<?php
2
4
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'];
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 {
64 return !\Bitrix\Landing\Restriction\Manager::isAllowed(
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 '#LOGO#' => $logo,
237 '<linksite>' => '<a class="bitrix-footer-link" target="_blank" href="' . $linkSite . '">',
238 '</linksite>' => '</a>',
239 ],
240 $lang
241 );
242 }
243
244 // default
245 return str_replace(
246 [
247 '#LOGO#',
248 '<linklogo>', '</linklogo>',
249 '<linksite>', '</linksite>',
250 '<linkcrm>', '</linkcrm>',
251 ],
252 [
253 $logo, '', '', '', '', '', ''
254 ],
255 $commonText
256 );
257 }
258
263 protected function getAdditionalText(): string
264 {
265 if (!$this->isRuLang() || !Manager::isB24())
266 {
267 return '';
268 }
269
270 $type = strtoupper(Landing::getSiteType());
271 $phrases = $this->getRandomPhraseCollection($type);
272 $code = (int)$this->fields['CODE']->getValue() ?: 1;
273 $text = $phrases[$code] ?: $phrases[1];
274 if (is_array($text))
275 {
276 $text = $text[0];
277 }
278 $component = $this->getPublicComponent();
279
280 $link = $component->getRefLink('websites', true, true);
281 if ($type === self::PAGE_TYPE_STORE)
282 {
283 $link = str_replace('features/sites.php', 'features/shop.php', $link);
284 }
285
286 return '. <a href="' . $link . '" class="bitrix-footer-link">' . $text . '</a>';
287 }
288
289 protected function getPublicComponent(): \LandingPubComponent
290 {
294 static $component = null;
295
296 if (!$component)
297 {
298 $componentClass = \CBitrixComponent::includeComponentClass('bitrix:landing.pub');
299 $component = new $componentClass;
300 $component->setZone($this->getLang());
301 }
302
303 return $component;
304 }
305
306 protected function getTermsContent(): string
307 {
308 $content = '<div class="bitrix-footer-terms">';
309 $lang = $this->getLang();
310 $setLinks = [
311 'com' => [
312 'report' => 'https://www.bitrix24.com/abuse/',
313 ],
314 'ru' => [
315 'report' => 'https://www.bitrix24.ru/abuse/',
316 ],
317 'br' => [
318 'report' => 'https://www.bitrix24.com.br/abuse/',
319 ],
320 'de' => [
321 'report' => 'https://www.bitrix24.de/abuse/',
322 ],
323 'es' => [
324 'report' => 'https://www.bitrix24.es/abuse/',
325 ],
326 'ua' => [
327 'report' => 'https://www.bitrix24.ua/abuse/',
328 ],
329 'kz' => [
330 'report' => 'https://www.bitrix24.kz/abuse/',
331 ],
332 'by' => [
333 'report' => 'https://www.bitrix24.by/abuse/',
334 ],
335 ];
336 $region = Application::getInstance()->getLicense()->getRegion();
337 $hrefLinkReport = new Uri($setLinks[$region]['report'] ?? $setLinks['com']['report']);
338 $protocol = Manager::isHttps() ? 'https://' : 'http://';
339 $url = $protocol . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
340 $siteId = $this->getSiteId();
341 $portalName = \COption::getOptionString("main", "server_name", '');
342 $senderPage = strtoupper(Landing::getSiteType());
343 $urlParams = [
344 'sender_page' => urlencode($senderPage),
345 'hostname' => urlencode($portalName),
346 'siteId' => urlencode($siteId),
347 'from_url' => urlencode($url),
348 ];
349 $hrefLinkReportWithParams = $hrefLinkReport->addParams($urlParams);
350 $linkReport = '<a class="bitrix-footer-link bitrix-footer-link-report" target="_blank" rel="nofollow" href="'
351 . $hrefLinkReportWithParams
352 . '">'
353 . Loc::getMessage('LANDING_HOOK_COPYRIGHT_TEXT_CONTENT_LINK_REPORT', null, $lang)
354 . '</a>';
355 $hintText = Loc::getMessage('LANDING_HOOK_COPYRIGHT_TEXT_CONTENT_LINK_REPORT_HINT', null, $lang);
356 $hint = '<span class="bitrix-footer-hint" data-hint="' . $hintText . '"></span>';
357 $content .= $linkReport . $hint;
358 $content .= '</div>';
359
360 return $content;
361 }
362
367 protected function getRandomPhraseCollection(string $type): array
368 {
369 $phrases = [];
370
371 if ($this->isRuLang())
372 {
373 Loc::loadMessages(Manager::getDocRoot() . '/bitrix/modules/landing/lib/hook/page/copyright_notranslate.php');
374 if ($type === self::PAGE_TYPE_STORE)
375 {
376 for ($i = 1; $i <= self::RANDOM_PHRASE_COUNT; $i++)
377 {
378 $phrases[$i] = Loc::getMessage('LANDING_HOOK_COPYRIGHT_TEXT_STORE_' . $i, null, 'ru');
379 }
380 }
381 // default
382 else
383 {
384 for ($i = 1; $i <= self::RANDOM_PHRASE_COUNT; $i++)
385 {
386 $phrases[$i] = Loc::getMessage('LANDING_HOOK_COPYRIGHT_TEXT_PAGE_' . $i, null, 'ru');
387 }
388 }
389 }
390
391 return $phrases;
392 }
393
398 public static function getRandomPhraseId(): int
399 {
400 return rand(1, self::RANDOM_PHRASE_COUNT);
401 }
402
412 public static function onCopy(?array $data, int $entityId, string $type, bool $publication = false): ?array
413 {
414 // only for site
415 if ($type !== Hook::ENTITY_TYPE_SITE)
416 {
417 return $data;
418 }
419
420 $data = $data ?: [];
421 $newData = $data;
422
423 if (!isset($newData['SHOW']))
424 {
425 $newData['SHOW'] = 'Y';
426 }
427 if (
428 !isset($newData['CODE'])
429 || !$publication
430 )
431 {
432 $newData['CODE'] = self::getRandomPhraseId();
433 }
434
435 // update
436 if (
437 $data !== $newData
438 && $publication
439 )
440 {
441 $fields = [
442 'HOOK' => 'COPYRIGHT',
443 'ENTITY_ID' => $entityId,
444 'ENTITY_TYPE' => $type,
445 'PUBLIC' => 'N',
446 ];
447 $existing = HookDataTable::getList([
448 'select' => ['ID', 'CODE'],
449 'filter' => $fields,
450 ]);
451 while ($row = $existing->fetch())
452 {
453 $res = HookDataTable::update($row['ID'], [
454 'VALUE' => $newData[$row['CODE']]
455 ]);
456 if ($res->isSuccess())
457 {
458 unset($newData[$row['CODE']]);
459 }
460 }
461
462 if (!empty($newData))
463 {
464 foreach($newData as $code => $value)
465 {
466 $fieldsAdd = $fields;
467 $fieldsAdd['CODE'] = $code;
468 $fieldsAdd['VALUE'] = $value;
469 HookDataTable::add($fieldsAdd);
470 }
471 }
472 }
473
474 return $newData;
475 }
476}
const ENTITY_TYPE_SITE
Definition hook.php:20
static getUrlFromFile($file)
Definition manager.php:1067
static loadMessages($file)
Definition loc.php:64
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29