ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
Vorbiscomment.php
Go to the documentation of this file.
1<?php
2
3namespace GetId3\Write;
4
6
9// available at http://getid3.sourceforge.net //
10// or http://www.getid3.org //
12// See readme.txt for more details //
14// //
15// write.vorbiscomment.php //
16// module for writing VorbisComment tags //
17// dependencies: /helperapps/vorbiscomment.exe //
18// ///
20
30{
31
32 public $filename;
33 public $tag_data;
38 public $warnings = array(); // any non-critical errors will be stored here
43 public $errors = array(); // any critical errors will be stored here
44
49 public function __construct()
50 {
51 return true;
52 }
53
58 public function WriteVorbisComment()
59 {
60 if (preg_match('#(1|ON)#i', ini_get('safe_mode'))) {
61 $this->errors[] = 'PHP running in Safe Mode (backtick operator not available) - cannot call vorbiscomment, tags not written';
62
63 return false;
64 }
65
66 // Create file with new comments
67 $tempcommentsfilename = tempnam(GetId3Core::getTempDir(), 'getID3');
68 if (is_writable($tempcommentsfilename) && is_file($tempcommentsfilename) && ($fpcomments = fopen($tempcommentsfilename, 'wb'))) {
69
70 foreach ($this->tag_data as $key => $value) {
71 foreach ($value as $commentdata) {
72 fwrite($fpcomments, $this->CleanVorbisCommentName($key).'='.$commentdata."\n");
73 }
74 }
75 fclose($fpcomments);
76
77 } else {
78 $this->errors[] = 'failed to open temporary tags file "'.$tempcommentsfilename.'", tags not written';
79
80 return false;
81 }
82
83 $oldignoreuserabort = ignore_user_abort(true);
85
86 if (file_exists(GetId3Core::getHelperAppsDir().'vorbiscomment.exe')) {
87 //$commandline = '"'.GetId3Core::getHelperAppsDir().'vorbiscomment.exe" -w --raw -c "'.$tempcommentsfilename.'" "'.str_replace('/', '\\', $this->filename).'"';
88 // vorbiscomment works fine if you copy-paste the above commandline into a command prompt,
89 // but refuses to work with `backtick` if there are "doublequotes" present around BOTH
90 // the metaflac pathname and the target filename. For whatever reason...??
91 // The solution is simply ensure that the metaflac pathname has no spaces,
92 // and therefore does not need to be quoted
93
94 // On top of that, if error messages are not always captured properly under Windows
95 // To at least see if there was a problem, compare file modification timestamps before and after writing
96 clearstatcache();
97 $timestampbeforewriting = filemtime($this->filename);
98
99 $commandline = GetId3Core::getHelperAppsDir().'vorbiscomment.exe -w --raw -c "'.$tempcommentsfilename.'" "'.$this->filename.'" 2>&1';
100 $VorbiscommentError = `$commandline`;
101
102 if (empty($VorbiscommentError)) {
103 clearstatcache();
104 if ($timestampbeforewriting == filemtime($this->filename)) {
105 $VorbiscommentError = 'File modification timestamp has not changed - it looks like the tags were not written';
106 }
107 }
108 } else {
109 $VorbiscommentError = 'vorbiscomment.exe not found in '.GetId3Core::getHelperAppsDir();
110 }
111
112 } else {
113
114 $commandline = 'vorbiscomment -w --raw -c "'.$tempcommentsfilename.'" "'.$this->filename.'" 2>&1';
115 $VorbiscommentError = `$commandline`;
116
117 }
118
119 // Remove temporary comments file
120 unlink($tempcommentsfilename);
121 ignore_user_abort($oldignoreuserabort);
122
123 if (!empty($VorbiscommentError)) {
124
125 $this->errors[] = 'system call to vorbiscomment failed with message: '."\n\n".$VorbiscommentError;
126
127 return false;
128
129 }
130
131 return true;
132 }
133
138 public function DeleteVorbisComment()
139 {
140 $this->tag_data = array(array());
141
142 return $this->WriteVorbisComment();
143 }
144
150 public function CleanVorbisCommentName($originalcommentname)
151 {
152 // A case-insensitive field name that may consist of ASCII 0x20 through 0x7D, 0x3D ('=') excluded.
153 // ASCII 0x41 through 0x5A inclusive (A-Z) is to be considered equivalent to ASCII 0x61 through
154 // 0x7A inclusive (a-z).
155
156 // replace invalid chars with a space, return uppercase text
157 // Thanks Chris Bolt <chris-getid3Øbolt*cx> for improving this function
158 // note: *reg_replace() replaces nulls with empty string (not space)
159 return strtoupper(preg_replace('#[^ -<>-}]#', ' ', str_replace("\x00", ' ', $originalcommentname)));
160
161 }
162
163}
An exception for terminatinating execution or to throw for unit testing.
GetId3() by James Heinrich info@getid3.org //.
Definition: GetId3Core.php:26
static environmentIsWindows()
static getHelperAppsDir()
Definition: GetId3Core.php:186
GetId3() by James Heinrich info@getid3.org //.
CleanVorbisCommentName($originalcommentname)