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; $model = $this->getModel(); $userId = JFactory::getUser()->get("id"); if (!$this->item or $model->isRestricted($this->item, $userId)) { $app->enqueueMessage(JText::_("COM_CROWDFUNDING_ERROR_INVALID_PROJECT"), "notice"); $app->redirect(JRoute::_('index.php?option=com_crowdfunding&view=discover', false)); return; } // Get rewards of the project $this->imageFolder = $this->params->get("images_directory", "images/crowdfunding"); // Prepare the link that points to project page $host = JUri::getInstance()->toString(array("scheme", "host")); $this->item->link = $host . JRoute::_(CrowdFundingHelperRoute::getDetailsRoute($this->item->slug, $this->item->catslug)); // Prepare the link that points to project image $this->item->link_image = $host . "/" . $this->imageFolder . "/" . $this->item->image; // Get the current screen $this->screen = $app->input->getCmd("screen", "home"); $this->prepareDocument(); // Import content plugins JPluginHelper::importPlugin('content'); switch ($this->screen) { case "updates": $this->prepareUpdatesScreen(); break; case "comments": $this->prepareCommentsScreen(); break; case "funders": $this->prepareFundersScreen(); break; default: // Home break; } // Events $dispatcher = JEventDispatcher::getInstance(); $this->item->event = new stdClass(); $offset = 0; $results = $dispatcher->trigger('onContentBeforeDisplay', array('com_crowdfunding.details', &$this->item, &$this->params, $offset)); $this->item->event->beforeDisplayContent = trim(implode("\n", $results)); $results = $dispatcher->trigger('onContentAfterDisplayMedia', array('com_crowdfunding.details', &$this->item, &$this->params, $offset)); $this->item->event->onContentAfterDisplayMedia = trim(implode("\n", $results)); $results = $dispatcher->trigger('onContentAfterDisplay', array('com_crowdfunding.details', &$this->item, &$this->params, $offset)); $this->item->event->onContentAfterDisplay = trim(implode("\n", $results)); // Count hits $model->hit($this->item->id); $this->version = new CrowdFundingVersion(); parent::display($tpl); }
public function save($key = null, $urlVar = null) { // Check for request forgeries. JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN')); $userId = JFactory::getUser()->get("id"); if (!$userId) { $redirectOptions = array("force_direction" => "index.php?option=com_users&view=login"); $this->displayNotice(JText::_('COM_CROWDFUNDING_ERROR_NOT_LOG_IN'), $redirectOptions); return; } // Get the data from the form POST $data = $this->input->post->get('jform', array(), 'array'); $itemId = JArrayHelper::getValue($data, "project_id"); // Get project jimport("crowdfunding.project"); $item = CrowdFundingProject::getInstance(JFactory::getDbo(), $itemId); $redirectOptions = array("force_direction" => CrowdFundingHelperRoute::getDetailsRoute($item->getSlug(), $item->getCatSlug(), "updates")); // Check for valid owner. if ($userId != $item->getUserId()) { $this->displayWarning(JText::_('COM_CROWDFUNDING_ERROR_INVALID_PROJECT'), $redirectOptions); return; } $model = $this->getModel(); /** @var $model CrowdFundingModelUpdate */ $form = $model->getForm($data, false); /** @var $form JForm */ if (!$form) { throw new Exception(JText::_("COM_CROWDFUNDING_ERROR_FORM_CANNOT_BE_LOADED")); } // Test if the data is valid. $validData = $model->validate($form, $data); // Check for validation errors. if ($validData === false) { $errors = $form->getErrors(); $error = array_shift($errors); $msg = $error->getMessage(); $this->displayNotice($msg, $redirectOptions); return; } try { $model->save($validData); } catch (Exception $e) { JLog::add($e->getMessage()); throw new Exception(JText::_('COM_CROWDFUNDING_ERROR_SYSTEM')); } // Redirect to next page $this->displayNotice(JText::_("COM_CROWDFUNDING_UPDATE_SUCCESSFULLY_SAVED"), $redirectOptions); }
public function display($tpl = null) { $app = JFactory::getApplication(); /** @var $app JApplicationSite */ // Get user ID. $this->userId = JFactory::getUser()->get("id"); // Get reward ID. $rewardId = $app->input->getInt("id"); // Validate reward owner jimport("crowdfunding.validator.reward.owner"); $validator = new CrowdFundingValidatorRewardOwner(JFactory::getDbo(), $rewardId, $this->userId); if (!$validator->isValid()) { $app->enqueueMessage(JText::_("COM_CROWDFUNDING_ERROR_INVALID_REWARD"), "notice"); $app->redirect(JRoute::_(CrowdFundingHelperRoute::getDiscoverRoute())); return; } $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; // Prepare an URL where user will be redirected when change the state of a reward. $this->redirectUrl = "index.php?option=com_crowdfunding&view=reward&id=" . $rewardId; // 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; // Load reward data. jimport("crowdfunding.reward"); $this->reward = new CrowdFundingReward(JFactory::getDbo()); $this->reward->load($rewardId); // Prepare reward delivery date. $dateValidator = new ITPrismValidatorDate($this->reward->getDeliveryDate()); $this->deliveryDate = $dateValidator->isValid() ? JHtml::_('date', $this->reward->getDeliveryDate(), JText::_('DATE_FORMAT_LC3')) : "--"; // Get images folder. $this->imagesFolder = CrowdFundingHelper::getImagesFolderUri($this->userId); // Get social profile $socialPlatform = $this->params->get("integration_social_platform"); if (!empty($socialPlatform)) { $this->prepareSocialIntegration($socialPlatform); } $this->prepareDocument(); $this->version = new CrowdFundingVersion(); parent::display($tpl); }
public function send() { // Check for request forgeries. JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN')); $redirectOptions = array("view" => "discover"); $params = JComponentHelper::getParams("com_crowdfunding"); /** @var $params Joomla\Registry\Registry */ if (!$params->get("security_display_friend_form", 0)) { $this->displayNotice(JText::_('COM_CROWDFUNDING_ERROR_CANT_SEND_MAIL'), $redirectOptions); return; } // Get the data from the form POST $data = $this->input->post->get('jform', array(), 'array'); $itemId = JArrayHelper::getValue($data, "id", 0, "uint"); // Get project jimport("crowdfunding.project"); $item = CrowdFundingProject::getInstance(JFactory::getDbo(), $itemId); // Prepare redirect link $link = CrowdFundingHelperRoute::getEmbedRoute($item->getSlug(), $item->getCatSlug(), "email"); $redirectOptions = array("force_direction" => $link); $model = $this->getModel(); /** @var $model CrowdFundingModelFriendMail */ $form = $model->getForm($data, false); /** @var $form JForm */ if (!$form) { throw new Exception(JText::_("COM_CROWDFUNDING_ERROR_FORM_CANNOT_BE_LOADED")); } // Test if the data is valid. $validData = $model->validate($form, $data); // Check for validation errors. if ($validData === false) { $this->displayNotice($form->getErrors(), $redirectOptions); return; } try { $model->send($validData); } catch (Exception $e) { JLog::add($e->getMessage()); throw new Exception(JText::_('COM_CROWDFUNDING_ERROR_SYSTEM')); } // Redirect to next page $this->displayMessage(JText::_("COM_CROWDFUNDING_FRIEND_MAIL_SUCCESSFULLY_SEND"), $redirectOptions); }
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); }
?> </a> <?php } ?> </li> <li <?php echo $active["share"] ? 'class="active"' : ''; ?> > <?php if (!empty($displayData->paymentSession->step2)) { ?> <a href="<?php echo JRoute::_(CrowdFundingHelperRoute::getBackingRoute($displayData->item->slug, $displayData->item->catslug, "share")); ?> "> (4) <?php echo JText::_("COM_CROWDFUNDING_STEP_SHARE"); ?> </a> <?php } else { ?> <a href="javascript: void(0);" class="disabled">(4) <?php echo JText::_("COM_CROWDFUNDING_STEP_SHARE"); ?> </a> <?php
protected function getCancelUrl($slug, $catslug) { $page = JString::trim($this->params->get('paypal_cancel_url')); if (!$page) { $uri = JURI::getInstance(); $page = $uri->toString(array("scheme", "host")) . JRoute::_(CrowdFundingHelperRoute::getBackingRoute($slug, $catslug, "default"), false); } // DEBUG DATA JDEBUG ? $this->log->add(JText::_($this->textPrefix . "_DEBUG_CANCEL_URL"), $this->debugType, $page) : null; return $page; }
?> <div class="cfrewards<?php echo $moduleclassSfx; ?> "> <div class="reward_title center"><?php echo JText::_("MOD_CROWDFUNDINGREWARDS_PLEDGE_REWARDS"); ?> </div> <?php foreach ($rewards as $reward) { ?> <div class="reward"> <a href="<?php echo JRoute::_(CrowdFundingHelperRoute::getBackingRoute($project->getSlug(), $project->getCatSlug(), "default", $reward->id)); ?> "> <span class="ramount"> <?php $amount = $currency->getAmountString($reward->amount); echo JText::sprintf("MOD_CROWDFUNDINGREWARDS_INVEST_MORE", $amount); ?> </span> <span class="rtitle"><?php echo htmlspecialchars($reward->title, ENT_QUOTES, "UTF-8"); ?> </span> <span class="rdesc"><?php echo htmlspecialchars($reward->description, ENT_QUOTES, "UTF-8"); ?>
<div class="well"> <div class="cf-fund-result-state pull-center"><?php echo JHtml::_("crowdfunding.resultState", $project->getFundedPercent(), $project->getFundingType()); ?> </div> <div class="cf-frss pull-center"><?php echo JHtml::_("crowdfunding.resultStateText", $project->getFundedPercent(), $project->getFundingType()); ?> </div> </div> <?php } else { ?> <div class="cfinfo-funding-action"> <a class="btn btn-large btn-block" href="<?php echo JRoute::_(CrowdFundingHelperRoute::getBackingRoute($project->getSlug(), $project->getCatSlug())); ?> "> <?php echo JText::_("MOD_CROWDFUNDINGINFO_INVEST_NOW"); ?> </a> </div> <?php } ?> <div class="cfinfo-funding-type-info"> <?php $endDate = JHtml::_('crowdfunding.date', $project->getFundingEnd(), JText::_('DATE_FORMAT_LC3')); if ("FIXED" == $project->getFundingType()) {
/** * 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); } } }
// Get social platform and a link to the profile $socialProfile = CrowdFundingHelper::getSocialProfile($this->item->user_id, $this->socialPlatform); $socialProfileLink = !$socialProfile ? null : $socialProfile->getLink(); ?> <li class="span12"> <div class="thumbnail"> <img src="<?php echo $this->item->link_image; ?> " alt="<?php echo $this->item->title; ?> " width="200" height="200"> <div class="caption"> <h3><a href="<?php echo JRoute::_(CrowdFundingHelperRoute::getDetailsRoute($this->item->slug, $this->item->catslug)); ?> " target="_blank"><?php echo $this->item->title; ?> </a></h3> <span class="cf-founder"> by <?php echo JHtml::_("crowdfunding.socialProfileLink", $socialProfileLink, $this->item->user_name, array("target" => "_blank")); ?> </span> <p><?php echo $this->item->short_desc; ?> </p>
/** * Catch a request from payment plugin via AJAX and process a transaction. */ public function notifyAjax() { jimport('itprism.response.json'); $response = new ITPrismResponseJson(); // Check for disabled payment functionality if ($this->params->get("debug_payment_disabled", 0)) { // Log the error. $error = JText::_("COM_CROWDFUNDING_ERROR_PAYMENT_HAS_BEEN_DISABLED") . "\n"; $error .= JText::sprintf("COM_CROWDFUNDING_TRANSACTION_DATA", var_export($_REQUEST, true)); $this->log->add($error, "CONTROLLER_NOTIFIER_AJAX_ERROR"); // Send response to the browser $response->setTitle(JText::_("COM_CROWDFUNDING_FAIL"))->setText(JText::_("COM_CROWDFUNDING_ERROR_PAYMENT_HAS_BEEN_DISABLED_MESSAGE"))->failure(); echo $response; JFactory::getApplication()->close(); } // Get model object. $model = $this->getModel(); $transaction = null; $project = null; $reward = null; $paymentSession = null; $redirectUrl = null; $message = null; // Trigger the event try { // Import CrowdFunding Payment Plugins JPluginHelper::importPlugin('crowdfundingpayment'); // Trigger onPaymenNotify event. $dispatcher = JEventDispatcher::getInstance(); $results = $dispatcher->trigger("onPaymenNotify", array($this->context, &$this->params)); if (!empty($results)) { foreach ($results as $result) { if (!empty($result) and isset($result["transaction"])) { $transaction = JArrayHelper::getValue($result, "transaction"); $project = JArrayHelper::getValue($result, "project"); $reward = JArrayHelper::getValue($result, "reward"); $paymentSession = JArrayHelper::getValue($result, "payment_session"); $redirectUrl = JArrayHelper::getValue($result, "redirect_url"); $message = JArrayHelper::getValue($result, "message"); break; } } } // If there is no transaction data, the status might be pending or another one. // So, we have to stop the script execution. if (!$transaction) { // Remove the record of the payment session from database. $model->closePaymentSession($paymentSession); // Send response to the browser $response->setTitle(JText::_("COM_CROWDFUNDING_FAIL"))->setText(JText::_("COM_CROWDFUNDING_TRANSACTION_NOT_PROCESSED_SUCCESSFULLY"))->failure(); echo $response; JFactory::getApplication()->close(); } // Trigger the event onAfterPayment $dispatcher->trigger('onAfterPayment', array($this->context, &$transaction, &$this->params, &$project, &$reward, &$paymentSession)); // Remove the record of the payment session from database. $model->closePaymentSession($paymentSession); } catch (Exception $e) { // Store log data to the database. $this->log->add(JText::_("COM_CROWDFUNDING_ERROR_SYSTEM"), "CONTROLLER_NOTIFIER_AJAX_ERROR", $e->getMessage()); // Remove the record of the payment session from database. $model->closePaymentSession($paymentSession); // Send response to the browser $response->failure()->setTitle(JText::_("COM_CROWDFUNDING_FAIL"))->setText(JText::_("COM_CROWDFUNDING_ERROR_SYSTEM")); // Send notification about the error to the administrator. $model->sendMailToAdministrator(); echo $response; JFactory::getApplication()->close(); } // Generate redirect URL if (!$redirectUrl) { $uri = JUri::getInstance(); $redirectUrl = $uri->toString(array("scheme", "host")) . JRoute::_(CrowdFundingHelperRoute::getBackingRoute($project->slug, $project->catslug, "share")); } if (!$message) { $message = JText::_("COM_CROWDFUNDING_TRANSACTION_PROCESSED_SUCCESSFULLY"); } // Send response to the browser $response->success()->setTitle(JText::_("COM_CROWDFUNDING_SUCCESS"))->setText($message)->setRedirectUrl($redirectUrl); echo $response; JFactory::getApplication()->close(); }
public static function projectTitle($title, $categoryState, $slug, $catSlug) { $html = array(); if (!$categoryState) { $html[] = htmlspecialchars($title, ENT_QUOTES, "utf-8"); $html[] = '<button type="button" class="hasTooltip" title="' . htmlspecialchars(JText::_("COM_CROWDFUNDING_SELECT_OTHER_CATEGORY_TOOLTIP"), ENT_QUOTES, "utf-8") . '">'; $html[] = '<i class="icon-info-sign"></i>'; $html[] = '</button>'; } else { $html[] = '<a href="' . JRoute::_(CrowdFundingHelperRoute::getDetailsRoute($slug, $catSlug)) . '">'; $html[] = htmlspecialchars($title, ENT_QUOTES, "utf-8"); $html[] = '</a>'; } return implode("\n", $html); }
/** * Method to parse Route * * @param array $segments * @return array */ function CrowdFundingParseRoute($segments) { $vars = array(); //Get the active menu item. $app = JFactory::getApplication(); $menu = $app->getMenu(); $item = $menu->getActive(); // Count route segments $count = count($segments); // Standard routing for articles. If we don't pick up an Itemid then we get the view from the segments // the first segment is the view and the last segment is the id of the details, category or payment. if (!isset($item)) { $vars['view'] = $segments[0]; $vars['catid'] = $segments[$count - 1]; return $vars; } // COUNT == 1 // Category ( Discover ) if ($count == 1) { // we check to see if an alias is given. If not, we assume it is a project, // because categories have always alias. if (false == strpos($segments[0], ':')) { $vars['view'] = 'details'; $vars['id'] = (int) $segments[0]; return $vars; } list($id, $alias) = explode(':', $segments[0], 2); // first we check if it is a category $category = JCategories::getInstance('CrowdFunding')->get($id); if ($category and strcmp($category->alias, $alias) == 0) { $vars['view'] = 'discover'; $vars['id'] = $id; return $vars; } else { $project = CrowdFundingHelperRoute::getProject($id); if ($project) { if ($project->alias == $alias) { $vars['view'] = 'details'; $vars['catid'] = (int) $project->catid; $vars['id'] = (int) $id; return $vars; } } } } // COUNT >= 2 if ($count >= 2) { $view = $segments[$count - 1]; switch ($view) { case "backing": $itemId = (int) $segments[$count - 2]; // Get catid from menu item if (!empty($item->query["id"])) { $catId = (int) $item->query["id"]; } else { $catId = (int) $segments[$count - 3]; } $vars['view'] = 'backing'; $vars['id'] = (int) $itemId; $vars['catid'] = (int) $catId; break; case "embed": // Backing without reward $itemId = (int) $segments[$count - 2]; // Get catid from menu item if (!empty($item->query["id"])) { $catId = (int) $item->query["id"]; } else { $catId = (int) $segments[$count - 3]; } $vars['view'] = 'embed'; $vars['id'] = (int) $itemId; $vars['catid'] = (int) $catId; break; case "updates": // Screens of details - "updates", "comments", "funders" // Screens of details - "updates", "comments", "funders" case "comments": case "funders": $itemId = (int) $segments[$count - 2]; // Get catid from menu item if (!empty($item->query["id"])) { $catId = (int) $item->query["id"]; } else { $catId = (int) $segments[$count - 3]; } $vars['view'] = 'details'; $vars['id'] = (int) $itemId; $vars['catid'] = (int) $catId; // Get screen $screen = $segments[$count - 1]; $allowedScreens = array("updates", "comments", "funders"); if (in_array($screen, $allowedScreens)) { $vars['screen'] = $screen; } break; default: // if there was more than one segment, then we can determine where the URL points to // because the first segment will have the target category id prepended to it. If the // last segment has a number prepended, it is details, otherwise, it is a category. $catId = (int) $segments[$count - 2]; $id = (int) $segments[$count - 1]; if ($id > 0 and $catId > 0) { $vars['view'] = 'details'; $vars['catid'] = $catId; $vars['id'] = $id; } else { $vars['view'] = 'category'; $vars['id'] = $id; } break; } } return $vars; }
</td> <td> <?php echo $this->deliveryDate; ?> </td> </tr> </tbody> </table> </div> </div> </div> <div class="clearfix"></div> <a href="<?php echo JRoute::_(CrowdFundingHelperRoute::getFormRoute($this->reward->getProjectId(), "manager")); ?> " class="btn"> <i class="icon-circle-arrow-left"></i> <?php echo JText::_("COM_CROWDFUNDING_BACK_PROJECT_MANAGER"); ?> </a> <div class="clearfix"></div> <div class="pagination"> <?php if ($this->params->def('show_pagination_results', 1)) { ?> <p class="counter"> <?php
echo $this->params->get("pageclass_sfx"); ?> "> <div class="row-fluid"> <div class="span11"> <h2><?php echo JText::_("COM_CROWDFUNDING_SEND_TO_FRIEND"); ?> </h2> <p><?php echo JText::_("COM_CROWDFUNDING_SEND_TO_FRIEND_HELP"); ?> </p> <form method="post" action="<?php echo JRoute::_(CrowdFundingHelperRoute::getEmbedRoute($this->item->slug, $this->item->catslug) . "&task=friendmail.send"); ?> " class="bs-docs-example cfbf" id="form-send-to-friend" autocomplete="off"> <?php echo $this->form->getLabel('subject'); ?> <?php echo $this->form->getInput('subject'); ?> <?php echo $this->form->getLabel('sender_name'); ?> <?php echo $this->form->getInput('sender_name');
/** * Generate HTML code for embeding. * * @param object $item * @param string $host * * @return string * * @todo check this method */ protected function prepareEmbedCode($item, $host) { // Generate embed link $this->embedLink = $host . JRoute::_(CrowdFundingHelperRoute::getEmbedRoute($this->item->slug, $this->item->catslug) . "&layout=widget&tmpl=component", false); $code = '<iframe src="' . $this->embedLink . '" width="280px" height="560px" frameborder="0" scrolling="no"></iframe>'; return $code; }
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"); }
public function saveState() { // Check for request forgeries. JSession::checkToken("get") or jexit(JText::_('JINVALID_TOKEN')); $userId = JFactory::getUser()->get("id"); if (!$userId) { $redirectOptions = array("force_direction" => "index.php?option=com_users&view=login"); $this->displayNotice(JText::_('COM_CROWDFUNDING_ERROR_NOT_LOG_IN'), $redirectOptions); return; } // Get component parameters $params = JComponentHelper::getParams($this->option); /** @var $params Joomla\Registry\Registry */ // Get the data from the form $itemId = $this->input->get->get('id', 0, 'int'); $state = $this->input->get->get('state', 0, 'int'); $state = !$state ? 0 : 1; $return = $this->input->get->get('return'); $returnLink = JRoute::_(CrowdFundingHelperRoute::getProjectsRoute(), false); // Get return link from parameters. if (!empty($return)) { $returnLink = base64_decode($return); } $redirectOptions = array("force_direction" => $returnLink); $model = $this->getModel(); /** @var $model CrowdFundingModelProjectItem */ $item = $model->getItem($itemId, $userId); if (!$item->id) { $this->displayNotice(JText::_('COM_CROWDFUNDING_ERROR_INVALID_PROJECT'), $redirectOptions); return; } // Include plugins to validate content. $dispatcher = JEventDispatcher::getInstance(); JPluginHelper::importPlugin('content'); // Trigger onContentValidate event. $context = $this->option . ".projects.changestate"; $results = $dispatcher->trigger("onContentValidateChangeState", array($context, &$item, &$params, $state)); // If there is an error, redirect to another page. foreach ($results as $result) { if ($result["success"] == false) { $this->displayNotice(JArrayHelper::getValue($result, "message"), $redirectOptions); return; } } try { $model->saveState($itemId, $userId, $state); } catch (RuntimeException $e) { $this->setMessage($e->getMessage(), "warning"); $this->setRedirect($returnLink); return; } catch (Exception $e) { JLog::add($e->getMessage()); throw new Exception(JText::_('COM_CROWDFUNDING_ERROR_SYSTEM')); } // Redirect to next page if (!$state) { $msg = JText::_("COM_CROWDFUNDING_PROJECT_STOPPED_SUCCESSFULLY"); } else { $msg = JText::_("COM_CROWDFUNDING_PROJECT_LAUNCHED_SUCCESSFULLY_INFO"); } $this->displayMessage($msg, $redirectOptions); }
protected function sendMail($project, $emailId) { $app = JFactory::getApplication(); /** @var $app JApplicationSite */ // Send mail to the administrator if (!$emailId) { return false; } // Get website $uri = JUri::getInstance(); $website = $uri->toString(array("scheme", "host")); $emailMode = $this->params->get("email_mode", "plain"); // 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))); $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 $result = $mailer->sendMail($email->getSenderEmail(), $email->getSenderName(), $recipientMail, $subject, $body, CrowdFundingConstants::MAIL_MODE_HTML); } else { // Send as plain text. $result = $mailer->sendMail($email->getSenderEmail(), $email->getSenderName(), $recipientMail, $subject, $body, CrowdFundingConstants::MAIL_MODE_PLAIN); } // Log the error. if ($result !== true) { $this->log->add(JText::sprintf("PLG_CONTENT_CROWDFUNDINGADMINMAIL_ERROR_SEND_MAIL_ADMIN", $mailer->ErrorInfo), "PLG_CONTENT_ADMIN_EMAIL_ERROR"); return false; } return true; }
<?php if ($project->getId()) { ?> <li> <div class="thumbnail cf-project"> <img src="<?php echo $imageFolder . "/" . $project->getImage(); ?> " alt="<?php echo htmlspecialchars($project->getTitle(), ENT_QUOTES, "UTF-8"); ?> " width="200" height="200"> <div class="caption"> <h3> <a href="<?php echo JRoute::_(CrowdFundingHelperRoute::getDetailsRoute($project->getSlug(), $project->getCatSlug())); ?> "> <?php echo htmlspecialchars($project->getTitle(), ENT_QUOTES, "UTF-8"); ?> </a> </h3> <span class="font-xxsmall"> <?php echo JText::_("MOD_CROWDFUNDINGDETAILS_BY"); if (!empty($socialProfileLink)) { ?> <a href="<?php echo $socialProfileLink; ?>
<?php echo JHtml::_("crowdfunding.approved", $item->approved); ?> </td> <td class="hidden-phone"> <a href="<?php echo JRoute::_(CrowdFundingHelperRoute::getFormRoute($item->id)); ?> " class="btn btn-small"> <i class="icon-edit icon-white"></i> <?php echo JText::_("COM_CROWDFUNDING_EDIT"); ?> </a> <a href="<?php echo JRoute::_(CrowdFundingHelperRoute::getFormRoute($item->id, "manager")); ?> " class="btn btn-small"> <i class="icon-wrench icon-white"></i> <?php echo JText::_("COM_CROWDFUNDING_MANAGER"); ?> </a> </td> </tr> <?php } ?> </tbody> </table>
public function docheckout() { // Get component parameters $params = JComponentHelper::getParams("com_crowdfunding"); /** @var $params Joomla\Registry\Registry */ // Check for disabled payment functionality if ($params->get("debug_payment_disabled", 0)) { throw new Exception(JText::_("COM_CROWDFUNDING_ERROR_PAYMENT_HAS_BEEN_DISABLED_MESSAGE")); } $output = array(); // Get the name of the payment service. $paymentService = $this->paymentProcess->paymentService; // Trigger the event try { // Create project object. $item = $this->prepareItem($this->projectId, $params); $context = 'com_crowdfunding.payments.docheckout.' . JString::strtolower($paymentService); // Import CrowdFunding Payment Plugins $dispatcher = JEventDispatcher::getInstance(); JPluginHelper::importPlugin('crowdfundingpayment'); // Trigger onContentPreparePayment event. $results = $dispatcher->trigger("onPaymentsDoCheckout", array($context, &$item, &$params)); // Get the result, that comes from the plugin. if (!empty($results)) { foreach ($results as $result) { if (!is_null($result) and is_array($result)) { $output =& $result; break; } } } } catch (UnexpectedValueException $e) { $this->setMessage($e->getMessage(), "notice"); $this->setRedirect(JRoute::_(CrowdFundingHelperRoute::getDiscoverRoute(), false)); return; } catch (Exception $e) { // Store log data in the database $this->log->add(JText::_("COM_CROWDFUNDING_ERROR_SYSTEM"), "CONTROLLER_PAYMENTS_DOCHECKOUT_ERROR", $e->getMessage()); throw new Exception(JText::_("COM_CROWDFUNDING_ERROR_SYSTEM")); } $redirectUrl = JArrayHelper::getValue($output, "redirect_url"); if (!$redirectUrl) { throw new UnexpectedValueException(JText::_("COM_CROWDFUNDING_ERROR_INVALID_REDIRECT_URL")); } $this->setRedirect($redirectUrl); }
protected function sendMail($project, $emailId) { $app = JFactory::getApplication(); /** @var $app JApplicationSite */ // Get website $uri = JUri::getInstance(); $website = $uri->toString(array("scheme", "host")); $emailMode = $this->params->get("email_mode", "plain"); // Route project URI $appSite = JApplicationCms::getInstance('site'); $router = $appSite->getRouter('site'); $routedUri = $router->build(CrowdFundingHelperRoute::getDetailsRoute($project->slug, $project->catslug)); if ($routedUri instanceof JUri) { $routedUri = $routedUri->toString(); } if (0 === strpos($routedUri, "/administrator")) { $routedUri = str_replace("/administrator", "", $routedUri); } // Prepare data for parsing $data = array("site_name" => $app->get("sitename"), "site_url" => JUri::root(), "item_title" => $project->title, "item_url" => $website . $routedUri); // Send mail to the administrator if (!$emailId) { return false; } $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")); } $recipientName = $project->name; $recipientMail = $project->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 $result = $mailer->sendMail($email->getSenderEmail(), $email->getSenderName(), $recipientMail, $subject, $body, CrowdFundingConstants::MAIL_MODE_HTML); } else { // Send as plain text. $result = $mailer->sendMail($email->getSenderEmail(), $email->getSenderName(), $recipientMail, $subject, $body, CrowdFundingConstants::MAIL_MODE_PLAIN); } // Log the error. if ($result !== true) { $this->log->add(JText::sprintf("PLG_CONTENT_CROWDFUNDINGUSERMAIL_ERROR_SEND_MAIL_USER", $mailer->ErrorInfo), "PLG_CONTENT_USERE_MAIL_ERROR"); return false; } return true; }
public function onContentBeforeDisplay($context, &$article, &$params, $page = 0) { $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("html", $docType) != 0) { return null; } if (strcmp("com_crowdfunding.details", $context) != 0) { return null; } // Load language $this->loadLanguage(); $itemId = $app->input->getInt("id"); $stats = CrowdFundingHelper::getProjectData($itemId); $screen = $app->input->getCmd("screen", "home"); $html = '<ul class="nav nav-pills cf-plg-navigation">'; if ($this->params->get("display_home")) { $class = 'class="cf-plg-nav-home'; if (strcmp($screen, "home") == 0) { $class .= ' active'; } $class .= '"'; $html .= '<li ' . $class . '><a href="' . JRoute::_(CrowdFundingHelperRoute::getDetailsRoute($article->slug, $article->catslug)) . '">' . JText::_("PLG_CONTENT_CROWDFUNDINGNAV_HOME") . "</a></li>"; } if ($this->params->get("display_updates")) { $class = 'class="cf-plg-nav-updates'; if (strcmp($screen, "updates") == 0) { $class .= ' active'; } $class .= '"'; $stat = '<span class="label">' . JArrayHelper::getValue($stats, "updates", 0) . '</span>'; $html .= '<li ' . $class . '><a href="' . JRoute::_(CrowdFundingHelperRoute::getDetailsRoute($article->slug, $article->catslug, "updates")) . '">' . JText::_("PLG_CONTENT_CROWDFUNDINGNAV_UPDATES") . ' ' . $stat . '</a></li>'; } if ($this->params->get("display_comments")) { $class = 'class="cf-plg-nav-comments'; if (strcmp($screen, "comments") == 0) { $class .= ' active'; } $class .= '"'; if (!$params->get("comments_enabled", 1)) { $stat = '<span class="cf-dclabel"> </span>'; } else { $stat = '<span class="label">' . JArrayHelper::getValue($stats, "comments", 0) . '</span>'; } $html .= '<li ' . $class . '><a href="' . JRoute::_(CrowdFundingHelperRoute::getDetailsRoute($article->slug, $article->catslug, "comments")) . '">' . JText::_("PLG_CONTENT_CROWDFUNDINGNAV_COMMENTS") . ' ' . $stat . '</a></li>'; } if ($this->params->get("display_funders")) { $class = 'class="cf-plg-nav-funders'; if (strcmp($screen, "funders") == 0) { $class .= ' active'; } $class .= '"'; $stat = '<span class="label">' . JArrayHelper::getValue($stats, "funders", 0) . '</span>'; $html .= '<li ' . $class . '><a href="' . JRoute::_(CrowdFundingHelperRoute::getDetailsRoute($article->slug, $article->catslug, "funders")) . '">' . JText::_("PLG_CONTENT_CROWDFUNDINGNAV_FUNDERS") . ' ' . $stat . '</a></li>'; } $html .= '</ul>'; return $html; }
/** * @param string $slug * @param string $catslug * @param Joomla\Registry\Registry $params * @param string $url * * @return string */ private function getEmbeded($slug, $catslug, $params, $url) { $html = ""; if (!$params->get("display_embed_link", 1) and !$params->get("display_embed_button", 1) and !$params->get("display_embed_email", 1)) { return $html; } $html = '<div class="clearfix"></div>'; $html .= '<div class="crowdf-embeded">'; if ($params->get("display_embed_link", 1)) { $html .= '<input type="text" name="share_url" value="' . html_entity_decode($url, ENT_COMPAT, 'UTF-8') . '" class="crowdf-embeded-input" />'; } if ($params->get("display_embed_button", 1)) { $link = JRoute::_(CrowdFundingHelperRoute::getEmbedRoute($slug, $catslug), false); $html .= '<a href="' . $link . '" class="btn"><i class="icon-th-large"></i> ' . JText::_("PLG_CONTENT_CROWDFUNDINGSHARE_EMBED") . '</a>'; } if ($params->get("display_embed_email", 1)) { $link = JRoute::_(CrowdFundingHelperRoute::getEmbedRoute($slug, $catslug, "email"), false); $html .= '<a class="btn" href="' . $link . '"><i class="icon-envelope"></i> ' . JText::_("PLG_CONTENT_CROWDFUNDINGSHARE_EMAIL") . '</a>'; } $html .= '</div>'; return $html; }
protected function preparePayment(&$paymentSession) { // If missing the flag "step1", redirect to first step. if (!$paymentSession->step1) { $this->app->enqueueMessage(JText::_("COM_CROWDFUNDING_ERROR_INVALID_AMOUNT"), "notice"); $this->app->redirect(JRoute::_(CrowdFundingHelperRoute::getBackingRoute($this->item->slug, $this->item->catslug), false)); } // Check for both user states. The user must have only one state, registered or anonymous. $userId = JFactory::getUser()->get("id"); $aUserId = $this->app->getUserState("auser_id"); if (!empty($userId) and !empty($aUserId) or empty($userId) and empty($aUserId)) { // Reset anonymous hash user ID and redirect to first step. $this->app->setUserState("auser_id", ""); // Reset the flag for step 1 $paymentSession->step1 = false; $this->app->setUserState($this->paymentSessionContext, $paymentSession); $this->app->redirect(JRoute::_(CrowdFundingHelperRoute::getBackingRoute($this->item->slug, $this->item->catslug), false)); } if (!$this->item->days_left) { // Reset the flag for step 1 $paymentSession->step1 = false; $this->app->setUserState($this->paymentSessionContext, $paymentSession); $this->app->enqueueMessage(JText::_("COM_CROWDFUNDING_ERROR_PROJECT_COMPLETED"), "notice"); $this->app->redirect(JRoute::_(CrowdFundingHelperRoute::getBackingRoute($this->item->slug, $this->item->catslug), false)); } // Validate reward $this->reward = null; $keys = array("id" => $paymentSession->rewardId, "project_id" => $this->item->id); jimport("crowdfunding.reward"); $this->reward = new CrowdFundingReward(JFactory::getDbo()); $this->reward->load($keys); if ($this->reward->getId()) { if ($this->reward->isLimited() and !$this->reward->getAvailable()) { // Reset the flag for step 1 $paymentSession->step1 = false; $this->app->setUserState($this->paymentSessionContext, $paymentSession); $this->app->enqueueMessage(JText::_("COM_CROWDFUNDING_ERROR_REWARD_NOT_AVAILABLE"), "notice"); $this->app->redirect(JRoute::_(CrowdFundingHelperRoute::getBackingRoute($this->item->slug, $this->item->catslug), false)); } } // Validate amount $this->amount = $paymentSession->amount; if (!$this->amount) { // Reset the flag for step 1 $paymentSession->step1 = false; $this->app->setUserState($this->paymentSessionContext, $paymentSession); $this->app->enqueueMessage(JText::_("COM_CROWDFUNDING_ERROR_INVALID_AMOUNT"), "notice"); $this->app->redirect(JRoute::_(CrowdFundingHelperRoute::getBackingRoute($this->item->slug, $this->item->catslug), false)); } $item = new stdClass(); $item->id = $this->item->id; $item->title = $this->item->title; $item->slug = $this->item->slug; $item->catslug = $this->item->catslug; $item->rewardId = $paymentSession->rewardId; $item->amount = $paymentSession->amount; $item->currencyCode = $this->currency->getAbbr(); // Events JPluginHelper::importPlugin('crowdfundingpayment'); $dispatcher = JEventDispatcher::getInstance(); $results = $dispatcher->trigger('onProjectPayment', array('com_crowdfunding.payment', &$item, &$this->params)); $this->item->event = new stdClass(); $this->item->event->onProjectPayment = trim(implode("\n", $results)); }
if (strcmp("three_steps", $this->wizardType) == 0) { $layout = new JLayoutFile('payment_wizard', $this->layoutsBasePath); } else { $layout = new JLayoutFile('payment_wizard_four_steps', $this->layoutsBasePath); } echo $layout->render($this->layoutData); ?> </div> </div> <div class="row-fluid"> <div class="span12"> <form method="post" action="<?php echo JRoute::_(CrowdFundingHelperRoute::getBackingRoute($this->item->slug, $this->item->catslug)); ?> " class="bs-docs-example cfbf" id="form-pledge" autocomplete="off"> <fieldset> <legend><?php echo JText::_("COM_CROWDFUNDING_ENTER_YOUR_INVESTMENT_AMOUNT"); ?> </legend> <?php echo JHtml::_("crowdfunding.inputAmount", $this->rewardAmount, $this->currency, array("name" => "amount", "id" => "js-current-amount")); ?> <?php if ($this->params->get("backing_terms", 0)) { $termsUrl = $this->params->get("backing_terms_url", ""); ?> <label class="checkbox">
public function process() { $app = JFactory::getApplication(); /** @var $app JApplicationSite */ // Check for request forgeries. $requestMethod = $app->input->getMethod(); if (strcmp("POST", $requestMethod) == 0) { JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN')); } else { JSession::checkToken("get") or jexit(JText::_('JINVALID_TOKEN')); } // Get params $params = JComponentHelper::getParams("com_crowdfunding"); /** @var $params Joomla\Registry\Registry */ // Get the data from the form $itemId = $this->input->getInt('id', 0); $rewardId = $this->input->getInt('rid', 0); // Get amount $amount = $this->input->get("amount", 0, "float"); // Get user ID $user = JFactory::getUser(); $userId = (int) $user->get("id"); // Anonymous user ID $aUserId = ""; $model = $this->getModel(); /** @var $model CrowdFundingModelBacking */ // Get the item $item = $model->getItem($itemId); $returnUrl = CrowdFundingHelperRoute::getBackingRoute($item->slug, $item->catslug); // Authorise the user if (!$user->authorise("crowdfunding.donate", "com_crowdfunding")) { $this->setRedirect(JRoute::_($returnUrl, false), JText::_('COM_CROWDFUNDING_ERROR_NO_PERMISSIONS'), "notice"); return; } // Check for valid project if (empty($item->id)) { $this->setRedirect(JRoute::_(CrowdFundingHelperRoute::getDiscoverRoute()), JText::_('COM_CROWDFUNDING_ERROR_INVALID_PROJECT'), "notice"); return; } // Check for maintenance (debug) state if ($params->get("debug_payment_disabled", 0)) { $msg = JString::trim($params->get("debug_disabled_functionality_msg")); if (!$msg) { $msg = JText::_("COM_CROWDFUNDING_DEBUG_MODE_DEFAULT_MSG"); } $this->setRedirect(JRoute::_($returnUrl, false), $msg, "notice"); return; } // Check for agreed conditions from the user if ($params->get("backing_terms", 0)) { $terms = $this->input->get("terms", 0, "int"); if (!$terms) { $this->setRedirect(JRoute::_($returnUrl, false), JText::_("COM_CROWDFUNDING_ERROR_TERMS_NOT_ACCEPTED"), "notice"); return; } } // Check for valid amount if (!$amount) { $this->setRedirect(JRoute::_($returnUrl, false), JText::_("COM_CROWDFUNDING_ERROR_INVALID_AMOUNT"), "notice"); return; } // Store payment process data // Get the payment process object and // store the selected data from the user. $paymentSessionContext = CrowdFundingConstants::PAYMENT_SESSION_CONTEXT . $item->id; $paymentSession = $app->getUserState($paymentSessionContext); $paymentSession->step1 = true; $paymentSession->amount = $amount; $paymentSession->rewardId = $rewardId; $app->setUserState($paymentSessionContext, $paymentSession); // Create an intention. // Generate hash user ID used for anonymous payment. if (!$userId) { $aUserId = $app->getUserState("auser_id"); if (!$aUserId) { // Generate a hash ID for anonymous user. jimport("itprism.string"); $anonymousUserId = new ITPrismString(); $anonymousUserId->generateRandomString(32); $aUserId = (string) $anonymousUserId; $app->setUserState("auser_id", $aUserId); } $intentionKeys = array("auser_id" => $aUserId, "project_id" => $item->id); } else { $intentionKeys = array("user_id" => $userId, "project_id" => $item->id); } jimport("crowdfunding.intention"); $intention = new CrowdFundingIntention(JFactory::getDbo()); $intention->load($intentionKeys); $date = new JDate(); $custom = array("user_id" => $userId, "auser_id" => $aUserId, "project_id" => $item->id, "reward_id" => $rewardId, "record_date" => $date->toSql(), "session_id" => $paymentSession->session_id); $intention->bind($custom); $intention->store(); // Redirect to next page $link = CrowdFundingHelperRoute::getBackingRoute($item->slug, $item->catslug, "payment"); $this->setRedirect(JRoute::_($link, false)); }
protected static function findItem($needles = null) { $app = JFactory::getApplication(); $menus = $app->getMenu('site'); // Prepare the reverse lookup array. // Collect all menu items and creat an array that contains // the ID from the query string of the menu item as a key, // and the menu item id (Itemid) as a value // Example: // array( "category" => // 1(id) => 100 (Itemid), // 2(id) => 101 (Itemid) // ); if (self::$lookup === null) { self::$lookup = array(); $component = JComponentHelper::getComponent('com_crowdfunding'); $items = $menus->getItems('component_id', $component->id); if ($items) { foreach ($items as $item) { if (isset($item->query) && isset($item->query['view'])) { $view = $item->query['view']; if (!isset(self::$lookup[$view])) { self::$lookup[$view] = array(); } if (isset($item->query['id'])) { self::$lookup[$view][$item->query['id']] = $item->id; } else { // If it is a root element that have no a request parameter ID ( categories, authors ), we set 0 for an key self::$lookup[$view][0] = $item->id; } } } } } if ($needles) { foreach ($needles as $view => $ids) { if (isset(self::$lookup[$view])) { foreach ($ids as $id) { if (isset(self::$lookup[$view][(int) $id])) { return self::$lookup[$view][(int) $id]; } } } } } else { $active = $menus->getActive(); if ($active) { return $active->id; } } return null; }