• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

Services/MediaObjects/getid3/getid3/write.metaflac.php

Go to the documentation of this file.
00001 <?php
00004 //  available at http://getid3.sourceforge.net                 //
00005 //            or http://www.getid3.org                         //
00007 // See readme.txt for more details                             //
00009 //                                                             //
00010 // write.metaflac.php                                          //
00011 // module for writing metaflac tags                            //
00012 // dependencies: /helperapps/metaflac.exe                      //
00013 //                                                            ///
00015 
00016 
00017 class getid3_write_metaflac
00018 {
00019 
00020         var $filename;
00021         var $tag_data;
00022         var $warnings = array(); // any non-critical errors will be stored here
00023         var $errors   = array(); // any critical errors will be stored here
00024 
00025         function getid3_write_metaflac() {
00026                 return true;
00027         }
00028 
00029         function WriteMetaFLAC() {
00030 
00031                 if (!ini_get('safe_mode')) {
00032 
00033                         // Create file with new comments
00034                         $tempcommentsfilename = tempnam('*', 'getID3');
00035                         if ($fpcomments = @fopen($tempcommentsfilename, 'wb')) {
00036 
00037                                 foreach ($this->tag_data as $key => $value) {
00038                                         foreach ($value as $commentdata) {
00039                                                 fwrite($fpcomments, $this->CleanmetaflacName($key).'='.$commentdata."\n");
00040                                         }
00041                                 }
00042                                 fclose($fpcomments);
00043 
00044                         } else {
00045 
00046                                 $this->errors[] = 'failed to open temporary tags file "'.$tempcommentsfilename.'", tags not written';
00047                                 return false;
00048 
00049                         }
00050 
00051                         $oldignoreuserabort = ignore_user_abort(true);
00052                         if (GETID3_OS_ISWINDOWS) {
00053 
00054                                 if (file_exists(GETID3_HELPERAPPSDIR.'metaflac.exe')) {
00055                                         //$commandline = '"'.GETID3_HELPERAPPSDIR.'metaflac.exe" --no-utf8-convert --remove-vc-all --import-vc-from="'.$tempcommentsfilename.'" "'.str_replace('/', '\\', $this->filename).'"';
00056                                         //  metaflac works fine if you copy-paste the above commandline into a command prompt,
00057                                         //  but refuses to work with `backtick` if there are "doublequotes" present around BOTH
00058                                         //  the metaflac pathname and the target filename. For whatever reason...??
00059                                         //  The solution is simply ensure that the metaflac pathname has no spaces,
00060                                         //  and therefore does not need to be quoted
00061 
00062                                         // On top of that, if error messages are not always captured properly under Windows
00063                                         // To at least see if there was a problem, compare file modification timestamps before and after writing
00064                                         clearstatcache();
00065                                         $timestampbeforewriting = filemtime($this->filename);
00066 
00067                                         $commandline = GETID3_HELPERAPPSDIR.'metaflac.exe --no-utf8-convert --remove-vc-all --import-vc-from="'.$tempcommentsfilename.'" "'.$this->filename.'" 2>&1';
00068                                         $metaflacError = `$commandline`;
00069 
00070                                         if (empty($metaflacError)) {
00071                                                 clearstatcache();
00072                                                 if ($timestampbeforewriting == filemtime($this->filename)) {
00073                                                         $metaflacError = 'File modification timestamp has not changed - it looks like the tags were not written';
00074                                                 }
00075                                         }
00076                                 } else {
00077                                         $metaflacError = 'metaflac.exe not found in '.GETID3_HELPERAPPSDIR;
00078                                 }
00079 
00080                         } else {
00081 
00082                                 // It's simpler on *nix
00083                                 $commandline = 'metaflac --no-utf8-convert --remove-vc-all --import-vc-from='.$tempcommentsfilename.' "'.$this->filename.'" 2>&1';
00084                                 $metaflacError = `$commandline`;
00085 
00086                         }
00087 
00088                         // Remove temporary comments file
00089                         unlink($tempcommentsfilename);
00090                         ignore_user_abort($oldignoreuserabort);
00091 
00092                         if (!empty($metaflacError)) {
00093 
00094                                 $this->errors[] = 'System call to metaflac failed with this message returned: '."\n\n".$metaflacError;
00095                                 return false;
00096 
00097                         }
00098 
00099                         return true;
00100                 }
00101 
00102                 $this->errors[] = 'PHP running in Safe Mode (backtick operator not available) - cannot call metaflac, tags not written';
00103                 return false;
00104         }
00105 
00106 
00107         function DeleteMetaFLAC() {
00108 
00109                 if (!ini_get('safe_mode')) {
00110 
00111                         $oldignoreuserabort = ignore_user_abort(true);
00112                         if (GETID3_OS_ISWINDOWS) {
00113 
00114                                 if (file_exists(GETID3_HELPERAPPSDIR.'metaflac.exe')) {
00115                                         // To at least see if there was a problem, compare file modification timestamps before and after writing
00116                                         clearstatcache();
00117                                         $timestampbeforewriting = filemtime($this->filename);
00118 
00119                                         $commandline = GETID3_HELPERAPPSDIR.'metaflac.exe --remove-vc-all "'.$this->filename.'" 2>&1';
00120                                         $metaflacError = `$commandline`;
00121 
00122                                         if (empty($metaflacError)) {
00123                                                 clearstatcache();
00124                                                 if ($timestampbeforewriting == filemtime($this->filename)) {
00125                                                         $metaflacError = 'File modification timestamp has not changed - it looks like the tags were not deleted';
00126                                                 }
00127                                         }
00128                                 } else {
00129                                         $metaflacError = 'metaflac.exe not found in '.GETID3_HELPERAPPSDIR;
00130                                 }
00131 
00132                         } else {
00133 
00134                                 // It's simpler on *nix
00135                                 $commandline = 'metaflac --remove-vc-all "'.$this->filename.'" 2>&1';
00136                                 $metaflacError = `$commandline`;
00137 
00138                         }
00139 
00140                         ignore_user_abort($oldignoreuserabort);
00141 
00142                         if (!empty($metaflacError)) {
00143                                 $this->errors[] = 'System call to metaflac failed with this message returned: '."\n\n".$metaflacError;
00144                                 return false;
00145                         }
00146                         return true;
00147                 }
00148                 $this->errors[] = 'PHP running in Safe Mode (backtick operator not available) - cannot call metaflac, tags not deleted';
00149                 return false;
00150         }
00151 
00152 
00153         function CleanmetaflacName($originalcommentname) {
00154                 // A case-insensitive field name that may consist of ASCII 0x20 through 0x7D, 0x3D ('=') excluded.
00155                 // ASCII 0x41 through 0x5A inclusive (A-Z) is to be considered equivalent to ASCII 0x61 through
00156                 // 0x7A inclusive (a-z).
00157 
00158                 // replace invalid chars with a space, return uppercase text
00159                 // Thanks Chris Bolt <chris-getid3Øbolt*cx> for improving this function
00160                 // note: ereg_replace() replaces nulls with empty string (not space)
00161                 return strtoupper(ereg_replace('[^ -<>-}]', ' ', str_replace("\x00", ' ', $originalcommentname)));
00162 
00163         }
00164 
00165 }
00166 
00167 ?>

Generated on Fri Dec 13 2013 17:56:59 for ILIAS Release_3_9_x_branch .rev 46835 by  doxygen 1.7.1