*/ class MEC_feature_schema extends MEC_base { public $factory; public $main; public $settings; /** * Constructor method * @author Webnus */ public function __construct() { // Import MEC Factory $this->factory = $this->getFactory(); // Import MEC Main $this->main = $this->getMain(); // MEC Settings $this->settings = $this->main->get_settings(); } /** * Initialize locations feature * @author Webnus */ public function init() { // Schema Meta Box $this->factory->action('mec_metabox_details', array($this, 'meta_box_schema'), 60); if(!isset($this->settings['fes_section_schema']) or (isset($this->settings['fes_section_schema']) and $this->settings['fes_section_schema'])) $this->factory->action('mec_fes_metabox_details', array($this, 'meta_box_schema'), 60); // Save Schema Data $this->factory->action('save_post', array($this, 'save_event')); // Print Schema if(isset($this->settings['schema']) and $this->settings['schema'] != 0) { $this->factory->action('mec_schema', array($this, 'schema'), 10); $this->factory->filter('mec_schema_text', array($this, 'schema_text'), 10, 2); } } /** * Show location meta box * @author Webnus * @param object $post */ public function meta_box_schema($post) { $event_status = get_post_meta($post->ID, 'mec_event_status', true); if(!trim($event_status)) $event_status = 'EventScheduled'; $moved_online_link = get_post_meta($post->ID, 'mec_moved_online_link', true); $cancelled_reason = get_post_meta($post->ID, 'mec_cancelled_reason', true); $display_cancellation_reason_in_single_page = get_post_meta($post->ID, 'mec_display_cancellation_reason_in_single_page', true); ?>

>

* @param int $post_id * @return boolean */ public function save_event($post_id) { // Check if our nonce is set. if(!isset($_POST['mec_event_nonce'])) return false; // Verify that the nonce is valid. if(!wp_verify_nonce(sanitize_text_field($_POST['mec_event_nonce']), 'mec_event_data')) return false; // If this is an autosave, our form has not been submitted, so we don't want to do anything. if(defined('DOING_AUTOSAVE') and DOING_AUTOSAVE) return false; // Get Modern Events Calendar Data $_mec = isset($_POST['mec']) ? $this->main->sanitize_deep_array($_POST['mec']) : []; $event_status = isset($_mec['event_status']) ? sanitize_text_field($_mec['event_status']) : 'EventScheduled'; if(!in_array($event_status, array('EventScheduled', 'EventRescheduled', 'EventPostponed', 'EventCancelled', 'EventMovedOnline'))) $event_status = 'EventScheduled'; update_post_meta($post_id, 'mec_event_status', $event_status); $moved_online_link = (isset($_mec['moved_online_link']) and filter_var($_mec['moved_online_link'], FILTER_VALIDATE_URL)) ? sanitize_url($_mec['moved_online_link']) : ''; update_post_meta($post_id, 'mec_moved_online_link', $moved_online_link); $cancelled_reason = (isset($_mec['cancelled_reason']) and !empty($_mec['cancelled_reason'])) ? sanitize_text_field($_mec['cancelled_reason']) : ''; update_post_meta($post_id, 'mec_cancelled_reason', $cancelled_reason); $display_cancellation_reason_in_single_page = (isset($_mec['display_cancellation_reason_in_single_page']) and !empty($_mec['display_cancellation_reason_in_single_page'])); update_post_meta($post_id, 'mec_display_cancellation_reason_in_single_page', $display_cancellation_reason_in_single_page); return true; } public function schema($event) { $status = $this->settings['schema'] ?? 0; if(!$status) return; $speakers = []; if(isset($event->data->speakers) and is_array($event->data->speakers) and count($event->data->speakers)) { foreach($event->data->speakers as $value) { $speakers[] = array( "@type" => isset($value['type']) && $value['type'] == 'group' ? "PerformingGroup" : "Person", "name" => $value['name'], "image" => $value['thumbnail'], "sameAs" => $value['facebook'], ); } } $start_timestamp = ($event->data->time['start_timestamp'] ?? ($event->date['start']['timestamp'] ?? strtotime($event->date['start']['date']))); // All Params $params = MEC_feature_occurrences::param($event->ID, $start_timestamp, '*'); $event_status = (isset($event->data->meta['mec_event_status']) and trim($event->data->meta['mec_event_status'])) ? $event->data->meta['mec_event_status'] : 'EventScheduled'; $event_status = (isset($params['event_status']) and trim($params['event_status']) != '') ? $params['event_status'] : $event_status; if(!in_array($event_status, array('EventScheduled', 'EventRescheduled', 'EventPostponed', 'EventCancelled', 'EventMovedOnline'))) $event_status = 'EventScheduled'; $cost = $this->main->get_event_cost($event, false); $location_id = $this->main->get_master_location_id($event); $location = ($location_id ? $this->main->get_location_data($location_id) : array()); $start_date = (isset($event->date) and isset($event->date['start']) and isset($event->date['start']['date'])) ? $event->date['start']['date'] : NULL; $end_date = (isset($event->date) and isset($event->date['end']) and isset($event->date['end']['date'])) ? $event->date['end']['date'] : NULL; $event_link = $this->main->get_event_date_permalink($event, $start_date); $soldout = $this->main->is_soldout($event, $event->date); $organizer_id = $this->main->get_master_organizer_id($event); $organizer = $organizer_id ? $this->main->get_organizer_data($organizer_id) : []; $moved_online_link = (isset($event->data->meta['mec_moved_online_link']) and trim($event->data->meta['mec_moved_online_link'])) ? $event->data->meta['mec_moved_online_link'] : ''; $moved_online_link = (isset($params['moved_online_link']) and trim($params['moved_online_link']) != '') ? $params['moved_online_link'] : $moved_online_link; $content = strip_tags($event->data->post->post_content); $this->factory->printOnAjaxOrFooter(function() use($event, $event_status, $start_date, $end_date, $moved_online_link, $event_link, $location, $organizer, $cost, $soldout, $content, $speakers) { ?>