Skip to content

Commit

Permalink
feat(shows): set Auphonic preset for each show
Browse files Browse the repository at this point in the history
  • Loading branch information
eteubert committed Feb 11, 2022
1 parent 432cc19 commit dcc9f74
Show file tree
Hide file tree
Showing 5 changed files with 109 additions and 11 deletions.
41 changes: 41 additions & 0 deletions lib/modules/auphonic/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,46 @@ var PODLOVE = PODLOVE || {};
}
}

PODLOVE.AuphonicPresetFetcher = function () {

function getPresetForShow(showSlug) {

const params = new URLSearchParams({
showSlug: showSlug,
episodeId: podlove_vue.episode_id,
action: 'podlove-get-auphonic-preset'
});

fetch(ajaxurl + '?' + params.toString())
.then((response) => response.json())
.then((data) => {
let preset = {key: data.preset_key, name: data.preset_name};

// update "data store"
$("#auphonic").data('presetuuid', preset.key)
});
}

function initPresetFetching() {
const showWidget = document.getElementById("showschecklist")
const items = showWidget.querySelectorAll('li input');

for (const item of items) {
item.addEventListener('click', (e) => {
const input = item;

getPresetForShow(input.value)
})
}
}

if (document.readyState !== 'loading') {
initPresetFetching();
} else {
document.addEventListener('DOMContentLoaded', initPresetFetching);
}
};

PODLOVE.AuphonicImport = function () {

var statusTimeoutId;
Expand Down Expand Up @@ -971,6 +1011,7 @@ var PODLOVE = PODLOVE || {};
jQuery(function($) {
if ($("#auphonic").length && pagenow && pagenow === "podcast") {
PODLOVE.AuphonicImport();
PODLOVE.AuphonicPresetFetcher();
}

$(".podlove_auphonic_production_refresh").on( 'click', function() {
Expand Down
69 changes: 59 additions & 10 deletions lib/modules/auphonic/auphonic.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Podlove\Modules\Auphonic;

use Podlove\Http;
use Podlove\Modules\Shows\Model\Show;

class Auphonic extends \Podlove\Modules\Base
{
Expand All @@ -28,6 +29,9 @@ public function load()

add_action('admin_print_styles', [$this, 'admin_print_styles']);
add_action('wp_ajax_podlove-refresh-auphonic-presets', [$this, 'ajax_refresh_presets']);
add_action('wp_ajax_podlove-get-auphonic-preset', [$this, 'ajax_get_preset']);

add_action('podlove_show_form_end', [$this, 'shows_module_append_preset_option']);

if (isset($_GET['page']) && $_GET['page'] == 'podlove_settings_modules_handle') {
add_action('admin_bar_init', [$this, 'check_code']);
Expand Down Expand Up @@ -77,16 +81,7 @@ public function register_settings()
'html' => ['class' => 'regular-text'],
]);

// Fetch Auphonic presets
$presets = $this->api->fetch_presets();
if ($presets && is_array($presets->data)) {
$preset_list = [];
foreach ($presets->data as $preset_id => $preset) {
$preset_list[$preset->uuid] = $preset->preset_name;
}
} else {
$preset_list[] = __('Presets could not be loaded', 'podlove-podcasting-plugin-for-wordpress');
}
$preset_list = $this->get_presets_list();

$this->register_option('auphonic_production_preset', 'select', [
'label' => __('Auphonic production preset', 'podlove-podcasting-plugin-for-wordpress'),
Expand Down Expand Up @@ -114,6 +109,18 @@ public function register_settings()
}
}

public function shows_module_append_preset_option($wrapper)
{
$preset_list = $this->get_presets_list();

$wrapper->select('auphonic_preset', [
'label' => __('Auphonic Preset', 'podlove-podcasting-plugin-for-wordpress'),
'description' => __('Define a Auphonic Preset for this show. If none is set, the global module preset is used.', 'podlove-podcasting-plugin-for-wordpress'),
'type' => 'select',
'options' => $preset_list,
]);
}

/**
* Register Event for Auphonic Webhook.
*/
Expand Down Expand Up @@ -257,6 +264,48 @@ public function ajax_refresh_presets()
return \Podlove\AJAX\AJAX::respond_with_json($result);
}

public function get_presets_list()
{
$presets = $this->api->fetch_presets();
if ($presets && is_array($presets->data)) {
$preset_list = [];
foreach ($presets->data as $preset_id => $preset) {
$preset_list[$preset->uuid] = $preset->preset_name;
}
} else {
$preset_list[] = __('Presets could not be loaded', 'podlove-podcasting-plugin-for-wordpress');
}

return $preset_list;
}

public function ajax_get_preset()
{
$show_slug = filter_input(INPUT_GET, 'showSlug');

$default = $this->get_module_option('auphonic_production_preset');

$preset_list = $this->get_presets_list();

$show = Show::find_one_term_by_property('slug', $show_slug);
if ($show && $show->auphonic_preset && $preset_list[$show->auphonic_preset]) {
$show_preset_key = $show->auphonic_preset;
$show_preset_name = $preset_list[$show->auphonic_preset];
} else {
$show_preset_key = null;
$show_preset_name = null;
}

return \Podlove\AJAX\AJAX::respond_with_json([
'preset_key' => $show_preset_key ?? $default,
'preset_name' => $show_preset_name ?? $preset_list[$default],
'default_preset_key' => $default,
'default_preset_name' => $preset_list[$default],
'show_preset_key' => $show_preset_key,
'show_preset_name' => $show_preset_name,
]);
}

/**
* Register a new Episode that can be published via Auphonic.
*/
Expand Down
2 changes: 2 additions & 0 deletions lib/modules/shows/model/show.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public function __construct()
$this->image = '';
$this->language = '';
$this->category = '';
$this->auphonic_preset = '';
}

/**
Expand Down Expand Up @@ -145,6 +146,7 @@ public static function format_term($term)
$show->image = get_term_meta($term->term_id, 'image', true);
$show->language = get_term_meta($term->term_id, 'language', true);
$show->category = get_term_meta($term->term_id, 'category', true);
$show->auphonic_preset = get_term_meta($term->term_id, 'auphonic_preset', true);

return $show;
}
Expand Down
4 changes: 3 additions & 1 deletion lib/modules/shows/settings/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function __construct($handle)

public static function show_meta_data_fields()
{
return ['subtitle', 'language', 'image', 'category'];
return ['subtitle', 'language', 'image', 'category', 'auphonic_preset'];
}

public function add_screen_options()
Expand Down Expand Up @@ -322,6 +322,8 @@ private function form_template($show, $action, $button_text = null)
'type' => 'select',
'options' => \Podlove\Itunes\categories(),
]);

do_action('podlove_show_form_end', $wrapper);
});
}

Expand Down
4 changes: 4 additions & 0 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,10 @@ This product includes GeoLite2 data created by MaxMind, available from http://ww

== Changelog ==

= 2022-02-11 =

- new: each show can define its own Auphonic production preset

= 2022-02-10 =

- fix: feed cache issue when using the "Shows" module
Expand Down

0 comments on commit dcc9f74

Please sign in to comment.