Example #1
0
function pageController()
{
    session_start();
    if (!isset($_SESSION['Loggedinuser'])) {
        $loginstatus = "Members, Log In!";
    } else {
        $loginstatus = $_SESSION['Loggedinuser'] . " is logged in!";
    }
    // Upon arrival at this page, this will load all the ads from the database.
    $adsArray = Ad::all();
    // Upon choosing a category, $clickcategories is set in $_GET. This variable is used to query the database.
    $clickedcategories = Input::has('clickcategory') ? '%' . Input::get('clickcategory') . '%' : '%';
    $adsArray = Ad::findCategories($clickedcategories);
    arsort($adsArray);
    // This portion of code gets all the ads' categories in one array.
    // The categories, which are strings (sometimes with multiple categories in it),
    // are then put into the array by themselves. The array is imploded into a string and then exploded into an
    // array again. This allows us to split the strings with multiple categories in them.
    // The php array_unique removes duplicate category values and sort orders them by first letter.
    $arrayCategories = Ad::showJustCategories();
    $justCategories = [];
    foreach ($arrayCategories as $key => $value) {
        array_push($justCategories, $value['categories']);
    }
    $justCategoriesString = implode(', ', $justCategories);
    $justCategoriesArray = explode(', ', $justCategoriesString);
    $justCategoriesArrayUnique = array_unique($justCategoriesArray);
    sort($justCategoriesArrayUnique);
    // This randomly selects an ad to show in the spotlight spatula box.
    $spotlight = $adsArray[array_rand($adsArray, 1)];
    return array('adsArray' => $adsArray, 'loginstatus' => $loginstatus, 'clickedcategories' => $clickedcategories, 'spotlight' => $spotlight, 'justCategoriesArrayUnique' => $justCategoriesArrayUnique);
}
Example #2
0
 public static function minutely()
 {
     // process all the campaign which needs processing
     $today = date('Y-m-d');
     $ads = \Ad::all(['meta.processing' => true, 'created' => Db::dateQuery($today, $today)]);
     foreach ($ads as $a) {
         $meta = $a->meta;
         switch ($a->type) {
             case 'video':
                 // download the video and save it
                 $arr = [];
                 $found = false;
                 foreach (['240p', '360p'] as $q) {
                     $vid = Utils::media($a->meta['videoUrl'], 'download', ['type' => 'video', 'quality' => $q]);
                     if (strlen($vid) >= 4) {
                         $found = true;
                         $arr[] = ['file' => $vid, 'quality' => $q];
                     }
                 }
                 if ($found) {
                     unset($meta['processing']);
                 }
                 $meta['videos'] = $arr;
                 $a->meta = $meta;
                 $a->save();
                 break;
         }
     }
 }
Example #3
0
 /**
  * @before _secure
  */
 public function campaigns()
 {
     $this->seo(array("title" => "Campaigns"));
     $view = $this->getActionView();
     $start = RM::get("start", strftime("%Y-%m-%d", strtotime('-7 day')));
     $end = RM::get("end", strftime("%Y-%m-%d", strtotime('now')));
     $limit = RM::get("limit", 20);
     $page = RM::get("page", 1);
     $query = ["user_id" => $this->user->id];
     $ads = \Ad::all($query, ['title', 'image', 'category', '_id', 'live', 'created'], 'created', 'desc', $limit, $page);
     $count = \Ad::count($query);
     $in = Db::convertType(array_keys($ads));
     $query["created"] = Db::dateQuery($start, $end);
     $records = Db::query('Click', ['adid' => ['$in' => $in], 'is_bot' => false, 'created' => $query["created"]], ['adid']);
     $view->set("ads", $ads);
     $view->set("start", $start);
     $view->set("end", $end);
     $view->set(['count' => $count, 'page' => $page, 'limit' => $limit, 'dateQuery' => $query['created'], 'clicks' => Click::classify($records, 'adid')]);
 }
Example #4
0
 public static function livePerf($user, $s = null, $e = null)
 {
     $start = $end = date('Y-m-d');
     $type = $user->type ?? '';
     if ($s) {
         $start = $s;
     }
     if ($e) {
         $end = $e;
     }
     $perf = new \Performance();
     $match = ['is_bot' => false, 'created' => Db::dateQuery($start, $end)];
     switch ($user->type) {
         case 'publisher':
             $match['pid'] = Db::convertType($user->_id);
             break;
         case 'advertiser':
             $ads = \Ad::all(['user_id' => $user->_id], ['_id']);
             $keys = array_keys($ads);
             $match['adid'] = ['$in' => Db::convertType($keys)];
             break;
         default:
             return $perf;
     }
     $results = $commissions = [];
     $records = self::_livePerfQuery($match);
     foreach ($records as $r) {
         $obj = Utils::toArray($r);
         $adid = Utils::getMongoID($obj['_id']);
         $results[$adid] = $obj;
     }
     $comms = Db::query('Commission', ['ad_id' => ['$in' => array_keys($results)]], ['ad_id', 'rate', 'revenue', 'model', 'coverage']);
     $comms = \Click::classify($comms, 'ad_id');
     foreach ($comms as $adid => $value) {
         $value = array_map(function ($v) {
             $v["ad_id"] = Utils::getMongoID($v["ad_id"]);
             unset($v["_id"]);
             return (object) $v;
         }, Utils::toArray($value));
         $commissions[$adid] = \Commission::filter($value);
     }
     foreach ($results as $adid => $obj) {
         $comms = $commissions[$adid];
         foreach ($obj['countries'] as $value) {
             $country = $value['country'];
             $clicks = $value['count'];
             $commission = \Commission::campaignRate($adid, $comms, $country, ['type' => $type, "{$type}" => $user, 'start' => $start, 'end' => $end, 'commFetched' => true]);
             $updateData = [];
             $earning = \Ad::earning($commission, $clicks);
             AM::copy($earning, $updateData);
             $perf->update($updateData);
         }
     }
     return $perf;
 }
<?php

require_once '../bootstrap.php';
if (!Auth::check()) {
    header("Location: login.php");
    exit;
}
$ads = [];
$ads = Ad::all();
if (Input::has('id') && Input::get('id') >= 0) {
    $id = Input::get('id');
} else {
    $id = 0;
}
Ad::isOwner($ads[$id]['user_id']);
Ad::delete($id);
header("Refresh: 3;url=/profile");
?>

<html>
<head>
    <title>Instrument Exchange</title>
    <!-- Bootstrap styling -->
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
    <!-- Custom styling for site -->
    <link rel="stylesheet" type="text/css" href="../css/main.css">
</head>
<body>
    <?// include "../views/partials/navbar.php"; ?>

Example #6
0
 /**
  * @before _secure
  * @after _displayData
  */
 public function platforms($id = null)
 {
     $this->seo(["title" => "Platform wise click stats"]);
     $view = $this->getActionView();
     $org = $this->org;
     $clickCol = Registry::get("MongoDB")->clicks;
     // find the platforms
     $platforms = \Platform::all(['user_id' => ['$in' => $org->users('advertisers')]], ['_id', 'url']);
     if (count($platforms) === 0) {
         return $view->set(['platforms' => [], 'publishers' => []]);
     }
     $key = array_rand($platforms);
     $url = RM::get('link', $platforms[$key]->url);
     // find ads having this url
     $ads = \Ad::all(['org_id' => $org->_id], ['_id', 'url']);
     $in = Utils::mongoObjectId(array_keys($ads));
     $matched = [];
     foreach ($ads as $a) {
         $regex = preg_quote($url, '.');
         if (preg_match('#^' . $regex . '#', $a->url)) {
             $matched[] = Utils::mongoObjectId($a->_id);
         }
     }
     if (count($matched) === 0) {
         $query['adid'] = ['$in' => $in];
     } else {
         $query['adid'] = ['$in' => $matched];
     }
     $query['is_bot'] = false;
     $query['created'] = Db::dateQuery($this->start, $this->end);
     $records = $clickCol->aggregate([['$match' => $query], ['$projection' => ['_id' => 1, 'pid' => 1]], ['$group' => ['_id' => '$pid', 'count' => ['$sum' => 1]]], ['$sort' => ['count' => -1]]]);
     $result = [];
     $publishers = [];
     foreach ($records as $r) {
         $obj = (object) $r;
         $id = Utils::getMongoID($obj->_id);
         $user = User::first(['_id' => $id], ['_id', 'name']);
         $result[$id] = (object) ['_id' => $user->_id, 'name' => $user->name, 'clicks' => $obj->count];
     }
     $view->set(['platforms' => $platforms, 'link' => $url, 'publishers' => $result]);
 }
Example #7
0
<?php

require '../models/Ad.php';
require '../utils/Auth.php';
session_start();
$ads_list = Ad::all();
?>

<html>
	<?php 
require_once '../views/header.php';
?>
	<?php 
require_once '../views/navbar.php';
?>

<body>
	

	<?php 
require_once '../views/footer.php';
?>
  
</body>
</html>
Example #8
0
 /**
  * Display a listing of ads
  *
  * @return Response
  */
 public function index()
 {
     $ads = Ad::all();
     return View::make('ads.index', compact('ads'));
 }
Example #9
0
 public function delete()
 {
     $deleteList = ['Link', 'Platform', 'Ad', 'Performance', 'Invoice', 'Adaccess'];
     $query = ['user_id' => $this->_id];
     $delete = false;
     switch ($this->_type) {
         case 'publisher':
             $clicks = Click::count(['pid' => $this->_id]);
             if ($clicks !== 0) {
                 return false;
             }
             $delete = true;
             $this->removeFields();
             break;
         case 'advertiser':
             $ads = Ad::all(['user_id' => $this->_id], ['_id']);
             if (count($ads) === 0) {
                 $delete = true;
             } else {
                 $in = array_keys($ads);
                 $in = Db::convertType($in, 'id');
                 $clickCount = Click::count(['adid' => ['$in' => $in]]);
                 if ($clickCount === 0) {
                     Commission::deleteAll(['ad_id' => ['$in' => $in]]);
                     $delete = true;
                 }
             }
             break;
     }
     if ($delete) {
         parent::delete();
         foreach ($deleteList as $table) {
             $table::deleteAll($query);
         }
     }
     return $delete;
 }
Example #10
0
 /**
  * @before _secure
  */
 public function manage()
 {
     $this->seo(['title' => 'Campaign: List', 'description' => 'Manage campaigns']);
     $view = $this->getActionView();
     $campaigns = [];
     $page = RM::get("page", 1);
     $limit = RM::get("limit", 10);
     $property = RM::get("property");
     $value = RM::get("value");
     switch (RM::get("sort")) {
         case 'trending':
             $start = RM::get("start", date("Y-m-d", strtotime('now')));
             $end = RM::get("end", date("Y-m-d", strtotime('now')));
             $q = ['start' => $start, 'end' => $end];
             $view->set($q);
             // Only find the ads for this organizations
             $allAds = \Ad::all(['org_id' => $this->org->_id], ['_id']);
             $in = Db::convertType(array_keys($allAds));
             $clickCol = Db::collection('Click');
             $match = ['created' => Db::dateQuery($start, $end), 'is_bot' => false, 'adid' => ['$in' => $in]];
             $records = $clickCol->aggregate([['$match' => $match], ['$project' => ['adid' => 1, '_id' => 0]], ['$group' => ['_id' => '$adid', 'count' => ['$sum' => 1]]], ['$sort' => ['count' => -1]], ['$limit' => (int) $limit]]);
             foreach ($records as $r) {
                 $arr = Utils::toArray($r);
                 $id = Utils::getMongoID($arr['_id']);
                 $campaigns[] = Ad::first(["id = ?" => $id]);
             }
             $count = $limit;
             break;
         default:
             $query = ["org_id = ?" => $this->org->id];
             if (in_array($property, ["user_id", "live", "id"])) {
                 $query[$property] = $value;
             } else {
                 if (in_array($property, ["url", "title"])) {
                     $query[$property] = Utils::mongoRegex(preg_quote($value));
                 }
             }
             $campaigns = \Ad::all($query, [], 'created', 'desc', $limit, $page);
             $count = \Ad::count($query);
             break;
     }
     $categories = \Category::all(['org_id' => $this->org->_id], ['_id', 'name']);
     $active = \Ad::count(["org_id = ?" => $this->org->id, "live = ?" => 1]);
     $inactive = \Ad::count(["org_id = ?" => $this->org->id, "live = ?" => 0]);
     $view->set("campaigns", $campaigns)->set("count", $count)->set("active", $active)->set("inactive", $inactive)->set("limit", $limit)->set("page", $page)->set("property", $property)->set("value", $value)->set("categories", $categories);
 }
Example #11
0
 public function links()
 {
     $this->seo(array("title" => "Tracking Links"));
     $view = $this->getActionView();
     $links = Link::all(['user_id' => $this->user->_id], ['ad_id', 'domain', '_id']);
     $in = ArrayMethods::arrayKeys($links, 'ad_id');
     $ads = Ad::all(['_id' => ['$in' => $in]], ['title', '_id']);
     $result = [];
     foreach ($links as $l) {
         $adid = $l->ad_id;
         $result[] = ArrayMethods::toObject(['title' => $ads[$adid]->title, 'url' => $l->getUrl()]);
     }
     $view->set('links', $result);
     if ($this->defaultExtension === "csv") {
         $view->erase('start')->erase('end');
         $this->_org = $this->_user = null;
     }
 }
Example #12
0
 /**
  * @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;
     }
 }