public function onContentAfterDisplay($context, &$item, &$params) { if (strcmp("com_crowdfunding.details", $context) != 0) { return null; } if ($this->app->isAdmin()) { return null; } $doc = JFactory::getDocument(); /** @var $doc JDocumentHtml */ // Check document type $docType = $doc->getType(); if (strcmp("html", $docType) != 0) { return null; } $html = ""; $files = new CrowdfundingFiles\Files(JFactory::getDbo()); $files->load(array("project_id" => $item->id)); if (count($files) > 0) { $mediaFolderUri = CrowdfundingFilesHelper::getMediaFolderUri($item->user_id); // Get the path for the layout file $path = JPath::clean(JPluginHelper::getLayoutPath('content', 'crowdfundingfiles')); // Render the login form. ob_start(); include $path; $html = ob_get_clean(); } return $html; }
/** * This method validates project data before a user launch its campaign. * It works only on front-end. * * @param string $context * @param stdClass $item * @param Joomla\Registry\Registry $params * @param int $state * * @return null|array */ public function onContentValidateChangeState($context, &$item, &$params, $state) { if (strcmp('com_crowdfunding.projects.changestate', $context) !== 0) { return null; } // This validation have to be processed when the state is for launching (publishing) campaign. if ((int) $state !== 1) { return null; } if ($this->app->isAdmin()) { return null; } $doc = JFactory::getDocument(); /** @var $doc JDocumentHtml */ // Check document type $docType = $doc->getType(); if (strcmp('html', $docType) !== 0) { return null; } $result = array('success' => false, 'message' => ''); // Get user ID. $userId = JFactory::getUser()->get('id'); // Get component parameters $componentParams = JComponentHelper::getParams('com_crowdfundingfinance'); /** @var $componentParams Joomla\Registry\Registry */ // Verify the number of campaigns per user at one time. $allowedActiveCampaigns = (int) $componentParams->get('protection_active_projects'); if ($allowedActiveCampaigns > 0) { // Get the number of active projects for a user. $userStatistics = new Crowdfunding\Statistics\User(JFactory::getDbo(), $userId); $activeCampaigns = (int) $userStatistics->getNumberOfActiveCampaigns(); // Validate number of active campaigns per user. if ($activeCampaigns >= $allowedActiveCampaigns) { $result['message'] = JText::sprintf('PLG_CONTENT_CROWDFUNDINGFRAUDPREVENTION_ERROR_ACTIVE_PROJECTS_D', $allowedActiveCampaigns); return $result; } } // Verify the number of campaigns per user per year. $allowedCampaignsPerYear = (int) $componentParams->get('protection_projects_per_year'); if ($allowedCampaignsPerYear > 0) { // Get the number of active projects for a user. $userStatistics = new Crowdfunding\Statistics\User(JFactory::getDbo(), $userId); $numberOfCampaigns = (int) $userStatistics->getNumberOfCampaignsInPeriod(); // Validate number of campaigns per year. if ($numberOfCampaigns >= $allowedCampaignsPerYear) { $result['message'] = JText::sprintf('PLG_CONTENT_CROWDFUNDINGFRAUDPREVENTION_ERROR_PROJECTS_YEAR_D', $allowedCampaignsPerYear); return $result; } } // Validation completed successfully. $result = array('success' => true); return $result; }
/** * This method does some validations before the system to provide payment methods. * * @param string $context This string gives information about that where it has been executed the trigger. * @param stdClass $item A project data. * @param Prism\Money\Money $money An Money object. * @param Joomla\Registry\Registry $params The parameters of the component * * @throws \InvalidArgumentException * * @return null|string */ public function onBeforePaymentAuthorize($context, &$item, &$money, &$params) { if (strcmp('com_crowdfunding.before.payment.authorize', $context) !== 0) { return null; } if ($this->app->isAdmin()) { return null; } $doc = JFactory::getDocument(); /** @var $doc JDocumentHtml */ // Check document type $docType = $doc->getType(); if (strcmp('html', $docType) !== 0) { return null; } // Get user ID. $userId = JFactory::getUser()->get('id'); $html = array(); // Display login form if (!$userId) { $html[] = '<p class="bg-warning p-5">'; $html[] = '<span class="fa fa-exclamation-triangle"></span>'; $html[] = JText::_('PLG_CROWDFUNDINGPAYMENT_FRAUD_PREVENTION_ERROR_NOT_REGISTERED'); $html[] = '</p>'; } // Verifications // Get component parameters $componentParams = JComponentHelper::getParams('com_crowdfundingfinance'); /** @var $componentParams Joomla\Registry\Registry */ // Verify maximum allowed amount for contribution. $allowedContributedAmount = $money->setAmount($componentParams->get('protection_max_contributed_amount'))->parse(); // Validate maximum allowed amount. if ($allowedContributedAmount and $allowedContributedAmount < (double) $item->amount) { $html[] = '<p class="bg-warning p-5">'; $html[] = '<span class="fa fa-exclamation-triangle"></span>'; $html[] = JText::sprintf('PLG_CROWDFUNDINGPAYMENT_FRAUD_PREVENTION_ERROR_CONTRIBUTION_AMOUNT_S', $money->setAmount($allowedContributedAmount)->formatCurrency()); $html[] = '</p>'; } // Verify the number of payments per project. $allowedPaymentsPerProject = (int) $componentParams->get('protection_payments_per_project'); if ($allowedPaymentsPerProject > 0) { $userStatistics = new Crowdfunding\Statistics\User(JFactory::getDbo(), $userId); $paymentsPerProject = (int) $userStatistics->getNumberOfPayments($item->id); // Validate number of payments per project. if ($paymentsPerProject >= $allowedPaymentsPerProject) { $html[] = '<p class="bg-warning p-5">'; $html[] = '<span class="fa fa-exclamation-triangle"></span>'; $html[] = JText::sprintf('PLG_CROWDFUNDINGPAYMENT_FRAUD_PREVENTION_ERROR_PAYMENT_PER_PROJECT_D', $allowedPaymentsPerProject); $html[] = '</p>'; } } return count($html) > 0 ? implode("\n", $html) : null; }
/** * This method prepares a code that will be included to step "Extras" on project wizard. * * @param string $context This string gives information about that where it has been executed the trigger. * @param object $item A project data. * @param Joomla\Registry\Registry $params The parameters of the component * * @return null|string */ public function onExtrasDisplay($context, &$item, &$params) { if (strcmp("com_crowdfunding.project.extras", $context) != 0) { return null; } if ($this->app->isAdmin()) { return null; } $doc = JFactory::getDocument(); /** @var $doc JDocumentHtml */ // Check document type $docType = $doc->getType(); if (strcmp("html", $docType) != 0) { return null; } if (empty($item->user_id)) { return null; } // Create a media folder. $mediaFolder = CrowdfundingFilesHelper::getMediaFolder(); if (!JFolder::exists($mediaFolder)) { CrowdfundingHelper::createFolder($mediaFolder); } // Create a media folder for a user. $mediaFolder = CrowdfundingFilesHelper::getMediaFolder($item->user_id); if (!JFolder::exists($mediaFolder)) { CrowdfundingHelper::createFolder($mediaFolder); } $componentParams = JComponentHelper::getParams("com_crowdfundingfiles"); /** @var $componentParams Joomla\Registry\Registry */ $mediaUri = CrowdfundingFilesHelper::getMediaFolderUri($item->user_id); $options = array("project_id" => $item->id, "user_id" => $item->user_id); $files = new CrowdfundingFiles\Files(JFactory::getDbo()); $files->load($options); // Load jQuery JHtml::_("jquery.framework"); JHtml::_("prism.ui.pnotify"); JHtml::_('prism.ui.fileupload'); JHtml::_('prism.ui.joomlaHelper'); // Include the translation of the confirmation question. JText::script('PLG_CROWDFUNDING_FILES_DELETE_QUESTION'); // Get the path for the layout file $path = JPath::clean(JPluginHelper::getLayoutPath('crowdfunding', 'files')); // Render the login form. ob_start(); include $path; $html = ob_get_clean(); return $html; }
/** * This method is executed after complete payment. * It is used to be stored the transaction ID and the investor ID in data record. * * @param object $context * @param object $transaction Transaction data * @param Joomla\Registry\Registry $params Component parameters * @param object $project Project data * @param object $reward Reward data * @param object $paymentSession Payment session object. * * @return void */ public function onAfterPayment($context, &$transaction, &$params, &$project, &$reward, &$paymentSession) { if (0 !== strpos($context, "com_crowdfunding.notify")) { return; } if ($this->app->isAdmin()) { return; } $doc = JFactory::getDocument(); /** @var $doc JDocumentHtml */ // Check document type $docType = $doc->getType(); if (strcmp("raw", $docType) != 0) { return; } // Load record data from database. $keys = array("session_id" => $paymentSession->session_id); $record = new CrowdfundingData\Record(JFactory::getDbo()); $record->load($keys); if (!$record->getId()) { return null; } // Set transaction ID. if (!empty($transaction->id)) { $record->setTransactionId($transaction->id); } // Set user ID. if (!empty($transaction->investor_id)) { $record->setUserId($transaction->investor_id); } $record->store(); }
/** * This method prepares a code that will be included to step "Extras" on project wizard. * * @param string $context This string gives information about that where it has been executed the trigger. * @param object $item A project data. * @param Joomla\Registry\Registry $params The parameters of the component * * @return null|string */ public function onExtrasDisplay($context, &$item, &$params) { if (strcmp("com_crowdfunding.project.extras", $context) != 0) { return null; } if ($this->app->isAdmin()) { return null; } $doc = JFactory::getDocument(); /** @var $doc JDocumentHtml */ // Check document type $docType = $doc->getType(); if (strcmp("html", $docType) != 0) { return null; } if (empty($item->user_id)) { return null; } // A flag that shows the options are active. if (!$this->params->get("display_paypal", 0) and !$this->params->get("display_banktransfer", 0)) { return ""; } $activeTab = ""; if ($this->params->get("display_paypal", 0)) { $activeTab = "paypal"; } elseif ($this->params->get("display_banktransfer", 0)) { $activeTab = "banktransfer"; } $payout = new CrowdfundingFinance\Payout(JFactory::getDbo()); $payout->load($item->id); // Load jQuery JHtml::_("jquery.framework"); JHtml::_("prism.ui.pnotify"); JHtml::_('prism.ui.joomlaHelper'); // Get the path for the layout file $path = JPath::clean(JPluginHelper::getLayoutPath('crowdfunding', 'payoutoptions')); // Render the login form. ob_start(); include $path; $html = ob_get_clean(); return $html; }
private function isRestricted() { if ($this->app->isAdmin()) { return true; } $document = JFactory::getDocument(); /** @var $document JDocumentHTML */ $type = $document->getType(); if (strcmp('html', $type) !== 0) { return true; } // It works only for GET request $method = $this->app->input->getMethod(); if (strcmp('GET', $method) !== 0) { return true; } // Check component enabled if (!JComponentHelper::isEnabled('com_itpmeta')) { return true; } return false; }
/** * Generate and display a list of team members on details page. * * @param string $context * @param object $item * @param Joomla\Registry\Registry $params * * @return null|string */ public function onContentAfterDisplay($context, &$item, &$params) { if (strcmp("com_crowdfunding.details", $context) != 0) { return null; } if ($this->app->isAdmin()) { return null; } $doc = JFactory::getDocument(); /** @var $doc JDocumentHtml */ // Check document type $docType = $doc->getType(); if (strcmp("html", $docType) != 0) { return null; } $html = ""; $partners = new CrowdfundingPartners\Partners(JFactory::getDbo()); $partners->load($item->id); if (0 < count($partners)) { // Include the project owner to the team. if ($this->params->get("display_owner", 0)) { $user = JFactory::getUser($item->user_id); $owner = array("name" => $user->get("name"), "project_id" => $item->id, "partner_id" => $item->user_id); $partners->add($owner); } // Get a social platform for integration $socialPlatform = $params->get("integration_social_platform"); // Prepare avatars. $this->prepareIntegration($partners, $socialPlatform); // Get the path for the layout file $path = JPath::clean(JPluginHelper::getLayoutPath('content', 'crowdfundingpartners')); // Render the login form. ob_start(); include $path; $html = ob_get_clean(); } return $html; }
/** * This method prepares a code that will be included to step "Extras" on project wizard. * * @param string $context This string gives information about that where it has been executed the trigger. * @param object $item A project data. * @param Joomla\Registry\Registry $params The parameters of the component * * @return null|string */ public function onExtrasDisplay($context, &$item, &$params) { if (strcmp("com_crowdfunding.project.extras", $context) != 0) { return null; } if ($this->app->isAdmin()) { return null; } $doc = JFactory::getDocument(); /** @var $doc JDocumentHtml */ // Check document type $docType = $doc->getType(); if (strcmp("html", $docType) != 0) { return null; } if (empty($item->user_id)) { return null; } $partners = new CrowdfundingPartners\Partners(JFactory::getDbo()); $partners->load($item->id); // Get a social platform for integration $socialPlatform = $params->get("integration_social_platform"); // Prepare avatars. $this->prepareIntegration($partners, $socialPlatform); // Load jQuery JHtml::_("jquery.framework"); JHtml::_("prism.ui.pnotify"); JHtml::_('prism.ui.joomlaHelper'); // Include the translation of the confirmation question. JText::script('PLG_CROWDFUNDING_PARTNERS_DELETE_QUESTION'); // Get the path for the layout file $path = JPath::clean(JPluginHelper::getLayoutPath('crowdfunding', 'partners')); // Render the login form. ob_start(); include $path; $html = ob_get_clean(); return $html; }
/** * This method is used from the system to authorize step 2, * when you use a payment wizard in four steps. * If this method return true, the system will continue to step 2. * * @param string $context This string gives information about that where it has been executed the trigger. * @param object $item * @param Joomla\Registry\Registry $params * @param JUser $user * * @return bool */ public function onPaymentAuthorize($context, &$item, &$params, &$user) { if (strcmp("com_crowdfunding.payment.authorize", $context) != 0) { return null; } if ($this->app->isAdmin()) { return null; } $doc = JFactory::getDocument(); /** @var $doc JDocumentHtml */ // Check document type $docType = $doc->getType(); if (strcmp("html", $docType) != 0) { return null; } return true; }
/** * This method is executed after complete payment. * It is used to be sent mails to user and administrator * * @param string $context Transaction data * @param \stdClass $transaction Transaction data * @param Registry $params Component parameters * @param \stdClass $project Project data * @param \stdClass $reward Reward data * @param \stdClass $paymentSession Payment session data. */ public function onAfterPayment($context, &$transaction, &$params, &$project, &$reward, &$paymentSession) { if (strcmp('com_crowdfunding.notify.' . $this->serviceAlias, $context) !== 0) { return; } if ($this->app->isAdmin()) { return; } $doc = \JFactory::getDocument(); /** @var $doc \JDocumentHtml */ // Check document type $docType = $doc->getType(); if (strcmp('raw', $docType) !== 0) { return; } // Send mails $this->sendMails($project, $transaction, $params, $reward); }
/** * This method is executed after complete payment. * It is used to be sent mails to user and administrator * * @param string $context * @param object $transaction Transaction data * @param Joomla\Registry\Registry $params Component parameters * @param object $project Project data * @param object $reward Reward data * @param object $paymentSession Payment session data. * * @return void */ public function onAfterPayment($context, &$transaction, &$params, &$project, &$reward, &$paymentSession) { if (strcmp("com_crowdfunding.notify.paypal", $context) != 0) { return; } if ($this->app->isAdmin()) { return; } $doc = JFactory::getDocument(); /** @var $doc JDocumentRaw */ // Check document type $docType = $doc->getType(); if (strcmp("raw", $docType) != 0) { return; } // Send mails $this->sendMails($project, $transaction, $params); }
/** * This method will be executed after all payment events, especially onAfterPaymentNotify. * It is used to close payment session. * * <code> * $paymentResult->transaction; * $paymentResult->project; * $paymentResult->reward; * $paymentResult->paymentSession; * $paymentResult->serviceProvider; * $paymentResult->serviceAlias; * $paymentResult->response; * $paymentResult->returnUrl; * $paymentResult->message; * $paymentResult->triggerEvents; * </code> * * @param string $context * @param \stdClass $paymentResult Object that contains Transaction, Reward, Project, PaymentSession, etc. * @param Registry $params Component parameters * * @throws \InvalidArgumentException */ public function onAfterPayment($context, $paymentResult, $params) { if (!preg_match('/com_crowdfunding\\.(notify|payments)/', $context)) { return; } if ($this->app->isAdmin()) { return; } // Check document type $docType = \JFactory::getDocument()->getType(); if (!in_array($docType, array('raw', 'html'), true)) { return; } $paymentSession = $paymentResult->paymentSession; /** @var PaymentSessionRemote $paymentSession */ // Remove payment session record from database. if ($paymentSession instanceof PaymentSessionRemote and $paymentSession->getId()) { $paymentSession->delete(); } }
/** * Disconnect user from payment gateway. * * @param string $context * @param Joomla\Registry\Registry $params * * @return null|array */ public function onPayoutsDeauthorize($context, $params) { if (strcmp('com_crowdfundingfinance.payouts.deauthorize.stripeconnect', $context) !== 0) { return null; } if ($this->app->isAdmin()) { return null; } $doc = JFactory::getDocument(); /** @var $doc JDocumentHtml */ // Check document type $docType = $doc->getType(); if (strcmp('html', $docType) !== 0) { return null; } // Prepare output data. $output = array('redirect_url' => '', 'message' => ''); $errorOutput = array('redirect_url' => JRoute::_(CrowdfundingHelperRoute::getDiscoverRoute()), 'message' => ''); // DEBUG DATA JDEBUG ? $this->log->add(JText::_($this->textPrefix . '_DEBUG_GET_RESPONSE_AUTHORIZE'), $this->debugType, $_GET) : null; $userId = JFactory::getUser()->get('id'); if (!$userId) { $errorOutput['message'] = JText::_($this->textPrefix . '_ERROR_NOT_REGISTERED_USER'); return $errorOutput; } // Get token $state = $this->app->input->get('state'); if (!$state) { $errorOutput['message'] = JText::_($this->textPrefix . '_ERROR_INVALID_AUTHORIZATION_DATA'); return $errorOutput; } // Get project ID and redirect URL from the session. $stateData = $this->app->getUserState($state); if (count($stateData) === 0 or (!$stateData['redirect_url'] or !$stateData['project_id'])) { $errorOutput['message'] = JText::_($this->textPrefix . '_ERROR_INVALID_AUTHORIZATION_DATA'); return $errorOutput; } $cfFinanceParams = JComponentHelper::getParams('com_crowdfundingfinance'); $apiKeys = Crowdfundingfinance\Stripe\Helper::getKeys($cfFinanceParams); if (!$apiKeys['client_id'] or !$apiKeys['secret_key']) { $errorOutput['message'] = JText::_($this->textPrefix . '_ERROR_CONFIGURATION'); return $errorOutput; } $payout = new Crowdfundingfinance\Payout(JFactory::getDbo()); $payout->setSecretKey($this->app->get('secret')); $payout->load(array('project_id' => (int) $stateData['project_id'])); if (!$payout->getId()) { $errorOutput['message'] = JText::_($this->textPrefix . '_ERROR_INVALID_PAYOUT'); return $errorOutput; } $alias = !$apiKeys['test'] ? 'production' : 'test'; $stripeData = $payout->getStripe(); if (!$stripeData->get('stripeconnect.' . $alias . '.account_id')) { $errorOutput['message'] = JText::_($this->textPrefix . '_ERROR_NOT_CONNECTED'); return $errorOutput; } Crowdfundingfinance\Stripe\Helper::deauthorize($apiKeys, $stripeData->get('stripeconnect.' . $alias . '.account_id')); $stripeData->set('stripeconnect.' . $alias . '.access_token', ''); $stripeData->set('stripeconnect.' . $alias . '.refresh_token', ''); $stripeData->set('stripeconnect.' . $alias . '.account_id', ''); $stripeData->set('stripeconnect.' . $alias . '.expires', 0); $payout->setStripe($stripeData); $payout->storeStripe(); // Get next URL. $output['redirect_url'] = base64_decode($stateData['redirect_url']); return $output; }
/** * Tests the JApplicationCms::isAdmin method. * * @return void * * @since 3.2 */ public function testIsAdmin() { $this->assertFalse($this->class->isAdmin()); }
/** * Tests the JApplicationCms::isAdmin method. * * @return void * * @since 3.2 */ public function testIsAdmin() { $this->assertThat($this->class->isAdmin(), $this->isFalse(), 'JApplicationAdministrator is not an admin app'); }