PluginProbe
WPVR – 360 Panorama viewer and Virtual Tour Builder for WordPress / 8.5.35
WPVR – 360 Panorama viewer and Virtual Tour Builder for WordPress v8.5.35
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 / elementor / elements / Wpvr-widget.php

Wpvr-widget.php in WPVR – 360 Panorama viewer and Virtual Tour Builder for WordPress 8.5.35, at elementor/elements/Wpvr-widget.php

289 lines 7.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace WpvrElement\Elements\Wpvr;
4
5 use Elementor\Controls_Stack;
6 use Elementor\Widget_Base;
7 use Elementor\Controls_Manager;
8
9
10 if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
11
12 /**
13 *
14 * Elementor widget for WPVR
15 *
16 * @since 1.0.0
17 */
18 class Wpvr_Widget extends Widget_Base {
19
20 /**
21 * Retrieve the widget name.
22 *
23 * @since 1.0.0
24 *
25 * @access public
26 *
27 * @return string Widget name.
28 */
29 public function get_name() {
30 return 'Wpvr-widget';
31 }
32
33 /**
34 * Retrieve the widget title.
35 *
36 * @since 1.0.0
37 *
38 * @access public
39 *
40 * @return string Widget title.
41 */
42 public function get_title() {
43 return __( 'WPVR', 'wpvr' );
44 }
45
46 /**
47 * Retrieve the widget icon.
48 *
49 * @since 1.0.0
50 *
51 * @access public
52 *
53 * @return string Widget icon.
54 */
55 public function get_icon() {
56 return 'icon-wpvrtourmake_icon';
57 }
58
59 /**
60 * Retrieve the list of categories the widget belongs to.
61 *
62 * Used to determine where to display the widget in the editor.
63 *
64 * Note that currently Elementor supports only one category.
65 * When multiple categories passed, Elementor uses the first one.
66 *
67 * @since 1.0.0
68 *
69 * @access public
70 *
71 * @return array Widget categories.
72 */
73 public function get_categories() {
74 return [ 'general' ];
75 }
76
77 /**
78 * Retrieve the list of scripts the widget depended on.
79 *
80 * Used to set scripts dependencies required to run the widget.
81 *
82 * @since 1.0.0
83 *
84 * @access public
85 *
86 * @return array Widget scripts dependencies.
87 */
88 public function get_script_depends() {
89 return [ 'Wpvr-widget' ];
90 }
91
92
93 /**
94 * Register the widget controls.
95 *
96 * Adds different input fields to allow the user to change and Wpvrize the widget settings.
97 *
98 * @since 1.0.0
99 *
100 * @access protected
101 */
102 protected function init_controls() {
103 if ( version_compare(ELEMENTOR_VERSION, '3.1.0', '>=') ) {
104 $this->register_controls();
105 } else {
106 $this->_register_controls();
107 }
108 }
109
110 protected function _register_controls() {
111 $this->wpvr_shortcode_controls();
112 }
113
114 protected function register_controls() {
115 $this->wpvr_shortcode_controls();
116 }
117
118 /**
119 * Register shortcode Controls.
120 *
121 * @access protected
122 */
123 protected function wpvr_shortcode_controls(){
124
125 /**
126 *
127 * get all tour info and store in $wpvr_post
128 */
129 $the_posts = get_posts(array('post_type' => 'wpvr_item',
130 'posts_per_page' => -1));
131
132 $wpvr_post = array();
133
134 foreach($the_posts as $post){
135 if($post->post_title){
136 $wpvr_post[$post->ID] = $post->post_title.' : '.$post->ID;
137 }else{
138 $wpvr_post[$post->ID] = 'No title' .' : '.$post->ID;
139 }
140 }
141
142 $this->start_controls_section(
143 'section_content',
144 [
145 'label' => __( 'WPVR Setup', 'wpvr' ),
146 ]
147 );
148
149 /**
150 *
151 * add a select type field instead of text field
152 */
153 $this->add_control(
154 'vr_id',
155 [
156 'label' => __( 'Select Tour:', 'wpvr' ),
157 'type' => \Elementor\Controls_Manager::SELECT,
158 'options' => $wpvr_post
159 ]
160 );
161
162 $this->add_control(
163 'vr_width',
164 [
165 'label' => __( 'Width:', 'wpvr' ),
166 'type' => Controls_Manager::TEXT,
167 'input_type' => 'text',
168 'placeholder' => __( 'Put value in PX', 'wpvr' ),
169 ]
170 );
171
172 $this->add_control(
173 'vr_height',
174 [
175 'label' => __( 'Height:', 'wpvr' ),
176 'type' => Controls_Manager::TEXT,
177 'input_type' => 'text',
178 'placeholder' => __( 'Put value in PX', 'wpvr' ),
179 ]
180 );
181
182 $this->add_control(
183 'vr_radius',
184 [
185 'label' => __( 'Radius:', 'wpvr' ),
186 'type' => Controls_Manager::TEXT,
187 'input_type' => 'text',
188 'placeholder' => __( 'Put value in PX', 'wpvr' ),
189 ]
190 );
191
192 $this->add_control(
193 'vr_mobile',
194 [
195 'label' => __('Mobile Height', 'wpvr'),
196 'type' => Controls_Manager::TEXT,
197 'placeholder' => __( 'Put value in PX', 'wpvr' ),
198 ]
199 );
200
201
202 $this->end_controls_section();
203
204 }
205
206 /**
207 * Render the widget output on the frontend.
208 *
209 * Written in PHP and used to generate the final HTML.
210 *
211 * @since 1.0.0
212 *
213 * @access protected
214 */
215 protected function render() {
216 $settings = $this->get_settings_for_display();
217
218 $id = $settings['vr_id'] ?? 0;
219 $width = $settings['vr_width'] ?? "600px";
220 $height = $settings['vr_height'] ?? "400px";
221 $radius = $settings['vr_radius'] ?? "0px";
222 $mobile_height = $settings['vr_mobile'] ?? "300px";
223
224 // Ensure dimensions have 'px' if missing
225 foreach (['width', 'height', 'radius', 'mobile_height'] as $key) {
226 if (!empty($$key) && strpos($$key, 'px') === false) {
227 $$key .= 'px';
228 }
229 }
230
231 if ($id) {
232 echo do_shortcode('[wpvr id="'.$id.'" width="'.$width.'" height="'.$height.'" radius="'.$radius.'" mobile_height="'.$mobile_height.'"]');
233 }
234 }
235
236
237 /**
238 * Print element template.
239 *
240 * Used to generate the element template on the editor.
241 *
242 * @since 2.0.0
243 * @access public
244 */
245 public function print_template() {
246 ob_start();
247
248 if ( version_compare(ELEMENTOR_VERSION, '3.1.0', '>=') ) {
249 $this->content_template();
250 } else {
251 $this->_content_template();
252 }
253
254 $template_content = ob_get_clean();
255
256 $element_type = $this->get_type();
257
258 /**
259 * Template content.
260 *
261 * Filters the controls stack template content before it's printed in the editor.
262 *
263 * The dynamic portion of the hook name, `$element_type`, refers to the element type.
264 *
265 * @since 1.0.0
266 *
267 * @param string $content_template The controls stack template in the editor.
268 * @param Controls_Stack $this The controls stack.
269 */
270 $template_content = apply_filters( "elementor/{$element_type}/print_template", $template_content, $this );
271
272 if ( empty( $template_content ) ) {
273 return;
274 }
275 ?>
276 <script type="text/html" id="tmpl-elementor-<?php echo esc_attr( $this->get_name() ); ?>-content">
277 <?php $this->print_template_content( $template_content ); ?>
278 </script>
279
280 <?php
281 }
282 protected function _content_template() {
283
284 }
285 protected function content_template() {
286
287 }
288 }
289