/** * Static Singleton Factory Method * * @return self */ public static function instance() { if (!self::$instance) { self::$instance = new self(); } return self::$instance; }
/** * Queues the import on the Aggregator service * * @return mixed */ public function queue_import($args = array()) { $aggregator = Tribe__Events__Aggregator::instance(); $is_previewing = !empty($_GET['action']) && ('tribe_aggregator_create_import' === $_GET['action'] || 'tribe_aggregator_preview_import' === $_GET['action']); $error = null; $defaults = array('type' => $this->meta['type'], 'origin' => $this->meta['origin'], 'source' => $this->meta['source'], 'callback' => $is_previewing ? null : site_url('/event-aggregator/insert/?key=' . urlencode($this->meta['hash']))); if (!empty($this->meta['frequency'])) { $defaults['frequency'] = $this->meta['frequency']; } if (!empty($this->meta['file'])) { $defaults['file'] = $this->meta['file']; } if (!empty($this->meta['keywords'])) { $defaults['keywords'] = $this->meta['keywords']; } if (!empty($this->meta['location'])) { $defaults['location'] = $this->meta['location']; } if (!empty($this->meta['start'])) { $defaults['start'] = $this->meta['start']; } if (!empty($this->meta['radius'])) { $defaults['radius'] = $this->meta['radius']; } if ($is_previewing) { $defaults['preview'] = true; } $args = wp_parse_args($args, $defaults); // create the import on the Event Aggregator service $response = $aggregator->api('import')->create($args); // if the Aggregator API returns a WP_Error, set this record as failed if (is_wp_error($response)) { $error = $response; return $this->set_status_as_failed($error); } // if the Aggregator response has an unexpected format, set this record as failed if (empty($response->message_code)) { return $this->set_status_as_failed(tribe_error('core:aggregator:invalid-service-response')); } // if the Import creation was unsuccessful, set this record as failed if ('success:create-import' != $response->message_code && 'queued' != $response->message_code) { /** * @todo Allow overwriting the message */ $error = new WP_Error($response->message_code, Tribe__Events__Aggregator__Errors::build(esc_html__($response->message, 'the-events-calendar'), empty($response->data->message_args) ? array() : $response->data->message_args)); return $this->set_status_as_failed($error); } // if the Import creation didn't provide an import id, the response was invalid so mark as failed if (empty($response->data->import_id)) { return $this->set_status_as_failed(tribe_error('core:aggregator:invalid-service-response')); } // only set as pending if we aren't previewing the record if (!$is_previewing) { // if we get here, we're good! Set the status to pending $this->set_status_as_pending(); } // store the import id update_post_meta($this->id, self::$meta_key_prefix . 'import_id', $response->data->import_id); return $response; }
/** * 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')); }
/** * Static Singleton Factory Method * * @return self */ public static function instance() { return self::$instance ? self::$instance : (self::$instance = new self()); }