private function build_event_array($event_id, array $record)
 {
     $start_date = strtotime($this->get_event_start_date($record));
     $end_date = strtotime($this->get_event_end_date($record));
     $event = array('post_type' => Tribe__Events__Main::POSTTYPE, 'post_title' => $this->get_value_by_key($record, 'event_name'), 'post_status' => Tribe__Events__Importer__Options::get_default_post_status('csv'), 'post_content' => $this->get_value_by_key($record, 'event_description'), 'comment_status' => $this->get_boolean_value_by_key($record, 'event_comment_status', 'open', 'closed'), 'ping_status' => $this->get_boolean_value_by_key($record, 'event_ping_status', 'open', 'closed'), 'post_excerpt' => $this->get_post_excerpt($event_id, $this->get_value_by_key($record, 'event_excerpt')), 'menu_order' => $this->get_boolean_value_by_key($record, 'event_sticky', '-1', '0'), 'EventStartDate' => date('Y-m-d', $start_date), 'EventStartHour' => date('h', $start_date), 'EventStartMinute' => date('i', $start_date), 'EventStartMeridian' => date('a', $start_date), 'EventEndDate' => date('Y-m-d', $end_date), 'EventEndHour' => date('h', $end_date), 'EventEndMinute' => date('i', $end_date), 'EventEndMeridian' => date('a', $end_date), 'EventShowMapLink' => $this->get_boolean_value_by_key($record, 'event_show_map_link', '1', ''), 'EventShowMap' => $this->get_boolean_value_by_key($record, 'event_show_map', '1', ''), 'EventCost' => $this->get_value_by_key($record, 'event_cost'), 'EventAllDay' => $this->get_boolean_value_by_key($record, 'event_all_day', 'yes'), 'EventHideFromUpcoming' => $this->get_boolean_value_by_key($record, 'event_hide', 'yes', ''), 'EventURL' => $this->get_value_by_key($record, 'event_website'), 'EventCurrencySymbol' => $this->get_value_by_key($record, 'event_currency_symbol'), 'EventCurrencyPosition' => $this->get_currency_position($record), 'FeaturedImage' => $this->get_featured_image($event_id, $record), 'EventTimezone' => $this->get_timezone($this->get_value_by_key($record, 'event_timezone')));
     if ($organizer_id = $this->find_matching_organizer_id($record)) {
         $event['organizer'] = is_array($organizer_id) ? $organizer_id : array('OrganizerID' => $organizer_id);
     }
     if ($venue_id = $this->find_matching_venue_id($record)) {
         $event['venue'] = array('VenueID' => $venue_id);
     }
     if ($cats = $this->get_value_by_key($record, 'event_category')) {
         $event['tax_input'][Tribe__Events__Main::TAXONOMY] = $this->translate_terms_to_ids(explode(',', $cats));
     }
     if ($tags = $this->get_value_by_key($record, 'event_tags')) {
         $event['tax_input']['post_tag'] = $tags;
     }
     // don't create the _EventHideFromUpcoming meta key/value pair if it doesn't need to be created
     if (!$event['EventHideFromUpcoming']) {
         unset($event['EventHideFromUpcoming']);
     }
     if ($event['menu_order'] == '-1') {
         $event['EventShowInCalendar'] = 'yes';
     }
     $additional_fields = apply_filters('tribe_events_csv_import_event_additional_fields', array());
     if (!empty($additional_fields)) {
         foreach ($additional_fields as $key => $csv_column) {
             $event[$key] = $this->get_value_by_key($record, $key);
         }
     }
     return $event;
 }
Beispiel #2
0
 public function add_settings_fields($fields = array())
 {
     $newfields = array('csv-title' => array('type' => 'html', 'html' => '<h3>' . esc_html__('CSV Import Settings', 'the-events-calendar') . '</h3>'), 'csv-form-content-start' => array('type' => 'html', 'html' => '<div class="tribe-settings-form-wrap">'), 'imported_post_status[csv]' => array('type' => 'dropdown', 'label' => __('Default status to use for imported events', 'the-events-calendar'), 'options' => Tribe__Events__Importer__Options::get_possible_stati(), 'validation_type' => 'options', 'parent_option' => Tribe__Events__Main::OPTIONNAME), 'csv-form-content-end' => array('type' => 'html', 'html' => '</div>'));
     return array_merge($fields, $newfields);
 }
 public function import_next_row($throw = false, $preview = false)
 {
     $post_id = null;
     $record = $this->reader->read_next_row();
     $row = $this->reader->get_last_line_number_read() + 1;
     //Check if option to encode is active
     $encoding_option = Tribe__Events__Importer__Options::getOption('imported_encoding_status', array('csv' => 'encode'));
     if (isset($encoding_option['csv']) && 'encode' == $encoding_option['csv']) {
         $encoded = ForceUTF8__Encoding::toUTF8($record);
         $encoding_diff = array_diff($encoded, $record);
         if (!empty($encoding_diff)) {
             $this->encoding[] = $row;
         }
         $record = $encoded;
     }
     if ($preview) {
         return $record;
     }
     if (!$this->is_valid_record($record)) {
         if (!$throw) {
             $this->log[$row] = $this->get_skipped_row_message($row);
             $this->skipped[] = $row;
             return false;
         } else {
             throw new RuntimeException(sprintf('Missing required fields in row %d', $row));
         }
     }
     try {
         $post_id = $this->update_or_create_post($record);
     } catch (Exception $e) {
         $this->log[$row] = sprintf(esc_html__('Failed to import record in row %d.', 'the-events-calendar'), $row);
         $this->skipped[] = $row;
     }
     return $post_id;
 }
Beispiel #4
0
 * Hook to this filter to print More fields on the Importer Settings page
 */
$fields = apply_filters('tribe_import_general_settings', array());
foreach ($fields as $key => $field_args) {
    if (strpos($key, 'imported_post_status') === false) {
        $value = Tribe__Settings_Manager::get_option($key, null);
    } else {
        /**
         * Regular Expression to match "suboption_name" given "option_name[suboption_name]"
         */
        if (preg_match('/\\[([^\\]]+)\\]/i', $key, $match)) {
            $type = end($match);
        } else {
            $type = 'csv';
        }
        $value = Tribe__Events__Importer__Options::get_default_post_status($type);
    }
    new Tribe__Field($key, $field_args, $value);
}
wp_nonce_field('tribe-import-general-settings', 'tribe-import-general-settings');
?>
		<div class="tribe-settings-form-wrap">
			<p>
				<input type="submit" name="tribe-events-importexport-general-settings-submit" class="button-primary" value="<?php 
esc_attr_e('Save Settings', 'the-events-calendar');
?>
"/>
			</p>
		</div>
	</form>
</div>
 private function build_event_array(array $record)
 {
     $start_date = strtotime($this->get_event_start_date($record));
     $end_date = strtotime($this->get_event_end_date($record));
     $event = array('post_type' => Tribe__Events__Main::POSTTYPE, 'post_title' => $this->get_value_by_key($record, 'event_name'), 'post_status' => Tribe__Events__Importer__Options::get_default_post_status('csv'), 'post_content' => $this->get_value_by_key($record, 'event_description'), 'EventStartDate' => date('Y-m-d', $start_date), 'EventStartHour' => date('h', $start_date), 'EventStartMinute' => date('i', $start_date), 'EventStartMeridian' => date('a', $start_date), 'EventEndDate' => date('Y-m-d', $end_date), 'EventEndHour' => date('h', $end_date), 'EventEndMinute' => date('i', $end_date), 'EventEndMeridian' => date('a', $end_date), 'EventShowMapLink' => $this->get_boolean_value_by_key($record, 'event_show_map_link'), 'EventShowMap' => $this->get_boolean_value_by_key($record, 'event_show_map'), 'EventCost' => $this->get_value_by_key($record, 'event_cost'), 'EventAllDay' => $this->get_boolean_value_by_key($record, 'event_all_day', 'yes'), 'EventHideFromUpcoming' => $this->get_value_by_key($record, 'event_hide'), 'EventURL' => $this->get_value_by_key($record, 'event_website'), 'EventCurrencySymbol' => $this->get_value_by_key($record, 'event_currency_symbol'), 'EventCurrencyPosition' => $this->get_value_by_key($record, 'event_currency_position'));
     if ($organizer_id = $this->find_matching_organizer_id($record)) {
         $event['Organizer'] = array('OrganizerID' => $organizer_id);
     }
     if ($venue_id = $this->find_matching_venue_id($record)) {
         $event['Venue'] = array('VenueID' => $venue_id);
     }
     if ($cats = $this->get_value_by_key($record, 'event_category')) {
         $event['tax_input'][Tribe__Events__Main::TAXONOMY] = $this->translate_terms_to_ids(explode(',', $cats));
     }
     if ($tags = $this->get_value_by_key($record, 'event_tags')) {
         $event['tax_input']['post_tag'] = $tags;
     }
     $additional_fields = apply_filters('tribe_events_csv_import_event_additional_fields', array());
     if (!empty($additional_fields)) {
         foreach ($additional_fields as $key => $csv_column) {
             $event[$key] = $this->get_value_by_key($record, $key);
         }
     }
     return $event;
 }