class-qdr-tss-admin.php 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. <?php
  2. /**
  3. * The admin-specific functionality of the plugin.
  4. *
  5. * Defines the plugin name, version, and hooks for
  6. * the admin area of the site.
  7. *
  8. * @package QDR_Temporary_Shared_Storage
  9. * @since 1.0.0
  10. */
  11. class QDR_TSS_Admin {
  12. /**
  13. * The ID of this plugin.
  14. *
  15. * @since 1.0.0
  16. * @access private
  17. * @var string $plugin_name The ID of this plugin.
  18. */
  19. private $plugin_name;
  20. /**
  21. * The version of this plugin.
  22. *
  23. * @since 1.0.0
  24. * @access private
  25. * @var string $version The current version of this plugin.
  26. */
  27. private $version;
  28. /**
  29. * Initialize the class and set its properties.
  30. *
  31. * @since 1.0.0
  32. * @param string $plugin_name The name of this plugin.
  33. * @param string $version The version of this plugin.
  34. */
  35. public function __construct($plugin_name, $version) {
  36. $this->plugin_name = $plugin_name;
  37. $this->version = $version;
  38. }
  39. /**
  40. * Register the stylesheets for the admin area.
  41. *
  42. * @since 1.0.0
  43. */
  44. public function enqueue_styles() {
  45. // Only load on plugin admin pages
  46. $screen = get_current_screen();
  47. if (strpos($screen->id, 'qdr-temporary-shared-storage') === false) {
  48. return;
  49. }
  50. wp_enqueue_style(
  51. $this->plugin_name . '-admin',
  52. plugin_dir_url(dirname(__FILE__)) . 'admin/css/admin.css',
  53. array(),
  54. $this->version,
  55. 'all'
  56. );
  57. // Add jQuery UI styles for datepicker
  58. wp_enqueue_style('jquery-ui-datepicker');
  59. }
  60. /**
  61. * Register the JavaScript for the admin area.
  62. *
  63. * @since 1.0.0
  64. */
  65. public function enqueue_scripts() {
  66. // Only load on plugin admin pages
  67. $screen = get_current_screen();
  68. if (strpos($screen->id, 'qdr-temporary-shared-storage') === false) {
  69. return;
  70. }
  71. wp_enqueue_script(
  72. $this->plugin_name . '-admin',
  73. plugin_dir_url(dirname(__FILE__)) . 'admin/js/admin.js',
  74. array('jquery', 'jquery-ui-datepicker'),
  75. $this->version,
  76. true
  77. );
  78. // Localize script with translations and data
  79. wp_localize_script($this->plugin_name . '-admin', 'qdr_tss', array(
  80. 'ajaxurl' => admin_url('admin-ajax.php'),
  81. 'nonce' => wp_create_nonce('qdr_tss_nonce'),
  82. 'strings' => array(
  83. 'loading' => __('Loading...', 'qdr-temporary-shared-storage'),
  84. 'saving' => __('Saving...', 'qdr-temporary-shared-storage'),
  85. 'no_items' => __('No items', 'qdr-temporary-shared-storage'),
  86. 'no_items_found' => __('No items found.', 'qdr-temporary-shared-storage'),
  87. 'showing' => __('Showing', 'qdr-temporary-shared-storage'),
  88. 'of' => __('of', 'qdr-temporary-shared-storage'),
  89. 'first_page' => __('First Page', 'qdr-temporary-shared-storage'),
  90. 'previous_page' => __('Previous Page', 'qdr-temporary-shared-storage'),
  91. 'next_page' => __('Next Page', 'qdr-temporary-shared-storage'),
  92. 'last_page' => __('Last Page', 'qdr-temporary-shared-storage'),
  93. 'view_details' => __('View Details', 'qdr-temporary-shared-storage'),
  94. 'edit' => __('Edit', 'qdr-temporary-shared-storage'),
  95. 'delete' => __('Delete', 'qdr-temporary-shared-storage'),
  96. 'confirm_delete' => __('Are you sure you want to delete this file?', 'qdr-temporary-shared-storage'),
  97. 'confirm_purge' => __('Are you sure you want to purge all expired files?', 'qdr-temporary-shared-storage'),
  98. 'error_loading_items' => __('Error loading items.', 'qdr-temporary-shared-storage'),
  99. 'error_loading_items_try_again' => __('Error loading items. Please try again.', 'qdr-temporary-shared-storage'),
  100. 'error_loading_item_details' => __('Error loading item details.', 'qdr-temporary-shared-storage'),
  101. 'error_loading_item_details_try_again' => __('Error loading item details. Please try again.', 'qdr-temporary-shared-storage'),
  102. 'changes_saved' => __('Changes saved successfully.', 'qdr-temporary-shared-storage'),
  103. 'error_saving_changes' => __('Error saving changes.', 'qdr-temporary-shared-storage'),
  104. 'error_saving_changes_try_again' => __('Error saving changes. Please try again.', 'qdr-temporary-shared-storage'),
  105. 'file_deleted' => __('File deleted successfully.', 'qdr-temporary-shared-storage'),
  106. 'error_deleting_file' => __('Error deleting file.', 'qdr-temporary-shared-storage'),
  107. 'error_deleting_file_try_again' => __('Error deleting file. Please try again.', 'qdr-temporary-shared-storage'),
  108. 'shortcode_copied' => __('Shortcode copied to clipboard.', 'qdr-temporary-shared-storage'),
  109. 'permalink_copied' => __('Permalink copied to clipboard.', 'qdr-temporary-shared-storage'),
  110. )
  111. ));
  112. }
  113. /**
  114. * Add admin menu items.
  115. *
  116. * @since 1.0.0
  117. */
  118. public function add_admin_menu() {
  119. // Add Shared Storage page under Media menu
  120. add_submenu_page(
  121. 'upload.php',
  122. __('Shared Storage', 'qdr-temporary-shared-storage'),
  123. __('Shared Storage', 'qdr-temporary-shared-storage'),
  124. 'manage_options',
  125. 'qdr-temporary-shared-storage',
  126. array($this, 'render_media_page')
  127. );
  128. // Add Settings page
  129. add_submenu_page(
  130. 'options-general.php',
  131. __('Shared Storage Settings', 'qdr-temporary-shared-storage'),
  132. __('Shared Storage', 'qdr-temporary-shared-storage'),
  133. 'manage_options',
  134. 'qdr-temporary-shared-storage-settings',
  135. array($this, 'render_settings_page')
  136. );
  137. }
  138. /**
  139. * Render the Media Shared Storage admin page.
  140. *
  141. * @since 1.0.0
  142. */
  143. public function render_media_page() {
  144. require_once plugin_dir_path(dirname(__FILE__)) . 'admin/partials/media-page.php';
  145. }
  146. /**
  147. * Render the Settings admin page.
  148. *
  149. * @since 1.0.0
  150. */
  151. public function render_settings_page() {
  152. require_once plugin_dir_path(dirname(__FILE__)) . 'admin/partials/settings-page.php';
  153. }
  154. }