| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* Server-side renderer for the WP VR Breakdance element. |
| 5 |
* |
| 6 |
* @var array $propertiesData |
| 7 |
*/ |
| 8 |
|
| 9 |
$settings = $propertiesData['content']['wpvr'] ?? []; |
| 10 |
$tour_id = absint( $settings['tour'] ?? 0 ); |
| 11 |
|
| 12 |
if ( ! $tour_id ) { |
| 13 |
echo '<p>' . esc_html__( 'No tour has been selected.', 'wpvr' ) . '</p>'; |
| 14 |
return true; |
| 15 |
} |
| 16 |
|
| 17 |
$to_pixels = static function ( $value, $default ) { |
| 18 |
if ( '' === $value || null === $value || ! is_numeric( $value ) ) { |
| 19 |
$value = $default; |
| 20 |
} |
| 21 |
|
| 22 |
return max( 0, (float) $value ) . 'px'; |
| 23 |
}; |
| 24 |
|
| 25 |
$width = $to_pixels( $settings['width'] ?? null, 600 ); |
| 26 |
$height = $to_pixels( $settings['height'] ?? null, 400 ); |
| 27 |
$mobile_height = $to_pixels( $settings['mobile_height'] ?? null, 300 ); |
| 28 |
$radius = $to_pixels( $settings['radius'] ?? null, 0 ); |
| 29 |
|
| 30 |
$shortcode = sprintf( |
| 31 |
'[wpvr id="%d" width="%s" height="%s" mobile_height="%s" radius="%s"]', |
| 32 |
$tour_id, |
| 33 |
esc_attr( $width ), |
| 34 |
esc_attr( $height ), |
| 35 |
esc_attr( $mobile_height ), |
| 36 |
esc_attr( $radius ) |
| 37 |
); |
| 38 |
|
| 39 |
$html = do_shortcode( $shortcode ); |
| 40 |
|
| 41 |
if ( function_exists( '\Breakdance\isRequestFromBuilderSsr' ) && \Breakdance\isRequestFromBuilderSsr() ) { |
| 42 |
// Scripts inserted through Breakdance's AJAX SSR are inert. The element's |
| 43 |
// builder action executes these after its preview dependencies are ready. |
| 44 |
$html = str_replace( |
| 45 |
'<script>', |
| 46 |
'<script type="application/wpvr-breakdance-preview">', |
| 47 |
$html |
| 48 |
); |
| 49 |
} |
| 50 |
|
| 51 |
echo $html; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 52 |
|
| 53 |
return true; |
| 54 |
|