@@ -71,7 +71,7 @@ |
||
| 71 | 71 | |
| 72 | 72 | public function generatePathFromSecretKey($secretKey) |
| 73 | 73 | { |
| 74 | - if($secretKey == '') |
|
| 74 | + if($secretKey == '') |
|
| 75 | 75 | return ''; |
| 76 | 76 | |
| 77 | 77 | $mimeType = $this->getMimeType($secretKey); |
@@ -31,14 +31,14 @@ discard block |
||
| 31 | 31 | |
| 32 | 32 | public function previewIconFilter(\Twig_Environment $twig, $secretKey = '') |
| 33 | 33 | { |
| 34 | - if($secretKey == '') |
|
| 34 | + if ($secretKey == '') |
|
| 35 | 35 | return ''; |
| 36 | 36 | |
| 37 | 37 | $mimeType = $this->getMimeType($secretKey); |
| 38 | 38 | $icon = ''; |
| 39 | 39 | $link = ''; |
| 40 | 40 | |
| 41 | - if(preg_match('/^image/', $mimeType) === 0) { |
|
| 41 | + if (preg_match('/^image/', $mimeType) === 0) { |
|
| 42 | 42 | $icon = $this->getIcon($mimeType); |
| 43 | 43 | $link = $this->generatePath(true, $icon); |
| 44 | 44 | } |
@@ -62,7 +62,7 @@ discard block |
||
| 62 | 62 | |
| 63 | 63 | protected function generatePath($isIcon, $str) |
| 64 | 64 | { |
| 65 | - if($isIcon === true) { |
|
| 65 | + if ($isIcon === true) { |
|
| 66 | 66 | return $this->requestStack->getSchemeAndHttpHost().$this->requestStack->getBasePath().'/bundles/media/images/'.$str; |
| 67 | 67 | } |
| 68 | 68 | |
@@ -71,12 +71,12 @@ discard block |
||
| 71 | 71 | |
| 72 | 72 | public function generatePathFromSecretKey($secretKey) |
| 73 | 73 | { |
| 74 | - if($secretKey == '') |
|
| 74 | + if ($secretKey == '') |
|
| 75 | 75 | return ''; |
| 76 | 76 | |
| 77 | 77 | $mimeType = $this->getMimeType($secretKey); |
| 78 | 78 | |
| 79 | - if(preg_match('/^image/', $mimeType) === 0) { |
|
| 79 | + if (preg_match('/^image/', $mimeType) === 0) { |
|
| 80 | 80 | $icon = $this->getIcon($mimeType); |
| 81 | 81 | return $this->generatePath(true, $icon); |
| 82 | 82 | } |
@@ -53,7 +53,7 @@ discard block |
||
| 53 | 53 | |
| 54 | 54 | public function transform($data) |
| 55 | 55 | { |
| 56 | - if($data instanceof Collection) { |
|
| 56 | + if ($data instanceof Collection) { |
|
| 57 | 57 | return $this->reverseTransform($data); |
| 58 | 58 | } |
| 59 | 59 | |
@@ -79,7 +79,7 @@ discard block |
||
| 79 | 79 | |
| 80 | 80 | protected function transformSingleEntity($data) |
| 81 | 81 | { |
| 82 | - if($data instanceof Media) |
|
| 82 | + if ($data instanceof Media) |
|
| 83 | 83 | return $data->getSecretKey(); |
| 84 | 84 | else |
| 85 | 85 | return $this->em->getRepository($this->class)->findOneBySecretKey($data); |
@@ -91,7 +91,7 @@ discard block |
||
| 91 | 91 | return null; |
| 92 | 92 | } |
| 93 | 93 | |
| 94 | - if(!($data instanceof Collection)) { |
|
| 94 | + if (!($data instanceof Collection)) { |
|
| 95 | 95 | return $this->transform($data); |
| 96 | 96 | } |
| 97 | 97 | |
@@ -48,13 +48,13 @@ |
||
| 48 | 48 | { |
| 49 | 49 | $results = $event->getForm()->getData(); |
| 50 | 50 | |
| 51 | - if($results === null) |
|
| 51 | + if ($results === null) |
|
| 52 | 52 | return; |
| 53 | 53 | |
| 54 | - if(!is_array($results)) |
|
| 54 | + if (!is_array($results)) |
|
| 55 | 55 | $results = array($results); |
| 56 | 56 | |
| 57 | - foreach($results as $media) { |
|
| 57 | + foreach ($results as $media) { |
|
| 58 | 58 | $mediaEvent = new MediaEvent($media); |
| 59 | 59 | $this->dispatcher->dispatch(MediaEvent::POST_SUBMIT, $mediaEvent); |
| 60 | 60 | } |
@@ -34,13 +34,13 @@ discard block |
||
| 34 | 34 | $this->allowedMimetypes = $allowedMimetypes; |
| 35 | 35 | } |
| 36 | 36 | |
| 37 | - /** |
|
| 38 | - * $current_uri String actual uri of the file |
|
| 39 | - * $dest_folder String future uri of the file starting from web/upload folder |
|
| 40 | - * $lifetime DateTime lifetime of the file. If time goes over this limit, the file will be deleted. |
|
| 41 | - **/ |
|
| 42 | - public function upload(UploadedFile $file, $dest_folder = '', \DateTime $lifetime = null) |
|
| 43 | - { |
|
| 37 | + /** |
|
| 38 | + * $current_uri String actual uri of the file |
|
| 39 | + * $dest_folder String future uri of the file starting from web/upload folder |
|
| 40 | + * $lifetime DateTime lifetime of the file. If time goes over this limit, the file will be deleted. |
|
| 41 | + **/ |
|
| 42 | + public function upload(UploadedFile $file, $dest_folder = '', \DateTime $lifetime = null) |
|
| 43 | + { |
|
| 44 | 44 | |
| 45 | 45 | //Cleaning up old files before uploading this one |
| 46 | 46 | $this->cleanup(); |
@@ -63,7 +63,7 @@ discard block |
||
| 63 | 63 | |
| 64 | 64 | $fs = new Filesystem(); |
| 65 | 65 | if (!$fs->exists($this->uploadDir.$dest_folder)) { |
| 66 | - $fs->mkdir($this->uploadDir.$dest_folder); |
|
| 66 | + $fs->mkdir($this->uploadDir.$dest_folder); |
|
| 67 | 67 | } |
| 68 | 68 | |
| 69 | 69 | $em = $this->doctrine->getManager(); |
@@ -117,7 +117,7 @@ discard block |
||
| 117 | 117 | $em->flush(); |
| 118 | 118 | |
| 119 | 119 | return $media; |
| 120 | - } |
|
| 120 | + } |
|
| 121 | 121 | |
| 122 | 122 | public function cleanup() |
| 123 | 123 | { |
@@ -20,11 +20,11 @@ discard block |
||
| 20 | 20 | protected $allowedMimetypes; |
| 21 | 21 | |
| 22 | 22 | const SIZE_OF_KIBIOCTET = 1024; |
| 23 | - const OCTET_IN_KO = 1; |
|
| 24 | - const OCTET_IN_MO = 2; |
|
| 25 | - const OCTET_IN_GO = 3; |
|
| 26 | - const OCTET_IN_TO = 4; |
|
| 27 | - const OCTET_IN_PO = 5; |
|
| 23 | + const OCTET_IN_KO = 1; |
|
| 24 | + const OCTET_IN_MO = 2; |
|
| 25 | + const OCTET_IN_GO = 3; |
|
| 26 | + const OCTET_IN_TO = 4; |
|
| 27 | + const OCTET_IN_PO = 5; |
|
| 28 | 28 | |
| 29 | 29 | public function __construct(Registry $doctrine, Kernel $kernel, $uploadDir, $allowedMimetypes) |
| 30 | 30 | { |
@@ -50,14 +50,14 @@ discard block |
||
| 50 | 50 | |
| 51 | 51 | //checking mimetypes |
| 52 | 52 | $mimeTypePassed = false; |
| 53 | - foreach($this->allowedMimetypes as $mimeType) { |
|
| 54 | - if(preg_match('@'.$mimeType.'@', $file->getMimeType())) |
|
| 53 | + foreach ($this->allowedMimetypes as $mimeType) { |
|
| 54 | + if (preg_match('@'.$mimeType.'@', $file->getMimeType())) |
|
| 55 | 55 | { |
| 56 | 56 | $mimeTypePassed = true; |
| 57 | 57 | } |
| 58 | 58 | } |
| 59 | 59 | |
| 60 | - if(!$mimeTypePassed) { |
|
| 60 | + if (!$mimeTypePassed) { |
|
| 61 | 61 | throw new InvalidMimeTypeException; |
| 62 | 62 | } |
| 63 | 63 | |
@@ -81,7 +81,7 @@ discard block |
||
| 81 | 81 | |
| 82 | 82 | // Checking for a media with the same name |
| 83 | 83 | $mediaExists = $this->doctrine->getRepository('MediaBundle:Media')->findOneByUri($dest_folder.$filename); |
| 84 | - if(count($mediaExists) === 0) { |
|
| 84 | + if (count($mediaExists) === 0) { |
|
| 85 | 85 | $mediaExists = $fs->exists($this->uploadDir.$dest_folder.$filename); |
| 86 | 86 | } |
| 87 | 87 | |
@@ -185,7 +185,7 @@ discard block |
||
| 185 | 185 | |
| 186 | 186 | public function setAllowedMimeTypes(array $type) |
| 187 | 187 | { |
| 188 | - if($type !== null) { |
|
| 188 | + if ($type !== null) { |
|
| 189 | 189 | $this->allowedMimetypes = $type; |
| 190 | 190 | } |
| 191 | 191 | |
@@ -199,8 +199,8 @@ discard block |
||
| 199 | 199 | |
| 200 | 200 | public function convertOctetIn($size, $convert) |
| 201 | 201 | { |
| 202 | - if($convert > 0) { |
|
| 203 | - $size = ($size / self::SIZE_OF_KIBIOCTET) * 1; |
|
| 202 | + if ($convert > 0) { |
|
| 203 | + $size = ($size / self::SIZE_OF_KIBIOCTET) * 1; |
|
| 204 | 204 | return $this->convertOctetIn($size, $convert - 1); |
| 205 | 205 | } |
| 206 | 206 | |
@@ -16,9 +16,9 @@ |
||
| 16 | 16 | |
| 17 | 17 | public function onPostSubmit(MediaEvent $event) |
| 18 | 18 | { |
| 19 | - $media = $event->getMedia(); |
|
| 19 | + $media = $event->getMedia(); |
|
| 20 | 20 | |
| 21 | - if($media !== null) { |
|
| 21 | + if ($media !== null) { |
|
| 22 | 22 | $media->setLifetime(null); |
| 23 | 23 | $this->registry->getManager()->persist($media); |
| 24 | 24 | } |
@@ -32,15 +32,15 @@ discard block |
||
| 32 | 32 | $mediaPreview = $this->container->get('twig.extension.media_preview_extension'); |
| 33 | 33 | foreach ($this->get('request')->files as $files) { |
| 34 | 34 | if(!is_array($files)) |
| 35 | - $files = array($files); |
|
| 35 | + $files = array($files); |
|
| 36 | 36 | foreach($files as $file) { |
| 37 | - $media = $this->get('media')->upload($file, $this->get('request')->get('folder'), $lifetime); |
|
| 38 | - $path = $mediaPreview->generatePathFromSecretKey($media->getSecretKey()); |
|
| 39 | - $returnData[] = array( |
|
| 40 | - 'id' => $media->getSecretKey(), |
|
| 41 | - 'path' => $path, |
|
| 42 | - 'name' => $media->getName(), |
|
| 43 | - ); |
|
| 37 | + $media = $this->get('media')->upload($file, $this->get('request')->get('folder'), $lifetime); |
|
| 38 | + $path = $mediaPreview->generatePathFromSecretKey($media->getSecretKey()); |
|
| 39 | + $returnData[] = array( |
|
| 40 | + 'id' => $media->getSecretKey(), |
|
| 41 | + 'path' => $path, |
|
| 42 | + 'name' => $media->getName(), |
|
| 43 | + ); |
|
| 44 | 44 | } |
| 45 | 45 | } |
| 46 | 46 | |
@@ -81,29 +81,29 @@ discard block |
||
| 81 | 81 | */ |
| 82 | 82 | public function showMediaAction(Media $media, $filter = null) |
| 83 | 83 | { |
| 84 | - $response = new Response(); |
|
| 84 | + $response = new Response(); |
|
| 85 | 85 | |
| 86 | - $lastModified = new \DateTime('now'); |
|
| 86 | + $lastModified = new \DateTime('now'); |
|
| 87 | 87 | |
| 88 | 88 | |
| 89 | - //Checking if it is an image or not |
|
| 90 | - $src = $this->get('media')->getAbsolutePath($media); |
|
| 91 | - $isImage = @getimagesize($src); |
|
| 89 | + //Checking if it is an image or not |
|
| 90 | + $src = $this->get('media')->getAbsolutePath($media); |
|
| 91 | + $isImage = @getimagesize($src); |
|
| 92 | 92 | |
| 93 | - if($isImage) { |
|
| 93 | + if($isImage) { |
|
| 94 | 94 | $response->headers->set('Content-disposition', 'inline;filename='.$media->getName()); |
| 95 | 95 | if (!empty($filter) && $isImage) { |
| 96 | 96 | |
| 97 | - $src = $this->get('media')->getAbsolutePath($media, $filter); |
|
| 98 | - $dataManager = $this->get('liip_imagine.data.manager'); // the data manager service |
|
| 99 | - $filterManager = $this->get('liip_imagine.filter.manager');// the filter manager service |
|
| 97 | + $src = $this->get('media')->getAbsolutePath($media, $filter); |
|
| 98 | + $dataManager = $this->get('liip_imagine.data.manager'); // the data manager service |
|
| 99 | + $filterManager = $this->get('liip_imagine.filter.manager');// the filter manager service |
|
| 100 | 100 | |
| 101 | - $uploadDir = $this->get('media')->getUploadDir($filter); |
|
| 101 | + $uploadDir = $this->get('media')->getUploadDir($filter); |
|
| 102 | 102 | |
| 103 | - if (!is_file($src)) { |
|
| 103 | + if (!is_file($src)) { |
|
| 104 | 104 | $fs = new Filesystem(); |
| 105 | 105 | if (!$fs->exists($uploadDir.$media->getFolder())) { |
| 106 | - $fs->mkdir($uploadDir.$media->getFolder()); |
|
| 106 | + $fs->mkdir($uploadDir.$media->getFolder()); |
|
| 107 | 107 | } |
| 108 | 108 | |
| 109 | 109 | $path = 'upload/'.$media->getUri(); |
@@ -111,33 +111,33 @@ discard block |
||
| 111 | 111 | $responseData = $filterManager->applyFilter($image, $filter); // run the filter |
| 112 | 112 | $data = $responseData->getContent(); // get the image from the response |
| 113 | 113 | file_put_contents($uploadDir.$media->getUri(), $data); |
| 114 | - } else { |
|
| 114 | + } else { |
|
| 115 | 115 | $data = file_get_contents($src); |
| 116 | 116 | $lastModified->setTimestamp(filemtime($src)); |
| 117 | - } |
|
| 117 | + } |
|
| 118 | 118 | |
| 119 | 119 | } else { |
| 120 | - $src = $this->get('media')->getAbsolutePath($media); |
|
| 121 | - $lastModified->setTimestamp(filemtime($src)); |
|
| 122 | - $data = file_get_contents($src); |
|
| 120 | + $src = $this->get('media')->getAbsolutePath($media); |
|
| 121 | + $lastModified->setTimestamp(filemtime($src)); |
|
| 122 | + $data = file_get_contents($src); |
|
| 123 | 123 | } |
| 124 | - } else { |
|
| 124 | + } else { |
|
| 125 | 125 | $lastModified->setTimestamp(filemtime($src)); |
| 126 | 126 | $data = file_get_contents($src); |
| 127 | 127 | $response->headers->set('Content-disposition', 'attachment;filename='.basename($media->getUri())); |
| 128 | - } |
|
| 128 | + } |
|
| 129 | 129 | |
| 130 | - $response->setLastModified($lastModified); |
|
| 131 | - $response->setPublic(); |
|
| 132 | - $response->headers->set('Content-Type', $media->getMime()); |
|
| 130 | + $response->setLastModified($lastModified); |
|
| 131 | + $response->setPublic(); |
|
| 132 | + $response->headers->set('Content-Type', $media->getMime()); |
|
| 133 | 133 | |
| 134 | - if ($response->isNotModified($this->get('request'))) { |
|
| 135 | - return $response; |
|
| 136 | - } |
|
| 134 | + if ($response->isNotModified($this->get('request'))) { |
|
| 135 | + return $response; |
|
| 136 | + } |
|
| 137 | 137 | |
| 138 | - $response->setContent($data); |
|
| 138 | + $response->setContent($data); |
|
| 139 | 139 | |
| 140 | - return $response; |
|
| 140 | + return $response; |
|
| 141 | 141 | } |
| 142 | 142 | |
| 143 | 143 | } |
@@ -19,7 +19,7 @@ discard block |
||
| 19 | 19 | */ |
| 20 | 20 | public function uploadAction() |
| 21 | 21 | { |
| 22 | - $returnData = array(); |
|
| 22 | + $returnData = array(); |
|
| 23 | 23 | |
| 24 | 24 | if ($this->get('request')->get('lifetime') !== null) { |
| 25 | 25 | $lifetime = new \DateTime($this->get('request')->get('lifetime')); |
@@ -31,9 +31,9 @@ discard block |
||
| 31 | 31 | |
| 32 | 32 | $mediaPreview = $this->container->get('twig.extension.media_preview_extension'); |
| 33 | 33 | foreach ($this->get('request')->files as $files) { |
| 34 | - if(!is_array($files)) |
|
| 34 | + if (!is_array($files)) |
|
| 35 | 35 | $files = array($files); |
| 36 | - foreach($files as $file) { |
|
| 36 | + foreach ($files as $file) { |
|
| 37 | 37 | $media = $this->get('media')->upload($file, $this->get('request')->get('folder'), $lifetime); |
| 38 | 38 | $path = $mediaPreview->generatePathFromSecretKey($media->getSecretKey()); |
| 39 | 39 | $returnData[] = array( |
@@ -90,13 +90,13 @@ discard block |
||
| 90 | 90 | $src = $this->get('media')->getAbsolutePath($media); |
| 91 | 91 | $isImage = @getimagesize($src); |
| 92 | 92 | |
| 93 | - if($isImage) { |
|
| 93 | + if ($isImage) { |
|
| 94 | 94 | $response->headers->set('Content-disposition', 'inline;filename='.$media->getName()); |
| 95 | 95 | if (!empty($filter) && $isImage) { |
| 96 | 96 | |
| 97 | 97 | $src = $this->get('media')->getAbsolutePath($media, $filter); |
| 98 | - $dataManager = $this->get('liip_imagine.data.manager'); // the data manager service |
|
| 99 | - $filterManager = $this->get('liip_imagine.filter.manager');// the filter manager service |
|
| 98 | + $dataManager = $this->get('liip_imagine.data.manager'); // the data manager service |
|
| 99 | + $filterManager = $this->get('liip_imagine.filter.manager'); // the filter manager service |
|
| 100 | 100 | |
| 101 | 101 | $uploadDir = $this->get('media')->getUploadDir($filter); |
| 102 | 102 | |
@@ -107,9 +107,9 @@ discard block |
||
| 107 | 107 | } |
| 108 | 108 | |
| 109 | 109 | $path = 'upload/'.$media->getUri(); |
| 110 | - $image = $dataManager->find($filter, $path); // find the image and determine its type |
|
| 111 | - $responseData = $filterManager->applyFilter($image, $filter); // run the filter |
|
| 112 | - $data = $responseData->getContent(); // get the image from the response |
|
| 110 | + $image = $dataManager->find($filter, $path); // find the image and determine its type |
|
| 111 | + $responseData = $filterManager->applyFilter($image, $filter); // run the filter |
|
| 112 | + $data = $responseData->getContent(); // get the image from the response |
|
| 113 | 113 | file_put_contents($uploadDir.$media->getUri(), $data); |
| 114 | 114 | } else { |
| 115 | 115 | $data = file_get_contents($src); |