@@ -14,16 +14,16 @@ |
||
| 14 | 14 | |
| 15 | 15 | protected $medias; |
| 16 | 16 | |
| 17 | - public function getMediableModel(){ |
|
| 17 | + public function getMediableModel() { |
|
| 18 | 18 | return Reflection::getClassShortName($this); |
| 19 | 19 | } |
| 20 | 20 | |
| 21 | - public function getMediableId(){ |
|
| 21 | + public function getMediableId() { |
|
| 22 | 22 | return $this->getId(); |
| 23 | 23 | } |
| 24 | 24 | |
| 25 | - public function getMedias(){ |
|
| 26 | - $this->medias = $this->medias ? : new ArrayCollection(); |
|
| 25 | + public function getMedias() { |
|
| 26 | + $this->medias = $this->medias ?: new ArrayCollection(); |
|
| 27 | 27 | return $this->medias; |
| 28 | 28 | } |
| 29 | 29 | } |
@@ -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 | |
@@ -19,25 +19,25 @@ |
||
| 19 | 19 | } |
| 20 | 20 | |
| 21 | 21 | |
| 22 | - public static function getClassShortName ( $model ) { |
|
| 23 | - $reflection = new \ReflectionClass( $model ); |
|
| 22 | + public static function getClassShortName($model) { |
|
| 23 | + $reflection = new \ReflectionClass($model); |
|
| 24 | 24 | return $reflection->getShortName(); |
| 25 | 25 | } |
| 26 | 26 | |
| 27 | 27 | |
| 28 | - public static function getBundlePath ( $model ){ |
|
| 29 | - $explode = explode('\\', self::getClassName($model )); |
|
| 28 | + public static function getBundlePath($model) { |
|
| 29 | + $explode = explode('\\', self::getClassName($model)); |
|
| 30 | 30 | return $explode[0].'\\'.$explode[1].'\\'.$explode[2].'\\'.$explode[3]; |
| 31 | 31 | } |
| 32 | 32 | |
| 33 | 33 | |
| 34 | - public static function getBundleRepository ( $model ){ |
|
| 35 | - $explode = explode('\\', self::getClassName($model )); |
|
| 34 | + public static function getBundleRepository($model) { |
|
| 35 | + $explode = explode('\\', self::getClassName($model)); |
|
| 36 | 36 | return $explode[0].$explode[1].':'.$explode[3]; |
| 37 | 37 | } |
| 38 | 38 | |
| 39 | - public static function getShortBundleRepository ( $model ){ |
|
| 40 | - $explode = explode('\\', self::getClassName($model )); |
|
| 39 | + public static function getShortBundleRepository($model) { |
|
| 40 | + $explode = explode('\\', self::getClassName($model)); |
|
| 41 | 41 | return $explode[0].$explode[1]; |
| 42 | 42 | } |
| 43 | 43 | |
@@ -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 | } |
@@ -16,35 +16,35 @@ discard block |
||
| 16 | 16 | |
| 17 | 17 | public function getModelInfos(array $datas) |
| 18 | 18 | { |
| 19 | - $ids= []; |
|
| 19 | + $ids = []; |
|
| 20 | 20 | $models = []; |
| 21 | 21 | $model_exist = false; |
| 22 | 22 | |
| 23 | - foreach( $datas as $k=>$data ) |
|
| 23 | + foreach ($datas as $k=>$data) |
|
| 24 | 24 | { |
| 25 | - if($data instanceof Mediable) |
|
| 25 | + if ($data instanceof Mediable) |
|
| 26 | 26 | { |
| 27 | - array_push($ids,$data->getMediableId()); |
|
| 28 | - if( $model_exist != $data->getMediableModel() ) |
|
| 27 | + array_push($ids, $data->getMediableId()); |
|
| 28 | + if ($model_exist != $data->getMediableModel()) |
|
| 29 | 29 | { |
| 30 | - array_push($models,$data->getMediableModel()); |
|
| 30 | + array_push($models, $data->getMediableModel()); |
|
| 31 | 31 | $model_exist = $data->getMediableModel(); |
| 32 | 32 | } |
| 33 | 33 | } |
| 34 | 34 | } |
| 35 | 35 | |
| 36 | - return [ 'ids'=>$ids, 'models'=>$models ]; |
|
| 36 | + return ['ids'=>$ids, 'models'=>$models]; |
|
| 37 | 37 | } |
| 38 | 38 | |
| 39 | 39 | public function refreshMediasArray(array $medias, array $models) |
| 40 | 40 | { |
| 41 | 41 | $this->clean($models); |
| 42 | - foreach($models as $model) |
|
| 42 | + foreach ($models as $model) |
|
| 43 | 43 | { |
| 44 | - foreach($medias as $media){ |
|
| 45 | - if($model instanceof Mediable) |
|
| 44 | + foreach ($medias as $media) { |
|
| 45 | + if ($model instanceof Mediable) |
|
| 46 | 46 | { |
| 47 | - if($model->getId() == $media->getMediableId() && $model->getMediableModel() == $media->getMediableModel()) |
|
| 47 | + if ($model->getId() == $media->getMediableId() && $model->getMediableModel() == $media->getMediableModel()) |
|
| 48 | 48 | { |
| 49 | 49 | $model->getMedias()->add($media); |
| 50 | 50 | } |
@@ -60,9 +60,9 @@ discard block |
||
| 60 | 60 | |
| 61 | 61 | public function addMedias(array $medias, Mediable $model) |
| 62 | 62 | { |
| 63 | - foreach($medias as $media){ |
|
| 64 | - if(!empty($media) && Reflection::getClassShortName($media) == 'Media'){ |
|
| 65 | - $this->addMedia($media,$model); |
|
| 63 | + foreach ($medias as $media) { |
|
| 64 | + if (!empty($media) && Reflection::getClassShortName($media) == 'Media') { |
|
| 65 | + $this->addMedia($media, $model); |
|
| 66 | 66 | } |
| 67 | 67 | } |
| 68 | 68 | } |
@@ -70,12 +70,12 @@ discard block |
||
| 70 | 70 | public function refreshMedias(array $medias, Mediable $model) |
| 71 | 71 | { |
| 72 | 72 | $model->getMedias()->clear(); |
| 73 | - $this->addMedias($medias,$model); |
|
| 73 | + $this->addMedias($medias, $model); |
|
| 74 | 74 | } |
| 75 | 75 | |
| 76 | 76 | public function clean(array $models) |
| 77 | 77 | { |
| 78 | - foreach($models as $model) |
|
| 78 | + foreach ($models as $model) |
|
| 79 | 79 | { |
| 80 | 80 | $model->getMedias()->clear(); |
| 81 | 81 | } |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | public $webroot; |
| 17 | 17 | |
| 18 | 18 | |
| 19 | - public function __construct(array $resize_option, $webroot){ |
|
| 19 | + public function __construct(array $resize_option, $webroot) { |
|
| 20 | 20 | $this->options = $resize_option; |
| 21 | 21 | $this->webroot = $webroot.'/img/'; |
| 22 | 22 | } |
@@ -24,22 +24,22 @@ discard block |
||
| 24 | 24 | |
| 25 | 25 | public function resize($image) |
| 26 | 26 | { |
| 27 | - $absolute_path = $this->webroot . $image; |
|
| 27 | + $absolute_path = $this->webroot.$image; |
|
| 28 | 28 | $absolute_info = pathinfo($absolute_path); |
| 29 | - $allowedExtension = ['jpg','JPG','jpeg',"JPEG",'png','PNG','gif','GIF']; |
|
| 29 | + $allowedExtension = ['jpg', 'JPG', 'jpeg', "JPEG", 'png', 'PNG', 'gif', 'GIF']; |
|
| 30 | 30 | $extension = pathinfo($image); |
| 31 | 31 | |
| 32 | - if(in_array($extension['extension'],$allowedExtension)) |
|
| 32 | + if (in_array($extension['extension'], $allowedExtension)) |
|
| 33 | 33 | { |
| 34 | - if(!empty($this->options)) |
|
| 34 | + if (!empty($this->options)) |
|
| 35 | 35 | { |
| 36 | - foreach($this->options['size'] as $k=>$v) |
|
| 36 | + foreach ($this->options['size'] as $k=>$v) |
|
| 37 | 37 | { |
| 38 | 38 | $width = $v['width']; |
| 39 | 39 | $height = $v['height']; |
| 40 | - $dest = $absolute_info['dirname'] . '/' . $absolute_info['filename'] . "_$width" . "x$height" . '.jpg'; |
|
| 40 | + $dest = $absolute_info['dirname'].'/'.$absolute_info['filename']."_$width"."x$height".'.jpg'; |
|
| 41 | 41 | |
| 42 | - if(file_exists($dest)) |
|
| 42 | + if (file_exists($dest)) |
|
| 43 | 43 | { |
| 44 | 44 | return false; |
| 45 | 45 | } |
@@ -47,8 +47,8 @@ discard block |
||
| 47 | 47 | $imagine = new \Imagine\Gd\Imagine(); |
| 48 | 48 | $mode = $this->options['mode']; |
| 49 | 49 | |
| 50 | - $imagine->open($absolute_info['dirname'] . '/' . $absolute_info['filename'] . '.jpg') |
|
| 51 | - ->thumbnail(new \Imagine\Image\Box($width,$height), !empty($mode) && $mode == 'inset' ? ImageInterface::THUMBNAIL_INSET : ImageInterface::THUMBNAIL_OUTBOUND) |
|
| 50 | + $imagine->open($absolute_info['dirname'].'/'.$absolute_info['filename'].'.jpg') |
|
| 51 | + ->thumbnail(new \Imagine\Image\Box($width, $height), !empty($mode) && $mode == 'inset' ? ImageInterface::THUMBNAIL_INSET : ImageInterface::THUMBNAIL_OUTBOUND) |
|
| 52 | 52 | ->save($dest); |
| 53 | 53 | } |
| 54 | 54 | } |