/** * Watermark constructor. * @param array $params * @param string $resultsDir * @throws \Exception */ public function __construct(array $params, $resultsDir = './../uploads/results/') { $this->imageine = new \Imagine\Imagick\Imagine(); $this->image['src'] = $this->imageine->open("./..{$params['img']}"); $this->image['size'] = $this->image['src']->getSize(); $this->watermark['src'] = $this->imageine->open("./..{$params['watermark']}"); $this->watermark['size'] = $this->watermark['src']->getSize(); $this->coordinates['x'] = $params['x']; $this->coordinates['y'] = $params['y']; $this->opacity = $params['opacity']; $this->watermark['src']->getImagick()->setImageOpacity($this->opacity / 100); $this->factor = $params['factor']; $this->tiling = isset($params['tiling']) && $params['tiling']; if ($this->tiling && isset($params['marginX']) && isset($params['marginY'])) { $this->margins['x'] = $params['marginX'] > 0 ? $this->factor * $params['marginX'] : 0; $this->margins['y'] = $params['marginY'] > 0 ? $this->factor * $params['marginY'] : 0; $this->count['x'] = $params['countX']; $this->count['y'] = $params['countY']; } if (file_exists($resultsDir)) { $this->resultsDir = $resultsDir; } else { throw new \Exception('Каталога в который будут сохраняться изображения, не существует!'); } }
/** * @param string $origName * @param string $thumbName * @param array $origInfo */ public function resize($origName, $thumbName, array $origInfo) { if ($this->shouldResize($origInfo)) { $resizeParameters = $this->getResizeParameters($origInfo); $cropParameters = $this->getCropParameters($resizeParameters); $resizeSize = $this->factory->getBox($resizeParameters[0], $resizeParameters[1]); $cropStart = $this->factory->getPoint($cropParameters[0], $cropParameters[1]); $cropSize = $this->factory->getBox($this->thumbConfig[static::CONFIG_WIDTH], $this->thumbConfig[static::CONFIG_HEIGHT]); $this->imagine->open($origName)->resize($resizeSize)->crop($cropStart, $cropSize)->save($thumbName); } else { copy($origName, $thumbName); } }
public function execute() { $options = ['quality' => 85, 'png_compression_level' => 9]; //60 SQUARE // create an cropped image with hard height/width of 60 $imagine = new Imagine(); $imagine->open($this->file->getPathname())->thumbnail(new Box(120, 120), ImageInterface::THUMBNAIL_OUTBOUND)->save($this->generateImagePath($this->file, FileProperties::DIR_SMALL, 2), $options)->thumbnail(new Box(60, 60), ImageInterface::THUMBNAIL_OUTBOUND)->save($this->generateImagePath($this->file, FileProperties::DIR_SMALL, 1), $options); $imagine = null; //300 SQUARE // create an cropped image with hard height/width of 300 $imagine = new Imagine(); $imagine->open($this->file->getPathname())->thumbnail(new Box(600, 600), ImageInterface::THUMBNAIL_OUTBOUND)->save($this->generateImagePath($this->file, FileProperties::DIR_MEDIUM, 2), $options)->thumbnail(new Box(300, 300), ImageInterface::THUMBNAIL_OUTBOUND)->save($this->generateImagePath($this->file, FileProperties::DIR_MEDIUM, 1), $options); $imagine = null; //LARGE // $imagine = new Imagine(); $image = $imagine->open($this->file->getPathname()); $image->resize($image->getSize()->widen(1200))->save($this->generateImagePath($this->file, FileProperties::DIR_LARGE, 2), $options)->resize($image->getSize()->widen(600))->save($this->generateImagePath($this->file, FileProperties::DIR_LARGE, 1), $options); $imagine = null; //ORIGINAL $imagine = new Imagine(); $image = $imagine->open($this->file->getPathname()); $image->resize($image->getSize()->getWidth() > 3600 ? $image->getSize()->widen(3600) : $image->getSize())->save($this->generateImagePath($this->file, FileProperties::DIR_ORIGINAL, 2), $options)->resize($image->getSize()->getWidth() > 2400 ? $image->getSize()->widen(2400) : $image->getSize())->save($this->generateImagePath($this->file, FileProperties::DIR_ORIGINAL, 1), $options); $imagine = null; return new FileProperties($this->file->getFilename()); }
/** * @Route("/file-upload", name="uploadFile") * @Template() */ public function uploadFileAction(Request $request) { $allow = $request->get('private', false); /** @var File $file */ $file = $request->files->get('file'); $imageName = uniqid('legofy-online') . '.png'; $command = sprintf('legofy %s/%s %s/../../../web/images/%s', $file->getPath(), $file->getFilename(), __DIR__, $imageName); $process = new Process($command); $process->run(); if (!$process->isSuccessful()) { throw new ProcessFailedException($process); } $imagine = new Imagine(); $imageFile = $imagine->open(sprintf('%s/../../../web/images/%s', __DIR__, $imageName)); $box = $imageFile->getSize(); if ($box->getHeight() > $box->getWidth()) { $imageFile->resize(new Box(400, $box->getHeight() * (400 / $box->getWidth())))->crop(new Point(0, 0), new Box(400, 400)); } else { $newWidth = $box->getWidth() * (400 / $box->getHeight()); $imageFile->resize(new Box($newWidth, 400))->crop(new Point(($newWidth - 400) / 2, 0), new Box(400, 400)); } $imageFile->save(sprintf('%s/../../../web/images/thumbnails/%s', __DIR__, $imageName)); $image = new Image(); $image->setPrivate($allow)->setName($imageName)->setCreationDate(new \DateTime()); $em = $this->getDoctrine()->getManager(); $em->persist($image); $em->flush(); return new JsonResponse(['url' => $this->generateUrl('editImage', ['id' => $image->getId(), 'name' => $image->getName()])]); }
protected function execute(InputInterface $input, OutputInterface $output) { /** @var EntityRepository $repository */ $repository = $this->getContainer()->get('doctrine')->getRepository('AppBundle:Image'); /** @var Image[] $images */ $images = $repository->findAll(); foreach ($images as $image) { $thumbnailFile = sprintf('%s/../../../web/images/thumbnails/%s', __DIR__, $image->getName()); if (file_exists($thumbnailFile)) { $output->writeln('Thumbnail already generated'); continue; } $imagine = new Imagine(); try { $imageFile = $imagine->open(sprintf('%s/../../../web/images/%s', __DIR__, $image->getName())); } catch (InvalidArgumentException $e) { $output->writeln($e->getMessage()); continue; } $box = $imageFile->getSize(); if ($box->getHeight() > $box->getWidth()) { $imageFile->resize(new Box(400, $box->getHeight() * (400 / $box->getWidth())))->crop(new Point(0, 0), new Box(400, 400)); } else { $newWidth = $box->getWidth() * (400 / $box->getHeight()); $imageFile->resize(new Box($newWidth, 400))->crop(new Point(($newWidth - 400) / 2, 0), new Box(400, 400)); } if ($imageFile->save($thumbnailFile)) { $output->writeln('Thumbnail generated'); } } }
/** * Обработаем создание нового изображения для дальнейшего скачивания пользователем. */ private function handleSaveImage() { $items = $_POST['items']; $category = $_POST['cat']; $image = $_POST['img']; $fileName = Image::getName($category, $image); $Palette = new RGB(); $Imagine = new Imagine(); $Image = $Imagine->open(IMG_1920x1080 . $fileName); foreach ($items as $item) { $text = $item['text']; $fontSize = $item['fontSize']; $x = $item['relativeX']; $y = $item['relativeY']; $sizedFontSize = $fontSize * 1920 / 500; $sizedX = $this->coeffX * $x; $sizedY = $this->coeffY * $y; $Font = $Imagine->font(FONT_DIR . 'Arial.ttf', $sizedFontSize, $Palette->color($item['color'])); $Position = new Point($sizedX, $sizedY); $angle = rad2deg($item['angle']); $Image->draw()->text($text, $Font, $Position, $angle); } $id = uniqid(); $filePath = IMG_DOWNLOAD . $id . Image::EXTENSION; $Image->save($filePath); header('Content-Type: application/json; charset=utf8'); echo json_encode(['id' => $id], JSON_UNESCAPED_UNICODE); exit; }
public function optimizeImage($file) { $imagine = new Imagine\Imagick\Imagine(); $options = array('quality' => 75, 'resolution-units' => Imagine\Image\ImageInterface::RESOLUTION_PIXELSPERINCH, 'resolution-x' => 72, 'resolution-y' => 72); $imagine->open($file)->interlace(Imagine\Image\ImageInterface::INTERLACE_PLANE)->save($file, $options); unset($imagine); }
private function getImagickImagine($file) { try { $imagine = new ImagickImagine(); $image = $imagine->open($file); } catch (RuntimeException $e) { $this->markTestSkipped($e->getMessage()); } return $image; }
function createThumb($thumbWidth, $thumbHeight) { if ($this->uploadStatus == true) { $this->setPaths($thumbWidth . 'x' . $thumbHeight); } else { return false; } $imagine = new Imagick\Imagine(); $size = new Image\Box($thumbWidth, $thumbHeight); $mode = Image\ImageInterface::THUMBNAIL_OUTBOUND; $imagine->open(App::$config['public_dir'] . '/' . $this->uploadfile)->thumbnail($size, $mode)->save(App::$config['public_dir'] . '/' . $this->thumb); }
/** * Add a watermark to image. If no position is entered the watermark will be centered. * * @param $source * @param null $x * @param null $y * @return $this */ public function addWatermark($source, $x = null, $y = null) { $watermark = $this->imagine->open($source); $wSize = $watermark->getSize(); if (!$x && !$y) { $x = $this->openImage()->image->getSize()->getWidth() / 2 + $wSize->getWidth() / 2 - $wSize->getWidth(); $y = $this->openImage()->image->getSize()->getHeight() / 2 + $wSize->getHeight() / 2 - $wSize->getHeight(); } $position = new \Imagine\Image\Point($x, $y); $this->image = $this->image->paste($watermark, $position); return $this; }
public function generateThumbnail($url) { if (!$url) { throw new \Exception("No url specified"); } $imagine = new Imagine(); // Open the image $image = $imagine->open($url); // Create Box from image $originalBox = $image->getSize(); $thumbBox = $originalBox->heighten(200); // Generate unique name $filename = uniqid() . '.png'; // Resize and Save $image->resize($thumbBox)->save(public_path('assets/images/thumbs/' . $filename)); // Return the filename for reference purposes return $filename; }
public function gravatarAction() { $source_path = FA_INCLUDE_TEMP . '/' . $this->user->lower . '_gravatar.png'; if (!@copy($this->_gravatar, $source_path)) { throw new \FA\Exception('Copy error: ' . error_get_last()); } $art_dir = $this->config->application->art_path; // Clean up original filename for destination filename. $dest_path = $art_dir . '/' . $this->user->lower . '/avatars/gravatar.gif'; // Create resized image for avatar. $imagine = new Imagine(); $size = new Box(100, 100); $mode = ImageInterface::THUMBNAIL_INSET; $imagine->open($source_path)->thumbnail($size, $mode)->save($dest_path); $this->user->setAvatar($dest_path); $this->alert('<b>Gravatar loaded!</b><br>Your Gravatar has been added to your avatar collection and set as your default.', 'green'); return $this->redirectFromHere(array('action' => 'index')); }
/** * {@inheritdoc} */ public function run() { $Imagine = new Imagine(); $ids = []; $id = $this->getFileCount(); foreach (CollectionCategory::getAllCategories() as $category) { $dirName = IMG_CREATE . $category . '/'; if (!is_dir($dirName)) { continue; } $DirHandler = opendir($dirName); while ($file = readdir($DirHandler)) { if ($file == '.' || $file == '..') { continue; } $imageName = $dirName . $file; $id++; echo 'Processed category ' . $category . ', file ' . $file . PHP_EOL; try { $Image = $Imagine->open($imageName); } catch (InvalidArgumentException $Ex) { echo $Ex->getMessage() . ' file: ' . $imageName . PHP_EOL; continue; } $fileName = Image::getName($category, $id); $Image->save(IMG_1920x1080 . $fileName); $Image->resize(new Box(500, 281))->save(IMG_500xY . $fileName); $Image->resize(new Box(230, 129))->save(IMG_230xY . $fileName); unlink($imageName); $ids[$category][] = $id; } } $result = []; foreach ($ids as $category => $imageIds) { $result[$category] = json_encode($imageIds); } file_put_contents('ids.txt', var_export($result, true)); var_dump($result); echo PHP_EOL . 'See ids.txt' . PHP_EOL . PHP_EOL; }
/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $imagine = new Imagine(); $width = $input->getOption('width') ?: Faker::numberBetween(200, 1200); $height = $input->getOption('height') ?: Faker::numberBetween(200, 1200); $extension = $input->getOption('extension') ?: Faker::randomElement($this->getAvailableExtensions()); $selector = new Selector($input->getOption('samples')); $images = $selector->select($width, $height, $extension); $filter = array_filter($images, function (Image $image) use($width, $height) { return $width * $height >= $image->getPixels(); }); if (true === empty($filter)) { $image = Faker::randomElement($images); } else { $image = Faker::randomElement($filter); } $transformed = tempnam(sys_get_temp_dir(), uniqid()); $transformation = new Transformation(); $transformation->thumbnail(new Box($width, $height), ImageInterface::THUMBNAIL_OUTBOUND)->save($transformed); $transformation->apply($imagine->open($image->getPath())); $this->getFormatter($input->getOption('formatter'))->output(new Image($transformed), $output); }
public function thumbnailFile(array $file, array $options) { $options = array('quality' => 90, 'mode' => 'outbound') + $options; $imagine = new Imagine(); $size = new \Imagine\Image\Box($options['width'], $options['height']); $uri = $this->parseFileUri($file['uri']); $savePath = tempnam(sys_get_temp_dir(), '_thumb_'); unlink($savePath); $imagine->open($file['file']->getRealPath())->thumbnail($size, $options['mode'])->save($savePath . '.jpg', array('quality' => $options['quality'])); $file = new File($savePath . '.jpg'); $file = $this->uploadFile('thumb', $file); return $file; }
/** * * @return RedirectResponse|Response */ public function myProfilePostAction() { $sc = $this->getSecurityTokenStorage(); $user = $sc->getToken()->getUser(); $oldDbpass = $user->getPassword(); $em = $this->getEntityManager(); $userUpdateProfileForm = $this->createForm(UserUpdateProfileTForm::class, $user); // $userUpdatePreferedLangForm = $this->createForm(UserUpdatePreferedLangTForm::class, $user); $userUpdateEmailForm = $this->createForm(UserUpdateEmailTForm::class, $user); $userUpdatePasswordForm = $this->createForm(UserUpdatePasswordTForm::class, $user); $userUploadAvatarForm = $this->createForm(UserUploadAvatarTForm::class, $user); $userCropAvatarForm = $this->createForm(UserCropAvatarTForm::class); $this->gvars['tabActive'] = $this->getSession()->get('tabActive', 2); $this->getSession()->remove('tabActive'); $request = $this->getRequest(); $reqData = $request->request->all(); $cloneUser = clone $user; if (isset($reqData['UserUpdateEmailForm'])) { $this->gvars['tabActive'] = 2; $this->getSession()->set('tabActive', 2); $userUpdateEmailForm->handleRequest($request); if ($userUpdateEmailForm->isValid()) { $em->persist($user); $em->flush(); $this->flashMsgSession('success', $this->translate('Profile.edit.success')); $this->traceEntity($cloneUser, $user); return $this->redirect($this->generateUrl('_security_profile')); } else { $em->refresh($user); $this->flashMsgSession('error', $this->translate('Profile.edit.failure')); } } elseif (isset($reqData['UserUpdatePasswordForm'])) { $this->gvars['tabActive'] = 2; $this->getSession()->set('tabActive', 2); $userUpdatePasswordForm->handleRequest($request); if ($userUpdatePasswordForm->isValid()) { $oldPassword = $userUpdatePasswordForm['oldPassword']->getData(); $encoder = new Pbkdf2PasswordEncoder('sha512', true, 1000); $oldpassEncoded = $encoder->encodePassword($oldPassword, $user->getSalt()); if ($oldpassEncoded != $oldDbpass) { $formError = new FormError($this->translate('User.oldPassword.incorrect', array(), 'validators')); $userUpdatePasswordForm['oldPassword']->addError($formError); $this->flashMsgSession('error', $this->translate('Profile.edit.failure')); } else { $em->persist($user); $em->flush(); $this->flashMsgSession('success', $this->translate('Profile.edit.success')); $this->traceEntity($cloneUser, $user); return $this->redirect($this->generateUrl('_security_profile')); } } else { $em->refresh($user); $this->flashMsgSession('error', $this->translate('Profile.edit.failure')); } } elseif (isset($reqData['UserUpdateProfileForm'])) { $this->gvars['tabActive'] = 2; $this->getSession()->set('tabActive', 2); $userUpdateProfileForm->handleRequest($request); if ($userUpdateProfileForm->isValid()) { $em->persist($user); $em->flush(); $this->flashMsgSession('success', $this->translate('Profile.edit.success')); $this->traceEntity($cloneUser, $user); return $this->redirect($this->generateUrl('_security_profile')); } else { $em->refresh($user); $this->flashMsgSession('error', $this->translate('Profile.edit.failure')); } } elseif (isset($reqData['UserUploadAvatarForm'])) { $this->gvars['tabActive'] = 2; $this->getSession()->set('tabActive', 2); $userUploadAvatarForm->handleRequest($request); if ($userUploadAvatarForm->isValid()) { $filename = $user->getUsername() . '_' . uniqid() . '.' . $userUploadAvatarForm['avatar']->getData()->guessExtension(); $userUploadAvatarForm['avatar']->getData()->move($this->getParameter('adapter_tmp_files'), $filename); $this->gvars['tmp_avatar'] = $filename; $userCropAvatarForm = $this->createForm(UserCropAvatarTForm::class, null, array('filename' => $filename)); $this->gvars['UserCropAvatarForm'] = $userCropAvatarForm->createView(); $this->gvars['user'] = $user; return $this->renderResponse('AcfSecurityBundle:Profile:resize_avatar.html.twig', $this->gvars); } else { $this->gvars['UserUploadAvatarForm'] = $userUploadAvatarForm->createView(); return $this->renderResponse('AcfSecurityBundle:Profile:resize_avatar_error.html.twig', $this->gvars); } } elseif (isset($reqData['UserCropAvatarForm'])) { $this->gvars['tabActive'] = 2; $this->getSession()->set('tabActive', 2); $userCropAvatarForm->handleRequest($request); if ($userCropAvatarForm->isValid()) { $filename = $userCropAvatarForm['avatar_tmp']->getData(); $path = $this->getParameter('adapter_tmp_files') . '/' . $filename; $x1 = $userCropAvatarForm['x1']->getData(); $y1 = $userCropAvatarForm['y1']->getData(); $w = $userCropAvatarForm['w']->getData(); $h = $userCropAvatarForm['h']->getData(); $imagine = new Imagine(); $image = $imagine->open($path); $firstpoint = new Point($x1, $y1); $selbox = new Box($w, $h); $lastbox = new Box(130, 130); $mode = ImageInterface::THUMBNAIL_OUTBOUND; $image->crop($firstpoint, $selbox)->thumbnail($lastbox, $mode)->save($path); $file = new File($path); $avatarDir = $this->getParameter('kernel.root_dir') . '/../web/res/avatars'; $file->move($avatarDir, $filename); $user->setAvatar($filename); $this->traceEntity($cloneUser, $user); $em->persist($user); $em->flush(); $this->flashMsgSession('success', $this->translate('Profile.edit.success')); $this->getSession()->set('tabActive', 1); return $this->redirect($this->generateUrl('_security_profile')); } else { $em->refresh($user); $this->flashMsgSession('error', $this->translate('Profile.edit.failure')); } } $this->gvars['user'] = $user; $this->gvars['UserUpdateProfileForm'] = $userUpdateProfileForm->createView(); $this->gvars['UserUpdateEmailForm'] = $userUpdateEmailForm->createView(); $this->gvars['UserUpdatePasswordForm'] = $userUpdatePasswordForm->createView(); $this->gvars['UserUploadAvatarForm'] = $userUploadAvatarForm->createView(); $this->gvars['UserCropAvatarForm'] = $userCropAvatarForm->createView(); $this->gvars['pagetitle'] = $this->translate('pagetitle.profile'); $this->gvars['pagetitle_txt'] = $this->translate('pagetitle.profile.txt'); return $this->renderResponse('AcfSecurityBundle:Profile:profile.default.html.twig', $this->gvars); }
public static function rotatePicture($filePath) { if (self::isJpeg($filePath)) { $exif = exif_read_data($filePath); if (!empty($exif['Orientation'])) { switch ($exif['Orientation']) { //See http://www.impulseadventure.com/photo/exif-orientation.html case 8: $angle = -90; break; case 3: $angle = 180; break; case 6: $angle = 90; break; default: return; } $imagine = new Imagine(); $transformation = new \Imagine\Filter\Transformation(); $transformation->rotate($angle); $transformation->apply($imagine->open($filePath))->save($filePath); } } }
/** * Creates a new ImageInterface instance from the given image at the provided path. * * @param File $image Path to an image on the disk. * * @return \Webiny\Component\Image\ImageInterface */ public function open(File $image) { return new Image($this->instance->open($image->getAbsolutePath())); }
/** * @param $path * * @throws MediaException */ protected function convertPsdToImage($path) { if (class_exists('Imagick')) { $imagine = new Imagine(); $image = $imagine->open($path); $image = $image->layers()[0]; file_put_contents($path, $image->get('png')); } else { throw new InvalidMimeTypeForPreviewException('image/vnd.adobe.photoshop'); } }
/** * Opens image with Imagick * * @return AbstractImage */ protected function openWithImagick() { $imagine = new ImagickImage(); return $imagine->open($this->path); }
/** * Rotates image * * @param Image $image * @param $degrees */ public function rotate_image(Image $image, $degrees) { $image_absolute = $this->getFilepath($image); $imagine = new Imagine(); $imagine->open($image_absolute)->rotate($degrees)->save($image_absolute); $this->drop_thumbnails($image); }
public static function open($file) { $adapter = new Imagine(); return $adapter->open($file); }
public function editPostAction($id) { $urlFrom = $this->getReferer(); if (null == $urlFrom || trim($urlFrom) == '') { return $this->redirect($this->generateUrl('_admin_user_list')); } $em = $this->getEntityManager(); try { $user = $em->getRepository('AllucoDataBundle:User')->find($id); if (null == $user) { $this->flashMsgSession('warning', 'User.edit.notfound'); } else { $userUpdateEmailForm = $this->createForm(new UserUpdateEmailTForm(), $user); $userUpdateLockoutForm = $this->createForm(new UserUpdateLockoutTForm(), $user); $userUpdatePasswordForm = $this->createForm(new UserUpdatePasswordTForm(), $user); $userUpdatePreferedLangForm = $this->createForm(new UserUpdatePreferedLangTForm(), $user); $userUpdateJobForm = $this->createForm(new UserUpdateJobTForm(), $user); $userUpdateProfileForm = $this->createForm(new UserUpdateProfileTForm(), $user); $userUpdateUserRolesForm = $this->createForm(new UserUpdateUserRolesTForm(), $user); $userUploadAvatarForm = $this->createForm(new UserUploadAvatarTForm(), $user); $userCropAvatarForm = $this->createForm(new UserCropAvatarTForm()); $this->gvars['tabActive'] = $this->getSession()->get('tabActive', 2); $this->getSession()->remove('tabActive'); $request = $this->getRequest(); $reqData = $request->request->all(); if (isset($reqData['UserUpdateEmailForm'])) { $this->gvars['tabActive'] = 2; $this->getSession()->set('tabActive', 2); $userUpdateEmailForm->handleRequest($request); if ($userUpdateEmailForm->isValid()) { $em->persist($user); $em->flush(); $this->flashMsgSession('success', $this->translate('User.edit.success', array('%user%' => $user->getUsername()))); return $this->redirect($urlFrom); } else { $em->refresh($user); $this->flashMsgSession('error', $this->translate('User.edit.failure', array('%user%' => $user->getUsername()))); } } elseif (isset($reqData['UserUpdateLockoutForm'])) { $this->gvars['tabActive'] = 2; $this->getSession()->set('tabActive', 2); $userUpdateLockoutForm->handleRequest($request); if ($userUpdateLockoutForm->isValid()) { $em->persist($user); $em->flush(); $this->flashMsgSession('success', $this->translate('User.edit.success', array('%user%' => $user->getUsername()))); return $this->redirect($urlFrom); } else { $em->refresh($user); $this->flashMsgSession('error', $this->translate('User.edit.failure', array('%user%' => $user->getUsername()))); } } elseif (isset($reqData['UserUpdatePasswordForm'])) { $this->gvars['tabActive'] = 2; $this->getSession()->set('tabActive', 2); $userUpdatePasswordForm->handleRequest($request); if ($userUpdatePasswordForm->isValid()) { $em->persist($user); $em->flush(); $this->flashMsgSession('success', $this->translate('User.edit.success', array('%user%' => $user->getUsername()))); return $this->redirect($urlFrom); } else { $em->refresh($user); $this->flashMsgSession('error', $this->translate('User.edit.failure', array('%user%' => $user->getUsername()))); } } elseif (isset($reqData['UserUpdatePreferedLangForm'])) { $this->gvars['tabActive'] = 2; $this->getSession()->set('tabActive', 2); $userUpdatePreferedLangForm->handleRequest($request); if ($userUpdatePreferedLangForm->isValid()) { $em->persist($user); $em->flush(); $this->flashMsgSession('success', $this->translate('User.edit.success', array('%user%' => $user->getUsername()))); return $this->redirect($urlFrom); } else { $em->refresh($user); $this->flashMsgSession('error', $this->translate('User.edit.failure', array('%user%' => $user->getUsername()))); } } elseif (isset($reqData['UserUpdateJobForm'])) { $this->gvars['tabActive'] = 2; $this->getSession()->set('tabActive', 2); $userUpdateJobForm->handleRequest($request); if ($userUpdateJobForm->isValid()) { $em->persist($user); $em->flush(); $this->flashMsgSession('success', $this->translate('User.edit.success', array('%user%' => $user->getUsername()))); return $this->redirect($urlFrom); } else { $em->refresh($user); $this->flashMsgSession('error', $this->translate('User.edit.failure', array('%user%' => $user->getUsername()))); } } elseif (isset($reqData['UserUpdateProfileForm'])) { $this->gvars['tabActive'] = 2; $this->getSession()->set('tabActive', 2); $userUpdateProfileForm->handleRequest($request); if ($userUpdateProfileForm->isValid()) { $em->persist($user); $em->flush(); $this->flashMsgSession('success', $this->translate('User.edit.success', array('%user%' => $user->getUsername()))); return $this->redirect($urlFrom); } else { $em->refresh($user); $this->flashMsgSession('error', $this->translate('User.edit.failure', array('%user%' => $user->getUsername()))); } } elseif (isset($reqData['UserUpdateUserRolesForm'])) { $this->gvars['tabActive'] = 2; $this->getSession()->set('tabActive', 2); $userUpdateUserRolesForm->handleRequest($request); if ($userUpdateUserRolesForm->isValid()) { $em->persist($user); $em->flush(); $this->flashMsgSession('success', $this->translate('User.edit.success', array('%user%' => $user->getUsername()))); return $this->redirect($urlFrom); } else { $em->refresh($user); $this->flashMsgSession('error', $this->translate('User.edit.failure', array('%user%' => $user->getUsername()))); } } elseif (isset($reqData['UserUploadAvatarForm'])) { $this->gvars['tabActive'] = 2; $this->getSession()->set('tabActive', 2); $userUploadAvatarForm->handleRequest($request); if ($userUploadAvatarForm->isValid()) { $filename = $user->getUsername() . "_" . uniqid() . '.' . $userUploadAvatarForm['avatar']->getData()->guessExtension(); $userUploadAvatarForm['avatar']->getData()->move($this->getParameter('adapter_tmp_files'), $filename); $this->gvars['tmp_avatar'] = $filename; $userCropAvatarForm = $this->createForm(new UserCropAvatarTForm($filename)); $this->gvars['UserCropAvatarForm'] = $userCropAvatarForm->createView(); $this->gvars['user'] = $user; return $this->renderResponse('AllucoAdminBundle:User:resize_avatar.html.twig', $this->gvars); } else { $this->gvars['UserUploadAvatarForm'] = $userUploadAvatarForm->createView(); return $this->renderResponse('AllucoAdminBundle:User:resize_avatar_error.html.twig', $this->gvars); } } elseif (isset($reqData['UserCropAvatarForm'])) { $this->gvars['tabActive'] = 2; $this->getSession()->set('tabActive', 2); $userCropAvatarForm->handleRequest($request); if ($userCropAvatarForm->isValid()) { $filename = $userCropAvatarForm['avatar_tmp']->getData(); $path = $this->getParameter('adapter_tmp_files') . '/' . $filename; $x1 = $userCropAvatarForm['x1']->getData(); $y1 = $userCropAvatarForm['y1']->getData(); $w = $userCropAvatarForm['w']->getData(); $h = $userCropAvatarForm['h']->getData(); $imagine = new Imagine(); $image = $imagine->open($path); /* $widh = $image->getSize()->getWidth(); $mult = 1; if ($widh > 400) { $mult = $widh / 400; } if ($widh < 130) { $mult = $widh / 130; } $x1 = round($x1 * $mult); $y1 = round($y1 * $mult); $w = round($w * $mult); $h = round($h * $mult);*/ $firstpoint = new Point($x1, $y1); $selbox = new Box($w, $h); $lastbox = new Box(130, 130); $mode = ImageInterface::THUMBNAIL_OUTBOUND; $image->crop($firstpoint, $selbox)->thumbnail($lastbox, $mode)->save($path); $file = new File($path); $avatarDir = $this->getParameter('kernel.root_dir') . '/../web/res/avatars'; $file->move($avatarDir, $filename); $user->setAvatar($filename); $em->persist($user); $em->flush(); $this->flashMsgSession('success', $this->translate('User.edit.success', array('%user%' => $user->getUsername()))); $this->getSession()->set('tabActive', 1); return $this->redirect($urlFrom); } else { $em->refresh($user); $this->flashMsgSession('error', $this->translate('User.edit.failure', array('%user%' => $user->getUsername()))); } } $this->gvars['user'] = $user; $this->gvars['UserUpdateEmailForm'] = $userUpdateEmailForm->createView(); $this->gvars['UserUpdateLockoutForm'] = $userUpdateLockoutForm->createView(); $this->gvars['UserUpdatePasswordForm'] = $userUpdatePasswordForm->createView(); $this->gvars['UserUpdatePreferedLangForm'] = $userUpdatePreferedLangForm->createView(); $this->gvars['UserUpdateJobForm'] = $userUpdateJobForm->createView(); $this->gvars['UserUpdateProfileForm'] = $userUpdateProfileForm->createView(); $this->gvars['UserUpdateUserRolesForm'] = $userUpdateUserRolesForm->createView(); $this->gvars['UserUploadAvatarForm'] = $userUploadAvatarForm->createView(); $this->gvars['UserCropAvatarForm'] = $userCropAvatarForm->createView(); $this->gvars['pagetitle'] = $this->translate('Pagetitle.user.edit', array('%user%' => $user->getUsername())); $this->gvars['pagetitle_txt'] = $this->translate('Pagetitle.user.edit.txt', array('%user%' => $user->getUsername())); return $this->renderResponse('AllucoAdminBundle:User:edit.html.twig', $this->gvars); } } catch (\Exception $e) { $logger = $this->getLogger(); $logger->addCritical($e->getLine() . ' ' . $e->getMessage() . ' ' . $e->getTraceAsString()); } return $this->redirect($urlFrom); }
public function myProfilePostAction() { $sc = $this->getSecurityContext(); $user = $sc->getToken()->getUser(); $oldDbpass = $user->getPassword(); $em = $this->getEntityManager(); $root = $em->getRepository('AllucoDataBundle:Staticpage')->findOneBy(array('pageUrl' => '/')); $this->gvars['root'] = $root; $staticpage = $em->getRepository('AllucoDataBundle:Staticpage')->findOneBy(array('pageUrl' => '/myProfile')); if (null != $staticpage) { $this->gvars['pagetitle_txt'] = $staticpage->getMetaTitleTrans(); $this->gvars['pagetitle'] = $staticpage->getPageTitleTrans(); $metas = array(); if (null != $staticpage->getMetaKeywordsTrans()) { $meta = array(); $meta['name'] = 'keywords'; $meta['content'] = $staticpage->getMetaKeywordsTrans(); $metas[] = $meta; } if (null != $staticpage->getMetaDescriptionTrans()) { $meta = array(); $meta['name'] = 'description'; $meta['content'] = $staticpage->getMetaDescriptionTrans(); $metas[] = $meta; } $this->gvars['metas'] = $metas; } $this->gvars['staticpage'] = $staticpage; $banners = $em->getRepository('AllucoDataBundle:Banner')->getAll(); $this->gvars['banners'] = $banners; $news = $em->getRepository('AllucoDataBundle:Sitenew')->getLimited(1); $this->gvars['news'] = $news; $groups = $em->getRepository('AllucoDataBundle:Product')->getRoots(); $this->gvars['groups'] = $groups; $userUpdateProfileForm = $this->createForm(new UserUpdateProfileTForm(), $user); $userUpdatePreferedLangForm = $this->createForm(new UserUpdatePreferedLangTForm(), $user); $userUpdateJobForm = $this->createForm(new UserUpdateJobTForm(), $user); $userUpdateEmailForm = $this->createForm(new UserUpdateEmailTForm(), $user); $userUpdatePasswordForm = $this->createForm(new UserUpdatePasswordTForm(), $user); $userUploadAvatarForm = $this->createForm(new UserUploadAvatarTForm(), $user); $userCropAvatarForm = $this->createForm(new UserCropAvatarTForm()); $this->gvars['tabActive'] = $this->getSession()->get('tabActive', 2); $this->getSession()->remove('tabActive'); $request = $this->getRequest(); $reqData = $request->request->all(); if (isset($reqData['UserUpdateEmailForm'])) { $this->gvars['tabActive'] = 2; $this->getSession()->set('tabActive', 2); $userUpdateEmailForm->bind($request); if ($userUpdateEmailForm->isValid()) { $em->persist($user); $em->flush(); $this->flashMsgSession('success', $this->translate('Profile.edit.success')); return $this->redirect($this->generateUrl('_security_profile')); } else { $em->refresh($user); $this->flashMsgSession('error', $this->translate('Profile.edit.failure')); } } elseif (isset($reqData['UserUpdatePasswordForm'])) { $this->gvars['tabActive'] = 2; $this->getSession()->set('tabActive', 2); $userUpdatePasswordForm->bind($request); if ($userUpdatePasswordForm->isValid()) { $oldPassword = $userUpdatePasswordForm['oldPassword']->getData(); $encoder = new Pbkdf2PasswordEncoder('sha512', true, 1000); $oldpassEncoded = $encoder->encodePassword($oldPassword, $user->getSalt()); if ($oldpassEncoded != $oldDbpass) { $formError = new FormError($this->translate('User.oldPassword.incorrect', array(), 'validators')); $userUpdatePasswordForm['oldPassword']->addError($formError); $this->flashMsgSession('error', $this->translate('Profile.edit.failure')); } else { $em->persist($user); $em->flush(); $this->flashMsgSession('success', $this->translate('Profile.edit.success')); return $this->redirect($this->generateUrl('_security_profile')); } } else { $em->refresh($user); $this->flashMsgSession('error', $this->translate('Profile.edit.failure')); } } elseif (isset($reqData['UserUpdatePreferedLangForm'])) { $this->gvars['tabActive'] = 2; $this->getSession()->set('tabActive', 2); $userUpdatePreferedLangForm->bind($request); if ($userUpdatePreferedLangForm->isValid()) { $em->persist($user); $em->flush(); $this->flashMsgSession('success', $this->translate('Profile.edit.success')); return $this->redirect($this->generateUrl('_security_profile')); } else { $em->refresh($user); $this->flashMsgSession('error', $this->translate('Profile.edit.failure')); } } elseif (isset($reqData['UserUpdateJobForm'])) { $this->gvars['tabActive'] = 2; $this->getSession()->set('tabActive', 2); $userUpdateJobForm->bind($request); if ($userUpdateJobForm->isValid()) { $em->persist($user); $em->flush(); $this->flashMsgSession('success', $this->translate('Profile.edit.success')); return $this->redirect($this->generateUrl('_security_profile')); } else { $em->refresh($user); $this->flashMsgSession('error', $this->translate('Profile.edit.failure')); } } elseif (isset($reqData['UserUpdateProfileForm'])) { $this->gvars['tabActive'] = 2; $this->getSession()->set('tabActive', 2); $userUpdateProfileForm->bind($request); if ($userUpdateProfileForm->isValid()) { $em->persist($user); $em->flush(); $this->flashMsgSession('success', $this->translate('Profile.edit.success')); return $this->redirect($this->generateUrl('_security_profile')); } else { $em->refresh($user); $this->flashMsgSession('error', $this->translate('Profile.edit.failure')); } } elseif (isset($reqData['UserUploadAvatarForm'])) { $this->gvars['tabActive'] = 2; $this->getSession()->set('tabActive', 2); $userUploadAvatarForm->bind($request); if ($userUploadAvatarForm->isValid()) { $filename = $user->getUsername() . "_" . uniqid() . '.' . $userUploadAvatarForm['avatar']->getData()->guessExtension(); $userUploadAvatarForm['avatar']->getData()->move($this->getParameter('adapter_tmp_files'), $filename); $this->gvars['tmp_avatar'] = $filename; $userCropAvatarForm = $this->createForm(new UserCropAvatarTForm($filename)); $this->gvars['UserCropAvatarForm'] = $userCropAvatarForm->createView(); $this->gvars['user'] = $user; return $this->renderResponse('AllucoSecurityBundle:Profile:resize_avatar.html.twig', $this->gvars); } else { $this->gvars['UserUploadAvatarForm'] = $userUploadAvatarForm->createView(); return $this->renderResponse('AllucoSecurityBundle:Profile:resize_avatar_error.html.twig', $this->gvars); } } elseif (isset($reqData['UserCropAvatarForm'])) { $this->gvars['tabActive'] = 2; $this->getSession()->set('tabActive', 2); $userCropAvatarForm->bind($request); if ($userCropAvatarForm->isValid()) { $filename = $userCropAvatarForm['avatar_tmp']->getData(); $path = $this->getParameter('adapter_tmp_files') . '/' . $filename; $x1 = $userCropAvatarForm['x1']->getData(); $y1 = $userCropAvatarForm['y1']->getData(); $w = $userCropAvatarForm['w']->getData(); $h = $userCropAvatarForm['h']->getData(); $imagine = new Imagine(); $image = $imagine->open($path); $firstpoint = new Point($x1, $y1); $selbox = new Box($w, $h); $lastbox = new Box(130, 130); $mode = ImageInterface::THUMBNAIL_OUTBOUND; $image->crop($firstpoint, $selbox)->thumbnail($lastbox, $mode)->save($path); $file = new File($path); $avatarDir = $this->getParameter('kernel.root_dir') . '/../web/res/avatars'; $file->move($avatarDir, $filename); $user->setAvatar($filename); $em->persist($user); $em->flush(); $this->flashMsgSession('success', $this->translate('Profile.edit.success')); $this->getSession()->set('tabActive', 1); return $this->redirect($this->generateUrl('_security_profile')); } else { $em->refresh($user); $this->flashMsgSession('error', $this->translate('Profile.edit.failure')); } } $this->gvars['user'] = $user; $this->gvars['UserUpdateProfileForm'] = $userUpdateProfileForm->createView(); $this->gvars['UserUpdatePreferedLangForm'] = $userUpdatePreferedLangForm->createView(); $this->gvars['UserUpdateJobForm'] = $userUpdateJobForm->createView(); $this->gvars['UserUpdateEmailForm'] = $userUpdateEmailForm->createView(); $this->gvars['UserUpdatePasswordForm'] = $userUpdatePasswordForm->createView(); $this->gvars['UserUploadAvatarForm'] = $userUploadAvatarForm->createView(); $this->gvars['UserCropAvatarForm'] = $userCropAvatarForm->createView(); return $this->renderResponse('AllucoSecurityBundle:Profile:profile.default.html.twig', $this->gvars); }
public function editAction() { $types = $this->config->fa->upload_types->toArray(); $id = (int) $this->getParam('id'); if ($id !== 0) { // Edit existing record. // TODO: Reimplement administrator access. $record = Upload::getRepository()->findOneBy(array('id' => $id, 'user_id' => $this->user->id)); if (!$record instanceof Upload) { throw new \FA\Exception('Submission ID not found!'); } $edit_mode = true; $type = $record->submission_type; } else { // Create new submission. $type = $this->getParam('type'); // Show type selector if no type is specified. if (empty($type) || !isset($types[$type])) { $this->view->types = $types; return $this->view->pick('uploads/select'); } $edit_mode = false; $record = NULL; } $type_info = $types[$type]; $form_config = $this->current_module_config->forms->uploads_edit->toArray(); // Create mode changes if (!$edit_mode) { $form_config['groups']['files']['elements']['submission'][1]['required'] = true; unset($form_config['groups']['files']['elements']['submission'][1]['description']); unset($form_config['groups']['files']['elements']['rebuild_thumbnail']); } // Changes to the form based on submission type. if (isset($type_info['category'])) { $form_config['groups']['metadata']['elements']['category'][1]['default'] = $type_info['category']; } if ($type !== Upload::TYPE_IMAGE) { unset($form_config['groups']['files']['elements']['rebuild_thumbnail']); } $form_config['groups']['files']['elements']['submission'][1]['allowedTypes'] = $type_info['types']; // Create the form class. $form = new \FA\Form($form_config); // Populate the form (if available). if ($record instanceof Upload) { $form->setDefaults($record->toArray(TRUE, TRUE)); } // Handle form submission. if ($_POST && $this->request->hasFiles() && $form->isValid(array_merge($_POST, $_FILES))) { $data = $form->getValues(); if (!$record instanceof Upload) { $record = new Upload(); $record->upload_type = $type; $record->user = $this->user; $record->is_hidden = true; // Hide until properly populated. $record->save(); // Immediately save to generate IDs used in next steps. } $record->fromArray($data); // Begin file handling. \IMagick::setResourceLimit(\Imagick::RESOURCETYPE_MEMORY, 32); \IMagick::setResourceLimit(\Imagick::RESOURCETYPE_MAP, 32); $files = $form->getFiles($this->request); $imagine = new Imagine(); $submission_file = $files['submission'][0]; $thumbnail_file = null; $thumbnail_paths = array(); $preview_file = null; $preview_paths = array(); if ($submission_file) { $submission_paths = $record->generatePaths($submission_file->getName()); // Create the proper artwork directory if it doesn't exist. $submission_dir = dirname($submission_paths['full']['path']); @mkdir($submission_dir); if ($type == Upload::TYPE_IMAGE) { // Handle image uploads. $submission_image = $imagine->open($submission_file->getTempName()); $is_animated = count($submission_image->layers()) > 1; // So, it seems Imagine really loves to screw up GIFs, so lets avoid that if ($is_animated) { $dest_path = $submission_paths['full']['path']; // Copying this instead of moving due to the file being reused by preview/thumbnail copy($submission_file->getTempName(), $dest_path); } else { $submission_image->save($submission_paths['full']['path'], array('animated' => $is_animated)); } // Make this file the thumbnail if no other is specified. if (empty($files['thumbnail']) && (!$edit_mode || $data['rebuild_thumbnail'])) { $thumbnail_file = $submission_file; $thumbnail_paths = $submission_paths; } // Set up the preview parameters $preview_file = $submission_file; $preview_paths = $submission_paths; } else { // Handle non-images. Way simpler, right? $dest_path = $submission_paths['full']['path']; $submission_file->moveTo($dest_path); // Prevent the file from being deleted below. $submission_file = null; } $record->setFull($submission_paths['full']['base']); } // Use the thumbnail field if supplied. if (!empty($files['thumbnail'])) { $thumbnail_file = $files['thumbnail'][0]; $thumbnail_paths = $record->generatePaths($thumbnail_file->getName()); } // If we haven't set a preview image/path, then use the thumbnail if possible if (is_null($preview_file)) { $preview_file = $thumbnail_file; $preview_paths = $thumbnail_paths; } // Process either the uploaded thumbnail, or resize the original file to be our preview. if ($preview_file) { // Generate "small" size thumbnail. $preview_size = new Box(self::MAX_PREVIEW_SIZE, self::MAX_PREVIEW_SIZE); self::_saveAsJPG($imagine, $preview_file, $preview_paths['small']['path'], 90, $preview_size); $record->setSmall(self::_changeExtension($preview_paths['small']['base'], 'jpg')); } // Process either the uploaded thumbnail, or thumbnailize the original file. if ($thumbnail_file) { // Generate "thumb" size thumbnail. $thumbnail_size = new Box(self::MAX_THUMB_SIZE, self::MAX_THUMB_SIZE); self::_saveAsJPG($imagine, $thumbnail_file, $thumbnail_paths['thumbnail']['path'], 90, $thumbnail_size); $record->setThumbnail(self::_changeExtension($thumbnail_paths['thumbnail']['base'], 'jpg')); } // Delete the temp files (if not already moved). if ($submission_file) { @unlink($submission_file->getTempName()); } if ($thumbnail_file) { @unlink($thumbnail_file->getTempName()); } // Unhide the record that was hidden earlier. if (!$edit_mode) { $record->is_hidden = false; } $record->save(); $view_url = $this->url->get('view/' . $record->id); $view_link = 'You can <a href="' . $view_url . '" target="_blank_">view your submission\'s public page here</a>.'; if ($edit_mode) { $this->alert('<b>Submission Updated!</b><br>' . $view_link, 'green'); } else { $this->alert('<b>New Submission Uploaded!</b><br>' . $view_link, 'green'); } return $this->redirectFromHere(array('action' => 'index', 'id' => NULL, 'type' => NULL)); } // Render the main form. $this->view->type_info = $type_info; $this->view->form = $form; }
/** * * @param string $id * @return \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response */ public function editPostAction($id) { if (!$this->hasRole('ROLE_SUPERADMIN')) { return $this->redirect($this->generateUrl('_admin_homepage')); } $urlFrom = $this->getReferer(); if (null == $urlFrom || trim($urlFrom) == '') { return $this->redirect($this->generateUrl('_admin_user_list')); } $em = $this->getEntityManager(); try { $user = $em->getRepository('AcfDataBundle:User')->find($id); if (null == $user) { $this->flashMsgSession('warning', 'User.edit.notfound'); } else { $traces = $em->getRepository('AcfDataBundle:Trace')->getAllByEntityId($user->getId(), Trace::AE_USER); $this->gvars['traces'] = array_reverse($traces); $userUpdateEmailForm = $this->createForm(UserUpdateEmailTForm::class, $user); $userUpdateLockoutForm = $this->createForm(UserUpdateLockoutTForm::class, $user); $userUpdatePasswordForm = $this->createForm(UserUpdatePasswordTForm::class, $user); $userUpdatePreferedLangForm = $this->createForm(UserUpdatePreferedLangTForm::class, $user); $userUpdateProfileForm = $this->createForm(UserUpdateProfileTForm::class, $user); $userUpdateUserRolesForm = $this->createForm(UserUpdateUserRolesTForm::class, $user); $userUploadAvatarForm = $this->createForm(UserUploadAvatarTForm::class, $user); $userCropAvatarForm = $this->createForm(UserCropAvatarTForm::class); $this->gvars['tabActive'] = $this->getSession()->get('tabActive', 2); $this->getSession()->remove('tabActive'); $request = $this->getRequest(); $reqData = $request->request->all(); $cloneUser = clone $user; if (isset($reqData['UserUpdateEmailForm'])) { $this->gvars['tabActive'] = 2; $this->getSession()->set('tabActive', 2); $userUpdateEmailForm->handleRequest($request); if ($userUpdateEmailForm->isValid()) { $em->persist($user); $em->flush(); $this->flashMsgSession('success', $this->translate('User.edit.success', array('%user%' => $user->getUsername()))); $this->traceEntity($cloneUser, $user); return $this->redirect($urlFrom); } else { $em->refresh($user); $this->flashMsgSession('error', $this->translate('User.edit.failure', array('%user%' => $user->getUsername()))); } } elseif (isset($reqData['UserUpdateLockoutForm'])) { $this->gvars['tabActive'] = 2; $this->getSession()->set('tabActive', 2); $userUpdateLockoutForm->handleRequest($request); if ($userUpdateLockoutForm->isValid()) { $em->persist($user); $em->flush(); $this->flashMsgSession('success', $this->translate('User.edit.success', array('%user%' => $user->getUsername()))); $this->traceEntity($cloneUser, $user); $from = $this->getParameter('mail_from'); $fromName = $this->getParameter('mail_from_name'); $message = \Swift_Message::newInstance()->setFrom($from, $fromName); $message->setTo($user->getEmail(), $user->getFullname()); $mvars = array(); $mvars['user'] = $user; $mvars['logo'] = $message->embed(\Swift_Image::fromPath($this->getParameter('kernel.root_dir') . '/../web/bundles/acfres/images/logo_acf.jpg')); if ($user->getLockout() == User::LOCKOUT_LOCKED) { $subject = $this->translate('_mail.register.lock.subject', array(), 'messages'); $message->setSubject($subject); $message->setBody($this->renderView('AcfSecurityBundle:Mail:user.lock.html.twig', $mvars), 'text/html'); } else { $subject = $this->translate('_mail.register.unlock.subject', array(), 'messages'); $message->setSubject($subject); $message->setBody($this->renderView('AcfSecurityBundle:Mail:user.unlock.html.twig', $mvars), 'text/html'); } $this->sendmail($message); $this->flashMsgSession('success', $this->translate('User.lockout.success', array('%mail%' => $user->getEmail()))); return $this->redirect($urlFrom); } else { $em->refresh($user); $this->flashMsgSession('error', $this->translate('User.edit.failure', array('%user%' => $user->getUsername()))); } } elseif (isset($reqData['UserUpdatePasswordForm'])) { $this->gvars['tabActive'] = 2; $this->getSession()->set('tabActive', 2); $userUpdatePasswordForm->handleRequest($request); if ($userUpdatePasswordForm->isValid()) { $em->persist($user); $em->flush(); $this->flashMsgSession('success', $this->translate('User.edit.success', array('%user%' => $user->getUsername()))); $this->traceEntity($cloneUser, $user); return $this->redirect($urlFrom); } else { $em->refresh($user); $this->flashMsgSession('error', $this->translate('User.edit.failure', array('%user%' => $user->getUsername()))); } } elseif (isset($reqData['UserUpdatePreferedLangForm'])) { $this->gvars['tabActive'] = 2; $this->getSession()->set('tabActive', 2); $userUpdatePreferedLangForm->handleRequest($request); if ($userUpdatePreferedLangForm->isValid()) { $em->persist($user); $em->flush(); $this->flashMsgSession('success', $this->translate('User.edit.success', array('%user%' => $user->getUsername()))); $this->traceEntity($cloneUser, $user); return $this->redirect($urlFrom); } else { $em->refresh($user); $this->flashMsgSession('error', $this->translate('User.edit.failure', array('%user%' => $user->getUsername()))); } } elseif (isset($reqData['UserUpdateProfileForm'])) { $this->gvars['tabActive'] = 2; $this->getSession()->set('tabActive', 2); $userUpdateProfileForm->handleRequest($request); if ($userUpdateProfileForm->isValid()) { $em->persist($user); $em->flush(); $this->flashMsgSession('success', $this->translate('User.edit.success', array('%user%' => $user->getUsername()))); $this->traceEntity($cloneUser, $user); return $this->redirect($urlFrom); } else { $em->refresh($user); $this->flashMsgSession('error', $this->translate('User.edit.failure', array('%user%' => $user->getUsername()))); } } elseif (isset($reqData['UserUpdateUserRolesForm'])) { $this->gvars['tabActive'] = 2; $this->getSession()->set('tabActive', 2); $userUpdateUserRolesForm->handleRequest($request); if ($userUpdateUserRolesForm->isValid()) { $em->persist($user); $em->flush(); $this->flashMsgSession('success', $this->translate('User.edit.success', array('%user%' => $user->getUsername()))); $this->traceEntity($cloneUser, $user); return $this->redirect($urlFrom); } else { $em->refresh($user); $this->flashMsgSession('error', $this->translate('User.edit.failure', array('%user%' => $user->getUsername()))); } } elseif (isset($reqData['UserUploadAvatarForm'])) { $this->gvars['tabActive'] = 2; $this->getSession()->set('tabActive', 2); $userUploadAvatarForm->handleRequest($request); if ($userUploadAvatarForm->isValid()) { $filename = $user->getUsername() . '_' . uniqid() . '.' . $userUploadAvatarForm['avatar']->getData()->guessExtension(); $userUploadAvatarForm['avatar']->getData()->move($this->getParameter('adapter_tmp_files'), $filename); $this->gvars['tmp_avatar'] = $filename; $userCropAvatarForm = $this->createForm(UserCropAvatarTForm::class, null, array('filename' => $filename)); $this->gvars['UserCropAvatarForm'] = $userCropAvatarForm->createView(); $this->gvars['user'] = $user; return $this->renderResponse('AcfAdminBundle:User:resize_avatar.html.twig', $this->gvars); } else { $this->gvars['UserUploadAvatarForm'] = $userUploadAvatarForm->createView(); return $this->renderResponse('AcfAdminBundle:User:resize_avatar_error.html.twig', $this->gvars); } } elseif (isset($reqData['UserCropAvatarForm'])) { $this->gvars['tabActive'] = 2; $this->getSession()->set('tabActive', 2); $userCropAvatarForm->handleRequest($request); if ($userCropAvatarForm->isValid()) { $filename = $userCropAvatarForm['avatar_tmp']->getData(); $path = $this->getParameter('adapter_tmp_files') . '/' . $filename; $x1 = $userCropAvatarForm['x1']->getData(); $y1 = $userCropAvatarForm['y1']->getData(); $w = $userCropAvatarForm['w']->getData(); $h = $userCropAvatarForm['h']->getData(); $imagine = new Imagine(); $image = $imagine->open($path); /* * $widh = $image->getSize()->getWidth(); * $mult = 1; * if ($widh > 400) { * $mult = $widh / 400; * } * if ($widh < 130) { * $mult = $widh / 130; * } * $x1 = round($x1 * $mult); * $y1 = round($y1 * $mult); * $w = round($w * $mult); * $h = round($h * $mult); */ $firstpoint = new Point($x1, $y1); $selbox = new Box($w, $h); $lastbox = new Box(130, 130); $mode = ImageInterface::THUMBNAIL_OUTBOUND; $image->crop($firstpoint, $selbox)->thumbnail($lastbox, $mode)->save($path); $file = new File($path); $avatarDir = $this->getParameter('kernel.root_dir') . '/../web/res/avatars'; $file->move($avatarDir, $filename); $user->setAvatar($filename); $em->persist($user); $em->flush(); $this->flashMsgSession('success', $this->translate('User.edit.success', array('%user%' => $user->getUsername()))); $this->traceEntity($cloneUser, $user); $this->getSession()->set('tabActive', 1); return $this->redirect($urlFrom); } else { $em->refresh($user); $this->flashMsgSession('error', $this->translate('User.edit.failure', array('%user%' => $user->getUsername()))); } } $this->gvars['user'] = $user; $this->gvars['UserUpdateEmailForm'] = $userUpdateEmailForm->createView(); $this->gvars['UserUpdateLockoutForm'] = $userUpdateLockoutForm->createView(); $this->gvars['UserUpdatePasswordForm'] = $userUpdatePasswordForm->createView(); $this->gvars['UserUpdatePreferedLangForm'] = $userUpdatePreferedLangForm->createView(); $this->gvars['UserUpdateProfileForm'] = $userUpdateProfileForm->createView(); $this->gvars['UserUpdateUserRolesForm'] = $userUpdateUserRolesForm->createView(); $this->gvars['UserUploadAvatarForm'] = $userUploadAvatarForm->createView(); $this->gvars['UserCropAvatarForm'] = $userCropAvatarForm->createView(); $this->gvars['pagetitle'] = $this->translate('pagetitle.user.edit', array('%user%' => $user->getUsername())); $this->gvars['pagetitle_txt'] = $this->translate('pagetitle.user.edit.txt', array('%user%' => $user->getUsername())); return $this->renderResponse('AcfAdminBundle:User:edit.html.twig', $this->gvars); } } catch (\Exception $e) { $logger = $this->getLogger(); $logger->addCritical($e->getLine() . ' ' . $e->getMessage() . ' ' . $e->getTraceAsString()); } return $this->redirect($urlFrom); }