class-qdr-tss.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  1. <?php
  2. /**
  3. * The core plugin class.
  4. *
  5. * This is used to define internationalization, admin-specific hooks, and
  6. * public-facing site hooks.
  7. *
  8. * @since 1.0.0
  9. * @package QDR_Temporary_Shared_Storage
  10. */
  11. class QDR_TSS {
  12. /**
  13. * The loader that's responsible for maintaining and registering all hooks that power
  14. * the plugin.
  15. *
  16. * @since 1.0.0
  17. * @access protected
  18. * @var QDR_TSS_Loader $loader Maintains and registers all hooks for the plugin.
  19. */
  20. protected $loader;
  21. /**
  22. * The unique identifier of this plugin.
  23. *
  24. * @since 1.0.0
  25. * @access protected
  26. * @var string $plugin_name The string used to uniquely identify this plugin.
  27. */
  28. protected $plugin_name;
  29. /**
  30. * The current version of the plugin.
  31. *
  32. * @since 1.0.0
  33. * @access protected
  34. * @var string $version The current version of the plugin.
  35. */
  36. protected $version;
  37. /**
  38. * Define the core functionality of the plugin.
  39. *
  40. * Set the plugin name and the plugin version that can be used throughout the plugin.
  41. * Load the dependencies, define the locale, and set the hooks for the admin area and
  42. * the public-facing side of the site.
  43. *
  44. * @since 1.0.0
  45. */
  46. public function __construct() {
  47. $this->version = QDR_TSS_VERSION;
  48. $this->plugin_name = 'qdr-temporary-shared-storage';
  49. $this->define_constants();
  50. $this->load_dependencies();
  51. $this->set_locale();
  52. $this->define_admin_hooks();
  53. $this->define_public_hooks();
  54. $this->define_rest_api_hooks();
  55. $this->define_cron_hooks();
  56. }
  57. /**
  58. * Define constants used by the plugin.
  59. *
  60. * @since 1.0.0
  61. * @access private
  62. */
  63. private function define_constants() {
  64. define('QDR_TSS_PLUGIN_DIR', plugin_dir_path(dirname(__FILE__)));
  65. define('QDR_TSS_PLUGIN_URL', plugin_dir_url(dirname(__FILE__)));
  66. define('QDR_TSS_PLUGIN_BASENAME', plugin_basename(dirname(__FILE__)));
  67. define('QDR_TSS_UPLOADS_DIR', wp_upload_dir()['basedir'] . '/qdr-shared-storage/');
  68. define('QDR_TSS_UPLOADS_URL', wp_upload_dir()['baseurl'] . '/qdr-shared-storage/');
  69. define('QDR_TSS_PLUGIN_TABLE', 'qdr_temporary_shared_storage');
  70. }
  71. /**
  72. * Load the required dependencies for this plugin.
  73. *
  74. * Include the following files that make up the plugin:
  75. *
  76. * - QDR_TSS_Loader. Orchestrates the hooks of the plugin.
  77. * - QDR_TSS_i18n. Defines internationalization functionality.
  78. * - QDR_TSS_Admin. Defines all hooks for the admin area.
  79. * - QDR_TSS_Public. Defines all hooks for the public side of the site.
  80. * - QDR_TSS_REST_Controller. Defines all hooks for the REST API.
  81. * - QDR_TSS_DB_Manager. Handles database operations.
  82. * - QDR_TSS_File_Manager. Handles file operations.
  83. * - QDR_TSS_Settings. Handles plugin settings.
  84. * - QDR_TSS_Cron_Manager. Handles scheduled tasks.
  85. *
  86. * @since 1.0.0
  87. * @access private
  88. */
  89. private function load_dependencies() {
  90. /**
  91. * The class responsible for orchestrating the actions and filters of the
  92. * core plugin.
  93. */
  94. require_once plugin_dir_path(dirname(__FILE__)) . 'includes/class-qdr-tss-loader.php';
  95. /**
  96. * The class responsible for defining internationalization functionality
  97. * of the plugin.
  98. */
  99. require_once plugin_dir_path(dirname(__FILE__)) . 'includes/class-qdr-tss-i18n.php';
  100. /**
  101. * The class responsible for defining all database operations.
  102. */
  103. require_once plugin_dir_path(dirname(__FILE__)) . 'includes/class-qdr-tss-db-manager.php';
  104. /**
  105. * The class responsible for defining all file operations.
  106. */
  107. require_once plugin_dir_path(dirname(__FILE__)) . 'includes/class-qdr-tss-file-manager.php';
  108. /**
  109. * The class responsible for handling plugin settings.
  110. */
  111. require_once plugin_dir_path(dirname(__FILE__)) . 'includes/class-qdr-tss-settings.php';
  112. /**
  113. * The class responsible for handling scheduled tasks.
  114. */
  115. require_once plugin_dir_path(dirname(__FILE__)) . 'includes/class-qdr-tss-cron-manager.php';
  116. /**
  117. * Helper functions.
  118. */
  119. require_once plugin_dir_path(dirname(__FILE__)) . 'includes/functions.php';
  120. /**
  121. * The class responsible for defining all actions that occur in the admin area.
  122. */
  123. require_once plugin_dir_path(dirname(__FILE__)) . 'admin/class-qdr-tss-admin.php';
  124. require_once plugin_dir_path(dirname(__FILE__)) . 'admin/class-qdr-tss-media-page.php';
  125. require_once plugin_dir_path(dirname(__FILE__)) . 'admin/class-qdr-tss-settings-page.php';
  126. /**
  127. * The class responsible for defining all actions that occur in the public-facing
  128. * side of the site.
  129. */
  130. require_once plugin_dir_path(dirname(__FILE__)) . 'public/class-qdr-tss-public.php';
  131. require_once plugin_dir_path(dirname(__FILE__)) . 'public/class-qdr-tss-shortcode.php';
  132. require_once plugin_dir_path(dirname(__FILE__)) . 'public/class-qdr-tss-download.php';
  133. /**
  134. * The class responsible for defining all REST API functionality.
  135. */
  136. require_once plugin_dir_path(dirname(__FILE__)) . 'rest-api/class-qdr-tss-rest-controller.php';
  137. require_once plugin_dir_path(dirname(__FILE__)) . 'rest-api/class-qdr-tss-media-controller.php';
  138. require_once plugin_dir_path(dirname(__FILE__)) . 'rest-api/class-qdr-tss-upload-controller.php';
  139. $this->loader = new QDR_TSS_Loader();
  140. }
  141. /**
  142. * Define the locale for this plugin for internationalization.
  143. *
  144. * Uses the QDR_TSS_i18n class in order to set the domain and to register the hook
  145. * with WordPress.
  146. *
  147. * @since 1.0.0
  148. * @access private
  149. */
  150. private function set_locale() {
  151. $plugin_i18n = new QDR_TSS_i18n();
  152. $this->loader->add_action('plugins_loaded', $plugin_i18n, 'load_plugin_textdomain');
  153. }
  154. /**
  155. * Register all of the hooks related to the admin area functionality
  156. * of the plugin.
  157. *
  158. * @since 1.0.0
  159. * @access private
  160. */
  161. private function define_admin_hooks() {
  162. $plugin_admin = new QDR_TSS_Admin($this->get_plugin_name(), $this->get_version());
  163. $media_page = new QDR_TSS_Media_Page($this->get_plugin_name(), $this->get_version());
  164. $settings_page = new QDR_TSS_Settings_Page($this->get_plugin_name(), $this->get_version());
  165. // Admin hooks
  166. $this->loader->add_action('admin_enqueue_scripts', $plugin_admin, 'enqueue_styles');
  167. $this->loader->add_action('admin_enqueue_scripts', $plugin_admin, 'enqueue_scripts');
  168. $this->loader->add_action('admin_menu', $plugin_admin, 'add_admin_menu');
  169. // AJAX handlers
  170. $this->loader->add_action('wp_ajax_qdr_tss_get_items', $media_page, 'ajax_get_items');
  171. $this->loader->add_action('wp_ajax_qdr_tss_edit_item', $media_page, 'ajax_edit_item');
  172. $this->loader->add_action('wp_ajax_qdr_tss_delete_item', $media_page, 'ajax_delete_item');
  173. $this->loader->add_action('wp_ajax_qdr_tss_get_item_details', $media_page, 'ajax_get_item_details');
  174. $this->loader->add_action('wp_ajax_qdr_tss_force_activate_item', $media_page, 'ajax_force_activate_item'); // NEW
  175. $this->loader->add_action('wp_ajax_qdr_tss_save_settings', $settings_page, 'ajax_save_settings');
  176. $this->loader->add_action('wp_ajax_qdr_tss_purge_expired', $settings_page, 'ajax_purge_expired');
  177. }
  178. /**
  179. * Register all of the hooks related to the public-facing functionality
  180. * of the plugin.
  181. *
  182. * @since 1.0.0
  183. * @access private
  184. */
  185. private function define_public_hooks() {
  186. $plugin_public = new QDR_TSS_Public($this->get_plugin_name(), $this->get_version());
  187. $plugin_shortcode = new QDR_TSS_Shortcode($this->get_plugin_name(), $this->get_version());
  188. $plugin_download = new QDR_TSS_Download($this->get_plugin_name(), $this->get_version());
  189. // Public hooks
  190. $this->loader->add_action('wp_enqueue_scripts', $plugin_public, 'enqueue_styles');
  191. $this->loader->add_action('wp_enqueue_scripts', $plugin_public, 'enqueue_scripts');
  192. $this->loader->add_action('init', $plugin_public, 'create_download_page');
  193. // Add rewrite rules
  194. $this->loader->add_action('init', $plugin_public, 'add_rewrite_rules');
  195. $this->loader->add_filter('query_vars', $plugin_public, 'add_query_vars');
  196. // Shortcode registration
  197. $this->loader->add_action('init', $plugin_shortcode, 'register_shortcodes');
  198. }
  199. /**
  200. * Register all of the hooks related to the REST API functionality
  201. * of the plugin.
  202. *
  203. * @since 1.0.0
  204. * @access private
  205. */
  206. private function define_rest_api_hooks() {
  207. $rest_controller = new QDR_TSS_REST_Controller($this->get_plugin_name(), $this->get_version());
  208. $media_controller = new QDR_TSS_Media_Controller($this->get_plugin_name(), $this->get_version());
  209. $upload_controller = new QDR_TSS_Upload_Controller($this->get_plugin_name(), $this->get_version());
  210. // REST API hooks
  211. $this->loader->add_action('rest_api_init', $rest_controller, 'register_routes');
  212. $this->loader->add_filter('rest_authentication_errors', $rest_controller, 'check_api_key');
  213. }
  214. /**
  215. * Register all of the hooks related to the cron functionality
  216. * of the plugin.
  217. *
  218. * @since 1.0.0
  219. * @access private
  220. */
  221. private function define_cron_hooks() {
  222. $cron_manager = new QDR_TSS_Cron_Manager($this->get_plugin_name(), $this->get_version());
  223. // Cron hooks
  224. $this->loader->add_action('qdr_tss_purge_expired_files', $cron_manager, 'purge_expired_files');
  225. }
  226. /**
  227. * Run the loader to execute all of the hooks with WordPress.
  228. *
  229. * @since 1.0.0
  230. */
  231. public function run() {
  232. $this->loader->run();
  233. }
  234. /**
  235. * The name of the plugin used to uniquely identify it within the context of
  236. * WordPress and to define internationalization functionality.
  237. *
  238. * @since 1.0.0
  239. * @return string The name of the plugin.
  240. */
  241. public function get_plugin_name() {
  242. return $this->plugin_name;
  243. }
  244. /**
  245. * The reference to the class that orchestrates the hooks with the plugin.
  246. *
  247. * @since 1.0.0
  248. * @return QDR_TSS_Loader Orchestrates the hooks of the plugin.
  249. */
  250. public function get_loader() {
  251. return $this->loader;
  252. }
  253. /**
  254. * Retrieve the version number of the plugin.
  255. *
  256. * @since 1.0.0
  257. * @return string The version number of the plugin.
  258. */
  259. public function get_version() {
  260. return $this->version;
  261. }
  262. }