@@ -16,18 +16,18 @@ |
||
16 | 16 | class ReportToViewHelper extends AbstractViewHelper |
17 | 17 | { |
18 | 18 | |
19 | - /** |
|
20 | - * Returns the people who will receive a report. |
|
21 | - * |
|
22 | - * @throws \Exception |
|
23 | - * @return string |
|
24 | - */ |
|
25 | - public function render() |
|
26 | - { |
|
27 | - $reportTo = 'null (Missing value in $GLOBALS[TYPO3_CONF_VARS][MAIL][defaultMailFromAddress])'; |
|
28 | - if (!empty($GLOBALS['TYPO3_CONF_VARS']['MAIL']['defaultMailFromAddress'])) { |
|
29 | - $reportTo = $GLOBALS['TYPO3_CONF_VARS']['MAIL']['defaultMailFromAddress']; |
|
30 | - } |
|
31 | - return $reportTo; |
|
32 | - } |
|
19 | + /** |
|
20 | + * Returns the people who will receive a report. |
|
21 | + * |
|
22 | + * @throws \Exception |
|
23 | + * @return string |
|
24 | + */ |
|
25 | + public function render() |
|
26 | + { |
|
27 | + $reportTo = 'null (Missing value in $GLOBALS[TYPO3_CONF_VARS][MAIL][defaultMailFromAddress])'; |
|
28 | + if (!empty($GLOBALS['TYPO3_CONF_VARS']['MAIL']['defaultMailFromAddress'])) { |
|
29 | + $reportTo = $GLOBALS['TYPO3_CONF_VARS']['MAIL']['defaultMailFromAddress']; |
|
30 | + } |
|
31 | + return $reportTo; |
|
32 | + } |
|
33 | 33 | } |
@@ -21,50 +21,50 @@ |
||
21 | 21 | class MetadataViewHelper extends AbstractViewHelper |
22 | 22 | { |
23 | 23 | |
24 | - /** |
|
25 | - * Returns metadata according to a template. |
|
26 | - * |
|
27 | - * @param File $file |
|
28 | - * @param string $template |
|
29 | - * @param array $metadataProperties |
|
30 | - * @param array $configuration |
|
31 | - * @return string |
|
32 | - */ |
|
33 | - public function render(File $file, $template = '', array $metadataProperties = array('size', 'width', 'height'), $configuration = []) |
|
34 | - { |
|
24 | + /** |
|
25 | + * Returns metadata according to a template. |
|
26 | + * |
|
27 | + * @param File $file |
|
28 | + * @param string $template |
|
29 | + * @param array $metadataProperties |
|
30 | + * @param array $configuration |
|
31 | + * @return string |
|
32 | + */ |
|
33 | + public function render(File $file, $template = '', array $metadataProperties = array('size', 'width', 'height'), $configuration = []) |
|
34 | + { |
|
35 | 35 | |
36 | - if (empty($template)) { |
|
37 | - $template = $this->getDefaultTemplate($file); |
|
38 | - } |
|
36 | + if (empty($template)) { |
|
37 | + $template = $this->getDefaultTemplate($file); |
|
38 | + } |
|
39 | 39 | |
40 | - $result = $template; |
|
41 | - foreach ($metadataProperties as $metadataProperty) { |
|
42 | - $value = $file->getProperty($metadataProperty); |
|
43 | - if ($metadataProperty === 'size') { |
|
44 | - $sizeUnit = empty($configuration['sizeUnit']) ? 1000 : $configuration['sizeUnit']; |
|
45 | - $value = round($file->getSize() / $sizeUnit); |
|
46 | - } |
|
47 | - $result = str_replace('%' . $metadataProperty, $value, $result); |
|
48 | - } |
|
40 | + $result = $template; |
|
41 | + foreach ($metadataProperties as $metadataProperty) { |
|
42 | + $value = $file->getProperty($metadataProperty); |
|
43 | + if ($metadataProperty === 'size') { |
|
44 | + $sizeUnit = empty($configuration['sizeUnit']) ? 1000 : $configuration['sizeUnit']; |
|
45 | + $value = round($file->getSize() / $sizeUnit); |
|
46 | + } |
|
47 | + $result = str_replace('%' . $metadataProperty, $value, $result); |
|
48 | + } |
|
49 | 49 | |
50 | - return $result; |
|
51 | - } |
|
50 | + return $result; |
|
51 | + } |
|
52 | 52 | |
53 | - /** |
|
54 | - * Returns a default template. |
|
55 | - * |
|
56 | - * @param File $file |
|
57 | - * @return string |
|
58 | - */ |
|
59 | - protected function getDefaultTemplate(File $file) |
|
60 | - { |
|
53 | + /** |
|
54 | + * Returns a default template. |
|
55 | + * |
|
56 | + * @param File $file |
|
57 | + * @return string |
|
58 | + */ |
|
59 | + protected function getDefaultTemplate(File $file) |
|
60 | + { |
|
61 | 61 | |
62 | - $template = '%size KB'; |
|
62 | + $template = '%size KB'; |
|
63 | 63 | |
64 | - if ($file->getType() == File::FILETYPE_IMAGE) { |
|
65 | - $template = '%width x %height - ' . $template; |
|
66 | - } |
|
64 | + if ($file->getType() == File::FILETYPE_IMAGE) { |
|
65 | + $template = '%width x %height - ' . $template; |
|
66 | + } |
|
67 | 67 | |
68 | - return $template; |
|
69 | - } |
|
68 | + return $template; |
|
69 | + } |
|
70 | 70 | } |
@@ -44,7 +44,7 @@ discard block |
||
44 | 44 | $sizeUnit = empty($configuration['sizeUnit']) ? 1000 : $configuration['sizeUnit']; |
45 | 45 | $value = round($file->getSize() / $sizeUnit); |
46 | 46 | } |
47 | - $result = str_replace('%' . $metadataProperty, $value, $result); |
|
47 | + $result = str_replace('%'.$metadataProperty, $value, $result); |
|
48 | 48 | } |
49 | 49 | |
50 | 50 | return $result; |
@@ -62,7 +62,7 @@ discard block |
||
62 | 62 | $template = '%size KB'; |
63 | 63 | |
64 | 64 | if ($file->getType() == File::FILETYPE_IMAGE) { |
65 | - $template = '%width x %height - ' . $template; |
|
65 | + $template = '%width x %height - '.$template; |
|
66 | 66 | } |
67 | 67 | |
68 | 68 | return $template; |
@@ -17,11 +17,11 @@ discard block |
||
17 | 17 | class ConfigurationArrayConverter extends ArrayConverter |
18 | 18 | { |
19 | 19 | |
20 | - /** |
|
21 | - * Match configuration options (to parse actual options) |
|
22 | - * @var string |
|
23 | - */ |
|
24 | - const PATTERN_MATCH_CONFIGURATIONOPTIONS = '/ |
|
20 | + /** |
|
21 | + * Match configuration options (to parse actual options) |
|
22 | + * @var string |
|
23 | + */ |
|
24 | + const PATTERN_MATCH_CONFIGURATIONOPTIONS = '/ |
|
25 | 25 | \s* |
26 | 26 | (?P<optionName>[a-z0-9]+) |
27 | 27 | \s*=\s* |
@@ -32,84 +32,84 @@ discard block |
||
32 | 32 | ) |
33 | 33 | /ixS'; |
34 | 34 | |
35 | - /** |
|
36 | - * We can only convert empty strings to array or array to array. |
|
37 | - * |
|
38 | - * @param mixed $source |
|
39 | - * @param string $targetType |
|
40 | - * @return boolean |
|
41 | - */ |
|
42 | - public function canConvertFrom($source, $targetType) |
|
43 | - { |
|
44 | - return is_string($source) || is_array($source); |
|
45 | - } |
|
35 | + /** |
|
36 | + * We can only convert empty strings to array or array to array. |
|
37 | + * |
|
38 | + * @param mixed $source |
|
39 | + * @param string $targetType |
|
40 | + * @return boolean |
|
41 | + */ |
|
42 | + public function canConvertFrom($source, $targetType) |
|
43 | + { |
|
44 | + return is_string($source) || is_array($source); |
|
45 | + } |
|
46 | 46 | |
47 | - /** |
|
48 | - * Convert from $source to $targetType, a noop if the source is an array. |
|
49 | - * If it is an empty string it will be converted to an empty array. |
|
50 | - * |
|
51 | - * @param string|array $source |
|
52 | - * @param string $targetType |
|
53 | - * @param array $convertedChildProperties |
|
54 | - * @param PropertyMappingConfigurationInterface $configuration |
|
55 | - * @return array |
|
56 | - * @api |
|
57 | - */ |
|
58 | - public function convertFrom($source, $targetType, array $convertedChildProperties = [], PropertyMappingConfigurationInterface $configuration = null) |
|
59 | - { |
|
60 | - if (is_string($source)) { |
|
61 | - if ($source === '') { |
|
62 | - $target = []; |
|
63 | - } else { |
|
64 | - $target = $this->parseConfigurationOptions($source); |
|
65 | - } |
|
66 | - } |
|
47 | + /** |
|
48 | + * Convert from $source to $targetType, a noop if the source is an array. |
|
49 | + * If it is an empty string it will be converted to an empty array. |
|
50 | + * |
|
51 | + * @param string|array $source |
|
52 | + * @param string $targetType |
|
53 | + * @param array $convertedChildProperties |
|
54 | + * @param PropertyMappingConfigurationInterface $configuration |
|
55 | + * @return array |
|
56 | + * @api |
|
57 | + */ |
|
58 | + public function convertFrom($source, $targetType, array $convertedChildProperties = [], PropertyMappingConfigurationInterface $configuration = null) |
|
59 | + { |
|
60 | + if (is_string($source)) { |
|
61 | + if ($source === '') { |
|
62 | + $target = []; |
|
63 | + } else { |
|
64 | + $target = $this->parseConfigurationOptions($source); |
|
65 | + } |
|
66 | + } |
|
67 | 67 | |
68 | - if (is_array($source)) { |
|
69 | - $target = $source; |
|
70 | - } |
|
68 | + if (is_array($source)) { |
|
69 | + $target = $source; |
|
70 | + } |
|
71 | 71 | |
72 | - return $target; |
|
73 | - } |
|
72 | + return $target; |
|
73 | + } |
|
74 | 74 | |
75 | - /** |
|
76 | - * Parses $rawValidatorOptions not containing quoted option values. |
|
77 | - * $rawValidatorOptions will be an empty string afterwards (pass by ref!). |
|
78 | - * |
|
79 | - * @param string $rawValidatorOptions |
|
80 | - * @return array An array of optionName/optionValue pairs |
|
81 | - */ |
|
82 | - protected function parseConfigurationOptions($rawConfigurationOptions) |
|
83 | - { |
|
84 | - $configurationOptions = []; |
|
85 | - $parsedConfigurationOptions = []; |
|
86 | - preg_match_all(self::PATTERN_MATCH_CONFIGURATIONOPTIONS, $rawConfigurationOptions, $configurationOptions, PREG_SET_ORDER); |
|
87 | - foreach ($configurationOptions as $configurationOption) { |
|
88 | - $parsedConfigurationOptions[trim($configurationOption['optionName'])] = trim($configurationOption['optionValue']); |
|
89 | - } |
|
90 | - array_walk($parsedConfigurationOptions, array($this, 'unquoteString')); |
|
91 | - return $parsedConfigurationOptions; |
|
92 | - } |
|
75 | + /** |
|
76 | + * Parses $rawValidatorOptions not containing quoted option values. |
|
77 | + * $rawValidatorOptions will be an empty string afterwards (pass by ref!). |
|
78 | + * |
|
79 | + * @param string $rawValidatorOptions |
|
80 | + * @return array An array of optionName/optionValue pairs |
|
81 | + */ |
|
82 | + protected function parseConfigurationOptions($rawConfigurationOptions) |
|
83 | + { |
|
84 | + $configurationOptions = []; |
|
85 | + $parsedConfigurationOptions = []; |
|
86 | + preg_match_all(self::PATTERN_MATCH_CONFIGURATIONOPTIONS, $rawConfigurationOptions, $configurationOptions, PREG_SET_ORDER); |
|
87 | + foreach ($configurationOptions as $configurationOption) { |
|
88 | + $parsedConfigurationOptions[trim($configurationOption['optionName'])] = trim($configurationOption['optionValue']); |
|
89 | + } |
|
90 | + array_walk($parsedConfigurationOptions, array($this, 'unquoteString')); |
|
91 | + return $parsedConfigurationOptions; |
|
92 | + } |
|
93 | 93 | |
94 | - /** |
|
95 | - * Removes escapings from a given argument string and trims the outermost |
|
96 | - * quotes. |
|
97 | - * |
|
98 | - * This method is meant as a helper for regular expression results. |
|
99 | - * |
|
100 | - * @param string &$quotedValue Value to unquote |
|
101 | - * @return void |
|
102 | - */ |
|
103 | - protected function unquoteString(&$quotedValue) |
|
104 | - { |
|
105 | - switch ($quotedValue[0]) { |
|
106 | - case '"': |
|
107 | - $quotedValue = str_replace('\\"', '"', trim($quotedValue, '"')); |
|
108 | - break; |
|
109 | - case '\'': |
|
110 | - $quotedValue = str_replace('\\\'', '\'', trim($quotedValue, '\'')); |
|
111 | - break; |
|
112 | - } |
|
113 | - $quotedValue = str_replace('\\\\', '\\', $quotedValue); |
|
114 | - } |
|
94 | + /** |
|
95 | + * Removes escapings from a given argument string and trims the outermost |
|
96 | + * quotes. |
|
97 | + * |
|
98 | + * This method is meant as a helper for regular expression results. |
|
99 | + * |
|
100 | + * @param string &$quotedValue Value to unquote |
|
101 | + * @return void |
|
102 | + */ |
|
103 | + protected function unquoteString(&$quotedValue) |
|
104 | + { |
|
105 | + switch ($quotedValue[0]) { |
|
106 | + case '"': |
|
107 | + $quotedValue = str_replace('\\"', '"', trim($quotedValue, '"')); |
|
108 | + break; |
|
109 | + case '\'': |
|
110 | + $quotedValue = str_replace('\\\'', '\'', trim($quotedValue, '\'')); |
|
111 | + break; |
|
112 | + } |
|
113 | + $quotedValue = str_replace('\\\\', '\\', $quotedValue); |
|
114 | + } |
|
115 | 115 | } |
116 | 116 | \ No newline at end of file |
@@ -20,124 +20,124 @@ |
||
20 | 20 | class TitleMetadataExtractor implements ExtractorInterface |
21 | 21 | { |
22 | 22 | |
23 | - /** |
|
24 | - * Returns an array of supported file types; |
|
25 | - * An empty array indicates all filetypes |
|
26 | - * |
|
27 | - * @return array |
|
28 | - */ |
|
29 | - public function getFileTypeRestrictions() |
|
30 | - { |
|
31 | - return []; |
|
32 | - } |
|
23 | + /** |
|
24 | + * Returns an array of supported file types; |
|
25 | + * An empty array indicates all filetypes |
|
26 | + * |
|
27 | + * @return array |
|
28 | + */ |
|
29 | + public function getFileTypeRestrictions() |
|
30 | + { |
|
31 | + return []; |
|
32 | + } |
|
33 | 33 | |
34 | - /** |
|
35 | - * Get all supported DriverClasses |
|
36 | - * Since some extractors may only work for local files, and other extractors |
|
37 | - * are especially made for grabbing data from remote. |
|
38 | - * Returns array of string with driver names of Drivers which are supported, |
|
39 | - * If the driver did not register a name, it's the classname. |
|
40 | - * empty array indicates no restrictions |
|
41 | - * |
|
42 | - * @return array |
|
43 | - */ |
|
44 | - public function getDriverRestrictions() |
|
45 | - { |
|
46 | - return []; |
|
47 | - } |
|
34 | + /** |
|
35 | + * Get all supported DriverClasses |
|
36 | + * Since some extractors may only work for local files, and other extractors |
|
37 | + * are especially made for grabbing data from remote. |
|
38 | + * Returns array of string with driver names of Drivers which are supported, |
|
39 | + * If the driver did not register a name, it's the classname. |
|
40 | + * empty array indicates no restrictions |
|
41 | + * |
|
42 | + * @return array |
|
43 | + */ |
|
44 | + public function getDriverRestrictions() |
|
45 | + { |
|
46 | + return []; |
|
47 | + } |
|
48 | 48 | |
49 | - /** |
|
50 | - * Returns the data priority of the extraction Service. |
|
51 | - * Defines the precedence of Data if several extractors |
|
52 | - * extracted the same property. |
|
53 | - * Should be between 1 and 100, 100 is more important than 1 |
|
54 | - * |
|
55 | - * @return integer |
|
56 | - */ |
|
57 | - public function getPriority() |
|
58 | - { |
|
59 | - return 15; |
|
60 | - } |
|
49 | + /** |
|
50 | + * Returns the data priority of the extraction Service. |
|
51 | + * Defines the precedence of Data if several extractors |
|
52 | + * extracted the same property. |
|
53 | + * Should be between 1 and 100, 100 is more important than 1 |
|
54 | + * |
|
55 | + * @return integer |
|
56 | + */ |
|
57 | + public function getPriority() |
|
58 | + { |
|
59 | + return 15; |
|
60 | + } |
|
61 | 61 | |
62 | - /** |
|
63 | - * Returns the execution priority of the extraction Service |
|
64 | - * Should be between 1 and 100, 100 means runs as first service, 1 runs at last service |
|
65 | - * |
|
66 | - * @return integer |
|
67 | - */ |
|
68 | - public function getExecutionPriority() |
|
69 | - { |
|
70 | - return 15; |
|
71 | - } |
|
62 | + /** |
|
63 | + * Returns the execution priority of the extraction Service |
|
64 | + * Should be between 1 and 100, 100 means runs as first service, 1 runs at last service |
|
65 | + * |
|
66 | + * @return integer |
|
67 | + */ |
|
68 | + public function getExecutionPriority() |
|
69 | + { |
|
70 | + return 15; |
|
71 | + } |
|
72 | 72 | |
73 | - /** |
|
74 | - * Checks if the given file can be processed by this Extractor |
|
75 | - * |
|
76 | - * @param File $file |
|
77 | - * @return boolean |
|
78 | - */ |
|
79 | - public function canProcess(File $file) |
|
80 | - { |
|
81 | - return true; |
|
82 | - } |
|
73 | + /** |
|
74 | + * Checks if the given file can be processed by this Extractor |
|
75 | + * |
|
76 | + * @param File $file |
|
77 | + * @return boolean |
|
78 | + */ |
|
79 | + public function canProcess(File $file) |
|
80 | + { |
|
81 | + return true; |
|
82 | + } |
|
83 | 83 | |
84 | - /** |
|
85 | - * The actual processing TASK |
|
86 | - * Should return an array with database properties for sys_file_metadata to write |
|
87 | - * |
|
88 | - * @param File $file |
|
89 | - * @param array $previousExtractedData optional, contains the array of already extracted data |
|
90 | - * @return array |
|
91 | - */ |
|
92 | - public function extractMetaData(File $file, array $previousExtractedData = []) |
|
93 | - { |
|
94 | - $metadata = []; |
|
95 | - $title = $file->getProperty('title'); |
|
96 | - if (empty($title)) { |
|
97 | - $metadata = array('title' => $this->guessTitle($file->getName())); |
|
98 | - } |
|
99 | - return $metadata; |
|
100 | - } |
|
84 | + /** |
|
85 | + * The actual processing TASK |
|
86 | + * Should return an array with database properties for sys_file_metadata to write |
|
87 | + * |
|
88 | + * @param File $file |
|
89 | + * @param array $previousExtractedData optional, contains the array of already extracted data |
|
90 | + * @return array |
|
91 | + */ |
|
92 | + public function extractMetaData(File $file, array $previousExtractedData = []) |
|
93 | + { |
|
94 | + $metadata = []; |
|
95 | + $title = $file->getProperty('title'); |
|
96 | + if (empty($title)) { |
|
97 | + $metadata = array('title' => $this->guessTitle($file->getName())); |
|
98 | + } |
|
99 | + return $metadata; |
|
100 | + } |
|
101 | 101 | |
102 | - /** |
|
103 | - * Guess a title given a file name. Examples: |
|
104 | - * name: my-file-name.jpg -> title: My file name |
|
105 | - * name: myFileName.jpg -> title: My file name |
|
106 | - * |
|
107 | - * @param string $fileName |
|
108 | - * @return string |
|
109 | - */ |
|
110 | - protected function guessTitle($fileName) |
|
111 | - { |
|
112 | - $fileNameWithoutExtension = $this->removeExtension($fileName); |
|
102 | + /** |
|
103 | + * Guess a title given a file name. Examples: |
|
104 | + * name: my-file-name.jpg -> title: My file name |
|
105 | + * name: myFileName.jpg -> title: My file name |
|
106 | + * |
|
107 | + * @param string $fileName |
|
108 | + * @return string |
|
109 | + */ |
|
110 | + protected function guessTitle($fileName) |
|
111 | + { |
|
112 | + $fileNameWithoutExtension = $this->removeExtension($fileName); |
|
113 | 113 | |
114 | - $title = $fileNameWithoutExtension; |
|
115 | - // first case: the name is separated by _ or - |
|
116 | - // second case: this is an upper camel case name |
|
117 | - if (preg_match('/-|_/is', $fileNameWithoutExtension)) { |
|
118 | - $title = preg_replace('/-|_/is', ' ', $fileNameWithoutExtension); |
|
119 | - } elseif (preg_match('/[A-Z]/', $fileNameWithoutExtension)) { |
|
120 | - $parts = preg_split('/(?=[A-Z])/', $fileNameWithoutExtension, -1, PREG_SPLIT_NO_EMPTY); |
|
121 | - $title = implode(' ', $parts); |
|
122 | - } |
|
114 | + $title = $fileNameWithoutExtension; |
|
115 | + // first case: the name is separated by _ or - |
|
116 | + // second case: this is an upper camel case name |
|
117 | + if (preg_match('/-|_/is', $fileNameWithoutExtension)) { |
|
118 | + $title = preg_replace('/-|_/is', ' ', $fileNameWithoutExtension); |
|
119 | + } elseif (preg_match('/[A-Z]/', $fileNameWithoutExtension)) { |
|
120 | + $parts = preg_split('/(?=[A-Z])/', $fileNameWithoutExtension, -1, PREG_SPLIT_NO_EMPTY); |
|
121 | + $title = implode(' ', $parts); |
|
122 | + } |
|
123 | 123 | |
124 | - // Remove double space. |
|
125 | - $title = preg_replace('/\s+/', ' ', $title); |
|
126 | - return ucfirst($title); |
|
127 | - } |
|
124 | + // Remove double space. |
|
125 | + $title = preg_replace('/\s+/', ' ', $title); |
|
126 | + return ucfirst($title); |
|
127 | + } |
|
128 | 128 | |
129 | - /** |
|
130 | - * Remove extension of a file. |
|
131 | - * |
|
132 | - * @param string $fileName |
|
133 | - * @return string |
|
134 | - */ |
|
135 | - protected function removeExtension($fileName) |
|
136 | - { |
|
137 | - $parts = explode('.', $fileName); |
|
138 | - if (!empty($parts)) { |
|
139 | - array_pop($parts); |
|
140 | - } |
|
141 | - return implode('.', $parts); |
|
142 | - } |
|
129 | + /** |
|
130 | + * Remove extension of a file. |
|
131 | + * |
|
132 | + * @param string $fileName |
|
133 | + * @return string |
|
134 | + */ |
|
135 | + protected function removeExtension($fileName) |
|
136 | + { |
|
137 | + $parts = explode('.', $fileName); |
|
138 | + if (!empty($parts)) { |
|
139 | + array_pop($parts); |
|
140 | + } |
|
141 | + return implode('.', $parts); |
|
142 | + } |
|
143 | 143 | } |
@@ -17,83 +17,83 @@ |
||
17 | 17 | class ImageOptimizer implements SingletonInterface |
18 | 18 | { |
19 | 19 | |
20 | - /** |
|
21 | - * @var array |
|
22 | - */ |
|
23 | - protected $optimizers = []; |
|
20 | + /** |
|
21 | + * @var array |
|
22 | + */ |
|
23 | + protected $optimizers = []; |
|
24 | 24 | |
25 | - /** |
|
26 | - * @var \TYPO3\CMS\Core\Resource\ResourceStorage |
|
27 | - */ |
|
28 | - protected $storage; |
|
25 | + /** |
|
26 | + * @var \TYPO3\CMS\Core\Resource\ResourceStorage |
|
27 | + */ |
|
28 | + protected $storage; |
|
29 | 29 | |
30 | - /** |
|
31 | - * Returns a class instance. |
|
32 | - * |
|
33 | - * @return ImageOptimizer |
|
34 | - * @throws \InvalidArgumentException |
|
35 | - * @param \TYPO3\CMS\Core\Resource\ResourceStorage $storage |
|
36 | - */ |
|
37 | - static public function getInstance($storage = null) |
|
38 | - { |
|
39 | - return GeneralUtility::makeInstance(self::class, $storage); |
|
40 | - } |
|
30 | + /** |
|
31 | + * Returns a class instance. |
|
32 | + * |
|
33 | + * @return ImageOptimizer |
|
34 | + * @throws \InvalidArgumentException |
|
35 | + * @param \TYPO3\CMS\Core\Resource\ResourceStorage $storage |
|
36 | + */ |
|
37 | + static public function getInstance($storage = null) |
|
38 | + { |
|
39 | + return GeneralUtility::makeInstance(self::class, $storage); |
|
40 | + } |
|
41 | 41 | |
42 | - /** |
|
43 | - * Constructor |
|
44 | - * |
|
45 | - * @return ImageOptimizer |
|
46 | - * @param \TYPO3\CMS\Core\Resource\ResourceStorage $storage |
|
47 | - */ |
|
48 | - public function __construct($storage = null) |
|
49 | - { |
|
50 | - $this->storage = $storage; |
|
51 | - $this->add('Fab\Media\FileUpload\Optimizer\Resize'); |
|
52 | - $this->add('Fab\Media\FileUpload\Optimizer\Rotate'); |
|
53 | - } |
|
42 | + /** |
|
43 | + * Constructor |
|
44 | + * |
|
45 | + * @return ImageOptimizer |
|
46 | + * @param \TYPO3\CMS\Core\Resource\ResourceStorage $storage |
|
47 | + */ |
|
48 | + public function __construct($storage = null) |
|
49 | + { |
|
50 | + $this->storage = $storage; |
|
51 | + $this->add('Fab\Media\FileUpload\Optimizer\Resize'); |
|
52 | + $this->add('Fab\Media\FileUpload\Optimizer\Rotate'); |
|
53 | + } |
|
54 | 54 | |
55 | - /** |
|
56 | - * Register a new optimizer |
|
57 | - * |
|
58 | - * @param string $className |
|
59 | - * @return void |
|
60 | - */ |
|
61 | - public function add($className) |
|
62 | - { |
|
63 | - $this->optimizers[] = $className; |
|
64 | - } |
|
55 | + /** |
|
56 | + * Register a new optimizer |
|
57 | + * |
|
58 | + * @param string $className |
|
59 | + * @return void |
|
60 | + */ |
|
61 | + public function add($className) |
|
62 | + { |
|
63 | + $this->optimizers[] = $className; |
|
64 | + } |
|
65 | 65 | |
66 | - /** |
|
67 | - * Un-register a new optimizer |
|
68 | - * |
|
69 | - * @param string $className |
|
70 | - * @return void |
|
71 | - */ |
|
72 | - public function remove($className) |
|
73 | - { |
|
74 | - if (in_array($className, $this->optimizers)) { |
|
75 | - $key = array_search($className, $this->optimizers); |
|
76 | - unset($this->optimizers[$key]); |
|
77 | - } |
|
78 | - } |
|
66 | + /** |
|
67 | + * Un-register a new optimizer |
|
68 | + * |
|
69 | + * @param string $className |
|
70 | + * @return void |
|
71 | + */ |
|
72 | + public function remove($className) |
|
73 | + { |
|
74 | + if (in_array($className, $this->optimizers)) { |
|
75 | + $key = array_search($className, $this->optimizers); |
|
76 | + unset($this->optimizers[$key]); |
|
77 | + } |
|
78 | + } |
|
79 | 79 | |
80 | - /** |
|
81 | - * Optimize an image |
|
82 | - * |
|
83 | - * @param UploadedFileInterface $uploadedFile |
|
84 | - * @return UploadedFileInterface |
|
85 | - * @throws \InvalidArgumentException |
|
86 | - */ |
|
87 | - public function optimize(UploadedFileInterface $uploadedFile) |
|
88 | - { |
|
80 | + /** |
|
81 | + * Optimize an image |
|
82 | + * |
|
83 | + * @param UploadedFileInterface $uploadedFile |
|
84 | + * @return UploadedFileInterface |
|
85 | + * @throws \InvalidArgumentException |
|
86 | + */ |
|
87 | + public function optimize(UploadedFileInterface $uploadedFile) |
|
88 | + { |
|
89 | 89 | |
90 | - foreach ($this->optimizers as $optimizer) { |
|
90 | + foreach ($this->optimizers as $optimizer) { |
|
91 | 91 | |
92 | - /** @var $optimizer \Fab\Media\FileUpload\ImageOptimizerInterface */ |
|
93 | - $optimizer = GeneralUtility::makeInstance($optimizer, $this->storage); |
|
94 | - $uploadedFile = $optimizer->optimize($uploadedFile); |
|
95 | - } |
|
92 | + /** @var $optimizer \Fab\Media\FileUpload\ImageOptimizerInterface */ |
|
93 | + $optimizer = GeneralUtility::makeInstance($optimizer, $this->storage); |
|
94 | + $uploadedFile = $optimizer->optimize($uploadedFile); |
|
95 | + } |
|
96 | 96 | |
97 | - return $uploadedFile; |
|
98 | - } |
|
97 | + return $uploadedFile; |
|
98 | + } |
|
99 | 99 | } |
@@ -14,83 +14,83 @@ |
||
14 | 14 | interface UploadedFileInterface |
15 | 15 | { |
16 | 16 | |
17 | - /** |
|
18 | - * Save the file to the specified path. |
|
19 | - * |
|
20 | - * @return boolean true on success |
|
21 | - */ |
|
22 | - public function save(); |
|
17 | + /** |
|
18 | + * Save the file to the specified path. |
|
19 | + * |
|
20 | + * @return boolean true on success |
|
21 | + */ |
|
22 | + public function save(); |
|
23 | 23 | |
24 | - /** |
|
25 | - * Get the original filename. |
|
26 | - * |
|
27 | - * @return string filename |
|
28 | - */ |
|
29 | - public function getOriginalName(); |
|
24 | + /** |
|
25 | + * Get the original filename. |
|
26 | + * |
|
27 | + * @return string filename |
|
28 | + */ |
|
29 | + public function getOriginalName(); |
|
30 | 30 | |
31 | - /** |
|
32 | - * Get the file size. |
|
33 | - * |
|
34 | - * @return int |
|
35 | - */ |
|
36 | - public function getSize(); |
|
31 | + /** |
|
32 | + * Get the file size. |
|
33 | + * |
|
34 | + * @return int |
|
35 | + */ |
|
36 | + public function getSize(); |
|
37 | 37 | |
38 | - /** |
|
39 | - * Get the file name. |
|
40 | - * |
|
41 | - * @return int |
|
42 | - */ |
|
43 | - public function getName(); |
|
38 | + /** |
|
39 | + * Get the file name. |
|
40 | + * |
|
41 | + * @return int |
|
42 | + */ |
|
43 | + public function getName(); |
|
44 | 44 | |
45 | - /** |
|
46 | - * Get the file type. |
|
47 | - * |
|
48 | - * @return int |
|
49 | - */ |
|
50 | - public function getType(); |
|
45 | + /** |
|
46 | + * Get the file type. |
|
47 | + * |
|
48 | + * @return int |
|
49 | + */ |
|
50 | + public function getType(); |
|
51 | 51 | |
52 | - /** |
|
53 | - * Get the mime type of the file. |
|
54 | - * |
|
55 | - * @return int |
|
56 | - */ |
|
57 | - public function getMimeType(); |
|
52 | + /** |
|
53 | + * Get the mime type of the file. |
|
54 | + * |
|
55 | + * @return int |
|
56 | + */ |
|
57 | + public function getMimeType(); |
|
58 | 58 | |
59 | - /** |
|
60 | - * Get the file with its absolute path. |
|
61 | - * |
|
62 | - * @return string |
|
63 | - */ |
|
64 | - public function getFileWithAbsolutePath(); |
|
59 | + /** |
|
60 | + * Get the file with its absolute path. |
|
61 | + * |
|
62 | + * @return string |
|
63 | + */ |
|
64 | + public function getFileWithAbsolutePath(); |
|
65 | 65 | |
66 | - /** |
|
67 | - * Get the file's public URL. |
|
68 | - * |
|
69 | - * @return string |
|
70 | - */ |
|
71 | - public function getPublicUrl(); |
|
66 | + /** |
|
67 | + * Get the file's public URL. |
|
68 | + * |
|
69 | + * @return string |
|
70 | + */ |
|
71 | + public function getPublicUrl(); |
|
72 | 72 | |
73 | - /** |
|
74 | - * Set the file input name from the DOM. |
|
75 | - * |
|
76 | - * @param string $inputName |
|
77 | - * @return \Fab\Media\FileUpload\UploadedFileInterface |
|
78 | - */ |
|
79 | - public function setInputName($inputName); |
|
73 | + /** |
|
74 | + * Set the file input name from the DOM. |
|
75 | + * |
|
76 | + * @param string $inputName |
|
77 | + * @return \Fab\Media\FileUpload\UploadedFileInterface |
|
78 | + */ |
|
79 | + public function setInputName($inputName); |
|
80 | 80 | |
81 | - /** |
|
82 | - * Set the upload folder |
|
83 | - * |
|
84 | - * @param string $uploadFolder |
|
85 | - * @return \Fab\Media\FileUpload\UploadedFileInterface |
|
86 | - */ |
|
87 | - public function setUploadFolder($uploadFolder); |
|
81 | + /** |
|
82 | + * Set the upload folder |
|
83 | + * |
|
84 | + * @param string $uploadFolder |
|
85 | + * @return \Fab\Media\FileUpload\UploadedFileInterface |
|
86 | + */ |
|
87 | + public function setUploadFolder($uploadFolder); |
|
88 | 88 | |
89 | - /** |
|
90 | - * Set the file name to be saved |
|
91 | - * |
|
92 | - * @param string $name |
|
93 | - * @return \Fab\Media\FileUpload\UploadedFileInterface |
|
94 | - */ |
|
95 | - public function setName($name); |
|
89 | + /** |
|
90 | + * Set the file name to be saved |
|
91 | + * |
|
92 | + * @param string $name |
|
93 | + * @return \Fab\Media\FileUpload\UploadedFileInterface |
|
94 | + */ |
|
95 | + public function setName($name); |
|
96 | 96 | } |
@@ -16,48 +16,48 @@ |
||
16 | 16 | class MultipartedFile extends UploadedFileAbstract |
17 | 17 | { |
18 | 18 | |
19 | - /** |
|
20 | - * @var string |
|
21 | - */ |
|
22 | - protected $inputName = 'qqfile'; |
|
19 | + /** |
|
20 | + * @var string |
|
21 | + */ |
|
22 | + protected $inputName = 'qqfile'; |
|
23 | 23 | |
24 | - /** |
|
25 | - * Save the file to the specified path |
|
26 | - * |
|
27 | - * @return boolean true on success |
|
28 | - */ |
|
29 | - public function save() |
|
30 | - { |
|
31 | - return move_uploaded_file($_FILES[$this->inputName]['tmp_name'], $this->getFileWithAbsolutePath()); |
|
32 | - } |
|
24 | + /** |
|
25 | + * Save the file to the specified path |
|
26 | + * |
|
27 | + * @return boolean true on success |
|
28 | + */ |
|
29 | + public function save() |
|
30 | + { |
|
31 | + return move_uploaded_file($_FILES[$this->inputName]['tmp_name'], $this->getFileWithAbsolutePath()); |
|
32 | + } |
|
33 | 33 | |
34 | - /** |
|
35 | - * Get the original filename |
|
36 | - * |
|
37 | - * @return string filename |
|
38 | - */ |
|
39 | - public function getOriginalName() |
|
40 | - { |
|
41 | - return $_FILES[$this->inputName]['name']; |
|
42 | - } |
|
34 | + /** |
|
35 | + * Get the original filename |
|
36 | + * |
|
37 | + * @return string filename |
|
38 | + */ |
|
39 | + public function getOriginalName() |
|
40 | + { |
|
41 | + return $_FILES[$this->inputName]['name']; |
|
42 | + } |
|
43 | 43 | |
44 | - /** |
|
45 | - * Get the file size |
|
46 | - * |
|
47 | - * @return integer file-size in byte |
|
48 | - */ |
|
49 | - public function getSize() |
|
50 | - { |
|
51 | - return $_FILES[$this->inputName]['size']; |
|
52 | - } |
|
44 | + /** |
|
45 | + * Get the file size |
|
46 | + * |
|
47 | + * @return integer file-size in byte |
|
48 | + */ |
|
49 | + public function getSize() |
|
50 | + { |
|
51 | + return $_FILES[$this->inputName]['size']; |
|
52 | + } |
|
53 | 53 | |
54 | - /** |
|
55 | - * Get the mime type of the file. |
|
56 | - * |
|
57 | - * @return int |
|
58 | - */ |
|
59 | - public function getMimeType() |
|
60 | - { |
|
61 | - return $_FILES[$this->inputName]['type']; |
|
62 | - } |
|
54 | + /** |
|
55 | + * Get the mime type of the file. |
|
56 | + * |
|
57 | + * @return int |
|
58 | + */ |
|
59 | + public function getMimeType() |
|
60 | + { |
|
61 | + return $_FILES[$this->inputName]['type']; |
|
62 | + } |
|
63 | 63 | } |
@@ -45,231 +45,231 @@ |
||
45 | 45 | class JpegExifOrient |
46 | 46 | { |
47 | 47 | |
48 | - /** |
|
49 | - * Sets the Exif Orientation for a given JPG file. |
|
50 | - * |
|
51 | - * @param string $filename |
|
52 | - * @param integer $orientation |
|
53 | - * @return void |
|
54 | - * @throws \RuntimeException |
|
55 | - */ |
|
56 | - public static function setOrientation($filename, $orientation) |
|
57 | - { |
|
58 | - $exif_data = []; // Buffer |
|
59 | - $offsetJfif = 0; |
|
48 | + /** |
|
49 | + * Sets the Exif Orientation for a given JPG file. |
|
50 | + * |
|
51 | + * @param string $filename |
|
52 | + * @param integer $orientation |
|
53 | + * @return void |
|
54 | + * @throws \RuntimeException |
|
55 | + */ |
|
56 | + public static function setOrientation($filename, $orientation) |
|
57 | + { |
|
58 | + $exif_data = []; // Buffer |
|
59 | + $offsetJfif = 0; |
|
60 | 60 | |
61 | - if (($fh = fopen($filename, 'rb+')) === false) { |
|
62 | - throw new \RuntimeException('Can\'t open ' . $filename, 1363533724); |
|
63 | - } |
|
61 | + if (($fh = fopen($filename, 'rb+')) === false) { |
|
62 | + throw new \RuntimeException('Can\'t open ' . $filename, 1363533724); |
|
63 | + } |
|
64 | 64 | |
65 | - // Read file head, check for JPEG SOI + JFIF/Exif APP1 |
|
66 | - for ($i = 0; $i < 4; $i++) $exif_data[$i] = self::read_1_byte($fh); |
|
67 | - if ($exif_data[0] !== 0xFF || |
|
68 | - $exif_data[1] !== 0xD8 |
|
69 | - ) { |
|
70 | - } |
|
65 | + // Read file head, check for JPEG SOI + JFIF/Exif APP1 |
|
66 | + for ($i = 0; $i < 4; $i++) $exif_data[$i] = self::read_1_byte($fh); |
|
67 | + if ($exif_data[0] !== 0xFF || |
|
68 | + $exif_data[1] !== 0xD8 |
|
69 | + ) { |
|
70 | + } |
|
71 | 71 | |
72 | - // JFIF segment: http://en.wikipedia.org/wiki/JPEG_File_Interchange_Format#JFIF_segment_format |
|
73 | - if ($exif_data[2] === 0xFF && $exif_data[3] === 0xE0) { |
|
74 | - // Get the marker parameter length count |
|
75 | - $length = self::read_2_bytes($fh); |
|
76 | - $offsetJfif = $length + 2; // "+ 2" to skip the 2 bytes introducing this additional segment |
|
77 | - // Length includes itself, so must be at least 2 |
|
78 | - // Following JFIF data length must be at least 6 |
|
79 | - if ($length < 8) { |
|
80 | - return; |
|
81 | - } |
|
82 | - $length -= 8; |
|
83 | - // Read JFIF head, check for "JFIF" |
|
84 | - for ($i = 0; $i < 5; $i++) $exif_data[$i] = self::read_1_byte($fh); |
|
85 | - if ($exif_data[0] !== 0x4A || |
|
86 | - $exif_data[1] !== 0x46 || |
|
87 | - $exif_data[2] !== 0x49 || |
|
88 | - $exif_data[3] !== 0x46 || |
|
89 | - $exif_data[4] !== 0 |
|
90 | - ) { |
|
91 | - return; |
|
92 | - } |
|
93 | - // Read JFIF body |
|
94 | - for ($i = 0; $i < $length; $i++) $exif_data[$i] = self::read_1_byte($fh); |
|
72 | + // JFIF segment: http://en.wikipedia.org/wiki/JPEG_File_Interchange_Format#JFIF_segment_format |
|
73 | + if ($exif_data[2] === 0xFF && $exif_data[3] === 0xE0) { |
|
74 | + // Get the marker parameter length count |
|
75 | + $length = self::read_2_bytes($fh); |
|
76 | + $offsetJfif = $length + 2; // "+ 2" to skip the 2 bytes introducing this additional segment |
|
77 | + // Length includes itself, so must be at least 2 |
|
78 | + // Following JFIF data length must be at least 6 |
|
79 | + if ($length < 8) { |
|
80 | + return; |
|
81 | + } |
|
82 | + $length -= 8; |
|
83 | + // Read JFIF head, check for "JFIF" |
|
84 | + for ($i = 0; $i < 5; $i++) $exif_data[$i] = self::read_1_byte($fh); |
|
85 | + if ($exif_data[0] !== 0x4A || |
|
86 | + $exif_data[1] !== 0x46 || |
|
87 | + $exif_data[2] !== 0x49 || |
|
88 | + $exif_data[3] !== 0x46 || |
|
89 | + $exif_data[4] !== 0 |
|
90 | + ) { |
|
91 | + return; |
|
92 | + } |
|
93 | + // Read JFIF body |
|
94 | + for ($i = 0; $i < $length; $i++) $exif_data[$i] = self::read_1_byte($fh); |
|
95 | 95 | |
96 | - if (self::read_1_byte($fh) !== 0) { |
|
97 | - // Seems there is a 0 byte to separate segments... |
|
98 | - return; |
|
99 | - } |
|
100 | - // Read next 2 bytes in $exif_data[2] and $exif_data[3] as Exif APP1 segment |
|
101 | - // is now expected |
|
102 | - $exif_data[2] = self::read_1_byte($fh); |
|
103 | - $exif_data[3] = self::read_1_byte($fh); |
|
104 | - } |
|
96 | + if (self::read_1_byte($fh) !== 0) { |
|
97 | + // Seems there is a 0 byte to separate segments... |
|
98 | + return; |
|
99 | + } |
|
100 | + // Read next 2 bytes in $exif_data[2] and $exif_data[3] as Exif APP1 segment |
|
101 | + // is now expected |
|
102 | + $exif_data[2] = self::read_1_byte($fh); |
|
103 | + $exif_data[3] = self::read_1_byte($fh); |
|
104 | + } |
|
105 | 105 | |
106 | - // Exif APP1 |
|
107 | - if ($exif_data[2] !== 0xFF || $exif_data[3] !== 0xE1) { |
|
108 | - return; |
|
109 | - } |
|
106 | + // Exif APP1 |
|
107 | + if ($exif_data[2] !== 0xFF || $exif_data[3] !== 0xE1) { |
|
108 | + return; |
|
109 | + } |
|
110 | 110 | |
111 | - // Get the marker parameter length count |
|
112 | - $length = self::read_2_bytes($fh); |
|
113 | - // Length includes itself, so must be at least 2 |
|
114 | - // Following Exif data length must be at least 6 |
|
115 | - if ($length < 8) { |
|
116 | - return; |
|
117 | - } |
|
118 | - $length -= 8; |
|
119 | - // Read Exif head, check for "Exif" |
|
120 | - for ($i = 0; $i < 6; $i++) $exif_data[$i] = self::read_1_byte($fh); |
|
121 | - if ($exif_data[0] !== 0x45 || |
|
122 | - $exif_data[1] !== 0x78 || |
|
123 | - $exif_data[2] !== 0x69 || |
|
124 | - $exif_data[3] !== 0x66 || |
|
125 | - $exif_data[4] !== 0 || |
|
126 | - $exif_data[5] !== 0 |
|
127 | - ) { |
|
128 | - return; |
|
129 | - } |
|
130 | - // Read Exif body |
|
131 | - for ($i = 0; $i < $length; $i++) $exif_data[$i] = self::read_1_byte($fh); |
|
111 | + // Get the marker parameter length count |
|
112 | + $length = self::read_2_bytes($fh); |
|
113 | + // Length includes itself, so must be at least 2 |
|
114 | + // Following Exif data length must be at least 6 |
|
115 | + if ($length < 8) { |
|
116 | + return; |
|
117 | + } |
|
118 | + $length -= 8; |
|
119 | + // Read Exif head, check for "Exif" |
|
120 | + for ($i = 0; $i < 6; $i++) $exif_data[$i] = self::read_1_byte($fh); |
|
121 | + if ($exif_data[0] !== 0x45 || |
|
122 | + $exif_data[1] !== 0x78 || |
|
123 | + $exif_data[2] !== 0x69 || |
|
124 | + $exif_data[3] !== 0x66 || |
|
125 | + $exif_data[4] !== 0 || |
|
126 | + $exif_data[5] !== 0 |
|
127 | + ) { |
|
128 | + return; |
|
129 | + } |
|
130 | + // Read Exif body |
|
131 | + for ($i = 0; $i < $length; $i++) $exif_data[$i] = self::read_1_byte($fh); |
|
132 | 132 | |
133 | - if ($length < 12) { // Length of an IFD entry |
|
134 | - return; |
|
135 | - } |
|
133 | + if ($length < 12) { // Length of an IFD entry |
|
134 | + return; |
|
135 | + } |
|
136 | 136 | |
137 | - // Discover byte order |
|
138 | - if ($exif_data[0] === 0x49 && $exif_data[1] === 0x49) { |
|
139 | - $is_motorola = false; |
|
140 | - } elseif ($exif_data[0] === 0x4D && $exif_data[1] === 0x4D) { |
|
141 | - $is_motorola = true; |
|
142 | - } else { |
|
143 | - return; |
|
144 | - } |
|
137 | + // Discover byte order |
|
138 | + if ($exif_data[0] === 0x49 && $exif_data[1] === 0x49) { |
|
139 | + $is_motorola = false; |
|
140 | + } elseif ($exif_data[0] === 0x4D && $exif_data[1] === 0x4D) { |
|
141 | + $is_motorola = true; |
|
142 | + } else { |
|
143 | + return; |
|
144 | + } |
|
145 | 145 | |
146 | - // Check Tag mark |
|
147 | - if ($is_motorola) { |
|
148 | - if ($exif_data[2] !== 0) return; |
|
149 | - if ($exif_data[3] !== 0x2A) return; |
|
150 | - } else { |
|
151 | - if ($exif_data[3] !== 0) return; |
|
152 | - if ($exif_data[2] !== 0x2A) return; |
|
153 | - } |
|
146 | + // Check Tag mark |
|
147 | + if ($is_motorola) { |
|
148 | + if ($exif_data[2] !== 0) return; |
|
149 | + if ($exif_data[3] !== 0x2A) return; |
|
150 | + } else { |
|
151 | + if ($exif_data[3] !== 0) return; |
|
152 | + if ($exif_data[2] !== 0x2A) return; |
|
153 | + } |
|
154 | 154 | |
155 | - // Get first IFD offset (offset to IFD0) |
|
156 | - if ($is_motorola) { |
|
157 | - if ($exif_data[4] !== 0) return; |
|
158 | - if ($exif_data[5] !== 0) return; |
|
159 | - $offset = $exif_data[6]; |
|
160 | - $offset <<= 8; |
|
161 | - $offset += $exif_data[7]; |
|
162 | - } else { |
|
163 | - if ($exif_data[7] !== 0) return; |
|
164 | - if ($exif_data[6] !== 0) return; |
|
165 | - $offset = $exif_data[5]; |
|
166 | - $offset <<= 8; |
|
167 | - $offset += $exif_data[4]; |
|
168 | - } |
|
169 | - // Check end of data segment |
|
170 | - if ($offset > $length - 2) return; |
|
155 | + // Get first IFD offset (offset to IFD0) |
|
156 | + if ($is_motorola) { |
|
157 | + if ($exif_data[4] !== 0) return; |
|
158 | + if ($exif_data[5] !== 0) return; |
|
159 | + $offset = $exif_data[6]; |
|
160 | + $offset <<= 8; |
|
161 | + $offset += $exif_data[7]; |
|
162 | + } else { |
|
163 | + if ($exif_data[7] !== 0) return; |
|
164 | + if ($exif_data[6] !== 0) return; |
|
165 | + $offset = $exif_data[5]; |
|
166 | + $offset <<= 8; |
|
167 | + $offset += $exif_data[4]; |
|
168 | + } |
|
169 | + // Check end of data segment |
|
170 | + if ($offset > $length - 2) return; |
|
171 | 171 | |
172 | - // Get the number of directory entries contained in this IFD |
|
173 | - if ($is_motorola) { |
|
174 | - $number_of_tags = $exif_data[$offset]; |
|
175 | - $number_of_tags <<= 8; |
|
176 | - $number_of_tags += $exif_data[$offset + 1]; |
|
177 | - } else { |
|
178 | - $number_of_tags = $exif_data[$offset + 1]; |
|
179 | - $number_of_tags <<= 8; |
|
180 | - $number_of_tags += $exif_data[$offset]; |
|
181 | - } |
|
182 | - if ($number_of_tags === 0) return; |
|
183 | - $offset += 2; |
|
172 | + // Get the number of directory entries contained in this IFD |
|
173 | + if ($is_motorola) { |
|
174 | + $number_of_tags = $exif_data[$offset]; |
|
175 | + $number_of_tags <<= 8; |
|
176 | + $number_of_tags += $exif_data[$offset + 1]; |
|
177 | + } else { |
|
178 | + $number_of_tags = $exif_data[$offset + 1]; |
|
179 | + $number_of_tags <<= 8; |
|
180 | + $number_of_tags += $exif_data[$offset]; |
|
181 | + } |
|
182 | + if ($number_of_tags === 0) return; |
|
183 | + $offset += 2; |
|
184 | 184 | |
185 | - // Search for Orientation Tag in IFD0 |
|
186 | - while (true) { |
|
187 | - // Check end of data segment |
|
188 | - if ($offset > $length - 12) return; |
|
189 | - // Get Tag number |
|
190 | - if ($is_motorola) { |
|
191 | - $tagnum = $exif_data[$offset]; |
|
192 | - $tagnum <<= 8; |
|
193 | - $tagnum += $exif_data[$offset + 1]; |
|
194 | - } else { |
|
195 | - $tagnum = $exif_data[$offset + 1]; |
|
196 | - $tagnum <<= 8; |
|
197 | - $tagnum += $exif_data[$offset]; |
|
198 | - } |
|
199 | - // Found Orientation Tag |
|
200 | - if ($tagnum === 0x0112) break; |
|
201 | - if (--$number_of_tags === 0) return; |
|
202 | - $offset += 12; |
|
203 | - } |
|
185 | + // Search for Orientation Tag in IFD0 |
|
186 | + while (true) { |
|
187 | + // Check end of data segment |
|
188 | + if ($offset > $length - 12) return; |
|
189 | + // Get Tag number |
|
190 | + if ($is_motorola) { |
|
191 | + $tagnum = $exif_data[$offset]; |
|
192 | + $tagnum <<= 8; |
|
193 | + $tagnum += $exif_data[$offset + 1]; |
|
194 | + } else { |
|
195 | + $tagnum = $exif_data[$offset + 1]; |
|
196 | + $tagnum <<= 8; |
|
197 | + $tagnum += $exif_data[$offset]; |
|
198 | + } |
|
199 | + // Found Orientation Tag |
|
200 | + if ($tagnum === 0x0112) break; |
|
201 | + if (--$number_of_tags === 0) return; |
|
202 | + $offset += 12; |
|
203 | + } |
|
204 | 204 | |
205 | - // Set the Orientation value |
|
206 | - if ($is_motorola) { |
|
207 | - $exif_data[$offset + 2] = 0; // Format = unsigned short (2 octets) |
|
208 | - $exif_data[$offset + 3] = 3; |
|
209 | - $exif_data[$offset + 4] = 0; // Number of Components = 1 |
|
210 | - $exif_data[$offset + 5] = 0; |
|
211 | - $exif_data[$offset + 6] = 0; |
|
212 | - $exif_data[$offset + 7] = 1; |
|
213 | - $exif_data[$offset + 8] = 0; |
|
214 | - $exif_data[$offset + 9] = $orientation; |
|
215 | - $exif_data[$offset + 10] = 0; |
|
216 | - $exif_data[$offset + 11] = 0; |
|
217 | - } else { |
|
218 | - $exif_data[$offset + 2] = 3; // Format = unsigned short (2 octets) |
|
219 | - $exif_data[$offset + 3] = 0; |
|
220 | - $exif_data[$offset + 4] = 1; // Number of Components = 1 |
|
221 | - $exif_data[$offset + 5] = 0; |
|
222 | - $exif_data[$offset + 6] = 0; |
|
223 | - $exif_data[$offset + 7] = 0; |
|
224 | - $exif_data[$offset + 8] = $orientation; |
|
225 | - $exif_data[$offset + 9] = 0; |
|
226 | - $exif_data[$offset + 10] = 0; |
|
227 | - $exif_data[$offset + 11] = 0; |
|
228 | - } |
|
229 | - fseek($fh, (4 + 2 + 6 + 2) + $offsetJfif + $offset, SEEK_SET); |
|
230 | - $data = ''; |
|
231 | - for ($i = 0; $i < 10; $i++) { |
|
232 | - $data .= chr($exif_data[$i + $offset + 2]); |
|
233 | - } |
|
234 | - fwrite($fh, $data); |
|
235 | - fclose($fh); |
|
236 | - } |
|
205 | + // Set the Orientation value |
|
206 | + if ($is_motorola) { |
|
207 | + $exif_data[$offset + 2] = 0; // Format = unsigned short (2 octets) |
|
208 | + $exif_data[$offset + 3] = 3; |
|
209 | + $exif_data[$offset + 4] = 0; // Number of Components = 1 |
|
210 | + $exif_data[$offset + 5] = 0; |
|
211 | + $exif_data[$offset + 6] = 0; |
|
212 | + $exif_data[$offset + 7] = 1; |
|
213 | + $exif_data[$offset + 8] = 0; |
|
214 | + $exif_data[$offset + 9] = $orientation; |
|
215 | + $exif_data[$offset + 10] = 0; |
|
216 | + $exif_data[$offset + 11] = 0; |
|
217 | + } else { |
|
218 | + $exif_data[$offset + 2] = 3; // Format = unsigned short (2 octets) |
|
219 | + $exif_data[$offset + 3] = 0; |
|
220 | + $exif_data[$offset + 4] = 1; // Number of Components = 1 |
|
221 | + $exif_data[$offset + 5] = 0; |
|
222 | + $exif_data[$offset + 6] = 0; |
|
223 | + $exif_data[$offset + 7] = 0; |
|
224 | + $exif_data[$offset + 8] = $orientation; |
|
225 | + $exif_data[$offset + 9] = 0; |
|
226 | + $exif_data[$offset + 10] = 0; |
|
227 | + $exif_data[$offset + 11] = 0; |
|
228 | + } |
|
229 | + fseek($fh, (4 + 2 + 6 + 2) + $offsetJfif + $offset, SEEK_SET); |
|
230 | + $data = ''; |
|
231 | + for ($i = 0; $i < 10; $i++) { |
|
232 | + $data .= chr($exif_data[$i + $offset + 2]); |
|
233 | + } |
|
234 | + fwrite($fh, $data); |
|
235 | + fclose($fh); |
|
236 | + } |
|
237 | 237 | |
238 | - /** |
|
239 | - * Reads one byte, testing for EOF. |
|
240 | - * |
|
241 | - * @param resource $handle |
|
242 | - * @return integer |
|
243 | - * @throws \RuntimeException |
|
244 | - */ |
|
245 | - protected static function read_1_byte($handle) |
|
246 | - { |
|
247 | - $c = fgetc($handle); |
|
248 | - if ($c === false) { |
|
249 | - throw new \RuntimeException('Premature EOF in JPEG file', 1363533326); |
|
250 | - } |
|
251 | - return ord($c); |
|
252 | - } |
|
238 | + /** |
|
239 | + * Reads one byte, testing for EOF. |
|
240 | + * |
|
241 | + * @param resource $handle |
|
242 | + * @return integer |
|
243 | + * @throws \RuntimeException |
|
244 | + */ |
|
245 | + protected static function read_1_byte($handle) |
|
246 | + { |
|
247 | + $c = fgetc($handle); |
|
248 | + if ($c === false) { |
|
249 | + throw new \RuntimeException('Premature EOF in JPEG file', 1363533326); |
|
250 | + } |
|
251 | + return ord($c); |
|
252 | + } |
|
253 | 253 | |
254 | - /** |
|
255 | - * Reads 2 bytes, converts them to unsigned int |
|
256 | - * Remark: All 2-byte quantities in JPEG markers are MSB first. |
|
257 | - * |
|
258 | - * @param resource $handle |
|
259 | - * @return integer |
|
260 | - * @throws \RuntimeException |
|
261 | - */ |
|
262 | - protected static function read_2_bytes($handle) |
|
263 | - { |
|
264 | - $c1 = fgetc($handle); |
|
265 | - if ($c1 === false) { |
|
266 | - throw new \RuntimeException('Premature EOF in JPEG file', 1363533326); |
|
267 | - } |
|
268 | - $c2 = fgetc($handle); |
|
269 | - if ($c2 === false) { |
|
270 | - throw new \RuntimeException('Premature EOF in JPEG file', 1363533326); |
|
271 | - } |
|
272 | - return (ord($c1) << 8) + (ord($c2)); |
|
273 | - } |
|
254 | + /** |
|
255 | + * Reads 2 bytes, converts them to unsigned int |
|
256 | + * Remark: All 2-byte quantities in JPEG markers are MSB first. |
|
257 | + * |
|
258 | + * @param resource $handle |
|
259 | + * @return integer |
|
260 | + * @throws \RuntimeException |
|
261 | + */ |
|
262 | + protected static function read_2_bytes($handle) |
|
263 | + { |
|
264 | + $c1 = fgetc($handle); |
|
265 | + if ($c1 === false) { |
|
266 | + throw new \RuntimeException('Premature EOF in JPEG file', 1363533326); |
|
267 | + } |
|
268 | + $c2 = fgetc($handle); |
|
269 | + if ($c2 === false) { |
|
270 | + throw new \RuntimeException('Premature EOF in JPEG file', 1363533326); |
|
271 | + } |
|
272 | + return (ord($c1) << 8) + (ord($c2)); |
|
273 | + } |
|
274 | 274 | |
275 | 275 | } |
@@ -55,11 +55,11 @@ discard block |
||
55 | 55 | */ |
56 | 56 | public static function setOrientation($filename, $orientation) |
57 | 57 | { |
58 | - $exif_data = []; // Buffer |
|
58 | + $exif_data = []; // Buffer |
|
59 | 59 | $offsetJfif = 0; |
60 | 60 | |
61 | 61 | if (($fh = fopen($filename, 'rb+')) === false) { |
62 | - throw new \RuntimeException('Can\'t open ' . $filename, 1363533724); |
|
62 | + throw new \RuntimeException('Can\'t open '.$filename, 1363533724); |
|
63 | 63 | } |
64 | 64 | |
65 | 65 | // Read file head, check for JPEG SOI + JFIF/Exif APP1 |
@@ -73,7 +73,7 @@ discard block |
||
73 | 73 | if ($exif_data[2] === 0xFF && $exif_data[3] === 0xE0) { |
74 | 74 | // Get the marker parameter length count |
75 | 75 | $length = self::read_2_bytes($fh); |
76 | - $offsetJfif = $length + 2; // "+ 2" to skip the 2 bytes introducing this additional segment |
|
76 | + $offsetJfif = $length + 2; // "+ 2" to skip the 2 bytes introducing this additional segment |
|
77 | 77 | // Length includes itself, so must be at least 2 |
78 | 78 | // Following JFIF data length must be at least 6 |
79 | 79 | if ($length < 8) { |
@@ -204,9 +204,9 @@ discard block |
||
204 | 204 | |
205 | 205 | // Set the Orientation value |
206 | 206 | if ($is_motorola) { |
207 | - $exif_data[$offset + 2] = 0; // Format = unsigned short (2 octets) |
|
207 | + $exif_data[$offset + 2] = 0; // Format = unsigned short (2 octets) |
|
208 | 208 | $exif_data[$offset + 3] = 3; |
209 | - $exif_data[$offset + 4] = 0; // Number of Components = 1 |
|
209 | + $exif_data[$offset + 4] = 0; // Number of Components = 1 |
|
210 | 210 | $exif_data[$offset + 5] = 0; |
211 | 211 | $exif_data[$offset + 6] = 0; |
212 | 212 | $exif_data[$offset + 7] = 1; |
@@ -215,9 +215,9 @@ discard block |
||
215 | 215 | $exif_data[$offset + 10] = 0; |
216 | 216 | $exif_data[$offset + 11] = 0; |
217 | 217 | } else { |
218 | - $exif_data[$offset + 2] = 3; // Format = unsigned short (2 octets) |
|
218 | + $exif_data[$offset + 2] = 3; // Format = unsigned short (2 octets) |
|
219 | 219 | $exif_data[$offset + 3] = 0; |
220 | - $exif_data[$offset + 4] = 1; // Number of Components = 1 |
|
220 | + $exif_data[$offset + 4] = 1; // Number of Components = 1 |
|
221 | 221 | $exif_data[$offset + 5] = 0; |
222 | 222 | $exif_data[$offset + 6] = 0; |
223 | 223 | $exif_data[$offset + 7] = 0; |
@@ -63,7 +63,9 @@ discard block |
||
63 | 63 | } |
64 | 64 | |
65 | 65 | // Read file head, check for JPEG SOI + JFIF/Exif APP1 |
66 | - for ($i = 0; $i < 4; $i++) $exif_data[$i] = self::read_1_byte($fh); |
|
66 | + for ($i = 0; $i < 4; $i++) { |
|
67 | + $exif_data[$i] = self::read_1_byte($fh); |
|
68 | + } |
|
67 | 69 | if ($exif_data[0] !== 0xFF || |
68 | 70 | $exif_data[1] !== 0xD8 |
69 | 71 | ) { |
@@ -81,7 +83,9 @@ discard block |
||
81 | 83 | } |
82 | 84 | $length -= 8; |
83 | 85 | // Read JFIF head, check for "JFIF" |
84 | - for ($i = 0; $i < 5; $i++) $exif_data[$i] = self::read_1_byte($fh); |
|
86 | + for ($i = 0; $i < 5; $i++) { |
|
87 | + $exif_data[$i] = self::read_1_byte($fh); |
|
88 | + } |
|
85 | 89 | if ($exif_data[0] !== 0x4A || |
86 | 90 | $exif_data[1] !== 0x46 || |
87 | 91 | $exif_data[2] !== 0x49 || |
@@ -91,7 +95,9 @@ discard block |
||
91 | 95 | return; |
92 | 96 | } |
93 | 97 | // Read JFIF body |
94 | - for ($i = 0; $i < $length; $i++) $exif_data[$i] = self::read_1_byte($fh); |
|
98 | + for ($i = 0; $i < $length; $i++) { |
|
99 | + $exif_data[$i] = self::read_1_byte($fh); |
|
100 | + } |
|
95 | 101 | |
96 | 102 | if (self::read_1_byte($fh) !== 0) { |
97 | 103 | // Seems there is a 0 byte to separate segments... |
@@ -117,7 +123,9 @@ discard block |
||
117 | 123 | } |
118 | 124 | $length -= 8; |
119 | 125 | // Read Exif head, check for "Exif" |
120 | - for ($i = 0; $i < 6; $i++) $exif_data[$i] = self::read_1_byte($fh); |
|
126 | + for ($i = 0; $i < 6; $i++) { |
|
127 | + $exif_data[$i] = self::read_1_byte($fh); |
|
128 | + } |
|
121 | 129 | if ($exif_data[0] !== 0x45 || |
122 | 130 | $exif_data[1] !== 0x78 || |
123 | 131 | $exif_data[2] !== 0x69 || |
@@ -128,7 +136,9 @@ discard block |
||
128 | 136 | return; |
129 | 137 | } |
130 | 138 | // Read Exif body |
131 | - for ($i = 0; $i < $length; $i++) $exif_data[$i] = self::read_1_byte($fh); |
|
139 | + for ($i = 0; $i < $length; $i++) { |
|
140 | + $exif_data[$i] = self::read_1_byte($fh); |
|
141 | + } |
|
132 | 142 | |
133 | 143 | if ($length < 12) { // Length of an IFD entry |
134 | 144 | return; |
@@ -145,29 +155,47 @@ discard block |
||
145 | 155 | |
146 | 156 | // Check Tag mark |
147 | 157 | if ($is_motorola) { |
148 | - if ($exif_data[2] !== 0) return; |
|
149 | - if ($exif_data[3] !== 0x2A) return; |
|
158 | + if ($exif_data[2] !== 0) { |
|
159 | + return; |
|
160 | + } |
|
161 | + if ($exif_data[3] !== 0x2A) { |
|
162 | + return; |
|
163 | + } |
|
150 | 164 | } else { |
151 | - if ($exif_data[3] !== 0) return; |
|
152 | - if ($exif_data[2] !== 0x2A) return; |
|
165 | + if ($exif_data[3] !== 0) { |
|
166 | + return; |
|
167 | + } |
|
168 | + if ($exif_data[2] !== 0x2A) { |
|
169 | + return; |
|
170 | + } |
|
153 | 171 | } |
154 | 172 | |
155 | 173 | // Get first IFD offset (offset to IFD0) |
156 | 174 | if ($is_motorola) { |
157 | - if ($exif_data[4] !== 0) return; |
|
158 | - if ($exif_data[5] !== 0) return; |
|
175 | + if ($exif_data[4] !== 0) { |
|
176 | + return; |
|
177 | + } |
|
178 | + if ($exif_data[5] !== 0) { |
|
179 | + return; |
|
180 | + } |
|
159 | 181 | $offset = $exif_data[6]; |
160 | 182 | $offset <<= 8; |
161 | 183 | $offset += $exif_data[7]; |
162 | 184 | } else { |
163 | - if ($exif_data[7] !== 0) return; |
|
164 | - if ($exif_data[6] !== 0) return; |
|
185 | + if ($exif_data[7] !== 0) { |
|
186 | + return; |
|
187 | + } |
|
188 | + if ($exif_data[6] !== 0) { |
|
189 | + return; |
|
190 | + } |
|
165 | 191 | $offset = $exif_data[5]; |
166 | 192 | $offset <<= 8; |
167 | 193 | $offset += $exif_data[4]; |
168 | 194 | } |
169 | 195 | // Check end of data segment |
170 | - if ($offset > $length - 2) return; |
|
196 | + if ($offset > $length - 2) { |
|
197 | + return; |
|
198 | + } |
|
171 | 199 | |
172 | 200 | // Get the number of directory entries contained in this IFD |
173 | 201 | if ($is_motorola) { |
@@ -179,13 +207,17 @@ discard block |
||
179 | 207 | $number_of_tags <<= 8; |
180 | 208 | $number_of_tags += $exif_data[$offset]; |
181 | 209 | } |
182 | - if ($number_of_tags === 0) return; |
|
210 | + if ($number_of_tags === 0) { |
|
211 | + return; |
|
212 | + } |
|
183 | 213 | $offset += 2; |
184 | 214 | |
185 | 215 | // Search for Orientation Tag in IFD0 |
186 | 216 | while (true) { |
187 | 217 | // Check end of data segment |
188 | - if ($offset > $length - 12) return; |
|
218 | + if ($offset > $length - 12) { |
|
219 | + return; |
|
220 | + } |
|
189 | 221 | // Get Tag number |
190 | 222 | if ($is_motorola) { |
191 | 223 | $tagnum = $exif_data[$offset]; |
@@ -197,8 +229,12 @@ discard block |
||
197 | 229 | $tagnum += $exif_data[$offset]; |
198 | 230 | } |
199 | 231 | // Found Orientation Tag |
200 | - if ($tagnum === 0x0112) break; |
|
201 | - if (--$number_of_tags === 0) return; |
|
232 | + if ($tagnum === 0x0112) { |
|
233 | + break; |
|
234 | + } |
|
235 | + if (--$number_of_tags === 0) { |
|
236 | + return; |
|
237 | + } |
|
202 | 238 | $offset += 12; |
203 | 239 | } |
204 | 240 |
@@ -16,117 +16,117 @@ |
||
16 | 16 | class Base64File extends \Fab\Media\FileUpload\UploadedFileAbstract |
17 | 17 | { |
18 | 18 | |
19 | - /** |
|
20 | - * @var string |
|
21 | - */ |
|
22 | - protected $inputName = 'qqfile'; |
|
23 | - |
|
24 | - /** |
|
25 | - * @var string |
|
26 | - */ |
|
27 | - protected $uploadFolder; |
|
28 | - |
|
29 | - /** |
|
30 | - * @var string |
|
31 | - */ |
|
32 | - protected $name; |
|
33 | - |
|
34 | - /** |
|
35 | - * @var string |
|
36 | - */ |
|
37 | - protected $image; |
|
38 | - |
|
39 | - /** |
|
40 | - * @var string |
|
41 | - */ |
|
42 | - protected $extension; |
|
43 | - |
|
44 | - /** |
|
45 | - * @return \Fab\Media\FileUpload\Base64File |
|
46 | - */ |
|
47 | - public function __construct() |
|
48 | - { |
|
49 | - |
|
50 | - // Processes the encoded image data and returns the decoded image |
|
51 | - $encodedImage = GeneralUtility::_POST($this->inputName); |
|
52 | - if (preg_match('/^data:image\/(jpg|jpeg|png)/i', $encodedImage, $matches)) { |
|
53 | - $this->extension = $matches[1]; |
|
54 | - } else { |
|
55 | - return false; |
|
56 | - } |
|
57 | - |
|
58 | - // Remove the mime-type header |
|
59 | - $data = reset(array_reverse(explode('base64,', $encodedImage))); |
|
60 | - |
|
61 | - // Use strict mode to prevent characters from outside the base64 range |
|
62 | - $this->image = base64_decode($data, true); |
|
63 | - |
|
64 | - if (!$this->image) { |
|
65 | - return false; |
|
66 | - } |
|
67 | - |
|
68 | - $this->setName(uniqid() . '.' . $this->extension); |
|
69 | - } |
|
70 | - |
|
71 | - /** |
|
72 | - * Save the file to the specified path |
|
73 | - * |
|
74 | - * @throws \Fab\Media\Exception\EmptyPropertyException |
|
75 | - * @return boolean true on success |
|
76 | - */ |
|
77 | - public function save() |
|
78 | - { |
|
79 | - |
|
80 | - if (is_null($this->uploadFolder)) { |
|
81 | - throw new \Fab\Media\Exception\EmptyPropertyException('Upload folder is not defined', 1362587741); |
|
82 | - } |
|
83 | - |
|
84 | - if (is_null($this->name)) { |
|
85 | - throw new \Fab\Media\Exception\EmptyPropertyException('File name is not defined', 1362587742); |
|
86 | - } |
|
87 | - |
|
88 | - return file_put_contents($this->getFileWithAbsolutePath(), $this->image) > 0; |
|
89 | - } |
|
90 | - |
|
91 | - /** |
|
92 | - * Get the original file name. |
|
93 | - * |
|
94 | - * @return string |
|
95 | - */ |
|
96 | - public function getOriginalName() |
|
97 | - { |
|
98 | - return $this->getName(); |
|
99 | - } |
|
100 | - |
|
101 | - /** |
|
102 | - * Get the file size |
|
103 | - * |
|
104 | - * @throws \Exception |
|
105 | - * @return integer file-size in byte |
|
106 | - */ |
|
107 | - public function getSize() |
|
108 | - { |
|
109 | - if (isset($GLOBALS['_SERVER']['CONTENT_LENGTH'])) { |
|
110 | - return (int)$GLOBALS['_SERVER']['CONTENT_LENGTH']; |
|
111 | - } else { |
|
112 | - throw new \Exception('Getting content length is not supported.'); |
|
113 | - } |
|
114 | - } |
|
115 | - |
|
116 | - /** |
|
117 | - * Get MIME type of file. |
|
118 | - * |
|
119 | - * @return string|boolean MIME type. eg, text/html, false on error |
|
120 | - */ |
|
121 | - public function getMimeType() |
|
122 | - { |
|
123 | - $this->checkFileExistence(); |
|
124 | - if (function_exists('finfo_file')) { |
|
125 | - $fileInfo = new \finfo(); |
|
126 | - return $fileInfo->file($this->getFileWithAbsolutePath(), FILEINFO_MIME_TYPE); |
|
127 | - } elseif (function_exists('mime_content_type')) { |
|
128 | - return mime_content_type($this->getFileWithAbsolutePath()); |
|
129 | - } |
|
130 | - return false; |
|
131 | - } |
|
19 | + /** |
|
20 | + * @var string |
|
21 | + */ |
|
22 | + protected $inputName = 'qqfile'; |
|
23 | + |
|
24 | + /** |
|
25 | + * @var string |
|
26 | + */ |
|
27 | + protected $uploadFolder; |
|
28 | + |
|
29 | + /** |
|
30 | + * @var string |
|
31 | + */ |
|
32 | + protected $name; |
|
33 | + |
|
34 | + /** |
|
35 | + * @var string |
|
36 | + */ |
|
37 | + protected $image; |
|
38 | + |
|
39 | + /** |
|
40 | + * @var string |
|
41 | + */ |
|
42 | + protected $extension; |
|
43 | + |
|
44 | + /** |
|
45 | + * @return \Fab\Media\FileUpload\Base64File |
|
46 | + */ |
|
47 | + public function __construct() |
|
48 | + { |
|
49 | + |
|
50 | + // Processes the encoded image data and returns the decoded image |
|
51 | + $encodedImage = GeneralUtility::_POST($this->inputName); |
|
52 | + if (preg_match('/^data:image\/(jpg|jpeg|png)/i', $encodedImage, $matches)) { |
|
53 | + $this->extension = $matches[1]; |
|
54 | + } else { |
|
55 | + return false; |
|
56 | + } |
|
57 | + |
|
58 | + // Remove the mime-type header |
|
59 | + $data = reset(array_reverse(explode('base64,', $encodedImage))); |
|
60 | + |
|
61 | + // Use strict mode to prevent characters from outside the base64 range |
|
62 | + $this->image = base64_decode($data, true); |
|
63 | + |
|
64 | + if (!$this->image) { |
|
65 | + return false; |
|
66 | + } |
|
67 | + |
|
68 | + $this->setName(uniqid() . '.' . $this->extension); |
|
69 | + } |
|
70 | + |
|
71 | + /** |
|
72 | + * Save the file to the specified path |
|
73 | + * |
|
74 | + * @throws \Fab\Media\Exception\EmptyPropertyException |
|
75 | + * @return boolean true on success |
|
76 | + */ |
|
77 | + public function save() |
|
78 | + { |
|
79 | + |
|
80 | + if (is_null($this->uploadFolder)) { |
|
81 | + throw new \Fab\Media\Exception\EmptyPropertyException('Upload folder is not defined', 1362587741); |
|
82 | + } |
|
83 | + |
|
84 | + if (is_null($this->name)) { |
|
85 | + throw new \Fab\Media\Exception\EmptyPropertyException('File name is not defined', 1362587742); |
|
86 | + } |
|
87 | + |
|
88 | + return file_put_contents($this->getFileWithAbsolutePath(), $this->image) > 0; |
|
89 | + } |
|
90 | + |
|
91 | + /** |
|
92 | + * Get the original file name. |
|
93 | + * |
|
94 | + * @return string |
|
95 | + */ |
|
96 | + public function getOriginalName() |
|
97 | + { |
|
98 | + return $this->getName(); |
|
99 | + } |
|
100 | + |
|
101 | + /** |
|
102 | + * Get the file size |
|
103 | + * |
|
104 | + * @throws \Exception |
|
105 | + * @return integer file-size in byte |
|
106 | + */ |
|
107 | + public function getSize() |
|
108 | + { |
|
109 | + if (isset($GLOBALS['_SERVER']['CONTENT_LENGTH'])) { |
|
110 | + return (int)$GLOBALS['_SERVER']['CONTENT_LENGTH']; |
|
111 | + } else { |
|
112 | + throw new \Exception('Getting content length is not supported.'); |
|
113 | + } |
|
114 | + } |
|
115 | + |
|
116 | + /** |
|
117 | + * Get MIME type of file. |
|
118 | + * |
|
119 | + * @return string|boolean MIME type. eg, text/html, false on error |
|
120 | + */ |
|
121 | + public function getMimeType() |
|
122 | + { |
|
123 | + $this->checkFileExistence(); |
|
124 | + if (function_exists('finfo_file')) { |
|
125 | + $fileInfo = new \finfo(); |
|
126 | + return $fileInfo->file($this->getFileWithAbsolutePath(), FILEINFO_MIME_TYPE); |
|
127 | + } elseif (function_exists('mime_content_type')) { |
|
128 | + return mime_content_type($this->getFileWithAbsolutePath()); |
|
129 | + } |
|
130 | + return false; |
|
131 | + } |
|
132 | 132 | } |
@@ -65,7 +65,7 @@ |
||
65 | 65 | return false; |
66 | 66 | } |
67 | 67 | |
68 | - $this->setName(uniqid() . '.' . $this->extension); |
|
68 | + $this->setName(uniqid().'.'.$this->extension); |
|
69 | 69 | } |
70 | 70 | |
71 | 71 | /** |