Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
site24.php
1<?php
3
6
7class Site24
8{
18 public static function updateDomain($domain, $newName, $url)
19 {
20 return self::Execute('update', array('domain' => $domain, 'newname' => $newName, 'url' => $url));
21 }
22
32 public static function activateDomain($domain, $active = 'Y', $lang = '')
33 {
34 return self::Execute('activate', array('domain' => $domain, 'active' => $active, 'lang' => $lang));
35 }
36
48 public static function addDomain($domain, $url, $active = 'Y', $type = 'site', $lang = '')
49 {
50 return self::Execute('add', array('domain' => $domain, 'url' => $url, 'active' => $active, 'type' => $type, 'lang' => $lang));
51 }
52
65 public static function isDomainExists($domain)
66 {
67 return self::Execute('check', array('domain' => $domain));
68 }
69
79 public static function deleteDomain($domain)
80 {
81 return self::Execute('delete', array('domain' => $domain));
82 }
83
95 public static function addRandomDomain($url, $type = 'site', $lang = '')
96 {
97 return self::Execute('addrandom', array('url' => $url, 'type' => $type, 'lang' => $lang));
98 }
99
109 protected static function Execute($operation, $params = array())
110 {
111 $params['operation'] = $operation;
112
113 $license = Application::getInstance()->getLicense();
114 $params['key'] = $license->getPublicHashKey();
115 $params['keysign'] = $license->getHashLicenseKey();
116 $params['host']= \Bitrix\Main\Config\Option::get('intranet', 'portal_url', null);
117
118 if (!$params['host'])
119 {
120 $params['host']= \Bitrix\Main\Config\Option::get(
121 'landing',
122 'portal_url',
123 $_SERVER['HTTP_HOST']
124 );
125 }
126
127 if (!$params['host'])
128 {
129 $params['host'] = $_SERVER['HTTP_HOST'];
130 }
131
132 $params['host'] = trim($params['host']);
133
134 if (
135 mb_strpos($params['host'], 'http://') === 0 ||
136 mb_strpos($params['host'], 'https://') === 0
137 )
138 {
139 $parseHost = parse_url($params['host']);
140 if (isset($parseHost['host']))
141 {
142 $params['host'] = $parseHost['host'];
143 if (isset($parseHost['port']))
144 {
145 $params['host'] .= ':' . $parseHost['port'];
146 }
147 }
148 }
149
150 if (!isset($params['lang']) || !$params['lang'])
151 {
152 unset($params['lang']);
153 }
154
155 $httpClient = new \Bitrix\Main\Web\HttpClient(array(
156 'socketTimeout' => 5,
157 'streamTimeout' => 30
158 ));
159
160 $httpClient->setHeader('User-Agent', 'Bitrix24 Sites');
161 $answer = $httpClient->post('https://pub.bitrix24.site/pub.php', $params);
162
163 $result = '';
164 if ($answer && $httpClient->getStatus() == '200')
165 {
166 $result = $httpClient->getResult();
167 }
168
169 if ($result <> '')
170 {
171 try
172 {
173 $result = \Bitrix\Main\Web\Json::decode($result);
174 }
175 catch(\Bitrix\Main\ArgumentException $e)
176 {
177 throw new SystemException('Bad response');
178 }
179
180 if ($result['result'] === 'Bad license')
181 {
182 throw new SystemException('Bad license');
183 }
184
185 return $result['result'];
186 }
187
188 throw new SystemException('Bad response');
189 }
190}
static deleteDomain($domain)
Definition site24.php:79
static activateDomain($domain, $active='Y', $lang='')
Definition site24.php:32
static updateDomain($domain, $newName, $url)
Definition site24.php:18
static Execute($operation, $params=array())
Definition site24.php:109
static addDomain($domain, $url, $active='Y', $type='site', $lang='')
Definition site24.php:48
static isDomainExists($domain)
Definition site24.php:65
static addRandomDomain($url, $type='site', $lang='')
Definition site24.php:95