function updateUrls()
 {
     $updatedKeywords = array();
     $dao = new KeywordDAO();
     $keywords = $dao->loadAll();
     foreach ($keywords as $keyword) {
         $keyword = $this->updateURL($keyword);
         if ($keyword->isChanged()) {
             $updatedKeywords[] = $keyword;
         }
     }
     // Save changes
     $dao = new KeywordDAO();
     $dao->saveKeywords($updatedKeywords);
     return $updatedKeywords;
 }
 function loadKeywords()
 {
     $keywordDAO = new KeywordDAO();
     $keywords = $keywordDAO->loadAll();
     $managedKeywords = array();
     $todayStart = mktime(0, 0, 0, date("m", time()), date("d", time()), date("Y", time()));
     $end = gmdate("Y-m-d", $todayStart - 1);
     foreach ($keywords as $keyword) {
         if ($keyword->isApplyBidRule()) {
             $increaseStart = gmdate("Y-m-d", $todayStart - $keyword->getKeywordIncreaseDays() * SECONDS_IN_DAY);
             $decreaseStart = gmdate("Y-m-d", $todayStart - $keyword->getKeywordDecreaseDays() * SECONDS_IN_DAY);
             $managedKeyword = $this->getManagedEntity($keyword->id, "keyword_id", $increaseStart, $decreaseStart, $end);
             $managedKeyword->ppcEntity = $keyword;
             $managedKeywords[] = $managedKeyword;
         }
     }
     return $managedKeywords;
 }
 function keywords($args)
 {
     $method = $_SERVER['REQUEST_METHOD'];
     switch ($method) {
         case 'GET':
             $keywordsDao = new KeywordDAO();
             $keywords =& $keywordsDao->getKeywords();
             // There are two obvious formats for this data:
             // * an HTML ul
             // * an HTML select
             // I think a ul would be a bit better, but in practice a select
             // is very handy.  I may change it someday, however.
             header('Content-type: text/plain');
             for ($i = 0; $i < count($keywords); ++$i) {
                 $keyword = $keywords[$i];
                 if ($i > 0) {
                     echo "\n";
                 }
                 echo $keyword->getName() . ':' . $keyword->getDescription();
             }
             break;
     }
 }
Example #4
0
<?php

require_once dirname(__FILE__) . '/../database/PPCEntityDAO.php';
$dao = new KeywordDAO();
$keywords = $dao->loadAll($_REQUEST["adgroupId"]);
$adgroupDAO = new AdgroupDAO();
$adgroup = $adgroupDAO->load($_REQUEST["adgroupId"]);
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
    <head>
        <title>Keywords</title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    </head>
    <body>
        <h2>Keywords</h2>
        <h3><?php 
print "{$adgroup->campaign->engine} >> {$adgroup->campaign->name} >> {$adgroup->name}";
?>
</h3>
        <table>
            <thead>
                <tr>
                    <th>Keyword</th>
                    <th>Match Type</th>
                </tr>
            </thead>
            <tbody>
                <?php 
foreach ($keywords as $keyword) {
    ?>
<?php

require_once dirname(__FILE__) . '/../database/BidRuleDAO.php';
require_once dirname(__FILE__) . '/../database/PPCEntityDAO.php';
$ruleDAO = new BidRuleDAO();
$keywordDAO = new KeywordDAO();
$keyword = $keywordDAO->load($_REQUEST["keywordId"]);
if ($keyword->keywordBidRule == null) {
    $keyword->keywordBidRule = new BidRule();
    $keyword->keywordBidRule->entityType = 1;
    $keyword->keywordBidRule->ruleType = 1;
}
if (isset($_REQUEST["keyword_cost_threshold"])) {
    $keyword->keywordBidRule->cost_threshold = strip_tags($_REQUEST["keyword_cost_threshold"]);
    $keyword->keywordBidRule->increase_percent = strip_tags($_REQUEST["keyword_bid_increase_percent"]);
    $keyword->keywordBidRule->increase_days = strip_tags($_REQUEST["keyword_bid_increase_days"]);
    $keyword->keywordBidRule->decrease_percent = strip_tags($_REQUEST["keyword_bid_decrease_percent"]);
    $keyword->keywordBidRule->decrease_days = strip_tags($_REQUEST["keyword_bid_decrease_days"]);
    $keyword->keywordBidRule->apply = $_REQUEST["apply_keyword_rule"] == "on";
    $keywordDAO->saveKeywords(array($keyword));
    header("Location: keywords.php?adgroupId={$keyword->adgroup->id}");
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
    <head>
        <title><?php 
print $keyword->name;
?>
 Bid Management Rules</title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        $keywords = $dao->loadAll(false, true);
        $service->yahooUpload($ysmMaster, $ysmClient, $keywords);
    }
    if ($_REQUEST["action"] == "adcenter_upload") {
        $dao = new KeywordDAO();
        $keywords = $dao->loadAll(false, true);
        $filename = "adcenter-" . date("Y-m-d_H-i-s") . ".csv";
        $service->adcenterUpload(dirname(__FILE__) . "/adcenter_temp/{$filename}", $keywords);
        header("Content-type: text/csv");
        header("Content-disposition: attachment; filename={$filename}");
        print file_get_contents(dirname(__FILE__) . "/adcenter_temp/{$filename}");
        die;
    }
    if ($_REQUEST["action"] == "update") {
        $service->updateUrls();
        $dao = new KeywordDAO();
        $keywords = $dao->loadAll(false, true);
    }
}
?>
<html>
    <head>
        <title>URL Update</title>
    </head>
    <body>
        <h1>URL Update</h1>
        <ul>
            <li><a href="<?php 
print $_SERVER["PHP_SELF"];
?>
?action=adwords_download">AdWords URL Download</a></li>
 function updateKeywords()
 {
     $updatedKeywords = array();
     $dao = new ManagedEntityDAO();
     $keywords = $dao->loadKeywords();
     foreach ($keywords as $keyword) {
         $keyword->update();
         if ($keyword->ppcEntity->isChanged()) {
             $updatedKeywords[] = $keyword->ppcEntity;
         }
     }
     // Save changes
     $dao = new KeywordDAO();
     $dao->saveKeywords($updatedKeywords);
     return $updatedKeywords;
 }
 private function importKeywords($adgroups)
 {
     $keywordDAO = new KeywordDAO();
     $report = $this->getKeywordReport();
     $oldKeywords = $keywordDAO->loadAll();
     $keywords = array();
     foreach ($oldKeywords as $keyword) {
         $keywords[$keyword->keywordId] = $keyword;
     }
     $rows = explode("\n", $report);
     foreach ($rows as $row) {
         $keyword = $this->importKeywordStructureRow($row, $adgroups, $keywords);
         if ($keyword) {
             $keywords[$keyword->keywordId] = $keyword;
         }
     }
     $keywordDAO->saveKeywords($keywords);
     return $keywords;
 }