| 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 |
* Instance of WPVR_StreetView class |
| 26 |
* |
| 27 |
* @var object |
| 28 |
* @since 8.0.0 |
| 29 |
*/ |
| 30 |
private $streetview; |
| 31 |
|
| 32 |
/** |
| 33 |
* Instance of WPVR_Video class |
| 34 |
* |
| 35 |
* @var object |
| 36 |
* @since 8.0.0 |
| 37 |
*/ |
| 38 |
private $video; |
| 39 |
|
| 40 |
/** |
| 41 |
* Instance of WPVR_Scene class |
| 42 |
* |
| 43 |
* @var object |
| 44 |
* @since 8.0.0 |
| 45 |
*/ |
| 46 |
private $scene; |
| 47 |
|
| 48 |
function __construct($plugin_name) |
| 49 |
{ |
| 50 |
$this->plugin_name = $plugin_name; |
| 51 |
$this->streetview = new WPVR_StreetView(); |
| 52 |
$this->video = new WPVR_Video(); |
| 53 |
$this->scene = new WPVR_Scene(); |
| 54 |
} |
| 55 |
|
| 56 |
/** |
| 57 |
* Shortcode output for the plugin |
| 58 |
* |
| 59 |
* @param array $atts |
| 60 |
* |
| 61 |
* @return array |
| 62 |
* @since 8.0.0 |
| 63 |
*/ |
| 64 |
public function wpvr_shortcode($atts) |
| 65 |
{ |
| 66 |
|
| 67 |
extract( |
| 68 |
shortcode_atts( |
| 69 |
array( |
| 70 |
'id' => 0, |
| 71 |
'width' => null, |
| 72 |
'height' => null, |
| 73 |
'mobile_height' => null, |
| 74 |
'radius' => null |
| 75 |
), |
| 76 |
$atts |
| 77 |
) |
| 78 |
); |
| 79 |
$id = esc_attr($id); |
| 80 |
$width = esc_attr($width); |
| 81 |
$height = esc_attr($height); |
| 82 |
$mobile_height = esc_attr($mobile_height); |
| 83 |
$radius = esc_attr($radius); |
| 84 |
if (!$id) { |
| 85 |
$obj = get_page_by_path($slug, OBJECT, $this->post_type); |
| 86 |
if ($obj) { |
| 87 |
$id = $obj->ID; |
| 88 |
} else { |
| 89 |
return __('Invalid Wpvr slug attribute', $this->plugin_name); |
| 90 |
} |
| 91 |
} |
| 92 |
|
| 93 |
if (empty($mobile_height)) { |
| 94 |
$mobile_height = "300px"; |
| 95 |
} |
| 96 |
$get_post = get_post_status($id); |
| 97 |
if ( $get_post !== 'publish' ) { |
| 98 |
return esc_html__('Oops! It seems like this post isn\'t published yet. Stay tuned for updates!', 'wpvr') ; |
| 99 |
} |
| 100 |
if( post_password_required( $id ) ){ |
| 101 |
return get_the_password_form(); |
| 102 |
} |
| 103 |
$postdata = get_post_meta($id, 'panodata', true); |
| 104 |
$panoid = 'pano'.$id; |
| 105 |
|
| 106 |
if (isset($postdata['streetviewdata'])){ |
| 107 |
$html = $this->streetview->render_streetview_shortcode($postdata, $width, $height); |
| 108 |
return $html; |
| 109 |
} |
| 110 |
|
| 111 |
|
| 112 |
if (isset($postdata['vidid'])) { |
| 113 |
$html = $this->video->render_video_shortcode($postdata, $id, $width, $height, $radius); |
| 114 |
return $html; |
| 115 |
} |
| 116 |
|
| 117 |
$html = $this->scene->render_scene_shortcode($postdata, $panoid, $id, $radius, $width, $height, $mobile_height); |
| 118 |
return $html; |
| 119 |
} |
| 120 |
} |