Added remove artwork option, and a few changes.
This commit is contained in:
parent
9f2d941c87
commit
2bb0976300
6 changed files with 106 additions and 39 deletions
|
@ -235,7 +235,7 @@ class FileDataHelper {
|
|||
*
|
||||
* @return string Path to artwork
|
||||
*/
|
||||
public static function uploadArtwork($trackid, $data)
|
||||
public static function setArtwork($trackid, $data)
|
||||
{
|
||||
$file = Application_Model_StoredFile::RecallById($trackid);
|
||||
$md = $file->getMetadata();
|
||||
|
@ -246,6 +246,13 @@ class FileDataHelper {
|
|||
$dbAudioPath = $md["MDATA_KEY_FILEPATH"];
|
||||
$fullpath = $fp . $dbAudioPath;
|
||||
|
||||
if ($data == "0") {
|
||||
|
||||
$get_img = "";
|
||||
self::removeArtwork($trackid, $data);
|
||||
|
||||
} else {
|
||||
|
||||
$base64 = @$data;
|
||||
$mime = explode(';', $base64)[0];
|
||||
|
||||
|
@ -274,9 +281,35 @@ class FileDataHelper {
|
|||
}
|
||||
self::resizeGroup($rfile, $ext);
|
||||
|
||||
}
|
||||
return $get_img;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Deletes just the artwork
|
||||
*/
|
||||
public static function removeArtwork($trackid)
|
||||
{
|
||||
$file = Application_Model_StoredFile::RecallById($trackid);
|
||||
$md = $file->getMetadata();
|
||||
|
||||
$storDir = Application_Model_MusicDir::getStorDir();
|
||||
$fp = $storDir->getDirectory();
|
||||
|
||||
$dbAudioPath = $md["MDATA_KEY_ARTWORK"];
|
||||
$fullpath = $fp . $dbAudioPath;
|
||||
|
||||
if (file_exists($fullpath)) {
|
||||
foreach (glob("$fullpath*", GLOB_NOSORT) as $filename) {
|
||||
unlink($filename);
|
||||
}
|
||||
} else {
|
||||
throw new Exception("Could not locate file ".$filepath);
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
/**
|
||||
* Resize artwork group
|
||||
*
|
||||
|
|
|
@ -397,15 +397,18 @@ class LibraryController extends Zend_Controller_Action
|
|||
if ($j["value"] == null || $j["value"] == ''){
|
||||
$serialized["artwork"] = FileDataHelper::resetArtwork($file_id);
|
||||
}
|
||||
} elseif ($j["name"] == "set_artwork") {
|
||||
if ($j["value"] != null || $j["value"] != ''){
|
||||
$serialized["artwork"] = FileDataHelper::setArtwork($file_id, $j["value"] );
|
||||
}
|
||||
} elseif ($j["name"] == "remove_artwork") {
|
||||
if ($j["value"] == 1){
|
||||
$remove_artwork = true;
|
||||
$serialized["artwork"] = FileDataHelper::removeArtwork($file_id);
|
||||
}
|
||||
} else {
|
||||
$serialized[$j["name"]] = $j["value"];
|
||||
}
|
||||
|
||||
if ($j["name"] == "artwork_uploaded") {
|
||||
if ($j["value"] != null || $j["value"] != ''){
|
||||
$serialized["artwork"] = FileDataHelper::uploadArtwork($file_id, $j["value"] );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Sanitize any wildly incorrect metadata before it goes to be validated.
|
||||
|
|
|
@ -20,6 +20,7 @@ class Application_Form_EditAudioMD extends Zend_Form
|
|||
|
||||
// Add artwork hidden field
|
||||
$artwork = new Zend_Form_Element_Hidden('artwork');
|
||||
$artwork->class = 'input_text artwork_'. $p_id;
|
||||
$artwork->setFilters(array('StringTrim'))
|
||||
->setValidators(array(
|
||||
new Zend_Validate_StringLength(array('max' => 2048))
|
||||
|
@ -29,13 +30,21 @@ class Application_Form_EditAudioMD extends Zend_Form
|
|||
$file_id->setAttrib('class', 'artwork');
|
||||
$this->addElement($artwork);
|
||||
|
||||
// Add artwork uploaded hidden field
|
||||
$artwork_uploaded = new Zend_Form_Element_Hidden('artwork_uploaded');
|
||||
$artwork_uploaded->class = 'input_text artwork_uploaded_'. $p_id;
|
||||
// Set artwork hidden field
|
||||
$set_artwork = new Zend_Form_Element_Hidden('set_artwork');
|
||||
$set_artwork->class = 'input_text set_artwork_'. $p_id;
|
||||
$file_id->addDecorator('HtmlTag', array('tag' => 'div', 'style' => 'display:none'));
|
||||
$file_id->removeDecorator('Label');
|
||||
$file_id->setAttrib('class', 'artwork_uploaded');
|
||||
$this->addElement($artwork_uploaded);
|
||||
$file_id->setAttrib('class', 'set_artwork');
|
||||
$this->addElement($set_artwork);
|
||||
|
||||
// Remove artwork hidden field
|
||||
$remove_artwork = new Zend_Form_Element_Hidden('remove_artwork');
|
||||
$remove_artwork->class = 'input_text remove_artwork_'. $p_id;
|
||||
$file_id->addDecorator('HtmlTag', array('tag' => 'div', 'style' => 'display:none'));
|
||||
$file_id->removeDecorator('Label');
|
||||
$file_id->setAttrib('class', 'remove_artwork');
|
||||
$this->addElement($remove_artwork);
|
||||
|
||||
// Add title field
|
||||
$track_title = new Zend_Form_Element_Text('track_title');
|
||||
|
|
|
@ -29,6 +29,9 @@
|
|||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<a href="#" class="delete-artwork" data-id="<?php echo($this->id); ?>" style="font-size: 11px;">Remove</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div style="height: 160px;"></div>
|
||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 69 KiB After Width: | Height: | Size: 66 KiB |
|
@ -1609,7 +1609,7 @@ function readArtworkURL(input, id) {
|
|||
$('.artwork-preview-'+id).css('background-image', 'url('+e.target.result +')');
|
||||
$('.artwork-preview-'+id).hide();
|
||||
$('.artwork-preview-'+id).fadeIn(500);
|
||||
$('.artwork_uploaded_'+id).val(function() {
|
||||
$('.set_artwork_'+id).val(function() {
|
||||
return e.target.result;
|
||||
});
|
||||
}
|
||||
|
@ -1678,6 +1678,25 @@ $(document).ready(function() {
|
|||
resizeAdvancedSearch();
|
||||
});
|
||||
|
||||
// delete artwork
|
||||
$(document).on('click', '.delete-artwork', function(event) {
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
var id = $(this).attr('data-id');
|
||||
$('.artwork-preview-'+id).css('background-image', 'url('+ baseUrl +'css/images/no-cover.jpg)');
|
||||
$('.artwork-preview-'+id).hide();
|
||||
$('.artwork-preview-'+id).fadeIn(500);
|
||||
$('.artwork_'+id).val(function() {
|
||||
return "";
|
||||
});
|
||||
$('.set_artwork_'+id).val(function() {
|
||||
return "";
|
||||
});
|
||||
$('.remove_artwork_'+id).val(function() {
|
||||
return 1;
|
||||
});
|
||||
});
|
||||
|
||||
// image upload by clicking on the artwork container
|
||||
$(document).on('change', '.artworkUpload', 'input', function(event) {
|
||||
event.preventDefault();
|
||||
|
@ -1760,7 +1779,7 @@ $(document).ready(function() {
|
|||
$('.artwork-preview-'+id).css('background-image', 'url('+ data +')');
|
||||
$('.artwork-preview-'+id).hide();
|
||||
$('.artwork-preview-'+id).fadeIn(500);
|
||||
$('.artwork_uploaded_'+id).val(function() {
|
||||
$('.set_artwork_'+id).val(function() {
|
||||
return data;
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue