public function UpdateStatistics() { global $database, $cphp_config; if (!empty($cphp_config->debugmode) || $this->sLastStatisticsUpdate < time() - 60 * 5) { /* Update subscriber count */ if ($result = $database->CachedQuery("SELECT COUNT(*) FROM subscriptions WHERE `CampaignId` = :CampaignId AND `Confirmed` = 1 AND `Active` = 1", array(":CampaignId" => $this->sId))) { $this->uSubscriberCount = $result->data[0]["COUNT(*)"]; } /* Update total monthly donations */ try { $sSubscriptions = Subscription::CreateFromQuery("SELECT * FROM subscriptions WHERE `CampaignId` = :CampaignId AND `Confirmed` = 1 AND `Active` = 1", array(":CampaignId" => $this->sId)); $sTotalDonations = 0; foreach ($sSubscriptions as $sSubscription) { $sTotalDonations += Currency::Convert("usd", $sSubscription->sCurrency, $sSubscription->sAmount); } $this->uMonthlyTotal = $sTotalDonations; } catch (NotFoundException $e) { $this->uMonthlyTotal = 0; } /* Update donation rate */ try { $sDonationsAsked = LogEntry::CreateFromQuery("SELECT * FROM log_entries WHERE `CampaignId` = :CampaignId AND `Type` = :Type AND `Date` > DATE_SUB(NOW(), INTERVAL 1 MONTH)", array(":CampaignId" => $this->sId, ":Type" => LogEntry::DONATION_ASKED)); $have_data = true; } catch (NotFoundException $e) { /* We don't have any data to work from yet. */ $sDonationsAsked = array(); $have_data = false; } if ($have_data) { try { $sDonationsMade = LogEntry::CreateFromQuery("SELECT * FROM log_entries WHERE `CampaignId` = :CampaignId AND `Type` = :Type AND `Date` > DATE_SUB(NOW(), INTERVAL 1 MONTH)", array(":CampaignId" => $this->sId, ":Type" => LogEntry::DONATION_MADE)); $this->uDonationRate = count($sDonationsMade) / count($sDonationsAsked) * 100; $this->uHaveData = true; } catch (NotFoundException $e) { $sDonationsMade = array(); $this->uDonationRate = 0; $this->uHaveData = false; } } else { $sDonationsMade = array(); $this->uDonationRate = 100; $this->uHaveData = false; } /* Update projected monthly donations */ $this->uMonthlyProjection = $this->uMonthlyTotal * ($this->uDonationRate / 100); /* Update past-month subscription count */ if ($result = $database->CachedQuery("SELECT COUNT(*) FROM log_entries WHERE `CampaignId` = :CampaignId AND `Type` = :Type AND `Date` > DATE_SUB(NOW(), INTERVAL 1 MONTH)", array(":CampaignId" => $this->sId, ":Type" => LogEntry::SUBSCRIPTION_CONFIRMED), 0)) { $this->uPastMonthSubscriptions = $result->data[0]["COUNT(*)"]; } /* Update past-month unsubscription count */ if ($result = $database->CachedQuery("SELECT COUNT(*) FROM log_entries WHERE `CampaignId` = :CampaignId AND `Type` = :Type AND `Date` > DATE_SUB(NOW(), INTERVAL 1 MONTH)", array(":CampaignId" => $this->sId, ":Type" => LogEntry::UNSUBSCRIPTION), 0)) { $this->uPastMonthUnsubscriptions = $result->data[0]["COUNT(*)"]; } /* Update past month donation count */ $this->uPastMonthDonations = count($sDonationsMade); /* Update past month non-donation count */ $this->uPastMonthNonDonations = count($sDonationsAsked) - count($sDonationsMade); $this->uLastStatisticsUpdate = time(); $this->InsertIntoDatabase(); } }
<?php /* * ReDonate is more free software. It is licensed under the WTFPL, which * allows you to do pretty much anything with it, without having to * ask permission. Commercial use is allowed, and no attribution is * required. We do politely request that you share your modifications * to benefit other developers, but you are under no enforced * obligation to do so :) * * Please read the accompanying LICENSE document for the full WTFPL * licensing text. */ if (!isset($_APP)) { die("Unauthorized."); } try { $sPaymentMethod = $sPaymentRequest->sCampaign->GetPaymentMethod(PaymentMethod::BITCOIN); } catch (NotFoundException $e) { throw new RouterException("No such payment method found."); } if ($sPaymentRequest->sCurrency != "btc") { $sAmount = Currency::Convert("btc", $sPaymentRequest->sCurrency, $sPaymentRequest->sAmount); } else { $sAmount = $sPaymentRequest->sAmount; } $sPageContents = NewTemplater::Render("payment/bitcoin", $locale->strings, array("address" => $sPaymentMethod->sAddress, "amount" => Currency::Format("btc", $sAmount), "done-url" => "/pay/{$sPaymentRequest->sSubscription->sEmailAddress}/{$sPaymentRequest->sId}/{$sPaymentRequest->sKey}/bitcoin/done"));
$sAmount = urlencode($_POST['amount']); } $sQuotedRecipient = urlencode($sPaymentMethod->sAddress); $sQuotedName = urlencode("{$sCampaign->sName} (via ReDonate.net)"); $sQuotedNumber = urlencode("0"); $sQuotedReturnUrl = urlencode("http://redonate.net/thanks/{$sCampaign->sUrlName}"); if (filter_var($sPaymentMethod->sAddress, FILTER_VALIDATE_EMAIL)) { $target = "https://www.paypal.com/cgi-bin/webscr?business={$sQuotedRecipient}&cmd=_donations&item_name={$sQuotedName}&item_number={$sQuotedNumber}¤cy_code={$sCurrency}&amount={$sAmount}&return={$sQuotedReturnUrl}"; } else { /* This is most likely a hosted button ID. We can only provide limited information in this case - we can really only set the item description. * Not sure if setting the return URL will work, but we might as well try. */ $target = "https://www.paypal.com/cgi-bin/webscr?hosted_button_id={$sQuotedRecipient}&cmd=_s-xclick&item_name={$sQuotedName}&return={$sQuotedReturnUrl}"; } redirect($target); return; case PaymentMethod::BITCOIN: if ($sPaymentRequest->sCurrency != "btc") { $sAmount = Currency::Convert("btc", $_POST['currency'], $_POST['amount']); } else { $sAmount = htmlspecialchars($_POST['amount']); } $sPageContents = NewTemplater::Render("payment/bitcoin", $locale->strings, array("address" => $sPaymentMethod->sAddress, "amount" => Currency::Format("btc", $sAmount), "done-url" => "/thanks/{$sCampaign->sUrlName}")); return; default: $sPageContents = NewTemplater::Render("payment/other", $locale->strings, array("name" => $sPaymentMethod->sCustomName, "address" => $sPaymentMethod->sAddress, "amount" => Currency::Format($_POST['currency'], $_POST['amount']), "done-url" => "/thanks/{$sCampaign->sUrlName}")); return; } } } $sPageTitle = "Donate to {$sCampaign->sName} once"; $sPageContents = NewTemplater::Render("donate", $locale->strings, array("campaign-name" => $sCampaign->sName, "method-id" => $sPaymentMethod->sId, "urlname" => $sCampaign->sUrlName, "method-name" => $sMethodName));
* obligation to do so :) * * Please read the accompanying LICENSE document for the full WTFPL * licensing text. */ if (!isset($_APP)) { die("Unauthorized."); } try { $sPaymentMethod = $sPaymentRequest->sCampaign->GetPaymentMethod(PaymentMethod::PAYPAL); } catch (NotFoundException $e) { throw new RouterException("No such payment method found."); } if (strtolower($sPaymentRequest->sCurrency) == "btc") { $sCurrency = urlencode("USD"); $sAmount = round(Currency::Convert("usd", "btc", $sPaymentRequest->sAmount), 2); } else { $sCurrency = urlencode(strtoupper($sPaymentRequest->sCurrency)); $sAmount = urlencode($sPaymentRequest->sAmount); } $sQuotedRecipient = urlencode($sPaymentMethod->sAddress); $sQuotedName = urlencode("{$sPaymentRequest->sCampaign->sName} (via ReDonate.net)"); $sQuotedNumber = urlencode("{$sPaymentRequest->sId}"); $sQuotedReturnUrl = urlencode("http://redonate.net/pay/{$sPaymentRequest->sSubscription->sEmailAddress}/{$sPaymentRequest->sId}/{$sPaymentRequest->sKey}/paypal/done"); if (filter_var($sPaymentMethod->sAddress, FILTER_VALIDATE_EMAIL)) { $target = "https://www.paypal.com/cgi-bin/webscr?business={$sQuotedRecipient}&cmd=_donations&item_name={$sQuotedName}&item_number={$sQuotedNumber}¤cy_code={$sCurrency}&amount={$sAmount}&return={$sQuotedReturnUrl}"; } else { /* This is most likely a hosted button ID. We can only provide limited information in this case - we can really only set the item description. * Not sure if setting the return URL will work, but we might as well try. */ $target = "https://www.paypal.com/cgi-bin/webscr?hosted_button_id={$sQuotedRecipient}&cmd=_s-xclick&item_name={$sQuotedName}&return={$sQuotedReturnUrl}"; }