| 1 |
<?php |
| 2 |
/** |
| 3 |
* Suppress "error - 0 - No summary was found for this file" on phpdoc generation |
| 4 |
* |
| 5 |
* @package plugin\includes |
| 6 |
*/ |
| 7 |
|
| 8 |
use WPDataAccess\Data_Dictionary\WPDA_Dictionary_Lists; |
| 9 |
use WPDataAccess\Data_Tables\WPDA_Data_Tables; |
| 10 |
use WPDataAccess\Utilities\WPDA_Table_Actions; |
| 11 |
use WPDataAccess\Utilities\WPDA_Example; |
| 12 |
use WPDataAccess\Utilities\WPDA_Export; |
| 13 |
use WPDataAccess\Utilities\WPDA_Favourites; |
| 14 |
use WPDataProjects\Utilities\WPDP_Export_Project; |
| 15 |
use WPDataAccess\Backup\WPDA_Data_Export; |
| 16 |
|
| 17 |
/** |
| 18 |
* Class WP_Data_Access |
| 19 |
* |
| 20 |
* Core plugin class used to define: |
| 21 |
* + admin specific functionality {@see WP_Data_Access_Admin} |
| 22 |
* + public specific functionality {@see WP_Data_Access_Public} |
| 23 |
* + internationalization {@see WP_Data_Access_I18n} |
| 24 |
* + plugin activation and deactivation {@see WP_Data_Access_Loader} |
| 25 |
* |
| 26 |
* @package plugin\includes |
| 27 |
* @author Peter Schulz |
| 28 |
* @since 1.0.0 |
| 29 |
* |
| 30 |
* @see WP_Data_Access_Admin |
| 31 |
* @see WP_Data_Access_Public |
| 32 |
* @see WP_Data_Access_I18n |
| 33 |
* @see WP_Data_Access_Loader |
| 34 |
*/ |
| 35 |
class WP_Data_Access { |
| 36 |
|
| 37 |
/** |
| 38 |
* Reference to plugin loader |
| 39 |
* |
| 40 |
* @var WP_Data_Access_Loader |
| 41 |
* |
| 42 |
* @since 1.0.0 |
| 43 |
* |
| 44 |
* @see WP_Data_Access_Loader |
| 45 |
*/ |
| 46 |
protected $loader; |
| 47 |
|
| 48 |
/** |
| 49 |
* WP_Data_Access constructor |
| 50 |
* |
| 51 |
* Calls method the following methods to setup plugin: |
| 52 |
* + {@see WP_Data_Access::load_dependencies()} |
| 53 |
* + {@see WP_Data_Access::set_locale()} |
| 54 |
* + {@see WP_Data_Access::define_admin_hooks()} |
| 55 |
* + {@see WP_Data_Access::define_public_hooks()} |
| 56 |
* |
| 57 |
* @since 1.0.0 |
| 58 |
* |
| 59 |
* @see WP_Data_Access::load_dependencies() |
| 60 |
* @see WP_Data_Access::set_locale() |
| 61 |
* @see WP_Data_Access::define_admin_hooks() |
| 62 |
* @see WP_Data_Access::define_public_hooks() |
| 63 |
*/ |
| 64 |
public function __construct() { |
| 65 |
|
| 66 |
$this->load_dependencies(); |
| 67 |
$this->set_locale(); |
| 68 |
$this->define_admin_hooks(); |
| 69 |
$this->define_public_hooks(); |
| 70 |
|
| 71 |
} |
| 72 |
|
| 73 |
/** |
| 74 |
* Load required dependencies |
| 75 |
* |
| 76 |
* Loads required plugin files and initiates the plugin loader. |
| 77 |
* |
| 78 |
* @since 1.0.0 |
| 79 |
* |
| 80 |
* @see WP_Data_Access_Loader |
| 81 |
*/ |
| 82 |
private function load_dependencies() { |
| 83 |
|
| 84 |
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wp-data-access-loader.php'; |
| 85 |
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wp-data-access-i18n.php'; |
| 86 |
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wp-data-access-admin.php'; |
| 87 |
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'public/class-wp-data-access-public.php'; |
| 88 |
|
| 89 |
$this->loader = new WP_Data_Access_Loader(); |
| 90 |
|
| 91 |
} |
| 92 |
|
| 93 |
/** |
| 94 |
* Set locale for internationalization |
| 95 |
* |
| 96 |
* @since 1.0.0 |
| 97 |
* |
| 98 |
* @see WP_Data_Access_I18n |
| 99 |
*/ |
| 100 |
private function set_locale() { |
| 101 |
|
| 102 |
$wpda_i18n = new WP_Data_Access_I18n(); |
| 103 |
$this->loader->add_action( 'init', $wpda_i18n, 'load_plugin_textdomain' ); |
| 104 |
|
| 105 |
} |
| 106 |
|
| 107 |
/** |
| 108 |
* Add admin hooks |
| 109 |
* |
| 110 |
* Initiates {@see WP_Data_Access_Admin} (admin functionality), {@see WPDA_Export} (export functionality) and |
| 111 |
* {@see WPDA_Example} (example plugin that demostrates the use of WP Data Access by code from another plugin). |
| 112 |
* Adds the appropriate actions to the loader. |
| 113 |
* |
| 114 |
* @since 1.0.0 |
| 115 |
* |
| 116 |
* @see WP_Data_Access_Admin |
| 117 |
* @see WPDA_Export |
| 118 |
* @see WPDA_Example |
| 119 |
*/ |
| 120 |
private function define_admin_hooks() { |
| 121 |
|
| 122 |
$plugin_admin = new WP_Data_Access_Admin(); |
| 123 |
|
| 124 |
// Handle plugin cookies. |
| 125 |
$this->loader->add_action( 'admin_init' , $plugin_admin, 'handle_plugin_cookies' ); |
| 126 |
|
| 127 |
// Admin menu. |
| 128 |
$this->loader->add_action( 'admin_menu', $plugin_admin, 'add_menu_items' ); |
| 129 |
$this->loader->add_action( 'admin_menu', $plugin_admin, 'add_menu_my_tables', 11 ); |
| 130 |
|
| 131 |
// Admin scripts. |
| 132 |
$this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_styles' ); |
| 133 |
$this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_scripts' ); |
| 134 |
|
| 135 |
// TinyMCE listboxes (get table list). |
| 136 |
$this->loader->add_action( 'admin_footer', $plugin_admin, 'tinymce_listboxes_get_tables' ); |
| 137 |
|
| 138 |
// Export action. |
| 139 |
$plugin_export = new WPDA_Export(); |
| 140 |
$this->loader->add_action( 'admin_action_wpda_export', $plugin_export, 'export' ); |
| 141 |
|
| 142 |
// Example requested. |
| 143 |
$plugin_example = new WPDA_Example(); |
| 144 |
$this->loader->add_action( 'admin_action_wpda_example', $plugin_example, 'get_example' ); |
| 145 |
|
| 146 |
// Add/remove favourites. |
| 147 |
$plugin_favourites = new WPDA_Favourites(); |
| 148 |
$this->loader->add_action( 'admin_action_add_favourite', $plugin_favourites, 'add' ); |
| 149 |
$this->loader->add_action( 'admin_action_rem_favourite', $plugin_favourites, 'rem' ); |
| 150 |
|
| 151 |
// Show tables actions. |
| 152 |
$plugin_table_actions = new WPDA_Table_Actions(); |
| 153 |
$this->loader->add_action( 'admin_action_show_table_actions', $plugin_table_actions, 'show' ); |
| 154 |
|
| 155 |
// Get columns for a specific table. |
| 156 |
$plugin_column_list = new WPDA_Dictionary_Lists(); |
| 157 |
$this->loader->add_action( 'admin_action_get_columns', $plugin_column_list, 'get_columns' ); |
| 158 |
|
| 159 |
// Export project. |
| 160 |
$plugin_export_project = new WPDP_Export_Project(); |
| 161 |
$this->loader->add_action( 'admin_action_wpdp_export_project', $plugin_export_project, 'export' ); |
| 162 |
|
| 163 |
// Data backup. |
| 164 |
$wpda_data_backup = new WPDA_Data_Export(); |
| 165 |
$this->loader->add_action( 'wpda_data_backup', $wpda_data_backup, 'wpda_data_backup' ); |
| 166 |
|
| 167 |
} |
| 168 |
|
| 169 |
/** |
| 170 |
* Add public hooks |
| 171 |
* |
| 172 |
* Initiates {@see WP_Data_Access_Public} (public functionality), {@see WPDA_Data_Tables} (ajax call to support |
| 173 |
* server side jQuery DataTables functionality) and {@see WPDA_Dictionary_Lists} (table and column list for tables |
| 174 |
* to which access is granted to the front-end to support the shortcode wizard). Adds the appropriate actions to |
| 175 |
* the loader. |
| 176 |
* |
| 177 |
* @since 1.0.0 |
| 178 |
* |
| 179 |
* @see WP_Data_Access_Public |
| 180 |
* @see WPDA_Data_Tables |
| 181 |
* @see WPDA_Dictionary_Lists |
| 182 |
*/ |
| 183 |
private function define_public_hooks() { |
| 184 |
|
| 185 |
$plugin_public = new WP_Data_Access_Public(); |
| 186 |
|
| 187 |
// Shortcodes. |
| 188 |
$this->loader->add_action( 'init', $plugin_public, 'register_shortcodes' ); |
| 189 |
$this->loader->add_action( 'init', $plugin_public, 'wpdataaccess_shortcode_button_init' ); |
| 190 |
|
| 191 |
// Public scripts. |
| 192 |
$this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_styles' ); |
| 193 |
$this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_scripts' ); |
| 194 |
|
| 195 |
// Ajax calls. |
| 196 |
$plugin_datatables = new WPDA_Data_Tables(); |
| 197 |
$this->loader->add_action( 'wp_ajax_wpda_datatables', $plugin_datatables, 'get_data' ); |
| 198 |
$this->loader->add_action( 'wp_ajax_nopriv_wpda_datatables', $plugin_datatables, 'get_data' ); |
| 199 |
|
| 200 |
// Ajax calls to dynamically load listbox content (tables and columns). |
| 201 |
$plugin_tinymce_listboxes = new WPDA_Dictionary_Lists(); |
| 202 |
$this->loader->add_action( 'wp_ajax_wpda_tinymce_listbox_tables', $plugin_tinymce_listboxes, 'get_tables_tinymce_listbox' ); |
| 203 |
$this->loader->add_action( 'wp_ajax_nopriv_wpda_tinymce_listbox_tables', $plugin_tinymce_listboxes, 'get_tables_tinymce_listbox' ); |
| 204 |
$this->loader->add_action( 'wp_ajax_wpda_tinymce_listbox_columns', $plugin_tinymce_listboxes, 'get_columns_tinymce_listbox' ); |
| 205 |
$this->loader->add_action( 'wp_ajax_nopriv_wpda_tinymce_listbox_columns', $plugin_tinymce_listboxes, 'get_columns_tinymce_listbox' ); |
| 206 |
|
| 207 |
} |
| 208 |
|
| 209 |
/** |
| 210 |
* Start plugin loader |
| 211 |
* |
| 212 |
* @since 1.0.0 |
| 213 |
*/ |
| 214 |
public function run() { |
| 215 |
|
| 216 |
$this->loader->run(); |
| 217 |
|
| 218 |
} |
| 219 |
|
| 220 |
} |
| 221 |
|