Example #1
0
 /**
  * Static Singleton Factory Method
  *
  * @return self
  */
 public static function instance()
 {
     if (!self::$instance) {
         self::$instance = new self();
     }
     return self::$instance;
 }
 /**
  * Fetches the link to this tab
  *
  * @param array|string $args     Query String or Array with the arguments
  * @param boolean      $relative Return a relative URL or absolute
  *
  * @return string
  */
 public function get_url($args = array(), $relative = false)
 {
     $defaults = array('tab' => $this->get_slug());
     // Allow the link to be "changed" on the fly
     $args = wp_parse_args($args, $defaults);
     // Escape after the filter
     return Tribe__Events__Aggregator__Page::instance()->get_url($args, $relative);
 }
    public function render_update_message()
    {
        if (!Tribe__Events__Aggregator__Page::instance()->is_screen()) {
            return;
        }
        $processor = Tribe__Events__Aggregator::instance()->queue_processor;
        if (!($this->record_id = $processor->next_waiting_record(true))) {
            return false;
        }
        $this->queue = $this->queue ? $this->queue : new Tribe__Events__Aggregator__Record__Queue($this->record_id);
        if ($this->queue->is_empty()) {
            return false;
        }
        $this->update_loop_vars();
        ob_start();
        $percent = $this->sanitize_progress($this->queue->progress_percentage());
        $spinner = '<img src="' . get_admin_url(null, '/images/spinner.gif') . '">';
        ?>
		<div class="tribe-message">
			<p>
				<?php 
        esc_html_e('Your import is currently in progress. Don\'t worry, you can safely navigate away&ndash;the import will continue in the background.', 'the-events-calendar');
        ?>
			</p>
		</div>
		<ul class="tracker">
			<li class="tracked-item track-created"><strong><?php 
        esc_html_e('Created:', 'the-events-calendar');
        ?>
</strong> <span class="value"></span></li>
			<li class="tracked-item track-updated"><strong><?php 
        esc_html_e('Updated:', 'the-events-calendar');
        ?>
</strong> <span class="value"></span></li>
			<li class="tracked-item track-skipped"><strong><?php 
        esc_html_e('Skipped:', 'the-events-calendar');
        ?>
</strong> <span class="value"></span></li>
		</ul>
		<div class="progress-container">
			<div class="progress" title="<?php 
        echo esc_html(sprintf(__('%d%% complete', 'the-events-calendar'), $percent));
        ?>
">
				<div class="bar"></div>
			</div>
			<img src="<?php 
        echo esc_url(get_admin_url(null, '/images/spinner.gif'));
        ?>
">
		</div>
		<?php 
        $html = ob_get_clean();
        return Tribe__Admin__Notices::instance()->render('aggregator-update-msg', $html);
    }
 /**
  * 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'));
 }
 /**
  * Checks if there are existing settings from the Old iCal or Facebook Plugins
  * and displays a notice with a button to migrated those using AJAX
  *
  * @return string
  */
 public function notice()
 {
     if (!Tribe__Events__Aggregator__Page::instance()->is_screen()) {
         return false;
     }
     if (($this->is_facebook_migrated() || !$this->has_facebook_setting()) && ($this->is_ical_migrated() || !$this->has_ical_setting())) {
         return false;
     }
     $aggregator = Tribe__Events__Aggregator::instance();
     $html = '<p>' . esc_html__('Thanks for activating Event Aggregator! It looks like you have some settings and imports configured on our legacy importer plugins. To complete your transition, we need to transfer those options to our new system.', 'the-events-calendar');
     if (!$this->is_facebook_migrated() && $this->has_facebook_setting()) {
         $html .= '<p style="display:inline-block;">' . get_submit_button(esc_html__('Migrate Facebook Events settings', 'the-events-calendar'), 'secondary', 'tribe-migrate-facebook-settings', false) . '<span class="spinner"></span></p>';
     }
     if (!$this->is_ical_migrated() && $this->has_ical_setting()) {
         $html .= '<p style="display:inline-block;">' . get_submit_button(esc_html__('Migrate iCal Importer settings', 'the-events-calendar'), 'secondary', 'tribe-migrate-ical-settings', false) . '<span class="spinner"></span></p>';
     }
     return Tribe__Admin__Notices::instance()->render('tribe-aggregator-migrate-legacy-settings', $html);
 }
Example #6
0
 public function handle_facebook_credentials()
 {
     /**
      * Verify that we are dealing with a FB token Request
      */
     if (!isset($_GET['ea-fb-token'])) {
         return false;
     }
     /**
      * @todo  include a way to handle errors on the Send back URL
      */
     $api = Tribe__Events__Aggregator__Service::instance()->api();
     $response = Tribe__Events__Aggregator__Service::instance()->get_facebook_token();
     $type = $_GET['ea-fb-token'];
     if (is_wp_error($response)) {
         return false;
     }
     if (empty($response->data)) {
         return false;
     }
     if (empty($response->data->expires) || empty($response->data->token) || empty($response->data->scopes)) {
         return false;
     }
     $url_map = array('new' => Tribe__Events__Aggregator__Page::instance()->get_url(array('tab' => $this->get_slug(), 'ea-auth' => 'facebook')), 'settings' => Tribe__Settings::instance()->get_url(array('tab' => 'addons', 'ea-auth' => 'facebook')));
     if (!isset($url_map[$type])) {
         return false;
     }
     // Calculate when will this Token Expire
     $expires = absint(trim(preg_replace('/[^0-9]/', '', $response->data->expires)));
     $expires += time();
     // Save the Options
     tribe_update_option('fb_token', trim(preg_replace('/[^a-zA-Z0-9]/', '', $response->data->token)));
     tribe_update_option('fb_token_expires', $expires);
     tribe_update_option('fb_token_scopes', trim(preg_replace('/[^a-zA-Z0-9\\,_-]/', '', $response->data->scopes)));
     // Send it back to the Given Url
     wp_redirect($url_map[$type]);
     exit;
 }
 private function handle_post($data = null)
 {
     if (is_null($data)) {
         if (!isset($_POST['aggregator'])) {
             return false;
         }
         $data = $_POST['aggregator'];
     }
     // Ensure it's an Object
     $data = (object) $data;
     if (!isset($data->action)) {
         return false;
     }
     if (!isset($data->nonce) || !wp_verify_nonce($data->nonce, 'aggregator_' . $this->get_slug() . '_request')) {
         return false;
     }
     if (empty($data->records)) {
         if (empty($data->ids)) {
             return false;
         }
         $data->records = explode(',', $data->ids);
     }
     // Ensures Records is an Array
     $data->records = (array) $data->records;
     switch ($data->action) {
         case 'delete':
             list($success, $errors) = $this->action_delete_record($data->records);
             break;
         case 'run-import':
             list($success, $errors) = $this->action_run_import($data->records);
             break;
     }
     $args = array('tab' => $this->get_slug(), 'action' => $data->action, 'ids' => implode(',', array_keys($success)));
     if (!empty($errors)) {
         $args['errors'] = $data->nonce;
         // Set the errors
         set_transient($this->get_errors_transient_name($data->nonce), $errors, 5 * MINUTE_IN_SECONDS);
     }
     $sendback = Tribe__Events__Aggregator__Page::instance()->get_url($args);
     wp_redirect($sendback);
     die;
 }
Example #8
0
 /**
  * Filter the Admin page tile and add Tab Name
  *
  * @param  string $admin_title Full Admin Title
  * @param  string $title       Original Title from the Page
  *
  * @return string
  */
 public function filter_admin_title($admin_title, $title)
 {
     if (!Tribe__Events__Aggregator__Page::instance()->is_screen()) {
         return $admin_title;
     }
     $tab = $this->get_active();
     return $tab->get_label() . ' &ndash; ' . $admin_title;
 }
Example #9
0
 protected function handle_row_actions($post, $column_name, $primary)
 {
     if ($primary !== $column_name) {
         return '';
     }
     if ('scheduled' !== $this->tab->get_slug()) {
         return '';
     }
     // disable row actions if the Aggregator service is inactive
     if (!Tribe__Events__Aggregator::instance()->is_service_active()) {
         return '';
     }
     $post_type_object = get_post_type_object($post->post_type);
     $actions = array();
     if (current_user_can($post_type_object->cap->edit_post, $post->ID)) {
         $actions['edit'] = sprintf('<a href="%s">%s</a>', get_edit_post_link($post->ID), __('Edit', 'the-events-calendar'));
         $args = array('tab' => $this->tab->get_slug(), 'action' => 'run-import', 'ids' => absint($post->ID), 'nonce' => wp_create_nonce('aggregator_' . $this->tab->get_slug() . '_request'));
         $actions['run-now'] = sprintf('<a href="%1$s" title="%2$s">%3$s</a>', Tribe__Events__Aggregator__Page::instance()->get_url($args), esc_attr__('Start an import from this source now, regardless of schedule.', 'the-events-calendar'), esc_html__('Run Import', 'the-events-calendar'));
     }
     if (current_user_can($post_type_object->cap->delete_post, $post->ID)) {
         $actions['delete'] = sprintf('<a href="%s" class="submitdelete">%s</a>', get_delete_post_link($post->ID, '', true), __('Delete', 'the-events-calendar'));
     }
     return $this->row_actions($actions);
 }
Example #10
0
 /**
  * Checks if a given Tab (slug) is active
  *
  * @param  string  $slug The Slug of the Tab
  *
  * @return boolean       Is this tab active?
  */
 public function is_active($slug = null)
 {
     if (!Tribe__Events__Aggregator__Page::instance()->is_screen()) {
         return false;
     }
     /**
      * Allow Developers to change the default tab
      * @param string $slug
      */
     $default = apply_filters('tribe_aggregator_default_tab', 'new');
     if (is_null($slug)) {
         // Set the slug
         $slug = !empty($_GET['tab']) && $this->exists($_GET['tab']) ? $_GET['tab'] : $default;
     }
     // Fetch the Active Tab
     $tab = $this->get_active();
     // Compare
     return $slug === $tab->get_slug();
 }