PluginProbe
Easy Appointments / trunk
Easy Appointments vtrunk
4.0.2.1 4.0.2 4.0.1 3.12.27 3.12.28 3.12.29 4.0 3.12.26 3.12.25 trunk 2.0.0 2.1.0 2.1.1 2.1.3 2.1.4 2.10.0 2.2.0 2.2.3 2.2.4 2.3.0 2.3.1 2.3.11 2.3.2 2.3.3 2.3.4 All 79 releases
easy-appointments / main.php

main.php in Easy Appointments trunk, at main.php

391 lines 12.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Plugin Name: Easy Appointments
5 * Plugin URI: https://easy-appointments.com/
6 * Description: Simple and easy to use management system for Appointments and Bookings
7 * Version: 4.0.2.1
8 * Requires PHP: 5.3
9 * Author: Nikola Loncar
10 * Author URI: https://easy-appointments.com/
11 * License: GPL v2 or later
12 * Text Domain: easy-appointments
13 * Domain Path: /languages
14 */
15
16
17 // If this file is called directly, abort.
18 if (!defined('WPINC')) {
19 die;
20 }
21
22 /**
23 * Currently plugin version.
24 */
25 define( 'EASY_APPOINTMENTS_VERSION', '4.0.2.1' );
26
27 // path for source files
28 // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedConstantFound
29 define('EA_SRC_DIR', dirname(__FILE__) . '/src/');
30
31 // path for JS files
32 // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedConstantFound
33 define('EA_JS_DIR', dirname(__FILE__) . '/js/');
34
35 // url for EA plugin dir
36 // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedConstantFound
37 define('EA_PLUGIN_URL', plugins_url('', __FILE__) . '/');
38 // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedConstantFound
39 define('EA_PLUGIN_DIR', plugin_dir_path( __FILE__));
40
41 // Register the autoloader that loads everything except the Google namespace.
42 if (version_compare(PHP_VERSION, '5.3', '<')) {
43 if (!function_exists('easy_ea_autoload')) {
44 function easy_ea_autoload($class)
45 {
46 global $easy_ea_class_location;
47
48 if (empty($easy_ea_class_location)) {
49 $easy_ea_class_location = include dirname(__FILE__) . '/vendor/composer/autoload_classmap.php';
50 }
51
52 if (is_array($easy_ea_class_location) && array_key_exists($class, $easy_ea_class_location)) {
53 require_once $easy_ea_class_location[$class];
54 }
55 }
56 }
57 // register autoloader
58 spl_autoload_register('easy_ea_autoload');
59 } else {
60 // PHP 5.3.0+ use composer auto loader
61 require_once dirname(__FILE__) . '/vendor/autoload.php';
62 }
63
64 require_once dirname(__FILE__) . '/ea-blocks/ea-blocks.php';
65 require_once dirname(__FILE__) . '/src/webhook.php';
66 require_once dirname(__FILE__) . '/new-ui/class-ea-appointments-new-ui.php';
67 require EA_PLUGIN_DIR . 'new-ui/class-ea-locations-new-ui.php';
68 require EA_PLUGIN_DIR . 'new-ui/class-ea-services-new-ui.php';
69 require EA_PLUGIN_DIR . 'new-ui/class-ea-workers-new-ui.php';
70 require EA_PLUGIN_DIR . 'new-ui/class-ea-connections-new-ui.php';
71 require EA_PLUGIN_DIR . 'new-ui/class-ea-publish-new-ui.php';
72 require EA_PLUGIN_DIR . 'new-ui/class-ea-customers-new-ui.php';
73 require_once dirname(__FILE__) . '/new-ui/class-ea-settings-new-ui.php';
74 require EA_PLUGIN_DIR . 'new-ui/class-ea-vacation-new-ui.php';
75 require EA_PLUGIN_DIR . 'new-ui/class-ea-help-support-new-ui.php';
76 require EA_PLUGIN_DIR . 'new-ui/class-ea-ui-mode-switcher.php';
77
78 /**
79 * Entry point
80 */
81 class EasyAppointment
82 {
83
84 /**
85 * DI Container
86 * @var tad_DI52_Container
87 */
88 protected $container;
89
90 function __construct()
91 {
92 // empty for now
93 }
94
95 /**
96 * Set all hooks and action callbacks
97 */
98 public function init()
99 {
100 $this->init_container();
101
102 // on register hook
103 register_activation_hook(__FILE__, array($this, 'install'));
104
105 // register uninstall hook
106 register_uninstall_hook(__FILE__, array('EasyAppointment', 'uninstall'));
107
108 // register deactivation hook
109 register_deactivation_hook(__FILE__, array('EasyAppointment', 'remove_scheduled_event'));
110
111 // plugin loaded
112 add_action('plugins_loaded', array($this, 'update'));
113
114 // cron
115 add_action('easyapp_hourly_event', array($this, 'delete_reservations'));
116 // daily expire appointments cron
117 // add_action('ea_daily_expire_appointments', array($this, 'expire_old_appointments'));
118
119 add_action('ea_gdpr_auto_delete', array($this, 'delete_old_data'));
120
121 // we want to check if it is link from EA mail
122 add_action('init', array($this, 'url_delete_reservations'));
123
124 add_action('rest_api_init', array($this, 'register_api'));
125
126 // init action for mails
127 /** @var EAMail $mail */
128 $mail = $this->container['mail'];
129 $mail->init();
130
131
132 // admin panel split loading for optimization
133 if (is_admin()) {
134 /** @var EAAdminPanel $admin */
135 $admin = $this->container['admin_panel'];
136 $admin->init();
137
138 $ui_switcher = new EA_UI_Switcher();
139 $ui_switcher->init();
140 } else {
141 /** @var Easy_EA_Frontend $frontend */
142 $frontend = $this->container['frontend'];
143 $frontend->init();
144
145 /** @var EasyEAFullCalendar $full_calendar */
146 $full_calendar = $this->container['fullcalendar']; // not ready yet
147 $full_calendar->init();
148
149 /** @var EasyEAUserFieldMapper $field_mapper */
150 $field_mapper = $this->container['user_field_mapper'];
151 $field_mapper->init();
152 }
153
154 // ajax hooks
155 /** @var EAAjax $ajax */
156 $ajax = $this->container['ajax'];
157 $ajax->init();
158
159 $this->install();
160 }
161
162 /**
163 * Init DI Container, set all services as globals
164 */
165 public function init_container()
166 {
167 global $wpdb;
168
169 $this->container = new tad_EA52_Container();
170 $this->container['wpdb'] = $wpdb;
171 $this->container['utils'] = new EAUtils();
172
173 $this->container['options'] = function($container) {
174 return new EAOptions($container['wpdb']);
175 };
176
177 $this->container['table_columns'] = function ($container) {
178 return new EATableColumns();
179 };
180
181 $this->container['db_models'] = function ($container) {
182 return new EADBModels( $container['wpdb'], $container['table_columns'], $container['options']);
183 };
184
185 $this->container['slots_logic'] = function ($container) {
186 return new EASlotsLogic($container['wpdb'], $container['options']);
187 };
188
189 $this->container['datetime'] = function ($container) {
190 return new EADateTime();
191 };
192
193 $this->container['logic'] = function ($container) {
194 return new EALogic($container['wpdb'], $container['db_models'], $container['options'], $container['slots_logic']);
195 };
196
197 $this->container['install_tools'] = function ($container) {
198 return new EAInstallTools( $container['wpdb'], $container['db_models'], $container['options']);
199 };
200
201 $this->container['report'] = function ($container) {
202 return new EAReport($container['logic'], $container['options']);
203 };
204
205 $this->container['admin_panel'] = function ($container) {
206 return new EAAdminPanel($container['options'], $container['logic'], $container['db_models'], $container['datetime'] );
207 };
208
209 $this->container['frontend'] = function ($container) {
210 return new Easy_EA_Frontend($container['db_models'], $container['options'], $container['datetime'], $container['utils']);
211 };
212
213 $this->container['fullcalendar'] = function ($container) {
214 return new EasyEAFullCalendar($container['db_models'], $container['logic'], $container['options'], $container['datetime']);
215 };
216
217 $this->container['ajax'] = function ($container) {
218 return new EAAjax($container['db_models'], $container['options'], $container['mail'], $container['logic'], $container['report']);
219 };
220
221 $this->container['mail'] = function ($container) {
222 return new EAMail($container['wpdb'], $container['db_models'], $container['logic'], $container['options'], $container['utils']);
223 };
224
225 $this->container['user_field_mapper'] = function ($container) {
226 return new EasyEAUserFieldMapper();
227 };
228 }
229
230 /**
231 * @return tad_EA52_Container
232 */
233 public function get_container()
234 {
235 return $this->container;
236 }
237
238 /**
239 * Installation of DB
240 */
241 public function install()
242 {
243 /** @var EAInstallTools $install */
244 $install = $this->container['install_tools'];
245
246 // skip update if db version are the same
247 if ($install->easy_app_db_version !== get_option('easy_app_db_version')) {
248 $install->init_db();
249 $install->init_data();
250 }
251 if ( wp_next_scheduled( 'easyapp_hourly_event' ) === false ) {
252 wp_schedule_event(time(), 'hourly', 'easyapp_hourly_event');
253 }
254 if (wp_next_scheduled('ea_daily_expire_appointments') === true) {
255 wp_clear_scheduled_hook('ea_daily_expire_appointments');
256 // wp_schedule_event(strtotime('00:05:00'), 'daily', 'ea_daily_expire_appointments');
257 }
258 }
259
260 /**
261 * Remove tables of Appointments plugin
262 */
263 public static function uninstall()
264 {
265 $uninstall = new EasyEAUninstallTools();
266 global $wpdb;
267 $options = new EAOptions($wpdb);
268 $all_options = $options->get_options();
269 if (isset($all_options['delete_data_on_uninstall']) && $all_options['delete_data_on_uninstall'] == '1') {
270 $uninstall->drop_db();
271 $uninstall->delete_db_version();
272 $uninstall->clear_cron();
273 }
274 }
275
276 /**
277 * Remove cron action
278 */
279 public static function remove_scheduled_event()
280 {
281 wp_clear_scheduled_hook('easyapp_hourly_event');
282 wp_clear_scheduled_hook('ea_daily_expire_appointments');
283 }
284
285 public function update()
286 {
287 // register domain
288 $this->register_text_domain();
289
290 // update database
291 /** @var EAInstallTools $tools */
292 $tools = $this->container['install_tools'];
293 $tools->update();
294 }
295
296 public function register_text_domain()
297 {
298 // load_plugin_textdomain(
299 // 'easy-appointments',
300 // false,
301 // dirname( plugin_basename( __FILE__ ) ) . '/languages/'
302 // );
303
304 }
305
306
307 /**
308 * Register all api endpoints
309 */
310 public function register_api()
311 {
312 // register API endpoints
313 new EasyEAMainApi($this->get_container()); // not ready yet
314 }
315
316 /**
317 * Reserved for cron execution, url for deleting reservations
318 */
319 public function url_delete_reservations()
320 {
321
322 $whitelist = array(
323 '127.0.0.1',
324 '::1'
325 );
326 // phpcs:ignore WordPress.Security.NonceVerification.Recommended
327 if (!empty($_GET['_ea-action']) && $_GET['_ea-action'] == 'clear_reservations') {
328
329 // only do this when is called from localhost
330 // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotValidated
331 if (in_array($_SERVER['REMOTE_ADDR'], $whitelist)) {
332 $this->delete_reservations();
333 die;
334 }
335 }
336 }
337
338 /**
339 * Delete old reservations that are not complete
340 */
341 public function delete_reservations()
342 {
343 /** @var EADBModels $models */
344 $models = $this->container['db_models'];
345 $models->delete_reservations();
346 }
347
348 public function delete_old_data()
349 {
350 $gdpr = new EasyEAGDPRActions($this->container['db_models']);
351 $gdpr->clear_old_custom_data();
352 }
353
354 /**
355 * Mark past unconfirmed appointments as expired
356 */
357 public function expire_old_appointments()
358 {
359 global $wpdb;
360
361 $table = $wpdb->prefix . 'ea_appointments';
362
363 $sql = "
364 UPDATE {$table}
365 SET status = %s
366 WHERE status != %s
367 AND end_date < %s
368 ";
369 // phpcs:ignore PluginCheck.Security.DirectDB.UnescapedDBParameter, WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
370 $wpdb->query(
371 $wpdb->prepare(
372 // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
373 $sql,
374 'expired',
375 'confirmed',
376 current_time('mysql')
377 )
378 );
379 }
380
381 }
382
383 /**
384 * INIT EASY APPOINTMENTS
385 */
386 $easy_ea_app = new EasyAppointment;
387 $easy_ea_app->init();
388 /**
389 * END
390 */
391