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