| 1 |
<?php |
| 2 |
/** |
| 3 |
* Shortcode class |
| 4 |
* |
| 5 |
* @package Timetics |
| 6 |
*/ |
| 7 |
|
| 8 |
namespace Timetics\Core\Frontend; |
| 9 |
|
| 10 |
defined( 'ABSPATH' ) || exit; |
| 11 |
|
| 12 |
use Timetics\Utils\Singleton; |
| 13 |
use Timetics; |
| 14 |
|
| 15 |
/** |
| 16 |
* Class Shortcode |
| 17 |
*/ |
| 18 |
class Shortcode { |
| 19 |
use Singleton; |
| 20 |
|
| 21 |
/** |
| 22 |
* Initialize the shortcode class |
| 23 |
* |
| 24 |
* @return void |
| 25 |
*/ |
| 26 |
public function init() { |
| 27 |
// [timetics-booking-form id=''] |
| 28 |
add_shortcode( 'timetics-booking-form', [ $this, 'booking_form' ] ); |
| 29 |
|
| 30 |
// [timetics-meeting-list limit=''] |
| 31 |
add_shortcode( 'timetics-meeting-list', [ $this, 'meeting_list' ] ); |
| 32 |
|
| 33 |
// [timetics-user-dashboard] |
| 34 |
add_shortcode( 'timetics-user-dashboard', [ $this, 'user_dashboard' ] ); |
| 35 |
|
| 36 |
// [timetics-category id=''] |
| 37 |
add_shortcode( 'timetics-category', [ $this, 'category_meetings' ] ); |
| 38 |
|
| 39 |
if ( class_exists( 'Wpeventin' ) ) { |
| 40 |
add_action( 'init', [ $this, 'eventin_seat_plan' ] ); |
| 41 |
} |
| 42 |
} |
| 43 |
|
| 44 |
/** |
| 45 |
* booking form for frontend |
| 46 |
* |
| 47 |
* @return void |
| 48 |
*/ |
| 49 |
public function booking_form( $attribute ) { |
| 50 |
wp_enqueue_style( 'timetics-vendor' ); |
| 51 |
wp_enqueue_style( 'timetics-frontend' ); |
| 52 |
wp_enqueue_script( 'timetics-flatpickr-scripts' ); |
| 53 |
wp_enqueue_script( 'timetics-frontend-scripts' ); |
| 54 |
wp_enqueue_script( 'calendar-locale' ); |
| 55 |
|
| 56 |
$id = isset( $attribute['id'] ) ? $attribute['id'] : ''; |
| 57 |
$data_controls = [ |
| 58 |
'id' => $id, |
| 59 |
]; |
| 60 |
$controls = wp_json_encode( $data_controls ); |
| 61 |
|
| 62 |
$visibility = get_post_meta( $id, '_tt_apointment_visibility', true ); |
| 63 |
$is_visible = 'enabled' === $visibility; |
| 64 |
|
| 65 |
if ( ! $is_visible && ! current_user_can( 'manage_options' ) ) { |
| 66 |
return '<div class="timetics-shortcode-wrapper"><p>' . esc_html__( 'This booking form is not available.', 'timetics' ) . '</p></div>'; |
| 67 |
} |
| 68 |
|
| 69 |
ob_start(); |
| 70 |
?> |
| 71 |
<div class="timetics-shortcode-wrapper"> |
| 72 |
<div class="timetics-single-booking-wrapper" |
| 73 |
data-controls="<?php echo esc_attr( $controls ); ?>"></div> |
| 74 |
</div> |
| 75 |
<?php |
| 76 |
return ob_get_clean(); |
| 77 |
} |
| 78 |
/** |
| 79 |
* user dashboard for frontend |
| 80 |
* |
| 81 |
* @return void |
| 82 |
*/ |
| 83 |
public function user_dashboard( $attribute ) { |
| 84 |
wp_enqueue_style( 'timetics-vendor' ); |
| 85 |
wp_enqueue_style( 'timetics-frontend' ); |
| 86 |
wp_enqueue_script( 'timetics-frontend-scripts' ); |
| 87 |
|
| 88 |
$id = get_current_user_id(); |
| 89 |
$data_controls = [ |
| 90 |
'id' => $id, |
| 91 |
]; |
| 92 |
$controls = wp_json_encode( $data_controls ); |
| 93 |
|
| 94 |
ob_start(); |
| 95 |
if (is_user_logged_in()) { |
| 96 |
|
| 97 |
?> |
| 98 |
<div class="timetics-shortcode-wrapper"> |
| 99 |
<div class="timetics-user-dashboard-wrapper" |
| 100 |
data-controls="<?php echo esc_attr( $controls ); ?>"> |
| 101 |
</div> |
| 102 |
</div> |
| 103 |
<?php |
| 104 |
|
| 105 |
}else{ |
| 106 |
?> |
| 107 |
<div class="timetics-userdashbaord-wrapper"> |
| 108 |
<h3> <?php esc_html_e( 'You are not logged in', 'timetics' ); ?> <a href="<?php echo esc_url( wp_login_url( get_permalink() ) ); ?>"><?php esc_html_e( 'Login', 'timetics' ); ?></a></h3> |
| 109 |
</div> |
| 110 |
<?php |
| 111 |
} |
| 112 |
return ob_get_clean(); |
| 113 |
|
| 114 |
} |
| 115 |
|
| 116 |
public function eventin_seat_plan() { |
| 117 |
wp_enqueue_style( 'timetics-vendor' ); |
| 118 |
wp_enqueue_style( 'timetics-frontend' ); |
| 119 |
wp_enqueue_script( 'timetics-flatpickr-scripts' ); |
| 120 |
wp_enqueue_script( 'timetics-frontend-scripts' ); |
| 121 |
} |
| 122 |
|
| 123 |
/** |
| 124 |
* booking form for frontend |
| 125 |
* |
| 126 |
* @return void |
| 127 |
*/ |
| 128 |
public function meeting_list( $attribute ) { |
| 129 |
wp_enqueue_style( 'timetics-vendor' ); |
| 130 |
wp_enqueue_style( 'timetics-frontend' ); |
| 131 |
wp_enqueue_script( 'timetics-flatpickr-scripts' ); |
| 132 |
wp_enqueue_script( 'timetics-frontend-scripts' ); |
| 133 |
wp_enqueue_script( 'calendar-locale' ); |
| 134 |
wp_enqueue_script( 'jquery' ); |
| 135 |
|
| 136 |
wp_enqueue_script( 'timetics-meeting-filtering', TIMETICS_ASSETS_URL . 'js/meeting-filter.js', ['jquery'], time(), true ); |
| 137 |
|
| 138 |
$timetics_limit = isset( $attribute['limit'] ) ? $attribute['limit'] : ''; |
| 139 |
$timetics_show_filter = isset( $attribute['show_filter'] ) && 'true' == $attribute['show_filter'] ? $attribute['show_filter'] : false; |
| 140 |
|
| 141 |
ob_start(); |
| 142 |
?> |
| 143 |
<div class="timetics-shortcode-wrapper"> |
| 144 |
<div class="timetics-meeting-list-wrapper"> |
| 145 |
<?php |
| 146 |
if ( file_exists( TIMETICS_PLUGIN_DIR . 'core/frontend/templates/meeting-list.php' ) ) { |
| 147 |
require_once TIMETICS_PLUGIN_DIR . 'core/frontend/templates/meeting-list.php'; |
| 148 |
} |
| 149 |
?> |
| 150 |
</div> |
| 151 |
</div> |
| 152 |
<?php |
| 153 |
return ob_get_clean(); |
| 154 |
} |
| 155 |
|
| 156 |
/** |
| 157 |
* category wise meeting for frontend |
| 158 |
* |
| 159 |
* @return void |
| 160 |
*/ |
| 161 |
public function category_meetings( $attribute ) { |
| 162 |
wp_enqueue_style( 'timetics-vendor' ); |
| 163 |
wp_enqueue_style( 'timetics-frontend' ); |
| 164 |
wp_enqueue_script( 'timetics-flatpickr-scripts' ); |
| 165 |
wp_enqueue_script( 'timetics-frontend-scripts' ); |
| 166 |
wp_enqueue_script( 'calendar-locale' ); |
| 167 |
|
| 168 |
$id = isset( $attribute['id'] ) ? $attribute['id'] : ''; |
| 169 |
$data_controls = [ |
| 170 |
'id' => $id, |
| 171 |
]; |
| 172 |
$controls = wp_json_encode( $data_controls ); |
| 173 |
|
| 174 |
ob_start(); |
| 175 |
?> |
| 176 |
<div class="timetics-shortcode-wrapper"> |
| 177 |
<div class="timetics-category-wrapper" |
| 178 |
data-controls="<?php echo esc_attr( $controls ); ?>"></div> |
| 179 |
</div> |
| 180 |
<?php |
| 181 |
return ob_get_clean(); |
| 182 |
} |
| 183 |
} |
| 184 |
|