/** * Executes index action * * @param sfRequest $request A request object */ public function executeIndex(sfWebRequest $request) { $this->getResponse()->setSlot('js_document_ready', $this->getPartial('deal/js_init_deal.js')); $url = $request->getParameter("url", null); // handle form submit if ($request->getMethod() == "POST") { $params = $request->getParameter('like'); $params['u_id'] = $this->getUser()->getUserId(); if ($url) { $params['i_url'] = $url; } $activity = new Documents\YiidActivity(); $activity->fromArray($params); // try to save activity try { $activity->save(); $this->redirect("@coupon?id=" . $activity->getId() . "&u_code=" . $activity->getCCode()); } catch (Exception $e) { // send error on exception $this->getLogger()->err($e->getMessage()); $this->redirect('@default_deal'); return sfView::SUCCESS; } } $deal = DealTable::getInstance()->getNextFromPool($this->getUser()->getUser(), $url); $this->deal = $deal; if (!$deal) { $this->hash = md5($this->getUser()->getId() . $url); $this->setTemplate('default_deal'); } }
/** * Executes index action * * @param sfRequest $request A request object */ public function executeIndex(sfWebRequest $request) { $lUrl = $request->getParameter("url", null); $lUrl = UrlUtils::narmalizeUrlScheme($lUrl); $request->setParameter("url", $lUrl); $this->url = $lUrl; $this->error = $this->pError = null; if (!$lUrl) { return $this->setTemplate("share"); } if ($request->getMethod() == "POST") { $lParams = $request->getParameter('like'); $lParams['u_id'] = $this->getUser()->getUserId(); $lActivity = new Documents\YiidActivity(); $lActivity->fromArray($lParams); // try to save activity try { $lActivity->save(); $this->redirect("@deal?url=" . urlencode($lUrl)); } catch (Exception $e) { // send error on exception $this->getLogger()->err($e->getMessage()); $this->pError = $e->getMessage(); } } $dm = MongoManager::getDM(); $this->pActivity = $dm->getRepository("Documents\\YiidActivity")->findOneBy(array("url" => $lUrl, "u_id" => intval($this->getUser()->getId()), "d_id" => array('$exists' => false))); // if user has already liked if ($this->pActivity) { $this->redirect("@deal?url=" . urlencode($lUrl)); } $lYiidMeta = new YiidMeta(); $lYiidMeta->fromParams($request->getParameterHolder()); $this->pYiidMeta = SocialObjectParser::fetch($request->getParameter("url"), $lYiidMeta); if ($this->pYiidMeta === false) { $this->error = "the url '{$lUrl}' is not well formed!"; return $this->setTemplate("share"); } $domainProfile = DomainProfileTable::getInstance()->retrieveByUrl($lUrl); $this->trackingUrl = null; if ($domainProfile) { $this->trackingUrl = $domainProfile->getTrackingUrl(); } $this->getResponse()->setSlot('js_document_ready', $this->getPartial('like/js_init_like.js', array('pImgCount' => count($this->pYiidMeta->getImages()), 'pUrl' => $request->getParameter("url")))); }
public function testPublisherDeals2() { $deal = DealTable::getInstance()->getNextFromPool($this->hugo, "http://www.missmotz.de/test"); $this->assertEquals($deal->getType(), DealTable::TYPE_PUBLISHER); $lActivity = new Documents\YiidActivity(); $lActivity->setUId($this->hugo->getId()); $lActivity->setDId($deal->getId()); $lActivity->setOiids($this->hugo->getOnlineIdentitesAsArray()); $lActivity->setIUrl('http://www.missmotz.de/test'); $lActivity->save(); $deal = DealTable::getInstance()->getNextFromPool($this->hugo, "http://www.missmotz.de/test"); $this->assertEquals($deal->getType(), DealTable::TYPE_POOL); }
protected function execute($arguments = array(), $options = array()) { try { sfContext::getInstance(); } catch (Exception $e) { // aize the database connection $configuration = ProjectConfiguration::getApplicationConfiguration($options['application'], $options['env'], true); sfContext::createInstance($configuration); } $databaseManager = new sfDatabaseManager($this->configuration); $databaseManager->loadConfiguration(); $connection = $databaseManager->getDatabase($options['connection'])->getConnection(); $originalPostToServicesValue = sfConfig::get('app_settings_post_to_services'); sfConfig::set('app_settings_post_to_services', 0); $this->log("Using mongo host: " . sfConfig::get('app_mongodb_host')); $lUserHugo = UserTable::retrieveByUsername('hugo'); $lHugoOis = $lUserHugo->getOnlineIdentitesAsArray(); $lUserJames = UserTable::retrieveByUsername('james'); $lJamesOis = $lUserJames->getOnlineIdentitesAsArray(); $lCommunityTwitter = CommunityTable::retrieveByCommunity('twitter'); $lCommunityFb = CommunityTable::retrieveByCommunity('facebook'); $lOiHugoTwitter = OnlineIdentityTable::retrieveByAuthIdentifier('http://twitter.com/account/profile?user_id=21092406', $lCommunityTwitter->getId()); $lOiJamesFacebook = OnlineIdentityTable::retrieveByAuthIdentifier('james_fb', $lCommunityFb->getId()); $urls = array('www.snirgel.de', 'notizblog.org', 'www.missmotz.de'); $tags = array('geekstuff', 'otherthings', 'schuhe'); $users = array($lUserHugo, $lUserJames); $services = array('facebook', 'twitter', 'linkedin', 'google'); $deals = array('Campaign No. 1', 'Campaign No. 2', 'Campaign No. 3'); $dm = MongoManager::getDM(); for ($i = 0; $i < 100; $i++) { $url = $this->oneOfThese($urls); $tag = $this->oneOfThese($tags); $user = $this->oneOfThese($users); $cb_ref = $this->oneOfThese(array('', '', '', '', '', '', 'http://tierscheisse.de')); $ra = $this->random(1000); $theC = mt_rand(strtotime("3 days ago"), strtotime("today")); $array = array('url' => "http://{$url}/{$ra}", 'url_hash' => "hash.{$ra}", 'u_id' => $user->getId(), 'oiids' => $user->getOnlineIdentitesAsArray(), 'tags' => $tag . $ra, 'title' => "{$url} title", 'descr' => "{$url} description", 'comment' => "{$url} comment", 'c' => $theC, 'cb' => $this->randBoolean() ? $this->random(30) : 0, 'cb_referer' => $cb_ref != '' ? $cb_ref : null, 'cb_service' => $cb_ref != '' ? $this->oneOfThese($services) : null); $lActivity = new Documents\YiidActivity(); $lActivity->fromArray($array); try { $lActivity->skipUrlCheck = true; $lActivity->save(); } catch (Exception $e) { $this->log($e->getMessage()); } } // same for deals for ($i = 0; $i < 100; $i++) { $url = $this->oneOfThese($urls); $tag = $this->oneOfThese($tags); $user = $this->oneOfThese($users); $cb_ref = $this->oneOfThese(array('', '', '', '', '', '', 'http://tierscheisse.de')); $i_url = $this->oneOfThese(array('http://ard.de', 'http://bild.de', 'http://spiegel.de', 'http://tierscheisse.de')); $ra = $this->random(1000); $theC = mt_rand(strtotime("3 days ago"), strtotime("today")); $deal = DealTable::getInstance()->findOneByName($this->oneOfThese($deals)); $array = array('url' => "http://{$url}/{$ra}", 'url_hash' => "hash.{$ra}", 'u_id' => $user->getId(), 'oiids' => $user->getOnlineIdentitesAsArray(), 'tags' => $tag . $ra, 'title' => "{$url} title", 'descr' => "{$url} description", 'comment' => "{$url} comment", 'c' => $theC, 'd_id' => $deal->getId(), 'cb' => $this->randBoolean() ? $this->random(30) : 0, 'cb_referer' => $cb_ref != '' ? $cb_ref : null, 'i_url' => $i_url, 'cb_service' => $cb_ref != '' ? $this->oneOfThese($services) : null); $lActivity = new Documents\YiidActivity(); $lActivity->fromArray($array); try { $lActivity->skipUrlCheck = true; $lActivity->save(); } catch (Exception $e) { $this->log($e->getMessage()); } } $ds = new Documents\DomainSettings(); $ds->setDomain("blog.local"); $ds->setMute(0); $ds->save(); $ds = new Documents\DomainSettings(); $ds->setDomain("pfefferle.org"); $ds->setDisableAds(true); $ds->save(); $ad = new Documents\Advertisement(); $ad->setDomains(array("pfefferle.org", "notizblog.org", "www.spiegel.de", "blog.local")); $ad->setAdCode('<script type="text/javascript" src="http://a.ligatus.com/?ids=34548&t=js"></script>'); $ad->setUpdatedAt(strtotime("now")); $ad->setStartingAt(strtotime("now")); $ad->setAdHeight(500); $ad->setAdWidth(50); $ad->save(); $ad = new Documents\Advertisement(); $ad->setDomains(array("blog.local")); $ad->setAdCode("<script type='text/javascript' src='http://imagesrv.adition.com/js/adition.js'></script>\n<script type='text/javascript' src='http://ad4.adfarm1.adition.com/js?wp_id=744125'></script>"); $ad->setUpdatedAt(strtotime("now")); $ad->setStartingAt(strtotime("now")); $ad->setAdHeight(100); $ad->setAdWidth(800); $ad->save(); $ad = new Documents\Advertisement(); $ad->setDomains(array("pfefferle.org", "notizblog.org", "www.spiegel.de", "blog.local")); $ad->setAdCode('<script type="text/javascript"><!-- google_ad_client = "ca-pub-1406192967534280"; /* spreadly */ google_ad_slot = "7458728780"; google_ad_width = 250; google_ad_height = 250; //--> </script> <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script>'); $ad->setUpdatedAt(strtotime("now")); $ad->setStartingAt(strtotime("now")); $ad->setAdHeight(250); $ad->setAdWidth(250); $ad->save(); /* $lActivity = new Documents\YiidActivity(); $lActivity->fromArray($array); $lActivity->save(); $array = array( 'url' => "http://$url", 'oiids' => array($lOiJamesFacebook->getId()), 'title' => "$url deal title", 'descr' => "$url description", 'comment' => "$url comment", 'thumb' => null, 'clickback' => null, 'tags' => null, 'u_id' => $lUserJames->getId() ); $lActivity = new Documents\YiidActivity(); $lActivity->fromArray($array); $lActivity->save(); if($deal[0]->canApprove()) { $deal[0]->approve(); } $url = 'notizblog.org'; $array = array( 'url' => "http://$url", 'oiids' => array($lOiHugoTwitter->getId()), 'title' => "$url deal title", 'descr' => "$url description", 'comment' => "$url comment", 'thumb' => null, 'clickback' => null, 'tags' => null, 'u_id' => $lUserHugo->getId() ); $lActivity = new Documents\YiidActivity(); $lActivity->fromArray($array); $lActivity->save(); $deal = DealTable::getInstance()->findByDescription('missmotz approved description'); if($deal[0]->canApprove()) { $deal[0]->approve(); } $url = 'www.missmotz.de'; $array = array( 'url' => "http://$url", 'oiids' => array($lOiHugoTwitter->getId()), 'title' => "$url deal title", 'descr' => "$url description", 'comment' => "$url comment", 'thumb' => null, 'clickback' => null, 'tags' => "Schuhe, Hemden", 'u_id' => $lUserHugo->getId() ); $lActivity = new Documents\YiidActivity(); $lActivity->fromArray($array); $lActivity->save(); */ sfConfig::set('app_settings_post_to_services', $originalPostToServicesValue); $this->generateErrorLog(); }