-
Notifications
You must be signed in to change notification settings - Fork 0
/
stackonet-repair-services.php
executable file
·418 lines (352 loc) · 13 KB
/
stackonet-repair-services.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
<?php
/**
* Plugin Name: Stackonet Toolkit for Phone Repairs ASAP
* Description: Stackonet Toolkit for Phone Repairs ASAP
* Version: 1.1.21
* Author: Stackonet Services (Pvt.) Ltd.
* Author URI: http://www.stackonet.com/
* Requires at least: 4.9
* Tested up to: 5.2
* Text Domain: stackonet-repair-services
*
* WC requires at least: 3.0
* WC tested up to: 3.6
*/
defined( 'ABSPATH' ) || exit;
final class Stackonet_Repair_Services {
/**
* The instance of the class
*
* @var self
*/
private static $instance;
/**
* Plugin name slug
*
* @var string
*/
private $plugin_name = 'stackonet-repair-services';
/**
* Plugin version
*
* @var string
*/
private $version = '1.1.21-b2';
/**
* Holds various class instances
*
* @var array
*/
private $container = array();
/**
* Minimum PHP version required
*
* @var string
*/
private $min_php = '5.3';
/**
* Ensures only one instance of the class is loaded or can be loaded.
*
* @return self
* @throws Exception
*/
public static function init() {
if ( is_null( self::$instance ) ) {
self::$instance = new self();
// define constants
self::$instance->define_constants();
// Check if PHP version is supported for our plugin
if ( ! self::$instance->is_supported_php() ) {
register_activation_hook( __FILE__, array( self::$instance, 'auto_deactivate' ) );
add_action( 'admin_notices', array( self::$instance, 'php_version_notice' ) );
return self::$instance;
}
// Include Classes
self::$instance->include_classes();
add_filter( 'cron_schedules', [ self::$instance, 'custom_cron_schedules' ] );
// initialize the classes
add_action( 'plugins_loaded', array( self::$instance, 'init_classes' ) );
// Load plugin textdomain
add_action( 'plugins_loaded', array( self::$instance, 'load_plugin_textdomain' ) );
add_action( 'phone_repairs_asap_activation', [ self::$instance, 'add_custom_role' ] );
add_action( 'dialog_contact_form/actions', [ self::$instance, 'add_action' ] );
// Register plugin activation activity
register_activation_hook( __FILE__, array( self::$instance, 'activation' ) );
}
return self::$instance;
}
/**
* Define plugin constants
*/
private function define_constants() {
define( 'STACKONET_REPAIR_SERVICES', $this->plugin_name );
define( 'STACKONET_REPAIR_SERVICES_VERSION', $this->version );
define( 'STACKONET_REPAIR_SERVICES_FILE', __FILE__ );
define( 'STACKONET_REPAIR_SERVICES_PATH', dirname( STACKONET_REPAIR_SERVICES_FILE ) );
define( 'STACKONET_REPAIR_SERVICES_INCLUDES', STACKONET_REPAIR_SERVICES_PATH . '/includes' );
define( 'STACKONET_REPAIR_SERVICES_URL', plugins_url( '', STACKONET_REPAIR_SERVICES_FILE ) );
define( 'STACKONET_REPAIR_SERVICES_ASSETS', STACKONET_REPAIR_SERVICES_URL . '/assets' );
}
/**
* Include classes
*
* @throws Exception
*/
private function include_classes() {
spl_autoload_register( function ( $className ) {
if ( class_exists( $className ) ) {
return;
}
// project-specific namespace prefix
$prefix = 'Stackonet\\';
// base directory for the namespace prefix
$base_dir = STACKONET_REPAIR_SERVICES_INCLUDES . DIRECTORY_SEPARATOR;
// does the class use the namespace prefix?
$len = strlen( $prefix );
if ( strncmp( $prefix, $className, $len ) !== 0 ) {
// no, move to the next registered autoloader
return;
}
// get the relative class name
$relative_class = substr( $className, $len );
// replace the namespace prefix with the base directory, replace namespace
// separators with directory separators in the relative class name, append
// with .php
$file = $base_dir . str_replace( '\\', '/', $relative_class ) . '.php';
// if the file exists, require it
if ( file_exists( $file ) ) {
require_once $file;
}
} );
}
/**
* Instantiate the required classes
*
* @return void
* @throws Exception
*/
public function init_classes() {
// Load autoload file
if ( file_exists( STACKONET_REPAIR_SERVICES_PATH . '/vendor/autoload.php' ) ) {
include_once STACKONET_REPAIR_SERVICES_PATH . '/vendor/autoload.php';
}
$this->container['assets'] = Stackonet\Assets::init();
$this->container['twilio'] = Stackonet\Integrations\Twilio::init();
$this->container['woocommerce'] = Stackonet\Integrations\WooCommerce::init();
$this->container['mercantile-theme'] = Stackonet\Integrations\MercantileTheme::init();
$this->container['reschedule'] = new Stackonet\Models\Reschedule();
$this->container['bulk_sms'] = new Stackonet\Sms\BulkSms();
$this->container['order_reminder'] = Stackonet\Models\OrderReminder::init();
$this->container['my_account'] = Stackonet\Modules\MyAccount\MyAccount::init();
$this->container['support_ticket'] = Stackonet\Modules\SupportTicket\SupportTicketManager::init();
$this->container['firebase_sync'] = Stackonet\Integrations\FirebaseDatabase::init();
$this->container['support_ticket_v3'] = Stackonet\Integrations\StackonetSupportTicket\V3\StackonetSupportTicket::init();
$this->container['ca_to_ticket'] = Stackonet\Modules\SupportTicket\CheckoutAnalysisToSupportTicket::init();
$this->container['page_template'] = Stackonet\PageTemplater::init();
if ( $this->is_request( 'admin' ) ) {
$this->container['reschedule-date-time'] = Stackonet\Admin\RescheduleDateTime::init();
$this->container['admin'] = Stackonet\Admin\Admin::init();
}
if ( $this->is_request( 'frontend' ) ) {
$this->container['frontend'] = Stackonet\Frontend::init();
$this->container['rest-testimonial'] = Stackonet\REST\TestimonialController::init();
$this->container['rest-unsupported-area'] = Stackonet\REST\UnsupportedAreaController::init();
$this->container['rest-reschedule-order'] = Stackonet\REST\OrderRescheduleController::init();
$this->container['rest-devices'] = Stackonet\REST\DeviceController::init();
$this->container['rest-issues'] = Stackonet\REST\IssueController::init();
$this->container['rest-phones'] = Stackonet\REST\PhoneController::init();
$this->container['rest-track-status'] = Stackonet\REST\TrackStatusController::init();
$this->container['rest-survey'] = Stackonet\REST\SurveyController::init();
$this->container['rest-logo'] = Stackonet\REST\LogoController::init();
$this->container['rest-technician'] = Stackonet\REST\TechnicianController::init();
$this->container['rest-appointment'] = Stackonet\REST\SpotAppointmentController::init();
$this->container['rest-checkout-analysis'] = Stackonet\REST\CheckoutAnalysisController::init();
$this->container['rest-login'] = Stackonet\REST\LoginController::init();
$this->container['rest-carrier-store'] = Stackonet\REST\CarrierStoreController::init();
$this->container['rest-sms'] = Stackonet\REST\SmsController::init();
$this->container['rest-calendar'] = Stackonet\REST\CalendarController::init();
$this->container['rest-checkout'] = Stackonet\REST\CheckoutController::init();
$this->container['rest-order'] = Stackonet\REST\OrderController::init();
$this->container['rest-map'] = Stackonet\REST\MapController::init();
$this->container['trackable-object'] = Stackonet\REST\TrackableObjectController::init();
$this->container['trackable-object-log'] = Stackonet\REST\TrackableObjectLogController::init();
$this->container['page-payment'] = Stackonet\Frontend\PaymentPage::init();
$this->container['page-dashboard'] = Stackonet\Frontend\DashboardPage::init();
$this->container['page-rentcenter'] = Stackonet\Frontend\RentCenter::init();
}
if ( $this->is_request( 'ajax' ) ) {
$this->container['ajax'] = Stackonet\Ajax::init();
}
}
/**
* @param array $schedules
*
* @return array
*/
public function custom_cron_schedules( $schedules ) {
$schedules ['every_minute'] = array( 'interval' => 60, 'display' => 'Every minute', );
return $schedules;
}
/**
* Async reschedule request
*
* @return Stackonet\Models\Reschedule
*/
public function async_reschedule() {
return $this->container['reschedule'];
}
/**
* Async reschedule request
*
* @return Stackonet\Models\OrderReminder
*/
public function order_reminder() {
return $this->container['order_reminder'];
}
/**
* Async bulk request request
*
* @return Stackonet\Sms\BulkSms
*/
public function bulk_sms() {
return $this->container['bulk_sms'];
}
/**
* Create tables on plugin activation
* @throws Exception
*/
public function activation() {
( new Stackonet\Models\UnsupportedArea )->create_table();
( new Stackonet\Models\Testimonial )->create_table();
( new Stackonet\Models\Phone )->create_table();
( new Stackonet\Models\Survey )->create_table();
( new Stackonet\Models\Technician )->create_table();
( new Stackonet\Models\Appointment )->create_table();
( new Stackonet\Models\CheckoutAnalysis )->create_table();
( new Stackonet\Modules\SupportTicket\SupportTicket )->create_table();
( new Stackonet\Models\CarrierStore )->create_table();
( new Stackonet\Models\Map )->create_table();
( new Stackonet\Models\TrackableObject )->create_table();
( new Stackonet\Models\TrackableObjectLog )->create_table();
( new Stackonet\Models\TrackableObjectTimeline )->create_table();
( new Stackonet\Models\GooglePlace() )->create_table();
( new Stackonet\Models\GoogleNearbyPlace() )->create_table();
do_action( 'phone_repairs_asap_activation' );
}
/**
* Add custom role
*/
public function add_custom_role() {
Stackonet\RoleAndCapability::activation();
}
/**
* Add our custom action to action manager
*
* @param DialogContactForm\Collections\Actions $actions
*/
public function add_action( $actions ) {
$actions->set( 'support_ticket', Stackonet\Modules\SupportTicket\ContactFormToSupportTicket::class );
}
/**
* Load plugin textdomain
*/
public function load_plugin_textdomain() {
// Traditional WordPress plugin locale filter
$locale = apply_filters( 'plugin_locale', get_locale(), $this->plugin_name );
$mofile = sprintf( '%1$s-%2$s.mo', $this->plugin_name, $locale );
// Setup paths to current locale file
$mofile_global = WP_LANG_DIR . '/stackonet-repair-services/' . $mofile;
// Look in global /wp-content/languages/dialog-contact-form folder
if ( file_exists( $mofile_global ) ) {
load_textdomain( $this->plugin_name, $mofile_global );
}
}
/**
* Show notice about PHP version
*
* @return void
*/
public function php_version_notice() {
if ( $this->is_supported_php() || ! current_user_can( 'manage_options' ) ) {
return;
}
$error = __( 'Your installed PHP Version is: ', 'vue-wp-starter' ) . PHP_VERSION . '. ';
$error .= sprintf( __( 'The Dialog Contact Form plugin requires PHP version %s or greater.',
'vue-wp-starter' ), $this->min_php );
?>
<div class="error">
<p><?php printf( $error ); ?></p>
</div>
<?php
}
/**
* Bail out if the php version is lower than
*
* @return void
*/
public function auto_deactivate() {
if ( $this->is_supported_php() ) {
return;
}
deactivate_plugins( plugin_basename( __FILE__ ) );
$error = '<h1>' . __( 'An Error Occurred', 'vue-wp-starter' ) . '</h1>';
$error .= '<h2>' . __( 'Your installed PHP Version is: ', 'vue-wp-starter' ) . PHP_VERSION . '</h2>';
$error .= '<p>' . sprintf( __( 'The Dialog Contact Form plugin requires PHP version %s or greater',
'vue-wp-starter' ), $this->min_php ) . '</p>';
$error .= '<p>' . sprintf( __( 'The version of your PHP is %s unsupported and old %s. ',
'vue-wp-starter' ),
'<a href="http://php.net/supported-versions.php" target="_blank"><strong>',
'</strong></a>'
);
$error .= __( 'You should update your PHP software or contact your host regarding this matter.',
'vue-wp-starter' ) . '</p>';
wp_die( $error, __( 'Plugin Activation Error', 'vue-wp-starter' ), array( 'back_link' => true ) );
}
/**
* What type of request is this?
*
* @param string $type admin, ajax, rest, cron or frontend.
*
* @return bool
*/
private function is_request( $type ) {
switch ( $type ) {
case 'admin' :
return is_admin();
case 'ajax' :
return defined( 'DOING_AJAX' );
case 'rest' :
return defined( 'REST_REQUEST' );
case 'cron' :
return defined( 'DOING_CRON' );
case 'frontend' :
return ( ! is_admin() || defined( 'DOING_AJAX' ) ) && ! defined( 'DOING_CRON' );
}
return false;
}
/**
* Check if the PHP version is supported
*
* @param null $min_php
*
* @return bool
*/
private function is_supported_php( $min_php = null ) {
$min_php = $min_php ? $min_php : $this->min_php;
if ( version_compare( PHP_VERSION, $min_php, '<=' ) ) {
return false;
}
return true;
}
}
/**
* Begins execution of the plugin.
*
* Since everything within the plugin is registered via hooks,
* then kicking off the plugin from this point in the file does
* not affect the page life cycle.
*/
function stackonet_repair_services() {
return Stackonet_Repair_Services::init();
}
stackonet_repair_services();