| 1 |
<?php |
| 2 |
if (!defined('ABSPATH')) exit; // Exit if accessed directly |
| 3 |
/** |
| 4 |
* Responsible for managing Video tab content on Setup metabox |
| 5 |
* |
| 6 |
* @link http://rextheme.com/ |
| 7 |
* @since 1.0.0 |
| 8 |
* |
| 9 |
* @package Wpvr |
| 10 |
* @subpackage Wpvr/admin/classes |
| 11 |
*/ |
| 12 |
|
| 13 |
class WPVR_Video { |
| 14 |
|
| 15 |
/** |
| 16 |
* Instance of WPVR_Format class |
| 17 |
*/ |
| 18 |
protected $format; |
| 19 |
|
| 20 |
/** |
| 21 |
* Instance of WPVR_Validation class |
| 22 |
*/ |
| 23 |
protected $validator; |
| 24 |
|
| 25 |
|
| 26 |
function __construct() |
| 27 |
{ |
| 28 |
$this->format = new WPVR_Format(); |
| 29 |
|
| 30 |
$this->validator = new WPVR_Validator(); |
| 31 |
} |
| 32 |
|
| 33 |
|
| 34 |
/** |
| 35 |
* Render Video Tab Content |
| 36 |
* @param mixed $postdata |
| 37 |
* |
| 38 |
* @return void |
| 39 |
* @since 8.0.0 |
| 40 |
*/ |
| 41 |
public function render_video($postdata) |
| 42 |
{ |
| 43 |
ob_start(); |
| 44 |
?> |
| 45 |
|
| 46 |
<h6 class="title"><?php echo __('Video Settings : ', 'wpvr'); ?></h6> |
| 47 |
|
| 48 |
<?php |
| 49 |
WPVR_Meta_Field::render_video_setting_meta_fields($postdata); |
| 50 |
ob_end_flush(); |
| 51 |
} |
| 52 |
|
| 53 |
|
| 54 |
/** |
| 55 |
* Update post meta data |
| 56 |
* |
| 57 |
* @param integer $postid |
| 58 |
* @param integer $panoid |
| 59 |
* |
| 60 |
* @return void |
| 61 |
* @since 8.0.0 |
| 62 |
*/ |
| 63 |
public function wpvr_update_meta_box($postid, $panoid) |
| 64 |
{ |
| 65 |
$vidid = 'vid' . $postid; |
| 66 |
$videourl = esc_url_raw($_POST['videourl']); |
| 67 |
|
| 68 |
$videodata = $this->format->prepare_video_settings_data(); |
| 69 |
$vidtype = ''; |
| 70 |
|
| 71 |
$this->validator->empty_video_validation($videourl); |
| 72 |
|
| 73 |
if (strpos($videourl, 'youtube') > 0) { |
| 74 |
$vidtype = 'youtube'; |
| 75 |
$html = $this->format->prepare_youtube_video_meta_data($videourl, $videodata); |
| 76 |
} elseif (strpos($videourl, 'youtu.be') > 0) { |
| 77 |
$vidtype = 'youtube'; |
| 78 |
$html = $this->format->prepare_youtu_be_video_meta_data($videourl, $videodata); |
| 79 |
} elseif (strpos($videourl, 'vimeo') > 0) { |
| 80 |
$vidtype = 'vimeo'; |
| 81 |
$html = $this->format->prepare_vimeo_video_meta_data($videourl, $videodata); |
| 82 |
} else { |
| 83 |
$vidtype = 'selfhost'; |
| 84 |
$html = $this->format->prepare_selfhost_video_meta_data($videourl, $vidid, $videodata); |
| 85 |
} |
| 86 |
|
| 87 |
$videoarray = array(); |
| 88 |
$videoarray = array( |
| 89 |
__("panoid") => $panoid, |
| 90 |
__("panoviddata") => $html, |
| 91 |
__("vidid") => $vidid, |
| 92 |
__("vidurl") => $videourl, |
| 93 |
__("vidtype") => $vidtype, |
| 94 |
__("autoplay") => $videodata['autoplay'], |
| 95 |
__("loop") => $videodata['loop'] |
| 96 |
); |
| 97 |
update_post_meta($postid, 'panodata', $videoarray); |
| 98 |
$response = array( |
| 99 |
'success' => true, |
| 100 |
'data' => array( |
| 101 |
'post_ID' => $postid, |
| 102 |
'post_status' => get_post_status($postid) |
| 103 |
) |
| 104 |
); |
| 105 |
do_action( 'wpvr_tour_settings_saved', $postid ); |
| 106 |
wp_send_json($response); |
| 107 |
die(); |
| 108 |
} |
| 109 |
|
| 110 |
|
| 111 |
/** |
| 112 |
* Video Tour Preview |
| 113 |
* |
| 114 |
* @param mixed $panoid |
| 115 |
* |
| 116 |
* @return wp_send_json_response |
| 117 |
* @since 8.0.0 |
| 118 |
*/ |
| 119 |
public function wpvr_video_preview($panoid) |
| 120 |
{ |
| 121 |
$randid = rand(1000, 1000000); |
| 122 |
$vidid = 'vid' . $randid; |
| 123 |
$videourl = esc_url_raw($_POST['videourl']); |
| 124 |
$videodata = $this->format->prepare_video_settings_data(); |
| 125 |
$vidtype = ''; |
| 126 |
|
| 127 |
$this->validator->empty_video_validation($videourl); |
| 128 |
|
| 129 |
if (strpos($videourl, 'youtube') > 0) { |
| 130 |
$vidtype = 'youtube'; |
| 131 |
$html = $this->format->prepare_youtube_video_preview($videourl, $videodata); |
| 132 |
} elseif (strpos($videourl, 'youtu.be') > 0) { |
| 133 |
$vidtype = 'youtube'; |
| 134 |
$html = $this->format->prepare_youtube_video_preview($videourl, $videodata); |
| 135 |
} elseif (strpos($videourl, 'vimeo') > 0) { |
| 136 |
$vidtype = 'vimeo'; |
| 137 |
$html = $this->format->prepare_vimeo_video_meta_data($videourl, $videodata); |
| 138 |
} else { |
| 139 |
$vidtype = 'selfhost'; |
| 140 |
$html = $this->format->prepare_selfhost_video_meta_data($videourl, $vidid, $videodata); |
| 141 |
} |
| 142 |
|
| 143 |
$response = array(); |
| 144 |
$response = array(__("panoid") => $panoid, __("panodata") => $html, __("vidid") => $vidid, __("vidtype") => $vidtype); |
| 145 |
wp_send_json_success($response); |
| 146 |
} |
| 147 |
|
| 148 |
|
| 149 |
/** |
| 150 |
* Render shortcode while postdata has video data |
| 151 |
* |
| 152 |
* @param array $postdata |
| 153 |
* @param integer $id |
| 154 |
* |
| 155 |
* @return string |
| 156 |
* @since 8.0.0 |
| 157 |
*/ |
| 158 |
public function render_video_shortcode($postdata, $id, $width, $height, $radius) |
| 159 |
{ |
| 160 |
if (empty($width)) { |
| 161 |
$width = '600px'; |
| 162 |
} |
| 163 |
if (empty($height)) { |
| 164 |
$height = '400px'; |
| 165 |
} |
| 166 |
|
| 167 |
$autoplay = 'off'; |
| 168 |
if (isset($postdata['autoplay'])) { |
| 169 |
$autoplay = $postdata['autoplay']; |
| 170 |
} |
| 171 |
|
| 172 |
$loop = 'off'; |
| 173 |
if (isset($postdata['loop'])) { |
| 174 |
$loop = $postdata['loop']; |
| 175 |
} |
| 176 |
|
| 177 |
if (strpos($postdata['vidurl'], 'youtube') > 0 || strpos($postdata['vidurl'], 'youtu') > 0) { |
| 178 |
$html = $this->format->prepare_youtube_video_shortcode_data($postdata, $width, $height, $autoplay, $loop, $radius); |
| 179 |
} elseif (strpos($postdata['vidurl'], 'vimeo') > 0) { |
| 180 |
$html = $this->format->prepare_vimeo_video_shortcode_data($postdata, $width, $height, $autoplay, $loop, $radius); |
| 181 |
} else { |
| 182 |
$html = $this->format->prepare_regular_video_shortcode_data($id, $postdata, $width, $height, $radius); |
| 183 |
} |
| 184 |
return $html; |
| 185 |
} |
| 186 |
|
| 187 |
} |