@@ -35,7 +35,7 @@ discard block |
||
| 35 | 35 | } elseif (is_string($imageContainer)) { |
| 36 | 36 | $this->_imageResource = imagecreatefromstring($imageContainer); |
| 37 | 37 | } else { |
| 38 | - throw new \Exception('Could not create image resource, accepted inputs are: "resource of type (gd)", path_to_image and "string". <br /><pre>' . var_export($imageContainer, true) . '</pre>'); |
|
| 38 | + throw new \Exception('Could not create image resource, accepted inputs are: "resource of type (gd)", path_to_image and "string". <br /><pre>'.var_export($imageContainer, true).'</pre>'); |
|
| 39 | 39 | } |
| 40 | 40 | } |
| 41 | 41 | |
@@ -179,9 +179,9 @@ discard block |
||
| 179 | 179 | // Cut it in parts of 2 bytes |
| 180 | 180 | $header_parts = str_split($header, 2); |
| 181 | 181 | // Get the width 4 bytes |
| 182 | - $width = hexdec($header_parts[19] . $header_parts[18]); |
|
| 182 | + $width = hexdec($header_parts[19].$header_parts[18]); |
|
| 183 | 183 | // Get the height 4 bytes |
| 184 | - $height = hexdec($header_parts[23] . $header_parts[22]); |
|
| 184 | + $height = hexdec($header_parts[23].$header_parts[22]); |
|
| 185 | 185 | // Unset the header params |
| 186 | 186 | unset($header_parts); |
| 187 | 187 | |
@@ -226,9 +226,9 @@ discard block |
||
| 226 | 226 | } |
| 227 | 227 | // Calculation of the RGB-pixel (defined as BGR in image-data). Define $iPos as absolute position in the body |
| 228 | 228 | $iPos = $i * 2; |
| 229 | - $r = hexdec($body[$iPos + 4] . $body[$iPos + 5]); |
|
| 230 | - $g = hexdec($body[$iPos + 2] . $body[$iPos + 3]); |
|
| 231 | - $b = hexdec($body[$iPos] . $body[$iPos + 1]); |
|
| 229 | + $r = hexdec($body[$iPos + 4].$body[$iPos + 5]); |
|
| 230 | + $g = hexdec($body[$iPos + 2].$body[$iPos + 3]); |
|
| 231 | + $b = hexdec($body[$iPos].$body[$iPos + 1]); |
|
| 232 | 232 | // Calculate and draw the pixel |
| 233 | 233 | $color = imagecolorallocate($image, $r, $g, $b); |
| 234 | 234 | imagesetpixel($image, $x, $height - $y, $color); |
@@ -9,232 +9,232 @@ |
||
| 9 | 9 | */ |
| 10 | 10 | |
| 11 | 11 | namespace CloudControl\Cms\images { |
| 12 | - class Image |
|
| 13 | - { |
|
| 14 | - private $_imageResource; |
|
| 15 | - |
|
| 16 | - /** |
|
| 17 | - * Load the a image resource into $this->_imageResource |
|
| 18 | - * automagically :-) |
|
| 19 | - * |
|
| 20 | - * @param resource | string | path |
|
| 21 | - * |
|
| 22 | - * @throws \Exception |
|
| 23 | - */ |
|
| 24 | - public function loadImage($imageContainer) |
|
| 25 | - { |
|
| 26 | - if (is_resource($imageContainer) && get_resource_type($imageContainer) === 'gd') { |
|
| 27 | - $this->_imageResource = $imageContainer; |
|
| 28 | - } elseif (is_string($imageContainer) && file_exists($imageContainer)) { |
|
| 29 | - if ($this->getImageMimeType($imageContainer) == IMAGETYPE_BMP) { |
|
| 30 | - $this->_imageResource = $this->createImageFromBmp($imageContainer); |
|
| 31 | - } else { |
|
| 32 | - $imageContent = file_get_contents($imageContainer); |
|
| 33 | - $this->_imageResource = imagecreatefromstring($imageContent); |
|
| 34 | - } |
|
| 35 | - } elseif (is_string($imageContainer)) { |
|
| 36 | - $this->_imageResource = imagecreatefromstring($imageContainer); |
|
| 37 | - } else { |
|
| 38 | - throw new \Exception('Could not create image resource, accepted inputs are: "resource of type (gd)", path_to_image and "string". <br /><pre>' . var_export($imageContainer, true) . '</pre>'); |
|
| 39 | - } |
|
| 40 | - } |
|
| 41 | - |
|
| 42 | - /** |
|
| 43 | - * Saves the image to a file |
|
| 44 | - * |
|
| 45 | - * @param string $path |
|
| 46 | - * @param int $mimeTypeConstantValue |
|
| 47 | - * @param int $quality |
|
| 48 | - * @param null $imageResource If no resource is given, uses $this->_imageResource |
|
| 49 | - * |
|
| 50 | - * @return bool |
|
| 51 | - * @throws \Exception |
|
| 52 | - */ |
|
| 53 | - public function saveImage($path, $mimeTypeConstantValue, $quality = 100, $imageResource = null) |
|
| 54 | - { |
|
| 55 | - if ($imageResource == null) { |
|
| 56 | - $imageResource = $this->getImageResource(); |
|
| 57 | - } |
|
| 58 | - |
|
| 59 | - if ($mimeTypeConstantValue == IMAGETYPE_GIF) { |
|
| 60 | - return imagegif($imageResource, $path); |
|
| 61 | - } elseif ($mimeTypeConstantValue == IMAGETYPE_JPEG) { |
|
| 62 | - return imagejpeg($imageResource, $path, $quality); |
|
| 63 | - } elseif ($mimeTypeConstantValue == IMAGETYPE_PNG) { |
|
| 64 | - return imagepng($imageResource, $path, (intval($quality / 10) - 1)); |
|
| 65 | - } else { |
|
| 66 | - throw new \Exception('Not a valid mimetypeconstant given see function documentation'); |
|
| 67 | - } |
|
| 68 | - } |
|
| 69 | - |
|
| 70 | - /** |
|
| 71 | - * Returns either the Mime-Type Constant value |
|
| 72 | - * or the default extension for the detected mime-type; |
|
| 73 | - * |
|
| 74 | - * @see http://www.php.net/manual/en/function.image-type-to-mime-type.php |
|
| 75 | - * |
|
| 76 | - * @param string $imagePath |
|
| 77 | - * @param bool $getExtension |
|
| 78 | - * |
|
| 79 | - * @return bool|int|string |
|
| 80 | - */ |
|
| 81 | - public function getImageMimeType($imagePath, $getExtension = false) |
|
| 82 | - { |
|
| 83 | - if (function_exists('exif_imagetype')) { |
|
| 84 | - $exif = exif_imagetype($imagePath); |
|
| 85 | - } else { |
|
| 86 | - if ((list($width, $height, $type, $attr) = getimagesize($imagePath)) !== false) { |
|
| 87 | - $exif = $type; |
|
| 88 | - } else { |
|
| 89 | - $exif = false; |
|
| 90 | - } |
|
| 91 | - } |
|
| 92 | - |
|
| 93 | - return $getExtension ? image_type_to_extension($exif) : $exif; |
|
| 94 | - } |
|
| 95 | - |
|
| 96 | - /** |
|
| 97 | - * Create Image resource from Bitmap |
|
| 98 | - * |
|
| 99 | - * @see http://www.php.net/manual/en/function.imagecreatefromwbmp.php#86214 |
|
| 100 | - * @author alexander at alexauto dot nl |
|
| 101 | - * |
|
| 102 | - * @param string $pathToBitmapFile |
|
| 103 | - * |
|
| 104 | - * @return resource |
|
| 105 | - */ |
|
| 106 | - public function createImageFromBmp($pathToBitmapFile) |
|
| 107 | - { |
|
| 108 | - $bitmapFileData = $this->getBitmapFileData($pathToBitmapFile); |
|
| 109 | - |
|
| 110 | - $temp = unpack("H*", $bitmapFileData); |
|
| 111 | - $hex = $temp[1]; |
|
| 112 | - $header = substr($hex, 0, 108); |
|
| 113 | - list($width, $height) = $this->calculateWidthAndHeight($header); |
|
| 114 | - |
|
| 115 | - // Define starting X and Y |
|
| 116 | - $x = 0; |
|
| 117 | - $y = 1; |
|
| 118 | - |
|
| 119 | - $image = imagecreatetruecolor($width, $height); |
|
| 120 | - |
|
| 121 | - // Grab the body from the image |
|
| 122 | - $body = substr($hex, 108); |
|
| 123 | - |
|
| 124 | - // Calculate if padding at the end-line is needed. Divided by two to keep overview. 1 byte = 2 HEX-chars |
|
| 125 | - $bodySize = (strlen($body) / 2); |
|
| 126 | - $headerSize = ($width * $height); |
|
| 127 | - |
|
| 128 | - // Use end-line padding? Only when needed |
|
| 129 | - $usePadding = ($bodySize > ($headerSize * 3) + 4); |
|
| 130 | - $this->loopThroughBodyAndCalculatePixels($bodySize, $x, $width, $usePadding, $y, $height, $body, $image); |
|
| 131 | - |
|
| 132 | - unset($body); |
|
| 133 | - |
|
| 134 | - return $image; |
|
| 135 | - } |
|
| 136 | - |
|
| 137 | - /** |
|
| 138 | - * Returns the image resource |
|
| 139 | - * @return resource |
|
| 140 | - * @throws \Exception |
|
| 141 | - */ |
|
| 142 | - final public function getImageResource() |
|
| 143 | - { |
|
| 144 | - if (is_resource($this->_imageResource) && get_resource_type($this->_imageResource) === 'gd') { |
|
| 145 | - return $this->_imageResource; |
|
| 146 | - } else { |
|
| 147 | - throw new \Exception('Image resource is not set. Use $this->LoadImage to load an image into the resource'); |
|
| 148 | - } |
|
| 149 | - } |
|
| 150 | - |
|
| 151 | - /** |
|
| 152 | - * @param $pathToBitmapFile |
|
| 153 | - * |
|
| 154 | - * @return string |
|
| 155 | - */ |
|
| 156 | - private function getBitmapFileData($pathToBitmapFile) |
|
| 157 | - { |
|
| 158 | - $fileHandle = fopen($pathToBitmapFile, "rb"); |
|
| 159 | - $bitmapFileData = fread($fileHandle, 10); |
|
| 160 | - while (!feof($fileHandle) && ($bitmapFileData <> "")) { |
|
| 161 | - $bitmapFileData .= fread($fileHandle, 1024); |
|
| 162 | - } |
|
| 163 | - |
|
| 164 | - return $bitmapFileData; |
|
| 165 | - } |
|
| 166 | - |
|
| 167 | - /** |
|
| 168 | - * @param $header |
|
| 169 | - * |
|
| 170 | - * @return array |
|
| 171 | - */ |
|
| 172 | - private function calculateWidthAndHeight($header) |
|
| 173 | - { |
|
| 174 | - $width = null; |
|
| 175 | - $height = null; |
|
| 176 | - |
|
| 177 | - // Structure: http://www.fastgraph.com/help/bmp_header_format.html |
|
| 178 | - if (substr($header, 0, 4) == "424d") { |
|
| 179 | - // Cut it in parts of 2 bytes |
|
| 180 | - $header_parts = str_split($header, 2); |
|
| 181 | - // Get the width 4 bytes |
|
| 182 | - $width = hexdec($header_parts[19] . $header_parts[18]); |
|
| 183 | - // Get the height 4 bytes |
|
| 184 | - $height = hexdec($header_parts[23] . $header_parts[22]); |
|
| 185 | - // Unset the header params |
|
| 186 | - unset($header_parts); |
|
| 187 | - |
|
| 188 | - return array($width, $height); |
|
| 189 | - } |
|
| 190 | - |
|
| 191 | - return array($width, $height); |
|
| 192 | - } |
|
| 193 | - |
|
| 194 | - /** |
|
| 195 | - * Loop through the data in the body of the bitmap |
|
| 196 | - * file and calculate each individual pixel based on the |
|
| 197 | - * bytes |
|
| 198 | - * @param $bodySize |
|
| 199 | - * @param $x |
|
| 200 | - * @param $width |
|
| 201 | - * @param $usePadding |
|
| 202 | - * @param $y |
|
| 203 | - * @param $height |
|
| 204 | - * @param $body |
|
| 205 | - * @param $image |
|
| 206 | - */ |
|
| 207 | - private function loopThroughBodyAndCalculatePixels($bodySize, $x, $width, $usePadding, $y, $height, $body, $image) |
|
| 208 | - { |
|
| 12 | + class Image |
|
| 13 | + { |
|
| 14 | + private $_imageResource; |
|
| 15 | + |
|
| 16 | + /** |
|
| 17 | + * Load the a image resource into $this->_imageResource |
|
| 18 | + * automagically :-) |
|
| 19 | + * |
|
| 20 | + * @param resource | string | path |
|
| 21 | + * |
|
| 22 | + * @throws \Exception |
|
| 23 | + */ |
|
| 24 | + public function loadImage($imageContainer) |
|
| 25 | + { |
|
| 26 | + if (is_resource($imageContainer) && get_resource_type($imageContainer) === 'gd') { |
|
| 27 | + $this->_imageResource = $imageContainer; |
|
| 28 | + } elseif (is_string($imageContainer) && file_exists($imageContainer)) { |
|
| 29 | + if ($this->getImageMimeType($imageContainer) == IMAGETYPE_BMP) { |
|
| 30 | + $this->_imageResource = $this->createImageFromBmp($imageContainer); |
|
| 31 | + } else { |
|
| 32 | + $imageContent = file_get_contents($imageContainer); |
|
| 33 | + $this->_imageResource = imagecreatefromstring($imageContent); |
|
| 34 | + } |
|
| 35 | + } elseif (is_string($imageContainer)) { |
|
| 36 | + $this->_imageResource = imagecreatefromstring($imageContainer); |
|
| 37 | + } else { |
|
| 38 | + throw new \Exception('Could not create image resource, accepted inputs are: "resource of type (gd)", path_to_image and "string". <br /><pre>' . var_export($imageContainer, true) . '</pre>'); |
|
| 39 | + } |
|
| 40 | + } |
|
| 41 | + |
|
| 42 | + /** |
|
| 43 | + * Saves the image to a file |
|
| 44 | + * |
|
| 45 | + * @param string $path |
|
| 46 | + * @param int $mimeTypeConstantValue |
|
| 47 | + * @param int $quality |
|
| 48 | + * @param null $imageResource If no resource is given, uses $this->_imageResource |
|
| 49 | + * |
|
| 50 | + * @return bool |
|
| 51 | + * @throws \Exception |
|
| 52 | + */ |
|
| 53 | + public function saveImage($path, $mimeTypeConstantValue, $quality = 100, $imageResource = null) |
|
| 54 | + { |
|
| 55 | + if ($imageResource == null) { |
|
| 56 | + $imageResource = $this->getImageResource(); |
|
| 57 | + } |
|
| 58 | + |
|
| 59 | + if ($mimeTypeConstantValue == IMAGETYPE_GIF) { |
|
| 60 | + return imagegif($imageResource, $path); |
|
| 61 | + } elseif ($mimeTypeConstantValue == IMAGETYPE_JPEG) { |
|
| 62 | + return imagejpeg($imageResource, $path, $quality); |
|
| 63 | + } elseif ($mimeTypeConstantValue == IMAGETYPE_PNG) { |
|
| 64 | + return imagepng($imageResource, $path, (intval($quality / 10) - 1)); |
|
| 65 | + } else { |
|
| 66 | + throw new \Exception('Not a valid mimetypeconstant given see function documentation'); |
|
| 67 | + } |
|
| 68 | + } |
|
| 69 | + |
|
| 70 | + /** |
|
| 71 | + * Returns either the Mime-Type Constant value |
|
| 72 | + * or the default extension for the detected mime-type; |
|
| 73 | + * |
|
| 74 | + * @see http://www.php.net/manual/en/function.image-type-to-mime-type.php |
|
| 75 | + * |
|
| 76 | + * @param string $imagePath |
|
| 77 | + * @param bool $getExtension |
|
| 78 | + * |
|
| 79 | + * @return bool|int|string |
|
| 80 | + */ |
|
| 81 | + public function getImageMimeType($imagePath, $getExtension = false) |
|
| 82 | + { |
|
| 83 | + if (function_exists('exif_imagetype')) { |
|
| 84 | + $exif = exif_imagetype($imagePath); |
|
| 85 | + } else { |
|
| 86 | + if ((list($width, $height, $type, $attr) = getimagesize($imagePath)) !== false) { |
|
| 87 | + $exif = $type; |
|
| 88 | + } else { |
|
| 89 | + $exif = false; |
|
| 90 | + } |
|
| 91 | + } |
|
| 92 | + |
|
| 93 | + return $getExtension ? image_type_to_extension($exif) : $exif; |
|
| 94 | + } |
|
| 95 | + |
|
| 96 | + /** |
|
| 97 | + * Create Image resource from Bitmap |
|
| 98 | + * |
|
| 99 | + * @see http://www.php.net/manual/en/function.imagecreatefromwbmp.php#86214 |
|
| 100 | + * @author alexander at alexauto dot nl |
|
| 101 | + * |
|
| 102 | + * @param string $pathToBitmapFile |
|
| 103 | + * |
|
| 104 | + * @return resource |
|
| 105 | + */ |
|
| 106 | + public function createImageFromBmp($pathToBitmapFile) |
|
| 107 | + { |
|
| 108 | + $bitmapFileData = $this->getBitmapFileData($pathToBitmapFile); |
|
| 109 | + |
|
| 110 | + $temp = unpack("H*", $bitmapFileData); |
|
| 111 | + $hex = $temp[1]; |
|
| 112 | + $header = substr($hex, 0, 108); |
|
| 113 | + list($width, $height) = $this->calculateWidthAndHeight($header); |
|
| 114 | + |
|
| 115 | + // Define starting X and Y |
|
| 116 | + $x = 0; |
|
| 117 | + $y = 1; |
|
| 118 | + |
|
| 119 | + $image = imagecreatetruecolor($width, $height); |
|
| 120 | + |
|
| 121 | + // Grab the body from the image |
|
| 122 | + $body = substr($hex, 108); |
|
| 123 | + |
|
| 124 | + // Calculate if padding at the end-line is needed. Divided by two to keep overview. 1 byte = 2 HEX-chars |
|
| 125 | + $bodySize = (strlen($body) / 2); |
|
| 126 | + $headerSize = ($width * $height); |
|
| 127 | + |
|
| 128 | + // Use end-line padding? Only when needed |
|
| 129 | + $usePadding = ($bodySize > ($headerSize * 3) + 4); |
|
| 130 | + $this->loopThroughBodyAndCalculatePixels($bodySize, $x, $width, $usePadding, $y, $height, $body, $image); |
|
| 131 | + |
|
| 132 | + unset($body); |
|
| 133 | + |
|
| 134 | + return $image; |
|
| 135 | + } |
|
| 136 | + |
|
| 137 | + /** |
|
| 138 | + * Returns the image resource |
|
| 139 | + * @return resource |
|
| 140 | + * @throws \Exception |
|
| 141 | + */ |
|
| 142 | + final public function getImageResource() |
|
| 143 | + { |
|
| 144 | + if (is_resource($this->_imageResource) && get_resource_type($this->_imageResource) === 'gd') { |
|
| 145 | + return $this->_imageResource; |
|
| 146 | + } else { |
|
| 147 | + throw new \Exception('Image resource is not set. Use $this->LoadImage to load an image into the resource'); |
|
| 148 | + } |
|
| 149 | + } |
|
| 150 | + |
|
| 151 | + /** |
|
| 152 | + * @param $pathToBitmapFile |
|
| 153 | + * |
|
| 154 | + * @return string |
|
| 155 | + */ |
|
| 156 | + private function getBitmapFileData($pathToBitmapFile) |
|
| 157 | + { |
|
| 158 | + $fileHandle = fopen($pathToBitmapFile, "rb"); |
|
| 159 | + $bitmapFileData = fread($fileHandle, 10); |
|
| 160 | + while (!feof($fileHandle) && ($bitmapFileData <> "")) { |
|
| 161 | + $bitmapFileData .= fread($fileHandle, 1024); |
|
| 162 | + } |
|
| 163 | + |
|
| 164 | + return $bitmapFileData; |
|
| 165 | + } |
|
| 166 | + |
|
| 167 | + /** |
|
| 168 | + * @param $header |
|
| 169 | + * |
|
| 170 | + * @return array |
|
| 171 | + */ |
|
| 172 | + private function calculateWidthAndHeight($header) |
|
| 173 | + { |
|
| 174 | + $width = null; |
|
| 175 | + $height = null; |
|
| 176 | + |
|
| 177 | + // Structure: http://www.fastgraph.com/help/bmp_header_format.html |
|
| 178 | + if (substr($header, 0, 4) == "424d") { |
|
| 179 | + // Cut it in parts of 2 bytes |
|
| 180 | + $header_parts = str_split($header, 2); |
|
| 181 | + // Get the width 4 bytes |
|
| 182 | + $width = hexdec($header_parts[19] . $header_parts[18]); |
|
| 183 | + // Get the height 4 bytes |
|
| 184 | + $height = hexdec($header_parts[23] . $header_parts[22]); |
|
| 185 | + // Unset the header params |
|
| 186 | + unset($header_parts); |
|
| 187 | + |
|
| 188 | + return array($width, $height); |
|
| 189 | + } |
|
| 190 | + |
|
| 191 | + return array($width, $height); |
|
| 192 | + } |
|
| 193 | + |
|
| 194 | + /** |
|
| 195 | + * Loop through the data in the body of the bitmap |
|
| 196 | + * file and calculate each individual pixel based on the |
|
| 197 | + * bytes |
|
| 198 | + * @param $bodySize |
|
| 199 | + * @param $x |
|
| 200 | + * @param $width |
|
| 201 | + * @param $usePadding |
|
| 202 | + * @param $y |
|
| 203 | + * @param $height |
|
| 204 | + * @param $body |
|
| 205 | + * @param $image |
|
| 206 | + */ |
|
| 207 | + private function loopThroughBodyAndCalculatePixels($bodySize, $x, $width, $usePadding, $y, $height, $body, $image) |
|
| 208 | + { |
|
| 209 | 209 | // Using a for-loop with index-calculation instead of str_split to avoid large memory consumption |
| 210 | - // Calculate the next DWORD-position in the body |
|
| 211 | - for ($i = 0; $i < $bodySize; $i += 3) { |
|
| 212 | - // Calculate line-ending and padding |
|
| 213 | - if ($x >= $width) { |
|
| 214 | - // If padding needed, ignore image-padding. Shift i to the ending of the current 32-bit-block |
|
| 215 | - if ($usePadding) { |
|
| 216 | - $i += $width % 4; |
|
| 217 | - } |
|
| 218 | - // Reset horizontal position |
|
| 219 | - $x = 0; |
|
| 220 | - // Raise the height-position (bottom-up) |
|
| 221 | - $y++; |
|
| 222 | - // Reached the image-height? Break the for-loop |
|
| 223 | - if ($y > $height) { |
|
| 224 | - break; |
|
| 225 | - } |
|
| 226 | - } |
|
| 227 | - // Calculation of the RGB-pixel (defined as BGR in image-data). Define $iPos as absolute position in the body |
|
| 228 | - $iPos = $i * 2; |
|
| 229 | - $r = hexdec($body[$iPos + 4] . $body[$iPos + 5]); |
|
| 230 | - $g = hexdec($body[$iPos + 2] . $body[$iPos + 3]); |
|
| 231 | - $b = hexdec($body[$iPos] . $body[$iPos + 1]); |
|
| 232 | - // Calculate and draw the pixel |
|
| 233 | - $color = imagecolorallocate($image, $r, $g, $b); |
|
| 234 | - imagesetpixel($image, $x, $height - $y, $color); |
|
| 235 | - // Raise the horizontal position |
|
| 236 | - $x++; |
|
| 237 | - } |
|
| 238 | - } |
|
| 239 | - } |
|
| 210 | + // Calculate the next DWORD-position in the body |
|
| 211 | + for ($i = 0; $i < $bodySize; $i += 3) { |
|
| 212 | + // Calculate line-ending and padding |
|
| 213 | + if ($x >= $width) { |
|
| 214 | + // If padding needed, ignore image-padding. Shift i to the ending of the current 32-bit-block |
|
| 215 | + if ($usePadding) { |
|
| 216 | + $i += $width % 4; |
|
| 217 | + } |
|
| 218 | + // Reset horizontal position |
|
| 219 | + $x = 0; |
|
| 220 | + // Raise the height-position (bottom-up) |
|
| 221 | + $y++; |
|
| 222 | + // Reached the image-height? Break the for-loop |
|
| 223 | + if ($y > $height) { |
|
| 224 | + break; |
|
| 225 | + } |
|
| 226 | + } |
|
| 227 | + // Calculation of the RGB-pixel (defined as BGR in image-data). Define $iPos as absolute position in the body |
|
| 228 | + $iPos = $i * 2; |
|
| 229 | + $r = hexdec($body[$iPos + 4] . $body[$iPos + 5]); |
|
| 230 | + $g = hexdec($body[$iPos + 2] . $body[$iPos + 3]); |
|
| 231 | + $b = hexdec($body[$iPos] . $body[$iPos + 1]); |
|
| 232 | + // Calculate and draw the pixel |
|
| 233 | + $color = imagecolorallocate($image, $r, $g, $b); |
|
| 234 | + imagesetpixel($image, $x, $height - $y, $color); |
|
| 235 | + // Raise the horizontal position |
|
| 236 | + $x++; |
|
| 237 | + } |
|
| 238 | + } |
|
| 239 | + } |
|
| 240 | 240 | } |
| 241 | 241 | \ No newline at end of file |
@@ -63,7 +63,7 @@ |
||
| 63 | 63 | |
| 64 | 64 | // Define the ratio and adjust the width and height |
| 65 | 65 | if ($this->_preserveAspectRatio) { |
| 66 | - $ratio = min($this->_width/$originalWidth, $this->_height/$originalHeight); |
|
| 66 | + $ratio = min($this->_width / $originalWidth, $this->_height / $originalHeight); |
|
| 67 | 67 | $this->_width = $originalWidth * $ratio; |
| 68 | 68 | $this->_height = $originalHeight * $ratio; |
| 69 | 69 | } |
@@ -14,73 +14,73 @@ |
||
| 14 | 14 | use CloudControl\Cms\images\IMethod; |
| 15 | 15 | |
| 16 | 16 | class Resize extends IMethod |
| 17 | - { |
|
| 18 | - protected $_width; |
|
| 19 | - protected $_height; |
|
| 20 | - protected $_preserveAspectRatio = true; |
|
| 17 | + { |
|
| 18 | + protected $_width; |
|
| 19 | + protected $_height; |
|
| 20 | + protected $_preserveAspectRatio = true; |
|
| 21 | 21 | |
| 22 | - /** |
|
| 23 | - * Set the width |
|
| 24 | - * |
|
| 25 | - * @param int $width |
|
| 26 | - * @return self |
|
| 27 | - */ |
|
| 28 | - public function SetWidth($width) |
|
| 29 | - { |
|
| 30 | - $this->_width = intval($width); |
|
| 31 | - return $this; |
|
| 32 | - } |
|
| 22 | + /** |
|
| 23 | + * Set the width |
|
| 24 | + * |
|
| 25 | + * @param int $width |
|
| 26 | + * @return self |
|
| 27 | + */ |
|
| 28 | + public function SetWidth($width) |
|
| 29 | + { |
|
| 30 | + $this->_width = intval($width); |
|
| 31 | + return $this; |
|
| 32 | + } |
|
| 33 | 33 | |
| 34 | - /** |
|
| 35 | - * Set the height |
|
| 36 | - * |
|
| 37 | - * @param int $height |
|
| 38 | - * @return self |
|
| 39 | - */ |
|
| 40 | - public function SetHeight($height) |
|
| 41 | - { |
|
| 42 | - $this->_height = intval($height); |
|
| 43 | - return $this; |
|
| 44 | - } |
|
| 34 | + /** |
|
| 35 | + * Set the height |
|
| 36 | + * |
|
| 37 | + * @param int $height |
|
| 38 | + * @return self |
|
| 39 | + */ |
|
| 40 | + public function SetHeight($height) |
|
| 41 | + { |
|
| 42 | + $this->_height = intval($height); |
|
| 43 | + return $this; |
|
| 44 | + } |
|
| 45 | 45 | |
| 46 | - /** |
|
| 47 | - * Sets wheter or not the aspect ratio of the original |
|
| 48 | - * image needs to preserved |
|
| 49 | - * |
|
| 50 | - * @param bool $bool |
|
| 51 | - * @return self |
|
| 52 | - */ |
|
| 53 | - public function SetPreserveAspectRatio($bool) |
|
| 54 | - { |
|
| 55 | - $this->_preserveAspectRatio = (bool) $bool; |
|
| 56 | - return $this; |
|
| 57 | - } |
|
| 46 | + /** |
|
| 47 | + * Sets wheter or not the aspect ratio of the original |
|
| 48 | + * image needs to preserved |
|
| 49 | + * |
|
| 50 | + * @param bool $bool |
|
| 51 | + * @return self |
|
| 52 | + */ |
|
| 53 | + public function SetPreserveAspectRatio($bool) |
|
| 54 | + { |
|
| 55 | + $this->_preserveAspectRatio = (bool) $bool; |
|
| 56 | + return $this; |
|
| 57 | + } |
|
| 58 | 58 | |
| 59 | - public function Execute($imageResource) |
|
| 60 | - { |
|
| 61 | - // Define the origial width and height |
|
| 62 | - $originalWidth = imagesx($imageResource); |
|
| 63 | - $originalHeight = imagesy($imageResource); |
|
| 59 | + public function Execute($imageResource) |
|
| 60 | + { |
|
| 61 | + // Define the origial width and height |
|
| 62 | + $originalWidth = imagesx($imageResource); |
|
| 63 | + $originalHeight = imagesy($imageResource); |
|
| 64 | 64 | |
| 65 | - // Define the ratio and adjust the width and height |
|
| 66 | - if ($this->_preserveAspectRatio) { |
|
| 67 | - $ratio = min($this->_width/$originalWidth, $this->_height/$originalHeight); |
|
| 68 | - $this->_width = $originalWidth * $ratio; |
|
| 69 | - $this->_height = $originalHeight * $ratio; |
|
| 70 | - } |
|
| 65 | + // Define the ratio and adjust the width and height |
|
| 66 | + if ($this->_preserveAspectRatio) { |
|
| 67 | + $ratio = min($this->_width/$originalWidth, $this->_height/$originalHeight); |
|
| 68 | + $this->_width = $originalWidth * $ratio; |
|
| 69 | + $this->_height = $originalHeight * $ratio; |
|
| 70 | + } |
|
| 71 | 71 | |
| 72 | - // Create the new image |
|
| 73 | - $new = imagecreatetruecolor($this->_width, $this->_height); |
|
| 72 | + // Create the new image |
|
| 73 | + $new = imagecreatetruecolor($this->_width, $this->_height); |
|
| 74 | 74 | |
| 75 | - // Preserve transparency |
|
| 76 | - imagecolortransparent($new, imagecolorallocatealpha($new, 0, 0, 0, 127)); |
|
| 77 | - imagealphablending($new, false); |
|
| 78 | - imagesavealpha($new, true); |
|
| 75 | + // Preserve transparency |
|
| 76 | + imagecolortransparent($new, imagecolorallocatealpha($new, 0, 0, 0, 127)); |
|
| 77 | + imagealphablending($new, false); |
|
| 78 | + imagesavealpha($new, true); |
|
| 79 | 79 | |
| 80 | - // Do the actual resizing |
|
| 81 | - imagecopyresampled($new, $imageResource, 0, 0, 0, 0, $this->_width, $this->_height, $originalWidth, $originalHeight); |
|
| 80 | + // Do the actual resizing |
|
| 81 | + imagecopyresampled($new, $imageResource, 0, 0, 0, 0, $this->_width, $this->_height, $originalWidth, $originalHeight); |
|
| 82 | 82 | |
| 83 | - return $new; |
|
| 84 | - } |
|
| 85 | - } |
|
| 83 | + return $new; |
|
| 84 | + } |
|
| 85 | + } |
|
| 86 | 86 | } |
| 87 | 87 | \ No newline at end of file |
@@ -26,14 +26,14 @@ |
||
| 26 | 26 | |
| 27 | 27 | // Define which ratio will be used, depending on which is the smallest side |
| 28 | 28 | $ratio = min($hRatio, $wRatio); |
| 29 | - if($ratio > 1) $ratio = 1; |
|
| 29 | + if ($ratio > 1) $ratio = 1; |
|
| 30 | 30 | |
| 31 | 31 | // Define sizes |
| 32 | 32 | $this->_destWidth = floor($originalWidth * $ratio); |
| 33 | 33 | $this->_destHeight = floor($originalHeight * $ratio); |
| 34 | 34 | |
| 35 | 35 | // Define margins |
| 36 | - $this->_destX = floor(($this->_width - $this->_destWidth) / 2); |
|
| 36 | + $this->_destX = floor(($this->_width - $this->_destWidth) / 2); |
|
| 37 | 37 | $this->_destY = floor(($this->_height - $this->_destHeight) / 2); |
| 38 | 38 | |
| 39 | 39 | // Execute the Crop method with the given parameters |
@@ -10,36 +10,36 @@ |
||
| 10 | 10 | |
| 11 | 11 | namespace CloudControl\Cms\images\methods |
| 12 | 12 | { |
| 13 | - class BoxCrop extends Crop |
|
| 14 | - { |
|
| 15 | - /** |
|
| 16 | - * @param resource $imageResource |
|
| 17 | - * @return resource |
|
| 13 | + class BoxCrop extends Crop |
|
| 14 | + { |
|
| 15 | + /** |
|
| 16 | + * @param resource $imageResource |
|
| 17 | + * @return resource |
|
| 18 | 18 | */ |
| 19 | - public function Execute($imageResource) |
|
| 20 | - { |
|
| 21 | - // Define the origial width and height |
|
| 22 | - $originalWidth = imagesx($imageResource); |
|
| 23 | - $originalHeight = imagesy($imageResource); |
|
| 19 | + public function Execute($imageResource) |
|
| 20 | + { |
|
| 21 | + // Define the origial width and height |
|
| 22 | + $originalWidth = imagesx($imageResource); |
|
| 23 | + $originalHeight = imagesy($imageResource); |
|
| 24 | 24 | |
| 25 | - // Define the ratios |
|
| 26 | - $wRatio = $this->_width / $originalWidth; |
|
| 27 | - $hRatio = $this->_height / $originalHeight; |
|
| 25 | + // Define the ratios |
|
| 26 | + $wRatio = $this->_width / $originalWidth; |
|
| 27 | + $hRatio = $this->_height / $originalHeight; |
|
| 28 | 28 | |
| 29 | - // Define which ratio will be used, depending on which is the smallest side |
|
| 30 | - $ratio = min($hRatio, $wRatio); |
|
| 31 | - if($ratio > 1) $ratio = 1; |
|
| 29 | + // Define which ratio will be used, depending on which is the smallest side |
|
| 30 | + $ratio = min($hRatio, $wRatio); |
|
| 31 | + if($ratio > 1) $ratio = 1; |
|
| 32 | 32 | |
| 33 | - // Define sizes |
|
| 34 | - $this->_destWidth = floor($originalWidth * $ratio); |
|
| 35 | - $this->_destHeight = floor($originalHeight * $ratio); |
|
| 33 | + // Define sizes |
|
| 34 | + $this->_destWidth = floor($originalWidth * $ratio); |
|
| 35 | + $this->_destHeight = floor($originalHeight * $ratio); |
|
| 36 | 36 | |
| 37 | - // Define margins |
|
| 38 | - $this->_destX = floor(($this->_width - $this->_destWidth) / 2); |
|
| 39 | - $this->_destY = floor(($this->_height - $this->_destHeight) / 2); |
|
| 37 | + // Define margins |
|
| 38 | + $this->_destX = floor(($this->_width - $this->_destWidth) / 2); |
|
| 39 | + $this->_destY = floor(($this->_height - $this->_destHeight) / 2); |
|
| 40 | 40 | |
| 41 | - // Execute the Crop method with the given parameters |
|
| 42 | - return parent::Execute($imageResource); |
|
| 43 | - } |
|
| 44 | - } |
|
| 41 | + // Execute the Crop method with the given parameters |
|
| 42 | + return parent::Execute($imageResource); |
|
| 43 | + } |
|
| 44 | + } |
|
| 45 | 45 | } |
| 46 | 46 | \ No newline at end of file |
@@ -45,7 +45,7 @@ discard block |
||
| 45 | 45 | } |
| 46 | 46 | return $returnFileNames; |
| 47 | 47 | } else { |
| 48 | - throw new \Exception('Image doesnt exist: ' . $imagePath); |
|
| 48 | + throw new \Exception('Image doesnt exist: '.$imagePath); |
|
| 49 | 49 | } |
| 50 | 50 | } |
| 51 | 51 | |
@@ -56,10 +56,10 @@ discard block |
||
| 56 | 56 | * @return string |
| 57 | 57 | * @throws \Exception |
| 58 | 58 | */ |
| 59 | - public function resize($imagePath='', $width='',$height='') |
|
| 59 | + public function resize($imagePath = '', $width = '', $height = '') |
|
| 60 | 60 | { |
| 61 | - $modifier = '-r' . $width . 'x' . $height; |
|
| 62 | - return $this->applyMethod('Resize', $imagePath, $width,$height, $modifier); |
|
| 61 | + $modifier = '-r'.$width.'x'.$height; |
|
| 62 | + return $this->applyMethod('Resize', $imagePath, $width, $height, $modifier); |
|
| 63 | 63 | } |
| 64 | 64 | |
| 65 | 65 | /** |
@@ -69,10 +69,10 @@ discard block |
||
| 69 | 69 | * @return string |
| 70 | 70 | * @throws \Exception |
| 71 | 71 | */ |
| 72 | - public function smartcrop($imagePath='', $width='',$height='') |
|
| 72 | + public function smartcrop($imagePath = '', $width = '', $height = '') |
|
| 73 | 73 | { |
| 74 | - $modifier = '-s' . $width . 'x' . $height; |
|
| 75 | - return $this->applyMethod('SmartCrop', $imagePath, $width,$height, $modifier); |
|
| 74 | + $modifier = '-s'.$width.'x'.$height; |
|
| 75 | + return $this->applyMethod('SmartCrop', $imagePath, $width, $height, $modifier); |
|
| 76 | 76 | } |
| 77 | 77 | |
| 78 | 78 | /** |
@@ -82,10 +82,10 @@ discard block |
||
| 82 | 82 | * @return string |
| 83 | 83 | * @throws \Exception |
| 84 | 84 | */ |
| 85 | - public function boxcrop($imagePath='', $width='',$height='') |
|
| 85 | + public function boxcrop($imagePath = '', $width = '', $height = '') |
|
| 86 | 86 | { |
| 87 | - $modifier = '-b' . $width . 'x' . $height; |
|
| 88 | - return $this->applyMethod('BoxCrop', $imagePath, $width,$height, $modifier); |
|
| 87 | + $modifier = '-b'.$width.'x'.$height; |
|
| 88 | + return $this->applyMethod('BoxCrop', $imagePath, $width, $height, $modifier); |
|
| 89 | 89 | } |
| 90 | 90 | |
| 91 | 91 | /** |
@@ -94,7 +94,7 @@ discard block |
||
| 94 | 94 | * |
| 95 | 95 | * @return string |
| 96 | 96 | */ |
| 97 | - private function modifyName($imagePath, $modifier='') |
|
| 97 | + private function modifyName($imagePath, $modifier = '') |
|
| 98 | 98 | { |
| 99 | 99 | $filename = basename($imagePath); |
| 100 | 100 | $path = dirname($imagePath); |
@@ -104,30 +104,30 @@ discard block |
||
| 104 | 104 | array_pop($fileParts); |
| 105 | 105 | $fileNameWithoutExtension = implode('-', $fileParts); |
| 106 | 106 | $fileNameWithoutExtension = StringUtil::slugify($fileNameWithoutExtension); |
| 107 | - $filename = $fileNameWithoutExtension . $modifier . '.' . $extension; |
|
| 107 | + $filename = $fileNameWithoutExtension.$modifier.'.'.$extension; |
|
| 108 | 108 | } else { |
| 109 | 109 | $filename = StringUtil::slugify($filename); |
| 110 | 110 | } |
| 111 | 111 | |
| 112 | - if (file_exists($path . '/' . $filename)) { |
|
| 112 | + if (file_exists($path.'/'.$filename)) { |
|
| 113 | 113 | $fileParts = explode('.', $filename); |
| 114 | 114 | if (count($fileParts) > 1) { |
| 115 | 115 | $extension = end($fileParts); |
| 116 | 116 | array_pop($fileParts); |
| 117 | 117 | $fileNameWithoutExtension = implode('-', $fileParts); |
| 118 | 118 | $fileNameWithoutExtension .= '-copy'; |
| 119 | - $filename = $fileNameWithoutExtension . '.' . $extension; |
|
| 119 | + $filename = $fileNameWithoutExtension.'.'.$extension; |
|
| 120 | 120 | } else { |
| 121 | 121 | $filename .= '-copy'; |
| 122 | 122 | } |
| 123 | - return $this->modifyName($path . '/' . $filename); |
|
| 123 | + return $this->modifyName($path.'/'.$filename); |
|
| 124 | 124 | } |
| 125 | - return $path . '/' . $filename; |
|
| 125 | + return $path.'/'.$filename; |
|
| 126 | 126 | } |
| 127 | 127 | |
| 128 | 128 | private function applyMethod($method, $imagePath, $width, $height, $modifier) |
| 129 | 129 | { |
| 130 | - $method = 'CloudControl\Cms\\images\\methods\\' . $method; |
|
| 130 | + $method = 'CloudControl\Cms\\images\\methods\\'.$method; |
|
| 131 | 131 | $destination = $this->modifyName($imagePath, $modifier); |
| 132 | 132 | if (file_exists($imagePath)) { |
| 133 | 133 | $image = new Image(); |
@@ -141,7 +141,7 @@ discard block |
||
| 141 | 141 | $resizedImage->saveImage($destination, $resizedImage->getImageMimeType($imagePath), 80); |
| 142 | 142 | return basename($destination); |
| 143 | 143 | } else { |
| 144 | - throw new \Exception('Image doesnt exist: ' . $imagePath); |
|
| 144 | + throw new \Exception('Image doesnt exist: '.$imagePath); |
|
| 145 | 145 | } |
| 146 | 146 | } |
| 147 | 147 | } |
@@ -5,144 +5,144 @@ |
||
| 5 | 5 | use CloudControl\Cms\cc\StringUtil; |
| 6 | 6 | |
| 7 | 7 | /** |
| 8 | - * Class ImageResizer |
|
| 9 | - * @package CloudControl\Cms\images |
|
| 10 | - */ |
|
| 11 | - class ImageResizer |
|
| 12 | - { |
|
| 13 | - protected $imageSet; |
|
| 8 | + * Class ImageResizer |
|
| 9 | + * @package CloudControl\Cms\images |
|
| 10 | + */ |
|
| 11 | + class ImageResizer |
|
| 12 | + { |
|
| 13 | + protected $imageSet; |
|
| 14 | 14 | |
| 15 | - /** |
|
| 16 | - * ImageResizer constructor. |
|
| 17 | - * |
|
| 18 | - * @param $imageSet |
|
| 19 | - */ |
|
| 20 | - public function __construct($imageSet) |
|
| 21 | - { |
|
| 22 | - $this->imageSet = $imageSet; |
|
| 23 | - } |
|
| 15 | + /** |
|
| 16 | + * ImageResizer constructor. |
|
| 17 | + * |
|
| 18 | + * @param $imageSet |
|
| 19 | + */ |
|
| 20 | + public function __construct($imageSet) |
|
| 21 | + { |
|
| 22 | + $this->imageSet = $imageSet; |
|
| 23 | + } |
|
| 24 | 24 | |
| 25 | - /** |
|
| 26 | - * @param $imagePath |
|
| 27 | - * |
|
| 28 | - * @return array |
|
| 29 | - * @throws \Exception |
|
| 30 | - */ |
|
| 31 | - public function applyImageSetToImage($imagePath) |
|
| 32 | - { |
|
| 33 | - $returnFileNames = array(); |
|
| 34 | - $filename = ''; |
|
| 35 | - if (file_exists($imagePath)) { |
|
| 36 | - foreach ($this->imageSet as $set) { |
|
| 37 | - if ($set->method == 'resize') { |
|
| 38 | - $filename = $this->resize($imagePath, $set->width, $set->height); |
|
| 39 | - } elseif ($set->method == 'smartcrop') { |
|
| 40 | - $filename = $this->smartcrop($imagePath, $set->width, $set->height); |
|
| 41 | - } elseif ($set->method == 'boxcrop') { |
|
| 42 | - $filename = $this->boxcrop($imagePath, $set->width, $set->height); |
|
| 43 | - } |
|
| 44 | - $returnFileNames[$set->slug] = $filename; |
|
| 45 | - } |
|
| 46 | - return $returnFileNames; |
|
| 47 | - } else { |
|
| 48 | - throw new \Exception('Image doesnt exist: ' . $imagePath); |
|
| 49 | - } |
|
| 50 | - } |
|
| 25 | + /** |
|
| 26 | + * @param $imagePath |
|
| 27 | + * |
|
| 28 | + * @return array |
|
| 29 | + * @throws \Exception |
|
| 30 | + */ |
|
| 31 | + public function applyImageSetToImage($imagePath) |
|
| 32 | + { |
|
| 33 | + $returnFileNames = array(); |
|
| 34 | + $filename = ''; |
|
| 35 | + if (file_exists($imagePath)) { |
|
| 36 | + foreach ($this->imageSet as $set) { |
|
| 37 | + if ($set->method == 'resize') { |
|
| 38 | + $filename = $this->resize($imagePath, $set->width, $set->height); |
|
| 39 | + } elseif ($set->method == 'smartcrop') { |
|
| 40 | + $filename = $this->smartcrop($imagePath, $set->width, $set->height); |
|
| 41 | + } elseif ($set->method == 'boxcrop') { |
|
| 42 | + $filename = $this->boxcrop($imagePath, $set->width, $set->height); |
|
| 43 | + } |
|
| 44 | + $returnFileNames[$set->slug] = $filename; |
|
| 45 | + } |
|
| 46 | + return $returnFileNames; |
|
| 47 | + } else { |
|
| 48 | + throw new \Exception('Image doesnt exist: ' . $imagePath); |
|
| 49 | + } |
|
| 50 | + } |
|
| 51 | 51 | |
| 52 | - /** |
|
| 53 | - * @param string $imagePath |
|
| 54 | - * @param string $width |
|
| 55 | - * @param string $height |
|
| 56 | - * @return string |
|
| 57 | - * @throws \Exception |
|
| 58 | - */ |
|
| 59 | - public function resize($imagePath='', $width='',$height='') |
|
| 60 | - { |
|
| 61 | - $modifier = '-r' . $width . 'x' . $height; |
|
| 62 | - return $this->applyMethod('Resize', $imagePath, $width,$height, $modifier); |
|
| 63 | - } |
|
| 52 | + /** |
|
| 53 | + * @param string $imagePath |
|
| 54 | + * @param string $width |
|
| 55 | + * @param string $height |
|
| 56 | + * @return string |
|
| 57 | + * @throws \Exception |
|
| 58 | + */ |
|
| 59 | + public function resize($imagePath='', $width='',$height='') |
|
| 60 | + { |
|
| 61 | + $modifier = '-r' . $width . 'x' . $height; |
|
| 62 | + return $this->applyMethod('Resize', $imagePath, $width,$height, $modifier); |
|
| 63 | + } |
|
| 64 | 64 | |
| 65 | - /** |
|
| 66 | - * @param string $imagePath |
|
| 67 | - * @param string $width |
|
| 68 | - * @param string $height |
|
| 69 | - * @return string |
|
| 70 | - * @throws \Exception |
|
| 71 | - */ |
|
| 72 | - public function smartcrop($imagePath='', $width='',$height='') |
|
| 73 | - { |
|
| 74 | - $modifier = '-s' . $width . 'x' . $height; |
|
| 75 | - return $this->applyMethod('SmartCrop', $imagePath, $width,$height, $modifier); |
|
| 76 | - } |
|
| 65 | + /** |
|
| 66 | + * @param string $imagePath |
|
| 67 | + * @param string $width |
|
| 68 | + * @param string $height |
|
| 69 | + * @return string |
|
| 70 | + * @throws \Exception |
|
| 71 | + */ |
|
| 72 | + public function smartcrop($imagePath='', $width='',$height='') |
|
| 73 | + { |
|
| 74 | + $modifier = '-s' . $width . 'x' . $height; |
|
| 75 | + return $this->applyMethod('SmartCrop', $imagePath, $width,$height, $modifier); |
|
| 76 | + } |
|
| 77 | 77 | |
| 78 | - /** |
|
| 79 | - * @param string $imagePath |
|
| 80 | - * @param string $width |
|
| 81 | - * @param string $height |
|
| 82 | - * @return string |
|
| 83 | - * @throws \Exception |
|
| 84 | - */ |
|
| 85 | - public function boxcrop($imagePath='', $width='',$height='') |
|
| 86 | - { |
|
| 87 | - $modifier = '-b' . $width . 'x' . $height; |
|
| 88 | - return $this->applyMethod('BoxCrop', $imagePath, $width,$height, $modifier); |
|
| 89 | - } |
|
| 78 | + /** |
|
| 79 | + * @param string $imagePath |
|
| 80 | + * @param string $width |
|
| 81 | + * @param string $height |
|
| 82 | + * @return string |
|
| 83 | + * @throws \Exception |
|
| 84 | + */ |
|
| 85 | + public function boxcrop($imagePath='', $width='',$height='') |
|
| 86 | + { |
|
| 87 | + $modifier = '-b' . $width . 'x' . $height; |
|
| 88 | + return $this->applyMethod('BoxCrop', $imagePath, $width,$height, $modifier); |
|
| 89 | + } |
|
| 90 | 90 | |
| 91 | - /** |
|
| 92 | - * @param $imagePath |
|
| 93 | - * @param string $modifier |
|
| 94 | - * |
|
| 95 | - * @return string |
|
| 96 | - */ |
|
| 97 | - private function modifyName($imagePath, $modifier='') |
|
| 98 | - { |
|
| 99 | - $filename = basename($imagePath); |
|
| 100 | - $path = dirname($imagePath); |
|
| 101 | - $fileParts = explode('.', $filename); |
|
| 102 | - if (count($fileParts) > 1) { |
|
| 103 | - $extension = end($fileParts); |
|
| 104 | - array_pop($fileParts); |
|
| 105 | - $fileNameWithoutExtension = implode('-', $fileParts); |
|
| 106 | - $fileNameWithoutExtension = StringUtil::slugify($fileNameWithoutExtension); |
|
| 107 | - $filename = $fileNameWithoutExtension . $modifier . '.' . $extension; |
|
| 108 | - } else { |
|
| 109 | - $filename = StringUtil::slugify($filename); |
|
| 110 | - } |
|
| 91 | + /** |
|
| 92 | + * @param $imagePath |
|
| 93 | + * @param string $modifier |
|
| 94 | + * |
|
| 95 | + * @return string |
|
| 96 | + */ |
|
| 97 | + private function modifyName($imagePath, $modifier='') |
|
| 98 | + { |
|
| 99 | + $filename = basename($imagePath); |
|
| 100 | + $path = dirname($imagePath); |
|
| 101 | + $fileParts = explode('.', $filename); |
|
| 102 | + if (count($fileParts) > 1) { |
|
| 103 | + $extension = end($fileParts); |
|
| 104 | + array_pop($fileParts); |
|
| 105 | + $fileNameWithoutExtension = implode('-', $fileParts); |
|
| 106 | + $fileNameWithoutExtension = StringUtil::slugify($fileNameWithoutExtension); |
|
| 107 | + $filename = $fileNameWithoutExtension . $modifier . '.' . $extension; |
|
| 108 | + } else { |
|
| 109 | + $filename = StringUtil::slugify($filename); |
|
| 110 | + } |
|
| 111 | 111 | |
| 112 | - if (file_exists($path . '/' . $filename)) { |
|
| 113 | - $fileParts = explode('.', $filename); |
|
| 114 | - if (count($fileParts) > 1) { |
|
| 115 | - $extension = end($fileParts); |
|
| 116 | - array_pop($fileParts); |
|
| 117 | - $fileNameWithoutExtension = implode('-', $fileParts); |
|
| 118 | - $fileNameWithoutExtension .= '-copy'; |
|
| 119 | - $filename = $fileNameWithoutExtension . '.' . $extension; |
|
| 120 | - } else { |
|
| 121 | - $filename .= '-copy'; |
|
| 122 | - } |
|
| 123 | - return $this->modifyName($path . '/' . $filename); |
|
| 124 | - } |
|
| 125 | - return $path . '/' . $filename; |
|
| 126 | - } |
|
| 112 | + if (file_exists($path . '/' . $filename)) { |
|
| 113 | + $fileParts = explode('.', $filename); |
|
| 114 | + if (count($fileParts) > 1) { |
|
| 115 | + $extension = end($fileParts); |
|
| 116 | + array_pop($fileParts); |
|
| 117 | + $fileNameWithoutExtension = implode('-', $fileParts); |
|
| 118 | + $fileNameWithoutExtension .= '-copy'; |
|
| 119 | + $filename = $fileNameWithoutExtension . '.' . $extension; |
|
| 120 | + } else { |
|
| 121 | + $filename .= '-copy'; |
|
| 122 | + } |
|
| 123 | + return $this->modifyName($path . '/' . $filename); |
|
| 124 | + } |
|
| 125 | + return $path . '/' . $filename; |
|
| 126 | + } |
|
| 127 | 127 | |
| 128 | - private function applyMethod($method, $imagePath, $width, $height, $modifier) |
|
| 129 | - { |
|
| 130 | - $method = 'CloudControl\Cms\\images\\methods\\' . $method; |
|
| 131 | - $destination = $this->modifyName($imagePath, $modifier); |
|
| 132 | - if (file_exists($imagePath)) { |
|
| 133 | - $image = new Image(); |
|
| 134 | - $image->loadImage($imagePath); |
|
| 135 | - $resize = new $method(); |
|
| 136 | - $resize->SetWidth($width); |
|
| 137 | - $resize->SetHeight($height); |
|
| 138 | - $resizedImageResource = $resize->Execute($image->getImageResource()); |
|
| 139 | - $resizedImage = new Image(); |
|
| 140 | - $resizedImage->loadImage($resizedImageResource); |
|
| 141 | - $resizedImage->saveImage($destination, $resizedImage->getImageMimeType($imagePath), 80); |
|
| 142 | - return basename($destination); |
|
| 143 | - } else { |
|
| 144 | - throw new \Exception('Image doesnt exist: ' . $imagePath); |
|
| 145 | - } |
|
| 146 | - } |
|
| 147 | - } |
|
| 128 | + private function applyMethod($method, $imagePath, $width, $height, $modifier) |
|
| 129 | + { |
|
| 130 | + $method = 'CloudControl\Cms\\images\\methods\\' . $method; |
|
| 131 | + $destination = $this->modifyName($imagePath, $modifier); |
|
| 132 | + if (file_exists($imagePath)) { |
|
| 133 | + $image = new Image(); |
|
| 134 | + $image->loadImage($imagePath); |
|
| 135 | + $resize = new $method(); |
|
| 136 | + $resize->SetWidth($width); |
|
| 137 | + $resize->SetHeight($height); |
|
| 138 | + $resizedImageResource = $resize->Execute($image->getImageResource()); |
|
| 139 | + $resizedImage = new Image(); |
|
| 140 | + $resizedImage->loadImage($resizedImageResource); |
|
| 141 | + $resizedImage->saveImage($destination, $resizedImage->getImageMimeType($imagePath), 80); |
|
| 142 | + return basename($destination); |
|
| 143 | + } else { |
|
| 144 | + throw new \Exception('Image doesnt exist: ' . $imagePath); |
|
| 145 | + } |
|
| 146 | + } |
|
| 147 | + } |
|
| 148 | 148 | } |
| 149 | 149 | \ No newline at end of file |
@@ -45,23 +45,23 @@ |
||
| 45 | 45 | */ |
| 46 | 46 | public function __construct() |
| 47 | 47 | { |
| 48 | - $rootPath = str_replace('\\', '/', realpath(str_replace('\\', '/', dirname(__FILE__)) . '/../../') . '/'); |
|
| 48 | + $rootPath = str_replace('\\', '/', realpath(str_replace('\\', '/', dirname(__FILE__)).'/../../').'/'); |
|
| 49 | 49 | |
| 50 | - self::$subfolders = '/' . str_replace('//', '/', str_replace(str_replace('\\', '/', $_SERVER['DOCUMENT_ROOT']), "", $rootPath)); |
|
| 50 | + self::$subfolders = '/'.str_replace('//', '/', str_replace(str_replace('\\', '/', $_SERVER['DOCUMENT_ROOT']), "", $rootPath)); |
|
| 51 | 51 | self::$subfolders = str_replace('//', '/', self::$subfolders); |
| 52 | 52 | if (PHP_SAPI === 'cli') { |
| 53 | 53 | global $argv; |
| 54 | 54 | array_shift($argv); |
| 55 | 55 | self::$queryString = ''; |
| 56 | - self::$requestUri = self::$subfolders . implode('/', $argv); |
|
| 56 | + self::$requestUri = self::$subfolders.implode('/', $argv); |
|
| 57 | 57 | } else { |
| 58 | 58 | self::$requestUri = $_SERVER['REQUEST_URI']; |
| 59 | 59 | self::$queryString = $_SERVER['QUERY_STRING']; |
| 60 | 60 | } |
| 61 | 61 | if (self::$subfolders === '/') { |
| 62 | - self::$relativeUri = str_replace('?' . self::$queryString, '', substr(self::$requestUri,1)); |
|
| 62 | + self::$relativeUri = str_replace('?'.self::$queryString, '', substr(self::$requestUri, 1)); |
|
| 63 | 63 | } else { |
| 64 | - self::$relativeUri = str_replace('?' . self::$queryString, '', str_replace(self::$subfolders, '', self::$requestUri)); |
|
| 64 | + self::$relativeUri = str_replace('?'.self::$queryString, '', str_replace(self::$subfolders, '', self::$requestUri)); |
|
| 65 | 65 | } |
| 66 | 66 | |
| 67 | 67 | self::$requestParameters = explode('/', self::$relativeUri); |
@@ -5,79 +5,79 @@ |
||
| 5 | 5 | * Class Request |
| 6 | 6 | * @package CloudControl\Cms\cc |
| 7 | 7 | */ |
| 8 | - class Request { |
|
| 8 | + class Request { |
|
| 9 | 9 | |
| 10 | - /** |
|
| 11 | - * @var string |
|
| 12 | - */ |
|
| 13 | - public static $subfolders; |
|
| 14 | - /** |
|
| 15 | - * @var string |
|
| 16 | - */ |
|
| 17 | - public static $requestUri; |
|
| 18 | - /** |
|
| 19 | - * @var string |
|
| 20 | - */ |
|
| 21 | - public static $relativeUri; |
|
| 22 | - /** |
|
| 23 | - * @var string |
|
| 24 | - */ |
|
| 25 | - public static $queryString; |
|
| 26 | - /** |
|
| 27 | - * @var array |
|
| 28 | - */ |
|
| 29 | - public static $requestParameters; |
|
| 30 | - /** |
|
| 31 | - * @var array |
|
| 32 | - */ |
|
| 33 | - public static $post = array(); |
|
| 34 | - /** |
|
| 35 | - * @var array |
|
| 36 | - */ |
|
| 37 | - public static $get = array(); |
|
| 38 | - /** |
|
| 39 | - * @var array |
|
| 40 | - */ |
|
| 41 | - private $statics = array(); |
|
| 10 | + /** |
|
| 11 | + * @var string |
|
| 12 | + */ |
|
| 13 | + public static $subfolders; |
|
| 14 | + /** |
|
| 15 | + * @var string |
|
| 16 | + */ |
|
| 17 | + public static $requestUri; |
|
| 18 | + /** |
|
| 19 | + * @var string |
|
| 20 | + */ |
|
| 21 | + public static $relativeUri; |
|
| 22 | + /** |
|
| 23 | + * @var string |
|
| 24 | + */ |
|
| 25 | + public static $queryString; |
|
| 26 | + /** |
|
| 27 | + * @var array |
|
| 28 | + */ |
|
| 29 | + public static $requestParameters; |
|
| 30 | + /** |
|
| 31 | + * @var array |
|
| 32 | + */ |
|
| 33 | + public static $post = array(); |
|
| 34 | + /** |
|
| 35 | + * @var array |
|
| 36 | + */ |
|
| 37 | + public static $get = array(); |
|
| 38 | + /** |
|
| 39 | + * @var array |
|
| 40 | + */ |
|
| 41 | + private $statics = array(); |
|
| 42 | 42 | |
| 43 | - /** |
|
| 44 | - * Request constructor. |
|
| 45 | - */ |
|
| 46 | - public function __construct() |
|
| 47 | - { |
|
| 43 | + /** |
|
| 44 | + * Request constructor. |
|
| 45 | + */ |
|
| 46 | + public function __construct() |
|
| 47 | + { |
|
| 48 | 48 | $rootPath = str_replace('\\', '/', realpath(str_replace('\\', '/', dirname(__FILE__)) . '/../../') . '/'); |
| 49 | 49 | |
| 50 | - self::$subfolders = '/' . str_replace('//', '/', str_replace(str_replace('\\', '/', $_SERVER['DOCUMENT_ROOT']), "", $rootPath)); |
|
| 51 | - self::$subfolders = str_replace('//', '/', self::$subfolders); |
|
| 52 | - if (PHP_SAPI === 'cli') { |
|
| 53 | - global $argv; |
|
| 54 | - array_shift($argv); |
|
| 55 | - self::$queryString = ''; |
|
| 56 | - self::$requestUri = self::$subfolders . implode('/', $argv); |
|
| 57 | - } else { |
|
| 58 | - self::$requestUri = $_SERVER['REQUEST_URI']; |
|
| 59 | - self::$queryString = $_SERVER['QUERY_STRING']; |
|
| 60 | - } |
|
| 61 | - if (self::$subfolders === '/') { |
|
| 62 | - self::$relativeUri = str_replace('?' . self::$queryString, '', substr(self::$requestUri,1)); |
|
| 63 | - } else { |
|
| 64 | - self::$relativeUri = str_replace('?' . self::$queryString, '', str_replace(self::$subfolders, '', self::$requestUri)); |
|
| 65 | - } |
|
| 50 | + self::$subfolders = '/' . str_replace('//', '/', str_replace(str_replace('\\', '/', $_SERVER['DOCUMENT_ROOT']), "", $rootPath)); |
|
| 51 | + self::$subfolders = str_replace('//', '/', self::$subfolders); |
|
| 52 | + if (PHP_SAPI === 'cli') { |
|
| 53 | + global $argv; |
|
| 54 | + array_shift($argv); |
|
| 55 | + self::$queryString = ''; |
|
| 56 | + self::$requestUri = self::$subfolders . implode('/', $argv); |
|
| 57 | + } else { |
|
| 58 | + self::$requestUri = $_SERVER['REQUEST_URI']; |
|
| 59 | + self::$queryString = $_SERVER['QUERY_STRING']; |
|
| 60 | + } |
|
| 61 | + if (self::$subfolders === '/') { |
|
| 62 | + self::$relativeUri = str_replace('?' . self::$queryString, '', substr(self::$requestUri,1)); |
|
| 63 | + } else { |
|
| 64 | + self::$relativeUri = str_replace('?' . self::$queryString, '', str_replace(self::$subfolders, '', self::$requestUri)); |
|
| 65 | + } |
|
| 66 | 66 | |
| 67 | - self::$requestParameters = explode('/', self::$relativeUri); |
|
| 67 | + self::$requestParameters = explode('/', self::$relativeUri); |
|
| 68 | 68 | |
| 69 | - self::$get = $_GET; |
|
| 70 | - self::$post = $_POST; |
|
| 69 | + self::$get = $_GET; |
|
| 70 | + self::$post = $_POST; |
|
| 71 | 71 | |
| 72 | - $this->statics = array( |
|
| 73 | - 'subfolders' => self::$subfolders, |
|
| 74 | - 'requestUri' => self::$requestUri, |
|
| 75 | - 'relativeUri' => self::$relativeUri, |
|
| 76 | - 'queryString' => self::$queryString, |
|
| 77 | - 'requestParameters' => self::$requestParameters, |
|
| 78 | - 'post' => self::$post, |
|
| 79 | - 'get' => self::$get |
|
| 80 | - ); |
|
| 81 | - } |
|
| 82 | - } |
|
| 72 | + $this->statics = array( |
|
| 73 | + 'subfolders' => self::$subfolders, |
|
| 74 | + 'requestUri' => self::$requestUri, |
|
| 75 | + 'relativeUri' => self::$relativeUri, |
|
| 76 | + 'queryString' => self::$queryString, |
|
| 77 | + 'requestParameters' => self::$requestParameters, |
|
| 78 | + 'post' => self::$post, |
|
| 79 | + 'get' => self::$get |
|
| 80 | + ); |
|
| 81 | + } |
|
| 82 | + } |
|
| 83 | 83 | } |
| 84 | 84 | \ No newline at end of file |
@@ -2,21 +2,21 @@ discard block |
||
| 2 | 2 | | THE FOLLOWING ERROR OCCURED | |
| 3 | 3 | ------------------------------------------------------------------------------------------------------------------------------------------------ |
| 4 | 4 | |
| 5 | - <?php echo $message . PHP_EOL; ?> |
|
| 5 | + <?php echo $message.PHP_EOL; ?> |
|
| 6 | 6 | |
| 7 | 7 | ------------------------------------------------------------------------------------------------------------------------------------------------ |
| 8 | 8 | | IN FILE | |
| 9 | 9 | ------------------------------------------------------------------------------------------------------------------------------------------------ |
| 10 | 10 | |
| 11 | - <?php echo $file . ':' . $line . PHP_EOL; ?> |
|
| 11 | + <?php echo $file.':'.$line.PHP_EOL; ?> |
|
| 12 | 12 | |
| 13 | 13 | ------------------------------------------------------------------------------------------------------------------------------------------------ |
| 14 | 14 | | CONTENTS OF THE FILE | |
| 15 | 15 | ------------------------------------------------------------------------------------------------------------------------------------------------ |
| 16 | 16 | |
| 17 | 17 | <?php |
| 18 | -foreach($lines as $nr => $currentLine) { |
|
| 19 | - echo ($nr == $line ? '* ' : ' ' ) . str_pad($nr, 3, "0", STR_PAD_LEFT) . ' ' . $currentLine; |
|
| 18 | +foreach ($lines as $nr => $currentLine) { |
|
| 19 | + echo ($nr == $line ? '* ' : ' ').str_pad($nr, 3, "0", STR_PAD_LEFT).' '.$currentLine; |
|
| 20 | 20 | } |
| 21 | 21 | ?> |
| 22 | 22 | |
@@ -25,11 +25,11 @@ discard block |
||
| 25 | 25 | ------------------------------------------------------------------------------------------------------------------------------------------------ |
| 26 | 26 | |
| 27 | 27 | <?php |
| 28 | -foreach($trace as $row) { |
|
| 29 | - echo (isset($row['file']) ? basename($row['file']) : '') . ':' |
|
| 30 | - . (isset($row['line']) ? $row['line'] : '') . "\t\t\t" |
|
| 31 | - . (isset($row['class']) ? $row['class'] : ' ') . "\t\t\t" |
|
| 32 | - . (isset($row['type']) ? $row['type'] : ' ') . "\t\t\t" |
|
| 33 | - . (isset($row['function']) ? $row['function'] : ' ') . PHP_EOL; |
|
| 28 | +foreach ($trace as $row) { |
|
| 29 | + echo (isset($row['file']) ? basename($row['file']) : '').':' |
|
| 30 | + . (isset($row['line']) ? $row['line'] : '')."\t\t\t" |
|
| 31 | + . (isset($row['class']) ? $row['class'] : ' ')."\t\t\t" |
|
| 32 | + . (isset($row['type']) ? $row['type'] : ' ')."\t\t\t" |
|
| 33 | + . (isset($row['function']) ? $row['function'] : ' ').PHP_EOL; |
|
| 34 | 34 | } |
| 35 | 35 | ?> |
| 36 | 36 | \ No newline at end of file |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | |
| 17 | 17 | <?php |
| 18 | 18 | foreach($lines as $nr => $currentLine) { |
| 19 | - echo ($nr == $line ? '* ' : ' ' ) . str_pad($nr, 3, "0", STR_PAD_LEFT) . ' ' . $currentLine; |
|
| 19 | + echo ($nr == $line ? '* ' : ' ' ) . str_pad($nr, 3, "0", STR_PAD_LEFT) . ' ' . $currentLine; |
|
| 20 | 20 | } |
| 21 | 21 | ?> |
| 22 | 22 | |
@@ -26,10 +26,10 @@ discard block |
||
| 26 | 26 | |
| 27 | 27 | <?php |
| 28 | 28 | foreach($trace as $row) { |
| 29 | - echo (isset($row['file']) ? basename($row['file']) : '') . ':' |
|
| 30 | - . (isset($row['line']) ? $row['line'] : '') . "\t\t\t" |
|
| 31 | - . (isset($row['class']) ? $row['class'] : ' ') . "\t\t\t" |
|
| 32 | - . (isset($row['type']) ? $row['type'] : ' ') . "\t\t\t" |
|
| 33 | - . (isset($row['function']) ? $row['function'] : ' ') . PHP_EOL; |
|
| 29 | + echo (isset($row['file']) ? basename($row['file']) : '') . ':' |
|
| 30 | + . (isset($row['line']) ? $row['line'] : '') . "\t\t\t" |
|
| 31 | + . (isset($row['class']) ? $row['class'] : ' ') . "\t\t\t" |
|
| 32 | + . (isset($row['type']) ? $row['type'] : ' ') . "\t\t\t" |
|
| 33 | + . (isset($row['function']) ? $row['function'] : ' ') . PHP_EOL; |
|
| 34 | 34 | } |
| 35 | 35 | ?> |
| 36 | 36 | \ No newline at end of file |
@@ -20,7 +20,7 @@ discard block |
||
| 20 | 20 | public static function slugify($str, $replace = array(), $delimiter = '-') |
| 21 | 21 | { |
| 22 | 22 | if (!empty($replace)) { |
| 23 | - $str = str_replace((array)$replace, ' ', $str); |
|
| 23 | + $str = str_replace((array) $replace, ' ', $str); |
|
| 24 | 24 | } |
| 25 | 25 | |
| 26 | 26 | $clean = iconv('UTF-8', 'ASCII//TRANSLIT//IGNORE', $str); |
@@ -79,13 +79,13 @@ discard block |
||
| 79 | 79 | public static function humanFileSize($size, $unit = "") |
| 80 | 80 | { |
| 81 | 81 | if ((!$unit && $size >= 1 << 30) || $unit == "GB") |
| 82 | - return number_format($size / (1 << 30), 2) . "GB"; |
|
| 82 | + return number_format($size / (1 << 30), 2)."GB"; |
|
| 83 | 83 | if ((!$unit && $size >= 1 << 20) || $unit == "MB") |
| 84 | - return number_format($size / (1 << 20), 2) . "MB"; |
|
| 84 | + return number_format($size / (1 << 20), 2)."MB"; |
|
| 85 | 85 | if ((!$unit && $size >= 1 << 10) || $unit == "KB") |
| 86 | - return number_format($size / (1 << 10), 2) . "KB"; |
|
| 86 | + return number_format($size / (1 << 10), 2)."KB"; |
|
| 87 | 87 | |
| 88 | - return number_format($size) . " bytes"; |
|
| 88 | + return number_format($size)." bytes"; |
|
| 89 | 89 | } |
| 90 | 90 | |
| 91 | 91 | /** |
@@ -121,7 +121,7 @@ discard block |
||
| 121 | 121 | if ($d >= 1) { |
| 122 | 122 | $r = round($d); |
| 123 | 123 | |
| 124 | - return $r . ' ' . ($r > 1 ? $a_plural[$str] : $str) . ' ago'; |
|
| 124 | + return $r.' '.($r > 1 ? $a_plural[$str] : $str).' ago'; |
|
| 125 | 125 | } |
| 126 | 126 | } |
| 127 | 127 | |
@@ -8,123 +8,123 @@ |
||
| 8 | 8 | |
| 9 | 9 | class StringUtil |
| 10 | 10 | { |
| 11 | - /** |
|
| 12 | - * Convert a string to url friendly slug |
|
| 13 | - * |
|
| 14 | - * @param string $str |
|
| 15 | - * @param array $replace |
|
| 16 | - * @param string $delimiter |
|
| 17 | - * |
|
| 18 | - * @return mixed|string |
|
| 19 | - */ |
|
| 20 | - public static function slugify($str, $replace = array(), $delimiter = '-') |
|
| 21 | - { |
|
| 22 | - if (!empty($replace)) { |
|
| 23 | - $str = str_replace((array)$replace, ' ', $str); |
|
| 24 | - } |
|
| 25 | - |
|
| 26 | - $clean = iconv('UTF-8', 'ASCII//TRANSLIT//IGNORE', $str); |
|
| 27 | - $clean = preg_replace("/[^a-zA-Z0-9\/_|+ -]/", '', $clean); |
|
| 28 | - $clean = strtolower(trim($clean, '-')); |
|
| 29 | - $clean = preg_replace("/[\/_|+ -]+/", $delimiter, $clean); |
|
| 30 | - |
|
| 31 | - return $clean; |
|
| 32 | - } |
|
| 33 | - |
|
| 34 | - /** |
|
| 35 | - * Selects the right font-awesome icon for each filetype |
|
| 36 | - * |
|
| 37 | - * @param $fileType |
|
| 38 | - * |
|
| 39 | - * @return string |
|
| 40 | - */ |
|
| 41 | - public static function iconByFileType($fileType) |
|
| 42 | - { |
|
| 43 | - $fileTypeIcons = array( |
|
| 44 | - 'image' => 'file-image-o', |
|
| 45 | - 'pdf' => 'file-pdf-o', |
|
| 46 | - 'audio' => 'file-audio-o', |
|
| 47 | - 'x-msdownload' => 'windows', |
|
| 48 | - 'application/vnd.ms-excel' => 'file-excel-o', |
|
| 49 | - 'application/msexcel' => 'file-excel-o', |
|
| 50 | - 'application/xls' => 'file-excel-o', |
|
| 51 | - 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' => 'file-excel-o', |
|
| 52 | - 'application/vnd.google-apps.spreadsheet' => 'file-excel-o', |
|
| 53 | - 'application/msword' => 'file-word-o', |
|
| 54 | - 'application/vnd.openxmlformats-officedocument.wordprocessingml.document' => 'file-word-o', |
|
| 55 | - 'application/x-rar-compressed' => 'file-archive-o', |
|
| 56 | - 'application/x-zip-compressed' => 'file-archive-o', |
|
| 57 | - 'application/zip' => 'file-archive-o', |
|
| 58 | - 'text' => 'file-text-o', |
|
| 59 | - ); |
|
| 60 | - |
|
| 61 | - foreach ($fileTypeIcons as $needle => $icon) { |
|
| 62 | - if (strpos($fileType, $needle) !== false) { |
|
| 63 | - return $icon; |
|
| 64 | - } |
|
| 65 | - } |
|
| 66 | - |
|
| 67 | - return 'file-o'; |
|
| 68 | - } |
|
| 69 | - |
|
| 70 | - /** |
|
| 71 | - * Converts an amount of bytes to a human readable |
|
| 72 | - * format |
|
| 73 | - * |
|
| 74 | - * @param $size |
|
| 75 | - * @param string $unit |
|
| 76 | - * |
|
| 77 | - * @return string |
|
| 78 | - */ |
|
| 79 | - public static function humanFileSize($size, $unit = "") |
|
| 80 | - { |
|
| 81 | - if ((!$unit && $size >= 1 << 30) || $unit == "GB") |
|
| 82 | - return number_format($size / (1 << 30), 2) . "GB"; |
|
| 83 | - if ((!$unit && $size >= 1 << 20) || $unit == "MB") |
|
| 84 | - return number_format($size / (1 << 20), 2) . "MB"; |
|
| 85 | - if ((!$unit && $size >= 1 << 10) || $unit == "KB") |
|
| 86 | - return number_format($size / (1 << 10), 2) . "KB"; |
|
| 87 | - |
|
| 88 | - return number_format($size) . " bytes"; |
|
| 89 | - } |
|
| 90 | - |
|
| 91 | - /** |
|
| 92 | - * @param $ptime |
|
| 93 | - * |
|
| 94 | - * @return string |
|
| 95 | - */ |
|
| 96 | - public static function timeElapsedString($ptime) |
|
| 97 | - { |
|
| 98 | - $etime = time() - $ptime; |
|
| 99 | - |
|
| 100 | - if ($etime < 1) { |
|
| 101 | - return '0 seconds'; |
|
| 102 | - } |
|
| 103 | - |
|
| 104 | - $a = array(365 * 24 * 60 * 60 => 'year', |
|
| 105 | - 30 * 24 * 60 * 60 => 'month', |
|
| 106 | - 24 * 60 * 60 => 'day', |
|
| 107 | - 60 * 60 => 'hour', |
|
| 108 | - 60 => 'minute', |
|
| 109 | - 1 => 'second' |
|
| 110 | - ); |
|
| 111 | - $a_plural = array('year' => 'years', |
|
| 112 | - 'month' => 'months', |
|
| 113 | - 'day' => 'days', |
|
| 114 | - 'hour' => 'hours', |
|
| 115 | - 'minute' => 'minutes', |
|
| 116 | - 'second' => 'seconds' |
|
| 117 | - ); |
|
| 118 | - |
|
| 119 | - foreach ($a as $secs => $str) { |
|
| 120 | - $d = $etime / $secs; |
|
| 121 | - if ($d >= 1) { |
|
| 122 | - $r = round($d); |
|
| 123 | - |
|
| 124 | - return $r . ' ' . ($r > 1 ? $a_plural[$str] : $str) . ' ago'; |
|
| 125 | - } |
|
| 126 | - } |
|
| 127 | - |
|
| 128 | - return 0; |
|
| 129 | - } |
|
| 11 | + /** |
|
| 12 | + * Convert a string to url friendly slug |
|
| 13 | + * |
|
| 14 | + * @param string $str |
|
| 15 | + * @param array $replace |
|
| 16 | + * @param string $delimiter |
|
| 17 | + * |
|
| 18 | + * @return mixed|string |
|
| 19 | + */ |
|
| 20 | + public static function slugify($str, $replace = array(), $delimiter = '-') |
|
| 21 | + { |
|
| 22 | + if (!empty($replace)) { |
|
| 23 | + $str = str_replace((array)$replace, ' ', $str); |
|
| 24 | + } |
|
| 25 | + |
|
| 26 | + $clean = iconv('UTF-8', 'ASCII//TRANSLIT//IGNORE', $str); |
|
| 27 | + $clean = preg_replace("/[^a-zA-Z0-9\/_|+ -]/", '', $clean); |
|
| 28 | + $clean = strtolower(trim($clean, '-')); |
|
| 29 | + $clean = preg_replace("/[\/_|+ -]+/", $delimiter, $clean); |
|
| 30 | + |
|
| 31 | + return $clean; |
|
| 32 | + } |
|
| 33 | + |
|
| 34 | + /** |
|
| 35 | + * Selects the right font-awesome icon for each filetype |
|
| 36 | + * |
|
| 37 | + * @param $fileType |
|
| 38 | + * |
|
| 39 | + * @return string |
|
| 40 | + */ |
|
| 41 | + public static function iconByFileType($fileType) |
|
| 42 | + { |
|
| 43 | + $fileTypeIcons = array( |
|
| 44 | + 'image' => 'file-image-o', |
|
| 45 | + 'pdf' => 'file-pdf-o', |
|
| 46 | + 'audio' => 'file-audio-o', |
|
| 47 | + 'x-msdownload' => 'windows', |
|
| 48 | + 'application/vnd.ms-excel' => 'file-excel-o', |
|
| 49 | + 'application/msexcel' => 'file-excel-o', |
|
| 50 | + 'application/xls' => 'file-excel-o', |
|
| 51 | + 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' => 'file-excel-o', |
|
| 52 | + 'application/vnd.google-apps.spreadsheet' => 'file-excel-o', |
|
| 53 | + 'application/msword' => 'file-word-o', |
|
| 54 | + 'application/vnd.openxmlformats-officedocument.wordprocessingml.document' => 'file-word-o', |
|
| 55 | + 'application/x-rar-compressed' => 'file-archive-o', |
|
| 56 | + 'application/x-zip-compressed' => 'file-archive-o', |
|
| 57 | + 'application/zip' => 'file-archive-o', |
|
| 58 | + 'text' => 'file-text-o', |
|
| 59 | + ); |
|
| 60 | + |
|
| 61 | + foreach ($fileTypeIcons as $needle => $icon) { |
|
| 62 | + if (strpos($fileType, $needle) !== false) { |
|
| 63 | + return $icon; |
|
| 64 | + } |
|
| 65 | + } |
|
| 66 | + |
|
| 67 | + return 'file-o'; |
|
| 68 | + } |
|
| 69 | + |
|
| 70 | + /** |
|
| 71 | + * Converts an amount of bytes to a human readable |
|
| 72 | + * format |
|
| 73 | + * |
|
| 74 | + * @param $size |
|
| 75 | + * @param string $unit |
|
| 76 | + * |
|
| 77 | + * @return string |
|
| 78 | + */ |
|
| 79 | + public static function humanFileSize($size, $unit = "") |
|
| 80 | + { |
|
| 81 | + if ((!$unit && $size >= 1 << 30) || $unit == "GB") |
|
| 82 | + return number_format($size / (1 << 30), 2) . "GB"; |
|
| 83 | + if ((!$unit && $size >= 1 << 20) || $unit == "MB") |
|
| 84 | + return number_format($size / (1 << 20), 2) . "MB"; |
|
| 85 | + if ((!$unit && $size >= 1 << 10) || $unit == "KB") |
|
| 86 | + return number_format($size / (1 << 10), 2) . "KB"; |
|
| 87 | + |
|
| 88 | + return number_format($size) . " bytes"; |
|
| 89 | + } |
|
| 90 | + |
|
| 91 | + /** |
|
| 92 | + * @param $ptime |
|
| 93 | + * |
|
| 94 | + * @return string |
|
| 95 | + */ |
|
| 96 | + public static function timeElapsedString($ptime) |
|
| 97 | + { |
|
| 98 | + $etime = time() - $ptime; |
|
| 99 | + |
|
| 100 | + if ($etime < 1) { |
|
| 101 | + return '0 seconds'; |
|
| 102 | + } |
|
| 103 | + |
|
| 104 | + $a = array(365 * 24 * 60 * 60 => 'year', |
|
| 105 | + 30 * 24 * 60 * 60 => 'month', |
|
| 106 | + 24 * 60 * 60 => 'day', |
|
| 107 | + 60 * 60 => 'hour', |
|
| 108 | + 60 => 'minute', |
|
| 109 | + 1 => 'second' |
|
| 110 | + ); |
|
| 111 | + $a_plural = array('year' => 'years', |
|
| 112 | + 'month' => 'months', |
|
| 113 | + 'day' => 'days', |
|
| 114 | + 'hour' => 'hours', |
|
| 115 | + 'minute' => 'minutes', |
|
| 116 | + 'second' => 'seconds' |
|
| 117 | + ); |
|
| 118 | + |
|
| 119 | + foreach ($a as $secs => $str) { |
|
| 120 | + $d = $etime / $secs; |
|
| 121 | + if ($d >= 1) { |
|
| 122 | + $r = round($d); |
|
| 123 | + |
|
| 124 | + return $r . ' ' . ($r > 1 ? $a_plural[$str] : $str) . ' ago'; |
|
| 125 | + } |
|
| 126 | + } |
|
| 127 | + |
|
| 128 | + return 0; |
|
| 129 | + } |
|
| 130 | 130 | } |
| 131 | 131 | \ No newline at end of file |
@@ -9,7 +9,7 @@ discard block |
||
| 9 | 9 | { ?> |
| 10 | 10 | <div class="grid-box-10"> |
| 11 | 11 | <h3> |
| 12 | - <a class="btn documentTitle" href="<?= $request::$subfolders ?><?= $cmsPrefix ?>/documents/edit-document?slug=<?= $slugPrefix . $document->slug ?>" title="Edit"> |
|
| 12 | + <a class="btn documentTitle" href="<?= $request::$subfolders ?><?= $cmsPrefix ?>/documents/edit-document?slug=<?= $slugPrefix.$document->slug ?>" title="Edit"> |
|
| 13 | 13 | <i class="fa fa-file-text-o"></i> |
| 14 | 14 | <small class="state <?= strtolower($document->state) ?>"> |
| 15 | 15 | <i class="fa <?= $document->state == 'published' ? 'fa-check-circle-o' : 'fa-times-circle-o' ?>"></i></small> |
@@ -32,23 +32,23 @@ discard block |
||
| 32 | 32 | <? if ($document->state == 'unpublished' || $document->unpublishedChanges) : ?> |
| 33 | 33 | <? renderAction('Publish', |
| 34 | 34 | 'publish', |
| 35 | - $request::$subfolders . $cmsPrefix . '/documents/publish-document?slug=' . $slugPrefix . $document->slug, |
|
| 35 | + $request::$subfolders.$cmsPrefix.'/documents/publish-document?slug='.$slugPrefix.$document->slug, |
|
| 36 | 36 | 'check'); ?> |
| 37 | 37 | <? endif ?> |
| 38 | 38 | <? if ($document->state == 'published') : ?> |
| 39 | 39 | <? renderAction('Unpublish', |
| 40 | 40 | 'unpublish', |
| 41 | - $request::$subfolders . $cmsPrefix . '/documents/unpublish-document?slug=' . $slugPrefix . $document->slug, |
|
| 41 | + $request::$subfolders.$cmsPrefix.'/documents/unpublish-document?slug='.$slugPrefix.$document->slug, |
|
| 42 | 42 | 'times'); ?> |
| 43 | 43 | <? endif ?> |
| 44 | 44 | <? renderAction('Edit', |
| 45 | 45 | '', |
| 46 | - $request::$subfolders . $cmsPrefix . '/documents/edit-document?slug=' . $slugPrefix . $document->slug, |
|
| 46 | + $request::$subfolders.$cmsPrefix.'/documents/edit-document?slug='.$slugPrefix.$document->slug, |
|
| 47 | 47 | 'pencil'); ?> |
| 48 | 48 | <? if ($document->state == 'unpublished') : ?> |
| 49 | 49 | <? renderAction('Delete', |
| 50 | 50 | 'error', |
| 51 | - $request::$subfolders . $cmsPrefix . '/documents/delete-document?slug=' . $slugPrefix . $document->slug, |
|
| 51 | + $request::$subfolders.$cmsPrefix.'/documents/delete-document?slug='.$slugPrefix.$document->slug, |
|
| 52 | 52 | 'trash', |
| 53 | 53 | 'return confirm(\'Are you sure you want to delete this document?\');'); ?> |
| 54 | 54 | <? endif ?> |
@@ -31,26 +31,26 @@ |
||
| 31 | 31 | <div class="documentActions grid-box-2"> |
| 32 | 32 | <? if ($document->state == 'unpublished' || $document->unpublishedChanges) : ?> |
| 33 | 33 | <? renderAction('Publish', |
| 34 | - 'publish', |
|
| 35 | - $request::$subfolders . $cmsPrefix . '/documents/publish-document?slug=' . $slugPrefix . $document->slug, |
|
| 36 | - 'check'); ?> |
|
| 34 | + 'publish', |
|
| 35 | + $request::$subfolders . $cmsPrefix . '/documents/publish-document?slug=' . $slugPrefix . $document->slug, |
|
| 36 | + 'check'); ?> |
|
| 37 | 37 | <? endif ?> |
| 38 | 38 | <? if ($document->state == 'published') : ?> |
| 39 | 39 | <? renderAction('Unpublish', |
| 40 | - 'unpublish', |
|
| 41 | - $request::$subfolders . $cmsPrefix . '/documents/unpublish-document?slug=' . $slugPrefix . $document->slug, |
|
| 42 | - 'times'); ?> |
|
| 40 | + 'unpublish', |
|
| 41 | + $request::$subfolders . $cmsPrefix . '/documents/unpublish-document?slug=' . $slugPrefix . $document->slug, |
|
| 42 | + 'times'); ?> |
|
| 43 | 43 | <? endif ?> |
| 44 | 44 | <? renderAction('Edit', |
| 45 | - '', |
|
| 46 | - $request::$subfolders . $cmsPrefix . '/documents/edit-document?slug=' . $slugPrefix . $document->slug, |
|
| 47 | - 'pencil'); ?> |
|
| 45 | + '', |
|
| 46 | + $request::$subfolders . $cmsPrefix . '/documents/edit-document?slug=' . $slugPrefix . $document->slug, |
|
| 47 | + 'pencil'); ?> |
|
| 48 | 48 | <? if ($document->state == 'unpublished') : ?> |
| 49 | 49 | <? renderAction('Delete', |
| 50 | - 'error', |
|
| 51 | - $request::$subfolders . $cmsPrefix . '/documents/delete-document?slug=' . $slugPrefix . $document->slug, |
|
| 52 | - 'trash', |
|
| 53 | - 'return confirm(\'Are you sure you want to delete this document?\');'); ?> |
|
| 50 | + 'error', |
|
| 51 | + $request::$subfolders . $cmsPrefix . '/documents/delete-document?slug=' . $slugPrefix . $document->slug, |
|
| 52 | + 'trash', |
|
| 53 | + 'return confirm(\'Are you sure you want to delete this document?\');'); ?> |
|
| 54 | 54 | <? endif ?> |
| 55 | 55 | </div> |
| 56 | 56 | <? } ?> |
@@ -4,9 +4,9 @@ discard block |
||
| 4 | 4 | </div> |
| 5 | 5 | <label><?= $brick->title ?></label> |
| 6 | 6 | <? if ($static == true) { |
| 7 | - $fieldPrefix = 'bricks[' . $myBrickSlug . '][' . str_replace('.', '', str_replace(' ', '', microtime())) . '][fields]'; |
|
| 7 | + $fieldPrefix = 'bricks['.$myBrickSlug.']['.str_replace('.', '', str_replace(' ', '', microtime())).'][fields]'; |
|
| 8 | 8 | } else { |
| 9 | - $fieldPrefix = 'dynamicBricks[' . $brick->slug . '][' . str_replace('.', '', str_replace(' ', '', microtime())) . ']'; |
|
| 9 | + $fieldPrefix = 'dynamicBricks['.$brick->slug.']['.str_replace('.', '', str_replace(' ', '', microtime())).']'; |
|
| 10 | 10 | } ?> |
| 11 | 11 | <? foreach ($brick->fields as $field) : ?> |
| 12 | 12 | <div class="form-element"> |
@@ -31,7 +31,7 @@ discard block |
||
| 31 | 31 | <a class="btn move ui-sortable-handle"><i class="fa fa-arrows-v"></i></a> |
| 32 | 32 | <div class="form-element"> |
| 33 | 33 | <? endif ?> |
| 34 | - <? include(__DIR__ . '/fieldTypes/' . str_replace(' ', '-', $field->type) . '.php') ?> |
|
| 34 | + <? include(__DIR__.'/fieldTypes/'.str_replace(' ', '-', $field->type).'.php') ?> |
|
| 35 | 35 | <? if ($field->multiple == true && $field->type != 'Rich Text') : ?> |
| 36 | 36 | |
| 37 | 37 | </div> |
@@ -53,7 +53,7 @@ discard block |
||
| 53 | 53 | <li class="grid-container"> |
| 54 | 54 | <div class="grid-box-10"> |
| 55 | 55 | <div class="grid-inner form-element"> |
| 56 | - <? include(__DIR__ . '/fieldTypes/' . str_replace(' ', '-', $field->type) . '.php') ?> |
|
| 56 | + <? include(__DIR__.'/fieldTypes/'.str_replace(' ', '-', $field->type).'.php') ?> |
|
| 57 | 57 | </div> |
| 58 | 58 | </div> |
| 59 | 59 | <div class="grid-box-2"> |
@@ -63,7 +63,7 @@ discard block |
||
| 63 | 63 | </div> |
| 64 | 64 | </div> |
| 65 | 65 | </li> |
| 66 | - <?$value='';?> |
|
| 66 | + <?$value = ''; ?> |
|
| 67 | 67 | <? endforeach ?> |
| 68 | 68 | <? endif ?> |
| 69 | 69 | </ul> |
@@ -80,10 +80,10 @@ discard block |
||
| 80 | 80 | <a class="btn error js-deletemultiple"><i class="fa fa-trash"></i></a> |
| 81 | 81 | <a class="btn move ui-sortable-handle"><i class="fa fa-arrows-v"></i></a> |
| 82 | 82 | <div class="form-element"> |
| 83 | - <? include(__DIR__ . '/fieldTypes/' . str_replace(' ', '-', $field->type) . '.php') ?> |
|
| 83 | + <? include(__DIR__.'/fieldTypes/'.str_replace(' ', '-', $field->type).'.php') ?> |
|
| 84 | 84 | </div> |
| 85 | 85 | </li> |
| 86 | - <?$value='';?> |
|
| 86 | + <?$value = ''; ?> |
|
| 87 | 87 | <? endforeach ?> |
| 88 | 88 | <? endif ?> |
| 89 | 89 | </div> |
@@ -92,5 +92,5 @@ discard block |
||
| 92 | 92 | <a class="btn js-addrtemultiple">+</a> |
| 93 | 93 | <? endif ?> |
| 94 | 94 | </div> |
| 95 | - <?$value='';?> |
|
| 95 | + <?$value = ''; ?> |
|
| 96 | 96 | <? endforeach ?> |
@@ -12,11 +12,11 @@ discard block |
||
| 12 | 12 | <div class="form-element"> |
| 13 | 13 | <label for="<?=$field->slug?>"><?=$field->title?></label> |
| 14 | 14 | <? if (isset($dynamicBrick)) : |
| 15 | - $fieldSlug = $field->slug; |
|
| 16 | - $value = isset($dynamicBrick->fields->$fieldSlug) ? current($dynamicBrick->fields->$fieldSlug) : ''; |
|
| 17 | - else : |
|
| 18 | - $value = ''; |
|
| 19 | - endif ?> |
|
| 15 | + $fieldSlug = $field->slug; |
|
| 16 | + $value = isset($dynamicBrick->fields->$fieldSlug) ? current($dynamicBrick->fields->$fieldSlug) : ''; |
|
| 17 | + else : |
|
| 18 | + $value = ''; |
|
| 19 | + endif ?> |
|
| 20 | 20 | <? if ($field->multiple == true && $field->type != 'Rich Text') : ?> |
| 21 | 21 | <ul class="grid-wrapper sortable"> |
| 22 | 22 | <li class="grid-container"> |
@@ -44,10 +44,10 @@ discard block |
||
| 44 | 44 | </div> |
| 45 | 45 | </li> |
| 46 | 46 | <? if (isset($dynamicBrick)) : |
| 47 | - $fieldSlug = $field->slug; |
|
| 48 | - $iterable = isset($dynamicBrick->fields->$fieldSlug) ? $dynamicBrick->fields->$fieldSlug : array(); |
|
| 49 | - array_shift($iterable); |
|
| 50 | - ?> |
|
| 47 | + $fieldSlug = $field->slug; |
|
| 48 | + $iterable = isset($dynamicBrick->fields->$fieldSlug) ? $dynamicBrick->fields->$fieldSlug : array(); |
|
| 49 | + array_shift($iterable); |
|
| 50 | + ?> |
|
| 51 | 51 | <? foreach ($iterable as $value) : ?> |
| 52 | 52 | |
| 53 | 53 | <li class="grid-container"> |
@@ -70,10 +70,10 @@ discard block |
||
| 70 | 70 | <a class="btn js-addmultiple">+</a> |
| 71 | 71 | <? elseif ($field->multiple == true) : ?> |
| 72 | 72 | <? if (isset($dynamicBrick)) : |
| 73 | - $fieldSlug = $field->slug; |
|
| 74 | - $iterable = isset($dynamicBrick->fields->$fieldSlug) ? $dynamicBrick->fields->$fieldSlug : array(); |
|
| 75 | - array_shift($iterable); |
|
| 76 | - ?> |
|
| 73 | + $fieldSlug = $field->slug; |
|
| 74 | + $iterable = isset($dynamicBrick->fields->$fieldSlug) ? $dynamicBrick->fields->$fieldSlug : array(); |
|
| 75 | + array_shift($iterable); |
|
| 76 | + ?> |
|
| 77 | 77 | <? foreach ($iterable as $value) : ?> |
| 78 | 78 | |
| 79 | 79 | <li> |