~canonical-sysadmins/wordpress/4.5.2

« back to all changes in this revision

Viewing changes to wp-includes/ID3/module.tag.apetag.php

  • Committer: Ryan Finnie
  • Date: 2015-08-31 16:09:47 UTC
  • mfrom: (1.1.9 upstream)
  • Revision ID: ryan.finnie@canonical.com-20150831160947-1h6rfxby9z1ec62u
Merge WP4.3 from upstream

Show diffs side-by-side

added added

removed removed

Lines of Context:
138
138
                        $thisfile_ape_items_current['flags'] = $this->parseAPEtagFlags($item_flags);
139
139
                        switch ($thisfile_ape_items_current['flags']['item_contents_raw']) {
140
140
                                case 0: // UTF-8
141
 
                                case 3: // Locator (URL, filename, etc), UTF-8 encoded
142
 
                                        $thisfile_ape_items_current['data'] = explode("\x00", trim($thisfile_ape_items_current['data']));
 
141
                                case 2: // Locator (URL, filename, etc), UTF-8 encoded
 
142
                                        $thisfile_ape_items_current['data'] = explode("\x00", $thisfile_ape_items_current['data']);
143
143
                                        break;
144
144
 
145
 
                                default: // binary data
 
145
                                case 1:  // binary data
 
146
                                default:
146
147
                                        break;
147
148
                        }
148
149
 
149
150
                        switch (strtolower($item_key)) {
 
151
                                // http://wiki.hydrogenaud.io/index.php?title=ReplayGain#MP3Gain
150
152
                                case 'replaygain_track_gain':
151
 
                                        $thisfile_replaygain['track']['adjustment'] = (float) str_replace(',', '.', $thisfile_ape_items_current['data'][0]); // float casting will see "0,95" as zero!
152
 
                                        $thisfile_replaygain['track']['originator'] = 'unspecified';
 
153
                                        if (preg_match('#^[\\-\\+][0-9\\.,]{8}$#', $thisfile_ape_items_current['data'][0])) {
 
154
                                                $thisfile_replaygain['track']['adjustment'] = (float) str_replace(',', '.', $thisfile_ape_items_current['data'][0]); // float casting will see "0,95" as zero!
 
155
                                                $thisfile_replaygain['track']['originator'] = 'unspecified';
 
156
                                        } else {
 
157
                                                $info['warning'][] = 'MP3gainTrackGain value in APEtag appears invalid: "'.$thisfile_ape_items_current['data'][0].'"';
 
158
                                        }
153
159
                                        break;
154
160
 
155
161
                                case 'replaygain_track_peak':
156
 
                                        $thisfile_replaygain['track']['peak']       = (float) str_replace(',', '.', $thisfile_ape_items_current['data'][0]); // float casting will see "0,95" as zero!
157
 
                                        $thisfile_replaygain['track']['originator'] = 'unspecified';
158
 
                                        if ($thisfile_replaygain['track']['peak'] <= 0) {
159
 
                                                $info['warning'][] = 'ReplayGain Track peak from APEtag appears invalid: '.$thisfile_replaygain['track']['peak'].' (original value = "'.$thisfile_ape_items_current['data'][0].'")';
 
162
                                        if (preg_match('#^[0-9\\.,]{8}$#', $thisfile_ape_items_current['data'][0])) {
 
163
                                                $thisfile_replaygain['track']['peak']       = (float) str_replace(',', '.', $thisfile_ape_items_current['data'][0]); // float casting will see "0,95" as zero!
 
164
                                                $thisfile_replaygain['track']['originator'] = 'unspecified';
 
165
                                                if ($thisfile_replaygain['track']['peak'] <= 0) {
 
166
                                                        $info['warning'][] = 'ReplayGain Track peak from APEtag appears invalid: '.$thisfile_replaygain['track']['peak'].' (original value = "'.$thisfile_ape_items_current['data'][0].'")';
 
167
                                                }
 
168
                                        } else {
 
169
                                                $info['warning'][] = 'MP3gainTrackPeak value in APEtag appears invalid: "'.$thisfile_ape_items_current['data'][0].'"';
160
170
                                        }
161
171
                                        break;
162
172
 
163
173
                                case 'replaygain_album_gain':
164
 
                                        $thisfile_replaygain['album']['adjustment'] = (float) str_replace(',', '.', $thisfile_ape_items_current['data'][0]); // float casting will see "0,95" as zero!
165
 
                                        $thisfile_replaygain['album']['originator'] = 'unspecified';
 
174
                                        if (preg_match('#^[\\-\\+][0-9\\.,]{8}$#', $thisfile_ape_items_current['data'][0])) {
 
175
                                                $thisfile_replaygain['album']['adjustment'] = (float) str_replace(',', '.', $thisfile_ape_items_current['data'][0]); // float casting will see "0,95" as zero!
 
176
                                                $thisfile_replaygain['album']['originator'] = 'unspecified';
 
177
                                        } else {
 
178
                                                $info['warning'][] = 'MP3gainAlbumGain value in APEtag appears invalid: "'.$thisfile_ape_items_current['data'][0].'"';
 
179
                                        }
166
180
                                        break;
167
181
 
168
182
                                case 'replaygain_album_peak':
169
 
                                        $thisfile_replaygain['album']['peak']       = (float) str_replace(',', '.', $thisfile_ape_items_current['data'][0]); // float casting will see "0,95" as zero!
170
 
                                        $thisfile_replaygain['album']['originator'] = 'unspecified';
171
 
                                        if ($thisfile_replaygain['album']['peak'] <= 0) {
172
 
                                                $info['warning'][] = 'ReplayGain Album peak from APEtag appears invalid: '.$thisfile_replaygain['album']['peak'].' (original value = "'.$thisfile_ape_items_current['data'][0].'")';
 
183
                                        if (preg_match('#^[0-9\\.,]{8}$#', $thisfile_ape_items_current['data'][0])) {
 
184
                                                $thisfile_replaygain['album']['peak']       = (float) str_replace(',', '.', $thisfile_ape_items_current['data'][0]); // float casting will see "0,95" as zero!
 
185
                                                $thisfile_replaygain['album']['originator'] = 'unspecified';
 
186
                                                if ($thisfile_replaygain['album']['peak'] <= 0) {
 
187
                                                        $info['warning'][] = 'ReplayGain Album peak from APEtag appears invalid: '.$thisfile_replaygain['album']['peak'].' (original value = "'.$thisfile_ape_items_current['data'][0].'")';
 
188
                                                }
 
189
                                        } else {
 
190
                                                $info['warning'][] = 'MP3gainAlbumPeak value in APEtag appears invalid: "'.$thisfile_ape_items_current['data'][0].'"';
173
191
                                        }
174
192
                                        break;
175
193
 
176
194
                                case 'mp3gain_undo':
177
 
                                        list($mp3gain_undo_left, $mp3gain_undo_right, $mp3gain_undo_wrap) = explode(',', $thisfile_ape_items_current['data'][0]);
178
 
                                        $thisfile_replaygain['mp3gain']['undo_left']  = intval($mp3gain_undo_left);
179
 
                                        $thisfile_replaygain['mp3gain']['undo_right'] = intval($mp3gain_undo_right);
180
 
                                        $thisfile_replaygain['mp3gain']['undo_wrap']  = (($mp3gain_undo_wrap == 'Y') ? true : false);
 
195
                                        if (preg_match('#^[\\-\\+][0-9]{3},[\\-\\+][0-9]{3},[NW]$#', $thisfile_ape_items_current['data'][0])) {
 
196
                                                list($mp3gain_undo_left, $mp3gain_undo_right, $mp3gain_undo_wrap) = explode(',', $thisfile_ape_items_current['data'][0]);
 
197
                                                $thisfile_replaygain['mp3gain']['undo_left']  = intval($mp3gain_undo_left);
 
198
                                                $thisfile_replaygain['mp3gain']['undo_right'] = intval($mp3gain_undo_right);
 
199
                                                $thisfile_replaygain['mp3gain']['undo_wrap']  = (($mp3gain_undo_wrap == 'Y') ? true : false);
 
200
                                        } else {
 
201
                                                $info['warning'][] = 'MP3gainUndo value in APEtag appears invalid: "'.$thisfile_ape_items_current['data'][0].'"';
 
202
                                        }
181
203
                                        break;
182
204
 
183
205
                                case 'mp3gain_minmax':
184
 
                                        list($mp3gain_globalgain_min, $mp3gain_globalgain_max) = explode(',', $thisfile_ape_items_current['data'][0]);
185
 
                                        $thisfile_replaygain['mp3gain']['globalgain_track_min'] = intval($mp3gain_globalgain_min);
186
 
                                        $thisfile_replaygain['mp3gain']['globalgain_track_max'] = intval($mp3gain_globalgain_max);
 
206
                                        if (preg_match('#^[0-9]{3},[0-9]{3}$#', $thisfile_ape_items_current['data'][0])) {
 
207
                                                list($mp3gain_globalgain_min, $mp3gain_globalgain_max) = explode(',', $thisfile_ape_items_current['data'][0]);
 
208
                                                $thisfile_replaygain['mp3gain']['globalgain_track_min'] = intval($mp3gain_globalgain_min);
 
209
                                                $thisfile_replaygain['mp3gain']['globalgain_track_max'] = intval($mp3gain_globalgain_max);
 
210
                                        } else {
 
211
                                                $info['warning'][] = 'MP3gainMinMax value in APEtag appears invalid: "'.$thisfile_ape_items_current['data'][0].'"';
 
212
                                        }
187
213
                                        break;
188
214
 
189
215
                                case 'mp3gain_album_minmax':
190
 
                                        list($mp3gain_globalgain_album_min, $mp3gain_globalgain_album_max) = explode(',', $thisfile_ape_items_current['data'][0]);
191
 
                                        $thisfile_replaygain['mp3gain']['globalgain_album_min'] = intval($mp3gain_globalgain_album_min);
192
 
                                        $thisfile_replaygain['mp3gain']['globalgain_album_max'] = intval($mp3gain_globalgain_album_max);
 
216
                                        if (preg_match('#^[0-9]{3},[0-9]{3}$#', $thisfile_ape_items_current['data'][0])) {
 
217
                                                list($mp3gain_globalgain_album_min, $mp3gain_globalgain_album_max) = explode(',', $thisfile_ape_items_current['data'][0]);
 
218
                                                $thisfile_replaygain['mp3gain']['globalgain_album_min'] = intval($mp3gain_globalgain_album_min);
 
219
                                                $thisfile_replaygain['mp3gain']['globalgain_album_max'] = intval($mp3gain_globalgain_album_max);
 
220
                                        } else {
 
221
                                                $info['warning'][] = 'MP3gainAlbumMinMax value in APEtag appears invalid: "'.$thisfile_ape_items_current['data'][0].'"';
 
222
                                        }
193
223
                                        break;
194
224
 
195
225
                                case 'tracknumber':
222
252
                                case 'cover art (recording)':
223
253
                                case 'cover art (studio)':
224
254
                                        // list of possible cover arts from http://taglib-sharp.sourcearchive.com/documentation/2.0.3.0-2/Ape_2Tag_8cs-source.html
 
255
                                        if (is_array($thisfile_ape_items_current['data'])) {
 
256
                                                $info['warning'][] = 'APEtag "'.$item_key.'" should be flagged as Binary data, but was incorrectly flagged as UTF-8';
 
257
                                                $thisfile_ape_items_current['data'] = implode("\x00", $thisfile_ape_items_current['data']);
 
258
                                        }
225
259
                                        list($thisfile_ape_items_current['filename'], $thisfile_ape_items_current['data']) = explode("\x00", $thisfile_ape_items_current['data'], 2);
226
260
                                        $thisfile_ape_items_current['data_offset'] = $thisfile_ape_items_current['offset'] + strlen($thisfile_ape_items_current['filename']."\x00");
227
261
                                        $thisfile_ape_items_current['data_length'] = strlen($thisfile_ape_items_current['data']);
269
303
                                                        if (!isset($info['ape']['comments']['picture'])) {
270
304
                                                                $info['ape']['comments']['picture'] = array();
271
305
                                                        }
272
 
                                                        $info['ape']['comments']['picture'][] = array('data'=>$thisfile_ape_items_current['data'], 'image_mime'=>$thisfile_ape_items_current['image_mime']);
 
306
                                                        $comments_picture_data = array();
 
307
                                                        foreach (array('data', 'image_mime', 'image_width', 'image_height', 'imagetype', 'picturetype', 'description', 'datalength') as $picture_key) {
 
308
                                                                if (isset($thisfile_ape_items_current[$picture_key])) {
 
309
                                                                        $comments_picture_data[$picture_key] = $thisfile_ape_items_current[$picture_key];
 
310
                                                                }
 
311
                                                        }
 
312
                                                        $info['ape']['comments']['picture'][] = $comments_picture_data;
 
313
                                                        unset($comments_picture_data);
273
314
                                                }
274
315
                                        } while (false);
275
316
                                        break;
317
358
        public function parseAPEtagFlags($rawflagint) {
318
359
                // "Note: APE Tags 1.0 do not use any of the APE Tag flags.
319
360
                // All are set to zero on creation and ignored on reading."
320
 
                // http://www.uni-jena.de/~pfk/mpp/sv8/apetagflags.html
 
361
                // http://wiki.hydrogenaud.io/index.php?title=Ape_Tags_Flags
321
362
                $flags['header']            = (bool) ($rawflagint & 0x80000000);
322
363
                $flags['footer']            = (bool) ($rawflagint & 0x40000000);
323
364
                $flags['this_is_header']    = (bool) ($rawflagint & 0x20000000);
368
409
                return in_array(strtolower($itemkey), $APEtagItemIsUTF8Lookup);
369
410
        }
370
411
 
371
 
}
 
 
b'\\ No newline at end of file'
 
412
}