/** * send notification */ public function execute() { // normal google hub \PubSubHubbub::push("http://pubsubhubbub.appspot.com/", "hub.mode=publish&hub.url=" . urlencode("http://api." . \sfConfig::get("app_settings_host") . "/feeds/global")); \PubSubHubbub::push("http://pubsubhubbub.superfeedr.com/", "hub.mode=publish&hub.url=" . urlencode("http://api." . \sfConfig::get("app_settings_host") . "/feeds/global")); // @todo googles Social Data Hub // \PubSubHubbub::push("http://pshbsubber.appspot.com/sub/spreadly", "", array("X-Hub-Signature" => "sha1=secret_checksum")); $dm = \MongoManager::getDM(); $ya = $dm->getRepository("Documents\\YiidActivity")->find(new \MongoId($this->getYiidActivityId())); if (!$ya) { return false; } // send webmentions or pingbacks $mc = new \MentionClient(\sfConfig::get('app_settings_my_url') . "/share/" . $ya->getId()); $mc->sendSupportedMentions($ya->getUrl()); $dp = $ya->getDomainProfile(); if (!$dp) { return false; } $ds = $dp->getDomainSubscriptions(); if (!$ds) { return false; } foreach ($ds as $s) { $info = \PubSubHubbub::push($s->getCallback(), $this->toJson($ya), array("Content-Type: application/json")); // all good -- anything in the 200 range if (substr($info['http_code'], 0, 1) == "2") { $this->finished(); } elseif ($info['http_code'] == 408) { $this->reschedule(array("code" => 408, "message" => "Server Timeout")); } else { $this->failed(array("code" => $info['http_code'], "message" => "PuSH failed")); } } }
public function executeAds(sfWebRequest $request) { $id = $request->getParameter("id"); $this->ad_code = '<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>'; $this->setLayout(false); if (!$id) { return sfView::SUCCESS; } $dm = MongoManager::getDM(); $ad = $dm->getRepository("Documents\\Advertisement")->find(new MongoId($id)); if (!$ad) { return sfView::SUCCESS; } $ad->save(); $this->ad_code = $ad->getAdCode(); }
public function executeAtom_feed($request) { $id = $request->getParameter("id"); $user = UserTable::retrieveByUsername($id); $this->forward404Unless($user); $this->activities = MongoManager::getDM()->getRepository('Documents\\YiidActivity')->findLatestByUserId($user->getId()); $this->user = $user; $this->setLayout("atom_layout"); }
public function executeCoupon(sfWebRequest $request) { $this->getResponse()->setSlot('js_document_ready', $this->getPartial('deal/js_init_deal.js')); $dm = MongoManager::getDM(); $activity = $dm->getRepository('Documents\\YiidActivity')->find($request->getParameter('id')); if ($activity) { $this->deal = $activity->getDeal(); } else { $this->setTemplate('default_deal'); } }
/** * Executes index action * * @param sfRequest $request A request object */ public function executeHost(sfWebRequest $request) { $social_object = MongoManager::getDM()->getRepository('Documents\\SocialObject'); $this->forward404Unless($request->getParameter("id")); $so = $social_object->find(new MongoId($request->getParameter("id"))); $this->forward404Unless($so); $this->social_object = $so; $this->social_objects = $social_object->findBy(array("url" => array('$regex' => parse_url($so->getUrl(), PHP_URL_HOST))))->limit(10)->sort(array("u" => -1)); $this->first_share = MongoManager::getStatsDM()->getRepository('Documents\\AnalyticsActivity')->findBy(array("host" => parse_url($so->getUrl(), PHP_URL_HOST)))->sort(array("date" => 1))->limit(1)->getNext(); $this->last_share = MongoManager::getStatsDM()->getRepository('Documents\\AnalyticsActivity')->findBy(array("host" => parse_url($so->getUrl(), PHP_URL_HOST)))->sort(array("date" => -1))->limit(1)->getNext(); $us = MongoManager::getStatsDM()->getRepository('Documents\\UrlSummary'); $this->url_summarys = $us->findBy(array("host" => parse_url($so->getUrl(), PHP_URL_HOST)))->limit(10)->sort(array("mp" => -1)); $hs = MongoManager::getStatsDM()->getRepository('Documents\\HostSummary'); $this->host_summary = $hs->findOneBy(array("host" => parse_url($so->getUrl(), PHP_URL_HOST))); }
/** * 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")))); }
/** * Executes index action * * @param sfRequest $request A request object */ public function executeCounter(sfWebRequest $request) { $this->getResponse()->setContentType('application/json'); $this->setLayout(false); $url = $request->getParameter("url", null); if (!$url) { $this->getResponse()->setStatusCode(409); return sfView::ERROR; } $dm = MongoManager::getDM(); $social_object = $dm->getRepository("Documents\\SocialObject")->findOneByUrl($url); if ($social_object) { $this->getResponse()->setStatusCode(200); $this->response_array = array("success" => array("code" => 200, "message" => "URL shared"), "counter" => $social_object->getLikeCount()); } else { $this->getResponse()->setStatusCode(204); $this->response_array = array("success" => array("code" => 204, "message" => "URL not yet shared"), "counter" => 0); } }
private function createCommission($analyticsActivity) { if ($analyticsActivity) { $yiidActivity = MongoManager::getDM()->getRepository("Documents\\YiidActivity")->find($analyticsActivity->getYiidActivityId()); $commissionValue = $this->getBillingType() == DealTable::BILLING_TYPE_LIKE ? $this->commission_per_unit : $this->commission_per_unit * $analyticsActivity->getMediaPenetration(); if ($this->commission_pot < $commissionValue) { $commissionValue = $this->commission_pot; } if ($commissionValue > 0) { $commission = new Commission(); $commission->setPrice($commissionValue); $commission->setDomainProfileId($yiidActivity->getIId()); $commission->setDealId($this->getId()); $commission->setYaId($yiidActivity->getId()); $commission->save(); $this->commission_pot -= $commissionValue; } } }
public function getLatestYiidActivity() { return \MongoManager::getDM()->getRepository("Documents\\YiidActivity")->findOneBy(array('social_object.$id' => new \MongoId($this->getId()))); }
public function executeSubscribe_api(sfWebRequest $request) { $dm = MongoManager::getDM(); $this->pHostId = $request->getParameter('host_id'); $this->pDomainProfile = Doctrine::getTable('DomainProfile')->find($this->pHostId); //gibt es nen endpoint? sollte mit in domain-profile-object und muss auch in index für die tabelle gesetzt sein pro domain-profile $this->pEndpoint = DomainSubscriptionsTable::getInstance()->findOneBy("domain_profile_id", $this->pDomainProfile->getId()); $this->pOk = $dm->getRepository("Documents\\PushJob")->countValidPuSHsLast24h($this->pHostId); $this->pTimeout = $dm->getRepository("Documents\\PushJob")->countTimeoutPuSHsLast24h($this->pHostId); $this->pResponseFail = $dm->getRepository("Documents\\PushJob")->countFailedPuSHsLast24h($this->pHostId); }
public function executeGlobal() { $lDm = MongoManager::getDM(); $this->activities = $lDm->getRepository("Documents\\YiidActivity")->findAll()->sort(array("c" => -1))->limit(100); $this->setLayout("atom_layout"); }
/** * Executes index action * * @param sfRequest $request A request object */ public function executeIndex(sfWebRequest $request) { $lDm = MongoManager::getDM(); $this->pErrors = $lDm->createQueryBuilder("Documents\\ApiErrorLog")->find()->sort(array("c" => -1))->limit(30)->getQuery()->execute(); }
$dm = MongoManager::getDM(); for ($i = 0; $i < 5; $i++) { $yas = $dm->getRepository('Documents\\YiidActivity')->findBy(array("social_object" => array('$exists' => false)))->limit(10); if (!$yas->hasNext()) { print_r("PFEFFI_SAYS_ITS_DONE"); return; } print_r("\n\n"); foreach ($yas as $ya) { try { @StatsFeeder::feed($ya); if (@($so = MongoManager::getDM()->getRepository("Documents\\SocialObject")->find($ya->getSoId()))) { @$ya->setSocialObject($so); @$ya->save(); unset($so); } else { $ya->upsertSocialObject(); $ya->save(); } print_r("yiid-activity: " . $ya->getId() . "\n"); unset($ya); } catch (Exception $e) { if (@($so = MongoManager::getDM()->getRepository("Documents\\SocialObject")->find($ya->getSoId()))) { @$ya->setSocialObject($so); @$ya->save(); unset($so); } print_r($e->getMessage()); } } }
public function getLikeCount() { $dm = MongoManager::getDM(); return $dm->getRepository("Documents\\YiidActivity")->findBy(array("u_id" => intval($this->getId())))->count(); }
/** * Imports all likes from a facebook account to store it in the mongodb * * @param int $online_identity */ public static function importInterests($online_identity) { $token = AuthTokenTable::getByUserAndOnlineIdentity($online_identity->getUserId(), $online_identity->getId()); if (!$token) { $online_identity->deactivate(); throw new Exception('damn theres no token!', '666'); } // get likes $response = UrlUtils::sendGetRequest("https://graph.facebook.com/me/likes?access_token=" . $token->getTokenKey()); // mongo manager $dm = MongoManager::getDM(); // check likes if ($response && ($objects = json_decode($response, true))) { if (!isset($objects['data'])) { return false; } // iterate and save in mongodb foreach ($objects["data"] as $object) { $interest = $dm->getRepository('Documents\\Interest')->upsert($object); // check interest if ($interest) { $user_interest = $dm->getRepository('Documents\\UserInterest')->upsert($online_identity, $interest); } } } return; }
/** * A nicer way to delete the object */ public function delete() { $dm = \MongoManager::getDM(); $dm->remove($this); $dm->flush(); }
public function getSpreadCount() { $yiid_activity_repo = MongoManager::getDM()->getRepository('Documents\\YiidActivity'); return $yiid_activity_repo->countByOnlineIdentityIds(array($this->getId())); }
public function generateErrorLog() { $lUserHugo = UserTable::retrieveByUsername('hugo'); $lHugoOis = $lUserHugo->getOnlineIdentities(); $lHugoOi = $lHugoOis[0]; for ($i = 0; $i <= 100; $i++) { $lError = new Documents\ApiErrorLog(); $lError->setCode($i); $lError->setMessage("I Pity the Fool"); $lError->setOiId($lHugoOi->getId()); $lError->setUId($lUserHugo->getId()); $dm = MongoManager::getDM(); $dm->persist($lError); $dm->flush(); } }
<?php /** * a batch file to send an email if a deal is expired * * @author Matthias Pfefferle */ require_once dirname(__FILE__) . '/../../config/ProjectConfiguration.class.php'; $configuration = ProjectConfiguration::getApplicationConfiguration('statistics', 'dev', false); sfContext::createInstance($configuration); $dm = MongoManager::getDM(); $logger = sfContext::getInstance()->getLogger(); $deals = DealTable::getInstance()->getExpiredDealsByExpirationDate(); $message = null; foreach ($deals as $deal) { $message .= "http://spreadly.com/backend.php/deal/" . $deal->getId() . "/edit \n"; } if ($message) { sfContext::getInstance()->getMailer()->composeAndSend($sender = array(sfConfig::get("app_email_address") => sfConfig::get("app_email_sender")), sfConfig::get("app_settings_support_email"), '[expired deals]', $message); }
/** * Applies the alarming attribute to a given query retrieving products. * * @param Doctrine_Query $query - query to have alarming attribute applied. * @param Integer $value - alarming? */ public function applyDealIdFilter($query, $value) { $rootAlias = $query->getRootAlias(); $dm = MongoManager::getDM(); $yas = $dm->getRepository('Documents\\YiidActivity')->findBy(array('d_id' => intval($value))); $user_ids = array(); foreach ($yas as $ya) { $user_ids[] = $ya->getUId(); } $user_ids = array_unique($user_ids); if (count($user_ids) == 0) { $user_ids[] = -1; } $query->whereIn($rootAlias . '.id', $user_ids); return $query; }
public function getYiidActivity() { $dm = \MongoManager::getDM(); return $dm->getRepository("Documents\\YiidActivity")->find(new \MongoId($this->getYiidActivityId())); }