add table for audios & delet visualizer background

This commit is contained in:
haakel 2024-06-18 21:28:38 +03:30
parent 9b5ea52006
commit afb97f51bb
4 changed files with 93 additions and 22 deletions

View File

@ -56,7 +56,25 @@
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1); /* سایه برای دادن عمق */ box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1); /* سایه برای دادن عمق */
} }
/* افزودن این استایل برای تغییر رنگ و ظاهر خط */ #visualizer {
.audio-diary-admin-page canvas { background-color: #f9f9f9; /* پس‌زمینه ملایم */
background-color: transparent; /* حذف پس‌زمینه سیاه */ border-radius: 8px;
border: 1px solid #ccc;
} }
.wrap table {
width: 100%;
border-collapse: collapse;
}
.wrap th, .wrap td {
border: 1px solid #ddd;
padding: 8px;
}
.wrap th {
background-color: #f2f2f2;
text-align: left;
}

View File

@ -16,27 +16,34 @@ jQuery(document).ready(function($) {
const canvas = document.getElementById('visualizer'); const canvas = document.getElementById('visualizer');
const canvasCtx = canvas.getContext('2d'); const canvasCtx = canvas.getContext('2d');
function draw() { function draw() {
requestAnimationFrame(draw); requestAnimationFrame(draw);
analyser.getByteTimeDomainData(dataArray); analyser.getByteTimeDomainData(dataArray);
canvasCtx.fillStyle = 'rgb(0, 0, 0)'; canvasCtx.clearRect(0, 0, canvas.width, canvas.height); // حذف پس‌زمینه سیاه
canvasCtx.fillRect(0, 0, canvas.width, canvas.height);
// تنظیمات خط وسط
const centerY = canvas.height / 2;
canvasCtx.beginPath();
canvasCtx.moveTo(0, centerY);
canvasCtx.lineTo(canvas.width, centerY);
canvasCtx.strokeStyle = 'rgba(0, 0, 0, 0.2)'; // خط وسط نیمه شفاف
canvasCtx.lineWidth = 1;
canvasCtx.stroke();
// تنظیمات خط موج صدا
canvasCtx.lineWidth = 2; canvasCtx.lineWidth = 2;
canvasCtx.strokeStyle = 'rgb(255, 255, 255)'; canvasCtx.strokeStyle = 'rgb(0, 0, 0)'; // خط موج صدا مشکی
canvasCtx.beginPath(); canvasCtx.beginPath();
let sliceWidth = canvas.width * 1.0 / bufferLength; let sliceWidth = canvas.width * 1.0 / bufferLength;
let x = 0; let x = 0;
for(let i = 0; i < bufferLength; i++) { for (let i = 0; i < bufferLength; i++) {
let v = dataArray[i] / 128.0; let v = dataArray[i] / 128.0;
let y = v * canvas.height / 2; let y = v * canvas.height / 2;
if(i === 0) { if (i === 0) {
canvasCtx.moveTo(x, y); canvasCtx.moveTo(x, y);
} else { } else {
canvasCtx.lineTo(x, y); canvasCtx.lineTo(x, y);
@ -99,7 +106,7 @@ jQuery(document).ready(function($) {
$.toast({ $.toast({
text: "Failed to save audio", // Text that is to be shown in the toast text: "Failed to save audio", // Text that is to be shown in the toast
heading: 'Note', // Optional heading to be shown on the toast heading: 'Note', // Optional heading to be shown on the toast
icon: 'Error', // Type of toast icon icon: 'error', // Type of toast icon
showHideTransition: 'fade', // fade, slide or plain showHideTransition: 'fade', // fade, slide or plain
allowToastClose: true, // Boolean value true or false allowToastClose: true, // Boolean value true or false
hideAfter: 3000, // false to make it sticky or number representing the miliseconds as time after which toast needs to be hidden hideAfter: 3000, // false to make it sticky or number representing the miliseconds as time after which toast needs to be hidden

View File

@ -30,10 +30,34 @@ class Audio_Diary_Admin_Page {
add_action('admin_menu', array($this, 'add_menu_item')); add_action('admin_menu', array($this, 'add_menu_item'));
add_action('admin_enqueue_scripts', array($this, 'enqueue_scripts')); add_action('admin_enqueue_scripts', array($this, 'enqueue_scripts'));
add_action('wp_ajax_save_audio', array($this, 'save_audio')); add_action('wp_ajax_save_audio', array($this, 'save_audio'));
add_action('wp_ajax_delete_audio_files', 'delete_audio_files');
$this->create_audio_folder(); $this->create_audio_folder();
} }
function delete_audio_files() {
check_ajax_referer('audio-diary-nonce', '_ajax_nonce');
if (!isset($_POST['files']) || !is_array($_POST['files'])) {
wp_send_json_error('Invalid request');
}
$uploads = wp_upload_dir();
$audio_dir = $uploads['basedir'] . '/audio-diary/';
$deleted = [];
foreach ($_POST['files'] as $file) {
$file_path = $audio_dir . basename($file);
if (file_exists($file_path) && unlink($file_path)) {
$deleted[] = $file;
}
}
if (empty($deleted)) {
wp_send_json_error('No files deleted');
}
wp_send_json_success($deleted);
}
public function add_menu_item() { public function add_menu_item() {
add_menu_page( add_menu_page(
'Audio Diary', // عنوان صفحه 'Audio Diary', // عنوان صفحه

View File

@ -1,14 +1,36 @@
<?php <?php
$uploads = wp_upload_dir(); $uploads = wp_upload_dir();
$audio_files = glob($uploads['basedir'] . '/audio-diary/*.wav'); $audio_files = glob($uploads['basedir'] . '/audio-diary/*.wav');
usort($audio_files, function($a, $b) {
return filemtime($b) - filemtime($a);
});
?> ?>
<div class="wrap"> <div class="wrap">
<h1><?php _e('Recorded Audios', 'audio-diary'); ?></h1> <h1><?php _e('Recorded Audios', 'audio-diary'); ?></h1>
<ul> <table>
<?php foreach ($audio_files as $file) : ?> <thead>
<li> <tr>
<audio controls src="<?php echo $uploads['baseurl'] . '/audio-diary/' . basename($file); ?>"></audio> <th><?php _e('Date', 'audio-diary'); ?></th>
</li> <th><?php _e('Time', 'audio-diary'); ?></th>
<?php endforeach; ?> <th><?php _e('Audio', 'audio-diary'); ?></th>
</ul> </tr>
</thead>
<tbody>
<?php foreach ($audio_files as $file) :
$file_date = date("Y-m-d", filemtime($file));
$file_time = date("H:i:s", filemtime($file));
$file_url = $uploads['baseurl'] . '/audio-diary/' . basename($file);
?>
<tr>
<td><?php echo $file_date; ?></td>
<td><?php echo $file_time; ?></td>
<td>
<audio controls src="<?php echo $file_url; ?>"></audio>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div> </div>