本文整理汇总了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();
}