示例#1
0
 /**
  * Static Singleton Factory Method
  *
  * @return Tribe__Events__Admin__Helpers
  */
 public static function instance()
 {
     if (!isset(self::$instance)) {
         $className = __CLASS__;
         self::$instance = new $className();
     }
     return self::$instance;
 }
示例#2
0
 /**
  * Add ratings nudge in admin footer
  *
  * @param $footer_text
  *
  * @return string
  */
 public function rating_nudge($footer_text)
 {
     $admin_helpers = Tribe__Events__Admin__Helpers::instance();
     // only display custom text on Tribe Admin Pages
     if ($admin_helpers->is_screen() || $admin_helpers->is_post_type_screen()) {
         $footer_text = sprintf(esc_html__('Rate %3$sThe Events Calendar%4$s %1$s on %2$s to keep this plugin free.  Thanks from the friendly folks at Modern Tribe.', 'the-events-calendar'), '<a href="http://wordpress.org/support/view/plugin-reviews/the-events-calendar?filter=5"  target="_blank">&#9733;&#9733;&#9733;&#9733;&#9733;</a>', '<a href="http://wordpress.org/support/view/plugin-reviews/the-events-calendar?filter=5"  target="_blank">WordPress.org</a>', '<strong>', '</strong>');
     }
     return $footer_text;
 }
示例#3
0
 /**
  * When the edit-tags.php screen loads, setup filters
  * to fix the tagcloud links
  *
  * @return void
  */
 public function prepare_to_fix_tagcloud_links()
 {
     if (Tribe__Events__Admin__Helpers::instance()->is_post_type_screen(self::POSTTYPE)) {
         add_filter('get_edit_term_link', array($this, 'add_post_type_to_edit_term_link'), 10, 4);
     }
 }
 /**
  * Determine if the event can use the default organizer setting
  *
  * @param array $current_organizers
  *
  * @return bool
  */
 protected function use_default_organizer($current_organizers)
 {
     if (!empty($current_organizers)) {
         return false;
         // the event already has organizers
     }
     if (!empty($this->event->ID) && get_post_status($this->event->ID) != 'auto-draft') {
         return false;
         // the event has already been saved
     }
     if (is_admin()) {
         return Tribe__Events__Admin__Helpers::instance()->is_action('add');
     } else {
         return true;
         // a front-end submission form (e.g., community)
     }
 }
示例#5
0
 /**
  * Is hooked by init() filter to parse the WP_Query arguments for main and alt queries.
  *
  * @param object $query WP_Query object args supplied or default
  *
  * @return object $query (modified)
  */
 public static function pre_get_posts($query)
 {
     $admin_helpers = Tribe__Events__Admin__Helpers::instance();
     if ($query->is_main_query() && is_home()) {
         // check option for including events in the main wordpress loop, if true, add events post type
         if (tribe_get_option('showEventsInMainLoop', false)) {
             $query->query_vars['post_type'] = isset($query->query_vars['post_type']) ? (array) $query->query_vars['post_type'] : array('post');
             $query->query_vars['post_type'][] = Tribe__Events__Main::POSTTYPE;
             $query->tribe_is_multi_posttype = true;
         }
     }
     if ($query->tribe_is_multi_posttype) {
         do_action('log', 'multi_posttype', 'default', $query->tribe_is_multi_posttype);
         add_filter('posts_fields', array(__CLASS__, 'multi_type_posts_fields'), 10, 2);
         add_filter('posts_join', array(__CLASS__, 'posts_join'), 10, 2);
         add_filter('posts_join', array(__CLASS__, 'posts_join_orderby'), 10, 2);
         add_filter('posts_distinct', array(__CLASS__, 'posts_distinct'));
         add_filter('posts_orderby', array(__CLASS__, 'posts_orderby'), 10, 2);
         do_action('tribe_events_pre_get_posts', $query);
         return;
     }
     if ($query->tribe_is_event || $query->tribe_is_event_category) {
         if (!($query->is_main_query() && 'month' === $query->get('eventDisplay'))) {
             add_filter('posts_fields', array(__CLASS__, 'posts_fields'), 10, 2);
             add_filter('posts_join', array(__CLASS__, 'posts_join'), 10, 2);
             add_filter('posts_join', array(__CLASS__, 'posts_join_orderby'), 10, 2);
             add_filter('posts_where', array(__CLASS__, 'posts_where'), 10, 2);
             add_filter('posts_distinct', array(__CLASS__, 'posts_distinct'));
         } else {
             // reduce number of queries triggered by main WP_Query on month view
             $query->set('posts_per_page', 1);
             $query->set('no_found_rows', true);
             $query->set('cache_results', false);
             $query->set('update_post_meta_cache', false);
             $query->set('update_post_term_cache', false);
             do_action('tribe_events_pre_get_posts', $query);
             return $query;
         }
         // if a user selects a date in the event bar we want it to persist as long as possible
         if (!empty($_REQUEST['tribe-bar-date'])) {
             $query->set('eventDate', $_REQUEST['tribe-bar-date']);
             do_action('log', 'changed eventDate to tribe-bar-date', 'tribe-events-query', $_REQUEST['tribe-bar-date']);
         }
         // if a user provides a search term we want to use that in the search params
         if (!empty($_REQUEST['tribe-bar-search'])) {
             $query->query_vars['s'] = $_REQUEST['tribe-bar-search'];
         }
         $query->query_vars['eventDisplay'] = !empty($query->query_vars['eventDisplay']) ? $query->query_vars['eventDisplay'] : Tribe__Events__Main::instance()->displaying;
         //@todo stop calling EOD cutoff transformations all over the place
         if (!empty($query->query_vars['eventDisplay'])) {
             switch ($query->query_vars['eventDisplay']) {
                 case 'custom':
                     // if the eventDisplay is 'custom', all we're gonna do is make sure the start and end dates are formatted
                     $start_date = $query->get('start_date');
                     if ($start_date) {
                         $query->set('start_date', date_i18n(Tribe__Events__Date_Utils::DBDATETIMEFORMAT, strtotime($start_date)));
                     }
                     $end_date = $query->get('end_date');
                     if ($end_date) {
                         $query->set('end_date', date_i18n(Tribe__Events__Date_Utils::DBDATETIMEFORMAT, strtotime($end_date)));
                     }
                     break;
                 case 'month':
                     // make sure start and end date are set
                     if ($query->get('start_date') == '') {
                         $event_date = $query->get('eventDate') != '' ? $query->get('eventDate') : date_i18n(Tribe__Events__Date_Utils::DBDATETIMEFORMAT);
                         $query->set('start_date', tribe_event_beginning_of_day($event_date));
                     }
                     if ($query->get('end_date' == '')) {
                         $query->set('end_date', tribe_event_end_of_day($query->get('start_date')));
                     }
                     $query->set('hide_upcoming', true);
                     break;
                 case 'day':
                     $event_date = $query->get('eventDate') != '' ? $query->get('eventDate') : Date('Y-m-d', current_time('timestamp'));
                     $query->set('eventDate', $event_date);
                     $beginning_of_day = strtotime(tribe_event_beginning_of_day($event_date)) + 1;
                     $query->set('start_date', date_i18n(Tribe__Events__Date_Utils::DBDATETIMEFORMAT, $beginning_of_day));
                     $query->set('end_date', tribe_event_end_of_day($event_date));
                     $query->set('posts_per_page', -1);
                     // show ALL day posts
                     $query->set('hide_upcoming', true);
                     $query->set('order', self::set_order('ASC', $query));
                     break;
                 case 'single-event':
                     if ($query->get('eventDate') != '') {
                         $query->set('start_date', $query->get('eventDate'));
                         $query->set('eventDate', $query->get('eventDate'));
                     }
                     break;
                 case 'all':
                 case 'list':
                 default:
                     // default display query
                     $event_date = $query->get('eventDate') != '' ? $query->get('eventDate') : date_i18n(Tribe__Events__Date_Utils::DBDATETIMEFORMAT);
                     if (!$query->tribe_is_past) {
                         $query->set('start_date', '' != $query->get('eventDate') ? tribe_event_beginning_of_day($event_date) : tribe_event_format_date(current_time('timestamp'), true, 'Y-m-d H:i:s'));
                         $query->set('end_date', '');
                         $query->set('order', self::set_order('ASC', $query));
                     } else {
                         // on past view, set the passed date as the end date
                         $query->set('start_date', '');
                         $query->set('end_date', tribe_event_end_of_day($event_date));
                         $query->set('order', self::set_order('DESC', $query));
                     }
                     $query->set('orderby', self::set_orderby(null, $query));
                     $query->set('hide_upcoming', true);
                     break;
             }
         } else {
             $query->set('hide_upcoming', true);
             $query->set('start_date', date_i18n(Tribe__Events__Date_Utils::DBDATETIMEFORMAT));
             $query->set('orderby', self::set_orderby(null, $query));
             $query->set('order', self::set_order(null, $query));
         }
         // eventCat becomes a standard taxonomy query - will need to deprecate and update views eventually
         if (!in_array($query->get(Tribe__Events__Main::TAXONOMY), array('', '-1'))) {
             $tax_query[] = array('taxonomy' => Tribe__Events__Main::TAXONOMY, 'field' => is_numeric($query->get(Tribe__Events__Main::TAXONOMY)) ? 'id' : 'slug', 'terms' => $query->get(Tribe__Events__Main::TAXONOMY), 'include_children' => apply_filters('tribe_events_query_include_children', true));
         }
         // Only add the postmeta hack if it's not the main admin events list
         // Because this method filters out drafts without EventStartDate.
         // For this screen we're doing the JOIN manually in Tribe__Events__Admin_List
         if (!Tribe__Events__Admin__Helpers::instance()->is_screen('edit-tribe_events')) {
             $event_start_key = Tribe__Events__Timezones::is_mode('site') ? '_EventStartDateUTC' : '_EventStartDate';
             $meta_query[] = array('key' => $event_start_key, 'type' => 'DATETIME');
         }
     }
     // filter by Venue ID
     if ($query->tribe_is_event_query && $query->get('venue') != '') {
         $meta_query[] = array('key' => '_EventVenueID', 'value' => $query->get('venue'));
     }
     // filter by Organizer ID
     if ($query->tribe_is_event_query && $query->get('organizer') != '') {
         $meta_query[] = array('key' => '_EventOrganizerID', 'value' => $query->get('organizer'));
     }
     // enable pagination setup
     if ($query->tribe_is_event_query && $query->get('posts_per_page') == '') {
         $query->set('posts_per_page', (int) tribe_get_option('postsPerPage', 10));
     }
     // hide upcoming events from query (only not in admin)
     if ($query->tribe_is_event_query && $query->get('hide_upcoming') && !$query->get('suppress_filters')) {
         $hide_upcoming_ids = self::getHideFromUpcomingEvents();
         if (!empty($hide_upcoming_ids)) {
             $query->set('post__not_in', $hide_upcoming_ids);
         }
     }
     if ($query->tribe_is_event_query && !empty($meta_query)) {
         // setup default relation for meta queries
         $meta_query['relation'] = 'AND';
         $meta_query_combined = array_merge((array) $meta_query, (array) $query->get('meta_query'));
         $query->set('meta_query', $meta_query_combined);
     }
     if ($query->tribe_is_event_query && !empty($tax_query)) {
         // setup default relation for tax queries
         $tax_query_combined = array_merge((array) $tax_query, (array) $query->get('tax_query'));
         $query->set('tax_query', $tax_query_combined);
     }
     if ($query->tribe_is_event_query) {
         add_filter('posts_orderby', array(__CLASS__, 'posts_orderby'), 10, 2);
     }
     // if is in the admin remove the event date & upcoming filters, unless is an ajax call
     if (is_admin() && $query->tribe_is_event_query && $admin_helpers->is_screen('edit-' . Tribe__Events__Main::POSTTYPE)) {
         if (!defined('DOING_AJAX') || defined('DOING_AJAX') && !DOING_AJAX) {
             remove_filter('posts_where', array(__CLASS__, 'posts_where'), 10, 2);
             remove_filter('posts_fields', array(__CLASS__, 'posts_fields'));
             $query->set('post__not_in', '');
             // set the default order for posts within admin lists
             if (!isset($query->query['order'])) {
                 $query->set('order', 'DESC');
             } else {
                 // making sure we preserve the order supplied by the query string even if it is overwritten above
                 $query->set('order', $query->query['order']);
             }
         }
     }
     if ($query->tribe_is_event_query) {
         do_action('tribe_events_pre_get_posts', $query);
     }
     return $query;
 }