/** * Pre-processor for $table->delete($pk) * * @param mixed $pk An optional primary key value to delete. If not set the instance property value is used. * * @return void * * @since 3.1.2 * @throws UnexpectedValueException */ public function onBeforeDelete($pk) { $userId = CrowdFundingHelper::getUserIdByRewardId($this->table->id); $imagesFolder = CrowdFundingHelper::getImagesFolder($userId); // Remove image. if (!empty($this->table->image)) { $fileSource = $imagesFolder . DIRECTORY_SEPARATOR . $this->table->image; if (JFile::exists($fileSource)) { JFile::delete($fileSource); } } // Remove thumbnail. if (!empty($this->table->image_thumb)) { $fileSource = $imagesFolder . DIRECTORY_SEPARATOR . $this->table->image_thumb; if (JFile::exists($fileSource)) { JFile::delete($fileSource); } } // Remove square image. if (!empty($this->table->image_square)) { $fileSource = $imagesFolder . DIRECTORY_SEPARATOR . $this->table->image_square; if (JFile::exists($fileSource)) { JFile::delete($fileSource); } } }
/** * Deletes extra image. */ public function removeExtraImage() { jimport("itprism.response.json"); $response = new ITPrismResponseJson(); $userId = $this->input->post->getInt("user_id"); $imageId = $this->input->post->getInt("id"); // Get the folder where the images are stored. $imagesFolder = CrowdFundingHelper::getImagesFolder($userId); try { jimport('joomla.filesystem.file'); // Get the model $model = $this->getModel(); $model->removeExtraImage($imageId, $imagesFolder); } catch (Exception $e) { JLog::add($e->getMessage()); $response->setTitle(JText::_('COM_CROWDFUNDING_FAIL'))->setText(JText::_('COM_CROWDFUNDING_ERROR_SYSTEM'))->failure(); echo $response; JFactory::getApplication()->close(); } $response->setTitle(JText::_('COM_CROWDFUNDING_SUCCESS'))->setText(JText::_('COM_CROWDFUNDING_IMAGE_DELETED'))->setData(array("item_id" => $imageId))->success(); echo $response; JFactory::getApplication()->close(); }
/** * Delete image */ public function removeImage() { // Check for request forgeries. JSession::checkToken("get") or jexit(JText::_('JINVALID_TOKEN')); // Get item id $itemId = $this->input->get->getInt("id"); $redirectOptions = array("view" => "reward", "layout" => "edit", "id" => $itemId); // Create an reward object. jimport("crowdfunding.reward"); $reward = new CrowdFundingReward(JFactory::getDbo()); $reward->load($itemId); // Check for registered user if (!$reward->getId()) { $this->displayNotice(JText::_('COM_CROWDFUNDING_ERROR_INVALID_IMAGE'), $redirectOptions); return; } $imagesFolder = CrowdFundingHelper::getImagesFolder($reward->getUserId()); try { jimport('joomla.filesystem.folder'); jimport('joomla.filesystem.file'); jimport('joomla.filesystem.path'); $model = $this->getModel(); $model->removeImage($itemId, $imagesFolder); } catch (Exception $e) { JLog::add($e->getMessage()); throw new Exception(JText::_('COM_CROWDFUNDING_ERROR_SYSTEM')); } $this->displayMessage(JText::_('COM_CROWDFUNDING_IMAGE_DELETED'), $redirectOptions); }
public function save() { // Check for request forgeries. JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN')); $userId = JFactory::getUser()->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; } $params = JComponentHelper::getParams("com_crowdfunding"); /** @var $params Joomla\Registry\Registry */ // Get the data from the form POST $data = $this->input->post->get('rewards', array(), 'array'); $projectId = $this->input->post->get('id', 0, 'int'); $actionSubmit = $this->input->post->getCmd('btn_submit', 'save'); $images = $this->input->files->get('images', array(), 'array'); $userId = JFactory::getUser()->get("id"); // Get wizard type $wizardType = $params->get("project_wizard_type", "five_steps"); $fiveStepsWizard = strcmp($wizardType, "five_steps") == 0 ? true : false; // If it is five steps wizard type, redirect to manager. // If it is six steps wizard type, redirect to extras. if (!$fiveStepsWizard) { $layout = strcmp($actionSubmit, "save_continue") == 0 ? "extras" : "rewards"; } else { $layout = strcmp($actionSubmit, "save_continue") == 0 ? "manager" : "rewards"; } $redirectOptions = array("view" => "project", "layout" => $layout, "id" => $projectId); // Validate project owner. jimport("crowdfunding.validator.project.owner"); $validator = new CrowdFundingValidatorProjectOwner(JFactory::getDbo(), $projectId, $userId); if (!$projectId or !$validator->isValid()) { $this->displayWarning(JText::_('COM_CROWDFUNDING_ERROR_INVALID_PROJECT'), $redirectOptions); return; } $model = $this->getModel(); /** @var $model CrowdFundingModelRewards */ try { $validData = $model->validate($data); $rewardsIds = $model->save($validData, $projectId); $imagesAllowed = $params->get("rewards_images", 0); // Upload images. if ($imagesAllowed and !empty($images) and !empty($rewardsIds)) { // Get the folder where the images will be stored $imagesFolder = CrowdFundingHelper::getImagesFolder($userId); jimport("joomla.filesystem.folder"); if (!JFolder::exists($imagesFolder)) { CrowdFundingHelper::createFolder($imagesFolder); } $images = $model->uploadImages($images, $imagesFolder, $rewardsIds); if (!empty($images)) { $model->storeImages($images, $imagesFolder); } } } catch (InvalidArgumentException $e) { $this->displayWarning($e->getMessage(), $redirectOptions); return; } catch (RuntimeException $e) { $this->displayWarning($e->getMessage(), $redirectOptions); return; } catch (Exception $e) { JLog::add($e->getMessage()); throw new Exception(JText::_('COM_CROWDFUNDING_ERROR_SYSTEM')); } // Redirect to next page $this->displayMessage(JText::_("COM_CROWDFUNDING_REWARDS_SUCCESSFULLY_SAVED"), $redirectOptions); }
/** * Delete an extra image. * */ public function removeExtraImage() { // Create response object jimport("itprism.response.json"); $response = new ITPrismResponseJson(); $userId = JFactory::getUser()->get("id"); if (!$userId) { $response->setTitle(JText::_('COM_CROWDFUNDING_FAIL'))->setText(JText::_('COM_CROWDFUNDING_ERROR_NOT_LOG_IN'))->failure(); echo $response; JFactory::getApplication()->close(); } // Get image ID. $imageId = $this->input->post->get("id"); // Get the folder where the images are stored. $imagesFolder = CrowdFundingHelper::getImagesFolder($userId); try { // Get the model $model = $this->getModel(); /** @var $model CrowdFundingModelStory */ $model->removeExtraImage($imageId, $imagesFolder, $userId); } catch (RuntimeException $e) { $response->setTitle(JText::_('COM_CROWDFUNDING_FAIL'))->setText(JText::_('COM_CROWDFUNDING_ERROR_INVALID_PROJECT'))->failure(); echo $response; JFactory::getApplication()->close(); } catch (Exception $e) { JLog::add($e->getMessage()); throw new Exception($e->getMessage()); } $response->setTitle(JText::_('COM_CROWDFUNDING_SUCCESS'))->setText(JText::_('COM_CROWDFUNDING_IMAGE_DELETED'))->setData(array("item_id" => $imageId))->success(); echo $response; JFactory::getApplication()->close(); }
protected function prepareStory() { $model = JModelLegacy::getInstance("Story", "CrowdFundingModel", $config = array('ignore_request' => false)); /** @var $model CrowdFundingModelStory */ // 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; // Get item $itemId = $this->state->get('story.id'); $this->item = $model->getItem($itemId, $this->userId); $this->form = $model->getForm(); $this->imageFolder = $this->params->get("images_directory", "images/crowdfunding"); $this->pitchImage = $this->item->get("pitch_image"); $this->pWidth = $this->params->get("pitch_image_width", 600); $this->pHeight = $this->params->get("pitch_image_height", 400); // Prepare extra images folder if ($this->params->get("extra_images", 0) and !empty($this->userId)) { jimport('joomla.filesystem.folder'); $userDestinationFolder = CrowdFundingHelper::getImagesFolder($this->userId); if (!JFolder::exists($userDestinationFolder)) { CrowdFundingHelper::createFolder($userDestinationFolder); } jimport("crowdfunding.images"); $this->images = new CrowdFundingImages(JFactory::getDbo()); $this->images->load($itemId); $this->extraImagesUri = CrowdFundingHelper::getImagesFolderUri($this->userId); } $this->pathwayName = JText::_("COM_CROWDFUNDING_STEP_STORY"); }
/** * Method to remove image via AJAX. * * @throws Exception * * @return void */ public function removeImage() { // Get the input $rewardId = $this->input->post->get('rid', 0, 'int'); $userId = JFactory::getUser()->get("id"); jimport("itprism.response.json"); $response = new ITPrismResponseJson(); // Validate user if (!$userId) { $response->setTitle(JText::_('COM_CROWDFUNDING_FAIL'))->setText(JText::_('COM_CROWDFUNDING_ERROR_NOT_LOG_IN'))->failure(); echo $response; JFactory::getApplication()->close(); } $params = JComponentHelper::getParams("com_crowdfunding"); /** @var $params Joomla\Registry\Registry */ if (!$params->get("rewards_images", 0)) { $response->setTitle(JText::_('COM_CROWDFUNDING_FAIL'))->setText(JText::_('COM_CROWDFUNDING_ERROR_INVALID_REWARD'))->failure(); echo $response; JFactory::getApplication()->close(); } // Validate reward owner. jimport("crowdfunding.validator.reward.owner"); $validator = new CrowdFundingValidatorRewardOwner(JFactory::getDbo(), $rewardId, $userId); if (!$rewardId or !$validator->isValid()) { $response->setTitle(JText::_('COM_CROWDFUNDING_FAIL'))->setText(JText::_('COM_CROWDFUNDING_ERROR_INVALID_REWARD'))->failure(); echo $response; JFactory::getApplication()->close(); } // Get the model $model = $this->getModel(); try { // Get the folder where the images will be stored $imagesFolder = CrowdFundingHelper::getImagesFolder($userId); $model->removeImage($rewardId, $imagesFolder); } catch (RuntimeException $e) { $response->setTitle(JText::_('COM_CROWDFUNDING_FAIL'))->setText($e->getMessage())->failure(); echo $response; JFactory::getApplication()->close(); } catch (Exception $e) { JLog::add($e->getMessage()); $response->setTitle(JText::_('COM_CROWDFUNDING_FAIL'))->setText(JText::_('COM_CROWDFUNDING_ERROR_SYSTEM'))->failure(); echo $response; JFactory::getApplication()->close(); } $response->setTitle(JText::_('COM_CROWDFUNDING_SUCCESS'))->setText(JText::_('COM_CROWDFUNDING_REWARD_IMAGE_REMOVED_SUCCESSFULLY'))->success(); echo $response; JFactory::getApplication()->close(); }