當前位置: 首頁>>代碼示例>>PHP>>正文


PHP CrowdfundingHelper::getTemporaryImagesFolderUri方法代碼示例

本文整理匯總了PHP中CrowdfundingHelper::getTemporaryImagesFolderUri方法的典型用法代碼示例。如果您正苦於以下問題:PHP CrowdfundingHelper::getTemporaryImagesFolderUri方法的具體用法?PHP CrowdfundingHelper::getTemporaryImagesFolderUri怎麽用?PHP CrowdfundingHelper::getTemporaryImagesFolderUri使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在CrowdfundingHelper的用法示例。


在下文中一共展示了CrowdfundingHelper::getTemporaryImagesFolderUri方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: cropImage

 public function cropImage()
 {
     // Check for request forgeries.
     JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN'));
     $app = JFactory::getApplication();
     /** @var $app JApplicationSite */
     $response = new Prism\Response\Json();
     $userId = JFactory::getUser()->get("id");
     if (!$userId) {
         $response->setTitle(JText::_('COM_CROWDFUNDING_FAIL'))->setText(JText::_('COM_CROWDFUNDING_ERROR_NOT_LOG_IN'))->failure();
         echo $response;
         $app->close();
     }
     // Get the model
     $model = $this->getModel();
     /** @var $model CrowdfundingModelProject */
     $projectId = $this->input->post->get("id");
     // If there is a project, validate the owner.
     if (!empty($projectId)) {
         // Validate project owner.
         $validator = new Crowdfunding\Validator\Project\Owner(JFactory::getDbo(), $projectId, $userId);
         if (!$validator->isValid()) {
             $response->setTitle(JText::_('COM_CROWDFUNDING_FAIL'))->setText(JText::_('COM_CROWDFUNDING_ERROR_INVALID_PROJECT'))->failure();
             echo $response;
             $app->close();
         }
     }
     // Get the filename from the session.
     $fileName = basename($app->getUserState(Crowdfunding\Constants::TEMPORARY_IMAGE_CONTEXT));
     $temporaryFile = JPath::clean(CrowdfundingHelper::getTemporaryImagesFolder() . "/" . $fileName);
     if (!$fileName or !JFile::exists($temporaryFile)) {
         $response->setTitle(JText::_('COM_CROWDFUNDING_FAIL'))->setText(JText::_('COM_CROWDFUNDING_ERROR_FILE_DOES_NOT_EXIST'))->failure();
         echo $response;
         $app->close();
     }
     $imageUrl = "";
     try {
         // Get the folder where the images will be stored
         $destination = CrowdfundingHelper::getTemporaryImagesFolder();
         $params = JComponentHelper::getParams("com_crowdfunding");
         $options = array("width" => $this->input->getFloat("width"), "height" => $this->input->getFloat("height"), "x" => $this->input->getFloat("x"), "y" => $this->input->getFloat("y"), "destination" => $destination, "resize_width" => $params->get("image_width", 200), "resize_height" => $params->get("image_height", 200));
         // Resize the picture.
         $images = $model->cropImage($temporaryFile, $options);
         $imageName = basename(Joomla\Utilities\ArrayHelper::getValue($images, "image"));
         // Remove the temporary images if they exist.
         $temporaryImages = $app->getUserState(Crowdfunding\Constants::CROPPED_IMAGES_CONTEXT);
         if (!empty($temporaryImages)) {
             $model->removeTemporaryImages($temporaryImages, $destination);
         }
         // If there is a project, store the images to database.
         // If there is NO project, store the images in the session.
         if (!empty($projectId)) {
             $model->updateImages($projectId, $images, $destination);
             $app->setUserState(Crowdfunding\Constants::CROPPED_IMAGES_CONTEXT, null);
             // Get the folder of the images where the pictures will be stored.
             $imageUrl = JUri::base() . CrowdfundingHelper::getImagesFolderUri() . "/" . $imageName;
         } else {
             $app->setUserState(Crowdfunding\Constants::CROPPED_IMAGES_CONTEXT, $images);
             // Get the temporary folder where the images will be stored.
             $imageUrl = JUri::base() . CrowdfundingHelper::getTemporaryImagesFolderUri() . "/" . $imageName;
         }
     } catch (RuntimeException $e) {
         $response->setTitle(JText::_('COM_CROWDFUNDING_FAIL'))->setText($e->getMessage())->failure();
         echo $response;
         $app->close();
     } catch (Exception $e) {
         $response->setTitle(JText::_('COM_CROWDFUNDING_FAIL'))->setText(JText::_('COM_CROWDFUNDING_ERROR_SYSTEM'))->failure();
         echo $response;
         $app->close();
     }
     $response->setTitle(JText::_('COM_CROWDFUNDING_SUCCESS'))->setText(JText::_('COM_CROWDFUNDING_IMAGE_SAVED'))->setData($imageUrl)->success();
     echo $response;
     $app->close();
 }
開發者ID:Eautentik,項目名稱:CrowdFunding,代碼行數:74,代碼來源:project.raw.php


注:本文中的CrowdfundingHelper::getTemporaryImagesFolderUri方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。