/** * Static Singleton Factory Method * * @return self */ public static function instance() { if (!self::$instance) { self::$instance = new self(); } return self::$instance; }
/** * A private method to prevent it to be created twice. * It will add the methods and setup any dependencies * * Note: This should load on `plugins_loaded@P10` */ private function __construct() { /** * As previously seen by other major features some users would rather have it not active * @var bool */ $should_load = (bool) apply_filters('tribe_aggregator_should_load', true); // You shall not Load! if (false === $should_load) { return; } // Loads the Required Classes and saves them as proprieties $this->meta_box = Tribe__Events__Aggregator__Meta_Box::instance(); $this->migrate = Tribe__Events__Aggregator__Migrate::instance(); $this->page = Tribe__Events__Aggregator__Page::instance(); $this->service = Tribe__Events__Aggregator__Service::instance(); $this->settings = Tribe__Events__Aggregator__Settings::instance(); $this->records = Tribe__Events__Aggregator__Records::instance(); $this->cron = Tribe__Events__Aggregator__Cron::instance(); $this->queue_processor = new Tribe__Events__Aggregator__Record__Queue_Processor(); $this->queue_realtime = new Tribe__Events__Aggregator__Record__Queue_Realtime(null, null, $this->queue_processor); $this->errors = Tribe__Events__Aggregator__Errors::instance(); $this->pue_checker = new Tribe__PUE__Checker('http://tri.be/', 'event-aggregator', array('context' => 'service')); // Initializes the Classes related to the API $this->api(); // Flags that the Aggregator has been fully loaded $this->is_loaded = true; // Register the Aggregator Endpoint add_action('tribe_events_pre_rewrite', array($this, 'action_endpoint_configuration')); // Intercept the Endpoint and trigger actions add_action('parse_request', array($this, 'action_endpoint_parse_request')); // Add endpoint query vars add_filter('query_vars', array($this, 'filter_endpoint_query_vars')); // Filter the "plugin name" for Event Aggregator add_filter('pue_get_plugin_name', array($this, 'filter_pue_plugin_name'), 10, 2); // To make sure that meaningful cache is purged when settings are changed add_action('updated_option', array($this, 'action_purge_transients')); // Remove aggregator records from ET add_filter('tribe_tickets_settings_post_types', array($this, 'filter_remove_record_post_type')); // Notify users about expiring Facebook Token if oauth is enabled add_action('plugins_loaded', array($this, 'setup_notices'), 11); // Let's prevent events-importer-ical from DESTROYING its saved recurring imports when it gets deactivated if (class_exists('Tribe__Events__Ical_Importer__Main')) { remove_action('deactivate_' . plugin_basename(Tribe__Events__Ical_Importer__Main::$plugin_path . 'the-events-calendar-ical-importer.php'), 'tribe_events_ical_deactivate'); } add_action('admin_init', array($this, 'add_status_to_help')); }
<?php $origin_slug = 'ical'; $field = (object) array(); $field->label = __('Import Type:', 'the-events-calendar'); $field->placeholder = __('Select Import Type', 'the-events-calendar'); $field->help = __('One-time imports include all events in the current feed, while scheduled imports automatically grab new events and updates from the feed on a set schedule.', 'the-events-calendar'); $field->source = 'ical_import_type'; $frequency = (object) array(); $frequency->placeholder = __('Select Frequency', 'the-events-calendar'); $frequency->help = __('Select how often you would like events to be automatically imported.', 'the-events-calendar'); $frequency->source = 'ical_import_frequency'; $cron = Tribe__Events__Aggregator__Cron::instance(); $frequencies = $cron->get_frequency(); ?> <tr class="tribe-dependent" data-depends="#tribe-ea-field-origin" data-condition="ical"> <th scope="row"> <label for="tribe-ea-field-import_type"><?php echo esc_html($field->label); ?> </label> </th> <td> <?php if ('edit' === $aggregator_action) { ?> <input type="hidden" name="aggregator[ical][import_type]" id="tribe-ea-field-ical_import_type" value="schedule" /> <strong class="tribe-ea-field-readonly"><?php echo esc_html__('Scheduled Import', 'the-events-calendar'); ?> </strong>
public function column_frequency($post) { if ('schedule' === $post->ping_status) { $frequency = Tribe__Events__Aggregator__Cron::instance()->get_frequency(array('id' => $post->post_content)); if (!empty($frequency->text)) { $html[] = $frequency->text; } else { $html[] = esc_html__('Invalid Frequency', 'the-events-calendar'); } } else { $html[] = esc_html__('One Time', 'the-events-calendar'); } return $this->render($html); }
/** * Creates a child record based on the import record * * @return boolean|WP_Error */ public function create_child_record() { $post = array('post_title' => $this->generate_title($this->type, $this->origin, $this->meta['frequency'], $this->post->ID), 'post_type' => $this->post->post_type, 'ping_status' => $this->post->ping_status, 'post_mime_type' => $this->post->post_mime_type, 'post_date' => current_time('mysql'), 'post_status' => Tribe__Events__Aggregator__Records::$status->draft, 'post_parent' => $this->id, 'meta_input' => array()); foreach ($this->meta as $key => $value) { if ('activity' === $key) { // don't copy the parent activity into the child record continue; } $post['meta_input'][self::$meta_key_prefix . $key] = $value; } $frequency = Tribe__Events__Aggregator__Cron::instance()->get_frequency(array('id' => $this->meta['frequency'])); if (!$frequency) { return tribe_error('core:aggregator:invalid-record-frequency', $meta); } // Setup the post_content as the Frequency (makes it easy to fetch by frequency) $post['post_content'] = $frequency->id; // create schedule post $child_id = wp_insert_post($post); // if the schedule creation failed, bail if (is_wp_error($child_id)) { return tribe_error('core:aggregator:save-child-failed'); } $this->maybe_add_meta_via_pre_wp_44_method($child_id, $post['meta_input']); // track the most recent child that was spawned $this->update_meta('recent_child', $child_id); return Tribe__Events__Aggregator__Records::instance()->get_by_post_id($child_id); }
/** * Get the Facebook frequency and convert to EA * * @param string $frequency Facebook Frequency * @return string EA Frequency */ private function convert_facebook_frequency($frequency) { $results = Tribe__Events__Aggregator__Cron::instance()->get_frequency(array('id' => $frequency)); // Return to the closest frequency if (empty($results)) { return 'daily'; } return $frequency; }