/** * Method to get the field input markup. * * @return string The field input markup. * * @since 11.1 */ protected function getInput() { // Initialize some field attributes. $size = $this->element['size'] ? ' size="' . (int) $this->element['size'] . '"' : ''; $maxLength = $this->element['maxlength'] ? ' maxlength="' . (int) $this->element['maxlength'] . '"' : ''; $readonly = (string) $this->element['readonly'] == 'true' ? ' readonly="readonly"' : ''; $disabled = (string) $this->element['disabled'] == 'true' ? ' disabled="disabled"' : ''; $class = !empty($this->element['class']) ? ' class="' . (string) $this->element['class'] . '"' : ""; // Initialize JavaScript field attributes. $onchange = $this->element['onchange'] ? ' onchange="' . (string) $this->element['onchange'] . '"' : ''; $params = JComponentHelper::getParams("com_crowdfunding"); /** @var $params Joomla\Registry\Registry */ $currencyId = $params->get("project_currency"); jimport("crowdfunding.currency"); $currency = CrowdFundingCurrency::getInstance(JFactory::getDbo(), $currencyId, $params); if ($currency->getSymbol()) { // Prepended $html = '<div class="input-prepend input-append"><span class="add-on">' . $currency->getSymbol() . '</span>'; } else { // Append $html = '<div class="input-append">'; } $html .= '<input type="text" name="' . $this->name . '" id="' . $this->id . '"' . ' value="' . htmlspecialchars($this->value, ENT_COMPAT, 'UTF-8') . '"' . $class . $size . $disabled . $readonly . $onchange . $maxLength . '/>'; // Appended $html .= '<span class="add-on">' . $currency->getAbbr() . '</span></div>'; return $html; }
public function display($tpl = null) { // Initialise variables $this->state = $this->get("State"); $this->items = $this->get('Items'); $this->pagination = $this->get('Pagination'); // Get params /** @var $params Joomla\Registry\Registry */ $params = $this->state->get("params"); $this->params = $params; $this->imageWidth = $this->params->get("image_width", 200); $this->imageHeight = $this->params->get("image_height", 200); $this->titleLength = $this->params->get("discover_title_length", 0); $this->descriptionLength = $this->params->get("discover_description_length", 0); $model = $this->getModel(); /** @var @model CrowdFundingModelFeatured * */ $this->numberInRow = $this->params->get("featured_items_row", 3); $this->items = $model->prepareItems($this->items, $this->numberInRow); // Get the folder with images $this->imageFolder = $params->get("images_directory", "images/crowdfunding"); // Get currency jimport("crowdfunding.currency"); $currencyId = $this->params->get("project_currency"); $this->currency = CrowdFundingCurrency::getInstance(JFactory::getDbo(), $currencyId, $this->params); $this->displayCreator = $this->params->get("integration_display_creator", true); // Prepare integration. Load avatars and profiles. if (!empty($this->displayCreator)) { $this->prepareIntegration($this->items, $this->params); } $this->prepareDocument(); $this->version = new CrowdFundingVersion(); parent::display($tpl); }
public function display($tpl = null) { $this->state = $this->get('State'); $this->items = $this->get('Items'); $this->pagination = $this->get('Pagination'); $this->params = $this->state->get("params"); jimport("crowdfunding.currency"); $currencyId = $this->state->params->get("project_currency"); $this->currency = CrowdFundingCurrency::getInstance(JFactory::getDbo(), $currencyId, $this->params); // Get projects IDs $projectsIds = array(); foreach ($this->items as $item) { $projectsIds[] = $item->id; } // Get number of rewards. jimport("crowdfunding.projects"); $projects = new CrowdFundingProjects(JFactory::getDbo()); $this->rewards = $projects->getRewardsNumber($projectsIds); // Add submenu CrowdFundingHelper::addSubmenu($this->getName()); // Prepare sorting data $this->prepareSorting(); // Prepare actions $this->addToolbar(); $this->addSidebar(); $this->setDocument(); parent::display($tpl); }
public function display($tpl = null) { $app = JFactory::getApplication(); /** @var $app JApplicationSite * */ // Get model state. $this->state = $this->get('State'); $this->item = $this->get("Item"); // Get params /** @var $params Joomla\Registry\Registry */ $params = $this->state->get("params"); $this->params = $params; $this->imageFolder = $this->params->get("images_directory", "images/crowdfunding"); if (!$this->item) { $app->enqueueMessage(JText::_("COM_CROWDFUNDING_ERROR_INVALID_PROJECT"), "notice"); $app->redirect(JRoute::_('index.php?option=com_crowdfunding&view=discover', false)); return; } // Get currency jimport("crowdfunding.currency"); $currencyId = $this->params->get("project_currency"); $this->currency = CrowdFundingCurrency::getInstance(JFactory::getDbo(), $currencyId, $this->params); // Get a social platform for integration. $this->socialPlatform = $this->params->get("integration_social_platform"); // Set a link to project page $uri = JUri::getInstance(); $host = $uri->toString(array("scheme", "host")); $this->item->link = $host . JRoute::_(CrowdFundingHelperRoute::getDetailsRoute($this->item->slug, $this->item->catslug), false); // Set a link to image $this->item->link_image = $host . "/" . $this->imageFolder . "/" . $this->item->image; $layout = $this->getLayout(); switch ($layout) { case "email": if (!$this->params->get("security_display_friend_form", 0)) { $app->enqueueMessage(JText::_("COM_CROWDFUNDING_ERROR_CANT_SEND_MAIL"), "notice"); $app->redirect(JRoute::_($this->item->link, false)); return; } $this->prepareEmailForm($this->item); break; default: // Embed HTML code $this->embedCode = $this->prepareEmbedCode($this->item, $host); break; } $this->prepareDocument(); $this->version = new CrowdFundingVersion(); parent::display($tpl); }
/** * Display the view */ public function display($tpl = null) { $app = JFactory::getApplication(); /** @var $app JApplicationAdministrator */ // Get user ID $userId = $app->input->getInt("id"); $model = $this->getModel(); $this->state = $model->getState(); $this->item = $model->getItem($userId); $this->params = JComponentHelper::getParams($this->option); // Get currency jimport("crowdfunding.currency"); $currencyId = $this->params->get("project_currency"); $this->currency = CrowdFundingCurrency::getInstance(JFactory::getDbo(), $currencyId, $this->params); // Get number of rewards. jimport("crowdfunding.statistics.user"); $statistics = new CrowdFundingStatisticsUser(JFactory::getDbo(), $this->item->id); $this->projects = $statistics->getProjectsNumber(); $amounts = $statistics->getAmounts(); if (!empty($amounts["invested"])) { $this->investedAmount = (double) $amounts["invested"]->amount; $this->investedTransactions = (int) $amounts["invested"]->number; } if (!empty($amounts["received"])) { $this->receivedAmount = (double) $amounts["received"]->amount; $this->receivedTransactions = (int) $amounts["received"]->number; } // Get social profile $socialPlatform = $this->params->get("integration_social_platform"); if (!empty($socialPlatform)) { $options = array("social_platform" => $socialPlatform, "user_id" => $this->item->id); jimport("itprism.integrate.profile.builder"); $profileBuilder = new ITPrismIntegrateProfileBuilder($options); $profileBuilder->build(); $this->socialProfile = $profileBuilder->getProfile(); $this->profileLink = $this->socialProfile->getLink(); } jimport("crowdfunding.user.rewards"); $this->rewards = new CrowdFundingUserRewards(JFactory::getDbo()); $this->rewards->load($this->item->id); $this->returnUrl = base64_encode("index.php?option=com_crowdfunding&view=user&id=" . $this->item->id); // Prepare actions, behaviors, scripts and document $this->addToolbar(); $this->setDocument(); parent::display($tpl); }
public function display($tpl = null) { // Initialise variables $this->items = $this->get('Items'); $this->state = $this->get('State'); $this->params = $this->state->get('params'); if (!empty($this->items)) { jimport("crowdfunding.currency"); $currencyId = $this->params->get("project_currency"); $this->currency = CrowdFundingCurrency::getInstance(JFactory::getDbo(), $currencyId, $this->params); } // Prepare filters $this->listOrder = $this->escape($this->state->get('list.ordering')); $this->listDirn = $this->escape($this->state->get('list.direction')); $this->saveOrder = strcmp($this->listOrder, 'a.ordering') != 0 ? false : true; $this->prepareDocument(); $this->version = new CrowdFundingVersion(); parent::display($tpl); }
public function display($tpl = null) { $this->state = $this->get('State'); $this->items = $this->get('Items'); $this->pagination = $this->get('Pagination'); $this->params = $this->state->get("params"); jimport("crowdfunding.currency"); $currencyId = $this->state->params->get("project_currency"); $this->currency = CrowdFundingCurrency::getInstance(JFactory::getDbo(), $currencyId, $this->params); // Add submenu CrowdFundingHelper::addSubmenu("projects"); $projectId = $this->state->get("project_id"); $this->projectTitle = CrowdFundingHelper::getProjectTitle($projectId); // Prepare sorting data $this->prepareSorting(); // Prepare actions $this->addToolbar(); $this->addSidebar(); $this->setDocument(); parent::display($tpl); }
public function display($tpl = null) { $this->state = $this->get("State"); $this->params = $this->state->get("params"); $this->version = new CrowdFundingVersion(); // Load ITPrism library version jimport("itprism.version"); if (!class_exists("ITPrismVersion")) { $this->itprismVersion = JText::_("COM_CROWDFUNDING_ITPRISM_LIBRARY_DOWNLOAD"); } else { $itprismVersion = new ITPrismVersion(); $this->itprismVersion = $itprismVersion->getShortVersion(); } // Get popular projects. jimport("crowdfunding.statistics.projects.popular"); $this->popular = new CrowdFundingStatisticsProjectsPopular(JFactory::getDbo()); $this->popular->load(5); // Get popular most funded. jimport("crowdfunding.statistics.projects.mostfunded"); $this->mostFunded = new CrowdFundingStatisticsProjectsMostFunded(JFactory::getDbo()); $this->mostFunded->load(5); // Get latest started. jimport("crowdfunding.statistics.projects.latest"); $this->latestStarted = new CrowdFundingStatisticsProjectsLatest(JFactory::getDbo()); $this->latestStarted->load(5); // Get latest created. $this->latestCreated = new CrowdFundingStatisticsProjectsLatest(JFactory::getDbo()); $this->latestCreated->loadByCreated(5); // Get currency. jimport("crowdfunding.currency"); $currencyId = $this->params->get("project_currency"); $this->currency = CrowdFundingCurrency::getInstance(JFactory::getDbo(), $currencyId, $this->params); // Add submenu CrowdFundingHelper::addSubmenu($this->getName()); $this->addToolbar(); $this->addSidebar(); $this->setDocument(); parent::display($tpl); }
public function display($tpl = null) { $this->items = $this->get('Items'); $this->state = $this->get('State'); $this->pagination = $this->get('Pagination'); // Get params /** @var $params Joomla\Registry\Registry */ $params = $this->state->get("params"); $this->params = $params; if (!empty($this->items)) { jimport("crowdfunding.currency"); $currencyId = $this->params->get("project_currency"); $this->currency = CrowdFundingCurrency::getInstance(JFactory::getDbo(), $currencyId, $this->params); } // Prepare filters $this->listOrder = $this->escape($this->state->get('list.ordering')); $this->listDirn = $this->escape($this->state->get('list.direction')); $this->saveOrder = strcmp($this->listOrder, 'a.ordering') != 0 ? false : true; $this->userId = JFactory::getUser()->get("id"); $this->redirectUrl = CrowdFundingHelperRoute::getTransactionsRoute(); $this->prepareDocument(); $this->version = new CrowdFundingVersion(); parent::display($tpl); }
public function display($tpl = null) { // Get model state. $this->state = $this->get('State'); $this->item = $this->get("Item"); // Get params /** @var $params Joomla\Registry\Registry */ $params = $this->state->get("params"); $this->params = $params; if (!$this->item) { $this->app->enqueueMessage(JText::_("COM_CROWDFUNDING_ERROR_INVALID_PROJECT"), "notice"); $this->app->redirect(JRoute::_(CrowdFundingHelperRoute::getDiscoverRoute(), false)); return; } // Create an object that will contain the data during the payment process. $this->paymentSessionContext = CrowdFundingConstants::PAYMENT_SESSION_CONTEXT . $this->item->id; $paymentSession = $this->app->getUserState($this->paymentSessionContext); // Create payment session object. if (!$paymentSession) { $paymentSession = new JData(); $paymentSession->step1 = false; } // Images $this->imageFolder = $this->params->get("images_directory", "images/crowdfunding"); // Get currency jimport("crowdfunding.currency"); $currencyId = $this->params->get("project_currency"); $this->currency = CrowdFundingCurrency::getInstance(JFactory::getDbo(), $currencyId, $this->params); // Set a link that points to project page $filter = JFilterInput::getInstance(); $host = JUri::getInstance()->toString(array('scheme', 'host')); $host = $filter->clean($host); $this->item->link = $host . JRoute::_(CrowdFundingHelperRoute::getDetailsRoute($this->item->slug, $this->item->catslug), false); // Set a link to image $this->item->link_image = $host . "/" . $this->imageFolder . "/" . $this->item->image; // Get params $params = JComponentHelper::getParams("com_crowdfunding"); // Get wizard type $this->wizardType = $params->get("backing_wizard_type", "three_steps"); $this->fourSteps = strcmp("four_steps", $this->wizardType) != 0 ? false : true; // Import "crowdfundingpayment" plugins. JPluginHelper::importPlugin('crowdfundingpayment'); $this->layout = $this->getLayout(); switch ($this->layout) { case "step2": $this->prepareStep2(); break; case "payment": $this->preparePayment($paymentSession); break; case "share": $this->prepareShare($paymentSession); break; default: // Pledge and Rewards $this->prepareRewards($paymentSession); break; } // Get project type and check for enabled rewards. $this->rewardsEnabled = true; if (!empty($this->item->type_id)) { jimport("crowdfunding.type"); $type = new CrowdFundingType(JFactory::getDbo()); $type->load($this->item->type_id); if ($type->getId() and !$type->isRewardsEnabled()) { $this->rewardsEnabled = false; } } // Check days left. If there is no days, disable the button. $this->disabledButton = ""; if (!$this->item->days_left) { $this->disabledButton = 'disabled="disabled"'; } $this->paymentSession = $paymentSession; // Prepare the data of the layout $this->layoutData = new JData(array("layout" => $this->layout, "item" => $this->item, "paymentSession" => $paymentSession)); $this->prepareDebugMode($paymentSession); $this->prepareDocument(); $this->version = new CrowdFundingVersion(); parent::display($tpl); }
/** * @param int $projectId * @param Joomla\Registry\Registry $params * * @return stdClass * @throws UnexpectedValueException */ protected function prepareItem($projectId, $params) { jimport("crowdfunding.project"); $project = new CrowdFundingProject(JFactory::getDbo()); $project->load($projectId); if (!$project->getId()) { throw new UnexpectedValueException(JText::_("COM_CROWDFUNDING_ERROR_INVALID_PROJECT")); } if ($project->isCompleted()) { throw new UnexpectedValueException(JText::_("COM_CROWDFUNDING_ERROR_COMPLETED_PROJECT")); } // Get currency jimport("crowdfunding.currency"); $currencyId = $params->get("project_currency"); $this->currency = CrowdFundingCurrency::getInstance(JFactory::getDbo(), $currencyId, $params); $item = new stdClass(); $item->id = $project->getId(); $item->title = $project->getTitle(); $item->slug = $project->getSlug(); $item->catslug = $project->getCatSlug(); $item->rewardId = $this->paymentProcess->rewardId; $item->amount = $this->paymentProcess->amount; $item->currency = $this->currency->getAbbr(); return $item; }
/** * Send emails to the administrator, project owner and the user who have made a donation. * * @param object $project * @param object $transaction * @param Joomla\Registry\Registry $params */ protected function sendMails($project, $transaction, $params) { $app = JFactory::getApplication(); /** @var $app JApplicationSite */ // Get website $uri = JUri::getInstance(); $website = $uri->toString(array("scheme", "host")); $emailMode = $this->params->get("email_mode", "plain"); jimport("crowdfunding.currency"); $currencyId = $params->get("project_currency"); $currency = CrowdFundingCurrency::getInstance(JFactory::getDbo(), $currencyId, $params); // Prepare data for parsing $data = array("site_name" => $app->get("sitename"), "site_url" => JUri::root(), "item_title" => $project->title, "item_url" => $website . JRoute::_(CrowdFundingHelperRoute::getDetailsRoute($project->slug, $project->catslug)), "amount" => $currency->getAmountString($transaction->txn_amount), "transaction_id" => $transaction->txn_id); // Send mail to the administrator $emailId = $this->params->get("admin_mail_id", 0); if (!empty($emailId)) { jimport("crowdfunding.email"); $email = new CrowdFundingEmail(); $email->setDb(JFactory::getDbo()); $email->load($emailId); if (!$email->getSenderName()) { $email->setSenderName($app->get("fromname")); } if (!$email->getSenderEmail()) { $email->setSenderEmail($app->get("mailfrom")); } // Prepare recipient data. $componentParams = JComponentHelper::getParams("com_crowdfunding"); $recipientId = $componentParams->get("administrator_id"); if (!empty($recipientId)) { $recipient = JFactory::getUser($recipientId); $recipientName = $recipient->get("name"); $recipientMail = $recipient->get("email"); } else { $recipientName = $app->get("fromname"); $recipientMail = $app->get("mailfrom"); } // Prepare data for parsing $data["sender_name"] = $email->getSenderName(); $data["sender_email"] = $email->getSenderEmail(); $data["recipient_name"] = $recipientName; $data["recipient_email"] = $recipientMail; $email->parse($data); $subject = $email->getSubject(); $body = $email->getBody($emailMode); $mailer = JFactory::getMailer(); if (strcmp("html", $emailMode) == 0) { // Send as HTML message $return = $mailer->sendMail($email->getSenderEmail(), $email->getSenderName(), $recipientMail, $subject, $body, CrowdFundingConstants::MAIL_MODE_HTML); } else { // Send as plain text. $return = $mailer->sendMail($email->getSenderEmail(), $email->getSenderName(), $recipientMail, $subject, $body, CrowdFundingConstants::MAIL_MODE_PLAIN); } // Check for an error. if ($return !== true) { $this->log->add(JText::_($this->textPrefix . "_ERROR_MAIL_SENDING_ADMIN"), $this->debugType); } } // Send mail to project owner $emailId = $this->params->get("creator_mail_id", 0); if (!empty($emailId)) { $email = new CrowdFundingEmail(); $email->setDb(JFactory::getDbo()); $email->load($emailId); if (!$email->getSenderName()) { $email->setSenderName($app->get("fromname")); } if (!$email->getSenderEmail()) { $email->setSenderEmail($app->get("mailfrom")); } $user = JFactory::getUser($transaction->receiver_id); $recipientName = $user->get("name"); $recipientMail = $user->get("email"); // Prepare data for parsing $data["sender_name"] = $email->getSenderName(); $data["sender_email"] = $email->getSenderEmail(); $data["recipient_name"] = $recipientName; $data["recipient_email"] = $recipientMail; $email->parse($data); $subject = $email->getSubject(); $body = $email->getBody($emailMode); $mailer = JFactory::getMailer(); if (strcmp("html", $emailMode) == 0) { // Send as HTML message $return = $mailer->sendMail($email->getSenderEmail(), $email->getSenderName(), $recipientMail, $subject, $body, CrowdFundingConstants::MAIL_MODE_HTML); } else { // Send as plain text. $return = $mailer->sendMail($email->getSenderEmail(), $email->getSenderName(), $recipientMail, $subject, $body, CrowdFundingConstants::MAIL_MODE_PLAIN); } // Check for an error. if ($return !== true) { // Log error $this->log->add(JText::_($this->textPrefix . "_ERROR_MAIL_SENDING_PROJECT_OWNER"), $this->debugType); } } // Send mail to backer $emailId = $this->params->get("user_mail_id", 0); $investorId = $transaction->investor_id; if (!empty($emailId) and !empty($investorId)) { $email = new CrowdFundingEmail(); $email->setDb(JFactory::getDbo()); $email->load($emailId); if (!$email->getSenderName()) { $email->setSenderName($app->get("fromname")); } if (!$email->getSenderEmail()) { $email->setSenderEmail($app->get("mailfrom")); } $user = JFactory::getUser($investorId); $recipientName = $user->get("name"); $recipientMail = $user->get("email"); // Prepare data for parsing $data["sender_name"] = $email->getSenderName(); $data["sender_email"] = $email->getSenderEmail(); $data["recipient_name"] = $recipientName; $data["recipient_email"] = $recipientMail; $email->parse($data); $subject = $email->getSubject(); $body = $email->getBody($emailMode); $mailer = JFactory::getMailer(); if (strcmp("html", $emailMode) == 0) { // Send as HTML message $return = $mailer->sendMail($email->getSenderEmail(), $email->getSenderName(), $recipientMail, $subject, $body, CrowdFundingConstants::MAIL_MODE_HTML); } else { // Send as plain text. $return = $mailer->sendMail($email->getSenderEmail(), $email->getSenderName(), $recipientMail, $subject, $body, CrowdFundingConstants::MAIL_MODE_PLAIN); } // Check for an error. if ($return !== true) { // Log error $this->log->add(JText::_($this->textPrefix . "_ERROR_MAIL_SENDING_USER"), $this->debugType); } } }
if (!$projectId) { echo JText::_("MOD_CROWDFUNDINGDETAILS_ERROR_INVALID_PROJECT"); return; } // Get project jimport("crowdfunding.project"); $project = CrowdFundingProject::getInstance(JFactory::getDbo(), $projectId); if (!$project->getId()) { echo JText::_("MOD_CROWDFUNDINGDETAILS_ERROR_INVALID_PROJECT"); return; } // Get component params $componentParams = JComponentHelper::getParams("com_crowdfunding"); /** @var $componentParams Joomla\Registry\Registry */ $socialPlatform = $componentParams->get("integration_social_platform"); $imageFolder = $componentParams->get("images_directory", "images/crowdfunding"); // Get currency jimport("crowdfunding.currency"); $currencyId = $componentParams->get("project_currency"); $currency = CrowdFundingCurrency::getInstance(JFactory::getDbo(), $currencyId, $componentParams); // Get social platform and a link to the profile jimport("itprism.integrate.profile." . JString::strtolower($socialPlatform)); $socialProfile = CrowdFundingHelper::getSocialProfile($project->getUserId(), $socialPlatform); $socialProfileLink = !$socialProfile ? null : $socialProfile->getLink(); // Get amounts $fundedAmount = $currency->getAmountString($project->getGoal()); $raised = $currency->getAmountString($project->getFunded()); // Prepare the value that I am going to display $fundedPercents = JHtml::_("crowdfunding.funded", $project->getFundedPercent()); $user = JFactory::getUser($project->getUserId()); require JModuleHelper::getLayoutPath('mod_crowdfundingdetails', $params->get('layout', 'default'));
protected function prepareFundersScreen() { $model = JModelLegacy::getInstance("Funders", "CrowdFundingModel", $config = array('ignore_request' => false)); $this->items = $model->getItems(); // Get users IDs $usersIds = array(); foreach ($this->items as $item) { $usersIds[] = $item->id; } // Create a currency object if I have to display funders amounts. $this->displayAmounts = $this->params->get("funders_display_amounts", 0); if ($this->displayAmounts) { jimport("crowdfunding.currency"); $currencyId = $this->params->get("project_currency"); $this->currency = CrowdFundingCurrency::getInstance(JFactory::getDbo(), $currencyId); } // Prepare integration. Load avatars and profiles. $this->prepareIntegration($usersIds, $this->params); }
protected function prepareManager() { $model = JModelLegacy::getInstance("Manager", "CrowdFundingModel", $config = array('ignore_request' => false)); /** @var $model CrowdFundingModelManager */ // Get state /** @var $state Joomla\Registry\Registry */ $this->state = $model->getState(); // Get params /** @var $params Joomla\Registry\Registry */ $params = $this->state->get("params"); $this->params = $params; $this->imageWidth = $this->params->get("image_width", 200); $this->imageHeight = $this->params->get("image_height", 200); $this->titleLength = $this->params->get("discover_title_length", 0); $this->descriptionLength = $this->params->get("discover_description_length", 0); // Get the folder with images $this->imageFolder = $params->get("images_directory", "images/crowdfunding"); // Filter the URL. $uri = JUri::getInstance(); $filter = JFilterInput::getInstance(); $this->returnUrl = $filter->clean($uri->toString()); // Get item $itemId = $this->state->get('manager.id'); // Create a currency object. jimport("crowdfunding.currency"); $currencyId = $this->params->get("project_currency"); $this->currency = CrowdFundingCurrency::getInstance(JFactory::getDbo(), $currencyId, $this->params); $this->item = $model->getItem($itemId, $this->userId); if (empty($this->item->id)) { $app = JFactory::getApplication(); /** $app JApplicationSite */ $app->enqueueMessage(JText::_("COM_CROWDFUNDING_ERROR_SOMETHING_WRONG"), "notice"); $app->redirect(JRoute::_(CrowdFundingHelperRoute::getDiscoverRoute())); return; } jimport("crowdfunding.statistics.project"); $statistics = new CrowdFundingStatisticsProject(JFactory::getDbo(), $this->item->id); $this->statistics = array("updates" => $statistics->getUpdatesNumber(), "comments" => $statistics->getCommentsNumber(), "funders" => $statistics->getTransactionsNumber()); // Get rewards jimport("crowdfunding.rewards"); $this->rewards = new CrowdFundingRewards(JFactory::getDbo()); $this->rewards->load($this->item->id); $this->pathwayName = JText::_("COM_CROWDFUNDING_STEP_MANAGER"); }
/** * This method processes transaction data that comes from PayPal instant notifier. * * @param string $context This string gives information about that where it has been executed the trigger. * @param Joomla\Registry\Registry $params The parameters of the component * * @return null|array */ public function onPaymenNotify($context, &$params) { if (strcmp("com_crowdfunding.notify.paypal", $context) != 0) { return null; } $app = JFactory::getApplication(); /** @var $app JApplicationSite */ if ($app->isAdmin()) { return null; } $doc = JFactory::getDocument(); /** @var $doc JDocumentHtml */ // Check document type $docType = $doc->getType(); if (strcmp("raw", $docType) != 0) { return null; } // Validate request method $requestMethod = $app->input->getMethod(); if (strcmp("POST", $requestMethod) != 0) { $this->log->add(JText::_($this->textPrefix . "_ERROR_INVALID_REQUEST_METHOD"), $this->debugType, JText::sprintf($this->textPrefix . "_ERROR_INVALID_TRANSACTION_REQUEST_METHOD", $requestMethod)); return null; } // DEBUG DATA JDEBUG ? $this->log->add(JText::_($this->textPrefix . "_DEBUG_RESPONSE"), $this->debugType, $_POST) : null; // Decode custom data $custom = JArrayHelper::getValue($_POST, "custom"); $custom = json_decode(base64_decode($custom), true); // DEBUG DATA JDEBUG ? $this->log->add(JText::_($this->textPrefix . "_DEBUG_CUSTOM"), $this->debugType, $custom) : null; // Verify gateway. Is it PayPal? if (!$this->isPayPalGateway($custom)) { $this->log->add(JText::_($this->textPrefix . "_ERROR_INVALID_PAYMENT_GATEWAY"), $this->debugType, array("custom" => $custom, "_POST" => $_POST)); return null; } // Get PayPal URL $sandbox = $this->params->get('paypal_sandbox', 0); if (!$sandbox) { $url = JString::trim($this->params->get('paypal_url', "https://www.paypal.com/cgi-bin/webscr")); } else { $url = JString::trim($this->params->get('paypal_sandbox_url', "https://www.sandbox.paypal.com/cgi-bin/webscr")); } jimport("itprism.payment.paypal.ipn"); $paypalIpn = new ITPrismPayPalIpn($url, $_POST); $loadCertificate = (bool) $this->params->get("paypal_load_certificate", 0); $paypalIpn->verify($loadCertificate); // DEBUG DATA JDEBUG ? $this->log->add(JText::_($this->textPrefix . "_DEBUG_VERIFY_OBJECT"), $this->debugType, $paypalIpn) : null; // Prepare the array that will be returned by this method $result = array("project" => null, "reward" => null, "transaction" => null, "payment_service" => "PayPal"); if ($paypalIpn->isVerified()) { // Get currency jimport("crowdfunding.currency"); $currencyId = $params->get("project_currency"); $currency = CrowdFundingCurrency::getInstance(JFactory::getDbo(), $currencyId); // Get intention data $intentionId = JArrayHelper::getValue($custom, "intention_id", 0, "int"); jimport("crowdfunding.intention"); $intention = new CrowdFundingIntention(JFactory::getDbo()); $intention->load($intentionId); // Get payment session as intention. if (!$intention->getId()) { jimport("crowdfunding.payment.session"); $keys = array("intention_id" => $intentionId); $intention = new CrowdFundingPaymentSession(JFactory::getDbo()); $intention->load($keys); } // DEBUG DATA JDEBUG ? $this->log->add(JText::_($this->textPrefix . "_DEBUG_INTENTION"), $this->debugType, $intention->getProperties()) : null; // Validate transaction data $validData = $this->validateData($_POST, $currency->getAbbr(), $intention); if (is_null($validData)) { return $result; } // DEBUG DATA JDEBUG ? $this->log->add(JText::_($this->textPrefix . "_DEBUG_VALID_DATA"), $this->debugType, $validData) : null; // Get project. jimport("crowdfunding.project"); $projectId = JArrayHelper::getValue($validData, "project_id"); $project = CrowdFundingProject::getInstance(JFactory::getDbo(), $projectId); // DEBUG DATA JDEBUG ? $this->log->add(JText::_($this->textPrefix . "_DEBUG_PROJECT_OBJECT"), $this->debugType, $project->getProperties()) : null; // Check for valid project if (!$project->getId()) { // Log data in the database $this->log->add(JText::_($this->textPrefix . "_ERROR_INVALID_PROJECT"), $this->debugType, $validData); return $result; } // Set the receiver of funds $validData["receiver_id"] = $project->getUserId(); // Save transaction data. // If it is not completed, return empty results. // If it is complete, continue with process transaction data $transactionData = $this->storeTransaction($validData, $project); if (is_null($transactionData)) { return $result; } // Update the number of distributed reward. $rewardId = JArrayHelper::getValue($transactionData, "reward_id"); $reward = null; if (!empty($rewardId)) { $reward = $this->updateReward($transactionData); // Validate the reward. if (!$reward) { $transactionData["reward_id"] = 0; } } // Generate object of data, based on the transaction properties. $result["transaction"] = JArrayHelper::toObject($transactionData); // Generate object of data based on the project properties $properties = $project->getProperties(); $result["project"] = JArrayHelper::toObject($properties); // Generate object of data based on the reward properties if (!empty($reward)) { $properties = $reward->getProperties(); $result["reward"] = JArrayHelper::toObject($properties); } // DEBUG DATA JDEBUG ? $this->log->add(JText::_($this->textPrefix . "_DEBUG_RESULT_DATA"), $this->debugType, $result) : null; // Remove intention $txnStatus = isset($result["transaction"]->txn_status) ? $result["transaction"]->txn_status : null; $this->removeIntention($intention, $txnStatus); unset($intention); } else { // Log error $this->log->add(JText::_($this->textPrefix . "_ERROR_INVALID_TRANSACTION_DATA"), $this->debugType, array("error message" => $paypalIpn->getError(), "paypalVerify" => $paypalIpn, "_POST" => $_POST)); } return $result; }