Merge branch 'cc-5709-airtime-analyzer' of github.com:sourcefabric/Airtime into cc-5709-airtime-analyzer
This commit is contained in:
commit
7caa42cf69
|
@ -15,39 +15,62 @@ class Application_Form_EditAudioMD extends Zend_Form
|
|||
'value' => $p_id
|
||||
));
|
||||
// Add title field
|
||||
$this->addElement('text', 'track_title', array(
|
||||
/*$this->addElement('text', 'track_title', array(
|
||||
'label' => _('Title:'),
|
||||
'class' => 'input_text',
|
||||
'filters' => array('StringTrim'),
|
||||
));
|
||||
));*/
|
||||
$track_title = new Zend_Form_Element_Text('track_title');
|
||||
$track_title->class = 'input_text';
|
||||
$track_title->setLabel(_('Title:'))
|
||||
->setFilters(array('StringTrim'))
|
||||
->setValidators(array(
|
||||
new Zend_Validate_StringLength(array('max' => 512))
|
||||
));
|
||||
$this->addElement($track_title);
|
||||
|
||||
// Add artist field
|
||||
$this->addElement('text', 'artist_name', array(
|
||||
/*$this->addElement('text', 'artist_name', array(
|
||||
'label' => _('Creator:'),
|
||||
'class' => 'input_text',
|
||||
'filters' => array('StringTrim'),
|
||||
));
|
||||
));*/
|
||||
$artist_name = new Zend_Form_Element_Text('artist_name');
|
||||
$artist_name->class = 'input_text';
|
||||
$artist_name->setLabel(_('Creator:'))
|
||||
->setFilters(array('StringTrim'))
|
||||
->setValidators(array(
|
||||
new Zend_Validate_StringLength(array('max' => 512))
|
||||
));
|
||||
$this->addElement($artist_name);
|
||||
|
||||
// Add album field
|
||||
$this->addElement('text', 'album_title', array(
|
||||
'label' => _('Album:'),
|
||||
'class' => 'input_text',
|
||||
'filters' => array('StringTrim')
|
||||
));
|
||||
$album_title = new Zend_Form_Element_Text('album_title');
|
||||
$album_title->class = 'input_text';
|
||||
$album_title->setLabel(_('Album:'))
|
||||
->setFilters(array('StringTrim'))
|
||||
->setValidators(array(
|
||||
new Zend_Validate_StringLength(array('max' => 512))
|
||||
));;
|
||||
$this->addElement($album_title);
|
||||
|
||||
// Add track number field
|
||||
$this->addElement('text', 'track_number', array(
|
||||
'label' => _('Track:'),
|
||||
'class' => 'input_text',
|
||||
'filters' => array('StringTrim'),
|
||||
));
|
||||
$track_number = new Zend_Form_Element('track_number');
|
||||
$track_number->class = 'input_text';
|
||||
$track_number->setLabel('Track Number:')
|
||||
->setFilters(array('StringTrim'))
|
||||
->setValidators(array(new Zend_Validate_Digits()));
|
||||
$this->addElement($track_number);
|
||||
|
||||
// Add genre field
|
||||
$this->addElement('text', 'genre', array(
|
||||
'label' => _('Genre:'),
|
||||
'class' => 'input_text',
|
||||
'filters' => array('StringTrim')
|
||||
));
|
||||
$genre = new Zend_Form_Element('genre');
|
||||
$genre->class = 'input_text';
|
||||
$genre->setLabel(_('Genre:'))
|
||||
->setFilters(array('StringTrim'))
|
||||
->setValidators(array(
|
||||
new Zend_Validate_StringLength(array('max' => 64))
|
||||
));
|
||||
$this->addElement($genre);
|
||||
|
||||
// Add year field
|
||||
$year = new Zend_Form_Element_Text('year');
|
||||
|
@ -63,32 +86,44 @@ class Application_Form_EditAudioMD extends Zend_Form
|
|||
$this->addElement($year);
|
||||
|
||||
// Add label field
|
||||
$this->addElement('text', 'label', array(
|
||||
'label' => _('Label:'),
|
||||
'class' => 'input_text',
|
||||
'filters' => array('StringTrim')
|
||||
));
|
||||
$label = new Zend_Form_Element('label');
|
||||
$label->class = 'input_text';
|
||||
$label->setLabel(_('Label:'))
|
||||
->setFilters(array('StringTrim'))
|
||||
->setValidators(array(
|
||||
new Zend_Validate_StringLength(array('max' => 512))
|
||||
));
|
||||
$this->addElement($label);
|
||||
|
||||
// Add composer field
|
||||
$this->addElement('text', 'composer', array(
|
||||
'label' => _('Composer:'),
|
||||
'class' => 'input_text',
|
||||
'filters' => array('StringTrim')
|
||||
));
|
||||
$composer = new Zend_Form_Element('composer');
|
||||
$composer->class = 'input_text';
|
||||
$composer->setLabel(_('Composer:'))
|
||||
->setFilters(array('StringTrim'))
|
||||
->setValidators(array(
|
||||
new Zend_Validate_StringLength(array('max' => 512))
|
||||
));
|
||||
$this->addElement($composer);
|
||||
|
||||
// Add conductor field
|
||||
$this->addElement('text', 'conductor', array(
|
||||
'label' => _('Conductor:'),
|
||||
'class' => 'input_text',
|
||||
'filters' => array('StringTrim')
|
||||
));
|
||||
$conductor = new Zend_Form_Element('conductor');
|
||||
$conductor->class = 'input_text';
|
||||
$conductor->setLabel(_('Conductor:'))
|
||||
->setFilters(array('StringTrim'))
|
||||
->setValidators(array(
|
||||
new Zend_Validate_StringLength(array('max' => 512))
|
||||
));
|
||||
$this->addElement($conductor);
|
||||
|
||||
// Add mood field
|
||||
$this->addElement('text', 'mood', array(
|
||||
'label' => _('Mood:'),
|
||||
'class' => 'input_text',
|
||||
'filters' => array('StringTrim')
|
||||
));
|
||||
$mood = new Zend_Form_Element('mood');
|
||||
$mood->class = 'input_text';
|
||||
$mood->setLabel(_('Mood:'))
|
||||
->setFilters(array('StringTrim'))
|
||||
->setValidators(array(
|
||||
new Zend_Validate_StringLength(array('max' => 64))
|
||||
));
|
||||
$this->addElement($mood);
|
||||
|
||||
// Add bmp field
|
||||
$bpm = new Zend_Form_Element_Text('bpm');
|
||||
|
@ -101,32 +136,44 @@ class Application_Form_EditAudioMD extends Zend_Form
|
|||
$this->addElement($bpm);
|
||||
|
||||
// Add copyright field
|
||||
$this->addElement('text', 'copyright', array(
|
||||
'label' => _('Copyright:'),
|
||||
'class' => 'input_text',
|
||||
'filters' => array('StringTrim')
|
||||
));
|
||||
$copyright = new Zend_Form_Element('copyright');
|
||||
$copyright->class = 'input_text';
|
||||
$copyright->setLabel(_('Copyright:'))
|
||||
->setFilters(array('StringTrim'))
|
||||
->setValidators(array(
|
||||
new Zend_Validate_StringLength(array('max' => 512))
|
||||
));
|
||||
$this->addElement($copyright);
|
||||
|
||||
// Add isrc number field
|
||||
$this->addElement('text', 'isrc_number', array(
|
||||
'label' => _('ISRC Number:'),
|
||||
'class' => 'input_text',
|
||||
'filters' => array('StringTrim')
|
||||
));
|
||||
$isrc_number = new Zend_Form_Element('isrc_number');
|
||||
$isrc_number->class = 'input_text';
|
||||
$isrc_number->setLabel(_('ISRC Number:'))
|
||||
->setFilters(array('StringTrim'))
|
||||
->setValidators(array(
|
||||
new Zend_Validate_StringLength(array('max' => 512))
|
||||
));
|
||||
$this->addElement($isrc_number);
|
||||
|
||||
// Add website field
|
||||
$this->addElement('text', 'info_url', array(
|
||||
'label' => _('Website:'),
|
||||
'class' => 'input_text',
|
||||
'filters' => array('StringTrim')
|
||||
));
|
||||
$info_url = new Zend_Form_Element('info_url');
|
||||
$info_url->class = 'input_text';
|
||||
$info_url->setLabel(_('Website:'))
|
||||
->setFilters(array('StringTrim'))
|
||||
->setValidators(array(
|
||||
new Zend_Validate_StringLength(array('max' => 512))
|
||||
));
|
||||
$this->addElement($info_url);
|
||||
|
||||
// Add language field
|
||||
$this->addElement('text', 'language', array(
|
||||
'label' => _('Language:'),
|
||||
'class' => 'input_text',
|
||||
'filters' => array('StringTrim')
|
||||
));
|
||||
$language = new Zend_Form_Element('language');
|
||||
$language->class = 'input_text';
|
||||
$language->setLabel(_('Language:'))
|
||||
->setFilters(array('StringTrim'))
|
||||
->setValidators(array(
|
||||
new Zend_Validate_StringLength(array('max' => 512))
|
||||
));
|
||||
$this->addElement($language);
|
||||
|
||||
// Add the submit button
|
||||
$this->addElement('button', 'editmdsave', array(
|
||||
|
|
|
@ -222,7 +222,6 @@ class Rest_MediaController extends Zend_Rest_Controller
|
|||
$requestData = json_decode($this->getRequest()->getRawBody(), true);
|
||||
$whiteList = $this->removeBlacklistedFieldsFromRequestData($requestData);
|
||||
$whiteList = $this->stripTimeStampFromYearTag($whiteList);
|
||||
$whiteList = $this->truncateGenreTag($whiteList);
|
||||
|
||||
if (!$this->validateRequestData($file, $whiteList)) {
|
||||
$file->save();
|
||||
|
@ -382,12 +381,29 @@ class Rest_MediaController extends Zend_Rest_Controller
|
|||
$resp->appendBody("ERROR: Invalid data");
|
||||
}
|
||||
|
||||
private function validateRequestData($file, $whiteList)
|
||||
private function validateRequestData($file, &$whiteList)
|
||||
{
|
||||
// EditAudioMD form is used here for validation
|
||||
$fileForm = new Application_Form_EditAudioMD();
|
||||
$fileForm->startForm($file->getDbId());
|
||||
$fileForm->populate($whiteList);
|
||||
|
||||
/*
|
||||
* Here we are truncating metadata of any characters greater than the
|
||||
* max string length set in the database. In the rare case a track's
|
||||
* genre is more than 64 chars, for example, we don't want to reject
|
||||
* tracks for that reason
|
||||
*/
|
||||
foreach($whiteList as $tag => &$value) {
|
||||
if ($fileForm->getElement($tag)) {
|
||||
$stringLengthValidator = $fileForm->getElement($tag)->getValidator('StringLength');
|
||||
//$stringLengthValidator will be false if the StringLength validator doesn't exist on the current element
|
||||
//in which case we don't have to truncate the extra characters
|
||||
if ($stringLengthValidator) {
|
||||
$value = substr($value, 0, $stringLengthValidator->getMax());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!$fileForm->isValidPartial($whiteList)) {
|
||||
$file->setDbImportStatus(2);
|
||||
|
@ -510,20 +526,5 @@ class Rest_MediaController extends Zend_Rest_Controller
|
|||
}
|
||||
return $metadata;
|
||||
}
|
||||
|
||||
/** The genre tag in our cc_files schema is currently a varchar(64). It's possible for MP3 genre tags
|
||||
* to be longer than that, so we have to truncate longer genres. (We've seen ridiculously long genre tags.)
|
||||
* @param string array $metadata
|
||||
*/
|
||||
private function truncateGenreTag($metadata)
|
||||
{
|
||||
if (isset($metadata["genre"]))
|
||||
{
|
||||
if (strlen($metadata["genre"]) >= 64) {
|
||||
$metadata["genre"] = substr($metadata["genre"], 0, 64);
|
||||
}
|
||||
}
|
||||
return $metadata;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue