|
Size: | 3514 |
Storage flags: | strip |
<?php
class getid3_write_metaflac
{
public $filename;
public $tag_data;
public $warnings = array();
public $errors = array();
public function getid3_write_metaflac() {
return true;
}
public function WriteMetaFLAC() {
if (preg_match('#(1|ON)#i', ini_get('safe_mode'))) {
$this->errors[] = 'PHP running in Safe Mode (backtick operator not available) - cannot call metaflac, tags not written';
return false;
}
$tempcommentsfilename = tempnam(GETID3_TEMP_DIR, 'getID3');
if (is_writable($tempcommentsfilename) && is_file($tempcommentsfilename) && ($fpcomments = fopen($tempcommentsfilename, 'wb'))) {
foreach ($this->tag_data as $key => $value) {
foreach ($value as $commentdata) {
fwrite($fpcomments, $this->CleanmetaflacName($key).'='.$commentdata."\n");
}
}
fclose($fpcomments);
} else {
$this->errors[] = 'failed to open temporary tags file, tags not written - fopen("'.$tempcommentsfilename.'", "wb")';
return false;
}
$oldignoreuserabort = ignore_user_abort(true);
if (GETID3_OS_ISWINDOWS) {
if (file_exists(GETID3_HELPERAPPSDIR.'metaflac.exe')) {
clearstatcache();
$timestampbeforewriting = filemtime($this->filename);
$commandline = GETID3_HELPERAPPSDIR.'metaflac.exe --no-utf8-convert --remove-all-tags --import-tags-from='.escapeshellarg($tempcommentsfilename).' '.escapeshellarg($this->filename).' 2>&1';
$metaflacError = `$commandline`;
if (empty($metaflacError)) {
clearstatcache();
if ($timestampbeforewriting == filemtime($this->filename)) {
$metaflacError = 'File modification timestamp has not changed - it looks like the tags were not written';
}
}
} else {
$metaflacError = 'metaflac.exe not found in '.GETID3_HELPERAPPSDIR;
}
} else {
$commandline = 'metaflac --no-utf8-convert --remove-all-tags --import-tags-from='.escapeshellarg($tempcommentsfilename).' '.escapeshellarg($this->filename).' 2>&1';
$metaflacError = `$commandline`;
}
unlink($tempcommentsfilename);
ignore_user_abort($oldignoreuserabort);
if (!empty($metaflacError)) {
$this->errors[] = 'System call to metaflac failed with this message returned: '."\n\n".$metaflacError;
return false;
}
return true;
}
public function DeleteMetaFLAC() {
if (preg_match('#(1|ON)#i', ini_get('safe_mode'))) {
$this->errors[] = 'PHP running in Safe Mode (backtick operator not available) - cannot call metaflac, tags not deleted';
return false;
}
$oldignoreuserabort = ignore_user_abort(true);
if (GETID3_OS_ISWINDOWS) {
if (file_exists(GETID3_HELPERAPPSDIR.'metaflac.exe')) {
clearstatcache();
$timestampbeforewriting = filemtime($this->filename);
$commandline = GETID3_HELPERAPPSDIR.'metaflac.exe --remove-all-tags "'.$this->filename.'" 2>&1';
$metaflacError = `$commandline`;
if (empty($metaflacError)) {
clearstatcache();
if ($timestampbeforewriting == filemtime($this->filename)) {
$metaflacError = 'File modification timestamp has not changed - it looks like the tags were not deleted';
}
}
} else {
$metaflacError = 'metaflac.exe not found in '.GETID3_HELPERAPPSDIR;
}
} else {
$commandline = 'metaflac --remove-all-tags "'.$this->filename.'" 2>&1';
$metaflacError = `$commandline`;
}
ignore_user_abort($oldignoreuserabort);
if (!empty($metaflacError)) {
$this->errors[] = 'System call to metaflac failed with this message returned: '."\n\n".$metaflacError;
return false;
}
return true;
}
public function CleanmetaflacName($originalcommentname) {
return strtoupper(preg_replace('#[^ -<>-}]#', ' ', str_replace("\x00", ' ', $originalcommentname)));
}
}