| 1 |
<?php |
| 2 |
/** |
| 3 |
* CHeck if we display chat |
| 4 |
* |
| 5 |
* @package wpstream-theme |
| 6 |
*/ |
| 7 |
|
| 8 |
if ( ! function_exists( 'wpstream_theme_check_if_show_chat' ) ) : |
| 9 |
function wpstream_theme_check_if_show_chat($post_id){ |
| 10 |
$post_type = get_post_type($post_id); |
| 11 |
$show_chat = false; |
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
if($post_type==='product' && get_theme_mod( 'wpstream_product_how_chat' ) ){ |
| 16 |
$show_chat = true; |
| 17 |
}else if($post_type==='wpstream_product' && get_theme_mod( 'wpstream_free_to_view_live_show_chat' ) ){ |
| 18 |
$show_chat = true; |
| 19 |
}else if($post_type==='wpstream_product_vod' && get_theme_mod( 'wpstream_video_on_demand_show_chat' ) ){ |
| 20 |
$show_chat = true; |
| 21 |
} |
| 22 |
|
| 23 |
return $show_chat; |
| 24 |
} |
| 25 |
|
| 26 |
endif; |
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
/** |
| 31 |
* Display video player wrapper . |
| 32 |
* |
| 33 |
* @package wpstream-theme |
| 34 |
*/ |
| 35 |
|
| 36 |
if ( ! function_exists( 'wpstream_theme_display_player_wrapper' ) ) : |
| 37 |
function wpstream_theme_display_player_wrapper($post_id){ |
| 38 |
global $wpstream_plugin; |
| 39 |
$current_user = wp_get_current_user(); |
| 40 |
|
| 41 |
$woo_product_bought_class=''; |
| 42 |
if ( is_singular( 'product' ) && function_exists('wc_get_product') ) { |
| 43 |
$product = wc_get_product( $post_id ); |
| 44 |
$product_type = $product->get_type(); |
| 45 |
if ( 'wpstream_bundle' !== $product_type ) { |
| 46 |
|
| 47 |
|
| 48 |
if ( function_exists( 'wc_customer_bought_product' ) && wc_customer_bought_product( $current_user->user_email, $current_user->ID, $post_id ) ) { |
| 49 |
$woo_product_bought_class='wpstream_woo_product_bought'; |
| 50 |
} |
| 51 |
} |
| 52 |
} |
| 53 |
|
| 54 |
|
| 55 |
print '<div class="row '.esc_attr( $woo_product_bought_class).'">'; |
| 56 |
|
| 57 |
if(wpstream_theme_check_if_show_chat($post_id)){ |
| 58 |
print '<div class="col-md-8 wpstream_theme_display_player_wrapper_with_chat">'; |
| 59 |
wpstream_theme_display_player( $post_id ); |
| 60 |
print '</div>'; |
| 61 |
|
| 62 |
print '<div class="col-md-4 wpstream_theme_display_player_chat_wrapper">'; |
| 63 |
wpstream_theme_display_better_messages_chat($post_id); |
| 64 |
print '</div>'; |
| 65 |
}else{ |
| 66 |
wpstream_theme_display_player( $post_id ); |
| 67 |
} |
| 68 |
|
| 69 |
|
| 70 |
print '</div>'; |
| 71 |
} |
| 72 |
endif; |
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
/** |
| 78 |
* Display better messages chat |
| 79 |
* |
| 80 |
* @package wpstream-theme |
| 81 |
*/ |
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
if ( ! function_exists( 'wpstream_theme_display_better_messages_chat' ) ) : |
| 86 |
function wpstream_theme_display_better_messages_chat($post_id){ |
| 87 |
|
| 88 |
|
| 89 |
if(function_exists('better_messages')){ |
| 90 |
|
| 91 |
$chat_post_id=get_post_meta( $post_id, 'wpstream_chat_post_id',true ); |
| 92 |
if(intval($chat_post_id)===0){ |
| 93 |
$chat_post_id = wpstream_create_better_messages_chat($post_id); |
| 94 |
} |
| 95 |
|
| 96 |
print do_shortcode('[bp_better_messages_chat_room id="'.intval($chat_post_id).'"]'); |
| 97 |
}else{ |
| 98 |
esc_html_e('For chat support you need to install Better Messages plugin','hello-wpstream'); |
| 99 |
} |
| 100 |
|
| 101 |
|
| 102 |
} |
| 103 |
endif; |
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
/** |
| 108 |
* Create Better messages chat room |
| 109 |
* |
| 110 |
* @package wpstream-theme |
| 111 |
*/ |
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
if ( ! function_exists( 'wpstream_create_better_messages_chat' ) ) : |
| 116 |
function wpstream_create_better_messages_chat($post_id){ |
| 117 |
|
| 118 |
if(function_exists('better_messages')){ |
| 119 |
$current_user = wp_get_current_user(); |
| 120 |
$userID = $current_user->ID; |
| 121 |
|
| 122 |
$post = array( |
| 123 |
'post_title' => sanitize_text_field(get_the_title( $post_id )), |
| 124 |
'post_status' => 'publish', |
| 125 |
'post_type' => 'bpbm-chat', |
| 126 |
'post_author' => $userID, |
| 127 |
); |
| 128 |
$chat_post_id = wp_insert_post($post ); |
| 129 |
update_post_meta( $post_id, 'wpstream_chat_post_id',$chat_post_id ); |
| 130 |
return $chat_post_id; |
| 131 |
|
| 132 |
} |
| 133 |
} |
| 134 |
endif; |
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
/** |
| 139 |
* Display video player. |
| 140 |
* |
| 141 |
* @package wpstream-theme |
| 142 |
*/ |
| 143 |
|
| 144 |
if ( ! function_exists( 'wpstream_theme_display_player' ) ) { |
| 145 |
/** |
| 146 |
* Display the video player for the specified post. |
| 147 |
* |
| 148 |
* @param int $post_id The ID of the post. |
| 149 |
* @return void |
| 150 |
*/ |
| 151 |
function wpstream_theme_display_player( $post_id ) { |
| 152 |
global $wpstream_plugin; |
| 153 |
$current_user = wp_get_current_user(); |
| 154 |
|
| 155 |
$poster_id = get_post_thumbnail_id($post_id); |
| 156 |
$poster_data = wp_get_attachment_image_src($poster_id,'full'); |
| 157 |
|
| 158 |
$poster_url = ''; |
| 159 |
if(isset($poster_data[0])){ |
| 160 |
$poster_url=$poster_data[0]; |
| 161 |
} |
| 162 |
?> |
| 163 |
|
| 164 |
|
| 165 |
<div class="wpstream_video_poster_holder wpstream_hide_on_trailer" style="background-image:url('<?php echo esc_attr($poster_url);?>');"></div> |
| 166 |
|
| 167 |
|
| 168 |
<div class="wpstream_player_container_gradient wpstream_hide_on_play"></div> |
| 169 |
|
| 170 |
|
| 171 |
<div class="wpstream_title_wrapper_simple wpstream_hide_on_trailer"> |
| 172 |
<?php |
| 173 |
if ( 'product' === get_post_type( $post_id ) ) { |
| 174 |
include WPSTREAM_PLUGIN_PATH . '/hello-wpstream/template-parts/single/product-add-to-cart-section.php'; |
| 175 |
}else{ |
| 176 |
include WPSTREAM_PLUGIN_PATH . '/hello-wpstream/template-parts/single/post-author-content-simple.php'; |
| 177 |
?> |
| 178 |
<h1 class="wpstream_title"><?php echo esc_html( get_the_title( $post_id ) ); ?></h1> |
| 179 |
<?php |
| 180 |
} |
| 181 |
?> |
| 182 |
</div> |
| 183 |
|
| 184 |
<?php |
| 185 |
if ( $wpstream_plugin->main->wpstream_player->wpstream_check_if_player_can_dsplay_theme( $post_id ) ) { |
| 186 |
|
| 187 |
if ( 'subscription' === get_post_type( $post_id ) ) { |
| 188 |
$wpstream_plugin->main->wpstream_player->wpstream_video_on_demand_player_only_trailer( $post_id ); |
| 189 |
}else if ( 'product' === get_post_type( $post_id ) && function_exists('wc_get_product') ) { |
| 190 |
$product = wc_get_product( $post_id ); |
| 191 |
$product_type = $product->get_type(); |
| 192 |
if ( 'wpstream_bundle' === $product_type ) { |
| 193 |
$wpstream_plugin->main->wpstream_player->wpstream_video_on_demand_player_only_trailer( $post_id ); |
| 194 |
}else{ |
| 195 |
$wpstream_plugin->main->wpstream_player->wpstream_video_player_shortcode( $post_id ); |
| 196 |
} |
| 197 |
}else{ |
| 198 |
$wpstream_plugin->main->wpstream_player->wpstream_video_player_shortcode( $post_id ); |
| 199 |
} |
| 200 |
// |
| 201 |
|
| 202 |
} elseif ( get_post_type( $post_id ) === 'product' && function_exists('wc_get_product') ) { |
| 203 |
|
| 204 |
$product = wc_get_product( $post_id ); |
| 205 |
$product_type = $product->get_type(); |
| 206 |
|
| 207 |
if ( 'subscription' === $product_type ) { |
| 208 |
if ( ! wcs_user_has_subscription( $current_user->ID, $post_id, 'active' ) ) { |
| 209 |
$wpstream_plugin->main->wpstream_player->wpstream_display_no_buy_message( 'nobuy', $post_id ); |
| 210 |
} |
| 211 |
} else { |
| 212 |
$wpstream_plugin->main->wpstream_player->wpstream_display_no_buy_message( 'nobuy', $post_id ); |
| 213 |
} |
| 214 |
} |
| 215 |
|
| 216 |
} |
| 217 |
} |
| 218 |
|
| 219 |
|
| 220 |
|
| 221 |
|
| 222 |
if ( ! function_exists( 'wpstream_display_trailer' ) ) { |
| 223 |
/** |
| 224 |
* Display the trailer for the specified post. |
| 225 |
* |
| 226 |
* @param int $post_id The ID of the post. |
| 227 |
* @param string $poster_thumb The URL of the poster thumbnail. |
| 228 |
* @return string HTML content for displaying the trailer. |
| 229 |
*/ |
| 230 |
function wpstream_display_trailer( $post_id, $poster_thumb = '' ) { |
| 231 |
|
| 232 |
$possible_bundle = get_post_meta( $post_id, 'wpstream_part_of_bundle', true ); |
| 233 |
$current_user = wp_get_current_user(); |
| 234 |
|
| 235 |
if ( |
| 236 |
get_post_type( $post_id ) === 'product' && |
| 237 |
function_exists('wc_get_product') && |
| 238 |
wc_get_product( $post_id )->get_type() === 'video_on_demand' && |
| 239 |
function_exists( 'wc_customer_bought_product' ) && |
| 240 |
wc_customer_bought_product( $current_user->user_email, $current_user->ID, $post_id ) |
| 241 |
) { |
| 242 |
echo 'do not display trailer player - trailer in plugin'; |
| 243 |
return; // We will display trailer in the plugin player. |
| 244 |
} elseif ( |
| 245 |
get_post_type( $post_id ) === 'product' && |
| 246 |
function_exists('wc_get_product') && |
| 247 |
wc_get_product( $post_id )->get_type() === 'subscription' && |
| 248 |
function_exists( 'wcs_user_has_subscription' ) && |
| 249 |
wcs_user_has_subscription( $current_user->ID, $post_id, 'active' ) |
| 250 |
) { |
| 251 |
echo 'do not display trailer player - trailer in plugin'; |
| 252 |
return; // We will display trailer in the plugin player. |
| 253 |
} elseif ( |
| 254 |
get_post_type( $post_id ) === 'product' && |
| 255 |
intval( $possible_bundle ) !== 0 && |
| 256 |
function_exists( 'wc_customer_bought_product' ) && |
| 257 |
wc_customer_bought_product( $current_user->user_email, $current_user->ID, $possible_bundle ) |
| 258 |
) { |
| 259 |
echo 'do not display trailer player - trailer in plugin'; |
| 260 |
return; // We will display trailer in the plugin player. |
| 261 |
} elseif ( get_post_type( $post_id ) === 'wpstream_product_vod' ) { |
| 262 |
echo 'do not display trailer player - trailer in plugin'; |
| 263 |
return; // We will display trailer in the plugin player. |
| 264 |
} |
| 265 |
|
| 266 |
$return = ''; |
| 267 |
ob_start(); |
| 268 |
|
| 269 |
$video_attachment_id = get_post_meta( $post_id, 'video_trailer', true ); |
| 270 |
$attachment_url = wp_get_attachment_url( $video_attachment_id ); |
| 271 |
$poster_thumb = get_the_post_thumbnail_url( $post_id, 'full' ); |
| 272 |
$attachment_metadata = wp_get_attachment_metadata( $video_attachment_id ); |
| 273 |
$video_type = ''; |
| 274 |
if ( isset( $attachment_metadata['mime_type'] ) ) { |
| 275 |
$video_type = $attachment_metadata['mime_type']; |
| 276 |
} |
| 277 |
|
| 278 |
if ( $attachment_url ) { |
| 279 |
?> |
| 280 |
|
| 281 |
<video id="wpstream-video-trailer" class="video-js vjs-default-skin vjs-16-9" |
| 282 |
data-product-id="<?php echo esc_attr( $post_id ); ?>" autoplay="true" muted="true" controls |
| 283 |
preload="auto" poster="<?php echo esc_url( $poster_thumb ); ?>"> |
| 284 |
|
| 285 |
<source src="<?php echo esc_attr( trim( $attachment_url ) ); ?>" |
| 286 |
type="<?php echo esc_attr( $video_type ); ?>"> |
| 287 |
<p class="vjs-no-js"> |
| 288 |
<?php esc_html_e('To view this video please enable JavaScript, and consider upgrading to a web browser that supports HTML5 video','hello-wpstream')?> |
| 289 |
</p> |
| 290 |
</video> |
| 291 |
|
| 292 |
<?php |
| 293 |
print '<div class="wpstream_video_on_demand_play_trailer_sound">' . esc_html__( 'play trailer with sound','hello-wpstream' ) . '</div>'; |
| 294 |
} |
| 295 |
|
| 296 |
$return = ob_get_contents(); |
| 297 |
ob_end_clean(); |
| 298 |
|
| 299 |
return $return; |
| 300 |
} |
| 301 |
} |
| 302 |
|
| 303 |
|
| 304 |
/** |
| 305 |
* Determine the column classes for video cards based on the number of columns per row. |
| 306 |
* |
| 307 |
* @param int $per_row The number of columns per row. |
| 308 |
* @return string The string of column classes. |
| 309 |
*/ |
| 310 |
function wpstream_video_cards_column_class( $per_row ) { |
| 311 |
$per_row = intval( $per_row ); |
| 312 |
$return = 'col-12 col-sm-6 col-md-4 col-lg-4'; |
| 313 |
|
| 314 |
if ( 4 === $per_row ) { |
| 315 |
$return = 'col-12 col-sm-6 col-md-4 col-lg-3'; |
| 316 |
}else if ( 2 === $per_row ) { |
| 317 |
$return = 'col-12 col-sm-6 col-md-6 col-lg-6'; |
| 318 |
}else if ( 6 === $per_row ) { |
| 319 |
$return = 'col-12 col-sm-6 col-md-4 col-lg-3 col-xl-2'; |
| 320 |
}else if ( 5 === $per_row ) { |
| 321 |
$return = 'col-12 col-sm-6 col-md-4 col-2-4'; |
| 322 |
} |
| 323 |
return $return; |
| 324 |
} |
| 325 |
|
| 326 |
/** |
| 327 |
* Generate the HTML markup for the non-live section of the WPStream theme. |
| 328 |
* |
| 329 |
* @param int $channel_id The ID of the channel. |
| 330 |
* @return string The HTML markup for the non-live section. |
| 331 |
*/ |
| 332 |
function wpstream_theme_not_live_section( $channel_id ) { |
| 333 |
$transient_name = 'event_data_to_return_'. $channel_id; |
| 334 |
$event_data = get_transient( $transient_name ); |
| 335 |
|
| 336 |
$return_string = '<div class="wpstream_not_live_mess wpstream_theme_not_live_section " style="display: none"><div class="wpstream_not_live_mess_back"></div>'; |
| 337 |
$return_string .= '<div class="wpstream_not_live_mess_mess">'; |
| 338 |
|
| 339 |
if ( ( isset( $event_data['status']) && |
| 340 |
in_array( $event_data['status'], array( 'stopped', 'stopping', 'starting' ) ) ) || |
| 341 |
( isset($event_data['error']) && $event_data['error'] === 'NO_SUCH_CHANNEL' ) ){ |
| 342 |
$return_string .= esc_html( get_option( 'wpstream_you_are_not_live', 'We are not live at this moment' ) );; |
| 343 |
} else { |
| 344 |
$return_string .= '<div classs="wpstream_loading_spinner vjs-loading-spinner" style="display: block;"></div>'; |
| 345 |
} |
| 346 |
|
| 347 |
$return_string .= '</div>'; |
| 348 |
$return_string .= '</div>'; |
| 349 |
return $return_string; |
| 350 |
} |
| 351 |
|
| 352 |
/** |
| 353 |
* Generate the HTML markup for past broadcasts in the non-live section of the WPStream theme. |
| 354 |
* |
| 355 |
* @param int $channel_id The ID of the channel. |
| 356 |
* @return string The HTML markup for past broadcasts. |
| 357 |
*/ |
| 358 |
function wpstream_past_broascast_for_non_live_section( $channel_id ) { |
| 359 |
$wpstream_get_post_type = get_post_type( $channel_id ); |
| 360 |
$author_id = wpstream_get_author_id( $channel_id ); |
| 361 |
$use_transient = wpstream_return_use_transient(); |
| 362 |
$transient_key = 'wpstream_product_broadcaster_vod_query_' . $author_id; |
| 363 |
|
| 364 |
$broadcaster_video_query_args = array( |
| 365 |
'post_status' => 'publish', |
| 366 |
'post_type' => 'wpstream_product_vod', |
| 367 |
'posts_per_page' => 3, |
| 368 |
'orderby' => 'date', |
| 369 |
'order' => 'DESC', |
| 370 |
'meta_query' => array(//phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query |
| 371 |
array( |
| 372 |
'key' => 'wpstream_theme_attach_to_channel', |
| 373 |
'value' => $channel_id, |
| 374 |
'compare' => '=', |
| 375 |
'type' => 'numeric', |
| 376 |
), |
| 377 |
|
| 378 |
), |
| 379 |
); |
| 380 |
|
| 381 |
$query = wpstream_custom_query( $broadcaster_video_query_args, $transient_key, $use_transient ); |
| 382 |
|
| 383 |
$return = ''; |
| 384 |
if ( $query->found_posts > 0 ) { |
| 385 |
$return .= '<section class="wpstream_section wpstream_broadcaster_section">'; |
| 386 |
$return .= '<div class="row wpstream_past_broascast_for_non_live_section_wrapper">'; |
| 387 |
ob_start(); |
| 388 |
include WPSTREAM_PLUGIN_PATH . '/hello-wpstream/template-parts/single/not-live-past-broadcast.php'; |
| 389 |
$return .= ob_get_contents(); |
| 390 |
ob_end_clean(); |
| 391 |
$return .= '</div></section>'; |
| 392 |
} |
| 393 |
|
| 394 |
return $return; |
| 395 |
} |
| 396 |
|