PluginProbe
WPVR – 360 Panorama viewer and Virtual Tour Builder for WordPress / 9.0.2
WPVR – 360 Panorama viewer and Virtual Tour Builder for WordPress v9.0.2
9.1.2 9.1.1 9.1.0 9.0.3 9.0.2 9.0.1 9.0.0 8.5.79 8.5.78 8.5.77 8.5.76 8.5.75 8.5.74 8.5.73 8.5.72 8.5.71 8.5.70 8.5.69 8.5.68 8.5.35 8.5.36 8.5.37 8.5.38 8.5.39 8.5.4 All 221 releases
wpvr / src / Frontend / Shortcode.php

Shortcode.php in WPVR – 360 Panorama viewer and Virtual Tour Builder for WordPress 9.0.2, at src/Frontend/Shortcode.php

77 lines 3.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace RexTheme\WPVR\Frontend;
4
5 /**
6 * Standalone wrapper for the legacy WPVR_Shortcode class.
7 *
8 * Registers the [wpvr] shortcode via the legacy class.
9 * When using Frontend\Frontend, Wpvr_Public already creates WPVR_Shortcode internally;
10 * instantiate this class only when you need the shortcode without the full public stack.
11 */
12 class Shortcode {
13
14 private $legacy;
15 private $legacy_video;
16
17 public function __construct() {
18 require_once WPVR_PLUGIN_LEGACY_DIR_PATH . 'public/class-wpvr-public.php';
19 require_once WPVR_PLUGIN_LEGACY_DIR_PATH . 'public/classes/class-wpvr-shortcode.php';
20 $this->legacy = new \WPVR_Shortcode( 'wpvr' );
21 $this->legacy_video = new \WPVR_Video();
22 add_shortcode( 'wpvr', [ $this, 'wpvr_shortcode' ] );
23 }
24
25 public function wpvr_shortcode( $atts ) {
26 $parsed = shortcode_atts( [ 'id' => 0, 'slug' => '', 'width' => null, 'height' => null, 'radius' => null ], $atts );
27 $id = (int) $parsed['id'];
28
29 if ( ! $id && ! empty( $parsed['slug'] ) ) {
30 $obj = get_page_by_path( sanitize_text_field( $parsed['slug'] ), OBJECT, 'wpvr_item' );
31 $id = $obj ? $obj->ID : 0;
32 }
33
34 if ( $id ) {
35 $postdata = get_post_meta( $id, 'panodata', true );
36 $postdata = is_array( $postdata ) ? wpvr_get_effective_panodata( $postdata ) : [];
37 $tour_type = is_array( $postdata ) ? ( $postdata['tour-type'] ?? '' ) : '';
38
39 if ( $tour_type === 'street-view' && ! isset( $postdata['streetviewdata'] ) ) {
40 return $this->render_streetview( $postdata, $parsed );
41 }
42
43 if ( $tour_type === 'video' && ! isset( $postdata['vidid'] ) ) {
44 return $this->render_video( $postdata, $parsed, $id );
45 }
46 }
47
48 // Pass original $atts so legacy handler can extract all its own params (width, height, radius…).
49 return $this->legacy->wpvr_shortcode( $atts );
50 }
51
52 private function render_streetview( array $postdata, array $atts ) {
53 if ( function_exists( 'wpvr_enqueue_frontend_scripts' ) ) {
54 wpvr_enqueue_frontend_scripts( 'streetview' );
55 }
56 $width = ! empty( $atts['width'] ) ? esc_attr( $atts['width'] ) : '600px';
57 $height = ! empty( $atts['height'] ) ? esc_attr( $atts['height'] ) : '400px';
58 $url = esc_url( $postdata['streetviewurl'] ?? '' );
59
60 return '<div class="vr-streetview" style="text-align:center;max-width:100%;width:' . $width . ';height:' . $height . ';margin:0 auto;">'
61 . '<iframe src="' . $url . '" frameborder="0" style="border:0;width:100%;height:100%;" allowfullscreen=""></iframe>'
62 . '</div>';
63 }
64
65 private function render_video( array $postdata, array $atts, int $id ) {
66 $width = ! empty( $atts['width'] ) ? esc_attr( $atts['width'] ) : '600px';
67 $height = ! empty( $atts['height'] ) ? esc_attr( $atts['height'] ) : '400px';
68 $radius = ! empty( $atts['radius'] ) ? esc_attr( $atts['radius'] ) : null;
69
70 // New UI stores video-autoplay / video-loop; legacy renderer expects autoplay / loop.
71 $postdata['autoplay'] = $postdata['video-autoplay'] ?? 'off';
72 $postdata['loop'] = $postdata['video-loop'] ?? 'off';
73
74 return $this->legacy_video->render_video_shortcode( $postdata, $id, $width, $height, $radius );
75 }
76 }
77