| 1 |
<?php |
| 2 |
/** |
| 3 |
* WPVR Tour Checklist Meta Box |
| 4 |
* |
| 5 |
* @package WPVR Admin Classes |
| 6 |
* @since 8.5.24 |
| 7 |
*/ |
| 8 |
|
| 9 |
if (!defined('ABSPATH')) exit; // Exit if accessed directly |
| 10 |
|
| 11 |
|
| 12 |
/** |
| 13 |
* WPVR_Tour_Checklist_Meta_Box |
| 14 |
* |
| 15 |
* @since 8.5.24 |
| 16 |
*/ |
| 17 |
class WPVR_Tour_Checklist_Meta_Box extends WPVR_Meta_Box { |
| 18 |
|
| 19 |
/** |
| 20 |
* @var string |
| 21 |
* @since 8.5.24 |
| 22 |
*/ |
| 23 |
protected $title = ''; |
| 24 |
|
| 25 |
/** |
| 26 |
* Metabox ID |
| 27 |
* |
| 28 |
* @var string |
| 29 |
* @since 8.5.24 |
| 30 |
*/ |
| 31 |
protected $slug = ''; |
| 32 |
|
| 33 |
/** |
| 34 |
* @var string |
| 35 |
* @since 8.5.24 |
| 36 |
*/ |
| 37 |
protected $post_type = ''; |
| 38 |
|
| 39 |
/** |
| 40 |
* Metabox context |
| 41 |
* |
| 42 |
* @var string |
| 43 |
* @since 8.5.24 |
| 44 |
*/ |
| 45 |
protected $context = ''; |
| 46 |
|
| 47 |
/** |
| 48 |
* Metabox priority |
| 49 |
* |
| 50 |
* @var string |
| 51 |
* @since 8.5.24 |
| 52 |
*/ |
| 53 |
protected $priority = ''; |
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
/** |
| 58 |
* Constructor |
| 59 |
* |
| 60 |
* @param string $slug Slug of the meta box |
| 61 |
* @param string $title Title of the meta box |
| 62 |
* @param string $post_type Post type of the meta box |
| 63 |
* @param string $context Context of the meta box |
| 64 |
* @param string $priority Priority of the meta box |
| 65 |
* |
| 66 |
* @return void |
| 67 |
* @since 8.5.24 |
| 68 |
*/ |
| 69 |
public function __construct( $slug, $title, $post_type, $context, $priority ) { |
| 70 |
if( $slug == '' || $context == '' || $priority == '' ) { |
| 71 |
return; |
| 72 |
} |
| 73 |
|
| 74 |
if( $title == '' ) { |
| 75 |
$this->title = ucfirst( $slug ); |
| 76 |
} |
| 77 |
|
| 78 |
if( empty( $post_type ) ) { |
| 79 |
return; |
| 80 |
} |
| 81 |
|
| 82 |
$this->title = $title; |
| 83 |
$this->slug = $slug; |
| 84 |
$this->post_type = $post_type; |
| 85 |
$this->context = $context; |
| 86 |
$this->priority = $priority; |
| 87 |
|
| 88 |
add_action( 'add_meta_boxes', array( $this, 'register' ) ); |
| 89 |
} |
| 90 |
|
| 91 |
|
| 92 |
/** |
| 93 |
* Register custom meta box |
| 94 |
* |
| 95 |
* @param string $post_type |
| 96 |
* |
| 97 |
* @return void |
| 98 |
* @since 8.5.24 |
| 99 |
*/ |
| 100 |
public function register( $post_type ) { |
| 101 |
if ( $post_type == $this->post_type ) { |
| 102 |
add_meta_box( $this->slug, $this->title, array( $this, 'render' ), $post_type, $this->context, $this->priority ); |
| 103 |
} |
| 104 |
} |
| 105 |
|
| 106 |
|
| 107 |
/** |
| 108 |
* Render custom meta box |
| 109 |
* |
| 110 |
* @param object $post |
| 111 |
* |
| 112 |
* @return void |
| 113 |
* @since 8.5.24 |
| 114 |
*/ |
| 115 |
public function render( $post ) { |
| 116 |
$saved_checklist = get_post_meta($post->ID, 'wpvr_checklist', true); |
| 117 |
$pano_data = get_post_meta($post->ID, 'panodata', true); |
| 118 |
|
| 119 |
$wpvr_check_scene = isset($saved_checklist['wpvr_check_scene']) && $saved_checklist['wpvr_check_scene'] === 'true' ? true : false; |
| 120 |
$wpvr_check_media = isset($saved_checklist['wpvr_check_media']) && $saved_checklist['wpvr_check_media'] === 'true' ? true : false; |
| 121 |
$wpvr_check_default = isset($saved_checklist['wpvr_check_default']) && $saved_checklist['wpvr_check_default'] === 'true' ? true : false; |
| 122 |
$wpvr_check_hotspots = isset($saved_checklist['wpvr_check_hotspots']) && $saved_checklist['wpvr_check_hotspots'] === 'true' ? true : false; |
| 123 |
$wpvr_check_movement_controls = isset($saved_checklist['wpvr_check_movement-controls']) && $saved_checklist['wpvr_check_movement-controls'] === 'true' ? true : false; |
| 124 |
$wpvr_check_zoom_controls = isset($saved_checklist['wpvr_check_zoom-controls']) && $saved_checklist['wpvr_check_zoom-controls'] === 'true' ? true : false; |
| 125 |
$wpvr_check_publish = isset($saved_checklist['wpvr_check_publish']) && $saved_checklist['wpvr_check_publish'] === 'true' ? true : false; |
| 126 |
|
| 127 |
if (!$wpvr_check_scene) { |
| 128 |
$wpvr_check_scene = isset($pano_data['panodata']['scene-list']) && count($pano_data['panodata']['scene-list']) > 0; |
| 129 |
} |
| 130 |
|
| 131 |
if (!$wpvr_check_media) { |
| 132 |
$wpvr_check_media = $this->hasValidSceneAttachment($pano_data); |
| 133 |
} |
| 134 |
|
| 135 |
if (!$wpvr_check_default) { |
| 136 |
$wpvr_check_default = $this->hasDefaultScene($pano_data); |
| 137 |
} |
| 138 |
|
| 139 |
if (!$wpvr_check_publish) { |
| 140 |
$wpvr_check_publish = $this->getPostStatusById($post->ID); |
| 141 |
} |
| 142 |
|
| 143 |
if (!$wpvr_check_hotspots) { |
| 144 |
$wpvr_check_hotspots = $this->hasValidHotspot($pano_data); |
| 145 |
} |
| 146 |
|
| 147 |
require_once WPVR_PLUGIN_DIR_PATH . 'admin/partials/wpvr_checklist_template.php'; |
| 148 |
} |
| 149 |
|
| 150 |
|
| 151 |
/** |
| 152 |
* Check if the tour has a valid scene attachment |
| 153 |
* |
| 154 |
* @param array $panodata |
| 155 |
* |
| 156 |
* @return bool |
| 157 |
* @since 8.5.24 |
| 158 |
*/ |
| 159 |
public function hasValidSceneAttachment($panodata) { |
| 160 |
if (!isset($panodata['panodata']['scene-list']) || !is_array($panodata['panodata']['scene-list'])) { |
| 161 |
return false; |
| 162 |
} |
| 163 |
|
| 164 |
foreach ($panodata['panodata']['scene-list'] as $scene) { |
| 165 |
if (!empty($scene['scene-attachment-url'])) { |
| 166 |
return true; |
| 167 |
} |
| 168 |
} |
| 169 |
|
| 170 |
return false; |
| 171 |
} |
| 172 |
|
| 173 |
/** |
| 174 |
* Check if the tour has a valid hotspot |
| 175 |
* |
| 176 |
* @param array $panodata |
| 177 |
* |
| 178 |
* @return bool |
| 179 |
* @since 8.5.24 |
| 180 |
*/ |
| 181 |
public function hasValidHotspot($panodata) { |
| 182 |
if (!isset($panodata['panodata']['scene-list']) || !is_array($panodata['panodata']['scene-list'])) { |
| 183 |
return false; |
| 184 |
} |
| 185 |
|
| 186 |
foreach ($panodata['panodata']['scene-list'] as $scene) { |
| 187 |
if (isset($scene['hotspot-list']) && is_array($scene['hotspot-list']) && !empty($scene['hotspot-list'])) { |
| 188 |
return true; |
| 189 |
} |
| 190 |
} |
| 191 |
|
| 192 |
return false; |
| 193 |
} |
| 194 |
|
| 195 |
/** |
| 196 |
* Check if the post is published |
| 197 |
* |
| 198 |
* @param int $post_id |
| 199 |
* |
| 200 |
* @return bool |
| 201 |
* @since 8.5.24 |
| 202 |
*/ |
| 203 |
public function getPostStatusById($post_id) { |
| 204 |
$status = get_post_status($post_id); |
| 205 |
return $status === 'publish' ? true : false; |
| 206 |
} |
| 207 |
|
| 208 |
|
| 209 |
/** |
| 210 |
* Check if the tour has a default scene |
| 211 |
* |
| 212 |
* @param array $panodata |
| 213 |
* |
| 214 |
* @return bool |
| 215 |
* @since 8.5.24 |
| 216 |
*/ |
| 217 |
public function hasDefaultScene($panodata){ |
| 218 |
if (!isset($panodata['panodata']['scene-list']) || !is_array($panodata['panodata']['scene-list'])) { |
| 219 |
return false; |
| 220 |
} |
| 221 |
|
| 222 |
foreach ($panodata['panodata']['scene-list'] as $scene) { |
| 223 |
if (isset($scene['dscene']) && !empty($scene['dscene']) && 'on' === $scene['dscene']) { |
| 224 |
return true; |
| 225 |
} |
| 226 |
} |
| 227 |
|
| 228 |
return false; |
| 229 |
} |
| 230 |
|
| 231 |
} |