Esempio n. 1
0
 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));
 }
Esempio n. 2
0
 protected function prepareRewards(&$paymentSession)
 {
     // Create payment session ID.
     jimport("itprism.string");
     $sessionId = new ITPrismString();
     $sessionId->generateRandomString(32);
     $paymentSession->session_id = (string) $sessionId;
     // Get selected reward ID
     $this->rewardId = $this->state->get("reward_id");
     // If it has been selected another reward, set the old one to 0.
     if ($this->rewardId != $paymentSession->rewardId) {
         $paymentSession->rewardId = 0;
         $paymentSession->step1 = false;
     }
     // Get amount from session
     $this->rewardAmount = !$paymentSession->amount ? 0 : $paymentSession->amount;
     // Get rewards
     jimport("crowdfunding.rewards");
     $this->rewards = new CrowdFundingRewards(JFactory::getDbo());
     $this->rewards->load($this->item->id, array("state" => 1));
     // Compare amount with the amount of reward, that is selected.
     // If the amount of selected reward is larger than amount from session,
     // use the amount of selected reward.
     if (!empty($this->rewardId)) {
         foreach ($this->rewards as $reward) {
             if ($this->rewardId == $reward->id) {
                 if ($this->rewardAmount < $reward->amount) {
                     $this->rewardAmount = $reward->amount;
                     $paymentSession->step1 = false;
                 }
                 break;
             }
         }
     }
     // Store the new values of the payment process to the user session.
     $this->app->setUserState($this->paymentSessionContext, $paymentSession);
     if (!$this->fourSteps) {
         $this->secondStepTask = "backing.process";
     } else {
         $this->secondStepTask = "backing.step2";
     }
 }
Esempio n. 3
0
 /**
  * Upload a pitch image.
  *
  * @param  array $image
  *
  * @throws Exception
  *
  * @return array
  */
 public function uploadPitchImage($image)
 {
     $app = JFactory::getApplication();
     /** @var $app JApplicationSite */
     $uploadedFile = JArrayHelper::getValue($image, 'tmp_name');
     $uploadedName = JArrayHelper::getValue($image, 'name');
     $errorCode = JArrayHelper::getValue($image, 'error');
     // Load parameters.
     $params = JComponentHelper::getParams($this->option);
     /** @var  $params Joomla\Registry\Registry */
     $destFolder = JPath::clean(JPATH_ROOT . DIRECTORY_SEPARATOR . $params->get("images_directory", "images/crowdfunding"));
     $tmpFolder = $app->get("tmp_path");
     // Joomla! media extension parameters
     $mediaParams = JComponentHelper::getParams("com_media");
     /** @var  $mediaParams Joomla\Registry\Registry */
     jimport("itprism.file");
     jimport("itprism.file.uploader.local");
     jimport("itprism.file.validator.size");
     jimport("itprism.file.validator.image");
     jimport("itprism.file.validator.server");
     $file = new ITPrismFile();
     // Prepare size validator.
     $KB = 1024 * 1024;
     $fileSize = (int) $app->input->server->get('CONTENT_LENGTH');
     $uploadMaxSize = $mediaParams->get("upload_maxsize") * $KB;
     $sizeValidator = new ITPrismFileValidatorSize($fileSize, $uploadMaxSize);
     // Prepare server validator.
     $serverValidator = new ITPrismFileValidatorServer($errorCode, array(UPLOAD_ERR_NO_FILE));
     // Prepare image validator.
     $imageValidator = new ITPrismFileValidatorImage($uploadedFile, $uploadedName);
     // Get allowed mime types from media manager options
     $mimeTypes = explode(",", $mediaParams->get("upload_mime"));
     $imageValidator->setMimeTypes($mimeTypes);
     // Get allowed image extensions from media manager options
     $imageExtensions = explode(",", $mediaParams->get("image_extensions"));
     $imageValidator->setImageExtensions($imageExtensions);
     $file->addValidator($sizeValidator)->addValidator($imageValidator)->addValidator($serverValidator);
     // Validate the file
     if (!$file->isValid()) {
         throw new RuntimeException($file->getError());
     }
     // Generate temporary file name
     $ext = JString::strtolower(JFile::makeSafe(JFile::getExt($image['name'])));
     jimport("itprism.string");
     $generatedName = new ITPrismString();
     $generatedName->generateRandomString(32);
     $tmpDestFile = $tmpFolder . DIRECTORY_SEPARATOR . $generatedName . "." . $ext;
     // Prepare uploader object.
     $uploader = new ITPrismFileUploaderLocal($uploadedFile);
     $uploader->setDestination($tmpDestFile);
     // Upload temporary file
     $file->setUploader($uploader);
     $file->upload();
     // Get file
     $tmpDestFile = $file->getFile();
     if (!is_file($tmpDestFile)) {
         throw new Exception('COM_CROWDFUNDING_ERROR_FILE_CANT_BE_UPLOADED');
     }
     // Resize image
     $image = new JImage();
     $image->loadFile($tmpDestFile);
     if (!$image->isLoaded()) {
         throw new Exception(JText::sprintf('COM_CROWDFUNDING_ERROR_FILE_NOT_FOUND', $tmpDestFile));
     }
     $imageName = $generatedName . "_pimage.png";
     $imageFile = JPath::clean($destFolder . DIRECTORY_SEPARATOR . $imageName);
     // Create main image
     $width = $params->get("pitch_image_width", 600);
     $height = $params->get("pitch_image_height", 400);
     $image->resize($width, $height, false);
     $image->toFile($imageFile, IMAGETYPE_PNG);
     // Remove the temporary
     if (is_file($tmpDestFile)) {
         JFile::delete($tmpDestFile);
     }
     return $imageName;
 }
Esempio n. 4
0
 public function uploadExtraImages($files, $options)
 {
     $images = array();
     $destination = JArrayHelper::getValue($options, "destination", "images/crowdfunding");
     jimport("itprism.file");
     jimport("itprism.file.image");
     jimport("itprism.file.uploader.local");
     jimport("itprism.file.validator.size");
     jimport("itprism.file.validator.image");
     jimport("itprism.file.validator.server");
     jimport("itprism.string");
     // Joomla! media extension parameters
     $mediaParams = JComponentHelper::getParams("com_media");
     /** @var  $mediaParams Joomla\Registry\Registry */
     // check for error
     foreach ($files as $image) {
         // Upload image
         if (!empty($image['name'])) {
             $uploadedFile = JArrayHelper::getValue($image, 'tmp_name');
             $uploadedName = JArrayHelper::getValue($image, 'name');
             $errorCode = JArrayHelper::getValue($image, 'error');
             $file = new ITPrismFile();
             // Prepare size validator.
             $KB = 1024 * 1024;
             $fileSize = JArrayHelper::getValue($image, "size");
             $uploadMaxSize = $mediaParams->get("upload_maxsize") * $KB;
             // Prepare file size validator
             $sizeValidator = new ITPrismFileValidatorSize($fileSize, $uploadMaxSize);
             // Prepare server validator.
             $serverValidator = new ITPrismFileValidatorServer($errorCode, array(UPLOAD_ERR_NO_FILE));
             // Prepare image validator.
             $imageValidator = new ITPrismFileValidatorImage($uploadedFile, $uploadedName);
             // Get allowed mime types from media manager options
             $mimeTypes = explode(",", $mediaParams->get("upload_mime"));
             $imageValidator->setMimeTypes($mimeTypes);
             // Get allowed image extensions from media manager options
             $imageExtensions = explode(",", $mediaParams->get("image_extensions"));
             $imageValidator->setImageExtensions($imageExtensions);
             $file->addValidator($sizeValidator)->addValidator($imageValidator)->addValidator($serverValidator);
             // Validate the file
             if (!$file->isValid()) {
                 throw new RuntimeException($file->getError());
             }
             // Generate file name
             $ext = JString::strtolower(JFile::makeSafe(JFile::getExt($image['name'])));
             $generatedName = new ITPrismString();
             $generatedName->generateRandomString(6);
             $tmpDestFile = $destination . DIRECTORY_SEPARATOR . $generatedName . "_extra." . $ext;
             // Prepare uploader object.
             $uploader = new ITPrismFileUploaderLocal($uploadedFile);
             $uploader->setDestination($tmpDestFile);
             // Upload temporary file
             $file->setUploader($uploader);
             $file->upload();
             // Get file
             $imageSource = $file->getFile();
             if (!JFile::exists($imageSource)) {
                 throw new RuntimeException(JText::_("COM_CROWDFUNDING_ERROR_FILE_CANT_BE_UPLOADED"));
             }
             // Create thumbnail
             $fileImage = new ITPrismFileImage($imageSource);
             $options["destination"] = $destination . DIRECTORY_SEPARATOR . $generatedName . "_extra_thumb." . $ext;
             $thumbSource = $fileImage->createThumbnail($options);
             $names = array("image" => "", "thumb" => "");
             $names['image'] = basename($imageSource);
             $names["thumb"] = basename($thumbSource);
             $images[] = $names;
         }
     }
     return $images;
 }
Esempio n. 5
0
 /**
  * Upload an image.
  *
  * @param  array $image
  * @param  string $destFolder
  *
  * @throws RuntimeException
  *
  * @return array
  */
 public function uploadImage($image, $destFolder)
 {
     // Load parameters.
     $params = JComponentHelper::getParams($this->option);
     /** @var  $params Joomla\Registry\Registry */
     // Joomla! media extension parameters
     $mediaParams = JComponentHelper::getParams("com_media");
     /** @var  $mediaParams Joomla\Registry\Registry */
     jimport("itprism.file");
     jimport("itprism.file.image");
     jimport("itprism.file.uploader.local");
     jimport("itprism.file.validator.size");
     jimport("itprism.file.validator.image");
     jimport("itprism.file.validator.server");
     $names = array("image" => "", "thumb" => "", "square" => "");
     $KB = 1024 * 1024;
     $uploadMaxSize = $mediaParams->get("upload_maxsize") * $KB;
     $mimeTypes = explode(",", $mediaParams->get("upload_mime"));
     $imageExtensions = explode(",", $mediaParams->get("image_extensions"));
     $uploadedFile = JArrayHelper::getValue($image, 'tmp_name');
     $uploadedName = JString::trim(JArrayHelper::getValue($image, 'name'));
     $errorCode = JArrayHelper::getValue($image, 'error');
     $file = new ITPrismFileImage();
     if (!empty($uploadedName)) {
         // Prepare size validator.
         $fileSize = (int) JArrayHelper::getValue($image, 'size');
         // Prepare file size validator.
         $sizeValidator = new ITPrismFileValidatorSize($fileSize, $uploadMaxSize);
         // Prepare server validator.
         $serverValidator = new ITPrismFileValidatorServer($errorCode, array(UPLOAD_ERR_NO_FILE));
         // Prepare image validator.
         $imageValidator = new ITPrismFileValidatorImage($uploadedFile, $uploadedName);
         // Get allowed mime types from media manager options
         $imageValidator->setMimeTypes($mimeTypes);
         // Get allowed image extensions from media manager options
         $imageValidator->setImageExtensions($imageExtensions);
         $file->addValidator($sizeValidator)->addValidator($imageValidator)->addValidator($serverValidator);
         // Validate the file
         if (!$file->isValid()) {
             throw new RuntimeException($file->getError());
         }
         // Generate temporary file name
         $ext = JString::strtolower(JFile::makeSafe(JFile::getExt($image['name'])));
         jimport("itprism.string");
         $generatedName = new ITPrismString();
         $generatedName->generateRandomString(12, "reward_");
         $destFile = JPath::clean($destFolder . DIRECTORY_SEPARATOR . $generatedName . "." . $ext);
         // Prepare uploader object.
         $uploader = new ITPrismFileUploaderLocal($uploadedFile);
         $uploader->setDestination($destFile);
         // Upload temporary file
         $file->setUploader($uploader);
         $file->upload();
         // Get file
         $imageSource = $file->getFile();
         if (!is_file($imageSource)) {
             throw new RuntimeException(JText::_("COM_CROWDFUNDING_ERROR_FILE_CANT_BE_UPLOADED"));
         }
         // Generate thumbnails.
         // Create thumbnail.
         $generatedName->generateRandomString(12, "reward_thumb_");
         $options = array("width" => $params->get("rewards_image_thumb_width", 200), "height" => $params->get("rewards_image_thumb_height", 200), "destination" => JPath::clean($destFolder . DIRECTORY_SEPARATOR . $generatedName . "." . $ext));
         $thumbSource = $file->createThumbnail($options);
         // Create square image.
         $generatedName->generateRandomString(12, "reward_square_");
         $options = array("width" => $params->get("rewards_image_square_width", 50), "height" => $params->get("rewards_image_square_height", 50), "destination" => JPath::clean($destFolder . DIRECTORY_SEPARATOR . $generatedName . "." . $ext));
         $squareSource = $file->createThumbnail($options);
         $names['image'] = basename($imageSource);
         $names["thumb"] = basename($thumbSource);
         $names["square"] = basename($squareSource);
     }
     return $names;
 }
Esempio n. 6
0
 protected function generateKeys()
 {
     // Generate a password that will be used to encrypt the file.
     jimport("itprism.string");
     $length = rand(16, 32);
     $password = new ITPrismString();
     $password->generateRandomString($length);
     // Generate a salt.
     $length = rand(16, 32);
     $salt = new ITPrismString();
     $salt->generateRandomString($length);
     $options = array("salt" => (string) $salt, "password" => (string) $password);
     $chiper = new JCryptCipherRijndael256();
     $key = $chiper->generateKey($options);
     return array("private" => $key->private, "public" => $key->public);
 }