* @global array $iblockElementInfo
 */

if(!defined("B_PROLOG_INCLUDED") || B_PROLOG_INCLUDED!==true) die();

global $APPLICATION;

use Bitrix\Main;
use Bitrix\Main\Text\Converter;
use Bitrix\Main\Localization\Loc;
use Bitrix\Seo\Engine;
use Bitrix\Seo\Adv;

Loc::loadMessages(dirname(__FILE__).'/../seo_adv.php');

$engine = new Engine\YandexDirect();
$bNeedAuth = !$engine->getAuthSettings();

try
{
	$currentUser = $engine->getCurrentUser();
}
catch(Exception $e)
{
	$currentUser = null;
	$bNeedAuth = true;
}

if($bNeedAuth)
{
	if(!defined('BX_PUBLIC_MODE') || !BX_PUBLIC_MODE)
 * @global CDatabase $DB
 * @global CUserTypeManager $USER_FIELD_MANAGER
 * @global CCacheManager $CACHE_MANAGER
 * @global array $iblockElementInfo
 */
if (!defined("B_PROLOG_INCLUDED") || B_PROLOG_INCLUDED !== true) {
    die;
}
global $APPLICATION;
use Bitrix\Main;
use Bitrix\Main\Text\Converter;
use Bitrix\Main\Localization\Loc;
use Bitrix\Seo\Engine;
use Bitrix\Seo\Adv;
Loc::loadMessages(dirname(__FILE__) . '/../seo_adv.php');
$engine = new Engine\YandexDirect();
$currentUser = $engine->getCurrentUser();
$bNeedAuth = !is_array($currentUser);
if ($bNeedAuth) {
    if (!defined('BX_PUBLIC_MODE') || !BX_PUBLIC_MODE) {
        $message = new CAdminMessage(array("TYPE" => "OK", "DETAILS" => Loc::getMessage("SEO_ERROR_NO_YANDEX_AUTH", array("#LANGUAGE_ID#" => LANGUAGE_ID)), "HTML" => true));
        echo $message->Show();
    } else {
        echo BeginNote() . Loc::getMessage("SEO_ERROR_NO_YANDEX_AUTH", array("#LANGUAGE_ID#" => LANGUAGE_ID)) . EndNote();
    }
    return;
}
$request = Main\Context::getCurrent()->getRequest();
$dbRes = Adv\YandexCampaignTable::getList(array("order" => array("NAME" => "asc"), "filter" => array('=ACTIVE' => Adv\YandexCampaignTable::ACTIVE, '=ENGINE_ID' => $engine->getId()), 'select' => array("ID", "NAME", "XML_ID", "OWNER_ID", "SETTINGS")));
$campaignList = array();
while ($campaign = $dbRes->fetch()) {
Beispiel #3
0
			if(
				(
					method_exists($this, "IsSectionActive")
					&& $this->IsSectionActive("seo_search_adv_items")
				)
				|| (
					defined('BX_ADMIN_SEO_ADV_MENU_OPEN')
					&& BX_ADMIN_SEO_ADV_MENU_OPEN == 1
				)
			)
			{
				if(\Bitrix\Main\Loader::includeModule('seo'))
				{
					$yandexAdvCampaigns = array();

					$engine = new Engine\YandexDirect();

					$dbRes = Adv\YandexCampaignTable::getList(array(
						'order' => array('NAME' => 'ASC'),
						'filter' => array(
							'=ENGINE_ID' => $engine->getId(),
							'=ACTIVE' => Adv\YandexCampaignTable::ACTIVE
						),
						'select' => array('ID', 'NAME'),
					));

					while($campaign = $dbRes->fetch())
					{
						if(
						(
							method_exists($this, "IsSectionActive")
if(!Main\Loader::includeModule('seo'))
{
	require($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/main/include/prolog_admin_after.php");
	ShowError(Loc::getMessage("SEO_ERROR_NO_MODULE"));
	require($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/main/include/epilog_admin.php");
}

if(!Main\Loader::includeModule('socialservices'))
{
	require($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/main/include/prolog_admin_after.php");
	ShowError(Loc::getMessage("SEO_ERROR_NO_MODULE_SOCSERV"));
	require($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/main/include/epilog_admin.php");
}

$engine = new Engine\YandexDirect();

$bNeedAuth = !$engine->getAuthSettings();

try
{
	$currentUser = $engine->getCurrentUser();
}
catch(Exception $e)
{
	$currentUser = null;
	$bNeedAuth = true;
}

$bReadOnly = $bNeedAuth;
$bAllowSimpleActions = !$bNeedAuth;
Beispiel #5
0
	/**
	 * Checks banner data before sending it to Yandex.
	 *
	 * $data array format:
	 *
	 * <ul>
	 * <li>ID
	 * <li>XML_ID
	 * <li>NAME
	 * <li>SETTINGS<ul>
	 *    <li>BannerID
	 *    <li>CampaignID *
	 *    <li>Title *
	 *    <li>Text *
	 *    <li>Href *
	 *    <li>Geo - comma-separated list of yandex location IDs
	 *    <li>Phrases *
	 *    <li>MinusKeywords
	 *  </ul>
	 * </ul>
	 *
	 * @param Engine\YandexDirect $engine Engine object.
	 * @param array $data Banner data.
	 * @param Entity\EventResult $result Event result object.
	 *
	 * @return array
	 * @see http://api.yandex.ru/direct/doc/reference/CreateOrUpdateBanner.xml
	 */
	protected static function createParam(Engine\YandexDirect $engine, array $data, Entity\EventResult $result)
	{
		$bannerParam = array();

		$newBanner = true;

		if(!empty($data["XML_ID"]))
		{
			$newBanner = false;
			$bannerParam["BannerID"] = $data["XML_ID"];
		}

		if(!empty($data["CAMPAIGN_ID"]))
		{
			$dbRes = YandexCampaignTable::getByPrimary($data["CAMPAIGN_ID"]);
			$campaign = $dbRes->fetch();
			if($campaign)
			{
				$data['SETTINGS']['CampaignID'] = $campaign['XML_ID'];
			}
			else
			{
				$result->addError(new Entity\FieldError(
					static::getEntity()->getField('CAMPAIGN_ID'),
					Loc::getMessage('SEO_BANNER_ERROR_CAMPAIGN_NOT_FOUND')
				));
			}
		}

		if($newBanner || isset($data['SETTINGS']['CampaignID']))
		{
			$bannerParam['CampaignID'] = $data['SETTINGS']['CampaignID'];
		}

		if($newBanner || isset($data['SETTINGS']["Title"]))
		{
			$bannerParam["Title"] = trim($data['SETTINGS']["Title"]);

			if(strlen($bannerParam["Title"]) <= 0)
			{
				$result->addError(new Entity\FieldError(
					static::getEntity()->getField('NAME'),
					Loc::getMessage('SEO_BANNER_ERROR_NO_NAME')
				));
			}
			elseif(strlen($bannerParam["Title"]) > static::MAX_TITLE_LENGTH)
			{
				$result->addError(new Entity\FieldError(
					static::getEntity()->getField('NAME'),
					Loc::getMessage('SEO_BANNER_ERROR_LONG_NAME', array(
						"#MAX#" => static::MAX_TITLE_LENGTH,
					))
				));
			}
		}

		if($newBanner || isset($data['SETTINGS']["Text"]))
		{
			$bannerParam["Text"] = trim($data['SETTINGS']["Text"]);
			if(strlen($bannerParam["Text"]) <= 0)
			{
				$result->addError(new Entity\FieldError(
					static::getEntity()->getField('SETTINGS'),
					Loc::getMessage('SEO_BANNER_ERROR_NO_TEXT')
				));
			}
			elseif(strlen($bannerParam["Text"]) > static::MAX_TEXT_LENGTH)
			{
				$result->addError(new Entity\FieldError(
					static::getEntity()->getField('SETTINGS'),
					Loc::getMessage('SEO_BANNER_ERROR_LONG_TEXT', array(
						"#MAX#" => static::MAX_TEXT_LENGTH,
					))
				));
			}
		}

		if($newBanner || isset($data['SETTINGS']["Href"]))
		{
			$bannerParam["Href"] = trim($data['SETTINGS']["Href"]);
			if(strlen($bannerParam["Href"]) <= 0)
			{
				$result->addError(new Entity\FieldError(
					static::getEntity()->getField('SETTINGS'),
					Loc::getMessage('SEO_BANNER_ERROR_NO_HREF')
				));
			}
		}

		if($newBanner || isset($data["SETTINGS"]["Geo"]))
		{
			if(is_array($data["SETTINGS"]["Geo"]))
			{
				$data["SETTINGS"]["Geo"] = implode(",", $data["SETTINGS"]["Geo"]);
			}

			$bannerParam["Geo"] = $data["SETTINGS"]["Geo"];
		}

		if($newBanner || isset($data["SETTINGS"]["Phrases"]))
		{
			if(!is_array($data["SETTINGS"]["Phrases"]) || count($data["SETTINGS"]["Phrases"]) <= 0)
			{
				$result->addError(new Entity\FieldError(
					static::getEntity()->getField('SETTINGS'),
					Loc::getMessage('SEO_BANNER_ERROR_NO_PHRASES')
				));
			}
			else
			{
				$bannerParam["Phrases"] = $data["SETTINGS"]["Phrases"];

				foreach($bannerParam["Phrases"] as $key => $phraseInfo)
				{
					$phraseInfo['AutoBudgetPriority'] = static::$priorityList[intval($phraseInfo['AutoBudgetPriority'])];

					$bannerParam["Phrases"][$key] = $phraseInfo;
				}
			}
		}

		if($newBanner || isset($data["SETTINGS"]["MinusKeywords"]))
		{
			if(!is_array($data["SETTINGS"]["MinusKeywords"]))
			{
				if(strlen($data["SETTINGS"]["MinusKeywords"]) > 0)
				{
					$data["SETTINGS"]["MinusKeywords"] = array();
				}
				else
				{
					$data["SETTINGS"]["MinusKeywords"] = array($data["SETTINGS"]["MinusKeywords"]);
				}
			}

			$bannerParam["MinusKeywords"] = $data["SETTINGS"]["MinusKeywords"];
		}

		if(!$newBanner && $result->getType() == Entity\EventResult::SUCCESS)
		{
			try
			{
				$yandexBannerParam = $engine->getBanners(array($data["XML_ID"]));

				if(!is_array($yandexBannerParam) || count($yandexBannerParam) <= 0)
				{
					$result->addError(new Entity\FieldError(
						static::getEntity()->getField('XML_ID'),
						Loc::getMessage(
							'SEO_CAMPAIGN_ERROR_BANNER_NOT_FOUND',
							array('#ID#' => $data["XML_ID"])
						)
					));
				}
				else
				{
					$bannerParam = array_replace_recursive($yandexBannerParam[0], $bannerParam);
				}
			}
			catch(Engine\YandexDirectException $e)
			{
				$result->addError(
					new Entity\FieldError(
						static::getEntity()->getField('ENGINE_ID'),
						$e->getMessage(),
						$e->getCode()
					)
				);
			}
		}

		return $bannerParam;
	}
Loc::loadMessages(dirname(__FILE__) . '/seo_search.php');
Loc::loadMessages(dirname(__FILE__) . '/seo_adv.php');
if (!$USER->CanDoOperation('seo_tools')) {
    $APPLICATION->AuthForm(Loc::getMessage("ACCESS_DENIED"));
}
if (!Main\Loader::includeModule('seo')) {
    require $_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/main/include/prolog_admin_after.php";
    ShowError(Loc::getMessage("SEO_ERROR_NO_MODULE"));
    require $_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/main/include/epilog_admin.php";
}
if (!Main\Loader::includeModule('socialservices')) {
    require $_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/main/include/prolog_admin_after.php";
    ShowError(Loc::getMessage("SEO_ERROR_NO_MODULE_SOCSERV"));
    require $_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/main/include/epilog_admin.php";
}
$engine = new Engine\YandexDirect();
$currentUser = $engine->getCurrentUser();
$bNeedAuth = !is_array($currentUser);
$bReadOnly = $bNeedAuth;
$bAllowSimpleActions = !$bNeedAuth;
$message = null;
$request = Main\Context::getCurrent()->getRequest();
$campaignId = intval($request["campaign"]);
$archive = isset($request['archive']) && $request['archive'] == 1;
$campaign = false;
if ($campaignId > 0) {
    $dbRes = Adv\YandexCampaignTable::getByPrimary($campaignId);
    $campaign = $dbRes->fetch();
}
if (!$campaign) {
    require $_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/main/include/prolog_admin_after.php";
Loc::loadMessages(dirname(__FILE__) . '/seo_search.php');
Loc::loadMessages(dirname(__FILE__) . '/seo_adv.php');
if (!$USER->CanDoOperation('seo_tools')) {
    $APPLICATION->AuthForm(Loc::getMessage("ACCESS_DENIED"));
}
if (!Main\Loader::includeModule('seo')) {
    require $_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/main/include/prolog_admin_after.php";
    ShowError(Loc::getMessage("SEO_ERROR_NO_MODULE"));
    require $_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/main/include/epilog_admin.php";
}
if (!Main\Loader::includeModule('socialservices')) {
    require $_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/main/include/prolog_admin_after.php";
    ShowError(Loc::getMessage("SEO_ERROR_NO_MODULE_SOCSERV"));
    require $_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/main/include/epilog_admin.php";
}
$engine = new Engine\YandexDirect();
$currentUser = $engine->getCurrentUser();
$bNeedAuth = !is_array($currentUser);
$bReadOnly = $bNeedAuth;
$bAllowUpdate = !$bNeedAuth;
$bSale = Main\ModuleManager::isModuleInstalled('sale') && Main\ModuleManager::isModuleInstalled('catalog') && Main\Loader::includeModule('currency');
$request = Main\Context::getCurrent()->getRequest();
$back_url = isset($request["back_url"]) ? $request["back_url"] : '';
$campaignId = intval($request["campaign"]);
$elementId = intval($request["element"]);
$ID = intval($request["ID"]);
$message = null;
if ($ID > 0) {
    $dbRes = Adv\YandexBannerTable::getByPrimary($ID);
    $banner = $dbRes->fetch();
    if ($banner) {
if(!Main\Loader::includeModule('seo'))
{
	require($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/main/include/prolog_admin_after.php");
	ShowError(Loc::getMessage("SEO_ERROR_NO_MODULE"));
	require($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/main/include/epilog_admin.php");
}

if(!Main\Loader::includeModule('socialservices'))
{
	require($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/main/include/prolog_admin_after.php");
	ShowError(Loc::getMessage("SEO_ERROR_NO_MODULE_SOCSERV"));
	require($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/main/include/epilog_admin.php");
}

$engine = new Engine\YandexDirect();
$bNeedAuth = !$engine->getAuthSettings();

try
{
	$currentUser = $engine->getCurrentUser();
}
catch(Exception $e)
{
	$currentUser = null;
	$bNeedAuth = true;
}

$request = Main\Context::getCurrent()->getRequest();

$archive = isset($request['archive']) && $request['archive'] == 1;
Beispiel #9
0
 protected function processStatsResult($campaignId, array $result, YandexDirect $liveEngine)
 {
     if ($result['Stat']) {
         $bannerIds = array();
         foreach ($result['Stat'] as $statEntry) {
             $bannerIds[] = $statEntry['BannerID'];
         }
         if (count($bannerIds) > 0) {
             $dbRes = YandexBannerTable::getList(array('filter' => array('=XML_ID' => array_values(array_unique($bannerIds)), '=ENGINE_ID' => $liveEngine->getId()), 'select' => array('ID', 'XML_ID')));
             $bannerList = array();
             while ($bannerData = $dbRes->fetch()) {
                 $bannerList[$bannerData['XML_ID']] = $bannerData['ID'];
             }
             if (count($bannerList) > 0) {
                 foreach ($result['Stat'] as $statEntry) {
                     if (array_key_exists($statEntry['BannerID'], $bannerList)) {
                         $statFields = array('CAMPAIGN_ID' => $campaignId, 'BANNER_ID' => $bannerList[$statEntry['BannerID']], 'DATE_DAY' => new Date($statEntry['StatDate'], 'Y-m-d'), 'CURRENCY' => $result['Currency'], 'SUM' => $statEntry['Sum'], 'SUM_SEARCH' => $statEntry['SumSearch'], 'SUM_CONTEXT' => $statEntry['SumContext'], 'CLICKS' => $statEntry['Clicks'], 'CLICKS_SEARCH' => $statEntry['ClicksSearch'], 'CLICKS_CONTEXT' => $statEntry['ClicksContext'], 'SHOWS' => $statEntry['Shows'], 'SHOWS_SEARCH' => $statEntry['ShowsSearch'], 'SHOWS_CONTEXT' => $statEntry['ShowsContext']);
                         $statCheckRes = static::getList(array('filter' => array('BANNER_ID' => $statFields['BANNER_ID'], 'DATE_DAY' => $statFields['DATE_DAY']), 'select' => array('ID')));
                         $statCheck = $statCheckRes->fetch();
                         if (!$statCheck) {
                             static::add($statFields);
                         }
                     }
                 }
             }
         }
     }
 }
Beispiel #10
0
 public static function checkQuantityAgent()
 {
     if (!IsModuleInstalled("catalog")) {
         return __CLASS__ . "::checkQuantityAgent();";
     }
     $dbRes = YandexBannerTable::getList(array('filter' => array(array('=AUTO_QUANTITY_ON' => YandexBannerTable::MARKED), array('=AUTO_QUANTITY_OFF' => YandexBannerTable::MARKED), 'LOGIC' => "OR"), 'select' => array('ID', 'XML_ID', 'CAMPAIGN_ID', 'CAMPAIGN_XML_ID' => 'CAMPAIGN.XML_ID', 'AUTO_QUANTITY_ON', 'AUTO_QUANTITY_OFF')));
     $engine = new YandexDirect();
     $bannersListToStop = array();
     $bannersListToResume = array();
     $bannersListToUnMarkStopped = array();
     $bannersListToUnMarkResumed = array();
     $bannersLogData = array();
     while ($banner = $dbRes->fetch()) {
         if ($banner["AUTO_QUANTITY_ON"] == YandexBannerTable::MARKED) {
             if (!isset($bannersListToResume[$banner["CAMPAIGN_XML_ID"]])) {
                 $bannersListToResume[$banner["CAMPAIGN_XML_ID"]] = array();
             }
             $bannersListToResume[$banner["CAMPAIGN_XML_ID"]][$banner["ID"]] = $banner["XML_ID"];
             $causeCode = AutologTable::CODE_QUANTITY_ON;
             if ($banner["AUTO_QUANTITY_OFF"] == YandexBannerTable::MARKED) {
                 $bannersListToUnMarkStopped[] = $banner["ID"];
             }
         } else {
             if (!isset($bannersListToResume[$banner["CAMPAIGN_XML_ID"]])) {
                 $bannersListToStop[$banner["CAMPAIGN_XML_ID"]] = array();
             }
             $bannersListToStop[$banner["CAMPAIGN_XML_ID"]][$banner["ID"]] = $banner["XML_ID"];
             $causeCode = AutologTable::CODE_QUANTITY_OFF;
             if ($banner["AUTO_QUANTITY_ON"] == YandexBannerTable::MARKED) {
                 $bannersListToUnMarkResumed[] = $banner["ID"];
             }
         }
         $bannersLogData[$banner["ID"]] = array('CAMPAIGN_ID' => $banner['CAMPAIGN_ID'], 'CAMPAIGN_XML_ID' => $banner['CAMPAIGN_XML_ID'], 'BANNER_ID' => $banner['ID'], 'BANNER_XML_ID' => $banner['XML_ID'], 'CAUSE_CODE' => $causeCode);
     }
     if (count($bannersLogData) > 0) {
         foreach ($bannersListToResume as $campaignId => $bannersList) {
             if (count($bannersList) > 0) {
                 $success = true;
                 try {
                     $engine->resumeBanners($campaignId, array_values($bannersList));
                 } catch (YandexDirectException $e) {
                     $success = false;
                 }
                 foreach ($bannersList as $bannerId => $bannerXmlId) {
                     $logEntry = $bannersLogData[$bannerId];
                     $logEntry['ENGINE_ID'] = $engine->getId();
                     $logEntry['SUCCESS'] = $success ? AutologTable::SUCCESS : AutologTable::FAILURE;
                     AutologTable::add($logEntry);
                 }
                 $bannersListToUnMarkResumed = array_merge($bannersListToUnMarkResumed, array_keys($bannersList));
             }
         }
         foreach ($bannersListToStop as $campaignId => $bannersList) {
             if (count($bannersList) > 0) {
                 $success = true;
                 try {
                     $engine->stopBanners($campaignId, array_values($bannersList));
                 } catch (YandexDirectException $e) {
                     $success = false;
                 }
                 foreach ($bannersList as $bannerId => $bannerXmlId) {
                     $logEntry = $bannersLogData[$bannerId];
                     $logEntry['ENGINE_ID'] = $engine->getId();
                     $logEntry['SUCCESS'] = $success ? AutologTable::SUCCESS : AutologTable::FAILURE;
                     AutologTable::add($logEntry);
                 }
                 $bannersListToUnMarkStopped = array_merge($bannersListToUnMarkStopped, array_keys($bannersList));
             }
         }
         if (count($bannersListToUnMarkStopped) > 0) {
             YandexBannerTable::unMarkStopped($bannersListToUnMarkStopped);
         }
         if (count($bannersListToUnMarkResumed) > 0) {
             YandexBannerTable::unMarkResumed($bannersListToUnMarkResumed);
         }
     }
     return __CLASS__ . "::checkQuantityAgent();";
 }
Beispiel #11
0
use Bitrix\Main\Loader;
use Bitrix\Main\Localization\Loc;
use Bitrix\Seo\Engine;
use Bitrix\Seo\Adv;
use Bitrix\Main\Type\Date;
use Bitrix\Seo\Service;
Loader::includeModule('seo');
Loader::includeModule('socialservices');
CUtil::JSPostUnescape();
Loc::loadMessages(dirname(__FILE__) . '/../include.php');
Loc::loadMessages(dirname(__FILE__) . '/../admin/seo_adv.php');
$action = isset($_REQUEST['action']) ? $_REQUEST["action"] : null;
if ($action !== "register") {
    $bNeedAuth = !Service::isRegistered();
    if (!$bNeedAuth && $action != "authorize") {
        $engine = new Engine\YandexDirect();
        $bNeedAuth = !Service::isAuthorized($engine->getCode());
        $currentUser = null;
        if (!$bNeedAuth) {
            try {
                $currentAuth = Service::getAuth($engine->getCode());
                if ($currentAuth) {
                    $currentUser = $currentAuth["user"];
                    $bNeedAuth = false;
                }
            } catch (Exception $e) {
                $bNeedAuth = true;
            }
        }
    }
} else {
Beispiel #12
0
use Bitrix\Seo\Engine;
use Bitrix\Main\Localization\Loc;
if ($APPLICATION->GetGroupRight("seo") > "D") {
    if (\Bitrix\Main\ModuleManager::isModuleInstalled('seo')) {
        IncludeModuleLangFile(__FILE__);
        $bShowYandexServices = COption::GetOptionString('main', 'vendor', '') == '1c_bitrix' && Loc::getDefaultLang(LANGUAGE_ID) == 'ru';
        $aMenu = array(array("parent_menu" => "global_menu_marketing", "section" => "seo", "sort" => 900, "text" => Loc::getMessage("SEO_MENU_MAIN"), "title" => Loc::getMessage("SEO_MENU_MAIN_TITLE"), "icon" => "seo_menu_icon", "page_icon" => "seo_page_icon", "module_id" => "seo", "items_id" => "menu_seo", "items" => array()));
        $arEngineList = array();
        $arAdvList = array();
        if ($bShowYandexServices) {
            $arEngineList[] = array('url' => 'seo_search_yandex.php?lang=' . LANGUAGE_ID, 'more_url' => array('seo_search_yandex_detail.php?lang=' . LANGUAGE_ID), 'text' => Loc::getMessage("SEO_MENU_YANDEX"));
            $yandexAdvItem = array('url' => 'seo_search_yandex_direct.php?lang=' . LANGUAGE_ID, 'more_url' => array('seo_search_yandex_direct_edit.php?lang=' . LANGUAGE_ID, 'seo_search_yandex_direct_banner.php?lang=' . LANGUAGE_ID, 'seo_search_yandex_direct_banner_edit.php?lang=' . LANGUAGE_ID), 'text' => Loc::getMessage("SEO_MENU_YANDEX_DIRECT"), "module_id" => "seo", 'items_id' => "seo_search_adv_items", "dynamic" => true, 'items' => array());
            if (method_exists($this, "IsSectionActive") && $this->IsSectionActive("seo_search_adv_items") || defined('BX_ADMIN_SEO_ADV_MENU_OPEN') && BX_ADMIN_SEO_ADV_MENU_OPEN == 1) {
                if (\Bitrix\Main\Loader::includeModule('seo')) {
                    $yandexAdvCampaigns = array();
                    $engine = new Engine\YandexDirect();
                    $dbRes = Adv\YandexCampaignTable::getList(array('order' => array('NAME' => 'ASC'), 'filter' => array('=ENGINE_ID' => $engine->getId(), '=ACTIVE' => Adv\YandexCampaignTable::ACTIVE), 'select' => array('ID', 'NAME')));
                    while ($campaign = $dbRes->fetch()) {
                        if (method_exists($this, "IsSectionActive") && $this->IsSectionActive("seo_search_adv_items/" . $campaign['ID']) || $GLOBALS["APPLICATION"]->GetCurPage() == '/bitrix/admin/seo_search_yandex_direct_banner_edit.php' && $_REQUEST['campaign'] == $campaign['ID']) {
                            $yandexAdvCampaigns[$campaign['ID']] = count($yandexAdvItem['items']);
                        }
                        $yandexAdvItem['items'][] = array('url' => 'seo_search_yandex_direct_edit.php?lang=' . LANGUAGE_ID . '&ID=' . $campaign['ID'], 'more_url' => array('seo_search_yandex_direct_banner.php?lang=' . LANGUAGE_ID . '&campaign=' . $campaign['ID'], 'seo_search_yandex_direct_banner_edit.php?lang=' . LANGUAGE_ID . '&campaign=' . $campaign['ID']), 'text' => $campaign['NAME'], 'module_id' => 'seo', 'dynamic' => true, 'items_id' => "seo_search_adv_items/" . $campaign['ID'], 'items' => array());
                    }
                    if (count($yandexAdvCampaigns) > 0) {
                        $dbRes = Adv\YandexBannerTable::getList(array('order' => array('NAME' => 'ASC'), 'filter' => array('=ENGINE_ID' => $engine->getId(), '=CAMPAIGN_ID' => array_keys($yandexAdvCampaigns), '=ACTIVE' => Adv\YandexBannerTable::ACTIVE), 'select' => array('ID', 'CAMPAIGN_ID', 'NAME')));
                        while ($banner = $dbRes->fetch()) {
                            $yandexAdvItem['items'][$yandexAdvCampaigns[$banner['CAMPAIGN_ID']]]['items'][] = array('url' => 'seo_search_yandex_direct_banner_edit.php?lang=' . LANGUAGE_ID . '&campaign=' . $banner['CAMPAIGN_ID'] . '&ID=' . $banner['ID'], 'text' => $banner['NAME'], 'parent_menu' => "seo_search_adv_items/" . $banner['CAMPAIGN_ID'], 'items_id' => "seo_search_adv_items/" . $banner['CAMPAIGN_ID'] . "/" . $banner['ID']);
                        }
                    }
                }
            }
use Bitrix\Main\Loader;
use Bitrix\Main\Localization\Loc;
use Bitrix\Seo\Engine;
use Bitrix\Seo\Adv;
use Bitrix\Main\Type\Date;

Loader::includeModule('seo');
Loader::includeModule('socialservices');

CUtil::JSPostUnescape();

Loc::loadMessages(dirname(__FILE__).'/../include.php');
Loc::loadMessages(dirname(__FILE__).'/../admin/seo_adv.php');

$engine = new Engine\YandexDirect();
$bNeedAuth = !$engine->getAuthSettings();

try
{
	$currentUser = $engine->getCurrentUser();
}
catch(Exception $e)
{
	$currentUser = null;
	$bNeedAuth = true;
}

if(isset($_REQUEST['action']) && !$bNeedAuth)
{
	try
Loc::loadMessages(dirname(__FILE__) . '/seo_search.php');
Loc::loadMessages(dirname(__FILE__) . '/seo_adv.php');
if (!$USER->CanDoOperation('seo_tools')) {
    $APPLICATION->AuthForm(Loc::getMessage("ACCESS_DENIED"));
}
if (!Main\Loader::includeModule('seo')) {
    require $_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/main/include/prolog_admin_after.php";
    ShowError(Loc::getMessage("SEO_ERROR_NO_MODULE"));
    require $_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/main/include/epilog_admin.php";
}
if (!Main\Loader::includeModule('socialservices')) {
    require $_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/main/include/prolog_admin_after.php";
    ShowError(Loc::getMessage("SEO_ERROR_NO_MODULE_SOCSERV"));
    require $_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/main/include/epilog_admin.php";
}
$engine = new Engine\YandexDirect();
$currentUser = $engine->getCurrentUser();
$bNeedAuth = !is_array($currentUser);
$request = Main\Context::getCurrent()->getRequest();
$archive = isset($request['archive']) && $request['archive'] == 1;
$tableID = "tbl_yandex_direct_campaign";
$oSort = new \CAdminSorting($tableID, "ID", "desc");
$adminList = new \CAdminList($tableID, $oSort);
if (!$bNeedAuth && ($campaignIDs = $adminList->GroupAction())) {
    // we have no group actions here
    $campaignId = intval($campaignIDs[0]);
    if ($campaignId > 0) {
        if ($_REQUEST['action'] == 'delete') {
            try {
                $result = Adv\YandexCampaignTable::delete($campaignId);
                if (!$result->isSuccess()) {
Beispiel #15
0
 /**
  * Checks campaign data before sending it to Yandex
  *
  * $data array format:
  *
  * <ul>
  * <li>ID
  * <li>XML_ID
  * <li>NAME
  * <li>SETTINGS<ul>
  *    <li>FIO
  *    <li>StartDate
  *    <li>Strategy<ul>
  *        <li>StrategyName
  *        <li>MaxPrice
  *        <li>AveragePrice
  *        <li>WeeklySumLimit
  *        <li>ClicksPerWeek
  *    </ul>
  *    <li>EmailNotification<ul>
  *        <li>Email
  *        <li>WarnPlaceInterval
  *        <li>MoneyWarningValue
  *    </ul>
  *  </ul>
  * </ul>
  *
  * @param Engine\YandexDirect $engine Engine object.
  * @param array $data Campaign data.
  * @param Entity\EventResult $result Event result object.
  *
  * @return array
  * @see http://api.yandex.ru/direct/doc/reference/CreateOrUpdateCampaign.xml
  */
 protected static function createParam(Engine\YandexDirect $engine, array $data, Entity\EventResult $result)
 {
     $settings = $engine->getSettings();
     $campaignParam = array("Login" => $settings["AUTH_USER"]["login"]);
     $newCampaign = true;
     if (!empty($data["XML_ID"])) {
         $newCampaign = false;
         $campaignParam["CampaignID"] = $data["XML_ID"];
     }
     if ($newCampaign || isset($data['SETTINGS']["Name"])) {
         $campaignParam["Name"] = trim($data['SETTINGS']["Name"]);
         if (strlen($campaignParam["Name"]) <= 0) {
             $result->addError(new Entity\FieldError(static::getEntity()->getField('NAME'), Loc::getMessage('SEO_CAMPAIGN_ERROR_NO_NAME')));
         }
     }
     if ($newCampaign || isset($data["SETTINGS"]["FIO"])) {
         $campaignParam["FIO"] = trim($data["SETTINGS"]["FIO"]);
         if (strlen($campaignParam["FIO"]) <= 0) {
             $result->addError(new Entity\FieldError(static::getEntity()->getField('SETTINGS'), Loc::getMessage('SEO_CAMPAIGN_ERROR_NO_FIO')));
         }
     }
     if (is_array($data["SETTINGS"]) && array_key_exists("StartDate", $data["SETTINGS"])) {
         if (is_a($data["SETTINGS"]["StartDate"], "Bitrix\\Main\\Type\\Date")) {
             $campaignParam["StartDate"] = $data["SETTINGS"]["StartDate"]->convertFormatToPhp("Y-m-d");
         } elseif (is_string($data["SETTINGS"]["StartDate"])) {
             if (preg_match("/^\\d{4}-\\d{2}-\\d{2}\$/", $data["SETTINGS"]["StartDate"])) {
                 $campaignParam["StartDate"] = $data["SETTINGS"]["StartDate"];
             } else {
                 $ts = MakeTimeStamp($data["SETTINGS"]["StartDate"], FORMAT_DATE);
                 if ($ts > 0) {
                     $campaignParam["StartDate"] = date('Y-m-d', $ts);
                 }
             }
         }
         if (!$campaignParam["StartDate"]) {
             $result->addError(new Entity\FieldError(static::getEntity()->getField('SETTINGS'), Loc::getMessage('SEO_CAMPAIGN_ERROR_NO_START_DATE')));
         }
     }
     if ($newCampaign || isset($data["SETTINGS"]["Strategy"])) {
         if (empty($data["SETTINGS"]["Strategy"]) || !is_array($data["SETTINGS"]["Strategy"]) || empty($data["SETTINGS"]["Strategy"]["StrategyName"])) {
             $result->addError(new Entity\FieldError(static::getEntity()->getField('SETTINGS'), Loc::getMessage('SEO_CAMPAIGN_ERROR_NO_STRATEGY')));
         }
         if (array_key_exists($data["SETTINGS"]["Strategy"]["StrategyName"], self::$strategyConfig)) {
             $strategy = $data["SETTINGS"]["Strategy"]["StrategyName"];
             $config = self::$strategyConfig[$strategy];
             $campaignParam["Strategy"] = array("StrategyName" => $strategy);
             foreach ($data["SETTINGS"]["Strategy"] as $param => $value) {
                 if ($param !== "StrategyName") {
                     if (array_key_exists($param, $config)) {
                         $campaignParam["Strategy"][$param] = $value;
                     } else {
                         $result->addError(new Entity\FieldError(static::getEntity()->getField('SETTINGS'), Loc::getMessage('SEO_CAMPAIGN_ERROR_STRATEGY_PARAM_NOT_SUPPORTED', array('#PARAM#' => $param, '#STRATEGY#' => $strategy))));
                     }
                 }
             }
             foreach ($config as $key => $def) {
                 if ($def['mandatory'] || isset($campaignParam["Strategy"][$key])) {
                     switch ($def['type']) {
                         case 'int':
                             $campaignParam["Strategy"][$key] = intval($campaignParam["Strategy"][$key]);
                             break;
                         case 'float':
                             $campaignParam["Strategy"][$key] = doubleval($campaignParam["Strategy"][$key]);
                             break;
                     }
                     if (!$def['mandatory'] && empty($campaignParam["Strategy"][$key])) {
                         unset($campaignParam["Strategy"][$key]);
                     }
                 }
                 if ($def['mandatory'] && empty($campaignParam["Strategy"][$key])) {
                     $result->addError(new Entity\FieldError(static::getEntity()->getField('SETTINGS'), Loc::getMessage('SEO_CAMPAIGN_ERROR_STRATEGY_PARAM_MANDATORY', array('#PARAM#' => Loc::getMessage('SEO_CAMPAIGN_STRATEGY_PARAM_' . ToUpper($key)), '#STRATEGY#' => Loc::getMessage('SEO_CAMPAIGN_STRATEGY_' . $strategy)))));
                 }
             }
         } else {
             $result->addError(new Entity\FieldError(static::getEntity()->getField('SETTINGS'), Loc::getMessage('SEO_CAMPAIGN_ERROR_STRATEGY_NOT_SUPPORTED', array('#STRATEGY#' => $data["SETTINGS"]["Strategy"]["StrategyName"]))));
         }
     }
     if ($newCampaign || !empty($data["SETTINGS"]["EmailNotification"])) {
         if (empty($data["SETTINGS"]["EmailNotification"]) || !is_array($data["SETTINGS"]["EmailNotification"]) || !check_email($data["SETTINGS"]["EmailNotification"]['Email'])) {
             $result->addError(new Entity\FieldError(static::getEntity()->getField('SETTINGS'), Loc::getMessage('SEO_CAMPAIGN_ERROR_WRONG_EMAIL')));
         }
         $campaignParam["EmailNotification"] = array("Email" => trim($data["SETTINGS"]["EmailNotification"]['Email']), "WarnPlaceInterval" => intval($data["SETTINGS"]["EmailNotification"]['WarnPlaceInterval']), "MoneyWarningValue" => intval($data["SETTINGS"]["EmailNotification"]['MoneyWarningValue']), "SendWarn" => intval($data["SETTINGS"]["EmailNotification"]['SendWarn']));
         if ($campaignParam["EmailNotification"]['SendWarn'] === true || $campaignParam["EmailNotification"]['SendWarn'] === 1 || $campaignParam["EmailNotification"]['SendWarn'] === 'Y') {
             $campaignParam["EmailNotification"]['SendWarn'] = Engine\YandexDirect::BOOL_YES;
         }
         if ($campaignParam["EmailNotification"]['SendWarn'] === false || $campaignParam["EmailNotification"]['SendWarn'] === 0 || $campaignParam["EmailNotification"]['SendWarn'] === 'N') {
             $campaignParam["EmailNotification"]['SendWarn'] = Engine\YandexDirect::BOOL_NO;
         }
         if (!in_array($campaignParam["EmailNotification"]["WarnPlaceInterval"], self::$allowedWarnPlaceIntervalValues)) {
             if ($campaignParam["EmailNotification"]['SendWarn'] == Engine\YandexDirect::BOOL_YES) {
                 $result->addError(new Entity\FieldError(static::getEntity()->getField('SETTINGS'), Loc::getMessage('SEO_CAMPAIGN_ERROR_WRONG_INTERVAL', array('#VALUES#' => implode(',', self::$allowedWarnPlaceIntervalValues)))));
             } else {
                 $campaignParam["EmailNotification"]["WarnPlaceInterval"] = self::MONEY_WARN_PLACE_INTERVAL_DEFAULT;
             }
         }
         if ($campaignParam["EmailNotification"]["MoneyWarningValue"] < self::$allowedMoneyWarningInterval[0] || $campaignParam["EmailNotification"]["MoneyWarningValue"] > self::$allowedMoneyWarningInterval[1]) {
             $result->addError(new Entity\FieldError(static::getEntity()->getField('SETTINGS'), Loc::getMessage('SEO_CAMPAIGN_ERROR_WRONG_WARNING', array('#MIN#' => self::$allowedMoneyWarningInterval[0], '#MAX#' => self::$allowedMoneyWarningInterval[1]))));
         }
     }
     if ($newCampaign || isset($data["SETTINGS"]["MinusKeywords"])) {
         if (!is_array($data["SETTINGS"]["MinusKeywords"])) {
             if (strlen($data["SETTINGS"]["MinusKeywords"]) > 0) {
                 $data["SETTINGS"]["MinusKeywords"] = array();
             } else {
                 $data["SETTINGS"]["MinusKeywords"] = array($data["SETTINGS"]["MinusKeywords"]);
             }
         }
         $campaignParam["MinusKeywords"] = $data["SETTINGS"]["MinusKeywords"];
     }
     if (!$newCampaign && $result->getType() == Entity\EventResult::SUCCESS) {
         try {
             $yandexCampaignParam = $engine->getCampaign($data["XML_ID"]);
             if (!is_array($yandexCampaignParam) || count($yandexCampaignParam) <= 0) {
                 $result->addError(new Entity\FieldError(static::getEntity()->getField('XML_ID'), Loc::getMessage('SEO_CAMPAIGN_ERROR_CAMPAIGN_NOT_FOUND', array('#ID#' => $data["XML_ID"]))));
             } else {
                 $campaignParam = array_replace_recursive($yandexCampaignParam[0], $campaignParam);
             }
         } catch (Engine\YandexDirectException $e) {
             $result->addError(new Entity\FieldError(static::getEntity()->getField('ENGINE_ID'), $e->getMessage(), $e->getCode()));
         }
     }
     return $campaignParam;
 }
if(!Main\Loader::includeModule('seo'))
{
	require($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/main/include/prolog_admin_after.php");
	ShowError(Loc::getMessage("SEO_ERROR_NO_MODULE"));
	require($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/main/include/epilog_admin.php");
}

if(!Main\Loader::includeModule('socialservices'))
{
	require($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/main/include/prolog_admin_after.php");
	ShowError(Loc::getMessage("SEO_ERROR_NO_MODULE_SOCSERV"));
	require($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/main/include/epilog_admin.php");
}

$engine = new Engine\YandexDirect();

$bNeedAuth = !$engine->getAuthSettings();

$message = null;

try
{
	$currentUser = $engine->getCurrentUser();
}
catch(Exception $e)
{
	$currentUser = null;
	$bNeedAuth = true;
}
use Bitrix\Seo\Engine;
use Bitrix\Seo\Adv;
use Bitrix\Seo\Service;
Loc::loadMessages(dirname(__FILE__) . '/../../main/tools.php');
Loc::loadMessages(dirname(__FILE__) . '/menu.php');
Loc::loadMessages(dirname(__FILE__) . '/seo_search.php');
Loc::loadMessages(dirname(__FILE__) . '/seo_adv.php');
if (!$USER->CanDoOperation('seo_tools')) {
    $APPLICATION->AuthForm(Loc::getMessage("ACCESS_DENIED"));
}
if (!Main\Loader::includeModule('seo')) {
    require $_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/main/include/prolog_admin_after.php";
    ShowError(Loc::getMessage("SEO_ERROR_NO_MODULE"));
    require $_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/main/include/epilog_admin.php";
}
$engine = new Engine\YandexDirect();
$tableID = "tbl_yandex_direct_auto_log";
$oSort = new \CAdminSorting($tableID, "ID", "desc");
$adminList = new \CAdminList($tableID, $oSort);
$arHeaders = array(array("id" => "ID", "content" => "ID", "sort" => "ID", "default" => true), array("id" => "TIMESTAMP_X", "content" => Loc::getMessage('SEO_AUTOLOG_TIMESTAMP_X'), "sort" => "TIMESTAMP_X", "default" => true), array("id" => "SUCCESS", "content" => Loc::getMessage('SEO_AUTOLOG_SUCCESS'), "sort" => "SUCCESS", "default" => true), array("id" => "CAMPAIGN", "content" => Loc::getMessage('SEO_AUTOLOG_CAMPAIGN'), "default" => true), array("id" => "BANNER", "content" => Loc::getMessage('SEO_AUTOLOG_BANNER'), "default" => true), array("id" => "DESCRIPTION", "content" => Loc::getMessage('SEO_AUTOLOG_DESCRIPTION'), "default" => true));
$adminList->AddHeaders($arHeaders);
$logEntriesList = Adv\AutologTable::getList(array('order' => array($by => $order), 'filter' => array('=ENGINE_ID' => $engine->getId())));
$data = new \CAdminResult($logEntriesList, $tableID);
$data->NavStart();
$adminList->NavText($data->GetNavPrint(Loc::getMessage("PAGES")));
while ($entry = $data->NavNext()) {
    $editUrl = "seo_search_yandex_direct_banner_edit.php?lang=" . LANGUAGE_ID . "&campaign=" . $entry["CAMPAIGN_ID"] . "&ID=" . $entry["BANNER_ID"];
    $row =& $adminList->AddRow($log["ID"], $entry, $editUrl, Loc::getMessage("SEO_BANNER_EDIT_TITLE", array("#ID#" => $entry["BANNER_ID"], "#XML_ID#" => $entry["BANNER_XML_ID"])));
    $row->AddViewField("ID", $entry['ID']);
    $row->AddViewField('TIMESTAMP_X', $entry['TIMESTAMP_X']);
    $row->AddViewField('SUCCESS', $entry["SUCCESS"] == Adv\AutologTable::SUCCESS ? '<div style="white-space:nowrap;"><div class="lamp-green" style="display:inline-block;"></div>&nbsp;' . Loc::getMessage("SEO_AUTOLOG_SUCCESS_" . $entry["SUCCESS"]) . '</div>' : '<div style="white-space:nowrap;"><div class="lamp-red" style="display:inline-block;"></div>&nbsp;' . Loc::getMessage("SEO_AUTOLOG_SUCCESS_" . $entry["SUCCESS"]) . '</div>');