Skip to content

Commit

Permalink
add TIFF and PDF formats to media settings
Browse files Browse the repository at this point in the history
  • Loading branch information
brookgagnon committed Jun 30, 2024
1 parent d3bad9d commit 11dfe07
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 5 deletions.
2 changes: 2 additions & 0 deletions controllers/media.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public function formats_get()
* @param video_formats
* @param image_formats
* @param audio_formats
* @param document_formats
*
* @route POST /v2/media/formats
*/
Expand All @@ -63,6 +64,7 @@ public function formats_save()
$data['video_formats'] = $this->data('video_formats');
$data['image_formats'] = $this->data('image_formats');
$data['audio_formats'] = $this->data('audio_formats');
$data['document_formats'] = $this->data('document_formats');

$validation = $this->models->media('formats_validate', ['data' => $data]);
if ($validation[0] == false) {
Expand Down
12 changes: 12 additions & 0 deletions html/media/settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,23 @@ <h1 data-t>Supported File Formats</h1>
<ob-field-checkbox value="png" data-edit class="image_formats" name="image_formats"></ob-field-checkbox> PNG (<span data-t>Portable Network Graphics</span>)
</div>

<div class="fieldrow">
<ob-field-checkbox value="tif" data-edit class="image_formats" name="image_formats"></ob-field-checkbox> TIFF (<span data-t>Tagged Image File Format</span>)
</div>

<div class="fieldrow">
<ob-field-checkbox value="svg" data-edit class="image_formats" name="image_formats"></ob-field-checkbox> SVG (<span data-t>Scalable Vector Graphics</span>)
</div>
</fieldset>

<fieldset>
<legend>Document Formats</legend>

<div class="fieldrow">
<ob-field-checkbox value="pdf" data-edit class="document_formats" name="document_formats"></ob-field-checkbox> PDF (<span data-t>Portable Document Format</span>)
</div>
</fieldset>

<fieldset>
<div class="fieldrow">
<button class="add" id="media_settings_formats_save" onclick="OB.Media.formatsSave();" data-t>Save</button>
Expand Down
10 changes: 9 additions & 1 deletion js/media/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ OB.Media.settings = function()
var video = formats.video_formats;
var image = formats.image_formats;
var audio = formats.audio_formats;
var document = formats.document_formats;

for(var i in video)
{
Expand All @@ -45,6 +46,11 @@ OB.Media.settings = function()
$('.image_formats[value='+image[i]+']').attr('checked',true);
}

for(var i in document)
{
$('.document_formats[value='+document[i]+']').attr('checked',true);
}

OB.Media.categoriesGet();
OB.Media.metadataGet();
OB.Media.fieldsGet();
Expand Down Expand Up @@ -355,8 +361,10 @@ OB.Media.formatsSave = function()
var audio_formats = Array.from(document.querySelectorAll('.audio_formats')).filter((elem) => elem.checked).map((elem) => elem.value);
var image_formats = Array.from(document.querySelectorAll('.image_formats')).filter((elem) => elem.checked).map((elem) => elem.value);
var video_formats = Array.from(document.querySelectorAll('.video_formats')).filter((elem) => elem.checked).map((elem) => elem.value);
var document_formats = Array.from(document.querySelectorAll('.document_formats')).filter((elem) => elem.checked).map((elem) => elem.value);


OB.API.post('media','formats_save', { 'audio_formats': audio_formats, 'video_formats': video_formats, 'image_formats': image_formats },function(data) {
OB.API.post('media','formats_save', { 'audio_formats': audio_formats, 'video_formats': video_formats, 'image_formats': image_formats, 'document_formats': document_formats },function(data) {
$('#formats_message').obWidget('success',data.msg);
});

Expand Down
44 changes: 40 additions & 4 deletions models/media_model.php
Original file line number Diff line number Diff line change
Expand Up @@ -2106,8 +2106,9 @@ public function formats_validate($args = [])

// list of valid formats...
$valid_video_formats = array('avi','mpg','ogg','wmv','mov');
$valid_image_formats = array('jpg','png','svg');
$valid_image_formats = array('jpg','png','tif','svg');
$valid_audio_formats = array('flac','mp3','ogg','webm','mp4','wav');
$valid_document_formats = array('pdf');

// verify image formats
if (!is_array($video_formats) || !is_array($image_formats) || !is_array($audio_formats)) {
Expand All @@ -2132,6 +2133,12 @@ public function formats_validate($args = [])
}
}

foreach ($document_formats as $format) {
if (array_search($format, $valid_document_formats) === false) {
return array(false,'There was a problem saving the format settings. One of the formats does not appear to be valid.');
}
}

return array(true,'');
}

Expand All @@ -2149,6 +2156,28 @@ public function formats_save($args = [])
$$name = $value;
}

// add empty settings if they don't exist
$this->db->where('name', 'audio_formats');
if (!$this->db->get_one('settings')) {
$this->db->insert('settings', ['name' => 'audio_formats', 'value' => '']);
}

$this->db->where('name', 'image_formats');
if (!$this->db->get_one('settings')) {
$this->db->insert('settings', ['name' => 'image_formats', 'value' => '']);
}

$this->db->where('name', 'video_formats');
if (!$this->db->get_one('settings')) {
$this->db->insert('settings', ['name' => 'video_formats', 'value' => '']);
}

$this->db->where('name', 'document_formats');
if (!$this->db->get_one('settings')) {
$this->db->insert('settings', ['name' => 'document_formats', 'value' => '']);
}

// update settings
$this->db->where('name', 'audio_formats');
$this->db->update('settings', array('value' => implode(',', $audio_formats)));

Expand All @@ -2157,6 +2186,9 @@ public function formats_save($args = [])

$this->db->where('name', 'video_formats');
$this->db->update('settings', array('value' => implode(',', $video_formats)));

$this->db->where('name', 'document_formats');
$this->db->update('settings', array('value' => implode(',', $document_formats)));
}

/**
Expand All @@ -2177,9 +2209,13 @@ public function formats_get_all($args = [])
$this->db->where('name', 'image_formats');
$image = $this->db->get_one('settings');

$return['audio_formats'] = $audio['value'] ? explode(',', $audio['value']) : [];
$return['video_formats'] = $video['value'] ? explode(',', $video['value']) : [];
$return['image_formats'] = $image['value'] ? explode(',', $image['value']) : [];
$this->db->where('name', 'document_formats');
$document = $this->db->get_one('settings');

$return['audio_formats'] = $audio ? explode(',', $audio['value']) : [];
$return['video_formats'] = $video ? explode(',', $video['value']) : [];
$return['image_formats'] = $image ? explode(',', $image['value']) : [];
$return['document_formats'] = $document ? explode(',', $document['value']) : [];

return $return;
}
Expand Down

0 comments on commit 11dfe07

Please sign in to comment.