| 1 |
<?php |
| 2 |
/** |
| 3 |
* This file is part of the WPVR module for DIVI Builders which enhances WordPress sites |
| 4 |
* with virtual reality content management capabilities. |
| 5 |
* |
| 6 |
* @package WPVR\Builder\DIVI\Modules |
| 7 |
*/ |
| 8 |
|
| 9 |
namespace WPVR\Builder\DIVI\Modules; |
| 10 |
|
| 11 |
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly |
| 12 |
|
| 13 |
use ET_Builder_Module; |
| 14 |
|
| 15 |
/** |
| 16 |
* Class WPVR_Tour |
| 17 |
* Handles the creation and functionality of the WPVR Tour module within the DIVI Builder. |
| 18 |
* |
| 19 |
* @since 8.4.8 |
| 20 |
*/ |
| 21 |
class WPVR_Tour extends ET_Builder_Module { |
| 22 |
|
| 23 |
/** |
| 24 |
* Module slug identifier. |
| 25 |
* |
| 26 |
* @var string |
| 27 |
*/ |
| 28 |
public $slug = 'wpvr_divi'; |
| 29 |
|
| 30 |
/** |
| 31 |
* Visual Builder support status. |
| 32 |
* |
| 33 |
* @var string |
| 34 |
*/ |
| 35 |
public $vb_support = 'on'; |
| 36 |
|
| 37 |
/** |
| 38 |
* Module icon path. |
| 39 |
* |
| 40 |
* @var string |
| 41 |
*/ |
| 42 |
public $icon_path; |
| 43 |
|
| 44 |
/** |
| 45 |
* Credits for the module, typically including author information. |
| 46 |
* |
| 47 |
* @var array |
| 48 |
*/ |
| 49 |
protected $module_credits = array( |
| 50 |
'module_uri' => '', |
| 51 |
'author' => '', |
| 52 |
'author_uri' => '', |
| 53 |
); |
| 54 |
/** |
| 55 |
* Initializes module properties such as name and settings toggles. |
| 56 |
* |
| 57 |
* @since 8.4.8 |
| 58 |
*/ |
| 59 |
public function init() { |
| 60 |
$this->name = esc_html__( 'WPVR', 'wpvr' ); |
| 61 |
$this->icon_path = plugin_dir_path( __FILE__ ) . 'VR.svg'; |
| 62 |
|
| 63 |
$this->settings_modal_toggles = array( |
| 64 |
'general' => array( |
| 65 |
'toggles' => array( |
| 66 |
'main_content' => __( 'WPVR', 'wpvr' ), |
| 67 |
), |
| 68 |
), |
| 69 |
); |
| 70 |
$this->main_css_element = '%%order_class%%'; |
| 71 |
} |
| 72 |
|
| 73 |
/** |
| 74 |
* Retrieves the configuration for advanced fields. |
| 75 |
* This method typically returns settings specific to this module that enhance or modify its behavior. |
| 76 |
* |
| 77 |
* @since 8.4.8 |
| 78 |
* @return array Advanced fields configuration. |
| 79 |
*/ |
| 80 |
public function get_advanced_fields_config() { |
| 81 |
|
| 82 |
$advanced_fields = array(); |
| 83 |
|
| 84 |
return $advanced_fields; |
| 85 |
} |
| 86 |
|
| 87 |
/** |
| 88 |
* Retrieves all active tours. |
| 89 |
* This function fetches all posts of type 'wpvr_item' and prepares them for use in the module. |
| 90 |
* |
| 91 |
* @since 8.4.8 |
| 92 |
* @return array Associative array of posts where the key is the post ID and the value is the post title. |
| 93 |
*/ |
| 94 |
public function get_all_tour() { |
| 95 |
$the_posts = get_posts( |
| 96 |
array( |
| 97 |
'post_type' => 'wpvr_item', |
| 98 |
'posts_per_page' => -1, |
| 99 |
'orderby' => 'DESC', |
| 100 |
|
| 101 |
) |
| 102 |
); |
| 103 |
|
| 104 |
$wpvr_post = array( |
| 105 |
'0' => 'none', |
| 106 |
); |
| 107 |
|
| 108 |
foreach ( $the_posts as $post ) { |
| 109 |
if ( $post->post_title ) { |
| 110 |
$wpvr_post[ $post->ID ] = $post->post_title . ' : ' . $post->ID; |
| 111 |
} else { |
| 112 |
$wpvr_post[ $post->ID ] = 'No title' . ' : ' . $post->ID; //phpcs:ignore |
| 113 |
} |
| 114 |
} |
| 115 |
return $wpvr_post; |
| 116 |
} |
| 117 |
|
| 118 |
/** |
| 119 |
* Returns the fields for the module. |
| 120 |
* This method specifies the options available to users in the module settings. |
| 121 |
* |
| 122 |
* @since 8.4.8 |
| 123 |
* @return array Configuration for fields. |
| 124 |
*/ |
| 125 |
public function get_fields() { |
| 126 |
return array( |
| 127 |
'vr_id' => array( |
| 128 |
'label' => esc_html__( 'Select Tour', 'wpvr' ), |
| 129 |
'description' => esc_html__( 'WPVR Tour ID', 'wpvr' ), |
| 130 |
'type' => 'select', |
| 131 |
'options' => $this->get_all_tour(), |
| 132 |
'priority' => 80, |
| 133 |
'default' => '0', |
| 134 |
'default_on_front' => '0', |
| 135 |
'toggle_slug' => 'main_content', |
| 136 |
'sub_toggle' => 'ul', |
| 137 |
'mobile_options' => true, |
| 138 |
), |
| 139 |
'vr_width' => array( |
| 140 |
'label' => __( 'Tour Width', 'wpvr' ), |
| 141 |
'description' => __( 'WPVR Width', 'wpvr' ), |
| 142 |
'type' => 'text', |
| 143 |
'default' => '600', |
| 144 |
'default_on_front' => '600', |
| 145 |
'toggle_slug' => 'main_content', |
| 146 |
'show_if' => array( |
| 147 |
'vr_fullwidth' => 'no', |
| 148 |
), |
| 149 |
), |
| 150 |
'vr_width_unit' => array( |
| 151 |
'label' => esc_html__( 'Tour Width Unit', 'wpvr' ), |
| 152 |
'description' => esc_html__( 'Width Unit', 'wpvr' ), |
| 153 |
'type' => 'select', |
| 154 |
'options' => array( |
| 155 |
'px' => __( 'px', 'wpvr' ), |
| 156 |
'%' => __( '%', 'wpvr' ), |
| 157 |
'vw' => __( 'vw', 'wpvr' ), |
| 158 |
), |
| 159 |
'default' => 'px', |
| 160 |
'default_on_front' => 'px', |
| 161 |
'toggle_slug' => 'main_content', |
| 162 |
'sub_toggle' => 'ul', |
| 163 |
'mobile_options' => true, |
| 164 |
'show_if' => array( |
| 165 |
'vr_fullwidth' => 'no', |
| 166 |
), |
| 167 |
), |
| 168 |
'vr_fullwidth' => array( |
| 169 |
'label' => esc_html__( 'Tour Fullwidth', 'wpvr' ), |
| 170 |
'description' => esc_html__( 'Fullwidth', 'wpvr' ), |
| 171 |
'type' => 'select', |
| 172 |
'options' => array( |
| 173 |
'yes' => __( 'Yes', 'wpvr' ), |
| 174 |
'no' => __( 'No', 'wpvr' ), |
| 175 |
), |
| 176 |
'default' => 'no', |
| 177 |
'default_on_front' => 'no', |
| 178 |
'toggle_slug' => 'main_content', |
| 179 |
'sub_toggle' => 'ul', |
| 180 |
'mobile_options' => true, |
| 181 |
), |
| 182 |
|
| 183 |
'vr_height' => array( |
| 184 |
'label' => __( 'Tour Height', 'wpvr' ), |
| 185 |
'description' => __( 'WPVR Height', 'wpvr' ), |
| 186 |
'type' => 'text', |
| 187 |
'default' => '400', |
| 188 |
'default_on_front' => '400', |
| 189 |
'toggle_slug' => 'main_content', |
| 190 |
), |
| 191 |
'vr_height_unit' => array( |
| 192 |
'label' => esc_html__( 'Tour Height Unit', 'wpvr' ), |
| 193 |
'description' => esc_html__( 'Height Unit', 'wpvr' ), |
| 194 |
'type' => 'select', |
| 195 |
'options' => array( |
| 196 |
'px' => __( 'px', 'wpvr' ), |
| 197 |
'vh' => __( 'vh', 'wpvr' ), |
| 198 |
), |
| 199 |
'default' => 'px', |
| 200 |
'default_on_front' => 'px', |
| 201 |
'toggle_slug' => 'main_content', |
| 202 |
'sub_toggle' => 'ul', |
| 203 |
'mobile_options' => true, |
| 204 |
), |
| 205 |
'vr_mobile_height' => array( |
| 206 |
'label' => __( 'Tour Mobile Height', 'wpvr' ), |
| 207 |
'description' => __( 'WPVR Mobile Height', 'wpvr' ), |
| 208 |
'type' => 'text', |
| 209 |
'default' => '300', |
| 210 |
'default_on_front' => '300', |
| 211 |
'toggle_slug' => 'main_content', |
| 212 |
), |
| 213 |
'vr_mobile_height_unit' => array( |
| 214 |
'label' => esc_html__( 'Tour Mobile Height Unit', 'wpvr' ), |
| 215 |
'description' => esc_html__( 'Mobile Height Unit', 'wpvr' ), |
| 216 |
'type' => 'select', |
| 217 |
'options' => array( |
| 218 |
'px' => __( 'px', 'wpvr' ), |
| 219 |
), |
| 220 |
'default' => 'px', |
| 221 |
'default_on_front' => 'px', |
| 222 |
'toggle_slug' => 'main_content', |
| 223 |
'sub_toggle' => 'ul', |
| 224 |
'mobile_options' => true, |
| 225 |
), |
| 226 |
|
| 227 |
'vr_radius' => array( |
| 228 |
'label' => __( 'Tour Radius', 'wpvr' ), |
| 229 |
'description' => __( 'WPVR Radius', 'wpvr' ), |
| 230 |
'type' => 'text', |
| 231 |
'default' => '0', |
| 232 |
'default_on_front' => '0', |
| 233 |
'toggle_slug' => 'main_content', |
| 234 |
), |
| 235 |
'vr_radius_unit' => array( |
| 236 |
'label' => esc_html__( 'Tour Radius Unit', 'wpvr' ), |
| 237 |
'description' => esc_html__( 'Radius Unit', 'wpvr' ), |
| 238 |
'type' => 'select', |
| 239 |
'options' => array( |
| 240 |
'px' => __( 'px', 'wpvr' ), |
| 241 |
), |
| 242 |
'default' => 'px', |
| 243 |
'default_on_front' => 'px', |
| 244 |
'toggle_slug' => 'main_content', |
| 245 |
'sub_toggle' => 'ul', |
| 246 |
'mobile_options' => true, |
| 247 |
), |
| 248 |
|
| 249 |
|
| 250 |
); |
| 251 |
} |
| 252 |
|
| 253 |
/** |
| 254 |
* Renders the WPVR module based on provided attributes. |
| 255 |
* This function is responsible for generating the frontend output of the module. |
| 256 |
* |
| 257 |
* @since 8.4.8 |
| 258 |
* @param array $props Attributes and settings for the module instance. |
| 259 |
* @return string Rendered HTML output of the module. |
| 260 |
*/ |
| 261 |
public static function wpvr_render( $props ) { |
| 262 |
$id = 0; |
| 263 |
$width = '600px'; |
| 264 |
$height = '400px'; |
| 265 |
$radius = '0px'; |
| 266 |
$id = $props['vr_id']; |
| 267 |
$width = $props['vr_width'] . $props['vr_width_unit']; |
| 268 |
$height = $props['vr_height'] . $props['vr_height_unit']; |
| 269 |
$radius = $props['vr_radius'] . $props['vr_radius_unit']; |
| 270 |
$vr_mobile_height = $props['vr_mobile_height'] . $props['vr_mobile_height_unit']; |
| 271 |
if ( empty( $width ) ) { |
| 272 |
$width = '600px'; |
| 273 |
} |
| 274 |
if ( 'yes' === $props['vr_fullwidth'] ) { |
| 275 |
$width = 'fullwidth'; |
| 276 |
} |
| 277 |
if ( empty( $height ) ) { |
| 278 |
$height = '400px'; |
| 279 |
} |
| 280 |
if ( empty( $radius ) ) { |
| 281 |
$radius = '0px'; |
| 282 |
} |
| 283 |
if ( empty( $vr_mobile_height ) ) { |
| 284 |
$vr_mobile_height = '300px'; |
| 285 |
} |
| 286 |
if ( $id ) { |
| 287 |
ob_start(); |
| 288 |
echo do_shortcode( '[wpvr id="' . $id . '" width="' . $width . '" height="' . $height . '" radius="' . $radius . '" mobile_height="' . $vr_mobile_height . '"]' ); |
| 289 |
return ob_get_clean(); |
| 290 |
} |
| 291 |
} |
| 292 |
|
| 293 |
/** |
| 294 |
* Outputs the final rendered HTML for the module. |
| 295 |
* This method is a wrapper that outputs the result of the rendering logic defined in wpvr_render. |
| 296 |
* |
| 297 |
* @since 8.4.8 |
| 298 |
* @param array $attrs Attributes passed to the module, typically from the shortcode or DIVI builder interface. |
| 299 |
* @param string|null $content Optional. Content included within the shortcode, if any. |
| 300 |
* @param string $render_slug Slug identifier for this module instance. |
| 301 |
* @return string Rendered output to be displayed on the frontend. |
| 302 |
*/ |
| 303 |
public function render( $attrs, $content = null, $render_slug = null ) { |
| 304 |
$output = self::wpvr_render( $this->props ); |
| 305 |
return $output; |
| 306 |
} |
| 307 |
} |
| 308 |
|
| 309 |
new WPVR_Tour(); |
| 310 |
|