Exemplo n.º 1
0
 /**
  *  Builds Ad group and its contents.
  *
  * @param array $data Initial data
  */
 public function buildVehiclesAdGroup($data = array())
 {
     $this->m_aItemData['l_geo_city'] = "в " . rus_city_pad($data['l_geo_city']);
     $this->gag_l_id = $data['l_id'];
     $this->gag_name = date("Y-m-d") . " " . $data['l_make'] . ' ' . $data['l_model'] . " в " . rus_city_pad($data['l_geo_city']);
     $this->save();
     $this->gag_name .= " " . $this->gag_id . ":" . $this->gag_l_id;
     require_once '../classes/KeywordForger.php';
     include '../config/keyword_forger.php';
     require_once '../classes/Keyword.php';
     $kw = array();
     foreach ($ad_group_by_item['vehicles'] as $key => $val) {
         $kw[] = $data[$key];
     }
     $result = $this->save();
     $keywords = KeywordForger::forgeKeywords($kw);
     $kw = new Keyword($this->db);
     foreach ($keywords as $val) {
         $kw->keyword = $val;
         $kw->save();
         $this->db->executeNoresSQL("INSERT IGNORE INTO m2m_keywords_to_google_ad_groups (gag_id, keyword_id) VALUES ({$this->gag_id}, {$kw->keyword_id})", $rowsAffected);
         $kw->reset();
     }
     return $result;
 }
Exemplo n.º 2
0
 public function executeAddKeyword()
 {
     $val = $this->getRequestParameter('keyword');
     $c = new Criteria();
     $c->add(KeywordPeer::LABEL, $val . "%", Criteria::LIKE);
     $keyword = KeywordPeer::doSelectOne($c);
     if (!$keyword) {
         $keyword = new Keyword();
         $keyword->setLabel($val);
         $keyword->save();
         exit($keyword->getId() . "," . $keyword->getLabel());
     }
     exit;
 }
Exemplo n.º 3
0
 public function actionAjaxCreate()
 {
     if (isset($_POST['term']) && isset($_POST['subcategory-id']) && $_POST['passcode'] == 'u98u8aUIUOa8scja89sjcjGBHJ') {
         $model = new Keyword();
         if (Keyword::model()->findByAttributes(array('term' => $_POST['term']))) {
             $failure = 0;
             echo $failure;
         } else {
             $model->term = $_POST['term'];
             $model->subcategory = $_POST['subcategory-id'];
             $model->category = $_POST['category-id'];
             $model->weight = 1;
             $model->save();
             $subcategories = $this->simplifySubcategories($this->getSubcategories($_POST['category-id']));
             $success = 1;
             echo $success . $this->renderPartial('term', array('term' => $model, 'subcategories' => $subcategories, 'subcategory' => KeywordSubcategory::model()->findByPk($model->subcategory), 'category_id' => $model->category), TRUE, TRUE);
         }
     }
     Yii::app()->end();
 }
Exemplo n.º 4
0
 /**
  * @return string|array Array on DB validation errors, else string messages
  */
 private function _saveSerp($keyword, $link)
 {
     $keyword = RequestMethods::post("keyword");
     $link = RequestMethods::post("link");
     $regex = Shared\Markup::websiteRegex();
     if (!preg_match("/^{$regex}\$/", $link)) {
         return "Invalid URL";
     }
     $serp = Keyword::first(array("link = ?" => $link, "user_id = ?" => $this->user->id, "keyword = ?" => $keyword, "serp = ?" => true));
     if ($serp) {
         return "SERP Already Registered";
     }
     $serp = new Keyword(array("link" => $link, "user_id" => $this->user->id, "keyword" => $keyword, "serp" => true));
     if ($serp->validate()) {
         $serp->save();
         return "Serp Action saved succesfully!!";
     } else {
         $errors = $keyword->errors;
         return $errors;
     }
 }
Exemplo n.º 5
0
 function testCreate()
 {
     $this->item->keyword = "test kw " . date("U");
     $this->assertTrue($this->item->save());
 }
Exemplo n.º 6
0
 public function testGetCount()
 {
     // Cleanup
     Keyword::deleteAll();
     for ($i = 0; $i < 50; $i++) {
         $keyword = new Keyword();
         $keyword->name = md5($i);
         $keyword->save();
     }
     $this->assertEquals(50, Keyword::getCount());
     $this->assertEquals(25, Keyword::getCount(array('number' => 25)));
 }
Exemplo n.º 7
0
 /**
  * 迁移
  * GET /api/migrate
  */
 public function actionRestmigrate()
 {
     $criteria = new CDbCriteria();
     $criteria->compare('archived', 1);
     $criteria->compare('type', 0);
     $criteria->order = 'created_time asc';
     $activities = Activity::model()->findAll($criteria);
     foreach ($activities as $activity) {
         // 创建reply
         $reply = new Autoreply();
         $reply->name = $activity->code;
         $reply->type = 0;
         $reply->reply = $activity->reply;
         if (!$reply->save()) {
             return $this->sendResponse(500, 'failed to save reply');
         }
         // 创建keywords
         $keywords = split(',', $activity->code);
         $count = 0;
         foreach ($keywords as $keywordStr) {
             $criteria = new CDbCriteria();
             $criteria->compare('word', $keywordStr);
             $criteria->compare('archived', 1);
             if (Keyword::model()->count($criteria) == 0) {
                 $keyword = new Keyword();
                 $keyword->word = $keywordStr;
                 $keyword->reply_id = $reply->id;
                 $keyword->save();
             }
         }
         $activity->archived = 0;
         $activity->save();
         sleep(1);
     }
     echo 'migrated';
 }
Exemplo n.º 8
0
 /**
  * @return string
  */
 private function _saveSocial()
 {
     $regex = Shared\Markup::websiteRegex();
     $link = RequestMethods::post("link");
     if (!preg_match("/^{$regex}\$/", $link)) {
         return "Invalid URL";
     }
     $tracker = Keyword::first(array("link = ?" => $link, "user_id = ?" => $this->user->id, "serp = ?" => false));
     if ($tracker) {
         return "Already added";
     }
     $tracker = new Keyword(array("keyword" => "social", "link" => $link, "user_id" => $this->user->id, "serp" => false));
     $tracker->save();
     return "Social Tracker Added";
 }
Exemplo n.º 9
0
 public function actionKeywords()
 {
     $keyword = new Keyword();
     $keywordForm = new KeywordForm();
     if ($postKeywordForm = Yii::app()->request->getParam('KeywordForm')) {
         $keywords = array();
         if (count($keywords = explode(PHP_EOL, $postKeywordForm['keywords'])) <= 1) {
             $keywords = array($postKeywordForm['keywords']);
         }
         foreach ($keywords as $k) {
             $k = trim($k);
             if (strlen($k) <= 0) {
                 continue;
             }
             if ($existingKeyword = Keyword::model()->findByAttributes(array('name' => $k, 'search_engine' => $postKeywordForm['searchEngine']))) {
                 $existingKeyword->deleted_at = null;
                 $existingKeyword->period = $postKeywordForm['period'];
                 $existingKeyword->update();
                 continue;
             }
             $newKeyword = new Keyword();
             $newKeyword->name = $k;
             $newKeyword->search_engine = $postKeywordForm['searchEngine'];
             $newKeyword->period = $postKeywordForm['period'];
             if (!$newKeyword->save()) {
                 throw new Exception(print_r($newKeyword->getErrors(), true));
             }
         }
         $this->refresh();
     }
     $this->render('keywords', array('keyword' => $keyword, 'keywordForm' => $keywordForm));
 }
Exemplo n.º 10
0
 public static function save_new_keyword($recipe_id, $word)
 {
     $keyword = new Keyword(array('keyword' => preg_replace('/\\s+/', ' ', $word)));
     if (strlen($keyword->keyword) > 1 && strlen($keyword->keyword) <= 30) {
         $keyword->save($recipe_id);
     }
 }