8namespace Bitrix\Seo\Engine;
10use Bitrix\Main\ArgumentNullException;
11use Bitrix\Main\Application;
12use Bitrix\Main\Entity\ExpressionField;
13use Bitrix\Main\SystemException;
14use Bitrix\Main\Type\DateTime;
15use Bitrix\Main\Web\HttpClient;
16use Bitrix\Seo\Adv\LogTable;
17use Bitrix\Seo\Adv\YandexBannerTable;
18use Bitrix\Seo\Adv\YandexCampaignTable;
20use Bitrix\Seo\IEngine;
21use Bitrix\Seo\Service;
24if (!defined(
'YANDEX_DIRECT_API_URL'))
26 define(
'YANDEX_DIRECT_API_URL',
'https://api.direct.yandex.ru/v4/json/');
102 $this->locale = in_array(LANGUAGE_ID,
array(
"ru",
"en",
"ua")) ? LANGUAGE_ID :
'en';
104 parent::__construct();
113 return $currentAuth[
'user'];
133 $result = $this->
getProxy()?->getInterface()?->addCampaign(static::ENGINE_ID, $campaignParam);
156 $result = $this->
getProxy()?->getInterface()?->updateCampaign(static::ENGINE_ID, $campaignParam);
178 if (empty($campaignsId))
183 if (!is_array($campaignsId))
185 $campaignsId =
array($campaignsId);
192 while ($offset <
count($campaignsId))
194 $currentCampaigns = array_slice($campaignsId, $offset, static::CAMPAIGN_LIMIT);
196 $currentResult = $this->
getProxy()?->getInterface()?->getCampaign(static::ENGINE_ID, $currentCampaigns);
197 $currentResult = $currentResult ?? [];
199 if (!empty($currentResult[
'error']))
206 $offset += static::CAMPAIGN_LIMIT;
215 $result = $this->
getProxy()?->getInterface()?->getCampaignList(static::ENGINE_ID);
228 if (empty($campaignId))
233 $result = $this->
getProxy()?->getInterface()?->archiveCampaign(static::ENGINE_ID, $campaignId);
246 if (empty($campaignId))
251 $result = $this->
getProxy()?->getInterface()?->unArchiveCampaign(static::ENGINE_ID, $campaignId);
264 if (empty($campaignId))
269 $result = $this->
getProxy()?->getInterface()?->resumeCampaign(static::ENGINE_ID, $campaignId);
282 if (empty($campaignId))
287 $result = $this->
getProxy()?->getInterface()?->stopCampaign(static::ENGINE_ID, $campaignId);
300 if (empty($campaignId))
305 $result = $this->
getProxy()?->getInterface()?->deleteCampaign(static::ENGINE_ID, $campaignId);
328 $result = $this->
getProxy()?->getInterface()?->addBanner(static::ENGINE_ID, $bannerParam);
351 $result = $this->
getProxy()?->getInterface()?->updateBanner(static::ENGINE_ID, $bannerParam);
364 if (empty($bannerId))
369 if (!is_array($bannerId))
371 $bannerId =
array($bannerId);
375 'BannerIDS' => $bannerId,
389 if (empty($campaignId))
394 if (!is_array($campaignId))
396 $campaignId =
array($campaignId);
400 'CampaignIDS' => $campaignId,
414 if (empty($campaignId))
420 'CampaignID' => $campaignId,
421 'BannerIDS' => $bannerIDs,
424 $result = $this->
getProxy()?->getInterface()?->moderateBanners(static::ENGINE_ID, $queryData);
437 if (empty($campaignId))
443 'CampaignID' => $campaignId,
444 'BannerIDS' => $bannerIDs,
448 $result = $this->
getProxy()?->getInterface()?->stopBanners(static::ENGINE_ID, $queryData);
461 if (empty($campaignId))
467 'CampaignID' => $campaignId,
468 'BannerIDS' => $bannerIDs,
471 $result = $this->
getProxy()?->getInterface()?->resumeBanners(static::ENGINE_ID, $queryData);
484 if (empty($campaignId))
490 'CampaignID' => $campaignId,
491 'BannerIDS' => $bannerIDs,
494 $result = $this->
getProxy()?->getInterface()?->archiveBanners(static::ENGINE_ID, $queryData);
507 if (empty($campaignId))
513 'CampaignID' => $campaignId,
514 'BannerIDS' => $bannerIDs,
517 $result = $this->
getProxy()?->getInterface()?->unArchiveBanners(static::ENGINE_ID, $queryData);
530 if (empty($campaignId))
536 'CampaignID' => $campaignId,
537 'BannerIDS' => $bannerIDs,
540 $result = $this->
getProxy()?->getInterface()?->deleteBanners(static::ENGINE_ID, $queryData);
560 $result = $this->
getProxy()?->getInterface()?->getRegions(static::ENGINE_ID);
573 $cacheManager = Application::getInstance()->getManagedCache();
575 if ($cacheManager->read(self::CACHE_TTL, self::CACHE_ID))
577 $result = $cacheManager->get(self::CACHE_ID);
581 $result = $this->
getProxy()?->getInterface()?->getClientsSettings(static::ENGINE_ID);
596 $cacheManager->set(self::CACHE_ID,
$result);
605 'Phrases' => $phrase,
610 $queryData[
'GeoID'] = $geo;
613 $result = $this->
getProxy()?->getInterface()?->createWordstatReport(static::ENGINE_ID, $queryData);
626 $result = $this->
getProxy()?->getInterface()?->deleteWordstatReport(static::ENGINE_ID, $reportId);
639 $result = $this->
getProxy()?->getInterface()?->getWordstatReport(static::ENGINE_ID, $reportId);
652 $result = $this->
getProxy()?->getInterface()?->getWordstatReportList(static::ENGINE_ID);
666 'Phrases' => $phrase,
671 $queryData[
'GeoID'] = $geo;
674 $result = $this->
getProxy()?->getInterface()?->createForecastReport(static::ENGINE_ID, $queryData);
687 $result = $this->
getProxy()?->getInterface()?->deleteForecastReport(static::ENGINE_ID, $reportId);
700 $result = $this->
getProxy()?->getInterface()?->getForecastReport(static::ENGINE_ID, $reportId);
713 $result = $this->
getProxy()?->getInterface()?->getForecastReportList(static::ENGINE_ID);
759 protected function query($scope,
$method =
"GET", $param = NULL, $skipRefreshAuth =
false)
766 if ($this->engineSettings[
'AUTH'])
769 $http->setRedirect(
false);
770 $http->setHeader(
"Content-Type",
"application/json; charset=utf-8");
774 "locale" => $this->locale,
775 "token" => $this->engineSettings[
'AUTH'][
'access_token'],
785 $ts = microtime(
true);
789 'ENGINE_ID' => $this->
getId(),
790 'REQUEST_URI' => static::API_URL,
792 'RESPONSE_TIME' => microtime(
true) - $ts,
793 'RESPONSE_STATUS' => $http->getStatus(),
794 'RESPONSE_DATA' => $http->getResult(),
797 if ($http->getStatus() == 401 && !$skipRefreshAuth)
815 if ($this->engineSettings[
'AUTH'])
818 $http->setRedirect(
false);
819 $http->setHeader(
"Content-Type",
"application/json; charset=utf-8");
823 $financeToken = hash(
825 $masterToken . $operationNum .
$method .
$auth[
'login']);
829 "finance_token" => $financeToken,
830 "operation_num" => $operationNum,
831 "locale" => $this->locale,
832 "token" => $this->engineSettings[
'AUTH'][
'access_token'],
844 if ($http->getStatus() == 401 && !$skipRefreshAuth)
862 $newCampaigns =
array();
872 if (!is_array($campaignId) && $campaignId > 0)
874 $campaignId =
array($campaignId);
877 $campaignList =
array();
878 if (is_array($campaignId) &&
count($campaignId) > 0)
883 '=ID' => $campaignId,
884 '=ENGINE_ID' => $this->
getId(),
886 'select' =>
array(
'XML_ID'),
889 while ($campaign =
$dbRes->fetch())
891 $keys[] = $campaign[
'XML_ID'];
894 if (
count($keys) > 0)
903 $campaignListSorted =
array();
904 $campaignListToDelete =
array();
906 foreach ($campaignList as $campaignInfo)
908 $campaignListSorted[$campaignInfo[
'CampaignID']] = $campaignInfo;
913 if(is_array($campaignId) &&
count($campaignId) > 0 &&
count($campaignListSorted) > 0)
914 $filter[
'=XML_ID'] = array_keys($campaignListSorted);
915 $dbCampaigns = YandexCampaignTable::getList(
array(
'filter' =>
$filter));
919 while ($campaign = $dbCampaigns->fetch())
921 if (isset($campaignListSorted[$campaign[
'XML_ID']]))
923 $result = YandexCampaignTable::update(
924 $campaign[
'ID'],
array(
925 "SETTINGS" => $campaignListSorted[$campaign[
'XML_ID']],
929 unset($campaignListSorted[$campaign[
'XML_ID']]);
943 $campaignListToDelete[$campaign[
'ID']] = $campaign[
'ID'];
948 if (
count($campaignListToDelete) > 0)
950 foreach ($campaignListToDelete as $campaignId)
952 $resultDelete = YandexCampaignTable::delete($campaignId);
959 foreach ($campaignListSorted as $campaignId => $campaignInfo)
962 "SETTINGS" => $campaignInfo,
967 $newCampaigns[] =
$result->getId();
977 if (
count($newCampaigns) > 0)
981 $res[
'new'] = $newCampaigns;
984 $cnt = ceil(
count($newCampaigns) / static::MAX_CAMPAIGNS_BANNER_UPDATE);
985 for (
$i = 0;
$i < $cnt;
$i++)
987 $res[
'banner'] = array_merge(
992 $i * static::MAX_CAMPAIGNS_BANNER_UPDATE,
993 static::MAX_CAMPAIGNS_BANNER_UPDATE
1011 if (!is_array($bannerId) && $bannerId > 0)
1013 $bannerId =
array($bannerId);
1016 $bannerList =
array();
1017 if (is_array($bannerId) &&
count($bannerId) > 0)
1023 '=ENGINE_ID' => $this->
getId(),
1025 'select' =>
array(
'XML_ID'),
1028 while ($banner =
$dbRes->fetch())
1030 $keys[] = $banner[
'XML_ID'];
1033 if(
count($keys) > 0)
1038 $dbCampaigns = YandexCampaignTable::getList(
array(
1040 '=ID' => $campaignId,
1041 '=ENGINE_ID' => $this->
getId(),
1043 'select' =>
array(
'ID',
'XML_ID'),
1046 while ($campaign = $dbCampaigns->fetch())
1048 $campaignIndex[$campaign[
'XML_ID']] = $campaign[
'ID'];
1052 if (
count($campaignIndex) > 0)
1056 $bannerListSorted =
array();
1057 $bannerListToDelete =
array();
1058 foreach ($bannerList as $bannerInfo)
1060 $bannerListSorted[$bannerInfo[
'BannerID']] = $bannerInfo;
1065 if(is_array($bannerId) &&
count($bannerId) > 0 &&
count($bannerListSorted) > 0)
1066 $filter[
'=XML_ID'] = array_keys($bannerListSorted);
1068 $filter[
'=CAMPAIGN_ID'] = $campaignId;
1069 $dbBanners = YandexBannerTable::getList(
array(
'filter' =>
$filter));
1071 YandexBannerTable::setSkipRemoteUpdate(
true);
1073 while ($banner = $dbBanners->fetch())
1075 if (isset($bannerListSorted[$banner[
'XML_ID']]))
1077 $result = YandexBannerTable::update(
1078 $banner[
'ID'],
array(
1079 "SETTINGS" => $bannerListSorted[$banner[
'XML_ID']],
1083 unset($bannerListSorted[$banner[
'XML_ID']]);
1097 $bannerListToDelete[$banner[
'ID']] = $banner[
'ID'];
1102 if (
count($bannerListToDelete) > 0)
1104 foreach ($bannerListToDelete as $bannerId)
1106 $resultDelete = YandexBannerTable::delete($bannerId);
1107 YandexBannerTable::setSkipRemoteUpdate(
true);
1112 foreach ($bannerListSorted as $bannerId => $bannerInfo)
1115 "CAMPAIGN_ID" => $campaignIndex[$bannerInfo[
'CampaignID']],
1116 "SETTINGS" => $bannerInfo,
1128 YandexBannerTable::setSkipRemoteUpdate(
false);
1142 return __CLASS__ .
"::updateAgent();";
1145 if (
$engine->getAuthSettings())
1152 '=ENGINE_ID' =>
$engine->getId(),
1154 'select' =>
array(
'CNT'),
1161 if (
$res[
'CNT'] > 0)
1163 $engine->updateCampaignManual();
1166 $availableCampaigns =
array();
1167 $campaignList =
$engine->getCampaignList();
1168 foreach ($campaignList as $campaignInfo)
1170 $availableCampaigns[] = $campaignInfo[
'CampaignID'];
1173 if (
count($availableCampaigns) > 0)
1176 'group' =>
array(
'CAMPAIGN_ID'),
1178 '<LAST_UPDATE' => DateTime::createFromTimestamp(time() - YandexBannerTable::CACHE_LIFETIME),
1179 '=ENGINE_ID' =>
$engine->getId(),
1180 '=CAMPAIGN.XML_ID' => $availableCampaigns,
1182 'select' =>
array(
'CAMPAIGN_ID'),
1185 $campaignId =
array();
1188 $campaignId[] =
$res[
'CAMPAIGN_ID'];
1191 if (
count($campaignId) > 0)
1193 $engine->updateBannersManual($campaignId);
1202 return __CLASS__ .
"::updateAgent();";
static setSkipRemoteUpdate($value)
const ERROR_WRONG_CURRENCY
const METHOD_FORECAST_REPORT_CREATE
const MAX_CAMPAIGNS_BANNER_UPDATE
updateBanner(array $bannerParam)
deleteCampaign($campaignId)
getForecastReport($reportId)
getCampaign($campaignsId)
const METHOD_CAMPAIGN_ARCHIVE
const METHOD_WORDSTAT_REPORT_CREATE
unArchiveCampaign($campaignId)
const METHOD_BANNER_MODERATE
resumeCampaign($campaignId)
createWordstatReport(array $phrase, $geo=NULL)
const METHOD_BANNER_UPDATE
const METHOD_CAMPAIGN_DELETE
const METHOD_WORDSTAT_REPORT_LIST
stopBanners($campaignId, array $bannerIDs)
updateCampaign(array $campaignParam)
const METHOD_FORECAST_REPORT_DELETE
addBanner(array $bannerParam)
addCampaign(array $campaignParam)
getCampaignBanners($campaignId)
const METHOD_FORECAST_REPORT_GET
const METHOD_CAMPAIGN_STOP
const METHOD_BANNER_UNARCHIVE
const METHOD_CAMPAIGN_LIST
updateCampaignManual($campaignId=NULL)
query($scope, $method="GET", $param=NULL, $skipRefreshAuth=false)
deleteForecastReport($reportId)
const METHOD_CAMPAIGN_ADD
createForecastReport(array $phrase, $geo=NULL)
const MAX_STAT_DAYS_DELTA
const METHOD_BANNER_DELETE
resumeBanners($campaignId, array $bannerIDs)
const METHOD_CAMPAIGN_RESUME
const METHOD_FORECAST_REPORT_LIST
const TTL_WORDSTAT_REPORT
archiveBanners($campaignId, array $bannerIDs)
moderateBanners($campaignId, array $bannerIDs)
const METHOD_BANNER_ARCHIVE
stopCampaign($campaignId)
const METHOD_CAMPAIGN_GET
const METHOD_CAMPAIGN_UNARCHIVE
unArchiveBanners($campaignId, array $bannerIDs)
deleteWordstatReport($reportId)
finance_query($method, $masterToken, $operationNum, $param=array(), $skipRefreshAuth=false)
const METHOD_CAMPAIGN_UPDATE
const TTL_FORECAST_REPORT
getWordstatReport($reportId)
getBannerStats(array $params)
updateBannersManual($campaignId, $bannerId=NULL)
const TTL_FORECAST_REPORT_EXT
const METHOD_WORDSTAT_REPORT_GET
deleteBanners($campaignId, array $bannerIDs)
const TTL_WORDSTAT_REPORT_EXT
const METHOD_WORDSTAT_REPORT_DELETE
const METHOD_BANNER_RESUME
archiveCampaign($campaignId)
const MAX_WORDSTAT_REPORTS
const MAX_FORECAST_REPORTS
static encode($data, $options=null)
static getAuth(string $engineCode)
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
</p ></td >< td valign=top style='border-top:none;border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;padding:0cm 2.0pt 0cm 2.0pt;height:9.0pt'>< p class=Normal align=center style='margin:0cm;margin-bottom:.0001pt;text-align:center;line-height:normal'>< a name=ТекстовоеПоле54 ></a ><?=($taxRate > count( $arTaxList) > 0) ? $taxRate."%"
if($inWords) echo htmlspecialcharsbx(Number2Word_Rus(roundEx($totalVatSum $params['CURRENCY']