@@ -97,6 +97,9 @@ |
||
| 97 | 97 | } |
| 98 | 98 | } |
| 99 | 99 | |
| 100 | + /** |
|
| 101 | + * @param \Symfony\Component\HttpFoundation\FileBag $file |
|
| 102 | + */ |
|
| 100 | 103 | private function initEvent($file,$model,$model_id) |
| 101 | 104 | { |
| 102 | 105 | $event = new UploadEvent(); |
@@ -27,24 +27,24 @@ discard block |
||
| 27 | 27 | * @param $editor |
| 28 | 28 | * @return \Symfony\Component\HttpFoundation\Response |
| 29 | 29 | */ |
| 30 | - public function indexAction( $model, $bundle, $model_id, $editor ) |
|
| 30 | + public function indexAction($model, $bundle, $model_id, $editor) |
|
| 31 | 31 | { |
| 32 | 32 | $params = [ |
| 33 | 33 | 'medias'=>$this->get('mk.media.manager')->findMediasByModelAndId($model, $model_id), |
| 34 | 34 | 'entity'=>$this->getManage()->getRepository("$bundle:$model")->find($model_id), |
| 35 | - 'mode'=>$editor=='true' ? $editor : null, |
|
| 36 | - 'url'=>$editor == "true" ? ['model'=>$model,'bundle'=>$bundle,'model_id'=>$model_id,'mode'=>'true'] : ['model'=>$model,'bundle'=>$bundle,'model_id'=>$model_id] |
|
| 35 | + 'mode'=>$editor == 'true' ? $editor : null, |
|
| 36 | + 'url'=>$editor == "true" ? ['model'=>$model, 'bundle'=>$bundle, 'model_id'=>$model_id, 'mode'=>'true'] : ['model'=>$model, 'bundle'=>$bundle, 'model_id'=>$model_id] |
|
| 37 | 37 | ]; |
| 38 | 38 | $form = $this->createForm( |
| 39 | 39 | new MediaType(), |
| 40 | 40 | new Media, |
| 41 | 41 | [ |
| 42 | - 'action' => $this->generateUrl('mykees_media_add',$params['url']), |
|
| 42 | + 'action' => $this->generateUrl('mykees_media_add', $params['url']), |
|
| 43 | 43 | 'method' => 'POST', |
| 44 | 44 | ] |
| 45 | 45 | ); |
| 46 | 46 | |
| 47 | - return $this->render('MykeesMediaBundle:Media:index.html.twig',[ |
|
| 47 | + return $this->render('MykeesMediaBundle:Media:index.html.twig', [ |
|
| 48 | 48 | 'form'=>$form->createView(), |
| 49 | 49 | 'model'=>$model, |
| 50 | 50 | 'bundle'=> $bundle, |
@@ -66,21 +66,21 @@ discard block |
||
| 66 | 66 | 'mode'=>$request->get('mode') |
| 67 | 67 | ]; |
| 68 | 68 | |
| 69 | - if( $request->isXmlHttpRequest() && $requestArray['file'] ) |
|
| 69 | + if ($request->isXmlHttpRequest() && $requestArray['file']) |
|
| 70 | 70 | { |
| 71 | 71 | // Init Event |
| 72 | 72 | $event = $this->initEvent($requestArray['file'], $model); |
| 73 | 73 | |
| 74 | - if($event->getMedia()) |
|
| 74 | + if ($event->getMedia()) |
|
| 75 | 75 | { |
| 76 | - return $this->render('MykeesMediaBundle:Media:upload/upload_list.html.twig',[ |
|
| 76 | + return $this->render('MykeesMediaBundle:Media:upload/upload_list.html.twig', [ |
|
| 77 | 77 | 'params'=>$requestArray, |
| 78 | 78 | 'media'=>$event->getMedia(), |
| 79 | 79 | 'model'=>$model, |
| 80 | 80 | 'bundle'=>$bundle, |
| 81 | 81 | ]); |
| 82 | 82 | return JsonResponse($event->getMedia()); |
| 83 | - }else{ |
|
| 83 | + }else { |
|
| 84 | 84 | $response = new Response(); |
| 85 | 85 | $response->setContent(json_encode(array( |
| 86 | 86 | 'error'=>"Le format n'est pas valid" |
@@ -98,7 +98,7 @@ discard block |
||
| 98 | 98 | * @throws \Exception |
| 99 | 99 | * @return \Symfony\Component\HttpFoundation\Response |
| 100 | 100 | */ |
| 101 | - public function addAction( Request $request ) |
|
| 101 | + public function addAction(Request $request) |
|
| 102 | 102 | { |
| 103 | 103 | $requestArray = [ |
| 104 | 104 | 'file'=>$request->files, |
@@ -108,24 +108,24 @@ discard block |
||
| 108 | 108 | $bundle = $request->get('bundle'); |
| 109 | 109 | $model_id = $request->get('model_id'); |
| 110 | 110 | |
| 111 | - if( $request->isXmlHttpRequest() && $requestArray['file'] ) |
|
| 111 | + if ($request->isXmlHttpRequest() && $requestArray['file']) |
|
| 112 | 112 | { |
| 113 | 113 | //Init Event |
| 114 | - $event = $this->initEvent($requestArray['file'],$model,$model_id); |
|
| 114 | + $event = $this->initEvent($requestArray['file'], $model, $model_id); |
|
| 115 | 115 | |
| 116 | - if($event->getMedia()) |
|
| 116 | + if ($event->getMedia()) |
|
| 117 | 117 | { |
| 118 | 118 | $requestArray['entity'] = $this->getManage()->getRepository("$bundle:$model")->find($model_id); |
| 119 | 119 | |
| 120 | 120 | |
| 121 | - return $this->render('MykeesMediaBundle:Media:upload/upload_list.html.twig',[ |
|
| 121 | + return $this->render('MykeesMediaBundle:Media:upload/upload_list.html.twig', [ |
|
| 122 | 122 | 'params'=>$requestArray, |
| 123 | 123 | 'media'=>$event->getMedia(), |
| 124 | 124 | 'model'=>$model, |
| 125 | 125 | 'bundle'=>$bundle, |
| 126 | 126 | 'model_id'=>$model_id |
| 127 | 127 | ]); |
| 128 | - }else{ |
|
| 128 | + }else { |
|
| 129 | 129 | $response = new Response(); |
| 130 | 130 | $response->setContent(json_encode(array( |
| 131 | 131 | 'error'=>"Le format n'est pas valid" |
@@ -160,10 +160,10 @@ discard block |
||
| 160 | 160 | * @param Request $request |
| 161 | 161 | * @return \Symfony\Component\HttpFoundation\RedirectResponse |
| 162 | 162 | */ |
| 163 | - public function thumbAction( $model, $bundle, $model_id, $id, Request $request ) |
|
| 163 | + public function thumbAction($model, $bundle, $model_id, $id, Request $request) |
|
| 164 | 164 | { |
| 165 | - $media = $this->getManage()->getRepository("MykeesMediaBundle:Media")->find($id); |
|
| 166 | - $entity = $this->getManage()->getRepository("$bundle:$model")->find($model_id); |
|
| 165 | + $media = $this->getManage()->getRepository("MykeesMediaBundle:Media")->find($id); |
|
| 166 | + $entity = $this->getManage()->getRepository("$bundle:$model")->find($model_id); |
|
| 167 | 167 | $entity->setThumb($media); |
| 168 | 168 | $this->getManage()->persist($entity); |
| 169 | 169 | $this->getManage()->flush(); |
@@ -178,16 +178,16 @@ discard block |
||
| 178 | 178 | * @param Request $request |
| 179 | 179 | * @return Response |
| 180 | 180 | */ |
| 181 | - public function showAction( $model=null, $id = null, Request $request ) |
|
| 181 | + public function showAction($model = null, $id = null, Request $request) |
|
| 182 | 182 | { |
| 183 | - if( !$id ) |
|
| 183 | + if (!$id) |
|
| 184 | 184 | { |
| 185 | 185 | $params = [ |
| 186 | 186 | 'class'=>$request->get('class'), |
| 187 | 187 | 'alt'=>$request->get('alt') |
| 188 | 188 | ]; |
| 189 | - $params['media'] = $this->getManage()->getRepository('MykeesMediaBundle:Media')->findOneBy(['name'=>$params['alt'],'model'=>$model]); |
|
| 190 | - }else{ |
|
| 189 | + $params['media'] = $this->getManage()->getRepository('MykeesMediaBundle:Media')->findOneBy(['name'=>$params['alt'], 'model'=>$model]); |
|
| 190 | + }else { |
|
| 191 | 191 | $params = [ |
| 192 | 192 | 'media'=>$this->getManage()->getRepository('MykeesMediaBundle:Media')->find($id), |
| 193 | 193 | 'class'=>null |
@@ -197,18 +197,18 @@ discard block |
||
| 197 | 197 | new MediaShowType(), |
| 198 | 198 | $params['media'], |
| 199 | 199 | [ |
| 200 | - 'action' => $this->generateUrl('mykees_media_show',['model'=>$model,'id'=>$id]), |
|
| 200 | + 'action' => $this->generateUrl('mykees_media_show', ['model'=>$model, 'id'=>$id]), |
|
| 201 | 201 | 'method' => 'POST', |
| 202 | 202 | ] |
| 203 | 203 | ); |
| 204 | - if($request->getMethod() == "POST") |
|
| 204 | + if ($request->getMethod() == "POST") |
|
| 205 | 205 | { |
| 206 | 206 | $media = $request->request->all(); |
| 207 | - return $this->render('MykeesMediaBundle:Media:tinymce.html.twig',['media'=>$media]); |
|
| 207 | + return $this->render('MykeesMediaBundle:Media:tinymce.html.twig', ['media'=>$media]); |
|
| 208 | 208 | } |
| 209 | 209 | |
| 210 | - return $this->render('MykeesMediaBundle:Media:show/show.html.twig',[ |
|
| 211 | - 'media'=>$params['media'],'form'=>$form->createView(),'class'=>$params['class'],"model"=>$model |
|
| 210 | + return $this->render('MykeesMediaBundle:Media:show/show.html.twig', [ |
|
| 211 | + 'media'=>$params['media'], 'form'=>$form->createView(), 'class'=>$params['class'], "model"=>$model |
|
| 212 | 212 | ]); |
| 213 | 213 | } |
| 214 | 214 | |
@@ -220,16 +220,16 @@ discard block |
||
| 220 | 220 | * @param $id |
| 221 | 221 | * @return Response |
| 222 | 222 | */ |
| 223 | - public function deleteAction( $model, $bundle, $id ) |
|
| 223 | + public function deleteAction($model, $bundle, $id) |
|
| 224 | 224 | { |
| 225 | - if( $id ) |
|
| 225 | + if ($id) |
|
| 226 | 226 | { |
| 227 | 227 | $media = $this->getManage()->getRepository('MykeesMediaBundle:Media')->find($id); |
| 228 | 228 | $media_manager = $this->get('mk.media.manager'); |
| 229 | - $media_manager->unlink($model,$media); |
|
| 229 | + $media_manager->unlink($model, $media); |
|
| 230 | 230 | |
| 231 | 231 | $model_referer = $this->getManage()->getRepository("$bundle:$model")->find($media->getMediableId()); |
| 232 | - if(method_exists($model_referer,'getThumb') && $model_referer->getThumb() !== null && $model_referer->getThumb()->getId() == $media->getId()) |
|
| 232 | + if (method_exists($model_referer, 'getThumb') && $model_referer->getThumb() !== null && $model_referer->getThumb()->getId() == $media->getId()) |
|
| 233 | 233 | { |
| 234 | 234 | $model_referer->setThumb(null); |
| 235 | 235 | } |
@@ -262,7 +262,7 @@ discard block |
||
| 262 | 262 | { |
| 263 | 263 | $params = [ |
| 264 | 264 | 'medias'=>$this->get('mk.media.manager')->findMediasByModel($model), |
| 265 | - 'url'=> ['model'=>$model,'bundle'=>$bundle] |
|
| 265 | + 'url'=> ['model'=>$model, 'bundle'=>$bundle] |
|
| 266 | 266 | ]; |
| 267 | 267 | $form = $this->createForm( |
| 268 | 268 | new MediaType(), |
@@ -273,7 +273,7 @@ discard block |
||
| 273 | 273 | ] |
| 274 | 274 | ); |
| 275 | 275 | |
| 276 | - return $this->render('MykeesMediaBundle:Media:basic-uploader.html.twig',[ |
|
| 276 | + return $this->render('MykeesMediaBundle:Media:basic-uploader.html.twig', [ |
|
| 277 | 277 | 'form'=>$form->createView(), |
| 278 | 278 | 'model'=>$model, |
| 279 | 279 | 'bundle'=> $bundle, |
@@ -80,7 +80,7 @@ discard block |
||
| 80 | 80 | 'bundle'=>$bundle, |
| 81 | 81 | ]); |
| 82 | 82 | return JsonResponse($event->getMedia()); |
| 83 | - }else{ |
|
| 83 | + } else{ |
|
| 84 | 84 | $response = new Response(); |
| 85 | 85 | $response->setContent(json_encode(array( |
| 86 | 86 | 'error'=>"Le format n'est pas valid" |
@@ -125,7 +125,7 @@ discard block |
||
| 125 | 125 | 'bundle'=>$bundle, |
| 126 | 126 | 'model_id'=>$model_id |
| 127 | 127 | ]); |
| 128 | - }else{ |
|
| 128 | + } else{ |
|
| 129 | 129 | $response = new Response(); |
| 130 | 130 | $response->setContent(json_encode(array( |
| 131 | 131 | 'error'=>"Le format n'est pas valid" |
@@ -187,7 +187,7 @@ discard block |
||
| 187 | 187 | 'alt'=>$request->get('alt') |
| 188 | 188 | ]; |
| 189 | 189 | $params['media'] = $this->getManage()->getRepository('MykeesMediaBundle:Media')->findOneBy(['name'=>$params['alt'],'model'=>$model]); |
| 190 | - }else{ |
|
| 190 | + } else{ |
|
| 191 | 191 | $params = [ |
| 192 | 192 | 'media'=>$this->getManage()->getRepository('MykeesMediaBundle:Media')->find($id), |
| 193 | 193 | 'class'=>null |
@@ -109,6 +109,9 @@ |
||
| 109 | 109 | return $this->em->getRepository('MykeesMediaBundle:Media')->queryForModelAndId($model,$model_id); |
| 110 | 110 | } |
| 111 | 111 | |
| 112 | + /** |
|
| 113 | + * @param string $model |
|
| 114 | + */ |
|
| 112 | 115 | public function unlink($model, Media $media) |
| 113 | 116 | { |
| 114 | 117 | $info = pathinfo($media->getFile()); |
@@ -20,7 +20,7 @@ discard block |
||
| 20 | 20 | public $rootDir; |
| 21 | 21 | public $resize_parameters; |
| 22 | 22 | |
| 23 | - public function __construct( ManagerRegistry $managerRegistry, $rootDir,$resize_parameters ) |
|
| 23 | + public function __construct(ManagerRegistry $managerRegistry, $rootDir, $resize_parameters) |
|
| 24 | 24 | { |
| 25 | 25 | $this->em = $managerRegistry->getManager(); |
| 26 | 26 | $this->rootDir = $rootDir; |
@@ -30,7 +30,7 @@ discard block |
||
| 30 | 30 | |
| 31 | 31 | public function webroot() |
| 32 | 32 | { |
| 33 | - return $this->rootDir . '/../web/img/'; |
|
| 33 | + return $this->rootDir.'/../web/img/'; |
|
| 34 | 34 | } |
| 35 | 35 | |
| 36 | 36 | /** |
@@ -52,7 +52,7 @@ discard block |
||
| 52 | 52 | $model_info = $this->getModelInfos($models); |
| 53 | 53 | $queryResult = $this->em->getRepository("MykeesMediaBundle:Media")->findForArrayModels($model_info); |
| 54 | 54 | |
| 55 | - return $this->refreshMediasArray($queryResult,$models); |
|
| 55 | + return $this->refreshMediasArray($queryResult, $models); |
|
| 56 | 56 | } |
| 57 | 57 | |
| 58 | 58 | /** |
@@ -73,9 +73,9 @@ discard block |
||
| 73 | 73 | $model = Reflection::getClassShortName($obj); |
| 74 | 74 | $model_id = $obj->getId(); |
| 75 | 75 | |
| 76 | - $queryResult = $this->em->getRepository('MykeesMediaBundle:Media')->findForModelAndId($model,$model_id); |
|
| 76 | + $queryResult = $this->em->getRepository('MykeesMediaBundle:Media')->findForModelAndId($model, $model_id); |
|
| 77 | 77 | |
| 78 | - return $this->refreshMedias($queryResult,$obj); |
|
| 78 | + return $this->refreshMedias($queryResult, $obj); |
|
| 79 | 79 | } |
| 80 | 80 | |
| 81 | 81 | /** |
@@ -85,7 +85,7 @@ discard block |
||
| 85 | 85 | */ |
| 86 | 86 | public function getQueryByModelAndId($model_name, $model_id) |
| 87 | 87 | { |
| 88 | - return $this->em->getRepository('MykeesMediaBundle:Media')->queryForModelAndId($model_name,$model_id); |
|
| 88 | + return $this->em->getRepository('MykeesMediaBundle:Media')->queryForModelAndId($model_name, $model_id); |
|
| 89 | 89 | } |
| 90 | 90 | |
| 91 | 91 | /** |
@@ -106,38 +106,38 @@ discard block |
||
| 106 | 106 | $model = Reflection::getClassShortName($obj); |
| 107 | 107 | $model_id = $obj->getId(); |
| 108 | 108 | |
| 109 | - return $this->em->getRepository('MykeesMediaBundle:Media')->queryForModelAndId($model,$model_id); |
|
| 109 | + return $this->em->getRepository('MykeesMediaBundle:Media')->queryForModelAndId($model, $model_id); |
|
| 110 | 110 | } |
| 111 | 111 | |
| 112 | 112 | public function unlink($model, Media $media) |
| 113 | 113 | { |
| 114 | - $info = pathinfo($media->getFile()); |
|
| 114 | + $info = pathinfo($media->getFile()); |
|
| 115 | 115 | |
| 116 | - $this->removeSizes($model,$info); |
|
| 116 | + $this->removeSizes($model, $info); |
|
| 117 | 117 | |
| 118 | - if(file_exists($this->webroot() . $media->getFile())) |
|
| 118 | + if (file_exists($this->webroot().$media->getFile())) |
|
| 119 | 119 | { |
| 120 | - return unlink($this->webroot() . $media->getFile()); |
|
| 120 | + return unlink($this->webroot().$media->getFile()); |
|
| 121 | 121 | } |
| 122 | 122 | |
| 123 | 123 | return false; |
| 124 | 124 | } |
| 125 | 125 | |
| 126 | - public function removeSizes($model,$info) |
|
| 126 | + public function removeSizes($model, $info) |
|
| 127 | 127 | { |
| 128 | - if(!empty($this->resize_parameters[$model])) |
|
| 128 | + if (!empty($this->resize_parameters[$model])) |
|
| 129 | 129 | { |
| 130 | - if(!empty($this->resize_parameters[$model]['size'])) |
|
| 130 | + if (!empty($this->resize_parameters[$model]['size'])) |
|
| 131 | 131 | { |
| 132 | 132 | $sizes = $this->resize_parameters[$model]['size']; |
| 133 | 133 | |
| 134 | - foreach($sizes as $k=>$size) |
|
| 134 | + foreach ($sizes as $k=>$size) |
|
| 135 | 135 | { |
| 136 | 136 | $w = $size['width']; |
| 137 | 137 | $h = $size['height']; |
| 138 | - $resizedFile = $this->webroot() . $info['dirname'] . '/' . $info['filename'] . "_$w" . "x$h" . '.jpg'; |
|
| 138 | + $resizedFile = $this->webroot().$info['dirname'].'/'.$info['filename']."_$w"."x$h".'.jpg'; |
|
| 139 | 139 | |
| 140 | - if(file_exists($resizedFile)) |
|
| 140 | + if (file_exists($resizedFile)) |
|
| 141 | 141 | { |
| 142 | 142 | unlink($resizedFile); |
| 143 | 143 | } |
@@ -160,12 +160,12 @@ discard block |
||
| 160 | 160 | /** |
| 161 | 161 | * @param Mediable $model |
| 162 | 162 | */ |
| 163 | - public function removeAllMediasForModel( Mediable $model ) |
|
| 163 | + public function removeAllMediasForModel(Mediable $model) |
|
| 164 | 164 | { |
| 165 | 165 | $model_name = Reflection::getClassShortName($model); |
| 166 | 166 | $model_id = $model->getId(); |
| 167 | 167 | |
| 168 | - if(method_exists($model,'getThumb') && $model->getThumb() !== null) |
|
| 168 | + if (method_exists($model, 'getThumb') && $model->getThumb() !== null) |
|
| 169 | 169 | { |
| 170 | 170 | $model->setThumb(null); |
| 171 | 171 | } |
@@ -173,7 +173,7 @@ discard block |
||
| 173 | 173 | 'model'=>$model_name, |
| 174 | 174 | 'modelId'=>$model_id |
| 175 | 175 | ]); |
| 176 | - foreach($medias as $k=>$media) |
|
| 176 | + foreach ($medias as $k=>$media) |
|
| 177 | 177 | { |
| 178 | 178 | $this->unlink($model_name, $media); |
| 179 | 179 | $this->remove($media); |
@@ -183,6 +183,6 @@ discard block |
||
| 183 | 183 | /** |
| 184 | 184 | * Remodel ALL Medias |
| 185 | 185 | */ |
| 186 | - public function removeAll(){} |
|
| 186 | + public function removeAll() {} |
|
| 187 | 187 | |
| 188 | 188 | } |
@@ -1,10 +1,10 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | - * Created by PhpStorm. |
|
| 4 | - * User: Rafidion Michael |
|
| 5 | - * Date: 30/11/2014 |
|
| 6 | - * Time: 03:40 |
|
| 7 | - */ |
|
| 3 | + * Created by PhpStorm. |
|
| 4 | + * User: Rafidion Michael |
|
| 5 | + * Date: 30/11/2014 |
|
| 6 | + * Time: 03:40 |
|
| 7 | + */ |
|
| 8 | 8 | |
| 9 | 9 | namespace Mykees\MediaBundle\Manager; |
| 10 | 10 | |
@@ -146,10 +146,10 @@ discard block |
||
| 146 | 146 | } |
| 147 | 147 | } |
| 148 | 148 | |
| 149 | - /** |
|
| 150 | - * @param Media $media |
|
| 151 | - * @return bool |
|
| 152 | - */ |
|
| 149 | + /** |
|
| 150 | + * @param Media $media |
|
| 151 | + * @return bool |
|
| 152 | + */ |
|
| 153 | 153 | public function remove(Media $media) |
| 154 | 154 | { |
| 155 | 155 | $this->em->remove($media); |
@@ -157,9 +157,9 @@ discard block |
||
| 157 | 157 | return true; |
| 158 | 158 | } |
| 159 | 159 | |
| 160 | - /** |
|
| 161 | - * @param Mediable $model |
|
| 162 | - */ |
|
| 160 | + /** |
|
| 161 | + * @param Mediable $model |
|
| 162 | + */ |
|
| 163 | 163 | public function removeAllMediasForModel( Mediable $model ) |
| 164 | 164 | { |
| 165 | 165 | $model_name = Reflection::getClassShortName($model); |
@@ -232,6 +232,7 @@ |
||
| 232 | 232 | * Note: this function has been modified to simple return true or false |
| 233 | 233 | * @author <[email protected]> |
| 234 | 234 | * @param string UTF-8 encoded string |
| 235 | + * @param string $str |
|
| 235 | 236 | * @return boolean true if valid |
| 236 | 237 | * @see http://hsivonen.iki.fi/php-utf8/ |
| 237 | 238 | */ |
@@ -227,18 +227,18 @@ discard block |
||
| 227 | 227 | } |
| 228 | 228 | |
| 229 | 229 | /** |
| 230 | - * Tests a string as to whether it's valid UTF-8 and supported by the |
|
| 231 | - * Unicode standard |
|
| 232 | - * Note: this function has been modified to simple return true or false |
|
| 233 | - * @author <[email protected]> |
|
| 234 | - * @param string UTF-8 encoded string |
|
| 235 | - * @return boolean true if valid |
|
| 236 | - * @see http://hsivonen.iki.fi/php-utf8/ |
|
| 237 | - */ |
|
| 230 | + * Tests a string as to whether it's valid UTF-8 and supported by the |
|
| 231 | + * Unicode standard |
|
| 232 | + * Note: this function has been modified to simple return true or false |
|
| 233 | + * @author <[email protected]> |
|
| 234 | + * @param string UTF-8 encoded string |
|
| 235 | + * @return boolean true if valid |
|
| 236 | + * @see http://hsivonen.iki.fi/php-utf8/ |
|
| 237 | + */ |
|
| 238 | 238 | public static function validUtf8($str) |
| 239 | 239 | { |
| 240 | 240 | $mState = 0; // cached expected number of octets after the current octet |
| 241 | - // until the beginning of the next UTF8 character sequence |
|
| 241 | + // until the beginning of the next UTF8 character sequence |
|
| 242 | 242 | $mUcs4 = 0; // cached Unicode character |
| 243 | 243 | $mBytes = 1; // cached expected number of octets in the current sequence |
| 244 | 244 | |
@@ -304,9 +304,9 @@ discard block |
||
| 304 | 304 | $tmp = ($tmp & 0x0000003F) << $shift; |
| 305 | 305 | $mUcs4 |= $tmp; |
| 306 | 306 | /** |
| 307 | - * End of the multi-octet sequence. mUcs4 now contains the final |
|
| 308 | - * Unicode codepoint to be output |
|
| 309 | - */ |
|
| 307 | + * End of the multi-octet sequence. mUcs4 now contains the final |
|
| 308 | + * Unicode codepoint to be output |
|
| 309 | + */ |
|
| 310 | 310 | if (0 == --$mState) { |
| 311 | 311 | /* |
| 312 | 312 | * Check for illegal sequences and codepoints. |
@@ -330,9 +330,9 @@ discard block |
||
| 330 | 330 | } |
| 331 | 331 | } else { |
| 332 | 332 | /** |
| 333 | - *((0xC0 & (*in) != 0x80) && (mState != 0)) |
|
| 334 | - * Incomplete multi-octet sequence. |
|
| 335 | - */ |
|
| 333 | + *((0xC0 & (*in) != 0x80) && (mState != 0)) |
|
| 334 | + * Incomplete multi-octet sequence. |
|
| 335 | + */ |
|
| 336 | 336 | return false; |
| 337 | 337 | } |
| 338 | 338 | } |
@@ -360,9 +360,9 @@ discard block |
||
| 360 | 360 | |
| 361 | 361 | // More stripping. Replace spaces with dashes |
| 362 | 362 | $text = strtolower(preg_replace('/[^A-Z^a-z^0-9^\/]+/', $separator, |
| 363 | - preg_replace('/([a-z\d])([A-Z])/', '\1_\2', |
|
| 364 | - preg_replace('/([A-Z]+)([A-Z][a-z])/', '\1_\2', |
|
| 365 | - preg_replace('/::/', '/', $text))))); |
|
| 363 | + preg_replace('/([a-z\d])([A-Z])/', '\1_\2', |
|
| 364 | + preg_replace('/([A-Z]+)([A-Z][a-z])/', '\1_\2', |
|
| 365 | + preg_replace('/::/', '/', $text))))); |
|
| 366 | 366 | |
| 367 | 367 | return trim($text, $separator); |
| 368 | 368 | } |
@@ -40,13 +40,13 @@ discard block |
||
| 40 | 40 | $stringLength = strlen($string); |
| 41 | 41 | for ($i = 0; $i < $stringLength; $i++) { |
| 42 | 42 | if (ord($string[$i]) < 0x80) continue; # 0bbbbbbb |
| 43 | - elseif ((ord($string[$i]) & 0xE0) == 0xC0) $n=1; # 110bbbbb |
|
| 44 | - elseif ((ord($string[$i]) & 0xF0) == 0xE0) $n=2; # 1110bbbb |
|
| 45 | - elseif ((ord($string[$i]) & 0xF8) == 0xF0) $n=3; # 11110bbb |
|
| 46 | - elseif ((ord($string[$i]) & 0xFC) == 0xF8) $n=4; # 111110bb |
|
| 47 | - elseif ((ord($string[$i]) & 0xFE) == 0xFC) $n=5; # 1111110b |
|
| 43 | + elseif ((ord($string[$i]) & 0xE0) == 0xC0) $n = 1; # 110bbbbb |
|
| 44 | + elseif ((ord($string[$i]) & 0xF0) == 0xE0) $n = 2; # 1110bbbb |
|
| 45 | + elseif ((ord($string[$i]) & 0xF8) == 0xF0) $n = 3; # 11110bbb |
|
| 46 | + elseif ((ord($string[$i]) & 0xFC) == 0xF8) $n = 4; # 111110bb |
|
| 47 | + elseif ((ord($string[$i]) & 0xFE) == 0xFC) $n = 5; # 1111110b |
|
| 48 | 48 | else return false; # Does not match any model |
| 49 | - for ($j=0; $j<$n; $j++) { # n bytes matching 10bbbbbb follow ? |
|
| 49 | + for ($j = 0; $j < $n; $j++) { # n bytes matching 10bbbbbb follow ? |
|
| 50 | 50 | if ((++$i == strlen($string)) || ((ord($string[$i]) & 0xC0) != 0x80)) |
| 51 | 51 | return false; |
| 52 | 52 | } |
@@ -123,7 +123,7 @@ discard block |
||
| 123 | 123 | chr(196).chr(172) => 'I', chr(196).chr(173) => 'i', |
| 124 | 124 | chr(196).chr(174) => 'I', chr(196).chr(175) => 'i', |
| 125 | 125 | chr(196).chr(176) => 'I', chr(196).chr(177) => 'i', |
| 126 | - chr(196).chr(178) => 'IJ',chr(196).chr(179) => 'ij', |
|
| 126 | + chr(196).chr(178) => 'IJ', chr(196).chr(179) => 'ij', |
|
| 127 | 127 | chr(196).chr(180) => 'J', chr(196).chr(181) => 'j', |
| 128 | 128 | chr(196).chr(182) => 'K', chr(196).chr(183) => 'k', |
| 129 | 129 | chr(196).chr(184) => 'k', chr(196).chr(185) => 'L', |
@@ -139,7 +139,7 @@ discard block |
||
| 139 | 139 | chr(197).chr(140) => 'O', chr(197).chr(141) => 'o', |
| 140 | 140 | chr(197).chr(142) => 'O', chr(197).chr(143) => 'o', |
| 141 | 141 | chr(197).chr(144) => 'O', chr(197).chr(145) => 'o', |
| 142 | - chr(197).chr(146) => 'OE',chr(197).chr(147) => 'oe', |
|
| 142 | + chr(197).chr(146) => 'OE', chr(197).chr(147) => 'oe', |
|
| 143 | 143 | chr(197).chr(148) => 'R', chr(197).chr(149) => 'r', |
| 144 | 144 | chr(197).chr(150) => 'R', chr(197).chr(151) => 'r', |
| 145 | 145 | chr(197).chr(152) => 'R', chr(197).chr(153) => 'r', |
@@ -169,11 +169,11 @@ discard block |
||
| 169 | 169 | 'Ä' => 'Ae', 'ä' => 'ae', 'Ü' => 'Ue', 'ü' => 'ue', |
| 170 | 170 | 'Ö' => 'Oe', 'ö' => 'oe', 'ß' => 'ss', |
| 171 | 171 | // Norwegian characters |
| 172 | - 'Å'=>'Aa','Æ'=>'Ae','Ø'=>'O','æ'=>'a','ø'=>'o','å'=>'aa' |
|
| 172 | + 'Å'=>'Aa', 'Æ'=>'Ae', 'Ø'=>'O', 'æ'=>'a', 'ø'=>'o', 'å'=>'aa' |
|
| 173 | 173 | ); |
| 174 | 174 | |
| 175 | 175 | $string = strtr($string, $chars); |
| 176 | - } else { |
|
| 176 | + }else { |
|
| 177 | 177 | // Assume ISO-8859-1 if not UTF-8 |
| 178 | 178 | $chars['in'] = chr(128).chr(131).chr(138).chr(142).chr(154).chr(158) |
| 179 | 179 | .chr(159).chr(162).chr(165).chr(181).chr(192).chr(193).chr(194) |
@@ -237,10 +237,10 @@ discard block |
||
| 237 | 237 | */ |
| 238 | 238 | public static function validUtf8($str) |
| 239 | 239 | { |
| 240 | - $mState = 0; // cached expected number of octets after the current octet |
|
| 240 | + $mState = 0; // cached expected number of octets after the current octet |
|
| 241 | 241 | // until the beginning of the next UTF8 character sequence |
| 242 | - $mUcs4 = 0; // cached Unicode character |
|
| 243 | - $mBytes = 1; // cached expected number of octets in the current sequence |
|
| 242 | + $mUcs4 = 0; // cached Unicode character |
|
| 243 | + $mBytes = 1; // cached expected number of octets in the current sequence |
|
| 244 | 244 | |
| 245 | 245 | $len = strlen($str); |
| 246 | 246 | for ($i = 0; $i < $len; $i++) { |
@@ -288,13 +288,13 @@ discard block |
||
| 288 | 288 | $mUcs4 = ($mUcs4 & 1) << 30; |
| 289 | 289 | $mState = 5; |
| 290 | 290 | $mBytes = 6; |
| 291 | - } else { |
|
| 291 | + }else { |
|
| 292 | 292 | /* Current octet is neither in the US-ASCII range nor a legal first |
| 293 | 293 | * octet of a multi-octet sequence. |
| 294 | 294 | */ |
| 295 | 295 | return false; |
| 296 | 296 | } |
| 297 | - } else { |
|
| 297 | + }else { |
|
| 298 | 298 | // When mState is non-zero, we expect a continuation of the multi-octet |
| 299 | 299 | // sequence |
| 300 | 300 | if (0x80 == (0xC0 & ($in))) { |
@@ -328,7 +328,7 @@ discard block |
||
| 328 | 328 | $mUcs4 = 0; |
| 329 | 329 | $mBytes = 1; |
| 330 | 330 | } |
| 331 | - } else { |
|
| 331 | + }else { |
|
| 332 | 332 | /** |
| 333 | 333 | *((0xC0 & (*in) != 0x80) && (mState != 0)) |
| 334 | 334 | * Incomplete multi-octet sequence. |
@@ -351,7 +351,7 @@ discard block |
||
| 351 | 351 | { |
| 352 | 352 | if (function_exists('mb_strtolower')) { |
| 353 | 353 | $text = mb_strtolower($text); |
| 354 | - } else { |
|
| 354 | + }else { |
|
| 355 | 355 | $text = strtolower($text); |
| 356 | 356 | } |
| 357 | 357 | |
@@ -39,17 +39,39 @@ |
||
| 39 | 39 | { |
| 40 | 40 | $stringLength = strlen($string); |
| 41 | 41 | for ($i = 0; $i < $stringLength; $i++) { |
| 42 | - if (ord($string[$i]) < 0x80) continue; # 0bbbbbbb |
|
| 43 | - elseif ((ord($string[$i]) & 0xE0) == 0xC0) $n=1; # 110bbbbb |
|
| 44 | - elseif ((ord($string[$i]) & 0xF0) == 0xE0) $n=2; # 1110bbbb |
|
| 45 | - elseif ((ord($string[$i]) & 0xF8) == 0xF0) $n=3; # 11110bbb |
|
| 46 | - elseif ((ord($string[$i]) & 0xFC) == 0xF8) $n=4; # 111110bb |
|
| 47 | - elseif ((ord($string[$i]) & 0xFE) == 0xFC) $n=5; # 1111110b |
|
| 48 | - else return false; # Does not match any model |
|
| 49 | - for ($j=0; $j<$n; $j++) { # n bytes matching 10bbbbbb follow ? |
|
| 50 | - if ((++$i == strlen($string)) || ((ord($string[$i]) & 0xC0) != 0x80)) |
|
| 42 | + if (ord($string[$i]) < 0x80) { |
|
| 43 | + continue; |
|
| 44 | + } |
|
| 45 | + # 0bbbbbbb |
|
| 46 | + elseif ((ord($string[$i]) & 0xE0) == 0xC0) { |
|
| 47 | + $n=1; |
|
| 48 | + } |
|
| 49 | + # 110bbbbb |
|
| 50 | + elseif ((ord($string[$i]) & 0xF0) == 0xE0) { |
|
| 51 | + $n=2; |
|
| 52 | + } |
|
| 53 | + # 1110bbbb |
|
| 54 | + elseif ((ord($string[$i]) & 0xF8) == 0xF0) { |
|
| 55 | + $n=3; |
|
| 56 | + } |
|
| 57 | + # 11110bbb |
|
| 58 | + elseif ((ord($string[$i]) & 0xFC) == 0xF8) { |
|
| 59 | + $n=4; |
|
| 60 | + } |
|
| 61 | + # 111110bb |
|
| 62 | + elseif ((ord($string[$i]) & 0xFE) == 0xFC) { |
|
| 63 | + $n=5; |
|
| 64 | + } |
|
| 65 | + # 1111110b |
|
| 66 | + else { |
|
| 51 | 67 | return false; |
| 52 | 68 | } |
| 69 | + # Does not match any model |
|
| 70 | + for ($j=0; $j<$n; $j++) { # n bytes matching 10bbbbbb follow ? |
|
| 71 | + if ((++$i == strlen($string)) || ((ord($string[$i]) & 0xC0) != 0x80)) { |
|
| 72 | + return false; |
|
| 73 | + } |
|
| 74 | + } |
|
| 53 | 75 | } |
| 54 | 76 | return true; |
| 55 | 77 | } |
@@ -1,10 +1,10 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | - * Created by PhpStorm. |
|
| 4 | - * User: Rafidion Michael |
|
| 5 | - * Date: 30/11/2014 |
|
| 6 | - * Time: 18:21 |
|
| 7 | - */ |
|
| 3 | + * Created by PhpStorm. |
|
| 4 | + * User: Rafidion Michael |
|
| 5 | + * Date: 30/11/2014 |
|
| 6 | + * Time: 18:21 |
|
| 7 | + */ |
|
| 8 | 8 | |
| 9 | 9 | namespace Mykees\MediaBundle\Event; |
| 10 | 10 | |
@@ -1,10 +1,10 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | - * Created by PhpStorm. |
|
| 4 | - * User: Rafidion Michael |
|
| 5 | - * Date: 18/11/2014 |
|
| 6 | - * Time: 01:22 |
|
| 7 | - */ |
|
| 3 | + * Created by PhpStorm. |
|
| 4 | + * User: Rafidion Michael |
|
| 5 | + * Date: 18/11/2014 |
|
| 6 | + * Time: 01:22 |
|
| 7 | + */ |
|
| 8 | 8 | |
| 9 | 9 | namespace Mykees\MediaBundle\Form\Type; |
| 10 | 10 | |
@@ -21,10 +21,10 @@ |
||
| 21 | 21 | public function buildForm(FormBuilderInterface $builder, array $options) |
| 22 | 22 | { |
| 23 | 23 | $builder |
| 24 | - ->add('name','text',[ |
|
| 24 | + ->add('name', 'text', [ |
|
| 25 | 25 | "label"=>"Nom de l'image" |
| 26 | 26 | ]) |
| 27 | - ->add('file','text',[ |
|
| 27 | + ->add('file', 'text', [ |
|
| 28 | 28 | "label"=>"Chemin de l'image" |
| 29 | 29 | ]) |
| 30 | 30 | ; |
@@ -15,7 +15,7 @@ |
||
| 15 | 15 | public function buildForm(FormBuilderInterface $builder, array $options) |
| 16 | 16 | { |
| 17 | 17 | $builder |
| 18 | - ->add('fileData','file') |
|
| 18 | + ->add('fileData', 'file') |
|
| 19 | 19 | ; |
| 20 | 20 | } |
| 21 | 21 | |
@@ -1,10 +1,10 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | - * Created by PhpStorm. |
|
| 4 | - * User: tetsu0o |
|
| 5 | - * Date: 29/12/14 |
|
| 6 | - * Time: 02:03 |
|
| 7 | - */ |
|
| 3 | + * Created by PhpStorm. |
|
| 4 | + * User: tetsu0o |
|
| 5 | + * Date: 29/12/14 |
|
| 6 | + * Time: 02:03 |
|
| 7 | + */ |
|
| 8 | 8 | |
| 9 | 9 | namespace Mykees\MediaBundle\Helper; |
| 10 | 10 | |
@@ -26,9 +26,9 @@ discard block |
||
| 26 | 26 | |
| 27 | 27 | public function resize($image) |
| 28 | 28 | { |
| 29 | - $absolute_path = $this->webroot . $image; |
|
| 29 | + $absolute_path = $this->webroot.$image; |
|
| 30 | 30 | $absolute_info = pathinfo($absolute_path); |
| 31 | - $allowedExtension = ['jpg','JPG','jpeg',"JPEG",'png','PNG','gif','GIF']; |
|
| 31 | + $allowedExtension = ['jpg', 'JPG', 'jpeg', "JPEG", 'png', 'PNG', 'gif', 'GIF']; |
|
| 32 | 32 | $extension = pathinfo($image); |
| 33 | 33 | $extension = $extension['extension']; |
| 34 | 34 | |
@@ -46,7 +46,7 @@ discard block |
||
| 46 | 46 | $imagine = new \Imagine\Gd\Imagine(); |
| 47 | 47 | $mode = $this->options['mode']; |
| 48 | 48 | |
| 49 | - $imagine->open($absolute_info['dirname'] . '/' . $absolute_info['filename'] . '.'.$extension) |
|
| 49 | + $imagine->open($absolute_info['dirname'].'/'.$absolute_info['filename'].'.'.$extension) |
|
| 50 | 50 | ->thumbnail( |
| 51 | 51 | new \Imagine\Image\Box($width, $height), |
| 52 | 52 | !empty($mode) && |
@@ -23,11 +23,11 @@ discard block |
||
| 23 | 23 | { |
| 24 | 24 | $query = $this->_em->createQueryBuilder() |
| 25 | 25 | ->select('m') |
| 26 | - ->from($this->_entityName,'m') |
|
| 26 | + ->from($this->_entityName, 'm') |
|
| 27 | 27 | ->where('m.model = :model') |
| 28 | 28 | ->andWhere('m.modelId = :modelId') |
| 29 | - ->setParameter('model',$model) |
|
| 30 | - ->setParameter('modelId',$model_id) |
|
| 29 | + ->setParameter('model', $model) |
|
| 30 | + ->setParameter('modelId', $model_id) |
|
| 31 | 31 | ->getQuery() |
| 32 | 32 | ; |
| 33 | 33 | return $query; |
@@ -42,9 +42,9 @@ discard block |
||
| 42 | 42 | { |
| 43 | 43 | $query = $this->_em->createQueryBuilder() |
| 44 | 44 | ->select('m') |
| 45 | - ->from($this->_entityName,'m') |
|
| 45 | + ->from($this->_entityName, 'm') |
|
| 46 | 46 | ->where('m.model = :model') |
| 47 | - ->setParameter('model',$model) |
|
| 47 | + ->setParameter('model', $model) |
|
| 48 | 48 | ->getQuery() |
| 49 | 49 | ; |
| 50 | 50 | return $query; |
@@ -59,11 +59,11 @@ discard block |
||
| 59 | 59 | { |
| 60 | 60 | $query = $this->_em->createQueryBuilder() |
| 61 | 61 | ->select('m') |
| 62 | - ->from($this->_entityName,'m') |
|
| 62 | + ->from($this->_entityName, 'm') |
|
| 63 | 63 | ->where('m.model IN(:model)') |
| 64 | 64 | ->andWhere('m.modelId IN(:modelId)') |
| 65 | - ->setParameter('model',array_values($model_info['models'])) |
|
| 66 | - ->setParameter('modelId',array_values($model_info['ids'])) |
|
| 65 | + ->setParameter('model', array_values($model_info['models'])) |
|
| 66 | + ->setParameter('modelId', array_values($model_info['ids'])) |
|
| 67 | 67 | ->getQuery() |
| 68 | 68 | ; |
| 69 | 69 | return $query; |
@@ -74,7 +74,7 @@ discard block |
||
| 74 | 74 | * @param array $model_info |
| 75 | 75 | * @return array |
| 76 | 76 | */ |
| 77 | - public function findForArrayModels(array $model_info){ |
|
| 77 | + public function findForArrayModels(array $model_info) { |
|
| 78 | 78 | return $this->queryForArray($model_info) |
| 79 | 79 | ->getResult(); |
| 80 | 80 | } |
@@ -1,10 +1,10 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | - * Created by PhpStorm. |
|
| 4 | - * User: tetsu0o |
|
| 5 | - * Date: 30/12/14 |
|
| 6 | - * Time: 02:47 |
|
| 7 | - */ |
|
| 3 | + * Created by PhpStorm. |
|
| 4 | + * User: tetsu0o |
|
| 5 | + * Date: 30/12/14 |
|
| 6 | + * Time: 02:47 |
|
| 7 | + */ |
|
| 8 | 8 | |
| 9 | 9 | namespace Mykees\MediaBundle\Twig\Extension; |
| 10 | 10 | |
@@ -27,12 +27,12 @@ discard block |
||
| 27 | 27 | ]; |
| 28 | 28 | } |
| 29 | 29 | |
| 30 | - public function getImage($image, $width, $height, $options=[]) |
|
| 30 | + public function getImage($image, $width, $height, $options = []) |
|
| 31 | 31 | { |
| 32 | 32 | $attr = false; |
| 33 | - foreach($options as $k=>$opt) |
|
| 33 | + foreach ($options as $k=>$opt) |
|
| 34 | 34 | { |
| 35 | - if( $k > 1 ){ |
|
| 35 | + if ($k > 1) { |
|
| 36 | 36 | $attr .= ' '; |
| 37 | 37 | } |
| 38 | 38 | $attr .= $k.'="'.$opt.'"'; |
@@ -40,13 +40,13 @@ discard block |
||
| 40 | 40 | |
| 41 | 41 | $webroot = $this->rootDir.'/../web/'; |
| 42 | 42 | $info = pathinfo($image); |
| 43 | - $imageResize = $info['dirname'] . '/' . $info['filename'] . "_$width" . "x$height" . '.jpg'; |
|
| 44 | - $fullPathImageResize = $webroot . $imageResize; |
|
| 43 | + $imageResize = $info['dirname'].'/'.$info['filename']."_$width"."x$height".'.jpg'; |
|
| 44 | + $fullPathImageResize = $webroot.$imageResize; |
|
| 45 | 45 | |
| 46 | - if(file_exists($fullPathImageResize)) |
|
| 46 | + if (file_exists($fullPathImageResize)) |
|
| 47 | 47 | { |
| 48 | - return '<img src="'. $imageResize .'" '. $attr .'>'; |
|
| 49 | - } else { |
|
| 48 | + return '<img src="'.$imageResize.'" '.$attr.'>'; |
|
| 49 | + }else { |
|
| 50 | 50 | return false; |
| 51 | 51 | } |
| 52 | 52 | |