Ejemplo n.º 1
0
 /**
  * 
  */
 public function filter_events($query)
 {
     if (is_admin()) {
         global $pagenow;
         $post_types = apply_filters('em_event_post_type', array('event'));
         foreach ($post_types as $post_type) {
             if ($pagenow === 'edit.php' && isset($query->query_vars['post_type']) && $query->query_vars['post_type'] === $post_type) {
                 $em_helper = new Events_Maker_Helper();
                 $meta_args = $query->get('meta_query');
                 $start = !empty($_GET['event_start_date']) ? sanitize_text_field($_GET['event_start_date']) : '';
                 $end = !empty($_GET['event_end_date']) ? sanitize_text_field($_GET['event_end_date']) : '';
                 $sb = $em_helper->is_valid_date($start);
                 $eb = $em_helper->is_valid_date($end);
                 if ($sb === TRUE && $eb === TRUE) {
                     $meta_args = array(array('key' => '_event_start_date', 'value' => $start, 'compare' => '>=', 'type' => 'DATE'), array('key' => '_event_end_date', 'value' => $end, 'compare' => '<=', 'type' => 'DATE'));
                 } elseif ($sb === TRUE && $eb !== TRUE) {
                     $meta_args = array(array('key' => '_event_start_date', 'value' => $start, 'compare' => '>=', 'type' => 'DATE'));
                 } elseif ($sb !== TRUE && $eb === TRUE) {
                     $meta_args = array(array('key' => '_event_end_date', 'value' => $end, 'compare' => '<=', 'type' => 'DATE'));
                 }
                 if (!empty($meta_args)) {
                     $query->set('meta_query', $meta_args);
                 }
             }
         }
     }
 }
Ejemplo n.º 2
0
 /**
  * Add custom recurrence dates.
  */
 private function add_custom_dates($post_id, $dates, $all_day, $separate_end_date, $start, $end)
 {
     $custom_dates = $separates = array();
     $diff = strtotime($end) - strtotime($start);
     $em_helper = new Events_Maker_Helper();
     // is it all day long event?
     if ($all_day === 1) {
         foreach ($dates as $id => $date) {
             if (isset($separate_end_date[$id])) {
                 if ($em_helper->is_valid_date($date['start']['date']) && $em_helper->is_valid_date($date['end']['date']) && $em_helper->is_after_date($date['end']['date'], $date['start']['date'], false)) {
                     $separates[] = true;
                     $custom_dates[] = array('start' => $date['start']['date'] . ' 00:00:00', 'end' => $date['end']['date'] . ' 00:00:00');
                 }
             } else {
                 if ($em_helper->is_valid_date($date['start']['date'])) {
                     $separates[] = false;
                     $custom_dates[] = array('start' => $date['start']['date'] . ' 00:00:00', 'end' => date('Y-m-d', strtotime($date['start']['date']) + $diff) . ' 00:00:00');
                 }
             }
         }
     } else {
         foreach ($dates as $id => $date) {
             if (isset($separate_end_date[$id])) {
                 if ($em_helper->is_valid_date($date['start']['date']) && $em_helper->is_valid_date($date['end']['date']) && $em_helper->is_valid_time($date['start']['time']) && $em_helper->is_valid_time($date['end']['time']) && $em_helper->is_after_date($date['end']['date'] . ' ' . $date['end']['time'], $date['start']['date'] . ' ' . $date['start']['time'], false)) {
                     $separates[] = true;
                     $custom_dates[] = array('start' => date('Y-m-d H:i:s', strtotime($date['start']['date'] . ' ' . $date['start']['time'])), 'end' => date('Y-m-d H:i:s', strtotime($date['end']['date'] . ' ' . $date['end']['time'])));
                 }
             } else {
                 if ($em_helper->is_valid_date($date['start']['date']) && $em_helper->is_valid_time($date['start']['time'])) {
                     $time = strtotime($date['start']['date'] . ' ' . $date['start']['time']);
                     $separates[] = false;
                     $custom_dates[] = array('start' => date('Y-m-d H:i:s', $time), 'end' => date('Y-m-d H:i:s', $time + $diff));
                 }
             }
         }
     }
     if (!empty($custom_dates)) {
         global $wpdb;
         $query = array();
         foreach ($custom_dates as $date) {
             $query[] = "(" . $post_id . ", '_event_occurrence_date', '" . $date['start'] . "|" . $date['end'] . "')";
         }
         if (!empty($query)) {
             $wpdb->query('INSERT INTO ' . $wpdb->postmeta . ' (post_id, meta_key, meta_value) VALUES ' . implode(', ', $query));
         }
         array_multisort($custom_dates);
         // get last occurrence
         $last = end($custom_dates);
         // add last occurrence
         add_post_meta($post_id, '_event_occurrence_last_date', $last['start'] . '|' . $last['end']);
     } else {
         // add last occurrence (same as first)
         add_post_meta($post_id, '_event_occurrence_last_date', $start . '|' . $end);
     }
     return $separates;
 }
Ejemplo n.º 3
0
 /**
  * Modify the query according to search form values.
  */
 public function alter_search_query($query)
 {
     if (empty($query) || is_admin() || !$query->is_main_query() && empty($query->query_vars['suppress_filters'])) {
         return $query;
     }
     // get URL vars
     $current_url = parse_url($_SERVER['REQUEST_URI']);
     if (empty($current_url['query'])) {
         return $query;
     }
     parse_str($current_url['query'], $vars);
     // get raxonomies
     $taxonomies = array();
     foreach ($vars as $var_key => $var_value) {
         if (!empty($var_value)) {
             if (stripos($var_key, 'tax_') === 0) {
                 $var_key = str_replace('tax_', '', $var_key);
                 if (in_array($var_key, array('event-category', 'event-location', 'event-organizer', 'event-tag'))) {
                     $taxonomies[] = array($var_key => $var_value);
                 }
             }
         }
     }
     // build tax query
     $tax_query = array();
     if ($taxonomies) {
         foreach ($taxonomies as $taxonomy) {
             $tax_query[] = array('taxonomy' => key($taxonomy), 'terms' => current($taxonomy), 'field' => 'term_id');
         }
     }
     if (!empty($query->tax_query->queries)) {
         $tax_query = array_merge($query->tax_query->queries, $tax_query);
     }
     // get event date
     $em_helper = new Events_Maker_Helper();
     $meta_query = $query->get('meta_query');
     $start = !empty($_GET['start_date']) ? sanitize_text_field($_GET['start_date']) : '';
     $end = !empty($_GET['end_date']) ? sanitize_text_field($_GET['end_date']) : '';
     $sb = $em_helper->is_valid_date($start);
     $eb = $em_helper->is_valid_date($end);
     if ($sb === true && $eb === true) {
         $meta_query = array(array('key' => '_event_start_date', 'value' => $start, 'compare' => '>=', 'type' => 'DATE'), array('key' => '_event_end_date', 'value' => $end, 'compare' => '<=', 'type' => 'DATE'));
     } elseif ($sb === true && $eb !== true) {
         $meta_query = array(array('key' => '_event_start_date', 'value' => $start, 'compare' => '>=', 'type' => 'DATE'));
     } elseif ($sb !== true && $eb === true) {
         $meta_query = array(array('key' => '_event_end_date', 'value' => $end, 'compare' => '<=', 'type' => 'DATE'));
     }
     if (!empty($tax_query)) {
         $query->set('tax_query', $tax_query);
     }
     if (!empty($meta_query)) {
         $query->set('meta_query', $meta_query);
     }
 }