| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138 |
- <?php
- /**
- * Settings Page functionality of the plugin.
- *
- * @package QDR_Temporary_Shared_Storage
- * @since 1.0.0
- */
- class QDR_TSS_Settings_Page {
- /**
- * The ID of this plugin.
- *
- * @since 1.0.0
- * @access private
- * @var string $plugin_name The ID of this plugin.
- */
- private $plugin_name;
- /**
- * The version of this plugin.
- *
- * @since 1.0.0
- * @access private
- * @var string $version The current version of this plugin.
- */
- private $version;
- /**
- * The settings instance.
- *
- * @since 1.0.0
- * @access private
- * @var QDR_TSS_Settings $settings The settings instance.
- */
- private $settings;
- /**
- * The database manager instance.
- *
- * @since 1.0.0
- * @access private
- * @var QDR_TSS_DB_Manager $db_manager The database manager instance.
- */
- private $db_manager;
- /**
- * The file manager instance.
- *
- * @since 1.0.0
- * @access private
- * @var QDR_TSS_File_Manager $file_manager The file manager instance.
- */
- private $file_manager;
- /**
- * The cron manager instance.
- *
- * @since 1.0.0
- * @access private
- * @var QDR_TSS_Cron_Manager $cron_manager The cron manager instance.
- */
- private $cron_manager;
- /**
- * Initialize the class and set its properties.
- *
- * @since 1.0.0
- * @param string $plugin_name The name of this plugin.
- * @param string $version The version of this plugin.
- */
- public function __construct($plugin_name, $version) {
- $this->plugin_name = $plugin_name;
- $this->version = $version;
- $this->settings = QDR_TSS_Settings::instance();
- $this->db_manager = QDR_TSS_DB_Manager::instance();
- $this->file_manager = QDR_TSS_File_Manager::instance();
- $this->cron_manager = new QDR_TSS_Cron_Manager($plugin_name, $version);
- }
- /**
- * AJAX handler for saving settings.
- *
- * @since 1.0.0
- */
- public function ajax_save_settings() {
- // Check nonce
- if (!isset($_POST['nonce']) || !wp_verify_nonce($_POST['nonce'], 'qdr_tss_nonce')) {
- wp_send_json_error(array('message' => __('Security check failed.', 'qdr-temporary-shared-storage')));
- }
-
- // Get settings
- $api_key = isset($_POST['api_key']) ? sanitize_text_field($_POST['api_key']) : '';
- $media_category = isset($_POST['media_category']) ? sanitize_text_field($_POST['media_category']) : 'shared-storage';
- $max_upload_size = isset($_POST['max_upload_size']) ? intval($_POST['max_upload_size']) : 1073741824; // 1GB default
-
- // Update settings
- $this->settings->update_settings(array(
- 'api_key' => $api_key,
- 'media_category' => $media_category,
- 'max_upload_size' => $max_upload_size
- ));
-
- wp_send_json_success(array(
- 'message' => __('Settings saved successfully.', 'qdr-temporary-shared-storage')
- ));
- }
- /**
- * AJAX handler for purging expired files.
- *
- * @since 1.0.0
- */
- public function ajax_purge_expired() {
- // Check nonce
- if (!isset($_POST['nonce']) || !wp_verify_nonce($_POST['nonce'], 'qdr_tss_nonce')) {
- wp_send_json_error(array('message' => __('Security check failed.', 'qdr-temporary-shared-storage')));
- }
-
- // Purge expired files
- $purged_count = $this->cron_manager->manual_purge_expired_files();
-
- // Translators: %d is the number of purged files
- $message = sprintf(
- _n(
- '%d expired file has been purged.',
- '%d expired files have been purged.',
- $purged_count,
- 'qdr-temporary-shared-storage'
- ),
- $purged_count
- );
-
- wp_send_json_success(array(
- 'message' => $message,
- 'purged_count' => $purged_count
- ));
- }
- }
|