Bootstrap.php
12.7 KB
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
<?php
namespace Codemanas\VczApi;
use Codemanas\VczApi\Blocks\Blocks;
if ( ! defined( 'ABSPATH' ) ) {
die( "Not Allowed Here !" ); // If this file is called directly, abort.
}
/**
* Ready Main Class
*
* @since 2.1.0
* @updated 3.6.0
* @author Deepen
*/
final class Bootstrap {
private static $_instance = null;
/**
* Create only one instance so that it may not Repeat
*
* @since 2.0.0
*/
public static function instance() {
if ( is_null( self::$_instance ) ) {
self::$_instance = new self();
}
return self::$_instance;
}
private $plugin_version = ZVC_PLUGIN_VERSION;
/**
* Constructor method for loading the components
*
* @since 2.0.0
* @author Deepen
*/
public function __construct() {
$this->autoloader();
$this->load_dependencies();
$this->init_api();
add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts_backend' ) );
add_action( 'init', array( $this, 'load_plugin_textdomain' ) );
//Block Themes Compat: register scripts on init - required as block themes fire the content before page render
add_action( 'init', [ $this, 'register_scripts' ] );
add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
add_filter( 'plugin_action_links', array( $this, 'action_link' ), 10, 2 );
add_action( 'after_setup_theme', array( $this, 'include_template_functions' ), 11 );
add_filter( 'wp_headers', [ $this, 'set_corp_headers' ], 10, 2 );
add_action( 'in_plugin_update_message-' . ZVC_PLUGIN_ABS_NAME, function ( $plugin_data ) {
$this->version_update_warning( ZVC_PLUGIN_VERSION, $plugin_data['new_version'] );
} );
}
/**
* Major Version Upgrade Notice
*
* @param $current_version
* @param $new_version
*/
public function version_update_warning( $current_version, $new_version ) {
$current_version_minor_part = explode( '.', $current_version )[1];
$new_version_minor_part = explode( '.', $new_version )[1];
if ( $current_version_minor_part === $new_version_minor_part ) {
return;
}
?>
<hr class="vczapi-major-update-warning__separator"/>
<div class="vczapi-major-update-warning">
<div class="vczapi-major-update-warning__icon">
<span class="dashicons dashicons-info-outline"></span>
</div>
<div class="vczapi-major-update-warning_wrapper">
<div class="vczapi-major-update-warning__title">
<?php esc_html_e( 'Heads up, Please backup before upgrade!', 'video-conferencing-with-zoom-api' ); ?>
</div>
<div class="vczapi-major-update-warning__message">
<?php
esc_html_e( 'The latest update includes some substantial changes across different areas of the plugin. We highly recommend you backup your site before upgrading, and make sure you first update in a staging environment', 'video-conferencing-with-zoom-api' );
?>
</div>
</div>
</div>
<?php
}
/**
* Add CORP headers for Zoom Meetings join via browser page
*
* @param $headers
* @param $wp
*
* @return mixed
*/
function set_corp_headers( $headers, $wp ) {
$type = filter_input( INPUT_GET, 'type' );
if ( isset( $wp->query_vars['post_type'] ) && $wp->query_vars['post_type'] == 'zoom-meetings' && ! empty( $type ) ) {
$headers['Cross-Origin-Embedder-Policy'] = 'require-corp';
$headers['Cross-Origin-Opener-Policy'] = 'same-origin';
}
return $headers;
}
public function autoloader() {
require_once ZVC_PLUGIN_DIR_PATH . 'vendor/autoload.php';
}
/**
* INitialize the hooks
*
* @since 2.0.0
* @modified 2.1.0
* @author Deepen Bajracharya
*/
protected function init_api() {
//Load the Credentials
zoom_conference()->zoom_api_key = get_option( 'zoom_api_key' );
zoom_conference()->zoom_api_secret = get_option( 'zoom_api_secret' );
}
/**
* @return void
*/
public function register_scripts( ) {
$minified = SCRIPT_DEBUG ? '' : '.min';
wp_register_style( 'video-conferencing-with-zoom-api', ZVC_PLUGIN_PUBLIC_ASSETS_URL . '/css/style' . $minified . '.css', false, $this->plugin_version );
$disable_moment_js = get_option( 'zoom_api_disable_moment_js' );
if ( empty( $disable_moment_js ) ) {
//Enqueue MomentJS
wp_register_script( 'video-conferencing-with-zoom-api-moment', ZVC_PLUGIN_VENDOR_ASSETS_URL . '/moment/moment.min.js', array( 'jquery' ), $this->plugin_version, true );
wp_register_script( 'video-conferencing-with-zoom-api-moment-locales', ZVC_PLUGIN_VENDOR_ASSETS_URL . '/moment/moment-with-locales.min.js', array(
'jquery',
'video-conferencing-with-zoom-api-moment',
), $this->plugin_version, true );
//Enqueue MomentJS Timezone
wp_register_script( 'video-conferencing-with-zoom-api-moment-timezone', ZVC_PLUGIN_VENDOR_ASSETS_URL . '/moment-timezone/moment-timezone-with-data-10-year-range.min.js', array( 'jquery' ), $this->plugin_version, true );
wp_register_script( 'video-conferencing-with-zoom-api', ZVC_PLUGIN_PUBLIC_ASSETS_URL . '/js/public' . $minified . '.js', array(
'jquery',
'video-conferencing-with-zoom-api-moment',
), $this->plugin_version, true );
}
}
/**
* Load Frontend Scriptsssssss
*
* @since 3.0.0
* @author Deepen Bajracharya
*/
function enqueue_scripts() {
if ( is_singular( 'zoom-meetings' ) ) {
wp_enqueue_style( 'video-conferencing-with-zoom-api' );
wp_enqueue_script( 'video-conferencing-with-zoom-api-moment' );
wp_enqueue_script( 'video-conferencing-with-zoom-api-moment-locales' );
wp_enqueue_script( 'video-conferencing-with-zoom-api-moment-timezone' );
wp_enqueue_script( 'video-conferencing-with-zoom-api' );
// Localize the script with new data
$date_format = get_option( 'zoom_api_date_time_format' );
if ( $date_format == 'custom' ) {
$date_format = get_option( 'zoom_api_custom_date_time_format' );
$date_format = vczapi_convertPHPToMomentFormat( $date_format );
}
$zoom_going_to_start = get_option( 'zoom_going_tostart_meeting_text' );
$zoom_ended = get_option( 'zoom_ended_meeting_text' );
$translation_array = apply_filters( 'vczapi_meeting_event_text', array(
'meeting_starting' => ! empty( $zoom_going_to_start ) ? $zoom_going_to_start : __( 'Click join button below to join the meeting now !', 'video-conferencing-with-zoom-api' ),
'meeting_ended' => ! empty( $zoom_ended ) ? $zoom_ended : __( 'This meeting has been ended by the host.', 'video-conferencing-with-zoom-api' ),
'date_format' => $date_format,
) );
wp_localize_script( 'video-conferencing-with-zoom-api', 'zvc_strings', $translation_array );
}
}
/**
* Include template files
*
* @since 3.7.1
*/
public function include_template_functions() {
require_once ZVC_PLUGIN_INCLUDES_PATH . '/template-functions.php';
}
/**
* Load the other class dependencies
*
* @since 2.0.0
* @modified 2.1.0
* @author Deepen Bajracharya
*/
protected function load_dependencies() {
//Include the Main Class
require_once ZVC_PLUGIN_INCLUDES_PATH . '/api/class-zvc-zoom-api-v2.php';
require_once ZVC_PLUGIN_INCLUDES_PATH . '/api/S2SOAuth.php';
//Loading Includes
require_once ZVC_PLUGIN_INCLUDES_PATH . '/helpers.php';
//AJAX CALLS SCRIPTS
require_once ZVC_PLUGIN_INCLUDES_PATH . '/admin/class-zvc-admin-ajax.php';
//Admin Classes
require_once ZVC_PLUGIN_INCLUDES_PATH . '/admin/class-zvc-admin-post-type.php';
require_once ZVC_PLUGIN_INCLUDES_PATH . '/admin/class-zvc-admin-users.php';
require_once ZVC_PLUGIN_INCLUDES_PATH . '/admin/class-zvc-admin-meetings.php';
require_once ZVC_PLUGIN_INCLUDES_PATH . '/admin/class-zvc-admin-webinars.php';
require_once ZVC_PLUGIN_INCLUDES_PATH . '/admin/class-zvc-admin-reports.php';
require_once ZVC_PLUGIN_INCLUDES_PATH . '/admin/class-zvc-admin-recordings.php';
require_once ZVC_PLUGIN_INCLUDES_PATH . '/admin/class-zvc-admin-settings.php';
require_once ZVC_PLUGIN_INCLUDES_PATH . '/admin/class-zvc-admin-addons.php';
require_once ZVC_PLUGIN_INCLUDES_PATH . '/admin/class-zvc-admin-sync.php';
require_once ZVC_PLUGIN_INCLUDES_PATH . '/admin/class-zvc-admin-setup-wizard.php';
//Timezone
Timezone::get_instance();
//Templates
require_once ZVC_PLUGIN_INCLUDES_PATH . '/template-hooks.php';
Filters::get_instance();
//Shortcode
Shortcodes::get_instance();
if ( did_action( 'elementor/loaded' ) ) {
require ZVC_PLUGIN_INCLUDES_PATH . '/Elementor/Elementor.php';
}
Blocks::get_instance();
}
/**
* Enqueuing Scripts and Styles for Admin
*
* @param $hook
*
* @since 2.0.0
* @modified 2.1.0
* @author Deepen Bajracharya
*/
public function enqueue_scripts_backend( $hook ) {
$pg = 'zoom-meetings_page_zoom-';
$screen = get_current_screen();
//Vendors
if ( $hook === $pg . "video-conferencing-addons" || $hook === $pg . "video-conferencing-reports" || $hook === $pg . "video-conferencing-recordings" || $hook === $pg . "video-conferencing-list-users" || $hook === $pg . "video-conferencing" || $hook === $pg . "video-conferencing-add-meeting" || $hook === $pg . "video-conferencing-webinars" || $hook === $pg . "video-conferencing-webinars-add" || $screen->id === "zoom-meetings" || $hook === $pg . "video-conferencing-host-id-assign" || $hook === $pg . "video-conferencing-sync" || $hook === $pg . "video-conferencing-add-users" ) {
wp_enqueue_style( 'video-conferencing-with-zoom-api-timepicker', ZVC_PLUGIN_VENDOR_ASSETS_URL . '/dtimepicker/jquery.datetimepicker.min.css', false, $this->plugin_version );
wp_enqueue_style( 'video-conferencing-with-zoom-api-select2', ZVC_PLUGIN_VENDOR_ASSETS_URL . '/select2/css/select2.min.css', false, $this->plugin_version );
wp_enqueue_style( 'video-conferencing-with-zoom-api-datable', ZVC_PLUGIN_VENDOR_ASSETS_URL . '/datatable/jquery.dataTables.min.css', false, $this->plugin_version );
}
wp_register_script( 'video-conferencing-with-zoom-api-select2-js', ZVC_PLUGIN_VENDOR_ASSETS_URL . '/select2/js/select2.min.js', array( 'jquery' ), $this->plugin_version, true );
wp_register_script( 'video-conferencing-with-zoom-api-timepicker-js', ZVC_PLUGIN_VENDOR_ASSETS_URL . '/dtimepicker/jquery.datetimepicker.full.js', array( 'jquery' ), $this->plugin_version, true );
wp_register_script( 'video-conferencing-with-zoom-api-datable-js', ZVC_PLUGIN_VENDOR_ASSETS_URL . '/datatable/jquery.dataTables.min.js', array( 'jquery' ), $this->plugin_version, true );
//Plugin Scripts
wp_enqueue_style( 'video-conferencing-with-zoom-api', ZVC_PLUGIN_ADMIN_ASSETS_URL . '/css/style.min.css', false, $this->plugin_version );
wp_register_script( 'video-conferencing-with-zoom-api-js', ZVC_PLUGIN_ADMIN_ASSETS_URL . '/js/script.min.js', array(
'jquery',
'video-conferencing-with-zoom-api-select2-js',
'video-conferencing-with-zoom-api-timepicker-js',
'video-conferencing-with-zoom-api-datable-js',
'underscore',
), $this->plugin_version, true );
wp_localize_script( 'video-conferencing-with-zoom-api-js', 'zvc_ajax', array(
'ajaxurl' => admin_url( 'admin-ajax.php' ),
'zvc_security' => wp_create_nonce( "_nonce_zvc_security" ),
'lang' => array(
'confirm_end' => __( "Are you sure you want to end this meeting ? Users won't be able to join this meeting shown from the shortcode.", "video-conferencing-with-zoom-api" ),
'host_id_search' => __( "Add a valid Host ID or Email address.", "video-conferencing-with-zoom-api" ),
),
) );
}
/**
* Load Plugin Domain Text here
*
* @since 2.0.0
* @author Deepen
*/
public function load_plugin_textdomain() {
load_plugin_textdomain( 'video-conferencing-with-zoom-api', false, ZVC_PLUGIN_LANGUAGE_PATH );
}
/**
* Fire on Activation
*
* @since 1.0.0
* @author Deepen
*/
public static function activate() {
require_once ZVC_PLUGIN_INCLUDES_PATH . '/admin/class-zvc-admin-post-type.php';
$post_type = \Zoom_Video_Conferencing_Admin_PostType::get_instance();
$post_type->register();
//Flush User Cache
update_option( '_zvc_user_lists', '' );
update_option( '_zvc_user_lists_expiry_time', '' );
//Flush Permalinks
flush_rewrite_rules();
}
/**
* Deactivating the plugin
*/
public static function deactivate() {
//Flush User Cache
update_option( '_zvc_user_lists', '' );
update_option( '_zvc_user_lists_expiry_time', '' );
flush_rewrite_rules();
}
/**
* Add Action links to plugins page.
*
* @param $actions
* @param $plugin_file
*
* @return array
*/
public function action_link( $actions, $plugin_file ) {
static $plugin;
if ( ! isset( $plugin ) ) {
$plugin = ZVC_PLUGIN_ABS_NAME;
}
if ( $plugin == $plugin_file ) {
$settings = array( 'settings' => '<a href="' . admin_url( 'edit.php?post_type=zoom-meetings&page=zoom-video-conferencing-settings' ) . '">' . __( 'Settings', 'video-conferencing-with-zoom-api' ) . '</a>' );
$actions = array_merge( $settings, $actions );
}
return $actions;
}
}