1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
mailtools.php
См. документацию.
1<?php
2
4{
5 public $aMatches = [];
6 protected $pcre_backtrack_limit = false;
7 protected $server_name = null;
8 protected $maxFileSize = 0;
9
10 public static function IsEightBit($str)
11 {
12 $len = mb_strlen($str);
13 for ($i = 0; $i < $len; $i++)
14 {
15 if (ord(mb_substr($str, $i, 1)) >> 7)
16 {
17 return true;
18 }
19 }
20 return false;
21 }
22
23 public static function EncodeMimeString($text, $charset)
24 {
26 {
27 return $text;
28 }
29
30 $maxl = intval((76 - mb_strlen($charset) + 7) * 0.4);
31
32 $res = '';
34 $len = mb_strlen($text);
35 for ($i = 0; $i < $len; $i += $maxl)
36 {
37 if ($i > 0)
38 {
39 $res .= $eol . "\t";
40 }
41 $res .= '=?' . $charset . '?B?' . base64_encode(mb_substr($text, $i, $maxl)) . '?=';
42 }
43 return $res;
44 }
45
46 public static function EncodeSubject($text, $charset)
47 {
48 return '=?' . $charset . '?B?' . base64_encode($text) . '?=';
49 }
50
51 public static function EncodeHeaderFrom($text, $charset)
52 {
53 $i = strlen($text);
54 while ($i > 0)
55 {
56 if (ord($text[$i - 1]) >> 7)
57 {
58 break;
59 }
60 $i--;
61 }
62 if ($i == 0)
63 {
64 return $text;
65 }
66 else
67 {
68 return '=?' . $charset . '?B?' . base64_encode(substr($text, 0, $i)) . '?=' . substr($text, $i);
69 }
70 }
71
72 protected function __replace_img($matches)
73 {
75 $src = $matches[3];
76
77 if ($src == '')
78 {
79 return $matches[0];
80 }
81
82 if (array_key_exists($src, $this->aMatches))
83 {
84 $uid = $this->aMatches[$src]['ID'];
85 return $matches[1] . $matches[2] . 'cid:' . $uid . $matches[4] . $matches[5];
86 }
87
88 $filePath = $io->GetPhysicalName($_SERVER['DOCUMENT_ROOT'] . $src);
89 if (!file_exists($filePath))
90 {
91 return $matches[0];
92 }
93
94 if (
95 $this->maxFileSize > 0
96 && filesize($filePath) > $this->maxFileSize
97 )
98 {
99 return $matches[0];
100 }
101
102 $image = new \Bitrix\Main\File\Image($filePath);
103 $info = $image->getInfo();
104 if (!$info)
105 {
106 return $matches[0];
107 }
108
109 if (function_exists('image_type_to_mime_type'))
110 {
111 $contentType = image_type_to_mime_type($info->getFormat());
112 }
113 else
114 {
116 }
117
118 $uid = uniqid(md5($src));
119
120 $this->aMatches[$src] = [
121 'SRC' => $src,
122 'PATH' => $filePath,
123 'CONTENT_TYPE' => $contentType,
124 'DEST' => bx_basename($src),
125 'ID' => $uid,
126 ];
127
128 return $matches[1] . $matches[2] . 'cid:' . $uid . $matches[4] . $matches[5];
129 }
130
131 public function ReplaceHrefs($text)
132 {
133 if ($this->pcre_backtrack_limit === false)
134 {
135 $this->pcre_backtrack_limit = intval(ini_get('pcre.backtrack_limit'));
136 }
137 $text_len = strlen($text);
138 $text_len++;
139 if ($this->pcre_backtrack_limit < $text_len)
140 {
141 @ini_set('pcre.backtrack_limit', $text_len);
142 $this->pcre_backtrack_limit = intval(ini_get('pcre.backtrack_limit'));
143 }
144
145 if (!isset($this->server_name))
146 {
147 $this->server_name = COption::GetOptionString('main', 'server_name', '');
148 }
149
150 if ($this->server_name != '')
151 {
152 $text = preg_replace(
153 "/(<a\\s[^>]*?(?<=\\s)href\\s*=\\s*)([\"'])(\\/.*?)(\\2)(\\s.+?>|\\s*>)/is",
154 "\\1\\2http://" . $this->server_name . "\\3\\4\\5",
155 $text
156 );
157 }
158
159 return $text;
160 }
161
162 public function ReplaceImages($text)
163 {
164 if ($this->pcre_backtrack_limit === false)
165 {
166 $this->pcre_backtrack_limit = intval(ini_get('pcre.backtrack_limit'));
167 }
168 $text_len = strlen($text);
169 $text_len++;
170 if ($this->pcre_backtrack_limit < $text_len)
171 {
172 @ini_set('pcre.backtrack_limit', $text_len);
173 $this->pcre_backtrack_limit = intval(ini_get('pcre.backtrack_limit'));
174 }
175 $this->maxFileSize = intval(COption::GetOptionInt('subscribe', 'max_file_size'));
176 $this->aMatches = [];
177 $text = preg_replace_callback(
178 "/(<img\\s[^>]*?(?<=\\s)src\\s*=\\s*)([\"']?)(.*?)(\\2)(\\s.+?>|\\s*>)/is",
179 [$this, '__replace_img'],
180 $text
181 );
182 $text = preg_replace_callback(
183 "/(background-image\\s*:\\s*url\\s*\\()([\"']?)(.*?)(\\2)(\\s*\\);)/is",
184 [$this, '__replace_img'],
185 $text
186 );
187 $text = preg_replace_callback(
188 "/(<td\\s[^>]*?(?<=\\s)background\\s*=\\s*)([\"']?)(.*?)(\\2)(\\s.+?>|\\s*>)/is",
189 [$this, '__replace_img'],
190 $text
191 );
192 $text = preg_replace_callback(
193 "/(<table\\s[^>]*?(?<=\\s)background\\s*=\\s*)([\"']?)(.*?)(\\2)(\\s.+?>|\\s*>)/is",
194 [$this, '__replace_img'],
195 $text
196 );
197 return $text;
198 }
199
200 public static function ImageTypeToMimeType($type)
201 {
202 static $aTypes = [
203 1 => 'image/gif',
204 2 => 'image/jpeg',
205 3 => 'image/png',
206 4 => 'application/x-shockwave-flash',
207 5 => 'image/psd',
208 6 => 'image/bmp',
209 7 => 'image/tiff',
210 8 => 'image/tiff',
211 9 => 'application/octet-stream',
212 10 => 'image/jp2',
213 11 => 'application/octet-stream',
214 12 => 'application/octet-stream',
215 13 => 'application/x-shockwave-flash',
216 14 => 'image/iff',
217 15 => 'image/vnd.wap.wbmp',
218 16 => 'image/xbm',
219 ];
220 if (isset($aTypes[$type]))
221 {
222 return $aTypes[$type];
223 }
224 else
225 {
226 return 'application/octet-stream';
227 }
228 }
229}
$type
Определения options.php:106
static getMailEol()
Определения mail.php:856
static GetInstance()
Определения virtual_io.php:60
Определения mailtools.php:4
static EncodeHeaderFrom($text, $charset)
Определения mailtools.php:51
__replace_img($matches)
Определения mailtools.php:72
$server_name
Определения mailtools.php:7
$aMatches
Определения mailtools.php:5
static IsEightBit($str)
Определения mailtools.php:10
$maxFileSize
Определения mailtools.php:8
static EncodeMimeString($text, $charset)
Определения mailtools.php:23
static EncodeSubject($text, $charset)
Определения mailtools.php:46
ReplaceHrefs($text)
Определения mailtools.php:131
$pcre_backtrack_limit
Определения mailtools.php:6
ReplaceImages($text)
Определения mailtools.php:162
static ImageTypeToMimeType($type)
Определения mailtools.php:200
$str
Определения commerceml2.php:63
$res
Определения filter_act.php:7
$uid
Определения hot_keys_act.php:8
$_SERVER["DOCUMENT_ROOT"]
Определения cron_frame.php:9
$io
Определения csv_new_run.php:98
if($NS['step']==6) if( $NS[ 'step']==7) if(COption::GetOptionInt('main', 'disk_space', 0) > 0) $info
Определения backup.php:924
bx_basename($path, $ext="")
Определения tools.php:3269
$contentType
Определения quickway.php:301
$text
Определения template_pdf.php:79
$i
Определения factura.php:643
$matches
Определения index.php:22