PluginProbe
WPVR – 360 Panorama viewer and Virtual Tour Builder for WordPress / 9.1.1
WPVR – 360 Panorama viewer and Virtual Tour Builder for WordPress v9.1.1
9.1.3 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 All 222 releases
wpvr / legacy / public / classes / class-wpvr-shortcode.php

class-wpvr-shortcode.php in WPVR – 360 Panorama viewer and Virtual Tour Builder for WordPress 9.1.1, at legacy/public/classes/class-wpvr-shortcode.php

242 lines 7.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 if (!defined('ABSPATH')) exit; // Exit if accessed directly
3 /**
4 * Responsible for managing Shortcode on frontend
5 *
6 * @link http://rextheme.com/
7 * @since 8.0.0
8 *
9 * @package Wpvr
10 * @subpackage Wpvr/public/classes
11 */
12
13 class WPVR_Shortcode {
14
15 /**
16 * The ID of this plugin.
17 *
18 * @since 8.0.0
19 * @access private
20 * @var string $plugin_name The ID of this plugin.
21 */
22 private $plugin_name;
23
24 /**
25 * Post type for wpvr
26 *
27 * @var string
28 * @since 8.0.0
29 */
30 private $post_type = 'wpvr_item';
31
32 /**
33 * Instance of WPVR_StreetView class
34 *
35 * @var object
36 * @since 8.0.0
37 */
38 private $streetview;
39
40 /**
41 * Instance of WPVR_Video class
42 *
43 * @var object
44 * @since 8.0.0
45 */
46 private $video;
47
48 /**
49 * Instance of WPVR_Scene class
50 *
51 * @var object
52 * @since 8.0.0
53 */
54 private $scene;
55
56 function __construct($plugin_name)
57 {
58 $this->plugin_name = $plugin_name;
59 $this->streetview = new WPVR_StreetView();
60 $this->video = new WPVR_Video();
61 $this->scene = new WPVR_Scene();
62
63 add_filter('no_texturize_shortcodes', array($this, 'no_texturize_wpvr_shortcode'));
64 }
65
66 /**
67 * Prevent WordPress wptexturize from corrupting [wpvr] shortcode content
68 *
69 * @param array $tags
70 * @return array
71 */
72 public function no_texturize_wpvr_shortcode($tags)
73 {
74 $tags[] = 'wpvr';
75 return $tags;
76 }
77
78 /**
79 * Shortcode output for the plugin
80 *
81 * @param array $atts
82 *
83 * @return string
84 * @since 8.0.0
85 */
86 public function wpvr_shortcode($atts)
87 {
88
89 extract(
90 shortcode_atts(
91 array(
92 'id' => 0,
93 'slug' => '',
94 'width' => null,
95 'height' => null,
96 'mobile_height' => null,
97 'radius' => null
98 ),
99 $atts
100 )
101 );
102 $id = esc_attr($id);
103 $slug = esc_attr($slug);
104 $width = esc_attr($width);
105 $height = esc_attr($height);
106 $mobile_height = esc_attr($mobile_height);
107 $radius = esc_attr($radius);
108 if (!$id) {
109 $obj = get_page_by_path($slug, OBJECT, $this->post_type);
110 if ($obj) {
111 $id = $obj->ID;
112 } else {
113 return __('Invalid Wpvr slug attribute', 'wpvr');
114 }
115 }
116
117 do_action('rex_wpvr_embadded_tour', $id);
118
119 if (empty($mobile_height)) {
120 $mobile_height = "300px";
121 }
122 $get_post = get_post_status($id);
123
124 if (empty($get_post)) {
125 return wp_kses(
126 __('Oops! It seems that the entered tour doesn\'t exist. Please enter correct shortcode.<br>', 'wpvr'),
127 ['br' => []]
128 );
129 }
130
131 if ( $get_post !== 'publish' ) {
132 return esc_html__('Oops! It seems like this post isn\'t published yet. Stay tuned for updates!', 'wpvr') ;
133 }
134 if( post_password_required( $id ) ){
135 return get_the_password_form();
136 }
137
138
139 $memberpress_active = defined('MEPR_VERSION');
140 $rcp_active = is_plugin_active( 'restrict-content-pro/restrict-content-pro.php' );
141
142 if (($memberpress_active || $rcp_active ) && apply_filters('is_wpvr_pro_active', false)) {
143
144 if (!is_user_logged_in()) {
145 return esc_html__('You need to log in to access this content.', 'wpvr');
146 }
147
148 $user_id = get_current_user_id();
149 $allowed_access = false;
150
151 // Get saved membership levels from post meta
152 $allowed_membership_levels = get_post_meta($id, '_wpvr_allowed_roles_levels', true);
153 if ( isset($allowed_membership_levels) && 'none' !== $allowed_membership_levels ) {
154 if (!is_array($allowed_membership_levels)) {
155 $allowed_membership_levels = array($allowed_membership_levels);
156 }
157
158 // Check MemberPress Access
159 if ($memberpress_active) {
160 $user = new MeprUser($user_id);
161 $active_memberships = $user->active_product_subscriptions();
162 if (array_intersect($allowed_membership_levels, $active_memberships) ) {
163 $allowed_access = true;
164 }
165 }
166
167 // Check Restrict Content Pro Access
168 if ($rcp_active) {
169 $customer = rcp_get_customer_by_user_id($user_id);
170
171 if ($customer) { // Ensure customer exists
172 $user_rcp_memberships = $customer->get_memberships(); // Use method on customer object
173
174 if (!empty($user_rcp_memberships)) { // Ensure memberships exist
175 foreach ($user_rcp_memberships as $membership) {
176 $rcp_access_level = [$membership->get_object_id()];
177
178 if (array_intersect($allowed_membership_levels, $rcp_access_level)) {
179 $allowed_access = true;
180 break;
181 }
182 }
183 }
184 }
185 }
186
187 } else {
188 // If no membership restriction is set, allow access by default
189 $allowed_access = true;
190 }
191
192 if (!$allowed_access) {
193 return esc_html__('You do not have access to this content.', 'wpvr');
194 }
195 }
196
197 $postdata = get_post_meta($id, 'panodata', true);
198 $postdata = is_array( $postdata ) ? wpvr_get_effective_panodata( $postdata ) : [];
199
200 static $tour_instances = array();
201 $tour_instances[$id] = isset($tour_instances[$id]) ? $tour_instances[$id] + 1 : 1;
202 $instance_num = $tour_instances[$id];
203 $panoid = ($instance_num === 1) ? ('pano' . $id) : ('pano' . $id . '_' . $instance_num);
204
205 $tour_type = isset( $postdata['tour-type'] ) ? $postdata['tour-type'] : '';
206
207 if ( $tour_type === 'street-view' || ( $tour_type === '' && isset( $postdata['streetviewdata'] ) ) ) {
208 wpvr_enqueue_frontend_scripts( 'streetview' );
209 $html = $this->streetview->render_streetview_shortcode($postdata, $width, $height);
210 return $html;
211 }
212
213 if ( $tour_type === 'video' || ( $tour_type === '' && ( ! empty( $postdata['vidid'] ) || ! empty( $postdata['vidurl'] ) ) ) ) {
214 wpvr_enqueue_frontend_scripts( 'video' );
215 $html = $this->video->render_video_shortcode($postdata, $id, $width, $height, $radius);
216 return $html;
217 }
218
219 wpvr_enqueue_frontend_scripts( 'scene' );
220 $html = $this->scene->render_scene_shortcode($postdata, $panoid, $id, $radius, $width, $height, $mobile_height);
221
222 // Extract any <script> tags so they are not corrupted by wptexturize or the_content filters
223 $scripts = '';
224 if (preg_match_all('/<script\b[^>]*>[\s\S]*?<\/script>/i', $html, $matches)) {
225 $scripts = implode("\n", $matches[0]);
226 $html = preg_replace('/<script\b[^>]*>[\s\S]*?<\/script>/i', '', $html);
227 }
228
229 if (!empty($scripts)) {
230 if (wp_doing_ajax() || (defined('REST_REQUEST') && REST_REQUEST) || did_action('wp_footer')) {
231 $html .= "\n" . $scripts;
232 } else {
233 add_action('wp_footer', function() use ($scripts) {
234 echo $scripts; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
235 }, 20);
236 }
237 }
238
239 return $html;
240 }
241 }
242