diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..4a37014 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,12 @@ +{ + "workbench.colorCustomizations": { + "activityBar.background": "#58b7f7", + "titleBar.activeBackground": "#58b7f7", + "titleBar.activeForeground": "#edfefc" + }, + "material-icon-theme.folders.associations": { + "features":"plugin" + }, + "editor.formatOnSave": true, + "editor.formatOnType": true +} \ No newline at end of file diff --git a/assets/js/audio-diary.js b/assets/js/audio-diary.js new file mode 100644 index 0000000..2c691fa --- /dev/null +++ b/assets/js/audio-diary.js @@ -0,0 +1,53 @@ +jQuery(document).ready(function($) { + var mediaRecorder; + var audioChunks = []; + + $('#start-recording').on('click', function() { + navigator.mediaDevices.getUserMedia({ audio: true }) + .then(stream => { + mediaRecorder = new MediaRecorder(stream); + mediaRecorder.start(); + + mediaRecorder.addEventListener("dataavailable", event => { + audioChunks.push(event.data); + }); + + mediaRecorder.addEventListener("stop", () => { + const audioBlob = new Blob(audioChunks, { type: 'audio/wav' }); + const audioUrl = URL.createObjectURL(audioBlob); + const audio = document.getElementById('audio-player'); + audio.src = audioUrl; + + var reader = new FileReader(); + reader.readAsDataURL(audioBlob); + reader.onloadend = function() { + var base64data = reader.result; + $.ajax({ + url: audioDiaryJsObject.ajax_url, + method: 'POST', + data: { + action: 'save_audio', + audio_data: base64data, + _wpnonce: audioDiaryJsObject.nonce + }, + success: function(response) { + console.log('Audio saved successfully.'); + }, + error: function() { + console.error('Failed to save audio.'); + } + }); + }; + }); + + $('#stop-recording').prop('disabled', false); + $('#start-recording').prop('disabled', true); + }); + }); + + $('#stop-recording').on('click', function() { + mediaRecorder.stop(); + $('#stop-recording').prop('disabled', true); + $('#start-recording').prop('disabled', false); + }); +}); diff --git a/audio-diary.php b/audio-diary.php index 9a120b9..da62503 100644 --- a/audio-diary.php +++ b/audio-diary.php @@ -31,23 +31,44 @@ if ( ! defined( 'ABSPATH' ) ) { $this->define_constants(); $this->Audio_diary_loader(); } - public function define_constants() { - - /** - * Defines all constants - * - */ - define( 'AUDIO_DIARY_VERSION', '1.0.0' ); - define( 'AUDIO_DIARY_FILE', __FILE__ ); - define( 'AUDIO_DIARY_PATH', plugin_dir_path( AUDIO_DIARY_FILE ) ); - define( 'AUDIO_DIARY_BASE', plugin_basename( AUDIO_DIARY_FILE ) ); - define( 'AUDIO_DIARY_SLUG', 'Audio_diary_settings' ); - define( 'AUDIO_DIARY_SETTINGS_LINK', admin_url( 'admin.php?page=' . AUDIO_DIARY_SLUG ) ); - define( 'AUDIO_DIARY_CLASSES_PATH', AUDIO_DIARY_PATH . 'classes/' ); - define( 'AUDIO_DIARY_IMAGES', AUDIO_DIARY_PATH . 'build/images' ); - define( 'AUDIO_DIARY_MODULES_PATH', AUDIO_DIARY_PATH . 'modules/' ); - define( 'AUDIO_DIARY_URL', plugins_url( '/', AUDIO_DIARY_FILE ) ); - } + /** + * Define all constants + */ + public function define_constants() { + if ( ! defined( 'AUDIO_DIARY_VERSION' ) ) { + define( 'AUDIO_DIARY_VERSION', '1.0.0' ); + } + if ( ! defined( 'AUDIO_DIARY_FILE' ) ) { + define( 'AUDIO_DIARY_FILE', __FILE__ ); + } + if ( ! defined( 'AUDIO_DIARY_PATH' ) ) { + define( 'AUDIO_DIARY_PATH', plugin_dir_path( AUDIO_DIARY_FILE ) ); + } + if ( ! defined( 'AUDIO_DIARY_BASE' ) ) { + define( 'AUDIO_DIARY_BASE', plugin_basename( AUDIO_DIARY_FILE ) ); + } + if ( ! defined( 'AUDIO_DIARY_SLUG' ) ) { + define( 'AUDIO_DIARY_SLUG', 'audio-diary-settings' ); + } + if ( ! defined( 'AUDIO_DIARY_SETTINGS_LINK' ) ) { + define( 'AUDIO_DIARY_SETTINGS_LINK', admin_url( 'admin.php?page=' . AUDIO_DIARY_SLUG ) ); + } + if ( ! defined( 'AUDIO_DIARY_CLASSES_PATH' ) ) { + define( 'AUDIO_DIARY_CLASSES_PATH', AUDIO_DIARY_PATH . 'classes/' ); + } + if ( ! defined( 'AUDIO_DIARY_IMAGES' ) ) { + define( 'AUDIO_DIARY_IMAGES', AUDIO_DIARY_PATH . 'build/images' ); + } + if ( ! defined( 'AUDIO_DIARY_MODULES_PATH' ) ) { + define( 'AUDIO_DIARY_MODULES_PATH', AUDIO_DIARY_PATH . 'modules/' ); + } + if ( ! defined( 'AUDIO_DIARY_ASSETS_PATH' ) ) { + define( 'AUDIO_DIARY_ASSETS_PATH', AUDIO_DIARY_PATH . 'assets/' ); + } + if ( ! defined( 'AUDIO_DIARY_URL' ) ) { + define( 'AUDIO_DIARY_URL', plugins_url( '/', AUDIO_DIARY_FILE ) ); + } + } /** * Require loader Audio diary class. * diff --git a/classes/class_Audio_diary_loader.php b/classes/class_Audio_diary_loader.php index fe2b7c4..3752c29 100644 --- a/classes/class_Audio_diary_loader.php +++ b/classes/class_Audio_diary_loader.php @@ -42,21 +42,22 @@ class Audio_Diary_loader{ */ private function load_dependencies() { - require_once AUDIO_DIARY_CLASSES_PATH . ''; - require_once AUDIO_DIARY_CLASSES_PATH . ''; + // require_once AUDIO_DIARY_CLASSES_PATH . ''; + // require_once AUDIO_DIARY_CLASSES_PATH . ''; // The class responsible for the settings page - require_once AUDIO_DIARY_CLASSES_PATH . ''; + require_once AUDIO_DIARY_CLASSES_PATH . 'class_admin_page.php'; // The class responsible for defining main options of the plugin. - require_once AUDIO_DIARY_CLASSES_PATH . ''; + + // require_once AUDIO_DIARY_CLASSES_PATH . ''; // The class responsible for defining REST Routs API of the plugin. - require_once AUDIO_DIARY_CLASSES_PATH . ''; + // require_once AUDIO_DIARY_CLASSES_PATH . ''; // The class responsible for defining all actions for edd. - require_once AUDIO_DIARY_MODULES_PATH . ''; + // require_once AUDIO_DIARY_MODULES_PATH . ''; } } diff --git a/classes/class_admin_page.php b/classes/class_admin_page.php new file mode 100644 index 0000000..ff99c6f --- /dev/null +++ b/classes/class_admin_page.php @@ -0,0 +1,113 @@ + +
+

+ + + +
+ +
+

+ +
+ admin_url('admin-ajax.php'), + 'nonce' => wp_create_nonce('audio_diary_nonce'), + ] + ); + } + + /** + * Render record page + */ + public function render_record_page() { + ?> +
+

+ + + +
+ +
+

+ +
+