예제 #1
0
 /**
  * @before _secure
  */
 public function campaign($id)
 {
     $ad = \Ad::first(['_id' => $id, 'org_id' => $this->org->_id]);
     if (!$ad) {
         $this->_404();
     }
     $this->seo(["title" => $ad->title]);
     $view = $this->getActionView();
     if (RM::post("action")) {
         // action value already checked in _postback func
         $this->_postback('add', ['ad' => $ad]);
     }
     if (RM::type() === 'DELETE') {
         $this->_postback('delete');
     }
     $start = RM::get("start", date('Y-m-d', strtotime("-7 day")));
     $end = RM::get("end", date('Y-m-d'));
     $limit = RM::get("limit", 10);
     $page = RM::get("page", 1);
     $query = ['adid' => Db::convertType($id), 'created' => Db::dateQuery($start, $end)];
     $clicks = \Click::all($query, [], 'created', 'desc', $limit, $page);
     $count = \Click::count($query);
     $cf = Utils::getConfig("cf", "cloudflare");
     $view->set("domain", $cf->api->domain)->set("clicks", $clicks)->set("count", $count)->set('advertiser', $this->user);
     $comms = Commission::all(["ad_id = ?" => $id], ['model', 'coverage', 'revenue', 'description']);
     $models = ArrayMethods::arrayKeys($comms, 'model');
     $advertiser = User::first(["id = ?" => $ad->user_id], ['name']);
     $categories = \Category::all(["org_id = ?" => $this->org->_id], ['name', '_id']);
     $this->_postback('show', ['ad' => $ad]);
     $view->set("ad", $ad)->set("comms", $comms)->set("categories", $categories)->set("advertiser", $advertiser)->set('models', $models)->set("start", $start)->set("end", $end);
 }
예제 #2
0
 protected function _parse($comment)
 {
     $meta = array();
     $pattern = "(@[a-zA-Z]+\\s*[a-zA-Z0-9, ()_]*)";
     $matches = StringMethods::match($comment, $pattern);
     if ($matches != null) {
         foreach ($matches as $match) {
             $parts = ArrayMethods::clean(ArrayMethods::trim(StringMethods::split($match, "[\\s]", 2)));
             $meta[$parts[0]] = true;
             if (sizeof($parts) > 1) {
                 $meta[$parts[0]] = ArrayMethods::clean(ArrayMethods::trim(StringMethods::split($parts[1], ",")));
             }
         }
     }
     return $meta;
 }
예제 #3
0
 /**
  * @before _secure
  */
 public function details($id)
 {
     $ad = \Ad::first(['_id' => $id, 'org_id' => $this->org->_id]);
     if (!$ad) {
         $this->_404();
     }
     $this->seo(array("title" => $ad->title));
     $view = $this->getActionView();
     $start = RM::get("start", date('Y-m-d', strtotime("-1 day")));
     $end = RM::get("end", date('Y-m-d'));
     if (RM::type() === 'DELETE') {
         $this->_commissionDel($ad, $view);
     }
     switch (RM::post("action")) {
         case 'caccess':
             $meta = $ad->meta;
             $meta["access"] = RM::post("access");
             $ad->meta = $meta;
             $ad->save();
             break;
     }
     switch (RM::get("action")) {
         case 'updateAccess':
             $access = AdAccess::first(["id = ?" => RM::get("access_id")]);
             if ($access) {
                 $access->live = RM::get("live", 0);
                 $access->save();
                 $this->redirect("/campaign/details/" . $ad->id . ".html#permission");
                 $session->set('$flashMessage', 'Access Updated');
             }
             break;
     }
     $comms = Commission::all(["ad_id = ?" => $id]);
     $models = ArrayMethods::arrayKeys($comms, 'model');
     $advertiser = User::first(["id = ?" => $ad->user_id], ['name']);
     $categories = \Category::all(["org_id = ?" => $this->org->_id], ['name', '_id']);
     $publishers = \User::all(['type' => 'publisher', 'org_id' => $this->org->_id, "live = ?" => true], ["id", "name"]);
     $adaccess = \AdAccess::all(['org_id' => $this->org->_id, "ad_id = ?" => $ad->id]);
     $view->set("ad", $ad)->set("comms", $comms)->set("categories", $categories)->set("advertiser", $advertiser)->set('publishers', \User::objectArr($publishers, ['_id', 'name']))->set('models', $models)->set('adaccess', $adaccess)->set("start", $start)->set("end", $end);
 }
예제 #4
0
파일: Ini.php 프로젝트: saulor/cpbquirophp
 public function parse($path)
 {
     $path = DIR_ROOT . SEPARADOR_DIRETORIO . $path;
     // se $path for vazio
     if (empty($path)) {
         //throw new Exception\Argument("\$path argument is not valid");
         throw new Exception("\$path argument is not valid");
     }
     // verifica se o parse já foi feito
     if (!isset($this->_parsed[$path])) {
         $config = array();
         // ativa o buffer de saída
         // enquanto estiver ativo a saída é armazenada em um buffer interno
         ob_start();
         // dá um include no arquivo .ini
         include "{$path}.ini";
         //include("{$path}.ini.php");
         // obtém o conteúdo do buffer de saída
         $string = ob_get_contents();
         // descarta o conteúdo e desativa o buffer de saída
         ob_end_clean();
         // transforma o conteúdo do buffer num array associativo chave => valor
         $pairs = parse_ini_string($string);
         // se não tiver nada aqui provavelmente foram encontrados erros de sintaxe
         if ($pairs == false) {
             //throw new Exception\Syntax("Could not parse configuration file");
             throw new Exception("Could not parse configuration file");
         }
         // percorre o array
         foreach ($pairs as $key => $value) {
             $config = $this->_pair($config, $key, $value);
         }
         // transforma o array num objeto
         $this->parsed[$path] = ArrayMethods::toObject($config);
     }
     return $this->parsed[$path];
 }
예제 #5
0
파일: click.php 프로젝트: vNative/vnative
 public static function classifyInfo($opts = [])
 {
     $clicks = $opts['clicks'];
     $type = $opts['type'];
     $arr = $opts['arr'];
     $deviceClicks = self::classify($clicks, $type);
     $from = self::counter($deviceClicks);
     ArrayMethods::add($from, $arr);
     return $arr;
 }
예제 #6
0
파일: report.php 프로젝트: vNative/vnative
 protected function _searchQuery($fields, &$adIds, &$pIds)
 {
     $searchQ = RM::get('query', []);
     $query = $searching = [];
     foreach ($searchQ as $q) {
         if (!in_array($q, $fields)) {
             continue;
         }
         $searching[$q] = RM::get($q);
         switch ($q) {
             case 'adid':
                 $adIdsGet = RM::get($q, []);
                 if (ArrayMethods::inArray($adIds, $adIdsGet)) {
                     $adIds = $adIdsGet;
                 }
                 break;
             case '_id':
             case 'cid':
                 $id = RM::get($q, null);
                 if ($id) {
                     $query[$q] = Db::convertType($id);
                 }
                 break;
             case 'is_bot':
                 $is_bot = RM::get($q, null);
                 if (!is_null($is_bot)) {
                     $query[$q] = (bool) (int) $is_bot;
                 }
                 break;
             case 'pid':
                 $pIdsGet = RM::get($q, []);
                 if (ArrayMethods::inArray($pIds, $pIdsGet)) {
                     $pIds = $pIdsGet;
                 }
                 break;
             case 'device':
             case 'os':
             case 'country':
                 $reqData = RM::get($q, []);
                 if (count($reqData) === 0) {
                     break;
                 }
                 $data = implode("|", $reqData);
                 $query[$q] = Db::convertType($data, 'regex');
                 break;
             case 'referer':
             case 'p1':
             case 'p2':
             case 'cookie':
                 $data = RM::get($q);
                 if ($data) {
                     $query[$q] = Db::convertType($data, 'regex');
                 }
                 break;
             case 'ip':
                 $reqData = RM::get('ip', '');
                 $pieces = explode(",", $reqData);
                 if (count($pieces) === 0) {
                     break;
                 }
                 $data = implode("|", $pieces);
                 $query[$q] = Db::convertType($data, 'regex');
                 break;
         }
     }
     return ['query' => $query, 'searching' => $searching];
 }
예제 #7
0
 /**
  * @before _admin
  */
 public function info($id = null)
 {
     $this->seo(array("title" => "Publisher Edit"));
     $view = $this->getActionView();
     $publisher = User::first(["_id = ?" => $id, "type = ?" => "publisher", "org_id = ?" => $this->org->id]);
     if (!$publisher) {
         $this->_404();
     }
     $platforms = Platform::all(["user_id = ?" => $publisher->id]);
     $view->set("platforms", $platforms);
     $view->set("errors", []);
     if (RM::type() == 'POST') {
         $action = RM::post('action', '');
         switch ($action) {
             case 'account':
                 $fields = ['name', 'email', 'phone', 'country', 'currency', 'username'];
                 foreach ($fields as $f) {
                     $publisher->{$f} = RM::post($f);
                 }
                 $publisher->save();
                 $view->set('message', 'Account Info updated!!');
                 break;
             case 'password':
                 $old = RM::post('password');
                 $new = RM::post('npassword');
                 $view->set($publisher->updatePassword($old, $new));
                 break;
             case 'campaign':
                 $publisher->getMeta()['campaign'] = ['model' => RM::post('model'), 'rate' => $this->currency(RM::post('rate'))];
                 $publisher->save();
                 $view->set('message', 'Payout Info Updated!!');
                 break;
             case 'trackingDomain':
                 $tdomain = (array) RM::post('tdomain', '');
                 if ($tdomain && ArrayMethods::inArray($this->org->tdomains, $tdomain)) {
                     $publisher->getMeta()['tdomain'] = $tdomain;
                     $publisher->save();
                     $view->set('message', 'Added Tracking Domain for publisher');
                 } else {
                     $view->set('message', 'Invalid Request!!');
                 }
             case 'commadd':
             case 'commedit':
                 $comm_id = RM::post('comm_id');
                 if ($comm_id) {
                     $comm = Commission::first(['_id' => $comm_id, 'user_id' => $publisher->_id]);
                 } else {
                     $comm = new Commission(['user_id' => $publisher->_id]);
                 }
                 $comm->model = RM::post('model');
                 $comm->description = RM::post('description');
                 $comm->rate = $this->currency(RM::post('rate'));
                 $comm->coverage = RM::post('coverage', ['ALL']);
                 $comm->save();
                 $view->set('message', "Multi Country Payout Saved!!");
                 break;
         }
     }
     if (RM::type() === 'DELETE') {
         $action = RM::get("action");
         switch ($action) {
             case 'payoutdel':
                 unset($publisher->getMeta()['campaign']);
                 $publisher->save();
                 $view->set('message', 'Payout Deleted!!');
                 break;
             case 'commDel':
                 $comm = Commission::first(['_id' => RM::get("comm_id"), 'user_id' => $publisher->_id]);
                 if ($comm) {
                     $comm->delete();
                     $view->set('message', 'Payout Deleted!!');
                 } else {
                     $view->set('message', 'Invalid Request!!');
                 }
                 break;
             case 'afields':
                 $meta = $publisher->meta;
                 $publisher->removeFields();
                 unset($meta['afields']);
                 Db::updateRaw('users', ['_id' => Db::convertType($publisher->_id, 'id')], ['$set' => ['meta' => $meta]]);
                 $view->set('message', 'Data Removed!!');
                 break;
             case 'defaultDomain':
                 unset($publisher->getMeta()['tdomain']);
                 $publisher->save();
                 $view->set('message', 'Removed tracking domain!!');
                 break;
         }
     }
     $afields = Meta::search('customField', $this->org);
     $view->set('afields', $afields)->set("publisher", $publisher)->set("commissions", Commission::all(["user_id = ?" => $publisher->id]))->set("start", strftime("%Y-%m-%d", strtotime('-7 day')))->set("end", strftime("%Y-%m-%d", strtotime('now')))->set("d", Performance::total(['start' => $start ?? $publisher->created->format('Y-m-d'), 'end' => $end ?? date('Y-m-d')], $publisher));
 }
예제 #8
0
파일: api.php 프로젝트: vNative/vnative
 /**
  * @before _secure
  * @after _cleanUp
  */
 public function campaign($id = null)
 {
     $view = $this->getActionView();
     $org = $this->_org;
     $active = RequestMethods::get('active', 1);
     $fields = ['_id', 'title', 'description', 'image', 'url', 'device', 'expiry', 'created'];
     $commFields = ['model', 'rate', 'revenue', 'coverage'];
     if ($id) {
         $campaign = Ad::first(['_id' => $id, 'org_id' => $org->_id], $fields);
     } else {
         $campaign = null;
     }
     if ($id && !$campaign) {
         return $this->failure('30');
     }
     $type = RequestMethods::type();
     switch ($type) {
         case 'GET':
             if (!$id) {
                 // display list of campaigns
                 $ads = Ad::all(['org_id' => $org->_id, 'live' => $active], $fields);
                 $ads = Ad::objectArr($ads, $fields);
                 $results = [];
                 foreach ($ads as $id => $a) {
                     $arr = Utils::toArray($a);
                     $comms = Commission::all(['ad_id' => $a->_id], $commFields);
                     $arr['commissions'] = Ad::objectArr($comms, $commFields);
                     $results[$id] = (object) $arr;
                 }
                 $data = ['campaigns' => $results];
                 $view->set('data', $data);
             } else {
                 $ads = Ad::objectArr($campaign, $fields);
                 $campaign = array_shift($ads);
                 $comm = Commission::all(['ad_id' => $campaign->_id], $commFields);
                 $data = ['campaign' => $campaign, 'commissions' => Commission::objectArr($comm, $commFields)];
                 $view->set('data', $data);
             }
             break;
         case 'POST':
             if ($id) {
                 // edit a particular campaign
             } else {
                 // create a new campaign
                 $fields = ['title', 'description', 'url', 'expiry', 'category', 'device', 'user_id'];
                 $img = RequestMethods::post('image');
                 // contains image url
                 $campaign = new Ad(['org_id' => $org->_id, 'type' => 'article', 'image' => Utils::media($img, 'download')]);
                 foreach ($fields as $f) {
                     $campaign->{$f} = RequestMethods::post($f);
                 }
                 $view->set('success', false);
                 $visibility = RequestMethods::post('visibility', 'public');
                 if ($visibility === 'private') {
                     $campaign->getMeta()['private'] = true;
                 }
                 $opts = ['devices' => array_keys(Shared\Markup::devices()), 'advertisers' => $org->users('advertiser', false)];
                 if (true) {
                     // $campaign->save();
                     $arr = ArrayMethods::reArray($_POST['commissions']);
                     var_dump($arr);
                     var_dump($_POST['commissions']);
                     $view->set('success', true);
                 } else {
                     $data = ['errors' => $campaign->errors];
                     $view->set('data', $data);
                 }
             }
             break;
         case 'DELETE':
             $message = $campaign->delete();
             $view->set($message);
             break;
     }
 }
예제 #9
0
파일: cron.php 프로젝트: vNative/vnative
 protected function _performance($date = null)
 {
     if (!$date) {
         $date = date('Y-m-d', strtotime('-1 day'));
     }
     $date = date('Y-m-d', strtotime('-1 day'));
     // find the publishers
     $publishers = \User::all(['type = ?' => 'publisher', 'live = ?' => true], ['_id', 'email', 'meta', 'org_id']);
     $dq = ['start' => $date, 'end' => $date];
     $dateQuery = Utils::dateQuery($dq);
     $start = $dateQuery['start'];
     $end = $dateQuery['end'];
     // store AD commission info
     $commInfo = [];
     $orgs = [];
     $advPerfs = [];
     $advertisers = [];
     $adsInfo = [];
     foreach ($publishers as $p) {
         $org = \Organization::find($orgs, $p->org_id);
         // find the clicks for the publisher
         $clicks = Db::query('Click', ['pid' => $p->_id, 'is_bot' => false, 'created' => Db::dateQuery($date, $date)], ['adid', 'country', 'device', 'os', 'referer']);
         $perf = Performance::exists($p, $date);
         // classify the clicks according to AD ID
         $classify = \Click::classify($clicks, 'adid');
         $countryWise = $deviceWise = $osWise = $refWise = [];
         foreach ($classify as $key => $value) {
             $ad = \Ad::find($adsInfo, $key, ['user_id', 'url']);
             $advert = Usr::find($advertisers, $ad->user_id, ['_id', 'meta', 'email', 'org_id']);
             $advertPerf = Usr::findPerf($advPerfs, $advert, $date);
             $countries = \Click::classify($value, 'country');
             foreach ($countries as $country => $records) {
                 $updateData = [];
                 $adClicks = count($records);
                 ArrayMethods::counter($countryWise, $country, $adClicks);
                 $pComm = \Commission::campaignRate($key, $commInfo, $country, array_merge(['type' => 'both', 'publisher' => $p], $dq));
                 $earning = \Ad::earning($pComm, $adClicks);
                 ArrayMethods::copy($earning, $updateData);
                 $updateData['profit'] = $updateData['revenue'] - $updateData['payout'];
                 $updateData['revenue'] = $updateData['payout'];
                 $perf->update($updateData);
                 $aComm = \Commission::campaignRate($key, $commInfo, $country, array_merge(['type' => 'advertiser'], $dq));
                 $updateData = [];
                 $earning = \Ad::earning($aComm, $adClicks);
                 ArrayMethods::copy($earning, $updateData);
                 $advertPerf->update($updateData);
             }
             $deviceWise = Click::classifyInfo(['clicks' => $value, 'type' => 'device', 'arr' => $deviceWise]);
             $osWise = Click::classifyInfo(['clicks' => $value, 'type' => 'os', 'arr' => $osWise]);
             $refWise = Click::classifyInfo(['clicks' => $value, 'type' => 'referer', 'arr' => $refWise]);
         }
         $msg = 'Performance saved for user: '******' with clicks: ' . $perf->clicks . ' impressions: ' . $perf->impressions;
         $this->log($msg);
         $splitCountry = ArrayMethods::topValues($countryWise);
         $splitCountry['rest'] = array_sum($countryWise) - array_sum($splitCountry);
         $meta = ['country' => $splitCountry, 'device' => ArrayMethods::topValues($deviceWise, count($deviceWise)), 'os' => ArrayMethods::topValues($osWise, count($osWise)), 'referer' => ArrayMethods::topValues($refWise, count($refWise))];
         $perf->meta = $meta;
         $perf->save();
     }
     foreach ($advPerfs as $key => $perf) {
         $msg = 'Saving performance for advertiser: ' . $key . ' with clicks: ' . $perf->clicks . ' earning: ' . $perf->revenue . ' impressions: ' . $perf->impressions;
         $this->log($msg);
         $perf->save();
     }
 }