Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
favicon.php
1<?php
3
4use \Bitrix\Landing\Field;
5use \Bitrix\Landing\File;
6use \Bitrix\Landing\Manager;
7use \Bitrix\Landing\PublicAction;
8use \Bitrix\Main\Localization\Loc;
9
10Loc::loadMessages(__FILE__);
11
13{
18 protected function getMap()
19 {
20 return array(
21 'PICTURE' => new Field\Hidden('PICTURE', array(
22 'title' => Loc::getMessage('LANDING_HOOK_FI_PICTURE'),
23 'fetch_data_modification' => function($value)
24 {
26 {
27 if ($value > 0)
28 {
29 $path = File::getFilePath($value);
30 if ($path)
31 {
32 $path = Manager::getUrlFromFile($path);
33 return $path;
34 }
35 }
36 }
37 return $value;
38 }
39 ))
40 );
41 }
42
47 public function getTitle()
48 {
49 return Loc::getMessage('LANDING_HOOK_FI_PICTURE');
50 }
51
56 public function enabledInEditMode()
57 {
58 return false;
59 }
60
65 public function enabled()
66 {
67 if ($this->issetCustomExec())
68 {
69 return true;
70 }
71
72 return $this->fields['PICTURE']->getValue() > 0;
73 }
74
79 public function exec()
80 {
81 if ($this->execCustom())
82 {
83 return;
84 }
85
86 $picture = intval($this->fields['PICTURE']->getValue());
87
88 if ($picture > 0)
89 {
90 $icons = "\n";
91 // first simple favicons
92 $sizes = ['16x16', '32x32', '96x96'];
93 foreach ($sizes as $size)
94 {
95 list($w, $h) = explode('x', $size);
96 $file = \CFile::resizeImageGet(
98 array(
99 'width' => $w,
100 'height' => $h
101 ),
102 BX_RESIZE_IMAGE_EXACT
103 );
104 if ($file)
105 {
106 $srcExplode = explode('.', $file['src']);
107 $ext = array_pop($srcExplode);
108 $icons .= '<link rel="icon" type="image/' . $ext .
109 '" href="' . $file['src'] . '" sizes="' . $size . '">' . "\n";
110 }
111 }
112 // apple icons
113 $sizes = array('120x120', '180x180', '152x152', '167x167');
114 foreach ($sizes as $size)
115 {
116 list($w, $h) = explode('x', $size);
117 $file = \CFile::resizeImageGet(
119 array(
120 'width' => $w,
121 'height' => $h
122 ),
123 BX_RESIZE_IMAGE_EXACT
124 );
125 if ($file)
126 {
127 $icons .= '<link rel="apple-touch-icon"' .
128 ' href="' . $file['src'] . '" sizes="' . $size . '">' . "\n";
129 }
130 }
131 if ($icons)
132 {
134 'BeforeHeadClose',
135 $icons,
136 true
137 );
138 }
139 }
140 }
141}
static getFileArray($fileId)
Definition file.php:580
static getFilePath($fileId)
Definition file.php:600
static getUrlFromFile($file)
Definition manager.php:1067
static setPageView(string $marker, string $content, bool $skipTrim=false)
Definition manager.php:465
static loadMessages($file)
Definition loc.php:64
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29