示例#1
0
 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);
 }
示例#2
0
 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);
 }
示例#3
0
 protected function removeTransactions(CrowdFundingProject $project)
 {
     // Create query object
     $db = $this->getDbo();
     $query = $db->getQuery(true);
     $query->delete($db->quoteName("#__crowdf_transactions"))->where($db->quoteName("project_id") . "=" . (int) $project->getId());
     $db->setQuery($query);
     $db->execute();
 }
示例#4
0
 /**
  * @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;
 }
示例#5
0
 /**
  * This method is invoked when the administrator changes transaction status from the backend.
  *
  * @param string  $context  This string gives information about that where it has been executed the trigger.
  * @param object  $item  A transaction data.
  * @param string  $oldStatus  Old status
  * @param string  $newStatus  New status
  *
  * @return void
  */
 public function onTransactionChangeState($context, &$item, $oldStatus, $newStatus)
 {
     $allowedContexts = array("com_crowdfunding.transaction", "com_crowdfundingfinance.transaction");
     if (!in_array($context, $allowedContexts)) {
         return;
     }
     $app = JFactory::getApplication();
     /** @var $app JApplicationSite */
     if ($app->isSite()) {
         return;
     }
     $doc = JFactory::getDocument();
     /**  @var $doc JDocumentHtml * */
     // Check document type
     $docType = $doc->getType();
     if (strcmp("html", $docType) != 0) {
         return;
     }
     // Verify the service provider.
     $paymentService = str_replace(" ", "", JString::strtolower(JString::trim($item->service_provider)));
     if (strcmp($this->paymentService, $paymentService) != 0) {
         return;
     }
     if (strcmp($oldStatus, "completed") == 0) {
         // Remove funds if someone change the status from completed to other one.
         jimport("crowdfunding.project");
         $project = new CrowdFundingProject(JFactory::getDbo());
         $project->load($item->project_id);
         // DEBUG DATA
         JDEBUG ? $this->log->add(JText::_($this->textPrefix . "_DEBUG_BCSNC"), $this->debugType, $project->getProperties()) : null;
         $project->removeFunds($item->txn_amount);
         $project->updateFunds();
         // DEBUG DATA
         JDEBUG ? $this->log->add(JText::_($this->textPrefix . "_DEBUG_ACSNC"), $this->debugType, $project->getProperties()) : null;
     } elseif (strcmp($newStatus, "completed") == 0) {
         // Add funds if someone change the status to completed.
         jimport("crowdfunding.project");
         $project = new CrowdFundingProject(JFactory::getDbo());
         $project->load($item->project_id);
         // DEBUG DATA
         JDEBUG ? $this->log->add(JText::_($this->textPrefix . "_DEBUG_BCSTC"), $this->debugType, $project->getProperties()) : null;
         $project->addFunds($item->txn_amount);
         $project->updateFunds();
         // DEBUG DATA
         JDEBUG ? $this->log->add(JText::_($this->textPrefix . "_DEBUG_ACSTC"), $this->debugType, $project->getProperties()) : null;
     }
 }
$view = $app->input->get("view");
$allowedViews = array("backing", "embed");
// If option is not "com_crowdfunding" and view is not one of allowed,
// do not display anything.
if (strcmp($option, "com_crowdfunding") != 0 or !in_array($view, $allowedViews)) {
    echo JText::_("MOD_CROWDFUNDINGDETAILS_ERROR_INVALID_VIEW");
    return;
}
$projectId = $app->input->getInt("id");
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));
 public function onAfterDispatch()
 {
     $app = JFactory::getApplication();
     /** @var $app JApplicationSite */
     if ($app->isAdmin()) {
         return;
     }
     $document = JFactory::getDocument();
     /** @var $document JDocumentHTML * */
     $type = $document->getType();
     if (strcmp("html", $type) != 0) {
         return;
     }
     // It works only for GET and POST requests.
     $method = JString::strtolower($app->input->getMethod());
     if (!in_array($method, array("get", "post"))) {
         return;
     }
     // Check component enabled
     if (!JComponentHelper::isEnabled('com_crowdfunding', true)) {
         return;
     }
     $view = $app->input->getCmd("view");
     $option = $app->input->getCmd("option");
     $isCrowdFundingComponent = strcmp($option, "com_crowdfunding") == 0;
     $isDetailsPage = (strcmp($option, "com_crowdfunding") == 0 and strcmp($view, "details") == 0);
     // Allowed views for the module CrowdFunding Details
     $allowedViews = array("backing", "embed");
     if ($this->params->get("module_info_details_page", 0)) {
         if (!$isCrowdFundingComponent or !$isDetailsPage) {
             $this->hideModule("mod_crowdfundinginfo");
         }
     }
     if ($this->params->get("module_rewards_details_page", 0)) {
         if (!$isCrowdFundingComponent or !$isDetailsPage) {
             $this->hideModule("mod_crowdfundingrewards");
         } else {
             // Check project type. If the reawards are disable, hide the module.
             $projectId = $app->input->getInt("id");
             if (!empty($projectId)) {
                 jimport("crowdfunding.project");
                 jimport("crowdfunding.type");
                 $project = CrowdFundingProject::getInstance(JFactory::getDbo(), $projectId);
                 $type = $project->getType();
                 // Hide the module CrowdFunding Rewards, if rewards are disabled for this type.
                 if (!is_null($type) and !$type->isRewardsEnabled()) {
                     $this->hideModule("mod_crowdfundingrewards");
                 }
             }
         }
     }
     // Module Profile Details page
     if ($this->params->get("module_profile_details_page", 0)) {
         if (!$isCrowdFundingComponent or !$isDetailsPage) {
             $this->hideModule("mod_crowdfundingprofile");
         }
     }
     // Backing page
     if ($this->params->get("module_details_backing_page", 0)) {
         if (strcmp($option, "com_crowdfunding") != 0 or strcmp($option, "com_crowdfunding") == 0 and !in_array($view, $allowedViews)) {
             $this->hideModule("mod_crowdfundingdetails");
         }
     }
     // Embed page
     if ($this->params->get("module_details_embed_page", 0)) {
         if (strcmp($option, "com_crowdfunding") != 0 or strcmp($option, "com_crowdfunding") == 0 and !in_array($view, $allowedViews)) {
             $this->hideModule("mod_crowdfundingdetails");
         }
     }
     // Module Filter Discover page
     if ($this->params->get("module_filters_discover_page", 0)) {
         if (strcmp($option, "com_crowdfunding") != 0 or strcmp($option, "com_crowdfunding") == 0 and strcmp($view, "discover") != 0) {
             $this->hideModule("mod_crowdfundingfilters");
         }
     }
 }
示例#8
0
 /**
  * Create an object.
  *
  * <code>
  * $projectId = 1;
  *
  * $project   = CrowdFundingProject::getInstance(JFactory::getDbo());
  * $project->load($projectId);
  * </code>
  *
  * @param JDatabaseDriver $db
  * @param int $id
  *
  * @return null|CrowdFundingProject
  */
 public static function getInstance(JDatabaseDriver $db, $id)
 {
     if (is_null(self::$instance)) {
         $item = new CrowdFundingProject($db);
         $item->load($id);
         self::$instance = $item;
     }
     return self::$instance;
 }
示例#9
0
    protected function prepareRewards()
    {
        $model = JModelLegacy::getInstance("Rewards", "CrowdFundingModel", $config = array('ignore_request' => false));
        // Initialise variables
        // Get state
        /** @var  $state Joomla\Registry\Registry */
        $state = $model->getState();
        $this->state = $state;
        // Get params
        /** @var  $params Joomla\Registry\Registry */
        $params = $this->state->get("params");
        $this->params = $params;
        $this->projectId = $this->state->get("rewards.id");
        $this->items = $model->getItems($this->projectId);
        // Get project and validate it
        jimport("crowdfunding.project");
        $project = CrowdFundingProject::getInstance(JFactory::getDbo(), $this->projectId);
        $project = $project->getProperties();
        $this->item = JArrayHelper::toObject($project);
        if (!$this->item->id or $this->item->user_id != $this->userId) {
            throw new Exception(JText::_("COM_CROWDFUNDING_ERROR_INVALID_PROJECT"));
        }
        // Create a currency object.
        jimport("crowdfunding.currency");
        $currencyId = $this->params->get("project_currency");
        $this->currency = CrowdFundingCurrency::getInstance(JFactory::getDbo(), $currencyId, $this->params);
        // Get date format
        $this->dateFormat = CrowdFundingHelper::getDateFormat();
        $this->dateFormatCalendar = CrowdFundingHelper::getDateFormat(true);
        $js = '
	        // Rewards calendar date format.
            var projectWizard = {
                dateFormat: "' . $this->dateFormatCalendar . '"
            };
        ';
        $this->document->addScriptDeclaration($js);
        // Prepare rewards images.
        $this->rewardsImagesEnabled = $this->params->get("rewards_images", 0);
        $this->rewardsImagesUri = CrowdFundingHelper::getImagesFolderUri($this->userId);
        $this->prepareProjectType();
        $this->pathwayName = JText::_("COM_CROWDFUNDING_STEP_REWARDS");
    }
示例#10
0
 /**
  * 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;
 }