class-qdr-tss-admin.php 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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. 'copy_permalink' => __('Copy Permalink', 'qdr-temporary-shared-storage'),
  97. 'force_activate' => __('Force Activate', 'qdr-temporary-shared-storage'),
  98. 'confirm_delete' => __('Are you sure you want to delete this file?', 'qdr-temporary-shared-storage'),
  99. 'confirm_purge' => __('Are you sure you want to purge all expired files?', 'qdr-temporary-shared-storage'),
  100. 'confirm_force_activate' => __('Are you sure you want to force activate this file? This will reset the active period starting from now.', 'qdr-temporary-shared-storage'),
  101. 'error_loading_items' => __('Error loading items.', 'qdr-temporary-shared-storage'),
  102. 'error_loading_items_try_again' => __('Error loading items. Please try again.', 'qdr-temporary-shared-storage'),
  103. 'error_loading_item_details' => __('Error loading item details.', 'qdr-temporary-shared-storage'),
  104. 'error_loading_item_details_try_again' => __('Error loading item details. Please try again.', 'qdr-temporary-shared-storage'),
  105. 'changes_saved' => __('Changes saved successfully.', 'qdr-temporary-shared-storage'),
  106. 'error_saving_changes' => __('Error saving changes.', 'qdr-temporary-shared-storage'),
  107. 'error_saving_changes_try_again' => __('Error saving changes. Please try again.', 'qdr-temporary-shared-storage'),
  108. 'file_deleted' => __('File deleted successfully.', 'qdr-temporary-shared-storage'),
  109. 'error_deleting_file' => __('Error deleting file.', 'qdr-temporary-shared-storage'),
  110. 'error_deleting_file_try_again' => __('Error deleting file. Please try again.', 'qdr-temporary-shared-storage'),
  111. 'shortcode_copied' => __('Shortcode copied to clipboard.', 'qdr-temporary-shared-storage'),
  112. 'permalink_copied' => __('Permalink copied to clipboard.', 'qdr-temporary-shared-storage'),
  113. 'permalink_copied_to_clipboard' => __('Permalink copied to clipboard successfully.', 'qdr-temporary-shared-storage'),
  114. 'error_getting_permalink' => __('Error getting permalink.', 'qdr-temporary-shared-storage'),
  115. 'error_getting_permalink_try_again' => __('Error getting permalink. Please try again.', 'qdr-temporary-shared-storage'),
  116. 'item_force_activated' => __('Item has been force activated successfully.', 'qdr-temporary-shared-storage'),
  117. 'error_force_activating' => __('Error force activating item.', 'qdr-temporary-shared-storage'),
  118. 'error_force_activating_try_again' => __('Error force activating item. Please try again.', 'qdr-temporary-shared-storage'),
  119. )
  120. ));
  121. }
  122. /**
  123. * Add admin menu items.
  124. *
  125. * @since 1.0.0
  126. */
  127. public function add_admin_menu() {
  128. // Add Shared Storage page under Media menu
  129. add_submenu_page(
  130. 'upload.php',
  131. __('Shared Storage', 'qdr-temporary-shared-storage'),
  132. __('Shared Storage', 'qdr-temporary-shared-storage'),
  133. 'manage_options',
  134. 'qdr-temporary-shared-storage',
  135. array($this, 'render_media_page')
  136. );
  137. // Add Settings page
  138. add_submenu_page(
  139. 'options-general.php',
  140. __('Shared Storage Settings', 'qdr-temporary-shared-storage'),
  141. __('Shared Storage', 'qdr-temporary-shared-storage'),
  142. 'manage_options',
  143. 'qdr-temporary-shared-storage-settings',
  144. array($this, 'render_settings_page')
  145. );
  146. }
  147. /**
  148. * Render the Media Shared Storage admin page.
  149. *
  150. * @since 1.0.0
  151. */
  152. public function render_media_page() {
  153. require_once plugin_dir_path(dirname(__FILE__)) . 'admin/partials/media-page.php';
  154. }
  155. /**
  156. * Render the Settings admin page.
  157. *
  158. * @since 1.0.0
  159. */
  160. public function render_settings_page() {
  161. require_once plugin_dir_path(dirname(__FILE__)) . 'admin/partials/settings-page.php';
  162. }
  163. }