/** * @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); }
/** * @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); }
/** * @before _secure */ public function platforms($id = null) { $this->seo(array("title" => "Platforms")); $view = $this->getActionView(); $query['user_id'] = ['$in' => $this->org->users('publisher')]; $limit = RM::get("limit", 20); $page = RM::get("page", 1); $property = RM::get("property", ''); $value = RM::get("value"); if (in_array($property, ["live", "user_id"])) { $query["{$property} = ?"] = $value; } else { if (in_array($property, ["url"])) { $query[$property] = Utils::mongoRegex($value); } } if (RM::type() === 'POST') { $p = \Platform::first(['_id' => $id, 'user_id' => $query['user_id']]); if (!$p) { return $view->set('message', "Invalid Request!!"); } try { $updateAble = ['live', 'user_id', 'url']; foreach ($_POST as $key => $value) { if (in_array($key, $updateAble)) { $p->{$key} = $value; } } $p->save(); return $view->set('message', 'Platform updated!!'); } catch (\Exception $e) { return $view->set('message', "Invalid Request Parameters!!"); } } if (RM::type() === 'DELETE') { $p = \Platform::first(['_id' => $id, 'user_id' => $query['user_id']]); if (!$p) { return $view->set('message', "Invalid Request!!"); } $p->delete(); return $view->set('message', "Platform Removed!!"); } $platforms = Platform::all($query, [], 'created', 'desc', $limit, $page); $count = Platform::count($query); $view->set("platforms", $platforms)->set("count", $count)->set("property", $property)->set("value", $value)->set("limit", $limit)->set("page", $page); }
/** * @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); }