do some thing, but not work
This commit is contained in:
parent
add4650840
commit
8bb24dd42b
|
|
@ -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
|
||||||
|
}
|
||||||
|
|
@ -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);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
@ -31,23 +31,44 @@ if ( ! defined( 'ABSPATH' ) ) {
|
||||||
$this->define_constants();
|
$this->define_constants();
|
||||||
$this->Audio_diary_loader();
|
$this->Audio_diary_loader();
|
||||||
}
|
}
|
||||||
public function define_constants() {
|
/**
|
||||||
|
* Define all constants
|
||||||
/**
|
*/
|
||||||
* Defines all constants
|
public function define_constants() {
|
||||||
*
|
if ( ! defined( 'AUDIO_DIARY_VERSION' ) ) {
|
||||||
*/
|
define( 'AUDIO_DIARY_VERSION', '1.0.0' );
|
||||||
define( 'AUDIO_DIARY_VERSION', '1.0.0' );
|
}
|
||||||
define( 'AUDIO_DIARY_FILE', __FILE__ );
|
if ( ! defined( 'AUDIO_DIARY_FILE' ) ) {
|
||||||
define( 'AUDIO_DIARY_PATH', plugin_dir_path( AUDIO_DIARY_FILE ) );
|
define( 'AUDIO_DIARY_FILE', __FILE__ );
|
||||||
define( 'AUDIO_DIARY_BASE', plugin_basename( AUDIO_DIARY_FILE ) );
|
}
|
||||||
define( 'AUDIO_DIARY_SLUG', 'Audio_diary_settings' );
|
if ( ! defined( 'AUDIO_DIARY_PATH' ) ) {
|
||||||
define( 'AUDIO_DIARY_SETTINGS_LINK', admin_url( 'admin.php?page=' . AUDIO_DIARY_SLUG ) );
|
define( 'AUDIO_DIARY_PATH', plugin_dir_path( AUDIO_DIARY_FILE ) );
|
||||||
define( 'AUDIO_DIARY_CLASSES_PATH', AUDIO_DIARY_PATH . 'classes/' );
|
}
|
||||||
define( 'AUDIO_DIARY_IMAGES', AUDIO_DIARY_PATH . 'build/images' );
|
if ( ! defined( 'AUDIO_DIARY_BASE' ) ) {
|
||||||
define( 'AUDIO_DIARY_MODULES_PATH', AUDIO_DIARY_PATH . 'modules/' );
|
define( 'AUDIO_DIARY_BASE', plugin_basename( AUDIO_DIARY_FILE ) );
|
||||||
define( 'AUDIO_DIARY_URL', plugins_url( '/', 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.
|
* Require loader Audio diary class.
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -42,21 +42,22 @@ class Audio_Diary_loader{
|
||||||
*/
|
*/
|
||||||
private function load_dependencies() {
|
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
|
// 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.
|
// 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.
|
// 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.
|
// The class responsible for defining all actions for edd.
|
||||||
|
|
||||||
require_once AUDIO_DIARY_MODULES_PATH . '';
|
// require_once AUDIO_DIARY_MODULES_PATH . '';
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,113 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
class Audio_Diary_Admin_Page {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instance
|
||||||
|
*
|
||||||
|
* @access private
|
||||||
|
* @var object Class object.
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
private static $instance;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initiator
|
||||||
|
*
|
||||||
|
* @return object Initialized object of class.
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
public static function get_instance() {
|
||||||
|
if ( ! isset( self::$instance ) ) {
|
||||||
|
self::$instance = new self();
|
||||||
|
}
|
||||||
|
|
||||||
|
return self::$instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function __construct() {
|
||||||
|
add_action('admin_menu', array($this, 'add_menu_item'));
|
||||||
|
add_action('admin_enqueue_scripts', array($this, 'enqueue_scripts'));
|
||||||
|
add_action('wp_ajax_save_audio', array($this, 'save_audio'));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function add_menu_item() {
|
||||||
|
add_menu_page(
|
||||||
|
'Audio Diary', // عنوان صفحه
|
||||||
|
'Audio Diary', // عنوان منو
|
||||||
|
'manage_options', // سطح دسترسی
|
||||||
|
'audio-diary', // اسلاگ صفحه
|
||||||
|
array($this, 'render_page'), // تابعی که محتوای صفحه را نمایش میدهد
|
||||||
|
'dashicons-media-audio', // آیکون منو
|
||||||
|
6
|
||||||
|
);
|
||||||
|
|
||||||
|
add_submenu_page(
|
||||||
|
'audio-diary',
|
||||||
|
__('Recorded Audios', 'audio-diary'),
|
||||||
|
__('Recorded Audios', 'audio-diary'),
|
||||||
|
'manage_options',
|
||||||
|
'audio-diary-list',
|
||||||
|
array($this, 'render_list_page')
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function enqueue_scripts() {
|
||||||
|
$script_url = plugins_url( 'js/audio-diary.js', AUDIO_DIARY_ASSETS_PATH );
|
||||||
|
wp_enqueue_script('audio-diary-script', $script_url, array('jquery'), '1.0', true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function render_record_page() {
|
||||||
|
?>
|
||||||
|
<div class="wrap">
|
||||||
|
<h1><?php _e('Audio Diary', 'audio-diary'); ?></h1>
|
||||||
|
<button id="start-recording"><?php _e('Start Recording', 'audio-diary'); ?></button>
|
||||||
|
<button id="stop-recording" disabled><?php _e('Stop Recording', 'audio-diary'); ?></button>
|
||||||
|
<audio id="audio-player" controls></audio>
|
||||||
|
</div>
|
||||||
|
<?php
|
||||||
|
}
|
||||||
|
|
||||||
|
public function render_list_page() {
|
||||||
|
$uploads = wp_upload_dir();
|
||||||
|
$audio_files = glob($uploads['basedir'] . '/audio-diary/*.wav');
|
||||||
|
|
||||||
|
?>
|
||||||
|
<div class="wrap">
|
||||||
|
<h1><?php _e('Recorded Audios', 'audio-diary'); ?></h1>
|
||||||
|
<ul>
|
||||||
|
<?php foreach ($audio_files as $file) : ?>
|
||||||
|
<li>
|
||||||
|
<audio controls src="<?php echo $uploads['baseurl'] . '/audio-diary/' . basename($file); ?>"></audio>
|
||||||
|
</li>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
<?php
|
||||||
|
}
|
||||||
|
|
||||||
|
public function save_audio() {
|
||||||
|
check_admin_referer('audio_diary_nonce');
|
||||||
|
|
||||||
|
$audio_data = $_POST['audio_data'];
|
||||||
|
$audio_data = base64_decode(str_replace('data:audio/wav;base64,', '', $audio_data));
|
||||||
|
|
||||||
|
$uploads = wp_upload_dir();
|
||||||
|
$audio_dir = $uploads['basedir'] . '/audio-diary/';
|
||||||
|
if (!file_exists($audio_dir)) {
|
||||||
|
mkdir($audio_dir, 0755, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
$filename = $audio_dir . uniqid() . '.wav';
|
||||||
|
file_put_contents($filename, $audio_data);
|
||||||
|
|
||||||
|
wp_send_json_success();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (class_exists('Audio_Diary')) {
|
||||||
|
$audio_diary = new Audio_Diary();
|
||||||
|
}
|
||||||
|
|
||||||
|
Audio_Diary_Admin_Page::get_instance();
|
||||||
|
|
@ -0,0 +1,91 @@
|
||||||
|
<?php
|
||||||
|
if ( ! defined( 'ABSPATH' ) ) {
|
||||||
|
echo "what the hell are you doing here?";
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
class Audio_Diary_Admin_Page {
|
||||||
|
/**
|
||||||
|
* Instance
|
||||||
|
*
|
||||||
|
* @access private
|
||||||
|
* @var object Class object.
|
||||||
|
*/
|
||||||
|
private static $instance;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initiator
|
||||||
|
*
|
||||||
|
* @return object Initialized object of class.
|
||||||
|
*/
|
||||||
|
public static function get_instance() {
|
||||||
|
if ( ! isset( self::$instance ) ) {
|
||||||
|
self::$instance = new self();
|
||||||
|
}
|
||||||
|
|
||||||
|
return self::$instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor
|
||||||
|
*/
|
||||||
|
public function __construct() {
|
||||||
|
// You can add actions here if needed, for example:
|
||||||
|
add_action('admin_enqueue_scripts', array($this, 'enqueue_scripts'));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enqueue scripts
|
||||||
|
*/
|
||||||
|
public function enqueue_scripts() {
|
||||||
|
$script_url = plugins_url('assets/js/audio-diary.js', AUDIO_DIARY_PATH);
|
||||||
|
wp_enqueue_script('audio-diary-script', $script_url, array('jquery'), '1.0', true);
|
||||||
|
|
||||||
|
wp_localize_script(
|
||||||
|
'audio-diary-script',
|
||||||
|
'audioDiaryJsObject',
|
||||||
|
[
|
||||||
|
'ajax_url' => admin_url('admin-ajax.php'),
|
||||||
|
'nonce' => wp_create_nonce('audio_diary_nonce'),
|
||||||
|
]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Render record page
|
||||||
|
*/
|
||||||
|
public function render_record_page() {
|
||||||
|
?>
|
||||||
|
<div class="wrap">
|
||||||
|
<h1><?php _e('Audio Diary', 'audio-diary'); ?></h1>
|
||||||
|
<button id="start-recording"><?php _e('Start Recording', 'audio-diary'); ?></button>
|
||||||
|
<button id="stop-recording" disabled><?php _e('Stop Recording', 'audio-diary'); ?></button>
|
||||||
|
<audio id="audio-player" controls></audio>
|
||||||
|
</div>
|
||||||
|
<?php
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Render list page
|
||||||
|
*/
|
||||||
|
public function render_list_page() {
|
||||||
|
$uploads = wp_upload_dir();
|
||||||
|
$audio_files = glob($uploads['basedir'] . '/audio-diary/*.wav');
|
||||||
|
|
||||||
|
?>
|
||||||
|
<div class="wrap">
|
||||||
|
<h1><?php _e('Recorded Audios', 'audio-diary'); ?></h1>
|
||||||
|
<ul>
|
||||||
|
<?php foreach ($audio_files as $file) : ?>
|
||||||
|
<li>
|
||||||
|
<audio controls src="<?php echo $uploads['baseurl'] . '/audio-diary/' . basename($file); ?>"></audio>
|
||||||
|
</li>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
<?php
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Initialize the class instance
|
||||||
|
Audio_Diary_Admin_Page::get_instance();
|
||||||
Loading…
Reference in New Issue