Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
mailserviceinstaller.php
1<?php
2
4
6
8{
9 private const SERVICES_VERSION = 2;
10 private const MODULE_NAME = 'mail';
11 private const OPTION_NAME = 'services_version';
12
21 public static function installServices($siteId)
22 {
23 $mailServices = array(
24 'gmail' => array(
25 'SERVER' => 'imap.gmail.com',
26 'PORT' => 993,
27 'ENCRYPTION' => 'Y',
28 'LINK' => 'https://mail.google.com/',
29 'SMTP_SERVER' => 'smtp.gmail.com',
30 'SMTP_PORT' => 465,
31 'SMTP_ENCRYPTION' => 'Y',
32 'SMTP_LOGIN_AS_IMAP' => 'Y',
33 'SMTP_PASSWORD_AS_IMAP' => 'Y',
34 'UPLOAD_OUTGOING' => 'N',
35 ),
36 'icloud' => array(
37 'SERVER' => 'imap.mail.me.com',
38 'PORT' => 993,
39 'ENCRYPTION' => 'Y',
40 'LINK' => 'https://www.icloud.com/#mail',
41 'SMTP_SERVER' => 'smtp.mail.me.com',
42 'SMTP_PORT' => 587,
43 'SMTP_ENCRYPTION' => 'N',
44 'SMTP_LOGIN_AS_IMAP' => 'Y',
45 'SMTP_PASSWORD_AS_IMAP' => 'Y',
46 'UPLOAD_OUTGOING' => 'Y',
47 ),
48 'outlook.com' => array(
49 'SERVER' => 'imap-mail.outlook.com',
50 'PORT' => 993,
51 'ENCRYPTION' => 'Y',
52 'LINK' => 'https://www.outlook.com/owa',
53 'SMTP_SERVER' => 'smtp-mail.outlook.com',
54 'SMTP_PORT' => 587,
55 'SMTP_ENCRYPTION' => 'N',
56 'SMTP_LOGIN_AS_IMAP' => 'Y',
57 'SMTP_PASSWORD_AS_IMAP' => 'Y',
58 'UPLOAD_OUTGOING' => 'Y',
59 ),
60 'office365' => array(
61 'SERVER' => 'outlook.office365.com',
62 'PORT' => 993,
63 'ENCRYPTION' => 'Y',
64 'LINK' => 'http://mail.office365.com/',
65 'SMTP_SERVER' => 'smtp.office365.com',
66 'SMTP_PORT' => 587,
67 'SMTP_ENCRYPTION' => 'N',
68 'SMTP_LOGIN_AS_IMAP' => 'Y',
69 'SMTP_PASSWORD_AS_IMAP' => 'Y',
70 'UPLOAD_OUTGOING' => 'N',
71 ),
72 'yahoo' => array(
73 'SERVER' => 'imap.mail.yahoo.com',
74 'PORT' => 993,
75 'ENCRYPTION' => 'Y',
76 'LINK' => 'http://mail.yahoo.com/',
77 'SMTP_SERVER' => 'smtp.mail.yahoo.com',
78 'SMTP_PORT' => 465,
79 'SMTP_ENCRYPTION' => 'Y',
80 'SMTP_LOGIN_AS_IMAP' => 'Y',
81 'SMTP_PASSWORD_AS_IMAP' => 'Y',
82 'UPLOAD_OUTGOING' => 'N',
83 ),
84 'aol' => array(
85 'SERVER' => 'imap.aol.com',
86 'PORT' => 993,
87 'ENCRYPTION' => 'Y',
88 'LINK' => 'http://mail.aol.com/',
89 'SMTP_SERVER' => 'smtp.aol.com',
90 'SMTP_PORT' => 465,
91 'SMTP_ENCRYPTION' => 'Y',
92 'SMTP_LOGIN_AS_IMAP' => 'Y',
93 'SMTP_PASSWORD_AS_IMAP' => 'Y',
94 'UPLOAD_OUTGOING' => 'Y',
95 ),
96 'yandex' => array(
97 'SERVER' => 'imap.yandex.ru',
98 'PORT' => 993,
99 'ENCRYPTION' => 'Y',
100 'LINK' => 'https://mail.yandex.ru/',
101 'SMTP_SERVER' => 'smtp.yandex.ru',
102 'SMTP_PORT' => 465,
103 'SMTP_ENCRYPTION' => 'Y',
104 'SMTP_LOGIN_AS_IMAP' => 'Y',
105 'SMTP_PASSWORD_AS_IMAP' => 'Y',
106 'UPLOAD_OUTGOING' => 'Y',
107 ),
108 'mail.ru' => array(
109 'SERVER' => 'imap.mail.ru',
110 'PORT' => 993,
111 'ENCRYPTION' => 'Y',
112 'LINK' => 'http://e.mail.ru/',
113 'SMTP_SERVER' => 'smtp.mail.ru',
114 'SMTP_PORT' => 465,
115 'SMTP_ENCRYPTION' => 'Y',
116 'SMTP_LOGIN_AS_IMAP' => 'Y',
117 'SMTP_PASSWORD_AS_IMAP' => 'Y',
118 'UPLOAD_OUTGOING' => 'Y',
119 ),
120 'exchange' => array(),
121 'other' => array(),
122 'exchangeOnline' => array(
123 'SERVER' => 'outlook.office365.com',
124 'PORT' => 993,
125 'ENCRYPTION' => 'Y',
126 'LINK' => 'https://mail.office365.com/',
127 'SMTP_SERVER' => 'smtp.office365.com',
128 'SMTP_PORT' => 587,
129 'SMTP_ENCRYPTION' => 'N',
130 'SMTP_LOGIN_AS_IMAP' => 'Y',
131 'SMTP_PASSWORD_AS_IMAP' => 'Y',
132 'UPLOAD_OUTGOING' => 'N',
133 ),
134 );
135
136 $mailServicesByLang = array(
137 'ru' => array(
138 100 => 'gmail',
139 200 => 'outlook.com',
140 300 => 'icloud',
141 400 => 'office365',
142 550 => 'exchangeOnline',
143 600 => 'yahoo',
144 700 => 'aol',
145 800 => 'yandex',
146 900 => 'mail.ru',
147 1000 => 'other',
148 ),
149 'ua' => array(
150 100 => 'gmail',
151 200 => 'outlook.com',
152 300 => 'icloud',
153 400 => 'office365',
154 550 => 'exchangeOnline',
155 600 => 'yahoo',
156 700 => 'aol',
157 800 => 'other',
158 ),
159 'en' => array(
160 100 => 'gmail',
161 200 => 'outlook.com',
162 300 => 'icloud',
163 400 => 'office365',
164 550 => 'exchangeOnline',
165 600 => 'yahoo',
166 700 => 'aol',
167 800 => 'other'
168 ),
169 'de' => array(
170 100 => 'gmail',
171 200 => 'outlook.com',
172 300 => 'icloud',
173 400 => 'office365',
174 550 => 'exchangeOnline',
175 600 => 'yahoo',
176 700 => 'aol',
177 800 => 'other'
178 )
179 );
180
181 $site = \Bitrix\Main\SiteTable::getList(array('filter' => ["=LID" => $siteId]))
182 ->fetch();
183
184 if (!$site)
185 return;
186
187 if (\CModule::IncludeModule('extranet') && \CExtranet::IsExtranetSite($site['LID']))
188 return;
189
190 $portalZone = \Bitrix\Main\Loader::includeModule('bitrix24')
191 ? \CBitrix24::getPortalZone()
192 : $site['LANGUAGE_ID']
193 ;
194
195 $portalZone = $portalZone ?: LANGUAGE_ID;
196 $portalZone = !in_array($portalZone, ['ru', 'kz', 'by']) ? $portalZone : 'ru';
197
198 $mailServicesList = isset($mailServicesByLang[$portalZone])
199 ? $mailServicesByLang[$portalZone]
200 : $mailServicesByLang['en'];
201
202 foreach ($mailServicesList as $serviceSort => $serviceName)
203 {
204 $exists = \Bitrix\Mail\MailServicesTable::getRow([
205 'filter' => [
206 '=SITE_ID' => $site['LID'],
207 '=NAME' => $serviceName,
208 '=SERVICE_TYPE' => 'imap',
209 ]
210 ]);
211
212 if ($exists)
213 {
214 continue;
215 }
216
217 $serviceSettings = $mailServices[$serviceName];
218
219 $serviceSettings['SITE_ID'] = $site['LID'];
220 $serviceSettings['ACTIVE'] = 'Y';
221 $serviceSettings['SERVICE_TYPE'] = 'imap';
222 $serviceSettings['NAME'] = $serviceName;
223 $serviceSettings['SORT'] = $serviceSort;
224
225 \Bitrix\Mail\MailServicesTable::add($serviceSettings);
226 }
227 }
228
238 public static function checkInstallComplete($siteId)
239 {
240 $version = (int)Option::get(self::MODULE_NAME, self::OPTION_NAME, 0, $siteId);
241
242 if ($version === self::SERVICES_VERSION)
243 {
244 return;
245 }
246 Option::set(self::MODULE_NAME, self::OPTION_NAME, self::SERVICES_VERSION, $siteId);
247
248 self::installServices($siteId);
249 }
250}