/** * @before _secure */ public function platforms() { $this->seo(array("title" => "List of Platforms")); $view = $this->getActionView(); if (RM::type() === 'POST') { $pid = RM::post('pid'); try { if ($pid) { $p = \Platform::first(['_id = ?' => $pid]); } else { $p = new \Platform(['user_id' => $this->user->_id, 'live' => true]); } $p->url = RM::post('url'); $p->save(); $view->set('message', 'Platform saved successfully!!'); } catch (\Exception $e) { $view->set('message', $e->getMessage()); } } $platforms = \Platform::all(["user_id = ?" => $this->user->_id], ['_id', 'url']); $results = []; $start = RM::get("start", date('Y-m-d', strtotime('-7 day'))); $end = RM::get("end", date('Y-m-d', strtotime('-1 day'))); $dateQuery = Utils::dateQuery(['start' => $start, 'end' => $end]); foreach ($platforms as $p) { $key = Utils::getMongoID($p->_id); } $view->set("platforms", $results)->set("start", $start)->set("end", $end); }
break; case 'updatePlatformDisplay': $platform = new Platform(new NamedArguments(array('primaryKey' => $_GET['updateID']))); $platform->reportDisplayName = $_GET['reportDisplayName']; try { $platform->save(); echo _("Platform Reporting Display Name has been updated"); } catch (Exception $e) { echo $e->getMessage(); } break; case 'updatePlatformDropDown': $platform = new Platform(new NamedArguments(array('primaryKey' => $_GET['platformID']))); $platform->reportDropDownInd = $_GET['dropDownInd']; try { $platform->save(); echo _("Default display list has been updated"); } catch (Exception $e) { echo $e->getMessage(); } break; case 'updatePublisherDisplay': $publisherPlatform = new PublisherPlatform(new NamedArguments(array('primaryKey' => $_GET['updateID']))); $publisherPlatform->reportDisplayName = $_GET['reportDisplayName']; try { $publisherPlatform->save(); echo _("Publisher Reporting Display Name has been updated"); } catch (Exception $e) { echo $e->getMessage(); } break;
/** * @before _secure */ public function platforms() { $this->seo(array("title" => "List of Platforms")); $view = $this->getActionView(); $nativeCode = $this->getAdCode('native', true); $bannerCode = $this->getAdCode('banner', true); $view->set('nativeCode', $nativeCode); $view->set('bannerCode', $bannerCode); if (RM::type() === 'POST') { $pid = RM::post('pid'); try { if ($pid) { $p = \Platform::first(['_id = ?' => $pid]); } else { $p = new \Platform(['org_id' => $this->org->id, 'user_id' => $this->user->_id]); } $p->url = RM::post('url'); $p->category = RM::post('category'); $p->type = RM::post('type'); $p->verified = false; $p->save(); $view->set('message', 'Platform saved successfully!!'); } catch (\Exception $e) { $view->set('message', $e->getMessage()); } } $platforms = \Platform::all(["user_id = ?" => $this->user->_id]); $view->set("platforms", $platforms); $categories = \Category::all(['org_id' => $this->org->_id]); $view->set('categories', $categories); }
/** * @before _secure */ public function import() { $this->seo(['title' => 'Campaign Import', 'description' => 'Create a new campaign']); $view = $this->getActionView(); $org = $this->org; $advertisers = \User::all(["org_id = ?" => $this->org->_id, 'type = ?' => 'advertiser'], ['_id', 'name']); if (count($advertisers) === 0) { $this->redirect('/advertiser/add.html'); } $platforms = \Platform::rssFeeds($this->org); $view->set('advertiser', $advertisers); $action = RM::post('action', ''); switch ($action) { case 'campImport': $this->_import($org, $advertisers, $view); break; case 'platform': $pid = RM::post('pid'); $p = $platforms[$pid]; $meta = $p->meta; $meta['rss']['url'] = RM::post('url'); $parsing = (bool) (int) RM::post('parsing', "1"); $meta['rss']['parsing'] = $parsing; $p->meta = $meta; $p->save(); $view->set('message', 'Updated Rss feed'); break; case 'newRss': $url = RM::post('rss_link'); $a = array_values($advertisers)[0]; $advert_id = RM::post('advert_id', $a->getMongoID()); $advert = \User::first(['_id = ?' => $advert_id, 'type = ?' => 'advertiser']); if (!$advert) { return $view->set('message', 'Invalid Request!!'); } // try to find a platform for the given advertiser $domain = parse_url($url, PHP_URL_HOST); $regex = preg_quote($domain); $p = \Platform::first(['user_id' => $advert_id, 'url' => Utils::mongoRegex($regex)]); $msg = "RSS Feed Added. Campaigns Will be imported within an hour"; try { // Now schedule importing of campaigns $result = \Shared\Rss::getFeed($url); $rate = RM::post('rate', 0.2); $revenue = RM::post('revenue', 0.25); $rss = ['url' => $url, 'parsing' => true, 'lastCrawled' => $result['lastCrawled'], 'campaign' => ['model' => RM::post('model', 'cpc'), 'rate' => $this->currency($rate), 'revenue' => $this->currency($rate)]]; // if platform not found then add new if (!$p) { $p = new \Platform(['url' => $domain, 'user_id' => $advert_id]); } $meta = $p->meta; $meta['rss'] = $rss; $p->meta = $meta; $p->save(); \Meta::campImport($this->user->_id, $advert_id, $result['urls'], $rss['campaign']); } catch (\Exception $e) { $msg = "Internal Server Error!!"; } $view->set('message', $msg); break; } $platforms = \Platform::rssFeeds($this->org); $view->set('platforms', $platforms); }
protected function _advertiserRegister($org, $view) { $platformUrl = RM::post("platform", ''); try { $platform = new \Platform(['url' => $platformUrl]); } catch (\Exception $e) { return $view->set('message', $e->getMessage()); } $user = User::addNew('advertiser', $org, $view); if ($user === false) { return; } $pass = $user->password; $user->password = sha1($pass); $user->save(); $platform->user_id = $user->_id; $platform->save(); Mail::send(['user' => $user, 'org' => $this->org, 'template' => 'advertReg', 'pass' => $pass, 'subject' => $this->org->name . ' Support']); return $view->set('message', "Registered Successfully"); }