/** * Method to get the data that should be injected in the form. * * @throws \RuntimeException * @throws \UnexpectedValueException * @throws \InvalidArgumentException * @throws \OutOfBoundsException * * @return mixed The data for the form. * @since 1.6 */ protected function loadFormData() { $app = JFactory::getApplication(); // Check the session for previously entered form data. $data = $app->getUserState($this->option . '.edit.transaction.data', array()); if (count($data) === 0) { $data = $this->getItem(); $params = JComponentHelper::getParams('com_crowdfunding'); /** @var $params Joomla\Registry\Registry */ $moneyFormatter = $this->getMoneyFormatter($params); // If it is new record, set default values. if (!$data->id) { $currency = $moneyFormatter->getCurrency(); $data->txn_currency = $currency->getCode(); $data->txn_id = strtoupper(Prism\Utilities\StringHelper::generateRandomString(13, 'TXN')); $data->service_provider = 'Cash'; $data->service_alias = 'cash'; $data->txn_status = 'completed'; $timezone = $app->get('offset'); $currentDate = new JDate('now', $timezone); $data->txn_date = $currentDate->toSql(); $data->update_project = 1; } $data->txn_amount = $moneyFormatter->setAmount($data->txn_amount)->format(); } return $data; }
protected function hideModule($moduleName) { $module = JModuleHelper::getModule($moduleName); if (is_object($module) and $module->id > 0) { $seed = Prism\Utilities\StringHelper::generateRandomString(16); $module->position = 'fp' . JApplicationHelper::getHash($seed); } }
protected function getInput() { // Initialize variables. $html = array(); // Get the field options. $options = (array) $this->getOptions(); $pointsTypes = array(); if (is_string($this->value) and $this->value !== '') { $pointsTypes_ = (array) json_decode($this->value); if (count($pointsTypes_) > 0) { foreach ($pointsTypes_ as $type) { $pointsTypes[$type->id] = $type->value; } } } if (count($options) > 0) { $html[] = '<div id="points-elements">'; foreach ($options as $option) { $attr = ' class="points-type'; // Initialize some field attributes. $attr .= $this->element['class'] ? ' ' . (string) $this->element['class'] . '"' : '"'; $attr .= $this->element['size'] ? ' size="' . (int) $this->element['size'] . '"' : ''; // Initialize JavaScript field attributes. $attr .= $this->element['onchange'] ? ' onchange="' . (string) $this->element['onchange'] . '"' : ''; $elementId = Prism\Utilities\StringHelper::generateRandomString(10); $value = Joomla\Utilities\ArrayHelper::getValue($pointsTypes, $option->value); $html[] = '<label for="' . $elementId . '">' . $option->text . '</label>'; $html[] = '<input type="text" value="' . $value . '" id="' . $elementId . '" data-id="' . $option->value . '" ' . $attr . ' style="margin-bottom: 15px;"/>'; } $html[] = '</div>'; } $html[] = '<input type="hidden" name="' . $this->name . '" value=\'' . $this->value . '\' id="' . $this->id . '" />'; // Scripts JHtml::_('behavior.framework'); $doc = JFactory::getDocument(); $doc->addScript(JUri::root() . 'media/com_gamification/js/admin/fields/pointstypes.js'); return implode($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 stdClass $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 (!isset($item->user_id) or !$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) and !$this->params->get('display_stripe', 0)) { return ''; } $activeTab = ''; if ($this->params->get('display_paypal', 0)) { $activeTab = 'paypal'; } elseif ($this->params->get('display_banktransfer', 0)) { $activeTab = 'banktransfer'; } elseif ($this->params->get('display_stripe', 0)) { $activeTab = 'stripe'; } $payout = new Crowdfundingfinance\Payout(JFactory::getDbo()); $payout->setSecretKey($this->app->get('secret')); $payout->load(array('project_id' => $item->id)); // Create payout record, if it does not exists. if (!$payout->getId()) { $payout->setProjectId($item->id); $payout->store(); } // Check if Stripe connected. if ($this->params->get('display_stripe', 0)) { $stripeWarning = null; $stripeButton = array(); $cfFinanceParams = JComponentHelper::getParams('com_crowdfundingfinance'); // Get keys. $apiKeys = Crowdfundingfinance\Stripe\Helper::getKeys($cfFinanceParams); if (!$apiKeys['client_id']) { $stripeWarning = JText::_('PLG_CROWDFUNDING_PAYOUTOPTIONS_ERROR_STRIPE_NOT_CONFIGURED'); } $token = Crowdfundingfinance\Stripe\Helper::getPayoutAccessToken($apiKeys, $payout, $cfFinanceParams->get('stripe_expiration_period', 7)); // Generate state HASH and use it as a session key that contains redirect URL. $state = Prism\Utilities\StringHelper::generateRandomString(32); $stateData = array('redirect_url' => base64_encode(JRoute::_(CrowdfundingHelperRoute::getFormRoute($item->id, 'extras'), false)), 'project_id' => $item->id); $this->app->setUserState($state, $stateData); if (!$token) { $stripeButton[] = '<div class="mt-20">'; $stripeButton[] = '<a href="https://connect.stripe.com/oauth/authorize?response_type=code&client_id=' . $apiKeys['client_id'] . '&scope=read_write&state=' . $state . '&redirect_uri=' . rawurlencode($this->params->get('stripe_redirect_uri')) . '">'; $stripeButton[] = '<img src="media/com_crowdfundingfinance/images/stripe/' . $cfFinanceParams->get('button', 'blue-on-dark') . '.png" width="190" height="33" />'; $stripeButton[] = '</a>'; $stripeButton[] = '</div>'; } else { $url = JRoute::_('index.php?option=com_crowdfundingfinance&task=payouts.deauthorize&payment_service=stripeconnect&pid=' . (int) $item->id . '&state=' . $state . '&' . JSession::getFormToken() . '=1'); $stripeButton[] = '<div class="mt-20">'; $stripeButton[] = '<p class="alert alert-info"><span class="fa fa-info-circle"></span> ' . JText::_('PLG_CROWDFUNDING_PAYOUTOPTIONS_STRIPE_CONNECTED') . '</p>'; $stripeButton[] = '<a href="' . $url . '" class="btn btn-danger" id="js-cff-btn-stripe-disconnect">'; $stripeButton[] = '<span class="fa fa-chain-broken"></span> ' . JText::_('PLG_CROWDFUNDING_PAYOUTOPTIONS_DISCONNECT_STRIPE'); $stripeButton[] = '</a>'; $stripeButton[] = '</div>'; } } // 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; }
echo $class; ?> "> <button class="btn btn-default" id="<?php echo $buttonId; ?> " type="button"> <i class="icon icon-plus"></i> <?php echo JText::_('COM_GAMIFICATION_ADD_DATA'); ?> </button> <?php foreach ($customData as $customDataKey => $customDataValue) { $customDataIndex = Prism\Utilities\StringHelper::generateRandomString(5); ?> <div id="<?php echo $customDataIndex; ?> "><input type="text" name="jform[custom_data][<?php echo $customDataIndex; ?> ][key]" placeholder="<?php echo strtolower(JText::_('COM_GAMIFICATION_KEY')); ?> " value="<?php echo $customDataKey; ?> " /><input type="text" name="jform[custom_data][<?php echo $customDataIndex;
/** * Crop the image and generates smaller ones. * * @param string $file * @param array $options * * @throws Exception * * @return array */ public function cropImage($file, $options) { // Resize image $image = new JImage(); $image->loadFile($file); if (!$image->isLoaded()) { throw new Exception(JText::sprintf('COM_CROWDFUNDING_ERROR_FILE_NOT_FOUND', $file)); } $destinationFolder = Joomla\Utilities\ArrayHelper::getValue($options, 'destination'); // Generate temporary file name $generatedName = Prism\Utilities\StringHelper::generateRandomString(32); $imageName = $generatedName . '_image.png'; $smallName = $generatedName . '_small.png'; $squareName = $generatedName . '_square.png'; $imageFile = JPath::clean($destinationFolder . DIRECTORY_SEPARATOR . $imageName); $smallFile = JPath::clean($destinationFolder . DIRECTORY_SEPARATOR . $smallName); $squareFile = JPath::clean($destinationFolder . DIRECTORY_SEPARATOR . $squareName); // Create main image $width = Joomla\Utilities\ArrayHelper::getValue($options, 'width', 200); $width = $width < 25 ? 50 : $width; $height = Joomla\Utilities\ArrayHelper::getValue($options, 'height', 200); $height = $height < 25 ? 50 : $height; $left = Joomla\Utilities\ArrayHelper::getValue($options, 'x', 0); $top = Joomla\Utilities\ArrayHelper::getValue($options, 'y', 0); $image->crop($width, $height, $left, $top, false); // Resize to general size. $width = Joomla\Utilities\ArrayHelper::getValue($options, 'resize_width', 200); $width = $width < 25 ? 50 : $width; $height = Joomla\Utilities\ArrayHelper::getValue($options, 'resize_height', 200); $height = $height < 25 ? 50 : $height; $image->resize($width, $height, false); // Store to file. $image->toFile($imageFile, IMAGETYPE_PNG); // Load parameters. $params = JComponentHelper::getParams($this->option); /** @var $params Joomla\Registry\Registry */ // Create small image $width = $params->get('image_small_width', 100); $height = $params->get('image_small_height', 100); $image->resize($width, $height, false); $image->toFile($smallFile, IMAGETYPE_PNG); // Create square image $width = $params->get('image_square_width', 50); $height = $params->get('image_square_height', 50); $image->resize($width, $height, false); $image->toFile($squareFile, IMAGETYPE_PNG); $names = array('image' => $imageName, 'image_small' => $smallName, 'image_square' => $squareName); // Remove the temporary file. if (is_file($file)) { JFile::delete($file); } return $names; }
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 = CrowdfundingHelper::parseAmount($this->input->getString('amount')); // 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 (is_object($item) and (int) $item->id === 0) { $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 = Crowdfunding\Constants::PAYMENT_SESSION_CONTEXT . $item->id; $paymentSessionLocal = $app->getUserState($paymentSessionContext); $paymentSessionLocal->step1 = true; $paymentSessionLocal->amount = $amount; $paymentSessionLocal->rewardId = $rewardId; $app->setUserState($paymentSessionContext, $paymentSessionLocal); // Generate hash user ID used for anonymous payment. if (!$userId) { $aUserId = $app->getUserState('auser_id'); if (!$aUserId) { // Generate a hash ID for anonymous user. $anonymousUserId = Prism\Utilities\StringHelper::generateRandomString(32); $aUserId = (string) $anonymousUserId; $app->setUserState('auser_id', $aUserId); } } $date = new JDate(); // Create an intention record. $intentionId = 0; if ($userId > 0) { $intentionKeys = array('user_id' => $userId, 'project_id' => $item->id); $intention = new Crowdfunding\Intention(JFactory::getDbo()); $intention->load($intentionKeys); $intentionData = array('user_id' => $userId, 'project_id' => $item->id, 'reward_id' => $rewardId, 'record_date' => $date->toSql()); $intention->bind($intentionData); $intention->store(); $intentionId = $intention->getId(); } // Create a payment session. $paymentSessionDatabase = new Crowdfunding\Payment\Session(JFactory::getDbo()); $paymentSessionData = array('user_id' => $userId, 'auser_id' => $aUserId, 'project_id' => $item->id, 'reward_id' => $rewardId, 'record_date' => $date->toSql(), 'session_id' => $paymentSessionLocal->session_id, 'intention_id' => $intentionId); $paymentSessionDatabase->bind($paymentSessionData); $paymentSessionDatabase->store(); // Redirect to next page $link = CrowdfundingHelperRoute::getBackingRoute($item->slug, $item->catslug, 'payment'); $this->setRedirect(JRoute::_($link, false)); }
/** * Upload a pitch image. * * @param array $image * * @throws Exception * * @return array */ public function uploadPitchImage($image) { $app = JFactory::getApplication(); /** @var $app JApplicationSite */ $uploadedFile = Joomla\Utilities\ArrayHelper::getValue($image, 'tmp_name'); $uploadedName = Joomla\Utilities\ArrayHelper::getValue($image, 'name'); $errorCode = Joomla\Utilities\ArrayHelper::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 */ $file = new Prism\File\File(); // Prepare size validator. $KB = 1024 * 1024; $fileSize = (int) $app->input->server->get('CONTENT_LENGTH'); $uploadMaxSize = $mediaParams->get("upload_maxsize") * $KB; $sizeValidator = new Prism\File\Validator\Size($fileSize, $uploadMaxSize); // Prepare server validator. $serverValidator = new Prism\File\Validator\Server($errorCode, array(UPLOAD_ERR_NO_FILE)); // Prepare image validator. $imageValidator = new Prism\File\Validator\Image($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']))); $generatedName = Prism\Utilities\StringHelper::generateRandomString(32); $tmpDestFile = JPath::clean($tmpFolder . DIRECTORY_SEPARATOR . $generatedName . "." . $ext); // Prepare uploader object. $uploader = new Prism\File\Uploader\Local($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; }
/** * Store the file in a folder of the extension. * * @param array $image * @param bool $resizeImage * * @throws \RuntimeException * @throws \Exception * @throws \InvalidArgumentException * * @return array */ public function uploadImage($image, $resizeImage = false) { $app = JFactory::getApplication(); /** @var $app JApplicationSite */ $uploadedFile = ArrayHelper::getValue($image, 'tmp_name'); $uploadedName = ArrayHelper::getValue($image, 'name'); $errorCode = ArrayHelper::getValue($image, 'error'); $params = JComponentHelper::getParams($this->option); /** @var $params Joomla\Registry\Registry */ $filesystemHelper = new Prism\Filesystem\Helper($params); $mediaFolder = $filesystemHelper->getMediaFolder(); $destinationFolder = JPath::clean(JPATH_ROOT . DIRECTORY_SEPARATOR . $mediaFolder); $temporaryFolder = $app->get('tmp_path'); // Joomla! media extension parameters $mediaParams = JComponentHelper::getParams('com_media'); /** @var $mediaParams Joomla\Registry\Registry */ $file = new Prism\File\File(); // Prepare size validator. $KB = 1024 * 1024; $fileSize = (int) $app->input->server->get('CONTENT_LENGTH'); $uploadMaxSize = $mediaParams->get('upload_maxsize') * $KB; // Prepare file validators. $sizeValidator = new Prism\File\Validator\Size($fileSize, $uploadMaxSize); $serverValidator = new Prism\File\Validator\Server($errorCode, array(UPLOAD_ERR_NO_FILE)); $imageValidator = new Prism\File\Validator\Image($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($serverValidator)->addValidator($imageValidator); // Validate the file if (!$file->isValid()) { throw new RuntimeException($file->getError()); } // Generate temporary file name $ext = strtolower(JFile::makeSafe(JFile::getExt($image['name']))); $generatedName = Prism\Utilities\StringHelper::generateRandomString(); $temporaryFile = $generatedName . '_reward.' . $ext; $temporaryDestination = JPath::clean($temporaryFolder . DIRECTORY_SEPARATOR . $temporaryFile); // Prepare uploader object. $uploader = new Prism\File\Uploader\Local($uploadedFile); $uploader->setDestination($temporaryDestination); // Upload temporary file $file->setUploader($uploader); $file->upload(); $temporaryFile = $file->getFile(); if (!is_file($temporaryFile)) { throw new Exception('COM_GAMIFICATION_ERROR_FILE_CANT_BE_UPLOADED'); } // Resize image $image = new JImage(); $image->loadFile($temporaryFile); if (!$image->isLoaded()) { throw new Exception(JText::sprintf('COM_GAMIFICATION_ERROR_FILE_NOT_FOUND', $temporaryDestination)); } $imageName = $generatedName . '_image.png'; $smallName = $generatedName . '_small.png'; $squareName = $generatedName . '_square.png'; $imageFile = $destinationFolder . DIRECTORY_SEPARATOR . $imageName; $smallFile = $destinationFolder . DIRECTORY_SEPARATOR . $smallName; $squareFile = $destinationFolder . DIRECTORY_SEPARATOR . $squareName; $scaleOption = $params->get('image_resizing_scale', JImage::SCALE_INSIDE); // Create main image if (!$resizeImage) { $image->toFile($imageFile, IMAGETYPE_PNG); } else { $width = $params->get('image_width', 200); $height = $params->get('image_height', 200); $image->resize($width, $height, false, $scaleOption); $image->toFile($imageFile, IMAGETYPE_PNG); } // Create small image $width = $params->get('image_small_width', 100); $height = $params->get('image_small_height', 100); $image->resize($width, $height, false, $scaleOption); $image->toFile($smallFile, IMAGETYPE_PNG); // Create square image $width = $params->get('image_square_width', 50); $height = $params->get('image_square_height', 50); $image->resize($width, $height, false, $scaleOption); $image->toFile($squareFile, IMAGETYPE_PNG); $names = array('image' => $imageName, 'image_small' => $smallName, 'image_square' => $squareName); // Remove the temporary file. if (JFile::exists($temporaryFile)) { JFile::delete($temporaryFile); } return $names; }
/** * Store the file in a folder of the extension. * * @param array $image * * @throws \InvalidArgumentException * @throws \Exception * @throws \UnexpectedValueException * @throws \RuntimeException * * @return string */ public function uploadImage($image) { $app = JFactory::getApplication(); /** @var $app JApplicationSite */ $uploadedFile = ArrayHelper::getValue($image, 'tmp_name'); $uploadedName = ArrayHelper::getValue($image, 'name'); $errorCode = ArrayHelper::getValue($image, 'error'); $params = JComponentHelper::getParams($this->option); /** @var $params Joomla\Registry\Registry */ $filesystemHelper = new Prism\Filesystem\Helper($params); $mediaFolder = $filesystemHelper->getMediaFolder(); $destinationFolder = JPath::clean(JPATH_ROOT . DIRECTORY_SEPARATOR . $mediaFolder); // Joomla! media extension parameters $mediaParams = JComponentHelper::getParams('com_media'); /** @var $mediaParams Joomla\Registry\Registry */ $file = new Prism\File\File(); // Prepare size validator. $KB = 1024 * 1024; $fileSize = (int) $app->input->server->get('CONTENT_LENGTH'); $uploadMaxSize = $mediaParams->get('upload_maxsize') * $KB; // Prepare file validators. $sizeValidator = new Prism\File\Validator\Size($fileSize, $uploadMaxSize); $serverValidator = new Prism\File\Validator\Server($errorCode, array(UPLOAD_ERR_NO_FILE)); $imageValidator = new Prism\File\Validator\Image($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($serverValidator)->addValidator($imageValidator); // Validate the file if (!$file->isValid()) { throw new RuntimeException($file->getError()); } // Generate temporary file name $ext = strtolower(JFile::makeSafe(JFile::getExt($image['name']))); $generatedName = Prism\Utilities\StringHelper::generateRandomString(16); $imageName = $generatedName . '_badge.' . $ext; $destination = JPath::clean($destinationFolder . DIRECTORY_SEPARATOR . $imageName); // Prepare uploader object. $uploader = new Prism\File\Uploader\Local($uploadedFile); $uploader->setDestination($destination); // Upload temporary file $file->setUploader($uploader); $file->upload(); $source = $file->getFile(); return basename($source); }
/** * Crop the image and generates smaller ones. * * @param string $file * @param array $options * @param Joomla\Registry\Registry $params * * @throws Exception * * @return array */ public function cropImage($file, $options, $params) { // Resize image $image = new JImage(); $image->loadFile($file); if (!$image->isLoaded()) { throw new Exception(JText::sprintf('COM_SOCIALCOMMUNITY_ERROR_FILE_NOT_FOUND', $file)); } $destinationFolder = Joomla\Utilities\ArrayHelper::getValue($options, 'destination'); // Generate temporary file name $generatedName = Prism\Utilities\StringHelper::generateRandomString(24); $profileName = $generatedName . '_profile.png'; $smallName = $generatedName . '_small.png'; $squareName = $generatedName . '_square.png'; $iconName = $generatedName . '_icon.png'; $imageFile = JPath::clean($destinationFolder . DIRECTORY_SEPARATOR . $profileName); $smallFile = JPath::clean($destinationFolder . DIRECTORY_SEPARATOR . $smallName); $squareFile = JPath::clean($destinationFolder . DIRECTORY_SEPARATOR . $squareName); $iconFile = JPath::clean($destinationFolder . DIRECTORY_SEPARATOR . $iconName); // Create profile image. $width = Joomla\Utilities\ArrayHelper::getValue($options, 'width', 200); $width = $width < 25 ? 50 : $width; $height = Joomla\Utilities\ArrayHelper::getValue($options, 'height', 200); $height = $height < 25 ? 50 : $height; $left = Joomla\Utilities\ArrayHelper::getValue($options, 'x', 0); $top = Joomla\Utilities\ArrayHelper::getValue($options, 'y', 0); $image->crop($width, $height, $left, $top, false); // Resize to general size. $width = $params->get('image_width', 200); $width = $width < 25 ? 50 : $width; $height = $params->get('image_height', 200); $height = $height < 25 ? 50 : $height; $image->resize($width, $height, false); // Store to file. $image->toFile($imageFile, IMAGETYPE_PNG); // Create small image. $width = $params->get('image_small_width', 100); $height = $params->get('image_small_height', 100); $image->resize($width, $height, false); $image->toFile($smallFile, IMAGETYPE_PNG); // Create square image. $width = $params->get('image_square_width', 50); $height = $params->get('image_square_height', 50); $image->resize($width, $height, false); $image->toFile($squareFile, IMAGETYPE_PNG); // Create icon image. $width = $params->get('image_icon_width', 25); $height = $params->get('image_icon_height', 25); $image->resize($width, $height, false); $image->toFile($iconFile, IMAGETYPE_PNG); $names = array('image_profile' => $profileName, 'image_small' => $smallName, 'image_square' => $squareName, 'image_icon' => $iconName); // Remove the temporary file. if (JFile::exists($file)) { JFile::delete($file); } return $names; }
/** * 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 */ $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 Prism\File\Image(); if (!empty($uploadedName)) { // Prepare size validator. $fileSize = (int) JArrayHelper::getValue($image, 'size'); // Prepare file size validator. $sizeValidator = new Prism\File\Validator\Size($fileSize, $uploadMaxSize); // Prepare server validator. $serverValidator = new Prism\File\Validator\Server($errorCode, array(UPLOAD_ERR_NO_FILE)); // Prepare image validator. $imageValidator = new Prism\File\Validator\Image($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']))); $generatedName = Prism\Utilities\StringHelper::generateRandomString(12, "reward_"); $destFile = JPath::clean($destFolder . DIRECTORY_SEPARATOR . $generatedName . "." . $ext); // Prepare uploader object. $uploader = new Prism\File\Uploader\Local($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 = Prism\Utilities\StringHelper::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 = Prism\Utilities\StringHelper::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; }
/** * This method prepare and return address to Blockchain, * where the user have to go to make a donation. * * @param string $context * @param stdClass $item * * @return null|string */ public function onProjectPayment($context, &$item) { if (strcmp('com_crowdfunding.payment', $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; } // This is a URI path to the plugin folder $pluginURI = 'plugins/crowdfundingpayment/blockchain'; $html = array(); $html[] = '<div class="well">'; // Open "well". $html[] = '<h4><img src="' . $pluginURI . '/images/blockchain_icon.png" width="38" height="32" /> ' . JText::_($this->textPrefix . '_TITLE') . '</h4>'; // Check for valid data. $receivingAddress = JString::trim($this->params->get('receiving_address')); $callbackUrl = $this->getCallbackUrl(); if (!$receivingAddress or !$callbackUrl) { $html[] = '<div class="bg-warning mtb-10"><span class="glyphicon glyphicon-warning-sign"></span> ' . JText::_($this->textPrefix . '_ERROR_PLUGIN_NOT_CONFIGURED') . '</div>'; $html[] = '</div>'; // Close "well". return implode("\n", $html); } // Get payment session $paymentSessionContext = Crowdfunding\Constants::PAYMENT_SESSION_CONTEXT . $item->id; $paymentSessionLocal = $this->app->getUserState($paymentSessionContext); $paymentSession = $this->getPaymentSession(array('session_id' => $paymentSessionLocal->session_id)); // Prepare transaction ID. $txnId = Prism\Utilities\StringHelper::generateRandomString(); $txnId = JString::strtoupper($txnId); // Store the unique key. $paymentSession->setUniqueKey($txnId); $paymentSession->storeUniqueKey(); // Prepare callback URL data. $callbackUrl .= '&payment_session_id=' . (int) $paymentSession->getId() . '&txn_id=' . $txnId; // DEBUG DATA JDEBUG ? $this->log->add(JText::_($this->textPrefix . '_DEBUG_CALLBACK_URL'), $this->debugType, $callbackUrl) : null; // Send request for button jimport('Prism.libs.Blockchain.Blockchain'); $blockchain = new Blockchain(); $response = $blockchain->Receive->generate($receivingAddress, $callbackUrl); // DEBUG DATA $responseResult = @var_export($response, true); JDEBUG ? $this->log->add(JText::_($this->textPrefix . '_DEBUG_RECEIVE_GENERATE_RESPONSE'), $this->debugType, $responseResult) : null; // Check for test mode. if ($this->params->get('test_mode', 1)) { $html[] = '<div class="bg-info p-10-5"><span class="glyphicon glyphicon-info-sign"></span> ' . JText::_($this->textPrefix . '_ERROR_TEST_MODE') . '</div>'; $html[] = '<label for="blockchain_callback_url">' . JText::_($this->textPrefix . '_CALLBACK_URL') . '</label>'; $html[] = '<textarea name="callback_url" id="blockchain_callback_url" class="form-control">' . $callbackUrl . '</textarea>'; } else { $html[] = '<div class="form-group">'; $html[] = '<label for="blockchain_receiving_address">' . JText::_($this->textPrefix . "_RECEIVING_ADDRESS") . '</label>'; $html[] = '<input class="form-control input-lg" type="text" value="' . $response->address . '" id="blockchain_receiving_address"/>'; $html[] = '</div>'; $html[] = '<p class="bg-info p-10-5 mt-10"><span class="glyphicon glyphicon-info-sign"></span> ' . JText::sprintf($this->textPrefix . '_SEND_COINS_TO_ADDRESS', $item->amountFormated) . '</p>'; $html[] = '<a class="btn btn-primary" href="' . JRoute::_(CrowdfundingHelperRoute::getBackingRoute($item->slug, $item->catslug, 'share')) . '"><span class="glyphicon glyphicon-chevron-right"></span> ' . JText::_($this->textPrefix . '_CONTINUE_NEXT_STEP') . '</a>'; } $html[] = '</div>'; // Close "well". return implode("\n", $html); }
protected function prepareRewards($paymentSession) { // Create payment session ID. $paymentSession->session_id = (string) Prism\Utilities\StringHelper::generateRandomString(32); // Get selected reward ID $this->rewardId = (int) $this->state->get('reward_id'); // If it has been selected another reward, set the old one to 0. if ($this->rewardId !== (int) $paymentSession->rewardId) { $paymentSession->rewardId = 0; $paymentSession->step1 = false; } // Get amount from session $this->rewardAmount = !$paymentSession->amount ? 0.0 : $paymentSession->amount; // Get rewards $this->rewards = new Crowdfunding\Rewards(JFactory::getDbo()); $this->rewards->load(array('project_id' => $this->item->id, 'state' => Prism\Constants::PUBLISHED)); // 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 ($this->rewardId > 0) { $reward = $this->rewards->getReward((int) $this->rewardId); if ($reward !== null and $this->rewardAmount < $reward->getAmount()) { $this->rewardAmount = $reward->getAmount(); $paymentSession->step1 = false; } } // Set the next task. $this->secondStepTask = 'backing.process'; if ($this->fourSteps) { $this->secondStepTask = 'backing.step2'; } return $paymentSession; }
protected function prepareRewards(&$paymentSession) { // Create payment session ID. $sessionId = Prism\Utilities\StringHelper::generateRandomString(32); $paymentSession->session_id = (string) $sessionId; // Get selected reward ID $this->rewardId = (int) $this->state->get('reward_id'); // If it has been selected another reward, set the old one to 0. if ($this->rewardId !== (int) $paymentSession->rewardId) { $paymentSession->rewardId = 0; $paymentSession->step1 = false; } // Get amount from session $this->rewardAmount = !$paymentSession->amount ? 0 : $paymentSession->amount; // Get rewards $this->rewards = new Crowdfunding\Rewards(JFactory::getDbo()); $this->rewards->load(array('project_id' => $this->item->id, '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 ($this->rewardId > 0) { foreach ($this->rewards as $reward) { if ($this->rewardId === (int) $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'; } }
/** * Upload an image * * @param array $image Array with information about uploaded file. * * @throws RuntimeException * @return array */ public function uploadImage($image) { $app = JFactory::getApplication(); /** @var $app JApplicationAdministrator */ $uploadedFile = Joomla\Utilities\ArrayHelper::getValue($image, 'tmp_name'); $uploadedName = Joomla\Utilities\ArrayHelper::getValue($image, 'name'); $errorCode = Joomla\Utilities\ArrayHelper::getValue($image, 'error'); $params = JComponentHelper::getParams($this->option); /** @var $params Joomla\Registry\Registry */ $temporaryFolder = JPath::clean($app->get('tmp_path')); // Joomla! media extension parameters /** @var $mediaParams Joomla\Registry\Registry */ $mediaParams = JComponentHelper::getParams('com_media'); $file = new Prism\File\File(); // Prepare size validator. $KB = 1024 * 1024; $fileSize = (int) $app->input->server->get('CONTENT_LENGTH'); $uploadMaxSize = $mediaParams->get('upload_maxsize') * $KB; // Prepare file size validator $sizeValidator = new Prism\File\Validator\Size($fileSize, $uploadMaxSize); // Prepare server validator. $serverValidator = new Prism\File\Validator\Server($errorCode); // Prepare image validator. $imageValidator = new Prism\File\Validator\Image($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 = JFile::makeSafe(JFile::getExt($image['name'])); $generatedName = Prism\Utilities\StringHelper::generateRandomString(16); $originalFile = JPath::clean($temporaryFolder . DIRECTORY_SEPARATOR . $generatedName . '.' . $ext); if (!JFile::upload($uploadedFile, $originalFile)) { throw new \RuntimeException(\JText::_('COM_SOCIALCOMMUNITY_ERROR_FILE_CANT_BE_UPLOADED')); } // Generate file names for the image files. $generatedName = Prism\Utilities\StringHelper::generateRandomString(16); $imageName = $generatedName . '_image.png'; $smallName = $generatedName . '_small.png'; $squareName = $generatedName . '_square.png'; $iconName = $generatedName . '_icon.png'; // Resize image $image = new JImage(); $image->loadFile($originalFile); if (!$image->isLoaded()) { throw new RuntimeException(JText::sprintf('COM_SOCIALCOMMUNITY_ERROR_FILE_NOT_FOUND', $originalFile)); } $imageFile = JPath::clean($temporaryFolder . DIRECTORY_SEPARATOR . $imageName); $smallFile = JPath::clean($temporaryFolder . DIRECTORY_SEPARATOR . $smallName); $squareFile = JPath::clean($temporaryFolder . DIRECTORY_SEPARATOR . $squareName); $iconFile = JPath::clean($temporaryFolder . DIRECTORY_SEPARATOR . $iconName); // Create profile picture $width = $params->get('image_width', 200); $height = $params->get('image_height', 200); $image->resize($width, $height, false); $image->toFile($imageFile, IMAGETYPE_PNG); // Create small profile picture $width = $params->get('small_width', 100); $height = $params->get('small_height', 100); $image->resize($width, $height, false); $image->toFile($smallFile, IMAGETYPE_PNG); // Create square picture $width = $params->get('square_width', 50); $height = $params->get('square_height', 50); $image->resize($width, $height, false); $image->toFile($squareFile, IMAGETYPE_PNG); // Create icon picture $width = $params->get('icon_width', 24); $height = $params->get('icon_height', 24); $image->resize($width, $height, false); $image->toFile($iconFile, IMAGETYPE_PNG); // Remove the temporary file if (JFile::exists($originalFile)) { JFile::delete($originalFile); } return $names = array('image' => $imageName, 'image_small' => $smallName, 'image_icon' => $iconName, 'image_square' => $squareName); }