Timezone.php
3.25 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
<?php
namespace Codemanas\VczApi;
// If this file is called directly, abort.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* Timezones AJAX handler
*
* @since 3.1.2
* @author Deepen
*/
class Timezone {
private static $_instance = null;
/**
* Create only one instance so that it may not Repeat
*
* @since 2.0.0
*/
public static function get_instance() {
if ( is_null( self::$_instance ) ) {
self::$_instance = new self();
}
return self::$_instance;
}
public function __construct() {
add_action( 'wp_ajax_set_timezone', array( $this, 'set_timezone' ) );
add_action( 'wp_ajax_nopriv_set_timezone', array( $this, 'set_timezone' ) );
}
/**
* See timezone and show links accordingly
*
* @throws \Exception
* @author Deepen Bajracharya
* @since 3.1.2
*/
public function set_timezone() {
$user_timezone = filter_input( INPUT_POST, 'user_timezone' );
$start_date = filter_input( INPUT_POST, 'start_date' );
$type = filter_input( INPUT_POST, 'type' );
$meeting_type = filter_input( INPUT_POST, 'meeting_type' );
$start_time = vczapi_dateConverter( $start_date, $user_timezone, false );
$current_user_time = vczapi_dateConverter( 'now -1 hour', $user_timezone, false );
$show_defined_post = apply_filters( 'vczapi_show_join_links_specific_postID', array() );
$past_join_links = get_option( 'zoom_past_join_links' );
$post_id = absint( filter_input( INPUT_POST, 'post_id' ) );
if ( $start_time >= $current_user_time || $past_join_links || in_array( $post_id, $show_defined_post ) || $meeting_type == 3 || $meeting_type == 6 ) {
if ( $type === "page" ) {
wp_send_json_success( $this->output_join_links_page( $post_id ) );
} else {
$join_uri = filter_input( INPUT_POST, 'join_uri' );
$browser_url = filter_input( INPUT_POST, 'browser_url' );
wp_send_json_success( $this->output_join_links_shortcodes( $join_uri, $browser_url ) );
}
} else {
wp_send_json_error( apply_filters( 'vczoom_shortcode_link_not_valid_anymore', __( 'This meeting is no longer valid and cannot be joined !', 'video-conferencing-with-zoom-api' ) ) );
}
wp_die();
}
/**
* Show join links from here for pages
*
* @param $post_id
*
* @return false|string
* @author Deepen Bajracharya
*
*/
private function output_join_links_page( $post_id ) {
unset( $GLOBALS['zoom'] );
unset( $GLOBALS['vanity_enabled'] );
$GLOBALS['zoom'] = get_post_meta( $post_id, '_meeting_zoom_details', true );
$GLOBALS['zoom']->post_id = $post_id;
$GLOBALS['vanity_enabled'] = get_option( 'zoom_vanity_url' );
ob_start(); //Init the output buffering
$template = vczapi_get_template( 'fragments/join-links.php', false );
if ( ! empty( $template ) ) {
include $template;
}
$content = ob_get_clean(); //Get the buffer and erase it
return $content;
}
/**
* Output join links for shortcode
*
* @param $join_uri
* @param $browser_url
*
* @return false|string
* @deprecated 3.3.1
*/
private function output_join_links_shortcodes( $join_uri, $browser_url ) {
ob_start(); //Init the output buffering
$template = vczapi_get_template( 'shortcode/join-links.php', false );
include $template;
$content = ob_get_clean(); //Get the buffer and erase it
return $content;
}
}