PluginProbe
WpStream – Live Streaming, Video on Demand, Pay Per View / 4.12.2
WpStream – Live Streaming, Video on Demand, Pay Per View v4.12.2
4.14.1 4.14.0 4.13.2 4.13.1 4.13 4.12.5 4.12.4 4.12.3 4.12.2 4.12.1 4.12 4.4.4 4.4.5 4.4.6 4.4.7 4.4.8 4.4.9 4.5 4.5.1 4.5.11 4.5.11.1 4.5.11.2 4.5.11.4 4.5.11.5 4.5.11.6 All 181 releases
wpstream / hello-wpstream / framework / wpstream-help-functions.php

wpstream-help-functions.php in WpStream – Live Streaming, Video on Demand, Pay Per View 4.12.2, at hello-wpstream/framework/wpstream-help-functions.php

752 lines 25.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 if ( ! function_exists( 'wpstream_theme_featured_image' ) ) {
4 /**
5 * Display the featured image for a post or page with additional functionality.
6 *
7 * @param int $post_id The ID of the post or page.
8 * @param string $size Optional. The image size to retrieve. Default is 'full'.
9 * @param string $context Optional. The context in which the function is being used. Default is 'unit_card'.
10 * @param bool $link Optional. Link to post.
11 * @param bool $show_badge Optional. Show badge.
12 * @return string The HTML markup for the featured image.
13 */
14 function wpstream_theme_featured_image( $post_id, $size = 'full', $context = 'unit_card', $link = false, $show_badge = false ) {
15 $featured_image_src = wpstream_theme_default_card_no_image_url( $size );
16 $featured_image_id = get_post_thumbnail_id( $post_id );
17 $featured_image_alt = get_post_meta( $featured_image_id, '_wp_attachment_image_alt', true );
18
19 // Check if a featured image is set for the current post or page.
20
21 if ( has_post_thumbnail( $post_id ) ) {
22 $featured_image_src = get_the_post_thumbnail_url( $post_id, $size );
23 }
24
25 $video_attachment_id = get_post_meta( $post_id, 'video_preview', true );
26
27 $return_string = '<div class="post-thumbnail wpstream_featured_image">';
28
29 if ( $link ) {
30 $return_string .= '<a class="d-block w-100 h-100" href="' . esc_url( get_permalink( $post_id ) ) . '">';
31 }
32
33 if ( ('unit_card' === $context || 'video_preview' === $context ) && '' !== $video_attachment_id ) {
34 $video_id = 'wpstream_unit_video_preview_' . wp_rand( 0, 99999999 );
35
36 $video_attachment_id = get_post_meta( $post_id, 'video_preview', true );
37
38 $video_src = wp_get_attachment_url( $video_attachment_id );
39 $play_button = $context === 'video_preview' ? '<div class="wpstream_video_unit_video_play">' . wpstream_theme_get_svg_icon('play_icon_white.svg') . '</div>' : "";
40
41 if ($context === 'video_preview' && get_post_type($post_id) === 'post'){
42 $play_button = '<div class="wpstream_video_unit_video_play">' . wpstream_theme_get_svg_icon('bloghover.svg') . '</div>';
43 }
44
45
46
47 $return_string .= '<div class="wpstream_video_unit_video_wrapper wpstream_video_unit_video_wrapper_trigger"
48 data-video-id="'. esc_attr( $video_id ).'">'
49
50 . $play_button
51 .'<div class="wpstream_video_unit_overlay"></div>'
52 .'<video id="' . esc_attr( $video_id ) . '" class="wpstream_video_unit_video" preload="none" poster="' . esc_url( $featured_image_src ) . '" muted>
53 <source src="' . esc_url( $video_src ) . '" type="video/mp4">
54 Your browser does not support the video tag.
55 </video>
56
57 </div>';
58 } else {
59 if( get_post_type($post_id) === 'post' || !wpstream_is_woo_video_product( $post_id ) ){
60 $play_button = '<div class="wpstream_video_unit_video_play">' . wpstream_theme_get_svg_icon('bloghover.svg') . '</div>';
61 }else{
62 $play_button = '<div class="wpstream_video_unit_video_play">' . wpstream_theme_get_svg_icon('play_icon_white.svg') . '</div>';
63 }
64
65
66 $return_string .= '<div class="wpstream_video_unit_overlay"></div>'. $play_button .'<img src="' . esc_url( $featured_image_src ) . '" alt="' . esc_attr( ! empty( $featured_image_alt ) ? $featured_image_alt : get_the_title( $post_id ) ) . '" class="wpstream_featured_unit_cards" />';
67 }
68
69 if ( $link ) {
70 $return_string .= '</a>';
71 }
72
73 if ( 'unit_card' === $context || $show_badge ) {
74 $views = intval( get_post_meta( $post_id, 'post_view_count', true ) );
75 $views_label = __( 'reads', 'hello-wpstream' );
76 if ( in_array(
77 get_post_type( $post_id ),
78 array(
79 'wpstream_product_vod',
80 'wpstream_product',
81 'product',
82 'wpstream_bundles'
83 ),
84 true
85 ) ) {
86 $views_label = __( 'views', 'hello-wpstream' );
87 }
88 $return_string .= '<div class="wpstream_featured_image_views">' . $views . ' ' . esc_html( $views_label ) . '</div>';
89 }
90
91 if ( ( get_post_type( $post_id ) === 'product' && has_term( 'live_stream', 'product_type', $post_id ) || get_post_type( $post_id ) === 'wpstream_product' ) ) {
92
93 $live_events = wpestream_integrations_get_current_user_live_events('no');
94 if ( is_array( $live_events) && array_key_exists( $post_id, $live_events ) ) {
95 $return_string .= '<div class="wpstream_featured_image_live_tag">' . esc_html_x( 'LIVE', 'Card tag', 'hello-wpstream' ) . '</div>';
96 }
97 }
98
99 $return_string .= '</div><!-- .post-thumbnail -->';
100
101 return $return_string;
102 }
103 }
104
105 if ( ! function_exists( 'wpstream_theme_default_card_no_image_url' ) ) {
106 /**
107 * Returns the default URL for card images if no image is available.
108 *
109 * @param string $size The size of the card image.
110 * @return string The URL of the default image.
111 */
112 function wpstream_theme_default_card_no_image_url( $size ) {
113 if ( 'wpstream_bundle_unit_cards_image' === $size ) {
114 $image_path = '/img/default-cover-big.png';
115 } else {
116 $image_path = '/img/default-cover.png';
117 }
118
119 // Define the default image URL.
120 $default_image_url = get_stylesheet_directory_uri() . $image_path;
121
122 // Return the default image URL.
123 return esc_url( $default_image_url );
124 }
125 }
126
127 if ( ! function_exists( 'wpstream_theme_get_svg_icon' ) ) {
128 /**
129 * Get the SVG content from a specified SVG file.
130 *
131 * @param string $icon_path The path to the SVG icon file.
132 * @return string|false The SVG content or false if the file doesn't exist.
133 */
134 function wpstream_theme_get_svg_icon( $icon_path ) {
135 $icon_path = get_template_directory() . '/img/icons/' . $icon_path;
136
137 // Check if the file exists.
138 if ( file_exists( $icon_path ) ) {
139 ob_start();
140 include $icon_path;
141
142 return ob_get_clean();
143 } else {
144 return false; // Return false if the icon file doesn't exist.
145 }
146 }
147 }
148
149 /**
150 * Get the count of likes for a specific post.
151 *
152 * @param int $post_id The ID of the post.
153 * @return int The count of likes for the post.
154 */
155 function wpstream_get_count_like_post( $post_id ) {
156 return intval( get_post_meta( $post_id, 'wpstream_like_items', true ) );
157 }
158
159 if ( ! function_exists( 'wpstream_query_arguments_add_order_by' ) ) {
160 /**
161 * Generate query arguments for ordering posts.
162 *
163 * @param int $order The order value.
164 * @return array An array containing the query arguments and transient appendix.
165 */
166 function wpstream_query_arguments_add_order_by( $order ) {
167 $meta_directions = 'DESC';
168 $meta_order = '';
169 $order_by = 'ID';
170
171 switch ( $order ) {
172 case 1:
173 $meta_order = '';
174 $meta_directions = 'DESC';
175 $order_by = 'ID';
176 break;
177 case 2:
178 $meta_order = '';
179 $meta_directions = 'ASC';
180 $order_by = 'ID';
181 break;
182 case 3:
183 $meta_order = '';
184 $meta_directions = 'DESC';
185 $order_by = 'modified';
186 break;
187 case 4:
188 $meta_order = '';
189 $meta_directions = 'ASC';
190 $order_by = 'modified';
191 break;
192 case 5:
193 $meta_order = 'post_view_count';
194 $meta_directions = 'DESC';
195 $order_by = 'meta_value_num';
196 break;
197 case 6:
198 $meta_order = 'post_view_count';
199 $meta_directions = 'ASC';
200 $order_by = 'meta_value_num';
201 break;
202 case 7:
203 $meta_order = '_price';
204 $meta_directions = 'DESC';
205 $order_by = 'meta_value_num';
206 break;
207 case 8:
208 $meta_order = '_price';
209 $meta_directions = 'ASC';
210 $order_by = 'meta_value_num';
211 break;
212 case 11:
213 $meta_order = 'wpstream_like_items';
214 $meta_directions = 'DESC';
215 $order_by = 'meta_value_num';
216 break;
217 case 12:
218 $meta_order = 'wpstream_like_items';
219 $meta_directions = 'ASC';
220 $order_by = 'meta_value_num';
221 break;
222 case 99:
223 $meta_order = '';
224 $meta_directions = 'ASC';
225 $order_by = 'rand';
226 break;
227 }
228
229 $transient_appendix = '_' . $meta_order . '_' . $meta_directions;
230
231 if ( 0 === $order ) {
232 $transient_appendix .= '_myorder';
233 }
234
235 $order_array = array(
236 'orderby' => $order_by,
237 );
238
239 if ( '' !== $meta_order ) {
240 $order_array['meta_key'] = $meta_order;//phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_key
241 }
242
243 if ( '' !== $meta_directions ) {
244 $order_array['order'] = $meta_directions;
245 }
246
247 return array(
248 'order_array' => $order_array,
249 'transient_appendix' => $transient_appendix,
250 );
251 }
252 }
253
254 if ( ! function_exists( 'wpstream_post_type_options_select' ) ) {
255 /**
256 * Generate a select dropdown for post type options.
257 *
258 * @param array $attributes An array of attributes for the select dropdown.
259 * @param string $selected_option The selected option.
260 * @return string The HTML for the select dropdown.
261 */
262 function wpstream_post_type_options_select( $attributes, $selected_option = '' ) {
263 $options = wpstream_post_type_options();
264
265 $name = 'post_type';
266 $class = 'wpstream_dropdown_select wpstream_dropdown_select_trigger_ajax wpstream_dropdown_select_post_type';
267 $id = 'post_type_dropdown';
268 $label = $attributes['label_post_types'];
269 $output = wpstream_create_custom_dropdown( $options, $name, $class, $id, $label, $selected_option );
270
271
272 return $output;
273 }
274 }
275
276 if ( ! function_exists( 'wpstream_post_type_options' ) ) {
277 /**
278 * Retrieve an array of available post type options.
279 *
280 * @return array An associative array of post type options.
281 */
282 function wpstream_post_type_options() {
283 $options = array(
284 'product' => esc_html__( 'Products', 'hello-wpstream' ),
285 'wpstream_bundles' => esc_html__( 'Bundles', 'hello-wpstream' ),
286 'wpstream_product_vod' => esc_html__( 'Free Vod', 'hello-wpstream' ),
287 'wpstream_product' => esc_html__( 'Free Events', 'hello-wpstream' ),
288 );
289
290 return $options;
291 }
292 }
293
294 if ( ! function_exists( 'wpstream_is_woo_video_product' ) ) {
295 /**
296 * Check if the product is a WpStream video product.
297 *
298 * @param int $product_id The ID of the product.
299 * @return bool True if the product is a video product, false otherwise.
300 */
301 function wpstream_is_woo_video_product( $product_id ) {
302 $wpstream_woo_product_types = ['video_on_demand', 'live_stream', 'wpstream_bundle', 'subscription'];
303
304 if ( ! function_exists( 'wc_get_product' ) ) {
305 return false;
306 }
307 $product = wc_get_product( $product_id );
308
309 if ( ! $product ) {
310 return false;
311 }
312
313 return in_array( $product->get_type(), $wpstream_woo_product_types, true );
314 }
315 }
316
317 /**
318 * Get the full path for a given card type.
319 *
320 * @param string $card_type The card type template name.
321 * @return string The full path to the card type template.
322 */
323 if ( ! function_exists( 'wpstream_get_card_type_path' ) ) {
324 function wpstream_get_card_type_path($card_type)
325 {
326 return WPSTREAM_PLUGIN_PATH . 'hello-wpstream/' . $card_type;
327 }
328 }
329
330 if ( ! function_exists( 'wpstream_get_all_items_list' ) ) {
331 /**
332 * Get all items list.
333 *
334 * @param int $limit The limit of posts to retrieve.
335 * @param string $post_type The post type to retrieve.
336 * @param array $ids The array of post IDs to retrieve.
337 * @return array Array containing titles and types of retrieved posts.
338 */
339 function wpstream_get_all_items_list( $limit = -1, $post_type = 'free', $ids = array() ) {
340
341 $options = array();
342
343 if ( 'free' === $post_type ) {
344 $post_type = array( 'wpstream_product_vod', 'wpstream_product' );
345 $taxonomy_array = array();
346 } else {
347 $post_type = array( 'product' );
348
349 $taxonomy_array = array(
350 'relation' => 'OR',
351 array(
352 'taxonomy' => 'product_type',
353 'field' => 'slug',
354 'terms' => array( 'live_stream', 'video_on_demand' ),
355 ),
356
357 array(
358 'taxonomy' => 'product_type',
359 'operator' => 'NOT EXISTS',
360 ),
361
362 );
363
364 }
365
366 $args = array(
367 'post_type' => $post_type,
368 'posts_per_page' => $limit,
369 'tax_query' => $taxonomy_array, //phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_tax_query
370 );
371
372 if ( ! empty( $ids ) ) {
373 $args['post__in'] = $ids;
374 $args['orderby'] = 'post__in';
375 }
376
377 $custom_post_types = get_posts( $args );
378
379 $options = array();
380
381 foreach ( $custom_post_types as $custom_post ) {
382
383 $options[ $custom_post->ID ] = array(
384 'title' => $custom_post->post_title,
385 'type' => $custom_post->post_type,
386 );
387 }
388
389 return $options;
390 }
391 }
392
393
394 if ( ! function_exists( 'wstream_sort_options_array' ) ) {
395 /**
396 * Sort options array
397 */
398 function wstream_sort_options_array() {
399 $listing_filter_array = array(
400 '1' => esc_html__( 'Newest first', 'hello-wpstream' ),
401 '2' => esc_html__( 'Oldest first', 'hello-wpstream' ),
402 '5' => esc_html__( 'Views High to Low', 'hello-wpstream' ),
403 '6' => esc_html__( 'Views Low to high', 'hello-wpstream' ),
404 '11' => esc_html__( 'Liked High to Low', 'hello-wpstream' ),
405 '12' => esc_html__( 'Liked Low to high', 'hello-wpstream' ),
406 '7' => esc_html__( 'Price High to Low', 'hello-wpstream' ),
407 '8' => esc_html__( 'Price Low to High', 'hello-wpstream' ),
408 '3' => esc_html__( 'Newest Edited', 'hello-wpstream' ),
409 '4' => esc_html__( 'Oldest Edited ', 'hello-wpstream' ),
410 '0' => esc_html__( 'Default', 'hello-wpstream' ),
411 );
412
413 return $listing_filter_array;
414 }
415 }
416
417 if ( ! function_exists( 'wpstream_theme_is_show_sidebar' ) ) {
418 /**
419 * Returns true if the sidebar should be display for post.
420 *
421 * @param $post_id
422 * @return bool
423 */
424 function wpstream_theme_is_show_sidebar( $post_id = null ) {
425 $is_show_sidebar=null;
426 if(function_exists('rwmb_meta')){
427 $is_show_sidebar = rwmb_meta( 'wpstream_theme_show_sidebar_on_post', array(), $post_id );
428 }
429 if ( '' !== $is_show_sidebar ) {
430 return '1' === $is_show_sidebar;
431 } else {
432 $post_type = get_post_type( $post_id );
433
434 switch ( $post_type ) {
435 case 'post':
436 $wpstream_show_sidebar = get_theme_mod( 'wpstream_blog_post_sidebar', true );
437 break;
438 default:
439 $wpstream_show_sidebar = apply_filters( 'wpstream_show_sidebar_for_post_type', false, $post_type );
440 break;
441 }
442
443 return $wpstream_show_sidebar;
444 }
445 }
446 }
447
448 if ( ! function_exists( 'wpstream_theme_featured_image_simple' ) ) {
449 /**
450 * Display the featured image for a post or page in a simple format.
451 *
452 * @param int $post_id The ID of the post or page.
453 * @param string $size Optional. The image size to retrieve. Default is 'full'.
454 * @param string $context Optional. The context in which the function is being used. Default is 'unit_card'.
455 * @return string The HTML markup for the featured image.
456 */
457 function wpstream_theme_featured_image_simple( $post_id, $size = 'full', $context = 'unit_card' ) {
458
459 $featured_image_src = wpstream_theme_default_card_no_image_url( $size );
460
461 // Check if a featured image is set for the current post or page.
462 if ( has_post_thumbnail( $post_id ) ) {
463 $featured_image_src = get_the_post_thumbnail_url( $post_id, $size );
464 }
465
466 $return_string = '<div class="post-thumbnail wpstream_featured_image">';
467
468 $return_string .= '<img src="' . esc_url( $featured_image_src ) . '" class="wpstream_featured_unit_cards rounded mb-3" />';
469
470 if ( 'unit_card' === $context ) {
471 $views = intval( get_post_meta( $post_id, 'post_view_count', true ) );
472 $return_string .= '<div class="wpstream_featured_image_views">' . $views . ' ' . esc_html__( 'views', 'hello-wpstream' ) . '</div>';
473 }
474
475 $return_string .= '</div><!-- .post-thumbnail -->';
476
477 return $return_string;
478 }
479 }
480
481 if ( ! function_exists( 'wpstream_generate_user_menu' ) ) {
482 /**
483 * Generate user menu
484 */
485 function wpstream_generate_user_menu() {
486 $return_string = '';
487
488 $svg_icons = [
489 'dashboard' => wpstream_theme_get_svg_icon('dashboard.svg'),
490 'orders' => wpstream_theme_get_svg_icon('orders-icon.svg'),
491 'downloads' => wpstream_theme_get_svg_icon('downloads.svg'),
492 'subscriptions' => wpstream_theme_get_svg_icon('orders-subscription.svg'),
493 'edit-address' => wpstream_theme_get_svg_icon('location-icon.svg'),
494 'edit-account' => wpstream_theme_get_svg_icon('edit-account-icon.svg'),
495 'event-list' => wpstream_theme_get_svg_icon('purchased-events-icon.svg'),
496 'video-list' => wpstream_theme_get_svg_icon('purchased-video-icon.svg'),
497 'start-streaming' => wpstream_theme_get_svg_icon('go-to-live-icon.svg'),
498 'watch-later' => wpstream_theme_get_svg_icon('watch-later-icon.svg'),
499 'customer-logout' => wpstream_theme_get_svg_icon('logout_icon.svg'),
500 'logout' => wpstream_theme_get_svg_icon('logout_icon.svg'),
501 ];
502
503 ob_start();
504
505 if ( function_exists( 'wc_get_account_menu_items' ) ) {
506 $menu_items = wc_get_account_menu_items();
507
508 if ( ! wpstream_check_if_user_can_stream()) {
509 unset($menu_items['start-streaming']);
510 }
511
512 foreach ( $menu_items as $endpoint => $label ) :
513 $menu_link= wc_get_account_endpoint_url( $endpoint ) ;
514 if($endpoint === 'subscriptions') {
515 $menu_link = home_url('/dashboard/subscriptions/');
516 }
517 ?>
518 <a href="<?php echo esc_url($menu_link); ?>" class="list-group-item list-group-item-action wpstream-account-item-<?php echo esc_attr( $endpoint ); ?>">
519 <?php echo isset($svg_icons[$endpoint]) ? trim($svg_icons[$endpoint]) : ''; ?>
520 <?php echo trim( esc_html( $label ));?>
521 </a>
522 <?php
523 endforeach;
524
525 } else {
526 $menu_items = array(
527 'dashboard' => esc_html__( 'Dashboard', 'hello-wpstream' ),
528 'start-streaming' => esc_html__( 'Go Live', 'hello-wpstream' ),
529 'edit-account' => esc_html__( 'Edit Account', 'hello-wpstream' ),
530 'watch-later' => esc_html__( 'Watch Later', 'hello-wpstream' ),
531 'logout' => esc_html__( 'Logout', 'hello-wpstream' ),
532 );
533
534 if ( ! wpstream_check_if_user_can_stream()) {
535 unset($menu_items['start-streaming']);
536 }
537
538 foreach ( $menu_items as $endpoint => $label ) :
539 $item_link = wpstream_non_woo_get_account_endpoint_url( $endpoint );
540 if ( 'logout' === $endpoint ) {
541 $item_link = wp_logout_url( home_url() );
542 }
543 ?>
544
545 <a href="<?php echo esc_url( $item_link ); ?>"
546 class="list-group-item list-group-item-action wpstream-account-item-<?php echo esc_attr( $endpoint ); ?>">
547 <?php echo trim($svg_icons[ $endpoint ]) ?? ''; ?>
548 <?php echo esc_html( $label ); ?>
549 </a>
550 <?php
551
552 endforeach;
553
554 }
555
556 $return_string = ob_get_contents();
557
558 ob_end_clean();
559
560 return $return_string;
561 }
562 }
563
564 if ( ! function_exists( 'wpstream_dashboard_get_products_by_user' ) ) {
565 /**
566 * Retrieve products purchased by a specific user.
567 *
568 * Retrieves all products of a specific type (default: 'video_on_demand') purchased by a user.
569 *
570 * @param int $user_id The ID of the user.
571 * @param string $product_type The type of products to retrieve. Default is 'video_on_demand'.
572 * @param int $page Optional. The page number of the results. Default is 1.
573 * @param int $per_page Optional. The number of products to retrieve per page. Default is 10.
574 * @return array An array containing paginated products, total number of products, and maximum number of pages.
575 */
576 function wpstream_dashboard_get_products_by_user( $user_id, $product_type = 'video_on_demand', $page = 1, $per_page = 10 ) {
577 $all_products = array();
578
579 // Get all customer orders.
580 $customer_orders = wc_get_orders(
581 array(
582 'customer_id' => $user_id,
583 'status' => 'completed',
584 'limit' => -1
585 )
586 );
587
588 // Loop through each customer order.
589 foreach ( $customer_orders as $customer_order ) {
590 $order_items = $customer_order->get_items();
591 $order = wc_get_order( $customer_order );
592 $order_id = $order->get_id();
593 $order_date = $order->get_date_created();
594 $formatted_date = wc_format_datetime( $order_date );
595
596 foreach ( $order_items as $item ) {
597 $product = $item->get_product();
598
599 if ( $product && $product_type === $product->get_type() ) {
600 $total_paid = $item->get_total();
601 $temp_array = array(
602 'price' => $total_paid,
603 'order_id' => $order_id,
604 'order_date' => $formatted_date,
605 'product' => $product,
606 );
607
608 $all_products[$product->get_id()] = $temp_array;
609 }
610 }
611 }
612
613 if(intval($per_page) === -1){
614 return $all_products;
615 }
616
617 // Calculate offset for pagination.
618 $offset = ( $page - 1 ) * $per_page;
619 $paginated_products = array_slice( $all_products, $offset, $per_page );
620
621 return array(
622 'products' => $paginated_products,
623 'total' => count( $all_products ),
624 'max_num_pages' => ceil( count( $all_products ) / $per_page ),
625 );
626 }
627 }
628
629 if ( ! function_exists( 'wpstream_non_woo_get_account_endpoint_url' ) ) {
630 /**
631 * Retrieves the URL for a given account endpoint.
632 *
633 * @param string $endpoint Optional. Endpoint to append to the URL.
634 * @return string URL for the account endpoint.
635 */
636 function wpstream_non_woo_get_account_endpoint_url( $endpoint = '' ) {
637 $url = wpstream_return_dashboard_page();
638
639 if ( $endpoint ) {
640 $url = add_query_arg( 'endpoint', $endpoint, $url );
641 }
642
643 return esc_url_raw( $url );
644 }
645 }
646
647 if ( ! function_exists( 'wpstream_theme_show_social_share_page' ) ) {
648 /**
649 * Display social share buttons for a given post.
650 *
651 * @param int $post_id The ID of the post.
652 * @param string $size Optional. The size of the post image. Default is 'full'.
653 * @param int $is_single Optional. Whether the post is single or not. Default is 1 (true).
654 * @return string The HTML markup for the social share buttons.
655 */
656 function wpstream_theme_show_social_share_page( $post_id, $size = 'full', $is_single = 1 ) {
657 $return_string = '<div class="wpstream-social-share-wrapper">';
658 $return_string .= wpstream_share_unit_desing( $post_id, $size, $is_single );
659 $return_string .= '</div>';
660
661 return $return_string;
662 }
663 }
664
665 if ( ! function_exists( 'wpstream_share_unit_desing' ) ) {
666 /**
667 * Generate social share buttons HTML for a post.
668 *
669 * @param int $post_id The ID of the post.
670 * @param string $size Optional. The size of the post image. Default is 'full'.
671 * @param int $is_single Optional. Whether the post is single or not. Default is 0 (false).
672 * @return string The HTML markup for the social share buttons.
673 */
674 function wpstream_share_unit_desing( $post_id, $size = 'full', $is_single = 0 ) {
675 $protocol = is_ssl() ? 'https' : 'http';
676 $pinterest = wp_get_attachment_image_src( get_post_thumbnail_id( $post_id ), $size );
677 $link = esc_url( get_permalink( $post_id ) );
678 $title = get_the_title( $post_id );
679 $twitter_status = rawurlencode( $title . ' ' . $link );
680 $email_link = 'subject=' . rawurlencode( $title ) . '&body=' . rawurlencode( esc_url( $link ) );
681
682 ob_start();
683
684 $facebook_label = '';
685 $twitter_label = '';
686 $pinterest_label = '';
687 $whatsup_label = '';
688 $email_label = '';
689
690 if ( intval( $is_single ) === 1 ) {
691 $facebook_label = esc_html__( 'Facebook', 'hello-wpstream' );
692 $twitter_label = esc_html__( 'Twitter', 'hello-wpstream' );
693 $pinterest_label = esc_html__( 'Pinterest', 'hello-wpstream' );
694 $whatsup_label = esc_html__( 'WhatsApp', 'hello-wpstream' );
695 $email_label = esc_html__( 'Email', 'hello-wpstream' );
696 }
697
698 $text_whats = get_the_title( $post_id ) . ' ' . esc_url( get_permalink( $post_id ) );
699
700 $whatsup_link = 'https://wa.me/?text=' . ( $text_whats );
701
702 ?>
703
704 <div class="share_unit">
705 <a href="<?php echo esc_url( $protocol . '://www.facebook.com/sharer.php?u=' . $link . '&amp;t=' . rawurlencode( get_the_title() ) ); ?>"
706 target="_blank" rel="noreferrer noopener nofollow" class="social_facebook d-flex align-items-center">
707
708 <?php echo wpstream_theme_get_svg_icon( 'facebook.svg' ); //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
709
710 <?php echo esc_html( $facebook_label ); ?>
711
712 </a>
713 <a href="<?php echo esc_url( $protocol . '://twitter.com/intent/tweet?text=' . $twitter_status ); ?>"
714 class="social_twitter d-flex align-items-center" rel="noreferrer noopener nofollow" target="_blank">
715
716 <?php echo wpstream_theme_get_svg_icon( 'x_twitter.svg' ); //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
717
718 <?php echo esc_html( $twitter_label ); ?>
719
720 </a>
721 <a href="<?php echo esc_url( $protocol . '://pinterest.com/pin/create/button/?url=' . $link . '&amp;media=' .
722 ( isset( $pinterest[0] ) ? esc_url( $pinterest[0] ) : '' ) .
723 '&amp;description=' . rawurlencode( get_the_title() ) ); ?>" target="_blank"
724 rel="noreferrer noopener nofollow" class="social_pinterest d-flex align-items-center">
725
726 <?php echo wpstream_theme_get_svg_icon( 'pinterest.svg' ); //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
727
728 <?php echo esc_html( $pinterest_label ); ?>
729
730 </a>
731 <a href="<?php echo esc_url( $whatsup_link ); ?>" class="social_whatsapp d-flex align-items-center"
732 rel="noreferrer noopener nofollow" target="_blank">
733
734 <?php echo wpstream_theme_get_svg_icon( 'whatsapp.svg' ); //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
735
736 <?php echo esc_html( $whatsup_label ); ?>
737
738 </a>
739 <a href="mailto:email@email.com?<?php echo esc_attr( trim( $email_link ) ); ?>" data-action="share email"
740 class="social_email d-flex align-items-center" rel="noreferrer noopener nofollow">
741
742 <?php echo wpstream_theme_get_svg_icon( 'email.svg' ); //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
743
744 <?php echo esc_html( $email_label ); ?>
745
746 </a>
747 </div>
748 <?php
749
750 return ob_get_clean();
751 }
752 }