تست کد PHP افزونه
لورم ایپسوم متن ساختگی با تولید سادگی نامفهوم از صنعت چاپ و با استفاده از طراحان گرافیک است. چاپگرها و متون بلکه روزنامه و مجله در ستون و سطرآنچنان که لازم است. لورم ایپسوم متن ساختگی با تولید سادگی نامفهوم از صنعت چاپ و با استفاده از طراحان گرافیک است. چاپگرها و متون بلکه روزنامه و مجله در ستون و سطرآنچنان که لازم است. لورم ایپسوم متن ساختگی با تولید سادگی نامفهوم از صنعت چاپ و با استفاده از طراحان گرافیک است. چاپگرها و متون بلکه روزنامه و مجله در ستون و سطرآنچنان که لازم است. لورم ایپسوم متن ساختگی با تولید سادگی نامفهوم از صنعت چاپ و با استفاده از طراحان گرافیک است. چاپگرها و متون بلکه روزنامه و مجله در ستون و سطرآنچنان که لازم است.
<?php/** * Plugin Name: مخزن DVD نورترازان معین * Description: سیستم مدیریت ارسال پکیج های DVD برای مشتریان * Version: 1.4.0 * Author: Ahmadreza Karimi */// جلوگیری از دسترسی مستقیمdefined('ABSPATH') || exit;/** * کلاس اصلی افزونه */class ak4w8DVD_Makhzan { private $table_name; public function __construct() { global $wpdb; $this->table_name = $wpdb->prefix . 'makhzan_dvd'; add_action('init', array($this, 'akdvd_init')); add_action('admin_menu', array($this, 'akdvd_add_admin_menu')); add_action('add_meta_boxes', array($this, 'akdvd_add_metabox')); add_action('wp_ajax_akdvd_send_to_dvd_store', array($this, 'akdvd_handle_ajax_send_to_dvd')); add_action('wp_ajax_akdvd_get_request_details', array($this, 'akdvd_handle_ajax_get_request_details')); add_action('wp_ajax_akdvd_update_request_status', array($this, 'akdvd_handle_ajax_update_status')); add_action('wp_ajax_akdvd_search_requests', array($this, 'akdvd_handle_ajax_search_requests')); add_action('wp_ajax_akdvd_filter_requests', array($this, 'akdvd_handle_ajax_filter_requests')); add_action('wp_ajax_akdvd_get_user_display_name', array($this, 'akdvd_handle_ajax_get_user_display_name')); add_action('wp_ajax_akdvd_delete_status_file', array($this, 'akdvd_handle_ajax_delete_status_file')); } /** * مقداردهی اولیه */ public function akdvd_init() { // ثبت سطح دسترسی $role = get_role('administrator'); if ($role) { $role->add_cap('can_enter_makhzan_dvd'); } // بارگذاری فایلهای استایل و اسکریپت add_action('admin_enqueue_scripts', array($this, 'akdvd_enqueue_assets')); } /** * بارگذاری فایلهای CSS و JS */ public function akdvd_enqueue_assets($hook) { if ($hook == 'post.php' || $hook == 'post-new.php') { wp_enqueue_script('akarimi-makhzan-dvd-js', plugin_dir_url(__FILE__) . 'assets/js/script.js', array('jquery'), '1.4.0', true); wp_localize_script('akarimi-makhzan-dvd-js', 'ak_ajax_obj', array( 'ajax_url' => admin_url('admin-ajax.php'), 'nonce' => wp_create_nonce('ak_makhzan_nonce') )); } if ($hook == 'toplevel_page_akarimi-makhzan-dvd') { wp_enqueue_style('akarimi-makhzan-dvd-css', plugin_dir_url(__FILE__) . 'assets/css/style.css', array(), '1.4.0'); wp_enqueue_script('akarimi-makhzan-dvd-panel-js', plugin_dir_url(__FILE__) . 'assets/js/panel.js', array('jquery'), '1.4.0', true); wp_enqueue_script('lucide-icons', plugin_dir_url(__FILE__) . 'assets/js/lucide.js', array('jquery'), '1.4.0', true); wp_localize_script('akarimi-makhzan-dvd-panel-js', 'ak_panel_ajax_obj', array( 'ajax_url' => admin_url('admin-ajax.php'), 'nonce' => wp_create_nonce('ak_makhzan_panel_nonce') )); } } /** * اضافه کردن منو به پنل مدیریت */ public function akdvd_add_admin_menu() { if (current_user_can('can_enter_makhzan_dvd')) { add_menu_page( 'مخزن DVD', 'مخزن DVD', 'can_enter_makhzan_dvd', 'akarimi-makhzan-dvd', array($this, 'akdvd_render_admin_page'), 'dashicons-database', 30 ); } } /** * رندر صفحه ادمین */ public function akdvd_render_admin_page() { include_once plugin_dir_path(__FILE__) . 'admin-page.php'; } /** * اضافه کردن متاباکس به پست تایپ vosooli */ /** * اضافه کردن متاباکس به پست تایپ vosooli */public function akdvd_add_metabox() { if (get_post_type() === 'vosooli' && current_user_can('can_enter_makhzan_dvd')) { add_meta_box( 'ak_send_to_dvd_store', 'ارسال به مخزن DVD', array($this, 'akdvd_render_metabox'), 'vosooli', 'side', 'default' ); }}/** * رندر متاباکس */public function akdvd_render_metabox($post) { $has_sent = get_post_meta($post->ID, '_dvd_store_sent', true); echo '<style> #ak-send-to-dvd-btn { width: 100%; background: linear-gradient(135deg, #2563eb, #0ea5e9); color: white; border: none; padding: 12px 16px; border-radius: 12px; cursor: pointer; font-size: 14px; font-weight: 500; transition: all 0.3s ease; margin-bottom: 10px; } #ak-send-to-dvd-btn:hover { transform: translateY(-1px); box-shadow: 0 5px 15px rgba(37, 99, 235, 0.3); } #ak-send-to-dvd-btn:disabled { opacity: 0.6; cursor: not-allowed; transform: none; box-shadow: none; } #ak-loading-spinner { display: flex; justify-content: center; align-items: center; padding: 10px 0; } .ak-loading-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: #2563eb; margin: 0 2px; animation: loading-pulse 1.4s infinite ease-in-out both; } .ak-loading-dot:nth-child(1) { animation-delay: -0.32s; } .ak-loading-dot:nth-child(2) { animation-delay: -0.16s; } @keyframes loading-pulse { 0%, 80%, 100% { transform: scale(0); } 40% { transform: scale(1.0); } } .ak-sent-info { color: green; font-size: 12px; margin-top: 10px; line-height: 1.4; } </style>'; echo '<div id="ak-send-to-dvd-container">'; if (!$has_sent) { echo '<button type="button" id="ak-send-to-dvd-btn" class="button">ارسال به مخزن DVD</button>'; echo '<div id="ak-loading-spinner" style="display:none;">'; echo '<span class="ak-loading-dot"></span><span class="ak-loading-dot"></span><span class="ak-loading-dot"></span>'; echo '</div>'; } else { $sent_info = get_post_meta($post->ID, '_dvd_store_sent_info', true); if ($sent_info) { $info = maybe_unserialize($sent_info); $jdate = akdvd_jdate('Y/m/d H:i:s', strtotime($info['date'])); echo '<p class="ak-sent-info">ثبت در '. $jdate .' توسط '. $info['user'].'</p>'; } } echo '</div>'; echo '<script type="text/javascript"> jQuery(document).ready(function($) { $("#ak-send-to-dvd-btn").click(function() { var btn = $(this); var spinner = $("#ak-loading-spinner"); btn.prop("disabled", true).text("در حال ارسال..."); spinner.show(); $.ajax({ url: ak_ajax_obj.ajax_url, type: "POST", data: { action: "akdvd_send_to_dvd_store", post_id: ' . $post->ID . ', nonce: ak_ajax_obj.nonce }, success: function(response) { if(response.success) { btn.hide(); spinner.hide(); $("#ak-send-to-dvd-container").append('<p class="ak-sent-info">' + response.data.message + '</p>'); } else { alert(response.data.message); btn.prop("disabled", false).text("ارسال به مخزن DVD"); spinner.hide(); } }, error: function() { alert("خطا در اتصال به سرور"); btn.prop("disabled", false).text("ارسال به مخزن DVD"); spinner.hide(); } }); }); }); </script>';} /** * هندلر AJAX برای ارسال به مخزن DVD */ /** * هندلر AJAX برای ارسال به مخزن DVD */public function akdvd_handle_ajax_send_to_dvd() { check_ajax_referer('ak_makhzan_nonce', 'nonce'); if (!current_user_can('can_enter_makhzan_dvd')) { wp_die('دسترسی غیرمجاز'); } $post_id = intval($_POST['post_id']); if (!$post_id) { wp_send_json_error(array('message' => 'پست معتبر نیست')); } // چک کردن وجود متا قبلی if (get_post_meta($post_id, '_dvd_store_sent', true)) { wp_send_json_error(array('message' => 'قبلاً در مخزن ثبت شده است')); } // گرفتن اطلاعات از پست وابسته $parvande_id = get_post_meta($post_id, 'parvande_id_invosolli', true); if (!$parvande_id) { wp_send_json_error(array('message' => 'شماره پرونده یافت نشد')); } // گرفتن اطلاعات از پرونده $customer_data = array( 'fullname' => get_post_meta($parvande_id, 'parvandeh_fullname', true), 'id_number' => get_post_meta($parvande_id, 'parvandeh_idnumber', true), 'phone' => get_post_meta($parvande_id, 'parvandeh_phone', true), 'address' => get_post_meta($parvande_id, 'parvandeh_address', true), 'postal_code' => get_post_meta($parvande_id, 'parvandeh_postalcode', true), 'job' => get_post_meta($parvande_id, 'parvandeh_jobb', true) ); // گرفتن اطلاعات از پست فعلی $order_data = array( 'amount' => get_post_meta($post_id, 'vosooli_mablaq', true), 'date' => get_post_meta($post_id, 'vosooli_taarikh', true) ); // تبدیل تاریخ جلالی به میلادی $greg_date = ''; if (function_exists('akdvd_gregdate')) { $greg_date = akdvd_gregdate('Y-m-d H:i:s', $order_data['date'] . ' 00:00:00'); } else { $greg_date = date('Y-m-d H:i:s'); } // ذخیره در دیتابیس global $wpdb; $result = $wpdb->insert( $this->table_name, array( 'customer_name' => sanitize_text_field($customer_data['fullname']), 'customer_national_id' => sanitize_text_field($customer_data['id_number']), 'customer_phone' => sanitize_text_field($customer_data['phone']), 'customer_address' => sanitize_textarea_field($customer_data['address']), 'customer_postal_code' => sanitize_text_field($customer_data['postal_code']), 'customer_job' => sanitize_text_field($customer_data['job']), 'order_amount' => floatval($order_data['amount']), 'order_date' => $greg_date, 'status' => 'pending', 'submitted_by' => get_current_user_id(), 'submitted_at' => current_time('mysql'), 'status_updated_at' => current_time('mysql') ), array( '%s', '%s', '%s', '%s', '%s', '%s', '%f', '%s', '%s', '%d', '%s', '%s' ) ); if ($result !== false) { // ذخیره متا در پست فعلی update_post_meta($post_id, '_dvd_store_sent', 1); $sent_info = array( 'date' => current_time('Y/m/d H:i:s'), 'user' => wp_get_current_user()->display_name ); update_post_meta($post_id, '_dvd_store_sent_info', serialize($sent_info)); wp_send_json_success(array( 'message' => 'ثبت در '. akdvd_jdate('Y/m/d H:i:s') .' توسط '. wp_get_current_user()->display_name )); } else { wp_send_json_error(array('message' => 'خطا در ذخیره اطلاعات')); }} /** * هندلر AJAX برای گرفتن جزئیات درخواست */public function akdvd_handle_ajax_get_request_details() { check_ajax_referer('ak_makhzan_panel_nonce', 'nonce'); if (!current_user_can('can_enter_makhzan_dvd')) { wp_die('دسترسی غیرمجاز'); } $request_id = intval($_POST['request_id']); global $wpdb; $request = $wpdb->get_row($wpdb->prepare( "SELECT * FROM {$this->table_name} WHERE id = %d", $request_id ), ARRAY_A); if ($request) { // تبدیل تاریخها به جلالی $submit_date = akdvd_jdate('Y/m/d H:i:s', strtotime($request['submitted_at'])); // تاریخ وصولی از پست وابسته $vosooli_date = $this->get_vosooli_date($request['id']); $user = get_userdata($request['submitted_by']); $submitted_by_display = $user ? $user->display_name : 'ناشناس'; // فرمت اعداد مبلغ $formatted_amount = number_format($request['order_amount'], 0, '', ','); $request['submit_date'] = $submit_date; $request['vosooli_date'] = $vosooli_date; $request['submitted_by_display'] = $submitted_by_display; $request['formatted_order_amount'] = $formatted_amount; // prepare files list $files = array(); if (!empty($request['status_files'])) { $stored = maybe_unserialize($request['status_files']); if (is_array($stored)) { foreach ($stored as $f) { if (is_array($f) && isset($f['url'])) { $files[] = $f; } elseif (is_string($f)) { $files[] = array('name' => basename($f), 'url' => (strpos($f, 'http') === 0) ? $f : content_url($f)); } } } } $request['status_files_array'] = $files; wp_send_json_success($request); } else { wp_send_json_error(array('message' => 'درخواست یافت نشد')); }}/** * تابع گرفتن تاریخ وصولی از پست وابسته */private function get_vosooli_date($request_id) { global $wpdb; // پیدا کردن پست وابسته با استفاده از اطلاعات مشتری $customer_name = $wpdb->get_var($wpdb->prepare( "SELECT customer_name FROM {$this->table_name} WHERE id = %d", $request_id )); if ($customer_name) { $post_id = $wpdb->get_var($wpdb->prepare( "SELECT ID FROM {$wpdb->posts} WHERE post_title = %s AND post_type = 'vosooli' AND post_status = 'publish'", $customer_name )); if ($post_id) { $vosooli_date = get_post_meta($post_id, 'vosooli_taarikh', true); if ($vosooli_date) { // تبدیل تاریخ جلالی به فرمت Y/m/d return str_replace('-', '/', $vosooli_date); } } } return '-';} /** * هندلر AJAX برای گرفتن نام نمایشی کاربر */public function akdvd_handle_ajax_get_user_display_name() { check_ajax_referer('ak_makhzan_panel_nonce', 'nonce'); if (!current_user_can('can_enter_makhzan_dvd')) { wp_die('دسترسی غیرمجاز'); } $user_id = intval($_POST['user_id']); $user = get_userdata($user_id); if ($user) { wp_send_json_success(array('display_name' => $user->display_name)); } else { wp_send_json_error(array('message' => 'کاربر یافت نشد')); }} /** * هندلر AJAX برای بروزرسانی وضعیت */ public function akdvd_handle_ajax_update_status() { check_ajax_referer('ak_makhzan_panel_nonce', 'nonce'); if (!current_user_can('can_enter_makhzan_dvd')) { wp_die('دسترسی غیرمجاز'); } $request_id = intval($_POST['request_id']); $status = sanitize_text_field($_POST['status']); $notes = sanitize_textarea_field($_POST['notes']); // files may be uploaded via multipart/form-data $uploaded_files = array(); // اعتبارسنجی if (!in_array($status, array('pending', 'sent', 'cancelled'))) { wp_send_json_error(array('message' => 'وضعیت نامعتبر')); } global $wpdb; // handle uploaded files if (!empty($_FILES) && isset($_FILES['files'])) { $files = $_FILES['files']; $count = count($files['name']); $base_dir = WP_CONTENT_DIR . '/makhzan-dvd/' . date('Y') . '/' . date('m') . '/' . date('d') . '/'; $base_url = content_url('makhzan-dvd/' . date('Y') . '/' . date('m') . '/' . date('d') . '/'); if (!file_exists($base_dir)) { wp_mkdir_p($base_dir); } for ($i = 0; $i < $count; $i++) { if ($files['error'][$i] !== UPLOAD_ERR_OK) continue; $tmp = $files['tmp_name'][$i]; $orig_name = sanitize_file_name($files['name'][$i]); $prefix = wp_generate_password(8, false, false); $new_name = $prefix . '_' . $orig_name; $dest = $base_dir . $new_name; if (move_uploaded_file($tmp, $dest)) { $uploaded_files[] = array( 'name' => $orig_name, 'url' => $base_url . $new_name, 'path' => $dest ); } } } // merge with existing files stored in DB $existing = $wpdb->get_var($wpdb->prepare("SELECT status_files FROM {$this->table_name} WHERE id = %d", $request_id)); $existing_arr = array(); if ($existing) { $maybe = maybe_unserialize($existing); if (is_array($maybe)) $existing_arr = $maybe; } // normalize existing entries to arrays with name/url/path if they are strings $normalized = array(); foreach ($existing_arr as $e) { if (is_array($e) && isset($e['url'])) { $normalized[] = $e; } elseif (is_string($e)) { $normalized[] = array('name' => basename($e), 'url' => (strpos($e, 'http') === 0) ? $e : content_url($e), 'path' => ''); } } $merged = $normalized; foreach ($uploaded_files as $uf) { $merged[] = $uf; } $result = $wpdb->update( $this->table_name, array( 'status' => $status, 'status_notes' => $notes, 'status_files' => serialize($merged), 'status_updated_at' => current_time('mysql') ), array('id' => $request_id), array('%s', '%s', '%s', '%s'), array('%d') ); if ($result !== false) { wp_send_json_success(array('message' => 'وضعیت با موفقیت بروزرسانی شد')); } else { wp_send_json_error(array('message' => 'خطا در بروزرسانی وضعیت')); } } /** * حذف یک فایل پیوست از وضعیت */ public function akdvd_handle_ajax_delete_status_file() { check_ajax_referer('ak_makhzan_panel_nonce', 'nonce'); if (!current_user_can('can_enter_makhzan_dvd')) { wp_die('دسترسی غیرمجاز'); } $request_id = intval($_POST['request_id']); $file_url = sanitize_text_field($_POST['file_url']); if (!$request_id || !$file_url) { wp_send_json_error(array('message' => 'پارامترهای نامعتبر')); } global $wpdb; $row = $wpdb->get_var($wpdb->prepare("SELECT status_files FROM {$this->table_name} WHERE id = %d", $request_id)); if (!$row) { wp_send_json_error(array('message' => 'درخواست یافت نشد')); } $files = maybe_unserialize($row); if (!is_array($files)) $files = array(); $found = false; $file_path_to_delete = ''; foreach ($files as $idx => $f) { if (is_array($f) && isset($f['url']) && $f['url'] === $file_url) { $found = true; $file_path_to_delete = isset($f['path']) ? $f['path'] : ''; unset($files[$idx]); break; } elseif (is_string($f) && (strpos($f, $file_url) !== false || basename($f) === basename($file_url))) { $found = true; $file_path_to_delete = ''; unset($files[$idx]); break; } } if (!$found) { wp_send_json_error(array('message' => 'فایل یافت نشد')); } // attempt to delete physical file if (!empty($file_path_to_delete) && file_exists($file_path_to_delete)) { @unlink($file_path_to_delete); } $files = array_values($files); $updated = $wpdb->update( $this->table_name, array('status_files' => serialize($files)), array('id' => $request_id), array('%s'), array('%d') ); if ($updated !== false) { wp_send_json_success(array('message' => 'فایل حذف شد')); } else { wp_send_json_error(array('message' => 'خطا در حذف فایل')); } } /** * هندلر AJAX برای جستجو */ public function akdvd_handle_ajax_search_requests() { check_ajax_referer('ak_makhzan_panel_nonce', 'nonce'); if (!current_user_can('can_enter_makhzan_dvd')) { wp_die('دسترسی غیرمجاز'); } $search_term = sanitize_text_field($_POST['search_term']); global $wpdb; $results = $wpdb->get_results($wpdb->prepare( "SELECT * FROM {$this->table_name} WHERE customer_name LIKE %s OR customer_national_id LIKE %s ORDER BY submitted_at DESC LIMIT 50", '%' . $wpdb->esc_like($search_term) . '%', '%' . $wpdb->esc_like($search_term) . '%' ), ARRAY_A); wp_send_json_success($results); } /** * هندلر AJAX برای فیلتر */ public function akdvd_handle_ajax_filter_requests() { check_ajax_referer('ak_makhzan_panel_nonce', 'nonce'); if (!current_user_can('can_enter_makhzan_dvd')) { wp_die('دسترسی غیرمجاز'); } $status = sanitize_text_field($_POST['status']); global $wpdb; $where_clause = ""; if ($status !== 'all') { $where_clause = $wpdb->prepare("WHERE status = %s", $status); } $results = $wpdb->get_results( "SELECT * FROM {$this->table_name} {$where_clause} ORDER BY submitted_at DESC LIMIT 50", ARRAY_A ); wp_send_json_success($results); }}/** * تابع تبدیل تاریخ میلادی به جلالی */if (!function_exists('akdvd_gregdate')) { function akdvd_gregdate($format='Y-m-d', $jalali='') { if (function_exists('parsidate')) { return parsidate($format, $jalali, 'jalali_to_greg'); } return $jalali; }}/** * تابع تبدیل تاریخ میلادی به جلالی */if (!function_exists('akdvd_jdate')) { function akdvd_jdate($format, $timestamp = null) { if (function_exists('parsidate')) { return parsidate($format, $timestamp ?: current_time('timestamp'), 'eng'); } return $timestamp ? date($format, $timestamp) : current_time($format); }}/** * تابع محاسبه آمار */function akdvd_get_stats() { global $wpdb; $table_name = $wpdb->prefix . 'makhzan_dvd'; $total_customers = $wpdb->get_var("SELECT COUNT(*) FROM {$table_name}"); $pending_count = $wpdb->get_var("SELECT COUNT(*) FROM {$table_name} WHERE status = 'pending'"); $sent_count = $wpdb->get_var("SELECT COUNT(*) FROM {$table_name} WHERE status = 'sent'"); return array( 'total_customers' => $total_customers, 'pending_count' => $pending_count, 'sent_count' => $sent_count );}/** * تابع محاسبه سطح مبلغ */function akdvd_get_amount_level($amount) { if ($amount >= 1500000) { return 'سطح یک'; } elseif ($amount >= 1480000) { return 'سطح دو'; } elseif ($amount >= 1400000) { return 'سطح سه'; } else { return 'بدون سطح'; }}// ایجاد جدول در فعالسازی افزونهregister_activation_hook(__FILE__, 'akdvd_create_dvd_table');function akdvd_create_dvd_table() { global $wpdb; $table_name = $wpdb->prefix . 'makhzan_dvd'; $charset_collate = $wpdb->get_charset_collate(); $sql = "CREATE TABLE $table_name ( id mediumint(9) NOT NULL AUTO_INCREMENT, customer_name varchar(255) NOT NULL, customer_national_id varchar(50) DEFAULT '', customer_phone varchar(20) DEFAULT '', customer_address text DEFAULT '', customer_postal_code varchar(20) DEFAULT '', customer_job varchar(100) DEFAULT '', order_amount decimal(15,2) DEFAULT 0.00, order_date datetime DEFAULT '0000-00-00 00:00:00', status varchar(20) DEFAULT 'pending', submitted_by bigint(20) DEFAULT 0, submitted_at datetime DEFAULT '0000-00-00 00:00:00', status_notes text DEFAULT '', status_files longtext DEFAULT '', status_updated_at datetime DEFAULT '0000-00-00 00:00:00', PRIMARY KEY (id), KEY customer_national_id (customer_national_id), KEY status (status), KEY submitted_at (submitted_at) ) $charset_collate;"; require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); dbDelta($sql);}// حذف جدول در غیرفعالسازی افزونهregister_deactivation_hook(__FILE__, 'akdvd_drop_dvd_table');function akdvd_drop_dvd_table() { global $wpdb; $table_name = $wpdb->prefix . 'makhzan_dvd'; $wpdb->query("DROP TABLE IF EXISTS $table_name");}// نمونهسازی کلاسnew ak4w8DVD_Makhzan();
توضیحات تکمیلی
این توضیحات تست است
توضیحات کامل اینجا نوشته می شود
دیدگاههای شما
گفتوگو را محترمانه و سازنده نگه داریم.
گفتوگوها
در حال بارگذاری دیدگاهها…