Example #1
0
 public static function convertType($value, $type = 'id')
 {
     switch ($type) {
         case 'id':
             return Utils::mongoObjectId($value);
         case 'regex':
             return Utils::mongoRegex($value);
         case 'date':
         case 'datetime':
         case 'time':
             return self::time($value);
     }
     return '';
 }
Example #2
0
 /**
  * @before _secure
  * @after _displayData
  */
 public function links()
 {
     $this->seo(array("title" => "Link Logs"));
     $view = $this->getActionView();
     $prop = RM::get("property");
     $val = RM::get("value");
     $sort = RM::get("sort", "desc");
     $sign = RM::get("sign", "equal");
     $orderBy = RM::get("order", 'created');
     $fields = (new \Link())->getColumns();
     $searching = $query = [];
     $query['user_id'] = ['$in' => $this->org->users('publisher')];
     foreach ($fields as $key => $value) {
         $search = RM::get($key);
         if (!$search) {
             continue;
         }
         $searching[$key] = $search;
         // Only allow full object ID's and rest regex searching
         if (in_array($key, ['user_id', 'ad_id', '_id'])) {
             $query[$key] = RM::get($key);
         } else {
             $query[$key] = Utils::mongoRegex($search);
         }
     }
     $dateQuery = Utils::dateQuery(['start' => $this->start, 'end' => $this->end]);
     $query['created'] = ['$gte' => $dateQuery['start'], '$lte' => $dateQuery['end']];
     $records = \Link::all($query, [], $orderBy, $sort, $this->limit, $this->page);
     $count = \Link::count($query);
     $view->set(['links' => $records, 'fields' => $fields, 'property' => $prop, 'value' => $val, 'sign' => $sign, 'sort' => $sort, 'order' => $orderBy, 'count' => $count, 'query' => $searching]);
 }
Example #3
0
 /**
  * @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);
 }
Example #4
0
 /**
  * @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);
 }