Exemplo n.º 1
0
        }
    }
}
$arHeaders = array(array("id" => "ID", "content" => Loc::getMessage("SEO_CAMPAIGN_ID"), "sort" => "ID", "default" => true), array("id" => "STATUS", "content" => Loc::getMessage('SEO_CAMPAIGN_STATUS'), "default" => true), array("id" => "NAME", "content" => Loc::getMessage('SEO_CAMPAIGN_NAME'), "sort" => "NAME", "default" => true), array("id" => "XML_ID", "content" => Loc::getMessage('SEO_CAMPAIGN_XML_ID'), "sort" => "XML_ID", "default" => true), array("id" => "STRATEGY", "content" => Loc::getMessage('SEO_CAMPAIGN_STRATEGY'), "default" => true), array("id" => "LAST_UPDATE", "content" => Loc::getMessage('SEO_CAMPAIGN_LAST_UPDATE'), "sort" => "LAST_UPDATE", "default" => true), array("id" => "BANNER_CNT", "content" => Loc::getMessage('SEO_CAMPAIGN_BANNER_CNT'), "default" => true), array("id" => "SHOW", "content" => Loc::getMessage('SEO_STATUS_SHOW'), "default" => true), array("id" => "SHOW", "content" => Loc::getMessage('SEO_STATUS_SHOW'), "default" => true), array("id" => "SUM", "content" => Loc::getMessage('SEO_CAMPAIGN_SUM'), "default" => true), array("id" => "REST", "content" => Loc::getMessage('SEO_CAMPAIGN_REST'), "default" => true), array("id" => "SHOWS", "content" => Loc::getMessage('SEO_CAMPAIGN_SHOWS'), "default" => true), array("id" => "CLICKS", "content" => Loc::getMessage('SEO_CAMPAIGN_CLICKS'), "default" => true));
if ($request["mode"] != 'excel') {
    $arHeaders[] = array("id" => "UPDATE", "content" => "", "default" => true);
}
$adminList->AddHeaders($arHeaders);
$campaignList = Adv\YandexCampaignTable::getList(array('order' => array($by => $order), 'filter' => array("=ENGINE_ID" => $engine->getId(), '=ACTIVE' => $archive ? Adv\YandexCampaignTable::INACTIVE : Adv\YandexCampaignTable::ACTIVE), "select" => array("ID", "BANNER_CNT"), 'runtime' => array(new Entity\ExpressionField('BANNER_CNT', 'COUNT(%s)', "\\Bitrix\\Seo\\Adv\\YandexBannerTable:CAMPAIGN.ID"))));
$data = new \CAdminResult($campaignList, $tableID);
$data->NavStart();
$adminList->NavText($data->GetNavPrint(Loc::getMessage("PAGES")));
$campaignAdminList = array();
while ($campaign = $data->NavNext()) {
    $bannerCnt = $campaign["BANNER_CNT"];
    $campaignDetail = Adv\YandexCampaignTable::getList(array('filter' => array("=ID" => $campaign["ID"])));
    $campaign = $campaignDetail->fetch();
    $editUrl = "seo_search_yandex_direct_edit.php?lang=" . LANGUAGE_ID . "&ID=" . $campaign["ID"];
    $row =& $adminList->AddRow($campaign["ID"], $campaign, $editUrl, Loc::getMessage("SEO_CAMPAIGN_EDIT_TITLE", array("#ID#" => $campaign["ID"], "#XML_ID#" => $campaign["XML_ID"])));
    $bOwner = $campaign['OWNER_ID'] == $currentUser['id'];
    $row->AddViewField("ID", $campaign['ID']);
    $row->AddField("NAME", '<a href="' . Converter::getHtmlConverter()->encode($editUrl) . '" title="' . Loc::getMessage("SEO_CAMPAIGN_EDIT_TITLE", array("#ID#" => $campaign["ID"], "#XML_ID#" => $campaign["XML_ID"])) . '">' . Converter::getHtmlConverter()->encode($campaign['NAME']) . '</a>');
    $row->AddViewField('LAST_UPDATE', $campaign['LAST_UPDATE'] ? $campaign['LAST_UPDATE'] : Loc::getMessage('SEO_UPDATE_NEVER'));
    $row->AddViewField('SHOW', Loc::getMessage('SEO_YANDEX_STATUS_' . $campaign['SETTINGS']['StatusShow']));
    $active = 'grey';
    $active_title = $campaign['SETTINGS']['Status'];
    if ($campaign['SETTINGS']['IsActive'] == Engine\YandexDirect::BOOL_YES) {
        $active = 'green';
    } elseif ($campaign['SETTINGS']['StatusModerate'] == Engine\YandexDirect::BOOL_YES && $campaign['SETTINGS']['StatusShow'] == Engine\YandexDirect::BOOL_YES) {
        if ($campaign['SETTINGS']['StatusActivating'] == Engine\YandexDirect::BOOL_YES) {
            $active = 'red';
		$message = new CAdminMessage(array(
			"TYPE" => "ERROR",
			"DETAILS" => Loc::getMessage("SEO_ERROR_NO_BANNER"),
			"HTML" => true
		));
		echo $message->Show();

		require($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/main/include/epilog_admin.php");
	}
}

$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");

	$message = new CAdminMessage(array(
		"TYPE" => "ERROR",
		"DETAILS" => Loc::getMessage("SEO_ERROR_NO_CAMPAIGN"),
	));
	echo $message->Show();

	require($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/main/include/epilog_admin.php");
}
Exemplo n.º 3
0
				|| (
					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']
						))
Exemplo n.º 4
0
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()) {
    if ($campaign['OWNER_ID'] == $currentUser['id']) {
        $campaignList[$campaign['ID']] = $campaign;
    }
}
if (count($campaignList) <= 0) {
    if (!defined('BX_PUBLIC_MODE') || !BX_PUBLIC_MODE) {
        $message = new CAdminMessage(array("TYPE" => "OK", "DETAILS" => Loc::getMessage("SEO_ERROR_NO_CAMPAIGNS", array("#LANGUAGE_ID#" => LANGUAGE_ID)), "HTML" => true));
        echo $message->Show();
    } else {
        echo BeginNote() . Loc::getMessage("SEO_ERROR_NO_CAMPAIGNS", array("#LANGUAGE_ID#" => LANGUAGE_ID)) . EndNote();
    }
    ?>
<a href="/bitrix/admin/seo_search_yandex_direct_edit.php?lang=<?php 
Exemplo n.º 5
0
 public static function updateAgent()
 {
     $engine = new self();
     if ($engine->getAuthSettings()) {
         try {
             $dbRes = YandexCampaignTable::getList(array('filter' => array('<LAST_UPDATE' => DateTime::createFromTimestamp(time() - YandexCampaignTable::CACHE_LIFETIME), '=ENGINE_ID' => $engine->getId()), 'select' => array('CNT'), 'runtime' => array(new ExpressionField('CNT', 'COUNT(*)'))));
             $res = $dbRes->fetch();
             if ($res['CNT'] > 0) {
                 $engine->updateCampaignManual();
             }
             $availableCampaigns = array();
             $campaignList = $engine->getCampaignList();
             foreach ($campaignList as $campaignInfo) {
                 $availableCampaigns[] = $campaignInfo['CampaignID'];
             }
             if (count($availableCampaigns) > 0) {
                 $dbRes = YandexBannerTable::getList(array('group' => array('CAMPAIGN_ID'), 'filter' => array('<LAST_UPDATE' => DateTime::createFromTimestamp(time() - YandexBannerTable::CACHE_LIFETIME), '=ENGINE_ID' => $engine->getId(), '=CAMPAIGN.XML_ID' => $availableCampaigns), 'select' => array('CAMPAIGN_ID')));
                 $campaignId = array();
                 while ($res = $dbRes->fetch()) {
                     $campaignId[] = $res['CAMPAIGN_ID'];
                 }
                 if (count($campaignId) > 0) {
                     $engine->updateBannersManual($campaignId);
                 }
             }
         } catch (YandexDirectException $e) {
         }
     }
     return __CLASS__ . "::updateAgent();";
 }
Exemplo n.º 6
0
 public static function loadCampaignStat($campaignId, $dateStart, $dateFinish)
 {
     $liveEngine = new YandexDirectLive();
     $dbRes = YandexCampaignTable::getList(array('filter' => array('=ID' => $campaignId, '=ENGINE_ID' => $liveEngine->getId()), 'select' => array('ID', 'XML_ID')));
     $campaign = $dbRes->fetch();
     if ($campaign) {
         $result = static::loadStat($liveEngine, $campaign['XML_ID'], $dateStart, $dateFinish);
         if ($result['Stat']) {
             static::processStatsResult($campaignId, $result, $liveEngine);
             return true;
         }
     }
     return false;
 }
Exemplo n.º 7
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;
	}
	$campaignSettings['EmailNotification']['SendWarn'] = $campaignSettings['EmailNotification']['SendWarn'] == 'Y';

	$campaignSettings['MinusKeywords'] = preg_split("/[\\n,;]+\\s*/", $campaignSettings['MinusKeywords']);

	$campaignFields = array(
		"SETTINGS" => $campaignSettings
	);

	if($ID > 0)
	{
		$result = Adv\YandexCampaignTable::update($ID, $campaignFields);
	}
	else
	{
		$result = Adv\YandexCampaignTable::add($campaignFields);
	}

	if($result->isSuccess())
	{
		$ID = $result->getId();
		if($request["apply"]<>'')
		{
			LocalRedirect('/bitrix/admin/seo_search_yandex_direct_edit.php?lang='.LANGUAGE_ID.'&ID='.$ID.'&'.$tabControl->ActiveTabParam());
		}
		else
		{
			if($back_url == '')
			{
				LocalRedirect("/bitrix/admin/seo_search_yandex_direct.php?lang=".LANGUAGE_ID);
			}
Exemplo n.º 9
0
 $bSingle = !is_array($bannerId);
 if ($bSingle) {
     $bannerId = array($bannerId);
 }
 array_map('intval', $bannerId);
 if (count($bannerId) > 0) {
     $dbBanners = Adv\YandexBannerTable::getList(array('filter' => array('@ID' => $bannerId, '=ENGINE_ID' => $engine->getId(), '=ACTIVE' => Adv\YandexBannerTable::ACTIVE), 'select' => array('ID', 'CAMPAIGN_ID', 'SETTINGS')));
     $bannerList = array();
     $campaignList = array();
     while ($banner = $dbBanners->fetch()) {
         $campaignList[] = $banner['CAMPAIGN_ID'];
         $bannerList[$banner['ID']] = $banner;
     }
     $campaignList = array_unique($campaignList);
     if (count($campaignList) > 0) {
         $dbCampaigns = Adv\YandexCampaignTable::getList(array('filter' => array('@ID' => $campaignList, '=ENGINE_ID' => $engine->getId(), '=ACTIVE' => Adv\YandexCampaignTable::ACTIVE), 'select' => array('ID', 'SETTINGS')));
         $campaignList = array();
         while ($campaign = $dbCampaigns->fetch()) {
             $campaignList[$campaign['ID']] = $campaign;
         }
         $dateFinish = new Date();
         $bannerListToCheck = array();
         foreach ($bannerList as $key => $banner) {
             $banner['DATE_START'] = $campaignList[$banner['CAMPAIGN_ID']]['SETTINGS']['StartDate'];
             if ($bSale) {
                 $banner['PROFIT'] = 0;
             }
             if ($banner['DATE_START']) {
                 $banner['DATE_START'] = new Date($banner['DATE_START'], 'Y-m-d');
                 $banner['STATS_DATA'] = Adv\YandexStatTable::getBannerStat($banner['ID'], $banner['DATE_START'], $dateFinish);
                 $gaps = Adv\YandexStatTable::getMissedPeriods($banner['STATS_DATA'], $banner['DATE_START'], $dateFinish);
						{
							if(!isset($arBanners[$banner['BANNER_CAMPAIGN_ID']]))
							{
								$arBanners[$banner['BANNER_CAMPAIGN_ID']] = array();
							}

							$arBanners[$banner['BANNER_CAMPAIGN_ID']][] = $banner;
							$iblockElementInfo['IBLOCK']['ID'] = $banner['LINK_IBLOCK_ID'];
						}

						$dbRes = Adv\YandexCampaignTable::getList(array(
							"order" => array("NAME" => "asc"),
							"filter" => array(
								"=ID" > array_keys($arBanners),
								'=ACTIVE' => Adv\YandexCampaignTable::ACTIVE,
								'=ENGINE_ID' => $engine->getId(),
							),
							'select' => array(
								"ID", "NAME", "XML_ID"
							)
						));
						$campaignList = array();

						while($campaign = $dbRes->fetch())
						{
							$campaignList[$campaign['ID']] = $campaign;
						}

						require(dirname(__FILE__)."/../admin/tab/seo_search_yandex_direct_list_link.php");
					}
					elseif($_REQUEST['get_list_html'] == '2')
Exemplo n.º 11
0
$campaignAdminList = array();
while($campaign = $data->NavNext())
{
	$campaignAdminList[$campaign['ID']] = $campaign;
}

if(count($campaignAdminList) > 0)
{
	$campaignList = Adv\YandexCampaignTable::getList(array(
		'filter' => array(
			"=ID" => array_keys($campaignAdminList),
		),
		"select" => array('ID', 'BANNER_CNT'),
		'runtime' => array(
			new Entity\ExpressionField(
				'BANNER_CNT',
				'COUNT(%s)',
				"\\Bitrix\\Seo\\Adv\\YandexBannerTable:CAMPAIGN.ID"
			),
		)
	));
	while($campaignCounter = $campaignList->fetch())
	{
		$campaignAdminList[$campaignCounter["ID"]]["BANNER_CNT"] = $campaignCounter["BANNER_CNT"];
	}
}

foreach($campaignAdminList as $campaign)
{
	$editUrl = "seo_search_yandex_direct_edit.php?lang=".LANGUAGE_ID."&ID=".$campaign["ID"];