コード例 #1
0
 public function __construct($config = array())
 {
     parent::__construct($config);
     $this->app = JFactory::getApplication();
     // Get project ID.
     $this->projectId = $this->input->getUint('pid');
     // Prepare log object.
     $this->log = new Prism\Log\Log();
     // Set database log adapter if Joomla! debug is enabled.
     if ($this->logTable !== null and $this->logTable !== '' and JDEBUG) {
         $this->log->addAdapter(new Prism\Log\Adapter\Database(\JFactory::getDbo(), $this->logTable));
     }
     // Set file log adapter.
     if ($this->logFile !== null and $this->logFile !== '') {
         $file = \JPath::clean($this->app->get('log_path') . DIRECTORY_SEPARATOR . basename($this->logFile));
         $this->log->addAdapter(new Prism\Log\Adapter\File($file));
     }
     // Prepare context
     $filter = new JFilterInput();
     $paymentService = $filter->clean(trim(strtolower($this->input->getCmd('payment_service'))), 'ALNUM');
     $this->context = Joomla\String\StringHelper::strlen($paymentService) > 0 ? 'com_crowdfunding.notify.' . $paymentService : 'com_crowdfunding.notify';
     // Prepare params
     $this->params = JComponentHelper::getParams('com_crowdfunding');
     // Prepare container and some of the most used objects.
     $this->container = Prism\Container::getContainer();
     $this->prepareCurrency($this->container, $this->params);
     $this->prepareMoneyFormatter($this->container, $this->params);
 }
コード例 #2
0
 /**
  * Upload an image.
  *
  * @param  array $image
  * @param  string $destFolder
  *
  * @throws RuntimeException
  * @throws InvalidArgumentException
  *
  * @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();
     $uploadedFile = Joomla\Utilities\ArrayHelper::getValue($image, 'tmp_name');
     $uploadedName = JString::trim(Joomla\Utilities\ArrayHelper::getValue($image, 'name'));
     $errorCode = Joomla\Utilities\ArrayHelper::getValue($image, 'error');
     $fileOptions = new Joomla\Registry\Registry(array('filename_length' => 12));
     $file = new Prism\File\Image($image, $destFolder, $fileOptions);
     if (Joomla\String\StringHelper::strlen($uploadedName) > 0) {
         $KB = 1024 * 1024;
         $uploadMaxSize = $mediaParams->get('upload_maxsize') * $KB;
         $mimeTypes = explode(',', $mediaParams->get('upload_mime'));
         $imageExtensions = explode(',', $mediaParams->get('image_extensions'));
         // Prepare size validator.
         $fileSize = Joomla\Utilities\ArrayHelper::getValue($image, 'size', 0, 'int');
         // 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());
         }
         try {
             $fileData = $file->upload();
             $names['image'] = $fileData['filename'];
         } catch (\Exception $e) {
             throw new RuntimeException(JText::_('COM_CROWDFUNDING_ERROR_FILE_CANT_BE_UPLOADED'));
         }
         // Generate thumbnails.
         // Create thumbnail.
         $options = array('width' => $params->get('rewards_image_thumb_width', 200), 'height' => $params->get('rewards_image_thumb_height', 200), 'scale' => $params->get('rewards_image_resizing_scale', JImage::SCALE_INSIDE));
         $fileData = $file->resize($options, Prism\Constants::DO_NOT_REPLACE, 'reward_thumb_');
         $names['thumb'] = $fileData['filename'];
         // Create square image.
         $options = array('width' => $params->get('rewards_image_square_width', 50), 'height' => $params->get('rewards_image_square_height', 50), 'scale' => $params->get('rewards_image_resizing_scale', JImage::SCALE_INSIDE));
         $fileData = $file->resize($options, Prism\Constants::DO_NOT_REPLACE, 'reward_square_');
         $names['square'] = $fileData['filename'];
     }
     return $names;
 }