Esempio n. 1
0
 public static function checkMailDomain($service_id, $user_id, $cnt = 1)
 {
     $service_id = intval($service_id);
     $user_id = intval($user_id);
     $cnt = intval($cnt);
     if (!CModule::includeModule('mail')) {
         return '';
     }
     $arAdmin = CUser::getList($by, $order, array('ID' => $user_id, 'GROUPS_ID' => 1, 'ACTIVE' => 'Y'), array('FIELDS' => array('ID', 'TIME_ZONE_OFFSET')))->fetch();
     if (empty($arAdmin)) {
         return '';
     }
     $service = \Bitrix\Mail\MailServicesTable::getList(array('filter' => array('=ID' => $service_id)))->fetch();
     if (empty($service) || $service['ACTIVE'] != 'Y' || !in_array($service['SERVICE_TYPE'], array('domain', 'crdomain'))) {
         return '';
     }
     if ($service['SERVICE_TYPE'] == 'domain') {
         $result = CMailDomain2::getDomainStatus($service['TOKEN'], $service['SERVER']);
         $stage = empty($result['stage']) ? null : $result['stage'];
     } else {
         $crResponse = CControllerClient::executeEvent('OnMailControllerCheckMemberDomain', array('DOMAIN' => $service['SERVER']));
         $stage = empty($crResponse['result']['stage']) ? null : $crResponse['result']['stage'];
     }
     if (!in_array($stage, array('none', 'owner-check', 'mx-check', 'added'))) {
         return false;
     } else {
         if (in_array($stage, array('none', 'added'))) {
             if ($stage == 'added') {
                 if (CModule::includeModule('im')) {
                     includeModuleLangFile(__FILE__);
                     $siteUrl = sprintf('http%s://%s%s', CMain::isHTTPS() ? 's' : '', $_SERVER['SERVER_NAME'], in_array($_SERVER['SERVER_PORT'], array(80, 443)) ? '' : ':' . $_SERVER['SERVER_PORT']);
                     CIMNotify::add(array('TO_USER_ID' => $user_id, 'FROM_USER_ID' => 0, 'NOTIFY_TYPE' => IM_NOTIFY_SYSTEM, 'NOTIFY_MODULE' => 'intranet', 'NOTIFY_MESSAGE' => str_replace(array('#DOMAIN#', '#SERVER#'), array(htmlspecialcharsbx($service['SERVER']), $siteUrl), getMessage('INTR_MAIL_DOMAINREADY_NOTICE'))));
                 }
                 $timeout = new DateTime(intval($arAdmin['TIME_ZONE_OFFSET']) . ' seconds +7 days');
                 if ($timeout->format('N') > 5) {
                     $timeout->modify('next monday');
                 }
                 CAgent::addAgent('CIntranetUtils::notifyMailDomain("nomailbox", ' . $service_id . ', ' . $user_id . ');', 'intranet', 'N', $timeout->getTimestamp() - intval($arAdmin['TIME_ZONE_OFFSET']) - time());
             }
             return '';
         } else {
             if ($cnt > 100) {
                 return '';
             }
             global $pPERIOD;
             $pPERIOD = $pPERIOD * $cnt;
             if ($pPERIOD > 3600 * 4) {
                 $pPERIOD = 3600 * 4;
             }
             return 'CIntranetUtils::checkMailDomain(' . $service_id . ', ' . $user_id . ', ' . ++$cnt . ');';
         }
     }
 }
Esempio n. 2
0
 /**
  * Gets host url with port and scheme.
  * @return string
  * @throws \Bitrix\Main\ArgumentNullException
  */
 public function getHostUrl()
 {
     $protocol = \CMain::isHTTPS() ? 'https' : 'http';
     if (defined("SITE_SERVER_NAME") && SITE_SERVER_NAME) {
         $host = SITE_SERVER_NAME;
     } else {
         $host = Option::get('main', 'server_name', Context::getCurrent()->getServer()->getHttpHost());
     }
     $port = Context::getCurrent()->getServer()->getServerPort();
     if ($port != 80 && $port != 443 && $port > 0 && strpos($host, ':') === false) {
         $host .= ':' . $port;
     } elseif ($protocol == 'http' && $port == 80) {
         $host = str_replace(':80', '', $host);
     } elseif ($protocol == 'https' && $port == 443) {
         $host = str_replace(':443', '', $host);
     }
     return $protocol . '://' . $host;
 }