PluginProbe
WpStream – Live Streaming, Video on Demand, Pay Per View / 4.8.2
WpStream – Live Streaming, Video on Demand, Pay Per View v4.8.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.8.2, at hello-wpstream/framework/wpstream-help-functions.php

751 lines 24.9 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 'subscriptions' => wpstream_theme_get_svg_icon('orders-subscription.svg'),
492 'edit-address' => wpstream_theme_get_svg_icon('location-icon.svg'),
493 'edit-account' => wpstream_theme_get_svg_icon('edit-account-icon.svg'),
494 'event-list' => wpstream_theme_get_svg_icon('purchased-events-icon.svg'),
495 'video-list' => wpstream_theme_get_svg_icon('purchased-video-icon.svg'),
496 'start-streaming' => wpstream_theme_get_svg_icon('go-to-live-icon.svg'),
497 'watch-later' => wpstream_theme_get_svg_icon('watch-later-icon.svg'),
498 'customer-logout' => wpstream_theme_get_svg_icon('logout_icon.svg'),
499 'logout' => wpstream_theme_get_svg_icon('logout_icon.svg'),
500 ];
501
502 ob_start();
503
504 if ( function_exists( 'wc_get_account_menu_items' ) ) {
505 $menu_items = wc_get_account_menu_items();
506
507 if ( ! wpstream_check_if_user_can_stream()) {
508 unset($menu_items['start-streaming']);
509 }
510
511 foreach ( $menu_items as $endpoint => $label ) :
512 $menu_link= wc_get_account_endpoint_url( $endpoint ) ;
513 if($endpoint === 'subscriptions') {
514 $menu_link = home_url('/dashboard/subscriptions/');
515 }
516 ?>
517 <a href="<?php echo esc_url($menu_link); ?>" class="list-group-item list-group-item-action wpstream-account-item-<?php echo esc_attr( $endpoint ); ?>">
518 <?php echo isset($svg_icons[$endpoint]) ? trim($svg_icons[$endpoint]) : ''; ?>
519 <?php echo trim( esc_html( $label ));?>
520 </a>
521 <?php
522 endforeach;
523
524 } else {
525 $menu_items = array(
526 'dashboard' => esc_html__( 'Dashboard', 'hello-wpstream' ),
527 'start-streaming' => esc_html__( 'Go Live', 'hello-wpstream' ),
528 'edit-account' => esc_html__( 'Edit Account', 'hello-wpstream' ),
529 'watch-later' => esc_html__( 'Watch Later', 'hello-wpstream' ),
530 'logout' => esc_html__( 'Logout', 'hello-wpstream' ),
531 );
532
533 if ( ! wpstream_check_if_user_can_stream()) {
534 unset($menu_items['start-streaming']);
535 }
536
537 foreach ( $menu_items as $endpoint => $label ) :
538 $item_link = wpstream_non_woo_get_account_endpoint_url( $endpoint );
539 if ( 'logout' === $endpoint ) {
540 $item_link = wp_logout_url( home_url() );
541 }
542 ?>
543
544 <a href="<?php echo esc_url( $item_link ); ?>"
545 class="list-group-item list-group-item-action wpstream-account-item-<?php echo esc_attr( $endpoint ); ?>">
546 <?php echo trim($svg_icons[ $endpoint ]) ?? ''; ?>
547 <?php echo esc_html( $label ); ?>
548 </a>
549 <?php
550
551 endforeach;
552
553 }
554
555 $return_string = ob_get_contents();
556
557 ob_end_clean();
558
559 return $return_string;
560 }
561 }
562
563 if ( ! function_exists( 'wpstream_dashboard_get_products_by_user' ) ) {
564 /**
565 * Retrieve products purchased by a specific user.
566 *
567 * Retrieves all products of a specific type (default: 'video_on_demand') purchased by a user.
568 *
569 * @param int $user_id The ID of the user.
570 * @param string $product_type The type of products to retrieve. Default is 'video_on_demand'.
571 * @param int $page Optional. The page number of the results. Default is 1.
572 * @param int $per_page Optional. The number of products to retrieve per page. Default is 10.
573 * @return array An array containing paginated products, total number of products, and maximum number of pages.
574 */
575 function wpstream_dashboard_get_products_by_user( $user_id, $product_type = 'video_on_demand', $page = 1, $per_page = 10 ) {
576 $all_products = array();
577
578 // Get all customer orders.
579 $customer_orders = wc_get_orders(
580 array(
581 'customer_id' => $user_id,
582 'status' => 'completed',
583 'limit' => -1
584 )
585 );
586
587 // Loop through each customer order.
588 foreach ( $customer_orders as $customer_order ) {
589 $order_items = $customer_order->get_items();
590 $order = wc_get_order( $customer_order );
591 $order_id = $order->get_id();
592 $order_date = $order->get_date_created();
593 $formatted_date = wc_format_datetime( $order_date );
594
595 foreach ( $order_items as $item ) {
596 $product = $item->get_product();
597
598 if ( $product && $product_type === $product->get_type() ) {
599 $total_paid = $item->get_total();
600 $temp_array = array(
601 'price' => $total_paid,
602 'order_id' => $order_id,
603 'order_date' => $formatted_date,
604 'product' => $product,
605 );
606
607 $all_products[$product->get_id()] = $temp_array;
608 }
609 }
610 }
611
612 if(intval($per_page) === -1){
613 return $all_products;
614 }
615
616 // Calculate offset for pagination.
617 $offset = ( $page - 1 ) * $per_page;
618 $paginated_products = array_slice( $all_products, $offset, $per_page );
619
620 return array(
621 'products' => $paginated_products,
622 'total' => count( $all_products ),
623 'max_num_pages' => ceil( count( $all_products ) / $per_page ),
624 );
625 }
626 }
627
628 if ( ! function_exists( 'wpstream_non_woo_get_account_endpoint_url' ) ) {
629 /**
630 * Retrieves the URL for a given account endpoint.
631 *
632 * @param string $endpoint Optional. Endpoint to append to the URL.
633 * @return string URL for the account endpoint.
634 */
635 function wpstream_non_woo_get_account_endpoint_url( $endpoint = '' ) {
636 $url = wpstream_return_dashboard_page();
637
638 if ( $endpoint ) {
639 $url = add_query_arg( 'endpoint', $endpoint, $url );
640 }
641
642 return esc_url_raw( $url );
643 }
644 }
645
646 if ( ! function_exists( 'wpstream_theme_show_social_share_page' ) ) {
647 /**
648 * Display social share buttons for a given post.
649 *
650 * @param int $post_id The ID of the post.
651 * @param string $size Optional. The size of the post image. Default is 'full'.
652 * @param int $is_single Optional. Whether the post is single or not. Default is 1 (true).
653 * @return string The HTML markup for the social share buttons.
654 */
655 function wpstream_theme_show_social_share_page( $post_id, $size = 'full', $is_single = 1 ) {
656 $return_string = '<div class="wpstream-social-share-wrapper">';
657 $return_string .= wpstream_share_unit_desing( $post_id, $size, $is_single );
658 $return_string .= '</div>';
659
660 return $return_string;
661 }
662 }
663
664 if ( ! function_exists( 'wpstream_share_unit_desing' ) ) {
665 /**
666 * Generate social share buttons HTML for a post.
667 *
668 * @param int $post_id The ID of the post.
669 * @param string $size Optional. The size of the post image. Default is 'full'.
670 * @param int $is_single Optional. Whether the post is single or not. Default is 0 (false).
671 * @return string The HTML markup for the social share buttons.
672 */
673 function wpstream_share_unit_desing( $post_id, $size = 'full', $is_single = 0 ) {
674 $protocol = is_ssl() ? 'https' : 'http';
675 $pinterest = wp_get_attachment_image_src( get_post_thumbnail_id( $post_id ), $size );
676 $link = esc_url( get_permalink( $post_id ) );
677 $title = get_the_title( $post_id );
678 $twitter_status = rawurlencode( $title . ' ' . $link );
679 $email_link = 'subject=' . rawurlencode( $title ) . '&body=' . rawurlencode( esc_url( $link ) );
680
681 ob_start();
682
683 $facebook_label = '';
684 $twitter_label = '';
685 $pinterest_label = '';
686 $whatsup_label = '';
687 $email_label = '';
688
689 if ( intval( $is_single ) === 1 ) {
690 $facebook_label = esc_html__( 'Facebook', 'hello-wpstream' );
691 $twitter_label = esc_html__( 'Twitter', 'hello-wpstream' );
692 $pinterest_label = esc_html__( 'Pinterest', 'hello-wpstream' );
693 $whatsup_label = esc_html__( 'WhatsApp', 'hello-wpstream' );
694 $email_label = esc_html__( 'Email', 'hello-wpstream' );
695 }
696
697 $text_whats = get_the_title( $post_id ) . ' ' . esc_url( get_permalink( $post_id ) );
698
699 $whatsup_link = 'https://wa.me/?text=' . ( $text_whats );
700
701 ?>
702
703 <div class="share_unit">
704 <a href="<?php echo esc_url( $protocol . '://www.facebook.com/sharer.php?u=' . $link . '&amp;t=' . rawurlencode( get_the_title() ) ); ?>"
705 target="_blank" rel="noreferrer noopener nofollow" class="social_facebook d-flex align-items-center">
706
707 <?php echo wpstream_theme_get_svg_icon( 'facebook.svg' ); //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
708
709 <?php echo esc_html( $facebook_label ); ?>
710
711 </a>
712 <a href="<?php echo esc_url( $protocol . '://twitter.com/intent/tweet?text=' . $twitter_status ); ?>"
713 class="social_twitter d-flex align-items-center" rel="noreferrer noopener nofollow" target="_blank">
714
715 <?php echo wpstream_theme_get_svg_icon( 'x_twitter.svg' ); //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
716
717 <?php echo esc_html( $twitter_label ); ?>
718
719 </a>
720 <a href="<?php echo esc_url( $protocol . '://pinterest.com/pin/create/button/?url=' . $link . '&amp;media=' .
721 ( isset( $pinterest[0] ) ? esc_url( $pinterest[0] ) : '' ) .
722 '&amp;description=' . rawurlencode( get_the_title() ) ); ?>" target="_blank"
723 rel="noreferrer noopener nofollow" class="social_pinterest d-flex align-items-center">
724
725 <?php echo wpstream_theme_get_svg_icon( 'pinterest.svg' ); //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
726
727 <?php echo esc_html( $pinterest_label ); ?>
728
729 </a>
730 <a href="<?php echo esc_url( $whatsup_link ); ?>" class="social_whatsapp d-flex align-items-center"
731 rel="noreferrer noopener nofollow" target="_blank">
732
733 <?php echo wpstream_theme_get_svg_icon( 'whatsapp.svg' ); //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
734
735 <?php echo esc_html( $whatsup_label ); ?>
736
737 </a>
738 <a href="mailto:email@email.com?<?php echo esc_attr( trim( $email_link ) ); ?>" data-action="share email"
739 class="social_email d-flex align-items-center" rel="noreferrer noopener nofollow">
740
741 <?php echo wpstream_theme_get_svg_icon( 'email.svg' ); //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
742
743 <?php echo esc_html( $email_label ); ?>
744
745 </a>
746 </div>
747 <?php
748
749 return ob_get_clean();
750 }
751 }