settings-page.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. /**
  3. * Admin Settings Page
  4. *
  5. * @package QDR_Temporary_Shared_Storage
  6. */
  7. // If this file is called directly, abort.
  8. if (!defined('WPINC')) {
  9. die;
  10. }
  11. // Get current settings
  12. $settings = QDR_TSS_Settings::instance()->get_settings();
  13. $db_manager = QDR_TSS_DB_Manager::instance();
  14. // Get total storage usage
  15. $total_size = $db_manager->get_total_storage();
  16. $max_size = $settings['max_upload_size'];
  17. $usage_percent = ($max_size > 0) ? min(100, ($total_size / $max_size) * 100) : 0;
  18. ?>
  19. <div class="wrap qdr-tss-admin">
  20. <h1><?php esc_html_e('Shared Storage Settings', 'qdr-temporary-shared-storage'); ?></h1>
  21. <form id="qdr-tss-settings-form" method="post">
  22. <table class="form-table">
  23. <tbody>
  24. <tr>
  25. <th scope="row">
  26. <label for="qdr-tss-api-key"><?php esc_html_e('API Key', 'qdr-temporary-shared-storage'); ?></label>
  27. </th>
  28. <td>
  29. <input type="text" id="qdr-tss-api-key" name="api_key" value="<?php echo esc_attr($settings['api_key']); ?>" class="regular-text">
  30. <p class="description"><?php esc_html_e('API key for REST API authentication.', 'qdr-temporary-shared-storage'); ?></p>
  31. <button type="button" id="qdr-tss-generate-key" class="button"><?php esc_html_e('Generate New Key', 'qdr-temporary-shared-storage'); ?></button>
  32. </td>
  33. </tr>
  34. <tr>
  35. <th scope="row">
  36. <label for="qdr-tss-media-category"><?php esc_html_e('Media Category', 'qdr-temporary-shared-storage'); ?></label>
  37. </th>
  38. <td>
  39. <input type="text" id="qdr-tss-media-category" name="media_category" value="<?php echo esc_attr($settings['media_category']); ?>" class="regular-text">
  40. <p class="description"><?php esc_html_e('Category to assign to uploaded media.', 'qdr-temporary-shared-storage'); ?></p>
  41. </td>
  42. </tr>
  43. <tr>
  44. <th scope="row">
  45. <label for="qdr-tss-max-upload-size"><?php esc_html_e('Maximum Storage Size (bytes)', 'qdr-temporary-shared-storage'); ?></label>
  46. </th>
  47. <td>
  48. <input type="number" id="qdr-tss-max-upload-size" name="max_upload_size" value="<?php echo esc_attr($settings['max_upload_size']); ?>" class="regular-text">
  49. <p class="description">
  50. <?php esc_html_e('Maximum total storage size in bytes. Current usage:', 'qdr-temporary-shared-storage'); ?>
  51. <span id="qdr-tss-current-usage"><?php echo esc_html(qdr_tss_format_bytes($total_size)); ?></span>
  52. (<?php echo esc_html(qdr_tss_format_bytes($settings['max_upload_size'])); ?> <?php esc_html_e('max', 'qdr-temporary-shared-storage'); ?>)
  53. </p>
  54. <div class="qdr-tss-storage-bar">
  55. <div class="qdr-tss-storage-used" style="width: <?php echo min(100, ($total_size / $settings['max_upload_size']) * 100); ?>%"></div>
  56. </div>
  57. <p class="description">
  58. <?php esc_html_e('Common sizes:', 'qdr-temporary-shared-storage'); ?><br>
  59. 1 GB = 1073741824 <?php esc_html_e('bytes', 'qdr-temporary-shared-storage'); ?><br>
  60. 5 GB = 5368709120 <?php esc_html_e('bytes', 'qdr-temporary-shared-storage'); ?><br>
  61. 10 GB = 10737418240 <?php esc_html_e('bytes', 'qdr-temporary-shared-storage'); ?>
  62. </p>
  63. </td>
  64. </tr>
  65. </tbody>
  66. </table>
  67. <p class="submit">
  68. <button type="submit" id="qdr-tss-save-settings" class="button button-primary"><?php esc_html_e('Save Settings', 'qdr-temporary-shared-storage'); ?></button>
  69. <button type="button" id="qdr-tss-purge-expired" class="button"><?php esc_html_e('Purge Expired Files', 'qdr-temporary-shared-storage'); ?></button>
  70. </p>
  71. </form>
  72. </div>