Exemplo n.º 1
0
 public function createSubmit()
 {
     $name = isset($_POST['name']) ? $_POST['name'] : '';
     $description = isset($_POST['description']) ? $_POST['description'] : '';
     $type = isset($_POST['type']) ? $_POST['type'] : HouseAd::HOUSEAD_TYPE_ICON;
     $link = isset($_POST['link']) ? $_POST['link'] : '';
     $linkType = isset($_POST['linkType']) ? $_POST['linkType'] : HouseAd::HOUSEAD_LINKTYPE_WEBSITE;
     $imageLink = isset($_POST['imageLink']) ? $_POST['imageLink'] : '';
     $houseAd = new HouseAd();
     $houseAd->id = SDB::uuid();
     $houseAd->uid = $_SESSION['uid'];
     $houseAd->name = $name;
     $houseAd->description = $description;
     $houseAd->type = $type;
     $houseAd->link = HouseAdUtil::getFixedLink($link, $linkType);
     $houseAd->linkType = $linkType;
     $houseAd->launchType = HouseAdUtil::getLaunchType($linkType);
     $houseAd->imageLink = $imageLink;
     $result = $houseAd->put();
     $aids_of_apps_to_add = isset($_POST['apps']) ? $_POST['apps'] : null;
     AppHouseAdUtil::addRemoveAppHouseAds($houseAd->id, $aids_of_apps_to_add, array());
     fb($houseAd);
     $this->redirect($_REQUEST['returnPage'] . '?&n_cid=' . $houseAd->id . '&n_name=' . $houseAd->name . '&n_type=' . $houseAd->type . '&n_linkType=' . $houseAd->linkType);
 }
 public static function addRemoveAppHouseAds($cid, $aids_of_apps_to_add, $ahids_of_appHouseAds_to_delete)
 {
     fb("AppHouseAdUtil", "addRemoveAppHouseAds");
     $ret = array();
     if (isset($aids_of_apps_to_add) && isset($cid)) {
         foreach ($aids_of_apps_to_add as $aid) {
             fb("Adding", $aid);
             $sum = 0;
             $appHouseAds = AppHouseAdUtil::getAppHouseAdsByAid($aid);
             foreach ($appHouseAds as $appHouseAd) {
                 $sum += $appHouseAd->weight;
             }
             $appHouseAd = new AppHouseAd();
             $appHouseAd->id = SDB::uuid();
             $appHouseAd->cid = $cid;
             $appHouseAd->aid = $aid;
             $appHouseAd->weight = 100 - $sum;
             // if the app has no ads then 100% otherwise 0%
             $appHouseAd->put();
             fb('new_appHouseAd', $appHouseAd);
             $app = new App($aid);
             $ret[$aid] = $app->adjustHouseAdNetwork($appHouseAd->id, null);
         }
     }
     fb("appHouseAdsToDelete", $ahids_of_appHouseAds_to_delete);
     if (isset($ahids_of_appHouseAds_to_delete)) {
         foreach ($ahids_of_appHouseAds_to_delete as $ahid) {
             fb("Removing", $ahid);
             $appHouseAd = new AppHouseAd($ahid);
             $aid = $appHouseAd->aid;
             $removed_weight = floatval($appHouseAd->weight);
             $appHouseAd->delete();
             $app = new App($aid);
             $ret[$aid] = $app->adjustHouseAdNetwork(null, $ahid);
             $appHouseAds = AppHouseAdUtil::getAppHouseAdsByAid($aid);
             fb("apphouseAds", $appHouseAds);
             $non_zero_appHouseAds = array();
             $total = 0;
             foreach ($appHouseAds as $key => $appHouseAd) {
                 if ($appHouseAd->id == null) {
                     continue;
                 }
                 if ($appHouseAd->id == $ahid) {
                     unset($appHouseAds[$key]);
                     continue;
                 }
                 if ($appHouseAd->weight > 0) {
                     $total += intval($appHouseAd->weight);
                     $non_zero_appHouseAds[] = $appHouseAd;
                 }
             }
             fb("non_zero", $non_zero_appHouseAds);
             if (count($non_zero_appHouseAds) > 0) {
                 $appHouseAds_to_increase = $non_zero_appHouseAds;
             } else {
                 // no non_zero
                 $appHouseAds_to_increase = $appHouseAds;
             }
             if (count($appHouseAds_to_increase) == 0) {
                 continue;
             }
             fb("non_zero", $non_zero_appHouseAds);
             $last = end($appHouseAds_to_increase);
             $sum = 0;
             fb("increase-rem weight", $removed_weight);
             fb("total", $total);
             $inc = $removed_weight / count($appHouseAds_to_increase);
             fb("inc", $inc);
             fb('count', count($appHouseAds_to_increase));
             foreach ($appHouseAds_to_increase as $appHouseAd) {
                 fb("aha", $appHouseAd);
                 if ($appHouseAd != $last) {
                     $weight = intval($appHouseAd->weight);
                     fb("old_weight", $weight);
                     $weight = intval($inc + $weight);
                     fb("new_weight", $weight);
                     $sum += $weight;
                     fb("sum", $sum);
                     $appHouseAd->weight = strval($weight);
                 } else {
                     $appHouseAd->weight = strval(100 - $sum);
                 }
                 $appHouseAd->put();
             }
         }
     }
     return $ret;
 }
Exemplo n.º 3
0
 public function createSubmit()
 {
     if (isset($_REQUEST['n_aid']) || !isset($_REQUEST['name'])) {
         $this->redirect('/apps/apps');
     }
     $this->printHeader = false;
     $this->printFooter = false;
     $name = $_POST['name'];
     $storeUrl = $_POST['storeUrl'];
     $platform = $_POST['platform'];
     $fgColor = $_POST['fgColor'];
     $bgColor = $_POST['bgColor'];
     $cycleTime = $_POST['cycleTime'];
     $transition = $_POST['transition'];
     $locationOn = $_POST['locationOn'];
     $app = new App();
     $app->id = SDB::uuid();
     $app->uid = $this->user->id;
     $app->name = $name;
     $app->storeUrl = $storeUrl;
     $app->platform = $platform;
     $app->fgColor = $fgColor;
     $app->bgColor = $bgColor;
     $app->cycleTime = $cycleTime;
     $app->transition = $transition;
     $app->locationOn = $locationOn;
     $app->adsOn = 1;
     $app->put();
     $_POST['aid'] = $app->id;
     // before finishing, check to see if the new app has been added to th SDB
     $sdb = SDB::getInstance();
     // sleeps for half a second until we see an entry for this id
     $fields = "name";
     while (!$sdb->get($app->getSDBDomain(), $app->id, $fields)) {
         $fields = "name";
         // necessary since get overwrites $fields
         usleep(500);
     }
 }
Exemplo n.º 4
0
 public function adjustHouseAdNetwork($add_ahid, $del_ahid)
 {
     $retVal = "doNothing";
     fb("adjusthouseAdNet", "start");
     $networks = $this->getNetworks();
     if ($networks != null) {
         foreach ($networks as $type => $network) {
             if ($type == Network::NETWORK_TYPE_HOUSE) {
                 $houseAdNet = $network;
             }
         }
     }
     $appHouseAds = AppHouseAdUtil::getAppHouseAdsByAid($this->id);
     $count = count($appHouseAds);
     if ($count == 0 && $add_ahid != null) {
         $count++;
     } else {
         if ($count == 1 && $appHouseAds['0']->id == $del_ahid) {
             $count--;
         }
     }
     fb("appHouseAds", $appHouseAds);
     fb($count, 'count');
     fb(isset($houseAdNet), 'hasHouseAdNet');
     if ($count > 0 && !isset($houseAdNet)) {
         // add houseAdNet
         fb("Should Add");
         $network = new Network();
         $network->id = SDB::uuid();
         $network->aid = $this->id;
         $network->type = Network::NETWORK_TYPE_HOUSE;
         $network->adsOn = 0;
         $network->weight = 0;
         $network->priority = 99;
         $network->keys = array("_CUSTOMS_");
         $network->put();
         $retVal = "add";
     } else {
         if ($count == 0 && isset($houseAdNet)) {
             // should remove or turn off
             $hasHouseAds = count(HouseAdUtil::getHouseAdsByUid($_SESSION['uid'])) > 0;
             if ($hasHouseAds) {
                 fb("should turn off");
                 $houseAdNet->adsOn = 0;
                 $houseAdNet->put();
                 $retVal = "turnOff";
             } else {
                 fb("Should Remove", $houseAdNet);
                 $houseAdNet->delete();
                 unset($networks['9']);
                 $retVal = "delete";
             }
             App::setWeights($networks);
             App::setPriorities($networks);
         }
     }
     fb("adjustHouseAdNet", "end");
     return $retVal;
 }
 public static function registerNewUser($email, $firstName, $lastName, $password, $allowEmail)
 {
     $sdb = SDB::getInstance();
     $user = new User($email);
     if ($user->id != null) {
         return false;
     }
     $uid = SDB::uuid();
     $password = User::getHashedPassword($password);
     $aa = array('email' => $email, 'password' => $password, 'allowEmail' => $allowEmail, 'firstName' => $firstName, 'lastName' => $lastName, 'createdAt' => date('Y-m-d'));
     $sdb->put(self::$DOMAIN_USERS_UNVERIFIED, $uid, $aa, true);
     $activationLink = 'http://' . $_SERVER['HTTP_HOST'] . '/home/register/confirm?uid=' . $uid;
     $to = $email;
     $subject = 'AdWhirl Account Registration';
     $message = "Hello iPhone and Android Developer,\n\nThanks for registering with AdWhirl. Click on the link below to validate your email address and activate your account.\n\n{$activationLink}\n\nWe hope that you’ll find AdWhirl’s mediation very helpful in managing your ad inventory, as you can simultaneously run as many or as few ad networks as you’d like, and you’re also able to create and run your own house ads whenever you want to – all for free – and all open source.\n\nWe are spending a lot of time perfecting the library and the interface, and giving you, the developer, as many hooks as possible to optimize revenue. We’d love to hear from you with suggestions, feedback, anything! You can also contribute directly to the AdWhirl Open Source community on our project page (http://code.google.com/p/adwhirl/).\n\nIf you have any questions, or trouble logging in, please email us at support@adwhirl.com. \n\nHappy Advertising!\n\nAdWhirl Team";
     mail($to, $subject, $message);
     return true;
 }